================
@@ -132,6 +133,41 @@ MacroExpansionContext::getOriginalText(SourceLocation
MacroExpansionLoc) const {
LangOpts);
}
+std::optional<StringRef> MacroExpansionContext::getFormattedExpandedText(
+ SourceLocation MacroExpansionLoc, bool ShouldFormatMacrosPlist) const {
+ std::optional<StringRef> ExpandedText = getExpandedText(MacroExpansionLoc);
+ if (!ExpandedText)
+ return std::nullopt;
+
+ if (!ShouldFormatMacrosPlist)
+ return ExpandedText;
+
+ auto CachedIt = FormattedExpandedTokens.find(MacroExpansionLoc);
+ if (CachedIt != FormattedExpandedTokens.end())
+ return StringRef(CachedIt->getSecond());
+
+ clang::format::FormatStyle Style = clang::format::getLLVMStyle();
+
+ std::string MacroCodeBlock = ExpandedText->str();
+
+ std::vector<clang::tooling::Range> Ranges;
+ Ranges.emplace_back(0, MacroCodeBlock.length());
+
+ auto Replacements = clang::format::reformat(Style, MacroCodeBlock, Ranges,
+ "<macro-expansion>");
+
+ auto Result =
----------------
NagyDonat wrote:
Using `auto` makes these two declarations a bit cryptic -- unless the types are
complex and ugly, I would prefer spelling them out explicitly to make the code
easier to read. (I know that many IDEs show the type in tooltips, but it is not
available e.g. in this review.)
(Note that e.g. `auto CachedIt` is fine, because (1) it is well-known that
`find` returns an iterator (2) iterator types are complex and ugly.)
https://github.com/llvm/llvm-project/pull/156046
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits