Improve tokenizing of "do{ ... } while(0)".
The simplification will be the same for every combination, except for the 'continue' and the 'break'. In that case, keep the block braces.
This commit is contained in:
parent
c9ee19c654
commit
882b0c15a0
|
@ -8662,18 +8662,23 @@ void Tokenizer::simplifyWhile0()
|
||||||
if (while0 && Token::simpleMatch(tok->previous(), "}")) {
|
if (while0 && Token::simpleMatch(tok->previous(), "}")) {
|
||||||
// find "do"
|
// find "do"
|
||||||
Token *tok2 = tok->previous()->link();
|
Token *tok2 = tok->previous()->link();
|
||||||
tok2 = tok2 ? tok2->previous() : 0;
|
tok2 = tok2->previous();
|
||||||
if (tok2 && tok2->str() == "do" && !Token::findmatch(tok2, "continue|break", tok)) {
|
if (tok2 && tok2->str() == "do") {
|
||||||
// delete "do {"
|
bool flowmatch = Token::findmatch(tok2, "continue|break", tok) != NULL;
|
||||||
|
// delete "do ({)"
|
||||||
tok2->deleteThis();
|
tok2->deleteThis();
|
||||||
|
if (!flowmatch)
|
||||||
tok2->deleteThis();
|
tok2->deleteThis();
|
||||||
|
|
||||||
// delete "} while ( 0 )"
|
// delete "(}) while ( 0 ) (;)"
|
||||||
tok = tok->previous();
|
tok = tok->previous();
|
||||||
tok->deleteNext(); // while
|
tok->deleteNext(); // while
|
||||||
tok->deleteNext(); // (
|
tok->deleteNext(); // (
|
||||||
tok->deleteNext(); // 0
|
tok->deleteNext(); // 0
|
||||||
tok->deleteNext(); // )
|
tok->deleteNext(); // )
|
||||||
|
if (tok->next() && tok->next()->str() == ";")
|
||||||
|
tok->deleteNext(); // ;
|
||||||
|
if (!flowmatch)
|
||||||
tok->deleteThis(); // }
|
tok->deleteThis(); // }
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -6450,8 +6450,10 @@ private:
|
||||||
|
|
||||||
void while0() {
|
void while0() {
|
||||||
ASSERT_EQUALS("; x = 1 ;", tok("; do { x = 1 ; } while (0);"));
|
ASSERT_EQUALS("; x = 1 ;", tok("; do { x = 1 ; } while (0);"));
|
||||||
ASSERT_EQUALS("; do { continue ; } while ( false ) ;", tok("; do { continue ; } while (0);"));
|
ASSERT_EQUALS("; return 0 ;", tok("; do { return 0; } while (0);"));
|
||||||
ASSERT_EQUALS("; do { break ; } while ( false ) ;", tok("; do { break; } while (0);"));
|
ASSERT_EQUALS("void foo ( ) { goto label ; }", tok("void foo() { do { goto label; } while (0); }"));
|
||||||
|
ASSERT_EQUALS("; { continue ; }", tok("; do { continue ; } while (0);"));
|
||||||
|
ASSERT_EQUALS("; { break ; }", tok("; do { break; } while (0);"));
|
||||||
ASSERT_EQUALS(";", tok("; while (false) { a; }"));
|
ASSERT_EQUALS(";", tok("; while (false) { a; }"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue