Skip to content

Commit

Permalink
Splitted class TokenList from Tokenizer
Browse files Browse the repository at this point in the history
  • Loading branch information
PKEuS committed May 5, 2012
1 parent 5d088aa commit 1a5fbd6
Show file tree
Hide file tree
Showing 19 changed files with 724 additions and 626 deletions.
6 changes: 3 additions & 3 deletions lib/check.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,13 @@ class Check {

ErrorLogger::ErrorMessage::FileLocation loc;
loc.line = (*it)->linenr();
loc.setfile(_tokenizer->file(*it));
loc.setfile(_tokenizer->list.file(*it));
locationList.push_back(loc);
}

ErrorLogger::ErrorMessage errmsg(locationList, severity, msg, id, inconclusive);
if (_tokenizer && !_tokenizer->getFiles().empty())
errmsg.file0 = _tokenizer->getFiles()[0];
if (_tokenizer && !_tokenizer->list.getFiles().empty())
errmsg.file0 = _tokenizer->list.getFiles()[0];
if (_errorLogger)
_errorLogger->reportErr(errmsg);
else
Expand Down
2 changes: 1 addition & 1 deletion lib/checkbufferoverrun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1293,7 +1293,7 @@ void CheckBufferOverrun::checkGlobalAndLocalVariable()
// nextTok : number of tokens used in variable declaration - used to skip to next statement.
int nextTok = 0;

_errorLogger->reportProgress(_tokenizer->getFiles().front(),
_errorLogger->reportProgress(_tokenizer->getSourceFilePath(),
"Check (BufferOverrun::checkGlobalAndLocalVariable)",
tok->progressValue());

Expand Down
16 changes: 8 additions & 8 deletions lib/checkmemoryleak.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ void CheckMemoryLeak::reportErr(const std::list<const Token *> &callstack, Sever

ErrorLogger::ErrorMessage::FileLocation loc;
loc.line = tok->linenr();
loc.setfile(tokenizer->file(tok));
loc.setfile(tokenizer->list.file(tok));

locations.push_back(loc);
}
Expand Down Expand Up @@ -669,7 +669,7 @@ const char * CheckMemoryLeakInFunction::call_func(const Token *tok, std::list<co
ret = "alloc";
else if (Token::simpleMatch(func, "; dealloc ; }"))
ret = "dealloc";
Tokenizer::deleteTokens(func);
TokenList::deleteTokens(func);
return ret;
}

Expand Down Expand Up @@ -734,7 +734,7 @@ const char * CheckMemoryLeakInFunction::call_func(const Token *tok, std::list<co
else if (Token::findsimplematch(func_, "&use"))
ret = "&use";

Tokenizer::deleteTokens(func);
TokenList::deleteTokens(func);
return ret;
}
if (varid > 0 && Token::Match(tok, "& %varid% [,()]", varid)) {
Expand Down Expand Up @@ -889,7 +889,7 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::list<const Toke
if (Token::Match(tok, "asprintf|vasprintf (")) {
// todo: check how the return value is used.
if (!Token::Match(tok->previous(), "[;{}]")) {
Tokenizer::deleteTokens(rethead);
TokenList::deleteTokens(rethead);
return 0;
}
alloc = Malloc;
Expand Down Expand Up @@ -2071,7 +2071,7 @@ void CheckMemoryLeakInFunction::checkScope(const Token *Tok1, const std::string

// If the variable is not allocated at all => no memory leak
if (Token::findsimplematch(tok, "alloc") == 0) {
Tokenizer::deleteTokens(tok);
TokenList::deleteTokens(tok);
return;
}

Expand All @@ -2083,13 +2083,13 @@ void CheckMemoryLeakInFunction::checkScope(const Token *Tok1, const std::string

// If the variable is not allocated at all => no memory leak
if (Token::findsimplematch(tok, "alloc") == 0) {
Tokenizer::deleteTokens(tok);
TokenList::deleteTokens(tok);
return;
}

/** @todo handle "goto" */
if (Token::findsimplematch(tok, "goto")) {
Tokenizer::deleteTokens(tok);
TokenList::deleteTokens(tok);
return;
}

Expand Down Expand Up @@ -2129,7 +2129,7 @@ void CheckMemoryLeakInFunction::checkScope(const Token *Tok1, const std::string
}
}

Tokenizer::deleteTokens(tok);
TokenList::deleteTokens(tok);
}
//---------------------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion lib/checkmemoryleak.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ class CheckMemoryLeakInFunction : private Check, public CheckMemoryLeak {
* @param classmember should be set if the inspected function is a class member
* @param sz size of type, used to check for mismatching size of allocation. for example "int *a;" => the sz is "sizeof(int)"
* @return Newly allocated token array. Caller needs to release reserved
* memory by calling Tokenizer::deleteTokens(returnValue);
* memory by calling TokenList::deleteTokens(returnValue);
* Returned tokens:
* - "alloc" : the variable is allocated
* - "assign" : the variable is assigned a new value
Expand Down
4 changes: 2 additions & 2 deletions lib/checkunusedfunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ void CheckUnusedFunctions::parseTokens(const Tokenizer &tokenizer)

// No filename set yet..
if (func.filename.empty()) {
func.filename = tokenizer.getFiles().at(0);
func.filename = tokenizer.getSourceFilePath();
}
// Multiple files => filename = "+"
else if (func.filename != tokenizer.getFiles().at(0)) {
else if (func.filename != tokenizer.getSourceFilePath()) {
//func.filename = "+";
func.usedOtherFile |= func.usedSameFile;
}
Expand Down
6 changes: 3 additions & 3 deletions lib/cppcheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,8 @@ void CppCheck::checkFile(const std::string &code, const char FileName[])
}

// Update the _dependencies..
if (_tokenizer.getFiles().size() >= 2)
_dependencies.insert(_tokenizer.getFiles().begin()+1, _tokenizer.getFiles().end());
if (_tokenizer.list.getFiles().size() >= 2)
_dependencies.insert(_tokenizer.list.getFiles().begin()+1, _tokenizer.list.getFiles().end());

// call all "runChecks" in all registered Check classes
for (std::list<Check *>::iterator it = Check::instances().begin(); it != Check::instances().end(); ++it) {
Expand Down Expand Up @@ -423,7 +423,7 @@ void CppCheck::checkFile(const std::string &code, const char FileName[])
ErrorLogger::ErrorMessage::FileLocation loc;
if (e.token) {
loc.line = e.token->linenr();
const std::string fixedpath = Path::toNativeSeparators(_tokenizer.file(e.token));
const std::string fixedpath = Path::toNativeSeparators(_tokenizer.list.file(e.token));
loc.setfile(fixedpath);
} else {
loc.setfile(_tokenizer.getSourceFilePath());
Expand Down
2 changes: 1 addition & 1 deletion lib/preprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2275,7 +2275,7 @@ class PreprocessorMacro {

// Tokenize the macro to make it easier to handle
std::istringstream istr(macro);
tokenizer.createTokens(istr);
tokenizer.list.createTokens(istr);

// macro name..
if (tokens() && tokens()->isName())
Expand Down
36 changes: 18 additions & 18 deletions lib/symboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1225,7 +1225,7 @@ void SymbolDatabase::debugMessage(const Token *tok, const std::string &msg) cons
std::list<ErrorLogger::ErrorMessage::FileLocation> locationList;
ErrorLogger::ErrorMessage::FileLocation loc;
loc.line = tok->linenr();
loc.setfile(_tokenizer->file(tok));
loc.setfile(_tokenizer->list.file(tok));
locationList.push_back(loc);

const ErrorLogger::ErrorMessage errmsg(locationList,
Expand Down Expand Up @@ -1288,14 +1288,14 @@ void SymbolDatabase::printVariable(const Variable *var, const char *indent) cons
{
std::cout << indent << "_name: " << var->nameToken();
if (var->nameToken()) {
std::cout << " " << var->name() << " " << _tokenizer->fileLine(var->nameToken()) << std::endl;
std::cout << " " << var->name() << " " << _tokenizer->list.fileLine(var->nameToken()) << std::endl;
std::cout << indent << " varId: " << var->varId() << std::endl;
} else
std::cout << std::endl;
std::cout << indent << "_start: " << var->typeStartToken() << " " << var->typeStartToken()->str()
<< " " << _tokenizer->fileLine(var->typeStartToken()) << std::endl;;
<< " " << _tokenizer->list.fileLine(var->typeStartToken()) << std::endl;;
std::cout << indent << "_end: " << var->typeEndToken() << " " << var->typeEndToken()->str()
<< " " << _tokenizer->fileLine(var->typeEndToken()) << std::endl;;
<< " " << _tokenizer->list.fileLine(var->typeEndToken()) << std::endl;;
std::cout << indent << "_index: " << var->index() << std::endl;
std::cout << indent << "_access: " <<
(var->isPublic() ? "Public" :
Expand All @@ -1319,15 +1319,15 @@ void SymbolDatabase::printVariable(const Variable *var, const char *indent) cons
std::cout << indent << "_type: ";
if (var->type()) {
std::cout << var->type()->className << " " << var->type()->type << " "
<< _tokenizer->fileLine(var->type()->classDef) << std::endl;
<< _tokenizer->list.fileLine(var->type()->classDef) << std::endl;
} else
std::cout << "none" << std::endl;

std::cout << indent << "_scope: ";
if (var->scope()) {
std::cout << var->scope()->className << " " << var->scope()->type;
if (var->scope()->classDef)
std::cout << " " << _tokenizer->fileLine(var->scope()->classDef) << std::endl;
std::cout << " " << _tokenizer->list.fileLine(var->scope()->classDef) << std::endl;
else
std::cout << std::endl;
} else
Expand All @@ -1353,19 +1353,19 @@ void SymbolDatabase::printOut(const char *title) const
std::cout << " className: " << scope->className << std::endl;
std::cout << " classDef: " << scope->classDef;
if (scope->classDef)
std::cout << " " << scope->classDef->str() << " " << _tokenizer->fileLine(scope->classDef) << std::endl;
std::cout << " " << scope->classDef->str() << " " << _tokenizer->list.fileLine(scope->classDef) << std::endl;
else
std::cout << std::endl;

std::cout << " classStart: " << scope->classStart;
if (scope->classStart)
std::cout << " " << scope->classStart->str() << " " << _tokenizer->fileLine(scope->classStart) << std::endl;
std::cout << " " << scope->classStart->str() << " " << _tokenizer->list.fileLine(scope->classStart) << std::endl;
else
std::cout << std::endl;

std::cout << " classEnd: " << scope->classEnd;
if (scope->classEnd)
std::cout << " " << scope->classEnd->str() << " " << _tokenizer->fileLine(scope->classEnd) << std::endl;
std::cout << " " << scope->classEnd->str() << " " << _tokenizer->list.fileLine(scope->classEnd) << std::endl;
else
std::cout << std::endl;

Expand All @@ -1375,7 +1375,7 @@ void SymbolDatabase::printOut(const char *title) const
for (func = scope->functionList.begin(); func != scope->functionList.end(); ++func) {
std::cout << " Function: " << &*func << std::endl;
std::cout << " name: " << func->tokenDef->str() << " "
<< _tokenizer->fileLine(func->tokenDef) << std::endl;
<< _tokenizer->list.fileLine(func->tokenDef) << std::endl;
std::cout << " type: " << (func->type == Function::eConstructor? "Constructor" :
func->type == Function::eCopyConstructor ? "CopyConstructor" :
func->type == Function::eOperatorEqual ? "OperatorEqual" :
Expand All @@ -1396,16 +1396,16 @@ void SymbolDatabase::printOut(const char *title) const
std::cout << " isExplicit: " << (func->isExplicit ? "true" : "false") << std::endl;
std::cout << " isOperator: " << (func->isOperator ? "true" : "false") << std::endl;
std::cout << " retFuncPtr: " << (func->retFuncPtr ? "true" : "false") << std::endl;
std::cout << " tokenDef: " << _tokenizer->fileLine(func->tokenDef) << std::endl;
std::cout << " argDef: " << _tokenizer->fileLine(func->argDef) << std::endl;
std::cout << " tokenDef: " << _tokenizer->list.fileLine(func->tokenDef) << std::endl;
std::cout << " argDef: " << _tokenizer->list.fileLine(func->argDef) << std::endl;
if (func->hasBody) {
std::cout << " token: " << _tokenizer->fileLine(func->token) << std::endl;
std::cout << " arg: " << _tokenizer->fileLine(func->arg) << std::endl;
std::cout << " token: " << _tokenizer->list.fileLine(func->token) << std::endl;
std::cout << " arg: " << _tokenizer->list.fileLine(func->arg) << std::endl;
}
std::cout << " functionScope: ";
if (func->functionScope) {
std::cout << func->functionScope->className << " "
<< _tokenizer->fileLine(func->functionScope->classDef) << std::endl;
<< _tokenizer->list.fileLine(func->functionScope->classDef) << std::endl;
} else
std::cout << "Unknown" << std::endl;

Expand Down Expand Up @@ -1482,21 +1482,21 @@ void SymbolDatabase::printOut(const char *title) const
std::cout << "::" << tok1->strAt(1);
tok1 = tok1->tokAt(2);
}
std::cout << " " << _tokenizer->fileLine(*use) << std::endl;
std::cout << " " << _tokenizer->list.fileLine(*use) << std::endl;
}

std::cout << " functionOf: " << scope->functionOf;
if (scope->functionOf) {
std::cout << " " << scope->functionOf->type << " " << scope->functionOf->className;
if (scope->functionOf->classDef)
std::cout << " " << _tokenizer->fileLine(scope->functionOf->classDef);
std::cout << " " << _tokenizer->list.fileLine(scope->functionOf->classDef);
}
std::cout << std::endl;

std::cout << " function: " << scope->function;
if (scope->function) {
std::cout << " " << scope->function->tokenDef->str() << " "
<< _tokenizer->fileLine(scope->function->tokenDef);
<< _tokenizer->list.fileLine(scope->function->tokenDef);
}
std::cout << std::endl;
}
Expand Down
Loading

0 comments on commit 1a5fbd6

Please sign in to comment.