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 @@ -83,6 +83,8 @@ JsonObj["typeSourceInfos"] = Obj.TypeSourceInfos; if (!Obj.TypeLocs.empty()) JsonObj["typeLocs"] = Obj.TypeLocs; + if (!Obj.NestedNameLocs.empty()) + JsonObj["nestedNameLocs"] = Obj.NestedNameLocs; return JsonObj; } @@ -218,6 +220,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 @@ -119,7 +119,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' @@ -153,6 +154,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): 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 @@ -210,15 +210,37 @@ llvm::sort(ExpectedLocations); // clang-format off - EXPECT_EQ( - llvm::makeArrayRef(ExpectedLocations), - (ArrayRef>{ + std::vector> ActualLocations{ STRING_LOCATION_STDPAIR(MethodDecl, getBeginLoc()), STRING_LOCATION_STDPAIR(MethodDecl, getBodyRBrace()), STRING_LOCATION_STDPAIR(MethodDecl, getEndLoc()), 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()), @@ -228,6 +250,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()), @@ -242,6 +272,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()), @@ -251,9 +289,11 @@ STRING_LOCATION_STDPAIR(MethodDecl, getTypeSourceInfo()->getTypeLoc().getNextTypeLoc().getNextTypeLoc().getEndLoc()), STRING_LOCATION_STDPAIR(MethodDecl, getTypeSpecEndLoc()), STRING_LOCATION_STDPAIR(MethodDecl, getTypeSpecStartLoc()) - })); + }; // clang-format on + EXPECT_EQ(ExpectedLocations, ActualLocations); + auto ExpectedRanges = FormatExpected(Result.RangeAccessors); llvm::sort(ExpectedRanges, [](const auto &LHS, const auto &RHS) { @@ -266,12 +306,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()), @@ -279,6 +335,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()), @@ -317,23 +377,31 @@ auto ExpectedLocations = FormatExpected(Result.LocationAccessors); - EXPECT_THAT( - 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( + llvm::sort(ExpectedLocations); + + EXPECT_EQ( + llvm::makeArrayRef(ExpectedLocations), + (ArrayRef>{ + 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()),