From d93d7401c6c0d9dfe3bad0935fa2f480d7d7ff2a Mon Sep 17 00:00:00 2001 From: PKEuS Date: Wed, 4 Jun 2014 18:00:22 +0200 Subject: [PATCH] Moved getSourceFilePath(), isC() and isCPP() from Tokenizer to TokenList Conflicts: lib/tokenize.cpp --- lib/checkbufferoverrun.cpp | 2 +- lib/checkunusedfunctions.cpp | 6 +++--- lib/cppcheck.cpp | 2 +- lib/symboldatabase.cpp | 2 +- lib/tokenize.cpp | 19 ------------------- lib/tokenize.h | 11 ++++++----- lib/tokenlist.cpp | 21 +++++++++++++++++++++ lib/tokenlist.h | 9 +++++++++ 8 files changed, 42 insertions(+), 30 deletions(-) diff --git a/lib/checkbufferoverrun.cpp b/lib/checkbufferoverrun.cpp index e56c3d4f6..867d89801 100644 --- a/lib/checkbufferoverrun.cpp +++ b/lib/checkbufferoverrun.cpp @@ -1502,7 +1502,7 @@ void CheckBufferOverrun::checkGlobalAndLocalVariable() // nextTok : number of tokens used in variable declaration - used to skip to next statement. int nextTok = 0; - _errorLogger->reportProgress(_tokenizer->getSourceFilePath(), + _errorLogger->reportProgress(_tokenizer->list.getSourceFilePath(), "Check (BufferOverrun::checkGlobalAndLocalVariable)", tok->progressValue()); diff --git a/lib/checkunusedfunctions.cpp b/lib/checkunusedfunctions.cpp index 60171e1a3..ff79cdd28 100644 --- a/lib/checkunusedfunctions.cpp +++ b/lib/checkunusedfunctions.cpp @@ -61,10 +61,10 @@ void CheckUnusedFunctions::parseTokens(const Tokenizer &tokenizer, const char Fi // No filename set yet.. if (usage.filename.empty()) { - usage.filename = tokenizer.getSourceFilePath(); + usage.filename = tokenizer.list.getSourceFilePath(); } // Multiple files => filename = "+" - else if (usage.filename != tokenizer.getSourceFilePath()) { + else if (usage.filename != tokenizer.list.getSourceFilePath()) { //func.filename = "+"; usage.usedOtherFile |= usage.usedSameFile; } @@ -92,7 +92,7 @@ void CheckUnusedFunctions::parseTokens(const Tokenizer &tokenizer, const char Fi _functions[markupVarToken->str()].usedOtherFile = true; else if (markupVarToken->next()->str() == "(") { FunctionUsage &func = _functions[markupVarToken->str()]; - func.filename = tokenizer.getSourceFilePath(); + func.filename = tokenizer.list.getSourceFilePath(); if (func.filename.empty() || func.filename == "+") func.usedOtherFile = true; else diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index 45504c07f..6f246bda7 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -413,7 +413,7 @@ void CppCheck::checkFile(const std::string &code, const char FileName[]) ErrorLogger::ErrorMessage::FileLocation loc2; loc2.setfile(Path::toNativeSeparators(FileName)); locationList.push_back(loc2); - loc.setfile(_tokenizer.getSourceFilePath()); + loc.setfile(_tokenizer.list.getSourceFilePath()); } locationList.push_back(loc); const ErrorLogger::ErrorMessage errmsg(locationList, diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index ebdc04655..4c92fbc58 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -49,7 +49,7 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti for (const Token *tok = _tokenizer->tokens(); tok; tok = tok ? tok->next() : nullptr) { // #5593 suggested to add here: if (_errorLogger) - _errorLogger->reportProgress(_tokenizer->getSourceFilePath(), + _errorLogger->reportProgress(_tokenizer->list.getSourceFilePath(), "SymbolDatabase", tok->progressValue()); // Locate next class diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 0fc183309..ca9cea406 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -10495,25 +10495,6 @@ void Tokenizer::simplifyMathExpressions() } } -const std::string& Tokenizer::getSourceFilePath() const -{ - if (list.getFiles().empty()) { - static const std::string empty; - return empty; - } - return list.getFiles()[0]; -} - -bool Tokenizer::isC() const -{ - return _settings->enforcedLang == Settings::C || (_settings->enforcedLang == Settings::None && Path::isC(getSourceFilePath())); -} - -bool Tokenizer::isCPP() const -{ - return _settings->enforcedLang == Settings::CPP || (_settings->enforcedLang == Settings::None && Path::isCPP(getSourceFilePath())); -} - void Tokenizer::reportError(const Token* tok, const Severity::SeverityType severity, const std::string& id, const std::string& msg, bool inconclusive) const { const std::list callstack(1, tok); diff --git a/lib/tokenize.h b/lib/tokenize.h index 93f667132..4b98c1804 100644 --- a/lib/tokenize.h +++ b/lib/tokenize.h @@ -48,14 +48,15 @@ public: m_timerResults = tr; } - /** @return the source file path. e.g. "file.cpp" */ - const std::string& getSourceFilePath() const; - /** Is the code C. Used for bailouts */ - bool isC() const; + bool isC() const { + return list.isC(); + } /** Is the code CPP. Used for bailouts */ - bool isCPP() const; + bool isCPP() const { + return list.isCPP(); + } /** * Check if inner scope ends with a call to a noreturn function diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index 79df478d3..5c4a59eae 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -51,6 +51,27 @@ TokenList::~TokenList() //--------------------------------------------------------------------------- +const std::string& TokenList::getSourceFilePath() const +{ + if (getFiles().empty()) { + static const std::string empty; + return empty; + } + return getFiles()[0]; +} + +bool TokenList::isC() const +{ + return _settings->enforcedLang == Settings::C || (_settings->enforcedLang == Settings::None && Path::isC(getSourceFilePath())); +} + +bool TokenList::isCPP() const +{ + return _settings->enforcedLang == Settings::CPP || (_settings->enforcedLang == Settings::None && Path::isCPP(getSourceFilePath())); +} + +//--------------------------------------------------------------------------- + // Deallocate lists.. void TokenList::deallocateTokens() { diff --git a/lib/tokenlist.h b/lib/tokenlist.h index 9e76430ec..3134c7c8c 100644 --- a/lib/tokenlist.h +++ b/lib/tokenlist.h @@ -40,6 +40,15 @@ public: _settings = settings; } + /** @return the source file path. e.g. "file.cpp" */ + const std::string& getSourceFilePath() const; + + /** Is the code C. Used for bailouts */ + bool isC() const; + + /** Is the code CPP. Used for bailouts */ + bool isCPP() const; + /** * Delete all tokens in given token list * @param tok token list to delete