diff options
author | Alp Toker <alp@nuanti.com> | 2014-01-01 05:57:51 +0000 |
---|---|---|
committer | Alp Toker <alp@nuanti.com> | 2014-01-01 05:57:51 +0000 |
commit | 12e1f5dc4f3636eab2b7e5038bbe1d34014c2b71 (patch) | |
tree | 39aba27e167e239e00dc023a13afd8cef6985d0b /lib/Sema | |
parent | ca70f4fa1c4eae6a47c97c773b8e63803a43a90c (diff) | |
download | clang-12e1f5dc4f3636eab2b7e5038bbe1d34014c2b71.tar.gz |
Eliminate UnaryTypeTraitExpr
Remove UnaryTypeTraitExpr and switch all remaining type trait related handling
over to TypeTraitExpr.
The UTT/BTT/TT enum prefix and evaluation code is retained pending further
cleanup.
This is part of the ongoing work to unify type traits following the removal of
BinaryTypeTraitExpr in r197273.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@198271 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema')
-rw-r--r-- | lib/Sema/SemaExceptionSpec.cpp | 1 | ||||
-rw-r--r-- | lib/Sema/SemaExpr.cpp | 2 | ||||
-rw-r--r-- | lib/Sema/SemaExprCXX.cpp | 44 | ||||
-rw-r--r-- | lib/Sema/TreeTransform.h | 28 |
4 files changed, 12 insertions, 63 deletions
diff --git a/lib/Sema/SemaExceptionSpec.cpp b/lib/Sema/SemaExceptionSpec.cpp index 72ff109af7..81fd3f9631 100644 --- a/lib/Sema/SemaExceptionSpec.cpp +++ b/lib/Sema/SemaExceptionSpec.cpp @@ -1085,7 +1085,6 @@ CanThrowResult Sema::canThrow(const Expr *E) { case Expr::PredefinedExprClass: case Expr::SizeOfPackExprClass: case Expr::StringLiteralClass: - case Expr::UnaryTypeTraitExprClass: // These expressions can never throw. return CT_Cannot; diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 5fd65f53f4..aa9d6947cb 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -3290,7 +3290,7 @@ static void warnOnSizeofOnArrayDecay(Sema &S, SourceLocation Loc, QualType T, << ICE->getSubExpr()->getType(); } -/// \brief Check the constrains on expression operands to unary type expression +/// \brief Check the constraints on expression operands to unary type expression /// and type traits. /// /// Completes any types necessary and validates the constraints on the operand diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp index 2591dbfede..b73c453ae4 100644 --- a/lib/Sema/SemaExprCXX.cpp +++ b/lib/Sema/SemaExprCXX.cpp @@ -3082,26 +3082,13 @@ Sema::PerformImplicitConversion(Expr *From, QualType ToType, return Owned(From); } -ExprResult Sema::ActOnUnaryTypeTrait(UnaryTypeTrait UTT, - SourceLocation KWLoc, - ParsedType Ty, - SourceLocation RParen) { - TypeSourceInfo *TSInfo; - QualType T = GetTypeFromParser(Ty, &TSInfo); - - if (!TSInfo) - TSInfo = Context.getTrivialTypeSourceInfo(T); - return BuildUnaryTypeTrait(UTT, KWLoc, TSInfo, RParen); -} - /// \brief Check the completeness of a type in a unary type trait. /// /// If the particular type trait requires a complete type, tries to complete /// it. If completing the type fails, a diagnostic is emitted and false /// returned. If completing the type succeeds or no completion was required, /// returns true. -static bool CheckUnaryTypeTraitTypeCompleteness(Sema &S, - UnaryTypeTrait UTT, +static bool CheckUnaryTypeTraitTypeCompleteness(Sema &S, TypeTrait UTT, SourceLocation Loc, QualType ArgTy) { // C++0x [meta.unary.prop]p3: @@ -3114,6 +3101,7 @@ static bool CheckUnaryTypeTraitTypeCompleteness(Sema &S, // these class templates. We also try to follow any GCC documented behavior // in these expressions to ensure portability of standard libraries. switch (UTT) { + default: llvm_unreachable("not a UTT"); // is_complete_type somewhat obviously cannot require a complete type. case UTT_IsCompleteType: // Fall-through @@ -3200,7 +3188,6 @@ static bool CheckUnaryTypeTraitTypeCompleteness(Sema &S, return !S.RequireCompleteType( Loc, ElTy, diag::err_incomplete_type_used_in_type_trait_expr); } - llvm_unreachable("Type trait not handled by switch"); } static bool HasNoThrowOperator(const RecordType *RT, OverloadedOperatorKind Op, @@ -3239,12 +3226,13 @@ static bool HasNoThrowOperator(const RecordType *RT, OverloadedOperatorKind Op, return false; } -static bool EvaluateUnaryTypeTrait(Sema &Self, UnaryTypeTrait UTT, +static bool EvaluateUnaryTypeTrait(Sema &Self, TypeTrait UTT, SourceLocation KeyLoc, QualType T) { assert(!T->isDependentType() && "Cannot evaluate traits of dependent type"); ASTContext &C = Self.Context; switch(UTT) { + default: llvm_unreachable("not a UTT"); // Type trait expressions corresponding to the primary type category // predicates in C++0x [meta.unary.cat]. case UTT_IsVoid: @@ -3576,23 +3564,6 @@ static bool EvaluateUnaryTypeTrait(Sema &Self, UnaryTypeTrait UTT, // function call. return !T->isIncompleteType(); } - llvm_unreachable("Type trait not covered by switch"); -} - -ExprResult Sema::BuildUnaryTypeTrait(UnaryTypeTrait UTT, - SourceLocation KWLoc, - TypeSourceInfo *TSInfo, - SourceLocation RParen) { - QualType T = TSInfo->getType(); - if (!CheckUnaryTypeTraitTypeCompleteness(*this, UTT, KWLoc, T)) - return ExprError(); - - bool Value = false; - if (!T->isDependentType()) - Value = EvaluateUnaryTypeTrait(*this, UTT, KWLoc, T); - - return Owned(new (Context) UnaryTypeTraitExpr(KWLoc, UTT, TSInfo, Value, - RParen, Context.BoolTy)); } /// \brief Determine whether T has a non-trivial Objective-C lifetime in @@ -3620,6 +3591,9 @@ static bool EvaluateBinaryTypeTrait(Sema &Self, TypeTrait BTT, QualType LhsT, static bool evaluateTypeTrait(Sema &S, TypeTrait Kind, SourceLocation KWLoc, ArrayRef<TypeSourceInfo *> Args, SourceLocation RParenLoc) { + if (Kind <= UTT_Last) + return EvaluateUnaryTypeTrait(S, Kind, KWLoc, Args[0]->getType()); + if (Kind <= BTT_Last) return EvaluateBinaryTypeTrait(S, Kind, Args[0]->getType(), Args[1]->getType(), RParenLoc); @@ -3709,6 +3683,10 @@ ExprResult Sema::BuildTypeTrait(TypeTrait Kind, SourceLocation KWLoc, SourceLocation RParenLoc) { QualType ResultType = Context.getLogicalOperationType(); + if (Kind <= UTT_Last && !CheckUnaryTypeTraitTypeCompleteness( + *this, Kind, KWLoc, Args[0]->getType())) + return ExprError(); + bool Dependent = false; for (unsigned I = 0, N = Args.size(); I != N; ++I) { if (Args[I]->getType()->isDependentType()) { diff --git a/lib/Sema/TreeTransform.h b/lib/Sema/TreeTransform.h index 8c7838e6a7..36a6520fcd 100644 --- a/lib/Sema/TreeTransform.h +++ b/lib/Sema/TreeTransform.h @@ -2135,17 +2135,6 @@ public: Operand); } - /// \brief Build a new unary type trait expression. - /// - /// By default, performs semantic analysis to build the new expression. - /// Subclasses may override this routine to provide different behavior. - ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait, - SourceLocation StartLoc, - TypeSourceInfo *T, - SourceLocation RParenLoc) { - return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc); - } - /// \brief Build a new type trait expression. /// /// By default, performs semantic analysis to build the new expression. @@ -7866,23 +7855,6 @@ TreeTransform<Derived>::TransformUnresolvedLookupExpr( template<typename Derived> ExprResult -TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) { - TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo()); - if (!T) - return ExprError(); - - if (!getDerived().AlwaysRebuild() && - T == E->getQueriedTypeSourceInfo()) - return SemaRef.Owned(E); - - return getDerived().RebuildUnaryTypeTrait(E->getTrait(), - E->getLocStart(), - T, - E->getLocEnd()); -} - -template<typename Derived> -ExprResult TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) { bool ArgChanged = false; SmallVector<TypeSourceInfo *, 4> Args; |