Skip to content

Commit ec5d934

Browse files
dmcppcheckclaude
andcommitted
HideSetExpander: get the arguments as written before they are expanded
# needs the arguments that are not expanded. No behaviour change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 6604e52 commit ec5d934

1 file changed

Lines changed: 17 additions & 6 deletions

File tree

‎simplecpp.cpp‎

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3064,7 +3064,7 @@ namespace simplecpp {
30643064
const std::set<TokenString> &hs1 = call.cfront()->hideSet();
30653065
const std::set<TokenString> &hs2 = delimiters.back()->hideSet();
30663066
std::set_intersection(hs1.begin(), hs1.end(), hs2.begin(), hs2.end(), std::inserter(hideSet, hideSet.begin()));
3067-
arguments = expandArguments(macro, delimiters);
3067+
arguments = expandArguments(getArguments(macro, delimiters));
30683068
} else {
30693069
hideSet = tok->hideSet();
30703070
delete tok;
@@ -3089,21 +3089,32 @@ namespace simplecpp {
30893089
}
30903090
}
30913091

3092-
/** Each argument of the call, fully macro expanded */
3093-
std::vector<TokenList> expandArguments(const Macro &macro, const std::vector<const Token *> &delimiters) {
3092+
/** Each argument of the call, as written in the call */
3093+
std::vector<TokenList> getArguments(const Macro &macro, const std::vector<const Token *> &delimiters) const {
30943094
std::vector<TokenList> arguments;
30953095
for (std::size_t i = 0; i < macro.args.size(); ++i) {
30963096
arguments.emplace_back(files);
30973097
if (i + 1U >= delimiters.size())
30983098
continue; // empty variadic argument
3099-
Input input(nullptr);
31003099
for (const Token *tok = delimiters[i]->next; tok != delimiters[i + 1U]; tok = tok->next)
3101-
input.pending.push_back(new Token(*tok));
3102-
expandInput(arguments.back(), input);
3100+
arguments.back().push_back(new Token(*tok));
31033101
}
31043102
return arguments;
31053103
}
31063104

3105+
/** Each argument fully macro expanded, on its own */
3106+
std::vector<TokenList> expandArguments(const std::vector<TokenList> &arguments) {
3107+
std::vector<TokenList> expanded;
3108+
for (const TokenList &argument : arguments) {
3109+
expanded.emplace_back(files);
3110+
Input input(nullptr);
3111+
for (const Token *tok = argument.cfront(); tok; tok = tok->next)
3112+
input.pending.push_back(new Token(*tok));
3113+
expandInput(expanded.back(), input);
3114+
}
3115+
return expanded;
3116+
}
3117+
31073118
/** The replacement list of the macro, with the parameters replaced by the arguments */
31083119
void substitute(TokenList &result, const Macro &macro, const std::vector<TokenList> &arguments, const std::set<TokenString> &hideSet) const {
31093120
if (macro.variadicOpt)

0 commit comments

Comments
 (0)