Ast: impl default onto all nodes
This commit is contained in:
parent
279c9d6135
commit
d935533b6a
|
@ -2,7 +2,7 @@
|
||||||
gen_decl = 0.7
|
gen_decl = 0.7
|
||||||
gen_subroutine = 0.0
|
gen_subroutine = 0.0
|
||||||
gen_typedef = 0.0
|
gen_typedef = 0.0
|
||||||
end_generation = 0.3
|
end_generation = 0.1
|
||||||
|
|
||||||
[statements]
|
[statements]
|
||||||
[statements.gen_assign]
|
[statements.gen_assign]
|
||||||
|
|
27
src/ast.rs
27
src/ast.rs
|
@ -12,6 +12,13 @@ pub trait Statement: AstNode {}
|
||||||
pub enum Quantifier {
|
pub enum Quantifier {
|
||||||
Const,
|
Const,
|
||||||
Var,
|
Var,
|
||||||
|
Unset,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for Quantifier {
|
||||||
|
fn default() -> Self {
|
||||||
|
Quantifier::Unset
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToString for Quantifier {
|
impl ToString for Quantifier {
|
||||||
|
@ -19,6 +26,7 @@ impl ToString for Quantifier {
|
||||||
match *self {
|
match *self {
|
||||||
Quantifier::Const => "const",
|
Quantifier::Const => "const",
|
||||||
Quantifier::Var => "var",
|
Quantifier::Var => "var",
|
||||||
|
Quantifier::Unset => panic!("Found unset quantifier"),
|
||||||
}.to_string()
|
}.to_string()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,6 +36,13 @@ pub enum BaseType {
|
||||||
Int,
|
Int,
|
||||||
Real,
|
Real,
|
||||||
Never,
|
Never,
|
||||||
|
Unset,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for BaseType {
|
||||||
|
fn default() -> Self {
|
||||||
|
BaseType::Unset
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToString for BaseType {
|
impl ToString for BaseType {
|
||||||
|
@ -37,6 +52,7 @@ impl ToString for BaseType {
|
||||||
BaseType::Int => "integer",
|
BaseType::Int => "integer",
|
||||||
BaseType::Real => "real",
|
BaseType::Real => "real",
|
||||||
BaseType::Never => panic!("Attempting to get string of never type"),
|
BaseType::Never => panic!("Attempting to get string of never type"),
|
||||||
|
BaseType::Unset => panic!("Found unset basetype"),
|
||||||
}.to_string()
|
}.to_string()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -47,7 +63,7 @@ pub struct GlobalBlock {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl 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);
|
self.statements.push(node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -71,7 +87,7 @@ pub struct Block {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl 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);
|
self.statements.push(node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -94,6 +110,7 @@ impl AstNode for Block {}
|
||||||
|
|
||||||
impl Statement for Block {}
|
impl Statement for Block {}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
pub enum Literal {
|
pub enum Literal {
|
||||||
Int(i32),
|
Int(i32),
|
||||||
Real(f32),
|
Real(f32),
|
||||||
|
@ -119,7 +136,7 @@ impl Expr for Literal {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Builder)]
|
#[derive(Default, Builder)]
|
||||||
pub struct Declaration <T: Expr> {
|
pub struct Declaration <T: Expr> {
|
||||||
variable: Variable,
|
variable: Variable,
|
||||||
assn: T,
|
assn: T,
|
||||||
|
@ -146,7 +163,8 @@ impl<T: Expr> AstNode for Declaration<T> {}
|
||||||
|
|
||||||
impl<T: Expr> Statement for Declaration<T> {}
|
impl<T: Expr> Statement for Declaration<T> {}
|
||||||
|
|
||||||
#[derive(Clone, Builder)]
|
#[derive(Clone, Default, Builder)]
|
||||||
|
#[builder(setter(into))]
|
||||||
pub struct Variable {
|
pub struct Variable {
|
||||||
type_: BaseType,
|
type_: BaseType,
|
||||||
quantifer: Quantifier,
|
quantifer: Quantifier,
|
||||||
|
@ -167,6 +185,7 @@ impl Expr for Variable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
pub enum BinaryOperator <L: Expr, R: Expr>
|
pub enum BinaryOperator <L: Expr, R: Expr>
|
||||||
{
|
{
|
||||||
Add(L, R),
|
Add(L, R),
|
||||||
|
|
Loading…
Reference in a new issue