|
18 | 18 | #ifndef SWIFT_FRONTEND_H
|
19 | 19 | #define SWIFT_FRONTEND_H
|
20 | 20 |
|
21 |
| -#include "swift/Basic/DiagnosticOptions.h" |
22 |
| -#include "swift/Basic/LangOptions.h" |
23 |
| -#include "swift/Basic/SourceManager.h" |
24 | 21 | #include "swift/AST/DiagnosticConsumer.h"
|
25 | 22 | #include "swift/AST/DiagnosticEngine.h"
|
26 | 23 | #include "swift/AST/IRGenOptions.h"
|
27 | 24 | #include "swift/AST/LinkLibrary.h"
|
28 | 25 | #include "swift/AST/Module.h"
|
29 |
| -#include "swift/AST/SearchPathOptions.h" |
30 | 26 | #include "swift/AST/SILOptions.h"
|
31 |
| -#include "swift/Parse/CodeCompletionCallbacks.h" |
32 |
| -#include "swift/Parse/Parser.h" |
| 27 | +#include "swift/AST/SearchPathOptions.h" |
| 28 | +#include "swift/Basic/DiagnosticOptions.h" |
| 29 | +#include "swift/Basic/LangOptions.h" |
| 30 | +#include "swift/Basic/SourceManager.h" |
33 | 31 | #include "swift/ClangImporter/ClangImporter.h"
|
34 | 32 | #include "swift/ClangImporter/ClangImporterOptions.h"
|
35 | 33 | #include "swift/Frontend/FrontendOptions.h"
|
36 | 34 | #include "swift/Migrator/MigratorOptions.h"
|
| 35 | +#include "swift/Parse/CodeCompletionCallbacks.h" |
| 36 | +#include "swift/Parse/Parser.h" |
| 37 | +#include "swift/SIL/SILModule.h" |
37 | 38 | #include "swift/Sema/SourceLoader.h"
|
38 | 39 | #include "swift/Serialization/Validation.h"
|
39 |
| -#include "swift/SIL/SILModule.h" |
| 40 | +#include "swift/Subsystems.h" |
40 | 41 | #include "llvm/ADT/IntrusiveRefCntPtr.h"
|
41 | 42 | #include "llvm/Option/ArgList.h"
|
42 | 43 | #include "llvm/Support/Host.h"
|
@@ -304,6 +305,16 @@ class CompilerInvocation {
|
304 | 305 | /// identifying the conditions under which the module was built, for use
|
305 | 306 | /// in generating a cached PCH file for the bridging header.
|
306 | 307 | std::string getPCHHash() const;
|
| 308 | + |
| 309 | + SourceFile::ImplicitModuleImportKind getImplicitModuleImportKind() { |
| 310 | + if (getInputKind() == InputFileKind::IFK_SIL) { |
| 311 | + return SourceFile::ImplicitModuleImportKind::None; |
| 312 | + } |
| 313 | + if (getParseStdlib()) { |
| 314 | + return SourceFile::ImplicitModuleImportKind::Builtin; |
| 315 | + } |
| 316 | + return SourceFile::ImplicitModuleImportKind::Stdlib; |
| 317 | + } |
307 | 318 | };
|
308 | 319 |
|
309 | 320 | /// A class which manages the state and execution of the compiler.
|
@@ -341,11 +352,14 @@ class CompilerInstance {
|
341 | 352 |
|
342 | 353 | enum : unsigned { NO_SUCH_BUFFER = ~0U };
|
343 | 354 | unsigned MainBufferID = NO_SUCH_BUFFER;
|
| 355 | + |
| 356 | + /// PrimaryBufferID corresponds to PrimaryInput. |
344 | 357 | unsigned PrimaryBufferID = NO_SUCH_BUFFER;
|
| 358 | + bool isWholeModuleCompilation() { return PrimaryBufferID == NO_SUCH_BUFFER; } |
345 | 359 |
|
346 | 360 | SourceFile *PrimarySourceFile = nullptr;
|
347 | 361 |
|
348 |
| - void createSILModule(bool WholeModule = false); |
| 362 | + void createSILModule(); |
349 | 363 | void setPrimarySourceFile(SourceFile *SF);
|
350 | 364 |
|
351 | 365 | public:
|
@@ -433,6 +447,55 @@ class CompilerInstance {
|
433 | 447 | /// Frees up the ASTContext and SILModule objects that this instance is
|
434 | 448 | /// holding on.
|
435 | 449 | void freeContextAndSIL();
|
| 450 | + |
| 451 | +private: |
| 452 | + /// Load stdlib & return true if should continue, i.e. no error |
| 453 | + bool loadStdlib(); |
| 454 | + ModuleDecl *importUnderlyingModule(); |
| 455 | + ModuleDecl *importBridgingHeader(); |
| 456 | + |
| 457 | + void |
| 458 | + getImplicitlyImportedModules(SmallVectorImpl<ModuleDecl *> &importModules); |
| 459 | + |
| 460 | +public: // for static functions in Frontend.cpp |
| 461 | + struct ImplicitImports { |
| 462 | + SourceFile::ImplicitModuleImportKind kind; |
| 463 | + ModuleDecl *objCModuleUnderlyingMixedFramework; |
| 464 | + ModuleDecl *headerModule; |
| 465 | + SmallVector<ModuleDecl *, 4> modules; |
| 466 | + |
| 467 | + explicit ImplicitImports(CompilerInstance &compiler); |
| 468 | + }; |
| 469 | + |
| 470 | +private: |
| 471 | + void createREPLFile(const ImplicitImports &implicitImports) const; |
| 472 | + std::unique_ptr<DelayedParsingCallbacks> computeDelayedParsingCallback(); |
| 473 | + |
| 474 | + void addMainFileToModule(const ImplicitImports &implicitImports); |
| 475 | + |
| 476 | + void parseAndCheckTypes(const ImplicitImports &implicitImports); |
| 477 | + |
| 478 | + void parseLibraryFile(unsigned BufferID, |
| 479 | + const ImplicitImports &implicitImports, |
| 480 | + PersistentParserState &PersistentState, |
| 481 | + DelayedParsingCallbacks *DelayedParseCB); |
| 482 | + |
| 483 | + /// Return true if had load error |
| 484 | + bool |
| 485 | + parsePartialModulesAndLibraryFiles(const ImplicitImports &implicitImports, |
| 486 | + PersistentParserState &PersistentState, |
| 487 | + DelayedParsingCallbacks *DelayedParseCB); |
| 488 | + |
| 489 | + OptionSet<TypeCheckingFlags> computeTypeCheckingOptions(); |
| 490 | + |
| 491 | + void forEachFileToTypeCheck(llvm::function_ref<void(SourceFile &)> fn); |
| 492 | + |
| 493 | + void parseAndTypeCheckMainFile(PersistentParserState &PersistentState, |
| 494 | + DelayedParsingCallbacks *DelayedParseCB, |
| 495 | + OptionSet<TypeCheckingFlags> TypeCheckOptions); |
| 496 | + void performTypeCheckingAndDelayedParsing(); |
| 497 | + |
| 498 | + void finishTypeChecking(OptionSet<TypeCheckingFlags> TypeCheckOptions); |
436 | 499 | };
|
437 | 500 |
|
438 | 501 | } // namespace swift
|
|
0 commit comments