Tweaked Tokenizer::simplifyAsm2()
This commit is contained in:
parent
97dccefe3d
commit
a0971355b7
|
@ -9305,42 +9305,36 @@ void Tokenizer::simplifyAsm2()
|
||||||
|
|
||||||
if (Token::simpleMatch(tok, "^ {") || Token::simpleMatch(tok->linkAt(1), ") {")) {
|
if (Token::simpleMatch(tok, "^ {") || Token::simpleMatch(tok->linkAt(1), ") {")) {
|
||||||
Token * start = tok;
|
Token * start = tok;
|
||||||
while (start && !Token::Match(start, "[;{}=]")) {
|
while (start && !Token::Match(start, "[,(;{}=]")) {
|
||||||
if (start->link() && Token::Match(start, ")|]|>"))
|
if (start->link() && Token::Match(start, ")|]|>"))
|
||||||
start = start->link();
|
start = start->link();
|
||||||
start = start->previous();
|
start = start->previous();
|
||||||
}
|
}
|
||||||
if (start)
|
|
||||||
start = start->next();
|
|
||||||
const Token *last = tok->next()->link();
|
const Token *last = tok->next()->link();
|
||||||
if (Token::simpleMatch(last, ") {"))
|
if (Token::simpleMatch(last, ") {"))
|
||||||
last = last->linkAt(1);
|
last = last->linkAt(1);
|
||||||
if (start != tok) {
|
|
||||||
last = last->next();
|
last = last->next();
|
||||||
while (last && !Token::Match(last, "[;{})]")) {
|
while (last && !Token::Match(last, "%cop%|,|;|{|}|)")) {
|
||||||
last = last->next();
|
if (Token::Match(last, "(|["))
|
||||||
if (last && last->link() && last->str() == "(")
|
last = last->link();
|
||||||
last = last->link()->next();
|
|
||||||
}
|
|
||||||
if (last)
|
|
||||||
last = last->next();
|
last = last->next();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (start && last) {
|
if (start && last) {
|
||||||
std::string asmcode(start->str());
|
std::string asmcode;
|
||||||
while (start->next() != last) {
|
while (start->next() != last) {
|
||||||
asmcode += start->next()->str();
|
asmcode += start->next()->str();
|
||||||
start->deleteNext();
|
start->deleteNext();
|
||||||
}
|
}
|
||||||
asmcode += last->str();
|
if (last->str() == "}")
|
||||||
start->deleteNext();
|
|
||||||
start->insertToken(";");
|
start->insertToken(";");
|
||||||
start->insertToken(")");
|
start->insertToken(")");
|
||||||
start->insertToken("\"" + asmcode + "\"");
|
start->insertToken("\"" + asmcode + "\"");
|
||||||
start->insertToken("(");
|
start->insertToken("(");
|
||||||
start->str("asm");
|
start->insertToken("asm");
|
||||||
start->link(nullptr);
|
start->tokAt(2)->link(start->tokAt(4));
|
||||||
start->next()->link(start->tokAt(3));
|
start->tokAt(4)->link(start->tokAt(2));
|
||||||
start->tokAt(3)->link(start->next());
|
|
||||||
tok = start->tokAt(4);
|
tok = start->tokAt(4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -679,8 +679,8 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
void garbageCode58() { // #6732, #6762
|
void garbageCode58() { // #6732, #6762
|
||||||
ASSERT_THROW(checkCode("{ }> {= ~A()^{} }P { }"), InternalError);
|
checkCode("{ }> {= ~A()^{} }P { }");
|
||||||
ASSERT_THROW(checkCode("{= ~A()^{} }P { } { }> is"), InternalError);
|
checkCode("{= ~A()^{} }P { } { }> is");
|
||||||
}
|
}
|
||||||
|
|
||||||
void garbageCode59() { // #6735
|
void garbageCode59() { // #6735
|
||||||
|
|
|
@ -999,14 +999,13 @@ private:
|
||||||
// #4725 - ^{}
|
// #4725 - ^{}
|
||||||
void simplifyAsm2() {
|
void simplifyAsm2() {
|
||||||
ASSERT_EQUALS("void f ( ) { asm ( \"^{}\" ) ; }", tokenizeAndStringify("void f() { ^{} }"));
|
ASSERT_EQUALS("void f ( ) { asm ( \"^{}\" ) ; }", tokenizeAndStringify("void f() { ^{} }"));
|
||||||
ASSERT_EQUALS("void f ( ) { asm ( \"x(^{});\" ) ; }", tokenizeAndStringify("void f() { x(^{}); }"));
|
ASSERT_EQUALS("void f ( ) { x ( asm ( \"^{}\" ) ) ; }", tokenizeAndStringify("void f() { x(^{}); }"));
|
||||||
ASSERT_EQUALS("void f ( ) { asm ( \"foo(A(),^{bar();});\" ) ; }", tokenizeAndStringify("void f() { foo(A(), ^{ bar(); }); }"));
|
ASSERT_EQUALS("void f ( ) { foo ( A ( ) , asm ( \"^{bar();}\" ) ) ; }", tokenizeAndStringify("void f() { foo(A(), ^{ bar(); }); }"));
|
||||||
ASSERT_EQUALS("int f0 ( Args args ) {\n"
|
ASSERT_EQUALS("int f0 ( Args args ) { asm ( \"asm(\"return^{returnsizeof...(Args);}()\")+^{returnsizeof...(args);}()\" )\n"
|
||||||
"asm ( \"return^{returnsizeof...(Args);}()+\" ) ;\n"
|
"2:\n"
|
||||||
"\n"
|
"|\n"
|
||||||
"asm ( \"^{returnsizeof...(args);}\" ) ;\n"
|
"5:\n"
|
||||||
"\n"
|
"6: ;\n"
|
||||||
"\n"
|
|
||||||
"} ;", tokenizeAndStringify("int f0(Args args) {\n"
|
"} ;", tokenizeAndStringify("int f0(Args args) {\n"
|
||||||
" return ^{\n"
|
" return ^{\n"
|
||||||
" return sizeof...(Args);\n"
|
" return sizeof...(Args);\n"
|
||||||
|
@ -1014,16 +1013,18 @@ private:
|
||||||
" return sizeof...(args);\n"
|
" return sizeof...(args);\n"
|
||||||
" }();\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"
|
tokenizeAndStringify("int(^block)(void) = ^{\n"
|
||||||
" static int test = 0;\n"
|
" static int test = 0;\n"
|
||||||
" return test;\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
|
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});"));
|
tokenizeAndStringify("; return f(^(void){somecode});"));
|
||||||
|
ASSERT_EQUALS("; asm ( \"a?(b?(c,asm(\"^{}\")):0):^{}\" ) ;",
|
||||||
|
tokenizeAndStringify(";a?(b?(c,^{}):0):^{};"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ifAddBraces1() {
|
void ifAddBraces1() {
|
||||||
|
|
Loading…
Reference in New Issue