Ast: impl default onto all nodes

This commit is contained in:
Akemi Izuko 2023-11-16 19:43:53 -07:00
parent 279c9d6135
commit d935533b6a
Signed by: akemi
GPG key ID: 8DE0764E1809E9FC
2 changed files with 24 additions and 5 deletions

View file

@ -2,7 +2,7 @@
gen_decl = 0.7
gen_subroutine = 0.0
gen_typedef = 0.0
end_generation = 0.3
end_generation = 0.1
[statements]
[statements.gen_assign]

View file

@ -12,6 +12,13 @@ pub trait Statement: AstNode {}
pub enum Quantifier {
Const,
Var,
Unset,
}
impl Default for Quantifier {
fn default() -> Self {
Quantifier::Unset
}
}
impl ToString for Quantifier {
@ -19,6 +26,7 @@ impl ToString for Quantifier {
match *self {
Quantifier::Const => "const",
Quantifier::Var => "var",
Quantifier::Unset => panic!("Found unset quantifier"),
}.to_string()
}
}
@ -28,6 +36,13 @@ pub enum BaseType {
Int,
Real,
Never,
Unset,
}
impl Default for BaseType {
fn default() -> Self {
BaseType::Unset
}
}
impl ToString for BaseType {
@ -37,6 +52,7 @@ impl ToString for BaseType {
BaseType::Int => "integer",
BaseType::Real => "real",
BaseType::Never => panic!("Attempting to get string of never type"),
BaseType::Unset => panic!("Found unset basetype"),
}.to_string()
}
}
@ -47,7 +63,7 @@ pub struct GlobalBlock {
}
impl GlobalBlock {
pub fn push_node(&mut self, node: Box<dyn Statement>) {
pub fn push(&mut self, node: Box<dyn Statement>) {
self.statements.push(node);
}
}
@ -71,7 +87,7 @@ pub struct Block {
}
impl Block {
pub fn push_node(&mut self, node: Box<dyn Statement>) {
pub fn push(&mut self, node: Box<dyn Statement>) {
self.statements.push(node);
}
}
@ -94,6 +110,7 @@ impl AstNode for Block {}
impl Statement for Block {}
#[derive(Debug, Clone)]
pub enum Literal {
Int(i32),
Real(f32),
@ -119,7 +136,7 @@ impl Expr for Literal {
}
}
#[derive(Builder)]
#[derive(Default, Builder)]
pub struct Declaration <T: Expr> {
variable: Variable,
assn: T,
@ -146,7 +163,8 @@ impl<T: Expr> AstNode for Declaration<T> {}
impl<T: Expr> Statement for Declaration<T> {}
#[derive(Clone, Builder)]
#[derive(Clone, Default, Builder)]
#[builder(setter(into))]
pub struct Variable {
type_: BaseType,
quantifer: Quantifier,
@ -167,6 +185,7 @@ impl Expr for Variable {
}
}
#[derive(Debug, Clone)]
pub enum BinaryOperator <L: Expr, R: Expr>
{
Add(L, R),