[clang] f63db91 - Only add targetFallback if target is not in defined in current product
Daniel Grumberg via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 7 05:12:46 PST 2022
Author: Daniel Grumberg
Date: 2022-11-07T13:12:34Z
New Revision: f63db9159bbbb0db98e13cb4440fdaa5c40e219b
URL: https://github.com/llvm/llvm-project/commit/f63db9159bbbb0db98e13cb4440fdaa5c40e219b
DIFF: https://github.com/llvm/llvm-project/commit/f63db9159bbbb0db98e13cb4440fdaa5c40e219b.diff
LOG: Only add targetFallback if target is not in defined in current product
Added:
Modified:
clang/include/clang/ExtractAPI/API.h
clang/lib/ExtractAPI/API.cpp
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/include/clang/ExtractAPI/API.h b/clang/include/clang/ExtractAPI/API.h
index b77d76d500df6..ffb700eb923f8 100644
--- a/clang/include/clang/ExtractAPI/API.h
+++ b/clang/include/clang/ExtractAPI/API.h
@@ -675,6 +675,12 @@ class APISet {
const RecordMap<MacroDefinitionRecord> &getMacros() const { return Macros; }
const RecordMap<TypedefRecord> &getTypedefs() const { return Typedefs; }
+ /// Get the APIRecord associated with the USR if it's defined in the
+ /// current product.
+ ///
+ /// \returns a APIRecord pointer to the stored symbol record if it exists.
+ APIRecord *getSymbolForUSR(StringRef USR) const;
+
/// Generate and store the USR of declaration \p D.
///
/// Note: The USR string is stored in and owned by Allocator.
diff --git a/clang/lib/ExtractAPI/API.cpp b/clang/lib/ExtractAPI/API.cpp
index 8ab03a833e3c2..48322023d5041 100644
--- a/clang/lib/ExtractAPI/API.cpp
+++ b/clang/lib/ExtractAPI/API.cpp
@@ -197,6 +197,39 @@ TypedefRecord *APISet::addTypedef(StringRef Name, StringRef USR,
Comment, Declaration, SubHeading, UnderlyingType);
}
+template <class RecordMap>
+static APIRecord *getSymbolInRecordMapForUSR(StringRef USR,
+ const RecordMap &Records) {
+ auto It = Records.find(USR);
+ return (It != Records.end() ? It->second.get() : nullptr);
+}
+
+APIRecord *APISet::getSymbolForUSR(StringRef USR) const {
+ if (USR.empty())
+ return nullptr;
+ if (auto *Record = getSymbolInRecordMapForUSR(USR, ObjCProtocols))
+ return Record;
+ if (auto *Record = getSymbolInRecordMapForUSR(USR, ObjCInterfaces))
+ return Record;
+ if (auto *Record = getSymbolInRecordMapForUSR(USR, ObjCCategories))
+ return Record;
+ if (auto *Record = getSymbolInRecordMapForUSR(USR, ObjCCategories))
+ return Record;
+ if (auto *Record = getSymbolInRecordMapForUSR(USR, Structs))
+ return Record;
+ if (auto *Record = getSymbolInRecordMapForUSR(USR, Enums))
+ return Record;
+ if (auto *Record = getSymbolInRecordMapForUSR(USR, Typedefs))
+ return Record;
+ if (auto *Record = getSymbolInRecordMapForUSR(USR, GlobalFunctions))
+ return Record;
+ if (auto *Record = getSymbolInRecordMapForUSR(USR, GlobalVariables))
+ return Record;
+ if (auto *Record = getSymbolInRecordMapForUSR(USR, Macros))
+ return Record;
+ return nullptr;
+}
+
StringRef APISet::recordUSR(const Decl *D) {
SmallString<128> USR;
index::generateUSRForDecl(D, USR);
diff --git a/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp b/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
index 641f1ae812a58..807c618e3198f 100644
--- a/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
+++ b/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
@@ -559,7 +559,10 @@ void SymbolGraphSerializer::serializeRelationship(RelationshipKind Kind,
Object Relationship;
Relationship["source"] = Source.USR;
Relationship["target"] = Target.USR;
- Relationship["targetFallback"] = Target.Name;
+ // Emit a fallback if the target is not a symbol that will be part of this
+ // symbol graph.
+ if (API.getSymbolForUSR(Target.USR) == nullptr)
+ 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 abb96db058dbf..e20abfdd86ab4 100644
--- a/clang/test/ExtractAPI/anonymous_record_no_typedef.c
+++ b/clang/test/ExtractAPI/anonymous_record_no_typedef.c
@@ -56,26 +56,22 @@ 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",
- "targetFallback": "Vehicle::enum (unnamed)"
+ "target": "c:@S at Vehicle@E at input.h@64"
},
{
"kind": "memberOf",
"source": "c:@S at Vehicle@E at input.h@64 at Car",
- "target": "c:@S at Vehicle@E at input.h@64",
- "targetFallback": "Vehicle::enum (unnamed)"
+ "target": "c:@S at Vehicle@E at input.h@64"
},
{
"kind": "memberOf",
"source": "c:@S at Vehicle@FI at type",
- "target": "c:@S at Vehicle",
- "targetFallback": "Vehicle"
+ "target": "c:@S at Vehicle"
},
{
"kind": "memberOf",
"source": "c:@S at Vehicle@FI at information",
- "target": "c:@S at Vehicle",
- "targetFallback": "Vehicle"
+ "target": "c:@S at Vehicle"
}
],
"symbols": [
diff --git a/clang/test/ExtractAPI/enum.c b/clang/test/ExtractAPI/enum.c
index 7b345464cb982..07d848082981f 100644
--- a/clang/test/ExtractAPI/enum.c
+++ b/clang/test/ExtractAPI/enum.c
@@ -65,68 +65,57 @@ enum {
{
"kind": "memberOf",
"source": "c:@E at Vehicle@Bicycle",
- "target": "c:@E at Vehicle",
- "targetFallback": "Vehicle"
+ "target": "c:@E at Vehicle"
},
{
"kind": "memberOf",
"source": "c:@E at Vehicle@Car",
- "target": "c:@E at Vehicle",
- "targetFallback": "Vehicle"
+ "target": "c:@E at Vehicle"
},
{
"kind": "memberOf",
"source": "c:@E at Vehicle@Train",
- "target": "c:@E at Vehicle",
- "targetFallback": "Vehicle"
+ "target": "c:@E at Vehicle"
},
{
"kind": "memberOf",
"source": "c:@E at Vehicle@Ship",
- "target": "c:@E at Vehicle",
- "targetFallback": "Vehicle"
+ "target": "c:@E at Vehicle"
},
{
"kind": "memberOf",
"source": "c:@E at Vehicle@Airplane",
- "target": "c:@E at Vehicle",
- "targetFallback": "Vehicle"
+ "target": "c:@E at Vehicle"
},
{
"kind": "memberOf",
"source": "c:@E at Direction@North",
- "target": "c:@E at Direction",
- "targetFallback": "Direction"
+ "target": "c:@E at Direction"
},
{
"kind": "memberOf",
"source": "c:@E at Direction@East",
- "target": "c:@E at Direction",
- "targetFallback": "Direction"
+ "target": "c:@E at Direction"
},
{
"kind": "memberOf",
"source": "c:@E at Direction@South",
- "target": "c:@E at Direction",
- "targetFallback": "Direction"
+ "target": "c:@E at Direction"
},
{
"kind": "memberOf",
"source": "c:@E at Direction@West",
- "target": "c:@E at Direction",
- "targetFallback": "Direction"
+ "target": "c:@E at Direction"
},
{
"kind": "memberOf",
"source": "c:@Ea at Constant@Constant",
- "target": "c:@Ea at Constant",
- "targetFallback": "enum (unnamed)"
+ "target": "c:@Ea at Constant"
},
{
"kind": "memberOf",
"source": "c:@Ea at OtherConstant@OtherConstant",
- "target": "c:@Ea at OtherConstant",
- "targetFallback": "enum (unnamed)"
+ "target": "c:@Ea at OtherConstant"
}
],
"symbols": [
diff --git a/clang/test/ExtractAPI/objc_category.m b/clang/test/ExtractAPI/objc_category.m
index 185016dfe848c..b0bdaaddbdade 100644
--- a/clang/test/ExtractAPI/objc_category.m
+++ b/clang/test/ExtractAPI/objc_category.m
@@ -54,20 +54,17 @@ + (void)ClassMethod;
{
"kind": "memberOf",
"source": "c:objc(cs)Interface(im)InstanceMethod",
- "target": "c:objc(cs)Interface",
- "targetFallback": "Interface"
+ "target": "c:objc(cs)Interface"
},
{
"kind": "memberOf",
"source": "c:objc(cs)Interface(cm)ClassMethod",
- "target": "c:objc(cs)Interface",
- "targetFallback": "Interface"
+ "target": "c:objc(cs)Interface"
},
{
"kind": "memberOf",
"source": "c:objc(cs)Interface(py)Property",
- "target": "c:objc(cs)Interface",
- "targetFallback": "Interface"
+ "target": "c:objc(cs)Interface"
},
{
"kind": "conformsTo",
diff --git a/clang/test/ExtractAPI/objc_interface.m b/clang/test/ExtractAPI/objc_interface.m
index 159e97a193a13..908ee37f85bb2 100644
--- a/clang/test/ExtractAPI/objc_interface.m
+++ b/clang/test/ExtractAPI/objc_interface.m
@@ -57,20 +57,17 @@ - (char)getIvar;
{
"kind": "memberOf",
"source": "c:objc(cs)Super(cm)getWithProperty:",
- "target": "c:objc(cs)Super",
- "targetFallback": "Super"
+ "target": "c:objc(cs)Super"
},
{
"kind": "memberOf",
"source": "c:objc(cs)Super(im)setProperty:andOtherThing:",
- "target": "c:objc(cs)Super",
- "targetFallback": "Super"
+ "target": "c:objc(cs)Super"
},
{
"kind": "memberOf",
"source": "c:objc(cs)Super(py)Property",
- "target": "c:objc(cs)Super",
- "targetFallback": "Super"
+ "target": "c:objc(cs)Super"
},
{
"kind": "conformsTo",
@@ -81,20 +78,17 @@ - (char)getIvar;
{
"kind": "memberOf",
"source": "c:objc(cs)Derived at Ivar",
- "target": "c:objc(cs)Derived",
- "targetFallback": "Derived"
+ "target": "c:objc(cs)Derived"
},
{
"kind": "memberOf",
"source": "c:objc(cs)Derived(im)getIvar",
- "target": "c:objc(cs)Derived",
- "targetFallback": "Derived"
+ "target": "c:objc(cs)Derived"
},
{
"kind": "inheritsFrom",
"source": "c:objc(cs)Derived",
- "target": "c:objc(cs)Super",
- "targetFallback": "Super"
+ "target": "c:objc(cs)Super"
}
],
"symbols": [
diff --git a/clang/test/ExtractAPI/objc_property.m b/clang/test/ExtractAPI/objc_property.m
index f09a5ad724238..1b50950d44243 100644
--- a/clang/test/ExtractAPI/objc_property.m
+++ b/clang/test/ExtractAPI/objc_property.m
@@ -55,44 +55,37 @@ @interface Interface (Category) <Protocol>
{
"kind": "memberOf",
"source": "c:objc(cs)Interface(cpy)myInterfaceTypeProp",
- "target": "c:objc(cs)Interface",
- "targetFallback": "Interface"
+ "target": "c:objc(cs)Interface"
},
{
"kind": "memberOf",
"source": "c:objc(cs)Interface(py)myInterfaceInstanceProp",
- "target": "c:objc(cs)Interface",
- "targetFallback": "Interface"
+ "target": "c:objc(cs)Interface"
},
{
"kind": "memberOf",
"source": "c:objc(cs)Interface(cpy)myCategoryTypeProp",
- "target": "c:objc(cs)Interface",
- "targetFallback": "Interface"
+ "target": "c:objc(cs)Interface"
},
{
"kind": "memberOf",
"source": "c:objc(cs)Interface(py)myCategoryInstanceProp",
- "target": "c:objc(cs)Interface",
- "targetFallback": "Interface"
+ "target": "c:objc(cs)Interface"
},
{
"kind": "conformsTo",
"source": "c:objc(cs)Interface",
- "target": "c:objc(pl)Protocol",
- "targetFallback": "Protocol"
+ "target": "c:objc(pl)Protocol"
},
{
"kind": "memberOf",
"source": "c:objc(pl)Protocol(cpy)myProtocolTypeProp",
- "target": "c:objc(pl)Protocol",
- "targetFallback": "Protocol"
+ "target": "c:objc(pl)Protocol"
},
{
"kind": "memberOf",
"source": "c:objc(pl)Protocol(py)myProtocolInstanceProp",
- "target": "c:objc(pl)Protocol",
- "targetFallback": "Protocol"
+ "target": "c:objc(pl)Protocol"
}
],
"symbols": [
diff --git a/clang/test/ExtractAPI/objc_protocol.m b/clang/test/ExtractAPI/objc_protocol.m
index d9a65f419df89..036850924587c 100644
--- a/clang/test/ExtractAPI/objc_protocol.m
+++ b/clang/test/ExtractAPI/objc_protocol.m
@@ -49,8 +49,7 @@ @protocol AnotherProtocol <Protocol>
{
"kind": "conformsTo",
"source": "c:objc(pl)AnotherProtocol",
- "target": "c:objc(pl)Protocol",
- "targetFallback": "Protocol"
+ "target": "c:objc(pl)Protocol"
}
],
"symbols": [
diff --git a/clang/test/ExtractAPI/struct.c b/clang/test/ExtractAPI/struct.c
index 7e93f0d7e7bfa..516055768749c 100644
--- a/clang/test/ExtractAPI/struct.c
+++ b/clang/test/ExtractAPI/struct.c
@@ -52,26 +52,22 @@ struct Color {
{
"kind": "memberOf",
"source": "c:@S at Color@FI at Red",
- "target": "c:@S at Color",
- "targetFallback": "Color"
+ "target": "c:@S at Color"
},
{
"kind": "memberOf",
"source": "c:@S at Color@FI at Green",
- "target": "c:@S at Color",
- "targetFallback": "Color"
+ "target": "c:@S at Color"
},
{
"kind": "memberOf",
"source": "c:@S at Color@FI at Blue",
- "target": "c:@S at Color",
- "targetFallback": "Color"
+ "target": "c:@S at Color"
},
{
"kind": "memberOf",
"source": "c:@S at Color@FI at Alpha",
- "target": "c:@S at Color",
- "targetFallback": "Color"
+ "target": "c:@S at Color"
}
],
"symbols": [
diff --git a/clang/test/ExtractAPI/underscored.c b/clang/test/ExtractAPI/underscored.c
index 6eeaf1ce412c3..47f1893cdb029 100644
--- a/clang/test/ExtractAPI/underscored.c
+++ b/clang/test/ExtractAPI/underscored.c
@@ -65,8 +65,7 @@ typedef _HiddenTypedef ExposedTypedefToHidden;
{
"kind": "memberOf",
"source": "c:@S at ExposedRecord@FI at a",
- "target": "c:@S at ExposedRecord",
- "targetFallback": "ExposedRecord"
+ "target": "c:@S at ExposedRecord"
}
],
"symbols": [
More information about the cfe-commits
mailing list