1//===-- APINotesTypes.cpp - API Notes Data Types ----------------*- 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#include "clang/APINotes/Types.h"
10#include "llvm/Support/raw_ostream.h"
11
12namespace clang {
13namespace api_notes {
14LLVM_DUMP_METHOD void CommonEntityInfo::dump(llvm::raw_ostream &OS) const {
15 if (Unavailable)
16 OS << "[Unavailable] (" << UnavailableMsg << ")" << ' ';
17 if (UnavailableInSwift)
18 OS << "[UnavailableInSwift] ";
19 if (SwiftPrivateSpecified)
20 OS << (SwiftPrivate ? "[SwiftPrivate] " : "");
21 if (SwiftSafetyAudited) {
22 switch (*getSwiftSafety()) {
23 case SwiftSafetyKind::Safe:
24 OS << "[Safe] ";
25 break;
26 case SwiftSafetyKind::Unsafe:
27 OS << "[Unsafe] ";
28 break;
29 case SwiftSafetyKind::Unspecified:
30 OS << "[Unspecified] ";
31 break;
32 case SwiftSafetyKind::None:
33 break;
34 }
35 }
36 if (!SwiftName.empty())
37 OS << "Swift Name: " << SwiftName << ' ';
38 OS << '\n';
39}
40
41LLVM_DUMP_METHOD void CommonTypeInfo::dump(llvm::raw_ostream &OS) const {
42 static_cast<const CommonEntityInfo &>(*this).dump(OS);
43 if (SwiftBridge)
44 OS << "Swift Briged Type: " << *SwiftBridge << ' ';
45 if (NSErrorDomain)
46 OS << "NSError Domain: " << *NSErrorDomain << ' ';
47 OS << '\n';
48}
49
50LLVM_DUMP_METHOD void ContextInfo::dump(llvm::raw_ostream &OS) {
51 static_cast<CommonTypeInfo &>(*this).dump(OS);
52 if (HasDefaultNullability)
53 OS << "DefaultNullability: " << DefaultNullability << ' ';
54 if (HasDesignatedInits)
55 OS << "[HasDesignatedInits] ";
56 if (SwiftImportAsNonGenericSpecified)
57 OS << (SwiftImportAsNonGeneric ? "[SwiftImportAsNonGeneric] " : "");
58 if (SwiftObjCMembersSpecified)
59 OS << (SwiftObjCMembers ? "[SwiftObjCMembers] " : "");
60 OS << '\n';
61}
62
63LLVM_DUMP_METHOD void VariableInfo::dump(llvm::raw_ostream &OS) const {
64 static_cast<const CommonEntityInfo &>(*this).dump(OS);
65 if (NullabilityAudited)
66 OS << "Audited Nullability: " << Nullable << ' ';
67 if (!Type.empty())
68 OS << "C Type: " << Type << ' ';
69 OS << '\n';
70}
71
72LLVM_DUMP_METHOD void ObjCPropertyInfo::dump(llvm::raw_ostream &OS) const {
73 static_cast<const VariableInfo &>(*this).dump(OS);
74 if (SwiftImportAsAccessorsSpecified)
75 OS << (SwiftImportAsAccessors ? "[SwiftImportAsAccessors] " : "");
76 OS << '\n';
77}
78
79LLVM_DUMP_METHOD void BoundsSafetyInfo::dump(llvm::raw_ostream &OS) const {
80 if (KindAudited) {
81 switch (static_cast<BoundsSafetyKind>(Kind)) {
82 case BoundsSafetyKind::CountedBy:
83 OS << "[counted_by] ";
84 break;
85 case BoundsSafetyKind::CountedByOrNull:
86 OS << "[counted_by_or_null] ";
87 break;
88 case BoundsSafetyKind::SizedBy:
89 OS << "[sized_by] ";
90 break;
91 case BoundsSafetyKind::SizedByOrNull:
92 OS << "[sized_by_or_null] ";
93 break;
94 case BoundsSafetyKind::EndedBy:
95 OS << "[ended_by] ";
96 break;
97 }
98 }
99 if (LevelAudited)
100 OS << "Level: " << Level << " ";
101 OS << "ExternalBounds: "
102 << (ExternalBounds.empty() ? "<missing>" : ExternalBounds) << '\n';
103}
104
105LLVM_DUMP_METHOD void ParamInfo::dump(llvm::raw_ostream &OS) const {
106 static_cast<const VariableInfo &>(*this).dump(OS);
107 if (NoEscapeSpecified)
108 OS << (NoEscape ? "[NoEscape] " : "");
109 if (LifetimeboundSpecified)
110 OS << (Lifetimebound ? "[Lifetimebound] " : "");
111 OS << "RawRetainCountConvention: " << RawRetainCountConvention << ' ';
112 OS << '\n';
113 if (BoundsSafety)
114 BoundsSafety->dump(OS);
115}
116
117LLVM_DUMP_METHOD void FunctionInfo::dump(llvm::raw_ostream &OS) const {
118 static_cast<const CommonEntityInfo &>(*this).dump(OS);
119 OS << (NullabilityAudited ? "[NullabilityAudited] " : "")
120 << "RawRetainCountConvention: " << RawRetainCountConvention << ' ';
121 if (!ResultType.empty())
122 OS << "Result Type: " << ResultType << ' ';
123 if (!SwiftReturnOwnership.empty())
124 OS << "SwiftReturnOwnership: " << SwiftReturnOwnership << ' ';
125 if (!Params.empty())
126 OS << '\n';
127 for (auto &PI : Params)
128 PI.dump(OS);
129}
130
131LLVM_DUMP_METHOD void ObjCMethodInfo::dump(llvm::raw_ostream &OS) {
132 static_cast<FunctionInfo &>(*this).dump(OS);
133 if (Self)
134 Self->dump(OS);
135 OS << (DesignatedInit ? "[DesignatedInit] " : "")
136 << (RequiredInit ? "[RequiredInit] " : "") << '\n';
137}
138
139LLVM_DUMP_METHOD void CXXMethodInfo::dump(llvm::raw_ostream &OS) {
140 static_cast<FunctionInfo &>(*this).dump(OS);
141 if (This)
142 This->dump(OS);
143}
144
145LLVM_DUMP_METHOD void TagInfo::dump(llvm::raw_ostream &OS) {
146 static_cast<CommonTypeInfo &>(*this).dump(OS);
147 if (HasFlagEnum)
148 OS << (IsFlagEnum ? "[FlagEnum] " : "");
149 if (EnumExtensibility)
150 OS << "Enum Extensibility: " << static_cast<long>(*EnumExtensibility)
151 << ' ';
152 if (SwiftCopyableSpecified)
153 OS << (SwiftCopyable ? "[SwiftCopyable] " : "[~SwiftCopyable]");
154 if (SwiftEscapableSpecified)
155 OS << (SwiftEscapable ? "[SwiftEscapable] " : "[~SwiftEscapable]");
156 OS << '\n';
157}
158
159LLVM_DUMP_METHOD void TypedefInfo::dump(llvm::raw_ostream &OS) const {
160 static_cast<const CommonTypeInfo &>(*this).dump(OS);
161 if (SwiftWrapper)
162 OS << "Swift Type: " << static_cast<long>(*SwiftWrapper) << ' ';
163 OS << '\n';
164}
165} // namespace api_notes
166} // namespace clang
167