Skip to content

Commit c7f0f24

Browse files
committed
[NFC] Refactor InputFile Construction
Add a new constructor that takes an explicit file_type::ID to allow for the eventual deletion of InputFileKind.
1 parent 66ad0c1 commit c7f0f24

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

include/swift/Frontend/InputFile.h

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -53,27 +53,30 @@ class InputFile {
5353
/// caller to ensure that an associated memory buffer outlives the \c InputFile.
5454
class InputFile final {
5555
std::string Filename;
56-
bool IsPrimary;
57-
/// Points to a buffer overriding the file's contents, or nullptr if there is
58-
/// none.
59-
llvm::MemoryBuffer *Buffer;
60-
61-
/// If there are explicit primary inputs (i.e. designated with -primary-input
62-
/// or -primary-filelist), the paths specific to those inputs (other than the
63-
/// input file path itself) are kept here. If there are no explicit primary
64-
/// inputs (for instance for whole module optimization), the corresponding
65-
/// paths are kept in the first input file.
56+
file_types::ID FileID;
57+
llvm::PointerIntPair<llvm::MemoryBuffer *, 1, bool> BufferAndIsPrimary;
6658
PrimarySpecificPaths PSPs;
6759

6860
public:
69-
/// Does not take ownership of \p buffer. Does take ownership of (copy) a
70-
/// string.
61+
/// Constructs an input file from the provided data.
62+
///
63+
/// \warning This entrypoint infers the type of the file from its extension
64+
/// and is therefore not suitable for most clients that use files synthesized
65+
/// from memory buffers. Use the overload of this constructor accepting a
66+
/// memory buffer and an explicit \c file_types::ID instead.
7167
InputFile(StringRef name, bool isPrimary,
72-
llvm::MemoryBuffer *buffer = nullptr,
73-
StringRef outputFilename = StringRef())
68+
llvm::MemoryBuffer *buffer = nullptr)
69+
: InputFile(name, isPrimary, buffer,
70+
file_types::lookupTypeForExtension(
71+
llvm::sys::path::extension(name))) {}
72+
73+
/// Constructs an input file from the provided data.
74+
InputFile(StringRef name, bool isPrimary, llvm::MemoryBuffer *buffer,
75+
file_types::ID FileID)
7476
: Filename(
7577
convertBufferNameFromLLVM_getFileOrSTDIN_toSwiftConventions(name)),
76-
IsPrimary(isPrimary), Buffer(buffer), PSPs(PrimarySpecificPaths()) {
78+
FileID(FileID), BufferAndIsPrimary(buffer, isPrimary),
79+
PSPs(PrimarySpecificPaths()) {
7780
assert(!name.empty());
7881
}
7982

0 commit comments

Comments
 (0)