diff options
author | Sebastian Redl <sebastian.redl@getdesigned.at> | 2008-11-11 17:56:53 +0000 |
---|---|---|
committer | Sebastian Redl <sebastian.redl@getdesigned.at> | 2008-11-11 17:56:53 +0000 |
commit | 0518999d3adcc289997bd974dce90cc97f5c1c44 (patch) | |
tree | b37c751f8fee36d162d7bf009aaa64d22e64910c /lib/AST/ExprConstant.cpp | |
parent | 8f5aab696173cc6e9c9963635d91dc2e83d54442 (diff) |
Introduce a single AST node SizeOfAlignOfExpr for all sizeof and alignof expressions, both of values and types.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59057 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/ExprConstant.cpp')
-rw-r--r-- | lib/AST/ExprConstant.cpp | 24 |
1 files changed, 10 insertions, 14 deletions
diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp index 12010646bc..99fa8d5813 100644 --- a/lib/AST/ExprConstant.cpp +++ b/lib/AST/ExprConstant.cpp @@ -222,14 +222,10 @@ public: bool VisitCastExpr(CastExpr* E) { return HandleCast(E->getLocStart(), E->getSubExpr(), E->getType()); } - bool VisitSizeOfAlignOfTypeExpr(const SizeOfAlignOfTypeExpr *E) { - return EvaluateSizeAlignOf(E->isSizeOf(), E->getArgumentType(), - E->getType()); - } - + bool VisitSizeOfAlignOfExpr(const SizeOfAlignOfExpr *E); + private: bool HandleCast(SourceLocation CastLoc, Expr *SubExpr, QualType DestType); - bool EvaluateSizeAlignOf(bool isSizeOf, QualType SrcTy, QualType DstTy); }; } // end anonymous namespace @@ -426,14 +422,16 @@ bool IntExprEvaluator::VisitBinaryOperator(const BinaryOperator *E) { return true; } -/// EvaluateSizeAlignOf - Evaluate sizeof(SrcTy) or alignof(SrcTy) with a result -/// as a DstTy type. -bool IntExprEvaluator::EvaluateSizeAlignOf(bool isSizeOf, QualType SrcTy, - QualType DstTy) { +/// VisitSizeAlignOfExpr - Evaluate a sizeof or alignof with a result as the +/// expression's type. +bool IntExprEvaluator::VisitSizeOfAlignOfExpr(const SizeOfAlignOfExpr *E) { + QualType DstTy = E->getType(); // Return the result in the right width. Result.zextOrTrunc(getIntTypeSizeInBits(DstTy)); Result.setIsUnsigned(DstTy->isUnsignedIntegerType()); + QualType SrcTy = E->getTypeOfArgument(); + // sizeof(void) and __alignof__(void) = 1 as a gcc extension. if (SrcTy->isVoidType()) Result = 1; @@ -443,6 +441,8 @@ bool IntExprEvaluator::EvaluateSizeAlignOf(bool isSizeOf, QualType SrcTy, // FIXME: Should we attempt to evaluate this? return false; } + + bool isSizeOf = E->isSizeOf(); // GCC extension: sizeof(function) = 1. if (SrcTy->isFunctionType()) { @@ -470,10 +470,6 @@ bool IntExprEvaluator::VisitUnaryOperator(const UnaryOperator *E) { return true; } - if (E->isSizeOfAlignOfOp()) - return EvaluateSizeAlignOf(E->getOpcode() == UnaryOperator::SizeOf, - E->getSubExpr()->getType(), E->getType()); - // Get the operand value into 'Result'. if (!Visit(E->getSubExpr())) return false; |