Tokenizer: Improved handling of compiler extensions that use @ (see https://sourceforge.net/p/cppcheck/discussion/general/thread/8f618cb0a3)

This commit is contained in:
Daniel Marjamäki 2018-12-04 19:33:39 +01:00
parent 88c61e8d1e
commit bd0a935d8a
2 changed files with 20 additions and 1 deletions

View File

@ -9385,12 +9385,28 @@ void Tokenizer::simplifyAsm2()
void Tokenizer::simplifyAt()
{
std::set<std::string> 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();
}

View File

@ -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() {}"));
}