Moved getSourceFilePath(), isC() and isCPP() from Tokenizer to TokenList

Conflicts:
	lib/tokenize.cpp
This commit is contained in:
PKEuS 2014-06-04 18:00:22 +02:00
parent 6aa88248ac
commit d93d7401c6
8 changed files with 42 additions and 30 deletions

View File

@ -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());

View File

@ -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

View File

@ -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,

View File

@ -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

View File

@ -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<const Token*> callstack(1, tok);

View File

@ -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

View File

@ -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()
{

View File

@ -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