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