Revert "Bump simplecpp"

This reverts commit eec622b515.
This commit is contained in:
Daniel Marjamäki 2020-07-02 21:31:23 +02:00
parent eec622b515
commit 8ab305d3c9
1 changed files with 52 additions and 67 deletions

View File

@ -1026,15 +1026,15 @@ void simplecpp::TokenList::constFoldBitwise(Token *tok)
{ {
Token * const tok1 = tok; Token * const tok1 = tok;
for (const char *op = "&^|"; *op; op++) { for (const char *op = "&^|"; *op; op++) {
const std::string* alternativeOp; const std::string* altop;
if (*op == '&') if (*op == '&')
alternativeOp = &BITAND; altop = &BITAND;
else if (*op == '|') else if (*op == '|')
alternativeOp = &BITOR; altop = &BITOR;
else else
alternativeOp = &XOR; altop = &XOR;
for (tok = tok1; tok && tok->op != ')'; tok = tok->next) { for (tok = tok1; tok && tok->op != ')'; tok = tok->next) {
if (tok->op != *op && !isAlternativeBinaryOp(tok, *alternativeOp)) if (tok->op != *op && !isAlternativeBinaryOp(tok, *altop))
continue; continue;
if (!tok->previous || !tok->previous->number) if (!tok->previous || !tok->previous->number)
continue; continue;
@ -1472,7 +1472,6 @@ namespace simplecpp {
} }
const Token *appendTokens(TokenList *tokens, const Token *appendTokens(TokenList *tokens,
const Location &rawloc,
const Token *lpar, const Token *lpar,
const std::map<TokenString,Macro> &macros, const std::map<TokenString,Macro> &macros,
const std::set<TokenString> &expandedmacros, const std::set<TokenString> &expandedmacros,
@ -1484,17 +1483,17 @@ namespace simplecpp {
while (sameline(lpar, tok)) { while (sameline(lpar, tok)) {
if (tok->op == '#' && sameline(tok,tok->next) && tok->next->op == '#' && sameline(tok,tok->next->next)) { if (tok->op == '#' && sameline(tok,tok->next) && tok->next->op == '#' && sameline(tok,tok->next->next)) {
// A##B => AB // A##B => AB
tok = expandHashHash(tokens, rawloc, tok, macros, expandedmacros, parametertokens); tok = expandHashHash(tokens, tok->location, tok, macros, expandedmacros, parametertokens);
} else if (tok->op == '#' && sameline(tok, tok->next) && tok->next->op != '#') { } else if (tok->op == '#' && sameline(tok, tok->next) && tok->next->op != '#') {
tok = expandHash(tokens, rawloc, tok, macros, expandedmacros, parametertokens); tok = expandHash(tokens, tok->location, tok, macros, expandedmacros, parametertokens);
} else { } else {
if (!expandArg(tokens, tok, rawloc, macros, expandedmacros, parametertokens)) { if (!expandArg(tokens, tok, tok->location, macros, expandedmacros, parametertokens)) {
bool expanded = false; bool expanded = false;
const std::map<TokenString, Macro>::const_iterator it = macros.find(tok->str()); const std::map<TokenString, Macro>::const_iterator it = macros.find(tok->str());
if (it != macros.end() && expandedmacros.find(tok->str()) == expandedmacros.end()) { if (it != macros.end() && expandedmacros.find(tok->str()) == expandedmacros.end()) {
const Macro &m = it->second; const Macro &m = it->second;
if (!m.functionLike()) { if (!m.functionLike()) {
m.expand(tokens, rawloc, tok, macros, expandedmacros); m.expand(tokens, tok->location, tok, macros, expandedmacros);
expanded = true; expanded = true;
} }
} }
@ -1613,19 +1612,13 @@ namespace simplecpp {
hashToken = hashToken->next; hashToken = hashToken->next;
++numberOfHash; ++numberOfHash;
} }
if (numberOfHash == 4 && tok->next->location.col + 1 == tok->next->next->location.col) { if (numberOfHash == 4) {
// # ## # => ## // # ## # => ##
output->push_back(newMacroToken("##", loc, isReplaced(expandedmacros))); output->push_back(newMacroToken("##", loc, isReplaced(expandedmacros)));
tok = hashToken; tok = hashToken;
continue; continue;
} }
if (numberOfHash >= 2 && tok->location.col + 1 < tok->next->location.col) {
output->push_back(new Token(*tok));
tok = tok->next;
continue;
}
tok = tok->next; tok = tok->next;
if (tok == endToken) { if (tok == endToken) {
output->push_back(new Token(*tok->previous)); output->push_back(new Token(*tok->previous));
@ -1652,7 +1645,17 @@ namespace simplecpp {
return functionLike() ? parametertokens2.back()->next : nameTokInst->next; return functionLike() ? parametertokens2.back()->next : nameTokInst->next;
} }
const Token *recursiveExpandToken(TokenList *output, TokenList &temp, const Location &loc, const Token *tok, const std::map<TokenString,Macro> &macros, const std::set<TokenString> &expandedmacros, const std::vector<const Token*> &parametertokens) const { const Token *expandToken(TokenList *output, const Location &loc, const Token *tok, const std::map<TokenString,Macro> &macros, const std::set<TokenString> &expandedmacros, const std::vector<const Token*> &parametertokens) const {
// Not name..
if (!tok->name) {
output->push_back(newMacroToken(tok->str(), loc, true));
return tok->next;
}
// Macro parameter..
{
TokenList temp(files);
if (expandArg(&temp, tok, loc, macros, expandedmacros, parametertokens)) {
if (!(temp.cback() && temp.cback()->name && tok->next && tok->next->op == '(')) { if (!(temp.cback() && temp.cback()->name && tok->next && tok->next->op == '(')) {
output->takeTokens(temp); output->takeTokens(temp);
return tok->next; return tok->next;
@ -1678,55 +1681,37 @@ namespace simplecpp {
TokenList temp2(files); TokenList temp2(files);
temp2.push_back(new Token(temp.cback()->str(), tok->location)); temp2.push_back(new Token(temp.cback()->str(), tok->location));
const Token *tok2 = appendTokens(&temp2, loc, tok->next, macros, expandedmacros, parametertokens); const Token *tok2 = appendTokens(&temp2, tok->next, macros, expandedmacros, parametertokens);
if (!tok2) if (!tok2)
return tok->next; return tok->next;
output->takeTokens(temp); output->takeTokens(temp);
output->deleteToken(output->back()); output->deleteToken(output->back());
calledMacro.expand(output, loc, temp2.cfront(), macros, expandedmacros); calledMacro.expand(output, loc, temp2.cfront(), macros, expandedmacros);
return tok2->next; return tok2->next;
} }
const Token *expandToken(TokenList *output, const Location &loc, const Token *tok, const std::map<TokenString,Macro> &macros, const std::set<TokenString> &expandedmacros, const std::vector<const Token*> &parametertokens) const {
// Not name..
if (!tok->name) {
output->push_back(newMacroToken(tok->str(), loc, true));
return tok->next;
}
// Macro parameter..
{
TokenList temp(files);
if (expandArg(&temp, tok, loc, macros, expandedmacros, parametertokens))
return recursiveExpandToken(output, temp, loc, tok, macros, expandedmacros, parametertokens);
} }
// Macro.. // Macro..
const std::map<TokenString, Macro>::const_iterator it = macros.find(tok->str()); const std::map<TokenString, Macro>::const_iterator it = macros.find(tok->str());
if (it != macros.end() && expandedmacros.find(tok->str()) == expandedmacros.end()) { if (it != macros.end() && expandedmacros.find(tok->str()) == expandedmacros.end()) {
std::set<std::string> expandedmacros2(expandedmacros);
expandedmacros2.insert(tok->str());
const Macro &calledMacro = it->second; const Macro &calledMacro = it->second;
if (!calledMacro.functionLike()) { if (!calledMacro.functionLike())
TokenList temp(files); return calledMacro.expand(output, loc, tok, macros, expandedmacros);
calledMacro.expand(&temp, loc, tok, macros, expandedmacros);
return recursiveExpandToken(output, temp, loc, tok, macros, expandedmacros2, parametertokens);
}
if (!sameline(tok, tok->next) || tok->next->op != '(') { if (!sameline(tok, tok->next) || tok->next->op != '(') {
output->push_back(newMacroToken(tok->str(), loc, true)); output->push_back(newMacroToken(tok->str(), loc, true));
return tok->next; return tok->next;
} }
TokenList tokens(files); TokenList tokens(files);
tokens.push_back(new Token(*tok)); tokens.push_back(new Token(*tok));
const Token *tok2 = appendTokens(&tokens, loc, tok->next, macros, expandedmacros, parametertokens); const Token *tok2 = appendTokens(&tokens, tok->next, macros, expandedmacros, parametertokens);
if (!tok2) { if (!tok2) {
output->push_back(newMacroToken(tok->str(), loc, true)); output->push_back(newMacroToken(tok->str(), loc, true));
return tok->next; return tok->next;
} }
TokenList temp(files); calledMacro.expand(output, loc, tokens.cfront(), macros, expandedmacros);
calledMacro.expand(&temp, loc, tokens.cfront(), macros, expandedmacros); return tok2->next;
return recursiveExpandToken(output, temp, loc, tok2, macros, expandedmacros2, parametertokens);
} }
else if (tok->str() == DEFINED) { else if (tok->str() == DEFINED) {
@ -1894,7 +1879,7 @@ namespace simplecpp {
if (tokensB.empty() && sameline(B,B->next) && B->next->op=='(') { if (tokensB.empty() && sameline(B,B->next) && B->next->op=='(') {
const std::map<TokenString,Macro>::const_iterator it = macros.find(strAB); const std::map<TokenString,Macro>::const_iterator it = macros.find(strAB);
if (it != macros.end() && expandedmacros.find(strAB) == expandedmacros.end() && it->second.functionLike()) { if (it != macros.end() && expandedmacros.find(strAB) == expandedmacros.end() && it->second.functionLike()) {
const Token *tok2 = appendTokens(&tokens, loc, B->next, macros, expandedmacros, parametertokens); const Token *tok2 = appendTokens(&tokens, B->next, macros, expandedmacros, parametertokens);
if (tok2) if (tok2)
nextTok = tok2->next; nextTok = tok2->next;
} }