Skip to content

Commit

Permalink
Flatten cursor.kind() matching in Item::parse down to one match
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay authored and emilio committed Jan 12, 2024
1 parent f3f3d32 commit ba54134
Showing 1 changed file with 41 additions and 43 deletions.
84 changes: 41 additions & 43 deletions bindgen/ir/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1432,57 +1432,55 @@ impl Item {
}
}

// Guess how does clang treat extern "C" blocks?
if cursor.kind() == CXCursor_UnexposedDecl {
Err(ParseError::Recurse)
} else {
match cursor.kind() {
// Guess how does clang treat extern "C" blocks?
CXCursor_UnexposedDecl => Err(ParseError::Recurse),

// We allowlist cursors here known to be unhandled, to prevent being
// too noisy about this.
match cursor.kind() {
CXCursor_MacroDefinition |
CXCursor_MacroExpansion |
CXCursor_UsingDeclaration |
CXCursor_UsingDirective |
CXCursor_StaticAssert |
CXCursor_FunctionTemplate => {
debug!(
"Unhandled cursor kind {:?}: {:?}",
cursor.kind(),
cursor
);
}
CXCursor_InclusionDirective => {
let file = cursor.get_included_file_name();
match file {
None => {
warn!(
"Inclusion of a nameless file in {:?}",
cursor
);
}
Some(included_file) => {
for cb in &ctx.options().parse_callbacks {
cb.include_file(&included_file);
}
CXCursor_MacroDefinition |
CXCursor_MacroExpansion |
CXCursor_UsingDeclaration |
CXCursor_UsingDirective |
CXCursor_StaticAssert |
CXCursor_FunctionTemplate => {
debug!(
"Unhandled cursor kind {:?}: {:?}",
cursor.kind(),
cursor
);
Err(ParseError::Continue)
}

ctx.add_dep(included_file.into_boxed_str());
}
CXCursor_InclusionDirective => {
let file = cursor.get_included_file_name();
match file {
None => {
warn!("Inclusion of a nameless file in {:?}", cursor);
}
}
_ => {
// ignore toplevel operator overloads
let spelling = cursor.spelling();
if !spelling.starts_with("operator") {
warn!(
"Unhandled cursor kind {:?}: {:?}",
cursor.kind(),
cursor
);
Some(included_file) => {
for cb in &ctx.options().parse_callbacks {
cb.include_file(&included_file);
}

ctx.add_dep(included_file.into_boxed_str());
}
}
Err(ParseError::Continue)
}

Err(ParseError::Continue)
_ => {
// ignore toplevel operator overloads
let spelling = cursor.spelling();
if !spelling.starts_with("operator") {
warn!(
"Unhandled cursor kind {:?}: {:?}",
cursor.kind(),
cursor
);
}
Err(ParseError::Continue)
}
}
}

Expand Down

0 comments on commit ba54134

Please sign in to comment.