|
14 | 14 | #define SWIFT_AST_SEARCHPATHOPTIONS_H |
15 | 15 |
|
16 | 16 | #include "swift/Basic/ArrayRefView.h" |
| 17 | +#include "swift/Basic/ExternalUnion.h" |
17 | 18 | #include "swift/Basic/PathRemapper.h" |
18 | | -#include "swift/Basic/TaggedUnion.h" |
19 | 19 | #include "llvm/ADT/Hashing.h" |
20 | 20 | #include "llvm/ADT/IntrusiveRefCntPtr.h" |
21 | 21 | #include "llvm/ADT/StringMap.h" |
@@ -187,25 +187,81 @@ struct ExternalPluginSearchPathAndServerPath { |
187 | 187 | std::string ServerPath; |
188 | 188 | }; |
189 | 189 |
|
190 | | -namespace PluginSearchOption { |
191 | | -struct LoadPluginLibrary { |
192 | | - std::string LibraryPath; |
193 | | -}; |
194 | | -struct LoadPluginExecutable { |
195 | | - std::string ExecutablePath; |
196 | | - std::vector<std::string> ModuleNames; |
197 | | -}; |
198 | | -struct PluginPath { |
199 | | - std::string SearchPath; |
200 | | -}; |
201 | | -struct ExternalPluginPath { |
202 | | - std::string SearchPath; |
203 | | - std::string ServerPath; |
204 | | -}; |
| 190 | +class PluginSearchOption { |
| 191 | +public: |
| 192 | + struct LoadPluginLibrary { |
| 193 | + std::string LibraryPath; |
| 194 | + }; |
| 195 | + struct LoadPluginExecutable { |
| 196 | + std::string ExecutablePath; |
| 197 | + std::vector<std::string> ModuleNames; |
| 198 | + }; |
| 199 | + struct PluginPath { |
| 200 | + std::string SearchPath; |
| 201 | + }; |
| 202 | + struct ExternalPluginPath { |
| 203 | + std::string SearchPath; |
| 204 | + std::string ServerPath; |
| 205 | + }; |
| 206 | + |
| 207 | + enum class Kind : uint8_t { |
| 208 | + LoadPluginLibrary, |
| 209 | + LoadPluginExecutable, |
| 210 | + PluginPath, |
| 211 | + ExternalPluginPath, |
| 212 | + }; |
205 | 213 |
|
206 | | -using Value = TaggedUnion<LoadPluginLibrary, LoadPluginExecutable, PluginPath, |
207 | | - ExternalPluginPath>; |
208 | | -} // namespace PluginSearchOption |
| 214 | +private: |
| 215 | + using Members = ExternalUnionMembers<LoadPluginLibrary, LoadPluginExecutable, |
| 216 | + PluginPath, ExternalPluginPath>; |
| 217 | + static Members::Index getIndexForKind(Kind kind) { |
| 218 | + switch (kind) { |
| 219 | + case Kind::LoadPluginLibrary: |
| 220 | + return Members::indexOf<LoadPluginLibrary>(); |
| 221 | + case Kind::LoadPluginExecutable: |
| 222 | + return Members::indexOf<LoadPluginExecutable>(); |
| 223 | + case Kind::PluginPath: |
| 224 | + return Members::indexOf<PluginPath>(); |
| 225 | + case Kind::ExternalPluginPath: |
| 226 | + return Members::indexOf<ExternalPluginPath>(); |
| 227 | + } |
| 228 | + }; |
| 229 | + using Storage = ExternalUnion<Kind, Members, getIndexForKind>; |
| 230 | + |
| 231 | + Kind kind; |
| 232 | + Storage storage; |
| 233 | + |
| 234 | +public: |
| 235 | + PluginSearchOption(const LoadPluginLibrary &v) |
| 236 | + : kind(Kind::LoadPluginLibrary) { |
| 237 | + storage.emplace<LoadPluginLibrary>(kind, v); |
| 238 | + } |
| 239 | + PluginSearchOption(const LoadPluginExecutable &v) |
| 240 | + : kind(Kind::LoadPluginExecutable) { |
| 241 | + storage.emplace<LoadPluginExecutable>(kind, v); |
| 242 | + } |
| 243 | + PluginSearchOption(const PluginPath &v) : kind(Kind::PluginPath) { |
| 244 | + storage.emplace<PluginPath>(kind, v); |
| 245 | + } |
| 246 | + PluginSearchOption(const ExternalPluginPath &v) |
| 247 | + : kind(Kind::ExternalPluginPath) { |
| 248 | + storage.emplace<ExternalPluginPath>(kind, v); |
| 249 | + } |
| 250 | + |
| 251 | + Kind getKind() const { return kind; } |
| 252 | + |
| 253 | + template <typename T> |
| 254 | + const T *dyn_cast() const { |
| 255 | + if (Members::indexOf<T>() != getIndexForKind(kind)) |
| 256 | + return nullptr; |
| 257 | + return &storage.get<T>(kind); |
| 258 | + } |
| 259 | + |
| 260 | + template <typename T> |
| 261 | + const T &get() const { |
| 262 | + return storage.get<T>(kind); |
| 263 | + } |
| 264 | +}; |
209 | 265 |
|
210 | 266 | /// Options for controlling search path behavior. |
211 | 267 | class SearchPathOptions { |
@@ -383,7 +439,7 @@ class SearchPathOptions { |
383 | 439 | std::vector<std::string> RuntimeLibraryPaths; |
384 | 440 |
|
385 | 441 | /// Plugin search path options. |
386 | | - std::vector<PluginSearchOption::Value> PluginSearchOpts; |
| 442 | + std::vector<PluginSearchOption> PluginSearchOpts; |
387 | 443 |
|
388 | 444 | /// Don't look in for compiler-provided modules. |
389 | 445 | bool SkipRuntimeLibraryImportPaths = false; |
|
0 commit comments