diff --git a/clang/include/clang/Tooling/NodeIntrospection.h b/clang/include/clang/Tooling/NodeIntrospection.h --- a/clang/include/clang/Tooling/NodeIntrospection.h +++ b/clang/include/clang/Tooling/NodeIntrospection.h @@ -83,7 +83,7 @@ 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::NestedNameSpecifierLoc const &); NodeLocationAccessors GetLocations(clang::TemplateArgumentLoc const *); NodeLocationAccessors GetLocations(clang::CXXBaseSpecifier const *); NodeLocationAccessors GetLocations(clang::TypeLoc const &); diff --git a/clang/lib/Tooling/CMakeLists.txt b/clang/lib/Tooling/CMakeLists.txt --- a/clang/lib/Tooling/CMakeLists.txt +++ b/clang/lib/Tooling/CMakeLists.txt @@ -47,7 +47,7 @@ return {}; } NodeLocationAccessors NodeIntrospection::GetLocations( - clang::NestedNameSpecifierLoc const*) { + clang::NestedNameSpecifierLoc const&) { return {}; } NodeLocationAccessors NodeIntrospection::GetLocations( diff --git a/clang/lib/Tooling/DumpTool/APIData.h b/clang/lib/Tooling/DumpTool/APIData.h --- a/clang/lib/Tooling/DumpTool/APIData.h +++ b/clang/lib/Tooling/DumpTool/APIData.h @@ -21,6 +21,7 @@ std::vector TemplateParms; std::vector TypeSourceInfos; std::vector TypeLocs; + std::vector NestedNameLocs; // TODO: Extend this with locations available via typelocs etc. }; diff --git a/clang/lib/Tooling/DumpTool/ASTSrcLocProcessor.cpp b/clang/lib/Tooling/DumpTool/ASTSrcLocProcessor.cpp --- a/clang/lib/Tooling/DumpTool/ASTSrcLocProcessor.cpp +++ b/clang/lib/Tooling/DumpTool/ASTSrcLocProcessor.cpp @@ -82,6 +82,8 @@ JsonObj["typeSourceInfos"] = Obj.TypeSourceInfos; if (!Obj.TypeLocs.empty()) JsonObj["typeLocs"] = Obj.TypeLocs; + if (!Obj.NestedNameLocs.empty()) + JsonObj["nestedNameLocs"] = Obj.NestedNameLocs; return JsonObj; } @@ -203,6 +205,8 @@ CD.TypeSourceInfos = CaptureMethods("class clang::TypeSourceInfo *", ASTClass, Result); CD.TypeLocs = CaptureMethods("class clang::TypeLoc", ASTClass, Result); + CD.NestedNameLocs = + CaptureMethods("class clang::NestedNameSpecifierLoc", ASTClass, Result); if (const auto *DerivedFrom = Result.Nodes.getNodeAs("derivedFrom")) { diff --git a/clang/lib/Tooling/DumpTool/generate_cxx_src_locs.py b/clang/lib/Tooling/DumpTool/generate_cxx_src_locs.py --- a/clang/lib/Tooling/DumpTool/generate_cxx_src_locs.py +++ b/clang/lib/Tooling/DumpTool/generate_cxx_src_locs.py @@ -54,7 +54,7 @@ def GenerateBaseGetLocationsDeclaration(self, CladeName): InstanceDecoration = "*" - if CladeName == "TypeLoc": + if CladeName == "TypeLoc" or CladeName == "NestedNameSpecifierLoc": InstanceDecoration = "&" self.implementationContent += \ @@ -117,7 +117,8 @@ self.implementationContent += '\n' - if 'typeLocs' in ClassData or 'typeSourceInfos' in ClassData: + if 'typeLocs' in ClassData or 'typeSourceInfos' in ClassData \ + or 'nestedNameLocs' in ClassData: if CreateLocalRecursionGuard: self.implementationContent += \ 'std::vector TypeLocRecursionGuard;\n' @@ -151,6 +152,17 @@ self.implementationContent += '\n' + if 'nestedNameLocs' in ClassData: + for NN in ClassData['nestedNameLocs']: + self.implementationContent += \ + """ + if (Object.{0}()) + GetLocationsImpl( + llvm::makeIntrusiveRefCnt(Prefix, "{0}"), + Object.{0}(), Locs, Rngs, TypeLocRecursionGuard); + """.format(NN) + + self.implementationContent += '}\n' def GenerateFiles(self, OutputFile): @@ -164,7 +176,7 @@ MethodReturnType = 'NodeLocationAccessors' InstanceDecoration = "*" - if CladeName == "TypeLoc": + if CladeName == "TypeLoc" or CladeName == "NestedNameSpecifierLoc": InstanceDecoration = "&" Signature = \ @@ -196,7 +208,7 @@ RecursionGuardParam = ', TypeLocRecursionGuard' ArgPrefix = '*' - if CladeName == "TypeLoc": + if CladeName == "TypeLoc" or CladeName == "NestedNameSpecifierLoc": ArgPrefix = '' self.implementationContent += \ 'GetLocations{0}(Prefix, {1}Object, Locs, Rngs {2});'.format( @@ -290,7 +302,7 @@ if (const auto *N = Node.get<{0}>()) """.format(CladeName) ArgPrefix = "" - if CladeName == "TypeLoc": + if CladeName == "TypeLoc" or CladeName == "NestedNameSpecifierLoc": ArgPrefix = "*" self.implementationContent += \ """ @@ -351,7 +363,7 @@ return {}; } NodeLocationAccessors NodeIntrospection::GetLocations( - clang::NestedNameSpecifierLoc const*) { + clang::NestedNameSpecifierLoc const&) { return {}; } NodeLocationAccessors NodeIntrospection::GetLocations( diff --git a/clang/unittests/Introspection/IntrospectionTest.cpp b/clang/unittests/Introspection/IntrospectionTest.cpp --- a/clang/unittests/Introspection/IntrospectionTest.cpp +++ b/clang/unittests/Introspection/IntrospectionTest.cpp @@ -205,6 +205,30 @@ STRING_LOCATION_STDPAIR(MethodDecl, getInnerLocStart()), STRING_LOCATION_STDPAIR(MethodDecl, getLocation()), STRING_LOCATION_STDPAIR(MethodDecl, getOuterLocStart()), +STRING_LOCATION_STDPAIR(MethodDecl, getQualifierLoc().getBeginLoc()), +STRING_LOCATION_STDPAIR(MethodDecl, getQualifierLoc().getEndLoc()), +STRING_LOCATION_STDPAIR(MethodDecl, getQualifierLoc().getLocalBeginLoc()), +STRING_LOCATION_STDPAIR(MethodDecl, getQualifierLoc().getLocalEndLoc()), +STRING_LOCATION_STDPAIR(MethodDecl, getQualifierLoc().getPrefix().getBeginLoc()), +STRING_LOCATION_STDPAIR(MethodDecl, getQualifierLoc().getPrefix().getEndLoc()), +STRING_LOCATION_STDPAIR(MethodDecl, getQualifierLoc().getPrefix().getLocalBeginLoc()), +STRING_LOCATION_STDPAIR(MethodDecl, getQualifierLoc().getPrefix().getLocalEndLoc()), +STRING_LOCATION_STDPAIR(MethodDecl, getQualifierLoc().getPrefix().getPrefix().getBeginLoc()), +STRING_LOCATION_STDPAIR(MethodDecl, getQualifierLoc().getPrefix().getPrefix().getEndLoc()), +STRING_LOCATION_STDPAIR(MethodDecl, getQualifierLoc().getPrefix().getPrefix().getLocalBeginLoc()), +STRING_LOCATION_STDPAIR(MethodDecl, getQualifierLoc().getPrefix().getPrefix().getLocalEndLoc()), +STRING_LOCATION_STDPAIR(MethodDecl, getQualifierLoc().getPrefix().getPrefix().getPrefix().getBeginLoc()), +STRING_LOCATION_STDPAIR(MethodDecl, getQualifierLoc().getPrefix().getPrefix().getPrefix().getEndLoc()), +STRING_LOCATION_STDPAIR(MethodDecl, getQualifierLoc().getPrefix().getPrefix().getPrefix().getLocalBeginLoc()), +STRING_LOCATION_STDPAIR(MethodDecl, getQualifierLoc().getPrefix().getPrefix().getPrefix().getLocalEndLoc()), +STRING_LOCATION_STDPAIR(MethodDecl, getQualifierLoc().getPrefix().getTypeLoc().getAs().getLAngleLoc()), +STRING_LOCATION_STDPAIR(MethodDecl, getQualifierLoc().getPrefix().getTypeLoc().getAs().getRAngleLoc()), +STRING_LOCATION_STDPAIR(MethodDecl, getQualifierLoc().getPrefix().getTypeLoc().getAs().getTemplateNameLoc()), +STRING_LOCATION_STDPAIR(MethodDecl, getQualifierLoc().getPrefix().getTypeLoc().getBeginLoc()), +STRING_LOCATION_STDPAIR(MethodDecl, getQualifierLoc().getPrefix().getTypeLoc().getEndLoc()), +STRING_LOCATION_STDPAIR(MethodDecl, getQualifierLoc().getTypeLoc().getAs().getNameLoc()), +STRING_LOCATION_STDPAIR(MethodDecl, getQualifierLoc().getTypeLoc().getBeginLoc()), +STRING_LOCATION_STDPAIR(MethodDecl, getQualifierLoc().getTypeLoc().getEndLoc()), STRING_LOCATION_STDPAIR(MethodDecl, getTypeSourceInfo()->getTypeLoc().getAs().getLParenLoc()), STRING_LOCATION_STDPAIR(MethodDecl, getTypeSourceInfo()->getTypeLoc().getAs().getLocalRangeBegin()), STRING_LOCATION_STDPAIR(MethodDecl, getTypeSourceInfo()->getTypeLoc().getAs().getLocalRangeEnd()), @@ -214,6 +238,14 @@ STRING_LOCATION_STDPAIR(MethodDecl, getTypeSourceInfo()->getTypeLoc().getAs().getReturnLoc().getAs().getNamedTypeLoc().getAs().getTemplateNameLoc()), STRING_LOCATION_STDPAIR(MethodDecl, getTypeSourceInfo()->getTypeLoc().getAs().getReturnLoc().getAs().getNamedTypeLoc().getBeginLoc()), STRING_LOCATION_STDPAIR(MethodDecl, getTypeSourceInfo()->getTypeLoc().getAs().getReturnLoc().getAs().getNamedTypeLoc().getEndLoc()), +STRING_LOCATION_STDPAIR(MethodDecl, getTypeSourceInfo()->getTypeLoc().getAs().getReturnLoc().getAs().getQualifierLoc().getBeginLoc()), +STRING_LOCATION_STDPAIR(MethodDecl, getTypeSourceInfo()->getTypeLoc().getAs().getReturnLoc().getAs().getQualifierLoc().getEndLoc()), +STRING_LOCATION_STDPAIR(MethodDecl, getTypeSourceInfo()->getTypeLoc().getAs().getReturnLoc().getAs().getQualifierLoc().getLocalBeginLoc()), +STRING_LOCATION_STDPAIR(MethodDecl, getTypeSourceInfo()->getTypeLoc().getAs().getReturnLoc().getAs().getQualifierLoc().getLocalEndLoc()), +STRING_LOCATION_STDPAIR(MethodDecl, getTypeSourceInfo()->getTypeLoc().getAs().getReturnLoc().getAs().getQualifierLoc().getPrefix().getBeginLoc()), +STRING_LOCATION_STDPAIR(MethodDecl, getTypeSourceInfo()->getTypeLoc().getAs().getReturnLoc().getAs().getQualifierLoc().getPrefix().getEndLoc()), +STRING_LOCATION_STDPAIR(MethodDecl, getTypeSourceInfo()->getTypeLoc().getAs().getReturnLoc().getAs().getQualifierLoc().getPrefix().getLocalBeginLoc()), +STRING_LOCATION_STDPAIR(MethodDecl, getTypeSourceInfo()->getTypeLoc().getAs().getReturnLoc().getAs().getQualifierLoc().getPrefix().getLocalEndLoc()), STRING_LOCATION_STDPAIR(MethodDecl, getTypeSourceInfo()->getTypeLoc().getAs().getReturnLoc().getBeginLoc()), STRING_LOCATION_STDPAIR(MethodDecl, getTypeSourceInfo()->getTypeLoc().getAs().getReturnLoc().getEndLoc()), STRING_LOCATION_STDPAIR(MethodDecl, getTypeSourceInfo()->getTypeLoc().getAs().getReturnLoc().getNextTypeLoc().getAs().getLAngleLoc()), @@ -228,6 +260,14 @@ STRING_LOCATION_STDPAIR(MethodDecl, getTypeSourceInfo()->getTypeLoc().getNextTypeLoc().getAs().getNamedTypeLoc().getAs().getTemplateNameLoc()), STRING_LOCATION_STDPAIR(MethodDecl, getTypeSourceInfo()->getTypeLoc().getNextTypeLoc().getAs().getNamedTypeLoc().getBeginLoc()), STRING_LOCATION_STDPAIR(MethodDecl, getTypeSourceInfo()->getTypeLoc().getNextTypeLoc().getAs().getNamedTypeLoc().getEndLoc()), +STRING_LOCATION_STDPAIR(MethodDecl, getTypeSourceInfo()->getTypeLoc().getNextTypeLoc().getAs().getQualifierLoc().getBeginLoc()), +STRING_LOCATION_STDPAIR(MethodDecl, getTypeSourceInfo()->getTypeLoc().getNextTypeLoc().getAs().getQualifierLoc().getEndLoc()), +STRING_LOCATION_STDPAIR(MethodDecl, getTypeSourceInfo()->getTypeLoc().getNextTypeLoc().getAs().getQualifierLoc().getLocalBeginLoc()), +STRING_LOCATION_STDPAIR(MethodDecl, getTypeSourceInfo()->getTypeLoc().getNextTypeLoc().getAs().getQualifierLoc().getLocalEndLoc()), +STRING_LOCATION_STDPAIR(MethodDecl, getTypeSourceInfo()->getTypeLoc().getNextTypeLoc().getAs().getQualifierLoc().getPrefix().getBeginLoc()), +STRING_LOCATION_STDPAIR(MethodDecl, getTypeSourceInfo()->getTypeLoc().getNextTypeLoc().getAs().getQualifierLoc().getPrefix().getEndLoc()), +STRING_LOCATION_STDPAIR(MethodDecl, getTypeSourceInfo()->getTypeLoc().getNextTypeLoc().getAs().getQualifierLoc().getPrefix().getLocalBeginLoc()), +STRING_LOCATION_STDPAIR(MethodDecl, getTypeSourceInfo()->getTypeLoc().getNextTypeLoc().getAs().getQualifierLoc().getPrefix().getLocalEndLoc()), STRING_LOCATION_STDPAIR(MethodDecl, getTypeSourceInfo()->getTypeLoc().getNextTypeLoc().getBeginLoc()), STRING_LOCATION_STDPAIR(MethodDecl, getTypeSourceInfo()->getTypeLoc().getNextTypeLoc().getEndLoc()), STRING_LOCATION_STDPAIR(MethodDecl, getTypeSourceInfo()->getTypeLoc().getNextTypeLoc().getNextTypeLoc().getAs().getLAngleLoc()), @@ -252,12 +292,28 @@ (ArrayRef>{ STRING_LOCATION_STDPAIR(MethodDecl, getExceptionSpecSourceRange()), STRING_LOCATION_STDPAIR(MethodDecl, getParametersSourceRange()), +STRING_LOCATION_STDPAIR(MethodDecl, getQualifierLoc().getLocalSourceRange()), +STRING_LOCATION_STDPAIR(MethodDecl, getQualifierLoc().getPrefix().getLocalSourceRange()), +STRING_LOCATION_STDPAIR(MethodDecl, getQualifierLoc().getPrefix().getPrefix().getLocalSourceRange()), +STRING_LOCATION_STDPAIR(MethodDecl, getQualifierLoc().getPrefix().getPrefix().getPrefix().getLocalSourceRange()), +STRING_LOCATION_STDPAIR(MethodDecl, getQualifierLoc().getPrefix().getPrefix().getPrefix().getSourceRange()), +STRING_LOCATION_STDPAIR(MethodDecl, getQualifierLoc().getPrefix().getPrefix().getSourceRange()), +STRING_LOCATION_STDPAIR(MethodDecl, getQualifierLoc().getPrefix().getSourceRange()), +STRING_LOCATION_STDPAIR(MethodDecl, getQualifierLoc().getPrefix().getTypeLoc().getLocalSourceRange()), +STRING_LOCATION_STDPAIR(MethodDecl, getQualifierLoc().getPrefix().getTypeLoc().getSourceRange()), +STRING_LOCATION_STDPAIR(MethodDecl, getQualifierLoc().getSourceRange()), +STRING_LOCATION_STDPAIR(MethodDecl, getQualifierLoc().getTypeLoc().getLocalSourceRange()), +STRING_LOCATION_STDPAIR(MethodDecl, getQualifierLoc().getTypeLoc().getSourceRange()), STRING_LOCATION_STDPAIR(MethodDecl, getReturnTypeSourceRange()), STRING_LOCATION_STDPAIR(MethodDecl, getSourceRange()), STRING_LOCATION_STDPAIR(MethodDecl, getTypeSourceInfo()->getTypeLoc().getAs().getExceptionSpecRange()), STRING_LOCATION_STDPAIR(MethodDecl, getTypeSourceInfo()->getTypeLoc().getAs().getParensRange()), STRING_LOCATION_STDPAIR(MethodDecl, getTypeSourceInfo()->getTypeLoc().getAs().getReturnLoc().getAs().getNamedTypeLoc().getLocalSourceRange()), STRING_LOCATION_STDPAIR(MethodDecl, getTypeSourceInfo()->getTypeLoc().getAs().getReturnLoc().getAs().getNamedTypeLoc().getSourceRange()), +STRING_LOCATION_STDPAIR(MethodDecl, getTypeSourceInfo()->getTypeLoc().getAs().getReturnLoc().getAs().getQualifierLoc().getLocalSourceRange()), +STRING_LOCATION_STDPAIR(MethodDecl, getTypeSourceInfo()->getTypeLoc().getAs().getReturnLoc().getAs().getQualifierLoc().getPrefix().getLocalSourceRange()), +STRING_LOCATION_STDPAIR(MethodDecl, getTypeSourceInfo()->getTypeLoc().getAs().getReturnLoc().getAs().getQualifierLoc().getPrefix().getSourceRange()), +STRING_LOCATION_STDPAIR(MethodDecl, getTypeSourceInfo()->getTypeLoc().getAs().getReturnLoc().getAs().getQualifierLoc().getSourceRange()), STRING_LOCATION_STDPAIR(MethodDecl, getTypeSourceInfo()->getTypeLoc().getAs().getReturnLoc().getLocalSourceRange()), STRING_LOCATION_STDPAIR(MethodDecl, getTypeSourceInfo()->getTypeLoc().getAs().getReturnLoc().getNextTypeLoc().getLocalSourceRange()), STRING_LOCATION_STDPAIR(MethodDecl, getTypeSourceInfo()->getTypeLoc().getAs().getReturnLoc().getNextTypeLoc().getSourceRange()), @@ -265,6 +321,10 @@ STRING_LOCATION_STDPAIR(MethodDecl, getTypeSourceInfo()->getTypeLoc().getLocalSourceRange()), STRING_LOCATION_STDPAIR(MethodDecl, getTypeSourceInfo()->getTypeLoc().getNextTypeLoc().getAs().getNamedTypeLoc().getLocalSourceRange()), STRING_LOCATION_STDPAIR(MethodDecl, getTypeSourceInfo()->getTypeLoc().getNextTypeLoc().getAs().getNamedTypeLoc().getSourceRange()), +STRING_LOCATION_STDPAIR(MethodDecl, getTypeSourceInfo()->getTypeLoc().getNextTypeLoc().getAs().getQualifierLoc().getLocalSourceRange()), +STRING_LOCATION_STDPAIR(MethodDecl, getTypeSourceInfo()->getTypeLoc().getNextTypeLoc().getAs().getQualifierLoc().getPrefix().getLocalSourceRange()), +STRING_LOCATION_STDPAIR(MethodDecl, getTypeSourceInfo()->getTypeLoc().getNextTypeLoc().getAs().getQualifierLoc().getPrefix().getSourceRange()), +STRING_LOCATION_STDPAIR(MethodDecl, getTypeSourceInfo()->getTypeLoc().getNextTypeLoc().getAs().getQualifierLoc().getSourceRange()), STRING_LOCATION_STDPAIR(MethodDecl, getTypeSourceInfo()->getTypeLoc().getNextTypeLoc().getLocalSourceRange()), STRING_LOCATION_STDPAIR(MethodDecl, getTypeSourceInfo()->getTypeLoc().getNextTypeLoc().getNextTypeLoc().getLocalSourceRange()), STRING_LOCATION_STDPAIR(MethodDecl, getTypeSourceInfo()->getTypeLoc().getNextTypeLoc().getNextTypeLoc().getSourceRange()), @@ -298,28 +358,36 @@ const auto *NNS = BoundNodes[0].getNodeAs("nns"); - auto Result = NodeIntrospection::GetLocations(NNS); + auto Result = NodeIntrospection::GetLocations(*NNS); auto ExpectedLocations = FormatExpected(Result.LocationAccessors); - EXPECT_THAT( + llvm::sort(ExpectedLocations); + + EXPECT_EQ( ExpectedLocations, - UnorderedElementsAre( - STRING_LOCATION_PAIR(NNS, getBeginLoc()), - STRING_LOCATION_PAIR(NNS, getEndLoc()), - STRING_LOCATION_PAIR(NNS, getLocalBeginLoc()), - STRING_LOCATION_PAIR(NNS, getLocalEndLoc()), - STRING_LOCATION_PAIR( + (std::vector>{ + STRING_LOCATION_STDPAIR(NNS, getBeginLoc()), + STRING_LOCATION_STDPAIR(NNS, getEndLoc()), + STRING_LOCATION_STDPAIR(NNS, getLocalBeginLoc()), + STRING_LOCATION_STDPAIR(NNS, getLocalEndLoc()), + STRING_LOCATION_STDPAIR(NNS, getPrefix().getBeginLoc()), + STRING_LOCATION_STDPAIR(NNS, getPrefix().getEndLoc()), + STRING_LOCATION_STDPAIR(NNS, getPrefix().getLocalBeginLoc()), + STRING_LOCATION_STDPAIR(NNS, getPrefix().getLocalEndLoc()), + STRING_LOCATION_STDPAIR( NNS, getTypeLoc().getAs().getNameLoc()), - STRING_LOCATION_PAIR(NNS, getTypeLoc().getBeginLoc()), - STRING_LOCATION_PAIR(NNS, getTypeLoc().getEndLoc()))); + STRING_LOCATION_STDPAIR(NNS, getTypeLoc().getBeginLoc()), + STRING_LOCATION_STDPAIR(NNS, getTypeLoc().getEndLoc())})); auto ExpectedRanges = FormatExpected(Result.RangeAccessors); EXPECT_THAT( ExpectedRanges, UnorderedElementsAre( + STRING_LOCATION_PAIR(NNS, getPrefix().getLocalSourceRange()), + STRING_LOCATION_PAIR(NNS, getPrefix().getSourceRange()), STRING_LOCATION_PAIR(NNS, getLocalSourceRange()), STRING_LOCATION_PAIR(NNS, getSourceRange()), STRING_LOCATION_PAIR(NNS, getTypeLoc().getSourceRange()),