add stmt to ast

This commit is contained in:
nora 2022-07-05 20:25:58 +02:00
parent 30da01fc05
commit fb1ce74e08
2 changed files with 39 additions and 7 deletions

View file

@ -5,13 +5,15 @@ use dbg_pls::DebugPls;
use crate::Spanned;
pub type Ident = Spanned<String>;
//
// --- Expr
//
#[derive(Debug, DebugPls)]
pub enum Atom {
Ident(String),
Ident(Ident),
Int(i128),
Float(f64),
String(String),
@ -83,6 +85,38 @@ pub enum Expr {
Binary(ExprBinary),
}
//
// --- Statements
//
#[derive(Debug, DebugPls)]
pub enum Stmt {
Labeled(Box<Spanned<Stmt>>),
Compound(Vec<Spanned<Stmt>>),
If {
cond: Expr,
then: Vec<Spanned<Stmt>>,
otherwise: Option<Vec<Spanned<Stmt>>>,
},
Switch,
While {
cond: Expr,
body: Vec<Spanned<Stmt>>,
},
For {
init_decl: Option<Spanned<Decl>>,
init_expr: Option<Spanned<Expr>>,
cond: Option<Spanned<Expr>>,
post: Option<Spanned<Expr>>,
body: Vec<Spanned<Stmt>>,
},
Goto(Ident),
Continue,
Break,
Return(Option<Spanned<Expr>>),
Expr(Expr),
}
//
// --- Types and decls and garbage whatever
//
@ -107,8 +141,6 @@ pub enum TypeSpecifier {
// typedef-name
}
pub type Ident = Spanned<String>;
bitflags! {
pub struct DeclAttr: u8 {
const EXTERN = 0b00000001;
@ -174,7 +206,7 @@ pub struct Declarator {
#[derive(Debug, DebugPls)]
pub struct FunctionDef {
pub decl: Decl,
pub body: Vec<()>,
pub body: Vec<Stmt>,
}
#[derive(Debug, DebugPls)]