Skip to content

Commit dd21929

Browse files
committed
squash! use_as -> use_instead_of, and doc fixes.
1 parent 7a62941 commit dd21929

File tree

3 files changed

+34
-10
lines changed

3 files changed

+34
-10
lines changed

src/codegen/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,8 @@ impl ArrayTyBuilder {
206206
}
207207
}
208208

209+
/// Generates a proper type for a field or type with a given `Layout`, that is,
210+
/// a type with the correct size and alignment restrictions.
209211
struct BlobTyBuilder {
210212
layout: Layout,
211213
}
@@ -1154,8 +1156,8 @@ impl MethodCodegen for Method {
11541156
constness: ast::Constness::NotConst,
11551157
};
11561158

1157-
// TODO: This needs to be kept in sync, so we'd be better unifying this,
1158-
// I guess.
1159+
// TODO: We need to keep in sync the argument names, so we should unify
1160+
// this with the other loop that decides them.
11591161
let mut unnamed_arguments = 0;
11601162
let mut exprs = signature.argument_types().iter().map(|&(ref name, _ty)| {
11611163
let arg_name = match *name {

src/ir/annotations.rs

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub struct Annotations {
1818
hide: bool,
1919
/// Whether this type should be replaced by another. The name must be the
2020
/// canonical name that that type would get.
21-
use_as: Option<String>,
21+
use_instead_of: Option<String>,
2222
/// Manually disable deriving copy/clone on this type. Only applies to
2323
/// struct or union types.
2424
disallow_copy: bool,
@@ -44,7 +44,7 @@ impl Default for Annotations {
4444
Annotations {
4545
opaque: false,
4646
hide: false,
47-
use_as: None,
47+
use_instead_of: None,
4848
disallow_copy: false,
4949
private_fields: None,
5050
accessor_kind: None
@@ -73,8 +73,30 @@ impl Annotations {
7373
self.opaque
7474
}
7575

76-
pub fn use_as(&self) -> Option<&str> {
77-
self.use_as.as_ref().map(|s| &**s)
76+
/// For a given type, indicates the type it should replace.
77+
///
78+
/// For example, in the following code:
79+
///
80+
/// ```cpp
81+
///
82+
/// /** <div rustbindgen replaces="Bar"></div> */
83+
/// struct Foo { int x; };
84+
///
85+
/// struct Bar { char foo; };
86+
/// ```
87+
///
88+
/// the generated code would look something like:
89+
///
90+
/// ```rust
91+
/// /** <div rustbindgen replaces="Bar"></div> */
92+
/// struct Bar {
93+
/// int x;
94+
/// };
95+
/// ```
96+
///
97+
/// That is, code for `Foo` is used to generate `Bar`.
98+
pub fn use_instead_of(&self) -> Option<&str> {
99+
self.use_instead_of.as_ref().map(|s| &**s)
78100
}
79101

80102
pub fn disallow_copy(&self) -> bool {
@@ -103,7 +125,7 @@ impl Annotations {
103125
"opaque" => self.opaque = true,
104126
"hide" => self.hide = true,
105127
"nocopy" => self.disallow_copy = true,
106-
"replaces" => self.use_as = Some(value),
128+
"replaces" => self.use_instead_of = Some(value),
107129
"private" => self.private_fields = Some(value != "false"),
108130
"accessor"
109131
=> self.accessor_kind = Some(parse_accessor(&value)),

src/ir/item.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ impl Item {
248248
ctx.opaque_by_name(&self.real_canonical_name(ctx, false))
249249
}
250250

251-
/// Get the canonical name without taking into account the use_as
251+
/// Get the canonical name without taking into account the replaces
252252
/// annotation.
253253
fn real_canonical_name(&self, ctx: &BindgenContext, count_namespaces: bool) -> String {
254254
let base_name = match *self.kind() {
@@ -496,7 +496,7 @@ impl ClangItemParser for Item {
496496
Annotations::new(&decl)
497497
.or_else(|| location.as_ref().and_then(|l| Annotations::new(l)));
498498

499-
if let Some(ref replaced) = annotations.as_ref().and_then(|a| a.use_as()) {
499+
if let Some(ref replaced) = annotations.as_ref().and_then(|a| a.use_instead_of()) {
500500
context.replace(replaced, id);
501501
}
502502

@@ -635,7 +635,7 @@ impl ItemCanonicalName for Item {
635635
fn canonical_name(&self, ctx: &BindgenContext) -> String {
636636
debug_assert!(ctx.in_codegen_phase(),
637637
"You're not supposed to call this yet");
638-
if let Some(other_canon_type) = self.annotations.use_as() {
638+
if let Some(other_canon_type) = self.annotations.use_instead_of() {
639639
return other_canon_type.to_owned();
640640
}
641641
self.real_canonical_name(ctx, ctx.options().enable_cxx_namespaces)

0 commit comments

Comments
 (0)