Skip to content

Commit 28b2060

Browse files
author
David Ungar
committed
FrontendInputs data structure redo.
- Outlaw duplicate input files, fix driver, fix tests, and add test. - Reflect that no buffer is present without a (possibly pseudo) named file. - Reflect fact that every input has a (possible pseudo) name. - Break up CompilerInstance::setup. Don't bail on dups.
1 parent 2cda5a9 commit 28b2060

30 files changed

+576
-582
lines changed

include/swift/AST/DiagnosticsFrontend.def

+3
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,9 @@ ERROR(error_primary_file_not_found,none,
157157
ERROR(error_cannot_have_input_files_with_file_list,none,
158158
"cannot have input files with file list", ())
159159

160+
ERROR(error_duplicate_input_file,none,
161+
"duplicate input file '%0'", (StringRef))
162+
160163
ERROR(repl_must_be_initialized,none,
161164
"variables currently must have an initial value when entered at the "
162165
"top level of the REPL", ())

include/swift/Frontend/Frontend.h

+26-18
Original file line numberDiff line numberDiff line change
@@ -242,20 +242,6 @@ class CompilerInvocation {
242242
return FrontendOpts.ModuleName;
243243
}
244244

245-
void addInputFilename(StringRef Filename) {
246-
FrontendOpts.Inputs.addInputFilename(Filename);
247-
}
248-
249-
/// Does not take ownership of \p Buf.
250-
void addInputBuffer(llvm::MemoryBuffer *Buf) {
251-
FrontendOpts.Inputs.addInputBuffer(Buf);
252-
}
253-
254-
void setPrimaryInput(SelectedInput pi) {
255-
FrontendOpts.Inputs.setPrimaryInput(pi);
256-
}
257-
258-
void clearInputs() { FrontendOpts.Inputs.clearInputs(); }
259245

260246
StringRef getOutputFilename() const {
261247
return FrontendOpts.getSingleOutputFilename();
@@ -307,7 +293,7 @@ class CompilerInvocation {
307293
/// Return value includes the buffer so caller can keep it alive.
308294
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
309295
setUpInputForSILTool(StringRef inputFilename, StringRef moduleNameArg,
310-
bool alwaysSetModuleToMain,
296+
bool alwaysSetModuleToMain, bool bePrimary,
311297
serialization::ExtendedValidationInfo &extendedInfo);
312298
bool hasSerializedAST() {
313299
return FrontendOpts.InputKind == InputFileKind::IFK_Swift_Library;
@@ -359,8 +345,6 @@ class CompilerInstance {
359345
void createSILModule();
360346
void setPrimarySourceFile(SourceFile *SF);
361347

362-
bool setUpForFileAt(unsigned i);
363-
364348
public:
365349
SourceManager &getSourceMgr() { return SourceMgr; }
366350

@@ -436,6 +420,23 @@ class CompilerInstance {
436420
/// \brief Returns true if there was an error during setup.
437421
bool setup(const CompilerInvocation &Invocation);
438422

423+
private:
424+
void setUpLLVMArguments();
425+
void setUpDiagnosticOptions();
426+
bool setUpModuleLoaders();
427+
Optional<unsigned> setupCodeCompletionBuffer();
428+
bool setupInputs(Optional<unsigned> codeCompletionBufferID);
429+
bool isInMainMode() {
430+
return Invocation.getInputKind() == InputFileKind::IFK_Swift;
431+
}
432+
bool isInSILMode() {
433+
return Invocation.getInputKind() == InputFileKind::IFK_SIL;
434+
}
435+
bool setupForInput(const InputFile &input);
436+
void setupForBuffer(llvm::MemoryBuffer *buffer, bool isPrimary);
437+
bool setUpForFile(StringRef file, bool isPrimary);
438+
439+
public:
439440
/// Parses and type-checks all input files.
440441
void performSema();
441442

@@ -445,6 +446,13 @@ class CompilerInstance {
445446
///
446447
void performParseOnly(bool EvaluateConditionals = false);
447448

449+
private:
450+
SourceFile *
451+
createSourceFileForMainModule(SourceFileKind FileKind,
452+
SourceFile::ImplicitModuleImportKind ImportKind,
453+
Optional<unsigned> BufferID);
454+
455+
public:
448456
/// Frees up the ASTContext and SILModule objects that this instance is
449457
/// holding on.
450458
void freeContextAndSIL();
@@ -469,7 +477,7 @@ class CompilerInstance {
469477
};
470478

471479
private:
472-
void createREPLFile(const ImplicitImports &implicitImports) const;
480+
void createREPLFile(const ImplicitImports &implicitImports);
473481
std::unique_ptr<DelayedParsingCallbacks>
474482
computeDelayedParsingCallback(bool isPrimary);
475483

0 commit comments

Comments
 (0)