Fixed #2454 (Tokenizer::simplifyKnownVariables: problem with float/double variables)
This commit is contained in:
parent
cf32016444
commit
97d0755750
|
@ -6206,6 +6206,9 @@ bool Tokenizer::simplifyKnownVariables()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// variable id for float/double variables
|
||||||
|
std::set<unsigned int> floatvars;
|
||||||
|
|
||||||
// auto variables..
|
// auto variables..
|
||||||
for (Token *tok = _tokens; tok; tok = tok->next())
|
for (Token *tok = _tokens; tok; tok = tok->next())
|
||||||
{
|
{
|
||||||
|
@ -6218,6 +6221,11 @@ bool Tokenizer::simplifyKnownVariables()
|
||||||
Token *tok2 = tok;
|
Token *tok2 = tok;
|
||||||
for (; tok2; tok2 = tok2->next())
|
for (; tok2; tok2 = tok2->next())
|
||||||
{
|
{
|
||||||
|
if (Token::Match(tok2, "[;{}] float|double %var% ;"))
|
||||||
|
{
|
||||||
|
floatvars.insert(tok2->tokAt(2)->varId());
|
||||||
|
}
|
||||||
|
|
||||||
if (tok2->str() == "{")
|
if (tok2->str() == "{")
|
||||||
++indentlevel;
|
++indentlevel;
|
||||||
|
|
||||||
|
@ -6325,8 +6333,18 @@ bool Tokenizer::simplifyKnownVariables()
|
||||||
if (tok2->strAt(4) == ";")
|
if (tok2->strAt(4) == ";")
|
||||||
valueIsPointer = true;
|
valueIsPointer = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// float value should contain a "."
|
||||||
|
else if (tok2->tokAt(2)->isNumber() &&
|
||||||
|
floatvars.find(tok2->varId()) != floatvars.end() &&
|
||||||
|
value.find(".") == std::string::npos)
|
||||||
|
{
|
||||||
|
value += ".0";
|
||||||
|
}
|
||||||
|
|
||||||
if (Token::simpleMatch(tok2->next(), "= &"))
|
if (Token::simpleMatch(tok2->next(), "= &"))
|
||||||
tok2 = tok2->tokAt(3);
|
tok2 = tok2->tokAt(3);
|
||||||
|
|
||||||
tok3 = tok2->next();
|
tok3 = tok2->next();
|
||||||
}
|
}
|
||||||
Token* bailOutFromLoop = 0;
|
Token* bailOutFromLoop = 0;
|
||||||
|
|
|
@ -132,6 +132,7 @@ private:
|
||||||
TEST_CASE(simplifyKnownVariablesBailOutMemberFunction);
|
TEST_CASE(simplifyKnownVariablesBailOutMemberFunction);
|
||||||
TEST_CASE(simplifyKnownVariablesBailOutConditionalIncrement);
|
TEST_CASE(simplifyKnownVariablesBailOutConditionalIncrement);
|
||||||
TEST_CASE(simplifyKnownVariablesBailOutSwitchBreak); // ticket #2324
|
TEST_CASE(simplifyKnownVariablesBailOutSwitchBreak); // ticket #2324
|
||||||
|
TEST_CASE(simplifyKnownVariablesFloat); // #2454 - float variable
|
||||||
|
|
||||||
TEST_CASE(varid1);
|
TEST_CASE(varid1);
|
||||||
TEST_CASE(varid2);
|
TEST_CASE(varid2);
|
||||||
|
@ -2104,6 +2105,21 @@ private:
|
||||||
ASSERT_EQUALS(expected, tokenizeAndStringify(code,true));
|
ASSERT_EQUALS(expected, tokenizeAndStringify(code,true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void simplifyKnownVariablesFloat()
|
||||||
|
{
|
||||||
|
// Ticket #2454
|
||||||
|
const char code[] = "void f() {\n"
|
||||||
|
" float a = 40;\n"
|
||||||
|
" x(10 / a);\n"
|
||||||
|
"}\n";
|
||||||
|
|
||||||
|
const char expected[] = "void f ( ) {\n;\nx ( 0.25 ) ;\n}";
|
||||||
|
|
||||||
|
ASSERT_EQUALS(expected, tokenizeAndStringify(code,true));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
std::string tokenizeDebugListing(const std::string &code, bool simplify = false)
|
std::string tokenizeDebugListing(const std::string &code, bool simplify = false)
|
||||||
{
|
{
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
Loading…
Reference in New Issue