- Correctly set Scope::function variable in symboldatabase

- Refactorizations
- Fixed some cppcheck warnings
This commit is contained in:
PKEuS 2012-01-21 10:08:09 +01:00
parent 2a2d01a870
commit 96ae010e48
10 changed files with 24 additions and 23 deletions

View File

@ -90,7 +90,7 @@ CmdLineParser::CmdLineParser(Settings *settings)
{ {
} }
void CmdLineParser::PrintMessage(const std::string &message) void CmdLineParser::PrintMessage(const std::string &message) const
{ {
std::cout << message << std::endl; std::cout << message << std::endl;
} }
@ -682,7 +682,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
return true; return true;
} }
void CmdLineParser::PrintHelp() void CmdLineParser::PrintHelp() const
{ {
std::cout << "Cppcheck - A tool for static C/C++ code analysis\n" std::cout << "Cppcheck - A tool for static C/C++ code analysis\n"
"\n" "\n"

View File

@ -98,12 +98,12 @@ protected:
/** /**
* Print help text to the console. * Print help text to the console.
*/ */
void PrintHelp(); void PrintHelp() const;
/** /**
* Print message (to console?). * Print message (to console?).
*/ */
void PrintMessage(const std::string &message); void PrintMessage(const std::string &message) const;
private: private:
Settings *_settings; Settings *_settings;

View File

@ -637,16 +637,9 @@ void CheckClass::noMemset()
std::list<Scope>::const_iterator scope; std::list<Scope>::const_iterator scope;
for (scope = symbolDatabase->scopeList.begin(); scope != symbolDatabase->scopeList.end(); ++scope) { for (scope = symbolDatabase->scopeList.begin(); scope != symbolDatabase->scopeList.end(); ++scope) {
std::list<Function>::const_iterator func; if (scope->type == Scope::eFunction) {
for (func = scope->functionList.begin(); func != scope->functionList.end(); ++func) {
// only check functions with bodies
if (!func->hasBody)
continue;
// Locate all 'memset' tokens.. // Locate all 'memset' tokens..
const Token *end = func->start->link(); for (const Token *tok = scope->classStart; tok && tok != scope->classEnd; tok = tok->next()) {
for (const Token *tok = func->start; tok && tok != end; tok = tok->next()) {
if (!Token::Match(tok, "memset|memcpy|memmove")) if (!Token::Match(tok, "memset|memcpy|memmove"))
continue; continue;

View File

@ -1922,8 +1922,8 @@ void CheckOther::checkConstantFunctionParameter()
const SymbolDatabase * const symbolDatabase = _tokenizer->getSymbolDatabase(); const SymbolDatabase * const symbolDatabase = _tokenizer->getSymbolDatabase();
for (std::list<Scope>::const_iterator i = symbolDatabase->scopeList.begin(); i != symbolDatabase->scopeList.end(); ++i) { for (std::list<Scope>::const_iterator i = symbolDatabase->scopeList.begin(); i != symbolDatabase->scopeList.end(); ++i) {
for (std::list<Function>::const_iterator j = i->functionList.begin(); j != i->functionList.end(); ++j) { if (i->type == Scope::eFunction && i->function) {
for (const Token* tok = j->arg->next(); tok; tok = tok->nextArgument()) { for (const Token* tok = i->function->arg->next(); tok; tok = tok->nextArgument()) {
// TODO: False negatives. This pattern only checks for string. // TODO: False negatives. This pattern only checks for string.
// Investigate if there are other classes in the std // Investigate if there are other classes in the std
// namespace and add them to the pattern. There are // namespace and add them to the pattern. There are

View File

@ -81,7 +81,7 @@ public:
void clear() { void clear() {
_varUsage.clear(); _varUsage.clear();
} }
const VariableMap &varUsage() { const VariableMap &varUsage() const {
return _varUsage; return _varUsage;
} }
void addVar(const Token *name, VariableType type, const Scope *scope, bool write_); void addVar(const Token *name, VariableType type, const Scope *scope, bool write_);

View File

@ -410,8 +410,10 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
addNewFunction(&scope, &tok); addNewFunction(&scope, &tok);
if (scope) if (scope) {
old_scope->functionList.push_back(function); old_scope->functionList.push_back(function);
scope->function = &old_scope->functionList.back();
}
} }
// syntax error // syntax error
@ -461,8 +463,10 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
addNewFunction(&scope, &tok1); addNewFunction(&scope, &tok1);
if (scope) if (scope) {
old_scope->functionList.push_back(function); old_scope->functionList.push_back(function);
scope->function = &old_scope->functionList.back();
}
} }
// syntax error? // syntax error?

View File

@ -917,7 +917,7 @@ bool TemplateSimplifier::simplifyCalculations(Token *_tokens)
tok->str(MathLib::calculate(tok->str(), tok->strAt(2), tok->next()->str()[0])); tok->str(MathLib::calculate(tok->str(), tok->strAt(2), tok->next()->str()[0]));
} catch (InternalError &e) { } catch (InternalError &e) {
e.token = tok; e.token = tok;
throw e; throw;
} }
} }

View File

@ -53,9 +53,6 @@ private:
void reportErr(const ErrorLogger::ErrorMessage &msg) { void reportErr(const ErrorLogger::ErrorMessage &msg) {
id.push_back(msg._id); id.push_back(msg._id);
} }
void reportStatus(unsigned int /*fileindex*/, unsigned int /*filecount*/, long /*sizedone*/, long /*sizetotal*/) {
}
}; };
void run() { void run() {

View File

@ -61,7 +61,6 @@ protected:
public: public:
virtual void reportOut(const std::string &outmsg); virtual void reportOut(const std::string &outmsg);
virtual void reportErr(const ErrorLogger::ErrorMessage &msg); virtual void reportErr(const ErrorLogger::ErrorMessage &msg);
virtual void reportStatus(unsigned int /*fileindex*/, unsigned int /*filecount*/, long /*sizedone*/, long /*sizetotal*/) {}
void run(const std::string &str); void run(const std::string &str);
TestFixture(const std::string &_name); TestFixture(const std::string &_name);

View File

@ -677,6 +677,10 @@ private:
} }
} }
ASSERT(scope != 0);
if (!scope)
return;
ASSERT_EQUALS("X", scope->className); ASSERT_EQUALS("X", scope->className);
// The class has a constructor but the implementation _is not_ seen // The class has a constructor but the implementation _is not_ seen
@ -707,6 +711,10 @@ private:
} }
} }
ASSERT(scope != 0);
if (!scope)
return;
ASSERT_EQUALS("X", scope->className); ASSERT_EQUALS("X", scope->className);
// The class has a constructor and the implementation _is_ seen // The class has a constructor and the implementation _is_ seen