summaryrefslogtreecommitdiff
path: root/libbindgen/src
diff options
context:
space:
mode:
Diffstat (limited to 'libbindgen/src')
-rw-r--r--libbindgen/src/clang.rs14
-rw-r--r--libbindgen/src/ir/var.rs4
2 files changed, 17 insertions, 1 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 {
diff --git a/libbindgen/src/ir/var.rs b/libbindgen/src/ir/var.rs
index d9160eca..e18af91b 100644
--- a/libbindgen/src/ir/var.rs
+++ b/libbindgen/src/ir/var.rs
@@ -236,7 +236,9 @@ impl ClangSubItemParser for Var {
.and_then(|v| v.as_double())
.map(VarType::Float)
} else {
- None
+ cursor.evaluate()
+ .and_then(|v| v.as_literal_string())
+ .map(VarType::String)
};
let mangling = cursor_mangling(&cursor);