Make control flow in Expr::isConstantExpr more simple and

local, making the code easier to read.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43104 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2007-10-18 00:20:32 +00:00
Родитель 01c5748c29
Коммит 2777e494c9
1 изменённых файлов: 12 добавлений и 20 удалений

Просмотреть файл

@ -353,7 +353,6 @@ Expr::isModifiableLvalueResult Expr::isModifiableLvalue() const {
} }
bool Expr::isConstantExpr(ASTContext &Ctx, SourceLocation *Loc) const { bool Expr::isConstantExpr(ASTContext &Ctx, SourceLocation *Loc) const {
switch (getStmtClass()) { switch (getStmtClass()) {
default: default:
if (Loc) *Loc = getLocStart(); if (Loc) *Loc = getLocStart();
@ -367,20 +366,20 @@ bool Expr::isConstantExpr(ASTContext &Ctx, SourceLocation *Loc) const {
case ImaginaryLiteralClass: case ImaginaryLiteralClass:
case TypesCompatibleExprClass: case TypesCompatibleExprClass:
case CXXBoolLiteralExprClass: case CXXBoolLiteralExprClass:
break; return true;
case CallExprClass: { case CallExprClass: {
const CallExpr *CE = cast<CallExpr>(this); const CallExpr *CE = cast<CallExpr>(this);
llvm::APSInt Result(32); llvm::APSInt Result(32);
Result.zextOrTrunc( Result.zextOrTrunc(
static_cast<uint32_t>(Ctx.getTypeSize(getType(), CE->getLocStart()))); static_cast<uint32_t>(Ctx.getTypeSize(getType(), CE->getLocStart())));
if (CE->isBuiltinClassifyType(Result)) if (CE->isBuiltinClassifyType(Result))
break; return true;
if (Loc) *Loc = getLocStart(); if (Loc) *Loc = getLocStart();
return false; return false;
} }
case DeclRefExprClass: case DeclRefExprClass:
if (isa<EnumConstantDecl>(cast<DeclRefExpr>(this)->getDecl())) if (isa<EnumConstantDecl>(cast<DeclRefExpr>(this)->getDecl()))
break; return true;
if (Loc) *Loc = getLocStart(); if (Loc) *Loc = getLocStart();
return false; return false;
case UnaryOperatorClass: { case UnaryOperatorClass: {
@ -405,21 +404,20 @@ bool Expr::isConstantExpr(ASTContext &Ctx, SourceLocation *Loc) const {
// sizeof(vla) is not a constantexpr: C99 6.5.3.4p2. // sizeof(vla) is not a constantexpr: C99 6.5.3.4p2.
if (!Exp->getSubExpr()->getType()->isConstantSizeType(Ctx, Loc)) if (!Exp->getSubExpr()->getType()->isConstantSizeType(Ctx, Loc))
return false; return false;
break; return true;
case UnaryOperator::LNot: case UnaryOperator::LNot:
case UnaryOperator::Plus: case UnaryOperator::Plus:
case UnaryOperator::Minus: case UnaryOperator::Minus:
case UnaryOperator::Not: case UnaryOperator::Not:
break; return true;
} }
break;
} }
case SizeOfAlignOfTypeExprClass: { case SizeOfAlignOfTypeExprClass: {
const SizeOfAlignOfTypeExpr *Exp = cast<SizeOfAlignOfTypeExpr>(this); const SizeOfAlignOfTypeExpr *Exp = cast<SizeOfAlignOfTypeExpr>(this);
// alignof always evaluates to a constant. // alignof always evaluates to a constant.
if (Exp->isSizeOf() && !Exp->getArgumentType()->isConstantSizeType(Ctx,Loc)) if (Exp->isSizeOf() && !Exp->getArgumentType()->isConstantSizeType(Ctx,Loc))
return false; return false;
break; return true;
} }
case BinaryOperatorClass: { case BinaryOperatorClass: {
const BinaryOperator *Exp = cast<BinaryOperator>(this); const BinaryOperator *Exp = cast<BinaryOperator>(this);
@ -430,8 +428,7 @@ bool Expr::isConstantExpr(ASTContext &Ctx, SourceLocation *Loc) const {
if (!Exp->getRHS()->isConstantExpr(Ctx, Loc)) if (!Exp->getRHS()->isConstantExpr(Ctx, Loc))
return false; return false;
return true;
break;
} }
case ImplicitCastExprClass: case ImplicitCastExprClass:
case CastExprClass: { case CastExprClass: {
@ -448,20 +445,15 @@ bool Expr::isConstantExpr(ASTContext &Ctx, SourceLocation *Loc) const {
if (Loc) *Loc = SubExpr->getLocStart(); if (Loc) *Loc = SubExpr->getLocStart();
return false; return false;
} }
break; return true;
} }
case ConditionalOperatorClass: { case ConditionalOperatorClass: {
const ConditionalOperator *Exp = cast<ConditionalOperator>(this); const ConditionalOperator *Exp = cast<ConditionalOperator>(this);
if (!Exp->getCond()->isConstantExpr(Ctx, Loc) ||
if (!Exp->getCond()->isConstantExpr(Ctx, Loc)) !Exp->getLHS()->isConstantExpr(Ctx, Loc) ||
!Exp->getRHS()->isConstantExpr(Ctx, Loc))
return false; return false;
return true;
if (!Exp->getLHS()->isConstantExpr(Ctx, Loc))
return false;
if (!Exp->getRHS()->isConstantExpr(Ctx, Loc))
return false;
break;
} }
} }