clang 23.0.0git
APINotesReader.h
Go to the documentation of this file.
1//===--- APINotesReader.h - API Notes Reader --------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines the \c APINotesReader class that reads source API notes
10// data providing additional information about source code as a separate input,
11// such as the non-nil/nilable annotations for method parameters.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_CLANG_APINOTES_READER_H
16#define LLVM_CLANG_APINOTES_READER_H
17
19#include "llvm/Support/Error.h"
20#include "llvm/Support/MemoryBuffer.h"
21#include "llvm/Support/VersionTuple.h"
22#include <memory>
23
24namespace clang {
25namespace api_notes {
26
27/// A class that reads API notes data from a binary file that was written by
28/// the \c APINotesWriter.
29class APINotesReader {
30 class Implementation;
31 std::unique_ptr<Implementation> Implementation;
32
33 APINotesReader(llvm::MemoryBuffer *InputBuffer,
34 llvm::VersionTuple SwiftVersion, llvm::Error &Err);
35
36public:
37 /// Create a new API notes reader from the given memory buffer, which
38 /// contains the contents of a binary API notes file.
39 ///
40 /// \returns the new API notes reader, or an error if one occurred.
42 Create(std::unique_ptr<llvm::MemoryBuffer> InputBuffer,
43 llvm::VersionTuple SwiftVersion);
44
46
47 APINotesReader(const APINotesReader &) = delete;
48 APINotesReader &operator=(const APINotesReader &) = delete;
49
50 /// Captures the completed versioned information for a particular part of
51 /// API notes, including both unversioned API notes and each versioned API
52 /// note for that particular entity.
53 template <typename T> class VersionedInfo {
54 /// The complete set of results.
56
57 /// The index of the result that is the "selected" set based on the desired
58 /// Swift version, or null if nothing matched.
59 std::optional<unsigned> Selected;
60
61 public:
62 /// Form an empty set of versioned information.
63 VersionedInfo(std::nullopt_t) : Selected(std::nullopt) {}
64
65 /// Form a versioned info set given the desired version and a set of
66 /// results.
68 llvm::VersionTuple Version,
69 llvm::SmallVector<std::pair<llvm::VersionTuple, T>, 1> Results);
70
71 /// Retrieve the selected index in the result set.
72 std::optional<unsigned> getSelected() const { return Selected; }
73
74 /// Return the number of versioned results we know about.
75 unsigned size() const { return Results.size(); }
76
77 /// Access all versioned results.
78 const std::pair<llvm::VersionTuple, T> *begin() const {
79 assert(!Results.empty());
80 return Results.begin();
81 }
82 const std::pair<llvm::VersionTuple, T> *end() const {
83 return Results.end();
84 }
85
86 /// Access a specific versioned result.
87 const std::pair<llvm::VersionTuple, T> &operator[](unsigned index) const {
88 assert(index < Results.size());
89 return Results[index];
90 }
91 };
92
93 /// Look for the context ID of the given Objective-C class.
94 ///
95 /// \param Name The name of the class we're looking for.
96 ///
97 /// \returns The ID, if known.
98 std::optional<ContextID> lookupObjCClassID(llvm::StringRef Name);
99
100 /// Look for information regarding the given Objective-C class.
101 ///
102 /// \param Name The name of the class we're looking for.
103 ///
104 /// \returns The information about the class, if known.
105 VersionedInfo<ContextInfo> lookupObjCClassInfo(llvm::StringRef Name);
106
107 /// Look for the context ID of the given Objective-C protocol.
108 ///
109 /// \param Name The name of the protocol we're looking for.
110 ///
111 /// \returns The ID of the protocol, if known.
112 std::optional<ContextID> lookupObjCProtocolID(llvm::StringRef Name);
113
114 /// Look for information regarding the given Objective-C protocol.
115 ///
116 /// \param Name The name of the protocol we're looking for.
117 ///
118 /// \returns The information about the protocol, if known.
119 VersionedInfo<ContextInfo> lookupObjCProtocolInfo(llvm::StringRef Name);
120
121 /// Look for information regarding the given Objective-C property in
122 /// the given context.
123 ///
124 /// \param CtxID The ID that references the context we are looking for.
125 /// \param Name The name of the property we're looking for.
126 /// \param IsInstance Whether we are looking for an instance property (vs.
127 /// a class property).
128 ///
129 /// \returns Information about the property, if known.
130 VersionedInfo<ObjCPropertyInfo>
131 lookupObjCProperty(ContextID CtxID, llvm::StringRef Name, bool IsInstance);
132
133 /// Look for information regarding the given Objective-C method in
134 /// the given context.
135 ///
136 /// \param CtxID The ID that references the context we are looking for.
137 /// \param Selector The selector naming the method we're looking for.
138 /// \param IsInstanceMethod Whether we are looking for an instance method.
139 ///
140 /// \returns Information about the method, if known.
141 VersionedInfo<ObjCMethodInfo> lookupObjCMethod(ContextID CtxID,
143 bool IsInstanceMethod);
144
145 /// Look for information regarding the given field of a C struct.
146 ///
147 /// \param Name The name of the field.
148 ///
149 /// \returns information about the field, if known.
150 VersionedInfo<FieldInfo> lookupField(ContextID CtxID, llvm::StringRef Name);
151
152 /// Look for information regarding the given C++ method in the given C++ tag
153 /// context.
154 ///
155 /// \param CtxID The ID that references the parent context, i.e. a C++ tag.
156 /// \param Name The name of the C++ method we're looking for.
157 ///
158 /// \returns Information about the method, if known.
159 VersionedInfo<CXXMethodInfo> lookupCXXMethod(ContextID CtxID,
160 llvm::StringRef Name);
161
162 /// Look for information regarding the given global variable.
163 ///
164 /// \param Name The name of the global variable.
165 ///
166 /// \returns information about the global variable, if known.
167 VersionedInfo<GlobalVariableInfo>
168 lookupGlobalVariable(llvm::StringRef Name,
169 std::optional<Context> Ctx = std::nullopt);
170
171 /// Look for information regarding the given global function.
172 ///
173 /// \param Name The name of the global function.
174 ///
175 /// \returns information about the global function, if known.
176 VersionedInfo<GlobalFunctionInfo>
177 lookupGlobalFunction(llvm::StringRef Name,
178 std::optional<Context> Ctx = std::nullopt);
179
180 /// Look for information regarding the given enumerator.
181 ///
182 /// \param Name The name of the enumerator.
183 ///
184 /// \returns information about the enumerator, if known.
185 VersionedInfo<EnumConstantInfo> lookupEnumConstant(llvm::StringRef Name);
186
187 /// Look for the context ID of the given C++ tag.
188 ///
189 /// \param Name The name of the tag we're looking for.
190 /// \param ParentCtx The context in which this tag is declared, e.g. a C++
191 /// namespace.
192 ///
193 /// \returns The ID, if known.
194 std::optional<ContextID>
195 lookupTagID(llvm::StringRef Name,
196 std::optional<Context> ParentCtx = std::nullopt);
197
198 /// Look for information regarding the given tag
199 /// (struct/union/enum/C++ class).
200 ///
201 /// \param Name The name of the tag.
202 ///
203 /// \returns information about the tag, if known.
204 VersionedInfo<TagInfo> lookupTag(llvm::StringRef Name,
205 std::optional<Context> Ctx = std::nullopt);
206
207 /// Look for information regarding the given typedef.
208 ///
209 /// \param Name The name of the typedef.
210 ///
211 /// \returns information about the typedef, if known.
212 VersionedInfo<TypedefInfo>
213 lookupTypedef(llvm::StringRef Name,
214 std::optional<Context> Ctx = std::nullopt);
215
216 /// Look for the context ID of the given C++ namespace.
217 ///
218 /// \param Name The name of the class we're looking for.
219 ///
220 /// \returns The ID, if known.
221 std::optional<ContextID>
222 lookupNamespaceID(llvm::StringRef Name,
223 std::optional<ContextID> ParentNamespaceID = std::nullopt);
224};
225
226} // end namespace api_notes
227} // end namespace clang
228
229#endif // LLVM_CLANG_APINOTES_READER_H
Smart pointer class that efficiently represents Objective-C method names.
VersionedInfo(std::nullopt_t)
Form an empty set of versioned information.
const std::pair< llvm::VersionTuple, T > & operator[](unsigned index) const
Access a specific versioned result.
const std::pair< llvm::VersionTuple, T > * end() const
unsigned size() const
Return the number of versioned results we know about.
std::optional< unsigned > getSelected() const
Retrieve the selected index in the result set.
const std::pair< llvm::VersionTuple, T > * begin() const
Access all versioned results.
VersionedInfo< ContextInfo > lookupObjCClassInfo(llvm::StringRef Name)
Look for information regarding the given Objective-C class.
VersionedInfo< FieldInfo > lookupField(ContextID CtxID, llvm::StringRef Name)
Look for information regarding the given field of a C struct.
VersionedInfo< CXXMethodInfo > lookupCXXMethod(ContextID CtxID, llvm::StringRef Name)
Look for information regarding the given C++ method in the given C++ tag context.
VersionedInfo< TagInfo > lookupTag(llvm::StringRef Name, std::optional< Context > Ctx=std::nullopt)
Look for information regarding the given tag (struct/union/enum/C++ class).
VersionedInfo< GlobalFunctionInfo > lookupGlobalFunction(llvm::StringRef Name, std::optional< Context > Ctx=std::nullopt)
Look for information regarding the given global function.
VersionedInfo< ObjCPropertyInfo > lookupObjCProperty(ContextID CtxID, llvm::StringRef Name, bool IsInstance)
Look for information regarding the given Objective-C property in the given context.
VersionedInfo< ObjCMethodInfo > lookupObjCMethod(ContextID CtxID, ObjCSelectorRef Selector, bool IsInstanceMethod)
Look for information regarding the given Objective-C method in the given context.
VersionedInfo< GlobalVariableInfo > lookupGlobalVariable(llvm::StringRef Name, std::optional< Context > Ctx=std::nullopt)
Look for information regarding the given global variable.
std::optional< ContextID > lookupNamespaceID(llvm::StringRef Name, std::optional< ContextID > ParentNamespaceID=std::nullopt)
Look for the context ID of the given C++ namespace.
std::optional< ContextID > lookupTagID(llvm::StringRef Name, std::optional< Context > ParentCtx=std::nullopt)
Look for the context ID of the given C++ tag.
VersionedInfo< TypedefInfo > lookupTypedef(llvm::StringRef Name, std::optional< Context > Ctx=std::nullopt)
Look for information regarding the given typedef.
std::optional< ContextID > lookupObjCClassID(llvm::StringRef Name)
Look for the context ID of the given Objective-C class.
APINotesReader & operator=(const APINotesReader &)=delete
VersionedInfo< ContextInfo > lookupObjCProtocolInfo(llvm::StringRef Name)
Look for information regarding the given Objective-C protocol.
std::optional< ContextID > lookupObjCProtocolID(llvm::StringRef Name)
Look for the context ID of the given Objective-C protocol.
VersionedInfo< EnumConstantInfo > lookupEnumConstant(llvm::StringRef Name)
Look for information regarding the given enumerator.
APINotesReader(const APINotesReader &)=delete
Opaque context ID used to refer to an Objective-C class or protocol or a C++ namespace.
Definition Types.h:901
The JSON file list parser is used to communicate input to InstallAPI.
@ Create
'create' clause, allowed on Compute and Combined constructs, plus 'data', 'enter data',...
A temporary reference to an Objective-C selector, suitable for referencing selector data on the stack...
Definition Types.h:928