git-clang-format'ed

This commit is contained in:
David Ungar
2017-10-08 23:56:03 -07:00
parent c1821755de
commit 47ee930a50
13 changed files with 222 additions and 209 deletions

View File

@@ -250,16 +250,14 @@ public:
void addInputBuffer(llvm::MemoryBuffer *Buf) { void addInputBuffer(llvm::MemoryBuffer *Buf) {
FrontendOpts.Inputs.addInputBuffer(Buf); FrontendOpts.Inputs.addInputBuffer(Buf);
} }
void setPrimaryInput(SelectedInput pi) { void setPrimaryInput(SelectedInput pi) {
FrontendOpts.Inputs.setPrimaryInput(pi); FrontendOpts.Inputs.setPrimaryInput(pi);
} }
void clearInputs() { void clearInputs() { FrontendOpts.Inputs.clearInputs(); }
FrontendOpts.Inputs.clearInputs();
}
StringRef getOutputFilename() const { StringRef getOutputFilename() const {
return FrontendOpts.getSingleOutputFilename(); return FrontendOpts.getSingleOutputFilename();
} }
@@ -357,7 +355,7 @@ class CompilerInstance {
void createSILModule(); void createSILModule();
void setPrimarySourceFile(SourceFile *SF); void setPrimarySourceFile(SourceFile *SF);
bool setupForFileAt(unsigned i); bool setupForFileAt(unsigned i);
public: public:
@@ -416,7 +414,9 @@ public:
SerializedModuleLoader *getSerializedModuleLoader() const { return SML; } SerializedModuleLoader *getSerializedModuleLoader() const { return SML; }
ArrayRef<unsigned> getInputBufferIDs() const { return InputSourceCodeBufferIDs; } ArrayRef<unsigned> getInputBufferIDs() const {
return InputSourceCodeBufferIDs;
}
ArrayRef<LinkLibrary> getLinkLibraries() const { ArrayRef<LinkLibrary> getLinkLibraries() const {
return Invocation.getLinkLibraries(); return Invocation.getLinkLibraries();

View File

@@ -22,9 +22,9 @@
namespace llvm { namespace llvm {
class MemoryBuffer; class MemoryBuffer;
namespace opt { namespace opt {
class ArgList; class ArgList;
class Arg; class Arg;
} } // namespace opt
} }
namespace swift { namespace swift {
@@ -70,147 +70,134 @@ enum class InputFileKind {
class FrontendInputs { class FrontendInputs {
private: private:
// FIXME: (dmu) create a class for the inputs // FIXME: (dmu) create a class for the inputs
/// The names of input files to the frontend. /// The names of input files to the frontend.
std::vector<std::string> InputFilenames; std::vector<std::string> InputFilenames;
/// Input buffers which may override the file contents of input files. /// Input buffers which may override the file contents of input files.
std::vector<llvm::MemoryBuffer *> InputBuffers; std::vector<llvm::MemoryBuffer *> InputBuffers;
/// The input for which output should be generated. If not set, output will /// The input for which output should be generated. If not set, output will
/// be generated for the whole module. /// be generated for the whole module.
Optional<SelectedInput> PrimaryInput; Optional<SelectedInput> PrimaryInput;
public: public:
// Readers: // Readers:
// Input filename readers // Input filename readers
ArrayRef<std::string> getInputFilenames() const { ArrayRef<std::string> getInputFilenames() const { return InputFilenames; }
return InputFilenames; bool hasInputFilenames() const { return !getInputFilenames().empty(); }
}
bool hasInputFilenames() const {
return !getInputFilenames().empty();
}
unsigned inputFilenameCount() const { return getInputFilenames().size(); } unsigned inputFilenameCount() const { return getInputFilenames().size(); }
bool hasUniqueInputFilename() const { bool hasUniqueInputFilename() const { return inputFilenameCount() == 1; }
return inputFilenameCount() == 1;
}
const std::string &getFilenameOfFirstInput() const { const std::string &getFilenameOfFirstInput() const {
assert(hasInputFilenames()); assert(hasInputFilenames());
return getInputFilenames()[0]; return getInputFilenames()[0];
} }
bool isReadingFromStdin() { bool isReadingFromStdin() {
return hasUniqueInputFilename() && getFilenameOfFirstInput() == "-"; return hasUniqueInputFilename() && getFilenameOfFirstInput() == "-";
} }
// If we have exactly one input filename, and its extension is "bc" or "ll", // If we have exactly one input filename, and its extension is "bc" or "ll",
// treat the input as LLVM_IR. // treat the input as LLVM_IR.
bool shouldTreatAsLLVM() const; bool shouldTreatAsLLVM() const;
// Input buffer readers // Input buffer readers
ArrayRef<llvm::MemoryBuffer*> getInputBuffers() const { ArrayRef<llvm::MemoryBuffer *> getInputBuffers() const {
return InputBuffers; return InputBuffers;
} }
unsigned inputBufferCount() const { return getInputBuffers().size(); } unsigned inputBufferCount() const { return getInputBuffers().size(); }
// Primary input readers // Primary input readers
Optional<SelectedInput> getPrimaryInput() const { Optional<SelectedInput> getPrimaryInput() const { return PrimaryInput; }
return PrimaryInput; bool hasPrimaryInput() const { return getPrimaryInput().hasValue(); }
}
bool hasPrimaryInput() const {
return getPrimaryInput().hasValue();
}
bool isWholeModule() { return !hasPrimaryInput(); } bool isWholeModule() { return !hasPrimaryInput(); }
bool isPrimaryInputAFileAt(unsigned i) { bool isPrimaryInputAFileAt(unsigned i) {
return hasPrimaryInput() && getPrimaryInput()->isFilename() && getPrimaryInput()->Index == i; return hasPrimaryInput() && getPrimaryInput()->isFilename() &&
getPrimaryInput()->Index == i;
} }
bool haveAPrimaryInputFile() const { bool haveAPrimaryInputFile() const {
return hasPrimaryInput() && getPrimaryInput()->isFilename(); return hasPrimaryInput() && getPrimaryInput()->isFilename();
} }
Optional<unsigned> primaryInputFileIndex() const { Optional<unsigned> primaryInputFileIndex() const {
return haveAPrimaryInputFile() ? Optional<unsigned>(getPrimaryInput()->Index) : None; return haveAPrimaryInputFile()
? Optional<unsigned>(getPrimaryInput()->Index)
: None;
} }
StringRef primaryInputFilenameIfAny() const { StringRef primaryInputFilenameIfAny() const {
if (auto Index = primaryInputFileIndex()) { if (auto Index = primaryInputFileIndex()) {
return getInputFilenames()[*Index]; return getInputFilenames()[*Index];
} }
return StringRef(); return StringRef();
} }
// Multi-facet readers // Multi-facet readers
StringRef baseNameOfOutput(const llvm::opt::ArgList &Args, StringRef ModuleName) const; StringRef baseNameOfOutput(const llvm::opt::ArgList &Args,
StringRef ModuleName) const;
bool shouldTreatAsSIL() const; bool shouldTreatAsSIL() const;
/// Return true for error /// Return true for error
bool verifyInputs(DiagnosticEngine &Diags, bool TreatAsSIL, bool isREPLRequested, bool isNoneRequested) const; bool verifyInputs(DiagnosticEngine &Diags, bool TreatAsSIL,
bool isREPLRequested, bool isNoneRequested) const;
// Input filename writers // Input filename writers
void addInputFilename(StringRef Filename) { void addInputFilename(StringRef Filename) {
InputFilenames.push_back(Filename); InputFilenames.push_back(Filename);
} }
void transformInputFilenames(const llvm::function_ref<std::string(std::string)> &fn); void transformInputFilenames(
const llvm::function_ref<std::string(std::string)> &fn);
// Input buffer writers // Input buffer writers
void addInputBuffer(llvm::MemoryBuffer *Buf) { void addInputBuffer(llvm::MemoryBuffer *Buf) { InputBuffers.push_back(Buf); }
InputBuffers.push_back(Buf);
// Primary input writers
void setPrimaryInput(SelectedInput si) { PrimaryInput = si; }
void clearPrimaryInput() { PrimaryInput = 0; }
void setPrimaryInputForInputFilename(const std::string &inputFilename) {
setPrimaryInput(!inputFilename.empty() && inputFilename != "-"
? SelectedInput(inputFilenameCount(),
SelectedInput::InputKind::Filename)
: SelectedInput(inputBufferCount(),
SelectedInput::InputKind::Buffer));
} }
// Primary input writers
void setPrimaryInput(SelectedInput si) {
PrimaryInput = si;
}
void clearPrimaryInput() {
PrimaryInput = 0;
}
void setPrimaryInputForInputFilename(const std::string &inputFilename) {
setPrimaryInput(
!inputFilename.empty() && inputFilename != "-"
? SelectedInput(inputFilenameCount(), SelectedInput::InputKind::Filename)
: SelectedInput(inputBufferCount(), SelectedInput::InputKind::Buffer)
);
}
// Multi-faceted writers // Multi-faceted writers
void clearInputs() { void clearInputs() {
InputFilenames.clear(); InputFilenames.clear();
InputBuffers.clear(); InputBuffers.clear();
} }
void setInputFilenamesAndPrimaryInput(DiagnosticEngine &Diags, llvm::opt::ArgList &Args); void setInputFilenamesAndPrimaryInput(DiagnosticEngine &Diags,
llvm::opt::ArgList &Args);
void readInputFileList(DiagnosticEngine &diags,
llvm::opt::ArgList &Args, void readInputFileList(DiagnosticEngine &diags, llvm::opt::ArgList &Args,
const llvm::opt::Arg *filelistPath); const llvm::opt::Arg *filelistPath);
}; };
/// Options for controlling the behavior of the frontend. /// Options for controlling the behavior of the frontend.
class FrontendOptions { class FrontendOptions {
public: public:
FrontendInputs Inputs; FrontendInputs Inputs;
/// The kind of input on which the frontend should operate. /// The kind of input on which the frontend should operate.
InputFileKind InputKind = InputFileKind::IFK_Swift; InputFileKind InputKind = InputFileKind::IFK_Swift;
/// The specified output files. If only a single outputfile is generated, /// The specified output files. If only a single outputfile is generated,
/// the name of the last specified file is taken. /// the name of the last specified file is taken.
std::vector<std::string> OutputFilenames; std::vector<std::string> OutputFilenames;
void forAllOutputPaths(std::function<void(const std::string &)> fn) const; void forAllOutputPaths(std::function<void(const std::string &)> fn) const;
/// Gets the name of the specified output filename. /// Gets the name of the specified output filename.
/// If multiple files are specified, the last one is returned. /// If multiple files are specified, the last one is returned.
StringRef getSingleOutputFilename() const { StringRef getSingleOutputFilename() const {
@@ -223,9 +210,7 @@ public:
OutputFilenames.clear(); OutputFilenames.clear();
OutputFilenames.push_back(FileName); OutputFilenames.push_back(FileName);
} }
void setOutputFilenameToStdout() { void setOutputFilenameToStdout() { setSingleOutputFilename("-"); }
setSingleOutputFilename("-");
}
bool isOutputFilenameStdout() const { bool isOutputFilenameStdout() const {
return getSingleOutputFilename() == "-"; return getSingleOutputFilename() == "-";
} }
@@ -234,7 +219,8 @@ public:
bool hasNamedOutputFile() const { bool hasNamedOutputFile() const {
return !OutputFilenames.empty() && !isOutputFilenameStdout(); return !OutputFilenames.empty() && !isOutputFilenameStdout();
} }
void setOutputFileList(DiagnosticEngine &Diags, const llvm::opt::ArgList &Args ); void setOutputFileList(DiagnosticEngine &Diags,
const llvm::opt::ArgList &Args);
/// A list of arbitrary modules to import and make implicitly visible. /// A list of arbitrary modules to import and make implicitly visible.
std::vector<std::string> ImplicitImportModuleNames; std::vector<std::string> ImplicitImportModuleNames;
@@ -479,25 +465,22 @@ public:
/// Indicates whether the RequestedAction will immediately run code. /// Indicates whether the RequestedAction will immediately run code.
bool actionIsImmediate() const; bool actionIsImmediate() const;
/// Return a hash code of any components from these options that should /// Return a hash code of any components from these options that should
/// contribute to a Swift Bridging PCH hash. /// contribute to a Swift Bridging PCH hash.
llvm::hash_code getPCHHashComponents() const { llvm::hash_code getPCHHashComponents() const {
return llvm::hash_value(0); return llvm::hash_value(0);
} }
StringRef originalPath() const; StringRef originalPath() const;
StringRef determineFallbackModuleName() const; StringRef determineFallbackModuleName() const;
bool isCompilingExactlyOneSwiftFile() const { bool isCompilingExactlyOneSwiftFile() const {
return InputKind == InputFileKind::IFK_Swift && Inputs.hasUniqueInputFilename(); return InputKind == InputFileKind::IFK_Swift &&
Inputs.hasUniqueInputFilename();
} }
void setModuleName(DiagnosticEngine &Diags, const llvm::opt::ArgList &Args); void setModuleName(DiagnosticEngine &Diags, const llvm::opt::ArgList &Args);
}; };
} }

View File

@@ -325,16 +325,20 @@ static bool ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args,
return true; return true;
} }
bool TreatAsSIL = Args.hasArg(OPT_parse_sil) || Opts.Inputs.shouldTreatAsSIL(); bool TreatAsSIL =
Args.hasArg(OPT_parse_sil) || Opts.Inputs.shouldTreatAsSIL();
bool TreatAsLLVM = Opts.Inputs.shouldTreatAsLLVM(); bool TreatAsLLVM = Opts.Inputs.shouldTreatAsLLVM();
if (Opts.Inputs.verifyInputs(Diags, TreatAsSIL, Opts.RequestedAction == FrontendOptions::REPL, Opts.RequestedAction == FrontendOptions::NoneAction)) { if (Opts.Inputs.verifyInputs(
Diags, TreatAsSIL, Opts.RequestedAction == FrontendOptions::REPL,
Opts.RequestedAction == FrontendOptions::NoneAction)) {
return true; return true;
} }
if (Opts.RequestedAction == FrontendOptions::Immediate) { if (Opts.RequestedAction == FrontendOptions::Immediate) {
Opts.ImmediateArgv.push_back(Opts.Inputs.getFilenameOfFirstInput()); // argv[0] Opts.ImmediateArgv.push_back(
Opts.Inputs.getFilenameOfFirstInput()); // argv[0]
if (const Arg *A = Args.getLastArg(OPT__DASH_DASH)) { if (const Arg *A = Args.getLastArg(OPT__DASH_DASH)) {
for (unsigned i = 0, e = A->getNumValues(); i != e; ++i) { for (unsigned i = 0, e = A->getNumValues(); i != e; ++i) {
Opts.ImmediateArgv.push_back(A->getValue(i)); Opts.ImmediateArgv.push_back(A->getValue(i));
@@ -451,11 +455,12 @@ static bool ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args,
// First, if we're reading from stdin and we don't have a directory, // First, if we're reading from stdin and we don't have a directory,
// output to stdout. // output to stdout.
if (Opts.Inputs.isReadingFromStdin() && Opts.OutputFilenames.empty()) if (Opts.Inputs.isReadingFromStdin() && Opts.OutputFilenames.empty())
Opts.setOutputFilenameToStdout(); Opts.setOutputFilenameToStdout();
else { else {
// We have a suffix, so determine an appropriate name. // We have a suffix, so determine an appropriate name.
StringRef BaseName = Opts.Inputs.baseNameOfOutput(Args, Opts.ModuleName); StringRef BaseName =
Opts.Inputs.baseNameOfOutput(Args, Opts.ModuleName);
llvm::SmallString<128> Path(Opts.getSingleOutputFilename()); llvm::SmallString<128> Path(Opts.getSingleOutputFilename());
llvm::sys::path::append(Path, BaseName); llvm::sys::path::append(Path, BaseName);
llvm::sys::path::replace_extension(Path, Suffix); llvm::sys::path::replace_extension(Path, Suffix);
@@ -702,7 +707,7 @@ static bool ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args,
if (const Arg *A = Args.getLastArgNoClaim(OPT_import_objc_header)) { if (const Arg *A = Args.getLastArgNoClaim(OPT_import_objc_header)) {
Opts.ImplicitObjCHeaderPath = A->getValue(); Opts.ImplicitObjCHeaderPath = A->getValue();
Opts.SerializeBridgingHeader |= Opts.SerializeBridgingHeader |=
!Opts.Inputs.getPrimaryInput() && !Opts.ModuleOutputPath.empty(); !Opts.Inputs.getPrimaryInput() && !Opts.ModuleOutputPath.empty();
} }
for (const Arg *A : Args.filtered(OPT_import_module)) { for (const Arg *A : Args.filtered(OPT_import_module)) {
@@ -1432,7 +1437,8 @@ static bool ParseIRGenArgs(IRGenOptions &Opts, ArgList &Args,
// in other classes. // in other classes.
if (!SILOpts.SILOutputFileNameForDebugging.empty()) { if (!SILOpts.SILOutputFileNameForDebugging.empty()) {
Opts.MainInputFilename = SILOpts.SILOutputFileNameForDebugging; Opts.MainInputFilename = SILOpts.SILOutputFileNameForDebugging;
} else if (FrontendOpts.Inputs.getPrimaryInput() && FrontendOpts.Inputs.getPrimaryInput()->isFilename()) { } else if (FrontendOpts.Inputs.getPrimaryInput() &&
FrontendOpts.Inputs.getPrimaryInput()->isFilename()) {
unsigned Index = FrontendOpts.Inputs.getPrimaryInput()->Index; unsigned Index = FrontendOpts.Inputs.getPrimaryInput()->Index;
Opts.MainInputFilename = FrontendOpts.Inputs.getInputFilenames()[Index]; Opts.MainInputFilename = FrontendOpts.Inputs.getInputFilenames()[Index];
} else if (FrontendOpts.Inputs.hasUniqueInputFilename()) { } else if (FrontendOpts.Inputs.hasUniqueInputFilename()) {

View File

@@ -57,7 +57,8 @@ void CompilerInstance::createSILModule() {
assert(MainModule && "main module not created yet"); assert(MainModule && "main module not created yet");
// Assume WMO if a -primary-file option was not provided. // Assume WMO if a -primary-file option was not provided.
TheSILModule = SILModule::createEmptyModule( TheSILModule = SILModule::createEmptyModule(
getMainModule(), Invocation.getSILOptions(), Invocation.getFrontendOptions().Inputs.isWholeModule()); getMainModule(), Invocation.getSILOptions(),
Invocation.getFrontendOptions().Inputs.isWholeModule());
} }
void CompilerInstance::setPrimarySourceFile(SourceFile *SF) { void CompilerInstance::setPrimarySourceFile(SourceFile *SF) {
@@ -156,13 +157,16 @@ bool CompilerInstance::setup(const CompilerInvocation &Invok) {
Invocation.getLangOptions().EnableAccessControl = false; Invocation.getLangOptions().EnableAccessControl = false;
const Optional<SelectedInput> &PrimaryInput = const Optional<SelectedInput> &PrimaryInput =
Invocation.getFrontendOptions().Inputs.getPrimaryInput(); Invocation.getFrontendOptions().Inputs.getPrimaryInput();
// Add the memory buffers first, these will be associated with a filename // Add the memory buffers first, these will be associated with a filename
// and they can replace the contents of an input filename. // and they can replace the contents of an input filename.
for (unsigned i = 0, e = Invocation.getFrontendOptions().Inputs.inputBufferCount(); i != e; ++i) { for (unsigned i = 0,
e = Invocation.getFrontendOptions().Inputs.inputBufferCount();
i != e; ++i) {
// CompilerInvocation doesn't own the buffers, copy to a new buffer. // CompilerInvocation doesn't own the buffers, copy to a new buffer.
auto *InputBuffer = Invocation.getFrontendOptions().Inputs.getInputBuffers()[i]; auto *InputBuffer =
Invocation.getFrontendOptions().Inputs.getInputBuffers()[i];
auto Copy = std::unique_ptr<llvm::MemoryBuffer>( auto Copy = std::unique_ptr<llvm::MemoryBuffer>(
llvm::MemoryBuffer::getMemBufferCopy( llvm::MemoryBuffer::getMemBufferCopy(
InputBuffer->getBuffer(), InputBuffer->getBufferIdentifier())); InputBuffer->getBuffer(), InputBuffer->getBufferIdentifier()));
@@ -180,7 +184,9 @@ bool CompilerInstance::setup(const CompilerInvocation &Invok) {
} }
} }
for (unsigned i = 0, e = Invocation.getFrontendOptions().Inputs.inputFilenameCount(); i != e; ++i) { for (unsigned i = 0,
e = Invocation.getFrontendOptions().Inputs.inputFilenameCount();
i != e; ++i) {
bool hasError = setupForFileAt(i); bool hasError = setupForFileAt(i);
if (hasError) { if (hasError) {
return true; return true;
@@ -191,7 +197,8 @@ bool CompilerInstance::setup(const CompilerInvocation &Invok) {
if (CodeCompletionBufferID.hasValue()) if (CodeCompletionBufferID.hasValue())
PrimaryBufferID = *CodeCompletionBufferID; PrimaryBufferID = *CodeCompletionBufferID;
if (MainMode && MainBufferID == NO_SUCH_BUFFER && InputSourceCodeBufferIDs.size() == 1) if (MainMode && MainBufferID == NO_SUCH_BUFFER &&
InputSourceCodeBufferIDs.size() == 1)
MainBufferID = InputSourceCodeBufferIDs.front(); MainBufferID = InputSourceCodeBufferIDs.front();
return false; return false;
@@ -710,59 +717,59 @@ bool CompilerInstance::setupForFileAt(unsigned i) {
bool SILMode = (Invocation.getInputKind() == InputFileKind::IFK_SIL); bool SILMode = (Invocation.getInputKind() == InputFileKind::IFK_SIL);
auto &File = Invocation.getFrontendOptions().Inputs.getInputFilenames()[i]; auto &File = Invocation.getFrontendOptions().Inputs.getInputFilenames()[i];
// FIXME: Working with filenames is fragile, maybe use the real path // FIXME: Working with filenames is fragile, maybe use the real path
// or have some kind of FileManager. // or have some kind of FileManager.
using namespace llvm::sys::path; using namespace llvm::sys::path;
if (Optional<unsigned> ExistingBufferID = if (Optional<unsigned> ExistingBufferID =
SourceMgr.getIDForBufferIdentifier(File)) { SourceMgr.getIDForBufferIdentifier(File)) {
if (SILMode || (MainMode && filename(File) == "main.swift")) if (SILMode || (MainMode && filename(File) == "main.swift"))
MainBufferID = ExistingBufferID.getValue(); MainBufferID = ExistingBufferID.getValue();
if (Invocation.getFrontendOptions().Inputs.isPrimaryInputAFileAt(i)) if (Invocation.getFrontendOptions().Inputs.isPrimaryInputAFileAt(i))
PrimaryBufferID = ExistingBufferID.getValue(); PrimaryBufferID = ExistingBufferID.getValue();
return false; // replaced by a memory buffer. return false; // replaced by a memory buffer.
} }
// Open the input file. // Open the input file.
using FileOrError = llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>; using FileOrError = llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>;
FileOrError InputFileOrErr = llvm::MemoryBuffer::getFileOrSTDIN(File); FileOrError InputFileOrErr = llvm::MemoryBuffer::getFileOrSTDIN(File);
if (!InputFileOrErr) { if (!InputFileOrErr) {
Diagnostics.diagnose(SourceLoc(), diag::error_open_input_file, Diagnostics.diagnose(SourceLoc(), diag::error_open_input_file, File,
File, InputFileOrErr.getError().message()); InputFileOrErr.getError().message());
return true; return true;
} }
if (serialization::isSerializedAST(InputFileOrErr.get()->getBuffer())) { if (serialization::isSerializedAST(InputFileOrErr.get()->getBuffer())) {
llvm::SmallString<128> ModuleDocFilePath(File); llvm::SmallString<128> ModuleDocFilePath(File);
llvm::sys::path::replace_extension(ModuleDocFilePath, llvm::sys::path::replace_extension(ModuleDocFilePath,
SERIALIZED_MODULE_DOC_EXTENSION); SERIALIZED_MODULE_DOC_EXTENSION);
FileOrError ModuleDocOrErr = FileOrError ModuleDocOrErr =
llvm::MemoryBuffer::getFileOrSTDIN(ModuleDocFilePath.str()); llvm::MemoryBuffer::getFileOrSTDIN(ModuleDocFilePath.str());
if (!ModuleDocOrErr && if (!ModuleDocOrErr &&
ModuleDocOrErr.getError() != std::errc::no_such_file_or_directory) { ModuleDocOrErr.getError() != std::errc::no_such_file_or_directory) {
Diagnostics.diagnose(SourceLoc(), diag::error_open_input_file, Diagnostics.diagnose(SourceLoc(), diag::error_open_input_file, File,
File, ModuleDocOrErr.getError().message()); ModuleDocOrErr.getError().message());
return true; return true;
} }
PartialModules.push_back({ std::move(InputFileOrErr.get()), PartialModules.push_back(
ModuleDocOrErr? std::move(ModuleDocOrErr.get()) {std::move(InputFileOrErr.get()),
: nullptr }); ModuleDocOrErr ? std::move(ModuleDocOrErr.get()) : nullptr});
return false; return false;
} }
// Transfer ownership of the MemoryBuffer to the SourceMgr. // Transfer ownership of the MemoryBuffer to the SourceMgr.
unsigned BufferID = unsigned BufferID =
SourceMgr.addNewSourceBuffer(std::move(InputFileOrErr.get())); SourceMgr.addNewSourceBuffer(std::move(InputFileOrErr.get()));
InputSourceCodeBufferIDs.push_back(BufferID); InputSourceCodeBufferIDs.push_back(BufferID);
if (SILMode || (MainMode && filename(File) == "main.swift")) if (SILMode || (MainMode && filename(File) == "main.swift"))
MainBufferID = BufferID; MainBufferID = BufferID;
if (Invocation.getFrontendOptions().Inputs.isPrimaryInputAFileAt(i)) if (Invocation.getFrontendOptions().Inputs.isPrimaryInputAFileAt(i))
PrimaryBufferID = BufferID; PrimaryBufferID = BufferID;
return false; return false;
} }

View File

@@ -13,38 +13,37 @@
#include "swift/Frontend/FrontendOptions.h" #include "swift/Frontend/FrontendOptions.h"
#include "swift/AST/DiagnosticsFrontend.h" #include "swift/AST/DiagnosticsFrontend.h"
#include "swift/Parse/Lexer.h"
#include "swift/Option/Options.h" #include "swift/Option/Options.h"
#include "swift/Parse/Lexer.h"
#include "swift/Strings.h" #include "swift/Strings.h"
#include "llvm/Option/Arg.h" #include "llvm/Option/Arg.h"
#include "llvm/Option/ArgList.h" #include "llvm/Option/ArgList.h"
#include "llvm/Option/Option.h" #include "llvm/Option/Option.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/ErrorHandling.h" #include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/LineIterator.h" #include "llvm/Support/LineIterator.h"
#include "llvm/Support/Path.h" #include "llvm/Support/Path.h"
using namespace swift; using namespace swift;
using namespace llvm::opt; using namespace llvm::opt;
bool FrontendInputs::shouldTreatAsLLVM() const { bool FrontendInputs::shouldTreatAsLLVM() const {
if (hasUniqueInputFilename()) { if (hasUniqueInputFilename()) {
StringRef Input(getFilenameOfFirstInput()); StringRef Input(getFilenameOfFirstInput());
return return llvm::sys::path::extension(Input).endswith(LLVM_BC_EXTENSION) ||
llvm::sys::path::extension(Input).endswith(LLVM_BC_EXTENSION) || llvm::sys::path::extension(Input).endswith(LLVM_IR_EXTENSION);
llvm::sys::path::extension(Input).endswith(LLVM_IR_EXTENSION);
} }
return false; return false;
} }
StringRef FrontendInputs::baseNameOfOutput(const llvm::opt::ArgList &Args, StringRef ModuleName) const { StringRef FrontendInputs::baseNameOfOutput(const llvm::opt::ArgList &Args,
StringRef ModuleName) const {
StringRef pifn = primaryInputFilenameIfAny(); StringRef pifn = primaryInputFilenameIfAny();
if (!pifn.empty()) { if (!pifn.empty()) {
return llvm::sys::path::stem(pifn); return llvm::sys::path::stem(pifn);
} }
bool UserSpecifiedModuleName = Args.getLastArg(options::OPT_module_name); bool UserSpecifiedModuleName = Args.getLastArg(options::OPT_module_name);
if (!UserSpecifiedModuleName && hasUniqueInputFilename()) { if (!UserSpecifiedModuleName && hasUniqueInputFilename()) {
return llvm::sys::path::stem(getFilenameOfFirstInput()); return llvm::sys::path::stem(getFilenameOfFirstInput());
} }
return ModuleName; return ModuleName;
@@ -66,7 +65,9 @@ bool FrontendInputs::shouldTreatAsSIL() const {
return false; return false;
} }
bool FrontendInputs::verifyInputs(DiagnosticEngine &Diags, bool TreatAsSIL, bool isREPLRequested, bool isNoneRequested) const { bool FrontendInputs::verifyInputs(DiagnosticEngine &Diags, bool TreatAsSIL,
bool isREPLRequested,
bool isNoneRequested) const {
if (isREPLRequested) { if (isREPLRequested) {
if (hasInputFilenames()) { if (hasInputFilenames()) {
Diags.diagnose(SourceLoc(), diag::error_repl_requires_no_input_files); Diags.diagnose(SourceLoc(), diag::error_repl_requires_no_input_files);
@@ -78,7 +79,7 @@ bool FrontendInputs::verifyInputs(DiagnosticEngine &Diags, bool TreatAsSIL, bool
for (unsigned i = 0, e = inputFilenameCount(); i != e; ++i) { for (unsigned i = 0, e = inputFilenameCount(); i != e; ++i) {
if (i == getPrimaryInput()->Index) if (i == getPrimaryInput()->Index)
continue; continue;
StringRef File(getInputFilenames()[i]); StringRef File(getInputFilenames()[i]);
if (!llvm::sys::path::extension(File).endswith(SIB_EXTENSION)) { if (!llvm::sys::path::extension(File).endswith(SIB_EXTENSION)) {
Diags.diagnose(SourceLoc(), Diags.diagnose(SourceLoc(),
@@ -100,18 +101,21 @@ bool FrontendInputs::verifyInputs(DiagnosticEngine &Diags, bool TreatAsSIL, bool
return false; return false;
} }
void FrontendInputs::transformInputFilenames(const llvm::function_ref<std::string(std::string)> &fn) { void FrontendInputs::transformInputFilenames(
const llvm::function_ref<std::string(std::string)> &fn) {
for (auto &InputFile : InputFilenames) { for (auto &InputFile : InputFilenames) {
InputFile = fn(InputFile); InputFile = fn(InputFile);
} }
} }
void FrontendInputs::setInputFilenamesAndPrimaryInput(DiagnosticEngine &Diags, llvm::opt::ArgList &Args) { void FrontendInputs::setInputFilenamesAndPrimaryInput(
DiagnosticEngine &Diags, llvm::opt::ArgList &Args) {
if (const Arg *filelistPath = Args.getLastArg(options::OPT_filelist)) { if (const Arg *filelistPath = Args.getLastArg(options::OPT_filelist)) {
readInputFileList(Diags, Args, filelistPath); readInputFileList(Diags, Args, filelistPath);
return; return;
} }
for (const Arg *A : Args.filtered(options::OPT_INPUT, options::OPT_primary_file)) { for (const Arg *A :
Args.filtered(options::OPT_INPUT, options::OPT_primary_file)) {
if (A->getOption().matches(options::OPT_INPUT)) { if (A->getOption().matches(options::OPT_INPUT)) {
addInputFilename(A->getValue()); addInputFilename(A->getValue());
} else if (A->getOption().matches(options::OPT_primary_file)) { } else if (A->getOption().matches(options::OPT_primary_file)) {
@@ -123,7 +127,6 @@ void FrontendInputs::setInputFilenamesAndPrimaryInput(DiagnosticEngine &Diags, l
} }
} }
/// Try to read an input file list file. /// Try to read an input file list file.
/// ///
/// Returns false on error. /// Returns false on error.
@@ -131,21 +134,21 @@ void FrontendInputs::readInputFileList(DiagnosticEngine &diags,
llvm::opt::ArgList &Args, llvm::opt::ArgList &Args,
const llvm::opt::Arg *filelistPath) { const llvm::opt::Arg *filelistPath) {
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> buffer = llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> buffer =
llvm::MemoryBuffer::getFile(filelistPath->getValue()); llvm::MemoryBuffer::getFile(filelistPath->getValue());
if (!buffer) { if (!buffer) {
diags.diagnose(SourceLoc(), diag::cannot_open_file, diags.diagnose(SourceLoc(), diag::cannot_open_file,
filelistPath->getValue(), buffer.getError().message()); filelistPath->getValue(), buffer.getError().message());
return; return;
} }
const Arg *primaryFileArg = Args.getLastArg(options::OPT_primary_file); const Arg *primaryFileArg = Args.getLastArg(options::OPT_primary_file);
unsigned primaryFileIndex = 0; unsigned primaryFileIndex = 0;
bool foundPrimaryFile = false; bool foundPrimaryFile = false;
for (StringRef line : make_range(llvm::line_iterator(*buffer.get()), {})) { for (StringRef line : make_range(llvm::line_iterator(*buffer.get()), {})) {
addInputFilename(line); addInputFilename(line);
if (foundPrimaryFile || primaryFileArg == nullptr) if (foundPrimaryFile || primaryFileArg == nullptr)
continue; continue;
if (line == primaryFileArg->getValue()) if (line == primaryFileArg->getValue())
@@ -153,23 +156,18 @@ void FrontendInputs::readInputFileList(DiagnosticEngine &diags,
else else
++primaryFileIndex; ++primaryFileIndex;
} }
if (primaryFileArg && !foundPrimaryFile) { if (primaryFileArg && !foundPrimaryFile) {
diags.diagnose(SourceLoc(), diag::error_primary_file_not_found, diags.diagnose(SourceLoc(), diag::error_primary_file_not_found,
primaryFileArg->getValue(), filelistPath->getValue()); primaryFileArg->getValue(), filelistPath->getValue());
return; return;
} }
if (primaryFileArg) if (primaryFileArg)
setPrimaryInput(SelectedInput(primaryFileIndex)); setPrimaryInput(SelectedInput(primaryFileIndex));
assert(!Args.hasArg(options::OPT_INPUT) && "mixing -filelist with inputs"); assert(!Args.hasArg(options::OPT_INPUT) && "mixing -filelist with inputs");
} }
bool FrontendOptions::actionHasOutput() const { bool FrontendOptions::actionHasOutput() const {
switch (RequestedAction) { switch (RequestedAction) {
case NoneAction: case NoneAction:
@@ -256,22 +254,21 @@ void FrontendOptions::forAllOutputPaths(
} }
} }
void FrontendOptions::setModuleName(DiagnosticEngine &Diags,
void FrontendOptions::setModuleName(DiagnosticEngine &Diags, const llvm::opt::ArgList &Args) { const llvm::opt::ArgList &Args) {
const Arg *A = Args.getLastArg(options::OPT_module_name); const Arg *A = Args.getLastArg(options::OPT_module_name);
if (A) { if (A) {
ModuleName = A->getValue(); ModuleName = A->getValue();
} } else if (ModuleName.empty()) {
else if (ModuleName.empty()) {
// The user did not specify a module name, so determine a default fallback // The user did not specify a module name, so determine a default fallback
// based on other options. // based on other options.
// Note: this code path will only be taken when running the frontend // Note: this code path will only be taken when running the frontend
// directly; the driver should always pass -module-name when invoking the // directly; the driver should always pass -module-name when invoking the
// frontend. // frontend.
ModuleName = determineFallbackModuleName(); ModuleName = determineFallbackModuleName();
} }
if (Lexer::isIdentifier(ModuleName) && if (Lexer::isIdentifier(ModuleName) &&
(ModuleName != STDLIB_NAME || ParseStdlib)) { (ModuleName != STDLIB_NAME || ParseStdlib)) {
return; return;
@@ -280,19 +277,17 @@ void FrontendOptions::setModuleName(DiagnosticEngine &Diags, const llvm::opt::Ar
ModuleName = "main"; ModuleName = "main";
return; return;
} }
auto DID = (ModuleName == STDLIB_NAME) auto DID = (ModuleName == STDLIB_NAME) ? diag::error_stdlib_module_name
? diag::error_stdlib_module_name : diag::error_bad_module_name;
: diag::error_bad_module_name;
Diags.diagnose(SourceLoc(), DID, ModuleName, A == nullptr); Diags.diagnose(SourceLoc(), DID, ModuleName, A == nullptr);
ModuleName = "__bad__"; ModuleName = "__bad__";
} }
StringRef FrontendOptions::originalPath() const { StringRef FrontendOptions::originalPath() const {
if (hasNamedOutputFile()) if (hasNamedOutputFile())
// Put the serialized diagnostics file next to the output file. // Put the serialized diagnostics file next to the output file.
return getSingleOutputFilename(); return getSingleOutputFilename();
StringRef fn = Inputs.primaryInputFilenameIfAny(); StringRef fn = Inputs.primaryInputFilenameIfAny();
// If we have a primary input, so use that as the basis for the name of the // If we have a primary input, so use that as the basis for the name of the
// serialized diagnostics file, otherwise fall back on the // serialized diagnostics file, otherwise fall back on the
@@ -314,7 +309,9 @@ StringRef FrontendOptions::determineFallbackModuleName() const {
} }
StringRef OutputFilename = getSingleOutputFilename(); StringRef OutputFilename = getSingleOutputFilename();
bool useOutputFilename = isOutputFilePlainFile(); bool useOutputFilename = isOutputFilePlainFile();
return llvm::sys::path::stem(useOutputFilename ? OutputFilename : StringRef(Inputs.getFilenameOfFirstInput())); return llvm::sys::path::stem(
useOutputFilename ? OutputFilename
: StringRef(Inputs.getFilenameOfFirstInput()));
} }
/// Try to read an output file list file. /// Try to read an output file list file.
@@ -322,7 +319,7 @@ static void readOutputFileList(DiagnosticEngine &diags,
std::vector<std::string> &outputFiles, std::vector<std::string> &outputFiles,
const llvm::opt::Arg *filelistPath) { const llvm::opt::Arg *filelistPath) {
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> buffer = llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> buffer =
llvm::MemoryBuffer::getFile(filelistPath->getValue()); llvm::MemoryBuffer::getFile(filelistPath->getValue());
if (!buffer) { if (!buffer) {
diags.diagnose(SourceLoc(), diag::cannot_open_file, diags.diagnose(SourceLoc(), diag::cannot_open_file,
filelistPath->getValue(), buffer.getError().message()); filelistPath->getValue(), buffer.getError().message());
@@ -332,19 +329,23 @@ static void readOutputFileList(DiagnosticEngine &diags,
} }
} }
void FrontendOptions::setOutputFileList(swift::DiagnosticEngine &Diags, const llvm::opt::ArgList &Args) { void FrontendOptions::setOutputFileList(swift::DiagnosticEngine &Diags,
const llvm::opt::ArgList &Args) {
if (const Arg *A = Args.getLastArg(options::OPT_output_filelist)) { if (const Arg *A = Args.getLastArg(options::OPT_output_filelist)) {
readOutputFileList(Diags, OutputFilenames, A); readOutputFileList(Diags, OutputFilenames, A);
assert(!Args.hasArg(options::OPT_o) && "don't use -o with -output-filelist"); assert(!Args.hasArg(options::OPT_o) &&
"don't use -o with -output-filelist");
} else { } else {
OutputFilenames = Args.getAllArgValues(options::OPT_o); OutputFilenames = Args.getAllArgValues(options::OPT_o);
} }
} }
bool FrontendOptions::isOutputFileDirectory() const { bool FrontendOptions::isOutputFileDirectory() const {
return hasNamedOutputFile() && llvm::sys::fs::is_directory(getSingleOutputFilename()); return hasNamedOutputFile() &&
llvm::sys::fs::is_directory(getSingleOutputFilename());
} }
bool FrontendOptions::isOutputFilePlainFile() const { bool FrontendOptions::isOutputFilePlainFile() const {
return hasNamedOutputFile() && !llvm::sys::fs::is_directory(getSingleOutputFilename()); return hasNamedOutputFile() &&
!llvm::sys::fs::is_directory(getSingleOutputFilename());
} }

View File

@@ -135,7 +135,8 @@ static bool emitMakeDependencies(DiagnosticEngine &diags,
out << escape(targetName) << " :"; out << escape(targetName) << " :";
// First include all other files in the module. Make-style dependencies // First include all other files in the module. Make-style dependencies
// need to be conservative! // need to be conservative!
for (auto const &path : reversePathSortedFilenames(opts.Inputs.getInputFilenames())) for (auto const &path :
reversePathSortedFilenames(opts.Inputs.getInputFilenames()))
out << ' ' << escape(path); out << ' ' << escape(path);
// Then print dependencies we've picked up during compilation. // Then print dependencies we've picked up during compilation.
for (auto const &path : for (auto const &path :
@@ -527,15 +528,16 @@ static bool performCompile(CompilerInstance &Instance,
auto &ImporterOpts = Invocation.getClangImporterOptions(); auto &ImporterOpts = Invocation.getClangImporterOptions();
auto &PCHOutDir = ImporterOpts.PrecompiledHeaderOutputDir; auto &PCHOutDir = ImporterOpts.PrecompiledHeaderOutputDir;
if (!PCHOutDir.empty()) { if (!PCHOutDir.empty()) {
ImporterOpts.BridgingHeader = Invocation.getFrontendOptions().Inputs.getFilenameOfFirstInput(); ImporterOpts.BridgingHeader =
Invocation.getFrontendOptions().Inputs.getFilenameOfFirstInput();
// Create or validate a persistent PCH. // Create or validate a persistent PCH.
auto SwiftPCHHash = Invocation.getPCHHash(); auto SwiftPCHHash = Invocation.getPCHHash();
auto PCH = clangImporter->getOrCreatePCH(ImporterOpts, SwiftPCHHash); auto PCH = clangImporter->getOrCreatePCH(ImporterOpts, SwiftPCHHash);
return !PCH.hasValue(); return !PCH.hasValue();
} }
return clangImporter->emitBridgingPCH( return clangImporter->emitBridgingPCH(
Invocation.getFrontendOptions().Inputs.getFilenameOfFirstInput(), Invocation.getFrontendOptions().Inputs.getFilenameOfFirstInput(),
opts.getSingleOutputFilename()); opts.getSingleOutputFilename());
} }
IRGenOptions &IRGenOpts = Invocation.getIRGenOptions(); IRGenOptions &IRGenOpts = Invocation.getIRGenOptions();
@@ -548,12 +550,13 @@ static bool performCompile(CompilerInstance &Instance,
assert(Invocation.getFrontendOptions().Inputs.hasUniqueInputFilename() && assert(Invocation.getFrontendOptions().Inputs.hasUniqueInputFilename() &&
"We expect a single input for bitcode input!"); "We expect a single input for bitcode input!");
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> FileBufOrErr = llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> FileBufOrErr =
llvm::MemoryBuffer::getFileOrSTDIN(Invocation.getFrontendOptions().Inputs.getFilenameOfFirstInput()); llvm::MemoryBuffer::getFileOrSTDIN(
Invocation.getFrontendOptions().Inputs.getFilenameOfFirstInput());
if (!FileBufOrErr) { if (!FileBufOrErr) {
Instance.getASTContext().Diags.diagnose(SourceLoc(), Instance.getASTContext().Diags.diagnose(
diag::error_open_input_file, SourceLoc(), diag::error_open_input_file,
Invocation.getFrontendOptions().Inputs.getFilenameOfFirstInput(), Invocation.getFrontendOptions().Inputs.getFilenameOfFirstInput(),
FileBufOrErr.getError().message()); FileBufOrErr.getError().message());
return true; return true;
} }
llvm::MemoryBuffer *MainFile = FileBufOrErr.get().get(); llvm::MemoryBuffer *MainFile = FileBufOrErr.get().get();
@@ -565,10 +568,10 @@ static bool performCompile(CompilerInstance &Instance,
if (!Module) { if (!Module) {
// TODO: Translate from the diagnostic info to the SourceManager location // TODO: Translate from the diagnostic info to the SourceManager location
// if available. // if available.
Instance.getASTContext().Diags.diagnose(SourceLoc(), Instance.getASTContext().Diags.diagnose(
diag::error_parse_input_file, SourceLoc(), diag::error_parse_input_file,
Invocation.getFrontendOptions().Inputs.getFilenameOfFirstInput(), Invocation.getFrontendOptions().Inputs.getFilenameOfFirstInput(),
Err.getMessage()); Err.getMessage());
return true; return true;
} }

View File

@@ -998,7 +998,8 @@ getNotableRegions(StringRef SourceText, unsigned NameOffset, StringRef Name,
CompilerInvocation Invocation{}; CompilerInvocation Invocation{};
Invocation.addInputBuffer(InputBuffer.get()); Invocation.addInputBuffer(InputBuffer.get());
Invocation.getFrontendOptions().Inputs.setPrimaryInput( {0, SelectedInput::InputKind::Buffer} ); Invocation.getFrontendOptions().Inputs.setPrimaryInput(
{0, SelectedInput::InputKind::Buffer});
Invocation.getFrontendOptions().ModuleName = "extract"; Invocation.getFrontendOptions().ModuleName = "extract";
auto Instance = llvm::make_unique<swift::CompilerInstance>(); auto Instance = llvm::make_unique<swift::CompilerInstance>();

View File

@@ -156,12 +156,11 @@ Migrator::performAFixItMigration(version::Version SwiftLanguageVersion) {
} }
const unsigned PrimaryIndex = const unsigned PrimaryIndex =
Invocation.getFrontendOptions().Inputs.getInputBuffers().size(); Invocation.getFrontendOptions().Inputs.getInputBuffers().size();
Invocation.addInputBuffer(InputBuffer.get()); Invocation.addInputBuffer(InputBuffer.get());
Invocation.getFrontendOptions().Inputs.setPrimaryInput( { Invocation.getFrontendOptions().Inputs.setPrimaryInput(
PrimaryIndex, SelectedInput::InputKind::Buffer {PrimaryIndex, SelectedInput::InputKind::Buffer});
});
auto Instance = llvm::make_unique<swift::CompilerInstance>(); auto Instance = llvm::make_unique<swift::CompilerInstance>();
if (Instance->setup(Invocation)) { if (Instance->setup(Invocation)) {
@@ -449,6 +448,7 @@ const MigratorOptions &Migrator::getMigratorOptions() const {
const StringRef Migrator::getInputFilename() const { const StringRef Migrator::getInputFilename() const {
auto PrimaryInput = auto PrimaryInput =
StartInvocation.getFrontendOptions().Inputs.getPrimaryInput().getValue(); StartInvocation.getFrontendOptions().Inputs.getPrimaryInput().getValue();
return StartInvocation.getFrontendOptions().Inputs.getInputFilenames()[PrimaryInput.Index]; return StartInvocation.getFrontendOptions()
.Inputs.getInputFilenames()[PrimaryInput.Index];
} }

View File

@@ -399,9 +399,10 @@ bool SwiftASTManager::initCompilerInvocation(CompilerInvocation &Invocation,
// clang's FileManager ? // clang's FileManager ?
std::string PrimaryFile = std::string PrimaryFile =
SwiftLangSupport::resolvePathSymlinks(UnresolvedPrimaryFile); SwiftLangSupport::resolvePathSymlinks(UnresolvedPrimaryFile);
Invocation.getFrontendOptions().Inputs.transformInputFilenames( [] (std::string s) -> std::string { Invocation.getFrontendOptions().Inputs.transformInputFilenames(
return SwiftLangSupport::resolvePathSymlinks(s); [](std::string s) -> std::string {
}); return SwiftLangSupport::resolvePathSymlinks(s);
});
ClangImporterOptions &ImporterOpts = Invocation.getClangImporterOptions(); ClangImporterOptions &ImporterOpts = Invocation.getClangImporterOptions();
ImporterOpts.DetailedPreprocessingRecord = true; ImporterOpts.DetailedPreprocessingRecord = true;
@@ -426,8 +427,10 @@ bool SwiftASTManager::initCompilerInvocation(CompilerInvocation &Invocation,
if (!PrimaryFile.empty()) { if (!PrimaryFile.empty()) {
Optional<unsigned> PrimaryIndex; Optional<unsigned> PrimaryIndex;
for (auto i : indices(Invocation.getFrontendOptions().Inputs.getInputFilenames())) { for (auto i :
auto &CurFile = Invocation.getFrontendOptions().Inputs.getInputFilenames()[i]; indices(Invocation.getFrontendOptions().Inputs.getInputFilenames())) {
auto &CurFile =
Invocation.getFrontendOptions().Inputs.getInputFilenames()[i];
if (PrimaryFile == CurFile) { if (PrimaryFile == CurFile) {
PrimaryIndex = i; PrimaryIndex = i;
break; break;
@@ -440,7 +443,8 @@ bool SwiftASTManager::initCompilerInvocation(CompilerInvocation &Invocation,
Error = OS.str(); Error = OS.str();
return true; return true;
} }
Invocation.getFrontendOptions().Inputs.setPrimaryInput(SelectedInput(*PrimaryIndex)); Invocation.getFrontendOptions().Inputs.setPrimaryInput(
SelectedInput(*PrimaryIndex));
} }
return Err; return Err;
@@ -653,8 +657,10 @@ bool ASTProducer::shouldRebuild(SwiftASTManager::Implementation &MgrImpl,
// Check if the inputs changed. // Check if the inputs changed.
SmallVector<BufferStamp, 8> InputStamps; SmallVector<BufferStamp, 8> InputStamps;
InputStamps.reserve(Invok.Opts.Invok.getFrontendOptions().Inputs.inputFilenameCount()); InputStamps.reserve(
for (auto &File : Invok.Opts.Invok.getFrontendOptions().Inputs.getInputFilenames()) { Invok.Opts.Invok.getFrontendOptions().Inputs.inputFilenameCount());
for (auto &File :
Invok.Opts.Invok.getFrontendOptions().Inputs.getInputFilenames()) {
bool FoundSnapshot = false; bool FoundSnapshot = false;
for (auto &Snap : Snapshots) { for (auto &Snap : Snapshots) {
if (Snap->getFilename() == File) { if (Snap->getFilename() == File) {
@@ -666,7 +672,8 @@ bool ASTProducer::shouldRebuild(SwiftASTManager::Implementation &MgrImpl,
if (!FoundSnapshot) if (!FoundSnapshot)
InputStamps.push_back(MgrImpl.getBufferStamp(File)); InputStamps.push_back(MgrImpl.getBufferStamp(File));
} }
assert(InputStamps.size() == Invok.Opts.Invok.getFrontendOptions().Inputs.inputFilenameCount()); assert(InputStamps.size() ==
Invok.Opts.Invok.getFrontendOptions().Inputs.inputFilenameCount());
if (Stamps != InputStamps) if (Stamps != InputStamps)
return true; return true;
@@ -738,7 +745,8 @@ ASTUnitRef ASTProducer::createASTUnit(SwiftASTManager::Implementation &MgrImpl,
const InvocationOptions &Opts = InvokRef->Impl.Opts; const InvocationOptions &Opts = InvokRef->Impl.Opts;
SmallVector<FileContent, 8> Contents; SmallVector<FileContent, 8> Contents;
for (auto &File : Opts.Invok.getFrontendOptions().Inputs.getInputFilenames()) { for (auto &File :
Opts.Invok.getFrontendOptions().Inputs.getInputFilenames()) {
bool FoundSnapshot = false; bool FoundSnapshot = false;
for (auto &Snap : Snapshots) { for (auto &Snap : Snapshots) {
if (Snap->getFilename() == File) { if (Snap->getFilename() == File) {
@@ -758,7 +766,8 @@ ASTUnitRef ASTProducer::createASTUnit(SwiftASTManager::Implementation &MgrImpl,
} }
Contents.push_back(std::move(Content)); Contents.push_back(std::move(Content));
} }
assert(Contents.size() == Opts.Invok.getFrontendOptions().Inputs.inputFilenameCount()); assert(Contents.size() ==
Opts.Invok.getFrontendOptions().Inputs.inputFilenameCount());
for (auto &Content : Contents) for (auto &Content : Contents)
Stamps.push_back(Content.Stamp); Stamps.push_back(Content.Stamp);

View File

@@ -1711,14 +1711,14 @@ ImmutableTextSnapshotRef SwiftEditorDocument::replaceText(
// not update all open documents, since there could be too many of them. // not update all open documents, since there could be too many of them.
} }
} }
// Update the old syntax map offsets to account for the replaced range. // Update the old syntax map offsets to account for the replaced range.
// Also set the initial AffectedRange to cover any tokens that // Also set the initial AffectedRange to cover any tokens that
// the replaced range intersected. This allows for clients that split // the replaced range intersected. This allows for clients that split
// multi-line tokens at line boundaries, and ensure all parts of these tokens // multi-line tokens at line boundaries, and ensure all parts of these tokens
// will be cleared. // will be cleared.
Impl.AffectedRange = Impl.SyntaxMap.adjustForReplacement(Offset, Length, Str.size()); Impl.AffectedRange = Impl.SyntaxMap.adjustForReplacement(Offset, Length, Str.size());
return Snapshot; return Snapshot;
} }

View File

@@ -44,8 +44,10 @@ private:
public: public:
bool hasUniqueInputFilename() const { return InputFilenames.size() == 1; } bool hasUniqueInputFilename() const { return InputFilenames.size() == 1; }
const std::string &getFilenameOfFirstInput() const { return InputFilenames[0]; } const std::string &getFilenameOfFirstInput() const {
return InputFilenames[0];
}
void setMainExecutablePath(const std::string &Path) { void setMainExecutablePath(const std::string &Path) {
MainExecutablePath = Path; MainExecutablePath = Path;
} }

View File

@@ -201,8 +201,8 @@ int main(int argc, char **argv) {
CI.addDiagnosticConsumer(&PrintDiags); CI.addDiagnosticConsumer(&PrintDiags);
if (!PerformWMO) { if (!PerformWMO) {
Invocation.getFrontendOptions().Inputs Invocation.getFrontendOptions().Inputs.setPrimaryInputForInputFilename(
.setPrimaryInputForInputFilename(InputFilename); InputFilename);
} }
if (CI.setup(Invocation)) if (CI.setup(Invocation))

View File

@@ -349,7 +349,8 @@ int main(int argc, char **argv) {
CI.addDiagnosticConsumer(&PrintDiags); CI.addDiagnosticConsumer(&PrintDiags);
if (!PerformWMO) { if (!PerformWMO) {
Invocation.getFrontendOptions().Inputs.setPrimaryInputForInputFilename(InputFilename); Invocation.getFrontendOptions().Inputs.setPrimaryInputForInputFilename(
InputFilename);
} }
if (CI.setup(Invocation)) if (CI.setup(Invocation))