[clang] abacaef - [AST] Update introspection API to use const-ref for copyable types

Stephen Kelly via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 19 13:08:18 PDT 2021


Author: Stephen Kelly
Date: 2021-04-19T21:07:47+01:00
New Revision: abacaef1816254fc425fa81d137a8d54215d5913

URL: https://github.com/llvm/llvm-project/commit/abacaef1816254fc425fa81d137a8d54215d5913
DIFF: https://github.com/llvm/llvm-project/commit/abacaef1816254fc425fa81d137a8d54215d5913.diff

LOG: [AST] Update introspection API to use const-ref for copyable types

Differential Revision: https://reviews.llvm.org/D100720

Added: 
    

Modified: 
    clang/include/clang/Tooling/NodeIntrospection.h
    clang/lib/Tooling/CMakeLists.txt
    clang/lib/Tooling/DumpTool/generate_cxx_src_locs.py
    clang/unittests/Introspection/IntrospectionTest.cpp

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Tooling/NodeIntrospection.h b/clang/include/clang/Tooling/NodeIntrospection.h
index dd7ffe3991207..a04c08823339d 100644
--- a/clang/include/clang/Tooling/NodeIntrospection.h
+++ b/clang/include/clang/Tooling/NodeIntrospection.h
@@ -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);

diff  --git a/clang/lib/Tooling/CMakeLists.txt b/clang/lib/Tooling/CMakeLists.txt
index a0bb108a2b6c4..2baea134271e5 100644
--- a/clang/lib/Tooling/CMakeLists.txt
+++ b/clang/lib/Tooling/CMakeLists.txt
@@ -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(

diff  --git a/clang/lib/Tooling/DumpTool/generate_cxx_src_locs.py b/clang/lib/Tooling/DumpTool/generate_cxx_src_locs.py
index 3664f521e27b7..fdf586e7e1150 100755
--- a/clang/lib/Tooling/DumpTool/generate_cxx_src_locs.py
+++ b/clang/lib/Tooling/DumpTool/generate_cxx_src_locs.py
@@ -11,6 +11,8 @@ class Generator(object):
 
     implementationContent = ''
 
+    RefClades = {"NestedNameSpecifierLoc", "TemplateArgumentLoc", "TypeLoc"}
+
     def __init__(self, templateClasses):
         self.templateClasses = templateClasses
 
@@ -54,7 +56,7 @@ def GeneratePrologue(self):
 
     def GenerateBaseGetLocationsDeclaration(self, CladeName):
         InstanceDecoration = "*"
-        if CladeName == "TypeLoc":
+        if CladeName in self.RefClades:
             InstanceDecoration = "&"
 
         self.implementationContent += \
@@ -164,7 +166,7 @@ def GenerateBaseGetLocationsFunction(self, ASTClassNames,
 
         MethodReturnType = 'NodeLocationAccessors'
         InstanceDecoration = "*"
-        if CladeName == "TypeLoc":
+        if CladeName in self.RefClades:
             InstanceDecoration = "&"
 
         Signature = \
@@ -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(
@@ -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 += \
             """
@@ -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(

diff  --git a/clang/unittests/Introspection/IntrospectionTest.cpp b/clang/unittests/Introspection/IntrospectionTest.cpp
index 57431668a19f4..1db3e6a8e6d65 100644
--- a/clang/unittests/Introspection/IntrospectionTest.cpp
+++ b/clang/unittests/Introspection/IntrospectionTest.cpp
@@ -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);
@@ -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);
@@ -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);
@@ -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);
@@ -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);
@@ -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);
@@ -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);
@@ -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);
@@ -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);


        


More information about the cfe-commits mailing list