Skip to content

Commit e7a1d27

Browse files
Address review feedback
1 parent 07d1809 commit e7a1d27

19 files changed

+87
-51
lines changed

clang/include/clang/ExtractAPI/API.h

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,8 @@ struct APIRecord {
195195
RK_Unknown,
196196
// If adding a record context record kind here make sure to update
197197
// RecordContext::classof if needed and add a RECORD_CONTEXT entry to
198-
// APIRecords.inc RecordContext Kinds start
198+
// APIRecords.inc
199+
RK_FirstRecordContext,
199200
RK_Namespace,
200201
RK_Enum,
201202
RK_Struct,
@@ -207,7 +208,7 @@ struct APIRecord {
207208
RK_ClassTemplate,
208209
RK_ClassTemplateSpecialization,
209210
RK_ClassTemplatePartialSpecialization,
210-
// RecordContexts Kinds end
211+
RK_LastRecordContext,
211212
RK_GlobalFunction,
212213
RK_GlobalFunctionTemplate,
213214
RK_GlobalFunctionTemplateSpecialization,
@@ -270,10 +271,10 @@ struct APIRecord {
270271
friend class RecordContext;
271272
// Used to store the next child record in RecordContext. This works because
272273
// APIRecords semantically only have one parent.
273-
mutable APIRecord *NextInContex = nullptr;
274+
mutable APIRecord *NextInContext = nullptr;
274275

275276
public:
276-
APIRecord *getNextInContex() const { return NextInContex; }
277+
APIRecord *getNextInContext() const { return NextInContext; }
277278

278279
RecordKind getKind() const { return Kind; }
279280

@@ -312,8 +313,8 @@ class RecordContext {
312313
return classofKind(Record->getKind());
313314
}
314315
static bool classofKind(APIRecord::RecordKind K) {
315-
return K >= APIRecord::RK_Namespace &&
316-
K <= APIRecord::RK_ClassTemplatePartialSpecialization;
316+
return K > APIRecord::RK_FirstRecordContext &&
317+
K < APIRecord::RK_LastRecordContext;
317318
}
318319

319320
static bool classof(const RecordContext *Context) { return true; }
@@ -339,7 +340,8 @@ class RecordContext {
339340
// This doesn't strictly meet the iterator requirements, but it's the
340341
// behavior we want here.
341342
value_type operator->() const { return Current; }
342-
record_iterator &operator++() { Current = Current->getNextInContex();
343+
record_iterator &operator++() {
344+
Current = Current->getNextInContext();
343345
return *this;
344346
}
345347
record_iterator operator++(int) {
@@ -1421,8 +1423,8 @@ APISet::createRecord(StringRef USR, StringRef Name,
14211423

14221424
// Create the record if it does not already exist
14231425
if (Result.second) {
1424-
Record = new (Allocator) RecordTy(USRString, copyString(Name),
1425-
std::forward<CtorArgsContTy>(CtorArgs)...);
1426+
Record = new (Allocator) RecordTy(
1427+
USRString, copyString(Name), std::forward<CtorArgsContTy>(CtorArgs)...);
14261428
// Store the record in the record lookup map
14271429
Result.first->second = APIRecordStoredPtr(Record);
14281430

clang/include/clang/ExtractAPI/ExtractAPIVisitor.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -631,8 +631,8 @@ bool ExtractAPIVisitorBase<Derived>::VisitCXXMethodDecl(
631631
auto Access = DeclarationFragmentsBuilder::getAccessControl(Decl);
632632
auto Signature = DeclarationFragmentsBuilder::getFunctionSignature(Decl);
633633

634-
if (Decl->isTemplated()) {
635-
FunctionTemplateDecl *TemplateDecl = Decl->getDescribedFunctionTemplate();
634+
if (FunctionTemplateDecl *TemplateDecl =
635+
Decl->getDescribedFunctionTemplate()) {
636636
API.createRecord<CXXMethodTemplateRecord>(
637637
USR, Decl->getName(), createHierarchyInformationForDecl(*Decl), Loc,
638638
AvailabilityInfo::createFromDecl(Decl), Comment,
@@ -697,7 +697,7 @@ bool ExtractAPIVisitorBase<Derived>::VisitCXXConstructorDecl(
697697
DeclarationFragmentsBuilder::getFunctionSignature(Decl);
698698
AccessControl Access = DeclarationFragmentsBuilder::getAccessControl(Decl);
699699

700-
API.createRecord<CXXInstanceMethodRecord>(
700+
API.createRecord<CXXConstructorRecord>(
701701
USR, Name, createHierarchyInformationForDecl(*Decl), Loc,
702702
AvailabilityInfo::createFromDecl(Decl), Comment, Declaration, SubHeading,
703703
Signature, Access, isInSystemHeader(Decl));
@@ -730,7 +730,7 @@ bool ExtractAPIVisitorBase<Derived>::VisitCXXDestructorDecl(
730730
FunctionSignature Signature =
731731
DeclarationFragmentsBuilder::getFunctionSignature(Decl);
732732
AccessControl Access = DeclarationFragmentsBuilder::getAccessControl(Decl);
733-
API.createRecord<CXXInstanceMethodRecord>(
733+
API.createRecord<CXXDestructorRecord>(
734734
USR, Name, createHierarchyInformationForDecl(*Decl), Loc,
735735
AvailabilityInfo::createFromDecl(Decl), Comment, Declaration, SubHeading,
736736
Signature, Access, isInSystemHeader(Decl));
@@ -1247,6 +1247,10 @@ bool ExtractAPIVisitorBase<Derived>::VisitFieldDecl(const FieldDecl *Decl) {
12471247
template <typename Derived>
12481248
bool ExtractAPIVisitorBase<Derived>::VisitCXXConversionDecl(
12491249
const CXXConversionDecl *Decl) {
1250+
if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(Decl) ||
1251+
Decl->isImplicit())
1252+
return true;
1253+
12501254
auto Name = Decl->getNameAsString();
12511255
SmallString<128> USR;
12521256
index::generateUSRForDecl(Decl, USR);

clang/include/clang/ExtractAPI/Serialization/APISetVisitor.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ namespace extractapi {
3636
/// 2. at a given record, walk up the class hierarchy starting from the record's
3737
/// dynamic type until APIRecord is reached.
3838
/// 3. given a (record, class) combination where 'class' is some base class of
39-
/// the dynamic type of 'node', call a user-overridable function to actually
39+
/// the dynamic type of 'record', call a user-overridable function to actually
4040
/// visit the record.
4141
///
4242
/// These tasks are done by three groups of methods, respectively:
@@ -62,8 +62,8 @@ namespace extractapi {
6262
/// visitObjCInstancePropertyRecord()).
6363
///
6464
/// This scheme guarantees that all visit*() calls for the same record
65-
/// are grouped together. In other words, visit*() methods for different nodes
66-
/// are never interleaved.
65+
/// are grouped together. In other words, visit*() methods for different
66+
/// records are never interleaved.
6767
///
6868
/// Clients of this visitor should subclass the visitor (providing
6969
/// themselves as the template argument, using the curiously recurring
@@ -156,10 +156,13 @@ bool APISetVisitor<Derived>::traverseAPIRecord(const APIRecord *Record) {
156156
break; \
157157
}
158158
#include "../APIRecords.inc"
159-
case APIRecord::RK_Unknown:
159+
case APIRecord::RK_Unknown: {
160160
TRY_TO(walkUpFromAPIRecord(static_cast<const APIRecord *>(Record)));
161161
break;
162162
}
163+
default:
164+
llvm_unreachable("API Record with uninstantiable kind");
165+
}
163166
return true;
164167
}
165168

clang/lib/ExtractAPI/API.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ void RecordContext::addToRecordChain(APIRecord *Record) const {
6161
return;
6262
}
6363

64-
Last->NextInContex = Record;
64+
Last->NextInContext = Record;
6565
Last = Record;
6666
}
6767

clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,8 @@ Object serializeSymbolKind(APIRecord::RecordKind RK, Language Lang) {
499499
Kind["identifier"] = AddLangPrefix("typealias");
500500
Kind["displayName"] = "Type Alias";
501501
break;
502+
default:
503+
llvm_unreachable("API Record with uninstantiable kind");
502504
}
503505

504506
return Kind;
@@ -763,7 +765,7 @@ void SymbolGraphSerializer::serializeAPIRecord(const APIRecord *Record) {
763765
Obj["accessLevel"] = Record->Access.getAccess();
764766

765767
ExtendedModule &Module = getModuleForCurrentSymbol();
766-
// If the hierarchy has at leas one parent and child.
768+
// If the hierarchy has at least one parent and child.
767769
if (Hierarchy.size() >= 2)
768770
serializeRelationship(MemberOf, Hierarchy.back(),
769771
Hierarchy[Hierarchy.size() - 2], Module);
@@ -998,6 +1000,8 @@ void SymbolGraphSerializer::serializeSingleRecord(const APIRecord *Record) {
9981000
case APIRecord::RK_Unknown:
9991001
visitAPIRecord(Record);
10001002
break;
1003+
default:
1004+
llvm_unreachable("API Record with uninstantiable kind");
10011005
}
10021006
}
10031007

clang/lib/ExtractAPI/TypedefUnderlyingTypeResolver.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ TypedefUnderlyingTypeResolver::getSymbolReferenceForType(QualType Type,
5959

6060
clang::index::generateUSRForDecl(TypeDecl, TypeUSR);
6161
if (auto *OwningModule = TypeDecl->getImportedOwningModule())
62-
OwningModuleName = API.copyString(OwningModule->Name);
62+
OwningModuleName = OwningModule->Name;
6363
} else {
6464
clang::index::generateUSRForType(Type, Context, TypeUSR);
6565
}
6666

67-
return {API.copyString(TypeName), API.copyString(TypeUSR), OwningModuleName};
67+
return API.createSymbolReference(TypeName, TypeUSR, OwningModuleName);
6868
}
6969

7070
std::string TypedefUnderlyingTypeResolver::getUSRForType(QualType Type) const {

clang/test/ExtractAPI/constructor_destructor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ class Foo {
137137
"precise": "c:@S@Foo@F@Foo#"
138138
},
139139
"kind": {
140-
"displayName": "Instance Method",
140+
"displayName": "Constructor",
141141
"identifier": "c++.method"
142142
},
143143
"location": {
@@ -193,7 +193,7 @@ class Foo {
193193
"precise": "c:@S@Foo@F@~Foo#"
194194
},
195195
"kind": {
196-
"displayName": "Instance Method",
196+
"displayName": "Destructor",
197197
"identifier": "c++.method"
198198
},
199199
"location": {

clang/test/ExtractAPI/metadata_and_module.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// RUN: rm -rf %t
22
// RUN: %clang_cc1 -extract-api --pretty-sgf --product-name=module -triple arm64-apple-macosx -x c-header %s -o %t/module.symbols.json -verify
33

4-
// RUN: Filecheck %s --input-file %t/module.symbols.json --check-prefix METADATA
5-
// RUN: Filecheck %s --input-file %t/module.symbols.json --check-prefix MOD
4+
// RUN: FileCheck %s --input-file %t/module.symbols.json --check-prefix METADATA
5+
// RUN: FileCheck %s --input-file %t/module.symbols.json --check-prefix MOD
66

77
// expected-no-diagnostics
88

clang/test/ExtractAPI/objc_block.m

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// RUN: -fblocks -triple arm64-apple-macosx -x objective-c-header %s -o %t/output.symbols.json -verify
44

55
@interface Foo
6-
// RUN: Filecheck %s --input-file %t/output.symbols.json --check-prefix NOPARAM
6+
// RUN: FileCheck %s --input-file %t/output.symbols.json --check-prefix NOPARAM
77
-(void)methodBlockNoParam:(void (^)())block;
88
// NOPARAM-LABEL: "!testLabel": "c:objc(cs)Foo(im)methodBlockNoParam:"
99
// NOPARAM: "declarationFragments": [
@@ -88,7 +88,7 @@ -(void)methodBlockNoParam:(void (^)())block;
8888
// NOPARAM-NEXT: ]
8989
// NOPARAM-NEXT: }
9090

91-
// RUN: Filecheck %s --input-file %t/output.symbols.json --check-prefix PARAM
91+
// RUN: FileCheck %s --input-file %t/output.symbols.json --check-prefix PARAM
9292
-(void)methodBlockWithParam:(int (^)(int foo))block;
9393
// PARAM-LABEL: "!testLabel": "c:objc(cs)Foo(im)methodBlockWithParam:"
9494
// PARAM: "declarationFragments": [
@@ -207,7 +207,7 @@ -(void)methodBlockWithParam:(int (^)(int foo))block;
207207
// PARAM-NEXT: ]
208208
// PARAM-NEXT: }
209209

210-
// RUN: Filecheck %s --input-file %t/output.symbols.json --check-prefix MULTIPARAM
210+
// RUN: FileCheck %s --input-file %t/output.symbols.json --check-prefix MULTIPARAM
211211
-(void)methodBlockWithMultipleParam:(int (^)(int foo, unsigned baz))block;
212212
// MULTIPARAM-LABEL: "!testLabel": "c:objc(cs)Foo(im)methodBlockWithMultipleParam:"
213213
// MULTIPARAM: "declarationFragments": [
@@ -360,7 +360,7 @@ -(void)methodBlockWithMultipleParam:(int (^)(int foo, unsigned baz))block;
360360
// MULTIPARAM-NEXT: ]
361361
// MULTIPARAM-NEXT: },
362362

363-
// RUN: Filecheck %s --input-file %t/output.symbols.json --check-prefix VARIADIC
363+
// RUN: FileCheck %s --input-file %t/output.symbols.json --check-prefix VARIADIC
364364
-(void)methodBlockVariadic:(int (^)(int foo, ...))block;
365365
// VARIADIC-LABEL: "!testLabel": "c:objc(cs)Foo(im)methodBlockVariadic:"
366366
// VARIADIC: "declarationFragments": [
@@ -480,7 +480,7 @@ -(void)methodBlockVariadic:(int (^)(int foo, ...))block;
480480
// VARIADIC-NEXT: },
481481
@end
482482

483-
// RUN: Filecheck %s --input-file %t/output.symbols.json --check-prefix FUNC
483+
// RUN: FileCheck %s --input-file %t/output.symbols.json --check-prefix FUNC
484484
void func(int (^arg)(int foo));
485485
// FUNC-LABEL: "!testLabel": "c:@F@func"
486486
// FUNC: "declarationFragments": [
@@ -587,7 +587,7 @@ -(void)methodBlockVariadic:(int (^)(int foo, ...))block;
587587
// FUNC-NEXT: ]
588588
// FUNC-NEXT: },
589589

590-
// RUN: Filecheck %s --input-file %t/output.symbols.json --check-prefix GLOBAL
590+
// RUN: FileCheck %s --input-file %t/output.symbols.json --check-prefix GLOBAL
591591
int (^global)(int foo);
592592
// GLOBAL-LABEL: "!testLabel": "c:@global"
593593
// GLOBAL: "declarationFragments": [

clang/test/ExtractAPI/objc_category.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: rm -rf %t
22
// RUN: %clang_cc1 -extract-api --pretty-sgf --emit-sgf-symbol-labels-for-testing \
3-
// RUN: -triple arm64-apple-macosx -x objective-c-header %s -o - -verify | Filecheck %s
3+
// RUN: -triple arm64-apple-macosx -x objective-c-header %s -o - -verify | FileCheck %s
44

55
@protocol Protocol
66
@end

clang/test/ExtractAPI/objc_external_category.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ @interface ExtInterface
2828
header "ExternalModule.h"
2929
}
3030

31-
// RUN: Filecheck %s --input-file %t/symbols/Module.symbols.json --check-prefix MOD
31+
// RUN: FileCheck %s --input-file %t/symbols/Module.symbols.json --check-prefix MOD
3232
// MOD-NOT: "!testRelLabel": "memberOf $ c:objc(cs)ExtInterface(py)Property $ c:objc(cs)ExtInterface"
3333
// MOD-NOT: "!testRelLabel": "memberOf $ c:objc(cs)ExtInterface(im)InstanceMethod $ c:objc(cs)ExtInterface"
3434
// MOD-NOT: "!testRelLabel": "memberOf $ c:objc(cs)ExtInterface(cm)ClassMethod $ c:objc(cs)ExtInterface"
@@ -38,7 +38,7 @@ @interface ExtInterface
3838
// MOD-NOT: "!testLabel": "c:objc(cs)ExtInterface"
3939
// MOD-DAG: "!testLabel": "c:objc(cs)ModInterface"
4040

41-
// RUN: Filecheck %s --input-file %t/symbols/[email protected] --check-prefix EXT
41+
// RUN: FileCheck %s --input-file %t/symbols/[email protected] --check-prefix EXT
4242
// EXT-DAG: "!testRelLabel": "memberOf $ c:objc(cs)ExtInterface(py)Property $ c:objc(cs)ExtInterface"
4343
// EXT-DAG: "!testRelLabel": "memberOf $ c:objc(cs)ExtInterface(im)InstanceMethod $ c:objc(cs)ExtInterface"
4444
// EXT-DAG: "!testRelLabel": "memberOf $ c:objc(cs)ExtInterface(cm)ClassMethod $ c:objc(cs)ExtInterface"

clang/test/ExtractAPI/objc_id_protocol.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: rm -rf %t
22
// RUN: %clang_cc1 -extract-api --pretty-sgf --emit-sgf-symbol-labels-for-testing \
3-
// RUN: -x objective-c-header -triple arm64-apple-macosx %s -o - -verify | Filecheck %s
3+
// RUN: -x objective-c-header -triple arm64-apple-macosx %s -o - -verify | FileCheck %s
44

55
@protocol MyProtocol
66
@end

clang/test/ExtractAPI/objc_interface.m

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
@protocol Protocol
66
@end
77

8-
// RUN: Filecheck %s --input-file %t/output.symbols.json --check-prefix SUPER
8+
// RUN: FileCheck %s --input-file %t/output.symbols.json --check-prefix SUPER
99
@interface Super <Protocol>
1010
// SUPER: "!testRelLabel": "conformsTo $ c:objc(cs)Super $ c:objc(pl)Protocol"
1111
// SUPER-LABEL: "!testLabel": "c:objc(cs)Super"
@@ -33,7 +33,7 @@ @interface Super <Protocol>
3333
// SUPER-NEXT: "Super"
3434
// SUPER-NEXT: ]
3535

36-
// RUN: Filecheck %s --input-file %t/output.symbols.json --check-prefix PROP
36+
// RUN: FileCheck %s --input-file %t/output.symbols.json --check-prefix PROP
3737
@property(readonly, getter=getProperty) unsigned Property;
3838
// PROP: "!testRelLabel": "memberOf $ c:objc(cs)Super(py)Property $ c:objc(cs)Super"
3939
// PROP: "!testLabel": "c:objc(cs)Super(py)Property"
@@ -99,7 +99,7 @@ @interface Super <Protocol>
9999
// PROP-NEXT: "Property"
100100
// PROP-NEXT: ]
101101

102-
// RUN: Filecheck %s --input-file %t/output.symbols.json --check-prefix GET
102+
// RUN: FileCheck %s --input-file %t/output.symbols.json --check-prefix GET
103103
+ (id)getWithProperty:(unsigned) Property;
104104
// GET: "!testRelLabel": "memberOf $ c:objc(cs)Super(cm)getWithProperty: $ c:objc(cs)Super"
105105
// GET-LABEL: "!testLabel": "c:objc(cs)Super(cm)getWithProperty:"
@@ -185,7 +185,7 @@ + (id)getWithProperty:(unsigned) Property;
185185
// GET-NEXT: "getWithProperty:"
186186
// GET-NEXT: ]
187187

188-
// RUN: Filecheck %s --input-file %t/output.symbols.json --check-prefix SET
188+
// RUN: FileCheck %s --input-file %t/output.symbols.json --check-prefix SET
189189
- (void)setProperty:(unsigned) Property andOtherThing: (unsigned) Thing;
190190
// SET: "!testRelLabel": "memberOf $ c:objc(cs)Super(im)setProperty:andOtherThing: $ c:objc(cs)Super"
191191
// SET-LABEL: "!testLabel": "c:objc(cs)Super(im)setProperty:andOtherThing:"
@@ -317,11 +317,11 @@ - (void)setProperty:(unsigned) Property andOtherThing: (unsigned) Thing;
317317
// SET: "title": "setProperty:andOtherThing:"
318318
@end
319319

320-
// RUN: Filecheck %s --input-file %t/output.symbols.json --check-prefix DERIVED
320+
// RUN: FileCheck %s --input-file %t/output.symbols.json --check-prefix DERIVED
321321
@interface Derived : Super {
322322
// DERIVED: "!testRelLabel": "inheritsFrom $ c:objc(cs)Derived $ c:objc(cs)Super"
323323

324-
// RUN: Filecheck %s --input-file %t/output.symbols.json --check-prefix IVAR
324+
// RUN: FileCheck %s --input-file %t/output.symbols.json --check-prefix IVAR
325325
char Ivar;
326326
// IVAR: "!testRelLabel": "memberOf $ c:objc(cs)Derived@Ivar $ c:objc(cs)Derived"
327327
// IVAR-LABEL: "!testLabel": "c:objc(cs)Derived@Ivar"

clang/test/ExtractAPI/objc_property.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: rm -rf %t
22
// RUN: %clang_cc1 -extract-api --pretty-sgf --emit-sgf-symbol-labels-for-testing \
3-
// RUN: -triple arm64-apple-macosx -x objective-c-header %s -o - -verify | Filecheck %s
3+
// RUN: -triple arm64-apple-macosx -x objective-c-header %s -o - -verify | FileCheck %s
44

55
@protocol Protocol
66
@property(class) int myProtocolTypeProp;

clang/test/ExtractAPI/typedef.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ typedef int MyInt;
4343
// MYINT-NEXT: ],
4444
// MYINT: "type": "c:I"
4545

46-
// RUN: Filecheck %s --input-file %t/output.symbols.json --check-prefix BARPTR
46+
// RUN: FileCheck %s --input-file %t/output.symbols.json --check-prefix BARPTR
4747
typedef struct Bar *BarPtr;
4848
// BARPTR-LABEL: "!testLabel": "c:typedef.c@T@BarPtr"
4949
// BARPTR: "accessLevel": "public",
@@ -84,7 +84,7 @@ typedef struct Bar *BarPtr;
8484
// BARPTR-NEXT: ],
8585
// BARPTR: "type": "c:*$@S@Bar"
8686

87-
// RUN: Filecheck %s --input-file %t/output.symbols.json
87+
// RUN: FileCheck %s --input-file %t/output.symbols.json
8888
void foo(BarPtr value);
8989

9090
void baz(BarPtr *value);

0 commit comments

Comments
 (0)