[clang] 1cfe1e7 - [clang][ExtractAPI] Add queried symbol to parent contexts in libclang
Daniel Grumberg via cfe-commits
cfe-commits at lists.llvm.org
Wed Mar 29 08:32:42 PDT 2023
Author: Daniel Grumberg
Date: 2023-03-29T16:32:26+01:00
New Revision: 1cfe1e732ad8e8148f6fa8fc0f0c86f4b965d567
URL: https://github.com/llvm/llvm-project/commit/1cfe1e732ad8e8148f6fa8fc0f0c86f4b965d567
DIFF: https://github.com/llvm/llvm-project/commit/1cfe1e732ad8e8148f6fa8fc0f0c86f4b965d567.diff
LOG: [clang][ExtractAPI] Add queried symbol to parent contexts in libclang
Ensure that the current symbol is added to the parent contexts in the
output of libclang function for generating symbol graphs for single symbols.
Differential Revision: https://reviews.llvm.org/D147138
Added:
Modified:
clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
clang/test/Index/extract-api-cursor.m
clang/test/Index/extract-api-usr.m
Removed:
################################################################################
diff --git a/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp b/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
index 8a98f5cf0c71f..7676c74af6869 100644
--- a/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
+++ b/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
@@ -547,10 +547,6 @@ Array generateParentContexts(const RecordTy &Record, const APISet &API,
serializeParentContext(PC, Lang));
});
- // The last component would be the record itself so let's remove it.
- if (!ParentContexts.empty())
- ParentContexts.pop_back();
-
return ParentContexts;
}
diff --git a/clang/test/Index/extract-api-cursor.m b/clang/test/Index/extract-api-cursor.m
index 16844ca1674ee..1b27b6f61437b 100644
--- a/clang/test/Index/extract-api-cursor.m
+++ b/clang/test/Index/extract-api-cursor.m
@@ -34,7 +34,7 @@ - (void)derivedMethodWithValue:(id<Protocol>)value {
@end
// RUN: c-index-test -single-symbol-sgf-at=%s:4:9 local %s | FileCheck -check-prefix=CHECK-FOO %s
-// CHECK-FOO: "parentContexts":[]
+// CHECK-FOO: "parentContexts":[{"kind":"objective-c.struct","name":"Foo","usr":"c:@S at Foo"}]
// CHECK-FOO: "relatedSymbols":[]
// CHECK-FOO: "relationships":[]
// CHECK-FOO: "text":"Foo docs"
@@ -42,7 +42,7 @@ - (void)derivedMethodWithValue:(id<Protocol>)value {
// CHECK-FOO: "title":"Foo"
// RUN: c-index-test -single-symbol-sgf-at=%s:6:9 local %s | FileCheck -check-prefix=CHECK-BAR %s
-// CHECK-BAR: "parentContexts":[{"kind":"objective-c.struct","name":"Foo","usr":"c:@S at Foo"}]
+// CHECK-BAR: "parentContexts":[{"kind":"objective-c.struct","name":"Foo","usr":"c:@S at Foo"},{"kind":"objective-c.property","name":"bar","usr":"c:@S at Foo@FI at bar"}]
// CHECK-BAR: "relatedSymbols":[]
// CHECK-BAR: "relationships":[{"kind":"memberOf","source":"c:@S at Foo@FI at bar","target":"c:@S at Foo"
// CHECK-BAR: "text":"Bar docs"
@@ -50,7 +50,7 @@ - (void)derivedMethodWithValue:(id<Protocol>)value {
// CHECK-BAR: "title":"bar"
// RUN: c-index-test -single-symbol-sgf-at=%s:10:11 local %s | FileCheck -check-prefix=CHECK-BASE %s
-// CHECK-BASE: "parentContexts":[]
+// CHECK-BASE: "parentContexts":[{"kind":"objective-c.class","name":"Base","usr":"c:objc(cs)Base"}]
// CHECK-BASE: "relatedSymbols":[]
// CHECK-BASE: "relationships":[]
// CHECK-BASE: "text":"Base docs"
@@ -58,7 +58,7 @@ - (void)derivedMethodWithValue:(id<Protocol>)value {
// CHECK-BASE: "title":"Base"
// RUN: c-index-test -single-symbol-sgf-at=%s:12:25 local %s | FileCheck -check-prefix=CHECK-BASE-PROP %s
-// CHECK-BASE-PROP: "parentContexts":[{"kind":"objective-c.class","name":"Base","usr":"c:objc(cs)Base"}]
+// CHECK-BASE-PROP: "parentContexts":[{"kind":"objective-c.class","name":"Base","usr":"c:objc(cs)Base"},{"kind":"objective-c.property","name":"baseProperty","usr":"c:objc(cs)Base(py)baseProperty"}]
// CHECK-BASE-PROP: "relatedSymbols":[{"accessLevel":"public","declarationLanguage":"objective-c"
// CHECK-BASE-PROP: "isSystem":false
// CHECK-BASE-PROP: "usr":"c:@S at Foo"}]
@@ -68,7 +68,7 @@ - (void)derivedMethodWithValue:(id<Protocol>)value {
// CHECK-BASE-PROP: "title":"baseProperty"
// RUN: c-index-test -single-symbol-sgf-at=%s:15:9 local %s | FileCheck -check-prefix=CHECK-BASE-METHOD %s
-// CHECK-BASE-METHOD: "parentContexts":[{"kind":"objective-c.class","name":"Base","usr":"c:objc(cs)Base"}]
+// CHECK-BASE-METHOD: "parentContexts":[{"kind":"objective-c.class","name":"Base","usr":"c:objc(cs)Base"},{"kind":"objective-c.method","name":"baseMethodWithArg:","usr":"c:objc(cs)Base(im)baseMethodWithArg:"}]
// CHECK-BASE-METHOD: "relatedSymbols":[]
// CHECK-BASE-METHOD: "relationships":[{"kind":"memberOf","source":"c:objc(cs)Base(im)baseMethodWithArg:","target":"c:objc(cs)Base"
// CHECK-BASE-METHOD: "text":"Base method docs"
@@ -76,7 +76,7 @@ - (void)derivedMethodWithValue:(id<Protocol>)value {
// CHECK-BASE-METHOD: "title":"baseMethodWithArg:"
// RUN: c-index-test -single-symbol-sgf-at=%s:19:11 local %s | FileCheck -check-prefix=CHECK-PROTOCOL %s
-// CHECK-PROTOCOL: "parentContexts":[]
+// CHECK-PROTOCOL: "parentContexts":[{"kind":"objective-c.protocol","name":"Protocol","usr":"c:objc(pl)Protocol"}]
// CHECK-PROTOCOL: "relatedSymbols":[]
// CHECK-PROTOCOL: "relationships":[]
// CHECK-PROTOCOL: "text":"Protocol docs"
@@ -84,7 +84,7 @@ - (void)derivedMethodWithValue:(id<Protocol>)value {
// CHECK-PROTOCOL: "title":"Protocol"
// RUN: c-index-test -single-symbol-sgf-at=%s:21:27 local %s | FileCheck -check-prefix=CHECK-PROTOCOL-PROP %s
-// CHECK-PROTOCOL-PROP: "parentContexts":[{"kind":"objective-c.protocol","name":"Protocol","usr":"c:objc(pl)Protocol"}]
+// CHECK-PROTOCOL-PROP: "parentContexts":[{"kind":"objective-c.protocol","name":"Protocol","usr":"c:objc(pl)Protocol"},{"kind":"objective-c.property","name":"protocolProperty","usr":"c:objc(pl)Protocol(py)protocolProperty"}]
// CHECK-PROTOCOL-PROP: "relatedSymbols":[{"accessLevel":"public","declarationLanguage":"objective-c"
// CHECK-PROTOCOL-PROP: "isSystem":false
// CHECK-PROTOCOL-PROP: "usr":"c:@S at Foo"}]
@@ -94,7 +94,7 @@ - (void)derivedMethodWithValue:(id<Protocol>)value {
// CHECK-PROTOCOL-PROP: "title":"protocolProperty"
// RUN: c-index-test -single-symbol-sgf-at=%s:25:15 local %s | FileCheck -check-prefix=CHECK-DERIVED %s
-// CHECK-DERIVED: "parentContexts":[]
+// CHECK-DERIVED: "parentContexts":[{"kind":"objective-c.class","name":"Derived","usr":"c:objc(cs)Derived"}]
// CHECK-DERIVED: "relatedSymbols":[{"accessLevel":"public","declarationLanguage":"objective-c"
// CHECK-DERIVED: "isSystem":false
// CHECK-DERIVED: "usr":"c:objc(cs)Base"}]
@@ -104,7 +104,7 @@ - (void)derivedMethodWithValue:(id<Protocol>)value {
// CHECK-DERIVED: "title":"Derived"
// RUN: c-index-test -single-symbol-sgf-at=%s:27:11 local %s | FileCheck -check-prefix=CHECK-DERIVED-METHOD %s
-// CHECK-DERIVED-METHOD: "parentContexts":[{"kind":"objective-c.class","name":"Derived","usr":"c:objc(cs)Derived"}]
+// CHECK-DERIVED-METHOD: "parentContexts":[{"kind":"objective-c.class","name":"Derived","usr":"c:objc(cs)Derived"},{"kind":"objective-c.method","name":"derivedMethodWithValue:","usr":"c:objc(cs)Derived(im)derivedMethodWithValue:"}]
// CHECK-DERIVED-METHOD: "relatedSymbols":[]
// CHECK-DERIVED-METHOD: "relationships":[{"kind":"memberOf","source":"c:objc(cs)Derived(im)derivedMethodWithValue:","target":"c:objc(cs)Derived"
// CHECK-DERIVED-METHOD: "text":"Derived method docs"
@@ -112,7 +112,7 @@ - (void)derivedMethodWithValue:(id<Protocol>)value {
// CHECK-DERIVED-METHOD: "title":"derivedMethodWithValue:"
// RUN: c-index-test -single-symbol-sgf-at=%s:31:11 local %s | FileCheck -check-prefix=CHECK-DERIVED-METHOD-IMPL %s
-// CHECK-DERIVED-METHOD-IMPL: "parentContexts":[{"kind":"objective-c.class","name":"Derived","usr":"c:objc(cs)Derived"}]
+// CHECK-DERIVED-METHOD-IMPL: "parentContexts":[{"kind":"objective-c.class","name":"Derived","usr":"c:objc(cs)Derived"},{"kind":"objective-c.method","name":"derivedMethodWithValue:","usr":"c:objc(cs)Derived(im)derivedMethodWithValue:"}]
// CHECK-DERIVED-METHOD-IMPL: "relatedSymbols":[]
// CHECK-DERIVED-METHOD-IMPL: "relationships":[{"kind":"memberOf","source":"c:objc(cs)Derived(im)derivedMethodWithValue:","target":"c:objc(cs)Derived"
// CHECK-DERIVED-METHOD-IMPL: "text":"Derived method docs"
diff --git a/clang/test/Index/extract-api-usr.m b/clang/test/Index/extract-api-usr.m
index 12bfb0a676e66..0b468ee916708 100644
--- a/clang/test/Index/extract-api-usr.m
+++ b/clang/test/Index/extract-api-usr.m
@@ -28,7 +28,7 @@ - (void)derivedMethodWithValue:(id<Protocol>)value;
// Checking for Foo
// RUN: c-index-test "-single-symbol-sgf-for=c:@S at Foo" %s | FileCheck -check-prefix=CHECK-FOO %s
-// CHECK-FOO: "parentContexts":[]
+// CHECK-FOO: "parentContexts":[{"kind":"objective-c.struct","name":"Foo","usr":"c:@S at Foo"}]
// CHECK-FOO-SAME: "relatedSymbols":[]
// CHECK-FOO-SAME: "relationships":[]
// CHECK-FOO-SAME: "text":"Foo docs"
@@ -38,7 +38,7 @@ - (void)derivedMethodWithValue:(id<Protocol>)value;
// Checking for bar
// RUN: c-index-test "-single-symbol-sgf-for=c:@S at Foo@FI at bar" %s | FileCheck -check-prefix=CHECK-BAR %s
-// CHECK-BAR: "parentContexts":[{"kind":"objective-c.struct","name":"Foo","usr":"c:@S at Foo"}]
+// CHECK-BAR: "parentContexts":[{"kind":"objective-c.struct","name":"Foo","usr":"c:@S at Foo"},{"kind":"objective-c.property","name":"bar","usr":"c:@S at Foo@FI at bar"}]
// CHECK-BAR-SAME: "relatedSymbols":[]
// CHECK-BAR-SAME: "relationships":[{"kind":"memberOf","source":"c:@S at Foo@FI at bar","target":"c:@S at Foo"
// CHECK-BAR-SAME: "text":"Bar docs"
@@ -47,7 +47,7 @@ - (void)derivedMethodWithValue:(id<Protocol>)value;
// Checking for Base
// RUN: c-index-test "-single-symbol-sgf-for=c:objc(cs)Base" %s | FileCheck -check-prefix=CHECK-BASE %s
-// CHECK-BASE: "parentContexts":[]
+// CHECK-BASE: "parentContexts":[{"kind":"objective-c.class","name":"Base","usr":"c:objc(cs)Base"}]
// CHECK-BASE-SAME: "relatedSymbols":[]
// CHECK-BASE-SAME: "relationships":[]
// CHECK-BASE-SAME: "text":"Base docs"
@@ -56,7 +56,7 @@ - (void)derivedMethodWithValue:(id<Protocol>)value;
// Checking for baseProperty
// RUN: c-index-test "-single-symbol-sgf-for=c:objc(cs)Base(py)baseProperty" %s | FileCheck -check-prefix=CHECK-BASEPROP %s
-// CHECK-BASEPROP: "parentContexts":[{"kind":"objective-c.class","name":"Base","usr":"c:objc(cs)Base"}]
+// CHECK-BASEPROP: "parentContexts":[{"kind":"objective-c.class","name":"Base","usr":"c:objc(cs)Base"},{"kind":"objective-c.property","name":"baseProperty","usr":"c:objc(cs)Base(py)baseProperty"}]
// CHECK-BASEPROP-SAME:"relatedSymbols":[{"accessLevel":"public","declarationLanguage":"objective-c"
// CHECK-BASEPROP-SAME: "isSystem":false
// CHECK-BASEPROP-SAME: "usr":"c:@S at Foo"}]
@@ -67,7 +67,7 @@ - (void)derivedMethodWithValue:(id<Protocol>)value;
// Checking for baseMethodWithArg
// RUN: c-index-test "-single-symbol-sgf-for=c:objc(cs)Base(im)baseMethodWithArg:" %s | FileCheck -check-prefix=CHECK-BASEMETHOD %s
-// CHECK-BASEMETHOD: "parentContexts":[{"kind":"objective-c.class","name":"Base","usr":"c:objc(cs)Base"}]
+// CHECK-BASEMETHOD: "parentContexts":[{"kind":"objective-c.class","name":"Base","usr":"c:objc(cs)Base"},{"kind":"objective-c.method","name":"baseMethodWithArg:","usr":"c:objc(cs)Base(im)baseMethodWithArg:"}]
// CHECK-BASEMETHOD-SAME:"relatedSymbols":[]
// CHECK-BASEMETHOD-SAME: "relationships":[{"kind":"memberOf","source":"c:objc(cs)Base(im)baseMethodWithArg:","target":"c:objc(cs)Base"
// CHECK-BASEMETHOD-SAME: "text":"Base method docs"
@@ -76,7 +76,7 @@ - (void)derivedMethodWithValue:(id<Protocol>)value;
// Checking for Protocol
// RUN: c-index-test "-single-symbol-sgf-for=c:objc(pl)Protocol" %s | FileCheck -check-prefix=CHECK-PROT %s
-// CHECK-PROT: "parentContexts":[]
+// CHECK-PROT: "parentContexts":[{"kind":"objective-c.protocol","name":"Protocol","usr":"c:objc(pl)Protocol"}]
// CHECK-PROT-SAME: "relatedSymbols":[]
// CHECK-PROT-SAME: "relationships":[]
// CHECK-PROT-SAME: "text":"Protocol docs"
@@ -85,7 +85,7 @@ - (void)derivedMethodWithValue:(id<Protocol>)value;
// Checking for protocolProperty
// RUN: c-index-test "-single-symbol-sgf-for=c:objc(pl)Protocol(py)protocolProperty" %s | FileCheck -check-prefix=CHECK-PROTPROP %s
-// CHECK-PROTPROP: "parentContexts":[{"kind":"objective-c.protocol","name":"Protocol","usr":"c:objc(pl)Protocol"}]
+// CHECK-PROTPROP: "parentContexts":[{"kind":"objective-c.protocol","name":"Protocol","usr":"c:objc(pl)Protocol"},{"kind":"objective-c.property","name":"protocolProperty","usr":"c:objc(pl)Protocol(py)protocolProperty"}]
// CHECK-PROTPROP-SAME:"relatedSymbols":[{"accessLevel":"public","declarationLanguage":"objective-c"
// CHECK-PROTPROP-SAME: "isSystem":false
// CHECK-PROTPROP-SAME: "usr":"c:@S at Foo"}]
@@ -96,7 +96,7 @@ - (void)derivedMethodWithValue:(id<Protocol>)value;
// Checking for Derived
// RUN: c-index-test "-single-symbol-sgf-for=c:objc(cs)Derived" %s | FileCheck -check-prefix=CHECK-DERIVED %s
-// CHECK-DERIVED: "parentContexts":[]
+// CHECK-DERIVED: "parentContexts":[{"kind":"objective-c.class","name":"Derived","usr":"c:objc(cs)Derived"}]
// CHECK-DERIVED-SAME:"relatedSymbols":[{"accessLevel":"public","declarationLanguage":"objective-c"
// CHECK-DERIVED-SAME: "isSystem":false
// CHECK-DERIVED-SAME: "usr":"c:objc(cs)Base"}]
@@ -107,7 +107,7 @@ - (void)derivedMethodWithValue:(id<Protocol>)value;
// Checking for derivedMethodWithValue
// RUN: c-index-test "-single-symbol-sgf-for=c:objc(cs)Derived(im)derivedMethodWithValue:" %s | FileCheck -check-prefix=CHECK-DERIVEDMETHOD %s
-// CHECK-DERIVEDMETHOD: "parentContexts":[{"kind":"objective-c.class","name":"Derived","usr":"c:objc(cs)Derived"}]
+// CHECK-DERIVEDMETHOD: "parentContexts":[{"kind":"objective-c.class","name":"Derived","usr":"c:objc(cs)Derived"},{"kind":"objective-c.method","name":"derivedMethodWithValue:","usr":"c:objc(cs)Derived(im)derivedMethodWithValue:"}]
// CHECK-DERIVEDMETHOD-SAME:"relatedSymbols":[]
// CHECK-DERIVEDMETHOD-SAME: "relationships":[{"kind":"memberOf","source":"c:objc(cs)Derived(im)derivedMethodWithValue:","target":"c:objc(cs)Derived"
// CHECK-DERIVEDMETHOD-SAME: "text":"Derived method docs"
More information about the cfe-commits
mailing list