From: Daniel Dunbar Date: Thu, 24 Jul 2008 01:08:37 +0000 (+0000) Subject: Add Expr::getIntegerConstantExprValue helper method X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cd8f646eca128f52a7bce0103c51ff82ce96f374;p=clang Add Expr::getIntegerConstantExprValue helper method - 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 --- diff --git a/include/clang/AST/Expr.h b/include/clang/AST/Expr.h index 692a0ea85f..5569bb6c73 100644 --- a/include/clang/AST/Expr.h +++ b/include/clang/AST/Expr.h @@ -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