Skip to content

Commit 4ac390d

Browse files
author
David Ungar
committed
Move InputFile into a dedicated header.
1 parent 82d4386 commit 4ac390d

File tree

2 files changed

+66
-41
lines changed

2 files changed

+66
-41
lines changed

include/swift/Frontend/FrontendOptions.h

Lines changed: 1 addition & 41 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/InputFile.h"
1718
#include "llvm/ADT/Hashing.h"
1819

1920
#include <string>
@@ -25,47 +26,6 @@ namespace llvm {
2526

2627
namespace swift {
2728

28-
enum class InputFileKind {
29-
IFK_None,
30-
IFK_Swift,
31-
IFK_Swift_Library,
32-
IFK_Swift_REPL,
33-
IFK_SIL,
34-
IFK_LLVM_IR
35-
};
36-
37-
// Inputs may include buffers that override contents, and eventually should
38-
// always include a buffer.
39-
class InputFile {
40-
std::string Filename;
41-
bool IsPrimary;
42-
/// Null if the contents are not overridden.
43-
llvm::MemoryBuffer *Buffer;
44-
45-
public:
46-
/// Does not take ownership of \p buffer. Does take ownership of (copy) a
47-
/// string.
48-
InputFile(StringRef name, bool isPrimary,
49-
llvm::MemoryBuffer *buffer = nullptr)
50-
: Filename(name), IsPrimary(isPrimary), Buffer(buffer) {
51-
assert(!name.empty());
52-
}
53-
54-
bool isPrimary() const { return IsPrimary; }
55-
llvm::MemoryBuffer *buffer() const { return Buffer; }
56-
StringRef file() const {
57-
assert(!Filename.empty());
58-
return Filename;
59-
}
60-
61-
/// Return Swift-standard file name from a buffer name set by
62-
/// llvm::MemoryBuffer::getFileOrSTDIN, which uses "<stdin>" instead of "-".
63-
static StringRef convertBufferNameFromLLVM_getFileOrSTDIN_toSwiftConventions(
64-
StringRef filename) {
65-
return filename.equals("<stdin>") ? "-" : filename;
66-
}
67-
};
68-
6929
/// Information about all the inputs to the frontend.
7030
class FrontendInputs {
7131
friend class ArgsToFrontendInputsConverter;

include/swift/Frontend/InputFile.h

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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

Comments
 (0)