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 MrAlex94 committed May 28, 2024
1 parent 04b5800 commit e5b5c07
Showing 1 changed file with 38 additions and 39 deletions.
77 changes: 38 additions & 39 deletions third_party/rust/bindgen/ir/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1427,53 +1427,52 @@ 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(filename) => {
ctx.include_file(filename);
}
}
}
_ => {
// ignore toplevel operator overloads
let spelling = cursor.spelling();
if !spelling.starts_with("operator") {
CXCursor_MacroDefinition |
CXCursor_MacroExpansion |
CXCursor_UsingDeclaration |
CXCursor_UsingDirective |
CXCursor_StaticAssert |
CXCursor_FunctionTemplate => {
debug!(
"Unhandled cursor kind {:?}: {:?}",
cursor.kind(),
cursor
);
Err(ParseError::Continue)
}
CXCursor_InclusionDirective => {
let file = cursor.get_included_file_name();
match file {
None => {
warn!(
"Unhandled cursor kind {:?}: {:?}",
cursor.kind(),
"Inclusion of a nameless file in {:?}",
cursor
);
}
Some(filename) => {
ctx.include_file(filename);
}
}
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)
}

Err(ParseError::Continue)
}
}

Expand Down

0 comments on commit e5b5c07

Please sign in to comment.