Skip to content

Commit 2afecec

Browse files
author
bors-servo
authored
Auto merge of #566 - tsliang:master, r=emilio,fitzgen
Do not print builtin macro definitions in ast_dump Resolves issue #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.
2 parents 0ec92d7 + b826a80 commit 2afecec

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
@@ -77,6 +77,12 @@ impl Cursor {
7777
}
7878
}
7979

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

14471453
fn print_cursor<S: AsRef<str>>(depth: isize, prefix: S, c: &Cursor) {
1454+
if c.is_builtin() {
1455+
return;
1456+
}
14481457
let prefix = prefix.as_ref();
14491458
print_indent(depth,
14501459
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+
ctx.options().builtins || !cursor.is_builtin()
835830
}
836831

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

0 commit comments

Comments
 (0)