use super::context::{BindgenContext, ItemId};
use super::dot::DotAttributes;
use clang;
use parse::{ClangSubItemParser, ParseError, ParseResult};
use parse_one;
use std::io;
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum ModuleKind {
Normal,
Inline,
}
#[derive(Clone, Debug)]
pub struct Module {
name: Option<String>,
kind: ModuleKind,
children_ids: Vec<ItemId>,
}
impl Module {
pub fn new(name: Option<String>, kind: ModuleKind) -> Self {
Module {
name: name,
kind: kind,
children_ids: vec![],
}
}
pub fn name(&self) -> Option<&str> {
self.name.as_ref().map(|n| &**n)
}
pub fn children_mut(&mut self) -> &mut Vec<ItemId> {
&mut self.children_ids
}
pub fn children(&self) -> &[ItemId] {
&self.children_ids
}
pub fn is_inline(&self) -> bool {
self.kind == ModuleKind::Inline
}
}
impl DotAttributes for Module {
fn dot_attributes<W>(&self,
_ctx: &BindgenContext,
out: &mut W)
-> io::Result<()>
where W: io::Write,
{
writeln!(out, "<tr><td>ModuleKind</td><td>{:?}</td></tr>", self.kind)
}
}
impl ClangSubItemParser for Module {
fn parse(cursor: clang::Cursor,
ctx: &mut BindgenContext)
-> Result<ParseResult<Self>, ParseError> {
use clang_sys::*;
match cursor.kind() {
CXCursor_Namespace => {
let module_id = ctx.module(cursor);
ctx.with_module(module_id, |ctx| {
cursor.visit(|cursor| {
parse_one(ctx, cursor, Some(module_id))
})
});
Ok(ParseResult::AlreadyResolved(module_id))
}
_ => Err(ParseError::Continue),
}
}
}