summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDarren Kulp <darren@kulp.ch>2020-06-21 17:38:46 -0700
committerEmilio Cobos Álvarez <emilio@crisal.io>2020-07-20 18:55:10 +0200
commit4ea1e21bccfd33d79a9244a849d1de0f8ac42b3b (patch)
treeeec9d75b4ac1a8077784e54cbecdf2bf001ae7b1 /src
parentf4f773b6110b6b845f38414febbf37a056cc40ed (diff)
Simplify handle_function_macro for clang 3.9+
Diffstat (limited to 'src')
-rw-r--r--src/clang.rs10
-rw-r--r--src/ir/var.rs29
2 files changed, 6 insertions, 33 deletions
diff --git a/src/clang.rs b/src/clang.rs
index 9c09f71c..357a6dd5 100644
--- a/src/clang.rs
+++ b/src/clang.rs
@@ -237,14 +237,8 @@ impl Cursor {
}
/// Is this Cursor pointing to a function-like macro definition?
- /// Returns None if this cannot be determined with the available libclang
- /// (it requires 3.9 or greater).
- pub fn is_macro_function_like(&self) -> Option<bool> {
- if clang_Cursor_isMacroFunctionLike::is_loaded() {
- Some(unsafe { clang_Cursor_isMacroFunctionLike(self.x) != 0 })
- } else {
- None
- }
+ pub fn is_macro_function_like(&self) -> bool {
+ unsafe { clang_Cursor_isMacroFunctionLike(self.x) != 0 }
}
/// Get the kind of referent this cursor is pointing to.
diff --git a/src/ir/var.rs b/src/ir/var.rs
index 67b2e348..ef963503 100644
--- a/src/ir/var.rs
+++ b/src/ir/var.rs
@@ -141,31 +141,10 @@ fn handle_function_macro(
tokens: &[ClangToken],
callbacks: &dyn crate::callbacks::ParseCallbacks,
) -> Result<(), ParseError> {
- fn is_abutting(a: &ClangToken, b: &ClangToken) -> bool {
- unsafe {
- clang_sys::clang_equalLocations(
- clang_sys::clang_getRangeEnd(a.extent),
- clang_sys::clang_getRangeStart(b.extent),
- ) != 0
- }
- }
-
- let is_functional_macro =
- // If we have libclang >= 3.9, we can use `is_macro_function_like()` and
- // avoid checking for abutting tokens ourselves.
- cursor.is_macro_function_like().unwrap_or_else(|| {
- // If we cannot get a definitive answer from clang, we instead check
- // for a parenthesis token immediately adjacent to (that is,
- // abutting) the first token in the macro definition.
- // TODO: Once we don't need the fallback check here, we can hoist
- // the `is_macro_function_like` check into this function's caller,
- // and thus avoid allocating the `tokens` vector for non-functional
- // macros.
- match tokens.get(0..2) {
- Some([a, b]) => is_abutting(&a, &b) && b.spelling() == b"(",
- _ => false,
- }
- });
+ // TODO: Hoist the `is_macro_function_like` check into this function's
+ // caller, and thus avoid allocating the `tokens` vector for non-functional
+ // macros.
+ let is_functional_macro = cursor.is_macro_function_like();
if !is_functional_macro {
return Ok(());