From eda25f6502deb6c2072d519e00665be43c5141fb Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Sat, 26 Feb 2011 15:51:12 -0500 Subject: [PATCH] add a list of function arguments to symbol database Function class --- lib/symboldatabase.cpp | 66 ++++++++++++++++++++++++++++++++++++++++++ lib/symboldatabase.h | 2 ++ 2 files changed, 68 insertions(+) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 54f5ea32f..f47ab688b 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -456,6 +456,20 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti } } + // fill in function arguments + for (it = scopeList.begin(); it != scopeList.end(); ++it) + { + scope = *it; + + std::list::iterator func; + + for (func = scope->functionList.begin(); func != scope->functionList.end(); ++func) + { + // add arguments + func->addArguments(this, scope); + } + } + // determine if user defined type needs initialization unsigned int unknowns = 0; // stop checking when there are no unknowns unsigned int retry = 0; // bail if we don't resolve all the variable types for some reason @@ -1002,6 +1016,58 @@ unsigned int Function::initializedArgCount() const return count; } +void Function::addArguments(const SymbolDatabase *symbolDatabase, const Scope *scope) +{ + // check for non-empty argument list "( ... )" + if (arg->link() != arg->next()) + { + unsigned int count = 0; + const Token *startTok; + const Token *endTok; + const Token *nameTok; + bool isConstVar; + const Token *tok = arg->next(); + for (;;) + { + startTok = tok; + endTok = NULL; + nameTok = NULL; + isConstVar = bool(tok->str() == "const"); + + while (tok->str() != "," && tok->str() != ")") + { + if (tok->varId() != 0) + { + nameTok = tok; + endTok = tok->previous(); + } + tok = tok->next(); + } + + // check for argument with no name + if (!endTok) + endTok = tok->previous(); + + const Token *typeTok = startTok; + if (isConstVar) + typeTok = typeTok->next(); + + const Scope *argType = NULL; + if (!typeTok->isStandardType()) + argType = symbolDatabase->findVariableType(scope, typeTok); + + bool isClassVar = startTok == endTok && !startTok->isStandardType(); + + argumentList.push_back(Variable(nameTok, startTok, endTok, count++, Argument, false, false, isConstVar, isClassVar, argType, scope)); + + if (tok->str() == ")") + break; + + tok = tok->next(); + } + } +} + //--------------------------------------------------------------------------- Scope::Scope(SymbolDatabase *check_, const Token *classDef_, Scope *nestedIn_) : diff --git a/lib/symboldatabase.h b/lib/symboldatabase.h index d45ad701f..b9c7560a6 100644 --- a/lib/symboldatabase.h +++ b/lib/symboldatabase.h @@ -317,6 +317,7 @@ public: unsigned int argCount() const; unsigned int initializedArgCount() const; + void addArguments(const SymbolDatabase *symbolDatabase, const Scope *scope); const Token *tokenDef; // function name token in class definition const Token *argDef; // function argument start '(' in class definition @@ -335,6 +336,7 @@ public: bool isOperator; // is operator bool retFuncPtr; // returns function pointer Type type; // constructor, destructor, ... + std::list argumentList; // argument list }; class Scope