refactor(sema): Separated from ir
This commit is contained in:
+106
@@ -0,0 +1,106 @@
|
||||
use crate::{ast::types::{BinaryOp, UnaryOp}, diagnostic::span::Span, sema::{symbol::{FunctionId, FunctionSig, SymbolId}, types::SemaType}};
|
||||
|
||||
pub struct HirCompileUnit {
|
||||
pub global_decls: Vec<HirGlobalDeclStmt>,
|
||||
}
|
||||
|
||||
pub enum HirGlobalDeclStmt {
|
||||
VarDecl(HirVarDeclStmt),
|
||||
FuncDecl(HirFuncDeclStmt),
|
||||
}
|
||||
|
||||
pub struct HirVarDeclStmt {
|
||||
pub values: Vec<HirVarDeclStmtValue>,
|
||||
pub data_type: SemaType,
|
||||
pub type_span: Span,
|
||||
}
|
||||
|
||||
pub struct HirVarDeclStmtValue {
|
||||
pub symbol: SymbolId,
|
||||
pub name_span: Span,
|
||||
}
|
||||
|
||||
pub struct HirFuncDeclStmt {
|
||||
pub sig: FunctionSig,
|
||||
pub params: Vec<HirParam>,
|
||||
pub body: HirBlockStmt,
|
||||
pub ret_type_span: Span,
|
||||
pub name_span: Span,
|
||||
}
|
||||
|
||||
pub struct HirParam {
|
||||
pub symbol: SymbolId,
|
||||
pub param_type: SemaType,
|
||||
pub name_span: Span,
|
||||
pub type_span: Span,
|
||||
}
|
||||
|
||||
pub struct HirBlockStmt {
|
||||
pub statements: Vec<HirStatement>,
|
||||
}
|
||||
|
||||
pub enum HirStatement {
|
||||
Return(HirReturnStmt),
|
||||
Block(HirBlockStmt),
|
||||
Expr(HirExpr),
|
||||
VarDecl(HirVarDeclStmt),
|
||||
If(HirIfStmt),
|
||||
While(HirWhileStmt),
|
||||
Break(HirBreakStmt),
|
||||
Continue(HirContinueStmt),
|
||||
}
|
||||
|
||||
pub struct HirIfStmt {
|
||||
pub condition: HirExpr,
|
||||
pub then_branch: HirBlockStmt,
|
||||
pub ifelse_branch: Vec<HirIfElseBranch>,
|
||||
pub else_branch: Option<HirBlockStmt>,
|
||||
}
|
||||
|
||||
pub struct HirIfElseBranch {
|
||||
pub condition: HirExpr,
|
||||
pub then_branch: HirBlockStmt,
|
||||
}
|
||||
|
||||
pub struct HirWhileStmt {
|
||||
pub condition: HirExpr,
|
||||
pub body: HirBlockStmt,
|
||||
}
|
||||
|
||||
pub struct HirBreakStmt {
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
pub struct HirContinueStmt {
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
pub struct HirReturnStmt {
|
||||
pub value: Option<HirExpr>,
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
pub struct HirExpr {
|
||||
pub value: HirExprValue,
|
||||
pub ty: SemaType,
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
pub enum HirExprValue {
|
||||
IntLit(i64),
|
||||
Var(SymbolId),
|
||||
BinaryOp {
|
||||
lhs: Box<HirExpr>,
|
||||
op: BinaryOp,
|
||||
rhs: Box<HirExpr>,
|
||||
},
|
||||
UnaryOp {
|
||||
op: UnaryOp,
|
||||
operand: Box<HirExpr>,
|
||||
},
|
||||
FuncCall(FunctionId, Vec<HirExpr>),
|
||||
Assign {
|
||||
lvalue: Box<HirExpr>,
|
||||
rvalue: Box<HirExpr>,
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user