diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index ae3fe503d..a9aa2bd53 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -1975,6 +1975,8 @@ void Tokenizer::concatenateNegativeNumberAndAnyPositive() void Tokenizer::simplifyExternC() { + if (isC()) + return; for (Token *tok = list.front(); tok; tok = tok->next()) { if (Token::Match(tok, "extern \"C\" {|")) { if (tok->strAt(2) == "{") { @@ -3463,39 +3465,7 @@ bool Tokenizer::simplifyTokenList1(const char FileName[]) return false; // Put ^{} statements in asm() - for (Token *tok = list.front(); tok; tok = tok->next()) { - if (Token::simpleMatch(tok, "^ {")) { - Token * start = tok; - while (start && !Token::Match(start, "[;{}]")) - start = start->previous(); - if (start) - start = start->next(); - const Token *last = tok->next()->link(); - if (start != tok) { - last = last->next(); - while (last && !Token::Match(last->next(), "[;{}()]")) - last = last->next(); - } - if (start && last) { - std::string asmcode(start->str()); - while (start->next() != last) { - asmcode += start->next()->str(); - start->deleteNext(); - } - asmcode += last->str(); - start->deleteNext(); - start->insertToken(";"); - start->insertToken(")"); - start->insertToken("\"" + asmcode + "\""); - start->insertToken("("); - start->str("asm"); - start->link(nullptr); - start->next()->link(start->tokAt(3)); - start->tokAt(3)->link(start->next()); - tok = start->tokAt(4); - } - } - } + simplifyAsm2(); // When the assembly code has been cleaned up, no @ is allowed for (const Token *tok = list.front(); tok; tok = tok->next()) { @@ -9522,6 +9492,44 @@ void Tokenizer::simplifyAsm() } } +void Tokenizer::simplifyAsm2() +{ + // Put ^{} statements in asm() + for (Token *tok = list.front(); tok; tok = tok->next()) { + if (Token::simpleMatch(tok, "^ {")) { + Token * start = tok; + while (start && !Token::Match(start, "[;{}]")) + start = start->previous(); + if (start) + start = start->next(); + const Token *last = tok->next()->link(); + if (start != tok) { + last = last->next(); + while (last && !Token::Match(last->next(), "[;{}()]")) + last = last->next(); + } + if (start && last) { + std::string asmcode(start->str()); + while (start->next() != last) { + asmcode += start->next()->str(); + start->deleteNext(); + } + asmcode += last->str(); + start->deleteNext(); + start->insertToken(";"); + start->insertToken(")"); + start->insertToken("\"" + asmcode + "\""); + start->insertToken("("); + start->str("asm"); + start->link(nullptr); + start->next()->link(start->tokAt(3)); + start->tokAt(3)->link(start->next()); + tok = start->tokAt(4); + } + } + } +} + // Simplify bitfields void Tokenizer::simplifyBitfields() { @@ -9841,6 +9849,13 @@ void Tokenizer::simplifyMicrosoftStringFunctions() // Remove Borland code void Tokenizer::simplifyBorland() { + // skip if not Windows + if (_settings->platformType != Settings::Win32A && + _settings->platformType != Settings::Win32W && + _settings->platformType != Settings::Win64) + return; + if (isC()) + return; for (Token *tok = list.front(); tok; tok = tok->next()) { if (Token::Match(tok, "( __closure * %name% )")) { tok->deleteNext(); diff --git a/lib/tokenize.h b/lib/tokenize.h index 736717ae3..91d41499c 100644 --- a/lib/tokenize.h +++ b/lib/tokenize.h @@ -620,6 +620,11 @@ public: */ void simplifyAsm(); + /** + * asm heuristics, Put ^{} statements in asm() + */ + void simplifyAsm2(); + /** * Simplify bitfields - the field width is removed as we don't use it. */