Skip to content

Commit

Permalink
Issue #31 revisited
Browse files Browse the repository at this point in the history
  • Loading branch information
datadiode committed Aug 29, 2024
1 parent e229f86 commit 414909d
Showing 1 changed file with 6 additions and 27 deletions.
33 changes: 6 additions & 27 deletions simplecpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,6 @@ static const simplecpp::TokenString ONCE("once");

static const simplecpp::TokenString HAS_INCLUDE("__has_include");

static const simplecpp::TokenString INNER_COMMA(",,");

template<class T> static std::string toString(T t)
{
// NOLINTNEXTLINE(misc-const-correctness) - false positive
Expand Down Expand Up @@ -1623,10 +1621,6 @@ namespace simplecpp {
rawtok = rawtok2->next;
}
output->takeTokens(output2);
for (Token* tok = output->front(); tok; tok = tok->next) {
if (tok->str() == INNER_COMMA)
tok->setstr(",");
}
return rawtok;
}

Expand Down Expand Up @@ -1796,25 +1790,9 @@ namespace simplecpp {
tok = expandHash(tokens, rawloc, tok, macros, expandedmacros, parametertokens);
} else {
if (!expandArg(tokens, tok, rawloc, macros, expandedmacros, parametertokens)) {
bool expanded = false;
const MacroMap::const_iterator it = macros.find(tok->str());
if (it != macros.end() && expandedmacros.find(tok->str()) == expandedmacros.end()) {
const Macro &m = it->second;
if (!m.functionLike()) {
Token* mtok = tokens->back();
m.expand(tokens, rawloc, tok, macros, expandedmacros);
for (mtok = mtok->next; mtok; mtok = mtok->next) {
if (mtok->op == ',')
mtok->setstr(INNER_COMMA);
}
expanded = true;
}
}
if (!expanded) {
tokens->push_back(new Token(*tok));
if (tok->macro.empty() && (par > 0 || tok->str() != "("))
tokens->back()->macro = name();
}
tokens->push_back(new Token(*tok));
if (tok->macro.empty() && (par > 0 || tok->str() != "("))
tokens->back()->macro = name();
}

if (tok->op == '(')
Expand Down Expand Up @@ -2139,9 +2117,10 @@ namespace simplecpp {
return true;
for (const Token *partok = parametertokens[argnr]->next; partok != parametertokens[argnr + 1U];) {
const MacroMap::const_iterator it = macros.find(partok->str());
if (it != macros.end() && !partok->isExpandedFrom(&it->second) && (partok->str() == name() || expandedmacros.find(partok->str()) == expandedmacros.end()))
if (it != macros.end() && !partok->isExpandedFrom(&it->second) && (partok->str() == name() || expandedmacros.find(partok->str()) == expandedmacros.end())) {
std::set<TokenString> expandedmacros;
partok = it->second.expand(output, loc, partok, macros, expandedmacros);
else {
} else {
output->push_back(newMacroToken(partok->str(), loc, isReplaced(expandedmacros), partok));
output->back()->macro = partok->macro;
partok = partok->next;
Expand Down

0 comments on commit 414909d

Please sign in to comment.