From cd8f646eca128f52a7bce0103c51ff82ce96f374 Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Thu, 24 Jul 2008 01:08:37 +0000 Subject: [PATCH] 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 --- include/clang/AST/Expr.h | 10 ++++++++++ 1 file changed, 10 insertions(+) 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 -- 2.50.1