Fixed #7203 (Better syntax error, handle array declaration with @)

This commit is contained in:
Daniel Marjamäki 2019-01-01 09:45:41 +01:00
parent c37b807613
commit 04d3672bde
3 changed files with 12 additions and 2 deletions

View File

@ -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 {

View File

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

View File

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