|
|
|||
File indexing completed on 2026-05-10 08:36:27
0001 //===--- APINotesReader.h - API Notes Reader --------------------*- C++ -*-===// 0002 // 0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 0004 // See https://llvm.org/LICENSE.txt for license information. 0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 0006 // 0007 //===----------------------------------------------------------------------===// 0008 // 0009 // This file defines the \c APINotesReader class that reads source API notes 0010 // data providing additional information about source code as a separate input, 0011 // such as the non-nil/nilable annotations for method parameters. 0012 // 0013 //===----------------------------------------------------------------------===// 0014 0015 #ifndef LLVM_CLANG_APINOTES_READER_H 0016 #define LLVM_CLANG_APINOTES_READER_H 0017 0018 #include "clang/APINotes/Types.h" 0019 #include "llvm/Support/MemoryBuffer.h" 0020 #include "llvm/Support/VersionTuple.h" 0021 #include <memory> 0022 0023 namespace clang { 0024 namespace api_notes { 0025 0026 /// A class that reads API notes data from a binary file that was written by 0027 /// the \c APINotesWriter. 0028 class APINotesReader { 0029 class Implementation; 0030 std::unique_ptr<Implementation> Implementation; 0031 0032 APINotesReader(llvm::MemoryBuffer *InputBuffer, 0033 llvm::VersionTuple SwiftVersion, bool &Failed); 0034 0035 public: 0036 /// Create a new API notes reader from the given member buffer, which 0037 /// contains the contents of a binary API notes file. 0038 /// 0039 /// \returns the new API notes reader, or null if an error occurred. 0040 static std::unique_ptr<APINotesReader> 0041 Create(std::unique_ptr<llvm::MemoryBuffer> InputBuffer, 0042 llvm::VersionTuple SwiftVersion); 0043 0044 ~APINotesReader(); 0045 0046 APINotesReader(const APINotesReader &) = delete; 0047 APINotesReader &operator=(const APINotesReader &) = delete; 0048 0049 /// Captures the completed versioned information for a particular part of 0050 /// API notes, including both unversioned API notes and each versioned API 0051 /// note for that particular entity. 0052 template <typename T> class VersionedInfo { 0053 /// The complete set of results. 0054 llvm::SmallVector<std::pair<llvm::VersionTuple, T>, 1> Results; 0055 0056 /// The index of the result that is the "selected" set based on the desired 0057 /// Swift version, or null if nothing matched. 0058 std::optional<unsigned> Selected; 0059 0060 public: 0061 /// Form an empty set of versioned information. 0062 VersionedInfo(std::nullopt_t) : Selected(std::nullopt) {} 0063 0064 /// Form a versioned info set given the desired version and a set of 0065 /// results. 0066 VersionedInfo( 0067 llvm::VersionTuple Version, 0068 llvm::SmallVector<std::pair<llvm::VersionTuple, T>, 1> Results); 0069 0070 /// Retrieve the selected index in the result set. 0071 std::optional<unsigned> getSelected() const { return Selected; } 0072 0073 /// Return the number of versioned results we know about. 0074 unsigned size() const { return Results.size(); } 0075 0076 /// Access all versioned results. 0077 const std::pair<llvm::VersionTuple, T> *begin() const { 0078 assert(!Results.empty()); 0079 return Results.begin(); 0080 } 0081 const std::pair<llvm::VersionTuple, T> *end() const { 0082 return Results.end(); 0083 } 0084 0085 /// Access a specific versioned result. 0086 const std::pair<llvm::VersionTuple, T> &operator[](unsigned index) const { 0087 assert(index < Results.size()); 0088 return Results[index]; 0089 } 0090 }; 0091 0092 /// Look for the context ID of the given Objective-C class. 0093 /// 0094 /// \param Name The name of the class we're looking for. 0095 /// 0096 /// \returns The ID, if known. 0097 std::optional<ContextID> lookupObjCClassID(llvm::StringRef Name); 0098 0099 /// Look for information regarding the given Objective-C class. 0100 /// 0101 /// \param Name The name of the class we're looking for. 0102 /// 0103 /// \returns The information about the class, if known. 0104 VersionedInfo<ContextInfo> lookupObjCClassInfo(llvm::StringRef Name); 0105 0106 /// Look for the context ID of the given Objective-C protocol. 0107 /// 0108 /// \param Name The name of the protocol we're looking for. 0109 /// 0110 /// \returns The ID of the protocol, if known. 0111 std::optional<ContextID> lookupObjCProtocolID(llvm::StringRef Name); 0112 0113 /// Look for information regarding the given Objective-C protocol. 0114 /// 0115 /// \param Name The name of the protocol we're looking for. 0116 /// 0117 /// \returns The information about the protocol, if known. 0118 VersionedInfo<ContextInfo> lookupObjCProtocolInfo(llvm::StringRef Name); 0119 0120 /// Look for information regarding the given Objective-C property in 0121 /// the given context. 0122 /// 0123 /// \param CtxID The ID that references the context we are looking for. 0124 /// \param Name The name of the property we're looking for. 0125 /// \param IsInstance Whether we are looking for an instance property (vs. 0126 /// a class property). 0127 /// 0128 /// \returns Information about the property, if known. 0129 VersionedInfo<ObjCPropertyInfo> 0130 lookupObjCProperty(ContextID CtxID, llvm::StringRef Name, bool IsInstance); 0131 0132 /// Look for information regarding the given Objective-C method in 0133 /// the given context. 0134 /// 0135 /// \param CtxID The ID that references the context we are looking for. 0136 /// \param Selector The selector naming the method we're looking for. 0137 /// \param IsInstanceMethod Whether we are looking for an instance method. 0138 /// 0139 /// \returns Information about the method, if known. 0140 VersionedInfo<ObjCMethodInfo> lookupObjCMethod(ContextID CtxID, 0141 ObjCSelectorRef Selector, 0142 bool IsInstanceMethod); 0143 0144 /// Look for information regarding the given field of a C struct. 0145 /// 0146 /// \param Name The name of the field. 0147 /// 0148 /// \returns information about the field, if known. 0149 VersionedInfo<FieldInfo> lookupField(ContextID CtxID, llvm::StringRef Name); 0150 0151 /// Look for information regarding the given C++ method in the given C++ tag 0152 /// context. 0153 /// 0154 /// \param CtxID The ID that references the parent context, i.e. a C++ tag. 0155 /// \param Name The name of the C++ method we're looking for. 0156 /// 0157 /// \returns Information about the method, if known. 0158 VersionedInfo<CXXMethodInfo> lookupCXXMethod(ContextID CtxID, 0159 llvm::StringRef Name); 0160 0161 /// Look for information regarding the given global variable. 0162 /// 0163 /// \param Name The name of the global variable. 0164 /// 0165 /// \returns information about the global variable, if known. 0166 VersionedInfo<GlobalVariableInfo> 0167 lookupGlobalVariable(llvm::StringRef Name, 0168 std::optional<Context> Ctx = std::nullopt); 0169 0170 /// Look for information regarding the given global function. 0171 /// 0172 /// \param Name The name of the global function. 0173 /// 0174 /// \returns information about the global function, if known. 0175 VersionedInfo<GlobalFunctionInfo> 0176 lookupGlobalFunction(llvm::StringRef Name, 0177 std::optional<Context> Ctx = std::nullopt); 0178 0179 /// Look for information regarding the given enumerator. 0180 /// 0181 /// \param Name The name of the enumerator. 0182 /// 0183 /// \returns information about the enumerator, if known. 0184 VersionedInfo<EnumConstantInfo> lookupEnumConstant(llvm::StringRef Name); 0185 0186 /// Look for the context ID of the given C++ tag. 0187 /// 0188 /// \param Name The name of the tag we're looking for. 0189 /// \param ParentCtx The context in which this tag is declared, e.g. a C++ 0190 /// namespace. 0191 /// 0192 /// \returns The ID, if known. 0193 std::optional<ContextID> 0194 lookupTagID(llvm::StringRef Name, 0195 std::optional<Context> ParentCtx = std::nullopt); 0196 0197 /// Look for information regarding the given tag 0198 /// (struct/union/enum/C++ class). 0199 /// 0200 /// \param Name The name of the tag. 0201 /// 0202 /// \returns information about the tag, if known. 0203 VersionedInfo<TagInfo> lookupTag(llvm::StringRef Name, 0204 std::optional<Context> Ctx = std::nullopt); 0205 0206 /// Look for information regarding the given typedef. 0207 /// 0208 /// \param Name The name of the typedef. 0209 /// 0210 /// \returns information about the typedef, if known. 0211 VersionedInfo<TypedefInfo> 0212 lookupTypedef(llvm::StringRef Name, 0213 std::optional<Context> Ctx = std::nullopt); 0214 0215 /// Look for the context ID of the given C++ namespace. 0216 /// 0217 /// \param Name The name of the class we're looking for. 0218 /// 0219 /// \returns The ID, if known. 0220 std::optional<ContextID> 0221 lookupNamespaceID(llvm::StringRef Name, 0222 std::optional<ContextID> ParentNamespaceID = std::nullopt); 0223 }; 0224 0225 } // end namespace api_notes 0226 } // end namespace clang 0227 0228 #endif // LLVM_CLANG_APINOTES_READER_H
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|