From e26ec09fb3d4d9554a12fd57c688be751abf220f Mon Sep 17 00:00:00 2001 From: Bruno Ricci Date: Tue, 8 Jan 2019 14:44:34 +0000 Subject: [PATCH] [AST][NFC] Pack CXXNoexceptExpr and SubstNonTypeTemplateParmExpr Use the newly available space in the bit-fields of Stmt. This saves one pointer per CXXNoexceptExpr/SubstNonTypeTemplateParmExpr. Use this opportunity to run clang-format on these two classes and fix some style issues. NFC overall. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@350627 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/ExprCXX.h | 55 +++++++++++++++-------------- include/clang/AST/Stmt.h | 21 +++++++++++ lib/Serialization/ASTReaderStmt.cpp | 4 +-- 3 files changed, 51 insertions(+), 29 deletions(-) diff --git a/include/clang/AST/ExprCXX.h b/include/clang/AST/ExprCXX.h index e105f33da7..00e83eb723 100644 --- a/include/clang/AST/ExprCXX.h +++ b/include/clang/AST/ExprCXX.h @@ -3720,7 +3720,6 @@ inline TemplateArgumentLoc *OverloadExpr::getTrailingTemplateArgumentLoc() { class CXXNoexceptExpr : public Expr { friend class ASTStmtReader; - bool Value : 1; Stmt *Operand; SourceRange Range; @@ -3728,21 +3727,23 @@ public: CXXNoexceptExpr(QualType Ty, Expr *Operand, CanThrowResult Val, SourceLocation Keyword, SourceLocation RParen) : Expr(CXXNoexceptExprClass, Ty, VK_RValue, OK_Ordinary, - /*TypeDependent*/false, - /*ValueDependent*/Val == CT_Dependent, + /*TypeDependent*/ false, + /*ValueDependent*/ Val == CT_Dependent, Val == CT_Dependent || Operand->isInstantiationDependent(), Operand->containsUnexpandedParameterPack()), - Value(Val == CT_Cannot), Operand(Operand), Range(Keyword, RParen) {} + Operand(Operand), Range(Keyword, RParen) { + CXXNoexceptExprBits.Value = Val == CT_Cannot; + } CXXNoexceptExpr(EmptyShell Empty) : Expr(CXXNoexceptExprClass, Empty) {} - Expr *getOperand() const { return static_cast(Operand); } + Expr *getOperand() const { return static_cast(Operand); } - SourceLocation getBeginLoc() const LLVM_READONLY { return Range.getBegin(); } - SourceLocation getEndLoc() const LLVM_READONLY { return Range.getEnd(); } - SourceRange getSourceRange() const LLVM_READONLY { return Range; } + SourceLocation getBeginLoc() const { return Range.getBegin(); } + SourceLocation getEndLoc() const { return Range.getEnd(); } + SourceRange getSourceRange() const { return Range; } - bool getValue() const { return Value; } + bool getValue() const { return CXXNoexceptExprBits.Value; } static bool classof(const Stmt *T) { return T->getStmtClass() == CXXNoexceptExprClass; @@ -3965,27 +3966,27 @@ class SubstNonTypeTemplateParmExpr : public Expr { /// The replacement expression. Stmt *Replacement; - /// The location of the non-type template parameter reference. - SourceLocation NameLoc; - explicit SubstNonTypeTemplateParmExpr(EmptyShell Empty) : Expr(SubstNonTypeTemplateParmExprClass, Empty) {} public: - SubstNonTypeTemplateParmExpr(QualType type, - ExprValueKind valueKind, - SourceLocation loc, - NonTypeTemplateParmDecl *param, - Expr *replacement) - : Expr(SubstNonTypeTemplateParmExprClass, type, valueKind, OK_Ordinary, - replacement->isTypeDependent(), replacement->isValueDependent(), - replacement->isInstantiationDependent(), - replacement->containsUnexpandedParameterPack()), - Param(param), Replacement(replacement), NameLoc(loc) {} - - SourceLocation getNameLoc() const { return NameLoc; } - SourceLocation getBeginLoc() const LLVM_READONLY { return NameLoc; } - SourceLocation getEndLoc() const LLVM_READONLY { return NameLoc; } + SubstNonTypeTemplateParmExpr(QualType Ty, ExprValueKind ValueKind, + SourceLocation Loc, + NonTypeTemplateParmDecl *Param, + Expr *Replacement) + : Expr(SubstNonTypeTemplateParmExprClass, Ty, ValueKind, OK_Ordinary, + Replacement->isTypeDependent(), Replacement->isValueDependent(), + Replacement->isInstantiationDependent(), + Replacement->containsUnexpandedParameterPack()), + Param(Param), Replacement(Replacement) { + SubstNonTypeTemplateParmExprBits.NameLoc = Loc; + } + + SourceLocation getNameLoc() const { + return SubstNonTypeTemplateParmExprBits.NameLoc; + } + SourceLocation getBeginLoc() const { return getNameLoc(); } + SourceLocation getEndLoc() const { return getNameLoc(); } Expr *getReplacement() const { return cast(Replacement); } @@ -3996,7 +3997,7 @@ public: } // Iterators - child_range children() { return child_range(&Replacement, &Replacement+1); } + child_range children() { return child_range(&Replacement, &Replacement + 1); } }; /// Represents a reference to a non-type template parameter pack that diff --git a/include/clang/AST/Stmt.h b/include/clang/AST/Stmt.h index 792f96e6a1..e11e319703 100644 --- a/include/clang/AST/Stmt.h +++ b/include/clang/AST/Stmt.h @@ -760,6 +760,25 @@ protected: SourceLocation OperatorLoc; }; + class CXXNoexceptExprBitfields { + friend class ASTStmtReader; + friend class CXXNoexceptExpr; + + unsigned : NumExprBits; + + unsigned Value : 1; + }; + + class SubstNonTypeTemplateParmExprBitfields { + friend class ASTStmtReader; + friend class SubstNonTypeTemplateParmExpr; + + unsigned : NumExprBits; + + /// The location of the non-type template parameter reference. + SourceLocation NameLoc; + }; + //===--- C++ Coroutines TS bitfields classes ---===// class CoawaitExprBitfields { @@ -848,6 +867,8 @@ protected: ExprWithCleanupsBitfields ExprWithCleanupsBits; CXXUnresolvedConstructExprBitfields CXXUnresolvedConstructExprBits; CXXDependentScopeMemberExprBitfields CXXDependentScopeMemberExprBits; + CXXNoexceptExprBitfields CXXNoexceptExprBits; + SubstNonTypeTemplateParmExprBitfields SubstNonTypeTemplateParmExprBits; // C++ Coroutines TS expressions CoawaitExprBitfields CoawaitBits; diff --git a/lib/Serialization/ASTReaderStmt.cpp b/lib/Serialization/ASTReaderStmt.cpp index 53eb5bcf38..edaaef0033 100644 --- a/lib/Serialization/ASTReaderStmt.cpp +++ b/lib/Serialization/ASTReaderStmt.cpp @@ -1719,7 +1719,7 @@ void ASTStmtReader::VisitExpressionTraitExpr(ExpressionTraitExpr *E) { void ASTStmtReader::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) { VisitExpr(E); - E->Value = (bool)Record.readInt(); + E->CXXNoexceptExprBits.Value = Record.readInt(); E->Range = ReadSourceRange(); E->Operand = Record.readSubExpr(); } @@ -1753,7 +1753,7 @@ void ASTStmtReader::VisitSubstNonTypeTemplateParmExpr( SubstNonTypeTemplateParmExpr *E) { VisitExpr(E); E->Param = ReadDeclAs(); - E->NameLoc = ReadSourceLocation(); + E->SubstNonTypeTemplateParmExprBits.NameLoc = ReadSourceLocation(); E->Replacement = Record.readSubExpr(); } -- 2.40.0