2525#include " swift/AST/Decl.h"
2626#include " swift/AST/DeclContext.h"
2727#include " swift/AST/DeclNameLoc.h"
28+ #include " swift/AST/FreestandingMacroExpansion.h"
2829#include " swift/AST/FunctionRefKind.h"
2930#include " swift/AST/ProtocolConformanceRef.h"
3031#include " swift/AST/TypeAlignments.h"
@@ -6214,10 +6215,10 @@ class TypeJoinExpr final : public Expr,
62146215
62156216// / An invocation of a macro expansion, spelled with `#` for freestanding
62166217// / macros or `@` for attached macros.
6217- class MacroExpansionExpr final : public Expr {
6218+ class MacroExpansionExpr final : public Expr,
6219+ public FreestandingMacroExpansion {
62186220private:
62196221 DeclContext *DC;
6220- MacroExpansionInfo *info;
62216222 Expr *Rewritten;
62226223 MacroRoles Roles;
62236224 MacroExpansionDecl *SubstituteDecl;
@@ -6226,47 +6227,31 @@ class MacroExpansionExpr final : public Expr {
62266227 enum : unsigned { InvalidDiscriminator = 0xFFFF };
62276228
62286229 explicit MacroExpansionExpr (DeclContext *dc, MacroExpansionInfo *info,
6229- MacroRoles roles,
6230- bool isImplicit = false ,
6230+ MacroRoles roles, bool isImplicit = false ,
62316231 Type ty = Type())
62326232 : Expr(ExprKind::MacroExpansion, isImplicit, ty),
6233- DC(dc) , info(info ), Rewritten( nullptr ), Roles(roles ),
6234- SubstituteDecl(nullptr ) {
6233+ FreestandingMacroExpansion(FreestandingMacroKind::Expr , info), DC(dc ),
6234+ Rewritten( nullptr ), Roles(roles), SubstituteDecl(nullptr ) {
62356235 Bits.MacroExpansionExpr .Discriminator = InvalidDiscriminator;
62366236 }
62376237
6238- explicit MacroExpansionExpr (DeclContext *dc,
6239- SourceLoc sigilLoc, DeclNameRef macroName,
6240- DeclNameLoc macroNameLoc,
6241- SourceLoc leftAngleLoc,
6242- ArrayRef<TypeRepr *> genericArgs,
6243- SourceLoc rightAngleLoc,
6244- ArgumentList *argList,
6245- MacroRoles roles,
6246- bool isImplicit = false ,
6247- Type ty = Type());
6248-
6249- DeclNameRef getMacroName () const { return info->MacroName ; }
6250- DeclNameLoc getMacroNameLoc () const { return info->MacroNameLoc ; }
6238+ static MacroExpansionExpr *
6239+ create (DeclContext *dc, SourceLoc sigilLoc, DeclNameRef macroName,
6240+ DeclNameLoc macroNameLoc, SourceLoc leftAngleLoc,
6241+ ArrayRef<TypeRepr *> genericArgs, SourceLoc rightAngleLoc,
6242+ ArgumentList *argList, MacroRoles roles, bool isImplicit = false ,
6243+ Type ty = Type());
62516244
62526245 Expr *getRewritten () const { return Rewritten; }
62536246 void setRewritten (Expr *rewritten) { Rewritten = rewritten; }
62546247
6255- ArrayRef<TypeRepr *> getGenericArgs () const { return info->GenericArgs ; }
6256-
6257- SourceRange getGenericArgsRange () const {
6258- return SourceRange (info->LeftAngleLoc , info->RightAngleLoc );
6248+ ArgumentList *getArgs () const {
6249+ return FreestandingMacroExpansion::getArgs ();
62596250 }
62606251
6261- ArgumentList *getArgs () const { return info->ArgList ; }
6262- void setArgs (ArgumentList *newArgs) { info->ArgList = newArgs; }
6263-
62646252 MacroRoles getMacroRoles () const { return Roles; }
62656253
6266- SourceLoc getLoc () const { return info->SigilLoc ; }
6267-
6268- ConcreteDeclRef getMacroRef () const { return info->macroRef ; }
6269- void setMacroRef (ConcreteDeclRef ref) { info->macroRef = ref; }
6254+ SourceLoc getLoc () const { return getPoundLoc (); }
62706255
62716256 DeclContext *getDeclContext () const { return DC; }
62726257 void setDeclContext (DeclContext *dc) { DC = dc; }
@@ -6289,16 +6274,19 @@ class MacroExpansionExpr final : public Expr {
62896274 Bits.MacroExpansionExpr .Discriminator = discriminator;
62906275 }
62916276
6292- MacroExpansionInfo * getExpansionInfo () const { return info; }
6293-
6294- SourceRange getSourceRange () const ;
6277+ SourceRange getSourceRange () const {
6278+ return getExpansionInfo ()-> getSourceRange ();
6279+ }
62956280
62966281 MacroExpansionDecl *createSubstituteDecl ();
62976282 MacroExpansionDecl *getSubstituteDecl () const ;
62986283
62996284 static bool classof (const Expr *E) {
63006285 return E->getKind () == ExprKind::MacroExpansion;
63016286 }
6287+ static bool classof (const FreestandingMacroExpansion *expansion) {
6288+ return expansion->getFreestandingMacroKind () == FreestandingMacroKind::Expr;
6289+ }
63026290};
63036291
63046292inline bool Expr::isInfixOperator () const {
0 commit comments