Skip to content

Instantly share code, notes, and snippets.

@kwk
Created March 7, 2014 11:52
Show Gist options
  • Save kwk/9410155 to your computer and use it in GitHub Desktop.
Save kwk/9410155 to your computer and use it in GitHub Desktop.
How to get the value of a Clang variable initialization
// 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