Bump simplecpp

This commit is contained in:
Daniel Marjamäki 2021-06-28 19:47:37 +02:00
parent 33fb855ff9
commit 2bc87d13e1
1 changed files with 13 additions and 19 deletions

View File

@ -1504,8 +1504,11 @@ namespace simplecpp {
expanded = true; expanded = true;
} }
} }
if (!expanded) if (!expanded) {
tokens->push_back(new Token(*tok)); tokens->push_back(new Token(*tok));
if (tok->macro.empty() && (par > 0 || tok->str() != "("))
tokens->back()->macro = name();
}
} }
if (tok->op == '(') if (tok->op == '(')
@ -1609,7 +1612,14 @@ namespace simplecpp {
if (sameline(tok, tok->next) && tok->next && tok->next->op == '#' && tok->next->next && tok->next->next->op == '#') { if (sameline(tok, tok->next) && tok->next && tok->next->op == '#' && tok->next->next && tok->next->next->op == '#') {
if (!sameline(tok, tok->next->next->next)) if (!sameline(tok, tok->next->next->next))
throw invalidHashHash(tok->location, name()); throw invalidHashHash(tok->location, name());
output->push_back(newMacroToken(expandArgStr(tok, parametertokens2), loc, isReplaced(expandedmacros))); TokenList new_output(files);
if (!expandArg(&new_output, tok, parametertokens2))
output->push_back(newMacroToken(tok->str(), loc, isReplaced(expandedmacros)));
else if (new_output.empty()) // placemarker token
output->push_back(newMacroToken("", loc, isReplaced(expandedmacros)));
else
for (const Token *tok2 = new_output.cfront(); tok2; tok2 = tok2->next)
output->push_back(newMacroToken(tok2->str(), loc, isReplaced(expandedmacros)));
tok = tok->next; tok = tok->next;
} else { } else {
tok = expandToken(output, loc, tok, macros, expandedmacros, parametertokens2); tok = expandToken(output, loc, tok, macros, expandedmacros, parametertokens2);
@ -1805,29 +1815,13 @@ namespace simplecpp {
partok = it->second.expand(output, loc, partok, macros, expandedmacros); partok = it->second.expand(output, loc, partok, macros, expandedmacros);
else { else {
output->push_back(newMacroToken(partok->str(), loc, isReplaced(expandedmacros))); output->push_back(newMacroToken(partok->str(), loc, isReplaced(expandedmacros)));
output->back()->macro = partok->macro;
partok = partok->next; partok = partok->next;
} }
} }
return true; return true;
} }
/**
* Get string for token. If token is argument, the expanded string is returned.
* @param tok The token
* @param parametertokens parameters given when expanding this macro
* @return string
*/
std::string expandArgStr(const Token *tok, const std::vector<const Token *> &parametertokens) const {
TokenList tokens(files);
if (expandArg(&tokens, tok, parametertokens)) {
std::string s;
for (const Token *tok2 = tokens.cfront(); tok2; tok2 = tok2->next)
s += tok2->str();
return s;
}
return tok->str();
}
/** /**
* Expand #X => "X" * Expand #X => "X"
* @param output destination tokenlist * @param output destination tokenlist