Ast: typedef statements
This commit is contained in:
parent
f9e4e554b6
commit
4006e0778c
2 changed files with 26 additions and 0 deletions
|
@ -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;
|
||||
|
|
|
@ -9,6 +9,7 @@ use super::GazType;
|
|||
pub enum Stat {
|
||||
Block(Box<Block>),
|
||||
Declaration(Box<Declaration>),
|
||||
TypeDef(Box<TypeDef>),
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue