Tweaked Tokenizer::simplifyAsm2()

This commit is contained in:
Daniel Marjamäki 2016-01-04 19:18:10 +01:00
parent 97dccefe3d
commit a0971355b7
3 changed files with 27 additions and 32 deletions

View File

@ -9305,42 +9305,36 @@ void Tokenizer::simplifyAsm2()
if (Token::simpleMatch(tok, "^ {") || Token::simpleMatch(tok->linkAt(1), ") {")) {
Token * start = tok;
while (start && !Token::Match(start, "[;{}=]")) {
while (start && !Token::Match(start, "[,(;{}=]")) {
if (start->link() && Token::Match(start, ")|]|>"))
start = start->link();
start = start->previous();
}
if (start)
start = start->next();
const Token *last = tok->next()->link();
if (Token::simpleMatch(last, ") {"))
last = last->linkAt(1);
if (start != tok) {
last = last->next();
while (last && !Token::Match(last, "%cop%|,|;|{|}|)")) {
if (Token::Match(last, "(|["))
last = last->link();
last = last->next();
while (last && !Token::Match(last, "[;{})]")) {
last = last->next();
if (last && last->link() && last->str() == "(")
last = last->link()->next();
}
if (last)
last = last->next();
}
if (start && last) {
std::string asmcode(start->str());
std::string asmcode;
while (start->next() != last) {
asmcode += start->next()->str();
start->deleteNext();
}
asmcode += last->str();
start->deleteNext();
start->insertToken(";");
if (last->str() == "}")
start->insertToken(";");
start->insertToken(")");
start->insertToken("\"" + asmcode + "\"");
start->insertToken("(");
start->str("asm");
start->link(nullptr);
start->next()->link(start->tokAt(3));
start->tokAt(3)->link(start->next());
start->insertToken("asm");
start->tokAt(2)->link(start->tokAt(4));
start->tokAt(4)->link(start->tokAt(2));
tok = start->tokAt(4);
}
}

View File

@ -679,8 +679,8 @@ private:
}
void garbageCode58() { // #6732, #6762
ASSERT_THROW(checkCode("{ }> {= ~A()^{} }P { }"), InternalError);
ASSERT_THROW(checkCode("{= ~A()^{} }P { } { }> is"), InternalError);
checkCode("{ }> {= ~A()^{} }P { }");
checkCode("{= ~A()^{} }P { } { }> is");
}
void garbageCode59() { // #6735

View File

@ -999,14 +999,13 @@ private:
// #4725 - ^{}
void simplifyAsm2() {
ASSERT_EQUALS("void f ( ) { asm ( \"^{}\" ) ; }", tokenizeAndStringify("void f() { ^{} }"));
ASSERT_EQUALS("void f ( ) { asm ( \"x(^{});\" ) ; }", tokenizeAndStringify("void f() { x(^{}); }"));
ASSERT_EQUALS("void f ( ) { asm ( \"foo(A(),^{bar();});\" ) ; }", tokenizeAndStringify("void f() { foo(A(), ^{ bar(); }); }"));
ASSERT_EQUALS("int f0 ( Args args ) {\n"
"asm ( \"return^{returnsizeof...(Args);}()+\" ) ;\n"
"\n"
"asm ( \"^{returnsizeof...(args);}\" ) ;\n"
"\n"
"\n"
ASSERT_EQUALS("void f ( ) { x ( asm ( \"^{}\" ) ) ; }", tokenizeAndStringify("void f() { x(^{}); }"));
ASSERT_EQUALS("void f ( ) { foo ( A ( ) , asm ( \"^{bar();}\" ) ) ; }", tokenizeAndStringify("void f() { foo(A(), ^{ bar(); }); }"));
ASSERT_EQUALS("int f0 ( Args args ) { asm ( \"asm(\"return^{returnsizeof...(Args);}()\")+^{returnsizeof...(args);}()\" )\n"
"2:\n"
"|\n"
"5:\n"
"6: ;\n"
"} ;", tokenizeAndStringify("int f0(Args args) {\n"
" return ^{\n"
" return sizeof...(Args);\n"
@ -1014,16 +1013,18 @@ private:
" return sizeof...(args);\n"
" }();\n"
"};"));
ASSERT_EQUALS("int ( ^ block ) ( void ) = asm ( \"^{staticinttest=0;returntest;}\" ) ;",
ASSERT_EQUALS("int ( ^ block ) ( void ) = asm ( \"^{staticinttest=0;returntest;}\" )\n\n\n;",
tokenizeAndStringify("int(^block)(void) = ^{\n"
" static int test = 0;\n"
" return test;\n"
"};"));
ASSERT_EQUALS("; asm ( \"returnf(a[b=c],^{});\" ) ;",
ASSERT_EQUALS("; return f ( a [ b = c ] , asm ( \"^{}\" ) ) ;",
tokenizeAndStringify("; return f(a[b=c],^{});")); // #7185
ASSERT_EQUALS("; asm ( \"returnf(^(void){somecode});\" ) ;",
ASSERT_EQUALS("; return f ( asm ( \"^(void){somecode}\" ) ) ;",
tokenizeAndStringify("; return f(^(void){somecode});"));
ASSERT_EQUALS("; asm ( \"a?(b?(c,asm(\"^{}\")):0):^{}\" ) ;",
tokenizeAndStringify(";a?(b?(c,^{}):0):^{};"));
}
void ifAddBraces1() {