Refactoring Tokenizer

Create Tokenizer::simplifyAsm2(), skip simplifyExternC() in C code and
simplifyBorland() on non-Microsoft or C code
This commit is contained in:
amai2012 2015-06-16 20:53:11 +02:00
parent e32257db0a
commit 919fcb38f5
2 changed files with 53 additions and 33 deletions

View File

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

View File

@ -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.
*/