Identifier fields
This commit is contained in:
+14
-5
@@ -84,8 +84,8 @@ impl LocalScope {
|
|||||||
|
|
||||||
pub fn walk_postfixes(
|
pub fn walk_postfixes(
|
||||||
self: &Arc<Self>,
|
self: &Arc<Self>,
|
||||||
initial: &Box<ast::Expression>,
|
initial: &mut Box<ast::Expression>,
|
||||||
postfixes: &Vec<Postfix>,
|
postfixes: &mut Vec<Postfix>,
|
||||||
) -> Option<Arc<TypeRef>> {
|
) -> Option<Arc<TypeRef>> {
|
||||||
let mut current_type = self.get_type_from_expr(initial)?;
|
let mut current_type = self.get_type_from_expr(initial)?;
|
||||||
|
|
||||||
@@ -93,7 +93,9 @@ impl LocalScope {
|
|||||||
match postfix {
|
match postfix {
|
||||||
Postfix::FieldAccess(id) => match &*current_type {
|
Postfix::FieldAccess(id) => match &*current_type {
|
||||||
TypeRef::Struct(s) => {
|
TypeRef::Struct(s) => {
|
||||||
current_type = s.fields.get(id)?.var_type.clone();
|
let field = s.fields.get(id)?;
|
||||||
|
*id = field.name.clone();
|
||||||
|
current_type = field.var_type.clone();
|
||||||
}
|
}
|
||||||
_ => unimplemented!(),
|
_ => unimplemented!(),
|
||||||
},
|
},
|
||||||
@@ -111,7 +113,10 @@ impl LocalScope {
|
|||||||
Some(current_type)
|
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: &mut ast::Expression,
|
||||||
|
) -> Option<Arc<TypeRef>> {
|
||||||
match expr {
|
match expr {
|
||||||
ast::Expression::IntLiteral(_) => self
|
ast::Expression::IntLiteral(_) => self
|
||||||
.parent
|
.parent
|
||||||
@@ -133,7 +138,11 @@ impl LocalScope {
|
|||||||
.get_reference(&"string".to_string())
|
.get_reference(&"string".to_string())
|
||||||
.map(|r| r.var_type.clone()),
|
.map(|r| r.var_type.clone()),
|
||||||
|
|
||||||
ast::Expression::Identifier(id) => self.get_reference(id).map(|r| r.var_type.clone()),
|
ast::Expression::Identifier(id) => {
|
||||||
|
let rf = self.get_reference(id)?;
|
||||||
|
*id = rf.name.clone();
|
||||||
|
Some(rf.var_type.clone())
|
||||||
|
}
|
||||||
|
|
||||||
ast::Expression::Postfix { initial, postfixes } => {
|
ast::Expression::Postfix { initial, postfixes } => {
|
||||||
self.walk_postfixes(initial, postfixes)
|
self.walk_postfixes(initial, postfixes)
|
||||||
|
|||||||
+6
-2
@@ -1,5 +1,9 @@
|
|||||||
function test(): int { }
|
struct MyType {
|
||||||
|
x: int,
|
||||||
|
}
|
||||||
|
|
||||||
|
function test(): MyType { }
|
||||||
|
|
||||||
function add() {
|
function add() {
|
||||||
let output = test();
|
let output = test().x;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user