26
26
#include " swift/AST/Type.h"
27
27
#include " swift/AST/Evaluator.h"
28
28
#include " swift/AST/Pattern.h"
29
+ #include " swift/AST/PluginRegistry.h"
29
30
#include " swift/AST/ProtocolConformance.h"
30
31
#include " swift/AST/SimpleRequest.h"
31
32
#include " swift/AST/SourceFile.h"
@@ -49,8 +50,6 @@ struct ExternalMacroDefinition;
49
50
class ClosureExpr ;
50
51
class GenericParamList ;
51
52
class LabeledStmt ;
52
- class LoadedExecutablePlugin ;
53
- class LoadedLibraryPlugin ;
54
53
class MacroDefinition ;
55
54
class PrecedenceGroupDecl ;
56
55
class PropertyWrapperInitializerInfo ;
@@ -3999,41 +3998,20 @@ class ExpandSynthesizedMemberMacroRequest
3999
3998
bool isCached () const { return true ; }
4000
3999
};
4001
4000
4002
- // / Load a plugin module with the given name.
4003
- // /
4004
- // /
4001
+ // / Represent a loaded plugin either an in-process library or an executable.
4005
4002
class LoadedCompilerPlugin {
4006
- enum class PluginKind : uint8_t {
4007
- None,
4008
- InProcess,
4009
- Executable,
4010
- };
4011
- PluginKind kind;
4012
- void *ptr;
4013
-
4014
- LoadedCompilerPlugin (PluginKind kind, void *ptr) : kind(kind), ptr(ptr) {
4015
- assert (ptr != nullptr || kind == PluginKind::None);
4016
- }
4003
+ llvm::PointerUnion<LoadedLibraryPlugin *, LoadedExecutablePlugin *> ptr;
4017
4004
4018
4005
public:
4019
- LoadedCompilerPlugin (std::nullptr_t ) : kind(PluginKind::None), ptr(nullptr ) {}
4020
-
4021
- static LoadedCompilerPlugin inProcess (LoadedLibraryPlugin *ptr) {
4022
- return {PluginKind::InProcess, ptr};
4023
- }
4024
- static LoadedCompilerPlugin executable (LoadedExecutablePlugin *ptr) {
4025
- return {PluginKind::Executable, ptr};
4026
- }
4006
+ LoadedCompilerPlugin (std::nullptr_t ) : ptr(nullptr ) {}
4007
+ LoadedCompilerPlugin (LoadedLibraryPlugin *ptr) : ptr(ptr){};
4008
+ LoadedCompilerPlugin (LoadedExecutablePlugin *ptr) : ptr(ptr){};
4027
4009
4028
- LoadedLibraryPlugin *getAsInProcessPlugin () const {
4029
- return kind == PluginKind::InProcess
4030
- ? static_cast <LoadedLibraryPlugin *>(ptr)
4031
- : nullptr ;
4010
+ LoadedLibraryPlugin *getAsLibraryPlugin () const {
4011
+ return ptr.dyn_cast <LoadedLibraryPlugin *>();
4032
4012
}
4033
4013
LoadedExecutablePlugin *getAsExecutablePlugin () const {
4034
- return kind == PluginKind::Executable
4035
- ? static_cast <LoadedExecutablePlugin *>(ptr)
4036
- : nullptr ;
4014
+ return ptr.dyn_cast <LoadedExecutablePlugin *>();
4037
4015
}
4038
4016
};
4039
4017
0 commit comments