Skip to content

Commit 29ef65a

Browse files
author
Tai Sassen-Liang
committed
Do not print builtin macro definitions in ast_dump
Resolves issue rust-lang#476. Moves out logic for checking whether a cursor has a filename (previously used exclusively in private function lib::filter_builtins) into the actual cursor. This code is then used to check whether a cursor is a builtin when dumping the AST.
1 parent c85fa24 commit 29ef65a

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/clang.rs

+9
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ impl Cursor {
7676
}
7777
}
7878

79+
/// Returns whether the cursor refers to a built-in definition.
80+
pub fn is_builtin(&self) -> bool {
81+
let (file, _, _, _) = self.location().location();
82+
!file.name().is_some()
83+
}
84+
7985
/// Get the `Cursor` for this cursor's referent's lexical parent.
8086
///
8187
/// The lexical parent is the parent of the definition. The semantic parent
@@ -1415,6 +1421,9 @@ pub fn ast_dump(c: &Cursor, depth: isize) -> CXChildVisitResult {
14151421
}
14161422

14171423
fn print_cursor<S: AsRef<str>>(depth: isize, prefix: S, c: &Cursor) {
1424+
if c.is_builtin() {
1425+
return;
1426+
}
14181427
let prefix = prefix.as_ref();
14191428
print_indent(depth,
14201429
format!(" {}kind = {}", prefix, kind_to_str(c.kind())));

src/lib.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -826,12 +826,7 @@ impl<'ctx> Bindings<'ctx> {
826826
/// Determines whether the given cursor is in any of the files matched by the
827827
/// options.
828828
fn filter_builtins(ctx: &BindgenContext, cursor: &clang::Cursor) -> bool {
829-
let (file, _, _, _) = cursor.location().location();
830-
831-
match file.name() {
832-
None => ctx.options().builtins,
833-
Some(..) => true,
834-
}
829+
!cursor.is_builtin() || ctx.options().builtins
835830
}
836831

837832
/// Parse one `Item` from the Clang cursor.

0 commit comments

Comments
 (0)