mirror of
https://github.com/Ed94/Odin.git
synced 2026-07-20 16:36:46 +00:00
Big Refactor to type less :P
This commit is contained in:
+56
-57
@@ -19,8 +19,7 @@ struct Operand {
|
||||
AddressingMode mode;
|
||||
Type *type;
|
||||
ExactValue value;
|
||||
|
||||
AstNode *expression;
|
||||
AstNode *expr;
|
||||
BuiltinProcedureId builtin_id;
|
||||
};
|
||||
|
||||
@@ -30,7 +29,7 @@ struct TypeAndValue {
|
||||
ExactValue value;
|
||||
};
|
||||
|
||||
struct DeclarationInfo {
|
||||
struct DeclInfo {
|
||||
Scope *scope;
|
||||
|
||||
Entity **entities;
|
||||
@@ -45,26 +44,26 @@ struct DeclarationInfo {
|
||||
};
|
||||
|
||||
|
||||
void init_declaration_info(DeclarationInfo *d, Scope *scope) {
|
||||
void init_declaration_info(DeclInfo *d, Scope *scope) {
|
||||
d->scope = scope;
|
||||
map_init(&d->deps, gb_heap_allocator());
|
||||
}
|
||||
|
||||
DeclarationInfo *make_declaration_info(gbAllocator a, Scope *scope) {
|
||||
DeclarationInfo *d = gb_alloc_item(a, DeclarationInfo);
|
||||
DeclInfo *make_declaration_info(gbAllocator a, Scope *scope) {
|
||||
DeclInfo *d = gb_alloc_item(a, DeclInfo);
|
||||
init_declaration_info(d, scope);
|
||||
return d;
|
||||
}
|
||||
|
||||
void destroy_declaration_info(DeclarationInfo *d) {
|
||||
void destroy_declaration_info(DeclInfo *d) {
|
||||
map_destroy(&d->deps);
|
||||
}
|
||||
|
||||
b32 has_init(DeclarationInfo *d) {
|
||||
b32 has_init(DeclInfo *d) {
|
||||
if (d->init_expr != NULL)
|
||||
return true;
|
||||
if (d->proc_decl != NULL) {
|
||||
if (d->proc_decl->procedure_declaration.body != NULL)
|
||||
if (d->proc_decl->proc_decl.body != NULL)
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -91,7 +90,7 @@ ExpressionInfo make_expression_info(b32 is_lhs, AddressingMode mode, Type *type,
|
||||
struct ProcedureInfo {
|
||||
AstFile *file;
|
||||
Token token;
|
||||
DeclarationInfo *decl;
|
||||
DeclInfo *decl;
|
||||
Type * type; // Type_Procedure
|
||||
AstNode * body; // AstNode_BlockStatement
|
||||
};
|
||||
@@ -151,7 +150,7 @@ gb_global BuiltinProcedure builtin_procedures[BuiltinProcedure_Count] = {
|
||||
|
||||
struct CheckerContext {
|
||||
Scope *scope;
|
||||
DeclarationInfo *decl;
|
||||
DeclInfo *decl;
|
||||
};
|
||||
|
||||
struct CheckerInfo {
|
||||
@@ -160,7 +159,7 @@ struct CheckerInfo {
|
||||
Map<Entity *> uses; // Key: AstNode * | Identifier -> Entity
|
||||
Map<Scope *> scopes; // Key: AstNode * | Node -> Scope
|
||||
Map<ExpressionInfo> untyped; // Key: AstNode * | Expression -> ExpressionInfo
|
||||
Map<DeclarationInfo *> entities; // Key: Entity *
|
||||
Map<DeclInfo *> entities; // Key: Entity *
|
||||
};
|
||||
|
||||
struct Checker {
|
||||
@@ -259,7 +258,7 @@ Entity *scope_insert_entity(Scope *s, Entity *entity) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void add_dependency(DeclarationInfo *d, Entity *e) {
|
||||
void add_dependency(DeclInfo *d, Entity *e) {
|
||||
map_set(&d->deps, hash_pointer(e), cast(b32)true);
|
||||
}
|
||||
|
||||
@@ -391,8 +390,8 @@ TypeAndValue *type_and_value_of_expression(CheckerInfo *i, AstNode *expression)
|
||||
}
|
||||
|
||||
|
||||
Entity *entity_of_identifier(CheckerInfo *i, AstNode *identifier) {
|
||||
GB_ASSERT(identifier->kind == AstNode_Identifier);
|
||||
Entity *entity_of_ident(CheckerInfo *i, AstNode *identifier) {
|
||||
GB_ASSERT(identifier->kind == AstNode_Ident);
|
||||
Entity **found = map_get(&i->definitions, hash_pointer(identifier));
|
||||
if (found)
|
||||
return *found;
|
||||
@@ -403,12 +402,12 @@ Entity *entity_of_identifier(CheckerInfo *i, AstNode *identifier) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Type *type_of_expression(CheckerInfo *i, AstNode *expression) {
|
||||
Type *type_of_expr(CheckerInfo *i, AstNode *expression) {
|
||||
TypeAndValue *found = type_and_value_of_expression(i, expression);
|
||||
if (found)
|
||||
return found->type;
|
||||
if (expression->kind == AstNode_Identifier) {
|
||||
Entity *entity = entity_of_identifier(i, expression);
|
||||
if (expression->kind == AstNode_Ident) {
|
||||
Entity *entity = entity_of_ident(i, expression);
|
||||
if (entity)
|
||||
return entity->type;
|
||||
}
|
||||
@@ -441,7 +440,7 @@ void add_type_and_value(CheckerInfo *i, AstNode *expression, AddressingMode mode
|
||||
|
||||
void add_entity_definition(CheckerInfo *i, AstNode *identifier, Entity *entity) {
|
||||
GB_ASSERT(identifier != NULL);
|
||||
GB_ASSERT(identifier->kind == AstNode_Identifier);
|
||||
GB_ASSERT(identifier->kind == AstNode_Ident);
|
||||
u64 key = hash_pointer(identifier);
|
||||
map_set(&i->definitions, key, entity);
|
||||
}
|
||||
@@ -460,14 +459,14 @@ void add_entity(Checker *c, Scope *scope, AstNode *identifier, Entity *entity) {
|
||||
|
||||
void add_entity_use(CheckerInfo *i, AstNode *identifier, Entity *entity) {
|
||||
GB_ASSERT(identifier != NULL);
|
||||
GB_ASSERT(identifier->kind == AstNode_Identifier);
|
||||
GB_ASSERT(identifier->kind == AstNode_Ident);
|
||||
u64 key = hash_pointer(identifier);
|
||||
map_set(&i->uses, key, entity);
|
||||
}
|
||||
|
||||
|
||||
void add_file_entity(Checker *c, AstNode *identifier, Entity *e, DeclarationInfo *d) {
|
||||
GB_ASSERT(are_strings_equal(identifier->identifier.token.string, e->token.string));
|
||||
void add_file_entity(Checker *c, AstNode *identifier, Entity *e, DeclInfo *d) {
|
||||
GB_ASSERT(are_strings_equal(identifier->ident.token.string, e->token.string));
|
||||
|
||||
add_entity(c, c->global_scope, identifier, e);
|
||||
map_set(&c->info.entities, hash_pointer(e), d);
|
||||
@@ -475,7 +474,7 @@ void add_file_entity(Checker *c, AstNode *identifier, Entity *e, DeclarationInfo
|
||||
}
|
||||
|
||||
|
||||
void check_procedure_later(Checker *c, AstFile *file, Token token, DeclarationInfo *decl, Type *type, AstNode *body) {
|
||||
void check_procedure_later(Checker *c, AstFile *file, Token token, DeclInfo *decl, Type *type, AstNode *body) {
|
||||
ProcedureInfo info = {};
|
||||
info.file = file;
|
||||
info.token = token;
|
||||
@@ -533,27 +532,27 @@ void check_parsed_files(Checker *c) {
|
||||
gb_for_array(i, c->parser->files) {
|
||||
AstFile *f = &c->parser->files[i];
|
||||
add_curr_ast_file(c, f);
|
||||
for (AstNode *decl = f->declarations; decl != NULL; decl = decl->next) {
|
||||
if (!is_ast_node_declaration(decl))
|
||||
for (AstNode *decl = f->decls; decl != NULL; decl = decl->next) {
|
||||
if (!is_ast_node_decl(decl))
|
||||
continue;
|
||||
|
||||
switch (decl->kind) {
|
||||
case AstNode_BadDeclaration:
|
||||
case AstNode_BadDecl:
|
||||
break;
|
||||
|
||||
case AstNode_VariableDeclaration: {
|
||||
auto *vd = &decl->variable_declaration;
|
||||
case AstNode_VarDecl: {
|
||||
auto *vd = &decl->var_decl;
|
||||
|
||||
switch (vd->kind) {
|
||||
case Declaration_Immutable: {
|
||||
for (AstNode *name = vd->name_list, *value = vd->value_list;
|
||||
name != NULL && value != NULL;
|
||||
name = name->next, value = value->next) {
|
||||
GB_ASSERT(name->kind == AstNode_Identifier);
|
||||
GB_ASSERT(name->kind == AstNode_Ident);
|
||||
ExactValue v = {ExactValue_Invalid};
|
||||
Entity *e = make_entity_constant(c->allocator, c->context.scope, name->identifier.token, NULL, v);
|
||||
DeclarationInfo *di = make_declaration_info(c->allocator, c->global_scope);
|
||||
di->type_expr = vd->type_expression;
|
||||
Entity *e = make_entity_constant(c->allocator, c->context.scope, name->ident.token, NULL, v);
|
||||
DeclInfo *di = make_declaration_info(c->allocator, c->global_scope);
|
||||
di->type_expr = vd->type;
|
||||
di->init_expr = value;
|
||||
add_file_entity(c, name, e, di);
|
||||
}
|
||||
@@ -561,7 +560,7 @@ void check_parsed_files(Checker *c) {
|
||||
isize lhs_count = vd->name_count;
|
||||
isize rhs_count = vd->value_count;
|
||||
|
||||
if (rhs_count == 0 && vd->type_expression == NULL) {
|
||||
if (rhs_count == 0 && vd->type == NULL) {
|
||||
error(&c->error_collector, ast_node_token(decl), "Missing type or initial expression");
|
||||
} else if (lhs_count < rhs_count) {
|
||||
error(&c->error_collector, ast_node_token(decl), "Extra initial expression");
|
||||
@@ -572,25 +571,25 @@ void check_parsed_files(Checker *c) {
|
||||
isize entity_count = vd->name_count;
|
||||
isize entity_index = 0;
|
||||
Entity **entities = gb_alloc_array(c->allocator, Entity *, entity_count);
|
||||
DeclarationInfo *di = NULL;
|
||||
DeclInfo *di = NULL;
|
||||
if (vd->value_count == 1) {
|
||||
di = make_declaration_info(gb_heap_allocator(), c->global_scope);
|
||||
di->entities = entities;
|
||||
di->entity_count = entity_count;
|
||||
di->type_expr = vd->type_expression;
|
||||
di->type_expr = vd->type;
|
||||
di->init_expr = vd->value_list;
|
||||
}
|
||||
|
||||
AstNode *value = vd->value_list;
|
||||
for (AstNode *name = vd->name_list; name != NULL; name = name->next) {
|
||||
Entity *e = make_entity_variable(c->allocator, c->global_scope, name->identifier.token, NULL);
|
||||
Entity *e = make_entity_variable(c->allocator, c->global_scope, name->ident.token, NULL);
|
||||
entities[entity_index++] = e;
|
||||
|
||||
DeclarationInfo *d = di;
|
||||
DeclInfo *d = di;
|
||||
if (d == NULL) {
|
||||
AstNode *init_expr = value;
|
||||
d = make_declaration_info(gb_heap_allocator(), c->global_scope);
|
||||
d->type_expr = vd->type_expression;
|
||||
d->type_expr = vd->type;
|
||||
d->init_expr = init_expr;
|
||||
}
|
||||
|
||||
@@ -605,35 +604,35 @@ void check_parsed_files(Checker *c) {
|
||||
|
||||
} break;
|
||||
|
||||
case AstNode_TypeDeclaration: {
|
||||
AstNode *identifier = decl->type_declaration.name;
|
||||
Entity *e = make_entity_type_name(c->allocator, c->global_scope, identifier->identifier.token, NULL);
|
||||
DeclarationInfo *d = make_declaration_info(c->allocator, e->parent);
|
||||
d->type_expr = decl->type_declaration.type_expression;
|
||||
case AstNode_TypeDecl: {
|
||||
AstNode *identifier = decl->type_decl.name;
|
||||
Entity *e = make_entity_type_name(c->allocator, c->global_scope, identifier->ident.token, NULL);
|
||||
DeclInfo *d = make_declaration_info(c->allocator, e->parent);
|
||||
d->type_expr = decl->type_decl.type;
|
||||
add_file_entity(c, identifier, e, d);
|
||||
} break;
|
||||
|
||||
case AstNode_AliasDeclaration: {
|
||||
AstNode *identifier = decl->alias_declaration.name;
|
||||
Entity *e = make_entity_alias_name(c->allocator, c->global_scope, identifier->identifier.token, NULL);
|
||||
DeclarationInfo *d = make_declaration_info(c->allocator, e->parent);
|
||||
d->type_expr = decl->alias_declaration.type_expression;
|
||||
case AstNode_AliasDecl: {
|
||||
AstNode *identifier = decl->alias_decl.name;
|
||||
Entity *e = make_entity_alias_name(c->allocator, c->global_scope, identifier->ident.token, NULL);
|
||||
DeclInfo *d = make_declaration_info(c->allocator, e->parent);
|
||||
d->type_expr = decl->alias_decl.type;
|
||||
add_file_entity(c, identifier, e, d);
|
||||
} break;
|
||||
|
||||
case AstNode_ProcedureDeclaration: {
|
||||
AstNode *identifier = decl->procedure_declaration.name;
|
||||
Token token = identifier->identifier.token;
|
||||
case AstNode_ProcDecl: {
|
||||
AstNode *identifier = decl->proc_decl.name;
|
||||
Token token = identifier->ident.token;
|
||||
Entity *e = make_entity_procedure(c->allocator, c->global_scope, token, NULL);
|
||||
add_entity(c, c->global_scope, identifier, e);
|
||||
DeclarationInfo *d = make_declaration_info(c->allocator, e->parent);
|
||||
DeclInfo *d = make_declaration_info(c->allocator, e->parent);
|
||||
d->proc_decl = decl;
|
||||
map_set(&c->info.entities, hash_pointer(e), d);
|
||||
e->order = gb_array_count(c->info.entities.entries);
|
||||
|
||||
} break;
|
||||
|
||||
case AstNode_ImportDeclaration:
|
||||
case AstNode_ImportDecl:
|
||||
// NOTE(bill): ignore
|
||||
break;
|
||||
|
||||
@@ -648,8 +647,8 @@ void check_parsed_files(Checker *c) {
|
||||
gb_for_array(i, c->info.entities.entries) {
|
||||
auto *entry = &c->info.entities.entries[i];
|
||||
Entity *e = cast(Entity *)cast(uintptr)entry->key;
|
||||
DeclarationInfo *d = entry->value;
|
||||
check_entity_declaration(c, e, d, NULL);
|
||||
DeclInfo *d = entry->value;
|
||||
check_entity_decl(c, e, d, NULL);
|
||||
}
|
||||
|
||||
|
||||
@@ -657,7 +656,7 @@ void check_parsed_files(Checker *c) {
|
||||
gb_for_array(i, c->procedures) {
|
||||
ProcedureInfo *pi = &c->procedures[i];
|
||||
add_curr_ast_file(c, pi->file);
|
||||
check_procedure_body(c, pi->token, pi->decl, pi->type, pi->body);
|
||||
check_proc_body(c, pi->token, pi->decl, pi->type, pi->body);
|
||||
}
|
||||
|
||||
|
||||
@@ -668,7 +667,7 @@ void check_parsed_files(Checker *c) {
|
||||
AstNode *expr = cast(AstNode *)cast(uintptr)key;
|
||||
ExpressionInfo *info = &entry->value;
|
||||
if (is_type_typed(info->type)) {
|
||||
GB_PANIC("%s (type %s) is typed!", expression_to_string(expr), info->type);
|
||||
GB_PANIC("%s (type %s) is typed!", expr_to_string(expr), info->type);
|
||||
}
|
||||
add_type_and_value(&c->info, expr, info->mode, info->type, info->value);
|
||||
}
|
||||
|
||||
+264
-264
File diff suppressed because it is too large
Load Diff
+145
-145
@@ -6,12 +6,12 @@ enum StatementFlag : u32 {
|
||||
// Statement_FallthroughAllowed = GB_BIT(2), // TODO(bill): fallthrough
|
||||
};
|
||||
|
||||
void check_statement(Checker *c, AstNode *node, u32 flags);
|
||||
void check_stmt(Checker *c, AstNode *node, u32 flags);
|
||||
|
||||
void check_statement_list(Checker *c, AstNode *node, u32 flags) {
|
||||
void check_stmt_list(Checker *c, AstNode *node, u32 flags) {
|
||||
for (; node != NULL; node = node->next) {
|
||||
if (node->kind != AstNode_EmptyStatement) {
|
||||
check_statement(c, node, flags);
|
||||
if (node->kind != AstNode_EmptyStmt) {
|
||||
check_stmt(c, node, flags);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -27,7 +27,7 @@ b32 check_is_terminating_list(Checker *c, AstNode *list) {
|
||||
|
||||
// Iterate backwards
|
||||
for (AstNode *n = list; n != NULL; n = n->prev) {
|
||||
if (n->kind != AstNode_EmptyStatement)
|
||||
if (n->kind != AstNode_EmptyStmt)
|
||||
return check_is_terminating(c, n);
|
||||
}
|
||||
|
||||
@@ -39,26 +39,26 @@ b32 check_is_terminating_list(Checker *c, AstNode *list) {
|
||||
// TODO(bill): Warn/err against code after `return` that it won't be executed
|
||||
b32 check_is_terminating(Checker *c, AstNode *node) {
|
||||
switch (node->kind) {
|
||||
case AstNode_ReturnStatement:
|
||||
case AstNode_ReturnStmt:
|
||||
return true;
|
||||
|
||||
case AstNode_BlockStatement:
|
||||
return check_is_terminating_list(c, node->block_statement.list);
|
||||
case AstNode_BlockStmt:
|
||||
return check_is_terminating_list(c, node->block_stmt.list);
|
||||
|
||||
case AstNode_ExpressionStatement:
|
||||
return check_is_terminating(c, node->expression_statement.expression);
|
||||
case AstNode_ExprStmt:
|
||||
return check_is_terminating(c, node->expr_stmt.expr);
|
||||
|
||||
case AstNode_IfStatement:
|
||||
if (node->if_statement.else_statement != NULL) {
|
||||
if (check_is_terminating(c, node->if_statement.body) &&
|
||||
check_is_terminating(c, node->if_statement.else_statement)) {
|
||||
case AstNode_IfStmt:
|
||||
if (node->if_stmt.else_stmt != NULL) {
|
||||
if (check_is_terminating(c, node->if_stmt.body) &&
|
||||
check_is_terminating(c, node->if_stmt.else_stmt)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case AstNode_ForStatement:
|
||||
if (node->for_statement.cond == NULL) {
|
||||
case AstNode_ForStmt:
|
||||
if (node->for_stmt.cond == NULL) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
@@ -141,14 +141,14 @@ void check_assignment(Checker *c, Operand *operand, Type *type, String context_n
|
||||
if (!check_is_assignable_to(c, operand, type)) {
|
||||
gbString type_string = type_to_string(type);
|
||||
gbString op_type_string = type_to_string(operand->type);
|
||||
gbString expr_str = expression_to_string(operand->expression);
|
||||
gbString expr_str = expr_to_string(operand->expr);
|
||||
defer (gb_string_free(type_string));
|
||||
defer (gb_string_free(op_type_string));
|
||||
defer (gb_string_free(expr_str));
|
||||
|
||||
|
||||
// TODO(bill): is this a good enough error message?
|
||||
error(&c->error_collector, ast_node_token(operand->expression),
|
||||
error(&c->error_collector, ast_node_token(operand->expr),
|
||||
"Cannot assign value `%s` of type `%s` to `%s` in %.*s",
|
||||
expr_str,
|
||||
op_type_string,
|
||||
@@ -167,11 +167,11 @@ Type *check_assignment_variable(Checker *c, Operand *op_a, AstNode *lhs) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
AstNode *node = unparen_expression(lhs);
|
||||
AstNode *node = unparen_expr(lhs);
|
||||
|
||||
// NOTE(bill): Ignore assignments to `_`
|
||||
if (node->kind == AstNode_Identifier &&
|
||||
are_strings_equal(node->identifier.token.string, make_string("_"))) {
|
||||
if (node->kind == AstNode_Ident &&
|
||||
are_strings_equal(node->ident.token.string, make_string("_"))) {
|
||||
add_entity_definition(&c->info, node, NULL);
|
||||
check_assignment(c, op_a, NULL, make_string("assignment to `_` identifier"));
|
||||
if (op_a->mode == Addressing_Invalid)
|
||||
@@ -181,8 +181,8 @@ Type *check_assignment_variable(Checker *c, Operand *op_a, AstNode *lhs) {
|
||||
|
||||
Entity *e = NULL;
|
||||
b32 used = false;
|
||||
if (node->kind == AstNode_Identifier) {
|
||||
e = scope_lookup_entity(c->context.scope, node->identifier.token.string);
|
||||
if (node->kind == AstNode_Ident) {
|
||||
e = scope_lookup_entity(c->context.scope, node->ident.token.string);
|
||||
if (e != NULL && e->kind == Entity_Variable) {
|
||||
used = e->variable.used; // TODO(bill): Make backup just in case
|
||||
}
|
||||
@@ -190,7 +190,7 @@ Type *check_assignment_variable(Checker *c, Operand *op_a, AstNode *lhs) {
|
||||
|
||||
|
||||
Operand op_b = {Addressing_Invalid};
|
||||
check_expression(c, &op_b, lhs);
|
||||
check_expr(c, &op_b, lhs);
|
||||
if (e) e->variable.used = used;
|
||||
|
||||
if (op_b.mode == Addressing_Invalid ||
|
||||
@@ -204,15 +204,15 @@ Type *check_assignment_variable(Checker *c, Operand *op_a, AstNode *lhs) {
|
||||
case Addressing_Invalid:
|
||||
return NULL;
|
||||
default: {
|
||||
if (op_b.expression->kind == AstNode_SelectorExpression) {
|
||||
if (op_b.expr->kind == AstNode_SelectorExpr) {
|
||||
// NOTE(bill): Extra error checks
|
||||
Operand op_c = {Addressing_Invalid};
|
||||
check_expression(c, &op_c, op_b.expression->selector_expression.operand);
|
||||
check_expr(c, &op_c, op_b.expr->selector_expr.expr);
|
||||
}
|
||||
|
||||
gbString str = expression_to_string(op_b.expression);
|
||||
gbString str = expr_to_string(op_b.expr);
|
||||
defer (gb_string_free(str));
|
||||
error(&c->error_collector, ast_node_token(op_b.expression), "Cannot assign to `%s`", str);
|
||||
error(&c->error_collector, ast_node_token(op_b.expr), "Cannot assign to `%s`", str);
|
||||
} break;
|
||||
}
|
||||
|
||||
@@ -264,7 +264,7 @@ void check_init_variables(Checker *c, Entity **lhs, isize lhs_count, AstNode *in
|
||||
i < lhs_count && i < init_count && rhs != NULL;
|
||||
i++, rhs = rhs->next) {
|
||||
Operand operand = {};
|
||||
check_multi_expression(c, &operand, rhs);
|
||||
check_multi_expr(c, &operand, rhs);
|
||||
if (operand.type->kind != Type_Tuple) {
|
||||
check_init_variable(c, lhs[i], &operand, context_name);
|
||||
} else {
|
||||
@@ -297,8 +297,8 @@ void check_init_constant(Checker *c, Entity *e, Operand *operand) {
|
||||
|
||||
if (operand->mode != Addressing_Constant) {
|
||||
// TODO(bill): better error
|
||||
error(&c->error_collector, ast_node_token(operand->expression),
|
||||
"`%.*s` is not a constant", LIT(ast_node_token(operand->expression).string));
|
||||
error(&c->error_collector, ast_node_token(operand->expr),
|
||||
"`%.*s` is not a constant", LIT(ast_node_token(operand->expr).string));
|
||||
if (e->type == NULL)
|
||||
e->type = &basic_types[Basic_Invalid];
|
||||
return;
|
||||
@@ -319,7 +319,7 @@ void check_init_constant(Checker *c, Entity *e, Operand *operand) {
|
||||
}
|
||||
|
||||
|
||||
void check_constant_declaration(Checker *c, Entity *e, AstNode *type_expr, AstNode *init_expr) {
|
||||
void check_const_decl(Checker *c, Entity *e, AstNode *type_expr, AstNode *init_expr) {
|
||||
GB_ASSERT(e->type == NULL);
|
||||
|
||||
if (e->variable.visited) {
|
||||
@@ -343,11 +343,11 @@ void check_constant_declaration(Checker *c, Entity *e, AstNode *type_expr, AstNo
|
||||
|
||||
Operand operand = {Addressing_Invalid};
|
||||
if (init_expr)
|
||||
check_expression(c, &operand, init_expr);
|
||||
check_expr(c, &operand, init_expr);
|
||||
check_init_constant(c, e, &operand);
|
||||
}
|
||||
|
||||
void check_type_declaration(Checker *c, Entity *e, AstNode *type_expr, Type *named_type) {
|
||||
void check_type_decl(Checker *c, Entity *e, AstNode *type_expr, Type *named_type) {
|
||||
GB_ASSERT(e->type == NULL);
|
||||
Type *named = make_type_named(c->allocator, e->token.string, NULL, e);
|
||||
named->named.type_name = e;
|
||||
@@ -359,7 +359,7 @@ void check_type_declaration(Checker *c, Entity *e, AstNode *type_expr, Type *nam
|
||||
set_base_type(named, get_base_type(get_base_type(named)));
|
||||
}
|
||||
|
||||
void check_alias_declaration(Checker *c, Entity *e, AstNode *type_expr, Type *alias_type) {
|
||||
void check_alias_decl(Checker *c, Entity *e, AstNode *type_expr, Type *alias_type) {
|
||||
GB_ASSERT(e->type == NULL);
|
||||
Type *named = make_type_alias(c->allocator, e->token.string, NULL, e);
|
||||
named->alias.alias_name = e;
|
||||
@@ -371,18 +371,18 @@ void check_alias_declaration(Checker *c, Entity *e, AstNode *type_expr, Type *al
|
||||
set_base_type(named, get_base_type(get_base_type(named)));
|
||||
}
|
||||
|
||||
void check_procedure_body(Checker *c, Token token, DeclarationInfo *decl, Type *type, AstNode *body) {
|
||||
GB_ASSERT(body->kind == AstNode_BlockStatement);
|
||||
void check_proc_body(Checker *c, Token token, DeclInfo *decl, Type *type, AstNode *body) {
|
||||
GB_ASSERT(body->kind == AstNode_BlockStmt);
|
||||
|
||||
CheckerContext old_context = c->context;
|
||||
c->context.scope = decl->scope;
|
||||
c->context.decl = decl;
|
||||
|
||||
push_procedure(c, type);
|
||||
check_statement_list(c, body->block_statement.list, 0);
|
||||
check_stmt_list(c, body->block_stmt.list, 0);
|
||||
if (type->procedure.result_count > 0) {
|
||||
if (!check_is_terminating(c, body)) {
|
||||
error(&c->error_collector, body->block_statement.close, "Missing return statement at the end of the procedure");
|
||||
error(&c->error_collector, body->block_stmt.close, "Missing return statement at the end of the procedure");
|
||||
}
|
||||
}
|
||||
pop_procedure(c);
|
||||
@@ -390,12 +390,12 @@ void check_procedure_body(Checker *c, Token token, DeclarationInfo *decl, Type *
|
||||
c->context = old_context;
|
||||
}
|
||||
|
||||
void check_procedure_declaration(Checker *c, Entity *e, DeclarationInfo *d, b32 check_body_later) {
|
||||
void check_proc_decl(Checker *c, Entity *e, DeclInfo *d, b32 check_body_later) {
|
||||
GB_ASSERT(e->type == NULL);
|
||||
|
||||
Type *proc_type = make_type_procedure(c->allocator, e->parent, NULL, 0, NULL, 0);
|
||||
e->type = proc_type;
|
||||
auto *pd = &d->proc_decl->procedure_declaration;
|
||||
auto *pd = &d->proc_decl->proc_decl;
|
||||
|
||||
#if 1
|
||||
Scope *original_curr_scope = c->context.scope;
|
||||
@@ -407,9 +407,9 @@ void check_procedure_declaration(Checker *c, Entity *e, DeclarationInfo *d, b32
|
||||
b32 is_inline = false;
|
||||
b32 is_no_inline = false;
|
||||
for (AstNode *tag = pd->tag_list; tag != NULL; tag = tag->next) {
|
||||
GB_ASSERT(tag->kind == AstNode_TagExpression);
|
||||
GB_ASSERT(tag->kind == AstNode_TagExpr);
|
||||
|
||||
String tag_name = tag->tag_expression.name.string;
|
||||
String tag_name = tag->tag_expr.name.string;
|
||||
if (are_strings_equal(tag_name, make_string("foreign"))) {
|
||||
is_foreign = true;
|
||||
} else if (are_strings_equal(tag_name, make_string("inline"))) {
|
||||
@@ -435,11 +435,11 @@ void check_procedure_declaration(Checker *c, Entity *e, DeclarationInfo *d, b32
|
||||
|
||||
d->scope = c->context.scope;
|
||||
|
||||
GB_ASSERT(pd->body->kind == AstNode_BlockStatement);
|
||||
GB_ASSERT(pd->body->kind == AstNode_BlockStmt);
|
||||
if (check_body_later) {
|
||||
check_procedure_later(c, c->curr_ast_file, e->token, d, proc_type, pd->body);
|
||||
} else {
|
||||
check_procedure_body(c, e->token, d, proc_type, pd->body);
|
||||
check_proc_body(c, e->token, d, proc_type, pd->body);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -450,7 +450,7 @@ void check_procedure_declaration(Checker *c, Entity *e, DeclarationInfo *d, b32
|
||||
|
||||
}
|
||||
|
||||
void check_variable_declaration(Checker *c, Entity *e, Entity **entities, isize entity_count, AstNode *type_expr, AstNode *init_expr) {
|
||||
void check_var_decl(Checker *c, Entity *e, Entity **entities, isize entity_count, AstNode *type_expr, AstNode *init_expr) {
|
||||
GB_ASSERT(e->type == NULL);
|
||||
GB_ASSERT(e->kind == Entity_Variable);
|
||||
|
||||
@@ -472,7 +472,7 @@ void check_variable_declaration(Checker *c, Entity *e, Entity **entities, isize
|
||||
if (entities == NULL || entity_count == 1) {
|
||||
GB_ASSERT(entities == NULL || entities[0] == e);
|
||||
Operand operand = {};
|
||||
check_expression(c, &operand, init_expr);
|
||||
check_expr(c, &operand, init_expr);
|
||||
check_init_variable(c, e, &operand, make_string("variable declaration"));
|
||||
}
|
||||
|
||||
@@ -486,26 +486,26 @@ void check_variable_declaration(Checker *c, Entity *e, Entity **entities, isize
|
||||
|
||||
|
||||
|
||||
void check_entity_declaration(Checker *c, Entity *e, DeclarationInfo *d, Type *named_type) {
|
||||
void check_entity_decl(Checker *c, Entity *e, DeclInfo *d, Type *named_type) {
|
||||
if (e->type != NULL)
|
||||
return;
|
||||
switch (e->kind) {
|
||||
case Entity_Constant:
|
||||
c->context.decl = d;
|
||||
check_constant_declaration(c, e, d->type_expr, d->init_expr);
|
||||
check_const_decl(c, e, d->type_expr, d->init_expr);
|
||||
break;
|
||||
case Entity_Variable:
|
||||
c->context.decl = d;
|
||||
check_variable_declaration(c, e, d->entities, d->entity_count, d->type_expr, d->init_expr);
|
||||
check_var_decl(c, e, d->entities, d->entity_count, d->type_expr, d->init_expr);
|
||||
break;
|
||||
case Entity_TypeName:
|
||||
check_type_declaration(c, e, d->type_expr, named_type);
|
||||
check_type_decl(c, e, d->type_expr, named_type);
|
||||
break;
|
||||
case Entity_AliasName:
|
||||
check_alias_declaration(c, e, d->type_expr, named_type);
|
||||
check_alias_decl(c, e, d->type_expr, named_type);
|
||||
break;
|
||||
case Entity_Procedure:
|
||||
check_procedure_declaration(c, e, d, true);
|
||||
check_proc_decl(c, e, d, true);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -514,15 +514,15 @@ void check_entity_declaration(Checker *c, Entity *e, DeclarationInfo *d, Type *n
|
||||
|
||||
|
||||
|
||||
void check_statement(Checker *c, AstNode *node, u32 flags) {
|
||||
void check_stmt(Checker *c, AstNode *node, u32 flags) {
|
||||
switch (node->kind) {
|
||||
case AstNode_EmptyStatement: break;
|
||||
case AstNode_BadStatement: break;
|
||||
case AstNode_BadDeclaration: break;
|
||||
case AstNode_EmptyStmt: break;
|
||||
case AstNode_BadStmt: break;
|
||||
case AstNode_BadDecl: break;
|
||||
|
||||
case AstNode_ExpressionStatement: {
|
||||
case AstNode_ExprStmt: {
|
||||
Operand operand = {Addressing_Invalid};
|
||||
ExpressionKind kind = check_expression_base(c, &operand, node->expression_statement.expression);
|
||||
ExpressionKind kind = check_expr_base(c, &operand, node->expr_stmt.expr);
|
||||
switch (operand.mode) {
|
||||
case Addressing_Type:
|
||||
error(&c->error_collector, ast_node_token(node), "Is not an expression");
|
||||
@@ -535,15 +535,15 @@ void check_statement(Checker *c, AstNode *node, u32 flags) {
|
||||
}
|
||||
} break;
|
||||
|
||||
case AstNode_TagStatement:
|
||||
case AstNode_TagStmt:
|
||||
// TODO(bill): Tag Statements
|
||||
error(&c->error_collector, ast_node_token(node), "Tag statements are not supported yet");
|
||||
check_statement(c, node->tag_statement.statement, flags);
|
||||
check_stmt(c, node->tag_stmt.stmt, flags);
|
||||
break;
|
||||
|
||||
case AstNode_IncDecStatement: {
|
||||
case AstNode_IncDecStmt: {
|
||||
Token op = {};
|
||||
auto *s = &node->inc_dec_statement;
|
||||
auto *s = &node->inc_dec_stmt;
|
||||
op = s->op;
|
||||
switch (s->op.kind) {
|
||||
case Token_Increment:
|
||||
@@ -560,7 +560,7 @@ void check_statement(Checker *c, AstNode *node, u32 flags) {
|
||||
}
|
||||
|
||||
Operand operand = {Addressing_Invalid};
|
||||
check_expression(c, &operand, s->expression);
|
||||
check_expr(c, &operand, s->expr);
|
||||
if (operand.mode == Addressing_Invalid)
|
||||
return;
|
||||
if (!is_type_numeric(operand.type)) {
|
||||
@@ -568,36 +568,36 @@ void check_statement(Checker *c, AstNode *node, u32 flags) {
|
||||
return;
|
||||
}
|
||||
|
||||
AstNode basic_lit = {AstNode_BasicLiteral};
|
||||
basic_lit.basic_literal = s->op;
|
||||
basic_lit.basic_literal.kind = Token_Integer;
|
||||
basic_lit.basic_literal.string = make_string("1");
|
||||
AstNode basic_lit = {AstNode_BasicLit};
|
||||
basic_lit.basic_lit = s->op;
|
||||
basic_lit.basic_lit.kind = Token_Integer;
|
||||
basic_lit.basic_lit.string = make_string("1");
|
||||
|
||||
AstNode be = {AstNode_BinaryExpression};
|
||||
be.binary_expression.op = op;
|
||||
be.binary_expression.left = s->expression;;
|
||||
be.binary_expression.right = &basic_lit;
|
||||
check_binary_expression(c, &operand, &be);
|
||||
AstNode be = {AstNode_BinaryExpr};
|
||||
be.binary_expr.op = op;
|
||||
be.binary_expr.left = s->expr;;
|
||||
be.binary_expr.right = &basic_lit;
|
||||
check_binary_expr(c, &operand, &be);
|
||||
|
||||
} break;
|
||||
|
||||
case AstNode_AssignStatement:
|
||||
switch (node->assign_statement.op.kind) {
|
||||
case AstNode_AssignStmt:
|
||||
switch (node->assign_stmt.op.kind) {
|
||||
case Token_Eq: {
|
||||
// a, b, c = 1, 2, 3; // Multisided
|
||||
if (node->assign_statement.lhs_count == 0) {
|
||||
error(&c->error_collector, node->assign_statement.op, "Missing lhs in assignment statement");
|
||||
if (node->assign_stmt.lhs_count == 0) {
|
||||
error(&c->error_collector, node->assign_stmt.op, "Missing lhs in assignment statement");
|
||||
return;
|
||||
}
|
||||
|
||||
Operand operand = {};
|
||||
AstNode *lhs = node->assign_statement.lhs_list;
|
||||
AstNode *rhs = node->assign_statement.rhs_list;
|
||||
AstNode *lhs = node->assign_stmt.lhs_list;
|
||||
AstNode *rhs = node->assign_stmt.rhs_list;
|
||||
isize i = 0;
|
||||
for (;
|
||||
lhs != NULL && rhs != NULL;
|
||||
lhs = lhs->next, rhs = rhs->next) {
|
||||
check_multi_expression(c, &operand, rhs);
|
||||
check_multi_expr(c, &operand, rhs);
|
||||
if (operand.type->kind != Type_Tuple) {
|
||||
check_assignment_variable(c, &operand, lhs);
|
||||
i++;
|
||||
@@ -615,7 +615,7 @@ void check_statement(Checker *c, AstNode *node, u32 flags) {
|
||||
}
|
||||
}
|
||||
|
||||
if (i < node->assign_statement.lhs_count && i < node->assign_statement.rhs_count) {
|
||||
if (i < node->assign_stmt.lhs_count && i < node->assign_stmt.rhs_count) {
|
||||
if (lhs == NULL)
|
||||
error(&c->error_collector, ast_node_token(lhs), "Too few values on the right hand side of the declaration");
|
||||
} else if (rhs != NULL) {
|
||||
@@ -625,9 +625,9 @@ void check_statement(Checker *c, AstNode *node, u32 flags) {
|
||||
|
||||
default: {
|
||||
// a += 1; // Single-sided
|
||||
Token op = node->assign_statement.op;
|
||||
if (node->assign_statement.lhs_count != 1 ||
|
||||
node->assign_statement.rhs_count != 1) {
|
||||
Token op = node->assign_stmt.op;
|
||||
if (node->assign_stmt.lhs_count != 1 ||
|
||||
node->assign_stmt.rhs_count != 1) {
|
||||
error(&c->error_collector, op, "Assignment operation `%.*s` requires single-valued expressions", LIT(op.string));
|
||||
return;
|
||||
}
|
||||
@@ -637,61 +637,61 @@ void check_statement(Checker *c, AstNode *node, u32 flags) {
|
||||
}
|
||||
// TODO(bill): Check if valid assignment operator
|
||||
Operand operand = {Addressing_Invalid};
|
||||
AstNode be = {AstNode_BinaryExpression};
|
||||
be.binary_expression.op = op;
|
||||
AstNode be = {AstNode_BinaryExpr};
|
||||
be.binary_expr.op = op;
|
||||
// NOTE(bill): Only use the first one will be used
|
||||
be.binary_expression.left = node->assign_statement.lhs_list;
|
||||
be.binary_expression.right = node->assign_statement.rhs_list;
|
||||
be.binary_expr.left = node->assign_stmt.lhs_list;
|
||||
be.binary_expr.right = node->assign_stmt.rhs_list;
|
||||
|
||||
check_binary_expression(c, &operand, &be);
|
||||
check_binary_expr(c, &operand, &be);
|
||||
if (operand.mode == Addressing_Invalid)
|
||||
return;
|
||||
// NOTE(bill): Only use the first one will be used
|
||||
check_assignment_variable(c, &operand, node->assign_statement.lhs_list);
|
||||
check_assignment_variable(c, &operand, node->assign_stmt.lhs_list);
|
||||
} break;
|
||||
}
|
||||
break;
|
||||
|
||||
case AstNode_BlockStatement:
|
||||
case AstNode_BlockStmt:
|
||||
check_open_scope(c, node);
|
||||
check_statement_list(c, node->block_statement.list, flags);
|
||||
check_stmt_list(c, node->block_stmt.list, flags);
|
||||
check_close_scope(c);
|
||||
break;
|
||||
|
||||
case AstNode_IfStatement: {
|
||||
case AstNode_IfStmt: {
|
||||
check_open_scope(c, node);
|
||||
defer (check_close_scope(c));
|
||||
auto *is = &node->if_statement;
|
||||
auto *is = &node->if_stmt;
|
||||
|
||||
if (is->init != NULL)
|
||||
check_statement(c, is->init, 0);
|
||||
check_stmt(c, is->init, 0);
|
||||
|
||||
Operand operand = {Addressing_Invalid};
|
||||
check_expression(c, &operand, node->if_statement.cond);
|
||||
check_expr(c, &operand, node->if_stmt.cond);
|
||||
if (operand.mode != Addressing_Invalid &&
|
||||
!is_type_boolean(operand.type)) {
|
||||
error(&c->error_collector, ast_node_token(node->if_statement.cond),
|
||||
error(&c->error_collector, ast_node_token(node->if_stmt.cond),
|
||||
"Non-boolean condition in `if` statement");
|
||||
}
|
||||
|
||||
check_statement(c, node->if_statement.body, flags);
|
||||
check_stmt(c, node->if_stmt.body, flags);
|
||||
|
||||
if (node->if_statement.else_statement) {
|
||||
switch (node->if_statement.else_statement->kind) {
|
||||
case AstNode_IfStatement:
|
||||
case AstNode_BlockStatement:
|
||||
check_statement(c, node->if_statement.else_statement, flags);
|
||||
if (node->if_stmt.else_stmt) {
|
||||
switch (node->if_stmt.else_stmt->kind) {
|
||||
case AstNode_IfStmt:
|
||||
case AstNode_BlockStmt:
|
||||
check_stmt(c, node->if_stmt.else_stmt, flags);
|
||||
break;
|
||||
default:
|
||||
error(&c->error_collector, ast_node_token(node->if_statement.else_statement),
|
||||
error(&c->error_collector, ast_node_token(node->if_stmt.else_stmt),
|
||||
"Invalid `else` statement in `if` statement");
|
||||
break;
|
||||
}
|
||||
}
|
||||
} break;
|
||||
|
||||
case AstNode_ReturnStatement: {
|
||||
auto *rs = &node->return_statement;
|
||||
case AstNode_ReturnStmt: {
|
||||
auto *rs = &node->return_stmt;
|
||||
GB_ASSERT(gb_array_count(c->procedure_stack) > 0);
|
||||
|
||||
if (c->in_defer) {
|
||||
@@ -712,45 +712,45 @@ void check_statement(Checker *c, AstNode *node, u32 flags) {
|
||||
} else if (result_count > 0) {
|
||||
auto *tuple = &proc_type->procedure.results->tuple;
|
||||
check_init_variables(c, tuple->variables, tuple->variable_count,
|
||||
rs->results, rs->result_count, make_string("return statement"));
|
||||
rs->result_list, rs->result_count, make_string("return statement"));
|
||||
}
|
||||
} break;
|
||||
|
||||
case AstNode_ForStatement: {
|
||||
case AstNode_ForStmt: {
|
||||
flags |= Statement_BreakAllowed | Statement_ContinueAllowed;
|
||||
check_open_scope(c, node);
|
||||
defer (check_close_scope(c));
|
||||
|
||||
if (node->for_statement.init != NULL)
|
||||
check_statement(c, node->for_statement.init, 0);
|
||||
if (node->for_statement.cond) {
|
||||
if (node->for_stmt.init != NULL)
|
||||
check_stmt(c, node->for_stmt.init, 0);
|
||||
if (node->for_stmt.cond) {
|
||||
Operand operand = {Addressing_Invalid};
|
||||
check_expression(c, &operand, node->for_statement.cond);
|
||||
check_expr(c, &operand, node->for_stmt.cond);
|
||||
if (operand.mode != Addressing_Invalid &&
|
||||
!is_type_boolean(operand.type)) {
|
||||
error(&c->error_collector, ast_node_token(node->for_statement.cond),
|
||||
error(&c->error_collector, ast_node_token(node->for_stmt.cond),
|
||||
"Non-boolean condition in `for` statement");
|
||||
}
|
||||
}
|
||||
if (node->for_statement.end != NULL)
|
||||
check_statement(c, node->for_statement.end, 0);
|
||||
check_statement(c, node->for_statement.body, flags);
|
||||
if (node->for_stmt.end != NULL)
|
||||
check_stmt(c, node->for_stmt.end, 0);
|
||||
check_stmt(c, node->for_stmt.body, flags);
|
||||
} break;
|
||||
|
||||
case AstNode_DeferStatement: {
|
||||
auto *ds = &node->defer_statement;
|
||||
if (is_ast_node_declaration(ds->statement)) {
|
||||
case AstNode_DeferStmt: {
|
||||
auto *ds = &node->defer_stmt;
|
||||
if (is_ast_node_decl(ds->stmt)) {
|
||||
error(&c->error_collector, ds->token, "You cannot defer a declaration");
|
||||
} else {
|
||||
b32 out_in_defer = c->in_defer;
|
||||
c->in_defer = true;
|
||||
check_statement(c, ds->statement, 0);
|
||||
check_stmt(c, ds->stmt, 0);
|
||||
c->in_defer = out_in_defer;
|
||||
}
|
||||
} break;
|
||||
|
||||
case AstNode_BranchStatement: {
|
||||
Token token = node->branch_statement.token;
|
||||
case AstNode_BranchStmt: {
|
||||
Token token = node->branch_stmt.token;
|
||||
switch (token.kind) {
|
||||
case Token_break:
|
||||
if ((flags & Statement_BreakAllowed) == 0)
|
||||
@@ -768,8 +768,8 @@ void check_statement(Checker *c, AstNode *node, u32 flags) {
|
||||
|
||||
|
||||
// Declarations
|
||||
case AstNode_VariableDeclaration: {
|
||||
auto *vd = &node->variable_declaration;
|
||||
case AstNode_VarDecl: {
|
||||
auto *vd = &node->var_decl;
|
||||
isize entity_count = vd->name_count;
|
||||
isize entity_index = 0;
|
||||
Entity **entities = gb_alloc_array(c->allocator, Entity *, entity_count);
|
||||
@@ -780,8 +780,8 @@ void check_statement(Checker *c, AstNode *node, u32 flags) {
|
||||
|
||||
for (AstNode *name = vd->name_list; name != NULL; name = name->next) {
|
||||
Entity *entity = NULL;
|
||||
Token token = name->identifier.token;
|
||||
if (name->kind == AstNode_Identifier) {
|
||||
Token token = name->ident.token;
|
||||
if (name->kind == AstNode_Ident) {
|
||||
String str = token.string;
|
||||
Entity *found = NULL;
|
||||
// NOTE(bill): Ignore assignments to `_`
|
||||
@@ -807,8 +807,8 @@ void check_statement(Checker *c, AstNode *node, u32 flags) {
|
||||
}
|
||||
|
||||
Type *init_type = NULL;
|
||||
if (vd->type_expression) {
|
||||
init_type = check_type(c, vd->type_expression, NULL);
|
||||
if (vd->type) {
|
||||
init_type = check_type(c, vd->type, NULL);
|
||||
if (init_type == NULL)
|
||||
init_type = &basic_types[Basic_Invalid];
|
||||
}
|
||||
@@ -839,18 +839,18 @@ void check_statement(Checker *c, AstNode *node, u32 flags) {
|
||||
for (AstNode *name = vd->name_list, *value = vd->value_list;
|
||||
name != NULL && value != NULL;
|
||||
name = name->next, value = value->next) {
|
||||
GB_ASSERT(name->kind == AstNode_Identifier);
|
||||
GB_ASSERT(name->kind == AstNode_Ident);
|
||||
ExactValue v = {ExactValue_Invalid};
|
||||
Entity *e = make_entity_constant(c->allocator, c->context.scope, name->identifier.token, NULL, v);
|
||||
Entity *e = make_entity_constant(c->allocator, c->context.scope, name->ident.token, NULL, v);
|
||||
entities[entity_index++] = e;
|
||||
check_constant_declaration(c, e, vd->type_expression, value);
|
||||
check_const_decl(c, e, vd->type, value);
|
||||
}
|
||||
|
||||
isize lhs_count = vd->name_count;
|
||||
isize rhs_count = vd->value_count;
|
||||
|
||||
// TODO(bill): Better error messages or is this good enough?
|
||||
if (rhs_count == 0 && vd->type_expression == NULL) {
|
||||
if (rhs_count == 0 && vd->type == NULL) {
|
||||
error(&c->error_collector, ast_node_token(node), "Missing type or initial expression");
|
||||
} else if (lhs_count < rhs_count) {
|
||||
error(&c->error_collector, ast_node_token(node), "Extra initial expression");
|
||||
@@ -868,32 +868,32 @@ void check_statement(Checker *c, AstNode *node, u32 flags) {
|
||||
}
|
||||
} break;
|
||||
|
||||
case AstNode_ProcedureDeclaration: {
|
||||
auto *pd = &node->procedure_declaration;
|
||||
Entity *e = make_entity_procedure(c->allocator, c->context.scope, pd->name->identifier.token, NULL);
|
||||
case AstNode_ProcDecl: {
|
||||
auto *pd = &node->proc_decl;
|
||||
Entity *e = make_entity_procedure(c->allocator, c->context.scope, pd->name->ident.token, NULL);
|
||||
add_entity(c, c->context.scope, pd->name, e);
|
||||
|
||||
DeclarationInfo decl = {};
|
||||
DeclInfo decl = {};
|
||||
init_declaration_info(&decl, e->parent);
|
||||
decl.proc_decl = node;
|
||||
check_procedure_declaration(c, e, &decl, false);
|
||||
check_proc_decl(c, e, &decl, false);
|
||||
destroy_declaration_info(&decl);
|
||||
} break;
|
||||
|
||||
case AstNode_TypeDeclaration: {
|
||||
auto *td = &node->type_declaration;
|
||||
case AstNode_TypeDecl: {
|
||||
auto *td = &node->type_decl;
|
||||
AstNode *name = td->name;
|
||||
Entity *e = make_entity_type_name(c->allocator, c->context.scope, name->identifier.token, NULL);
|
||||
Entity *e = make_entity_type_name(c->allocator, c->context.scope, name->ident.token, NULL);
|
||||
add_entity(c, c->context.scope, name, e);
|
||||
check_type_declaration(c, e, td->type_expression, NULL);
|
||||
check_type_decl(c, e, td->type, NULL);
|
||||
} break;
|
||||
|
||||
case AstNode_AliasDeclaration: {
|
||||
auto *ad = &node->alias_declaration;
|
||||
case AstNode_AliasDecl: {
|
||||
auto *ad = &node->alias_decl;
|
||||
AstNode *name = ad->name;
|
||||
Entity *e = make_entity_alias_name(c->allocator, c->context.scope, name->identifier.token, NULL);
|
||||
Entity *e = make_entity_alias_name(c->allocator, c->context.scope, name->ident.token, NULL);
|
||||
add_entity(c, c->context.scope, name, e);
|
||||
check_alias_declaration(c, e, ad->type_expression, NULL);
|
||||
check_alias_decl(c, e, ad->type, NULL);
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user