[cfe-commits] r53468 - /cfe/trunk/lib/AST/ExprConstant.cpp

Chris Lattner sabre at nondot.org
Fri Jul 11 12:24:49 PDT 2008


Author: lattner
Date: Fri Jul 11 14:24:49 2008
New Revision: 53468

URL: http://llvm.org/viewvc/llvm-project?rev=53468&view=rev
Log:
add a new getIntTypeSizeInBits method.

Modified:
    cfe/trunk/lib/AST/ExprConstant.cpp

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=53468&r1=53467&r2=53468&view=diff

==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Fri Jul 11 14:24:49 2008
@@ -152,9 +152,14 @@
 public:
   IntExprEvaluator(ASTContext &ctx, APSInt &result) : Ctx(ctx), Result(result){}
 
+  unsigned getIntTypeSizeInBits(QualType T) const {
+    return (unsigned)Ctx.getTypeSize(T);
+  }
+    
   //===--------------------------------------------------------------------===//
   //                            Visitor Methods
   //===--------------------------------------------------------------------===//
+    
   bool VisitStmt(Stmt *S) {
     // FIXME: Remove this when we support more expressions.
     printf("unhandled int expression");
@@ -253,7 +258,7 @@
     Result = E->evaluateOffsetOf(Ctx);
   else if (E->isSizeOfAlignOfOp()) {
     // Return the result in the right width.
-    Result.zextOrTrunc(static_cast<uint32_t>(Ctx.getTypeSize(E->getType())));
+    Result.zextOrTrunc(getIntTypeSizeInBits(E->getType()));
 
     // sizeof(void) and __alignof__(void) = 1 as a gcc extension.
     if (E->getSubExpr()->getType()->isVoidType())
@@ -275,7 +280,7 @@
       if (E->getOpcode() == UnaryOperator::AlignOf)
         Result = Ctx.getTypeAlign(E->getSubExpr()->getType()) / CharSize;
       else
-        Result = Ctx.getTypeSize(E->getSubExpr()->getType()) / CharSize;
+        Result = getIntTypeSizeInBits(E->getSubExpr()->getType()) / CharSize;
     }
   } else {
     // Get the operand value.  If this is sizeof/alignof, do not evalute the
@@ -293,8 +298,7 @@
         return false;
     case UnaryOperator::LNot: {
       bool Val = Result == 0;
-      uint32_t typeSize = Ctx.getTypeSize(E->getType());
-      Result.zextOrTrunc(typeSize);
+      Result.zextOrTrunc(getIntTypeSizeInBits(E->getType()));
       Result = Val;
       break;
     }
@@ -314,9 +318,7 @@
 }
   
 bool IntExprEvaluator::HandleCast(const Expr* SubExpr, QualType DestType) {
-  llvm::APSInt Result(32);
-
-  uint32_t DestWidth = static_cast<uint32_t>(Ctx.getTypeSize(DestType));
+  unsigned DestWidth = getIntTypeSizeInBits(DestType);
 
   // Handle simple integer->integer casts.
   if (SubExpr->getType()->isIntegerType()) {
@@ -329,8 +331,7 @@
       // Conversion to bool compares against zero.
       Result = Result != 0;
       Result.zextOrTrunc(DestWidth);
-    }
-    else
+    } else
       Result.extOrTrunc(DestWidth);
   } else if (SubExpr->getType()->isPointerType()) {
     APValue LV;
@@ -352,7 +353,7 @@
 bool IntExprEvaluator::
 VisitSizeOfAlignOfTypeExpr(const SizeOfAlignOfTypeExpr *E) {
   // Return the result in the right width.
-  Result.zextOrTrunc(static_cast<uint32_t>(Ctx.getTypeSize(E->getType())));
+  Result.zextOrTrunc(getIntTypeSizeInBits(E->getType()));
 
   // sizeof(void) and __alignof__(void) = 1 as a gcc extension.
   if (E->getArgumentType()->isVoidType()) {
@@ -372,7 +373,7 @@
   } else { 
     unsigned CharSize = Ctx.Target.getCharWidth();
     if (E->isSizeOf())
-      Result = Ctx.getTypeSize(E->getArgumentType()) / CharSize;
+      Result = getIntTypeSizeInBits(E->getArgumentType()) / CharSize;
     else
       Result = Ctx.getTypeAlign(E->getArgumentType()) / CharSize;
   }





More information about the cfe-commits mailing list