| 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 | |
| 25 | namespace clang { |
| 26 | class FileEntry; |
| 27 | |
| 28 | namespace api_notes { |
| 29 | |
| 30 | /// A class that writes API notes data to a binary representation that can be |
| 31 | /// read by the \c APINotesReader. |
| 32 | class APINotesWriter { |
| 33 | class Implementation; |
| 34 | std::unique_ptr<Implementation> Implementation; |
| 35 | |
| 36 | public: |
| 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 specific C record field. |
| 90 | /// |
| 91 | /// \param CtxID The context in which this field resides, i.e. a C/C++ tag. |
| 92 | /// \param Name The name of the field. |
| 93 | /// \param Info Information about this field. |
| 94 | void addField(ContextID CtxID, llvm::StringRef Name, const FieldInfo &Info, |
| 95 | llvm::VersionTuple SwiftVersion); |
| 96 | |
| 97 | /// Add information about a global variable. |
| 98 | /// |
| 99 | /// \param Name The name of this global variable. |
| 100 | /// \param Info Information about this global variable. |
| 101 | void addGlobalVariable(std::optional<Context> Ctx, llvm::StringRef Name, |
| 102 | const GlobalVariableInfo &Info, |
| 103 | llvm::VersionTuple SwiftVersion); |
| 104 | |
| 105 | /// Add information about a global function. |
| 106 | /// |
| 107 | /// \param Name The name of this global function. |
| 108 | /// \param Info Information about this global function. |
| 109 | void addGlobalFunction(std::optional<Context> Ctx, llvm::StringRef Name, |
| 110 | const GlobalFunctionInfo &Info, |
| 111 | llvm::VersionTuple SwiftVersion); |
| 112 | |
| 113 | /// Add information about an enumerator. |
| 114 | /// |
| 115 | /// \param Name The name of this enumerator. |
| 116 | /// \param Info Information about this enumerator. |
| 117 | void addEnumConstant(llvm::StringRef Name, const EnumConstantInfo &Info, |
| 118 | llvm::VersionTuple SwiftVersion); |
| 119 | |
| 120 | /// Add information about a tag (struct/union/enum/C++ class). |
| 121 | /// |
| 122 | /// \param Name The name of this tag. |
| 123 | /// \param Info Information about this tag. |
| 124 | void addTag(std::optional<Context> Ctx, llvm::StringRef Name, |
| 125 | const TagInfo &Info, llvm::VersionTuple SwiftVersion); |
| 126 | |
| 127 | /// Add information about a typedef. |
| 128 | /// |
| 129 | /// \param Name The name of this typedef. |
| 130 | /// \param Info Information about this typedef. |
| 131 | void addTypedef(std::optional<Context> Ctx, llvm::StringRef Name, |
| 132 | const TypedefInfo &Info, llvm::VersionTuple SwiftVersion); |
| 133 | }; |
| 134 | } // namespace api_notes |
| 135 | } // namespace clang |
| 136 | |
| 137 | #endif // LLVM_CLANG_APINOTES_WRITER_H |
| 138 | |