Created
March 7, 2014 11:52
-
-
Save kwk/9410155 to your computer and use it in GitHub Desktop.
How to get the value of a Clang variable initialization
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// clang::VarDecl * varDecl; | |
// clang::ASTContext & ctx; | |
const clang::Expr * initializerExpr = varDecl->getInit(); | |
llvm::APSInt result; | |
if (initializerExpr->EvaluateAsInt(result, ctx)) { | |
std::cout << "Value as string: " << result.toString(10) << std::endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment