Skip to content

Commit 2677821

Browse files
dmcppcheckclaude
andcommitted
Rename Token::mExpandedFrom to mHideSet
setExpandedFrom(), markExpandedFrom() and isExpandedFrom() are renamed to setHideSet(), addToHideSet() and isInHideSet(). No behaviour change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 306faa9 commit 2677821

2 files changed

Lines changed: 20 additions & 17 deletions

File tree

‎simplecpp.cpp‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2006,7 +2006,7 @@ namespace simplecpp {
20062006
if (output2.cfront() != output2.cback() && macro2tok->str() == this->name())
20072007
break;
20082008
const MacroMap::const_iterator macro = macros.find(macro2tok->str());
2009-
if (macro == macros.end() || !macro->second.functionLike() || macro2tok->isExpandedFrom(&macro->second))
2009+
if (macro == macros.end() || !macro->second.functionLike() || macro2tok->isInHideSet(&macro->second))
20102010
break;
20112011
TokenList rawtokens2(inputFiles);
20122012
const Location loc(macro2tok->location);
@@ -2110,15 +2110,15 @@ namespace simplecpp {
21102110
* @param str the token text
21112111
* @param loc the location
21122112
* @param replaced Token::macro is set to the name of this macro
2113-
* @param expandedFromToken if not null, the new token copies its "expanded from" set and
2114-
* its whitespace, and this macro is added to the set
2113+
* @param expandedFromToken if not null, the new token copies its hide set and
2114+
* its whitespace, and this macro is added to the hide set
21152115
*/
21162116
Token *newMacroToken(const TokenString &str, const Location &loc, bool replaced, const Token *expandedFromToken=nullptr) const {
21172117
auto *tok = new Token(str,loc);
21182118
if (replaced)
21192119
tok->macro = nameTokDef->str();
21202120
if (expandedFromToken) {
2121-
tok->setExpandedFrom(expandedFromToken, this);
2121+
tok->setHideSet(expandedFromToken, this);
21222122
tok->whitespaceahead = expandedFromToken->whitespaceahead;
21232123
}
21242124
return tok;
@@ -2508,7 +2508,7 @@ namespace simplecpp {
25082508
const MacroMap::const_iterator it = macros.find(temp.cback()->str());
25092509
if (it == macros.end() || expandedmacros.find(temp.cback()->str()) != expandedmacros.end())
25102510
return nullptr;
2511-
if (!it->second.functionLike() || temp.cback()->isExpandedFrom(&it->second))
2511+
if (!it->second.functionLike() || temp.cback()->isInHideSet(&it->second))
25122512
return nullptr;
25132513
return &it->second;
25142514
}
@@ -2604,7 +2604,7 @@ namespace simplecpp {
26042604

26052605
output.push_back(newMacroToken(tok->str(), loc, true, tok));
26062606
if (it != macros.end())
2607-
output.back()->markExpandedFrom(&it->second);
2607+
output.back()->addToHideSet(&it->second);
26082608
return tok->next;
26092609
}
26102610

@@ -2680,7 +2680,7 @@ namespace simplecpp {
26802680
const Token * const argEnd = parametertokens[argnr + 1U];
26812681
for (const Token *partok = parametertokens[argnr]->next; partok != argEnd;) {
26822682
const MacroMap::const_iterator it = macros.find(partok->str());
2683-
if (it != macros.end() && !partok->isExpandedFrom(&it->second) && (partok->str() == name() || expandedmacros.find(partok->str()) == expandedmacros.end())) {
2683+
if (it != macros.end() && !partok->isInHideSet(&it->second) && (partok->str() == name() || expandedmacros.find(partok->str()) == expandedmacros.end())) {
26842684
std::set<TokenString> expandedmacros2(expandedmacros); // temporary amnesia to allow reexpansion of currently expanding macros during argument evaluation
26852685
expandedmacros2.erase(name());
26862686
TokenList temp(files);

‎simplecpp.h‎

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ namespace simplecpp {
165165
}
166166

167167
Token(const Token &tok) :
168-
macro(tok.macro), op(tok.op), comment(tok.comment), name(tok.name), number(tok.number), whitespaceahead(tok.whitespaceahead), location(tok.location), string(tok.string), mExpandedFrom(tok.mExpandedFrom) {}
168+
macro(tok.macro), op(tok.op), comment(tok.comment), name(tok.name), number(tok.number), whitespaceahead(tok.whitespaceahead), location(tok.location), string(tok.string), mHideSet(tok.mHideSet) {}
169169

170170
Token &operator=(const Token &tok) = delete;
171171

@@ -210,16 +210,19 @@ namespace simplecpp {
210210
return tok;
211211
}
212212

213-
/** Copy the "expanded from" set of tok, and add m */
214-
void setExpandedFrom(const Token *tok, const Macro* m) {
215-
mExpandedFrom = tok->mExpandedFrom;
216-
mExpandedFrom.insert(m);
213+
/**
214+
* The hide set holds the macros that this token must not be expanded into.
215+
* Set it to the hide set of tok, with m added.
216+
*/
217+
void setHideSet(const Token *tok, const Macro* m) {
218+
mHideSet = tok->mHideSet;
219+
mHideSet.insert(m);
217220
}
218-
bool isExpandedFrom(const Macro* m) const {
219-
return mExpandedFrom.find(m) != mExpandedFrom.end();
221+
bool isInHideSet(const Macro* m) const {
222+
return mHideSet.find(m) != mHideSet.end();
220223
}
221-
void markExpandedFrom(const Macro* m) {
222-
mExpandedFrom.insert(m);
224+
void addToHideSet(const Macro* m) {
225+
mHideSet.insert(m);
223226
}
224227

225228
void printAll() const;
@@ -235,7 +238,7 @@ namespace simplecpp {
235238

236239
TokenString string;
237240

238-
std::set<const Macro*> mExpandedFrom;
241+
std::set<const Macro*> mHideSet;
239242
};
240243

241244
/** Output from preprocessor */

0 commit comments

Comments
 (0)