Fixed #1430 (void foo(int nb))
This commit is contained in:
parent
a25cdd63b6
commit
e4a685c6e9
|
@ -467,44 +467,38 @@ public:
|
||||||
void CheckOther::functionVariableUsage()
|
void CheckOther::functionVariableUsage()
|
||||||
{
|
{
|
||||||
// Parse all executing scopes..
|
// Parse all executing scopes..
|
||||||
const Token *tok1 = _tokenizer->tokens();
|
for (const Token *token = Token::findmatch(_tokenizer->tokens(), ") const| {"); token;)
|
||||||
if (!tok1)
|
|
||||||
return;
|
|
||||||
|
|
||||||
while ((tok1 = Token::findmatch(tok1->next(), ") const| {")) != NULL)
|
|
||||||
{
|
{
|
||||||
|
// goto "{"
|
||||||
|
while (token->str() != "{")
|
||||||
|
token = token->next();
|
||||||
|
|
||||||
|
// First token for the current scope..
|
||||||
|
const Token * const tok1 = token;
|
||||||
|
|
||||||
|
// Find next scope that will be checked next time..
|
||||||
|
token = Token::findmatch(token->link(), ") const| {");
|
||||||
|
|
||||||
// Varname, usage {1=declare, 2=read, 4=write}
|
// Varname, usage {1=declare, 2=read, 4=write}
|
||||||
std::map<std::string, VariableUsage> varUsage;
|
std::map<std::string, VariableUsage> varUsage;
|
||||||
|
|
||||||
int indentlevel = 0;
|
unsigned int indentlevel = 0;
|
||||||
for (const Token *tok = tok1->next(); tok; tok = tok->next())
|
for (const Token *tok = tok1; tok; tok = tok->next())
|
||||||
{
|
{
|
||||||
if (tok->str() == "{")
|
if (tok->str() == "{")
|
||||||
++indentlevel;
|
++indentlevel;
|
||||||
else if (tok->str() == "}")
|
else if (tok->str() == "}")
|
||||||
{
|
{
|
||||||
--indentlevel;
|
if (indentlevel <= 1)
|
||||||
if (indentlevel <= 0)
|
|
||||||
break;
|
break;
|
||||||
|
--indentlevel;
|
||||||
}
|
}
|
||||||
else if (Token::Match(tok, "struct|union|class {") ||
|
else if (Token::Match(tok, "struct|union|class {") ||
|
||||||
Token::Match(tok, "struct|union|class %type% {"))
|
Token::Match(tok, "struct|union|class %type% {"))
|
||||||
{
|
{
|
||||||
int indentlevel0 = indentlevel;
|
|
||||||
|
|
||||||
while (tok->str() != "{")
|
while (tok->str() != "{")
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
|
tok = tok->link();
|
||||||
do
|
|
||||||
{
|
|
||||||
if (tok->str() == "{")
|
|
||||||
indentlevel++;
|
|
||||||
else if (tok->str() == "}")
|
|
||||||
indentlevel--;
|
|
||||||
tok = tok->next();
|
|
||||||
}
|
|
||||||
while (tok && indentlevel > indentlevel0);
|
|
||||||
|
|
||||||
if (! tok)
|
if (! tok)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -527,6 +521,9 @@ void CheckOther::functionVariableUsage()
|
||||||
else if (Token::Match(tok, ">>|& %var%"))
|
else if (Token::Match(tok, ">>|& %var%"))
|
||||||
varUsage[ tok->strAt(1)].use(); // use = read + write
|
varUsage[ tok->strAt(1)].use(); // use = read + write
|
||||||
|
|
||||||
|
else if (Token::Match(tok, "[(,] %var% [,)]"))
|
||||||
|
varUsage[ tok->strAt(1)].use(); // use = read + write
|
||||||
|
|
||||||
else if ((Token::Match(tok, "[(=&!]") || isOp(tok)) && Token::Match(tok->next(), "%var%"))
|
else if ((Token::Match(tok, "[(=&!]") || isOp(tok)) && Token::Match(tok->next(), "%var%"))
|
||||||
varUsage[ tok->strAt(1)].read = true;
|
varUsage[ tok->strAt(1)].read = true;
|
||||||
|
|
||||||
|
@ -536,9 +533,6 @@ void CheckOther::functionVariableUsage()
|
||||||
else if (Token::Match(tok, "%var%") && (tok->next()->str() == ")" || isOp(tok->next())))
|
else if (Token::Match(tok, "%var%") && (tok->next()->str() == ")" || isOp(tok->next())))
|
||||||
varUsage[ tok->str()].read = true;
|
varUsage[ tok->str()].read = true;
|
||||||
|
|
||||||
else if (Token::Match(tok, "[(,] %var% [,)]"))
|
|
||||||
varUsage[ tok->strAt(1)].use(); // use = read + write
|
|
||||||
|
|
||||||
else if (Token::Match(tok, "; %var% ;"))
|
else if (Token::Match(tok, "; %var% ;"))
|
||||||
varUsage[ tok->strAt(1)].read = true;
|
varUsage[ tok->strAt(1)].read = true;
|
||||||
}
|
}
|
||||||
|
@ -557,17 +551,17 @@ void CheckOther::functionVariableUsage()
|
||||||
|
|
||||||
if (usage.unused())
|
if (usage.unused())
|
||||||
{
|
{
|
||||||
unusedVariableError(tok1->next(), varname);
|
unusedVariableError(tok1, varname);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (!(usage.read))
|
else if (!(usage.read))
|
||||||
{
|
{
|
||||||
unreadVariableError(tok1->next(), varname);
|
unreadVariableError(tok1, varname);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (!(usage.write))
|
else if (!(usage.write))
|
||||||
{
|
{
|
||||||
unassignedVariableError(tok1->next(), varname);
|
unassignedVariableError(tok1, varname);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue