MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / addArguments

Method addArguments

lib/symboldatabase.cpp:4690–4830  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4688//---------------------------------------------------------------------------
4689
4690void Function::addArguments(const Scope *scope)
4691{
4692 // check for non-empty argument list "( ... )"
4693 const Token * start = arg ? arg : argDef;
4694 if (!Token::simpleMatch(start, "("))
4695 return;
4696 if (!(start && start->link() != start->next() && !Token::simpleMatch(start, "( void )")))
4697 return;
4698
4699 unsigned int count = 0;
4700
4701 for (const Token* tok = start->next(); tok; tok = tok->next()) {
4702 if (Token::Match(tok, ",|)"))
4703 return; // Syntax error
4704
4705 const Token* startTok = tok;
4706 const Token* endTok = nullptr;
4707 const Token* nameTok = nullptr;
4708
4709 do {
4710 if (Token::simpleMatch(tok, "decltype (")) {
4711 tok = tok->linkAt(1)->next();
4712 continue;
4713 }
4714 if (tok != startTok && !nameTok && Token::Match(tok, "( & %var% ) [")) {
4715 nameTok = tok->tokAt(2);
4716 endTok = nameTok->previous();
4717 tok = tok->link();
4718 } else if (tok != startTok && !nameTok && Token::Match(tok, "( * const| %var% ) (") && Token::Match(tok->link()->linkAt(1), ") [,)]")) {
4719 nameTok = tok->link()->previous();
4720 endTok = nameTok->previous();
4721 tok = tok->link()->linkAt(1);
4722 } else if (tok != startTok && !nameTok && Token::Match(tok, "( * %var% ) [")) {
4723 nameTok = tok->tokAt(2);
4724 endTok = nameTok->previous();
4725 tok = tok->link();
4726 } else if (tok->varId() != 0) {
4727 nameTok = tok;
4728 endTok = tok->previous();
4729 } else if (tok->str() == "[") {
4730 // skip array dimension(s)
4731 tok = tok->link();
4732 while (tok->strAt(1) == "[")
4733 tok = tok->linkAt(1);
4734 } else if (tok->str() == "<") {
4735 tok = tok->link();
4736 if (!tok) // something is wrong so just bail out
4737 return;
4738 }
4739
4740 tok = tok->next();
4741
4742 if (!tok) // something is wrong so just bail
4743 return;
4744 } while (tok->str() != "," && tok->str() != ")" && tok->str() != "=");
4745
4746 const Token *typeTok = startTok;
4747 // skip over stuff to get to type

Callers 1

Calls 14

hasBodyFunction · 0.85
isVariadicFunction · 0.85
findLambdaEndTokenFunction · 0.85
nextMethod · 0.80
linkAtMethod · 0.80
debugMessageMethod · 0.80
typeMethod · 0.80
simpleMatchFunction · 0.70
tokAtMethod · 0.45
strMethod · 0.45

Tested by

no test coverage detected