From 525b76b59cd335af2e16c0c1b5be1cad22745d05 Mon Sep 17 00:00:00 2001 From: Anders Carlsson Date: Fri, 16 Oct 2009 02:48:28 +0000 Subject: Make CheckVectorCast return a CastKind. Reduce nesting of if statements in CheckCastTypes. llvm-svn: 84242 --- clang/lib/Sema/SemaExpr.cpp | 50 ++++++++++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 19 deletions(-) (limited to 'clang/lib/Sema/SemaExpr.cpp') diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 279f50b9a71..b9983853984 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -3170,7 +3170,10 @@ bool Sema::CheckCastTypes(SourceRange TyR, QualType castType, Expr *&castExpr, Diag(TyR.getBegin(), diag::ext_typecheck_cast_nonscalar) << castType << castExpr->getSourceRange(); Kind = CastExpr::CK_NoOp; - } else if (castType->isUnionType()) { + return false; + } + + if (castType->isUnionType()) { // GCC cast to union extension RecordDecl *RD = castType->getAs()->getDecl(); RecordDecl::field_iterator Field, FieldEnd; @@ -3187,28 +3190,35 @@ bool Sema::CheckCastTypes(SourceRange TyR, QualType castType, Expr *&castExpr, return Diag(TyR.getBegin(), diag::err_typecheck_cast_to_union_no_type) << castExpr->getType() << castExpr->getSourceRange(); Kind = CastExpr::CK_ToUnion; - } else { - // Reject any other conversions to non-scalar types. - return Diag(TyR.getBegin(), diag::err_typecheck_cond_expect_scalar) - << castType << castExpr->getSourceRange(); + return false; } - } else if (!castExpr->getType()->isScalarType() && - !castExpr->getType()->isVectorType()) { + + // Reject any other conversions to non-scalar types. + return Diag(TyR.getBegin(), diag::err_typecheck_cond_expect_scalar) + << castType << castExpr->getSourceRange(); + } + + if (!castExpr->getType()->isScalarType() && + !castExpr->getType()->isVectorType()) { return Diag(castExpr->getLocStart(), diag::err_typecheck_expect_scalar_operand) << castExpr->getType() << castExpr->getSourceRange(); - } else if (castType->isExtVectorType()) { - if (CheckExtVectorCast(TyR, castType, castExpr->getType())) - return true; - } else if (castType->isVectorType()) { - if (CheckVectorCast(TyR, castType, castExpr->getType())) - return true; - } else if (castExpr->getType()->isVectorType()) { - if (CheckVectorCast(TyR, castExpr->getType(), castType)) - return true; - } else if (getLangOptions().ObjC1 && isa(castExpr)) { + } + + if (castType->isExtVectorType()) { + // FIXME: Set the cast kind. + return CheckExtVectorCast(TyR, castType, castExpr->getType()); + } + + if (castType->isVectorType()) + return CheckVectorCast(TyR, castType, castExpr->getType(), Kind); + if (castExpr->getType()->isVectorType()) + return CheckVectorCast(TyR, castExpr->getType(), castType, Kind); + + if (getLangOptions().ObjC1 && isa(castExpr)) return Diag(castExpr->getLocStart(), diag::err_illegal_super_cast) << TyR; - } else if (!castType->isArithmeticType()) { + + if (!castType->isArithmeticType()) { QualType castExprType = castExpr->getType(); if (!castExprType->isIntegralType() && castExprType->isArithmeticType()) return Diag(castExpr->getLocStart(), @@ -3225,7 +3235,8 @@ bool Sema::CheckCastTypes(SourceRange TyR, QualType castType, Expr *&castExpr, return false; } -bool Sema::CheckVectorCast(SourceRange R, QualType VectorTy, QualType Ty) { +bool Sema::CheckVectorCast(SourceRange R, QualType VectorTy, QualType Ty, + CastExpr::CastKind &Kind) { assert(VectorTy->isVectorType() && "Not a vector type!"); if (Ty->isVectorType() || Ty->isIntegerType()) { @@ -3240,6 +3251,7 @@ bool Sema::CheckVectorCast(SourceRange R, QualType VectorTy, QualType Ty) { diag::err_invalid_conversion_between_vector_and_scalar) << VectorTy << Ty << R; + Kind = CastExpr::CK_BitCast; return false; } -- cgit v1.2.3