@@ -192,6 +192,7 @@ enum class DescriptiveDeclKind : uint8_t {
192192 Requirement,
193193 OpaqueResultType,
194194 OpaqueVarType,
195+ Macro,
195196 MacroExpansion
196197};
197198
@@ -8270,6 +8271,68 @@ class MissingMemberDecl : public Decl {
82708271 }
82718272};
82728273
8274+ // / Provides a declaration of a macro.
8275+ // /
8276+ // / Macros are defined externally via conformances to the 'Macro' type
8277+ // / that is part of swift-syntax, and are introduced into the compiler via
8278+ // / various mechanisms (built-in macros are linked in directly, plugin macros
8279+ // / are introduced via compiler plugins, and so on). They have no explicit
8280+ // / representation in the source code, but are still declarations.
8281+ class MacroDecl : public GenericContext , public ValueDecl {
8282+ public:
8283+ // / The kind of macro, which determines how it can be used in source code.
8284+ enum Kind: uint8_t {
8285+ // / An expression macro.
8286+ Expression,
8287+ };
8288+
8289+ // / Describes how the macro is implemented.
8290+ enum class ImplementationKind : uint8_t {
8291+ // / The macro is built-in to the compiler, linked against the same
8292+ // / underlying syntax tree libraries.
8293+ Builtin,
8294+
8295+ // / The macro was defined in a compiler plugin.
8296+ Plugin,
8297+ };
8298+
8299+ // / The kind of macro.
8300+ const Kind kind;
8301+
8302+ // / How the macro is implemented.
8303+ const ImplementationKind implementationKind;
8304+
8305+ // / Supplemental modules that should be imported when
8306+ const ArrayRef<ModuleDecl *> supplementalSignatureModules;
8307+
8308+ // / An opaque handle to the representation of the macro.
8309+ void * const opaqueHandle;
8310+
8311+ public:
8312+ MacroDecl (
8313+ Kind kind, ImplementationKind implementationKind, Identifier name,
8314+ ModuleDecl *owningModule,
8315+ ArrayRef<ModuleDecl *> supplementalSignatureModules,
8316+ void *opaqueHandle
8317+ );
8318+
8319+ SourceRange getSourceRange () const ;
8320+
8321+ static bool classof (const DeclContext *C) {
8322+ if (auto D = C->getAsDecl ())
8323+ return classof (D);
8324+ return false ;
8325+ }
8326+
8327+ static bool classof (const Decl *D) {
8328+ return D->getKind () == DeclKind::Macro;
8329+ }
8330+
8331+ using DeclContext::operator new ;
8332+ using DeclContext::operator delete ;
8333+ using Decl::getASTContext;
8334+ };
8335+
82738336class MacroExpansionDecl : public Decl {
82748337 SourceLoc PoundLoc;
82758338 DeclNameRef Macro;
0 commit comments