diff --git a/nac3core/src/lib.rs b/nac3core/src/lib.rs index 69faf0bed..53d5d36ef 100644 --- a/nac3core/src/lib.rs +++ b/nac3core/src/lib.rs @@ -5,6 +5,7 @@ extern crate num_bigint; extern crate inkwell; extern crate rustpython_parser; +pub mod typedef; use std::error::Error; use std::fmt; use std::path::Path; diff --git a/nac3core/src/typedef.rs b/nac3core/src/typedef.rs new file mode 100644 index 000000000..bec61fd11 --- /dev/null +++ b/nac3core/src/typedef.rs @@ -0,0 +1,60 @@ +use std::collections::HashMap; +use std::rc::Rc; + +#[derive(PartialEq, Eq, Copy, Clone, Hash, Debug)] +pub struct PrimitiveId(pub(crate) usize); + +#[derive(PartialEq, Eq, Copy, Clone, Hash, Debug)] +pub struct ClassId(pub(crate) usize); + +#[derive(PartialEq, Eq, Copy, Clone, Hash, Debug)] +pub struct ParamId(pub(crate) usize); + +#[derive(PartialEq, Eq, Copy, Clone, Hash, Debug)] +pub struct VariableId(pub(crate) usize); + +#[derive(PartialEq, Eq, Clone, Hash, Debug)] +pub enum TypeEnum { + BotType, + SelfType, + PrimitiveType(PrimitiveId), + ClassType(ClassId), + VirtualClassType(ClassId), + ParametricType(ParamId, Vec>), + TypeVariable(VariableId), +} + +pub type Type = Rc; + +#[derive(Clone)] +pub struct FnDef { + // we assume methods first argument to be SelfType, + // so the first argument is not contained here + pub args: Vec, + pub result: Option, +} + +#[derive(Clone)] +pub struct TypeDef<'a> { + pub name: &'a str, + pub fields: HashMap<&'a str, Type>, + pub methods: HashMap<&'a str, FnDef>, +} + +#[derive(Clone)] +pub struct ClassDef<'a> { + pub base: TypeDef<'a>, + pub parents: Vec, +} + +#[derive(Clone)] +pub struct ParametricDef<'a> { + pub base: TypeDef<'a>, + pub params: Vec, +} + +#[derive(Clone)] +pub struct VarDef<'a> { + pub name: &'a str, + pub bound: Vec, +}