@@ -96,6 +96,13 @@ class MacroExpansionContext {
9696 std::optional<StringRef>
9797 getOriginalText (SourceLocation MacroExpansionLoc) const ;
9898
99+ // / \param MacroExpansionLoc Must be the expansion location of a macro.
100+ // / \return A formatted representation of the textual representation of the
101+ // / token sequence which was substituted in place of the macro.
102+ // / If no macro was expanded at that location, returns std::nullopt.
103+ std::optional<StringRef>
104+ getFormattedExpandedText (SourceLocation MacroExpansionLoc) const ;
105+
99106 LLVM_DUMP_METHOD void dumpExpansionRangesToStream (raw_ostream &OS) const ;
100107 LLVM_DUMP_METHOD void dumpExpandedTextsToStream (raw_ostream &OS) const ;
101108 LLVM_DUMP_METHOD void dumpExpansionRanges () const ;
@@ -106,6 +113,7 @@ class MacroExpansionContext {
106113 using MacroExpansionText = SmallString<40 >;
107114 using ExpansionMap = llvm::DenseMap<SourceLocation, MacroExpansionText>;
108115 using ExpansionRangeMap = llvm::DenseMap<SourceLocation, SourceLocation>;
116+ using FormattedExpansionMap = llvm::DenseMap<SourceLocation, std::string>;
109117
110118 // / Associates the textual representation of the expanded tokens at the given
111119 // / macro expansion location.
@@ -115,6 +123,9 @@ class MacroExpansionContext {
115123 // / substitution starting from a given macro expansion location.
116124 ExpansionRangeMap ExpansionRanges;
117125
126+ // / Caches formatted macro expansions keyed by expansion location.
127+ mutable FormattedExpansionMap FormattedExpandedTokens;
128+
118129 Preprocessor *PP = nullptr ;
119130 SourceManager *SM = nullptr ;
120131 const LangOptions &LangOpts;
0 commit comments