summaryrefslogtreecommitdiff
path: root/libbindgen/src/clang.rs
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2017-01-09 14:07:45 -0800
committerGitHub <noreply@github.com>2017-01-09 14:07:45 -0800
commitfab479dce41df1ebde617c060e9ee02eac92803d (patch)
tree5e8aa9b5a20ebb4d37ab4b0cd185e048a93a1b40 /libbindgen/src/clang.rs
parentb30fe53aec602c3ac506e1c89b5311aa08b4a548 (diff)
parenta20cf85dbb8b9f4ffcd656b3a541de24f4c37d95 (diff)
Auto merge of #390 - emilio:str, r=Manishearth
ir: Evaluate constant strings too. r? @Manishearth
Diffstat (limited to 'libbindgen/src/clang.rs')
-rw-r--r--libbindgen/src/clang.rs14
1 files changed, 14 insertions, 0 deletions
diff --git a/libbindgen/src/clang.rs b/libbindgen/src/clang.rs
index fc5575b3..491aaa07 100644
--- a/libbindgen/src/clang.rs
+++ b/libbindgen/src/clang.rs
@@ -1348,6 +1348,20 @@ impl EvalResult {
_ => None,
}
}
+
+ /// Evaluates the expression as a literal string, that may or may not be
+ /// valid utf-8.
+ pub fn as_literal_string(&self) -> Option<Vec<u8>> {
+ match self.kind() {
+ CXEval_StrLiteral => {
+ let ret = unsafe {
+ CStr::from_ptr(clang_EvalResult_getAsStr(self.x))
+ };
+ Some(ret.to_bytes().to_vec())
+ }
+ _ => None,
+ }
+ }
}
impl Drop for EvalResult {