Skip to content

Commit abacaef

Browse files
committed
[AST] Update introspection API to use const-ref for copyable types
Differential Revision: https://reviews.llvm.org/D100720
1 parent f9ddb81 commit abacaef

File tree

4 files changed

+21
-19
lines changed

4 files changed

+21
-19
lines changed

clang/include/clang/Tooling/NodeIntrospection.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ bool hasIntrospectionSupport();
8383
NodeLocationAccessors GetLocations(clang::Stmt const *Object);
8484
NodeLocationAccessors GetLocations(clang::Decl const *Object);
8585
NodeLocationAccessors GetLocations(clang::CXXCtorInitializer const *Object);
86-
NodeLocationAccessors GetLocations(clang::NestedNameSpecifierLoc const *);
87-
NodeLocationAccessors GetLocations(clang::TemplateArgumentLoc const *);
86+
NodeLocationAccessors GetLocations(clang::NestedNameSpecifierLoc const &);
87+
NodeLocationAccessors GetLocations(clang::TemplateArgumentLoc const &);
8888
NodeLocationAccessors GetLocations(clang::CXXBaseSpecifier const *);
8989
NodeLocationAccessors GetLocations(clang::TypeLoc const &);
9090
NodeLocationAccessors GetLocations(clang::DynTypedNode const &Node);

clang/lib/Tooling/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ NodeLocationAccessors NodeIntrospection::GetLocations(
4848
return {};
4949
}
5050
NodeLocationAccessors NodeIntrospection::GetLocations(
51-
clang::NestedNameSpecifierLoc const*) {
51+
clang::NestedNameSpecifierLoc const&) {
5252
return {};
5353
}
5454
NodeLocationAccessors NodeIntrospection::GetLocations(
55-
clang::TemplateArgumentLoc const*) {
55+
clang::TemplateArgumentLoc const&) {
5656
return {};
5757
}
5858
NodeLocationAccessors NodeIntrospection::GetLocations(

clang/lib/Tooling/DumpTool/generate_cxx_src_locs.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ class Generator(object):
1111

1212
implementationContent = ''
1313

14+
RefClades = {"NestedNameSpecifierLoc", "TemplateArgumentLoc", "TypeLoc"}
15+
1416
def __init__(self, templateClasses):
1517
self.templateClasses = templateClasses
1618

@@ -54,7 +56,7 @@ def GeneratePrologue(self):
5456

5557
def GenerateBaseGetLocationsDeclaration(self, CladeName):
5658
InstanceDecoration = "*"
57-
if CladeName == "TypeLoc":
59+
if CladeName in self.RefClades:
5860
InstanceDecoration = "&"
5961

6062
self.implementationContent += \
@@ -164,7 +166,7 @@ def GenerateBaseGetLocationsFunction(self, ASTClassNames,
164166

165167
MethodReturnType = 'NodeLocationAccessors'
166168
InstanceDecoration = "*"
167-
if CladeName == "TypeLoc":
169+
if CladeName in self.RefClades:
168170
InstanceDecoration = "&"
169171

170172
Signature = \
@@ -196,7 +198,7 @@ def GenerateBaseGetLocationsFunction(self, ASTClassNames,
196198
RecursionGuardParam = ', TypeLocRecursionGuard'
197199

198200
ArgPrefix = '*'
199-
if CladeName == "TypeLoc":
201+
if CladeName in self.RefClades:
200202
ArgPrefix = ''
201203
self.implementationContent += \
202204
'GetLocations{0}(Prefix, {1}Object, Locs, Rngs {2});'.format(
@@ -290,7 +292,7 @@ def GenerateDynNodeVisitor(self, CladeNames):
290292
if (const auto *N = Node.get<{0}>())
291293
""".format(CladeName)
292294
ArgPrefix = ""
293-
if CladeName == "TypeLoc":
295+
if CladeName in self.RefClades:
294296
ArgPrefix = "*"
295297
self.implementationContent += \
296298
"""
@@ -351,11 +353,11 @@ def main():
351353
return {};
352354
}
353355
NodeLocationAccessors NodeIntrospection::GetLocations(
354-
clang::NestedNameSpecifierLoc const*) {
356+
clang::NestedNameSpecifierLoc const&) {
355357
return {};
356358
}
357359
NodeLocationAccessors NodeIntrospection::GetLocations(
358-
clang::TemplateArgumentLoc const*) {
360+
clang::TemplateArgumentLoc const&) {
359361
return {};
360362
}
361363
NodeLocationAccessors NodeIntrospection::GetLocations(

clang/unittests/Introspection/IntrospectionTest.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ void ns::A::foo() {}
298298

299299
const auto *NNS = BoundNodes[0].getNodeAs<NestedNameSpecifierLoc>("nns");
300300

301-
auto Result = NodeIntrospection::GetLocations(NNS);
301+
auto Result = NodeIntrospection::GetLocations(*NNS);
302302

303303
auto ExpectedLocations =
304304
FormatExpected<SourceLocation>(Result.LocationAccessors);
@@ -352,7 +352,7 @@ void foo()
352352

353353
const auto *TA = BoundNodes[0].getNodeAs<TemplateArgumentLoc>("ta");
354354

355-
auto Result = NodeIntrospection::GetLocations(TA);
355+
auto Result = NodeIntrospection::GetLocations(*TA);
356356

357357
auto ExpectedLocations =
358358
FormatExpected<SourceLocation>(Result.LocationAccessors);
@@ -407,7 +407,7 @@ void test() {
407407

408408
const auto *TA = BoundNodes[0].getNodeAs<TemplateArgumentLoc>("ta");
409409

410-
auto Result = NodeIntrospection::GetLocations(TA);
410+
auto Result = NodeIntrospection::GetLocations(*TA);
411411

412412
auto ExpectedLocations =
413413
FormatExpected<SourceLocation>(Result.LocationAccessors);
@@ -444,7 +444,7 @@ void test() {
444444

445445
const auto *TA = BoundNodes[0].getNodeAs<TemplateArgumentLoc>("ta");
446446

447-
auto Result = NodeIntrospection::GetLocations(TA);
447+
auto Result = NodeIntrospection::GetLocations(*TA);
448448

449449
auto ExpectedLocations =
450450
FormatExpected<SourceLocation>(Result.LocationAccessors);
@@ -480,7 +480,7 @@ void test() {
480480

481481
const auto *TA = BoundNodes[0].getNodeAs<TemplateArgumentLoc>("ta");
482482

483-
auto Result = NodeIntrospection::GetLocations(TA);
483+
auto Result = NodeIntrospection::GetLocations(*TA);
484484

485485
auto ExpectedLocations =
486486
FormatExpected<SourceLocation>(Result.LocationAccessors);
@@ -517,7 +517,7 @@ void bar()
517517

518518
const auto *TA = BoundNodes[0].getNodeAs<TemplateArgumentLoc>("ta");
519519

520-
auto Result = NodeIntrospection::GetLocations(TA);
520+
auto Result = NodeIntrospection::GetLocations(*TA);
521521

522522
auto ExpectedLocations =
523523
FormatExpected<SourceLocation>(Result.LocationAccessors);
@@ -555,7 +555,7 @@ template<template<typename> class ...> class B { };
555555

556556
const auto *TA = BoundNodes[0].getNodeAs<TemplateArgumentLoc>("ta");
557557

558-
auto Result = NodeIntrospection::GetLocations(TA);
558+
auto Result = NodeIntrospection::GetLocations(*TA);
559559

560560
auto ExpectedLocations =
561561
FormatExpected<SourceLocation>(Result.LocationAccessors);
@@ -591,7 +591,7 @@ template<int I> class testExpr<I> { };
591591

592592
const auto *TA = BoundNodes[0].getNodeAs<TemplateArgumentLoc>("ta");
593593

594-
auto Result = NodeIntrospection::GetLocations(TA);
594+
auto Result = NodeIntrospection::GetLocations(*TA);
595595

596596
auto ExpectedLocations =
597597
FormatExpected<SourceLocation>(Result.LocationAccessors);
@@ -628,7 +628,7 @@ void foo()
628628

629629
const auto *TA = BoundNodes[0].getNodeAs<TemplateArgumentLoc>("ta");
630630

631-
auto Result = NodeIntrospection::GetLocations(TA);
631+
auto Result = NodeIntrospection::GetLocations(*TA);
632632

633633
auto ExpectedLocations =
634634
FormatExpected<SourceLocation>(Result.LocationAccessors);

0 commit comments

Comments
 (0)