@@ -303,42 +303,52 @@ static std::shared_ptr<CompileTimeValue> extractCompileTimeValue(Expr *expr) {
303303 return std::make_shared<RuntimeValue>();
304304}
305305
306- static std::vector<CustomAttrValue>
307- extractCustomAttrValues (VarDecl *propertyDecl) {
308- std::vector<CustomAttrValue> customAttrValues;
309-
310- for (auto *propertyWrapper : propertyDecl->getAttachedPropertyWrappers ()) {
311- std::vector<FunctionParameter> parameters;
312-
313- if (const auto *args = propertyWrapper->getArgs ()) {
314- for (auto arg : *args) {
315- const auto label = arg.getLabel ().str ().str ();
316- auto argExpr = arg.getExpr ();
317-
318- if (auto defaultArgument = dyn_cast<DefaultArgumentExpr>(argExpr)) {
319- auto *decl = defaultArgument->getParamDecl ();
320- if (decl->hasDefaultExpr ()) {
321- argExpr = decl->getTypeCheckedDefaultExpr ();
322- }
306+ static CustomAttrValue
307+ extractAttributeValue (const CustomAttr *attr) {
308+ std::vector<FunctionParameter> parameters;
309+ if (const auto *args = attr->getArgs ()) {
310+ for (auto arg : *args) {
311+ const auto label = arg.getLabel ().str ().str ();
312+ auto argExpr = arg.getExpr ();
313+
314+ if (auto defaultArgument = dyn_cast<DefaultArgumentExpr>(argExpr)) {
315+ auto *decl = defaultArgument->getParamDecl ();
316+ if (decl->hasDefaultExpr ()) {
317+ argExpr = decl->getTypeCheckedDefaultExpr ();
323318 }
324- parameters.push_back (
325- {label, argExpr->getType (), extractCompileTimeValue (argExpr)});
326319 }
320+ parameters.push_back (
321+ {label, argExpr->getType (), extractCompileTimeValue (argExpr)});
327322 }
328-
329- customAttrValues.push_back ({propertyWrapper, parameters});
330323 }
324+ return {attr, parameters};
325+ }
331326
327+ static AttrValueVector
328+ extractPropertyWrapperAttrValues (VarDecl *propertyDecl) {
329+ AttrValueVector customAttrValues;
330+ for (auto *propertyWrapper : propertyDecl->getAttachedPropertyWrappers ())
331+ customAttrValues.push_back (extractAttributeValue (propertyWrapper));
332+ return customAttrValues;
333+ }
334+
335+ static AttrValueVector
336+ extractRuntimeMetadataAttrValues (VarDecl *propertyDecl) {
337+ AttrValueVector customAttrValues;
338+ for (auto *runtimeMetadataAttribute : propertyDecl->getRuntimeDiscoverableAttrs ())
339+ customAttrValues.push_back (extractAttributeValue (runtimeMetadataAttribute));
332340 return customAttrValues;
333341}
334342
335343static ConstValueTypePropertyInfo
336344extractTypePropertyInfo (VarDecl *propertyDecl) {
337345 if (const auto binding = propertyDecl->getParentPatternBinding ()) {
338346 if (const auto originalInit = binding->getInit (0 )) {
339- if (propertyDecl->hasAttachedPropertyWrapper ()) {
347+ if (propertyDecl->hasAttachedPropertyWrapper () ||
348+ propertyDecl->hasRuntimeMetadataAttributes ()) {
340349 return {propertyDecl, extractCompileTimeValue (originalInit),
341- extractCustomAttrValues (propertyDecl)};
350+ extractPropertyWrapperAttrValues (propertyDecl),
351+ extractRuntimeMetadataAttrValues (propertyDecl)};
342352 }
343353
344354 return {propertyDecl, extractCompileTimeValue (originalInit)};
@@ -578,31 +588,51 @@ void writeValue(llvm::json::OStream &JSON,
578588 }
579589}
580590
591+ void writeAttributeInfo (llvm::json::OStream &JSON,
592+ const CustomAttrValue &AttrVal,
593+ const ASTContext &ctx) {
594+ JSON.object ([&] {
595+ JSON.attribute (" type" ,
596+ toFullyQualifiedTypeNameString (AttrVal.Attr ->getType ()));
597+ writeLocationInformation (JSON, AttrVal.Attr ->getLocation (), ctx);
598+ JSON.attributeArray (" arguments" , [&] {
599+ for (auto FP : AttrVal.Parameters ) {
600+ JSON.object ([&] {
601+ JSON.attribute (" label" , FP.Label );
602+ JSON.attribute (" type" , toFullyQualifiedTypeNameString (FP.Type ));
603+ writeValue (JSON, FP.Value );
604+ });
605+ }
606+ });
607+ });
608+ }
609+
581610void writePropertyWrapperAttributes (
582611 llvm::json::OStream &JSON,
583- llvm::Optional<std::vector<CustomAttrValue> > PropertyWrappers,
612+ llvm::Optional<AttrValueVector > PropertyWrappers,
584613 const ASTContext &ctx) {
585614 if (!PropertyWrappers.has_value ()) {
586615 return ;
587616 }
588617
589618 JSON.attributeArray (" propertyWrappers" , [&] {
590- for (auto PW : PropertyWrappers.value ()) {
591- JSON.object ([&] {
592- JSON.attribute (" type" ,
593- toFullyQualifiedTypeNameString (PW.Attr ->getType ()));
594- writeLocationInformation (JSON, PW.Attr ->getLocation (), ctx);
595- JSON.attributeArray (" arguments" , [&] {
596- for (auto FP : PW.Parameters ) {
597- JSON.object ([&] {
598- JSON.attribute (" label" , FP.Label );
599- JSON.attribute (" type" , toFullyQualifiedTypeNameString (FP.Type ));
600- writeValue (JSON, FP.Value );
601- });
602- }
603- });
604- });
605- }
619+ for (auto PW : PropertyWrappers.value ())
620+ writeAttributeInfo (JSON, PW, ctx);
621+ });
622+ }
623+
624+ void writeRuntimeMetadataAttributes (
625+ llvm::json::OStream &JSON,
626+ llvm::Optional<AttrValueVector> RuntimeMetadataAttributes,
627+ const ASTContext &ctx) {
628+ if (!RuntimeMetadataAttributes.has_value () ||
629+ RuntimeMetadataAttributes.value ().empty ()) {
630+ return ;
631+ }
632+
633+ JSON.attributeArray (" runtimeMetadataAttributes" , [&] {
634+ for (auto RMA : RuntimeMetadataAttributes.value ())
635+ writeAttributeInfo (JSON, RMA, ctx);;
606636 });
607637}
608638
@@ -737,6 +767,8 @@ bool writeAsJSONToFile(const std::vector<ConstValueTypeInfo> &ConstValueInfos,
737767 writeValue (JSON, PropertyInfo.Value );
738768 writePropertyWrapperAttributes (
739769 JSON, PropertyInfo.PropertyWrappers , decl->getASTContext ());
770+ writeRuntimeMetadataAttributes (
771+ JSON, PropertyInfo.RuntimeMetadataAttributes , decl->getASTContext ());
740772 writeResultBuilderInformation (JSON, TypeDecl, decl);
741773 writeAttrInformation (JSON, decl->getAttrs ());
742774 });
0 commit comments