Tokenizer: Skip inline assembly (Bug 2220727)

This commit is contained in:
Daniel Marjamäki 2008-11-05 07:28:40 +00:00
parent fd4b02e538
commit eb86a0fc34
2 changed files with 60 additions and 0 deletions

View File

@ -36,6 +36,8 @@ private:
{
TEST_CASE( multiline );
TEST_CASE( longtok );
TEST_CASE( inlineasm );
}
@ -92,6 +94,40 @@ private:
DeallocateTokens();
}
void inlineasm()
{
const char filedata[] = "void foo()\n"
"{\n"
" __asm\n"
" {\n"
" jmp $jump1\n"
" $jump1:\n"
" }\n"
"}\n";
// tokenize..
tokens = tokens_back = NULL;
std::istringstream istr(filedata);
TokenizeCode(istr, 0);
// Expected result..
const char *expected[] =
{
"void",
"foo",
"(",
")",
"{",
"}",
0
};
// Compare..
ASSERT_EQUALS( true, cmptok(expected, tokens) );
DeallocateTokens();
}
};
REGISTER_TEST( TestTokenizer )

View File

@ -637,6 +637,30 @@ void TokenizeCode(std::istream &code, const unsigned int FileIndex)
}
}
}
// Remove __asm..
for ( TOKEN *tok = tokens; tok; tok = tok->next )
{
if ( Match(tok->next, "__asm {") )
{
while ( tok->next )
{
bool last = Match( tok->next, "}" );
// Unlink and delete tok->next
TOKEN *next = tok->next;
tok->next = tok->next->next;
free(next->str);
delete next;
// break if this was the last token to delete..
if (last)
break;
}
}
}
}
//---------------------------------------------------------------------------