arichardson created this revision. arichardson added reviewers: MyDeveloperDay, JakeMerdichAMD, sammccall, curdeius. Herald added a project: clang. Herald added a subscriber: cfe-commits. arichardson requested review of this revision.
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. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D87006 Files: clang/lib/Format/FormatToken.h clang/lib/Format/UnwrappedLineParser.cpp Index: clang/lib/Format/UnwrappedLineParser.cpp =================================================================== --- clang/lib/Format/UnwrappedLineParser.cpp +++ clang/lib/Format/UnwrappedLineParser.cpp @@ -2753,7 +2753,7 @@ 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(), Index: clang/lib/Format/FormatToken.h =================================================================== --- clang/lib/Format/FormatToken.h +++ clang/lib/Format/FormatToken.h @@ -118,7 +118,7 @@ /// 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 @@ -149,8 +149,8 @@ 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; @@ -233,18 +233,6 @@ 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; @@ -271,6 +259,18 @@ 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 static_cast<TokenType>(Type); } + void setType(TokenType T) { + Type = T; + assert(getType() == T && "TokenType overflow!"); + } + /// The number of newlines immediately before the \c Token. /// /// This can be used to determine what the user wrote in the original code
Index: clang/lib/Format/UnwrappedLineParser.cpp =================================================================== --- clang/lib/Format/UnwrappedLineParser.cpp +++ clang/lib/Format/UnwrappedLineParser.cpp @@ -2753,7 +2753,7 @@ 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(), Index: clang/lib/Format/FormatToken.h =================================================================== --- clang/lib/Format/FormatToken.h +++ clang/lib/Format/FormatToken.h @@ -118,7 +118,7 @@ /// 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 @@ -149,8 +149,8 @@ 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; @@ -233,18 +233,6 @@ 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; @@ -271,6 +259,18 @@ 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 static_cast<TokenType>(Type); } + void setType(TokenType T) { + Type = T; + assert(getType() == T && "TokenType overflow!"); + } + /// The number of newlines immediately before the \c Token. /// /// This can be used to determine what the user wrote in the original code
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits