fixed tokenizer problem when reading char constants

This commit is contained in:
Daniel Marjamäki 2009-03-04 17:02:45 +00:00
parent 5c1d4f2703
commit 8b7a5dd494
2 changed files with 12 additions and 24 deletions

View File

@ -334,6 +334,9 @@ void CppCheck::checkFile(const std::string &code, const char FileName[])
// Tokenize the file // Tokenize the file
{ {
std::cout << "code..\n" << code << std::endl;
std::istringstream istr(code); std::istringstream istr(code);
_tokenizer.tokenize(istr, FileName); _tokenizer.tokenize(istr, FileName);
} }
@ -365,7 +368,7 @@ void CppCheck::checkFile(const std::string &code, const char FileName[])
_tokenizer.simplifyTokenList(); _tokenizer.simplifyTokenList();
// Write simplified token list to a file.. // Write simplified token list to a file..
//std::cout << _tokenizer.tokens()->stringifyList(true) << std::endl; std::cout << _tokenizer.tokens()->stringifyList(true) << std::endl;
if (_settings._unusedFunctions) if (_settings._unusedFunctions)
_checkFunctionUsage.parseTokens(_tokenizer); _checkFunctionUsage.parseTokens(_tokenizer);

View File

@ -185,32 +185,14 @@ void Tokenizer::tokenize(std::istream &code, const char FileName[])
continue; continue;
} }
// char.. // char/string..
if (ch == '\'') if (ch == '\'' || ch == '\"')
{ {
// Add previous token // Add previous token
addtoken(CurrentToken.c_str(), lineno, FileIndex); addtoken(CurrentToken.c_str(), lineno, FileIndex);
CurrentToken.clear(); CurrentToken.clear();
// Read this .. // read char
CurrentToken += ch;
CurrentToken += (char)code.get();
CurrentToken += (char)code.get();
if (CurrentToken[1] == '\\')
CurrentToken += (char)code.get();
// Add token and start on next..
addtoken(CurrentToken.c_str(), lineno, FileIndex);
CurrentToken.clear();
continue;
}
// String..
if (ch == '\"')
{
addtoken(CurrentToken.c_str(), lineno, FileIndex);
CurrentToken.clear();
bool special = false; bool special = false;
char c = ch; char c = ch;
do do
@ -230,10 +212,13 @@ void Tokenizer::tokenize(std::istream &code, const char FileName[])
// Get next character // Get next character
c = (char)code.get(); c = (char)code.get();
} }
while (code.good() && (special || c != '\"')); while (code.good() && (special || c != ch));
CurrentToken += '\"'; CurrentToken += ch;
// Add token and start on next..
addtoken(CurrentToken.c_str(), lineno, FileIndex); addtoken(CurrentToken.c_str(), lineno, FileIndex);
CurrentToken.clear(); CurrentToken.clear();
continue; continue;
} }