summaryrefslogtreecommitdiff
path: root/src/parser.rs
diff options
context:
space:
mode:
authorEmilio Cobos Álvarez <ecoal95@gmail.com>2016-03-23 23:59:15 +0100
committerEmilio Cobos Álvarez <ecoal95@gmail.com>2016-03-23 23:59:32 +0100
commitaa9bd918772039e45a7e2ff5f90a36488776af4c (patch)
treebd2ea0f7d65f100c4644af63b7652896fbe8cfcf /src/parser.rs
parenta624bc81095df028859f0982b80881dc6cd38e28 (diff)
gen: Add option to replace types via annotations
This is limited to the same namespace, but well, it seems useful enough.
Diffstat (limited to 'src/parser.rs')
-rw-r--r--src/parser.rs13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/parser.rs b/src/parser.rs
index 538d5d9c..8db8031b 100644
--- a/src/parser.rs
+++ b/src/parser.rs
@@ -467,6 +467,7 @@ fn opaque_ty(ctx: &mut ClangParserCtx, ty: &cx::Type) {
struct Annotations {
opaque: bool,
hide: bool,
+ use_as: Option<String>,
}
impl Annotations {
@@ -474,6 +475,7 @@ impl Annotations {
let mut anno = Annotations {
opaque: false,
hide: false,
+ use_as: None,
};
anno.parse(&cursor.comment());
@@ -487,10 +489,10 @@ impl Annotations {
comment.get_tag_attr_name(0) == "rustbindgen" {
for i in 0..comment.get_num_tag_attrs() {
let name = comment.get_tag_attr_name(i);
-
match name.as_str() {
"opaque" => self.opaque = true,
"hide" => self.hide = true,
+ "replaces" => self.use_as = Some(comment.get_tag_attr_value(i)),
_ => (),
}
}
@@ -860,7 +862,7 @@ fn visit_top(cursor: &Cursor,
| CXCursor_ClassDecl
| CXCursor_ClassTemplate => {
let anno = Annotations::new(cursor);
- fwd_decl(ctx, cursor, |ctx_| {
+ fwd_decl(ctx, cursor, move |ctx_| {
let decl = decl_name(ctx_, cursor);
let ci = decl.compinfo();
cursor.visit(|c, p| {
@@ -873,7 +875,12 @@ fn visit_top(cursor: &Cursor,
if anno.hide {
ci.borrow_mut().hide = true;
}
- ctx_.current_module_mut().globals.push(GComp(ci));
+ if let Some(other_type_name) = anno.use_as {
+ ci.borrow_mut().name = other_type_name.clone();
+ ctx_.current_module_mut().translations.insert(other_type_name, GComp(ci));
+ } else {
+ ctx_.current_module_mut().globals.push(GComp(ci));
+ }
});
CXChildVisit_Continue
}