use Options;
use core::Handle;
use core::errors::Result;
use flavored::{RpEnumBody, RpInterfaceBody, RpServiceBody};
use genco::java::{Class, Enum, Interface, Method};
use std::rc::Rc;
macro_rules! codegen {
($type:tt, $e:ty) => {
impl<T> $type for Rc<T>
where
T: $type,
{
fn generate(&self, e: $e) -> Result<()> {
self.as_ref().generate(e)
}
}
};
}
pub struct GetterAdded<'a, 'el: 'a> {
pub name: &'el str,
pub getter: &'a mut Method<'el>,
}
pub struct ClassAdded<'a, 'el: 'a> {
pub names: &'a [&'el str],
pub spec: &'a mut Class<'el>,
pub interface: Option<&'a RpInterfaceBody>,
}
pub struct TupleAdded<'a, 'el: 'a> {
pub spec: &'a mut Class<'el>,
}
pub struct EnumAdded<'a, 'el: 'a> {
pub body: &'el RpEnumBody,
pub spec: &'a mut Enum<'el>,
pub from_value: &'a mut Method<'el>,
pub to_value: &'a mut Method<'el>,
}
pub struct InterfaceAdded<'a, 'el: 'a> {
pub body: &'el RpInterfaceBody,
pub spec: &'a mut Interface<'el>,
}
pub struct ServiceAdded<'a, 'el: 'a> {
pub body: &'el RpServiceBody,
pub spec: &'a mut Interface<'el>,
}
pub struct Configure<'a> {
pub options: &'a mut Options,
}
pub trait Codegen {
fn generate(&self, handle: &Handle) -> Result<()>;
}
pub trait ServiceCodegen {
fn generate(&self, e: ServiceAdded) -> Result<()>;
}
codegen!(ServiceCodegen, ServiceAdded);
pub trait GetterCodegen {
fn generate(&self, e: GetterAdded) -> Result<()>;
}
codegen!(GetterCodegen, GetterAdded);
pub trait ClassCodegen {
fn generate(&self, e: ClassAdded) -> Result<()>;
}
codegen!(ClassCodegen, ClassAdded);
pub trait TupleCodegen {
fn generate(&self, e: TupleAdded) -> Result<()>;
}
codegen!(TupleCodegen, TupleAdded);
pub trait InterfaceCodegen {
fn generate(&self, e: InterfaceAdded) -> Result<()>;
}
codegen!(InterfaceCodegen, InterfaceAdded);
pub trait EnumCodegen {
fn generate(&self, e: EnumAdded) -> Result<()>;
}
codegen!(EnumCodegen, EnumAdded);