[clang] 0a3c82e - [clang-format][NFC] Store FormatToken::Type as an enum instead of bitfield
Alex Richardson via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 7 09:18:16 PDT 2020
Author: Alex Richardson
Date: 2020-10-07T17:17:40+01:00
New Revision: 0a3c82e85b73e51e830b57844b2f5b98cb59afd1
URL: https://github.com/llvm/llvm-project/commit/0a3c82e85b73e51e830b57844b2f5b98cb59afd1
DIFF: https://github.com/llvm/llvm-project/commit/0a3c82e85b73e51e830b57844b2f5b98cb59afd1.diff
LOG: [clang-format][NFC] Store FormatToken::Type as an enum instead of bitfield
This improves the debugging experience since LLDB will print the enumerator
name instead of a decimal number. This changes TokenType to have uint8_t
as the underlying type and moves it after the remaining bitfields to avoid
increasing the size of FormatToken.
Reviewed By: MyDeveloperDay
Differential Revision: https://reviews.llvm.org/D87006
Added:
Modified:
clang/lib/Format/FormatToken.h
clang/lib/Format/UnwrappedLineParser.cpp
Removed:
################################################################################
diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index c6af71a768a1a..9cc65bb11b54e 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -118,7 +118,7 @@ namespace format {
/// Determines the semantic type of a syntactic token, e.g. whether "<" is a
/// template opener or binary operator.
-enum TokenType {
+enum TokenType : uint8_t {
#define TYPE(X) TT_##X,
LIST_TOKEN_TYPES
#undef TYPE
@@ -211,8 +211,8 @@ struct FormatToken {
ClosesTemplateDeclaration(false), StartsBinaryExpression(false),
EndsBinaryExpression(false), PartOfMultiVariableDeclStmt(false),
ContinuesLineCommentSection(false), Finalized(false),
- BlockKind(BK_Unknown), Type(TT_Unknown), Decision(FD_Unformatted),
- PackingKind(PPK_Inconclusive) {}
+ BlockKind(BK_Unknown), Decision(FD_Unformatted),
+ PackingKind(PPK_Inconclusive), Type(TT_Unknown) {}
/// The \c Token.
Token Tok;
@@ -297,18 +297,6 @@ struct FormatToken {
assert(getBlockKind() == BBK && "BraceBlockKind overflow!");
}
-private:
- unsigned Type : 8;
-
-public:
- /// Returns the token's type, e.g. whether "<" is a template opener or
- /// binary operator.
- TokenType getType() const { return static_cast<TokenType>(Type); }
- void setType(TokenType T) {
- Type = T;
- assert(getType() == T && "TokenType overflow!");
- }
-
private:
/// Stores the formatting decision for the token once it was made.
unsigned Decision : 2;
@@ -335,6 +323,15 @@ struct FormatToken {
assert(getPackingKind() == K && "ParameterPackingKind overflow!");
}
+private:
+ TokenType Type;
+
+public:
+ /// Returns the token's type, e.g. whether "<" is a template opener or
+ /// binary operator.
+ TokenType getType() const { return Type; }
+ void setType(TokenType T) { Type = T; }
+
/// The number of newlines immediately before the \c Token.
///
/// This can be used to determine what the user wrote in the original code
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp
index b599168b48e17..7075a6fe33f76 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -2753,7 +2753,7 @@ LLVM_ATTRIBUTE_UNUSED static void printDebugInfo(const UnwrappedLine &Line,
E = Line.Tokens.end();
I != E; ++I) {
llvm::dbgs() << I->Tok->Tok.getName() << "["
- << "T=" << I->Tok->getType()
+ << "T=" << (unsigned)I->Tok->getType()
<< ", OC=" << I->Tok->OriginalColumn << "] ";
}
for (std::list<UnwrappedLineNode>::const_iterator I = Line.Tokens.begin(),
More information about the cfe-commits
mailing list