Tokenizer::simplifyKnownVariables: Split up the function into smaller functions. Broke out ..GetData function that extracts info about assigned variable before the simplification is made.
This commit is contained in:
parent
edc472dd34
commit
63ade3e4f6
|
@ -6237,6 +6237,25 @@ bool Tokenizer::simplifyKnownVariables()
|
|||
Token *tok3 = NULL;
|
||||
bool valueIsPointer = false;
|
||||
|
||||
if (!simplifyKnownVariablesGetData(varid, &tok2, &tok3, value, valueVarId, valueIsPointer, floatvars.find(tok2->varId()) != floatvars.end()))
|
||||
continue;
|
||||
|
||||
ret |= simplifyKnownVariablesSimplify(&tok2, tok3, varid, structname, value, valueVarId, valueIsPointer, pointeralias, indentlevel);
|
||||
}
|
||||
}
|
||||
|
||||
if (tok2)
|
||||
tok = tok2->previous();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool Tokenizer::simplifyKnownVariablesGetData(unsigned int varid, Token **_tok2, Token **_tok3, std::string &value, unsigned int &valueVarId, bool &valueIsPointer, bool floatvar)
|
||||
{
|
||||
Token *tok2 = *_tok2;
|
||||
Token *tok3 = *_tok3;
|
||||
|
||||
if (Token::Match(tok2->tokAt(-2), "for ( %varid% = %num% ; %varid% <|<= %num% ; ++| %varid% ++| ) {", varid))
|
||||
{
|
||||
// is there a "break" in the for loop?
|
||||
|
@ -6259,7 +6278,7 @@ bool Tokenizer::simplifyKnownVariables()
|
|||
}
|
||||
}
|
||||
if (hasbreak)
|
||||
break;
|
||||
return false;
|
||||
|
||||
// no break => the value of the counter value is known after the for loop..
|
||||
const std::string compareop = tok2->strAt(5);
|
||||
|
@ -6297,7 +6316,7 @@ bool Tokenizer::simplifyKnownVariables()
|
|||
|
||||
// float value should contain a "."
|
||||
else if (tok2->tokAt(2)->isNumber() &&
|
||||
floatvars.find(tok2->varId()) != floatvars.end() &&
|
||||
floatvar &&
|
||||
value.find(".") == std::string::npos)
|
||||
{
|
||||
value += ".0";
|
||||
|
@ -6308,15 +6327,9 @@ bool Tokenizer::simplifyKnownVariables()
|
|||
|
||||
tok3 = tok2->next();
|
||||
}
|
||||
ret |= simplifyKnownVariablesSimplify(&tok2, tok3, varid, structname, value, valueVarId, valueIsPointer, pointeralias, indentlevel);
|
||||
}
|
||||
}
|
||||
|
||||
if (tok2)
|
||||
tok = tok2->previous();
|
||||
}
|
||||
|
||||
return ret;
|
||||
*_tok2 = tok2;
|
||||
*_tok3 = tok3;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Tokenizer::simplifyKnownVariablesSimplify(Token **tok2, Token *tok3, unsigned int varid, const std::string &structname, std::string &value, unsigned int valueVarId, bool valueIsPointer, bool pointeralias, int indentlevel)
|
||||
|
|
|
@ -308,6 +308,12 @@ public:
|
|||
*/
|
||||
bool simplifyKnownVariables();
|
||||
|
||||
/**
|
||||
* Utility function for simplifyKnownVariables. Get data about an
|
||||
* assigned variable.
|
||||
*/
|
||||
bool simplifyKnownVariablesGetData(unsigned int varid, Token **_tok2, Token **_tok3, std::string &value, unsigned int &valueVarId, bool &valueIsPointer, bool floatvar);
|
||||
|
||||
/**
|
||||
* utility function for simplifyKnownVariables. Perform simplification
|
||||
* of a given variable
|
||||
|
|
Loading…
Reference in New Issue