refactoring, use early return
This commit is contained in:
parent
32fe0aba41
commit
ea598d5284
|
@ -3001,98 +3001,99 @@ void Function::addArguments(const SymbolDatabase *symbolDatabase, const Scope *s
|
||||||
{
|
{
|
||||||
// check for non-empty argument list "( ... )"
|
// check for non-empty argument list "( ... )"
|
||||||
const Token * start = arg ? arg : argDef;
|
const Token * start = arg ? arg : argDef;
|
||||||
if (start && start->link() != start->next() && !Token::simpleMatch(start, "( void )")) {
|
if (!(start && start->link() != start->next() && !Token::simpleMatch(start, "( void )")))
|
||||||
unsigned int count = 0;
|
return;
|
||||||
|
|
||||||
for (const Token* tok = start->next(); tok; tok = tok->next()) {
|
unsigned int count = 0;
|
||||||
if (Token::Match(tok, ",|)"))
|
|
||||||
return; // Syntax error
|
|
||||||
|
|
||||||
const Token* startTok = tok;
|
for (const Token* tok = start->next(); tok; tok = tok->next()) {
|
||||||
const Token* endTok = nullptr;
|
if (Token::Match(tok, ",|)"))
|
||||||
const Token* nameTok = nullptr;
|
return; // Syntax error
|
||||||
|
|
||||||
do {
|
const Token* startTok = tok;
|
||||||
if (tok->varId() != 0) {
|
const Token* endTok = nullptr;
|
||||||
nameTok = tok;
|
const Token* nameTok = nullptr;
|
||||||
endTok = tok->previous();
|
|
||||||
} else if (tok->str() == "[") {
|
|
||||||
// skip array dimension(s)
|
|
||||||
tok = tok->link();
|
|
||||||
while (tok->next()->str() == "[")
|
|
||||||
tok = tok->next()->link();
|
|
||||||
} else if (tok->str() == "<") {
|
|
||||||
tok = tok->link();
|
|
||||||
if (!tok) // something is wrong so just bail out
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
tok = tok->next();
|
do {
|
||||||
|
if (tok->varId() != 0) {
|
||||||
if (!tok) // something is wrong so just bail
|
nameTok = tok;
|
||||||
|
endTok = tok->previous();
|
||||||
|
} else if (tok->str() == "[") {
|
||||||
|
// skip array dimension(s)
|
||||||
|
tok = tok->link();
|
||||||
|
while (tok->next()->str() == "[")
|
||||||
|
tok = tok->next()->link();
|
||||||
|
} else if (tok->str() == "<") {
|
||||||
|
tok = tok->link();
|
||||||
|
if (!tok) // something is wrong so just bail out
|
||||||
return;
|
return;
|
||||||
} while (tok->str() != "," && tok->str() != ")" && tok->str() != "=");
|
}
|
||||||
|
|
||||||
const Token *typeTok = startTok;
|
tok = tok->next();
|
||||||
// skip over stuff to get to type
|
|
||||||
while (Token::Match(typeTok, "const|enum|struct|::"))
|
|
||||||
typeTok = typeTok->next();
|
|
||||||
// skip over qualification
|
|
||||||
while (Token::Match(typeTok, "%type% ::"))
|
|
||||||
typeTok = typeTok->tokAt(2);
|
|
||||||
|
|
||||||
// check for argument with no name or missing varid
|
if (!tok) // something is wrong so just bail
|
||||||
if (!endTok) {
|
return;
|
||||||
if (tok->previous()->isName() && tok->strAt(-1) != "const") {
|
} while (tok->str() != "," && tok->str() != ")" && tok->str() != "=");
|
||||||
if (tok->previous() != typeTok) {
|
|
||||||
nameTok = tok->previous();
|
|
||||||
endTok = nameTok->previous();
|
|
||||||
|
|
||||||
if (hasBody())
|
const Token *typeTok = startTok;
|
||||||
symbolDatabase->debugMessage(nameTok, "Function::addArguments found argument \'" + nameTok->str() + "\' with varid 0.");
|
// skip over stuff to get to type
|
||||||
} else
|
while (Token::Match(typeTok, "const|enum|struct|::"))
|
||||||
endTok = typeTok;
|
typeTok = typeTok->next();
|
||||||
|
// skip over qualification
|
||||||
|
while (Token::Match(typeTok, "%type% ::"))
|
||||||
|
typeTok = typeTok->tokAt(2);
|
||||||
|
|
||||||
|
// check for argument with no name or missing varid
|
||||||
|
if (!endTok) {
|
||||||
|
if (tok->previous()->isName() && tok->strAt(-1) != "const") {
|
||||||
|
if (tok->previous() != typeTok) {
|
||||||
|
nameTok = tok->previous();
|
||||||
|
endTok = nameTok->previous();
|
||||||
|
|
||||||
|
if (hasBody())
|
||||||
|
symbolDatabase->debugMessage(nameTok, "Function::addArguments found argument \'" + nameTok->str() + "\' with varid 0.");
|
||||||
} else
|
} else
|
||||||
endTok = tok->previous();
|
endTok = typeTok;
|
||||||
}
|
} else
|
||||||
|
endTok = tok->previous();
|
||||||
const ::Type *argType = nullptr;
|
|
||||||
if (!typeTok->isStandardType()) {
|
|
||||||
argType = findVariableTypeIncludingUsedNamespaces(symbolDatabase, scope, typeTok);
|
|
||||||
|
|
||||||
// save type
|
|
||||||
const_cast<Token *>(typeTok)->type(argType);
|
|
||||||
}
|
|
||||||
|
|
||||||
// skip default values
|
|
||||||
if (tok->str() == "=") {
|
|
||||||
do {
|
|
||||||
if (tok->link() && Token::Match(tok, "[{[(<]"))
|
|
||||||
tok = tok->link();
|
|
||||||
tok = tok->next();
|
|
||||||
} while (tok->str() != "," && tok->str() != ")");
|
|
||||||
}
|
|
||||||
|
|
||||||
// skip over stuff before type
|
|
||||||
while (Token::Match(startTok, "enum|struct|const"))
|
|
||||||
startTok = startTok->next();
|
|
||||||
|
|
||||||
argumentList.push_back(Variable(nameTok, startTok, endTok, count++, Argument, argType, functionScope, &symbolDatabase->_settings->library));
|
|
||||||
|
|
||||||
if (tok->str() == ")") {
|
|
||||||
// check for a variadic function
|
|
||||||
if (Token::simpleMatch(startTok, ". . ."))
|
|
||||||
isVariadic(true);
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// count default arguments
|
const ::Type *argType = nullptr;
|
||||||
for (const Token* tok = argDef->next(); tok && tok != argDef->link(); tok = tok->next()) {
|
if (!typeTok->isStandardType()) {
|
||||||
if (tok->str() == "=")
|
argType = findVariableTypeIncludingUsedNamespaces(symbolDatabase, scope, typeTok);
|
||||||
initArgCount++;
|
|
||||||
|
// save type
|
||||||
|
const_cast<Token *>(typeTok)->type(argType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// skip default values
|
||||||
|
if (tok->str() == "=") {
|
||||||
|
do {
|
||||||
|
if (tok->link() && Token::Match(tok, "[{[(<]"))
|
||||||
|
tok = tok->link();
|
||||||
|
tok = tok->next();
|
||||||
|
} while (tok->str() != "," && tok->str() != ")");
|
||||||
|
}
|
||||||
|
|
||||||
|
// skip over stuff before type
|
||||||
|
while (Token::Match(startTok, "enum|struct|const"))
|
||||||
|
startTok = startTok->next();
|
||||||
|
|
||||||
|
argumentList.push_back(Variable(nameTok, startTok, endTok, count++, Argument, argType, functionScope, &symbolDatabase->_settings->library));
|
||||||
|
|
||||||
|
if (tok->str() == ")") {
|
||||||
|
// check for a variadic function
|
||||||
|
if (Token::simpleMatch(startTok, ". . ."))
|
||||||
|
isVariadic(true);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// count default arguments
|
||||||
|
for (const Token* tok = argDef->next(); tok && tok != argDef->link(); tok = tok->next()) {
|
||||||
|
if (tok->str() == "=")
|
||||||
|
initArgCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue