Skip to content

Commit 23da523

Browse files
committed
Simplify handle_function_macro for clang 3.9+
1 parent f995ee0 commit 23da523

File tree

2 files changed

+6
-33
lines changed

2 files changed

+6
-33
lines changed

src/clang.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -237,14 +237,8 @@ impl Cursor {
237237
}
238238

239239
/// Is this Cursor pointing to a function-like macro definition?
240-
/// Returns None if this cannot be determined with the available libclang
241-
/// (it requires 3.9 or greater).
242-
pub fn is_macro_function_like(&self) -> Option<bool> {
243-
if clang_Cursor_isMacroFunctionLike::is_loaded() {
244-
Some(unsafe { clang_Cursor_isMacroFunctionLike(self.x) != 0 })
245-
} else {
246-
None
247-
}
240+
pub fn is_macro_function_like(&self) -> bool {
241+
unsafe { clang_Cursor_isMacroFunctionLike(self.x) != 0 }
248242
}
249243

250244
/// Get the kind of referent this cursor is pointing to.

src/ir/var.rs

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -141,31 +141,10 @@ fn handle_function_macro(
141141
tokens: &[ClangToken],
142142
callbacks: &dyn crate::callbacks::ParseCallbacks,
143143
) -> Result<(), ParseError> {
144-
fn is_abutting(a: &ClangToken, b: &ClangToken) -> bool {
145-
unsafe {
146-
clang_sys::clang_equalLocations(
147-
clang_sys::clang_getRangeEnd(a.extent),
148-
clang_sys::clang_getRangeStart(b.extent),
149-
) != 0
150-
}
151-
}
152-
153-
let is_functional_macro =
154-
// If we have libclang >= 3.9, we can use `is_macro_function_like()` and
155-
// avoid checking for abutting tokens ourselves.
156-
cursor.is_macro_function_like().unwrap_or_else(|| {
157-
// If we cannot get a definitive answer from clang, we instead check
158-
// for a parenthesis token immediately adjacent to (that is,
159-
// abutting) the first token in the macro definition.
160-
// TODO: Once we don't need the fallback check here, we can hoist
161-
// the `is_macro_function_like` check into this function's caller,
162-
// and thus avoid allocating the `tokens` vector for non-functional
163-
// macros.
164-
match tokens.get(0..2) {
165-
Some([a, b]) => is_abutting(&a, &b) && b.spelling() == b"(",
166-
_ => false,
167-
}
168-
});
144+
// TODO: Hoist the `is_macro_function_like` check into this function's
145+
// caller, and thus avoid allocating the `tokens` vector for non-functional
146+
// macros.
147+
let is_functional_macro = cursor.is_macro_function_like();
169148

170149
if !is_functional_macro {
171150
return Ok(());

0 commit comments

Comments
 (0)