diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index 178e38b58..1ac478bab 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -441,6 +441,7 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string ErrorLogger::ErrorMessage::FileLocation loc; if (e.token) { loc.line = e.token->linenr(); + loc.col = e.token->col(); const std::string fixedpath = Path::toNativeSeparators(mTokenizer.list.file(e.token)); loc.setfile(fixedpath); } else { diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 63db2c9bb..e10ea915b 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -3817,11 +3817,12 @@ bool Tokenizer::simplifyTokenList1(const char FileName[]) // When the assembly code has been cleaned up, no @ is allowed for (const Token *tok = list.front(); tok; tok = tok->next()) { if (tok->str() == "(") { + const Token *tok1 = tok; tok = tok->link(); if (!tok) - syntaxError(nullptr); + syntaxError(tok1); } else if (tok->str() == "@") { - syntaxError(nullptr); + syntaxError(tok); } } @@ -9408,6 +9409,12 @@ void Tokenizer::simplifyAt() Token::eraseTokens(tok,tok->tokAt(5)); } + // array declaration + if (Token::Match(tok, "] @ %num% ;")) { + tok->isAtAddress(true); + Token::eraseTokens(tok,tok->tokAt(3)); + } + // 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")) { diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 862e69e78..4a286ed05 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -1073,6 +1073,8 @@ private: ASSERT_EQUALS("bool x ;", tokenizeAndStringify("bool x@123:1;")); ASSERT_EQUALS("char PORTB ; bool PB3 ;", tokenizeAndStringify("char PORTB @ 0x10; bool PB3 @ PORTB:3;\n")); + ASSERT_EQUALS("int x [ 10 ] ;", tokenizeAndStringify("int x[10]@0x100;")); + ASSERT_EQUALS("interrupt@ f ( ) { }", tokenizeAndStringify("@interrupt f() {}")); }