@@ -53,27 +53,30 @@ class InputFile {
53
53
// / caller to ensure that an associated memory buffer outlives the \c InputFile.
54
54
class InputFile final {
55
55
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;
66
58
PrimarySpecificPaths PSPs;
67
59
68
60
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.
71
67
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)
74
76
: Filename(
75
77
convertBufferNameFromLLVM_getFileOrSTDIN_toSwiftConventions (name)),
76
- IsPrimary(isPrimary), Buffer(buffer), PSPs(PrimarySpecificPaths()) {
78
+ FileID(FileID), BufferAndIsPrimary(buffer, isPrimary),
79
+ PSPs(PrimarySpecificPaths()) {
77
80
assert (!name.empty ());
78
81
}
79
82
0 commit comments