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 @@ -85,6 +85,7 @@ }; namespace NodeIntrospection { +bool hasIntrospectionSupport(); NodeLocationAccessors GetLocations(clang::Stmt const *Object); NodeLocationAccessors GetLocations(clang::Decl const *Object); NodeLocationAccessors GetLocations(clang::CXXCtorInitializer const *Object); 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 @@ -35,6 +35,8 @@ namespace clang { namespace tooling { +bool NodeIntrospection::hasIntrospectionSupport() { return false; } + NodeLocationAccessors NodeIntrospection::GetLocations(clang::Stmt const *) { return {}; } 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 @@ -28,6 +28,8 @@ using LocationAndString = SourceLocationMap::value_type; using RangeAndString = SourceRangeMap::value_type; + +bool NodeIntrospection::hasIntrospectionSupport() { return true; } """ def GenerateBaseGetLocationsDeclaration(self, CladeName): @@ -174,6 +176,8 @@ namespace clang { namespace tooling { +bool NodeIntrospection::hasIntrospectionSupport() { return false; } + NodeLocationAccessors NodeIntrospection::GetLocations(clang::Stmt const *) { return {}; } 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 @@ -46,6 +46,8 @@ #define STRING_LOCATION_PAIR(INSTANCE, LOC) Pair(#LOC, INSTANCE->LOC) TEST(Introspection, SourceLocations_Stmt) { + if (!NodeIntrospection::hasIntrospectionSupport()) + return; auto AST = buildASTFromCode("void foo() {} void bar() { foo(); }", "foo.cpp", std::make_shared()); auto &Ctx = AST->getASTContext(); @@ -62,11 +64,6 @@ auto Result = NodeIntrospection::GetLocations(FooCall); - if (Result.LocationAccessors.empty() && Result.RangeAccessors.empty()) - { - return; - } - auto ExpectedLocations = FormatExpected(Result.LocationAccessors); @@ -84,6 +81,8 @@ } TEST(Introspection, SourceLocations_Decl) { + if (!NodeIntrospection::hasIntrospectionSupport()) + return; auto AST = buildASTFromCode(R"cpp( namespace ns1 { @@ -118,10 +117,6 @@ auto Result = NodeIntrospection::GetLocations(MethodDecl); - if (Result.LocationAccessors.empty() && Result.RangeAccessors.empty()) { - return; - } - auto ExpectedLocations = FormatExpected(Result.LocationAccessors); @@ -148,6 +143,8 @@ } TEST(Introspection, SourceLocations_NNS) { + if (!NodeIntrospection::hasIntrospectionSupport()) + return; auto AST = buildASTFromCode(R"cpp( namespace ns @@ -171,10 +168,6 @@ auto Result = NodeIntrospection::GetLocations(NNS); - if (Result.LocationAccessors.empty() && Result.RangeAccessors.empty()) { - return; - } - auto ExpectedLocations = FormatExpected(Result.LocationAccessors); @@ -194,6 +187,8 @@ } TEST(Introspection, SourceLocations_TA_Type) { + if (!NodeIntrospection::hasIntrospectionSupport()) + return; auto AST = buildASTFromCode(R"cpp( template @@ -219,10 +214,6 @@ auto Result = NodeIntrospection::GetLocations(TA); - if (Result.LocationAccessors.empty() && Result.RangeAccessors.empty()) { - return; - } - auto ExpectedLocations = FormatExpected(Result.LocationAccessors); @@ -236,6 +227,8 @@ } TEST(Introspection, SourceLocations_TA_Decl) { + if (!NodeIntrospection::hasIntrospectionSupport()) + return; auto AST = buildASTFromCode(R"cpp( template @@ -258,10 +251,6 @@ auto Result = NodeIntrospection::GetLocations(TA); - if (Result.LocationAccessors.empty() && Result.RangeAccessors.empty()) { - return; - } - auto ExpectedLocations = FormatExpected(Result.LocationAccessors); @@ -275,6 +264,8 @@ } TEST(Introspection, SourceLocations_TA_Nullptr) { + if (!NodeIntrospection::hasIntrospectionSupport()) + return; auto AST = buildASTFromCode(R"cpp( template @@ -297,10 +288,6 @@ auto Result = NodeIntrospection::GetLocations(TA); - if (Result.LocationAccessors.empty() && Result.RangeAccessors.empty()) { - return; - } - auto ExpectedLocations = FormatExpected(Result.LocationAccessors); @@ -314,6 +301,8 @@ } TEST(Introspection, SourceLocations_TA_Integral) { + if (!NodeIntrospection::hasIntrospectionSupport()) + return; auto AST = buildASTFromCode(R"cpp( template @@ -335,10 +324,6 @@ auto Result = NodeIntrospection::GetLocations(TA); - if (Result.LocationAccessors.empty() && Result.RangeAccessors.empty()) { - return; - } - auto ExpectedLocations = FormatExpected(Result.LocationAccessors); @@ -352,6 +337,8 @@ } TEST(Introspection, SourceLocations_TA_Template) { + if (!NodeIntrospection::hasIntrospectionSupport()) + return; auto AST = buildASTFromCode(R"cpp( template class A; @@ -374,10 +361,6 @@ auto Result = NodeIntrospection::GetLocations(TA); - if (Result.LocationAccessors.empty() && Result.RangeAccessors.empty()) { - return; - } - auto ExpectedLocations = FormatExpected(Result.LocationAccessors); @@ -393,6 +376,8 @@ } TEST(Introspection, SourceLocations_TA_TemplateExpansion) { + if (!NodeIntrospection::hasIntrospectionSupport()) + return; auto AST = buildASTFromCodeWithArgs( R"cpp( template class ...> class B { }; @@ -414,10 +399,6 @@ auto Result = NodeIntrospection::GetLocations(TA); - if (Result.LocationAccessors.empty() && Result.RangeAccessors.empty()) { - return; - } - auto ExpectedLocations = FormatExpected(Result.LocationAccessors); @@ -434,6 +415,8 @@ } TEST(Introspection, SourceLocations_TA_Expression) { + if (!NodeIntrospection::hasIntrospectionSupport()) + return; auto AST = buildASTFromCode(R"cpp( template class testExpr; @@ -452,10 +435,6 @@ auto Result = NodeIntrospection::GetLocations(TA); - if (Result.LocationAccessors.empty() && Result.RangeAccessors.empty()) { - return; - } - auto ExpectedLocations = FormatExpected(Result.LocationAccessors); @@ -469,6 +448,8 @@ } TEST(Introspection, SourceLocations_TA_Pack) { + if (!NodeIntrospection::hasIntrospectionSupport()) + return; auto AST = buildASTFromCodeWithArgs( R"cpp( template class A {}; @@ -491,10 +472,6 @@ auto Result = NodeIntrospection::GetLocations(TA); - if (Result.LocationAccessors.empty() && Result.RangeAccessors.empty()) { - return; - } - auto ExpectedLocations = FormatExpected(Result.LocationAccessors); @@ -508,6 +485,8 @@ } TEST(Introspection, SourceLocations_CXXCtorInitializer_base) { + if (!NodeIntrospection::hasIntrospectionSupport()) + return; auto AST = buildASTFromCode(R"cpp( struct A { @@ -532,10 +511,6 @@ auto Result = NodeIntrospection::GetLocations(CtorInit); - if (Result.LocationAccessors.empty() && Result.RangeAccessors.empty()) { - return; - } - auto ExpectedLocations = FormatExpected(Result.LocationAccessors); @@ -552,6 +527,8 @@ } TEST(Introspection, SourceLocations_CXXCtorInitializer_member) { + if (!NodeIntrospection::hasIntrospectionSupport()) + return; auto AST = buildASTFromCode(R"cpp( struct A { @@ -574,10 +551,6 @@ auto Result = NodeIntrospection::GetLocations(CtorInit); - if (Result.LocationAccessors.empty() && Result.RangeAccessors.empty()) { - return; - } - auto ExpectedLocations = FormatExpected(Result.LocationAccessors); @@ -595,6 +568,8 @@ } TEST(Introspection, SourceLocations_CXXCtorInitializer_ctor) { + if (!NodeIntrospection::hasIntrospectionSupport()) + return; auto AST = buildASTFromCode(R"cpp( struct C { @@ -617,10 +592,6 @@ auto Result = NodeIntrospection::GetLocations(CtorInit); - if (Result.LocationAccessors.empty() && Result.RangeAccessors.empty()) { - return; - } - auto ExpectedLocations = FormatExpected(Result.LocationAccessors); @@ -637,6 +608,8 @@ } TEST(Introspection, SourceLocations_CXXCtorInitializer_pack) { + if (!NodeIntrospection::hasIntrospectionSupport()) + return; auto AST = buildASTFromCodeWithArgs( R"cpp( template @@ -664,10 +637,6 @@ auto Result = NodeIntrospection::GetLocations(CtorInit); - if (Result.LocationAccessors.empty() && Result.RangeAccessors.empty()) { - return; - } - auto ExpectedLocations = FormatExpected(Result.LocationAccessors); @@ -686,6 +655,8 @@ } TEST(Introspection, SourceLocations_CXXBaseSpecifier_plain) { + if (!NodeIntrospection::hasIntrospectionSupport()) + return; auto AST = buildASTFromCode(R"cpp( class A {}; @@ -706,10 +677,6 @@ auto Result = NodeIntrospection::GetLocations(Base); - if (Result.LocationAccessors.empty() && Result.RangeAccessors.empty()) { - return; - } - auto ExpectedLocations = FormatExpected(Result.LocationAccessors); @@ -725,6 +692,8 @@ } TEST(Introspection, SourceLocations_CXXBaseSpecifier_accessspec) { + if (!NodeIntrospection::hasIntrospectionSupport()) + return; auto AST = buildASTFromCode(R"cpp( class A {}; @@ -745,10 +714,6 @@ auto Result = NodeIntrospection::GetLocations(Base); - if (Result.LocationAccessors.empty() && Result.RangeAccessors.empty()) { - return; - } - auto ExpectedLocations = FormatExpected(Result.LocationAccessors); @@ -764,6 +729,8 @@ } TEST(Introspection, SourceLocations_CXXBaseSpecifier_virtual) { + if (!NodeIntrospection::hasIntrospectionSupport()) + return; auto AST = buildASTFromCode(R"cpp( class A {}; @@ -785,10 +752,6 @@ auto Result = NodeIntrospection::GetLocations(Base); - if (Result.LocationAccessors.empty() && Result.RangeAccessors.empty()) { - return; - } - auto ExpectedLocations = FormatExpected(Result.LocationAccessors); @@ -804,6 +767,8 @@ } TEST(Introspection, SourceLocations_CXXBaseSpecifier_template_base) { + if (!NodeIntrospection::hasIntrospectionSupport()) + return; auto AST = buildASTFromCode(R"cpp( template @@ -825,10 +790,6 @@ auto Result = NodeIntrospection::GetLocations(Base); - if (Result.LocationAccessors.empty() && Result.RangeAccessors.empty()) { - return; - } - auto ExpectedLocations = FormatExpected(Result.LocationAccessors); @@ -844,6 +805,8 @@ } TEST(Introspection, SourceLocations_CXXBaseSpecifier_pack) { + if (!NodeIntrospection::hasIntrospectionSupport()) + return; auto AST = buildASTFromCodeWithArgs( R"cpp( template @@ -866,10 +829,6 @@ auto Result = NodeIntrospection::GetLocations(Base); - if (Result.LocationAccessors.empty() && Result.RangeAccessors.empty()) { - return; - } - auto ExpectedLocations = FormatExpected(Result.LocationAccessors);