aboutsummaryrefslogtreecommitdiff
path: root/src/ast.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ast.c')
-rw-r--r--src/ast.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/ast.c b/src/ast.c
index e28b072..0aa19d4 100644
--- a/src/ast.c
+++ b/src/ast.c
@@ -95,15 +95,21 @@ int structdecl_init(StructDecl *self, Scope *parent, ArenaAllocator *allocator)
return scope_init(&self->body, parent, allocator);
}
+LhsExpr* structdecl_get_field_by_name(StructDecl *self, BufferView field_name) {
+ Ast* result;
+ if(!hash_map_get(&self->body.named_objects, field_name, &result))
+ return NULL;
+ return result->value.lhs_expr;
+}
+
void structfield_init(StructField *self, BufferView name, BufferView type_name) {
self->name = name;
variable_init(&self->type, type_name);
}
-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;
+void lhsexpr_init(LhsExpr *self, DeclFlag decl_flag, BufferView var_name) {
+ assert(!((decl_flag & DECL_FLAG_EXTERN) && (decl_flag & DECL_FLAG_EXPORT)) && "Expression cant be both extern and export");
+ self->decl_flags = decl_flag;
self->type.type = VARIABLE_TYPE_NONE;
self->type.value.variable = NULL;
self->var_name = var_name;
@@ -423,7 +429,7 @@ static void assignmentexpr_resolve(Ast *ast, AstCompilerContext *context) {
/* This also covers extern variables, since extern variables are always const */
/* TODO: var.field type expressions should also be checked */
- if(lhs_source && lhs_source->is_const) {
+ if(lhs_source && LHS_EXPR_IS_CONST(lhs_source)) {
Parser *parser;
parser = scope_get_parser(context->scope);
parser_print_error(parser, ast_get_code_reference(self->lhs_expr).data, "Can't assign to a const value");
@@ -587,7 +593,7 @@ static void binop_resolve_dot_access(Ast *ast, AstCompilerContext *context) {
throw(AST_ERR);
}
- if(!self->rhs->resolve_data.type->is_pub) {
+ if(!LHS_EXPR_IS_PUB(self->rhs->resolve_data.type)) {
parser_print_error(caller_parser, caller_code_ref.data, "Can't access non-public field \"%.*s\"", caller_code_ref.size, caller_code_ref.data);
/* TODO: use tokenizer_print_note, once it has been added */
/* TODO: Print type */