@@ -325,7 +325,8 @@ extractCustomAttrValues(VarDecl *propertyDecl) {
325325 {label, argExpr->getType (), extractCompileTimeValue (argExpr)});
326326 }
327327 }
328- customAttrValues.push_back ({propertyWrapper->getType (), parameters});
328+
329+ customAttrValues.push_back ({propertyWrapper, parameters});
329330 }
330331
331332 return customAttrValues;
@@ -458,29 +459,14 @@ gatherConstValuesForPrimary(const std::unordered_set<std::string> &Protocols,
458459 return Result;
459460}
460461
461- void writeFileInformation (llvm::json::OStream &JSON, const VarDecl *VD) {
462- SourceRange sourceRange = VD->getSourceRange ();
463- if (sourceRange.isInvalid ())
464- return ;
465-
466- const ASTContext &ctx = VD->getDeclContext ()->getASTContext ();
467- JSON.attribute (" file" , ctx.SourceMgr .getDisplayNameForLoc (sourceRange.Start ));
468- JSON.attribute (
469- " line" ,
470- ctx.SourceMgr .getPresumedLineAndColumnForLoc (sourceRange.Start ).first );
471- }
472-
473- void writeFileInformation (llvm::json::OStream &JSON,
474- const NominalTypeDecl *NTD) {
475- DeclContext *DC = NTD->getInnermostDeclContext ();
476- SourceLoc loc = extractNearestSourceLoc (DC);
477- if (loc.isInvalid ())
462+ void writeLocationInformation (llvm::json::OStream &JSON, SourceLoc Loc,
463+ const ASTContext &ctx) {
464+ if (Loc.isInvalid ())
478465 return ;
479466
480- const ASTContext &ctx = DC->getASTContext ();
481- JSON.attribute (" file" , ctx.SourceMgr .getDisplayNameForLoc (loc));
467+ JSON.attribute (" file" , ctx.SourceMgr .getDisplayNameForLoc (Loc));
482468 JSON.attribute (" line" ,
483- ctx.SourceMgr .getPresumedLineAndColumnForLoc (loc ).first );
469+ ctx.SourceMgr .getPresumedLineAndColumnForLoc (Loc ).first );
484470}
485471
486472void writeValue (llvm::json::OStream &JSON,
@@ -592,17 +578,20 @@ void writeValue(llvm::json::OStream &JSON,
592578 }
593579}
594580
595- void writeAttributes (
581+ void writePropertyWrapperAttributes (
596582 llvm::json::OStream &JSON,
597- llvm::Optional<std::vector<CustomAttrValue>> PropertyWrappers) {
583+ llvm::Optional<std::vector<CustomAttrValue>> PropertyWrappers,
584+ const ASTContext &ctx) {
598585 if (!PropertyWrappers.has_value ()) {
599586 return ;
600587 }
601588
602- JSON.attributeArray (" attributes " , [&] {
589+ JSON.attributeArray (" propertyWrappers " , [&] {
603590 for (auto PW : PropertyWrappers.value ()) {
604591 JSON.object ([&] {
605- JSON.attribute (" type" , toFullyQualifiedTypeNameString (PW.Type ));
592+ JSON.attribute (" type" ,
593+ toFullyQualifiedTypeNameString (PW.Attr ->getType ()));
594+ writeLocationInformation (JSON, PW.Attr ->getLocation (), ctx);
606595 JSON.attributeArray (" arguments" , [&] {
607596 for (auto FP : PW.Parameters ) {
608597 JSON.object ([&] {
@@ -730,7 +719,9 @@ bool writeAsJSONToFile(const std::vector<ConstValueTypeInfo> &ConstValueInfos,
730719 " kind" ,
731720 TypeDecl->getDescriptiveKindName (TypeDecl->getDescriptiveKind ())
732721 .str ());
733- writeFileInformation (JSON, TypeDecl);
722+ writeLocationInformation (
723+ JSON, extractNearestSourceLoc (TypeDecl->getInnermostDeclContext ()),
724+ TypeDecl->getInnermostDeclContext ()->getASTContext ());
734725 JSON.attributeArray (" properties" , [&] {
735726 for (const auto &PropertyInfo : TypeInfo.Properties ) {
736727 JSON.object ([&] {
@@ -741,9 +732,11 @@ bool writeAsJSONToFile(const std::vector<ConstValueTypeInfo> &ConstValueInfos,
741732 JSON.attribute (" isStatic" , decl->isStatic () ? " true" : " false" );
742733 JSON.attribute (" isComputed" ,
743734 !decl->hasStorage () ? " true" : " false" );
744- writeFileInformation (JSON, decl);
735+ writeLocationInformation (JSON, decl->getLoc (),
736+ decl->getDeclContext ()->getASTContext ());
745737 writeValue (JSON, PropertyInfo.Value );
746- writeAttributes (JSON, PropertyInfo.PropertyWrappers );
738+ writePropertyWrapperAttributes (
739+ JSON, PropertyInfo.PropertyWrappers , decl->getASTContext ());
747740 writeResultBuilderInformation (JSON, TypeDecl, decl);
748741 writeAttrInformation (JSON, decl->getAttrs ());
749742 });
0 commit comments