Created
December 9, 2019 05:24
-
-
Save markoshorro/16d7df8e868c6ea0813639a4a3a516dd to your computer and use it in GitHub Desktop.
Clang: get int value from clang::Expr
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
/// ASTContext needed, you can get it from CompilerInstance | |
int64_t getIntFromExpr(const Expr *E, const ASTContext *C) { | |
clang::Expr::EvalResult R; | |
if (E->EvaluateAsInt(R, *C)) { | |
return R.Val.getInt().getExtValue(); | |
} | |
/// Could be that returning -1 is not safe, you should modify this | |
return -1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment