@@ -45,68 +45,7 @@ template <typename NodeT> class IncludeTreeBase : public ObjectProxy {
45
45
friend class IncludeTreeRoot ;
46
46
};
47
47
48
- // / Represents a \p SourceManager file (or buffer in the case of preprocessor
49
- // / predefines) that got included by the preprocessor.
50
- class IncludeFile : public IncludeTreeBase <IncludeFile> {
51
- public:
52
- static constexpr StringRef getNodeKind () { return " File" ; }
53
-
54
- ObjectRef getFilenameRef () const { return getReference (0 ); }
55
- ObjectRef getContentsRef () const { return getReference (1 ); }
56
-
57
- Expected<ObjectProxy> getFilename () {
58
- return getCAS ().getProxy (getFilenameRef ());
59
- }
60
-
61
- Expected<ObjectProxy> getContents () {
62
- return getCAS ().getProxy (getContentsRef ());
63
- }
64
-
65
- struct FileInfo {
66
- StringRef Filename;
67
- StringRef Contents;
68
- };
69
-
70
- Expected<FileInfo> getFileInfo () {
71
- auto Filename = getFilename ();
72
- if (!Filename)
73
- return Filename.takeError ();
74
- auto Contents = getContents ();
75
- if (!Contents)
76
- return Contents.takeError ();
77
- return FileInfo{Filename->getData (), Contents->getData ()};
78
- }
79
-
80
- static Expected<IncludeFile> create (ObjectStore &DB, StringRef Filename,
81
- ObjectRef Contents);
82
-
83
- llvm::Error print (llvm::raw_ostream &OS, unsigned Indent = 0 );
84
-
85
- static bool isValid (const ObjectProxy &Node) {
86
- if (!IncludeTreeBase::isValid (Node))
87
- return false ;
88
- IncludeTreeBase Base (Node);
89
- return Base.getNumReferences () == 2 && Base.getData ().empty ();
90
- }
91
- static bool isValid (ObjectStore &DB, ObjectRef Ref) {
92
- auto Node = DB.getProxy (Ref);
93
- if (!Node) {
94
- llvm::consumeError (Node.takeError ());
95
- return false ;
96
- }
97
- return isValid (*Node);
98
- }
99
-
100
- private:
101
- friend class IncludeTreeBase <IncludeFile>;
102
- friend class IncludeFileList ;
103
- friend class IncludeTree ;
104
- friend class IncludeTreeRoot ;
105
-
106
- explicit IncludeFile (ObjectProxy Node) : IncludeTreeBase(std::move(Node)) {
107
- assert (isValid (*this ));
108
- }
109
- };
48
+ class IncludeFile ;
110
49
111
50
// / Represents a DAG of included files by the preprocessor.
112
51
// / Each node in the DAG represents a particular inclusion of a file that
@@ -117,22 +56,17 @@ class IncludeTree : public IncludeTreeBase<IncludeTree> {
117
56
public:
118
57
static constexpr StringRef getNodeKind () { return " Tree" ; }
119
58
120
- Expected<IncludeFile> getBaseFile () {
121
- auto Node = getCAS ().getProxy (getBaseFileRef ());
122
- if (!Node)
123
- return Node.takeError ();
124
- return IncludeFile (std::move (*Node));
125
- }
59
+ Expected<IncludeFile> getBaseFile ();
126
60
127
61
// / The include file that resulted in this include-tree.
128
62
ObjectRef getBaseFileRef () const { return getReference (0 ); }
129
63
130
- Expected<IncludeFile::FileInfo> getBaseFileInfo () {
131
- auto File = getBaseFile () ;
132
- if (!File)
133
- return File. takeError () ;
134
- return File-> getFileInfo ();
135
- }
64
+ struct FileInfo {
65
+ StringRef Filename ;
66
+ StringRef Contents;
67
+ } ;
68
+
69
+ Expected<FileInfo> getBaseFileInfo ();
136
70
137
71
SrcMgr::CharacteristicKind getFileCharacteristic () const {
138
72
return (SrcMgr::CharacteristicKind)dataSkippingIncludes ().front ();
@@ -216,6 +150,64 @@ class IncludeTree : public IncludeTreeBase<IncludeTree> {
216
150
}
217
151
};
218
152
153
+ // / Represents a \p SourceManager file (or buffer in the case of preprocessor
154
+ // / predefines) that got included by the preprocessor.
155
+ class IncludeFile : public IncludeTreeBase <IncludeFile> {
156
+ public:
157
+ static constexpr StringRef getNodeKind () { return " File" ; }
158
+
159
+ ObjectRef getFilenameRef () const { return getReference (0 ); }
160
+ ObjectRef getContentsRef () const { return getReference (1 ); }
161
+
162
+ Expected<ObjectProxy> getFilename () {
163
+ return getCAS ().getProxy (getFilenameRef ());
164
+ }
165
+
166
+ Expected<ObjectProxy> getContents () {
167
+ return getCAS ().getProxy (getContentsRef ());
168
+ }
169
+
170
+ Expected<IncludeTree::FileInfo> getFileInfo () {
171
+ auto Filename = getFilename ();
172
+ if (!Filename)
173
+ return Filename.takeError ();
174
+ auto Contents = getContents ();
175
+ if (!Contents)
176
+ return Contents.takeError ();
177
+ return IncludeTree::FileInfo{Filename->getData (), Contents->getData ()};
178
+ }
179
+
180
+ static Expected<IncludeFile> create (ObjectStore &DB, StringRef Filename,
181
+ ObjectRef Contents);
182
+
183
+ llvm::Error print (llvm::raw_ostream &OS, unsigned Indent = 0 );
184
+
185
+ static bool isValid (const ObjectProxy &Node) {
186
+ if (!IncludeTreeBase::isValid (Node))
187
+ return false ;
188
+ IncludeTreeBase Base (Node);
189
+ return Base.getNumReferences () == 2 && Base.getData ().empty ();
190
+ }
191
+ static bool isValid (ObjectStore &DB, ObjectRef Ref) {
192
+ auto Node = DB.getProxy (Ref);
193
+ if (!Node) {
194
+ llvm::consumeError (Node.takeError ());
195
+ return false ;
196
+ }
197
+ return isValid (*Node);
198
+ }
199
+
200
+ private:
201
+ friend class IncludeTreeBase <IncludeFile>;
202
+ friend class IncludeFileList ;
203
+ friend class IncludeTree ;
204
+ friend class IncludeTreeRoot ;
205
+
206
+ explicit IncludeFile (ObjectProxy Node) : IncludeTreeBase(std::move(Node)) {
207
+ assert (isValid (*this ));
208
+ }
209
+ };
210
+
219
211
// / A flat list of \p IncludeFile entries. This is used along with a simple
220
212
// / implementation of a \p vfs::FileSystem produced via
221
213
// / \p createIncludeTreeFileSystem().
0 commit comments