symbol database: improve function argument count and default argument count
This commit is contained in:
parent
d17a204096
commit
faaff942d2
|
@ -651,7 +651,7 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
|
|||
if (func->type == Function::eConstructor)
|
||||
{
|
||||
// check for no arguments: func ( )
|
||||
if (func->argDef->next() == func->argDef->link())
|
||||
if (func->argCount() == 0)
|
||||
{
|
||||
hasDefaultConstructor = true;
|
||||
break;
|
||||
|
@ -1195,14 +1195,12 @@ void SymbolDatabase::debugMessage(const Token *tok, const std::string &msg) cons
|
|||
unsigned int Function::initializedArgCount() const
|
||||
{
|
||||
unsigned int count = 0;
|
||||
std::list<Variable>::const_iterator var;
|
||||
|
||||
if (argDef->link() != argDef->next())
|
||||
for (var = argumentList.begin(); var != argumentList.end(); ++var)
|
||||
{
|
||||
for (const Token *tok = argDef->next(); tok && tok->next() && tok->next() != argDef->link(); tok = tok->next())
|
||||
{
|
||||
if (tok->str() == "=")
|
||||
count++;
|
||||
}
|
||||
if (var->hasDefault())
|
||||
++count;
|
||||
}
|
||||
|
||||
return count;
|
||||
|
@ -1219,6 +1217,7 @@ void Function::addArguments(const SymbolDatabase *symbolDatabase, const Scope *s
|
|||
const Token *nameTok;
|
||||
bool isConstVar;
|
||||
bool isArrayVar;
|
||||
bool hasDefault;
|
||||
const Token *tok = arg->next();
|
||||
for (;;)
|
||||
{
|
||||
|
@ -1227,6 +1226,7 @@ void Function::addArguments(const SymbolDatabase *symbolDatabase, const Scope *s
|
|||
nameTok = NULL;
|
||||
isConstVar = bool(tok->str() == "const");
|
||||
isArrayVar = false;
|
||||
hasDefault = false;
|
||||
|
||||
while (tok->str() != "," && tok->str() != ")" && tok->str() != "=")
|
||||
{
|
||||
|
@ -1270,15 +1270,17 @@ void Function::addArguments(const SymbolDatabase *symbolDatabase, const Scope *s
|
|||
|
||||
bool isClassVar = startTok == endTok && !startTok->isStandardType();
|
||||
|
||||
argumentList.push_back(Variable(nameTok, startTok, endTok, count++, Argument, false, false, isConstVar, isClassVar, argType, functionScope, isArrayVar));
|
||||
|
||||
// skip default values
|
||||
if (tok->str() == "=")
|
||||
{
|
||||
hasDefault = true;
|
||||
|
||||
while (tok->str() != "," && tok->str() != ")")
|
||||
tok = tok->next();
|
||||
}
|
||||
|
||||
argumentList.push_back(Variable(nameTok, startTok, endTok, count++, Argument, false, false, isConstVar, isClassVar, argType, functionScope, isArrayVar, hasDefault));
|
||||
|
||||
if (tok->str() == ")")
|
||||
break;
|
||||
|
||||
|
@ -1365,8 +1367,7 @@ Scope::hasDefaultConstructor() const
|
|||
|
||||
for (func = functionList.begin(); func != functionList.end(); ++func)
|
||||
{
|
||||
if (func->type == Function::eConstructor &&
|
||||
func->argDef->link() == func->argDef->next())
|
||||
if (func->type == Function::eConstructor && func->argCount() == 0)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,11 +46,12 @@ class Variable
|
|||
/** @brief flags mask used to access specific bit. */
|
||||
enum
|
||||
{
|
||||
fIsMutable = (1 << 0), /** @brief mutable variable */
|
||||
fIsStatic = (1 << 1), /** @brief static variable */
|
||||
fIsConst = (1 << 2), /** @brief const variable */
|
||||
fIsClass = (1 << 3), /** @brief user defined type */
|
||||
fIsArray = (1 << 4) /** @brief array variable */
|
||||
fIsMutable = (1 << 0), /** @brief mutable variable */
|
||||
fIsStatic = (1 << 1), /** @brief static variable */
|
||||
fIsConst = (1 << 2), /** @brief const variable */
|
||||
fIsClass = (1 << 3), /** @brief user defined type */
|
||||
fIsArray = (1 << 4), /** @brief array variable */
|
||||
fHasDefault = (1 << 5) /** @brief function argument with default value */
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -77,7 +78,7 @@ public:
|
|||
Variable(const Token *name_, const Token *start_, const Token *end_,
|
||||
std::size_t index_, AccessControl access_, bool mutable_,
|
||||
bool static_, bool const_, bool class_, const Scope *type_,
|
||||
const Scope *scope_, bool array_)
|
||||
const Scope *scope_, bool array_, bool default_)
|
||||
: _name(name_),
|
||||
_start(start_),
|
||||
_end(end_),
|
||||
|
@ -92,6 +93,7 @@ public:
|
|||
setFlag(fIsConst, const_);
|
||||
setFlag(fIsClass, class_);
|
||||
setFlag(fIsArray, array_);
|
||||
setFlag(fHasDefault, default_);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -266,6 +268,15 @@ public:
|
|||
return getFlag(fIsArray);
|
||||
}
|
||||
|
||||
/**
|
||||
* Does variable have a default value.
|
||||
* @return true if has a default falue, false if not
|
||||
*/
|
||||
bool hasDefault() const
|
||||
{
|
||||
return getFlag(fHasDefault);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Scope pointer of known type.
|
||||
* @return pointer to type if known, NULL if not known
|
||||
|
@ -445,7 +456,7 @@ public:
|
|||
{
|
||||
varlist.push_back(Variable(token_, start_, end_, varlist.size(),
|
||||
access_, mutable_, static_, const_, class_,
|
||||
type_, scope_, array_));
|
||||
type_, scope_, array_, false));
|
||||
}
|
||||
|
||||
/** @brief initialize varlist */
|
||||
|
|
Loading…
Reference in New Issue