diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 56498b0d786..4d38a749845 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -5499,6 +5499,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); @@ -5710,9 +5713,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() == "(") { @@ -9599,9 +9599,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; @@ -9622,7 +9622,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 81c850b3613..4f4ac10d249 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -938,6 +938,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() {