Skip to content

Commit

Permalink
[AST] Update introspection API to use const-ref for copyable types
Browse files Browse the repository at this point in the history
Differential Revision: https://reviews.llvm.org/D100720
  • Loading branch information
steveire committed Apr 19, 2021
1 parent f9ddb81 commit abacaef
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 19 deletions.
4 changes: 2 additions & 2 deletions clang/include/clang/Tooling/NodeIntrospection.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ bool hasIntrospectionSupport();
NodeLocationAccessors GetLocations(clang::Stmt const *Object);
NodeLocationAccessors GetLocations(clang::Decl const *Object);
NodeLocationAccessors GetLocations(clang::CXXCtorInitializer const *Object);
NodeLocationAccessors GetLocations(clang::NestedNameSpecifierLoc const *);
NodeLocationAccessors GetLocations(clang::TemplateArgumentLoc const *);
NodeLocationAccessors GetLocations(clang::NestedNameSpecifierLoc const &);
NodeLocationAccessors GetLocations(clang::TemplateArgumentLoc const &);
NodeLocationAccessors GetLocations(clang::CXXBaseSpecifier const *);
NodeLocationAccessors GetLocations(clang::TypeLoc const &);
NodeLocationAccessors GetLocations(clang::DynTypedNode const &Node);
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/Tooling/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ NodeLocationAccessors NodeIntrospection::GetLocations(
return {};
}
NodeLocationAccessors NodeIntrospection::GetLocations(
clang::NestedNameSpecifierLoc const*) {
clang::NestedNameSpecifierLoc const&) {
return {};
}
NodeLocationAccessors NodeIntrospection::GetLocations(
clang::TemplateArgumentLoc const*) {
clang::TemplateArgumentLoc const&) {
return {};
}
NodeLocationAccessors NodeIntrospection::GetLocations(
Expand Down
14 changes: 8 additions & 6 deletions clang/lib/Tooling/DumpTool/generate_cxx_src_locs.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ class Generator(object):

implementationContent = ''

RefClades = {"NestedNameSpecifierLoc", "TemplateArgumentLoc", "TypeLoc"}

def __init__(self, templateClasses):
self.templateClasses = templateClasses

Expand Down Expand Up @@ -54,7 +56,7 @@ def GeneratePrologue(self):

def GenerateBaseGetLocationsDeclaration(self, CladeName):
InstanceDecoration = "*"
if CladeName == "TypeLoc":
if CladeName in self.RefClades:
InstanceDecoration = "&"

self.implementationContent += \
Expand Down Expand Up @@ -164,7 +166,7 @@ def GenerateBaseGetLocationsFunction(self, ASTClassNames,

MethodReturnType = 'NodeLocationAccessors'
InstanceDecoration = "*"
if CladeName == "TypeLoc":
if CladeName in self.RefClades:
InstanceDecoration = "&"

Signature = \
Expand Down Expand Up @@ -196,7 +198,7 @@ def GenerateBaseGetLocationsFunction(self, ASTClassNames,
RecursionGuardParam = ', TypeLocRecursionGuard'

ArgPrefix = '*'
if CladeName == "TypeLoc":
if CladeName in self.RefClades:
ArgPrefix = ''
self.implementationContent += \
'GetLocations{0}(Prefix, {1}Object, Locs, Rngs {2});'.format(
Expand Down Expand Up @@ -290,7 +292,7 @@ def GenerateDynNodeVisitor(self, CladeNames):
if (const auto *N = Node.get<{0}>())
""".format(CladeName)
ArgPrefix = ""
if CladeName == "TypeLoc":
if CladeName in self.RefClades:
ArgPrefix = "*"
self.implementationContent += \
"""
Expand Down Expand Up @@ -351,11 +353,11 @@ def main():
return {};
}
NodeLocationAccessors NodeIntrospection::GetLocations(
clang::NestedNameSpecifierLoc const*) {
clang::NestedNameSpecifierLoc const&) {
return {};
}
NodeLocationAccessors NodeIntrospection::GetLocations(
clang::TemplateArgumentLoc const*) {
clang::TemplateArgumentLoc const&) {
return {};
}
NodeLocationAccessors NodeIntrospection::GetLocations(
Expand Down
18 changes: 9 additions & 9 deletions clang/unittests/Introspection/IntrospectionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ void ns::A::foo() {}

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

auto Result = NodeIntrospection::GetLocations(NNS);
auto Result = NodeIntrospection::GetLocations(*NNS);

auto ExpectedLocations =
FormatExpected<SourceLocation>(Result.LocationAccessors);
Expand Down Expand Up @@ -352,7 +352,7 @@ void foo()

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

auto Result = NodeIntrospection::GetLocations(TA);
auto Result = NodeIntrospection::GetLocations(*TA);

auto ExpectedLocations =
FormatExpected<SourceLocation>(Result.LocationAccessors);
Expand Down Expand Up @@ -407,7 +407,7 @@ void test() {

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

auto Result = NodeIntrospection::GetLocations(TA);
auto Result = NodeIntrospection::GetLocations(*TA);

auto ExpectedLocations =
FormatExpected<SourceLocation>(Result.LocationAccessors);
Expand Down Expand Up @@ -444,7 +444,7 @@ void test() {

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

auto Result = NodeIntrospection::GetLocations(TA);
auto Result = NodeIntrospection::GetLocations(*TA);

auto ExpectedLocations =
FormatExpected<SourceLocation>(Result.LocationAccessors);
Expand Down Expand Up @@ -480,7 +480,7 @@ void test() {

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

auto Result = NodeIntrospection::GetLocations(TA);
auto Result = NodeIntrospection::GetLocations(*TA);

auto ExpectedLocations =
FormatExpected<SourceLocation>(Result.LocationAccessors);
Expand Down Expand Up @@ -517,7 +517,7 @@ void bar()

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

auto Result = NodeIntrospection::GetLocations(TA);
auto Result = NodeIntrospection::GetLocations(*TA);

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

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

auto Result = NodeIntrospection::GetLocations(TA);
auto Result = NodeIntrospection::GetLocations(*TA);

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

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

auto Result = NodeIntrospection::GetLocations(TA);
auto Result = NodeIntrospection::GetLocations(*TA);

auto ExpectedLocations =
FormatExpected<SourceLocation>(Result.LocationAccessors);
Expand Down Expand Up @@ -628,7 +628,7 @@ void foo()

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

auto Result = NodeIntrospection::GetLocations(TA);
auto Result = NodeIntrospection::GetLocations(*TA);

auto ExpectedLocations =
FormatExpected<SourceLocation>(Result.LocationAccessors);
Expand Down

0 comments on commit abacaef

Please sign in to comment.