diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index c99d75114d5..a6a9560e06c 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -5509,6 +5509,9 @@ bool Tokenizer::simplifyTokenList1(const char FileName[]) simplifySpaceshipOperator(); + // @.. + simplifyAt(); + // Bail out if code is garbage if (mTimerResults) { Timer t("Tokenizer::simplifyTokens1::simplifyTokenList1::findGarbageCode", mSettings.showtime, mTimerResults); @@ -5720,9 +5723,6 @@ bool Tokenizer::simplifyTokenList1(const char FileName[]) // Put ^{} statements in asm() simplifyAsm2(); - // @.. - simplifyAt(); - // When the assembly code has been cleaned up, no @ is allowed for (const Token *tok = list.front(); tok; tok = tok->next()) { if (tok->str() == "(") { @@ -9609,9 +9609,9 @@ void Tokenizer::simplifyAt() std::set var; for (Token *tok = list.front(); tok; tok = tok->next()) { - if (Token::Match(tok, "%name%|] @ %num%|%name%|(")) { + if (Token::Match(tok, "%name%|] @ %num%|%name%|%str%|(")) { const Token *end = tok->tokAt(2); - if (end->isNumber()) + if (end->isLiteral()) end = end->next(); else if (end->str() == "(") { int par = 0; @@ -9632,7 +9632,7 @@ void Tokenizer::simplifyAt() if (Token::Match(end, ": %num% ;")) end = end->tokAt(2); - if (end && end->str() == ";") { + if (Token::Match(end, "[;=]")) { if (tok->isName()) var.insert(tok->str()); tok->isAtAddress(true); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index c60cc947901..b95c544cc37 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -936,6 +936,8 @@ class TestTokenizer : public TestFixture { ASSERT_EQUALS("int x [ 10 ] ;", tokenizeAndStringify("int x[10]@0x100;")); ASSERT_EQUALS("interrupt@ f ( ) { }", tokenizeAndStringify("@interrupt f() {}")); + + ASSERT_EQUALS("const short MyVariable = 0xF0F0 ;", tokenizeAndStringify("const short MyVariable @ \"MYOWNSECTION\" = 0xF0F0; ")); // #12602 } void inlineasm() {