clang 24.0.0git
APINotesWriter.h
Go to the documentation of this file.
1//===-- APINotesWriter.h - API Notes Writer ---------------------*- 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 APINotesWriter class that writes out source
10// API notes data providing additional information about source code as
11// a separate input, such as the non-nil/nilable annotations for
12// method parameters.
13//
14//===----------------------------------------------------------------------===//
15#ifndef LLVM_CLANG_APINOTES_WRITER_H
16#define LLVM_CLANG_APINOTES_WRITER_H
17
19#include "llvm/ADT/ArrayRef.h"
20#include "llvm/ADT/StringRef.h"
21#include "llvm/Support/VersionTuple.h"
22#include "llvm/Support/raw_ostream.h"
23
24#include <memory>
25#include <optional>
26
27namespace clang {
28class FileEntry;
29
30namespace api_notes {
31
32/// A class that writes API notes data to a binary representation that can be
33/// read by the \c APINotesReader.
35 class Implementation;
36 std::unique_ptr<Implementation> Implementation;
37
38public:
39 /// Create a new API notes writer with the given module name and
40 /// (optional) source file.
41 APINotesWriter(llvm::StringRef ModuleName, const FileEntry *SF);
43
44 APINotesWriter(const APINotesWriter &) = delete;
46
47 void writeToStream(llvm::raw_ostream &OS);
48
49 /// Add information about a specific Objective-C class or protocol or a C++
50 /// namespace.
51 ///
52 /// \param Name The name of this class/protocol/namespace.
53 /// \param Kind Whether this is a class, a protocol, or a namespace.
54 /// \param Info Information about this class/protocol/namespace.
55 ///
56 /// \returns the ID of the class, protocol, or namespace, which can be used to
57 /// add properties and methods to the class/protocol/namespace.
58 ContextID addContext(std::optional<ContextID> ParentCtxID,
59 llvm::StringRef Name, ContextKind Kind,
60 const ContextInfo &Info,
61 llvm::VersionTuple SwiftVersion);
62
63 /// Add information about a specific Objective-C property.
64 ///
65 /// \param CtxID The context in which this property resides.
66 /// \param Name The name of this property.
67 /// \param Info Information about this property.
68 void addObjCProperty(ContextID CtxID, llvm::StringRef Name,
69 bool IsInstanceProperty, const ObjCPropertyInfo &Info,
70 llvm::VersionTuple SwiftVersion);
71
72 /// Add information about a specific Objective-C method.
73 ///
74 /// \param CtxID The context in which this method resides.
75 /// \param Selector The selector that names this method.
76 /// \param IsInstanceMethod Whether this method is an instance method
77 /// (vs. a class method).
78 /// \param Info Information about this method.
80 bool IsInstanceMethod, const ObjCMethodInfo &Info,
81 llvm::VersionTuple SwiftVersion);
82
83 /// Add information about a specific C++ method.
84 ///
85 /// \param CtxID The context in which this method resides, i.e. a C++ tag.
86 /// \param Name The name of the method.
87 /// \param Info Information about this method.
88 void addCXXMethod(ContextID CtxID, llvm::StringRef Name,
89 const CXXMethodInfo &Info, llvm::VersionTuple SwiftVersion);
90
91 /// Add information about a C++ method with an exact parameter selector. An
92 /// empty parameter list uses an exact zero-parameter key, and a non-empty
93 /// list uses an exact ordered parameter key.
94 void addCXXMethod(ContextID CtxID, llvm::StringRef Name,
96 const CXXMethodInfo &Info, llvm::VersionTuple SwiftVersion);
97
98 /// Add information about a specific C record field.
99 ///
100 /// \param CtxID The context in which this field resides, i.e. a C/C++ tag.
101 /// \param Name The name of the field.
102 /// \param Info Information about this field.
103 void addField(ContextID CtxID, llvm::StringRef Name, const FieldInfo &Info,
104 llvm::VersionTuple SwiftVersion);
105
106 /// Add information about a global variable.
107 ///
108 /// \param Name The name of this global variable.
109 /// \param Info Information about this global variable.
110 void addGlobalVariable(std::optional<Context> Ctx, llvm::StringRef Name,
111 const GlobalVariableInfo &Info,
112 llvm::VersionTuple SwiftVersion);
113
114 /// Add information about a global function.
115 ///
116 /// \param Name The name of this global function.
117 /// \param Info Information about this global function.
118 void addGlobalFunction(std::optional<Context> Ctx, llvm::StringRef Name,
119 const GlobalFunctionInfo &Info,
120 llvm::VersionTuple SwiftVersion);
121
122 /// Add information about a global function with an exact parameter selector.
123 /// An empty parameter list uses an exact zero-parameter key, and a non-empty
124 /// list uses an exact ordered parameter key.
125 void addGlobalFunction(std::optional<Context> Ctx, llvm::StringRef Name,
127 const GlobalFunctionInfo &Info,
128 llvm::VersionTuple SwiftVersion);
129
130 /// Add information about an enumerator.
131 ///
132 /// \param Name The name of this enumerator.
133 /// \param Info Information about this enumerator.
134 void addEnumConstant(llvm::StringRef Name, const EnumConstantInfo &Info,
135 llvm::VersionTuple SwiftVersion);
136
137 /// Add information about a tag (struct/union/enum/C++ class).
138 ///
139 /// \param Name The name of this tag.
140 /// \param Info Information about this tag.
141 void addTag(std::optional<Context> Ctx, llvm::StringRef Name,
142 const TagInfo &Info, llvm::VersionTuple SwiftVersion);
143
144 /// Add information about a typedef.
145 ///
146 /// \param Name The name of this typedef.
147 /// \param Info Information about this typedef.
148 void addTypedef(std::optional<Context> Ctx, llvm::StringRef Name,
149 const TypedefInfo &Info, llvm::VersionTuple SwiftVersion);
150};
151} // namespace api_notes
152} // namespace clang
153
154#endif // LLVM_CLANG_APINOTES_WRITER_H
Cached information about one file (either on disk or in the virtual file system).
Definition FileEntry.h:273
Smart pointer class that efficiently represents Objective-C method names.
void addObjCMethod(ContextID CtxID, ObjCSelectorRef Selector, bool IsInstanceMethod, const ObjCMethodInfo &Info, llvm::VersionTuple SwiftVersion)
Add information about a specific Objective-C method.
APINotesWriter & operator=(const APINotesWriter &)=delete
void addEnumConstant(llvm::StringRef Name, const EnumConstantInfo &Info, llvm::VersionTuple SwiftVersion)
Add information about an enumerator.
void addCXXMethod(ContextID CtxID, llvm::StringRef Name, llvm::ArrayRef< llvm::StringRef > Parameters, const CXXMethodInfo &Info, llvm::VersionTuple SwiftVersion)
Add information about a C++ method with an exact parameter selector.
ContextID addContext(std::optional< ContextID > ParentCtxID, llvm::StringRef Name, ContextKind Kind, const ContextInfo &Info, llvm::VersionTuple SwiftVersion)
Add information about a specific Objective-C class or protocol or a C++ namespace.
void addGlobalFunction(std::optional< Context > Ctx, llvm::StringRef Name, llvm::ArrayRef< llvm::StringRef > Parameters, const GlobalFunctionInfo &Info, llvm::VersionTuple SwiftVersion)
Add information about a global function with an exact parameter selector.
void addGlobalFunction(std::optional< Context > Ctx, llvm::StringRef Name, const GlobalFunctionInfo &Info, llvm::VersionTuple SwiftVersion)
Add information about a global function.
void addObjCProperty(ContextID CtxID, llvm::StringRef Name, bool IsInstanceProperty, const ObjCPropertyInfo &Info, llvm::VersionTuple SwiftVersion)
Add information about a specific Objective-C property.
void addField(ContextID CtxID, llvm::StringRef Name, const FieldInfo &Info, llvm::VersionTuple SwiftVersion)
Add information about a specific C record field.
void addGlobalVariable(std::optional< Context > Ctx, llvm::StringRef Name, const GlobalVariableInfo &Info, llvm::VersionTuple SwiftVersion)
Add information about a global variable.
void addTypedef(std::optional< Context > Ctx, llvm::StringRef Name, const TypedefInfo &Info, llvm::VersionTuple SwiftVersion)
Add information about a typedef.
void writeToStream(llvm::raw_ostream &OS)
APINotesWriter(const APINotesWriter &)=delete
void addCXXMethod(ContextID CtxID, llvm::StringRef Name, const CXXMethodInfo &Info, llvm::VersionTuple SwiftVersion)
Add information about a specific C++ method.
void addTag(std::optional< Context > Ctx, llvm::StringRef Name, const TagInfo &Info, llvm::VersionTuple SwiftVersion)
Add information about a tag (struct/union/enum/C++ class).
APINotesWriter(llvm::StringRef ModuleName, const FileEntry *SF)
Create a new API notes writer with the given module name and (optional) source file.
Describes API notes data for a C++ method.
Definition Types.h:803
Opaque context ID used to refer to an Objective-C class or protocol or a C++ namespace.
Definition Types.h:970
Describes API notes data for an Objective-C class or protocol or a C++ namespace.
Definition Types.h:235
Describes API notes data for an enumerator.
Definition Types.h:821
Describes API notes data for a C/C++ record field.
Definition Types.h:797
Describes API notes data for a global function.
Definition Types.h:791
Describes API notes data for a global variable.
Definition Types.h:785
Describes API notes data for an Objective-C method.
Definition Types.h:744
Describes API notes data for an Objective-C property.
Definition Types.h:457
Describes API notes data for a tag.
Definition Types.h:827
Describes API notes data for a typedef.
Definition Types.h:938
The JSON file list parser is used to communicate input to InstallAPI.
A temporary reference to an Objective-C selector, suitable for referencing selector data on the stack...
Definition Types.h:997