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 ;
@@ -4018,41 +4017,20 @@ class ExpandSynthesizedMemberMacroRequest
4018
4017
void noteCycleStep (DiagnosticEngine &diags) const ;
4019
4018
};
4020
4019
4021
- // / Load a plugin module with the given name.
4022
- // /
4023
- // /
4020
+ // / Represent a loaded plugin either an in-process library or an executable.
4024
4021
class LoadedCompilerPlugin {
4025
- enum class PluginKind : uint8_t {
4026
- None,
4027
- InProcess,
4028
- Executable,
4029
- };
4030
- PluginKind kind;
4031
- void *ptr;
4032
-
4033
- LoadedCompilerPlugin (PluginKind kind, void *ptr) : kind(kind), ptr(ptr) {
4034
- assert (ptr != nullptr || kind == PluginKind::None);
4035
- }
4022
+ llvm::PointerUnion<LoadedLibraryPlugin *, LoadedExecutablePlugin *> ptr;
4036
4023
4037
4024
public:
4038
- LoadedCompilerPlugin (std::nullptr_t ) : kind(PluginKind::None), ptr(nullptr ) {}
4039
-
4040
- static LoadedCompilerPlugin inProcess (LoadedLibraryPlugin *ptr) {
4041
- return {PluginKind::InProcess, ptr};
4042
- }
4043
- static LoadedCompilerPlugin executable (LoadedExecutablePlugin *ptr) {
4044
- return {PluginKind::Executable, ptr};
4045
- }
4025
+ LoadedCompilerPlugin (std::nullptr_t ) : ptr(nullptr ) {}
4026
+ LoadedCompilerPlugin (LoadedLibraryPlugin *ptr) : ptr(ptr){};
4027
+ LoadedCompilerPlugin (LoadedExecutablePlugin *ptr) : ptr(ptr){};
4046
4028
4047
- LoadedLibraryPlugin *getAsInProcessPlugin () const {
4048
- return kind == PluginKind::InProcess
4049
- ? static_cast <LoadedLibraryPlugin *>(ptr)
4050
- : nullptr ;
4029
+ LoadedLibraryPlugin *getAsLibraryPlugin () const {
4030
+ return ptr.dyn_cast <LoadedLibraryPlugin *>();
4051
4031
}
4052
4032
LoadedExecutablePlugin *getAsExecutablePlugin () const {
4053
- return kind == PluginKind::Executable
4054
- ? static_cast <LoadedExecutablePlugin *>(ptr)
4055
- : nullptr ;
4033
+ return ptr.dyn_cast <LoadedExecutablePlugin *>();
4056
4034
}
4057
4035
};
4058
4036
0 commit comments