Fixed #4725 (Tokenizer: Replace block declaration (^{}) with asm())

This commit is contained in:
Daniel Marjamäki 2013-05-09 14:47:18 +02:00
parent 455b07a641
commit cbe0a0825c
2 changed files with 42 additions and 0 deletions

View File

@ -1759,6 +1759,41 @@ bool Tokenizer::tokenize(std::istream &code,
// Remove __asm..
simplifyAsm();
// Put ^{} statements in asm()
for (Token *tok = list.front(); tok; tok = tok->next()) {
if (Token::simpleMatch(tok, "^ {")) {
Token * start = tok;
while (start && !Token::Match(start, "[;{}]"))
start = start->previous();
if (start)
start = start->next();
const Token *last = tok->next()->link();
if (start != tok) {
last = last->next();
while (last && !Token::Match(last, "[;{}]"))
last = last->next();
}
if (start && last) {
std::string asmcode(start->str());
while (start->next() != last) {
asmcode += start->next()->str();
start->deleteNext();
}
asmcode += last->str();
start->deleteNext();
start->insertToken(";");
start->insertToken(")");
start->insertToken("\"" + asmcode + "\"");
start->insertToken("(");
start->str("asm");
start->link(NULL);
start->next()->link(start->tokAt(3));
start->tokAt(3)->link(start->next());
tok = start->tokAt(4);
}
}
}
// When the assembly code has been cleaned up, no @ is allowed
for (const Token *tok = list.front(); tok; tok = tok->next()) {
if (tok->str() == "(")

View File

@ -59,6 +59,7 @@ private:
TEST_CASE(tokenize25); // #4239 (segmentation fault)
TEST_CASE(tokenize26); // #4245 (segmentation fault)
TEST_CASE(tokenize27); // #4525 (segmentation fault)
TEST_CASE(tokenize28); // #4725 (writing asm() around "^{}")
// don't freak out when the syntax is wrong
TEST_CASE(wrong_syntax1);
@ -732,6 +733,12 @@ private:
);
}
// #4725 - ^{}
void tokenize28() {
ASSERT_EQUALS("void f ( ) { asm ( \"^{}\" ) ; }", tokenizeAndStringify("void f() { ^{} }"));
ASSERT_EQUALS("void f ( ) { asm ( \"x(^{});\" ) ; }", tokenizeAndStringify("void f() { x(^{}); }"));
}
void wrong_syntax1() {
{
const std::string code("TR(kvmpio, PROTO(int rw), ARGS(rw), TP_(aa->rw;))");