Merge branch 'master' of http://github.com/danmar/cppcheck
This commit is contained in:
commit
211074270c
6
Makefile
6
Makefile
|
@ -1,7 +1,7 @@
|
||||||
# This file is generated by tools/dmake, do not edit.
|
# This file is generated by tools/dmake, do not edit.
|
||||||
|
|
||||||
ifndef CXXFLAGS
|
ifndef CXXFLAGS
|
||||||
CXXFLAGS=-Wall -Wextra -Wshadow -pedantic -Wno-long-long -Wfloat-equal -Wcast-qual -Wsign-conversion -g
|
CXXFLAGS=-Wall -Wextra -Wshadow -pedantic -Wno-long-long -Wfloat-equal -Wcast-qual -Wsign-conversion -Wconversion -g
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifndef CXX
|
ifndef CXX
|
||||||
|
@ -103,8 +103,8 @@ cppcheck: $(LIBOBJ) $(CLIOBJ) $(EXTOBJ)
|
||||||
|
|
||||||
all: cppcheck testrunner
|
all: cppcheck testrunner
|
||||||
|
|
||||||
testrunner: $(TESTOBJ) $(LIBOBJ) $(EXTOBJ) cli/threadexecutor.o cli/cmdlineparser.o cli/cppcheckexecutor.o cli/filelister.o cli/filelister_unix.o
|
testrunner: $(TESTOBJ) $(LIBOBJ) $(EXTOBJ) cli/threadexecutor.o cli/cmdlineparser.o cli/cppcheckexecutor.o
|
||||||
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -o testrunner $(TESTOBJ) $(LIBOBJ) $(EXTOBJ) -lpcre cli/threadexecutor.o cli/cmdlineparser.o cli/filelister.o cli/filelister_unix.o $(LDFLAGS)
|
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -o testrunner $(TESTOBJ) $(LIBOBJ) $(EXTOBJ) -lpcre cli/threadexecutor.o cli/cmdlineparser.o cli/cppcheckexecutor.o $(LDFLAGS)
|
||||||
|
|
||||||
test: all
|
test: all
|
||||||
./testrunner
|
./testrunner
|
||||||
|
|
|
@ -70,7 +70,7 @@ void CheckClass::constructors()
|
||||||
|
|
||||||
std::list<Scope *>::const_iterator i;
|
std::list<Scope *>::const_iterator i;
|
||||||
|
|
||||||
for (i = symbolDatabase->spaceInfoList.begin(); i != symbolDatabase->spaceInfoList.end(); ++i)
|
for (i = symbolDatabase->scopeList.begin(); i != symbolDatabase->scopeList.end(); ++i)
|
||||||
{
|
{
|
||||||
const Scope *scope = *i;
|
const Scope *scope = *i;
|
||||||
|
|
||||||
|
@ -233,7 +233,7 @@ bool CheckClass::isBaseClassFunc(const Token *tok, const Scope *scope)
|
||||||
// Iterate through each base class...
|
// Iterate through each base class...
|
||||||
for (size_t i = 0; i < scope->derivedFrom.size(); ++i)
|
for (size_t i = 0; i < scope->derivedFrom.size(); ++i)
|
||||||
{
|
{
|
||||||
const Scope *derivedFrom = scope->derivedFrom[i].spaceInfo;
|
const Scope *derivedFrom = scope->derivedFrom[i].scope;
|
||||||
|
|
||||||
// Check if base class exists in database
|
// Check if base class exists in database
|
||||||
if (derivedFrom)
|
if (derivedFrom)
|
||||||
|
@ -592,7 +592,7 @@ void CheckClass::privateFunctions()
|
||||||
|
|
||||||
std::list<Scope *>::const_iterator i;
|
std::list<Scope *>::const_iterator i;
|
||||||
|
|
||||||
for (i = symbolDatabase->spaceInfoList.begin(); i != symbolDatabase->spaceInfoList.end(); ++i)
|
for (i = symbolDatabase->scopeList.begin(); i != symbolDatabase->scopeList.end(); ++i)
|
||||||
{
|
{
|
||||||
const Scope *scope = *i;
|
const Scope *scope = *i;
|
||||||
|
|
||||||
|
@ -860,7 +860,7 @@ void CheckClass::operatorEq()
|
||||||
|
|
||||||
std::list<Scope *>::const_iterator i;
|
std::list<Scope *>::const_iterator i;
|
||||||
|
|
||||||
for (i = symbolDatabase->spaceInfoList.begin(); i != symbolDatabase->spaceInfoList.end(); ++i)
|
for (i = symbolDatabase->scopeList.begin(); i != symbolDatabase->scopeList.end(); ++i)
|
||||||
{
|
{
|
||||||
std::list<Function>::const_iterator it;
|
std::list<Function>::const_iterator it;
|
||||||
|
|
||||||
|
@ -944,7 +944,7 @@ void CheckClass::operatorEqRetRefThis()
|
||||||
|
|
||||||
std::list<Scope *>::const_iterator i;
|
std::list<Scope *>::const_iterator i;
|
||||||
|
|
||||||
for (i = symbolDatabase->spaceInfoList.begin(); i != symbolDatabase->spaceInfoList.end(); ++i)
|
for (i = symbolDatabase->scopeList.begin(); i != symbolDatabase->scopeList.end(); ++i)
|
||||||
{
|
{
|
||||||
const Scope *scope = *i;
|
const Scope *scope = *i;
|
||||||
|
|
||||||
|
@ -1000,7 +1000,7 @@ void CheckClass::operatorEqToSelf()
|
||||||
|
|
||||||
std::list<Scope *>::const_iterator i;
|
std::list<Scope *>::const_iterator i;
|
||||||
|
|
||||||
for (i = symbolDatabase->spaceInfoList.begin(); i != symbolDatabase->spaceInfoList.end(); ++i)
|
for (i = symbolDatabase->scopeList.begin(); i != symbolDatabase->scopeList.end(); ++i)
|
||||||
{
|
{
|
||||||
const Scope *scope = *i;
|
const Scope *scope = *i;
|
||||||
std::list<Function>::const_iterator it;
|
std::list<Function>::const_iterator it;
|
||||||
|
@ -1177,7 +1177,7 @@ void CheckClass::virtualDestructor()
|
||||||
|
|
||||||
std::list<Scope *>::const_iterator i;
|
std::list<Scope *>::const_iterator i;
|
||||||
|
|
||||||
for (i = symbolDatabase->spaceInfoList.begin(); i != symbolDatabase->spaceInfoList.end(); ++i)
|
for (i = symbolDatabase->scopeList.begin(); i != symbolDatabase->scopeList.end(); ++i)
|
||||||
{
|
{
|
||||||
const Scope *scope = *i;
|
const Scope *scope = *i;
|
||||||
|
|
||||||
|
@ -1203,15 +1203,15 @@ void CheckClass::virtualDestructor()
|
||||||
for (unsigned int j = 0; j < scope->derivedFrom.size(); ++j)
|
for (unsigned int j = 0; j < scope->derivedFrom.size(); ++j)
|
||||||
{
|
{
|
||||||
// Check if base class is public and exists in database
|
// Check if base class is public and exists in database
|
||||||
if (scope->derivedFrom[j].access != Private && scope->derivedFrom[j].spaceInfo)
|
if (scope->derivedFrom[j].access != Private && scope->derivedFrom[j].scope)
|
||||||
{
|
{
|
||||||
const Scope *spaceInfo = scope->derivedFrom[j].spaceInfo;
|
const Scope *derivedFrom = scope->derivedFrom[j].scope;
|
||||||
|
|
||||||
// Name of base class..
|
// Name of base class..
|
||||||
const std::string baseName = spaceInfo->className;
|
const std::string baseName = derivedFrom->className;
|
||||||
|
|
||||||
// Find the destructor declaration for the base class.
|
// Find the destructor declaration for the base class.
|
||||||
const Function *base_destructor = spaceInfo->getDestructor();
|
const Function *base_destructor = derivedFrom->getDestructor();
|
||||||
const Token *base = 0;
|
const Token *base = 0;
|
||||||
if (base_destructor)
|
if (base_destructor)
|
||||||
base = base_destructor->token;
|
base = base_destructor->token;
|
||||||
|
@ -1219,8 +1219,8 @@ void CheckClass::virtualDestructor()
|
||||||
// Check that there is a destructor..
|
// Check that there is a destructor..
|
||||||
if (!base_destructor)
|
if (!base_destructor)
|
||||||
{
|
{
|
||||||
if (spaceInfo->derivedFrom.empty())
|
if (derivedFrom->derivedFrom.empty())
|
||||||
virtualDestructorError(spaceInfo->classDef, baseName, derivedClass->str());
|
virtualDestructorError(derivedFrom->classDef, baseName, derivedClass->str());
|
||||||
}
|
}
|
||||||
else if (!base_destructor->isVirtual)
|
else if (!base_destructor->isVirtual)
|
||||||
{
|
{
|
||||||
|
@ -1230,7 +1230,7 @@ void CheckClass::virtualDestructor()
|
||||||
// Proper solution is to check all of the base classes. If base class is not
|
// Proper solution is to check all of the base classes. If base class is not
|
||||||
// found or if one of the base classes has virtual destructor, error should not
|
// found or if one of the base classes has virtual destructor, error should not
|
||||||
// be printed. See TODO test case "virtualDestructorInherited"
|
// be printed. See TODO test case "virtualDestructorInherited"
|
||||||
if (spaceInfo->derivedFrom.empty())
|
if (derivedFrom->derivedFrom.empty())
|
||||||
{
|
{
|
||||||
// Make sure that the destructor is public (protected or private
|
// Make sure that the destructor is public (protected or private
|
||||||
// would not compile if inheritance is used in a way that would
|
// would not compile if inheritance is used in a way that would
|
||||||
|
@ -1296,7 +1296,7 @@ void CheckClass::checkConst()
|
||||||
|
|
||||||
std::list<Scope *>::const_iterator it;
|
std::list<Scope *>::const_iterator it;
|
||||||
|
|
||||||
for (it = symbolDatabase->spaceInfoList.begin(); it != symbolDatabase->spaceInfoList.end(); ++it)
|
for (it = symbolDatabase->scopeList.begin(); it != symbolDatabase->scopeList.end(); ++it)
|
||||||
{
|
{
|
||||||
const Scope *scope = *it;
|
const Scope *scope = *it;
|
||||||
|
|
||||||
|
@ -1440,12 +1440,12 @@ bool CheckClass::isMemberVar(const Scope *scope, const Token *tok)
|
||||||
for (unsigned int i = 0; i < scope->derivedFrom.size(); ++i)
|
for (unsigned int i = 0; i < scope->derivedFrom.size(); ++i)
|
||||||
{
|
{
|
||||||
// find the base class
|
// find the base class
|
||||||
const Scope *spaceInfo = scope->derivedFrom[i].spaceInfo;
|
const Scope *derivedFrom = scope->derivedFrom[i].scope;
|
||||||
|
|
||||||
// find the function in the base class
|
// find the function in the base class
|
||||||
if (spaceInfo)
|
if (derivedFrom)
|
||||||
{
|
{
|
||||||
if (isMemberVar(spaceInfo, tok))
|
if (isMemberVar(derivedFrom, tok))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1471,12 +1471,12 @@ bool CheckClass::isConstMemberFunc(const Scope *scope, const Token *tok)
|
||||||
for (unsigned int i = 0; i < scope->derivedFrom.size(); ++i)
|
for (unsigned int i = 0; i < scope->derivedFrom.size(); ++i)
|
||||||
{
|
{
|
||||||
// find the base class
|
// find the base class
|
||||||
const Scope *spaceInfo = scope->derivedFrom[i].spaceInfo;
|
const Scope *derivedFrom = scope->derivedFrom[i].scope;
|
||||||
|
|
||||||
// find the function in the base class
|
// find the function in the base class
|
||||||
if (spaceInfo)
|
if (derivedFrom)
|
||||||
{
|
{
|
||||||
if (isConstMemberFunc(spaceInfo, tok))
|
if (isConstMemberFunc(derivedFrom, tok))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1588,9 +1588,9 @@ bool CheckClass::isVirtualFunc(const Scope *scope, const Token *functionToken) c
|
||||||
for (unsigned int i = 0; i < scope->derivedFrom.size(); ++i)
|
for (unsigned int i = 0; i < scope->derivedFrom.size(); ++i)
|
||||||
{
|
{
|
||||||
// check if base class exists in database
|
// check if base class exists in database
|
||||||
if (scope->derivedFrom[i].spaceInfo)
|
if (scope->derivedFrom[i].scope)
|
||||||
{
|
{
|
||||||
const Scope *derivedFrom = scope->derivedFrom[i].spaceInfo;
|
const Scope *derivedFrom = scope->derivedFrom[i].scope;
|
||||||
|
|
||||||
std::list<Function>::const_iterator func;
|
std::list<Function>::const_iterator func;
|
||||||
|
|
||||||
|
|
|
@ -567,7 +567,7 @@ void CheckMemoryLeakInFunction::parse_noreturn()
|
||||||
|
|
||||||
std::list<Scope *>::const_iterator i;
|
std::list<Scope *>::const_iterator i;
|
||||||
|
|
||||||
for (i = symbolDatabase->spaceInfoList.begin(); i != symbolDatabase->spaceInfoList.end(); ++i)
|
for (i = symbolDatabase->scopeList.begin(); i != symbolDatabase->scopeList.end(); ++i)
|
||||||
{
|
{
|
||||||
const Scope *scope = *i;
|
const Scope *scope = *i;
|
||||||
|
|
||||||
|
@ -2493,7 +2493,7 @@ void CheckMemoryLeakInFunction::checkReallocUsage()
|
||||||
{
|
{
|
||||||
std::list<Scope *>::const_iterator i;
|
std::list<Scope *>::const_iterator i;
|
||||||
|
|
||||||
for (i = symbolDatabase->spaceInfoList.begin(); i != symbolDatabase->spaceInfoList.end(); ++i)
|
for (i = symbolDatabase->scopeList.begin(); i != symbolDatabase->scopeList.end(); ++i)
|
||||||
{
|
{
|
||||||
const Scope *scope = *i;
|
const Scope *scope = *i;
|
||||||
|
|
||||||
|
@ -2646,7 +2646,7 @@ void CheckMemoryLeakInFunction::check()
|
||||||
|
|
||||||
std::list<Scope *>::const_iterator i;
|
std::list<Scope *>::const_iterator i;
|
||||||
|
|
||||||
for (i = symbolDatabase->spaceInfoList.begin(); i != symbolDatabase->spaceInfoList.end(); ++i)
|
for (i = symbolDatabase->scopeList.begin(); i != symbolDatabase->scopeList.end(); ++i)
|
||||||
{
|
{
|
||||||
const Scope *scope = *i;
|
const Scope *scope = *i;
|
||||||
|
|
||||||
|
@ -2703,7 +2703,7 @@ void CheckMemoryLeakInClass::check()
|
||||||
|
|
||||||
std::list<Scope *>::const_iterator i;
|
std::list<Scope *>::const_iterator i;
|
||||||
|
|
||||||
for (i = symbolDatabase->spaceInfoList.begin(); i != symbolDatabase->spaceInfoList.end(); ++i)
|
for (i = symbolDatabase->scopeList.begin(); i != symbolDatabase->scopeList.end(); ++i)
|
||||||
{
|
{
|
||||||
const Scope *scope = *i;
|
const Scope *scope = *i;
|
||||||
|
|
||||||
|
@ -3168,7 +3168,7 @@ void CheckMemoryLeakNoVar::check()
|
||||||
|
|
||||||
std::list<Scope *>::const_iterator i;
|
std::list<Scope *>::const_iterator i;
|
||||||
|
|
||||||
for (i = symbolDatabase->spaceInfoList.begin(); i != symbolDatabase->spaceInfoList.end(); ++i)
|
for (i = symbolDatabase->scopeList.begin(); i != symbolDatabase->scopeList.end(); ++i)
|
||||||
{
|
{
|
||||||
Scope *scope = *i;
|
Scope *scope = *i;
|
||||||
|
|
||||||
|
|
|
@ -39,40 +39,40 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
|
||||||
: _tokenizer(tokenizer), _settings(settings), _errorLogger(errorLogger)
|
: _tokenizer(tokenizer), _settings(settings), _errorLogger(errorLogger)
|
||||||
{
|
{
|
||||||
// find all namespaces (class,struct and namespace)
|
// find all namespaces (class,struct and namespace)
|
||||||
Scope *info = new Scope(this, NULL, NULL);
|
Scope *scope = new Scope(this, NULL, NULL);
|
||||||
spaceInfoList.push_back(info);
|
scopeList.push_back(scope);
|
||||||
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
|
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
|
||||||
{
|
{
|
||||||
// Locate next class
|
// Locate next class
|
||||||
if (Token::Match(tok, "class|struct|namespace %var% [{:]"))
|
if (Token::Match(tok, "class|struct|namespace %var% [{:]"))
|
||||||
{
|
{
|
||||||
Scope *new_info = new Scope(this, tok, info);
|
Scope *new_scope = new Scope(this, tok, scope);
|
||||||
const Token *tok2 = tok->tokAt(2);
|
const Token *tok2 = tok->tokAt(2);
|
||||||
|
|
||||||
// only create base list for classes and structures
|
// only create base list for classes and structures
|
||||||
if (new_info->isClassOrStruct())
|
if (new_scope->isClassOrStruct())
|
||||||
{
|
{
|
||||||
// fill the classAndStructTypes set..
|
// fill the classAndStructTypes set..
|
||||||
classAndStructTypes.insert(new_info->className);
|
classAndStructTypes.insert(new_scope->className);
|
||||||
|
|
||||||
// goto initial '{'
|
// goto initial '{'
|
||||||
tok2 = initBaseInfo(new_info, tok);
|
tok2 = initBaseInfo(new_scope, tok);
|
||||||
}
|
}
|
||||||
|
|
||||||
new_info->classStart = tok2;
|
new_scope->classStart = tok2;
|
||||||
new_info->classEnd = tok2->link();
|
new_scope->classEnd = tok2->link();
|
||||||
|
|
||||||
// make sure we have valid code
|
// make sure we have valid code
|
||||||
if (!new_info->classEnd)
|
if (!new_scope->classEnd)
|
||||||
{
|
{
|
||||||
delete new_info;
|
delete new_scope;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
info = new_info;
|
scope = new_scope;
|
||||||
|
|
||||||
// add namespace
|
// add namespace
|
||||||
spaceInfoList.push_back(info);
|
scopeList.push_back(scope);
|
||||||
|
|
||||||
tok = tok2;
|
tok = tok2;
|
||||||
}
|
}
|
||||||
|
@ -91,33 +91,33 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// check for end of space
|
// check for end of space
|
||||||
if (tok == info->classEnd)
|
if (tok == scope->classEnd)
|
||||||
{
|
{
|
||||||
info = info->nestedIn;
|
scope = scope->nestedIn;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if in class or structure
|
// check if in class or structure
|
||||||
else if (info->type == Scope::eClass || info->type == Scope::eStruct)
|
else if (scope->type == Scope::eClass || scope->type == Scope::eStruct)
|
||||||
{
|
{
|
||||||
const Token *funcStart = 0;
|
const Token *funcStart = 0;
|
||||||
const Token *argStart = 0;
|
const Token *argStart = 0;
|
||||||
|
|
||||||
// What section are we in..
|
// What section are we in..
|
||||||
if (tok->str() == "private:")
|
if (tok->str() == "private:")
|
||||||
info->access = Private;
|
scope->access = Private;
|
||||||
else if (tok->str() == "protected:")
|
else if (tok->str() == "protected:")
|
||||||
info->access = Protected;
|
scope->access = Protected;
|
||||||
else if (tok->str() == "public:")
|
else if (tok->str() == "public:")
|
||||||
info->access = Public;
|
scope->access = Public;
|
||||||
else if (Token::Match(tok, "public|protected|private %var% :"))
|
else if (Token::Match(tok, "public|protected|private %var% :"))
|
||||||
{
|
{
|
||||||
if (tok->str() == "private")
|
if (tok->str() == "private")
|
||||||
info->access = Private;
|
scope->access = Private;
|
||||||
else if (tok->str() == "protected")
|
else if (tok->str() == "protected")
|
||||||
info->access = Protected;
|
scope->access = Protected;
|
||||||
else if (tok->str() == "public")
|
else if (tok->str() == "public")
|
||||||
info->access = Public;
|
scope->access = Public;
|
||||||
|
|
||||||
tok = tok->tokAt(2);
|
tok = tok->tokAt(2);
|
||||||
}
|
}
|
||||||
|
@ -131,7 +131,7 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
|
||||||
function.argDef = argStart;
|
function.argDef = argStart;
|
||||||
|
|
||||||
// save the access type
|
// save the access type
|
||||||
function.access = info->access;
|
function.access = scope->access;
|
||||||
|
|
||||||
// save the function name location
|
// save the function name location
|
||||||
function.tokenDef = funcStart;
|
function.tokenDef = funcStart;
|
||||||
|
@ -147,13 +147,13 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
|
||||||
}
|
}
|
||||||
|
|
||||||
// class constructor/destructor
|
// class constructor/destructor
|
||||||
else if (function.tokenDef->str() == info->className)
|
else if (function.tokenDef->str() == scope->className)
|
||||||
{
|
{
|
||||||
if (function.tokenDef->previous()->str() == "~")
|
if (function.tokenDef->previous()->str() == "~")
|
||||||
function.type = Function::eDestructor;
|
function.type = Function::eDestructor;
|
||||||
else if ((Token::Match(function.tokenDef, "%var% ( const %var% & )") ||
|
else if ((Token::Match(function.tokenDef, "%var% ( const %var% & )") ||
|
||||||
Token::Match(function.tokenDef, "%var% ( const %var% & %var% )")) &&
|
Token::Match(function.tokenDef, "%var% ( const %var% & %var% )")) &&
|
||||||
function.tokenDef->strAt(3) == info->className)
|
function.tokenDef->strAt(3) == scope->className)
|
||||||
function.type = Function::eCopyConstructor;
|
function.type = Function::eCopyConstructor;
|
||||||
else
|
else
|
||||||
function.type = Function::eConstructor;
|
function.type = Function::eConstructor;
|
||||||
|
@ -214,7 +214,7 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
|
||||||
|
|
||||||
// count the number of constructors
|
// count the number of constructors
|
||||||
if (function.type == Function::eConstructor || function.type == Function::eCopyConstructor)
|
if (function.type == Function::eConstructor || function.type == Function::eCopyConstructor)
|
||||||
info->numConstructors++;
|
scope->numConstructors++;
|
||||||
|
|
||||||
// assume implementation is inline (definition and implementation same)
|
// assume implementation is inline (definition and implementation same)
|
||||||
function.token = function.tokenDef;
|
function.token = function.tokenDef;
|
||||||
|
@ -226,7 +226,7 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
|
||||||
// find the function implementation later
|
// find the function implementation later
|
||||||
tok = end->next();
|
tok = end->next();
|
||||||
|
|
||||||
info->functionList.push_back(function);
|
scope->functionList.push_back(function);
|
||||||
}
|
}
|
||||||
|
|
||||||
// inline function
|
// inline function
|
||||||
|
@ -236,14 +236,14 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
|
||||||
function.hasBody = true;
|
function.hasBody = true;
|
||||||
function.arg = function.argDef;
|
function.arg = function.argDef;
|
||||||
|
|
||||||
info->functionList.push_back(function);
|
scope->functionList.push_back(function);
|
||||||
|
|
||||||
const Token *tok2 = funcStart;
|
const Token *tok2 = funcStart;
|
||||||
Scope *functionOf = info;
|
Scope *functionOf = scope;
|
||||||
|
|
||||||
addNewFunction(&info, &tok2);
|
addNewFunction(&scope, &tok2);
|
||||||
if (info)
|
if (scope)
|
||||||
info->functionOf = functionOf;
|
scope->functionOf = functionOf;
|
||||||
|
|
||||||
tok = tok2;
|
tok = tok2;
|
||||||
}
|
}
|
||||||
|
@ -251,7 +251,7 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
|
||||||
|
|
||||||
// nested class function?
|
// nested class function?
|
||||||
else if (tok->previous()->str() == "::" && isFunction(tok, &funcStart, &argStart))
|
else if (tok->previous()->str() == "::" && isFunction(tok, &funcStart, &argStart))
|
||||||
addFunction(&info, &tok, argStart);
|
addFunction(&scope, &tok, argStart);
|
||||||
|
|
||||||
// friend class declaration?
|
// friend class declaration?
|
||||||
else if (Token::Match(tok, "friend class| %any% ;"))
|
else if (Token::Match(tok, "friend class| %any% ;"))
|
||||||
|
@ -260,12 +260,12 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
|
||||||
|
|
||||||
friendInfo.name = tok->strAt(1) == "class" ? tok->strAt(2) : tok->strAt(1);
|
friendInfo.name = tok->strAt(1) == "class" ? tok->strAt(2) : tok->strAt(1);
|
||||||
/** @todo fill this in later after parsing is complete */
|
/** @todo fill this in later after parsing is complete */
|
||||||
friendInfo.spaceInfo = 0;
|
friendInfo.scope = 0;
|
||||||
|
|
||||||
info->friendList.push_back(friendInfo);
|
scope->friendList.push_back(friendInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (info->type == Scope::eNamespace || info->type == Scope::eGlobal)
|
else if (scope->type == Scope::eNamespace || scope->type == Scope::eGlobal)
|
||||||
{
|
{
|
||||||
const Token *funcStart = 0;
|
const Token *funcStart = 0;
|
||||||
const Token *argStart = 0;
|
const Token *argStart = 0;
|
||||||
|
@ -278,12 +278,12 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
|
||||||
{
|
{
|
||||||
// class function
|
// class function
|
||||||
if (tok->previous() && tok->previous()->str() == "::")
|
if (tok->previous() && tok->previous()->str() == "::")
|
||||||
addFunction(&info, &tok, argStart);
|
addFunction(&scope, &tok, argStart);
|
||||||
|
|
||||||
// class destructor
|
// class destructor
|
||||||
else if (tok->previous() && tok->previous()->str() == "~" &&
|
else if (tok->previous() && tok->previous()->str() == "~" &&
|
||||||
tok->previous()->previous() && tok->previous()->previous()->str() == "::")
|
tok->previous()->previous() && tok->previous()->previous()->str() == "::")
|
||||||
addFunction(&info, &tok, argStart);
|
addFunction(&scope, &tok, argStart);
|
||||||
|
|
||||||
// regular function
|
// regular function
|
||||||
else
|
else
|
||||||
|
@ -305,17 +305,17 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
|
||||||
function.arg = function.argDef;
|
function.arg = function.argDef;
|
||||||
function.type = Function::eFunction;
|
function.type = Function::eFunction;
|
||||||
|
|
||||||
Scope *old_info = info;
|
Scope *old_scope = scope;
|
||||||
|
|
||||||
addNewFunction(&info, &tok);
|
addNewFunction(&scope, &tok);
|
||||||
|
|
||||||
if (info)
|
if (scope)
|
||||||
old_info->functionList.push_back(function);
|
old_scope->functionList.push_back(function);
|
||||||
|
|
||||||
// syntax error
|
// syntax error
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
info = old_info;
|
scope = old_scope;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -326,19 +326,19 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
|
||||||
Token::Match(argStart->link()->tokAt(2)->link(), ") const| {"))
|
Token::Match(argStart->link()->tokAt(2)->link(), ") const| {"))
|
||||||
{
|
{
|
||||||
const Token *tok1 = funcStart;
|
const Token *tok1 = funcStart;
|
||||||
Scope *old_info = info;
|
Scope *old_scope = scope;
|
||||||
|
|
||||||
// class function
|
// class function
|
||||||
if (tok1->previous()->str() == "::")
|
if (tok1->previous()->str() == "::")
|
||||||
addFunction(&info, &tok1, argStart);
|
addFunction(&scope, &tok1, argStart);
|
||||||
|
|
||||||
// regular function
|
// regular function
|
||||||
else
|
else
|
||||||
addNewFunction(&info, &tok1);
|
addNewFunction(&scope, &tok1);
|
||||||
|
|
||||||
// syntax error?
|
// syntax error?
|
||||||
if (!info)
|
if (!scope)
|
||||||
info = old_info;
|
scope = old_scope;
|
||||||
|
|
||||||
tok = tok1;
|
tok = tok1;
|
||||||
}
|
}
|
||||||
|
@ -350,36 +350,36 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
|
||||||
std::list<Scope *>::iterator it;
|
std::list<Scope *>::iterator it;
|
||||||
|
|
||||||
// fill in base class info
|
// fill in base class info
|
||||||
for (it = spaceInfoList.begin(); it != spaceInfoList.end(); ++it)
|
for (it = scopeList.begin(); it != scopeList.end(); ++it)
|
||||||
{
|
{
|
||||||
info = *it;
|
scope = *it;
|
||||||
|
|
||||||
// skip namespaces and functions
|
// skip namespaces and functions
|
||||||
if (!info->isClassOrStruct())
|
if (!scope->isClassOrStruct())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// finish filling in base class info
|
// finish filling in base class info
|
||||||
for (unsigned int i = 0; i < info->derivedFrom.size(); ++i)
|
for (unsigned int i = 0; i < scope->derivedFrom.size(); ++i)
|
||||||
{
|
{
|
||||||
std::list<Scope *>::iterator it1;
|
std::list<Scope *>::iterator it1;
|
||||||
|
|
||||||
for (it1 = spaceInfoList.begin(); it1 != spaceInfoList.end(); ++it1)
|
for (it1 = scopeList.begin(); it1 != scopeList.end(); ++it1)
|
||||||
{
|
{
|
||||||
Scope *spaceInfo = *it1;
|
Scope *scope1 = *it1;
|
||||||
|
|
||||||
/** @todo handle derived base classes and namespaces */
|
/** @todo handle derived base classes and namespaces */
|
||||||
if (spaceInfo->type == Scope::eClass || spaceInfo->type == Scope::eStruct)
|
if (scope1->type == Scope::eClass || scope1->type == Scope::eStruct)
|
||||||
{
|
{
|
||||||
// do class names match?
|
// do class names match?
|
||||||
if (spaceInfo->className == info->derivedFrom[i].name)
|
if (scope1->className == scope->derivedFrom[i].name)
|
||||||
{
|
{
|
||||||
// are they in the same namespace or different namespaces with same name?
|
// are they in the same namespace or different namespaces with same name?
|
||||||
if ((spaceInfo->nestedIn == info->nestedIn) ||
|
if ((scope1->nestedIn == scope->nestedIn) ||
|
||||||
((spaceInfo->nestedIn && spaceInfo->nestedIn->type == Scope::eNamespace) &&
|
((scope1->nestedIn && scope1->nestedIn->type == Scope::eNamespace) &&
|
||||||
(info->nestedIn && info->nestedIn->type == Scope::eNamespace) &&
|
(scope->nestedIn && scope->nestedIn->type == Scope::eNamespace) &&
|
||||||
(spaceInfo->nestedIn->className == info->nestedIn->className)))
|
(scope1->nestedIn->className == scope->nestedIn->className)))
|
||||||
{
|
{
|
||||||
info->derivedFrom[i].spaceInfo = spaceInfo;
|
scope->derivedFrom[i].scope = scope1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -389,15 +389,15 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
|
||||||
}
|
}
|
||||||
|
|
||||||
// fill in variable info
|
// fill in variable info
|
||||||
for (it = spaceInfoList.begin(); it != spaceInfoList.end(); ++it)
|
for (it = scopeList.begin(); it != scopeList.end(); ++it)
|
||||||
{
|
{
|
||||||
info = *it;
|
scope = *it;
|
||||||
|
|
||||||
// skip functions
|
// skip functions
|
||||||
if (info->type != Scope::eFunction)
|
if (scope->type != Scope::eFunction)
|
||||||
{
|
{
|
||||||
// find variables
|
// find variables
|
||||||
info->getVariableList();
|
scope->getVariableList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -409,18 +409,18 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
|
||||||
{
|
{
|
||||||
unknowns = 0;
|
unknowns = 0;
|
||||||
|
|
||||||
for (it = spaceInfoList.begin(); it != spaceInfoList.end(); ++it)
|
for (it = scopeList.begin(); it != scopeList.end(); ++it)
|
||||||
{
|
{
|
||||||
info = *it;
|
scope = *it;
|
||||||
|
|
||||||
if (info->isClassOrStruct() && info->needInitialization == Scope::Unknown)
|
if (scope->isClassOrStruct() && scope->needInitialization == Scope::Unknown)
|
||||||
{
|
{
|
||||||
// check for default constructor
|
// check for default constructor
|
||||||
bool hasDefaultConstructor = false;
|
bool hasDefaultConstructor = false;
|
||||||
|
|
||||||
std::list<Function>::const_iterator func;
|
std::list<Function>::const_iterator func;
|
||||||
|
|
||||||
for (func = info->functionList.begin(); func != info->functionList.end(); ++func)
|
for (func = scope->functionList.begin(); func != scope->functionList.end(); ++func)
|
||||||
{
|
{
|
||||||
if (func->type == Function::eConstructor)
|
if (func->type == Function::eConstructor)
|
||||||
{
|
{
|
||||||
|
@ -444,7 +444,7 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
|
||||||
// We assume the default constructor initializes everything.
|
// We assume the default constructor initializes everything.
|
||||||
// Another check will figure out if the constructor actually initializes everything.
|
// Another check will figure out if the constructor actually initializes everything.
|
||||||
if (hasDefaultConstructor)
|
if (hasDefaultConstructor)
|
||||||
info->needInitialization = Scope::False;
|
scope->needInitialization = Scope::False;
|
||||||
|
|
||||||
// check each member variable to see if it needs initialization
|
// check each member variable to see if it needs initialization
|
||||||
else
|
else
|
||||||
|
@ -453,7 +453,7 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
|
||||||
bool unknown = false;
|
bool unknown = false;
|
||||||
|
|
||||||
std::list<Variable>::const_iterator var;
|
std::list<Variable>::const_iterator var;
|
||||||
for (var = info->varlist.begin(); var != info->varlist.end(); ++var)
|
for (var = scope->varlist.begin(); var != scope->varlist.end(); ++var)
|
||||||
{
|
{
|
||||||
if (var->isClass())
|
if (var->isClass())
|
||||||
{
|
{
|
||||||
|
@ -473,12 +473,12 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
|
||||||
if (!unknown)
|
if (!unknown)
|
||||||
{
|
{
|
||||||
if (needInitialization)
|
if (needInitialization)
|
||||||
info->needInitialization = Scope::True;
|
scope->needInitialization = Scope::True;
|
||||||
else
|
else
|
||||||
info->needInitialization = Scope::False;
|
scope->needInitialization = Scope::False;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (info->needInitialization == Scope::Unknown)
|
if (scope->needInitialization == Scope::Unknown)
|
||||||
unknowns++;
|
unknowns++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -491,16 +491,16 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
|
||||||
// this shouldn't happen so output a debug warning
|
// this shouldn't happen so output a debug warning
|
||||||
if (retry == 100 && _settings->debugwarnings)
|
if (retry == 100 && _settings->debugwarnings)
|
||||||
{
|
{
|
||||||
for (it = spaceInfoList.begin(); it != spaceInfoList.end(); ++it)
|
for (it = scopeList.begin(); it != scopeList.end(); ++it)
|
||||||
{
|
{
|
||||||
info = *it;
|
scope = *it;
|
||||||
|
|
||||||
if (info->isClassOrStruct() && info->needInitialization == Scope::Unknown)
|
if (scope->isClassOrStruct() && scope->needInitialization == Scope::Unknown)
|
||||||
{
|
{
|
||||||
std::list<ErrorLogger::ErrorMessage::FileLocation> locationList;
|
std::list<ErrorLogger::ErrorMessage::FileLocation> locationList;
|
||||||
ErrorLogger::ErrorMessage::FileLocation loc;
|
ErrorLogger::ErrorMessage::FileLocation loc;
|
||||||
loc.line = info->classDef->linenr();
|
loc.line = scope->classDef->linenr();
|
||||||
loc.setfile(_tokenizer->file(info->classDef));
|
loc.setfile(_tokenizer->file(scope->classDef));
|
||||||
locationList.push_back(loc);
|
locationList.push_back(loc);
|
||||||
|
|
||||||
const ErrorLogger::ErrorMessage errmsg(locationList,
|
const ErrorLogger::ErrorMessage errmsg(locationList,
|
||||||
|
@ -520,7 +520,7 @@ SymbolDatabase::~SymbolDatabase()
|
||||||
{
|
{
|
||||||
std::list<Scope *>::iterator it;
|
std::list<Scope *>::iterator it;
|
||||||
|
|
||||||
for (it = spaceInfoList.begin(); it != spaceInfoList.end(); ++it)
|
for (it = scopeList.begin(); it != scopeList.end(); ++it)
|
||||||
delete *it;
|
delete *it;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -582,7 +582,7 @@ bool SymbolDatabase::isFunction(const Token *tok, const Token **funcStart, const
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SymbolDatabase::argsMatch(const Scope *info, const Token *first, const Token *second, const std::string &path, unsigned int depth) const
|
bool SymbolDatabase::argsMatch(const Scope *scope, const Token *first, const Token *second, const std::string &path, unsigned int depth) const
|
||||||
{
|
{
|
||||||
bool match = false;
|
bool match = false;
|
||||||
while (first->str() == second->str())
|
while (first->str() == second->str())
|
||||||
|
@ -658,7 +658,7 @@ bool SymbolDatabase::argsMatch(const Scope *info, const Token *first, const Toke
|
||||||
|
|
||||||
// nested class variable
|
// nested class variable
|
||||||
else if (depth == 0 && Token::Match(first->next(), "%var%") &&
|
else if (depth == 0 && Token::Match(first->next(), "%var%") &&
|
||||||
second->next()->str() == info->className && second->strAt(2) == "::" &&
|
second->next()->str() == scope->className && second->strAt(2) == "::" &&
|
||||||
first->next()->str() == second->strAt(3))
|
first->next()->str() == second->strAt(3))
|
||||||
{
|
{
|
||||||
second = second->tokAt(2);
|
second = second->tokAt(2);
|
||||||
|
@ -671,7 +671,7 @@ bool SymbolDatabase::argsMatch(const Scope *info, const Token *first, const Toke
|
||||||
return match;
|
return match;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SymbolDatabase::addFunction(Scope **info, const Token **tok, const Token *argStart)
|
void SymbolDatabase::addFunction(Scope **scope, const Token **tok, const Token *argStart)
|
||||||
{
|
{
|
||||||
int count = 0;
|
int count = 0;
|
||||||
bool added = false;
|
bool added = false;
|
||||||
|
@ -703,32 +703,32 @@ void SymbolDatabase::addFunction(Scope **info, const Token **tok, const Token *a
|
||||||
std::list<Scope *>::iterator it1;
|
std::list<Scope *>::iterator it1;
|
||||||
|
|
||||||
// search for match
|
// search for match
|
||||||
for (it1 = spaceInfoList.begin(); it1 != spaceInfoList.end(); ++it1)
|
for (it1 = scopeList.begin(); it1 != scopeList.end(); ++it1)
|
||||||
{
|
{
|
||||||
Scope *info1 = *it1;
|
Scope *scope1 = *it1;
|
||||||
|
|
||||||
bool match = false;
|
bool match = false;
|
||||||
if (info1->className == tok1->str() && (info1->type != Scope::eFunction))
|
if (scope1->className == tok1->str() && (scope1->type != Scope::eFunction))
|
||||||
{
|
{
|
||||||
// do the spaces match (same space) or do their names match (multiple namespaces)
|
// do the spaces match (same space) or do their names match (multiple namespaces)
|
||||||
if ((*info == info1->nestedIn) || (*info && info1 &&
|
if ((*scope == scope1->nestedIn) || (*scope && scope1 &&
|
||||||
(*info)->className == info1->nestedIn->className &&
|
(*scope)->className == scope1->nestedIn->className &&
|
||||||
!(*info)->className.empty() &&
|
!(*scope)->className.empty() &&
|
||||||
(*info)->type == info1->nestedIn->type))
|
(*scope)->type == scope1->nestedIn->type))
|
||||||
{
|
{
|
||||||
Scope *info2 = info1;
|
Scope *scope2 = scope1;
|
||||||
|
|
||||||
while (info2 && count > 0)
|
while (scope2 && count > 0)
|
||||||
{
|
{
|
||||||
count--;
|
count--;
|
||||||
tok1 = tok1->tokAt(2);
|
tok1 = tok1->tokAt(2);
|
||||||
info2 = info2->findInNestedList(tok1->str());
|
scope2 = scope2->findInNestedList(tok1->str());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count == 0 && info2)
|
if (count == 0 && scope2)
|
||||||
{
|
{
|
||||||
match = true;
|
match = true;
|
||||||
info1 = info2;
|
scope1 = scope2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -737,7 +737,7 @@ void SymbolDatabase::addFunction(Scope **info, const Token **tok, const Token *a
|
||||||
{
|
{
|
||||||
std::list<Function>::iterator func;
|
std::list<Function>::iterator func;
|
||||||
|
|
||||||
for (func = info1->functionList.begin(); func != info1->functionList.end(); ++func)
|
for (func = scope1->functionList.begin(); func != scope1->functionList.end(); ++func)
|
||||||
{
|
{
|
||||||
if (!func->hasBody)
|
if (!func->hasBody)
|
||||||
{
|
{
|
||||||
|
@ -745,7 +745,7 @@ void SymbolDatabase::addFunction(Scope **info, const Token **tok, const Token *a
|
||||||
(*tok)->str() == "operator" &&
|
(*tok)->str() == "operator" &&
|
||||||
func->tokenDef->str() == (*tok)->strAt(1))
|
func->tokenDef->str() == (*tok)->strAt(1))
|
||||||
{
|
{
|
||||||
if (argsMatch(info1, func->tokenDef->tokAt(2), (*tok)->tokAt(3), path, path_length))
|
if (argsMatch(scope1, func->tokenDef->tokAt(2), (*tok)->tokAt(3), path, path_length))
|
||||||
{
|
{
|
||||||
func->hasBody = true;
|
func->hasBody = true;
|
||||||
func->token = (*tok)->next();
|
func->token = (*tok)->next();
|
||||||
|
@ -756,7 +756,7 @@ void SymbolDatabase::addFunction(Scope **info, const Token **tok, const Token *a
|
||||||
(*tok)->previous()->str() == "~" &&
|
(*tok)->previous()->str() == "~" &&
|
||||||
func->tokenDef->str() == (*tok)->str())
|
func->tokenDef->str() == (*tok)->str())
|
||||||
{
|
{
|
||||||
if (argsMatch(info1, func->tokenDef->next(), (*tok)->next(), path, path_length))
|
if (argsMatch(scope1, func->tokenDef->next(), (*tok)->next(), path, path_length))
|
||||||
{
|
{
|
||||||
func->hasBody = true;
|
func->hasBody = true;
|
||||||
func->token = *tok;
|
func->token = *tok;
|
||||||
|
@ -765,7 +765,7 @@ void SymbolDatabase::addFunction(Scope **info, const Token **tok, const Token *a
|
||||||
}
|
}
|
||||||
else if (func->tokenDef->str() == (*tok)->str() && (*tok)->previous()->str() != "~")
|
else if (func->tokenDef->str() == (*tok)->str() && (*tok)->previous()->str() != "~")
|
||||||
{
|
{
|
||||||
if (argsMatch(info1, func->tokenDef->next(), (*tok)->next(), path, path_length))
|
if (argsMatch(scope1, func->tokenDef->next(), (*tok)->next(), path, path_length))
|
||||||
{
|
{
|
||||||
// normal function?
|
// normal function?
|
||||||
if (!func->retFuncPtr && (*tok)->next()->link())
|
if (!func->retFuncPtr && (*tok)->next()->link())
|
||||||
|
@ -792,10 +792,10 @@ void SymbolDatabase::addFunction(Scope **info, const Token **tok, const Token *a
|
||||||
|
|
||||||
if (func->hasBody)
|
if (func->hasBody)
|
||||||
{
|
{
|
||||||
addNewFunction(info, tok);
|
addNewFunction(scope, tok);
|
||||||
if (info)
|
if (scope)
|
||||||
{
|
{
|
||||||
(*info)->functionOf = info1;
|
(*scope)->functionOf = scope1;
|
||||||
added = true;
|
added = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -807,13 +807,13 @@ void SymbolDatabase::addFunction(Scope **info, const Token **tok, const Token *a
|
||||||
|
|
||||||
// check for class function for unknown class
|
// check for class function for unknown class
|
||||||
if (!added)
|
if (!added)
|
||||||
addNewFunction(info, tok);
|
addNewFunction(scope, tok);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SymbolDatabase::addNewFunction(Scope **info, const Token **tok)
|
void SymbolDatabase::addNewFunction(Scope **scope, const Token **tok)
|
||||||
{
|
{
|
||||||
const Token *tok1 = *tok;
|
const Token *tok1 = *tok;
|
||||||
Scope *new_info = new Scope(this, tok1, *info);
|
Scope *new_scope = new Scope(this, tok1, *scope);
|
||||||
|
|
||||||
// skip to start of function
|
// skip to start of function
|
||||||
while (tok1 && tok1->str() != "{")
|
while (tok1 && tok1->str() != "{")
|
||||||
|
@ -821,30 +821,30 @@ void SymbolDatabase::addNewFunction(Scope **info, const Token **tok)
|
||||||
|
|
||||||
if (tok1)
|
if (tok1)
|
||||||
{
|
{
|
||||||
new_info->classStart = tok1;
|
new_scope->classStart = tok1;
|
||||||
new_info->classEnd = tok1->link();
|
new_scope->classEnd = tok1->link();
|
||||||
|
|
||||||
// syntax error?
|
// syntax error?
|
||||||
if (!new_info->classEnd)
|
if (!new_scope->classEnd)
|
||||||
{
|
{
|
||||||
delete new_info;
|
delete new_scope;
|
||||||
while (tok1->next())
|
while (tok1->next())
|
||||||
tok1 = tok1->next();
|
tok1 = tok1->next();
|
||||||
*info = NULL;
|
*scope = NULL;
|
||||||
*tok = tok1;
|
*tok = tok1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
*info = new_info;
|
*scope = new_scope;
|
||||||
|
|
||||||
// add space
|
// add space
|
||||||
spaceInfoList.push_back(new_info);
|
scopeList.push_back(new_scope);
|
||||||
|
|
||||||
*tok = tok1;
|
*tok = tok1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const Token *SymbolDatabase::initBaseInfo(Scope *info, const Token *tok)
|
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);
|
||||||
|
@ -896,7 +896,7 @@ const Token *SymbolDatabase::initBaseInfo(Scope *info, const Token *tok)
|
||||||
}
|
}
|
||||||
|
|
||||||
base.name += tok2->str();
|
base.name += tok2->str();
|
||||||
base.spaceInfo = 0;
|
base.scope = 0;
|
||||||
|
|
||||||
// don't add unhandled templates
|
// don't add unhandled templates
|
||||||
if (tok2->next()->str() == "<")
|
if (tok2->next()->str() == "<")
|
||||||
|
@ -920,7 +920,7 @@ const Token *SymbolDatabase::initBaseInfo(Scope *info, const Token *tok)
|
||||||
// save pattern for base class name
|
// save pattern for base class name
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
info->derivedFrom.push_back(base);
|
scope->derivedFrom.push_back(base);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tok2 = tok2->next();
|
tok2 = tok2->next();
|
||||||
|
@ -1199,12 +1199,12 @@ void Scope::getVariableList()
|
||||||
Check::reportError(errmsg);
|
Check::reportError(errmsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
const Scope *spaceInfo = NULL;
|
const Scope *scope = NULL;
|
||||||
|
|
||||||
if (typetok)
|
if (typetok)
|
||||||
spaceInfo = check->findVariableType(this, typetok);
|
scope = check->findVariableType(this, typetok);
|
||||||
|
|
||||||
addVariable(vartok, varaccess, isMutable, isStatic, isConst, isClass, spaceInfo);
|
addVariable(vartok, varaccess, isMutable, isStatic, isConst, isClass, scope);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1314,16 +1314,16 @@ const Scope *SymbolDatabase::findVariableType(const Scope *start, const Token *t
|
||||||
{
|
{
|
||||||
std::list<Scope *>::const_iterator it;
|
std::list<Scope *>::const_iterator it;
|
||||||
|
|
||||||
for (it = spaceInfoList.begin(); it != spaceInfoList.end(); ++it)
|
for (it = scopeList.begin(); it != scopeList.end(); ++it)
|
||||||
{
|
{
|
||||||
const Scope *info = *it;
|
const Scope *scope = *it;
|
||||||
|
|
||||||
// skip namespaces and functions
|
// skip namespaces and functions
|
||||||
if (info->type == Scope::eNamespace || info->type == Scope::eFunction || info->type == Scope::eGlobal)
|
if (scope->type == Scope::eNamespace || scope->type == Scope::eFunction || scope->type == Scope::eGlobal)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// do the names match?
|
// do the names match?
|
||||||
if (info->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()->str() != "::")
|
if (type->previous()->str() != "::")
|
||||||
|
@ -1331,18 +1331,18 @@ const Scope *SymbolDatabase::findVariableType(const Scope *start, const Token *t
|
||||||
const Scope *parent = start;
|
const Scope *parent = start;
|
||||||
|
|
||||||
// check if in same namespace
|
// check if in same namespace
|
||||||
while (parent && parent != info->nestedIn)
|
while (parent && parent != scope->nestedIn)
|
||||||
parent = parent->nestedIn;
|
parent = parent->nestedIn;
|
||||||
|
|
||||||
if (info->nestedIn == parent)
|
if (scope->nestedIn == parent)
|
||||||
return info;
|
return scope;
|
||||||
}
|
}
|
||||||
|
|
||||||
// type has a namespace
|
// type has a namespace
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// FIXME check if namespace path matches supplied path
|
// FIXME check if namespace path matches supplied path
|
||||||
return info;
|
return scope;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -269,22 +269,22 @@ public:
|
||||||
{
|
{
|
||||||
AccessControl access; // public/protected/private
|
AccessControl access; // public/protected/private
|
||||||
std::string name;
|
std::string name;
|
||||||
Scope *spaceInfo;
|
Scope *scope;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct FriendInfo
|
struct FriendInfo
|
||||||
{
|
{
|
||||||
std::string name;
|
std::string name;
|
||||||
Scope *spaceInfo;
|
Scope *scope;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum SpaceType { eGlobal, eClass, eStruct, eUnion, eNamespace, eFunction };
|
enum ScopeType { eGlobal, eClass, eStruct, eUnion, eNamespace, eFunction };
|
||||||
enum NeedInitialization { Unknown, True, False };
|
enum NeedInitialization { Unknown, True, False };
|
||||||
|
|
||||||
Scope(SymbolDatabase *check_, const Token *classDef_, Scope *nestedIn_);
|
Scope(SymbolDatabase *check_, const Token *classDef_, Scope *nestedIn_);
|
||||||
|
|
||||||
SymbolDatabase *check;
|
SymbolDatabase *check;
|
||||||
SpaceType type;
|
ScopeType type;
|
||||||
std::string className;
|
std::string className;
|
||||||
const Token *classDef; // class/struct/union/namespace token
|
const Token *classDef; // class/struct/union/namespace token
|
||||||
const Token *classStart; // '{' token
|
const Token *classStart; // '{' token
|
||||||
|
@ -307,7 +307,7 @@ public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief find if name is in nested list
|
* @brief find if name is in nested list
|
||||||
* @param name name of nested space
|
* @param name name of nested scope
|
||||||
*/
|
*/
|
||||||
Scope * findInNestedList(const std::string & name);
|
Scope * findInNestedList(const std::string & name);
|
||||||
|
|
||||||
|
@ -322,7 +322,7 @@ public:
|
||||||
const Function *getDestructor() const;
|
const Function *getDestructor() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief get the number of nested spaces that are not functions
|
* @brief get the number of nested scopes that are not functions
|
||||||
*
|
*
|
||||||
* This returns the number of user defined types (class, struct, union)
|
* This returns the number of user defined types (class, struct, union)
|
||||||
* that are defined in this user defined type or namespace.
|
* that are defined in this user defined type or namespace.
|
||||||
|
@ -352,7 +352,7 @@ public:
|
||||||
~SymbolDatabase();
|
~SymbolDatabase();
|
||||||
|
|
||||||
/** @brief Information about all namespaces/classes/structrues */
|
/** @brief Information about all namespaces/classes/structrues */
|
||||||
std::list<Scope *> spaceInfoList;
|
std::list<Scope *> scopeList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief find a variable type if it's a user defined type
|
* @brief find a variable type if it's a user defined type
|
||||||
|
|
|
@ -7955,7 +7955,7 @@ const Token *Tokenizer::getFunctionTokenByName(const char funcname[]) const
|
||||||
|
|
||||||
std::list<Scope *>::const_iterator i;
|
std::list<Scope *>::const_iterator i;
|
||||||
|
|
||||||
for (i = _symbolDatabase->spaceInfoList.begin(); i != _symbolDatabase->spaceInfoList.end(); ++i)
|
for (i = _symbolDatabase->scopeList.begin(); i != _symbolDatabase->scopeList.end(); ++i)
|
||||||
{
|
{
|
||||||
const Scope *scope = *i;
|
const Scope *scope = *i;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue