- 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;
}
@ -682,7 +682,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
return true;
}
void CmdLineParser::PrintHelp()
void CmdLineParser::PrintHelp() const
{
std::cout << "Cppcheck - A tool for static C/C++ code analysis\n"
"\n"

View File

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

View File

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

View File

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

View File

@ -81,7 +81,7 @@ public:
void clear() {
_varUsage.clear();
}
const VariableMap &varUsage() {
const VariableMap &varUsage() const {
return _varUsage;
}
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);
if (scope)
if (scope) {
old_scope->functionList.push_back(function);
scope->function = &old_scope->functionList.back();
}
}
// syntax error
@ -461,8 +463,10 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
addNewFunction(&scope, &tok1);
if (scope)
if (scope) {
old_scope->functionList.push_back(function);
scope->function = &old_scope->functionList.back();
}
}
// 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]));
} catch (InternalError &e) {
e.token = tok;
throw e;
throw;
}
}

View File

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

View File

@ -61,7 +61,6 @@ protected:
public:
virtual void reportOut(const std::string &outmsg);
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);
TestFixture(const std::string &_name);

View File

@ -677,6 +677,10 @@ private:
}
}
ASSERT(scope != 0);
if (!scope)
return;
ASSERT_EQUALS("X", scope->className);
// 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);
// The class has a constructor and the implementation _is_ seen