clang 20.0.0git
APINotesYAMLCompiler.cpp
Go to the documentation of this file.
1//===-- APINotesYAMLCompiler.cpp - API Notes YAML Format Reader -*- 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// The types defined locally are designed to represent the YAML state, which
10// adds an additional bit of state: e.g. a tri-state boolean attribute (yes, no,
11// not applied) becomes a tri-state boolean + present. As a result, while these
12// enumerations appear to be redefining constants from the attributes table
13// data, they are distinct.
14//
15
19#include "clang/Basic/LLVM.h"
21#include "llvm/ADT/StringSet.h"
22#include "llvm/Support/SourceMgr.h"
23#include "llvm/Support/VersionTuple.h"
24#include "llvm/Support/YAMLTraits.h"
25#include <optional>
26#include <vector>
27
28using namespace clang;
29using namespace api_notes;
30
31namespace {
32enum class APIAvailability {
33 Available = 0,
34 None,
35 NonSwift,
36};
37} // namespace
38
39namespace llvm {
40namespace yaml {
41template <> struct ScalarEnumerationTraits<APIAvailability> {
42 static void enumeration(IO &IO, APIAvailability &AA) {
43 IO.enumCase(AA, "none", APIAvailability::None);
44 IO.enumCase(AA, "nonswift", APIAvailability::NonSwift);
45 IO.enumCase(AA, "available", APIAvailability::Available);
46 }
47};
48} // namespace yaml
49} // namespace llvm
50
51namespace {
52enum class MethodKind {
53 Class,
54 Instance,
55};
56} // namespace
57
58namespace llvm {
59namespace yaml {
60template <> struct ScalarEnumerationTraits<MethodKind> {
61 static void enumeration(IO &IO, MethodKind &MK) {
62 IO.enumCase(MK, "Class", MethodKind::Class);
63 IO.enumCase(MK, "Instance", MethodKind::Instance);
64 }
65};
66} // namespace yaml
67} // namespace llvm
68
69namespace {
70struct Param {
71 unsigned Position;
72 std::optional<bool> NoEscape = false;
73 std::optional<NullabilityKind> Nullability;
74 std::optional<RetainCountConventionKind> RetainCountConvention;
75 StringRef Type;
76};
77
78typedef std::vector<Param> ParamsSeq;
79} // namespace
80
81LLVM_YAML_IS_SEQUENCE_VECTOR(Param)
82LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(NullabilityKind)
83
84namespace llvm {
85namespace yaml {
86template <> struct ScalarEnumerationTraits<NullabilityKind> {
87 static void enumeration(IO &IO, NullabilityKind &NK) {
88 IO.enumCase(NK, "Nonnull", NullabilityKind::NonNull);
89 IO.enumCase(NK, "Optional", NullabilityKind::Nullable);
90 IO.enumCase(NK, "Unspecified", NullabilityKind::Unspecified);
91 IO.enumCase(NK, "NullableResult", NullabilityKind::NullableResult);
92 // TODO: Mapping this to it's own value would allow for better cross
93 // checking. Also the default should be Unknown.
94 IO.enumCase(NK, "Scalar", NullabilityKind::Unspecified);
95
96 // Aliases for compatibility with existing APINotes.
97 IO.enumCase(NK, "N", NullabilityKind::NonNull);
98 IO.enumCase(NK, "O", NullabilityKind::Nullable);
99 IO.enumCase(NK, "U", NullabilityKind::Unspecified);
100 IO.enumCase(NK, "S", NullabilityKind::Unspecified);
101 }
102};
103
104template <> struct ScalarEnumerationTraits<RetainCountConventionKind> {
105 static void enumeration(IO &IO, RetainCountConventionKind &RCCK) {
106 IO.enumCase(RCCK, "none", RetainCountConventionKind::None);
107 IO.enumCase(RCCK, "CFReturnsRetained",
108 RetainCountConventionKind::CFReturnsRetained);
109 IO.enumCase(RCCK, "CFReturnsNotRetained",
110 RetainCountConventionKind::CFReturnsNotRetained);
111 IO.enumCase(RCCK, "NSReturnsRetained",
112 RetainCountConventionKind::NSReturnsRetained);
113 IO.enumCase(RCCK, "NSReturnsNotRetained",
114 RetainCountConventionKind::NSReturnsNotRetained);
115 }
116};
117
118template <> struct MappingTraits<Param> {
119 static void mapping(IO &IO, Param &P) {
120 IO.mapRequired("Position", P.Position);
121 IO.mapOptional("Nullability", P.Nullability, std::nullopt);
122 IO.mapOptional("RetainCountConvention", P.RetainCountConvention);
123 IO.mapOptional("NoEscape", P.NoEscape);
124 IO.mapOptional("Type", P.Type, StringRef(""));
125 }
126};
127} // namespace yaml
128} // namespace llvm
129
130namespace {
131typedef std::vector<NullabilityKind> NullabilitySeq;
132
133struct AvailabilityItem {
134 APIAvailability Mode = APIAvailability::Available;
135 StringRef Msg;
136};
137
138/// Old attribute deprecated in favor of SwiftName.
139enum class FactoryAsInitKind {
140 /// Infer based on name and type (the default).
141 Infer,
142 /// Treat as a class method.
143 AsClassMethod,
144 /// Treat as an initializer.
145 AsInitializer,
146};
147
148struct Method {
149 StringRef Selector;
150 MethodKind Kind;
151 ParamsSeq Params;
152 NullabilitySeq Nullability;
153 std::optional<NullabilityKind> NullabilityOfRet;
154 std::optional<RetainCountConventionKind> RetainCountConvention;
155 AvailabilityItem Availability;
156 std::optional<bool> SwiftPrivate;
157 StringRef SwiftName;
158 FactoryAsInitKind FactoryAsInit = FactoryAsInitKind::Infer;
159 bool DesignatedInit = false;
160 bool Required = false;
161 StringRef ResultType;
162};
163
164typedef std::vector<Method> MethodsSeq;
165} // namespace
166
167LLVM_YAML_IS_SEQUENCE_VECTOR(Method)
168
169namespace llvm {
170namespace yaml {
171template <> struct ScalarEnumerationTraits<FactoryAsInitKind> {
172 static void enumeration(IO &IO, FactoryAsInitKind &FIK) {
173 IO.enumCase(FIK, "A", FactoryAsInitKind::Infer);
174 IO.enumCase(FIK, "C", FactoryAsInitKind::AsClassMethod);
175 IO.enumCase(FIK, "I", FactoryAsInitKind::AsInitializer);
176 }
177};
178
179template <> struct MappingTraits<Method> {
180 static void mapping(IO &IO, Method &M) {
181 IO.mapRequired("Selector", M.Selector);
182 IO.mapRequired("MethodKind", M.Kind);
183 IO.mapOptional("Parameters", M.Params);
184 IO.mapOptional("Nullability", M.Nullability);
185 IO.mapOptional("NullabilityOfRet", M.NullabilityOfRet, std::nullopt);
186 IO.mapOptional("RetainCountConvention", M.RetainCountConvention);
187 IO.mapOptional("Availability", M.Availability.Mode,
188 APIAvailability::Available);
189 IO.mapOptional("AvailabilityMsg", M.Availability.Msg, StringRef(""));
190 IO.mapOptional("SwiftPrivate", M.SwiftPrivate);
191 IO.mapOptional("SwiftName", M.SwiftName, StringRef(""));
192 IO.mapOptional("FactoryAsInit", M.FactoryAsInit, FactoryAsInitKind::Infer);
193 IO.mapOptional("DesignatedInit", M.DesignatedInit, false);
194 IO.mapOptional("Required", M.Required, false);
195 IO.mapOptional("ResultType", M.ResultType, StringRef(""));
196 }
197};
198} // namespace yaml
199} // namespace llvm
200
201namespace {
202struct Property {
203 StringRef Name;
204 std::optional<MethodKind> Kind;
205 std::optional<NullabilityKind> Nullability;
206 AvailabilityItem Availability;
207 std::optional<bool> SwiftPrivate;
208 StringRef SwiftName;
209 std::optional<bool> SwiftImportAsAccessors;
210 StringRef Type;
211};
212
213typedef std::vector<Property> PropertiesSeq;
214} // namespace
215
216LLVM_YAML_IS_SEQUENCE_VECTOR(Property)
217
218namespace llvm {
219namespace yaml {
220template <> struct MappingTraits<Property> {
221 static void mapping(IO &IO, Property &P) {
222 IO.mapRequired("Name", P.Name);
223 IO.mapOptional("PropertyKind", P.Kind);
224 IO.mapOptional("Nullability", P.Nullability, std::nullopt);
225 IO.mapOptional("Availability", P.Availability.Mode,
226 APIAvailability::Available);
227 IO.mapOptional("AvailabilityMsg", P.Availability.Msg, StringRef(""));
228 IO.mapOptional("SwiftPrivate", P.SwiftPrivate);
229 IO.mapOptional("SwiftName", P.SwiftName, StringRef(""));
230 IO.mapOptional("SwiftImportAsAccessors", P.SwiftImportAsAccessors);
231 IO.mapOptional("Type", P.Type, StringRef(""));
232 }
233};
234} // namespace yaml
235} // namespace llvm
236
237namespace {
238struct Class {
239 StringRef Name;
240 bool AuditedForNullability = false;
241 AvailabilityItem Availability;
242 std::optional<bool> SwiftPrivate;
243 StringRef SwiftName;
244 std::optional<StringRef> SwiftBridge;
245 std::optional<StringRef> NSErrorDomain;
246 std::optional<bool> SwiftImportAsNonGeneric;
247 std::optional<bool> SwiftObjCMembers;
248 MethodsSeq Methods;
249 PropertiesSeq Properties;
250};
251
252typedef std::vector<Class> ClassesSeq;
253} // namespace
254
255LLVM_YAML_IS_SEQUENCE_VECTOR(Class)
256
257namespace llvm {
258namespace yaml {
259template <> struct MappingTraits<Class> {
260 static void mapping(IO &IO, Class &C) {
261 IO.mapRequired("Name", C.Name);
262 IO.mapOptional("AuditedForNullability", C.AuditedForNullability, false);
263 IO.mapOptional("Availability", C.Availability.Mode,
264 APIAvailability::Available);
265 IO.mapOptional("AvailabilityMsg", C.Availability.Msg, StringRef(""));
266 IO.mapOptional("SwiftPrivate", C.SwiftPrivate);
267 IO.mapOptional("SwiftName", C.SwiftName, StringRef(""));
268 IO.mapOptional("SwiftBridge", C.SwiftBridge);
269 IO.mapOptional("NSErrorDomain", C.NSErrorDomain);
270 IO.mapOptional("SwiftImportAsNonGeneric", C.SwiftImportAsNonGeneric);
271 IO.mapOptional("SwiftObjCMembers", C.SwiftObjCMembers);
272 IO.mapOptional("Methods", C.Methods);
273 IO.mapOptional("Properties", C.Properties);
274 }
275};
276} // namespace yaml
277} // namespace llvm
278
279namespace {
280struct Function {
281 StringRef Name;
282 ParamsSeq Params;
283 NullabilitySeq Nullability;
284 std::optional<NullabilityKind> NullabilityOfRet;
285 std::optional<api_notes::RetainCountConventionKind> RetainCountConvention;
286 AvailabilityItem Availability;
287 std::optional<bool> SwiftPrivate;
288 StringRef SwiftName;
289 StringRef Type;
290 StringRef ResultType;
291};
292
293typedef std::vector<Function> FunctionsSeq;
294} // namespace
295
296LLVM_YAML_IS_SEQUENCE_VECTOR(Function)
297
298namespace llvm {
299namespace yaml {
300template <> struct MappingTraits<Function> {
301 static void mapping(IO &IO, Function &F) {
302 IO.mapRequired("Name", F.Name);
303 IO.mapOptional("Parameters", F.Params);
304 IO.mapOptional("Nullability", F.Nullability);
305 IO.mapOptional("NullabilityOfRet", F.NullabilityOfRet, std::nullopt);
306 IO.mapOptional("RetainCountConvention", F.RetainCountConvention);
307 IO.mapOptional("Availability", F.Availability.Mode,
308 APIAvailability::Available);
309 IO.mapOptional("AvailabilityMsg", F.Availability.Msg, StringRef(""));
310 IO.mapOptional("SwiftPrivate", F.SwiftPrivate);
311 IO.mapOptional("SwiftName", F.SwiftName, StringRef(""));
312 IO.mapOptional("ResultType", F.ResultType, StringRef(""));
313 }
314};
315} // namespace yaml
316} // namespace llvm
317
318namespace {
319struct GlobalVariable {
320 StringRef Name;
321 std::optional<NullabilityKind> Nullability;
322 AvailabilityItem Availability;
323 std::optional<bool> SwiftPrivate;
324 StringRef SwiftName;
325 StringRef Type;
326};
327
328typedef std::vector<GlobalVariable> GlobalVariablesSeq;
329} // namespace
330
331LLVM_YAML_IS_SEQUENCE_VECTOR(GlobalVariable)
332
333namespace llvm {
334namespace yaml {
335template <> struct MappingTraits<GlobalVariable> {
336 static void mapping(IO &IO, GlobalVariable &GV) {
337 IO.mapRequired("Name", GV.Name);
338 IO.mapOptional("Nullability", GV.Nullability, std::nullopt);
339 IO.mapOptional("Availability", GV.Availability.Mode,
340 APIAvailability::Available);
341 IO.mapOptional("AvailabilityMsg", GV.Availability.Msg, StringRef(""));
342 IO.mapOptional("SwiftPrivate", GV.SwiftPrivate);
343 IO.mapOptional("SwiftName", GV.SwiftName, StringRef(""));
344 IO.mapOptional("Type", GV.Type, StringRef(""));
345 }
346};
347} // namespace yaml
348} // namespace llvm
349
350namespace {
351struct EnumConstant {
352 StringRef Name;
353 AvailabilityItem Availability;
354 std::optional<bool> SwiftPrivate;
355 StringRef SwiftName;
356};
357
358typedef std::vector<EnumConstant> EnumConstantsSeq;
359} // namespace
360
361LLVM_YAML_IS_SEQUENCE_VECTOR(EnumConstant)
362
363namespace llvm {
364namespace yaml {
365template <> struct MappingTraits<EnumConstant> {
366 static void mapping(IO &IO, EnumConstant &EC) {
367 IO.mapRequired("Name", EC.Name);
368 IO.mapOptional("Availability", EC.Availability.Mode,
369 APIAvailability::Available);
370 IO.mapOptional("AvailabilityMsg", EC.Availability.Msg, StringRef(""));
371 IO.mapOptional("SwiftPrivate", EC.SwiftPrivate);
372 IO.mapOptional("SwiftName", EC.SwiftName, StringRef(""));
373 }
374};
375} // namespace yaml
376} // namespace llvm
377
378namespace {
379/// Syntactic sugar for EnumExtensibility and FlagEnum
380enum class EnumConvenienceAliasKind {
381 /// EnumExtensibility: none, FlagEnum: false
382 None,
383 /// EnumExtensibility: open, FlagEnum: false
384 CFEnum,
385 /// EnumExtensibility: open, FlagEnum: true
386 CFOptions,
387 /// EnumExtensibility: closed, FlagEnum: false
388 CFClosedEnum
389};
390} // namespace
391
392namespace llvm {
393namespace yaml {
394template <> struct ScalarEnumerationTraits<EnumConvenienceAliasKind> {
395 static void enumeration(IO &IO, EnumConvenienceAliasKind &ECAK) {
396 IO.enumCase(ECAK, "none", EnumConvenienceAliasKind::None);
397 IO.enumCase(ECAK, "CFEnum", EnumConvenienceAliasKind::CFEnum);
398 IO.enumCase(ECAK, "NSEnum", EnumConvenienceAliasKind::CFEnum);
399 IO.enumCase(ECAK, "CFOptions", EnumConvenienceAliasKind::CFOptions);
400 IO.enumCase(ECAK, "NSOptions", EnumConvenienceAliasKind::CFOptions);
401 IO.enumCase(ECAK, "CFClosedEnum", EnumConvenienceAliasKind::CFClosedEnum);
402 IO.enumCase(ECAK, "NSClosedEnum", EnumConvenienceAliasKind::CFClosedEnum);
403 }
404};
405} // namespace yaml
406} // namespace llvm
407
408namespace {
409struct Field {
410 StringRef Name;
411 std::optional<NullabilityKind> Nullability;
412 AvailabilityItem Availability;
413 std::optional<bool> SwiftPrivate;
414 StringRef SwiftName;
415 StringRef Type;
416};
417
418typedef std::vector<Field> FieldsSeq;
419} // namespace
420
421LLVM_YAML_IS_SEQUENCE_VECTOR(Field)
422
423namespace llvm {
424namespace yaml {
425template <> struct MappingTraits<Field> {
426 static void mapping(IO &IO, Field &F) {
427 IO.mapRequired("Name", F.Name);
428 IO.mapOptional("Nullability", F.Nullability, std::nullopt);
429 IO.mapOptional("Availability", F.Availability.Mode,
430 APIAvailability::Available);
431 IO.mapOptional("AvailabilityMsg", F.Availability.Msg, StringRef(""));
432 IO.mapOptional("SwiftPrivate", F.SwiftPrivate);
433 IO.mapOptional("SwiftName", F.SwiftName, StringRef(""));
434 IO.mapOptional("Type", F.Type, StringRef(""));
435 }
436};
437} // namespace yaml
438} // namespace llvm
439
440namespace {
441struct Tag;
442typedef std::vector<Tag> TagsSeq;
443
444struct Tag {
445 StringRef Name;
446 AvailabilityItem Availability;
447 StringRef SwiftName;
448 std::optional<bool> SwiftPrivate;
449 std::optional<StringRef> SwiftBridge;
450 std::optional<StringRef> NSErrorDomain;
451 std::optional<std::string> SwiftImportAs;
452 std::optional<std::string> SwiftRetainOp;
453 std::optional<std::string> SwiftReleaseOp;
454 std::optional<std::string> SwiftConformance;
455 std::optional<EnumExtensibilityKind> EnumExtensibility;
456 std::optional<bool> FlagEnum;
457 std::optional<EnumConvenienceAliasKind> EnumConvenienceKind;
458 std::optional<bool> SwiftCopyable;
459 FunctionsSeq Methods;
460 FieldsSeq Fields;
461
462 /// Tags that are declared within the current tag. Only the tags that have
463 /// corresponding API Notes will be listed.
464 TagsSeq Tags;
465};
466} // namespace
467
468LLVM_YAML_IS_SEQUENCE_VECTOR(Tag)
469
470namespace llvm {
471namespace yaml {
472template <> struct ScalarEnumerationTraits<EnumExtensibilityKind> {
473 static void enumeration(IO &IO, EnumExtensibilityKind &EEK) {
474 IO.enumCase(EEK, "none", EnumExtensibilityKind::None);
475 IO.enumCase(EEK, "open", EnumExtensibilityKind::Open);
476 IO.enumCase(EEK, "closed", EnumExtensibilityKind::Closed);
477 }
478};
479
480template <> struct MappingTraits<Tag> {
481 static void mapping(IO &IO, Tag &T) {
482 IO.mapRequired("Name", T.Name);
483 IO.mapOptional("Availability", T.Availability.Mode,
484 APIAvailability::Available);
485 IO.mapOptional("AvailabilityMsg", T.Availability.Msg, StringRef(""));
486 IO.mapOptional("SwiftPrivate", T.SwiftPrivate);
487 IO.mapOptional("SwiftName", T.SwiftName, StringRef(""));
488 IO.mapOptional("SwiftBridge", T.SwiftBridge);
489 IO.mapOptional("NSErrorDomain", T.NSErrorDomain);
490 IO.mapOptional("SwiftImportAs", T.SwiftImportAs);
491 IO.mapOptional("SwiftReleaseOp", T.SwiftReleaseOp);
492 IO.mapOptional("SwiftRetainOp", T.SwiftRetainOp);
493 IO.mapOptional("SwiftConformsTo", T.SwiftConformance);
494 IO.mapOptional("EnumExtensibility", T.EnumExtensibility);
495 IO.mapOptional("FlagEnum", T.FlagEnum);
496 IO.mapOptional("EnumKind", T.EnumConvenienceKind);
497 IO.mapOptional("SwiftCopyable", T.SwiftCopyable);
498 IO.mapOptional("Methods", T.Methods);
499 IO.mapOptional("Fields", T.Fields);
500 IO.mapOptional("Tags", T.Tags);
501 }
502};
503} // namespace yaml
504} // namespace llvm
505
506namespace {
507struct Typedef {
508 StringRef Name;
509 AvailabilityItem Availability;
510 StringRef SwiftName;
511 std::optional<bool> SwiftPrivate;
512 std::optional<StringRef> SwiftBridge;
513 std::optional<StringRef> NSErrorDomain;
514 std::optional<SwiftNewTypeKind> SwiftType;
515};
516
517typedef std::vector<Typedef> TypedefsSeq;
518} // namespace
519
520LLVM_YAML_IS_SEQUENCE_VECTOR(Typedef)
521
522namespace llvm {
523namespace yaml {
524template <> struct ScalarEnumerationTraits<SwiftNewTypeKind> {
525 static void enumeration(IO &IO, SwiftNewTypeKind &SWK) {
526 IO.enumCase(SWK, "none", SwiftNewTypeKind::None);
527 IO.enumCase(SWK, "struct", SwiftNewTypeKind::Struct);
528 IO.enumCase(SWK, "enum", SwiftNewTypeKind::Enum);
529 }
530};
531
532template <> struct MappingTraits<Typedef> {
533 static void mapping(IO &IO, Typedef &T) {
534 IO.mapRequired("Name", T.Name);
535 IO.mapOptional("Availability", T.Availability.Mode,
536 APIAvailability::Available);
537 IO.mapOptional("AvailabilityMsg", T.Availability.Msg, StringRef(""));
538 IO.mapOptional("SwiftPrivate", T.SwiftPrivate);
539 IO.mapOptional("SwiftName", T.SwiftName, StringRef(""));
540 IO.mapOptional("SwiftBridge", T.SwiftBridge);
541 IO.mapOptional("NSErrorDomain", T.NSErrorDomain);
542 IO.mapOptional("SwiftWrapper", T.SwiftType);
543 }
544};
545} // namespace yaml
546} // namespace llvm
547
548namespace {
549struct Namespace;
550typedef std::vector<Namespace> NamespacesSeq;
551
552struct TopLevelItems {
553 ClassesSeq Classes;
554 ClassesSeq Protocols;
555 FunctionsSeq Functions;
556 GlobalVariablesSeq Globals;
557 EnumConstantsSeq EnumConstants;
558 TagsSeq Tags;
559 TypedefsSeq Typedefs;
560 NamespacesSeq Namespaces;
561};
562} // namespace
563
564namespace llvm {
565namespace yaml {
566static void mapTopLevelItems(IO &IO, TopLevelItems &TLI) {
567 IO.mapOptional("Classes", TLI.Classes);
568 IO.mapOptional("Protocols", TLI.Protocols);
569 IO.mapOptional("Functions", TLI.Functions);
570 IO.mapOptional("Globals", TLI.Globals);
571 IO.mapOptional("Enumerators", TLI.EnumConstants);
572 IO.mapOptional("Tags", TLI.Tags);
573 IO.mapOptional("Typedefs", TLI.Typedefs);
574 IO.mapOptional("Namespaces", TLI.Namespaces);
575}
576} // namespace yaml
577} // namespace llvm
578
579namespace {
580struct Namespace {
581 StringRef Name;
582 AvailabilityItem Availability;
583 StringRef SwiftName;
584 std::optional<bool> SwiftPrivate;
585 TopLevelItems Items;
586};
587} // namespace
588
589LLVM_YAML_IS_SEQUENCE_VECTOR(Namespace)
590
591namespace llvm {
592namespace yaml {
593template <> struct MappingTraits<Namespace> {
594 static void mapping(IO &IO, Namespace &T) {
595 IO.mapRequired("Name", T.Name);
596 IO.mapOptional("Availability", T.Availability.Mode,
597 APIAvailability::Available);
598 IO.mapOptional("AvailabilityMsg", T.Availability.Msg, StringRef(""));
599 IO.mapOptional("SwiftPrivate", T.SwiftPrivate);
600 IO.mapOptional("SwiftName", T.SwiftName, StringRef(""));
601 mapTopLevelItems(IO, T.Items);
602 }
603};
604} // namespace yaml
605} // namespace llvm
606
607namespace {
608struct Versioned {
609 VersionTuple Version;
610 TopLevelItems Items;
611};
612
613typedef std::vector<Versioned> VersionedSeq;
614} // namespace
615
616LLVM_YAML_IS_SEQUENCE_VECTOR(Versioned)
617
618namespace llvm {
619namespace yaml {
620template <> struct MappingTraits<Versioned> {
621 static void mapping(IO &IO, Versioned &V) {
622 IO.mapRequired("Version", V.Version);
623 mapTopLevelItems(IO, V.Items);
624 }
625};
626} // namespace yaml
627} // namespace llvm
628
629namespace {
630struct Module {
631 StringRef Name;
632 AvailabilityItem Availability;
633 TopLevelItems TopLevel;
634 VersionedSeq SwiftVersions;
635
636 std::optional<bool> SwiftInferImportAsMember;
637
638#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
639 LLVM_DUMP_METHOD void dump() /*const*/;
640#endif
641};
642} // namespace
643
644namespace llvm {
645namespace yaml {
646template <> struct MappingTraits<Module> {
647 static void mapping(IO &IO, Module &M) {
648 IO.mapRequired("Name", M.Name);
649 IO.mapOptional("Availability", M.Availability.Mode,
650 APIAvailability::Available);
651 IO.mapOptional("AvailabilityMsg", M.Availability.Msg, StringRef(""));
652 IO.mapOptional("SwiftInferImportAsMember", M.SwiftInferImportAsMember);
653 mapTopLevelItems(IO, M.TopLevel);
654 IO.mapOptional("SwiftVersions", M.SwiftVersions);
655 }
656};
657} // namespace yaml
658} // namespace llvm
659
660#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
661LLVM_DUMP_METHOD void Module::dump() {
662 llvm::yaml::Output OS(llvm::errs());
663 OS << *this;
664}
665#endif
666
667namespace {
668bool parseAPINotes(StringRef YI, Module &M, llvm::SourceMgr::DiagHandlerTy Diag,
669 void *DiagContext) {
670 llvm::yaml::Input IS(YI, nullptr, Diag, DiagContext);
671 IS >> M;
672 return static_cast<bool>(IS.error());
673}
674} // namespace
675
677 llvm::raw_ostream &OS) {
678 Module M;
679 if (parseAPINotes(YI, M, nullptr, nullptr))
680 return true;
681
682 llvm::yaml::Output YOS(OS);
683 YOS << M;
684
685 return false;
686}
687
688namespace {
689using namespace api_notes;
690
691class YAMLConverter {
692 const Module &M;
693 APINotesWriter Writer;
694 llvm::raw_ostream &OS;
695 llvm::SourceMgr::DiagHandlerTy DiagHandler;
696 void *DiagHandlerCtxt;
697 bool ErrorOccured;
698
699 /// Emit a diagnostic
700 bool emitError(llvm::Twine Message) {
701 DiagHandler(
702 llvm::SMDiagnostic("", llvm::SourceMgr::DK_Error, Message.str()),
703 DiagHandlerCtxt);
704 ErrorOccured = true;
705 return true;
706 }
707
708public:
709 YAMLConverter(const Module &TheModule, const FileEntry *SourceFile,
710 llvm::raw_ostream &OS,
711 llvm::SourceMgr::DiagHandlerTy DiagHandler,
712 void *DiagHandlerCtxt)
713 : M(TheModule), Writer(TheModule.Name, SourceFile), OS(OS),
714 DiagHandler(DiagHandler), DiagHandlerCtxt(DiagHandlerCtxt),
715 ErrorOccured(false) {}
716
717 void convertAvailability(const AvailabilityItem &Availability,
718 CommonEntityInfo &CEI, llvm::StringRef APIName) {
719 // Populate the unavailability information.
720 CEI.Unavailable = (Availability.Mode == APIAvailability::None);
721 CEI.UnavailableInSwift = (Availability.Mode == APIAvailability::NonSwift);
722 if (CEI.Unavailable || CEI.UnavailableInSwift) {
723 CEI.UnavailableMsg = std::string(Availability.Msg);
724 } else {
725 if (!Availability.Msg.empty())
726 emitError(llvm::Twine("availability message for available API '") +
727 APIName + "' will not be used");
728 }
729 }
730
731 void convertParams(const ParamsSeq &Params, FunctionInfo &OutInfo) {
732 for (const auto &P : Params) {
733 ParamInfo PI;
734 if (P.Nullability)
735 PI.setNullabilityAudited(*P.Nullability);
736 PI.setNoEscape(P.NoEscape);
737 PI.setType(std::string(P.Type));
738 PI.setRetainCountConvention(P.RetainCountConvention);
739 if (OutInfo.Params.size() <= P.Position)
740 OutInfo.Params.resize(P.Position + 1);
741 OutInfo.Params[P.Position] |= PI;
742 }
743 }
744
745 void convertNullability(const NullabilitySeq &Nullability,
746 std::optional<NullabilityKind> ReturnNullability,
747 FunctionInfo &OutInfo, llvm::StringRef APIName) {
749 emitError(llvm::Twine("nullability info for '") + APIName +
750 "' does not fit");
751 return;
752 }
753
754 bool audited = false;
755 unsigned int idx = 1;
756 for (const auto &N : Nullability)
757 OutInfo.addTypeInfo(idx++, N);
758 audited = Nullability.size() > 0 || ReturnNullability;
759 if (audited)
760 OutInfo.addTypeInfo(0, ReturnNullability ? *ReturnNullability
761 : NullabilityKind::NonNull);
762 if (!audited)
763 return;
764 OutInfo.NullabilityAudited = audited;
765 OutInfo.NumAdjustedNullable = idx;
766 }
767
768 /// Convert the common parts of an entity from YAML.
769 template <typename T>
770 void convertCommonEntity(const T &Common, CommonEntityInfo &Info,
771 StringRef APIName) {
772 convertAvailability(Common.Availability, Info, APIName);
773 Info.setSwiftPrivate(Common.SwiftPrivate);
774 Info.SwiftName = std::string(Common.SwiftName);
775 }
776
777 /// Convert the common parts of a type entity from YAML.
778 template <typename T>
779 void convertCommonType(const T &Common, CommonTypeInfo &Info,
780 StringRef APIName) {
781 convertCommonEntity(Common, Info, APIName);
782 if (Common.SwiftBridge)
783 Info.setSwiftBridge(std::string(*Common.SwiftBridge));
784 Info.setNSErrorDomain(Common.NSErrorDomain);
785 }
786
787 // Translate from Method into ObjCMethodInfo and write it out.
788 void convertMethod(const Method &M, ContextID ClassID, StringRef ClassName,
789 VersionTuple SwiftVersion) {
791 convertCommonEntity(M, MI, M.Selector);
792
793 // Check if the selector ends with ':' to determine if it takes arguments.
794 bool takesArguments = M.Selector.ends_with(":");
795
796 // Split the selector into pieces.
798 M.Selector.split(Args, ":", /*MaxSplit*/ -1, /*KeepEmpty*/ false);
799 if (!takesArguments && Args.size() > 1) {
800 emitError("selector '" + M.Selector + "' is missing a ':' at the end");
801 return;
802 }
803
804 // Construct ObjCSelectorRef.
806 Selector.NumArgs = !takesArguments ? 0 : Args.size();
807 Selector.Identifiers = Args;
808
809 // Translate the initializer info.
810 MI.DesignatedInit = M.DesignatedInit;
811 MI.RequiredInit = M.Required;
812 if (M.FactoryAsInit != FactoryAsInitKind::Infer)
813 emitError("'FactoryAsInit' is no longer valid; use 'SwiftName' instead");
814
815 MI.ResultType = std::string(M.ResultType);
816
817 // Translate parameter information.
818 convertParams(M.Params, MI);
819
820 // Translate nullability info.
821 convertNullability(M.Nullability, M.NullabilityOfRet, MI, M.Selector);
822
823 MI.setRetainCountConvention(M.RetainCountConvention);
824
825 // Write it.
826 Writer.addObjCMethod(ClassID, Selector, M.Kind == MethodKind::Instance, MI,
827 SwiftVersion);
828 }
829
830 template <typename T>
831 void convertVariable(const T &Entity, VariableInfo &VI) {
832 convertAvailability(Entity.Availability, VI, Entity.Name);
833 VI.setSwiftPrivate(Entity.SwiftPrivate);
834 VI.SwiftName = std::string(Entity.SwiftName);
835 if (Entity.Nullability)
836 VI.setNullabilityAudited(*Entity.Nullability);
837 VI.setType(std::string(Entity.Type));
838 }
839
840 void convertContext(std::optional<ContextID> ParentContextID, const Class &C,
841 ContextKind Kind, VersionTuple SwiftVersion) {
842 // Write the class.
843 ContextInfo CI;
844 convertCommonType(C, CI, C.Name);
845
846 if (C.AuditedForNullability)
847 CI.setDefaultNullability(NullabilityKind::NonNull);
848 if (C.SwiftImportAsNonGeneric)
849 CI.setSwiftImportAsNonGeneric(*C.SwiftImportAsNonGeneric);
850 if (C.SwiftObjCMembers)
851 CI.setSwiftObjCMembers(*C.SwiftObjCMembers);
852
853 ContextID CtxID =
854 Writer.addContext(ParentContextID, C.Name, Kind, CI, SwiftVersion);
855
856 // Write all methods.
857 llvm::StringMap<std::pair<bool, bool>> KnownMethods;
858 for (const auto &method : C.Methods) {
859 // Check for duplicate method definitions.
860 bool IsInstanceMethod = method.Kind == MethodKind::Instance;
861 bool &Known = IsInstanceMethod ? KnownMethods[method.Selector].first
862 : KnownMethods[method.Selector].second;
863 if (Known) {
864 emitError(llvm::Twine("duplicate definition of method '") +
865 (IsInstanceMethod ? "-" : "+") + "[" + C.Name + " " +
866 method.Selector + "]'");
867 continue;
868 }
869 Known = true;
870
871 convertMethod(method, CtxID, C.Name, SwiftVersion);
872 }
873
874 // Write all properties.
875 llvm::StringSet<> KnownInstanceProperties;
876 llvm::StringSet<> KnownClassProperties;
877 for (const auto &Property : C.Properties) {
878 // Check for duplicate property definitions.
879 if ((!Property.Kind || *Property.Kind == MethodKind::Instance) &&
880 !KnownInstanceProperties.insert(Property.Name).second) {
881 emitError(llvm::Twine("duplicate definition of instance property '") +
882 C.Name + "." + Property.Name + "'");
883 continue;
884 }
885
886 if ((!Property.Kind || *Property.Kind == MethodKind::Class) &&
887 !KnownClassProperties.insert(Property.Name).second) {
888 emitError(llvm::Twine("duplicate definition of class property '") +
889 C.Name + "." + Property.Name + "'");
890 continue;
891 }
892
893 // Translate from Property into ObjCPropertyInfo.
895 convertVariable(Property, PI);
896 if (Property.SwiftImportAsAccessors)
897 PI.setSwiftImportAsAccessors(*Property.SwiftImportAsAccessors);
898
899 // Add both instance and class properties with this name.
900 if (Property.Kind) {
901 Writer.addObjCProperty(CtxID, Property.Name,
902 *Property.Kind == MethodKind::Instance, PI,
903 SwiftVersion);
904 } else {
905 Writer.addObjCProperty(CtxID, Property.Name, true, PI, SwiftVersion);
906 Writer.addObjCProperty(CtxID, Property.Name, false, PI, SwiftVersion);
907 }
908 }
909 }
910
911 void convertNamespaceContext(std::optional<ContextID> ParentContextID,
912 const Namespace &TheNamespace,
913 VersionTuple SwiftVersion) {
914 // Write the namespace.
915 ContextInfo CI;
916 convertCommonEntity(TheNamespace, CI, TheNamespace.Name);
917
918 ContextID CtxID =
919 Writer.addContext(ParentContextID, TheNamespace.Name,
920 ContextKind::Namespace, CI, SwiftVersion);
921
922 convertTopLevelItems(Context(CtxID, ContextKind::Namespace),
923 TheNamespace.Items, SwiftVersion);
924 }
925
926 void convertFunction(const Function &Function, FunctionInfo &FI) {
927 convertAvailability(Function.Availability, FI, Function.Name);
928 FI.setSwiftPrivate(Function.SwiftPrivate);
929 FI.SwiftName = std::string(Function.SwiftName);
930 convertParams(Function.Params, FI);
931 convertNullability(Function.Nullability, Function.NullabilityOfRet, FI,
932 Function.Name);
933 FI.ResultType = std::string(Function.ResultType);
934 FI.setRetainCountConvention(Function.RetainCountConvention);
935 }
936
937 void convertTagContext(std::optional<Context> ParentContext, const Tag &T,
938 VersionTuple SwiftVersion) {
939 TagInfo TI;
940 std::optional<ContextID> ParentContextID =
941 ParentContext ? std::optional<ContextID>(ParentContext->id)
942 : std::nullopt;
943 convertCommonType(T, TI, T.Name);
944
945 if ((T.SwiftRetainOp || T.SwiftReleaseOp) && !T.SwiftImportAs) {
946 emitError(llvm::Twine("should declare SwiftImportAs to use "
947 "SwiftRetainOp and SwiftReleaseOp (for ") +
948 T.Name + ")");
949 return;
950 }
951 if (T.SwiftReleaseOp.has_value() != T.SwiftRetainOp.has_value()) {
952 emitError(llvm::Twine("should declare both SwiftReleaseOp and "
953 "SwiftRetainOp (for ") +
954 T.Name + ")");
955 return;
956 }
957
958 if (T.SwiftImportAs)
959 TI.SwiftImportAs = T.SwiftImportAs;
960 if (T.SwiftRetainOp)
961 TI.SwiftRetainOp = T.SwiftRetainOp;
962 if (T.SwiftReleaseOp)
963 TI.SwiftReleaseOp = T.SwiftReleaseOp;
964 if (T.SwiftConformance)
965 TI.SwiftConformance = T.SwiftConformance;
966
967 if (T.SwiftCopyable)
968 TI.setSwiftCopyable(T.SwiftCopyable);
969
970 if (T.EnumConvenienceKind) {
971 if (T.EnumExtensibility) {
972 emitError(
973 llvm::Twine("cannot mix EnumKind and EnumExtensibility (for ") +
974 T.Name + ")");
975 return;
976 }
977 if (T.FlagEnum) {
978 emitError(llvm::Twine("cannot mix EnumKind and FlagEnum (for ") +
979 T.Name + ")");
980 return;
981 }
982 switch (*T.EnumConvenienceKind) {
983 case EnumConvenienceAliasKind::None:
984 TI.EnumExtensibility = EnumExtensibilityKind::None;
985 TI.setFlagEnum(false);
986 break;
987 case EnumConvenienceAliasKind::CFEnum:
988 TI.EnumExtensibility = EnumExtensibilityKind::Open;
989 TI.setFlagEnum(false);
990 break;
991 case EnumConvenienceAliasKind::CFOptions:
992 TI.EnumExtensibility = EnumExtensibilityKind::Open;
993 TI.setFlagEnum(true);
994 break;
995 case EnumConvenienceAliasKind::CFClosedEnum:
996 TI.EnumExtensibility = EnumExtensibilityKind::Closed;
997 TI.setFlagEnum(false);
998 break;
999 }
1000 } else {
1001 TI.EnumExtensibility = T.EnumExtensibility;
1002 TI.setFlagEnum(T.FlagEnum);
1003 }
1004
1005 Writer.addTag(ParentContext, T.Name, TI, SwiftVersion);
1006
1007 ContextInfo CI;
1008 auto TagCtxID = Writer.addContext(ParentContextID, T.Name, ContextKind::Tag,
1009 CI, SwiftVersion);
1010 Context TagCtx(TagCtxID, ContextKind::Tag);
1011
1012 for (const auto &Field : T.Fields) {
1013 FieldInfo FI;
1014 convertVariable(Field, FI);
1015 Writer.addField(TagCtxID, Field.Name, FI, SwiftVersion);
1016 }
1017
1018 for (const auto &CXXMethod : T.Methods) {
1019 CXXMethodInfo MI;
1020 convertFunction(CXXMethod, MI);
1021 Writer.addCXXMethod(TagCtxID, CXXMethod.Name, MI, SwiftVersion);
1022 }
1023
1024 // Convert nested tags.
1025 for (const auto &Tag : T.Tags)
1026 convertTagContext(TagCtx, Tag, SwiftVersion);
1027 }
1028
1029 void convertTopLevelItems(std::optional<Context> Ctx,
1030 const TopLevelItems &TLItems,
1031 VersionTuple SwiftVersion) {
1032 std::optional<ContextID> CtxID =
1033 Ctx ? std::optional(Ctx->id) : std::nullopt;
1034
1035 // Write all classes.
1036 llvm::StringSet<> KnownClasses;
1037 for (const auto &Class : TLItems.Classes) {
1038 // Check for duplicate class definitions.
1039 if (!KnownClasses.insert(Class.Name).second) {
1040 emitError(llvm::Twine("multiple definitions of class '") + Class.Name +
1041 "'");
1042 continue;
1043 }
1044
1045 convertContext(CtxID, Class, ContextKind::ObjCClass, SwiftVersion);
1046 }
1047
1048 // Write all protocols.
1049 llvm::StringSet<> KnownProtocols;
1050 for (const auto &Protocol : TLItems.Protocols) {
1051 // Check for duplicate protocol definitions.
1052 if (!KnownProtocols.insert(Protocol.Name).second) {
1053 emitError(llvm::Twine("multiple definitions of protocol '") +
1054 Protocol.Name + "'");
1055 continue;
1056 }
1057
1058 convertContext(CtxID, Protocol, ContextKind::ObjCProtocol, SwiftVersion);
1059 }
1060
1061 // Write all namespaces.
1062 llvm::StringSet<> KnownNamespaces;
1063 for (const auto &Namespace : TLItems.Namespaces) {
1064 // Check for duplicate namespace definitions.
1065 if (!KnownNamespaces.insert(Namespace.Name).second) {
1066 emitError(llvm::Twine("multiple definitions of namespace '") +
1067 Namespace.Name + "'");
1068 continue;
1069 }
1070
1071 convertNamespaceContext(CtxID, Namespace, SwiftVersion);
1072 }
1073
1074 // Write all global variables.
1075 llvm::StringSet<> KnownGlobals;
1076 for (const auto &Global : TLItems.Globals) {
1077 // Check for duplicate global variables.
1078 if (!KnownGlobals.insert(Global.Name).second) {
1079 emitError(llvm::Twine("multiple definitions of global variable '") +
1080 Global.Name + "'");
1081 continue;
1082 }
1083
1085 convertVariable(Global, GVI);
1086 Writer.addGlobalVariable(Ctx, Global.Name, GVI, SwiftVersion);
1087 }
1088
1089 // Write all global functions.
1090 llvm::StringSet<> KnownFunctions;
1091 for (const auto &Function : TLItems.Functions) {
1092 // Check for duplicate global functions.
1093 if (!KnownFunctions.insert(Function.Name).second) {
1094 emitError(llvm::Twine("multiple definitions of global function '") +
1095 Function.Name + "'");
1096 continue;
1097 }
1098
1100 convertFunction(Function, GFI);
1101 Writer.addGlobalFunction(Ctx, Function.Name, GFI, SwiftVersion);
1102 }
1103
1104 // Write all enumerators.
1105 llvm::StringSet<> KnownEnumConstants;
1106 for (const auto &EnumConstant : TLItems.EnumConstants) {
1107 // Check for duplicate enumerators
1108 if (!KnownEnumConstants.insert(EnumConstant.Name).second) {
1109 emitError(llvm::Twine("multiple definitions of enumerator '") +
1110 EnumConstant.Name + "'");
1111 continue;
1112 }
1113
1114 EnumConstantInfo ECI;
1115 convertAvailability(EnumConstant.Availability, ECI, EnumConstant.Name);
1116 ECI.setSwiftPrivate(EnumConstant.SwiftPrivate);
1117 ECI.SwiftName = std::string(EnumConstant.SwiftName);
1118 Writer.addEnumConstant(EnumConstant.Name, ECI, SwiftVersion);
1119 }
1120
1121 // Write all tags.
1122 llvm::StringSet<> KnownTags;
1123 for (const auto &Tag : TLItems.Tags) {
1124 // Check for duplicate tag definitions.
1125 if (!KnownTags.insert(Tag.Name).second) {
1126 emitError(llvm::Twine("multiple definitions of tag '") + Tag.Name +
1127 "'");
1128 continue;
1129 }
1130
1131 convertTagContext(Ctx, Tag, SwiftVersion);
1132 }
1133
1134 // Write all typedefs.
1135 llvm::StringSet<> KnownTypedefs;
1136 for (const auto &Typedef : TLItems.Typedefs) {
1137 // Check for duplicate typedef definitions.
1138 if (!KnownTypedefs.insert(Typedef.Name).second) {
1139 emitError(llvm::Twine("multiple definitions of typedef '") +
1140 Typedef.Name + "'");
1141 continue;
1142 }
1143
1144 TypedefInfo TInfo;
1145 convertCommonType(Typedef, TInfo, Typedef.Name);
1146 TInfo.SwiftWrapper = Typedef.SwiftType;
1147
1148 Writer.addTypedef(Ctx, Typedef.Name, TInfo, SwiftVersion);
1149 }
1150 }
1151
1152 bool convertModule() {
1153 // Write the top-level items.
1154 convertTopLevelItems(/* context */ std::nullopt, M.TopLevel,
1155 VersionTuple());
1156
1157 // Convert the versioned information.
1158 for (const auto &Versioned : M.SwiftVersions)
1159 convertTopLevelItems(/* context */ std::nullopt, Versioned.Items,
1160 Versioned.Version);
1161
1162 if (!ErrorOccured)
1163 Writer.writeToStream(OS);
1164
1165 return ErrorOccured;
1166 }
1167};
1168} // namespace
1169
1170static bool compile(const Module &M, const FileEntry *SourceFile,
1171 llvm::raw_ostream &OS,
1172 llvm::SourceMgr::DiagHandlerTy DiagHandler,
1173 void *DiagHandlerCtxt) {
1174 YAMLConverter C(M, SourceFile, OS, DiagHandler, DiagHandlerCtxt);
1175 return C.convertModule();
1176}
1177
1178/// Simple diagnostic handler that prints diagnostics to standard error.
1179static void printDiagnostic(const llvm::SMDiagnostic &Diag, void *Context) {
1180 Diag.print(nullptr, llvm::errs());
1181}
1182
1183bool api_notes::compileAPINotes(StringRef YAMLInput,
1184 const FileEntry *SourceFile,
1185 llvm::raw_ostream &OS,
1186 llvm::SourceMgr::DiagHandlerTy DiagHandler,
1187 void *DiagHandlerCtxt) {
1188 Module TheModule;
1189
1190 if (!DiagHandler)
1191 DiagHandler = &printDiagnostic;
1192
1193 if (parseAPINotes(YAMLInput, TheModule, DiagHandler, DiagHandlerCtxt))
1194 return true;
1195
1196 return compile(TheModule, SourceFile, OS, DiagHandler, DiagHandlerCtxt);
1197}
static void printDiagnostic(const llvm::SMDiagnostic &Diag, void *Context)
Simple diagnostic handler that prints diagnostics to standard error.
static bool compile(const Module &M, const FileEntry *SourceFile, llvm::raw_ostream &OS, llvm::SourceMgr::DiagHandlerTy DiagHandler, void *DiagHandlerCtxt)
#define V(N, I)
Definition: ASTContext.h:3341
StringRef P
enum clang::sema::@1655::IndirectLocalPathEntry::EntryKind Kind
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
static DiagnosticBuilder Diag(DiagnosticsEngine *Diags, const LangOptions &Features, FullSourceLoc TokLoc, const char *TokBegin, const char *TokRangeBegin, const char *TokRangeEnd, unsigned DiagID)
Produce a diagnostic highlighting some portion of a literal.
Defines various enumerations that describe declaration and type specifiers.
Cached information about one file (either on disk or in the virtual file system).
Definition: FileEntry.h:300
Describes a module or submodule.
Definition: Module.h:105
std::string Name
The name of this module.
Definition: Module.h:108
void dump() const
Dump the contents of this module to the given output stream.
Smart pointer class that efficiently represents Objective-C method names.
The base class of the type hierarchy.
Definition: Type.h:1829
A class that writes API notes data to a binary representation that can be read by the APINotesReader.
void addObjCMethod(ContextID CtxID, ObjCSelectorRef Selector, bool IsInstanceMethod, const ObjCMethodInfo &Info, llvm::VersionTuple SwiftVersion)
Add information about a specific Objective-C method.
void addEnumConstant(llvm::StringRef Name, const EnumConstantInfo &Info, llvm::VersionTuple SwiftVersion)
Add information about an enumerator.
ContextID addContext(std::optional< ContextID > ParentCtxID, llvm::StringRef Name, ContextKind Kind, const ContextInfo &Info, llvm::VersionTuple SwiftVersion)
Add information about a specific Objective-C class or protocol or a C++ namespace.
void addGlobalFunction(std::optional< Context > Ctx, llvm::StringRef Name, const GlobalFunctionInfo &Info, llvm::VersionTuple SwiftVersion)
Add information about a global function.
void addObjCProperty(ContextID CtxID, llvm::StringRef Name, bool IsInstanceProperty, const ObjCPropertyInfo &Info, llvm::VersionTuple SwiftVersion)
Add information about a specific Objective-C property.
void addField(ContextID CtxID, llvm::StringRef Name, const FieldInfo &Info, llvm::VersionTuple SwiftVersion)
Add information about a specific C record field.
void addGlobalVariable(std::optional< Context > Ctx, llvm::StringRef Name, const GlobalVariableInfo &Info, llvm::VersionTuple SwiftVersion)
Add information about a global variable.
void addTypedef(std::optional< Context > Ctx, llvm::StringRef Name, const TypedefInfo &Info, llvm::VersionTuple SwiftVersion)
Add information about a typedef.
void writeToStream(llvm::raw_ostream &OS)
void addCXXMethod(ContextID CtxID, llvm::StringRef Name, const CXXMethodInfo &Info, llvm::VersionTuple SwiftVersion)
Add information about a specific C++ method.
void addTag(std::optional< Context > Ctx, llvm::StringRef Name, const TagInfo &Info, llvm::VersionTuple SwiftVersion)
Add information about a tag (struct/union/enum/C++ class).
Describes API notes data for a C++ method.
Definition: Types.h:666
Describes API notes data for any entity.
Definition: Types.h:52
unsigned UnavailableInSwift
Whether this entity is marked unavailable in Swift.
Definition: Types.h:63
unsigned Unavailable
Whether this entity is marked unavailable.
Definition: Types.h:59
std::string SwiftName
Swift name of this entity.
Definition: Types.h:76
void setSwiftPrivate(std::optional< bool > Private)
Definition: Types.h:87
std::string UnavailableMsg
Message to use when this entity is unavailable.
Definition: Types.h:55
Describes API notes for types.
Definition: Types.h:135
void setNSErrorDomain(const std::optional< std::string > &Domain)
Definition: Types.h:159
void setSwiftBridge(std::optional< std::string > SwiftType)
Definition: Types.h:151
Opaque context ID used to refer to an Objective-C class or protocol or a C++ namespace.
Definition: Types.h:800
Describes API notes data for an Objective-C class or protocol or a C++ namespace.
Definition: Types.h:197
void setDefaultNullability(NullabilityKind Kind)
Set the default nullability for properties and methods of this class.
Definition: Types.h:239
void setSwiftObjCMembers(std::optional< bool > Value)
Definition: Types.h:261
void setSwiftImportAsNonGeneric(std::optional< bool > Value)
Definition: Types.h:252
Describes API notes data for an enumerator.
Definition: Types.h:672
Describes API notes data for a C/C++ record field.
Definition: Types.h:660
API notes for a function or method.
Definition: Types.h:489
void addTypeInfo(unsigned index, NullabilityKind kind)
Definition: Types.h:532
void setRetainCountConvention(std::optional< RetainCountConventionKind > Value)
Definition: Types.h:572
std::vector< ParamInfo > Params
The function parameters.
Definition: Types.h:522
unsigned NumAdjustedNullable
Number of types whose nullability is encoded with the NullabilityPayload.
Definition: Types.h:506
std::string ResultType
The result type of this function, as a C type.
Definition: Types.h:519
static unsigned getMaxNullabilityIndex()
Definition: Types.h:528
unsigned NullabilityAudited
Whether the signature has been audited with respect to nullability.
Definition: Types.h:503
Describes API notes data for a global function.
Definition: Types.h:654
Describes API notes data for a global variable.
Definition: Types.h:648
Describes API notes data for an Objective-C method.
Definition: Types.h:609
unsigned DesignatedInit
Whether this is a designated initializer of its class.
Definition: Types.h:613
unsigned RequiredInit
Whether this is a required initializer.
Definition: Types.h:617
Describes API notes data for an Objective-C property.
Definition: Types.h:361
void setSwiftImportAsAccessors(std::optional< bool > Value)
Definition: Types.h:376
Describes a function or method parameter.
Definition: Types.h:419
void setNoEscape(std::optional< bool > Value)
Definition: Types.h:442
void setRetainCountConvention(std::optional< RetainCountConventionKind > Value)
Definition: Types.h:453
Describes API notes data for a tag.
Definition: Types.h:678
std::optional< std::string > SwiftReleaseOp
Definition: Types.h:692
std::optional< std::string > SwiftRetainOp
Definition: Types.h:691
std::optional< std::string > SwiftImportAs
Definition: Types.h:690
std::optional< EnumExtensibilityKind > EnumExtensibility
Definition: Types.h:697
void setSwiftCopyable(std::optional< bool > Value)
Definition: Types.h:717
void setFlagEnum(std::optional< bool > Value)
Definition: Types.h:708
std::optional< std::string > SwiftConformance
The Swift protocol that this type should be automatically conformed to.
Definition: Types.h:695
Describes API notes data for a typedef.
Definition: Types.h:768
std::optional< SwiftNewTypeKind > SwiftWrapper
Definition: Types.h:770
API notes for a variable/property.
Definition: Types.h:304
void setNullabilityAudited(NullabilityKind kind)
Definition: Types.h:326
void setType(const std::string &type)
Definition: Types.h:332
RetainCountConventionKind
Definition: Types.h:25
bool compileAPINotes(llvm::StringRef YAMLInput, const FileEntry *SourceFile, llvm::raw_ostream &OS, llvm::SourceMgr::DiagHandlerTy DiagHandler=nullptr, void *DiagHandlerCtxt=nullptr)
Converts API notes from YAML format to binary format.
SwiftNewTypeKind
The kind of a swift_wrapper/swift_newtype.
Definition: Types.h:43
EnumExtensibilityKind
The payload for an enum_extensibility attribute.
Definition: Types.h:36
bool parseAndDumpAPINotes(llvm::StringRef YI, llvm::raw_ostream &OS)
Parses the APINotes YAML content and writes the representation back to the specified stream.
The JSON file list parser is used to communicate input to InstallAPI.
NullabilityKind
Describes the nullability of a particular type.
Definition: Specifiers.h:336
@ Property
The type of a property.
const FunctionProtoType * T
@ Class
The "class" keyword introduces the elaborated-type-specifier.
static void mapTopLevelItems(IO &IO, TopLevelItems &TLI)
Diagnostic wrappers for TextAPI types for error reporting.
Definition: Dominators.h:30
#define false
Definition: stdbool.h:26
A temporary reference to an Objective-C selector, suitable for referencing selector data on the stack...
Definition: Types.h:827
static void mapping(IO &IO, Class &C)
static void mapping(IO &IO, EnumConstant &EC)
static void mapping(IO &IO, Field &F)
static void mapping(IO &IO, Function &F)
static void mapping(IO &IO, GlobalVariable &GV)
static void mapping(IO &IO, Method &M)
static void mapping(IO &IO, Module &M)
static void mapping(IO &IO, Namespace &T)
static void mapping(IO &IO, Param &P)
static void mapping(IO &IO, Property &P)
static void mapping(IO &IO, Tag &T)
static void mapping(IO &IO, Typedef &T)
static void mapping(IO &IO, Versioned &V)
static void enumeration(IO &IO, APIAvailability &AA)
static void enumeration(IO &IO, EnumConvenienceAliasKind &ECAK)
static void enumeration(IO &IO, EnumExtensibilityKind &EEK)
static void enumeration(IO &IO, FactoryAsInitKind &FIK)
static void enumeration(IO &IO, NullabilityKind &NK)
static void enumeration(IO &IO, RetainCountConventionKind &RCCK)
static void enumeration(IO &IO, SwiftNewTypeKind &SWK)