Skip to content

Commit ce06610

Browse files
committed
fix
1 parent 208326f commit ce06610

1 file changed

Lines changed: 29 additions & 24 deletions

File tree

simplecpp.cpp

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2249,33 +2249,38 @@ namespace simplecpp {
22492249
}
22502250

22512251
if (tok->str() == DEFINED) {
2252-
const Token * const tok2 = tok->next;
2253-
const Token * const tok3 = tok2 ? tok2->next : nullptr;
2254-
const Token * const tok4 = tok3 ? tok3->next : nullptr;
2255-
const Token *defToken = nullptr;
2256-
const Token *lastToken = nullptr;
2257-
if (sameline(tok, tok4) && tok2->op == '(' && tok3->name && tok4->op == ')') {
2258-
defToken = tok3;
2259-
lastToken = tok4;
2260-
} else if (sameline(tok,tok2) && tok2->name) {
2261-
defToken = lastToken = tok2;
2252+
std::string macroName;
2253+
TokenList temp(files);
2254+
const Token *argTok = tok->next;
2255+
bool expectParen = false;
2256+
if (argTok->op == '(') {
2257+
argTok = argTok->next;
2258+
expectParen = true;
22622259
}
2263-
if (defToken) {
2264-
std::string macroName = defToken->str();
2265-
if (defToken->next && defToken->next->op == '#' && defToken->next->next && defToken->next->next->op == '#' && defToken->next->next->next && defToken->next->next->next->name && sameline(defToken,defToken->next->next->next)) {
2266-
TokenList temp(files);
2267-
if (expandArg(temp, defToken, parametertokens))
2268-
macroName = temp.cback()->str();
2269-
if (expandArg(temp, defToken->next->next->next, parametertokens))
2270-
macroName += temp.cback() ? temp.cback()->str() : "";
2271-
else
2272-
macroName += defToken->next->next->next->str();
2273-
lastToken = defToken->next->next->next;
2260+
while (argTok->name) {
2261+
if (expandArg(temp, argTok, parametertokens))
2262+
macroName += temp.cback() ? temp.cback()->str() : "";
2263+
else
2264+
macroName += argTok->str();
2265+
argTok = argTok->next;
2266+
if (!sameline(tok, argTok))
2267+
break;
2268+
if (argTok && argTok->str() == "#") {
2269+
if (!argTok->next || argTok->next->str() != "#")
2270+
throw Error(argTok->location, "Expected '#'");
2271+
argTok = argTok->next->next;
2272+
} else {
2273+
break;
22742274
}
2275-
const bool def = (macros.find(macroName) != macros.end());
2276-
output.push_back(newMacroToken(def ? "1" : "0", loc, true));
2277-
return lastToken->next;
22782275
}
2276+
if (expectParen) {
2277+
if (!sameline(tok, argTok) && argTok->op != ')')
2278+
throw Error(argTok->location, "Expected ')'");
2279+
argTok = argTok->next;
2280+
}
2281+
const bool def = (macros.find(macroName) != macros.end());
2282+
output.push_back(newMacroToken(def ? "1" : "0", loc, true));
2283+
return argTok;
22792284
}
22802285

22812286
output.push_back(newMacroToken(tok->str(), loc, true, tok));

0 commit comments

Comments
 (0)