Skip to content

Commit 660e65c

Browse files
committed
fixup! turn SuppressTagKeywordInAnonymousTagNames into an SuppressTagKeyword enum case
1 parent 700ea0d commit 660e65c

File tree

3 files changed

+24
-14
lines changed

3 files changed

+24
-14
lines changed

clang/include/clang/AST/PrettyPrinter.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,19 @@ class PrintingCallbacks {
5757
/// It is very frequently copied.
5858
struct PrintingPolicy {
5959
enum class SuppressInlineNamespaceMode : uint8_t { None, Redundant, All };
60-
enum class SuppressTagKeywordMode : uint8_t { None, InElaboratedNames };
60+
enum class SuppressTagKeywordMode : uint8_t {
61+
None,
62+
InAnonNames,
63+
InElaboratedNames,
64+
All
65+
};
6166

6267
/// Create a default printing policy for the specified language.
6368
PrintingPolicy(const LangOptions &LO)
6469
: Indentation(2), SuppressSpecifiers(false),
6570
SuppressTagKeyword(llvm::to_underlying(
6671
LO.CPlusPlus ? SuppressTagKeywordMode::InElaboratedNames
6772
: SuppressTagKeywordMode::None)),
68-
SuppressTagKeywordInAnonymousTagNames(false),
6973
IncludeTagDefinition(false), SuppressScope(false),
7074
SuppressUnwrittenScope(false),
7175
SuppressInlineNamespace(
@@ -128,8 +132,7 @@ struct PrintingPolicy {
128132
/// struct Geometry::Point;
129133
/// \endcode
130134
LLVM_PREFERRED_TYPE(SuppressTagKeywordMode)
131-
unsigned SuppressTagKeyword : 1;
132-
unsigned SuppressTagKeywordInAnonymousTagNames : 1;
135+
unsigned SuppressTagKeyword : 2;
133136

134137
/// When true, include the body of a tag definition.
135138
///

clang/lib/AST/Decl.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1799,8 +1799,8 @@ void NamedDecl::printNestedNameSpecifier(raw_ostream &OS,
17991799
//
18001800
// I.e., suppress tag locations, suppress leading keyword, *don't*
18011801
// suppress tag in name
1802-
Copy.SuppressTagKeyword = true;
1803-
Copy.SuppressTagKeywordInAnonymousTagNames = false;
1802+
Copy.SuppressTagKeyword = llvm::to_underlying(
1803+
PrintingPolicy::SuppressTagKeywordMode::InElaboratedNames);
18041804
Copy.AnonymousTagLocations = false;
18051805
RD->printName(OS, Copy);
18061806
} else if (const auto *FD = dyn_cast<FunctionDecl>(DC)) {
@@ -4969,11 +4969,18 @@ void TagDecl::printAnonymousTagDecl(llvm::raw_ostream &OS,
49694969
return;
49704970
}
49714971

4972-
bool SuppressTagKeywordInName = Policy.SuppressTagKeywordInAnonymousTagNames;
4972+
bool SuppressTagKeywordInName =
4973+
(Policy.SuppressTagKeyword ==
4974+
llvm::to_underlying(
4975+
PrintingPolicy::SuppressTagKeywordMode::InAnonNames)) ||
4976+
(Policy.SuppressTagKeyword ==
4977+
llvm::to_underlying(PrintingPolicy::SuppressTagKeywordMode::All));
49734978

49744979
// Emit leading keyword. Since we printed a leading keyword make sure we
49754980
// don't print the tag as part of the name too.
4976-
if (!Policy.SuppressTagKeyword) {
4981+
if (Policy.SuppressTagKeyword <
4982+
llvm::to_underlying(
4983+
PrintingPolicy::SuppressTagKeywordMode::InElaboratedNames)) {
49774984
OS << getKindName() << ' ';
49784985
SuppressTagKeywordInName = true;
49794986
}

clang/lib/AST/TypePrinter.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1523,8 +1523,9 @@ void TypePrinter::printTagType(const TagType *T, raw_ostream &OS) {
15231523

15241524
bool PrintedKindDecoration = false;
15251525
if (T->isCanonicalUnqualified()) {
1526-
if (Policy.SuppressTagKeyword ==
1527-
llvm::to_underlying(PrintingPolicy::SuppressTagKeywordMode::None) &&
1526+
if (Policy.SuppressTagKeyword <
1527+
llvm::to_underlying(
1528+
PrintingPolicy::SuppressTagKeywordMode::InElaboratedNames) &&
15281529
!D->getTypedefNameForAnonDecl()) {
15291530
PrintedKindDecoration = true;
15301531
OS << D->getKindName();
@@ -1553,10 +1554,9 @@ void TypePrinter::printTagType(const TagType *T, raw_ostream &OS) {
15531554
clang::PrintingPolicy Copy(Policy);
15541555

15551556
// Suppress the redundant tag keyword if we just printed one.
1556-
if (PrintedKindDecoration) {
1557-
Copy.SuppressTagKeywordInAnonymousTagNames = true;
1558-
Copy.SuppressTagKeyword = true;
1559-
}
1557+
if (PrintedKindDecoration)
1558+
Copy.SuppressTagKeyword =
1559+
llvm::to_underlying(PrintingPolicy::SuppressTagKeywordMode::All);
15601560

15611561
D->printName(OS, Copy);
15621562
}

0 commit comments

Comments
 (0)