Skip to content

Commit 361ff72

Browse files
author
David Ungar
committed
Move FrontendInputs into separate .h and .cpp files.
1 parent 4ac390d commit 361ff72

File tree

6 files changed

+308
-218
lines changed

6 files changed

+308
-218
lines changed
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
//===--- FrontendInputs.h ---------------------------------------*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef SWIFT_FRONTEND_FRONTENDINPUTS_H
14+
#define SWIFT_FRONTEND_FRONTENDINPUTS_H
15+
16+
#include "swift/AST/Module.h"
17+
#include "swift/Frontend/FrontendInputs.h"
18+
#include "swift/Frontend/InputFile.h"
19+
#include "llvm/ADT/Hashing.h"
20+
#include "llvm/ADT/MapVector.h"
21+
22+
#include <string>
23+
#include <vector>
24+
25+
namespace llvm {
26+
class MemoryBuffer;
27+
}
28+
29+
namespace swift {
30+
31+
/// Information about all the inputs to the frontend.
32+
class FrontendInputs {
33+
friend class ArgsToFrontendInputsConverter;
34+
35+
std::vector<InputFile> AllFiles;
36+
typedef llvm::StringMap<unsigned> InputFileMap;
37+
InputFileMap PrimaryInputs;
38+
39+
public:
40+
FrontendInputs() = default;
41+
42+
FrontendInputs(const FrontendInputs &other);
43+
44+
FrontendInputs &operator=(const FrontendInputs &other);
45+
46+
// Readers:
47+
48+
ArrayRef<InputFile> getAllFiles() const { return AllFiles; }
49+
50+
std::vector<std::string> getInputFilenames() const;
51+
52+
unsigned inputCount() const { return getAllFiles().size(); }
53+
54+
bool hasInputs() const { return !AllFiles.empty(); }
55+
56+
bool hasSingleInput() const { return inputCount() == 1; }
57+
58+
StringRef getFilenameOfFirstInput() const;
59+
60+
bool isReadingFromStdin() const;
61+
62+
// If we have exactly one input filename, and its extension is "bc" or "ll",
63+
// treat the input as LLVM_IR.
64+
bool shouldTreatAsLLVM() const;
65+
66+
// Primary input readers
67+
68+
private:
69+
void assertMustNotBeMoreThanOnePrimaryInput() const;
70+
71+
bool areAllNonPrimariesSIB() const;
72+
73+
public:
74+
unsigned primaryInputCount() const { return PrimaryInputs.size(); }
75+
76+
// Primary count readers:
77+
78+
bool hasUniquePrimaryInput() const { return primaryInputCount() == 1; }
79+
80+
bool hasPrimaryInputs() const { return primaryInputCount() > 0; }
81+
82+
bool isWholeModule() const { return !hasPrimaryInputs(); }
83+
84+
// Count-dependend readers:
85+
86+
/// \return the unique primary input, if one exists.
87+
const InputFile *getUniquePrimaryInput() const;
88+
89+
const InputFile &getRequiredUniquePrimaryInput() const;
90+
91+
/// \return the name of the unique primary input, or an empty StrinRef if
92+
/// there isn't one.
93+
StringRef getNameOfUniquePrimaryInputFile() const;
94+
95+
bool isFilePrimary(StringRef file) const;
96+
97+
unsigned numberOfPrimaryInputsEndingWith(const char *extension) const;
98+
99+
// Multi-facet readers
100+
101+
bool shouldTreatAsSIL() const;
102+
103+
/// \return true for error
104+
bool verifyInputs(DiagnosticEngine &diags, bool treatAsSIL,
105+
bool isREPLRequested, bool isNoneRequested) const;
106+
107+
// Writers
108+
109+
void addInputFile(StringRef file, llvm::MemoryBuffer *buffer = nullptr) {
110+
addInput(InputFile(file, false, buffer));
111+
}
112+
void addPrimaryInputFile(StringRef file,
113+
llvm::MemoryBuffer *buffer = nullptr) {
114+
addInput(InputFile(file, true, buffer));
115+
}
116+
117+
void addInput(const InputFile &input);
118+
119+
void clearInputs() {
120+
AllFiles.clear();
121+
PrimaryInputs.clear();
122+
}
123+
};
124+
125+
} // namespace swift
126+
127+
#endif /* SWIFT_FRONTEND_FRONTENDINPUTS_H */

include/swift/Frontend/FrontendOptions.h

Lines changed: 3 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#define SWIFT_FRONTEND_FRONTENDOPTIONS_H
1515

1616
#include "swift/AST/Module.h"
17+
#include "swift/Frontend/FrontendInputs.h"
1718
#include "swift/Frontend/InputFile.h"
1819
#include "llvm/ADT/Hashing.h"
1920

@@ -26,142 +27,6 @@ namespace llvm {
2627

2728
namespace swift {
2829

29-
/// Information about all the inputs to the frontend.
30-
class FrontendInputs {
31-
friend class ArgsToFrontendInputsConverter;
32-
33-
std::vector<InputFile> AllFiles;
34-
typedef llvm::StringMap<unsigned> InputFileMap;
35-
InputFileMap PrimaryInputs;
36-
37-
public:
38-
FrontendInputs() = default;
39-
40-
FrontendInputs(const FrontendInputs &other) {
41-
for (InputFile input : other.getAllFiles())
42-
addInput(input);
43-
}
44-
45-
FrontendInputs &operator=(const FrontendInputs &other) {
46-
clearInputs();
47-
for (InputFile input : other.getAllFiles())
48-
addInput(input);
49-
return *this;
50-
}
51-
52-
// Readers:
53-
54-
ArrayRef<InputFile> getAllFiles() const { return AllFiles; }
55-
56-
std::vector<std::string> getInputFilenames() const {
57-
std::vector<std::string> filenames;
58-
for (auto &input : getAllFiles()) {
59-
filenames.push_back(input.file());
60-
}
61-
return filenames;
62-
}
63-
64-
unsigned inputCount() const { return getAllFiles().size(); }
65-
66-
bool hasInputs() const { return !AllFiles.empty(); }
67-
68-
bool hasSingleInput() const { return inputCount() == 1; }
69-
70-
StringRef getFilenameOfFirstInput() const {
71-
assert(hasInputs());
72-
const InputFile &inp = getAllFiles()[0];
73-
StringRef f = inp.file();
74-
assert(!f.empty());
75-
return f;
76-
}
77-
78-
bool isReadingFromStdin() const {
79-
return hasSingleInput() && getFilenameOfFirstInput() == "-";
80-
}
81-
82-
// If we have exactly one input filename, and its extension is "bc" or "ll",
83-
// treat the input as LLVM_IR.
84-
bool shouldTreatAsLLVM() const;
85-
86-
// Primary input readers
87-
88-
private:
89-
void assertMustNotBeMoreThanOnePrimaryInput() const {
90-
assert(primaryInputCount() < 2 &&
91-
"have not implemented >1 primary input yet");
92-
}
93-
bool areAllNonPrimariesSIB() const;
94-
95-
public:
96-
unsigned primaryInputCount() const { return PrimaryInputs.size(); }
97-
98-
// Primary count readers:
99-
100-
bool hasUniquePrimaryInput() const { return primaryInputCount() == 1; }
101-
102-
bool hasPrimaryInputs() const { return primaryInputCount() > 0; }
103-
104-
bool isWholeModule() const { return !hasPrimaryInputs(); }
105-
106-
// Count-dependend readers:
107-
108-
/// Return the unique primary input, if one exists.
109-
const InputFile *getUniquePrimaryInput() const {
110-
assertMustNotBeMoreThanOnePrimaryInput();
111-
const auto b = PrimaryInputs.begin();
112-
return b == PrimaryInputs.end() ? nullptr : &AllFiles[b->second];
113-
}
114-
115-
const InputFile &getRequiredUniquePrimaryInput() const {
116-
if (const auto *input = getUniquePrimaryInput())
117-
return *input;
118-
llvm_unreachable("No primary when one is required");
119-
}
120-
121-
/// Return the name of the unique primary input, or an empty StrinRef if there
122-
/// isn't one.
123-
StringRef getNameOfUniquePrimaryInputFile() const {
124-
const auto *input = getUniquePrimaryInput();
125-
return input == nullptr ? StringRef() : input->file();
126-
}
127-
128-
bool isFilePrimary(StringRef file) {
129-
auto iterator = PrimaryInputs.find(file);
130-
return iterator != PrimaryInputs.end() &&
131-
AllFiles[iterator->second].isPrimary();
132-
}
133-
134-
unsigned numberOfPrimaryInputsEndingWith(const char *extension) const;
135-
136-
// Multi-facet readers
137-
138-
bool shouldTreatAsSIL() const;
139-
140-
/// Return true for error
141-
bool verifyInputs(DiagnosticEngine &diags, bool treatAsSIL,
142-
bool isREPLRequested, bool isNoneRequested) const;
143-
144-
// Writers
145-
146-
void addInputFile(StringRef file, llvm::MemoryBuffer *buffer = nullptr) {
147-
addInput(InputFile(file, false, buffer));
148-
}
149-
void addPrimaryInputFile(StringRef file,
150-
llvm::MemoryBuffer *buffer = nullptr) {
151-
addInput(InputFile(file, true, buffer));
152-
}
153-
154-
void addInput(const InputFile &input) {
155-
if (!input.file().empty() && input.isPrimary())
156-
PrimaryInputs.insert(std::make_pair(input.file(), AllFiles.size()));
157-
AllFiles.push_back(input);
158-
}
159-
160-
void clearInputs() {
161-
AllFiles.clear();
162-
PrimaryInputs.clear();
163-
}
164-
};
16530

16631
/// Options for controlling the behavior of the frontend.
16732
class FrontendOptions {
@@ -454,8 +319,6 @@ class FrontendOptions {
454319
}
455320

456321
private:
457-
static const char *suffixForPrincipalOutputFileForAction(ActionType);
458-
459322
bool hasUnusedDependenciesFilePath() const;
460323
static bool canActionEmitDependencies(ActionType);
461324
bool hasUnusedObjCHeaderOutputPath() const;
@@ -467,9 +330,11 @@ class FrontendOptions {
467330
bool hasUnusedModuleDocOutputPath() const;
468331
static bool canActionEmitModuleDoc(ActionType);
469332

333+
public:
470334
static bool doesActionProduceOutput(ActionType);
471335
static bool doesActionProduceTextualOutput(ActionType);
472336
static bool needsProperModuleName(ActionType);
337+
static const char *suffixForPrincipalOutputFileForAction(ActionType);
473338
};
474339

475340
}

lib/Frontend/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ add_swift_library(swiftFrontend STATIC
22
CompilerInvocation.cpp
33
DiagnosticVerifier.cpp
44
Frontend.cpp
5+
FrontendInputs.cpp
56
FrontendOptions.cpp
67
PrintingDiagnosticConsumer.cpp
78
SerializedDiagnosticConsumer.cpp

lib/Frontend/CompilerInvocation.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#include "swift/Frontend/Frontend.h"
14+
1415
#include "swift/AST/DiagnosticsFrontend.h"
1516
#include "swift/Basic/Platform.h"
1617
#include "swift/Option/Options.h"

0 commit comments

Comments
 (0)