Tokenizer: some changes to line numbers of some tokens:
simplifyAsm: change line number of newly added 'asm ( )' in order to be the same as next ';'. simplifyIfAddBraces: Change line number of newly added '}' in order to be the same as next 'else', except for '{ ; } else'.
This commit is contained in:
parent
dc59fc4391
commit
79b82f115f
|
@ -4953,6 +4953,13 @@ bool Tokenizer::simplifyIfAddBraces()
|
|||
if (tempToken) {
|
||||
tempToken->insertToken("}");
|
||||
Token::createMutualLinks(tok, tempToken->next());
|
||||
|
||||
// move '}' in the same line as 'else' if there's it after the new token,
|
||||
// except for '}' which is after '{ ; }'
|
||||
tempToken = tempToken->next();
|
||||
if (!Token::simpleMatch(tempToken->link(), "{ ; }") && tempToken->next() && tempToken->next()->str() == "else" &&
|
||||
tempToken->next()->linenr() != tempToken->linenr())
|
||||
tempToken->linenr(tempToken->next()->linenr());
|
||||
} else {
|
||||
// Can't insert matching "}" so give up. This is fatal because it
|
||||
// causes unbalanced braces.
|
||||
|
@ -9360,6 +9367,18 @@ void Tokenizer::simplifyAsm()
|
|||
tok->insertToken("asm");
|
||||
|
||||
Token::createMutualLinks(tok->tokAt(2), tok->tokAt(3));
|
||||
|
||||
//move the new tokens in the same line as ";" if available
|
||||
tok = tok->tokAt(3);
|
||||
if (tok->next() && tok->next()->str() == ";" &&
|
||||
tok->next()->linenr() != tok->linenr()) {
|
||||
unsigned int endposition = tok->next()->linenr();
|
||||
tok = tok->tokAt(-3);
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
tok = tok->next();
|
||||
tok->linenr(endposition);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -86,6 +86,7 @@ private:
|
|||
TEST_CASE(ifAddBraces13);
|
||||
TEST_CASE(ifAddBraces14); // #2610 - segfault: if()<{}
|
||||
TEST_CASE(ifAddBraces15); // #2616 - unknown macro before if
|
||||
TEST_CASE(ifAddBraces16); // '} else' should be in the same line
|
||||
|
||||
TEST_CASE(whileAddBraces);
|
||||
TEST_CASE(doWhileAddBraces);
|
||||
|
@ -750,6 +751,9 @@ private:
|
|||
ASSERT_EQUALS("; asm ( ) ;", tokenizeAndStringify("; __asm__ (\"fnstcw %0\" : \"= m\" (old_cw));"));
|
||||
ASSERT_EQUALS("; asm ( ) ;", tokenizeAndStringify("; __asm __volatile__ (\"ddd\") ;"));
|
||||
ASSERT_EQUALS("; asm ( ) ;", tokenizeAndStringify(";__asm__ volatile ( \"mov ax,bx\" );"));
|
||||
|
||||
// 'asm ( ) ;' should be in the same line
|
||||
ASSERT_EQUALS(";\n\nasm ( ) ;", tokenizeAndStringify(";\n\n__asm__ volatile ( \"mov ax,bx\" );", true));
|
||||
}
|
||||
|
||||
|
||||
|
@ -941,6 +945,25 @@ private:
|
|||
ASSERT_EQUALS("{ A if ( x ) { y ( ) ; } }", tokenizeAndStringify("{A if(x)y();}", false));
|
||||
}
|
||||
|
||||
void ifAddBraces16() {
|
||||
const char code[] = "void f()\n"
|
||||
"{\n"
|
||||
" if (a)\n"
|
||||
" bar1 ();\n"
|
||||
" \n"
|
||||
" else\n"
|
||||
" bar2 ();\n"
|
||||
"}\n";
|
||||
ASSERT_EQUALS("void f ( )\n"
|
||||
"{\n"
|
||||
"if ( a ) {\n"
|
||||
"bar1 ( ) ;\n\n"
|
||||
"} else {\n"
|
||||
"bar2 ( ) ; }\n"
|
||||
"}", tokenizeAndStringify(code, true));
|
||||
}
|
||||
|
||||
|
||||
|
||||
void whileAddBraces() {
|
||||
const char code[] = ";while(a);";
|
||||
|
|
Loading…
Reference in New Issue