Skip to content

Commit

Permalink
table: removed code enumerator in-line increment functions
Browse files Browse the repository at this point in the history
changed operators to sub-string assignment operators so that they match
the base sub-string functions; this allows the assign string recreate
function to not have to search for the base sub-string function code

removed using -1 as second associated index of sub-string functions
removed negative second associated index change from set token code
  (this function is not used for sub-string functions)
added ASC2, INSTR3, MID3 as second associated code to ASC, INSTR2, MID2
changed translator to use second associated code for multiple codes
removed token next code access function
  • Loading branch information
thunder422 committed Dec 13, 2014
1 parent 9a3c075 commit e5b55fa
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 56 deletions.
13 changes: 3 additions & 10 deletions basic/let.cpp
Expand Up @@ -237,16 +237,9 @@ void assignStrRecreate(Recreator &recreator, RpnItemPtr &rpnItem)
Code code {rpnItem->token()->code()};
if (recreator.table().hasFlag(code, SubStr_Flag))
{
// for sub-string assignments, get original sub-string function code
std::string name {recreator.table().name(code)};
Code subStrCode = Table::find(name);
// check multiple flag to see if sub-string code is correct code
if (recreator.table().hasFlag(code, Multiple_Flag))
{
subStrCode++; // move to next code
}
recreator.pushWithOperands(std::move(name),
recreator.table().operandCount(subStrCode));
// for sub-string assignments, treat as function to recreate
recreator.pushWithOperands(std::string{recreator.table().name(code)},
recreator.table().operandCount(code));
}

// deterine if assignment is an sub-string assignment keep code
Expand Down
16 changes: 0 additions & 16 deletions ibcp.h
Expand Up @@ -271,22 +271,6 @@ enum Code
Function_Code
};

// code operator in-line functions for additional, increment and decrement
inline Code operator +(Code code, int number)
{
return (Code)((int)code + number);
}

inline Code operator ++(Code &code)
{
return code = code + 1;
}

inline Code operator ++(Code &code, int)
{
return code = code + 1;
}


// miscellenous constant definitions
constexpr int HighestPrecedence {127}; // highest precedence value
Expand Down
53 changes: 29 additions & 24 deletions table.cpp
Expand Up @@ -137,6 +137,7 @@ static Code Add_AssocCode[] = {
AddInt_Code, CatStr_Code, AddI2_Code
};
static Code AddInt_AssocCode[] = {AddI1_Code};
static Code Asc_AssocCode[] = {Asc2_Code};
static Code Assign_AssocCode[] = {
AssignInt_Code, AssignStr_Code, AssignList_Code
};
Expand Down Expand Up @@ -168,6 +169,7 @@ static Code InputAssign_AssocCode[] = {
};
static Code InputAssignInt_AssocCode[] = {InputParseInt_Code};
static Code InputAssignStr_AssocCode[] = {InputParseStr_Code};
static Code Instr_AssocCode[] = {Instr3_Code};
static Code Left_AssocCode[] = {AssignLeft_Code};
static Code Lt_AssocCode[] = {
LtInt_Code, LtStr_Code, LtI2_Code
Expand All @@ -177,7 +179,7 @@ static Code LtEq_AssocCode[] = {
LtEqInt_Code, LtEqStr_Code, LtEqI2_Code
};
static Code LtEqInt_AssocCode[] = {LtEqI1_Code};
static Code Mid2_AssocCode[] = {AssignMid2_Code};
static Code Mid2_AssocCode[] = {AssignMid2_Code, Mid3_Code};
static Code Mid3_AssocCode[] = {AssignMid3_Code};
static Code Mod_AssocCode[] = {ModInt_Code, ModI2_Code};
static Code ModInt_AssocCode[] = {ModI1_Code};
Expand Down Expand Up @@ -583,7 +585,9 @@ static TableEntry tableEntries[] =
{ // Asc_Code
Token::Type::IntFuncP,
"ASC(", "", "",
Multiple_Flag, 2, &Int_Str_ExprInfo, DataType{},
Multiple_Flag, 2,
new ExprInfo(DataType::Integer, Operands(Str), AssocCode(Asc)),
DataType{},
NULL, NULL, NULL, NULL, internalFunctionRecreate
},
{ // Asc2_Code
Expand All @@ -601,7 +605,9 @@ static TableEntry tableEntries[] =
{ // Instr2_Code
Token::Type::IntFuncP,
"INSTR(", "2", "",
Multiple_Flag, 2, &Int_StrStr_ExprInfo, DataType{},
Multiple_Flag, 2,
new ExprInfo(DataType::Integer, Operands(StrStr), AssocCode(Instr)),
DataType{},
NULL, NULL, NULL, NULL, internalFunctionRecreate
},
{ // Instr3_Code
Expand All @@ -614,7 +620,7 @@ static TableEntry tableEntries[] =
Token::Type::IntFuncP,
"LEFT$(", "", "",
SubStr_Flag, 2,
new ExprInfo(DataType::String, Operands(StrInt), AssocCode2(Left, -1)),
new ExprInfo(DataType::String, Operands(StrInt), AssocCode(Left)),
DataType{},
NULL, NULL, NULL, NULL, internalFunctionRecreate
},
Expand All @@ -628,16 +634,16 @@ static TableEntry tableEntries[] =
Token::Type::IntFuncP,
"MID$(", "2", "",
Multiple_Flag | SubStr_Flag, 2,
new ExprInfo(DataType::String, Operands(StrInt), AssocCode2(Mid2, -1)),
new ExprInfo(DataType::String, Operands(StrInt), AssocCode2(Mid2, 1)),
DataType{},
NULL, NULL, NULL, NULL, internalFunctionRecreate
},
{ // Mid3_Code
Token::Type::IntFuncP,
"MID$(", "3", "",
SubStr_Flag, 2,
new ExprInfo(DataType::String, Operands(StrIntInt),
AssocCode2(Mid3, -1)), DataType{},
new ExprInfo(DataType::String, Operands(StrIntInt), AssocCode(Mid3)),
DataType{},
NULL, NULL, NULL, NULL, internalFunctionRecreate
},
{ // Repeat_Code
Expand All @@ -650,7 +656,7 @@ static TableEntry tableEntries[] =
Token::Type::IntFuncP,
"RIGHT$(", "", "",
SubStr_Flag, 2,
new ExprInfo(DataType::String, Operands(StrInt), AssocCode2(Right, -1)),
new ExprInfo(DataType::String, Operands(StrInt), AssocCode(Right)),
DataType{},
NULL, NULL, NULL, NULL, internalFunctionRecreate
},
Expand Down Expand Up @@ -816,78 +822,81 @@ static TableEntry tableEntries[] =
Token::Type::Operator,
"=", "Assign", "LET",
Reference_Flag, 4,
new ExprInfo(DataType::Double, Operands(DblDbl), AssocCode2(Assign, 2)),
new ExprInfo(DataType::Double, Operands(Dbl), AssocCode2(Assign, 2)),
DataType{},
NULL, NULL, NULL, NULL, assignRecreate
},
{ // AssignInt_Code
Token::Type::Operator,
"=", "Assign%", "LET",
Reference_Flag, 4,
new ExprInfo(DataType::Integer, Operands(IntInt), AssocCode(AssignInt)),
new ExprInfo(DataType::Integer, Operands(Int), AssocCode(AssignInt)),
DataType{},
NULL, NULL, NULL, NULL, assignRecreate
},
{ // AssignStr_Code
Token::Type::Operator,
"=", "Assign$", "LET",
Reference_Flag, 4, new ExprInfo(DataType::String, Operands(StrStr),
Reference_Flag, 4, new ExprInfo(DataType::String, Operands(Str),
AssocCode2(AssignStr, 1)), DataType{},
NULL, NULL, NULL, NULL, assignStrRecreate
},
{ // AssignLeft_Code
Token::Type::Operator,
"LEFT$(", "Assign", "LET",
Reference_Flag | SubStr_Flag, 4,
new ExprInfo(DataType::String, Operands(StrStr), AssocCode(AssignLeft)),
new ExprInfo(DataType::String, Operands(StrInt), AssocCode(AssignLeft)),
DataType{},
NULL, NULL, NULL, NULL, assignStrRecreate
},
{ // AssignMid2_Code
Token::Type::Operator,
"MID$(", "Assign2", "LET",
Reference_Flag | SubStr_Flag, 4,
new ExprInfo(DataType::String, Operands(StrStr), AssocCode(AssignMid2)),
new ExprInfo(DataType::String, Operands(StrInt), AssocCode(AssignMid2)),
DataType{},
NULL, NULL, NULL, NULL, assignStrRecreate
},
{ // AssignMid3_Code
Token::Type::Operator,
"MID$(", "Assign3", "LET",
Reference_Flag | SubStr_Flag | Multiple_Flag, 4,
new ExprInfo(DataType::String, Operands(StrStr), AssocCode(AssignMid3)),
new ExprInfo(DataType::String, Operands(StrIntInt),
AssocCode(AssignMid3)),
DataType{},
NULL, NULL, NULL, NULL, assignStrRecreate
},
{ // AssignRight_Code
Token::Type::Operator,
"RIGHT$(", "Assign", "LET",
Reference_Flag | SubStr_Flag, 4, new ExprInfo(DataType::String,
Operands(StrStr), AssocCode(AssignRight)), DataType{},
Reference_Flag | SubStr_Flag, 4,
new ExprInfo(DataType::String, Operands(StrInt),
AssocCode(AssignRight)),
DataType{},
NULL, NULL, NULL, NULL, assignStrRecreate
},
{ // AssignList_Code
Token::Type::Operator,
"=", "AssignList", "LET",
Reference_Flag, 4, &Dbl_DblDbl_ExprInfo, DataType{},
Reference_Flag, 4, &Dbl_Dbl_ExprInfo, DataType{},
NULL, NULL, NULL, NULL, assignRecreate
},
{ // AssignListInt_Code
Token::Type::Operator,
"=", "AssignList%", "LET",
Reference_Flag, 4, &Int_IntInt_ExprInfo, DataType{},
Reference_Flag, 4, &Int_Int_ExprInfo, DataType{},
NULL, NULL, NULL, NULL, assignRecreate
},
{ // AssignListStr_Code
Token::Type::Operator,
"=", "AssignList$", "LET",
Reference_Flag, 4, &Str_StrStr_ExprInfo, DataType{},
Reference_Flag, 4, &Str_Str_ExprInfo, DataType{},
NULL, NULL, NULL, NULL, assignRecreate
},
{ // AssignKeepStr_Code
Token::Type::Operator,
"", "AssignKeep$", "LET",
Reference_Flag | Keep_Flag, 4, &Str_StrStr_ExprInfo, DataType{},
Reference_Flag | Keep_Flag, 4, &Str_Str_ExprInfo, DataType{},
NULL, NULL, NULL, NULL, assignStrRecreate
},
{ // AssignKeepLeft_Code
Expand Down Expand Up @@ -1938,10 +1947,6 @@ bool Table::setTokenCode(TokenPtr token, Code code, DataType dataType,
{
// if not, see if data type of any associated code matches
int i {secondAssociatedIndex(code)};
if (i < 0) // if second index -1, then no associated codes to search
{
return false;
}
// determine range of associated codes to search
int end {associatedCodeCount(code)};
if (operandIndex == 0 && i != 0) // first operand?
Expand Down
4 changes: 0 additions & 4 deletions token.h
Expand Up @@ -169,10 +169,6 @@ class Token
{
m_code = code;
}
Code nextCode(void)
{
return ++m_code;
}
bool isCode(Code code) const
{
return code == m_code;
Expand Down
5 changes: 3 additions & 2 deletions translator.cpp
Expand Up @@ -616,8 +616,9 @@ void Translator::processInternalFunction(Reference reference)
// function doesn't have multiple entries
throw TokenError {Status::ExpOpOrParen, m_token};
}
// move to next code; update code and last operand index
code = topToken->nextCode();
// get second associated code; update code and last operand
code = m_table.secondAssociatedCode(topToken->code());
topToken->setCode(code);
lastOperand = m_table.operandCount(code) - 1;
}
m_token.reset(); // delete comma token, it's not needed
Expand Down

0 comments on commit e5b55fa

Please sign in to comment.