Skip to content

Commit 482b7d8

Browse files
Michael137github-actions[bot]
authored andcommitted
Automerge: [clang][TypePrinter][NFC] Make SuppressInlineNamespaceMode an enum class (#170802)
The enum cases for `SuppressInlineNamespaceMode` leaked into the rest of `PrintingPolicy`, meaning if we wanted to introduce another enum (which I'm planning on doing in an unrelated PR), then `All`/`None`/`Redundant` are all already taken, which are quite useful names. This patch turns `SuppressInlineNamespaceMode` into an `enum class`, freeing up the names for use by other future enums in `PrintingPolicy`. Unfortunately that means we have to cast the values when assigning to `PrintingPolicy::SuppressInlineNamespace`, because its actual type is `unsigned`. But if we ever make the bitfields have proper enumeration types (which AFAIU is dependent on an MSVC codegen fix), then we can get rid of those casts. While doing this I found three instances of assigning booleans to `SuppressInlineNamespace`. I added a FIXME in LLDB to check what the intended value of the enum should be.
2 parents 33382d9 + 6dac9b4 commit 482b7d8

File tree

7 files changed

+19
-11
lines changed

7 files changed

+19
-11
lines changed

clang/include/clang/AST/PrettyPrinter.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#include "clang/Basic/LLVM.h"
1717
#include "clang/Basic/LangOptions.h"
18+
#include "llvm/ADT/STLForwardCompat.h"
1819

1920
namespace clang {
2021

@@ -55,14 +56,15 @@ class PrintingCallbacks {
5556
/// This type is intended to be small and suitable for passing by value.
5657
/// It is very frequently copied.
5758
struct PrintingPolicy {
58-
enum SuppressInlineNamespaceMode : uint8_t { None, Redundant, All };
59+
enum class SuppressInlineNamespaceMode : uint8_t { None, Redundant, All };
5960

6061
/// Create a default printing policy for the specified language.
6162
PrintingPolicy(const LangOptions &LO)
6263
: Indentation(2), SuppressSpecifiers(false),
6364
SuppressTagKeyword(LO.CPlusPlus), IncludeTagDefinition(false),
6465
SuppressScope(false), SuppressUnwrittenScope(false),
65-
SuppressInlineNamespace(SuppressInlineNamespaceMode::Redundant),
66+
SuppressInlineNamespace(
67+
llvm::to_underlying(SuppressInlineNamespaceMode::Redundant)),
6668
SuppressInitializers(false), ConstantArraySizeAsWritten(false),
6769
AnonymousTagLocations(true), SuppressStrongLifetime(false),
6870
SuppressLifetimeQualifiers(false),

clang/lib/AST/Decl.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1753,9 +1753,11 @@ void NamedDecl::printNestedNameSpecifier(raw_ostream &OS,
17531753
// Suppress inline namespace if it doesn't make the result ambiguous.
17541754
if (Ctx->isInlineNamespace() && NameInScope) {
17551755
if (P.SuppressInlineNamespace ==
1756-
PrintingPolicy::SuppressInlineNamespaceMode::All ||
1756+
llvm::to_underlying(
1757+
PrintingPolicy::SuppressInlineNamespaceMode::All) ||
17571758
(P.SuppressInlineNamespace ==
1758-
PrintingPolicy::SuppressInlineNamespaceMode::Redundant &&
1759+
llvm::to_underlying(
1760+
PrintingPolicy::SuppressInlineNamespaceMode::Redundant) &&
17591761
cast<NamespaceDecl>(Ctx)->isRedundantInlineQualifierFor(
17601762
NameInScope))) {
17611763
continue;

clang/lib/ASTMatchers/ASTMatchersInternal.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -654,9 +654,9 @@ bool HasNameMatcher::matchesNodeFullSlow(const NamedDecl &Node) const {
654654

655655
PrintingPolicy Policy = Node.getASTContext().getPrintingPolicy();
656656
Policy.SuppressUnwrittenScope = SkipUnwritten;
657-
Policy.SuppressInlineNamespace =
657+
Policy.SuppressInlineNamespace = llvm::to_underlying(
658658
SkipUnwritten ? PrintingPolicy::SuppressInlineNamespaceMode::All
659-
: PrintingPolicy::SuppressInlineNamespaceMode::None;
659+
: PrintingPolicy::SuppressInlineNamespaceMode::None);
660660
Node.printQualifiedName(OS, Policy);
661661

662662
const StringRef FullName = OS.str();

clang/lib/CIR/CodeGen/CIRGenTypes.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ std::string CIRGenTypes::getRecordTypeName(const clang::RecordDecl *recordDecl,
9797
llvm::raw_svector_ostream outStream(typeName);
9898

9999
PrintingPolicy policy = recordDecl->getASTContext().getPrintingPolicy();
100-
policy.SuppressInlineNamespace = false;
100+
policy.SuppressInlineNamespace =
101+
llvm::to_underlying(PrintingPolicy::SuppressInlineNamespaceMode::None);
101102
policy.AlwaysIncludeTypeForTemplateArgument = true;
102103
policy.PrintAsCanonical = true;
103104
policy.SuppressTagKeyword = true;

clang/lib/CodeGen/CGDebugInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ PrintingPolicy CGDebugInfo::getPrintingPolicy() const {
417417
}
418418

419419
PP.SuppressInlineNamespace =
420-
PrintingPolicy::SuppressInlineNamespaceMode::None;
420+
llvm::to_underlying(PrintingPolicy::SuppressInlineNamespaceMode::None);
421421
PP.PrintAsCanonical = true;
422422
PP.UsePreferredNames = false;
423423
PP.AlwaysIncludeTypeForTemplateArgument = true;

clang/lib/CodeGen/CodeGenTypes.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ void CodeGenTypes::addRecordTypeName(const RecordDecl *RD,
6262
// FullyQualifiedNames.
6363
PrintingPolicy Policy = RD->getASTContext().getPrintingPolicy();
6464
Policy.SuppressInlineNamespace =
65-
PrintingPolicy::SuppressInlineNamespaceMode::None;
65+
llvm::to_underlying(PrintingPolicy::SuppressInlineNamespaceMode::None);
6666

6767
// Name the codegen type after the typedef name
6868
// if there is no tag type name available

lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2149,7 +2149,8 @@ PrintingPolicy TypeSystemClang::GetTypePrintingPolicy() {
21492149
printing_policy.SuppressTagKeyword = true;
21502150
// Inline namespaces are important for some type formatters (e.g., libc++
21512151
// and libstdc++ are differentiated by their inline namespaces).
2152-
printing_policy.SuppressInlineNamespace = false;
2152+
printing_policy.SuppressInlineNamespace =
2153+
llvm::to_underlying(PrintingPolicy::SuppressInlineNamespaceMode::None);
21532154
printing_policy.SuppressUnwrittenScope = false;
21542155
// Default arguments are also always important for type formatters. Otherwise
21552156
// we would need to always specify two type names for the setups where we do
@@ -3870,7 +3871,9 @@ TypeSystemClang::GetDisplayTypeName(lldb::opaque_compiler_type_t type) {
38703871
printing_policy.SuppressTagKeyword = true;
38713872
printing_policy.SuppressScope = false;
38723873
printing_policy.SuppressUnwrittenScope = true;
3873-
printing_policy.SuppressInlineNamespace = true;
3874+
// FIXME: should we suppress "All" inline namespaces?
3875+
printing_policy.SuppressInlineNamespace = llvm::to_underlying(
3876+
PrintingPolicy::SuppressInlineNamespaceMode::Redundant);
38743877
return ConstString(qual_type.getAsString(printing_policy));
38753878
}
38763879

0 commit comments

Comments
 (0)