Refactorizations in SymbolDatabase:
- Skip struct keywords in argument list so that Variables declared like "Struct Foo bar" get a type - Remvoved redundant argument from Function::addArguments - Set Function::functionScope for global functions - Replaced some indendation counters by Token::findClosingBracket
This commit is contained in:
parent
6fd6f0998b
commit
a0d92f5ed9
|
@ -603,7 +603,7 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
|
||||||
|
|
||||||
for (func = it->functionList.begin(); func != it->functionList.end(); ++func) {
|
for (func = it->functionList.begin(); func != it->functionList.end(); ++func) {
|
||||||
// add arguments
|
// add arguments
|
||||||
func->addArguments(this, &*func, scope);
|
func->addArguments(this, scope);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -919,6 +919,7 @@ Function* SymbolDatabase::addGlobalFunction(Scope*& scope, const Token*& tok, co
|
||||||
|
|
||||||
if (scope) {
|
if (scope) {
|
||||||
scope->function = function;
|
scope->function = function;
|
||||||
|
function->functionScope = scope;
|
||||||
return function;
|
return function;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -956,7 +957,6 @@ Function* SymbolDatabase::addGlobalFunctionDecl(Scope*& scope, const Token*& tok
|
||||||
void SymbolDatabase::addClassFunction(Scope **scope, const Token **tok, const Token *argStart)
|
void SymbolDatabase::addClassFunction(Scope **scope, const Token **tok, const Token *argStart)
|
||||||
{
|
{
|
||||||
int count = 0;
|
int count = 0;
|
||||||
bool added = false;
|
|
||||||
std::string path;
|
std::string path;
|
||||||
unsigned int path_length = 0;
|
unsigned int path_length = 0;
|
||||||
const Token *tok1;
|
const Token *tok1;
|
||||||
|
@ -1081,19 +1081,16 @@ void SymbolDatabase::addClassFunction(Scope **scope, const Token **tok, const To
|
||||||
(*scope)->functionOf = scope1;
|
(*scope)->functionOf = scope1;
|
||||||
(*scope)->function = &*func;
|
(*scope)->function = &*func;
|
||||||
(*scope)->function->functionScope = *scope;
|
(*scope)->function->functionScope = *scope;
|
||||||
|
|
||||||
added = true;
|
|
||||||
}
|
}
|
||||||
break;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// check for class function for unknown class
|
// class function of unknown class
|
||||||
if (!added)
|
addNewFunction(scope, tok);
|
||||||
addNewFunction(scope, tok);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SymbolDatabase::addNewFunction(Scope **scope, const Token **tok)
|
void SymbolDatabase::addNewFunction(Scope **scope, const Token **tok)
|
||||||
|
@ -1134,16 +1131,13 @@ const Token *SymbolDatabase::initBaseInfo(Scope *scope, const Token *tok)
|
||||||
{
|
{
|
||||||
// goto initial '{'
|
// goto initial '{'
|
||||||
const Token *tok2 = tok->tokAt(2);
|
const Token *tok2 = tok->tokAt(2);
|
||||||
int level = 0;
|
|
||||||
while (tok2 && tok2->str() != "{") {
|
while (tok2 && tok2->str() != "{") {
|
||||||
// skip unsupported templates
|
// skip unsupported templates
|
||||||
if (tok2->str() == "<")
|
if (tok2->str() == "<")
|
||||||
level++;
|
tok2->findClosingBracket(tok2);
|
||||||
else if (tok2->str() == ">")
|
|
||||||
level--;
|
|
||||||
|
|
||||||
// check for base classes
|
// check for base classes
|
||||||
else if (level == 0 && Token::Match(tok2, ":|,")) {
|
else if (Token::Match(tok2, ":|,")) {
|
||||||
Scope::BaseInfo base;
|
Scope::BaseInfo base;
|
||||||
|
|
||||||
base.isVirtual = false;
|
base.isVirtual = false;
|
||||||
|
@ -1527,7 +1521,7 @@ unsigned int Function::initializedArgCount() const
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Function::addArguments(const SymbolDatabase *symbolDatabase, const Function *func, const Scope *scope)
|
void Function::addArguments(const SymbolDatabase *symbolDatabase, const Scope *scope)
|
||||||
{
|
{
|
||||||
// check for non-empty argument list "( ... )"
|
// check for non-empty argument list "( ... )"
|
||||||
if (arg && arg->link() != arg->next() && !Token::simpleMatch(arg, "( void )")) {
|
if (arg && arg->link() != arg->next() && !Token::simpleMatch(arg, "( void )")) {
|
||||||
|
@ -1554,17 +1548,8 @@ void Function::addArguments(const SymbolDatabase *symbolDatabase, const Function
|
||||||
while (tok->next()->str() == "[")
|
while (tok->next()->str() == "[")
|
||||||
tok = tok->next()->link();
|
tok = tok->next()->link();
|
||||||
} else if (tok->str() == "<") {
|
} else if (tok->str() == "<") {
|
||||||
int level = 1;
|
bool success = tok->findClosingBracket(tok);
|
||||||
while (tok && tok->next()) {
|
if (!tok || !success) // something is wrong so just bail out
|
||||||
tok = tok->next();
|
|
||||||
if (tok->str() == ">") {
|
|
||||||
--level;
|
|
||||||
if (level == 0)
|
|
||||||
break;
|
|
||||||
} else if (tok->str() == "<")
|
|
||||||
level++;
|
|
||||||
}
|
|
||||||
if (!tok) // something is wrong so just bail
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1575,6 +1560,8 @@ void Function::addArguments(const SymbolDatabase *symbolDatabase, const Function
|
||||||
}
|
}
|
||||||
|
|
||||||
const Token *typeTok = startTok->tokAt(isConstVar ? 1 : 0);
|
const Token *typeTok = startTok->tokAt(isConstVar ? 1 : 0);
|
||||||
|
if (typeTok->str() == "struct")
|
||||||
|
typeTok = typeTok->next();
|
||||||
|
|
||||||
// check for argument with no name or missing varid
|
// check for argument with no name or missing varid
|
||||||
if (!endTok) {
|
if (!endTok) {
|
||||||
|
@ -1583,7 +1570,7 @@ void Function::addArguments(const SymbolDatabase *symbolDatabase, const Function
|
||||||
nameTok = tok->previous();
|
nameTok = tok->previous();
|
||||||
endTok = nameTok->previous();
|
endTok = nameTok->previous();
|
||||||
|
|
||||||
if (func->hasBody)
|
if (hasBody)
|
||||||
symbolDatabase->debugMessage(nameTok, "Function::addArguments found argument \'" + nameTok->str() + "\' with varid 0.");
|
symbolDatabase->debugMessage(nameTok, "Function::addArguments found argument \'" + nameTok->str() + "\' with varid 0.");
|
||||||
} else
|
} else
|
||||||
endTok = startTok;
|
endTok = startTok;
|
||||||
|
@ -1767,7 +1754,7 @@ void Scope::getVariableList()
|
||||||
{
|
{
|
||||||
AccessControl varaccess = defaultAccess();
|
AccessControl varaccess = defaultAccess();
|
||||||
const Token *start;
|
const Token *start;
|
||||||
int level = 1;
|
unsigned int level = 1;
|
||||||
|
|
||||||
if (classStart)
|
if (classStart)
|
||||||
start = classStart->next();
|
start = classStart->next();
|
||||||
|
@ -2056,7 +2043,7 @@ const Scope *SymbolDatabase::findVariableType(const Scope *start, const Token *t
|
||||||
// do the names match?
|
// do the names match?
|
||||||
if (scope->className == type->str()) {
|
if (scope->className == type->str()) {
|
||||||
// check if type does not have a namespace
|
// check if type does not have a namespace
|
||||||
if (type->previous() != NULL && type->previous()->str() != "::") {
|
if (type->previous() == NULL || type->previous()->str() != "::") {
|
||||||
const Scope *parent = start;
|
const Scope *parent = start;
|
||||||
|
|
||||||
// check if in same namespace
|
// check if in same namespace
|
||||||
|
|
|
@ -385,7 +385,7 @@ public:
|
||||||
return argumentList.size();
|
return argumentList.size();
|
||||||
}
|
}
|
||||||
unsigned int initializedArgCount() const;
|
unsigned int initializedArgCount() const;
|
||||||
void addArguments(const SymbolDatabase *symbolDatabase, const Function *func, 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;
|
||||||
|
|
||||||
|
|
|
@ -150,6 +150,7 @@ private:
|
||||||
TEST_CASE(symboldatabase25); // ticket #3561 (throw C++)
|
TEST_CASE(symboldatabase25); // ticket #3561 (throw C++)
|
||||||
TEST_CASE(symboldatabase26); // ticket #3561 (throw C)
|
TEST_CASE(symboldatabase26); // ticket #3561 (throw C)
|
||||||
TEST_CASE(symboldatabase27); // ticket #3543 (segmentation fault)
|
TEST_CASE(symboldatabase27); // ticket #3543 (segmentation fault)
|
||||||
|
TEST_CASE(symboldatabase28);
|
||||||
|
|
||||||
TEST_CASE(isImplicitlyVirtual);
|
TEST_CASE(isImplicitlyVirtual);
|
||||||
}
|
}
|
||||||
|
@ -1133,6 +1134,12 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void symboldatabase28() {
|
||||||
|
GET_SYMBOL_DB("struct S {};\n"
|
||||||
|
"void foo(struct S s) {}");
|
||||||
|
ASSERT(db && db->getVariableFromVarId(1) && db->getVariableFromVarId(1)->type() && db->getVariableFromVarId(1)->type()->className == "S");
|
||||||
|
}
|
||||||
|
|
||||||
void isImplicitlyVirtual() {
|
void isImplicitlyVirtual() {
|
||||||
{
|
{
|
||||||
GET_SYMBOL_DB("class Base {\n"
|
GET_SYMBOL_DB("class Base {\n"
|
||||||
|
|
Loading…
Reference in New Issue