diff options
Diffstat (limited to 'src/ast.c')
-rw-r--r-- | src/ast.c | 26 |
1 files changed, 9 insertions, 17 deletions
@@ -82,7 +82,8 @@ void structfield_init(StructField *self, BufferView name, BufferView type_name) variable_init(&self->type, type_name); } -void lhsexpr_init(LhsExpr *self, bool is_const, BufferView var_name) { +void lhsexpr_init(LhsExpr *self, bool is_pub, bool is_const, BufferView var_name) { + self->is_pub = is_pub; self->is_const = is_const; variable_init(&self->type, create_buffer_view_null()); self->var_name = var_name; @@ -107,7 +108,6 @@ void number_init(Number *self, i64 value, bool is_integer) { void variable_init(Variable *self, BufferView name) { self->name = name; - self->resolved_variable = ast_none(); } void binop_init(Binop *self) { @@ -171,7 +171,7 @@ void scope_resolve(Scope *self, AstCompilerContext *context) { context->scope = self->parent; } -static Ast scope_get_resolved_variable(Scope *self, AstCompilerContext *context, BufferView name) { +static LhsExpr* scope_get_resolved_variable(Scope *self, AstCompilerContext *context, BufferView name) { Ast result; bool exists; Scope *prev_scope; @@ -199,20 +199,13 @@ static Ast scope_get_resolved_variable(Scope *self, AstCompilerContext *context, context->scope = prev_scope; assert(result.type == AST_LHS); - return result.value.lhs_expr->rhs_expr; + return result.value.lhs_expr; } -static void variable_resolve(Variable *self, AstCompilerContext *context, StructDecl **resolved_type) { - self->resolved_variable = scope_get_resolved_variable(context->scope, context, self->name); - /* TODO: Implement */ - if(self->resolved_variable.type == AST_STRUCT_DECL) { - *resolved_type = self->resolved_variable.value.struct_decl; - } else if(self->resolved_variable.type == AST_FUNCTION_DECL) { - /* TODO: Set resolved type to function declaration return type */ - *resolved_type = NULL; - } else { - *resolved_type = NULL; - } +/* @resolved_type is the same field as the ast resolved_type for the variable @self */ +static void variable_resolve(Variable *self, AstCompilerContext *context, LhsExpr **resolved_type) { + /* TODO: Verify this is correct in all cases */ + *resolved_type = scope_get_resolved_variable(context->scope, context, self->name); } static void lhs_resolve(Ast *self, AstCompilerContext *context) { @@ -269,10 +262,9 @@ static void funccall_resolve(Ast *self, AstCompilerContext *context) { } static void structdecl_resolve(Ast *self, AstCompilerContext *context) { - /* TODO: Implement */ + /* TODO: What to do with resolved_type? */ StructDecl *struct_decl; struct_decl = self->value.struct_decl; - self->resolved_type = struct_decl; scope_resolve(&struct_decl->body, context); } |