2929using namespace clang ;
3030using namespace api_notes ;
3131
32+ namespace llvm {
33+ namespace yaml {
34+ template <> struct ScalarEnumerationTraits <SwiftSafetyKind> {
35+ static void enumeration (IO &IO, SwiftSafetyKind &SK) {
36+ IO.enumCase (SK, " unspecified" , SwiftSafetyKind::Unspecified);
37+ IO.enumCase (SK, " safe" , SwiftSafetyKind::Safe);
38+ IO.enumCase (SK, " unsafe" , SwiftSafetyKind::Unsafe);
39+ }
40+ };
41+ } // namespace yaml
42+ } // namespace llvm
43+
3244namespace {
3345enum class APIAvailability {
3446 Available = 0 ,
@@ -163,6 +175,7 @@ struct Method {
163175 bool Required = false ;
164176 StringRef ResultType;
165177 StringRef SwiftReturnOwnership;
178+ SwiftSafetyKind SafetyKind = SwiftSafetyKind::None;
166179};
167180
168181typedef std::vector<Method> MethodsSeq;
@@ -199,6 +212,7 @@ template <> struct MappingTraits<Method> {
199212 IO.mapOptional (" ResultType" , M.ResultType , StringRef (" " ));
200213 IO.mapOptional (" SwiftReturnOwnership" , M.SwiftReturnOwnership ,
201214 StringRef (" " ));
215+ IO.mapOptional (" SwiftSafety" , M.SafetyKind , SwiftSafetyKind::None);
202216 }
203217};
204218} // namespace yaml
@@ -214,6 +228,7 @@ struct Property {
214228 StringRef SwiftName;
215229 std::optional<bool > SwiftImportAsAccessors;
216230 StringRef Type;
231+ SwiftSafetyKind SafetyKind = SwiftSafetyKind::None;
217232};
218233
219234typedef std::vector<Property> PropertiesSeq;
@@ -235,6 +250,7 @@ template <> struct MappingTraits<Property> {
235250 IO.mapOptional (" SwiftName" , P.SwiftName , StringRef (" " ));
236251 IO.mapOptional (" SwiftImportAsAccessors" , P.SwiftImportAsAccessors );
237252 IO.mapOptional (" Type" , P.Type , StringRef (" " ));
253+ IO.mapOptional (" SwiftSafety" , P.SafetyKind , SwiftSafetyKind::None);
238254 }
239255};
240256} // namespace yaml
@@ -254,6 +270,7 @@ struct Class {
254270 std::optional<std::string> SwiftConformance;
255271 MethodsSeq Methods;
256272 PropertiesSeq Properties;
273+ SwiftSafetyKind SafetyKind = SwiftSafetyKind::None;
257274};
258275
259276typedef std::vector<Class> ClassesSeq;
@@ -279,6 +296,7 @@ template <> struct MappingTraits<Class> {
279296 IO.mapOptional (" SwiftConformsTo" , C.SwiftConformance );
280297 IO.mapOptional (" Methods" , C.Methods );
281298 IO.mapOptional (" Properties" , C.Properties );
299+ IO.mapOptional (" SwiftSafety" , C.SafetyKind , SwiftSafetyKind::None);
282300 }
283301};
284302} // namespace yaml
@@ -297,6 +315,7 @@ struct Function {
297315 StringRef Type;
298316 StringRef ResultType;
299317 StringRef SwiftReturnOwnership;
318+ SwiftSafetyKind SafetyKind = SwiftSafetyKind::None;
300319};
301320
302321typedef std::vector<Function> FunctionsSeq;
@@ -321,6 +340,7 @@ template <> struct MappingTraits<Function> {
321340 IO.mapOptional (" ResultType" , F.ResultType , StringRef (" " ));
322341 IO.mapOptional (" SwiftReturnOwnership" , F.SwiftReturnOwnership ,
323342 StringRef (" " ));
343+ IO.mapOptional (" SwiftSafety" , F.SafetyKind , SwiftSafetyKind::None);
324344 }
325345};
326346} // namespace yaml
@@ -334,6 +354,7 @@ struct GlobalVariable {
334354 std::optional<bool > SwiftPrivate;
335355 StringRef SwiftName;
336356 StringRef Type;
357+ SwiftSafetyKind SafetyKind = SwiftSafetyKind::None;
337358};
338359
339360typedef std::vector<GlobalVariable> GlobalVariablesSeq;
@@ -353,6 +374,7 @@ template <> struct MappingTraits<GlobalVariable> {
353374 IO.mapOptional (" SwiftPrivate" , GV.SwiftPrivate );
354375 IO.mapOptional (" SwiftName" , GV.SwiftName , StringRef (" " ));
355376 IO.mapOptional (" Type" , GV.Type , StringRef (" " ));
377+ IO.mapOptional (" SwiftSafety" , GV.SafetyKind , SwiftSafetyKind::None);
356378 }
357379};
358380} // namespace yaml
@@ -364,6 +386,7 @@ struct EnumConstant {
364386 AvailabilityItem Availability;
365387 std::optional<bool > SwiftPrivate;
366388 StringRef SwiftName;
389+ SwiftSafetyKind SafetyKind = SwiftSafetyKind::None;
367390};
368391
369392typedef std::vector<EnumConstant> EnumConstantsSeq;
@@ -381,6 +404,7 @@ template <> struct MappingTraits<EnumConstant> {
381404 IO.mapOptional (" AvailabilityMsg" , EC.Availability .Msg , StringRef (" " ));
382405 IO.mapOptional (" SwiftPrivate" , EC.SwiftPrivate );
383406 IO.mapOptional (" SwiftName" , EC.SwiftName , StringRef (" " ));
407+ IO.mapOptional (" SwiftSafety" , EC.SafetyKind , SwiftSafetyKind::None);
384408 }
385409};
386410} // namespace yaml
@@ -424,6 +448,7 @@ struct Field {
424448 std::optional<bool > SwiftPrivate;
425449 StringRef SwiftName;
426450 StringRef Type;
451+ SwiftSafetyKind SafetyKind = SwiftSafetyKind::None;
427452};
428453
429454typedef std::vector<Field> FieldsSeq;
@@ -443,6 +468,7 @@ template <> struct MappingTraits<Field> {
443468 IO.mapOptional (" SwiftPrivate" , F.SwiftPrivate );
444469 IO.mapOptional (" SwiftName" , F.SwiftName , StringRef (" " ));
445470 IO.mapOptional (" Type" , F.Type , StringRef (" " ));
471+ IO.mapOptional (" SwiftSafety" , F.SafetyKind , SwiftSafetyKind::None);
446472 }
447473};
448474} // namespace yaml
@@ -470,6 +496,7 @@ struct Tag {
470496 std::optional<EnumConvenienceAliasKind> EnumConvenienceKind;
471497 std::optional<bool > SwiftCopyable;
472498 std::optional<bool > SwiftEscapable;
499+ SwiftSafetyKind SafetyKind = SwiftSafetyKind::None;
473500 FunctionsSeq Methods;
474501 FieldsSeq Fields;
475502
@@ -515,6 +542,7 @@ template <> struct MappingTraits<Tag> {
515542 IO.mapOptional (" Methods" , T.Methods );
516543 IO.mapOptional (" Fields" , T.Fields );
517544 IO.mapOptional (" Tags" , T.Tags );
545+ IO.mapOptional (" SwiftSafety" , T.SafetyKind , SwiftSafetyKind::None);
518546 }
519547};
520548} // namespace yaml
@@ -530,6 +558,7 @@ struct Typedef {
530558 std::optional<StringRef> NSErrorDomain;
531559 std::optional<SwiftNewTypeKind> SwiftType;
532560 std::optional<std::string> SwiftConformance;
561+ const SwiftSafetyKind SafetyKind = SwiftSafetyKind::None;
533562};
534563
535564typedef std::vector<Typedef> TypedefsSeq;
@@ -602,6 +631,7 @@ struct Namespace {
602631 StringRef SwiftName;
603632 std::optional<bool > SwiftPrivate;
604633 TopLevelItems Items;
634+ const SwiftSafetyKind SafetyKind = SwiftSafetyKind::None;
605635};
606636} // namespace
607637
@@ -797,6 +827,8 @@ class YAMLConverter {
797827 StringRef APIName) {
798828 convertAvailability (Common.Availability , Info, APIName);
799829 Info.setSwiftPrivate (Common.SwiftPrivate );
830+ if (Common.SafetyKind != SwiftSafetyKind::None)
831+ Info.setSwiftSafety (Common.SafetyKind );
800832 Info.SwiftName = std::string (Common.SwiftName );
801833 }
802834
@@ -956,6 +988,8 @@ class YAMLConverter {
956988 void convertFunction (const Function &Function, FuncOrMethodInfo &FI) {
957989 convertAvailability (Function.Availability , FI, Function.Name );
958990 FI.setSwiftPrivate (Function.SwiftPrivate );
991+ if (Function.SafetyKind != SwiftSafetyKind::None)
992+ FI.setSwiftSafety (Function.SafetyKind );
959993 FI.SwiftName = std::string (Function.SwiftName );
960994 std::optional<ParamInfo> This;
961995 convertParams (Function.Params , FI, This);
0 commit comments