Skip to content

Commit 25e79f2

Browse files
dmcppcheckclaude
andcommitted
HideSetExpander: add substituteRange() for a range of the replacement list
__VA_OPT__ will use it for its content. No behaviour change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 7f11b76 commit 25e79f2

1 file changed

Lines changed: 18 additions & 5 deletions

File tree

‎simplecpp.cpp‎

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3286,17 +3286,18 @@ namespace simplecpp {
32863286
}
32873287

32883288
/**
3289-
* The replacement list of the macro, with the parameters replaced by the arguments.
3289+
* Tokens of the replacement list of the macro, with the parameters replaced by the
3290+
* arguments and ## done.
32903291
* @param result destination tokenlist
32913292
* @param macro the macro
32923293
* @param call the macro call
3294+
* @param begin first token in the replacement list
3295+
* @param end the token after the last one
32933296
*/
3294-
void substitute(TokenList &result, const Macro &macro, const MacroCall &call) const {
3295-
if (macro.variadicOpt)
3296-
throw unsupported(loc, "__VA_OPT__");
3297+
void substituteRange(TokenList &result, const Macro &macro, const MacroCall &call, const Token *begin, const Token *end) const {
32973298
const Token *hashHash = nullptr; // the ## before the current operand
32983299
bool previousEmpty = false; // the previous operand was empty, it is a placemarker
3299-
for (const Token *tok = macro.valueToken; tok != macro.endToken; tok = tok->next) {
3300+
for (const Token *tok = begin; tok != end; tok = tok->next) {
33003301
if (isHashHash(macro, tok)) {
33013302
if (!result.back() && !previousEmpty)
33023303
throw Macro::invalidHashHash(tok->location, macro.name(), "Missing first argument");
@@ -3323,6 +3324,18 @@ namespace simplecpp {
33233324
}
33243325
if (hashHash)
33253326
throw Macro::invalidHashHash::unexpectedNewline(hashHash->location, macro.name());
3327+
}
3328+
3329+
/**
3330+
* The replacement list of the macro, with the parameters replaced by the arguments.
3331+
* @param result destination tokenlist
3332+
* @param macro the macro
3333+
* @param call the macro call
3334+
*/
3335+
void substitute(TokenList &result, const Macro &macro, const MacroCall &call) const {
3336+
if (macro.variadicOpt)
3337+
throw unsupported(loc, "__VA_OPT__");
3338+
substituteRange(result, macro, call, macro.valueToken, macro.endToken);
33263339
for (Token *tok = result.front(); tok; tok = tok->next) {
33273340
tok->location = loc;
33283341
tok->addToHideSet(call.hideSet);

0 commit comments

Comments
 (0)