]> granicus.if.org Git - clang/commitdiff
Add Expr::getIntegerConstantExprValue helper method
authorDaniel Dunbar <daniel@zuster.org>
Thu, 24 Jul 2008 01:08:37 +0000 (01:08 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Thu, 24 Jul 2008 01:08:37 +0000 (01:08 +0000)
 - For getting an APSInt from a known integer constant Expr.
 - TODO: Many users of Expr::isIntegerConstantExpr in codegen should
   probably be using this instead...

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@53974 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/Expr.h

index 692a0ea85f505d4bdcf36dde7ea3a3b6fceaf7e6..5569bb6c73e94385fdbe0259e716936aa0608db9 100644 (file)
@@ -95,6 +95,16 @@ public:
   
   bool isNullPointerConstant(ASTContext &Ctx) const;
 
+  /// getIntegerConstantExprValue() - Return the value of an integer
+  /// constant expression. The expression must be a valid integer
+  /// constant expression as determined by isIntegerConstantExpr.
+  llvm::APSInt getIntegerConstantExprValue(ASTContext &Ctx) const {
+    llvm::APSInt X(32);
+    bool success = isIntegerConstantExpr(X, Ctx);
+    assert(success && "Illegal argument to getIntegerConstantExpr");
+    return X;
+  }
+
   /// isIntegerConstantExpr - Return true if this expression is a valid integer
   /// constant expression, and, if so, return its value in Result.  If not a
   /// valid i-c-e, return false and fill in Loc (if specified) with the location