SymbolDatabase: Improved find function functionality. Taking arguments into account

This commit is contained in:
Robert Reif 2012-10-14 17:34:09 +02:00 committed by Daniel Marjamäki
parent 0d4b87c71e
commit cf7996e299
2 changed files with 8 additions and 16 deletions

View File

@ -1569,19 +1569,6 @@ void SymbolDatabase::printOut(const char *title) const
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
unsigned int Function::initializedArgCount() const
{
unsigned int count = 0;
std::list<Variable>::const_iterator var;
for (var = argumentList.begin(); var != argumentList.end(); ++var) {
if (var->hasDefault())
++count;
}
return count;
}
void Function::addArguments(const SymbolDatabase *symbolDatabase, const Scope *scope) void Function::addArguments(const SymbolDatabase *symbolDatabase, const Scope *scope)
{ {
// check for non-empty argument list "( ... )" // check for non-empty argument list "( ... )"
@ -1642,6 +1629,7 @@ void Function::addArguments(const SymbolDatabase *symbolDatabase, const Scope *s
// skip default values // skip default values
if (tok->str() == "=") { if (tok->str() == "=") {
initArgCount++;
while (tok->str() != "," && tok->str() != ")") { while (tok->str() != "," && tok->str() != ")") {
if (tok->link() && Token::Match(tok, "[{[(<]")) if (tok->link() && Token::Match(tok, "[{[(<]"))
tok = tok->link(); tok = tok->link();
@ -2175,8 +2163,7 @@ const Function* SymbolDatabase::findFunctionByNameAndArgs(const Token *tok, cons
const Function *func = &*i; const Function *func = &*i;
if (tok->strAt(1) == "(" && tok->tokAt(2)) { if (tok->strAt(1) == "(" && tok->tokAt(2)) {
// check if function has no arguments // check if function has no arguments
/** @todo check for default arguments */ if (tok->strAt(2) == ")" && (func->argCount() == 0 || func->argCount() == func->initializedArgCount()))
if (tok->strAt(2) == ")" && func->argCount() == 0)
return func; return func;
// check the arguments // check the arguments
@ -2184,6 +2171,7 @@ const Function* SymbolDatabase::findFunctionByNameAndArgs(const Token *tok, cons
const Token *arg = tok->tokAt(2); const Token *arg = tok->tokAt(2);
while (arg) { while (arg) {
/** @todo check argument type for match */ /** @todo check argument type for match */
/** @todo check for default arguments */
args++; args++;
arg = arg->nextArgument(); arg = arg->nextArgument();
} }

View File

@ -379,6 +379,7 @@ public:
arg(NULL), arg(NULL),
functionScope(NULL), functionScope(NULL),
nestedIn(NULL), nestedIn(NULL),
initArgCount(0),
type(eFunction), type(eFunction),
access(Public), access(Public),
hasBody(false), hasBody(false),
@ -397,7 +398,9 @@ public:
return argumentList.size(); return argumentList.size();
} }
const Variable* getArgumentVar(unsigned int num) const; const Variable* getArgumentVar(unsigned int num) const;
unsigned int initializedArgCount() const; unsigned int initializedArgCount() const {
return initArgCount;
}
void addArguments(const SymbolDatabase *symbolDatabase, const Scope *scope); void addArguments(const SymbolDatabase *symbolDatabase, const Scope *scope);
/** @brief check if this function is virtual in the base classes */ /** @brief check if this function is virtual in the base classes */
bool isImplicitlyVirtual(bool defaultVal = false) const; bool isImplicitlyVirtual(bool defaultVal = false) const;
@ -409,6 +412,7 @@ public:
Scope *functionScope; // scope of function body Scope *functionScope; // scope of function body
Scope* nestedIn; // Scope the function is declared in Scope* nestedIn; // Scope the function is declared in
std::list<Variable> argumentList; // argument list std::list<Variable> argumentList; // argument list
unsigned int initArgCount; // number of args with default values
Type type; // constructor, destructor, ... Type type; // constructor, destructor, ...
AccessControl access; // public/protected/private AccessControl access; // public/protected/private
bool hasBody; // has implementation bool hasBody; // has implementation