Skip to content

Commit c09ec13

Browse files
committed
[gen.rs] New gen_foreign_item function.
1 parent 04421af commit c09ec13

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

src/gen.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -992,12 +992,22 @@ fn cvar_to_rs(ctx: &mut GenCtx, name: String,
992992
attrs.push(mk_link_name_attr(ctx, &name));
993993
}
994994

995-
let val_ty = P(cty_to_rs(ctx, ty));
995+
let node = {
996+
let val_ty = P(cty_to_rs(ctx, ty));
997+
ast::ForeignItemKind::Static(val_ty, !is_const)
998+
};
999+
1000+
mk_foreign_item(ctx, &rust_name, attrs, node)
1001+
}
9961002

1003+
fn mk_foreign_item(ctx: &mut GenCtx,
1004+
name: &str,
1005+
attrs: Vec<ast::Attribute>,
1006+
node: ast::ForeignItemKind) -> ast::ForeignItem {
9971007
ast::ForeignItem {
998-
ident: ctx.ext_cx.ident_of(&rust_name[..]),
1008+
ident: ctx.ext_cx.ident_of(name),
9991009
attrs: attrs,
1000-
node: ast::ForeignItemKind::Static(val_ty, !is_const),
1010+
node: node,
10011011
id: ast::DUMMY_NODE_ID,
10021012
span: ctx.span,
10031013
vis: ast::Visibility::Public,
@@ -1063,14 +1073,7 @@ fn cfunc_to_rs(ctx: &mut GenCtx, name: String, rty: &Type,
10631073
attrs.push(mk_link_name_attr(ctx, &name));
10641074
}
10651075

1066-
ast::ForeignItem {
1067-
ident: ctx.ext_cx.ident_of(&rust_name[..]),
1068-
attrs: attrs,
1069-
node: decl,
1070-
id: ast::DUMMY_NODE_ID,
1071-
span: ctx.span,
1072-
vis: ast::Visibility::Public,
1073-
}
1076+
mk_foreign_item(ctx, &rust_name, attrs, decl)
10741077
}
10751078

10761079
fn cty_to_rs(ctx: &mut GenCtx, ty: &Type) -> ast::Ty {

0 commit comments

Comments
 (0)