aeubanks created this revision. Herald added a project: All. aeubanks requested review of this revision. Herald added projects: clang, LLDB. Herald added subscribers: lldb-commits, cfe-commits.
Followup to D134378 <https://reviews.llvm.org/D134378>. With PrintingPolicy::SuppressScope, we'd also not print the scope in template params. The intention was only to skip the scope for the class because we expect template params to be fully qualified when comparing them for simple template names. Add a PrintingPolicy::NoSuppressTemplateParamsScope which disables SuppressScope for template params. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D137583 Files: clang/include/clang/AST/PrettyPrinter.h clang/lib/AST/TypePrinter.cpp lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp lldb/test/API/lang/cpp/unique-types2/TestUniqueTypes.py lldb/test/API/lang/cpp/unique-types2/main.cpp
Index: lldb/test/API/lang/cpp/unique-types2/main.cpp =================================================================== --- lldb/test/API/lang/cpp/unique-types2/main.cpp +++ lldb/test/API/lang/cpp/unique-types2/main.cpp @@ -1,3 +1,7 @@ +namespace ns { +struct Bar {}; +} // namespace ns + template <class T> struct Foo { T t; template <class U> class Nested { @@ -23,5 +27,6 @@ FooPack<int, int, int> p7; Foo<int>::Nested<char> n1; + Foo<int>::Nested<ns::Bar> n2; // Set breakpoint here } Index: lldb/test/API/lang/cpp/unique-types2/TestUniqueTypes.py =================================================================== --- lldb/test/API/lang/cpp/unique-types2/TestUniqueTypes.py +++ lldb/test/API/lang/cpp/unique-types2/TestUniqueTypes.py @@ -36,6 +36,7 @@ self.expect("image lookup -A -t 'Foo<int>::Nested<int>'", DATA_TYPES_DISPLAYED_CORRECTLY, error=True) self.expect("image lookup -A -t 'Nested<char>'", DATA_TYPES_DISPLAYED_CORRECTLY, substrs=["1 match found"]) self.expect("image lookup -A -t '::Nested<char>'", DATA_TYPES_DISPLAYED_CORRECTLY, error=True) + self.expect("image lookup -A -t 'Foo<int>::Nested<ns::Bar>'", DATA_TYPES_DISPLAYED_CORRECTLY, substrs=["1 match found"]) self.expect_expr("t1", result_type="Foo<char>") self.expect_expr("t1", result_type="Foo<char>") @@ -49,6 +50,7 @@ self.expect_expr("p6", result_type="FooPack<int, int>") self.expect_expr("p7", result_type="FooPack<int, int, int>") self.expect_expr("n1", result_type="Foo<int>::Nested<char>") + self.expect_expr("n2", result_type="Foo<int>::Nested<ns::Bar>") @skipIf(compiler=no_match("clang")) @skipIf(compiler_version=["<", "15.0"]) Index: lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp =================================================================== --- lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp +++ lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp @@ -3792,6 +3792,7 @@ clang::PrintingPolicy printing_policy(GetTypePrintingPolicy()); printing_policy.SuppressScope = BaseOnly; + printing_policy.NoSuppressTemplateParamsScope = BaseOnly; return ConstString(qual_type.getAsString(printing_policy)); } Index: clang/lib/AST/TypePrinter.cpp =================================================================== --- clang/lib/AST/TypePrinter.cpp +++ clang/lib/AST/TypePrinter.cpp @@ -110,6 +110,23 @@ } }; +class NoSuppressTemplateParamsScopeRAII { + PrintingPolicy &Policy; + bool OldSuppressScope; + +public: + explicit NoSuppressTemplateParamsScopeRAII(PrintingPolicy &Policy) + : Policy(Policy) { + OldSuppressScope = Policy.SuppressScope; + if (Policy.NoSuppressTemplateParamsScope) + Policy.SuppressScope = false; + } + + ~NoSuppressTemplateParamsScopeRAII() { + Policy.SuppressScope = OldSuppressScope; + } +}; + class TypePrinter { PrintingPolicy Policy; unsigned Indentation; @@ -1370,6 +1387,7 @@ // If this is a class template specialization, print the template // arguments. if (const auto *Spec = dyn_cast<ClassTemplateSpecializationDecl>(D)) { + NoSuppressTemplateParamsScopeRAII SuppressScopeRAII(Policy); ArrayRef<TemplateArgument> Args; TypeSourceInfo *TAW = Spec->getTypeAsWritten(); if (!Policy.PrintCanonicalTypes && TAW) { Index: clang/include/clang/AST/PrettyPrinter.h =================================================================== --- clang/include/clang/AST/PrettyPrinter.h +++ clang/include/clang/AST/PrettyPrinter.h @@ -130,6 +130,9 @@ /// Suppresses printing of scope specifiers. unsigned SuppressScope : 1; + /// When SuppressScope is true, do not apply it to template parameters. + unsigned NoSuppressTemplateParamsScope : 1; + /// Suppress printing parts of scope specifiers that are never /// written, e.g., for anonymous namespaces. unsigned SuppressUnwrittenScope : 1;
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits