tokenizer: tokenize '++', '--' and '>>' correctly

This commit is contained in:
Daniel Marjamäki 2009-02-14 10:13:50 +00:00
parent d1e9efc66a
commit 4a1488b1a9
2 changed files with 5 additions and 3 deletions

View File

@ -349,6 +349,9 @@ void Tokenizer::tokenize(std::istream &code, const char FileName[])
addtoken(CurrentToken.c_str(), lineno, FileIndex);
CurrentToken.clear();
CurrentToken += ch;
// Add "++", "--" or ">>" token
if ((ch=='+' || ch=='-' || ch=='>') && (code.peek() == ch))
CurrentToken += (char)code.get();
addtoken(CurrentToken.c_str(), lineno, FileIndex);
CurrentToken.clear();
continue;
@ -373,7 +376,6 @@ void Tokenizer::tokenize(std::istream &code, const char FileName[])
static const char* combineWithNext[][3] =
{
{ "<", "<", "<<" },
{ ">", ">", ">>" },
{ "&", "&", "&&" },
{ "|", "|", "||" },

View File

@ -667,7 +667,7 @@ private:
"2: void f ( )\n"
"3: {\n"
"4: int i@2 = 2 ;\n"
"5: for ( int i@3 = 0 ; i@3 < 10 ; + + i@3 )\n"
"5: for ( int i@3 = 0 ; i@3 < 10 ; ++ i@3 )\n"
"6: i@3 = 3 ;\n"
"7: i@2 = 4 ;\n"
"8: }\n");
@ -1041,7 +1041,7 @@ private:
std::ostringstream ostr;
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next())
ostr << " " << tok->str();
ASSERT_EQUALS(std::string(" for ( int i = 0 ; i < 100 ; i + + ) { }"), ostr.str());
ASSERT_EQUALS(std::string(" for ( int i = 0 ; i < 100 ; i ++ ) { }"), ostr.str());
}
void simplify_numeric_condition()