diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/clang.rs | 22 | ||||
-rw-r--r-- | src/ir/ty.rs | 7 |
2 files changed, 22 insertions, 7 deletions
diff --git a/src/clang.rs b/src/clang.rs index ee422745..2dbe5e51 100644 --- a/src/clang.rs +++ b/src/clang.rs @@ -600,6 +600,17 @@ impl Cursor { } } +/// Checks whether the name looks like an identifier, i.e. is alphanumeric +/// (including '_') and does not start with a digit. +pub fn is_valid_identifier(name: &str) -> bool { + let mut chars = name.chars(); + let first_valid = chars.next() + .map(|c| c.is_alphabetic() || c == '_') + .unwrap_or(false); + + first_valid && chars.all(|c| c.is_alphanumeric() || c == '_') +} + extern "C" fn visit_children<Visitor>(cur: CXCursor, _parent: CXCursor, data: CXClientData) @@ -729,7 +740,16 @@ impl Type { /// Get a raw display name for this type. pub fn spelling(&self) -> String { - unsafe { cxstring_into_string(clang_getTypeSpelling(self.x)) } + let s = unsafe { cxstring_into_string(clang_getTypeSpelling(self.x)) }; + // Clang 5.0 introduced changes in the spelling API so it returned the + // full qualified name. Let's undo that here. + if s.split("::").all(|s| is_valid_identifier(s)) { + if let Some(s) = s.split("::").last() { + return s.to_owned(); + } + } + + s } /// Is this type const qualified? diff --git a/src/ir/ty.rs b/src/ir/ty.rs index 54925696..60d750ed 100644 --- a/src/ir/ty.rs +++ b/src/ir/ty.rs @@ -429,12 +429,7 @@ impl Type { /// Checks whether the name looks like an identifier, /// i.e. is alphanumeric (including '_') and does not start with a digit. pub fn is_valid_identifier(name: &str) -> bool { - let mut chars = name.chars(); - let first_valid = chars.next() - .map(|c| c.is_alphabetic() || c == '_') - .unwrap_or(false); - - first_valid && chars.all(|c| c.is_alphanumeric() || c == '_') + clang::is_valid_identifier(name) } /// See safe_canonical_type. |