aboutsummaryrefslogtreecommitdiff
path: root/src/ast.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ast.c')
-rw-r--r--src/ast.c27
1 files changed, 6 insertions, 21 deletions
diff --git a/src/ast.c b/src/ast.c
index 4194737..69243f8 100644
--- a/src/ast.c
+++ b/src/ast.c
@@ -19,6 +19,7 @@ static void ast_resolve(Ast *self, AstCompilerContext *context);
static void resolve_data_init(AstResolveData *self) {
self->status = AST_NOT_RESOLVED;
+ self->parser = NULL;
self->type = NULL;
}
@@ -94,7 +95,7 @@ void structfield_init(StructField *self, BufferView name, BufferView type_name)
variable_init(&self->type, type_name);
}
-int lhsexpr_init(LhsExpr *self, bool is_extern, bool is_pub, bool is_const, BufferView var_name, ScopedAllocator *allocator) {
+void lhsexpr_init(LhsExpr *self, bool is_extern, bool is_pub, bool is_const, BufferView var_name) {
self->is_extern = is_extern;
self->is_pub = is_pub;
self->is_const = is_const;
@@ -102,8 +103,6 @@ int lhsexpr_init(LhsExpr *self, bool is_extern, bool is_pub, bool is_const, Buff
self->type.value.variable = NULL;
self->var_name = var_name;
self->rhs_expr = NULL;
- return_if_error(scoped_allocator_create_mutex(allocator, &self->mutex));
- return 0;
}
void assignmentexpr_init(AssignmentExpr *self, Ast *lhs_expr, Ast *rhs_expr) {
@@ -159,7 +158,7 @@ int while_statement_init(WhileStatement *self, Scope *parent, ScopedAllocator *a
int scope_init(Scope *self, Scope *parent, ScopedAllocator *allocator) {
return_if_error(buffer_init(&self->ast_objects, allocator));
- return_if_error(hash_map_init(&self->named_objects, allocator, sizeof(Ast*), hash_compare_string, amal_hash_string));
+ return_if_error(hash_map_init(&self->named_objects, allocator, sizeof(Ast*), hash_map_compare_string, amal_hash_string));
self->parent = parent;
self->parser = NULL;
return 0;
@@ -627,6 +626,7 @@ static void while_statement_resolve(WhileStatement *while_stmt, AstCompilerConte
void ast_resolve(Ast *self, AstCompilerContext *context) {
assert(self);
+ assert(context->parser);
/*
TODO: Move these to the types that need checks for recursive dependency (function declaration, struct declaration)
For function declaration, it should be marked as resolved when the signature has been resolved
@@ -640,28 +640,15 @@ void ast_resolve(Ast *self, AstCompilerContext *context) {
*/
if(self->resolve_data.status == AST_RESOLVED) {
return;
- } else if(self->resolve_data.status == AST_RESOLVING) {
+ } else if(self->resolve_data.status == AST_RESOLVING && self->resolve_data.parser == context->parser) {
Parser *parser;
parser = scope_get_parser(context->scope);
parser_print_error(parser, ast_get_code_reference(self).data, "Found recursive dependency");
throw(AST_ERR);
}
- if(self->type == AST_LHS) {
- throw_if_error(amal_mutex_lock(self->value.lhs_expr->mutex, "ast_resolve"));
- if(self->resolve_data.status == AST_RESOLVED) {
- amal_mutex_tryunlock(self->value.lhs_expr->mutex);
- return;
- } else if(self->resolve_data.status == AST_RESOLVING) {
- Parser *parser;
- parser = scope_get_parser(context->scope);
- amal_mutex_tryunlock(self->value.lhs_expr->mutex);
- parser_print_error(parser, ast_get_code_reference(self).data, "Found recursive dependency");
- throw(AST_ERR);
- }
- }
-
self->resolve_data.status = AST_RESOLVING;
+ self->resolve_data.parser = context->parser;
switch(self->type) {
case AST_NUMBER: {
Number *number;
@@ -714,6 +701,4 @@ void ast_resolve(Ast *self, AstCompilerContext *context) {
}
/* TODO: See comment at the top of this function */
self->resolve_data.status = AST_RESOLVED;
- if(self->type == AST_LHS)
- amal_mutex_tryunlock(self->value.lhs_expr->mutex);
}