Updated tokenizer. To handle "#define f1(a,b) (a+b)" better

This commit is contained in:
Daniel Marjamäki 2008-03-18 07:45:35 +00:00
parent 101afe4344
commit d0cffeaa8c
2 changed files with 21 additions and 6 deletions

View File

@ -766,5 +766,13 @@ static void unused_variable()
"}\n";
check( CheckVariableScope, __LINE__, test5, "" );
const char test6[] = "static void f()\n"
"{\n"
"#define F1(x, y, z) (z ^ (x & (y ^ z)))\n"
"}\n";
check( CheckVariableScope, __LINE__, test6, "" );
}

View File

@ -328,13 +328,20 @@ void TokenizeCode(std::istream &code, const unsigned int FileIndex)
State = (State==Space1) ? Id : Value;
}
else if (State==Id && std::isspace(line[i]))
else if (State==Id)
{
strId = strdup(CurrentToken);
memset(CurrentToken, 0, sizeof(CurrentToken));
pToken = CurrentToken;
State = Space2;
continue;
if ( std::isspace( line[i] ) )
{
strId = strdup(CurrentToken);
memset(CurrentToken, 0, sizeof(CurrentToken));
pToken = CurrentToken;
State = Space2;
continue;
}
else if ( ! std::isalnum(line[i]) )
{
break;
}
}
*pToken = line[i];