|
13 | 13 | #include "SemaFixture.h"
|
14 | 14 | #include "swift/AST/Module.h"
|
15 | 15 | #include "swift/AST/ParseRequests.h"
|
16 |
| -#include "swift/Strings.h" |
| 16 | +#include "swift/AST/SourceFile.h" |
| 17 | +#include "swift/Basic/LLVMInitialize.h" |
| 18 | +#include "swift/ClangImporter/ClangImporter.h" |
| 19 | +#include "swift/Serialization/SerializedModuleLoader.h" |
17 | 20 | #include "swift/Subsystems.h"
|
18 | 21 |
|
19 | 22 | using namespace swift;
|
20 | 23 | using namespace swift::unittest;
|
21 | 24 |
|
| 25 | +using ModuleDecl = SourceFile::ImportedModuleDesc; |
| 26 | + |
22 | 27 | SemaTest::SemaTest()
|
23 | 28 | : Context(*ASTContext::get(LangOpts, TypeCheckerOpts, SearchPathOpts,
|
24 | 29 | ClangImporterOpts, SourceMgr, Diags)) {
|
| 30 | + INITIALIZE_LLVM(); |
| 31 | + |
25 | 32 | registerParseRequestFunctions(Context.evaluator);
|
26 | 33 | registerTypeCheckerRequestFunctions(Context.evaluator);
|
27 |
| - auto stdlibID = Context.getIdentifier(STDLIB_NAME); |
28 |
| - auto *module = ModuleDecl::create(stdlibID, Context); |
29 |
| - Context.addLoadedModule(module); |
30 | 34 |
|
31 |
| - FileForLookups = new (Context) SourceFile(*module, SourceFileKind::Library, |
32 |
| - /*buffer*/ None); |
33 |
| - module->addFile(*FileForLookups); |
| 35 | + Context.addModuleLoader(ImplicitSerializedModuleLoader::create(Context)); |
| 36 | + Context.addModuleLoader(ClangImporter::create(Context), /*isClang=*/true); |
| 37 | + |
| 38 | + auto *stdlib = Context.getStdlibModule(/*loadIfAbsent=*/true); |
| 39 | + assert(stdlib && "Failed to load standard library"); |
| 40 | + |
| 41 | + auto *module = |
| 42 | + ModuleDecl::create(Context.getIdentifier("SemaTests"), Context); |
| 43 | + |
| 44 | + MainFile = new (Context) SourceFile(*module, SourceFileKind::Main, |
| 45 | + /*buffer=*/None); |
| 46 | + |
| 47 | + auto stdlibImport = |
| 48 | + ModuleDesc({ImportPath::Access(), stdlib}, /*options=*/{}); |
| 49 | + |
| 50 | + MainFile->setImports(stdlibImport); |
| 51 | + module->addFile(*MainFile); |
34 | 52 |
|
35 | 53 | DC = module;
|
36 | 54 | }
|
0 commit comments