Ast: typedef statements

This commit is contained in:
Akemi Izuko 2023-11-17 15:31:47 -07:00
parent f9e4e554b6
commit 4006e0778c
Signed by: akemi
GPG key ID: 8DE0764E1809E9FC
2 changed files with 26 additions and 0 deletions

View file

@ -14,6 +14,8 @@ pub use statement::Block;
pub use statement::GlobalBlock; pub use statement::GlobalBlock;
pub use statement::Declaration; pub use statement::Declaration;
pub use statement::DeclarationBuilder; pub use statement::DeclarationBuilder;
pub use statement::TypeDef;
pub use statement::TypeDefBuilder;
pub trait GazType { pub trait GazType {
fn get_base(&self) -> BaseType; fn get_base(&self) -> BaseType;

View file

@ -9,6 +9,7 @@ use super::GazType;
pub enum Stat { pub enum Stat {
Block(Box<Block>), Block(Box<Block>),
Declaration(Box<Declaration>), Declaration(Box<Declaration>),
TypeDef(Box<TypeDef>),
} }
impl Stat { impl Stat {
@ -19,6 +20,10 @@ impl Stat {
pub fn new_decl(x: Declaration) -> Self { pub fn new_decl(x: Declaration) -> Self {
Self::Declaration(Box::new(x)) Self::Declaration(Box::new(x))
} }
pub fn new_typedef(x: TypeDef) -> Self {
Self::TypeDef(Box::new(x))
}
} }
impl ToString for Stat { impl ToString for Stat {
@ -26,6 +31,7 @@ impl ToString for Stat {
match self { match self {
Stat::Block(x) => x.to_string(), Stat::Block(x) => x.to_string(),
Stat::Declaration(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 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
}
}