Fixed wrong parsing of ^{}

This commit is contained in:
PKEuS 2015-11-02 22:14:41 +01:00
parent 4f565ba90f
commit b049050792
4 changed files with 23 additions and 10 deletions

View File

@ -9294,9 +9294,7 @@ void Tokenizer::simplifyAsm2()
for (Token *tok = list.front(); tok; tok = tok->next()) { for (Token *tok = list.front(); tok; tok = tok->next()) {
if (Token::simpleMatch(tok, "^ {")) { if (Token::simpleMatch(tok, "^ {")) {
Token * start = tok; 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(); start = start->previous();
} }
if (start) if (start)
@ -9304,8 +9302,9 @@ void Tokenizer::simplifyAsm2()
const Token *last = tok->next()->link(); const Token *last = tok->next()->link();
if (start != tok) { if (start != tok) {
last = last->next(); last = last->next();
while (last && !Token::Match(last->next(), "[;{}()]")) while (last && !Token::Match(last->next(), "[;{})]"))
last = last->next(); last = last->next();
last = last->next();
} }
if (start && last) { if (start && last) {
std::string asmcode(start->str()); std::string asmcode(start->str());

View File

@ -657,8 +657,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
@ -782,7 +782,7 @@ private:
} }
void garbageCode89() { // #6772 void garbageCode89() { // #6772
ASSERT_THROW(checkCode("{ { ( ) } P ( ) ^ { } { } { } ( ) } 0"), InternalError); // do not crash checkCode("{ { ( ) } P ( ) ^ { } { } { } ( ) } 0"); // do not crash
} }
void garbageCode90() { // #6790 void garbageCode90() { // #6790
@ -1164,6 +1164,8 @@ private:
" for (int ui = 0; ui < 1z; ui++)\n" " for (int ui = 0; ui < 1z; ui++)\n"
" ;\n" " ;\n"
"}"); "}");
checkCode("; void f ^ { return } int main ( ) { }"); // #4941
} }
void garbageValueFlow() { void garbageValueFlow() {

View File

@ -810,7 +810,7 @@ private:
" return sizeof...(args);\n" " return sizeof...(args);\n"
" }();\n" " }();\n"
"}"; "}";
ASSERT_THROW(tok(code), InternalError); tok(code);
} }
void template43() { // #5097 - Assert due to '>>' in 'B<A<C>>' not being treated as end of template instantation void template43() { // #5097 - Assert due to '>>' in 'B<A<C>>' not being treated as end of template instantation

View File

@ -775,8 +775,20 @@ private:
// #4725 - ^{} // #4725 - ^{}
void tokenize28() { void tokenize28() {
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 ( ) { asm ( \"x(^{});\" ) ; }", tokenizeAndStringify("void f() { x(^{}); }"));
ASSERT_EQUALS("; asm ( \"voidf^{return}intmain\" ) ; ( ) { }", tokenizeAndStringify("; void f ^ { return } int main ( ) { }")); ASSERT_EQUALS("int f0 ( Args args ) {\n"
"asm ( \"return^{returnsizeof...(Args);}()\" ) ;\n"
"\n"
"asm ( \"+^{returnsizeof...(args);}()\" ) ;\n"
"\n"
"\n"
"} ;", tokenizeAndStringify("int f0(Args args) {\n"
" return ^{\n"
" return sizeof...(Args);\n"
" }() + ^ {\n"
" return sizeof...(args);\n"
" }();\n"
"};"));
} }
// #3503 - don't "simplify" SetFunction member function to a variable // #3503 - don't "simplify" SetFunction member function to a variable