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 addObjCContext(std::optional<ContextID> ParentCtxID,
57 llvm::StringRef Name, ContextKind Kind,
58 const ObjCContextInfo &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 global variable.
82 ///
83 /// \param Name The name of this global variable.
84 /// \param Info Information about this global variable.
85 void addGlobalVariable(std::optional<Context> Ctx, llvm::StringRef Name,
86 const GlobalVariableInfo &Info,
87 llvm::VersionTuple SwiftVersion);
88
89 /// Add information about a global function.
90 ///
91 /// \param Name The name of this global function.
92 /// \param Info Information about this global function.
93 void addGlobalFunction(std::optional<Context> Ctx, llvm::StringRef Name,
94 const GlobalFunctionInfo &Info,
95 llvm::VersionTuple SwiftVersion);
96
97 /// Add information about an enumerator.
98 ///
99 /// \param Name The name of this enumerator.
100 /// \param Info Information about this enumerator.
101 void addEnumConstant(llvm::StringRef Name, const EnumConstantInfo &Info,
102 llvm::VersionTuple SwiftVersion);
103
104 /// Add information about a tag (struct/union/enum/C++ class).
105 ///
106 /// \param Name The name of this tag.
107 /// \param Info Information about this tag.
108 void addTag(std::optional<Context> Ctx, llvm::StringRef Name,
109 const TagInfo &Info, llvm::VersionTuple SwiftVersion);
110
111 /// Add information about a typedef.
112 ///
113 /// \param Name The name of this typedef.
114 /// \param Info Information about this typedef.
115 void addTypedef(std::optional<Context> Ctx, llvm::StringRef Name,
116 const TypedefInfo &Info, llvm::VersionTuple SwiftVersion);
117};
118} // namespace api_notes
119} // namespace clang
120
121#endif // LLVM_CLANG_APINOTES_WRITER_H
122

source code of clang/include/clang/APINotes/APINotesWriter.h