summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmilio Cobos Álvarez <me@emiliocobos.me>2016-04-15 18:17:15 +0200
committerEmilio Cobos Álvarez <me@emiliocobos.me>2016-04-15 18:17:15 +0200
commitf89fe53c75ecd6550fb713e4aebd742f52d08523 (patch)
treeb28b0cf76688bf971461f81cec8126d3bb5345a3
parent043de681c09e4e123bd19aab23c55427f9d50c21 (diff)
parser: Robustness of opaque types with template parameters
-rw-r--r--src/parser.rs33
-rw-r--r--src/types.rs13
2 files changed, 28 insertions, 18 deletions
diff --git a/src/parser.rs b/src/parser.rs
index 454d8843..32a35afe 100644
--- a/src/parser.rs
+++ b/src/parser.rs
@@ -96,7 +96,7 @@ fn decl_name(ctx: &mut ClangParserCtx, cursor: &Cursor) -> Global {
CompKind::Struct
};
- let opaque = ctx.options.opaque_types.iter().any(|name| *name == spelling);
+ let mut opaque = ctx.options.opaque_types.iter().any(|name| *name == spelling);
let hide = ctx.options.blacklist_type.iter().any(|name| *name == spelling);
let mut has_non_type_template_params = false;
@@ -122,23 +122,22 @@ fn decl_name(ctx: &mut ClangParserCtx, cursor: &Cursor) -> Global {
_ => vec![],
};
- let module_id = if args.is_empty() {
- ctx.current_module_id
- } else {
- // it's an instantiation of another template,
- // find the canonical declaration to find the module it belongs to.
- let parent = cursor.specialized();
- ctx.name.get(&parent).and_then(|global| {
- if let GCompDecl(ref ci) = *global {
- Some(ci.borrow().module_id)
- } else {
- None
+ let mut module_id = ctx.current_module_id;
+
+ // If it's an instantiation of another template,
+ // find the canonical declaration to find the module
+ // it belongs to and if it's opaque.
+ let parent = cursor.specialized();
+ if let Some(parent) = ctx.name.get(&parent) {
+ match *parent {
+ GComp(ref ci) |
+ GCompDecl(ref ci) => {
+ opaque |= ci.borrow().opaque;
+ module_id = ci.borrow().module_id;
}
- }).unwrap_or_else(|| {
- ctx.logger.warn("Template class wasn't declared when parsing specialisation!");
- ctx.current_module_id
- })
- };
+ _ => {}
+ }
+ }
let mut ci = CompInfo::new(spelling, module_id, filename, comment, kind, vec![], layout);
ci.opaque = opaque;
diff --git a/src/types.rs b/src/types.rs
index be1f4a5f..faaa0cae 100644
--- a/src/types.rs
+++ b/src/types.rs
@@ -213,8 +213,10 @@ impl Type {
pub fn is_opaque(&self) -> bool {
match *self {
+ TArray(ref t, _, _) => t.is_opaque(),
+ TPtr(ref t, _, _, _) => t.is_opaque(),
TNamed(ref ti) => ti.borrow().ty.is_opaque(),
- TComp(ref ci) => ci.borrow().opaque,
+ TComp(ref ci) => ci.borrow().is_opaque(),
_ => false,
}
}
@@ -400,6 +402,15 @@ impl CompInfo {
}
}
}
+
+ pub fn is_opaque(&self) -> bool {
+ if let Some(ref template) = self.ref_template {
+ if template.is_opaque() {
+ return true;
+ }
+ }
+ self.opaque
+ }
}
impl fmt::Debug for CompInfo {