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
{
std::cout << "code..\n" << code << std::endl;
std::istringstream istr(code);
_tokenizer.tokenize(istr, FileName);
}
@ -365,7 +368,7 @@ void CppCheck::checkFile(const std::string &code, const char FileName[])
_tokenizer.simplifyTokenList();
// 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)
_checkFunctionUsage.parseTokens(_tokenizer);

View File

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