Scope postfix ast walking

This commit is contained in:
2026-04-16 09:11:06 +02:00
parent bf3783a615
commit 1babc77957
2 changed files with 37 additions and 5 deletions
+29 -1
View File
@@ -3,7 +3,7 @@ use std::{
sync::{Arc, Mutex}, sync::{Arc, Mutex},
}; };
use parser::ast::{self, ParamList, Statement}; use parser::ast::{self, ParamList, Postfix, Statement};
use crate::{ use crate::{
hir::{FunctionRef, TopLevelHirScope, TypeRef, VarRef}, hir::{FunctionRef, TopLevelHirScope, TypeRef, VarRef},
@@ -83,6 +83,30 @@ impl LocalScope {
} }
} }
pub fn walk_postfixes(
self: &Arc<Self>,
initial: &Box<ast::Expression>,
postfixes: &Vec<Postfix>,
) -> Option<Arc<TypeRef>> {
let mut current_type = self.get_type_from_expr(initial)?;
dbg!(current_type.clone(), initial, postfixes);
for postfix in postfixes {
match postfix {
Postfix::FieldAccess(id) => match &*current_type {
TypeRef::Struct(s) => {
current_type = s.fields.get(id)?.var_type.clone();
}
_ => unimplemented!(),
},
_ => unimplemented!(),
}
}
Some(current_type)
}
pub fn get_type_from_expr(self: &Arc<Self>, expr: &ast::Expression) -> Option<Arc<TypeRef>> { pub fn get_type_from_expr(self: &Arc<Self>, expr: &ast::Expression) -> Option<Arc<TypeRef>> {
match expr { match expr {
ast::Expression::IntLiteral(_) => { ast::Expression::IntLiteral(_) => {
@@ -131,6 +155,10 @@ impl LocalScope {
_ => None, _ => None,
}, },
ast::Expression::Postfix { initial, postfixes } => {
self.walk_postfixes(initial, postfixes)
}
_ => unimplemented!(), _ => unimplemented!(),
} }
} }
+8 -4
View File
@@ -1,5 +1,9 @@
function add(a: int, b: int) { struct Test {
let myVar = 10; x: int
}
let test = myVar; function add() {
} let output = test().x;
}
function test(): Test { }