|
| 1 | +//===--- InputFile.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_INPUTFILE_H |
| 14 | +#define SWIFT_FRONTEND_INPUTFILE_H |
| 15 | + |
| 16 | +#include "llvm/Support/MemoryBuffer.h" |
| 17 | +#include <string> |
| 18 | +#include <vector> |
| 19 | + |
| 20 | +namespace swift { |
| 21 | + |
| 22 | +enum class InputFileKind { |
| 23 | + IFK_None, |
| 24 | + IFK_Swift, |
| 25 | + IFK_Swift_Library, |
| 26 | + IFK_Swift_REPL, |
| 27 | + IFK_SIL, |
| 28 | + IFK_LLVM_IR |
| 29 | +}; |
| 30 | + |
| 31 | +// Inputs may include buffers that override contents, and eventually should |
| 32 | +// always include a buffer. |
| 33 | +class InputFile { |
| 34 | + std::string Filename; |
| 35 | + bool IsPrimary; |
| 36 | + /// Null if the contents are not overridden. |
| 37 | + llvm::MemoryBuffer *Buffer; |
| 38 | + |
| 39 | +public: |
| 40 | + /// Does not take ownership of \p buffer. Does take ownership of (copy) a |
| 41 | + /// string. |
| 42 | + InputFile(StringRef name, bool isPrimary, |
| 43 | + llvm::MemoryBuffer *buffer = nullptr) |
| 44 | + : Filename(name), IsPrimary(isPrimary), Buffer(buffer) { |
| 45 | + assert(!name.empty()); |
| 46 | + } |
| 47 | + |
| 48 | + bool isPrimary() const { return IsPrimary; } |
| 49 | + llvm::MemoryBuffer *buffer() const { return Buffer; } |
| 50 | + StringRef file() const { |
| 51 | + assert(!Filename.empty()); |
| 52 | + return Filename; |
| 53 | + } |
| 54 | + |
| 55 | + /// Return Swift-standard file name from a buffer name set by |
| 56 | + /// llvm::MemoryBuffer::getFileOrSTDIN, which uses "<stdin>" instead of "-". |
| 57 | + static StringRef convertBufferNameFromLLVM_getFileOrSTDIN_toSwiftConventions( |
| 58 | + StringRef filename) { |
| 59 | + return filename.equals("<stdin>") ? "-" : filename; |
| 60 | + } |
| 61 | +}; |
| 62 | + |
| 63 | +} // namespace swift |
| 64 | + |
| 65 | +#endif /* SWIFT_FRONTEND_INPUTFILE_H */ |
0 commit comments