diff options
author | Tai Sassen-Liang <tsl@rupsvak.net> | 2017-03-07 20:05:48 +0100 |
---|---|---|
committer | Tai Sassen-Liang <tsassenliang@airtrade.nl> | 2017-03-08 11:03:19 +0100 |
commit | 96c4eb4bf728e09db849be77e8c6b2dc78bf0b87 (patch) | |
tree | fd89f2037c96969ebf2a40b5c48c914b97f3fcfb | |
parent | 0ec92d71e82c26d7374737d4ef6b399a2f5ce197 (diff) |
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..6af5d2c9 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_some() + } + /// 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, - } + !cursor.is_builtin() || ctx.options().builtins } /// Parse one `Item` from the Clang cursor. |