Scope postfix ast walking
This commit is contained in:
+29
-1
@@ -3,7 +3,7 @@ use std::{
|
||||
sync::{Arc, Mutex},
|
||||
};
|
||||
|
||||
use parser::ast::{self, ParamList, Statement};
|
||||
use parser::ast::{self, ParamList, Postfix, Statement};
|
||||
|
||||
use crate::{
|
||||
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>> {
|
||||
match expr {
|
||||
ast::Expression::IntLiteral(_) => {
|
||||
@@ -131,6 +155,10 @@ impl LocalScope {
|
||||
_ => None,
|
||||
},
|
||||
|
||||
ast::Expression::Postfix { initial, postfixes } => {
|
||||
self.walk_postfixes(initial, postfixes)
|
||||
}
|
||||
|
||||
_ => unimplemented!(),
|
||||
}
|
||||
}
|
||||
|
||||
+8
-4
@@ -1,5 +1,9 @@
|
||||
function add(a: int, b: int) {
|
||||
let myVar = 10;
|
||||
|
||||
let test = myVar;
|
||||
struct Test {
|
||||
x: int
|
||||
}
|
||||
|
||||
function add() {
|
||||
let output = test().x;
|
||||
}
|
||||
|
||||
function test(): Test { }
|
||||
Reference in New Issue
Block a user