diff --git a/simplecpp.cpp b/simplecpp.cpp index 2a91c3b3..1e1a0074 100755 --- a/simplecpp.cpp +++ b/simplecpp.cpp @@ -1597,6 +1597,18 @@ namespace simplecpp { return invalidHashHash(loc, macroName, "Combining '\\"+ tokenA->str()+ "' and '"+ strAB.substr(tokenA->str().size()) + "' yields universal character '\\" + strAB + "'. This is undefined behavior according to C standard chapter 5.1.1.2, paragraph 4."); } }; + + mutable std::set expandedToks; + + void addExpander(const Token *tok) const + { + expandedToks.insert(tok); + } + + bool expandsTok(const Token *tok) const + { + return expandedToks.find(tok) != expandedToks.end(); + } private: /** Create new token where Token::macro is set for replaced tokens */ Token *newMacroToken(const TokenString &str, const Location &loc, bool replaced, const Token *expandedFromToken=nullptr) const { @@ -2023,7 +2035,7 @@ 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() && !it->second.expandsTok(partok) && (partok->str() == name() || expandedmacros.find(partok->str()) == expandedmacros.end())) partok = it->second.expand(output, loc, partok, macros, expandedmacros); else { output->push_back(newMacroToken(partok->str(), loc, isReplaced(expandedmacros), partok)); @@ -2205,6 +2217,10 @@ namespace simplecpp { }; } +void simplecpp::Token::setExpandedFrom(const Token *tok, const Macro* m) { + m->addExpander(this); +} + namespace simplecpp { std::string convertCygwinToWindowsPath(const std::string &cygwinPath) diff --git a/simplecpp.h b/simplecpp.h index 1857908d..38613ca5 100755 --- a/simplecpp.h +++ b/simplecpp.h @@ -158,13 +158,7 @@ namespace simplecpp { return tok; } - void setExpandedFrom(const Token *tok, const Macro* m) { - mExpandedFrom = tok->mExpandedFrom; - mExpandedFrom.insert(m); - } - bool isExpandedFrom(const Macro* m) const { - return mExpandedFrom.find(m) != mExpandedFrom.end(); - } + void setExpandedFrom(const Token *tok, const Macro* m); void printAll() const; void printOut() const;