From bd0a935d8a696c2f314bcc1938ba40d5768333c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 4 Dec 2018 19:33:39 +0100 Subject: [PATCH] Tokenizer: Improved handling of compiler extensions that use @ (see https://sourceforge.net/p/cppcheck/discussion/general/thread/8f618cb0a3) --- lib/tokenize.cpp | 18 +++++++++++++++++- test/testtokenize.cpp | 3 +++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 76f9f9c19..5959fb39d 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -9385,12 +9385,28 @@ void Tokenizer::simplifyAsm2() void Tokenizer::simplifyAt() { + std::set var; + for (Token *tok = list.front(); tok; tok = tok->next()) { if (Token::Match(tok, "%name% @ %num% ;")) { + var.insert(tok->str()); tok->isAtAddress(true); Token::eraseTokens(tok,tok->tokAt(3)); } - if (Token::Match(tok, "@ far|near|interrupt")) { + if (Token::Match(tok, "%name% @ %num% : %num% ;")) { + var.insert(tok->str()); + tok->isAtAddress(true); + Token::eraseTokens(tok,tok->tokAt(5)); + } + if (Token::Match(tok, "%name% @ %name% : %num% ;") && var.find(tok->strAt(2)) != var.end()) { + var.insert(tok->str()); + tok->isAtAddress(true); + Token::eraseTokens(tok,tok->tokAt(5)); + } + + // keywords in compiler from cosmic software for STM8 + // TODO: Should use platform configuration. + if (Token::Match(tok, "@ builtin|eeprom|far|inline|interrupt|near|noprd|nostack|nosvf|packed|stack|svlreg|tiny|vector")) { tok->str(tok->next()->str() + "@"); tok->deleteNext(); } diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index c59bfe69e..f30dd1e4a 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -1069,6 +1069,9 @@ private: void simplifyAt() { ASSERT_EQUALS("int x ;", tokenizeAndStringify("int x@123;")); + ASSERT_EQUALS("int x ;", tokenizeAndStringify("bool x@123:1;")); + ASSERT_EQUALS("char PORTB ; bool PB3 ;", tokenizeAndStringify("char PORTB @ 0x10; bool PB3 @ PORTB:3;\n")); + ASSERT_EQUALS("interrupt@ f ( ) { }", tokenizeAndStringify("@interrupt f() {}")); }