Skip to content

Commit

Permalink
transpile: Reduce code duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
chrysn committed Sep 15, 2020
1 parent 3b61146 commit 73d503e
Showing 1 changed file with 11 additions and 19 deletions.
30 changes: 11 additions & 19 deletions c2rust-transpile/src/c_ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -532,41 +532,33 @@ impl TypedAstContext {
// be visible from another compilation unit.
for &decl_id in &self.c_decls_top {
let decl = self.index(decl_id);
match decl.kind {
let is_used = match decl.kind {
CDeclKind::Function {
body: Some(_),
is_global: true,
is_inline,
is_inline_externally_visible,
..
} if !is_inline || is_inline_externally_visible => {
// Depending on the C specification and dialect, an inlined function
// may be externally visible. We rely on clang to determine visibility.
to_walk.push(decl_id);
used.insert(decl_id);
}
} if !is_inline || is_inline_externally_visible => true,
CDeclKind::Function {
body: Some(_),
..
} if preserve_unused_functions => {
to_walk.push(decl_id);
used.insert(decl_id);
}
} if preserve_unused_functions => true,
CDeclKind::Variable {
is_defn: true,
is_externally_visible: true,
..
} => {
to_walk.push(decl_id);
used.insert(decl_id);
}
} => true,
CDeclKind::Variable { ref attrs, .. } | CDeclKind::Function { ref attrs, .. }
if attrs.contains(&Attribute::Used) =>
{
to_walk.push(decl_id);
used.insert(decl_id);
}
_ => {}
if attrs.contains(&Attribute::Used) => true,
_ => false,
};

if is_used {
to_walk.push(decl_id);
used.insert(decl_id);
}
}

Expand Down

0 comments on commit 73d503e

Please sign in to comment.