diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2017-03-09 10:46:47 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-09 10:46:47 -0800 |
commit | 2afecece53a82fdf18e53a98d1b8ed0077500995 (patch) | |
tree | adbeb0477e8e98a86835b2e2bc10028f9e4a9f71 | |
parent | 0ec92d71e82c26d7374737d4ef6b399a2f5ce197 (diff) | |
parent | b826a80d2016c4b32fc23019deb3c4071af91728 (diff) |
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.
-rw-r--r-- | src/clang.rs | 9 | ||||
-rw-r--r-- | src/lib.rs | 7 |
2 files changed, 10 insertions, 6 deletions
diff --git a/src/clang.rs b/src/clang.rs index b8086d99..fc7950dc 100644 --- a/src/clang.rs +++ b/src/clang.rs @@ -77,6 +77,12 @@ impl Cursor { } } + /// Returns whether the cursor refers to a built-in definition. + pub fn is_builtin(&self) -> bool { + let (file, _, _, _) = self.location().location(); + file.name().is_none() + } + /// Get the `Cursor` for this cursor's referent's lexical parent. /// /// 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 { } fn print_cursor<S: AsRef<str>>(depth: isize, prefix: S, c: &Cursor) { + if c.is_builtin() { + return; + } let prefix = prefix.as_ref(); print_indent(depth, format!(" {}kind = {}", prefix, kind_to_str(c.kind()))); @@ -826,12 +826,7 @@ impl<'ctx> Bindings<'ctx> { /// Determines whether the given cursor is in any of the files matched by the /// options. fn filter_builtins(ctx: &BindgenContext, cursor: &clang::Cursor) -> bool { - let (file, _, _, _) = cursor.location().location(); - - match file.name() { - None => ctx.options().builtins, - Some(..) => true, - } + ctx.options().builtins || !cursor.is_builtin() } /// Parse one `Item` from the Clang cursor. |