diff --git a/src/ast/mod.rs b/src/ast/mod.rs index 7be8600..6912899 100644 --- a/src/ast/mod.rs +++ b/src/ast/mod.rs @@ -14,6 +14,8 @@ pub use statement::Block; pub use statement::GlobalBlock; pub use statement::Declaration; pub use statement::DeclarationBuilder; +pub use statement::TypeDef; +pub use statement::TypeDefBuilder; pub trait GazType { fn get_base(&self) -> BaseType; diff --git a/src/ast/statement.rs b/src/ast/statement.rs index 4ff3d5d..2ce8a9e 100644 --- a/src/ast/statement.rs +++ b/src/ast/statement.rs @@ -9,6 +9,7 @@ use super::GazType; pub enum Stat { Block(Box), Declaration(Box), + TypeDef(Box), } impl Stat { @@ -19,6 +20,10 @@ impl Stat { pub fn new_decl(x: Declaration) -> Self { Self::Declaration(Box::new(x)) } + + pub fn new_typedef(x: TypeDef) -> Self { + Self::TypeDef(Box::new(x)) + } } impl ToString for Stat { @@ -26,6 +31,7 @@ impl ToString for Stat { match self { Stat::Block(x) => x.to_string(), Stat::Declaration(x) => x.to_string(), + Stat::TypeDef(x) => x.to_string(), } } } @@ -101,3 +107,21 @@ impl ToString for Declaration { s } } + +#[derive(Clone, Default, Builder)] +pub struct TypeDef { + old_name: String, + new_name: String, + basetype: BaseType, +} + +impl ToString for TypeDef { + fn to_string(&self) -> String { + let mut s = String::from("typedef "); + s.push_str(&self.old_name); + s.push(' '); + s.push_str(&self.new_name); + s.push(';'); + s + } +}