1
- // ===- SymbolGraph /API.h ----------------------------------------*- C++ -*-===//
1
+ // ===- ExtractAPI /API.h - ----------------------------------------*- C++ -*-===//
2
2
//
3
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
4
// See https://llvm.org/LICENSE.txt for license information.
7
7
// ===----------------------------------------------------------------------===//
8
8
// /
9
9
// / \file
10
- // / \brief Defines SymbolGraph API records.
10
+ // / This file defines the APIRecord-based structs and the APISet class.
11
+ // /
12
+ // / Clang ExtractAPI is a tool to collect API information from a given set of
13
+ // / header files. The structures in this file describe data representations of
14
+ // / the API information collected for various kinds of symbols.
11
15
// /
12
16
// ===----------------------------------------------------------------------===//
13
17
14
- #ifndef LLVM_CLANG_SYMBOLGRAPH_API_H
15
- #define LLVM_CLANG_SYMBOLGRAPH_API_H
18
+ #ifndef LLVM_CLANG_EXTRACTAPI_API_H
19
+ #define LLVM_CLANG_EXTRACTAPI_API_H
16
20
17
21
#include " clang/AST/Decl.h"
18
22
#include " clang/AST/RawCommentList.h"
19
23
#include " clang/Basic/SourceLocation.h"
20
- #include " clang/SymbolGraph /AvailabilityInfo.h"
21
- #include " clang/SymbolGraph /DeclarationFragments.h"
24
+ #include " clang/ExtractAPI /AvailabilityInfo.h"
25
+ #include " clang/ExtractAPI /DeclarationFragments.h"
22
26
#include " llvm/ADT/MapVector.h"
23
27
#include " llvm/ADT/StringRef.h"
24
28
#include " llvm/ADT/Triple.h"
27
31
#include < memory>
28
32
29
33
namespace clang {
30
- namespace symbolgraph {
34
+ namespace extractapi {
31
35
36
+ // / DocComment is a vector of RawComment::CommentLine.
37
+ // /
38
+ // / Each line represents one line of striped documentation comment,
39
+ // / with source range information. This simplifies calculating the source
40
+ // / location of a character in the doc comment for pointing back to the source
41
+ // / file.
42
+ // / e.g.
43
+ // / \code
44
+ // / /// This is a documentation comment
45
+ // / ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~' First line.
46
+ // / /// with multiple lines.
47
+ // / ^~~~~~~~~~~~~~~~~~~~~~~' Second line.
48
+ // / \endcode
32
49
using DocComment = std::vector<RawComment::CommentLine>;
33
50
51
+ // / The base representation of an API record. Holds common symbol information.
34
52
struct APIRecord {
35
53
StringRef Name;
36
54
StringRef USR;
37
55
PresumedLoc Location;
38
56
AvailabilityInfo Availability;
39
57
LinkageInfo Linkage;
58
+
59
+ // / Documentation comment lines attached to this symbol declaration.
40
60
DocComment Comment;
61
+
62
+ // / Declaration fragments of this symbol declaration.
41
63
DeclarationFragments Declaration;
64
+
65
+ // / SubHeading provides a more detailed representation than the plain
66
+ // / declaration name.
67
+ // /
68
+ // / SubHeading is an array of declaration fragments of tagged declaration
69
+ // / name, with potentially more tokens (for example the \c +/- symbol for
70
+ // / Objective-C class/instance methods).
42
71
DeclarationFragments SubHeading;
43
72
44
73
// / Discriminator for LLVM-style RTTI (dyn_cast<> et al.)
@@ -66,14 +95,18 @@ struct APIRecord {
66
95
virtual ~APIRecord () = 0 ;
67
96
};
68
97
98
+ // / The kind of a global record.
69
99
enum class GVKind : uint8_t {
70
100
Unknown = 0 ,
71
101
Variable = 1 ,
72
102
Function = 2 ,
73
103
};
74
104
105
+ // / This holds information associated with global variables or functions.
75
106
struct GlobalRecord : APIRecord {
76
107
GVKind GlobalKind;
108
+
109
+ // / The function signature of the record if it is a function.
77
110
FunctionSignature Signature;
78
111
79
112
GlobalRecord (GVKind Kind, StringRef Name, StringRef USR, PresumedLoc Loc,
@@ -87,40 +120,52 @@ struct GlobalRecord : APIRecord {
87
120
static bool classof (const APIRecord *Record) {
88
121
return Record->getKind () == RK_Global;
89
122
}
123
+
124
+ private:
125
+ virtual void anchor ();
90
126
};
91
127
128
+ // / APISet holds the set of API records collected from given inputs.
92
129
class APISet {
93
130
public:
94
- APISet ( const llvm::Triple &Target, const LangOptions &LangOpts)
95
- : Target(Target), LangOpts(LangOpts) {}
96
-
97
- const llvm::Triple & getTarget () const { return Target; }
98
- const LangOptions & getLangOpts () const { return LangOpts; }
99
-
131
+ // / Create and add a GlobalRecord of kind \p Kind into the API set.
132
+ // /
133
+ // / Note: the caller is responsible for keeping the StringRef \p Name and
134
+ // / \p USR alive. APISet::copyString provides a way to copy strings into
135
+ // / APISet itself, and APISet::recordUSR( const Decl *D) is a helper method
136
+ // / to generate the USR for \c D and keep it alive in APISet.
100
137
GlobalRecord *addGlobal (GVKind Kind, StringRef Name, StringRef USR,
101
138
PresumedLoc Loc, const AvailabilityInfo &Availability,
102
139
LinkageInfo Linkage, const DocComment &Comment,
103
140
DeclarationFragments Declaration,
104
141
DeclarationFragments SubHeading,
105
142
FunctionSignature Signature);
106
143
144
+ // / Create and add a global variable record into the API set.
145
+ // /
146
+ // / Note: the caller is responsible for keeping the StringRef \p Name and
147
+ // / \p USR alive. APISet::copyString provides a way to copy strings into
148
+ // / APISet itself, and APISet::recordUSR(const Decl *D) is a helper method
149
+ // / to generate the USR for \c D and keep it alive in APISet.
107
150
GlobalRecord *addGlobalVar (StringRef Name, StringRef USR, PresumedLoc Loc,
108
151
const AvailabilityInfo &Availability,
109
152
LinkageInfo Linkage, const DocComment &Comment,
110
153
DeclarationFragments Declaration,
111
154
DeclarationFragments SubHeading);
112
155
156
+ // / Create and add a function record into the API set.
157
+ // /
158
+ // / Note: the caller is responsible for keeping the StringRef \p Name and
159
+ // / \p USR alive. APISet::copyString provides a way to copy strings into
160
+ // / APISet itself, and APISet::recordUSR(const Decl *D) is a helper method
161
+ // / to generate the USR for \c D and keep it alive in APISet.
113
162
GlobalRecord *addFunction (StringRef Name, StringRef USR, PresumedLoc Loc,
114
163
const AvailabilityInfo &Availability,
115
164
LinkageInfo Linkage, const DocComment &Comment,
116
165
DeclarationFragments Declaration,
117
166
DeclarationFragments SubHeading,
118
167
FunctionSignature Signature);
119
168
120
- StringRef recordUSR (const Decl *D);
121
- StringRef copyString (StringRef String, llvm::BumpPtrAllocator &Allocator);
122
- StringRef copyString (StringRef String);
123
-
124
169
private:
125
170
// / \brief A custom deleter used for ``std::unique_ptr`` to APIRecords stored
126
171
// / in the BumpPtrAllocator.
@@ -138,20 +183,45 @@ class APISet {
138
183
using APIRecordUniquePtr =
139
184
std::unique_ptr<T, UniquePtrBumpPtrAllocatorDeleter<T>>;
140
185
186
+ // / A map to store the set of GlobalRecord%s with the declaration name as the
187
+ // / key.
141
188
using GlobalRecordMap =
142
189
llvm::MapVector<StringRef, APIRecordUniquePtr<GlobalRecord>>;
143
190
191
+ // / Get the target triple for the ExtractAPI invocation.
192
+ const llvm::Triple &getTarget () const { return Target; }
193
+
194
+ // / Get the language options used to parse the APIs.
195
+ const LangOptions &getLangOpts () const { return LangOpts; }
196
+
144
197
const GlobalRecordMap &getGlobals () const { return Globals; }
145
198
199
+ // / Generate and store the USR of declaration \p D.
200
+ // /
201
+ // / Note: The USR string is stored in and owned by Allocator.
202
+ // /
203
+ // / \returns a StringRef of the generated USR string.
204
+ StringRef recordUSR (const Decl *D);
205
+
206
+ // / Copy \p String into the Allocator in this APISet.
207
+ // /
208
+ // / \returns a StringRef of the copied string in APISet::Allocator.
209
+ StringRef copyString (StringRef String);
210
+
211
+ APISet (const llvm::Triple &Target, const LangOptions &LangOpts)
212
+ : Target(Target), LangOpts(LangOpts) {}
213
+
146
214
private:
215
+ // / BumpPtrAllocator to store APIRecord%s and generated/copied strings.
147
216
llvm::BumpPtrAllocator Allocator;
217
+
148
218
const llvm::Triple Target;
149
219
const LangOptions LangOpts;
150
220
151
221
GlobalRecordMap Globals;
152
222
};
153
223
154
- } // namespace symbolgraph
224
+ } // namespace extractapi
155
225
} // namespace clang
156
226
157
- #endif // LLVM_CLANG_SYMBOLGRAPH_API_H
227
+ #endif // LLVM_CLANG_EXTRACTAPI_API_H
0 commit comments