@@ -303,42 +303,52 @@ static std::shared_ptr<CompileTimeValue> extractCompileTimeValue(Expr *expr) {
303
303
return std::make_shared<RuntimeValue>();
304
304
}
305
305
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 ();
323
318
}
324
- parameters.push_back (
325
- {label, argExpr->getType (), extractCompileTimeValue (argExpr)});
326
319
}
320
+ parameters.push_back (
321
+ {label, argExpr->getType (), extractCompileTimeValue (argExpr)});
327
322
}
328
-
329
- customAttrValues.push_back ({propertyWrapper, parameters});
330
323
}
324
+ return {attr, parameters};
325
+ }
331
326
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));
332
340
return customAttrValues;
333
341
}
334
342
335
343
static ConstValueTypePropertyInfo
336
344
extractTypePropertyInfo (VarDecl *propertyDecl) {
337
345
if (const auto binding = propertyDecl->getParentPatternBinding ()) {
338
346
if (const auto originalInit = binding->getInit (0 )) {
339
- if (propertyDecl->hasAttachedPropertyWrapper ()) {
347
+ if (propertyDecl->hasAttachedPropertyWrapper () ||
348
+ propertyDecl->hasRuntimeMetadataAttributes ()) {
340
349
return {propertyDecl, extractCompileTimeValue (originalInit),
341
- extractCustomAttrValues (propertyDecl)};
350
+ extractPropertyWrapperAttrValues (propertyDecl),
351
+ extractRuntimeMetadataAttrValues (propertyDecl)};
342
352
}
343
353
344
354
return {propertyDecl, extractCompileTimeValue (originalInit)};
@@ -578,31 +588,51 @@ void writeValue(llvm::json::OStream &JSON,
578
588
}
579
589
}
580
590
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
+
581
610
void writePropertyWrapperAttributes (
582
611
llvm::json::OStream &JSON,
583
- llvm::Optional<std::vector<CustomAttrValue> > PropertyWrappers,
612
+ llvm::Optional<AttrValueVector > PropertyWrappers,
584
613
const ASTContext &ctx) {
585
614
if (!PropertyWrappers.has_value ()) {
586
615
return ;
587
616
}
588
617
589
618
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);;
606
636
});
607
637
}
608
638
@@ -737,6 +767,8 @@ bool writeAsJSONToFile(const std::vector<ConstValueTypeInfo> &ConstValueInfos,
737
767
writeValue (JSON, PropertyInfo.Value );
738
768
writePropertyWrapperAttributes (
739
769
JSON, PropertyInfo.PropertyWrappers , decl->getASTContext ());
770
+ writeRuntimeMetadataAttributes (
771
+ JSON, PropertyInfo.RuntimeMetadataAttributes , decl->getASTContext ());
740
772
writeResultBuilderInformation (JSON, TypeDecl, decl);
741
773
writeAttrInformation (JSON, decl->getAttrs ());
742
774
});
0 commit comments