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
18#include "clang/APINotes/Types.h"
19#include "llvm/ADT/StringRef.h"
20#include "llvm/Support/VersionTuple.h"
21#include "llvm/Support/raw_ostream.h"
22
23#include <memory>
24
25namespace clang {
26class FileEntry;
27
28namespace api_notes {
29
30/// A class that writes API notes data to a binary representation that can be
31/// read by the \c APINotesReader.
32class APINotesWriter {
33 class Implementation;
34 std::unique_ptr<Implementation> Implementation;
35
36public:
37 /// Create a new API notes writer with the given module name and
38 /// (optional) source file.
39 APINotesWriter(llvm::StringRef ModuleName, const FileEntry *SF);
40 ~APINotesWriter();
41
42 APINotesWriter(const APINotesWriter &) = delete;
43 APINotesWriter &operator=(const APINotesWriter &) = delete;
44
45 void writeToStream(llvm::raw_ostream &OS);
46
47 /// Add information about a specific Objective-C class or protocol or a C++
48 /// namespace.
49 ///
50 /// \param Name The name of this class/protocol/namespace.
51 /// \param Kind Whether this is a class, a protocol, or a namespace.
52 /// \param Info Information about this class/protocol/namespace.
53 ///
54 /// \returns the ID of the class, protocol, or namespace, which can be used to
55 /// add properties and methods to the class/protocol/namespace.
56 ContextID addContext(std::optional<ContextID> ParentCtxID,
57 llvm::StringRef Name, ContextKind Kind,
58 const ContextInfo &Info,
59 llvm::VersionTuple SwiftVersion);
60
61 /// Add information about a specific Objective-C property.
62 ///
63 /// \param CtxID The context in which this property resides.
64 /// \param Name The name of this property.
65 /// \param Info Information about this property.
66 void addObjCProperty(ContextID CtxID, llvm::StringRef Name,
67 bool IsInstanceProperty, const ObjCPropertyInfo &Info,
68 llvm::VersionTuple SwiftVersion);
69
70 /// Add information about a specific Objective-C method.
71 ///
72 /// \param CtxID The context in which this method resides.
73 /// \param Selector The selector that names this method.
74 /// \param IsInstanceMethod Whether this method is an instance method
75 /// (vs. a class method).
76 /// \param Info Information about this method.
77 void addObjCMethod(ContextID CtxID, ObjCSelectorRef Selector,
78 bool IsInstanceMethod, const ObjCMethodInfo &Info,
79 llvm::VersionTuple SwiftVersion);
80
81 /// Add information about a specific C++ method.
82 ///
83 /// \param CtxID The context in which this method resides, i.e. a C++ tag.
84 /// \param Name The name of the method.
85 /// \param Info Information about this method.
86 void addCXXMethod(ContextID CtxID, llvm::StringRef Name,
87 const CXXMethodInfo &Info, llvm::VersionTuple SwiftVersion);
88
89 /// Add information about a global variable.
90 ///
91 /// \param Name The name of this global variable.
92 /// \param Info Information about this global variable.
93 void addGlobalVariable(std::optional<Context> Ctx, llvm::StringRef Name,
94 const GlobalVariableInfo &Info,
95 llvm::VersionTuple SwiftVersion);
96
97 /// Add information about a global function.
98 ///
99 /// \param Name The name of this global function.
100 /// \param Info Information about this global function.
101 void addGlobalFunction(std::optional<Context> Ctx, llvm::StringRef Name,
102 const GlobalFunctionInfo &Info,
103 llvm::VersionTuple SwiftVersion);
104
105 /// Add information about an enumerator.
106 ///
107 /// \param Name The name of this enumerator.
108 /// \param Info Information about this enumerator.
109 void addEnumConstant(llvm::StringRef Name, const EnumConstantInfo &Info,
110 llvm::VersionTuple SwiftVersion);
111
112 /// Add information about a tag (struct/union/enum/C++ class).
113 ///
114 /// \param Name The name of this tag.
115 /// \param Info Information about this tag.
116 void addTag(std::optional<Context> Ctx, llvm::StringRef Name,
117 const TagInfo &Info, llvm::VersionTuple SwiftVersion);
118
119 /// Add information about a typedef.
120 ///
121 /// \param Name The name of this typedef.
122 /// \param Info Information about this typedef.
123 void addTypedef(std::optional<Context> Ctx, llvm::StringRef Name,
124 const TypedefInfo &Info, llvm::VersionTuple SwiftVersion);
125};
126} // namespace api_notes
127} // namespace clang
128
129#endif // LLVM_CLANG_APINOTES_WRITER_H
130