[clang] [Clang] [C++26] Iterating expansion statements using string injection (PR #208877)
Ambrose Leeb via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 4 10:16:41 PDT 2026
================
@@ -855,6 +855,31 @@ enum AttrName { Target, TargetClones, TargetVersion };
void inferNoReturnAttr(Sema &S, Decl *D);
+namespace sema {
+/// Proxy class to parse a list of tokens and/or code strings.
+///
+/// This is really intended to provide access to 'Parser' without making the
+/// Sema library depend on the Parser library. We sometimes may want to generate
+/// implicit AST nodes, but doing so by calling various ActOnXY() functions in
+/// hopefully the right order and with the right arguments is both verbose and
+/// fragile; instead, we'd much rather write regular C++ code and just parse it;
+/// the APIs defined in this class facilitate this.
+class TokenInjectionHandler {
+protected:
+ TokenInjectionHandler() = default;
+
+public:
+ virtual ~TokenInjectionHandler() = default;
+
+ /// Parse 'Code' as a single expression. Any identifier token whose name is
+ /// equal to a key in 'Replacements' will be replaced with the corresponding
+ /// token in the map before parsing.
+ virtual ExprResult
+ ParseAsExpression(StringRef Code, const llvm::StringMap<Token> &Replacements,
----------------
Sirraide wrote:
Yes, the replacements change on each call because they contain annotation tokens that contain a pointer to a particular expression, which is different for every expansion statement
https://github.com/llvm/llvm-project/pull/208877
More information about the cfe-commits
mailing list