[clang] 671709f - [clang][ExtractAPI] Add targetFallback to relationships in symbol graph

Daniel Grumberg via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 7 05:12:45 PST 2022


Author: Daniel Grumberg
Date: 2022-11-07T13:12:34Z
New Revision: 671709f0e7d49826fd0908be2c9aed07debf5bc9

URL: https://github.com/llvm/llvm-project/commit/671709f0e7d49826fd0908be2c9aed07debf5bc9
DIFF: https://github.com/llvm/llvm-project/commit/671709f0e7d49826fd0908be2c9aed07debf5bc9.diff

LOG: [clang][ExtractAPI] Add targetFallback to relationships in symbol graph

Adds a 'targetFallback' field to relationships in symbol graph that
contains the plain name of the relationship target. This is useful for
clients when the relationship target symbol is not available.

Differential Revision: https://reviews.llvm.org/D136455

Added: 
    

Modified: 
    clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
    clang/test/ExtractAPI/anonymous_record_no_typedef.c
    clang/test/ExtractAPI/enum.c
    clang/test/ExtractAPI/objc_category.m
    clang/test/ExtractAPI/objc_interface.m
    clang/test/ExtractAPI/objc_property.m
    clang/test/ExtractAPI/objc_protocol.m
    clang/test/ExtractAPI/struct.c
    clang/test/ExtractAPI/underscored.c

Removed: 
    


################################################################################
diff  --git a/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp b/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
index 988ecd2defa9c..641f1ae812a58 100644
--- a/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
+++ b/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
@@ -559,6 +559,7 @@ void SymbolGraphSerializer::serializeRelationship(RelationshipKind Kind,
   Object Relationship;
   Relationship["source"] = Source.USR;
   Relationship["target"] = Target.USR;
+  Relationship["targetFallback"] = Target.Name;
   Relationship["kind"] = getRelationshipString(Kind);
 
   Relationships.emplace_back(std::move(Relationship));

diff  --git a/clang/test/ExtractAPI/anonymous_record_no_typedef.c b/clang/test/ExtractAPI/anonymous_record_no_typedef.c
index e20abfdd86ab4..abb96db058dbf 100644
--- a/clang/test/ExtractAPI/anonymous_record_no_typedef.c
+++ b/clang/test/ExtractAPI/anonymous_record_no_typedef.c
@@ -56,22 +56,26 @@ struct Vehicle {
     {
       "kind": "memberOf",
       "source": "c:@S at Vehicle@E at input.h@64 at Bicycle",
-      "target": "c:@S at Vehicle@E at input.h@64"
+      "target": "c:@S at Vehicle@E at input.h@64",
+      "targetFallback": "Vehicle::enum (unnamed)"
     },
     {
       "kind": "memberOf",
       "source": "c:@S at Vehicle@E at input.h@64 at Car",
-      "target": "c:@S at Vehicle@E at input.h@64"
+      "target": "c:@S at Vehicle@E at input.h@64",
+      "targetFallback": "Vehicle::enum (unnamed)"
     },
     {
       "kind": "memberOf",
       "source": "c:@S at Vehicle@FI at type",
-      "target": "c:@S at Vehicle"
+      "target": "c:@S at Vehicle",
+      "targetFallback": "Vehicle"
     },
     {
       "kind": "memberOf",
       "source": "c:@S at Vehicle@FI at information",
-      "target": "c:@S at Vehicle"
+      "target": "c:@S at Vehicle",
+      "targetFallback": "Vehicle"
     }
   ],
   "symbols": [

diff  --git a/clang/test/ExtractAPI/enum.c b/clang/test/ExtractAPI/enum.c
index 07d848082981f..7b345464cb982 100644
--- a/clang/test/ExtractAPI/enum.c
+++ b/clang/test/ExtractAPI/enum.c
@@ -65,57 +65,68 @@ enum {
     {
       "kind": "memberOf",
       "source": "c:@E at Vehicle@Bicycle",
-      "target": "c:@E at Vehicle"
+      "target": "c:@E at Vehicle",
+      "targetFallback": "Vehicle"
     },
     {
       "kind": "memberOf",
       "source": "c:@E at Vehicle@Car",
-      "target": "c:@E at Vehicle"
+      "target": "c:@E at Vehicle",
+      "targetFallback": "Vehicle"
     },
     {
       "kind": "memberOf",
       "source": "c:@E at Vehicle@Train",
-      "target": "c:@E at Vehicle"
+      "target": "c:@E at Vehicle",
+      "targetFallback": "Vehicle"
     },
     {
       "kind": "memberOf",
       "source": "c:@E at Vehicle@Ship",
-      "target": "c:@E at Vehicle"
+      "target": "c:@E at Vehicle",
+      "targetFallback": "Vehicle"
     },
     {
       "kind": "memberOf",
       "source": "c:@E at Vehicle@Airplane",
-      "target": "c:@E at Vehicle"
+      "target": "c:@E at Vehicle",
+      "targetFallback": "Vehicle"
     },
     {
       "kind": "memberOf",
       "source": "c:@E at Direction@North",
-      "target": "c:@E at Direction"
+      "target": "c:@E at Direction",
+      "targetFallback": "Direction"
     },
     {
       "kind": "memberOf",
       "source": "c:@E at Direction@East",
-      "target": "c:@E at Direction"
+      "target": "c:@E at Direction",
+      "targetFallback": "Direction"
     },
     {
       "kind": "memberOf",
       "source": "c:@E at Direction@South",
-      "target": "c:@E at Direction"
+      "target": "c:@E at Direction",
+      "targetFallback": "Direction"
     },
     {
       "kind": "memberOf",
       "source": "c:@E at Direction@West",
-      "target": "c:@E at Direction"
+      "target": "c:@E at Direction",
+      "targetFallback": "Direction"
     },
     {
       "kind": "memberOf",
       "source": "c:@Ea at Constant@Constant",
-      "target": "c:@Ea at Constant"
+      "target": "c:@Ea at Constant",
+      "targetFallback": "enum (unnamed)"
     },
     {
       "kind": "memberOf",
       "source": "c:@Ea at OtherConstant@OtherConstant",
-      "target": "c:@Ea at OtherConstant"
+      "target": "c:@Ea at OtherConstant",
+      "targetFallback": "enum (unnamed)"
     }
   ],
   "symbols": [

diff  --git a/clang/test/ExtractAPI/objc_category.m b/clang/test/ExtractAPI/objc_category.m
index 56bac43a11cdc..185016dfe848c 100644
--- a/clang/test/ExtractAPI/objc_category.m
+++ b/clang/test/ExtractAPI/objc_category.m
@@ -54,22 +54,26 @@ + (void)ClassMethod;
     {
       "kind": "memberOf",
       "source": "c:objc(cs)Interface(im)InstanceMethod",
-      "target": "c:objc(cs)Interface"
+      "target": "c:objc(cs)Interface",
+      "targetFallback": "Interface"
     },
     {
       "kind": "memberOf",
       "source": "c:objc(cs)Interface(cm)ClassMethod",
-      "target": "c:objc(cs)Interface"
+      "target": "c:objc(cs)Interface",
+      "targetFallback": "Interface"
     },
     {
       "kind": "memberOf",
       "source": "c:objc(cs)Interface(py)Property",
-      "target": "c:objc(cs)Interface"
+      "target": "c:objc(cs)Interface",
+      "targetFallback": "Interface"
     },
     {
       "kind": "conformsTo",
       "source": "c:objc(cs)Interface",
-      "target": "c:objc(pl)Protocol"
+      "target": "c:objc(pl)Protocol",
+      "targetFallback": "Protocol"
     }
   ],
   "symbols": [

diff  --git a/clang/test/ExtractAPI/objc_interface.m b/clang/test/ExtractAPI/objc_interface.m
index 740a215400d9c..159e97a193a13 100644
--- a/clang/test/ExtractAPI/objc_interface.m
+++ b/clang/test/ExtractAPI/objc_interface.m
@@ -57,37 +57,44 @@ - (char)getIvar;
     {
       "kind": "memberOf",
       "source": "c:objc(cs)Super(cm)getWithProperty:",
-      "target": "c:objc(cs)Super"
+      "target": "c:objc(cs)Super",
+      "targetFallback": "Super"
     },
     {
       "kind": "memberOf",
       "source": "c:objc(cs)Super(im)setProperty:andOtherThing:",
-      "target": "c:objc(cs)Super"
+      "target": "c:objc(cs)Super",
+      "targetFallback": "Super"
     },
     {
       "kind": "memberOf",
       "source": "c:objc(cs)Super(py)Property",
-      "target": "c:objc(cs)Super"
+      "target": "c:objc(cs)Super",
+      "targetFallback": "Super"
     },
     {
       "kind": "conformsTo",
       "source": "c:objc(cs)Super",
-      "target": "c:objc(pl)Protocol"
+      "target": "c:objc(pl)Protocol",
+      "targetFallback": "Protocol"
     },
     {
       "kind": "memberOf",
       "source": "c:objc(cs)Derived at Ivar",
-      "target": "c:objc(cs)Derived"
+      "target": "c:objc(cs)Derived",
+      "targetFallback": "Derived"
     },
     {
       "kind": "memberOf",
       "source": "c:objc(cs)Derived(im)getIvar",
-      "target": "c:objc(cs)Derived"
+      "target": "c:objc(cs)Derived",
+      "targetFallback": "Derived"
     },
     {
       "kind": "inheritsFrom",
       "source": "c:objc(cs)Derived",
-      "target": "c:objc(cs)Super"
+      "target": "c:objc(cs)Super",
+      "targetFallback": "Super"
     }
   ],
   "symbols": [

diff  --git a/clang/test/ExtractAPI/objc_property.m b/clang/test/ExtractAPI/objc_property.m
index 1b50950d44243..f09a5ad724238 100644
--- a/clang/test/ExtractAPI/objc_property.m
+++ b/clang/test/ExtractAPI/objc_property.m
@@ -55,37 +55,44 @@ @interface Interface (Category) <Protocol>
     {
       "kind": "memberOf",
       "source": "c:objc(cs)Interface(cpy)myInterfaceTypeProp",
-      "target": "c:objc(cs)Interface"
+      "target": "c:objc(cs)Interface",
+      "targetFallback": "Interface"
     },
     {
       "kind": "memberOf",
       "source": "c:objc(cs)Interface(py)myInterfaceInstanceProp",
-      "target": "c:objc(cs)Interface"
+      "target": "c:objc(cs)Interface",
+      "targetFallback": "Interface"
     },
     {
       "kind": "memberOf",
       "source": "c:objc(cs)Interface(cpy)myCategoryTypeProp",
-      "target": "c:objc(cs)Interface"
+      "target": "c:objc(cs)Interface",
+      "targetFallback": "Interface"
     },
     {
       "kind": "memberOf",
       "source": "c:objc(cs)Interface(py)myCategoryInstanceProp",
-      "target": "c:objc(cs)Interface"
+      "target": "c:objc(cs)Interface",
+      "targetFallback": "Interface"
     },
     {
       "kind": "conformsTo",
       "source": "c:objc(cs)Interface",
-      "target": "c:objc(pl)Protocol"
+      "target": "c:objc(pl)Protocol",
+      "targetFallback": "Protocol"
     },
     {
       "kind": "memberOf",
       "source": "c:objc(pl)Protocol(cpy)myProtocolTypeProp",
-      "target": "c:objc(pl)Protocol"
+      "target": "c:objc(pl)Protocol",
+      "targetFallback": "Protocol"
     },
     {
       "kind": "memberOf",
       "source": "c:objc(pl)Protocol(py)myProtocolInstanceProp",
-      "target": "c:objc(pl)Protocol"
+      "target": "c:objc(pl)Protocol",
+      "targetFallback": "Protocol"
     }
   ],
   "symbols": [

diff  --git a/clang/test/ExtractAPI/objc_protocol.m b/clang/test/ExtractAPI/objc_protocol.m
index 036850924587c..d9a65f419df89 100644
--- a/clang/test/ExtractAPI/objc_protocol.m
+++ b/clang/test/ExtractAPI/objc_protocol.m
@@ -49,7 +49,8 @@ @protocol AnotherProtocol <Protocol>
     {
       "kind": "conformsTo",
       "source": "c:objc(pl)AnotherProtocol",
-      "target": "c:objc(pl)Protocol"
+      "target": "c:objc(pl)Protocol",
+      "targetFallback": "Protocol"
     }
   ],
   "symbols": [

diff  --git a/clang/test/ExtractAPI/struct.c b/clang/test/ExtractAPI/struct.c
index 516055768749c..7e93f0d7e7bfa 100644
--- a/clang/test/ExtractAPI/struct.c
+++ b/clang/test/ExtractAPI/struct.c
@@ -52,22 +52,26 @@ struct Color {
     {
       "kind": "memberOf",
       "source": "c:@S at Color@FI at Red",
-      "target": "c:@S at Color"
+      "target": "c:@S at Color",
+      "targetFallback": "Color"
     },
     {
       "kind": "memberOf",
       "source": "c:@S at Color@FI at Green",
-      "target": "c:@S at Color"
+      "target": "c:@S at Color",
+      "targetFallback": "Color"
     },
     {
       "kind": "memberOf",
       "source": "c:@S at Color@FI at Blue",
-      "target": "c:@S at Color"
+      "target": "c:@S at Color",
+      "targetFallback": "Color"
     },
     {
       "kind": "memberOf",
       "source": "c:@S at Color@FI at Alpha",
-      "target": "c:@S at Color"
+      "target": "c:@S at Color",
+      "targetFallback": "Color"
     }
   ],
   "symbols": [

diff  --git a/clang/test/ExtractAPI/underscored.c b/clang/test/ExtractAPI/underscored.c
index 47f1893cdb029..6eeaf1ce412c3 100644
--- a/clang/test/ExtractAPI/underscored.c
+++ b/clang/test/ExtractAPI/underscored.c
@@ -65,7 +65,8 @@ typedef _HiddenTypedef ExposedTypedefToHidden;
     {
       "kind": "memberOf",
       "source": "c:@S at ExposedRecord@FI at a",
-      "target": "c:@S at ExposedRecord"
+      "target": "c:@S at ExposedRecord",
+      "targetFallback": "ExposedRecord"
     }
   ],
   "symbols": [


        


More information about the cfe-commits mailing list