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