aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorgingerBill <ginger.bill.22@gmail.com>2016-08-01 13:11:50 +0100
committergingerBill <ginger.bill.22@gmail.com>2016-08-01 13:11:50 +0100
commite5665a190d196dc6f2a9bb45be737325eaf12cf5 (patch)
treecd74d861a7cd9e065a41c55df2f1130671b20398 /src
parent88e05ad2b25b51ad3f5dd92554ffbfa3eeaa57b9 (diff)
Big Refactor to type less :P
Diffstat (limited to 'src')
-rw-r--r--src/checker/checker.cpp113
-rw-r--r--src/checker/expression.cpp528
-rw-r--r--src/checker/statements.cpp290
-rw-r--r--src/codegen/codegen.cpp2
-rw-r--r--src/codegen/print.cpp33
-rw-r--r--src/codegen/ssa.cpp328
-rw-r--r--src/parser.cpp1216
-rw-r--r--src/printer.cpp172
8 files changed, 1399 insertions, 1283 deletions
diff --git a/src/checker/checker.cpp b/src/checker/checker.cpp
index b91f9c424..62e3b9019 100644
--- a/src/checker/checker.cpp
+++ b/src/checker/checker.cpp
@@ -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);
}
diff --git a/src/checker/expression.cpp b/src/checker/expression.cpp
index 1d4cf02a8..9a9ad4c7f 100644
--- a/src/checker/expression.cpp
+++ b/src/checker/expression.cpp
@@ -1,16 +1,16 @@
void check_assignment (Checker *c, Operand *operand, Type *type, String context_name);
b32 check_is_assignable_to (Checker *c, Operand *operand, Type *type);
-void check_expression (Checker *c, Operand *operand, AstNode *expression);
-void check_multi_expression (Checker *c, Operand *operand, AstNode *expression);
-void check_expression_or_type(Checker *c, Operand *operand, AstNode *expression);
-ExpressionKind check_expression_base (Checker *c, Operand *operand, AstNode *expression, Type *type_hint = NULL);
+void check_expr (Checker *c, Operand *operand, AstNode *expression);
+void check_multi_expr (Checker *c, Operand *operand, AstNode *expression);
+void check_expr_or_type (Checker *c, Operand *operand, AstNode *expression);
+ExpressionKind check_expr_base (Checker *c, Operand *operand, AstNode *expression, Type *type_hint = NULL);
Type * check_type (Checker *c, AstNode *expression, Type *named_type = NULL);
void check_selector (Checker *c, Operand *operand, AstNode *node);
void check_not_tuple (Checker *c, Operand *operand);
void convert_to_typed (Checker *c, Operand *operand, Type *target_type);
-gbString expression_to_string (AstNode *expression);
-void check_entity_declaration(Checker *c, Entity *e, DeclarationInfo *decl, Type *named_type);
-void check_procedure_body (Checker *c, Token token, DeclarationInfo *decl, Type *type, AstNode *body);
+gbString expr_to_string (AstNode *expression);
+void check_entity_decl (Checker *c, Entity *e, DeclInfo *decl, Type *named_type);
+void check_proc_body (Checker *c, Token token, DeclInfo *decl, Type *type, AstNode *body);
void check_struct_type(Checker *c, Type *struct_type, AstNode *node) {
@@ -29,7 +29,7 @@ void check_struct_type(Checker *c, Type *struct_type, AstNode *node) {
isize field_count = 0;
for (AstNode *field = st->field_list; field != NULL; field = field->next) {
for (AstNode *name = field->field.name_list; name != NULL; name = name->next) {
- GB_ASSERT(name->kind == AstNode_Identifier);
+ GB_ASSERT(name->kind == AstNode_Ident);
field_count++;
}
}
@@ -37,10 +37,10 @@ void check_struct_type(Checker *c, Type *struct_type, AstNode *node) {
Entity **fields = gb_alloc_array(c->allocator, Entity *, st->field_count);
isize field_index = 0;
for (AstNode *field = st->field_list; field != NULL; field = field->next) {
- Type *type = check_type(c, field->field.type_expression);
+ Type *type = check_type(c, field->field.type);
for (AstNode *name = field->field.name_list; name != NULL; name = name->next) {
- GB_ASSERT(name->kind == AstNode_Identifier);
- Token name_token = name->identifier.token;
+ GB_ASSERT(name->kind == AstNode_Ident);
+ Token name_token = name->ident.token;
// TODO(bill): is the curr_scope correct?
Entity *e = make_entity_field(c->allocator, c->context.scope, name_token, type);
u64 key = hash_string(name_token.string);
@@ -68,12 +68,12 @@ Type *check_get_params(Checker *c, Scope *scope, AstNode *field_list, isize fiel
isize variable_index = 0;
for (AstNode *field = field_list; field != NULL; field = field->next) {
GB_ASSERT(field->kind == AstNode_Field);
- AstNode *type_expression = field->field.type_expression;
- if (type_expression) {
- Type *type = check_type(c, type_expression);
+ AstNode *type_expr = field->field.type;
+ if (type_expr) {
+ Type *type = check_type(c, type_expr);
for (AstNode *name = field->field.name_list; name != NULL; name = name->next) {
- if (name->kind == AstNode_Identifier) {
- Entity *param = make_entity_param(c->allocator, scope, name->identifier.token, type);
+ if (name->kind == AstNode_Ident) {
+ Entity *param = make_entity_param(c->allocator, scope, name->ident.token, type);
add_entity(c, scope, name, param);
variables[variable_index++] = param;
} else {
@@ -117,30 +117,30 @@ Type *check_get_results(Checker *c, Scope *scope, AstNode *list, isize list_coun
void check_procedure_type(Checker *c, Type *type, AstNode *proc_type_node) {
- isize param_count = proc_type_node->procedure_type.param_count;
- isize result_count = proc_type_node->procedure_type.result_count;
+ isize param_count = proc_type_node->proc_type.param_count;
+ isize result_count = proc_type_node->proc_type.result_count;
// gb_printf("%td -> %td\n", param_count, result_count);
- Type *params = check_get_params(c, c->context.scope, proc_type_node->procedure_type.param_list, param_count);
- Type *results = check_get_results(c, c->context.scope, proc_type_node->procedure_type.result_list, result_count);
+ Type *params = check_get_params(c, c->context.scope, proc_type_node->proc_type.param_list, param_count);
+ Type *results = check_get_results(c, c->context.scope, proc_type_node->proc_type.result_list, result_count);
type->procedure.scope = c->context.scope;
type->procedure.params = params;
- type->procedure.param_count = proc_type_node->procedure_type.param_count;
+ type->procedure.param_count = proc_type_node->proc_type.param_count;
type->procedure.results = results;
- type->procedure.result_count = proc_type_node->procedure_type.result_count;
+ type->procedure.result_count = proc_type_node->proc_type.result_count;
}
void check_identifier(Checker *c, Operand *o, AstNode *n, Type *named_type) {
- GB_ASSERT(n->kind == AstNode_Identifier);
+ GB_ASSERT(n->kind == AstNode_Ident);
o->mode = Addressing_Invalid;
- o->expression = n;
- Entity *e = scope_lookup_entity(c->context.scope, n->identifier.token.string);
+ o->expr = n;
+ Entity *e = scope_lookup_entity(c->context.scope, n->ident.token.string);
if (e == NULL) {
- error(&c->error_collector, n->identifier.token,
- "Undeclared type or identifier `%.*s`", LIT(n->identifier.token.string));
+ error(&c->error_collector, n->ident.token,
+ "Undeclared type or identifier `%.*s`", LIT(n->ident.token.string));
return;
}
add_entity_use(&c->info, n, e);
@@ -148,14 +148,14 @@ void check_identifier(Checker *c, Operand *o, AstNode *n, Type *named_type) {
if (e->type == NULL) {
auto *found = map_get(&c->info.entities, hash_pointer(e));
if (found != NULL) {
- check_entity_declaration(c, e, *found, named_type);
+ check_entity_decl(c, e, *found, named_type);
} else {
- GB_PANIC("Internal Compiler Error: DeclarationInfo not found!");
+ GB_PANIC("Internal Compiler Error: DeclInfo not found!");
}
}
if (e->type == NULL) {
- GB_PANIC("Compiler error: How did this happen? type: %s; identifier: %.*s\n", type_to_string(e->type), LIT(n->identifier.token.string));
+ GB_PANIC("Compiler error: How did this happen? type: %s; identifier: %.*s\n", type_to_string(e->type), LIT(n->ident.token.string));
return;
}
@@ -203,7 +203,7 @@ void check_identifier(Checker *c, Operand *o, AstNode *n, Type *named_type) {
i64 check_array_count(Checker *c, AstNode *e) {
if (e) {
Operand o = {};
- check_expression(c, &o, e);
+ check_expr(c, &o, e);
if (o.mode != Addressing_Constant) {
if (o.mode != Addressing_Invalid) {
error(&c->error_collector, ast_node_token(e), "Array count must be a constant");
@@ -225,12 +225,12 @@ i64 check_array_count(Checker *c, AstNode *e) {
return 0;
}
-Type *check_type_expression_extra(Checker *c, AstNode *e, Type *named_type) {
+Type *check_type_expr_extra(Checker *c, AstNode *e, Type *named_type) {
gbString err_str = NULL;
defer (gb_string_free(err_str));
switch (e->kind) {
- case AstNode_Identifier: {
+ case AstNode_Ident: {
Operand o = {};
check_identifier(c, &o, e, named_type);
switch (o.mode) {
@@ -244,28 +244,28 @@ Type *check_type_expression_extra(Checker *c, AstNode *e, Type *named_type) {
break;
case Addressing_NoValue:
- err_str = expression_to_string(e);
+ err_str = expr_to_string(e);
error(&c->error_collector, ast_node_token(e), "`%s` used as a type", err_str);
break;
default:
- err_str = expression_to_string(e);
+ err_str = expr_to_string(e);
error(&c->error_collector, ast_node_token(e), "`%s` used as a type when not a type", err_str);
break;
}
} break;
- case AstNode_ParenExpression:
- return check_type(c, e->paren_expression.expression, named_type);
+ case AstNode_ParenExpr:
+ return check_type(c, e->paren_expr.expr, named_type);
case AstNode_ArrayType:
if (e->array_type.count != NULL) {
Type *t = make_type_array(c->allocator,
- check_type(c, e->array_type.element),
+ check_type(c, e->array_type.elem),
check_array_count(c, e->array_type.count));
set_base_type(named_type, t);
return t;
} else {
- Type *t = make_type_slice(c->allocator, check_type(c, e->array_type.element));
+ Type *t = make_type_slice(c->allocator, check_type(c, e->array_type.elem));
set_base_type(named_type, t);
return t;
}
@@ -279,12 +279,12 @@ Type *check_type_expression_extra(Checker *c, AstNode *e, Type *named_type) {
} break;
case AstNode_PointerType: {
- Type *t = make_type_pointer(c->allocator, check_type(c, e->pointer_type.type_expression));
+ Type *t = make_type_pointer(c->allocator, check_type(c, e->pointer_type.type));
set_base_type(named_type, t);
return t;
} break;
- case AstNode_ProcedureType: {
+ case AstNode_ProcType: {
Type *t = alloc_type(c->allocator, Type_Procedure);
set_base_type(named_type, t);
check_open_scope(c, e);
@@ -294,7 +294,7 @@ Type *check_type_expression_extra(Checker *c, AstNode *e, Type *named_type) {
} break;
default:
- err_str = expression_to_string(e);
+ err_str = expr_to_string(e);
error(&c->error_collector, ast_node_token(e), "`%s` is not a type", err_str);
break;
}
@@ -312,7 +312,7 @@ Type *check_type(Checker *c, AstNode *e, Type *named_type) {
defer (gb_string_free(err_str));
switch (e->kind) {
- case AstNode_Identifier: {
+ case AstNode_Ident: {
Operand operand = {};
check_identifier(c, &operand, e, named_type);
switch (operand.mode) {
@@ -326,17 +326,17 @@ Type *check_type(Checker *c, AstNode *e, Type *named_type) {
break;
case Addressing_NoValue:
- err_str = expression_to_string(e);
+ err_str = expr_to_string(e);
error(&c->error_collector, ast_node_token(e), "`%s` used as a type", err_str);
break;
default:
- err_str = expression_to_string(e);
+ err_str = expr_to_string(e);
error(&c->error_collector, ast_node_token(e), "`%s` used as a type when not a type", err_str);
break;
}
} break;
- case AstNode_SelectorExpression: {
+ case AstNode_SelectorExpr: {
Operand o = {};
check_selector(c, &o, e);
@@ -346,17 +346,17 @@ Type *check_type(Checker *c, AstNode *e, Type *named_type) {
}
} break;
- case AstNode_ParenExpression:
- return check_type(c, e->paren_expression.expression, named_type);
+ case AstNode_ParenExpr:
+ return check_type(c, e->paren_expr.expr, named_type);
case AstNode_ArrayType: {
if (e->array_type.count != NULL) {
type = make_type_array(c->allocator,
- check_type(c, e->array_type.element),
+ check_type(c, e->array_type.elem),
check_array_count(c, e->array_type.count));
set_base_type(named_type, type);
} else {
- type = make_type_slice(c->allocator, check_type(c, e->array_type.element));
+ type = make_type_slice(c->allocator, check_type(c, e->array_type.elem));
set_base_type(named_type, type);
}
goto end;
@@ -370,12 +370,12 @@ Type *check_type(Checker *c, AstNode *e, Type *named_type) {
} break;
case AstNode_PointerType: {
- type = make_type_pointer(c->allocator, check_type(c, e->pointer_type.type_expression));
+ type = make_type_pointer(c->allocator, check_type(c, e->pointer_type.type));
set_base_type(named_type, type);
goto end;
} break;
- case AstNode_ProcedureType: {
+ case AstNode_ProcType: {
type = alloc_type(c->allocator, Type_Procedure);
set_base_type(named_type, type);
check_procedure_type(c, type, e);
@@ -383,7 +383,7 @@ Type *check_type(Checker *c, AstNode *e, Type *named_type) {
} break;
default:
- err_str = expression_to_string(e);
+ err_str = expr_to_string(e);
error(&c->error_collector, ast_node_token(e), "`%s` is not a type", err_str);
break;
}
@@ -406,7 +406,7 @@ b32 check_unary_op(Checker *c, Operand *o, Token op) {
case Token_Add:
case Token_Sub:
if (!is_type_numeric(o->type)) {
- str = expression_to_string(o->expression);
+ str = expr_to_string(o->expr);
error(&c->error_collector, op, "Operator `%.*s` is not allowed with `%s`", LIT(op.string), str);
}
break;
@@ -419,7 +419,7 @@ b32 check_unary_op(Checker *c, Operand *o, Token op) {
case Token_Not:
if (!is_type_boolean(o->type)) {
- str = expression_to_string(o->expression);
+ str = expr_to_string(o->expr);
error(&c->error_collector, op, "Operator `%.*s` is only allowed on boolean expression", LIT(op.string));
}
break;
@@ -565,12 +565,12 @@ void check_is_expressible(Checker *c, Operand *o, Type *type) {
defer (gb_string_free(b));
if (is_type_numeric(o->type) && is_type_numeric(type)) {
if (!is_type_integer(o->type) && is_type_integer(type)) {
- error(&c->error_collector, ast_node_token(o->expression), "`%s` truncated to `%s`", a, b);
+ error(&c->error_collector, ast_node_token(o->expr), "`%s` truncated to `%s`", a, b);
} else {
- error(&c->error_collector, ast_node_token(o->expression), "`%s` overflows to `%s`", a, b);
+ error(&c->error_collector, ast_node_token(o->expr), "`%s` overflows to `%s`", a, b);
}
} else {
- error(&c->error_collector, ast_node_token(o->expression), "Cannot convert `%s` to `%s`", a, b);
+ error(&c->error_collector, ast_node_token(o->expr), "Cannot convert `%s` to `%s`", a, b);
}
o->mode = Addressing_Invalid;
@@ -578,10 +578,10 @@ void check_is_expressible(Checker *c, Operand *o, Type *type) {
}
-void check_unary_expression(Checker *c, Operand *o, Token op, AstNode *node) {
+void check_unary_expr(Checker *c, Operand *o, Token op, AstNode *node) {
if (op.kind == Token_Pointer) { // Pointer address
if (o->mode != Addressing_Variable) {
- gbString str = expression_to_string(node->unary_expression.operand);
+ gbString str = expr_to_string(node->unary_expr.expr);
defer (gb_string_free(str));
error(&c->error_collector, op, "Cannot take the pointer address of `%s`", str);
o->mode = Addressing_Invalid;
@@ -607,7 +607,7 @@ void check_unary_expression(Checker *c, Operand *o, Token op, AstNode *node) {
if (is_type_typed(type)) {
if (node != NULL)
- o->expression = node;
+ o->expr = node;
check_is_expressible(c, o, type);
}
return;
@@ -666,18 +666,18 @@ void check_comparison(Checker *c, Operand *x, Operand *y, Token op) {
x->type = &basic_types[Basic_UntypedBool];
}
-void check_binary_expression(Checker *c, Operand *x, AstNode *node) {
- GB_ASSERT(node->kind == AstNode_BinaryExpression);
+void check_binary_expr(Checker *c, Operand *x, AstNode *node) {
+ GB_ASSERT(node->kind == AstNode_BinaryExpr);
Operand y_ = {}, *y = &y_;
gbString err_str = NULL;
defer (gb_string_free(err_str));
- check_expression(c, x, node->binary_expression.left);
- check_expression(c, y, node->binary_expression.right);
+ check_expr(c, x, node->binary_expr.left);
+ check_expr(c, y, node->binary_expr.right);
if (x->mode == Addressing_Invalid) return;
if (y->mode == Addressing_Invalid) {
x->mode = Addressing_Invalid;
- x->expression = y->expression;
+ x->expr = y->expr;
return;
}
@@ -689,7 +689,7 @@ void check_binary_expression(Checker *c, Operand *x, AstNode *node) {
return;
}
- Token op = node->binary_expression.op;
+ Token op = node->binary_expr.op;
if (token_is_comparison(op)) {
check_comparison(c, x, y, op);
return;
@@ -702,7 +702,7 @@ void check_binary_expression(Checker *c, Operand *x, AstNode *node) {
gbString yt = type_to_string(y->type);
defer (gb_string_free(xt));
defer (gb_string_free(yt));
- err_str = expression_to_string(x->expression);
+ err_str = expr_to_string(x->expr);
error(&c->error_collector, op, "Mismatched types in binary expression `%s` : `%s` vs `%s`", err_str, xt, yt);
}
x->mode = Addressing_Invalid;
@@ -734,7 +734,7 @@ void check_binary_expression(Checker *c, Operand *x, AstNode *node) {
}
if (fail) {
- error(&c->error_collector, ast_node_token(y->expression), "Division by zero not allowed");
+ error(&c->error_collector, ast_node_token(y->expr), "Division by zero not allowed");
x->mode = Addressing_Invalid;
return;
}
@@ -754,7 +754,7 @@ void check_binary_expression(Checker *c, Operand *x, AstNode *node) {
x->value = exact_binary_operator_value(op, a, b);
if (is_type_typed(type)) {
if (node != NULL)
- x->expression = node;
+ x->expr = node;
check_is_expressible(c, x, type);
}
return;
@@ -764,24 +764,24 @@ void check_binary_expression(Checker *c, Operand *x, AstNode *node) {
}
-void update_expression_type(Checker *c, AstNode *e, Type *type) {
+void update_expr_type(Checker *c, AstNode *e, Type *type) {
ExpressionInfo *found = map_get(&c->info.untyped, hash_pointer(e));
if (!found)
return;
switch (e->kind) {
- case AstNode_UnaryExpression:
+ case AstNode_UnaryExpr:
if (found->value.kind != ExactValue_Invalid)
break;
- update_expression_type(c, e->unary_expression.operand, type);
+ update_expr_type(c, e->unary_expr.expr, type);
break;
- case AstNode_BinaryExpression:
+ case AstNode_BinaryExpr:
if (found->value.kind != ExactValue_Invalid)
break;
- if (!token_is_comparison(e->binary_expression.op)) {
- update_expression_type(c, e->binary_expression.left, type);
- update_expression_type(c, e->binary_expression.right, type);
+ if (!token_is_comparison(e->binary_expr.op)) {
+ update_expr_type(c, e->binary_expr.left, type);
+ update_expr_type(c, e->binary_expr.right, type);
}
}
@@ -792,14 +792,14 @@ void update_expression_type(Checker *c, AstNode *e, Type *type) {
}
}
-void update_expression_value(Checker *c, AstNode *e, ExactValue value) {
+void update_expr_value(Checker *c, AstNode *e, ExactValue value) {
ExpressionInfo *found = map_get(&c->info.untyped, hash_pointer(e));
if (found)
found->value = value;
}
void convert_untyped_error(Checker *c, Operand *operand, Type *target_type) {
- gbString expr_str = expression_to_string(operand->expression);
+ gbString expr_str = expr_to_string(operand->expr);
gbString type_str = type_to_string(target_type);
char *extra_text = "";
defer (gb_string_free(expr_str));
@@ -811,7 +811,7 @@ void convert_untyped_error(Checker *c, Operand *operand, Type *target_type) {
extra_text = " - Did you want `null`?";
}
}
- error(&c->error_collector, ast_node_token(operand->expression), "Cannot convert `%s` to `%s`%s", expr_str, type_str, extra_text);
+ error(&c->error_collector, ast_node_token(operand->expr), "Cannot convert `%s` to `%s`%s", expr_str, type_str, extra_text);
operand->mode = Addressing_Invalid;
}
@@ -830,7 +830,7 @@ void convert_to_typed(Checker *c, Operand *operand, Type *target_type) {
if (is_type_numeric(x) && is_type_numeric(y)) {
if (x < y) {
operand->type = target_type;
- update_expression_type(c, operand->expression, target_type);
+ update_expr_type(c, operand->expr, target_type);
}
} else if (x != y) {
convert_untyped_error(c, operand, target_type);
@@ -846,7 +846,7 @@ void convert_to_typed(Checker *c, Operand *operand, Type *target_type) {
if (operand->mode == Addressing_Invalid) {
return;
}
- update_expression_value(c, operand->expression, operand->value);
+ update_expr_value(c, operand->expr, operand->value);
} else {
// TODO(bill): Is this really needed?
switch (operand->type->basic.kind) {
@@ -888,7 +888,7 @@ void convert_to_typed(Checker *c, Operand *operand, Type *target_type) {
b32 check_index_value(Checker *c, AstNode *index_value, i64 max_count, i64 *value) {
Operand operand = {Addressing_Invalid};
- check_expression(c, &operand, index_value);
+ check_expr(c, &operand, index_value);
if (operand.mode == Addressing_Invalid) {
if (value) *value = 0;
return false;
@@ -901,8 +901,8 @@ b32 check_index_value(Checker *c, AstNode *index_value, i64 max_count, i64 *valu
}
if (!is_type_integer(operand.type)) {
- gbString expr_str = expression_to_string(operand.expression);
- error(&c->error_collector, ast_node_token(operand.expression),
+ gbString expr_str = expr_to_string(operand.expr);
+ error(&c->error_collector, ast_node_token(operand.expr),
"Index `%s` must be an integer", expr_str);
gb_string_free(expr_str);
if (value) *value = 0;
@@ -913,8 +913,8 @@ b32 check_index_value(Checker *c, AstNode *index_value, i64 max_count, i64 *valu
if (max_count >= 0) { // NOTE(bill): Do array bound checking
i64 i = exact_value_to_integer(operand.value).value_integer;
if (i < 0) {
- gbString expr_str = expression_to_string(operand.expression);
- error(&c->error_collector, ast_node_token(operand.expression),
+ gbString expr_str = expr_to_string(operand.expr);
+ error(&c->error_collector, ast_node_token(operand.expr),
"Index `%s` cannot be a negative value", expr_str);
gb_string_free(expr_str);
if (value) *value = 0;
@@ -924,8 +924,8 @@ b32 check_index_value(Checker *c, AstNode *index_value, i64 max_count, i64 *valu
if (value) *value = i;
if (i >= max_count) {
- gbString expr_str = expression_to_string(operand.expression);
- error(&c->error_collector, ast_node_token(operand.expression),
+ gbString expr_str = expr_to_string(operand.expr);
+ error(&c->error_collector, ast_node_token(operand.expr),
"Index `%s` is out of bounds range [0, %lld)", expr_str, max_count);
gb_string_free(expr_str);
return false;
@@ -941,12 +941,12 @@ b32 check_index_value(Checker *c, AstNode *index_value, i64 max_count, i64 *valu
}
Entity *lookup_field(Type *type, AstNode *field_node, isize *index = NULL) {
- GB_ASSERT(field_node->kind == AstNode_Identifier);
+ GB_ASSERT(field_node->kind == AstNode_Ident);
type = get_base_type(type);
if (type->kind == Type_Pointer)
type = get_base_type(type->pointer.element);
- String field_str = field_node->identifier.token.string;
+ String field_str = field_node->ident.token.string;
switch (type->kind) {
case Type_Structure:
for (isize i = 0; i < type->structure.field_count; i++) {
@@ -968,38 +968,38 @@ Entity *lookup_field(Type *type, AstNode *field_node, isize *index = NULL) {
}
void check_selector(Checker *c, Operand *operand, AstNode *node) {
- GB_ASSERT(node->kind == AstNode_SelectorExpression);
+ GB_ASSERT(node->kind == AstNode_SelectorExpr);
- AstNode *op_expr = node->selector_expression.operand;
- AstNode *selector = node->selector_expression.selector;
+ AstNode *op_expr = node->selector_expr.expr;
+ AstNode *selector = node->selector_expr.selector;
if (selector) {
Entity *entity = lookup_field(operand->type, selector);
if (entity == NULL) {
- gbString op_str = expression_to_string(op_expr);
- gbString sel_str = expression_to_string(selector);
+ gbString op_str = expr_to_string(op_expr);
+ gbString sel_str = expr_to_string(selector);
defer (gb_string_free(op_str));
defer (gb_string_free(sel_str));
error(&c->error_collector, ast_node_token(op_expr), "`%s` has no field `%s`", op_str, sel_str);
operand->mode = Addressing_Invalid;
- operand->expression = node;
+ operand->expr = node;
return;
}
add_entity_use(&c->info, selector, entity);
operand->type = entity->type;
- operand->expression = node;
+ operand->expr = node;
if (operand->mode != Addressing_Variable)
operand->mode = Addressing_Value;
} else {
operand->mode = Addressing_Invalid;
- operand->expression = node;
+ operand->expr = node;
}
}
b32 check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id) {
- GB_ASSERT(call->kind == AstNode_CallExpression);
- auto *ce = &call->call_expression;
+ GB_ASSERT(call->kind == AstNode_CallExpr);
+ auto *ce = &call->call_expr;
BuiltinProcedure *bp = &builtin_procedures[id];
{
char *err = NULL;
@@ -1009,7 +1009,7 @@ b32 check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id)
err = "Too many";
if (err) {
error(&c->error_collector, ce->close, "`%s` arguments for `%.*s`, expected %td, got %td",
- err, LIT(call->call_expression.proc->identifier.token.string),
+ err, LIT(call->call_expr.proc->ident.token.string),
bp->arg_count, ce->arg_list_count);
return false;
}
@@ -1022,7 +1022,7 @@ b32 check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id)
// NOTE(bill): The first arg is a Type, this will be checked case by case
break;
default:
- check_multi_expression(c, operand, ce->arg_list);
+ check_multi_expr(c, operand, ce->arg_list);
}
switch (id) {
@@ -1077,14 +1077,14 @@ b32 check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id)
case BuiltinProcedure_offset_of: {
// offset_val :: proc(Type, field)
Type *type = get_base_type(check_type(c, ce->arg_list));
- AstNode *field_arg = unparen_expression(ce->arg_list->next);
+ AstNode *field_arg = unparen_expr(ce->arg_list->next);
if (type) {
if (type->kind != Type_Structure) {
error(&c->error_collector, ast_node_token(ce->arg_list), "Expected a structure type for `offset_of`");
return false;
}
if (field_arg == NULL ||
- field_arg->kind != AstNode_Identifier) {
+ field_arg->kind != AstNode_Ident) {
error(&c->error_collector, ast_node_token(field_arg), "Expected an identifier for field argument");
return false;
}
@@ -1095,7 +1095,7 @@ b32 check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id)
if (entity == NULL) {
gbString type_str = type_to_string(type);
error(&c->error_collector, ast_node_token(ce->arg_list),
- "`%s` has no field named `%.*s`", type_str, LIT(field_arg->identifier.token.string));
+ "`%s` has no field named `%.*s`", type_str, LIT(field_arg->ident.token.string));
return false;
}
@@ -1106,15 +1106,15 @@ b32 check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id)
case BuiltinProcedure_offset_of_val: {
// offset_val :: proc(val)
- AstNode *arg = unparen_expression(ce->arg_list);
- if (arg->kind != AstNode_SelectorExpression) {
- gbString str = expression_to_string(arg);
+ AstNode *arg = unparen_expr(ce->arg_list);
+ if (arg->kind != AstNode_SelectorExpr) {
+ gbString str = expr_to_string(arg);
error(&c->error_collector, ast_node_token(arg), "`%s` is not a selector expression", str);
return false;
}
- auto *s = &arg->selector_expression;
+ auto *s = &arg->selector_expr;
- check_expression(c, operand, s->operand);
+ check_expr(c, operand, s->expr);
if (operand->mode == Addressing_Invalid)
return false;
@@ -1130,7 +1130,7 @@ b32 check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id)
if (entity == NULL) {
gbString type_str = type_to_string(type);
error(&c->error_collector, ast_node_token(arg),
- "`%s` has no field named `%.*s`", type_str, LIT(s->selector->identifier.token.string));
+ "`%s` has no field named `%.*s`", type_str, LIT(s->selector->ident.token.string));
return false;
}
@@ -1145,14 +1145,14 @@ b32 check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id)
if (operand->mode != Addressing_Constant ||
!is_type_boolean(operand->type)) {
- gbString str = expression_to_string(ce->arg_list);
+ gbString str = expr_to_string(ce->arg_list);
defer (gb_string_free(str));
error(&c->error_collector, ast_node_token(call),
"`%s` is not a constant boolean", str);
return false;
}
if (!operand->value.value_bool) {
- gbString str = expression_to_string(ce->arg_list);
+ gbString str = expr_to_string(ce->arg_list);
defer (gb_string_free(str));
error(&c->error_collector, ast_node_token(call),
"Static assertion: `%s`", str);
@@ -1193,8 +1193,8 @@ b32 check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id)
}
if (mode == Addressing_Invalid) {
- gbString str = expression_to_string(operand->expression);
- error(&c->error_collector, ast_node_token(operand->expression),
+ gbString str = expr_to_string(operand->expr);
+ error(&c->error_collector, ast_node_token(operand->expr),
"Invalid expression `%s` for `%.*s`",
str, LIT(bp->name));
gb_string_free(str);
@@ -1217,7 +1217,7 @@ b32 check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id)
dest_type = d->slice.element;
Operand op = {};
- check_expression(c, &op, ce->arg_list->next);
+ check_expr(c, &op, ce->arg_list->next);
if (op.mode == Addressing_Invalid)
return false;
Type *s = get_base_type(op.type);
@@ -1230,8 +1230,8 @@ b32 check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id)
}
if (!are_types_identical(dest_type, src_type)) {
- gbString d_arg = expression_to_string(ce->arg_list);
- gbString s_arg = expression_to_string(ce->arg_list->next);
+ gbString d_arg = expr_to_string(ce->arg_list);
+ gbString s_arg = expr_to_string(ce->arg_list->next);
gbString d_str = type_to_string(dest_type);
gbString s_str = type_to_string(src_type);
defer (gb_string_free(d_arg));
@@ -1265,9 +1265,9 @@ b32 check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id)
void check_call_arguments(Checker *c, Operand *operand, Type *proc_type, AstNode *call) {
- GB_ASSERT(call->kind == AstNode_CallExpression);
+ GB_ASSERT(call->kind == AstNode_CallExpr);
GB_ASSERT(proc_type->kind == Type_Procedure);
- auto *ce = &call->call_expression;
+ auto *ce = &call->call_expr;
isize error_code = 0;
isize param_index = 0;
isize param_count = 0;
@@ -1284,7 +1284,7 @@ void check_call_arguments(Checker *c, Operand *operand, Type *proc_type, AstNode
Entity **sig_params = proc_type->procedure.params->tuple.variables;
AstNode *call_arg = ce->arg_list;
for (; call_arg != NULL; call_arg = call_arg->next) {
- check_multi_expression(c, operand, call_arg);
+ check_multi_expr(c, operand, call_arg);
if (operand->mode == Addressing_Invalid)
continue;
if (operand->type->kind != Type_Tuple) {
@@ -1330,7 +1330,7 @@ void check_call_arguments(Checker *c, Operand *operand, Type *proc_type, AstNode
err_fmt = "Too many arguments for `%s`, expected %td arguments";
}
- gbString proc_str = expression_to_string(ce->proc);
+ gbString proc_str = expr_to_string(ce->proc);
error(&c->error_collector, ast_node_token(call), err_fmt, proc_str, param_count);
gb_string_free(proc_str);
@@ -1339,16 +1339,16 @@ void check_call_arguments(Checker *c, Operand *operand, Type *proc_type, AstNode
}
-ExpressionKind check_call_expression(Checker *c, Operand *operand, AstNode *call) {
- GB_ASSERT(call->kind == AstNode_CallExpression);
- auto *ce = &call->call_expression;
- check_expression_or_type(c, operand, ce->proc);
+ExpressionKind check_call_expr(Checker *c, Operand *operand, AstNode *call) {
+ GB_ASSERT(call->kind == AstNode_CallExpr);
+ auto *ce = &call->call_expr;
+ check_expr_or_type(c, operand, ce->proc);
if (operand->mode == Addressing_Invalid) {
for (AstNode *arg = ce->arg_list; arg != NULL; arg = arg->next)
- check_expression_base(c, operand, arg);
+ check_expr_base(c, operand, arg);
operand->mode = Addressing_Invalid;
- operand->expression = call;
+ operand->expr = call;
return Expression_Statement;
}
@@ -1356,19 +1356,19 @@ ExpressionKind check_call_expression(Checker *c, Operand *operand, AstNode *call
i32 id = operand->builtin_id;
if (!check_builtin_procedure(c, operand, call, id))
operand->mode = Addressing_Invalid;
- operand->expression = call;
+ operand->expr = call;
return builtin_procedures[id].kind;
}
Type *proc_type = get_base_type(operand->type);
if (proc_type == NULL || proc_type->kind != Type_Procedure) {
- AstNode *e = operand->expression;
- gbString str = expression_to_string(e);
+ AstNode *e = operand->expr;
+ gbString str = expr_to_string(e);
defer (gb_string_free(str));
error(&c->error_collector, ast_node_token(e), "Cannot call a non-procedure: `%s`", str);
operand->mode = Addressing_Invalid;
- operand->expression = call;
+ operand->expr = call;
return Expression_Statement;
}
@@ -1387,7 +1387,7 @@ ExpressionKind check_call_expression(Checker *c, Operand *operand, AstNode *call
operand->type = proc->results;
}
- operand->expression = call;
+ operand->expr = call;
return Expression_Statement;
}
@@ -1432,7 +1432,7 @@ b32 check_castable_to(Checker *c, Operand *operand, Type *y) {
return false;
}
-void check_cast_expression(Checker *c, Operand *operand, Type *type) {
+void check_cast_expr(Checker *c, Operand *operand, Type *type) {
b32 is_const_expr = operand->mode == Addressing_Constant;
b32 can_convert = false;
@@ -1449,11 +1449,11 @@ void check_cast_expression(Checker *c, Operand *operand, Type *type) {
}
if (!can_convert) {
- gbString expr_str = expression_to_string(operand->expression);
+ gbString expr_str = expr_to_string(operand->expr);
gbString type_str = type_to_string(type);
defer (gb_string_free(expr_str));
defer (gb_string_free(type_str));
- error(&c->error_collector, ast_node_token(operand->expression), "Cannot cast `%s` to `%s`", expr_str, type_str);
+ error(&c->error_collector, ast_node_token(operand->expr), "Cannot cast `%s` to `%s`", expr_str, type_str);
operand->mode = Addressing_Invalid;
return;
@@ -1462,8 +1462,8 @@ void check_cast_expression(Checker *c, Operand *operand, Type *type) {
operand->type = type;
}
-void check_expression_with_type_hint(Checker *c, Operand *o, AstNode *e, Type *t) {
- check_expression_base(c, o, e, t);
+void check_expr_with_type_hint(Checker *c, Operand *o, AstNode *e, Type *t) {
+ check_expr_base(c, o, e, t);
check_not_tuple(c, o);
char *err_str = NULL;
switch (o->mode) {
@@ -1478,29 +1478,29 @@ void check_expression_with_type_hint(Checker *c, Operand *o, AstNode *e, Type *t
break;
}
if (err_str != NULL) {
- gbString str = expression_to_string(e);
+ gbString str = expr_to_string(e);
defer (gb_string_free(str));
error(&c->error_collector, ast_node_token(e), "`%s` %s", str, err_str);
o->mode = Addressing_Invalid;
}
}
-ExpressionKind check__expression_base(Checker *c, Operand *o, AstNode *node, Type *type_hint) {
+ExpressionKind check__expr_base(Checker *c, Operand *o, AstNode *node, Type *type_hint) {
ExpressionKind kind = Expression_Statement;
o->mode = Addressing_Invalid;
o->type = &basic_types[Basic_Invalid];
switch (node->kind) {
- case AstNode_BadExpression:
+ case AstNode_BadExpr:
goto error;
- case AstNode_Identifier:
+ case AstNode_Ident:
check_identifier(c, o, node, type_hint);
break;
- case AstNode_BasicLiteral: {
+ case AstNode_BasicLit: {
BasicKind basic_kind = Basic_Invalid;
- Token lit = node->basic_literal;
+ Token lit = node->basic_lit;
switch (lit.kind) {
case Token_Integer: basic_kind = Basic_UntypedInteger; break;
case Token_Float: basic_kind = Basic_UntypedFloat; break;
@@ -1513,26 +1513,26 @@ ExpressionKind check__expression_base(Checker *c, Operand *o, AstNode *node, Typ
o->value = make_exact_value_from_basic_literal(lit);
} break;
- case AstNode_ProcedureLiteral: {
+ case AstNode_ProcLit: {
Scope *origin_curr_scope = c->context.scope;
- Type *proc_type = check_type(c, node->procedure_literal.type);
+ Type *proc_type = check_type(c, node->proc_lit.type);
if (proc_type != NULL) {
- check_procedure_body(c, empty_token, c->context.decl, proc_type, node->procedure_literal.body);
+ check_proc_body(c, empty_token, c->context.decl, proc_type, node->proc_lit.body);
o->mode = Addressing_Value;
o->type = proc_type;
} else {
- gbString str = expression_to_string(node);
+ gbString str = expr_to_string(node);
error(&c->error_collector, ast_node_token(node), "Invalid procedure literal `%s`", str);
gb_string_free(str);
goto error;
}
} break;
- case AstNode_CompoundLiteral: {
- auto *cl = &node->compound_literal;
+ case AstNode_CompoundLit: {
+ auto *cl = &node->compound_lit;
Type *type = type_hint;
- if (cl->type_expression != NULL) {
- type = check_type(c, cl->type_expression);
+ if (cl->type != NULL) {
+ type = check_type(c, cl->type);
}
if (type == NULL) {
@@ -1543,10 +1543,10 @@ ExpressionKind check__expression_base(Checker *c, Operand *o, AstNode *node, Typ
Type *t = get_base_type(type);
switch (t->kind) {
case Type_Structure: {
- if (cl->element_count == 0)
+ if (cl->elem_count == 0)
break; // NOTE(bill): No need to init
{ // Checker values
- AstNode *elem = cl->element_list;
+ AstNode *elem = cl->elem_list;
isize field_count = t->structure.field_count;
isize index = 0;
for (;
@@ -1554,15 +1554,15 @@ ExpressionKind check__expression_base(Checker *c, Operand *o, AstNode *node, Typ
elem = elem->next, index++) {
Entity *field = t->structure.fields[index];
- check_expression(c, o, elem);
+ check_expr(c, o, elem);
if (index >= field_count) {
- error(&c->error_collector, ast_node_token(o->expression), "Too many values in structure literal, expected %td", field_count);
+ error(&c->error_collector, ast_node_token(o->expr), "Too many values in structure literal, expected %td", field_count);
break;
}
check_assignment(c, o, field->type, make_string("structure literal"));
}
- if (cl->element_count < field_count) {
- error(&c->error_collector, node->compound_literal.close, "Too few values in structure literal, expected %td, got %td", field_count, cl->element_count);
+ if (cl->elem_count < field_count) {
+ error(&c->error_collector, node->compound_lit.close, "Too few values in structure literal, expected %td, got %td", field_count, cl->elem_count);
}
}
@@ -1584,7 +1584,7 @@ ExpressionKind check__expression_base(Checker *c, Operand *o, AstNode *node, Typ
i64 index = 0;
i64 max = 0;
- for (AstNode *elem = cl->element_list; elem != NULL; elem = elem->next, index++) {
+ for (AstNode *elem = cl->elem_list; elem != NULL; elem = elem->next, index++) {
AstNode *e = elem;
if (t->kind == Type_Array &&
t->array.count >= 0 &&
@@ -1593,7 +1593,7 @@ ExpressionKind check__expression_base(Checker *c, Operand *o, AstNode *node, Typ
}
Operand o = {};
- check_expression_with_type_hint(c, &o, e, element_type);
+ check_expr_with_type_hint(c, &o, e, element_type);
check_assignment(c, &o, element_type, context_name);
}
if (max < index)
@@ -1612,41 +1612,41 @@ ExpressionKind check__expression_base(Checker *c, Operand *o, AstNode *node, Typ
o->type = type;
} break;
- case AstNode_ParenExpression:
- kind = check_expression_base(c, o, node->paren_expression.expression, type_hint);
- o->expression = node;
+ case AstNode_ParenExpr:
+ kind = check_expr_base(c, o, node->paren_expr.expr, type_hint);
+ o->expr = node;
break;
- case AstNode_TagExpression:
+ case AstNode_TagExpr:
// TODO(bill): Tag expressions
error(&c->error_collector, ast_node_token(node), "Tag expressions are not supported yet");
- kind = check_expression_base(c, o, node->tag_expression.expression, type_hint);
- o->expression = node;
+ kind = check_expr_base(c, o, node->tag_expr.expr, type_hint);
+ o->expr = node;
break;
- case AstNode_UnaryExpression:
- check_expression(c, o, node->unary_expression.operand);
+ case AstNode_UnaryExpr:
+ check_expr(c, o, node->unary_expr.expr);
if (o->mode == Addressing_Invalid)
goto error;
- check_unary_expression(c, o, node->unary_expression.op, node);
+ check_unary_expr(c, o, node->unary_expr.op, node);
if (o->mode == Addressing_Invalid)
goto error;
break;
- case AstNode_BinaryExpression:
- check_binary_expression(c, o, node);
+ case AstNode_BinaryExpr:
+ check_binary_expr(c, o, node);
if (o->mode == Addressing_Invalid)
goto error;
break;
- case AstNode_SelectorExpression:
- check_expression_base(c, o, node->selector_expression.operand);
+ case AstNode_SelectorExpr:
+ check_expr_base(c, o, node->selector_expr.expr);
check_selector(c, o, node);
break;
- case AstNode_IndexExpression: {
- check_expression(c, o, node->index_expression.expression);
+ case AstNode_IndexExpr: {
+ check_expr(c, o, node->index_expr.expr);
if (o->mode == Addressing_Invalid)
goto error;
@@ -1687,26 +1687,26 @@ ExpressionKind check__expression_base(Checker *c, Operand *o, AstNode *node, Typ
}
if (!valid) {
- gbString str = expression_to_string(o->expression);
- error(&c->error_collector, ast_node_token(o->expression), "Cannot index `%s`", str);
+ gbString str = expr_to_string(o->expr);
+ error(&c->error_collector, ast_node_token(o->expr), "Cannot index `%s`", str);
gb_string_free(str);
goto error;
}
- if (node->index_expression.value == NULL) {
- gbString str = expression_to_string(o->expression);
- error(&c->error_collector, ast_node_token(o->expression), "Missing index for `%s`", str);
+ if (node->index_expr.index == NULL) {
+ gbString str = expr_to_string(o->expr);
+ error(&c->error_collector, ast_node_token(o->expr), "Missing index for `%s`", str);
gb_string_free(str);
goto error;
}
- check_index_value(c, node->index_expression.value, max_count, NULL);
+ check_index_value(c, node->index_expr.index, max_count, NULL);
} break;
- case AstNode_SliceExpression: {
- auto *se = &node->slice_expression;
- check_expression(c, o, se->expression);
+ case AstNode_SliceExpr: {
+ auto *se = &node->slice_expr;
+ check_expr(c, o, se->expr);
if (o->mode == Addressing_Invalid)
goto error;
@@ -1728,7 +1728,7 @@ ExpressionKind check__expression_base(Checker *c, Operand *o, AstNode *node, Typ
valid = true;
max_count = t->array.count;
if (o->mode != Addressing_Variable) {
- gbString str = expression_to_string(node);
+ gbString str = expr_to_string(node);
error(&c->error_collector, ast_node_token(node), "Cannot slice array `%s`, value is not addressable", str);
gb_string_free(str);
goto error;
@@ -1750,8 +1750,8 @@ ExpressionKind check__expression_base(Checker *c, Operand *o, AstNode *node, Typ
}
if (!valid) {
- gbString str = expression_to_string(o->expression);
- error(&c->error_collector, ast_node_token(o->expression), "Cannot slice `%s`", str);
+ gbString str = expr_to_string(o->expr);
+ error(&c->error_collector, ast_node_token(o->expr), "Cannot slice `%s`", str);
gb_string_free(str);
goto error;
}
@@ -1786,19 +1786,19 @@ ExpressionKind check__expression_base(Checker *c, Operand *o, AstNode *node, Typ
} break;
- case AstNode_CastExpression: {
- Type *cast_type = check_type(c, node->cast_expression.type_expression);
- check_expression_or_type(c, o, node->cast_expression.operand);
+ case AstNode_CastExpr: {
+ Type *cast_type = check_type(c, node->cast_expr.type);
+ check_expr_or_type(c, o, node->cast_expr.expr);
if (o->mode != Addressing_Invalid)
- check_cast_expression(c, o, cast_type);
+ check_cast_expr(c, o, cast_type);
} break;
- case AstNode_CallExpression:
- return check_call_expression(c, o, node);
+ case AstNode_CallExpr:
+ return check_call_expr(c, o, node);
- case AstNode_DereferenceExpression:
- check_expression_or_type(c, o, node->dereference_expression.operand);
+ case AstNode_DerefExpr:
+ check_expr_or_type(c, o, node->deref_expr.expr);
if (o->mode == Addressing_Invalid) {
goto error;
} else {
@@ -1807,15 +1807,15 @@ ExpressionKind check__expression_base(Checker *c, Operand *o, AstNode *node, Typ
o->mode = Addressing_Variable;
o->type = t->pointer.element;
} else {
- gbString str = expression_to_string(o->expression);
- error(&c->error_collector, ast_node_token(o->expression), "Cannot dereference `%s`", str);
+ gbString str = expr_to_string(o->expr);
+ error(&c->error_collector, ast_node_token(o->expr), "Cannot dereference `%s`", str);
gb_string_free(str);
goto error;
}
}
break;
- case AstNode_ProcedureType:
+ case AstNode_ProcType:
case AstNode_PointerType:
case AstNode_ArrayType:
case AstNode_StructType:
@@ -1825,17 +1825,17 @@ ExpressionKind check__expression_base(Checker *c, Operand *o, AstNode *node, Typ
}
kind = Expression_Expression;
- o->expression = node;
+ o->expr = node;
return kind;
error:
o->mode = Addressing_Invalid;
- o->expression = node;
+ o->expr = node;
return kind;
}
-ExpressionKind check_expression_base(Checker *c, Operand *o, AstNode *node, Type *type_hint) {
- ExpressionKind kind = check__expression_base(c, o, node, type_hint);
+ExpressionKind check_expr_base(Checker *c, Operand *o, AstNode *node, Type *type_hint) {
+ ExpressionKind kind = check__expr_base(c, o, node, type_hint);
Type *type = NULL;
ExactValue value = {ExactValue_Invalid};
switch (o->mode) {
@@ -1865,21 +1865,21 @@ ExpressionKind check_expression_base(Checker *c, Operand *o, AstNode *node, Type
}
-void check_multi_expression(Checker *c, Operand *o, AstNode *e) {
+void check_multi_expr(Checker *c, Operand *o, AstNode *e) {
gbString err_str = NULL;
defer (gb_string_free(err_str));
- check_expression_base(c, o, e);
+ check_expr_base(c, o, e);
switch (o->mode) {
default:
return; // NOTE(bill): Valid
case Addressing_NoValue:
- err_str = expression_to_string(e);
+ err_str = expr_to_string(e);
error(&c->error_collector, ast_node_token(e), "`%s` used as value", err_str);
break;
case Addressing_Type:
- err_str = expression_to_string(e);
+ err_str = expr_to_string(e);
error(&c->error_collector, ast_node_token(e), "`%s` is not an expression", err_str);
break;
}
@@ -1893,25 +1893,25 @@ void check_not_tuple(Checker *c, Operand *o) {
if (o->type->kind == Type_Tuple) {
isize count = o->type->tuple.variable_count;
GB_ASSERT(count != 1);
- error(&c->error_collector, ast_node_token(o->expression),
+ error(&c->error_collector, ast_node_token(o->expr),
"%td-valued tuple found where single value expected", count);
o->mode = Addressing_Invalid;
}
}
}
-void check_expression(Checker *c, Operand *o, AstNode *e) {
- check_multi_expression(c, o, e);
+void check_expr(Checker *c, Operand *o, AstNode *e) {
+ check_multi_expr(c, o, e);
check_not_tuple(c, o);
}
-void check_expression_or_type(Checker *c, Operand *o, AstNode *e) {
- check_expression_base(c, o, e);
+void check_expr_or_type(Checker *c, Operand *o, AstNode *e) {
+ check_expr_base(c, o, e);
check_not_tuple(c, o);
if (o->mode == Addressing_NoValue) {
- AstNode *e = o->expression;
- gbString str = expression_to_string(e);
+ AstNode *e = o->expr;
+ gbString str = expr_to_string(e);
defer (gb_string_free(str));
error(&c->error_collector, ast_node_token(e),
"`%s` used as value or type", str);
@@ -1920,7 +1920,7 @@ void check_expression_or_type(Checker *c, Operand *o, AstNode *e) {
}
-gbString write_expression_to_string(gbString str, AstNode *node);
+gbString write_expr_to_string(gbString str, AstNode *node);
gbString write_field_list_to_string(gbString str, AstNode *field_list, char *sep) {
isize i = 0;
@@ -1933,12 +1933,12 @@ gbString write_field_list_to_string(gbString str, AstNode *field_list, char *sep
for (AstNode *name = field->field.name_list; name != NULL; name = name->next) {
if (j > 0)
str = gb_string_appendc(str, ", ");
- str = write_expression_to_string(str, name);
+ str = write_expr_to_string(str, name);
j++;
}
str = gb_string_appendc(str, ": ");
- str = write_expression_to_string(str, field->field.type_expression);
+ str = write_expr_to_string(str, field->field.type);
i++;
}
@@ -1950,7 +1950,7 @@ gbString string_append_token(gbString str, Token token) {
}
-gbString write_expression_to_string(gbString str, AstNode *node) {
+gbString write_expr_to_string(gbString str, AstNode *node) {
if (node == NULL)
return str;
@@ -1959,108 +1959,108 @@ gbString write_expression_to_string(gbString str, AstNode *node) {
str = gb_string_appendc(str, "(bad expression)");
break;
- case AstNode_Identifier:
- str = string_append_token(str, node->identifier.token);
+ case AstNode_Ident:
+ str = string_append_token(str, node->ident.token);
break;
- case AstNode_BasicLiteral:
- str = string_append_token(str, node->basic_literal);
+ case AstNode_BasicLit:
+ str = string_append_token(str, node->basic_lit);
break;
- case AstNode_ProcedureLiteral:
- str = write_expression_to_string(str, node->procedure_literal.type);
+ case AstNode_ProcLit:
+ str = write_expr_to_string(str, node->proc_lit.type);
break;
- case AstNode_CompoundLiteral:
+ case AstNode_CompoundLit:
str = gb_string_appendc(str, "(");
- str = write_expression_to_string(str, node->compound_literal.type_expression);
+ str = write_expr_to_string(str, node->compound_lit.type);
str = gb_string_appendc(str, " literal)");
break;
- case AstNode_TagExpression:
+ case AstNode_TagExpr:
str = gb_string_appendc(str, "#");
- str = string_append_token(str, node->tag_expression.name);
- str = write_expression_to_string(str, node->tag_expression.expression);
+ str = string_append_token(str, node->tag_expr.name);
+ str = write_expr_to_string(str, node->tag_expr.expr);
break;
- case AstNode_UnaryExpression:
- str = string_append_token(str, node->unary_expression.op);
- str = write_expression_to_string(str, node->unary_expression.operand);
+ case AstNode_UnaryExpr:
+ str = string_append_token(str, node->unary_expr.op);
+ str = write_expr_to_string(str, node->unary_expr.expr);
break;
- case AstNode_BinaryExpression:
- str = write_expression_to_string(str, node->binary_expression.left);
+ case AstNode_BinaryExpr:
+ str = write_expr_to_string(str, node->binary_expr.left);
str = gb_string_appendc(str, " ");
- str = string_append_token(str, node->binary_expression.op);
+ str = string_append_token(str, node->binary_expr.op);
str = gb_string_appendc(str, " ");
- str = write_expression_to_string(str, node->binary_expression.right);
+ str = write_expr_to_string(str, node->binary_expr.right);
break;
- case AstNode_ParenExpression:
+ case AstNode_ParenExpr:
str = gb_string_appendc(str, "(");
- str = write_expression_to_string(str, node->paren_expression.expression);
+ str = write_expr_to_string(str, node->paren_expr.expr);
str = gb_string_appendc(str, ")");
break;
- case AstNode_SelectorExpression:
- str = write_expression_to_string(str, node->selector_expression.operand);
+ case AstNode_SelectorExpr:
+ str = write_expr_to_string(str, node->selector_expr.expr);
str = gb_string_appendc(str, ".");
- str = write_expression_to_string(str, node->selector_expression.selector);
+ str = write_expr_to_string(str, node->selector_expr.selector);
break;
- case AstNode_IndexExpression:
- str = write_expression_to_string(str, node->index_expression.expression);
+ case AstNode_IndexExpr:
+ str = write_expr_to_string(str, node->index_expr.expr);
str = gb_string_appendc(str, "[");
- str = write_expression_to_string(str, node->index_expression.value);
+ str = write_expr_to_string(str, node->index_expr.index);
str = gb_string_appendc(str, "]");
break;
- case AstNode_SliceExpression:
- str = write_expression_to_string(str, node->slice_expression.expression);
+ case AstNode_SliceExpr:
+ str = write_expr_to_string(str, node->slice_expr.expr);
str = gb_string_appendc(str, "[");
- str = write_expression_to_string(str, node->slice_expression.low);
+ str = write_expr_to_string(str, node->slice_expr.low);
str = gb_string_appendc(str, ":");
- str = write_expression_to_string(str, node->slice_expression.high);
- if (node->slice_expression.triple_indexed) {
+ str = write_expr_to_string(str, node->slice_expr.high);
+ if (node->slice_expr.triple_indexed) {
str = gb_string_appendc(str, ":");
- str = write_expression_to_string(str, node->slice_expression.max);
+ str = write_expr_to_string(str, node->slice_expr.max);
}
str = gb_string_appendc(str, "]");
break;
- case AstNode_CastExpression:
+ case AstNode_CastExpr:
str = gb_string_appendc(str, "cast(");
- str = write_expression_to_string(str, node->cast_expression.type_expression);
+ str = write_expr_to_string(str, node->cast_expr.type);
str = gb_string_appendc(str, ")");
- str = write_expression_to_string(str, node->cast_expression.operand);
+ str = write_expr_to_string(str, node->cast_expr.expr);
break;
case AstNode_PointerType:
str = gb_string_appendc(str, "^");
- str = write_expression_to_string(str, node->pointer_type.type_expression);
+ str = write_expr_to_string(str, node->pointer_type.type);
break;
case AstNode_ArrayType:
str = gb_string_appendc(str, "[");
- str = write_expression_to_string(str, node->array_type.count);
+ str = write_expr_to_string(str, node->array_type.count);
str = gb_string_appendc(str, "]");
- str = write_expression_to_string(str, node->array_type.element);
+ str = write_expr_to_string(str, node->array_type.elem);
break;
- case AstNode_CallExpression: {
- str = write_expression_to_string(str, node->call_expression.proc);
+ case AstNode_CallExpr: {
+ str = write_expr_to_string(str, node->call_expr.proc);
str = gb_string_appendc(str, "(");
isize i = 0;
- for (AstNode *arg = node->call_expression.arg_list; arg != NULL; arg = arg->next) {
+ for (AstNode *arg = node->call_expr.arg_list; arg != NULL; arg = arg->next) {
if (i > 0) gb_string_appendc(str, ", ");
- str = write_expression_to_string(str, arg);
+ str = write_expr_to_string(str, arg);
i++;
}
str = gb_string_appendc(str, ")");
} break;
- case AstNode_ProcedureType:
+ case AstNode_ProcType:
str = gb_string_appendc(str, "proc(");
- str = write_field_list_to_string(str, node->procedure_type.param_list, ", ");
+ str = write_field_list_to_string(str, node->proc_type.param_list, ", ");
str = gb_string_appendc(str, ")");
break;
@@ -2074,6 +2074,6 @@ gbString write_expression_to_string(gbString str, AstNode *node) {
return str;
}
-gbString expression_to_string(AstNode *expression) {
- return write_expression_to_string(gb_string_make(gb_heap_allocator(), ""), expression);
+gbString expr_to_string(AstNode *expression) {
+ return write_expr_to_string(gb_string_make(gb_heap_allocator(), ""), expression);
}
diff --git a/src/checker/statements.cpp b/src/checker/statements.cpp
index aa4dc2aee..364a1de69 100644
--- a/src/checker/statements.cpp
+++ b/src/checker/statements.cpp
@@ -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;
}
}
diff --git a/src/codegen/codegen.cpp b/src/codegen/codegen.cpp
index a28d0d170..94ccabe0f 100644
--- a/src/codegen/codegen.cpp
+++ b/src/codegen/codegen.cpp
@@ -39,7 +39,7 @@ void ssa_gen_code(ssaGen *s) {
gb_for_array(i, info->entities.entries) {
auto *entry = &info->entities.entries[i];
Entity *e = cast(Entity *)cast(uintptr)entry->key;
- DeclarationInfo *decl = entry->value;
+ DeclInfo *decl = entry->value;
String name = e->token.string;
diff --git a/src/codegen/print.cpp b/src/codegen/print.cpp
index 63b846c46..d8c76d034 100644
--- a/src/codegen/print.cpp
+++ b/src/codegen/print.cpp
@@ -228,10 +228,9 @@ void ssa_print_value(gbFile *f, ssaModule *m, ssaValue *value, Type *type_hint)
void ssa_print_instruction(gbFile *f, ssaModule *m, ssaValue *value) {
GB_ASSERT(value->kind == ssaValue_Instruction);
+ ssaInstruction *instr = &value->instruction;
ssa_fprintf(f, "\t");
-
- ssaInstruction *instr = &value->instruction;
switch (instr->kind) {
case ssaInstruction_Local: {
Type *type = instr->local.entity->type;
@@ -261,7 +260,7 @@ void ssa_print_instruction(gbFile *f, ssaModule *m, ssaValue *value) {
} break;
case ssaInstruction_Load: {
- Type *type = ssa_value_type(instr->load.address);
+ Type *type = instr->load.type;
ssa_fprintf(f, "%%%d = load ", value->id);
ssa_print_type(f, m->sizes, type);
ssa_fprintf(f, ", ");
@@ -271,6 +270,32 @@ void ssa_print_instruction(gbFile *f, ssaModule *m, ssaValue *value) {
ssa_fprintf(f, "\n");
} break;
+ case ssaInstruction_GetElementPtr: {
+ Type *rt = instr->get_element_ptr.result_type;
+ Type *et = instr->get_element_ptr.element_type;
+ Type *t_int = &basic_types[Basic_int];
+ ssa_fprintf(f, "%%%d = getelementptr ", value->id);
+ if (instr->get_element_ptr.inbounds)
+ ssa_fprintf(f, "inbounds ");
+
+ ssa_print_type(f, m->sizes, et);
+ ssa_fprintf(f, ", ");
+ ssa_print_type(f, m->sizes, et);
+ ssa_fprintf(f, "* ");
+ ssa_print_value(f, m, instr->get_element_ptr.address, et);
+ ssa_fprintf(f, ", ");
+ ssa_print_type(f, m->sizes, t_int);
+ ssa_fprintf(f, " ");
+ ssa_print_value(f, m, instr->get_element_ptr.indices[0], t_int);
+ if (instr->get_element_ptr.index_count == 2) {
+ ssa_fprintf(f, ", ");
+ ssa_print_type(f, m->sizes, t_int);
+ ssa_fprintf(f, " ");
+ ssa_print_value(f, m, instr->get_element_ptr.indices[1], t_int);
+ }
+ ssa_fprintf(f, "\n");
+ } break;
+
case ssaInstruction_BinaryOp: {
auto *bo = &value->instruction.binary_op;
@@ -366,7 +391,7 @@ void ssa_print_llvm_ir(gbFile *f, ssaModule *m) {
} break;
case ssaValue_Global: {
- ssaGlobal *g = &v->global;
+ auto *g = &v->global;
ssa_print_encoded_global(f, g->entity->token.string);
ssa_fprintf(f, " = global ");
ssa_print_type(f, m->sizes, get_base_type(g->entity->type));
diff --git a/src/codegen/ssa.cpp b/src/codegen/ssa.cpp
index b7d925d07..bb1f51b81 100644
--- a/src/codegen/ssa.cpp
+++ b/src/codegen/ssa.cpp
@@ -31,7 +31,7 @@ struct ssaProcedure {
String name;
Entity *entity;
Type *type;
- DeclarationInfo *decl;
+ DeclInfo *decl;
AstNode *type_expr;
AstNode *body;
@@ -42,36 +42,26 @@ struct ssaProcedure {
-struct ssaTypeName {
- Entity *entity;
- Type *type;
-};
-struct ssaGlobal {
- b32 generated;
- Entity *entity;
- Type *type;
- ssaValue *value;
-};
-struct ssaConstant {
- Type *type;
- ExactValue value;
-};
-
-
+#define SSA_INSTRUCTION_KINDS \
+ SSA_INSTRUCTION_KIND(Invalid), \
+ SSA_INSTRUCTION_KIND(Local), \
+ SSA_INSTRUCTION_KIND(Store), \
+ SSA_INSTRUCTION_KIND(Load), \
+ SSA_INSTRUCTION_KIND(GetElementPtr), \
+ SSA_INSTRUCTION_KIND(Convert), \
+ SSA_INSTRUCTION_KIND(BinaryOp), \
+ SSA_INSTRUCTION_KIND(Count),
enum ssaInstructionKind {
- ssaInstruction_Invalid,
-
- ssaInstruction_Local,
- ssaInstruction_Store,
- ssaInstruction_Load,
- ssaInstruction_GetElementPtr,
-
- ssaInstruction_Convert,
-
- ssaInstruction_BinaryOp,
+#define SSA_INSTRUCTION_KIND(x) GB_JOIN2(ssaInstruction_, x)
+ SSA_INSTRUCTION_KINDS
+#undef SSA_INSTRUCTION_KIND
+};
- ssaInstruction_Count,
+String const ssa_instruction_strings[] = {
+#define SSA_INSTRUCTION_KIND(x) {cast(u8 *)#x, gb_size_of(#x)-1}
+ SSA_INSTRUCTION_KINDS
+#undef SSA_INSTRUCTION_KIND
};
struct ssaInstruction {
@@ -91,18 +81,18 @@ struct ssaInstruction {
ssaValue *value;
} store;
struct {
+ Type *type;
ssaValue *address;
} load;
struct {
ssaValue *address;
- Type *result_type;
- Type *element_type;
- isize index_count;
- isize indices[2];
+ Type * result_type;
+ Type * element_type;
+ ssaValue *indices[2];
+ isize index_count;
+ b32 inbounds;
} get_element_ptr;
-
-
struct {
Type *type;
Token op;
@@ -131,9 +121,20 @@ struct ssaValue {
i32 id;
union {
- ssaConstant constant;
- ssaTypeName type_name;
- ssaGlobal global;
+ struct {
+ Type * type;
+ ExactValue value;
+ } constant;
+ struct {
+ Entity *entity;
+ Type * type;
+ } type_name;
+ struct {
+ b32 generated;
+ Entity * entity;
+ Type * type;
+ ssaValue *value;
+ } global;
ssaProcedure procedure;
ssaBlock block;
ssaInstruction instruction;
@@ -188,7 +189,9 @@ Type *ssa_instruction_type(ssaInstruction *instr) {
case ssaInstruction_Store:
return ssa_value_type(instr->store.address);
case ssaInstruction_Load:
- return ssa_value_type(instr->load.address);
+ return instr->load.type;
+ case ssaInstruction_GetElementPtr:
+ return instr->get_element_ptr.result_type;
case ssaInstruction_BinaryOp:
return instr->binary_op.type;
}
@@ -204,7 +207,10 @@ void ssa_instruction_set_type(ssaInstruction *instr, Type *type) {
ssa_value_set_type(instr->store.value, type);
break;
case ssaInstruction_Load:
- // NOTE(bill): Do nothing
+ instr->load.type = type;
+ break;
+ case ssaInstruction_GetElementPtr:
+ instr->get_element_ptr.result_type = type;
break;
case ssaInstruction_BinaryOp:
instr->binary_op.type = type;
@@ -251,8 +257,8 @@ void ssa_value_set_type(ssaValue *value, Type *type) {
-ssaValue *ssa_build_expression(ssaProcedure *proc, AstNode *expr);
-ssaValue *ssa_build_single_expression(ssaProcedure *proc, AstNode *expr, TypeAndValue *tv);
+ssaValue *ssa_build_expr(ssaProcedure *proc, AstNode *expr);
+ssaValue *ssa_build_single_expr(ssaProcedure *proc, AstNode *expr, TypeAndValue *tv);
ssaLvalue ssa_build_address(ssaProcedure *proc, AstNode *expr);
ssaValue *ssa_emit_conversion(ssaProcedure *proc, ssaValue *value, Type *a_type);
@@ -318,16 +324,24 @@ ssaValue *ssa_make_instruction_load(ssaProcedure *p, ssaValue *address) {
ssaValue *v = ssa_alloc_instruction(p->module->allocator, ssaInstruction_Load);
ssaInstruction *i = &v->instruction;
i->load.address = address;
+ i->load.type = ssa_value_type(address);
if (p->curr_block) {
gb_array_append(p->curr_block->values, v);
}
return v;
}
-ssaValue *ssa_make_instruction_get_element_ptr(ssaProcedure *p, ssaValue *address) {
+ssaValue *ssa_make_instruction_get_element_ptr(ssaProcedure *p, ssaValue *address,
+ ssaValue *index0, ssaValue *index1, isize index_count,
+ b32 inbounds) {
ssaValue *v = ssa_alloc_instruction(p->module->allocator, ssaInstruction_GetElementPtr);
ssaInstruction *i = &v->instruction;
i->get_element_ptr.address = address;
+ i->get_element_ptr.indices[0] = index0;
+ i->get_element_ptr.indices[1] = index1;
+ i->get_element_ptr.index_count = index_count;
+ i->get_element_ptr.element_type = ssa_value_type(address);
+ i->get_element_ptr.inbounds = inbounds;
if (p->curr_block) {
gb_array_append(p->curr_block->values, v);
}
@@ -354,7 +368,7 @@ ssaValue *ssa_make_value_constant(gbAllocator a, Type *type, ExactValue value) {
return v;
}
-ssaValue *ssa_make_value_procedure(gbAllocator a, Entity *e, DeclarationInfo *decl, ssaModule *m) {
+ssaValue *ssa_make_value_procedure(gbAllocator a, Entity *e, DeclInfo *decl, ssaModule *m) {
ssaValue *v = ssa_alloc_value(a, ssaValue_Procedure);
v->procedure.module = m;
v->procedure.entity = e;
@@ -446,8 +460,8 @@ void ssa_end_procedure_body(ssaProcedure *proc) {
b32 ssa_is_blank_identifier(AstNode *i) {
- GB_ASSERT(i->kind == AstNode_Identifier);
- return are_strings_equal(i->identifier.token.string, make_string("_"));
+ GB_ASSERT(i->kind == AstNode_Ident);
+ return are_strings_equal(i->ident.token.string, make_string("_"));
}
@@ -485,8 +499,6 @@ ssaValue *ssa_emit_store(ssaProcedure *p, ssaValue *address, ssaValue *value) {
ssaValue *ssa_emit_load(ssaProcedure *p, ssaValue *address) {
ssaValue *v = ssa_make_instruction_load(p, address);
- Type *t = ssa_value_type(address);
- ssa_value_set_type(v, type_deref(t));
ssa_emit(p, v);
return v;
}
@@ -590,12 +602,12 @@ ssaValue *ssa_emit_compare(ssaProcedure *proc, Token op, ssaValue *left, ssaValu
return ssa_emit(proc, v);
}
-ssaValue *ssa_build_single_expression(ssaProcedure *proc, AstNode *expr, TypeAndValue *tv) {
+ssaValue *ssa_build_single_expr(ssaProcedure *proc, AstNode *expr, TypeAndValue *tv) {
switch (expr->kind) {
- case AstNode_Identifier: {
+ case AstNode_Ident: {
Entity *e = *map_get(&proc->module->info->uses, hash_pointer(expr));
if (e->kind == Entity_Builtin) {
- // TODO(bill): Entity_Builtin
+ GB_PANIC("TODO(bill): Entity_Builtin");
return NULL;
}
@@ -605,32 +617,34 @@ ssaValue *ssa_build_single_expression(ssaProcedure *proc, AstNode *expr, TypeAnd
}
} break;
- case AstNode_ParenExpression:
- return ssa_build_single_expression(proc, unparen_expression(expr), tv);
+ case AstNode_ParenExpr:
+ return ssa_build_single_expr(proc, unparen_expr(expr), tv);
- case AstNode_DereferenceExpression: {
- ssaLvalue addr = ssa_build_address(proc, expr->dereference_expression.operand);
- return ssa_lvalue_load(addr, proc);
+ case AstNode_DerefExpr: {
+ ssaLvalue addr = ssa_build_address(proc, expr);
+ ssaValue *load = ssa_lvalue_load(addr, proc);
+ ssa_value_set_type(load, type_deref(ssa_value_type(load)));
+ return load;
} break;
- case AstNode_UnaryExpression: {
- auto *ue = &expr->unary_expression;
+ case AstNode_UnaryExpr: {
+ auto *ue = &expr->unary_expr;
switch (ue->op.kind) {
case Token_Pointer:
- return ssa_lvalue_address(ssa_build_address(proc, ue->operand), proc);
+ return ssa_lvalue_address(ssa_build_address(proc, ue->expr), proc);
case Token_Add:
- return ssa_build_expression(proc, ue->operand);
+ return ssa_build_expr(proc, ue->expr);
case Token_Sub: {
- // NOTE(bill): -x == 0 - x
+ // NOTE(bill): -`x` == 0 - `x`
ExactValue zero = make_exact_value_integer(0);
ssaValue *left = ssa_make_value_constant(proc->module->allocator, tv->type, zero);
- ssaValue *right = ssa_build_expression(proc, ue->operand);
+ ssaValue *right = ssa_build_expr(proc, ue->expr);
return ssa_emit_arith(proc, ue->op, left, right, tv->type);
} break;
case Token_Xor: { // Bitwise not
- // NOTE(bill): "not" x == x "xor" -1
+ // NOTE(bill): "not" `x` == `x` "xor" `-1`
ExactValue neg_one = make_exact_value_integer(-1);
- ssaValue *left = ssa_build_expression(proc, ue->operand);
+ ssaValue *left = ssa_build_expr(proc, ue->expr);
ssaValue *right = ssa_make_value_constant(proc->module->allocator, tv->type, neg_one);
return ssa_emit_arith(proc, ue->op, left, right, tv->type);
} break;
@@ -641,8 +655,8 @@ ssaValue *ssa_build_single_expression(ssaProcedure *proc, AstNode *expr, TypeAnd
}
} break;
- case AstNode_BinaryExpression: {
- auto *be = &expr->binary_expression;
+ case AstNode_BinaryExpr: {
+ auto *be = &expr->binary_expr;
switch (be->op.kind) {
case Token_Add:
case Token_Sub:
@@ -653,17 +667,17 @@ ssaValue *ssa_build_single_expression(ssaProcedure *proc, AstNode *expr, TypeAnd
case Token_Or:
case Token_Xor:
return ssa_emit_arith(proc, be->op,
- ssa_build_expression(proc, be->left),
- ssa_build_expression(proc, be->right),
+ ssa_build_expr(proc, be->left),
+ ssa_build_expr(proc, be->right),
tv->type);
case Token_AndNot: {
- AstNode ue = {AstNode_UnaryExpression};
- ue.unary_expression.op = be->op;
- ue.unary_expression.op.kind = Token_Xor;
- ue.unary_expression.operand = be->right;
- ssaValue *left = ssa_build_expression(proc, be->left);
- ssaValue *right = ssa_build_expression(proc, &ue);
+ AstNode ue = {AstNode_UnaryExpr};
+ ue.unary_expr.op = be->op;
+ ue.unary_expr.op.kind = Token_Xor;
+ ue.unary_expr.expr = be->right;
+ ssaValue *left = ssa_build_expr(proc, be->left);
+ ssaValue *right = ssa_build_expr(proc, &ue);
Token op = be->op;
op.kind = Token_And;
return ssa_emit_arith(proc, op, left, right, tv->type);
@@ -676,8 +690,8 @@ ssaValue *ssa_build_single_expression(ssaProcedure *proc, AstNode *expr, TypeAnd
case Token_Gt:
case Token_GtEq: {
ssaValue *cmp = ssa_emit_compare(proc, be->op,
- ssa_build_expression(proc, be->left),
- ssa_build_expression(proc, be->right));
+ ssa_build_expr(proc, be->left),
+ ssa_build_expr(proc, be->right));
return ssa_emit_conversion(proc, cmp, default_type(tv->type));
} break;
@@ -685,18 +699,43 @@ ssaValue *ssa_build_single_expression(ssaProcedure *proc, AstNode *expr, TypeAnd
GB_PANIC("Invalid binary expression");
}
} break;
- case AstNode_ProcedureLiteral:
+ case AstNode_ProcLit:
break;
- case AstNode_CastExpression:
+ case AstNode_CastExpr:
break;
- case AstNode_CallExpression:
+ case AstNode_CallExpr:
break;
- case AstNode_SliceExpression:
+ case AstNode_SliceExpr:
break;
- case AstNode_IndexExpression: {
+ case AstNode_IndexExpr: {
+ auto *ie = &expr->index_expr;
+ Type *t = type_of_expr(proc->module->info, ie->expr);
+ t = get_base_type(t);
+ switch (t->kind) {
+ case Type_Basic: {
+ // TODO(bill): Strings AstNode_IndexExpression
+ } break;
+ case Type_Array: {
+ Type *t_int = &basic_types[Basic_int];
+ ssaValue *e = ssa_lvalue_address(ssa_build_address(proc, ie->expr), proc);
+ ssaValue *i0 = ssa_make_value_constant(proc->module->allocator, t_int, make_exact_value_integer(0));
+ ssaValue *i1 = ssa_emit_conversion(proc, ssa_build_expr(proc, ie->index), t_int);
+ ssaValue *gep = ssa_make_instruction_get_element_ptr(proc, e,
+ i0, i1, 2,
+ true);
+ ssa_value_set_type(gep, t->array.element);
+ return ssa_emit_load(proc, ssa_emit(proc, gep));
+ } break;
+
+ case Type_Slice:
+ break;
+
+ case Type_Pointer:
+ break;
+ }
} break;
- case AstNode_SelectorExpression:
+ case AstNode_SelectorExpr:
break;
}
@@ -705,8 +744,8 @@ ssaValue *ssa_build_single_expression(ssaProcedure *proc, AstNode *expr, TypeAnd
}
-ssaValue *ssa_build_expression(ssaProcedure *proc, AstNode *expr) {
- expr = unparen_expression(expr);
+ssaValue *ssa_build_expr(ssaProcedure *proc, AstNode *expr) {
+ expr = unparen_expr(expr);
TypeAndValue *tv = map_get(&proc->module->info->types, hash_pointer(expr));
if (tv) {
@@ -723,7 +762,7 @@ ssaValue *ssa_build_expression(ssaProcedure *proc, AstNode *expr) {
gb_printf("!Addressable!\n");
// TODO(bill): Addressing_Variable
} else {
- value = ssa_build_single_expression(proc, expr, tv);
+ value = ssa_build_single_expr(proc, expr, tv);
}
return value;
@@ -734,9 +773,9 @@ ssaValue *ssa_build_expression(ssaProcedure *proc, AstNode *expr) {
ssaLvalue ssa_build_address(ssaProcedure *proc, AstNode *expr) {
switch (expr->kind) {
- case AstNode_Identifier: {
+ case AstNode_Ident: {
if (!ssa_is_blank_identifier(expr)) {
- Entity *e = entity_of_identifier(proc->module->info, expr);
+ Entity *e = entity_of_ident(proc->module->info, expr);
ssaLvalue val = {ssaLvalue_Address};
val.address.expr = expr;
@@ -748,22 +787,65 @@ ssaLvalue ssa_build_address(ssaProcedure *proc, AstNode *expr) {
}
} break;
- case AstNode_ParenExpression:
- return ssa_build_address(proc, unparen_expression(expr));
+ case AstNode_ParenExpr:
+ return ssa_build_address(proc, unparen_expr(expr));
+
+/*
+ ssaLvalue addr = ssa_build_address(proc, expr->dereference_expr.operand);
+ ssaValue *load = ssa_lvalue_load(addr, proc);
+ ssaValue *deref = ssa_emit_load(proc, load);
+ ssa_value_set_type(deref, type_deref(ssa_value_type(deref)));
+ return deref;
+*/
+
+#if 1
+ case AstNode_DerefExpr: {
+ AstNode *operand = expr->deref_expr.expr;
+ ssaLvalue addr = ssa_build_address(proc, operand);
+ ssaValue *value = ssa_lvalue_load(addr, proc);
- case AstNode_DereferenceExpression: {
ssaLvalue val = {ssaLvalue_Address};
- AstNode *operand = expr->dereference_expression.operand;
- val.address.value = ssa_build_expression(proc, operand);
+ val.address.value = value;
val.address.expr = expr;
return val;
} break;
+#endif
- case AstNode_SelectorExpression:
+ case AstNode_SelectorExpr:
break;
- case AstNode_IndexExpression:
- break;
+ case AstNode_IndexExpr: {
+ ssaValue *v = NULL;
+ Type *element_type = NULL;
+ auto *ie = &expr->index_expr;
+ Type *t = type_of_expr(proc->module->info, expr->index_expr.expr);
+ t = get_base_type(t);
+ switch (t->kind) {
+ case Type_Array: {
+ Type *t_int = &basic_types[Basic_int];
+ ssaValue *e = ssa_lvalue_address(ssa_build_address(proc, ie->expr), proc);
+ ssaValue *i0 = ssa_make_value_constant(proc->module->allocator, t_int, make_exact_value_integer(0));
+ ssaValue *i1 = ssa_emit_conversion(proc, ssa_build_expr(proc, ie->index), t_int);
+ ssaValue *gep = ssa_make_instruction_get_element_ptr(proc, e,
+ i0, i1, 2,
+ true);
+ element_type = t->array.element;
+ v = gep;
+ } break;
+ case Type_Pointer:
+ GB_PANIC("ssa_build_address AstNode_IndexExpression Type_Slice");
+ break;
+ case Type_Slice:
+ GB_PANIC("ssa_build_address AstNode_IndexExpression Type_Slice");
+ break;
+ }
+
+ ssa_value_set_type(v, element_type);
+ ssaLvalue val = {ssaLvalue_Address};
+ val.address.value = ssa_emit(proc, v);
+ val.address.expr = expr;
+ return val;
+ } break;
// TODO(bill): Others address
}
@@ -782,19 +864,19 @@ void ssa_build_assign_op(ssaProcedure *proc, ssaLvalue lhs, ssaValue *value, Tok
}
-void ssa_build_statement(ssaProcedure *proc, AstNode *s);
+void ssa_build_stmt(ssaProcedure *proc, AstNode *s);
-void ssa_build_statement_list(ssaProcedure *proc, AstNode *list) {
+void ssa_build_stmt_list(ssaProcedure *proc, AstNode *list) {
for (AstNode *stmt = list ; stmt != NULL; stmt = stmt->next)
- ssa_build_statement(proc, stmt);
+ ssa_build_stmt(proc, stmt);
}
-void ssa_build_statement(ssaProcedure *proc, AstNode *s) {
+void ssa_build_stmt(ssaProcedure *proc, AstNode *s) {
switch (s->kind) {
- case AstNode_EmptyStatement:
+ case AstNode_EmptyStmt:
break;
- case AstNode_VariableDeclaration: {
- auto *vd = &s->variable_declaration;
+ case AstNode_VarDecl: {
+ auto *vd = &s->var_decl;
if (vd->kind == Declaration_Mutable) {
if (vd->name_count == vd->value_count) { // 1:1 assigment
gbArray(ssaLvalue) lvals;
@@ -815,7 +897,7 @@ void ssa_build_statement(ssaProcedure *proc, AstNode *s) {
}
for (AstNode *value = vd->value_list; value != NULL; value = value->next) {
- ssaValue *init = ssa_build_expression(proc, value);
+ ssaValue *init = ssa_build_expr(proc, value);
gb_array_append(inits, init);
}
@@ -837,22 +919,22 @@ void ssa_build_statement(ssaProcedure *proc, AstNode *s) {
}
} break;
- case AstNode_IncDecStatement: {
- Token op = s->inc_dec_statement.op;
+ case AstNode_IncDecStmt: {
+ Token op = s->inc_dec_stmt.op;
if (op.kind == Token_Increment) {
op.kind = Token_Add;
} else if (op.kind == Token_Decrement) {
op.kind = Token_Sub;
}
- ssaLvalue lval = ssa_build_address(proc, s->inc_dec_statement.expression);
+ ssaLvalue lval = ssa_build_address(proc, s->inc_dec_stmt.expr);
ssaValue *one = ssa_make_value_constant(proc->module->allocator, ssa_lvalue_type(lval),
make_exact_value_integer(1));
ssa_build_assign_op(proc, lval, one, op);
} break;
- case AstNode_AssignStatement: {
- auto *assign = &s->assign_statement;
+ case AstNode_AssignStmt: {
+ auto *assign = &s->assign_stmt;
switch (assign->op.kind) {
case Token_Eq: {
gbArray(ssaLvalue) lvals;
@@ -873,7 +955,7 @@ void ssa_build_statement(ssaProcedure *proc, AstNode *s) {
if (assign->lhs_count == 1) {
AstNode *lhs = assign->lhs_list;
AstNode *rhs = assign->rhs_list;
- ssaValue *init = ssa_build_expression(proc, rhs);
+ ssaValue *init = ssa_build_expr(proc, rhs);
ssa_lvalue_store(lvals[0], proc, init);
} else {
gbArray(ssaValue *) inits;
@@ -881,7 +963,7 @@ void ssa_build_statement(ssaProcedure *proc, AstNode *s) {
defer (gb_array_free(inits));
for (AstNode *rhs = assign->rhs_list; rhs != NULL; rhs = rhs->next) {
- ssaValue *init = ssa_build_expression(proc, rhs);
+ ssaValue *init = ssa_build_expr(proc, rhs);
gb_array_append(inits, init);
}
@@ -903,33 +985,33 @@ void ssa_build_statement(ssaProcedure *proc, AstNode *s) {
kind += Token_Add - Token_AddEq; // Convert += to +
op.kind = cast(TokenKind)kind;
ssaLvalue lhs = ssa_build_address(proc, assign->lhs_list);
- ssaValue *value = ssa_build_expression(proc, assign->rhs_list);
+ ssaValue *value = ssa_build_expr(proc, assign->rhs_list);
ssa_build_assign_op(proc, lhs, value, op);
} break;
}
} break;
- case AstNode_ExpressionStatement:
- ssa_build_expression(proc, s->expression_statement.expression);
+ case AstNode_ExprStmt:
+ ssa_build_expr(proc, s->expr_stmt.expr);
break;
- case AstNode_BlockStatement:
- ssa_build_statement_list(proc, s->block_statement.list);
+ case AstNode_BlockStmt:
+ ssa_build_stmt_list(proc, s->block_stmt.list);
break;
- case AstNode_IfStatement:
+ case AstNode_IfStmt:
GB_PANIC("AstNode_IfStatement");
break;
- case AstNode_ReturnStatement:
+ case AstNode_ReturnStmt:
GB_PANIC("AstNode_ReturnStatement");
break;
- case AstNode_ForStatement:
+ case AstNode_ForStmt:
GB_PANIC("AstNode_ForStatement");
break;
- case AstNode_DeferStatement:
+ case AstNode_DeferStmt:
GB_PANIC("AstNode_DeferStatement");
break;
- case AstNode_BranchStatement:
+ case AstNode_BranchStmt:
GB_PANIC("AstNode_BranchStatement");
break;
}
@@ -945,9 +1027,9 @@ void ssa_build_procedure(ssaValue *value) {
AstNode *proc_decl = proc->decl->proc_decl;
switch (proc_decl->kind) {
- case AstNode_ProcedureDeclaration:
- proc->type_expr = proc_decl->procedure_declaration.type;
- proc->body = proc_decl->procedure_declaration.body;
+ case AstNode_ProcDecl:
+ proc->type_expr = proc_decl->proc_decl.type;
+ proc->body = proc_decl->proc_decl.body;
break;
default:
return;
@@ -960,7 +1042,7 @@ void ssa_build_procedure(ssaValue *value) {
ssa_begin_procedure_body(proc);
- ssa_build_statement(proc, proc->body);
+ ssa_build_stmt(proc, proc->body);
ssa_end_procedure_body(proc);
}
diff --git a/src/parser.cpp b/src/parser.cpp
index a595035d3..33e2c0abc 100644
--- a/src/parser.cpp
+++ b/src/parser.cpp
@@ -26,10 +26,10 @@ struct AstFile {
// >= 0: In Expression
// < 0: In Control Clause
// NOTE(bill): Used to prevent type literals in control clauses
- isize expression_level;
+ isize expr_level;
- AstNode *declarations;
- isize declaration_count;
+ AstNode *decls;
+ isize decl_count;
AstScope *file_scope;
AstScope *curr_scope;
@@ -50,7 +50,7 @@ struct AstFile {
struct AstEntity {
Token token;
AstScope *parent;
- AstNode * declaration;
+ AstNode * decl;
};
struct AstScope {
@@ -64,69 +64,80 @@ struct Parser {
isize import_index;
};
+#define AST_NODE_KINDS \
+ AST_NODE_KIND(Invalid), \
+\
+ AST_NODE_KIND(BasicLit), \
+ AST_NODE_KIND(Ident), \
+ AST_NODE_KIND(ProcLit), \
+ AST_NODE_KIND(CompoundLit), \
+\
+AST_NODE_KIND(_ExprBegin), \
+ AST_NODE_KIND(BadExpr), \
+ AST_NODE_KIND(TagExpr), \
+ AST_NODE_KIND(UnaryExpr), \
+ AST_NODE_KIND(BinaryExpr), \
+ AST_NODE_KIND(ParenExpr), \
+ AST_NODE_KIND(CallExpr), \
+ AST_NODE_KIND(SelectorExpr), \
+ AST_NODE_KIND(IndexExpr), \
+ AST_NODE_KIND(SliceExpr), \
+ AST_NODE_KIND(CastExpr), \
+ AST_NODE_KIND(DerefExpr), \
+AST_NODE_KIND(_ExprEnd), \
+\
+AST_NODE_KIND(_stmtBegin), \
+ AST_NODE_KIND(BadStmt), \
+ AST_NODE_KIND(EmptyStmt), \
+ AST_NODE_KIND(TagStmt), \
+ AST_NODE_KIND(ExprStmt), \
+ AST_NODE_KIND(IncDecStmt), \
+ AST_NODE_KIND(AssignStmt), \
+\
+AST_NODE_KIND(_ComplexStmtBegin), \
+ AST_NODE_KIND(BlockStmt), \
+ AST_NODE_KIND(IfStmt), \
+ AST_NODE_KIND(ReturnStmt), \
+ AST_NODE_KIND(ForStmt), \
+ AST_NODE_KIND(DeferStmt), \
+ AST_NODE_KIND(BranchStmt), \
+\
+AST_NODE_KIND(_ComplexStmtEnd), \
+\
+AST_NODE_KIND(_stmtEnd), \
+\
+AST_NODE_KIND(_DeclBegin), \
+ AST_NODE_KIND(BadDecl), \
+ AST_NODE_KIND(VarDecl), \
+ AST_NODE_KIND(ProcDecl), \
+ AST_NODE_KIND(TypeDecl), \
+ AST_NODE_KIND(AliasDecl), \
+ AST_NODE_KIND(ImportDecl), \
+AST_NODE_KIND(_DeclEnd), \
+\
+AST_NODE_KIND(_TypeBegin), \
+ AST_NODE_KIND(Field), \
+ AST_NODE_KIND(ProcType), \
+ AST_NODE_KIND(PointerType), \
+ AST_NODE_KIND(ArrayType), \
+ AST_NODE_KIND(StructType), \
+AST_NODE_KIND(_TypeEnd), \
+\
+ AST_NODE_KIND(Count),
+
enum AstNodeKind {
- AstNode_Invalid,
-
- AstNode_BasicLiteral,
- AstNode_Identifier,
- AstNode_ProcedureLiteral,
- AstNode_CompoundLiteral,
-
-AstNode__ExpressionBegin,
- AstNode_BadExpression, // NOTE(bill): Naughty expression
- AstNode_TagExpression,
- AstNode_UnaryExpression,
- AstNode_BinaryExpression,
- AstNode_ParenExpression,
- AstNode_CallExpression,
- AstNode_SelectorExpression,
- AstNode_IndexExpression,
- AstNode_SliceExpression,
- AstNode_CastExpression,
- AstNode_DereferenceExpression,
-AstNode__ExpressionEnd,
-
-AstNode__StatementBegin,
- AstNode_BadStatement, // NOTE(bill): Naughty statement
- AstNode_EmptyStatement,
- AstNode_TagStatement,
- AstNode_ExpressionStatement,
- AstNode_IncDecStatement,
- AstNode_AssignStatement,
-
-AstNode__ComplexStatementBegin,
- AstNode_BlockStatement,
- AstNode_IfStatement,
- AstNode_ReturnStatement,
- AstNode_ForStatement,
- AstNode_DeferStatement,
- AstNode_BranchStatement,
-
-AstNode__ComplexStatementEnd,
-
-AstNode__StatementEnd,
-
-AstNode__DeclarationBegin,
- AstNode_BadDeclaration, // NOTE(bill): Naughty declaration
- AstNode_VariableDeclaration,
- AstNode_ProcedureDeclaration,
- AstNode_TypeDeclaration,
- AstNode_AliasDeclaration,
- AstNode_ImportDeclaration,
-AstNode__DeclarationEnd,
-
-AstNode__TypeBegin,
- AstNode_Field,
- AstNode_ProcedureType,
- AstNode_PointerType,
- AstNode_ArrayType,
- AstNode_StructType,
-AstNode__TypeEnd,
-
- AstNode_Count,
+#define AST_NODE_KIND(x) GB_JOIN2(AstNode_, x)
+ AST_NODE_KINDS
+#undef AST_NODE_KIND
+};
+
+String const ast_node_strings[] = {
+#define AST_NODE_KIND(x) {cast(u8 *)#x, gb_size_of(#x)-1}
+ AST_NODE_KINDS
+#undef AST_NODE_KIND
};
-enum DeclarationKind {
+enum DeclKind {
Declaration_Invalid,
Declaration_Mutable,
@@ -139,143 +150,142 @@ enum DeclarationKind {
struct AstNode {
AstNodeKind kind;
AstNode *prev, *next; // NOTE(bill): allow for Linked list
- Type *type;
union {
// NOTE(bill): open/close for debugging/errors
- Token basic_literal;
+ Token basic_lit;
struct {
Token token;
AstEntity *entity;
- } identifier;
+ } ident;
struct {
- AstNode *type; // AstNode_ProcedureType
- AstNode *body; // AstNode_BlockStatement
- } procedure_literal;
+ AstNode *type; // AstNode_ProcType
+ AstNode *body; // AstNode_BlockStmt
+ } proc_lit;
struct {
- AstNode *type_expression;
- AstNode *element_list;
- isize element_count;
+ AstNode *type;
+ AstNode *elem_list;
+ isize elem_count;
Token open, close;
- } compound_literal;
+ } compound_lit;
struct {
Token token;
Token name;
- AstNode *expression;
- } tag_expression;
-
- struct { Token begin, end; } bad_expression;
- struct { Token op; AstNode *operand; } unary_expression;
- struct { Token op; AstNode *left, *right; } binary_expression;
- struct { AstNode *expression; Token open, close; } paren_expression;
- struct { Token token; AstNode *operand, *selector; } selector_expression;
- struct { AstNode *expression, *value; Token open, close; } index_expression;
- struct { Token token; AstNode *type_expression, *operand; } cast_expression;
+ AstNode *expr;
+ } tag_expr;
+
+ struct { Token begin, end; } bad_expr;
+ struct { Token op; AstNode *expr; } unary_expr;
+ struct { Token op; AstNode *left, *right; } binary_expr;
+ struct { AstNode *expr; Token open, close; } paren_expr;
+ struct { Token token; AstNode *expr, *selector; } selector_expr;
+ struct { AstNode *expr, *index; Token open, close; } index_expr;
+ struct { Token token; AstNode *type, *expr; } cast_expr;
struct {
AstNode *proc, *arg_list;
isize arg_list_count;
Token open, close;
- } call_expression;
- struct { Token op; AstNode *operand; } dereference_expression;
+ } call_expr;
+ struct { Token op; AstNode *expr; } deref_expr;
struct {
- AstNode *expression;
+ AstNode *expr;
Token open, close;
AstNode *low, *high, *max;
b32 triple_indexed; // [(1st):2nd:3rd]
- } slice_expression;
+ } slice_expr;
- struct { Token begin, end; } bad_statement;
- struct { Token token; } empty_statement;
- struct { AstNode *expression; } expression_statement;
- struct { Token op; AstNode *expression; } inc_dec_statement;
+ struct { Token begin, end; } bad_stmt;
+ struct { Token token; } empty_stmt;
+ struct { AstNode *expr; } expr_stmt;
+ struct { Token op; AstNode *expr; } inc_dec_stmt;
struct {
Token token;
Token name;
- AstNode *statement;
- } tag_statement;
+ AstNode *stmt;
+ } tag_stmt;
struct {
Token op;
AstNode *lhs_list, *rhs_list;
isize lhs_count, rhs_count;
- } assign_statement;
+ } assign_stmt;
struct {
AstNode *list;
isize list_count;
Token open, close;
- } block_statement;
+ } block_stmt;
struct {
Token token;
AstNode *init;
AstNode *cond;
AstNode *body;
- AstNode *else_statement;
- } if_statement;
+ AstNode *else_stmt;
+ } if_stmt;
struct {
Token token;
- AstNode *results; // NOTE(bill): Return values
+ AstNode *result_list;
isize result_count;
- } return_statement;
+ } return_stmt;
struct {
Token token;
AstNode *init, *cond, *end;
AstNode *body;
- } for_statement;
+ } for_stmt;
struct {
Token token;
- AstNode *statement;
- } defer_statement;
+ AstNode *stmt;
+ } defer_stmt;
struct {
Token token;
- } branch_statement;
+ } branch_stmt;
- struct { Token begin, end; } bad_declaration;
+ struct { Token begin, end; } bad_decl;
struct {
- DeclarationKind kind;
+ DeclKind kind;
AstNode *name_list;
- AstNode *type_expression;
+ AstNode *type;
AstNode *value_list;
isize name_count, value_count;
- } variable_declaration;
+ } var_decl;
struct {
AstNode *name_list;
isize name_count;
- AstNode *type_expression;
+ AstNode *type;
} field;
// TODO(bill): Unify Procedure Declarations and Literals
struct {
- DeclarationKind kind;
- AstNode *name; // AstNode_Identifier
- AstNode *type; // AstNode_ProcedureType
- AstNode *body; // AstNode_BlockStatement
- AstNode *tag_list; // AstNode_TagExpression
+ DeclKind kind;
+ AstNode *name; // AstNode_Ident
+ AstNode *type; // AstNode_ProcType
+ AstNode *body; // AstNode_BlockStmt
+ AstNode *tag_list; // AstNode_TagExpr
isize tag_count;
- } procedure_declaration;
+ } proc_decl;
struct {
Token token;
- AstNode *name; // AstNode_Identifier
- AstNode *type_expression;
- } type_declaration;
+ AstNode *name; // AstNode_Ident
+ AstNode *type;
+ } type_decl;
struct {
Token token;
- AstNode *name; // AstNode_Identifier
- AstNode *type_expression;
- } alias_declaration;
+ AstNode *name; // AstNode_Ident
+ AstNode *type;
+ } alias_decl;
struct {
Token token;
Token filepath;
- } import_declaration;
+ } import_decl;
struct {
Token token;
- AstNode *type_expression;
+ AstNode *type;
} pointer_type;
struct {
Token token;
AstNode *count; // NOTE(bill): Zero/NULL is probably a slice
- AstNode *element;
+ AstNode *elem;
} array_type;
struct {
Token token;
@@ -285,10 +295,10 @@ struct AstNode {
struct {
Token token;
AstNode *param_list; // AstNode_Field list
- isize param_count;
AstNode *result_list; // type expression list
+ isize param_count;
isize result_count;
- } procedure_type;
+ } proc_type;
};
};
@@ -300,17 +310,17 @@ gb_inline AstScope *make_ast_scope(AstFile *f, AstScope *parent) {
}
-gb_inline b32 is_ast_node_expression(AstNode *node) {
- return gb_is_between(node->kind, AstNode__ExpressionBegin+1, AstNode__ExpressionEnd-1);
+gb_inline b32 is_ast_node_expr(AstNode *node) {
+ return gb_is_between(node->kind, AstNode__ExprBegin+1, AstNode__ExprEnd-1);
}
-gb_inline b32 is_ast_node_statement(AstNode *node) {
- return gb_is_between(node->kind, AstNode__StatementBegin+1, AstNode__StatementEnd-1);
+gb_inline b32 is_ast_node_stmt(AstNode *node) {
+ return gb_is_between(node->kind, AstNode__stmtBegin+1, AstNode__stmtEnd-1);
}
-gb_inline b32 is_ast_node_complex_statement(AstNode *node) {
- return gb_is_between(node->kind, AstNode__ComplexStatementBegin+1, AstNode__ComplexStatementEnd-1);
+gb_inline b32 is_ast_node_complex_stmt(AstNode *node) {
+ return gb_is_between(node->kind, AstNode__ComplexStmtBegin+1, AstNode__ComplexStmtEnd-1);
}
-gb_inline b32 is_ast_node_declaration(AstNode *node) {
- return gb_is_between(node->kind, AstNode__DeclarationBegin+1, AstNode__DeclarationEnd-1);
+gb_inline b32 is_ast_node_decl(AstNode *node) {
+ return gb_is_between(node->kind, AstNode__DeclBegin+1, AstNode__DeclEnd-1);
}
gb_inline b32 is_ast_node_type(AstNode *node) {
return gb_is_between(node->kind, AstNode__TypeBegin+1, AstNode__TypeEnd-1);
@@ -319,80 +329,80 @@ gb_inline b32 is_ast_node_type(AstNode *node) {
Token ast_node_token(AstNode *node) {
switch (node->kind) {
- case AstNode_BasicLiteral:
- return node->basic_literal;
- case AstNode_Identifier:
- return node->identifier.token;
- case AstNode_ProcedureLiteral:
- return ast_node_token(node->procedure_literal.type);
- case AstNode_CompoundLiteral:
- return ast_node_token(node->compound_literal.type_expression);
- case AstNode_TagExpression:
- return node->tag_expression.token;
- case AstNode_BadExpression:
- return node->bad_expression.begin;
- case AstNode_UnaryExpression:
- return node->unary_expression.op;
- case AstNode_BinaryExpression:
- return ast_node_token(node->binary_expression.left);
- case AstNode_ParenExpression:
- return node->paren_expression.open;
- case AstNode_CallExpression:
- return ast_node_token(node->call_expression.proc);
- case AstNode_SelectorExpression:
- return ast_node_token(node->selector_expression.selector);
- case AstNode_IndexExpression:
- return node->index_expression.open;
- case AstNode_SliceExpression:
- return node->slice_expression.open;
- case AstNode_CastExpression:
- return node->cast_expression.token;
- case AstNode_DereferenceExpression:
- return node->dereference_expression.op;
- case AstNode_BadStatement:
- return node->bad_statement.begin;
- case AstNode_EmptyStatement:
- return node->empty_statement.token;
- case AstNode_ExpressionStatement:
- return ast_node_token(node->expression_statement.expression);
- case AstNode_TagStatement:
- return node->tag_statement.token;
- case AstNode_IncDecStatement:
- return node->inc_dec_statement.op;
- case AstNode_AssignStatement:
- return node->assign_statement.op;
- case AstNode_BlockStatement:
- return node->block_statement.open;
- case AstNode_IfStatement:
- return node->if_statement.token;
- case AstNode_ReturnStatement:
- return node->return_statement.token;
- case AstNode_ForStatement:
- return node->for_statement.token;
- case AstNode_DeferStatement:
- return node->defer_statement.token;
- case AstNode_BranchStatement:
- return node->branch_statement.token;
- case AstNode_BadDeclaration:
- return node->bad_declaration.begin;
- case AstNode_VariableDeclaration:
- return ast_node_token(node->variable_declaration.name_list);
- case AstNode_ProcedureDeclaration:
- return node->procedure_declaration.name->identifier.token;
- case AstNode_TypeDeclaration:
- return node->type_declaration.token;
- case AstNode_AliasDeclaration:
- return node->alias_declaration.token;
- case AstNode_ImportDeclaration:
- return node->import_declaration.token;
+ case AstNode_BasicLit:
+ return node->basic_lit;
+ case AstNode_Ident:
+ return node->ident.token;
+ case AstNode_ProcLit:
+ return ast_node_token(node->proc_lit.type);
+ case AstNode_CompoundLit:
+ return ast_node_token(node->compound_lit.type);
+ case AstNode_TagExpr:
+ return node->tag_expr.token;
+ case AstNode_BadExpr:
+ return node->bad_expr.begin;
+ case AstNode_UnaryExpr:
+ return node->unary_expr.op;
+ case AstNode_BinaryExpr:
+ return ast_node_token(node->binary_expr.left);
+ case AstNode_ParenExpr:
+ return node->paren_expr.open;
+ case AstNode_CallExpr:
+ return ast_node_token(node->call_expr.proc);
+ case AstNode_SelectorExpr:
+ return ast_node_token(node->selector_expr.selector);
+ case AstNode_IndexExpr:
+ return node->index_expr.open;
+ case AstNode_SliceExpr:
+ return node->slice_expr.open;
+ case AstNode_CastExpr:
+ return node->cast_expr.token;
+ case AstNode_DerefExpr:
+ return node->deref_expr.op;
+ case AstNode_BadStmt:
+ return node->bad_stmt.begin;
+ case AstNode_EmptyStmt:
+ return node->empty_stmt.token;
+ case AstNode_ExprStmt:
+ return ast_node_token(node->expr_stmt.expr);
+ case AstNode_TagStmt:
+ return node->tag_stmt.token;
+ case AstNode_IncDecStmt:
+ return node->inc_dec_stmt.op;
+ case AstNode_AssignStmt:
+ return node->assign_stmt.op;
+ case AstNode_BlockStmt:
+ return node->block_stmt.open;
+ case AstNode_IfStmt:
+ return node->if_stmt.token;
+ case AstNode_ReturnStmt:
+ return node->return_stmt.token;
+ case AstNode_ForStmt:
+ return node->for_stmt.token;
+ case AstNode_DeferStmt:
+ return node->defer_stmt.token;
+ case AstNode_BranchStmt:
+ return node->branch_stmt.token;
+ case AstNode_BadDecl:
+ return node->bad_decl.begin;
+ case AstNode_VarDecl:
+ return ast_node_token(node->var_decl.name_list);
+ case AstNode_ProcDecl:
+ return node->proc_decl.name->ident.token;
+ case AstNode_TypeDecl:
+ return node->type_decl.token;
+ case AstNode_AliasDecl:
+ return node->alias_decl.token;
+ case AstNode_ImportDecl:
+ return node->import_decl.token;
case AstNode_Field: {
if (node->field.name_list)
return ast_node_token(node->field.name_list);
else
- return ast_node_token(node->field.type_expression);
+ return ast_node_token(node->field.type);
}
- case AstNode_ProcedureType:
- return node->procedure_type.token;
+ case AstNode_ProcType:
+ return node->proc_type.token;
case AstNode_PointerType:
return node->pointer_type.token;
case AstNode_ArrayType:
@@ -430,10 +440,10 @@ gb_inline void close_ast_scope(AstFile *f) {
}
}
-AstEntity *make_ast_entity(AstFile *f, Token token, AstNode *declaration, AstScope *parent) {
+AstEntity *make_ast_entity(AstFile *f, Token token, AstNode *decl, AstScope *parent) {
AstEntity *entity = gb_alloc_item(gb_arena_allocator(&f->arena), AstEntity);
entity->token = token;
- entity->declaration = declaration;
+ entity->decl = decl;
entity->parent = parent;
return entity;
}
@@ -488,296 +498,296 @@ gb_inline AstNode *make_node(AstFile *f, AstNodeKind kind) {
return node;
}
-gb_inline AstNode *make_bad_expression(AstFile *f, Token begin, Token end) {
- AstNode *result = make_node(f, AstNode_BadExpression);
- result->bad_expression.begin = begin;
- result->bad_expression.end = end;
+gb_inline AstNode *make_bad_expr(AstFile *f, Token begin, Token end) {
+ AstNode *result = make_node(f, AstNode_BadExpr);
+ result->bad_expr.begin = begin;
+ result->bad_expr.end = end;
return result;
}
-gb_inline AstNode *make_tag_expression(AstFile *f, Token token, Token name, AstNode *expression) {
- AstNode *result = make_node(f, AstNode_TagExpression);
- result->tag_expression.token = token;
- result->tag_expression.name = name;
- result->tag_expression.expression = expression;
+gb_inline AstNode *make_tag_expr(AstFile *f, Token token, Token name, AstNode *expr) {
+ AstNode *result = make_node(f, AstNode_TagExpr);
+ result->tag_expr.token = token;
+ result->tag_expr.name = name;
+ result->tag_expr.expr = expr;
return result;
}
-gb_inline AstNode *make_tag_statement(AstFile *f, Token token, Token name, AstNode *statement) {
- AstNode *result = make_node(f, AstNode_TagStatement);
- result->tag_statement.token = token;
- result->tag_statement.name = name;
- result->tag_statement.statement = statement;
+gb_inline AstNode *make_tag_stmt(AstFile *f, Token token, Token name, AstNode *stmt) {
+ AstNode *result = make_node(f, AstNode_TagStmt);
+ result->tag_stmt.token = token;
+ result->tag_stmt.name = name;
+ result->tag_stmt.stmt = stmt;
return result;
}
-gb_inline AstNode *make_unary_expression(AstFile *f, Token op, AstNode *operand) {
- AstNode *result = make_node(f, AstNode_UnaryExpression);
- result->unary_expression.op = op;
- result->unary_expression.operand = operand;
+gb_inline AstNode *make_unary_expr(AstFile *f, Token op, AstNode *expr) {
+ AstNode *result = make_node(f, AstNode_UnaryExpr);
+ result->unary_expr.op = op;
+ result->unary_expr.expr = expr;
return result;
}
-gb_inline AstNode *make_binary_expression(AstFile *f, Token op, AstNode *left, AstNode *right) {
- AstNode *result = make_node(f, AstNode_BinaryExpression);
+gb_inline AstNode *make_binary_expr(AstFile *f, Token op, AstNode *left, AstNode *right) {
+ AstNode *result = make_node(f, AstNode_BinaryExpr);
if (left == NULL) {
ast_file_err(f, op, "No lhs expression for binary expression `%.*s`", LIT(op.string));
- left = make_bad_expression(f, op, op);
+ left = make_bad_expr(f, op, op);
}
if (right == NULL) {
ast_file_err(f, op, "No rhs expression for binary expression `%.*s`", LIT(op.string));
- right = make_bad_expression(f, op, op);
+ right = make_bad_expr(f, op, op);
}
- result->binary_expression.op = op;
- result->binary_expression.left = left;
- result->binary_expression.right = right;
+ result->binary_expr.op = op;
+ result->binary_expr.left = left;
+ result->binary_expr.right = right;
return result;
}
-gb_inline AstNode *make_paren_expression(AstFile *f, AstNode *expression, Token open, Token close) {
- AstNode *result = make_node(f, AstNode_ParenExpression);
- result->paren_expression.expression = expression;
- result->paren_expression.open = open;
- result->paren_expression.close = close;
+gb_inline AstNode *make_paren_expr(AstFile *f, AstNode *expr, Token open, Token close) {
+ AstNode *result = make_node(f, AstNode_ParenExpr);
+ result->paren_expr.expr = expr;
+ result->paren_expr.open = open;
+ result->paren_expr.close = close;
return result;
}
-gb_inline AstNode *make_call_expression(AstFile *f, AstNode *proc, AstNode *arg_list, isize arg_list_count, Token open, Token close) {
- AstNode *result = make_node(f, AstNode_CallExpression);
- result->call_expression.proc = proc;
- result->call_expression.arg_list = arg_list;
- result->call_expression.arg_list_count = arg_list_count;
- result->call_expression.open = open;
- result->call_expression.close = close;
+gb_inline AstNode *make_call_expr(AstFile *f, AstNode *proc, AstNode *arg_list, isize arg_list_count, Token open, Token close) {
+ AstNode *result = make_node(f, AstNode_CallExpr);
+ result->call_expr.proc = proc;
+ result->call_expr.arg_list = arg_list;
+ result->call_expr.arg_list_count = arg_list_count;
+ result->call_expr.open = open;
+ result->call_expr.close = close;
return result;
}
-gb_inline AstNode *make_selector_expression(AstFile *f, Token token, AstNode *operand, AstNode *selector) {
- AstNode *result = make_node(f, AstNode_SelectorExpression);
- result->selector_expression.operand = operand;
- result->selector_expression.selector = selector;
+gb_inline AstNode *make_selector_expr(AstFile *f, Token token, AstNode *expr, AstNode *selector) {
+ AstNode *result = make_node(f, AstNode_SelectorExpr);
+ result->selector_expr.expr = expr;
+ result->selector_expr.selector = selector;
return result;
}
-gb_inline AstNode *make_index_expression(AstFile *f, AstNode *expression, AstNode *value, Token open, Token close) {
- AstNode *result = make_node(f, AstNode_IndexExpression);
- result->index_expression.expression = expression;
- result->index_expression.value = value;
- result->index_expression.open = open;
- result->index_expression.close = close;
+gb_inline AstNode *make_index_expr(AstFile *f, AstNode *expr, AstNode *index, Token open, Token close) {
+ AstNode *result = make_node(f, AstNode_IndexExpr);
+ result->index_expr.expr = expr;
+ result->index_expr.index = index;
+ result->index_expr.open = open;
+ result->index_expr.close = close;
return result;
}
-gb_inline AstNode *make_slice_expression(AstFile *f, AstNode *expression, Token open, Token close, AstNode *low, AstNode *high, AstNode *max, b32 triple_indexed) {
- AstNode *result = make_node(f, AstNode_SliceExpression);
- result->slice_expression.expression = expression;
- result->slice_expression.open = open;
- result->slice_expression.close = close;
- result->slice_expression.low = low;
- result->slice_expression.high = high;
- result->slice_expression.max = max;
- result->slice_expression.triple_indexed = triple_indexed;
+gb_inline AstNode *make_slice_expr(AstFile *f, AstNode *expr, Token open, Token close, AstNode *low, AstNode *high, AstNode *max, b32 triple_indexed) {
+ AstNode *result = make_node(f, AstNode_SliceExpr);
+ result->slice_expr.expr = expr;
+ result->slice_expr.open = open;
+ result->slice_expr.close = close;
+ result->slice_expr.low = low;
+ result->slice_expr.high = high;
+ result->slice_expr.max = max;
+ result->slice_expr.triple_indexed = triple_indexed;
return result;
}
-gb_inline AstNode *make_cast_expression(AstFile *f, Token token, AstNode *type_expression, AstNode *operand) {
- AstNode *result = make_node(f, AstNode_CastExpression);
- result->cast_expression.token = token;
- result->cast_expression.type_expression = type_expression;
- result->cast_expression.operand = operand;
+gb_inline AstNode *make_cast_expr(AstFile *f, Token token, AstNode *type, AstNode *expr) {
+ AstNode *result = make_node(f, AstNode_CastExpr);
+ result->cast_expr.token = token;
+ result->cast_expr.type = type;
+ result->cast_expr.expr = expr;
return result;
}
-gb_inline AstNode *make_dereference_expression(AstFile *f, AstNode *operand, Token op) {
- AstNode *result = make_node(f, AstNode_DereferenceExpression);
- result->dereference_expression.operand = operand;
- result->dereference_expression.op = op;
+gb_inline AstNode *make_deref_expr(AstFile *f, AstNode *expr, Token op) {
+ AstNode *result = make_node(f, AstNode_DerefExpr);
+ result->deref_expr.expr = expr;
+ result->deref_expr.op = op;
return result;
}
-gb_inline AstNode *make_basic_literal(AstFile *f, Token basic_literal) {
- AstNode *result = make_node(f, AstNode_BasicLiteral);
- result->basic_literal = basic_literal;
+gb_inline AstNode *make_basic_lit(AstFile *f, Token basic_lit) {
+ AstNode *result = make_node(f, AstNode_BasicLit);
+ result->basic_lit = basic_lit;
return result;
}
gb_inline AstNode *make_identifier(AstFile *f, Token token, AstEntity *entity = NULL) {
- AstNode *result = make_node(f, AstNode_Identifier);
- result->identifier.token = token;
- result->identifier.entity = entity;
+ AstNode *result = make_node(f, AstNode_Ident);
+ result->ident.token = token;
+ result->ident.entity = entity;
return result;
}
gb_inline AstNode *make_procedure_literal(AstFile *f, AstNode *type, AstNode *body) {
- AstNode *result = make_node(f, AstNode_ProcedureLiteral);
- result->procedure_literal.type = type;
- result->procedure_literal.body = body;
+ AstNode *result = make_node(f, AstNode_ProcLit);
+ result->proc_lit.type = type;
+ result->proc_lit.body = body;
return result;
}
-gb_inline AstNode *make_compound_literal(AstFile *f, AstNode *type_expression, AstNode *element_list, isize element_count,
+gb_inline AstNode *make_compound_literal(AstFile *f, AstNode *type, AstNode *elem_list, isize elem_count,
Token open, Token close) {
- AstNode *result = make_node(f, AstNode_CompoundLiteral);
- result->compound_literal.type_expression = type_expression;
- result->compound_literal.element_list = element_list;
- result->compound_literal.element_count = element_count;
- result->compound_literal.open = open;
- result->compound_literal.close = close;
+ AstNode *result = make_node(f, AstNode_CompoundLit);
+ result->compound_lit.type = type;
+ result->compound_lit.elem_list = elem_list;
+ result->compound_lit.elem_count = elem_count;
+ result->compound_lit.open = open;
+ result->compound_lit.close = close;
return result;
}
-gb_inline AstNode *make_bad_statement(AstFile *f, Token begin, Token end) {
- AstNode *result = make_node(f, AstNode_BadStatement);
- result->bad_statement.begin = begin;
- result->bad_statement.end = end;
+gb_inline AstNode *make_bad_stmt(AstFile *f, Token begin, Token end) {
+ AstNode *result = make_node(f, AstNode_BadStmt);
+ result->bad_stmt.begin = begin;
+ result->bad_stmt.end = end;
return result;
}
-gb_inline AstNode *make_empty_statement(AstFile *f, Token token) {
- AstNode *result = make_node(f, AstNode_EmptyStatement);
- result->empty_statement.token = token;
+gb_inline AstNode *make_empty_stmt(AstFile *f, Token token) {
+ AstNode *result = make_node(f, AstNode_EmptyStmt);
+ result->empty_stmt.token = token;
return result;
}
-gb_inline AstNode *make_expression_statement(AstFile *f, AstNode *expression) {
- AstNode *result = make_node(f, AstNode_ExpressionStatement);
- result->expression_statement.expression = expression;
+gb_inline AstNode *make_expr_stmt(AstFile *f, AstNode *expr) {
+ AstNode *result = make_node(f, AstNode_ExprStmt);
+ result->expr_stmt.expr = expr;
return result;
}
-gb_inline AstNode *make_inc_dec_statement(AstFile *f, Token op, AstNode *expression) {
- AstNode *result = make_node(f, AstNode_IncDecStatement);
- result->inc_dec_statement.op = op;
- result->inc_dec_statement.expression = expression;
+gb_inline AstNode *make_inc_dec_stmt(AstFile *f, Token op, AstNode *expr) {
+ AstNode *result = make_node(f, AstNode_IncDecStmt);
+ result->inc_dec_stmt.op = op;
+ result->inc_dec_stmt.expr = expr;
return result;
}
-gb_inline AstNode *make_assign_statement(AstFile *f, Token op, AstNode *lhs_list, isize lhs_count, AstNode *rhs_list, isize rhs_count) {
- AstNode *result = make_node(f, AstNode_AssignStatement);
- result->assign_statement.op = op;
- result->assign_statement.lhs_list = lhs_list;
- result->assign_statement.lhs_count = lhs_count;
- result->assign_statement.rhs_list = rhs_list;
- result->assign_statement.rhs_count = rhs_count;
+gb_inline AstNode *make_assign_stmt(AstFile *f, Token op, AstNode *lhs_list, isize lhs_count, AstNode *rhs_list, isize rhs_count) {
+ AstNode *result = make_node(f, AstNode_AssignStmt);
+ result->assign_stmt.op = op;
+ result->assign_stmt.lhs_list = lhs_list;
+ result->assign_stmt.lhs_count = lhs_count;
+ result->assign_stmt.rhs_list = rhs_list;
+ result->assign_stmt.rhs_count = rhs_count;
return result;
}
-gb_inline AstNode *make_block_statement(AstFile *f, AstNode *list, isize list_count, Token open, Token close) {
- AstNode *result = make_node(f, AstNode_BlockStatement);
- result->block_statement.list = list;
- result->block_statement.list_count = list_count;
- result->block_statement.open = open;
- result->block_statement.close = close;
+gb_inline AstNode *make_block_stmt(AstFile *f, AstNode *list, isize list_count, Token open, Token close) {
+ AstNode *result = make_node(f, AstNode_BlockStmt);
+ result->block_stmt.list = list;
+ result->block_stmt.list_count = list_count;
+ result->block_stmt.open = open;
+ result->block_stmt.close = close;
return result;
}
-gb_inline AstNode *make_if_statement(AstFile *f, Token token, AstNode *init, AstNode *cond, AstNode *body, AstNode *else_statement) {
- AstNode *result = make_node(f, AstNode_IfStatement);
- result->if_statement.token = token;
- result->if_statement.init = init;
- result->if_statement.cond = cond;
- result->if_statement.body = body;
- result->if_statement.else_statement = else_statement;
+gb_inline AstNode *make_if_stmt(AstFile *f, Token token, AstNode *init, AstNode *cond, AstNode *body, AstNode *else_stmt) {
+ AstNode *result = make_node(f, AstNode_IfStmt);
+ result->if_stmt.token = token;
+ result->if_stmt.init = init;
+ result->if_stmt.cond = cond;
+ result->if_stmt.body = body;
+ result->if_stmt.else_stmt = else_stmt;
return result;
}
-gb_inline AstNode *make_return_statement(AstFile *f, Token token, AstNode *results, isize result_count) {
- AstNode *result = make_node(f, AstNode_ReturnStatement);
- result->return_statement.token = token;
- result->return_statement.results = results;
- result->return_statement.result_count = result_count;
+gb_inline AstNode *make_return_stmt(AstFile *f, Token token, AstNode *result_list, isize result_count) {
+ AstNode *result = make_node(f, AstNode_ReturnStmt);
+ result->return_stmt.token = token;
+ result->return_stmt.result_list = result_list;
+ result->return_stmt.result_count = result_count;
return result;
}
-gb_inline AstNode *make_for_statement(AstFile *f, Token token, AstNode *init, AstNode *cond, AstNode *end, AstNode *body) {
- AstNode *result = make_node(f, AstNode_ForStatement);
- result->for_statement.token = token;
- result->for_statement.init = init;
- result->for_statement.cond = cond;
- result->for_statement.end = end;
- result->for_statement.body = body;
+gb_inline AstNode *make_for_stmt(AstFile *f, Token token, AstNode *init, AstNode *cond, AstNode *end, AstNode *body) {
+ AstNode *result = make_node(f, AstNode_ForStmt);
+ result->for_stmt.token = token;
+ result->for_stmt.init = init;
+ result->for_stmt.cond = cond;
+ result->for_stmt.end = end;
+ result->for_stmt.body = body;
return result;
}
-gb_inline AstNode *make_defer_statement(AstFile *f, Token token, AstNode *statement) {
- AstNode *result = make_node(f, AstNode_DeferStatement);
- result->defer_statement.token = token;
- result->defer_statement.statement = statement;
+gb_inline AstNode *make_defer_stmt(AstFile *f, Token token, AstNode *stmt) {
+ AstNode *result = make_node(f, AstNode_DeferStmt);
+ result->defer_stmt.token = token;
+ result->defer_stmt.stmt = stmt;
return result;
}
-gb_inline AstNode *make_branch_statement(AstFile *f, Token token) {
- AstNode *result = make_node(f, AstNode_BranchStatement);
- result->branch_statement.token = token;
+gb_inline AstNode *make_branch_stmt(AstFile *f, Token token) {
+ AstNode *result = make_node(f, AstNode_BranchStmt);
+ result->branch_stmt.token = token;
return result;
}
-gb_inline AstNode *make_bad_declaration(AstFile *f, Token begin, Token end) {
- AstNode *result = make_node(f, AstNode_BadDeclaration);
- result->bad_declaration.begin = begin;
- result->bad_declaration.end = end;
+gb_inline AstNode *make_bad_decl(AstFile *f, Token begin, Token end) {
+ AstNode *result = make_node(f, AstNode_BadDecl);
+ result->bad_decl.begin = begin;
+ result->bad_decl.end = end;
return result;
}
-gb_inline AstNode *make_variable_declaration(AstFile *f, DeclarationKind kind, AstNode *name_list, isize name_count, AstNode *type_expression, AstNode *value_list, isize value_count) {
- AstNode *result = make_node(f, AstNode_VariableDeclaration);
- result->variable_declaration.kind = kind;
- result->variable_declaration.name_list = name_list;
- result->variable_declaration.name_count = name_count;
- result->variable_declaration.type_expression = type_expression;
- result->variable_declaration.value_list = value_list;
- result->variable_declaration.value_count = value_count;
+gb_inline AstNode *make_variable_decl(AstFile *f, DeclKind kind, AstNode *name_list, isize name_count, AstNode *type, AstNode *value_list, isize value_count) {
+ AstNode *result = make_node(f, AstNode_VarDecl);
+ result->var_decl.kind = kind;
+ result->var_decl.name_list = name_list;
+ result->var_decl.name_count = name_count;
+ result->var_decl.type = type;
+ result->var_decl.value_list = value_list;
+ result->var_decl.value_count = value_count;
return result;
}
-gb_inline AstNode *make_field(AstFile *f, AstNode *name_list, isize name_count, AstNode *type_expression) {
+gb_inline AstNode *make_field(AstFile *f, AstNode *name_list, isize name_count, AstNode *type) {
AstNode *result = make_node(f, AstNode_Field);
result->field.name_list = name_list;
result->field.name_count = name_count;
- result->field.type_expression = type_expression;
+ result->field.type = type;
return result;
}
-gb_inline AstNode *make_procedure_type(AstFile *f, Token token, AstNode *param_list, isize param_count, AstNode *result_list, isize result_count) {
- AstNode *result = make_node(f, AstNode_ProcedureType);
- result->procedure_type.token = token;
- result->procedure_type.param_list = param_list;
- result->procedure_type.param_count = param_count;
- result->procedure_type.result_list = result_list;
- result->procedure_type.result_count = result_count;
+gb_inline AstNode *make_proc_type(AstFile *f, Token token, AstNode *param_list, isize param_count, AstNode *result_list, isize result_count) {
+ AstNode *result = make_node(f, AstNode_ProcType);
+ result->proc_type.token = token;
+ result->proc_type.param_list = param_list;
+ result->proc_type.param_count = param_count;
+ result->proc_type.result_list = result_list;
+ result->proc_type.result_count = result_count;
return result;
}
-gb_inline AstNode *make_procedure_declaration(AstFile *f, DeclarationKind kind, AstNode *name, AstNode *procedure_type, AstNode *body, AstNode *tag_list, isize tag_count) {
- AstNode *result = make_node(f, AstNode_ProcedureDeclaration);
- result->procedure_declaration.kind = kind;
- result->procedure_declaration.name = name;
- result->procedure_declaration.type = procedure_type;
- result->procedure_declaration.body = body;
- result->procedure_declaration.tag_list = tag_list;
- result->procedure_declaration.tag_count = tag_count;
+gb_inline AstNode *make_procedure_decl(AstFile *f, DeclKind kind, AstNode *name, AstNode *proc_type, AstNode *body, AstNode *tag_list, isize tag_count) {
+ AstNode *result = make_node(f, AstNode_ProcDecl);
+ result->proc_decl.kind = kind;
+ result->proc_decl.name = name;
+ result->proc_decl.type = proc_type;
+ result->proc_decl.body = body;
+ result->proc_decl.tag_list = tag_list;
+ result->proc_decl.tag_count = tag_count;
return result;
}
-gb_inline AstNode *make_pointer_type(AstFile *f, Token token, AstNode *type_expression) {
+gb_inline AstNode *make_pointer_type(AstFile *f, Token token, AstNode *type) {
AstNode *result = make_node(f, AstNode_PointerType);
result->pointer_type.token = token;
- result->pointer_type.type_expression = type_expression;
+ result->pointer_type.type = type;
return result;
}
-gb_inline AstNode *make_array_type(AstFile *f, Token token, AstNode *count, AstNode *element) {
+gb_inline AstNode *make_array_type(AstFile *f, Token token, AstNode *count, AstNode *elem) {
AstNode *result = make_node(f, AstNode_ArrayType);
result->array_type.token = token;
result->array_type.count = count;
- result->array_type.element = element;
+ result->array_type.elem = elem;
return result;
}
@@ -789,27 +799,27 @@ gb_inline AstNode *make_struct_type(AstFile *f, Token token, AstNode *field_list
return result;
}
-gb_inline AstNode *make_type_declaration(AstFile *f, Token token, AstNode *name, AstNode *type_expression) {
- AstNode *result = make_node(f, AstNode_TypeDeclaration);
- result->type_declaration.token = token;
- result->type_declaration.name = name;
- result->type_declaration.type_expression = type_expression;
+gb_inline AstNode *make_type_decl(AstFile *f, Token token, AstNode *name, AstNode *type) {
+ AstNode *result = make_node(f, AstNode_TypeDecl);
+ result->type_decl.token = token;
+ result->type_decl.name = name;
+ result->type_decl.type = type;
return result;
}
-gb_inline AstNode *make_alias_declaration(AstFile *f, Token token, AstNode *name, AstNode *type_expression) {
- AstNode *result = make_node(f, AstNode_AliasDeclaration);
- result->alias_declaration.token = token;
- result->alias_declaration.name = name;
- result->alias_declaration.type_expression = type_expression;
+gb_inline AstNode *make_alias_decl(AstFile *f, Token token, AstNode *name, AstNode *type) {
+ AstNode *result = make_node(f, AstNode_AliasDecl);
+ result->alias_decl.token = token;
+ result->alias_decl.name = name;
+ result->alias_decl.type = type;
return result;
}
-gb_inline AstNode *make_import_declaration(AstFile *f, Token token, Token filepath) {
- AstNode *result = make_node(f, AstNode_ImportDeclaration);
- result->import_declaration.token = token;
- result->import_declaration.filepath = filepath;
+gb_inline AstNode *make_import_decl(AstFile *f, Token token, Token filepath) {
+ AstNode *result = make_node(f, AstNode_ImportDecl);
+ result->import_decl.token = token;
+ result->import_decl.filepath = filepath;
return result;
}
@@ -867,13 +877,13 @@ gb_inline b32 allow_token(AstFile *f, TokenKind kind) {
gb_internal void add_ast_entity(AstFile *f, AstScope *scope, AstNode *declaration, AstNode *name_list) {
for (AstNode *n = name_list; n != NULL; n = n->next) {
- if (n->kind != AstNode_Identifier) {
+ if (n->kind != AstNode_Ident) {
ast_file_err(f, ast_node_token(declaration), "Identifier is already declared or resolved");
continue;
}
- AstEntity *entity = make_ast_entity(f, n->identifier.token, declaration, scope);
- n->identifier.entity = entity;
+ AstEntity *entity = make_ast_entity(f, n->ident.token, declaration, scope);
+ n->ident.entity = entity;
AstEntity *insert_entity = ast_scope_insert(scope, *entity);
if (insert_entity != NULL &&
@@ -891,7 +901,7 @@ gb_internal void add_ast_entity(AstFile *f, AstScope *scope, AstNode *declaratio
-void fix_advance_to_next_statement(AstFile *f) {
+void fix_advance_to_next_stmt(AstFile *f) {
#if 0
for (;;) {
Token t = f->cursor[0];
@@ -926,10 +936,10 @@ void fix_advance_to_next_statement(AstFile *f) {
-AstNode *parse_expression(AstFile *f, b32 lhs);
-AstNode *parse_procedure_type(AstFile *f, AstScope **scope_);
-AstNode *parse_statement_list(AstFile *f, isize *list_count_);
-AstNode *parse_statement(AstFile *f);
+AstNode *parse_expr(AstFile *f, b32 lhs);
+AstNode *parse_proc_type(AstFile *f, AstScope **scope_);
+AstNode *parse_stmt_list(AstFile *f, isize *list_count_);
+AstNode *parse_stmt(AstFile *f);
AstNode *parse_body(AstFile *f, AstScope *scope);
AstNode *parse_identifier(AstFile *f) {
@@ -943,23 +953,23 @@ AstNode *parse_identifier(AstFile *f) {
return make_identifier(f, token);
}
-AstNode *parse_tag_expression(AstFile *f, AstNode *expression) {
+AstNode *parse_tag_expr(AstFile *f, AstNode *expression) {
Token token = expect_token(f, Token_Hash);
Token name = expect_token(f, Token_Identifier);
- return make_tag_expression(f, token, name, expression);
+ return make_tag_expr(f, token, name, expression);
}
-AstNode *parse_tag_statement(AstFile *f, AstNode *statement) {
+AstNode *parse_tag_stmt(AstFile *f, AstNode *statement) {
Token token = expect_token(f, Token_Hash);
Token name = expect_token(f, Token_Identifier);
- return make_tag_statement(f, token, name, statement);
+ return make_tag_stmt(f, token, name, statement);
}
-AstNode *unparen_expression(AstNode *node) {
+AstNode *unparen_expr(AstNode *node) {
for (;;) {
- if (node->kind != AstNode_ParenExpression)
+ if (node->kind != AstNode_ParenExpr)
return node;
- node = node->paren_expression.expression;
+ node = node->paren_expr.expr;
}
}
@@ -990,24 +1000,24 @@ AstNode *parse_element_list(AstFile *f, isize *element_count_) {
return root;
}
-AstNode *parse_literal_value(AstFile *f, AstNode *type_expression) {
+AstNode *parse_literal_value(AstFile *f, AstNode *type) {
AstNode *element_list = NULL;
isize element_count = 0;
Token open = expect_token(f, Token_OpenBrace);
- f->expression_level++;
+ f->expr_level++;
if (f->cursor[0].kind != Token_CloseBrace)
element_list = parse_element_list(f, &element_count);
- f->expression_level--;
+ f->expr_level--;
Token close = expect_token(f, Token_CloseBrace);
- return make_compound_literal(f, type_expression, element_list, element_count, open, close);
+ return make_compound_literal(f, type, element_list, element_count, open, close);
}
AstNode *parse_value(AstFile *f) {
if (f->cursor[0].kind == Token_OpenBrace)
return parse_literal_value(f, NULL);
- AstNode *value = parse_expression(f, false);
+ AstNode *value = parse_expr(f, false);
return value;
}
@@ -1027,7 +1037,7 @@ AstNode *parse_operand(AstFile *f, b32 lhs) {
case Token_Float:
case Token_String:
case Token_Rune:
- operand = make_basic_literal(f, f->cursor[0]);
+ operand = make_basic_lit(f, f->cursor[0]);
next_token(f);
return operand;
@@ -1035,32 +1045,32 @@ AstNode *parse_operand(AstFile *f, b32 lhs) {
Token open, close;
// NOTE(bill): Skip the Paren Expression
open = expect_token(f, Token_OpenParen);
- f->expression_level++;
- operand = parse_expression(f, false);
- f->expression_level--;
+ f->expr_level++;
+ operand = parse_expr(f, false);
+ f->expr_level--;
close = expect_token(f, Token_CloseParen);
- return make_paren_expression(f, operand, open, close);
+ return make_paren_expr(f, operand, open, close);
}
case Token_Hash: {
- operand = parse_tag_expression(f, NULL);
- operand->tag_expression.expression = parse_expression(f, false);
+ operand = parse_tag_expr(f, NULL);
+ operand->tag_expr.expr = parse_expr(f, false);
return operand;
}
// Parse Procedure Type or Literal
case Token_proc: {
AstScope *scope = NULL;
- AstNode *type = parse_procedure_type(f, &scope);
+ AstNode *type = parse_proc_type(f, &scope);
if (f->cursor[0].kind != Token_OpenBrace) {
return type;
} else {
AstNode *body;
- f->expression_level++;
+ f->expr_level++;
body = parse_body(f, scope);
- f->expression_level--;
+ f->expr_level--;
return make_procedure_literal(f, type, body);
}
@@ -1070,7 +1080,7 @@ AstNode *parse_operand(AstFile *f, b32 lhs) {
AstNode *type = parse_identifier_or_type(f);
if (type != NULL) {
// NOTE(bill): Sanity check as identifiers should be handled already
- GB_ASSERT_MSG(type->kind != AstNode_Identifier, "Type Cannot be identifier");
+ GB_ASSERT_MSG(type->kind != AstNode_Ident, "Type Cannot be identifier");
return type;
}
}
@@ -1078,14 +1088,14 @@ AstNode *parse_operand(AstFile *f, b32 lhs) {
Token begin = f->cursor[0];
ast_file_err(f, begin, "Expected an operand");
- fix_advance_to_next_statement(f);
- return make_bad_expression(f, begin, f->cursor[0]);
+ fix_advance_to_next_stmt(f);
+ return make_bad_expr(f, begin, f->cursor[0]);
}
b32 is_literal_type(AstNode *node) {
switch (node->kind) {
- case AstNode_BadExpression:
- case AstNode_Identifier:
+ case AstNode_BadExpr:
+ case AstNode_Ident:
case AstNode_ArrayType:
case AstNode_StructType:
return true;
@@ -1093,7 +1103,7 @@ b32 is_literal_type(AstNode *node) {
return false;
}
-AstNode *parse_atom_expression(AstFile *f, b32 lhs) {
+AstNode *parse_atom_expr(AstFile *f, b32 lhs) {
AstNode *operand = parse_operand(f, lhs);
b32 loop = true;
@@ -1108,7 +1118,7 @@ AstNode *parse_atom_expression(AstFile *f, b32 lhs) {
isize arg_list_count = 0;
Token open_paren, close_paren;
- f->expression_level++;
+ f->expr_level++;
open_paren = expect_token(f, Token_OpenParen);
while (f->cursor[0].kind != Token_CloseParen &&
@@ -1116,7 +1126,7 @@ AstNode *parse_atom_expression(AstFile *f, b32 lhs) {
if (f->cursor[0].kind == Token_Comma)
ast_file_err(f, f->cursor[0], "Expected an expression not a ,");
- DLIST_APPEND(arg_list, arg_list_curr, parse_expression(f, false));
+ DLIST_APPEND(arg_list, arg_list_curr, parse_expr(f, false));
arg_list_count++;
if (f->cursor[0].kind != Token_Comma) {
@@ -1127,10 +1137,10 @@ AstNode *parse_atom_expression(AstFile *f, b32 lhs) {
next_token(f);
}
- f->expression_level--;
+ f->expr_level--;
close_paren = expect_token(f, Token_CloseParen);
- operand = make_call_expression(f, operand, arg_list, arg_list_count, open_paren, close_paren);
+ operand = make_call_expr(f, operand, arg_list, arg_list_count, open_paren, close_paren);
} break;
case Token_Period: {
@@ -1141,12 +1151,12 @@ AstNode *parse_atom_expression(AstFile *f, b32 lhs) {
}
switch (f->cursor[0].kind) {
case Token_Identifier:
- operand = make_selector_expression(f, token, operand, parse_identifier(f));
+ operand = make_selector_expr(f, token, operand, parse_identifier(f));
break;
default: {
ast_file_err(f, f->cursor[0], "Expected a selector");
next_token(f);
- operand = make_selector_expression(f, f->cursor[0], operand, NULL);
+ operand = make_selector_expr(f, f->cursor[0], operand, NULL);
} break;
}
} break;
@@ -1158,11 +1168,11 @@ AstNode *parse_atom_expression(AstFile *f, b32 lhs) {
Token open, close;
AstNode *indices[3] = {};
- f->expression_level++;
+ f->expr_level++;
open = expect_token(f, Token_OpenBracket);
if (f->cursor[0].kind != Token_Colon)
- indices[0] = parse_expression(f, false);
+ indices[0] = parse_expr(f, false);
isize colon_count = 0;
Token colons[2] = {};
@@ -1172,38 +1182,38 @@ AstNode *parse_atom_expression(AstFile *f, b32 lhs) {
if (f->cursor[0].kind != Token_Colon &&
f->cursor[0].kind != Token_CloseBracket &&
f->cursor[0].kind != Token_EOF) {
- indices[colon_count] = parse_expression(f, false);
+ indices[colon_count] = parse_expr(f, false);
}
}
- f->expression_level--;
+ f->expr_level--;
close = expect_token(f, Token_CloseBracket);
if (colon_count == 0) {
- operand = make_index_expression(f, operand, indices[0], open, close);
+ operand = make_index_expr(f, operand, indices[0], open, close);
} else {
b32 triple_indexed = false;
if (colon_count == 2) {
triple_indexed = true;
if (indices[1] == NULL) {
ast_file_err(f, colons[0], "Second index is required in a triple indexed slice");
- indices[1] = make_bad_expression(f, colons[0], colons[1]);
+ indices[1] = make_bad_expr(f, colons[0], colons[1]);
}
if (indices[2] == NULL) {
ast_file_err(f, colons[1], "Third index is required in a triple indexed slice");
- indices[2] = make_bad_expression(f, colons[1], close);
+ indices[2] = make_bad_expr(f, colons[1], close);
}
}
- operand = make_slice_expression(f, operand, open, close, indices[0], indices[1], indices[2], triple_indexed);
+ operand = make_slice_expr(f, operand, open, close, indices[0], indices[1], indices[2], triple_indexed);
}
} break;
case Token_Pointer: // Deference
- operand = make_dereference_expression(f, operand, expect_token(f, Token_Pointer));
+ operand = make_deref_expr(f, operand, expect_token(f, Token_Pointer));
break;
case Token_OpenBrace: {
- if (is_literal_type(operand) && f->expression_level >= 0) {
+ if (is_literal_type(operand) && f->expr_level >= 0) {
gb_printf_err("here\n");
if (lhs) {
// TODO(bill): Handle this
@@ -1227,7 +1237,7 @@ AstNode *parse_atom_expression(AstFile *f, b32 lhs) {
AstNode *parse_type(AstFile *f);
-AstNode *parse_unary_expression(AstFile *f, b32 lhs) {
+AstNode *parse_unary_expr(AstFile *f, b32 lhs) {
switch (f->cursor[0].kind) {
case Token_Pointer:
case Token_Add:
@@ -1237,27 +1247,27 @@ AstNode *parse_unary_expression(AstFile *f, b32 lhs) {
AstNode *operand;
Token op = f->cursor[0];
next_token(f);
- operand = parse_unary_expression(f, false);
- return make_unary_expression(f, op, operand);
+ operand = parse_unary_expr(f, false);
+ return make_unary_expr(f, op, operand);
} break;
case Token_cast: {
- AstNode *type_expression, *operand;
+ AstNode *type, *operand;
Token token = f->cursor[0];
next_token(f);
expect_token(f, Token_OpenParen);
- type_expression = parse_type(f);
+ type = parse_type(f);
expect_token(f, Token_CloseParen);
- operand = parse_unary_expression(f, false);
- return make_cast_expression(f, token, type_expression, operand);
+ operand = parse_unary_expr(f, false);
+ return make_cast_expr(f, token, type, operand);
} break;
}
- return parse_atom_expression(f, lhs);
+ return parse_atom_expr(f, lhs);
}
-AstNode *parse_binary_expression(AstFile *f, b32 lhs, i32 prec_in) {
- AstNode *expression = parse_unary_expression(f, lhs);
+AstNode *parse_binary_expr(AstFile *f, b32 lhs, i32 prec_in) {
+ AstNode *expression = parse_unary_expr(f, lhs);
for (i32 prec = token_precedence(f->cursor[0]); prec >= prec_in; prec--) {
for (;;) {
AstNode *right;
@@ -1270,27 +1280,27 @@ AstNode *parse_binary_expression(AstFile *f, b32 lhs, i32 prec_in) {
// TODO(bill): error checking
lhs = false;
}
- right = parse_binary_expression(f, false, prec+1);
+ right = parse_binary_expr(f, false, prec+1);
if (!right)
ast_file_err(f, op, "Expected expression on the right hand side of the binary operator");
- expression = make_binary_expression(f, op, expression, right);
+ expression = make_binary_expr(f, op, expression, right);
}
}
return expression;
}
-AstNode *parse_expression(AstFile *f, b32 lhs) {
- return parse_binary_expression(f, lhs, 0+1);
+AstNode *parse_expr(AstFile *f, b32 lhs) {
+ return parse_binary_expr(f, lhs, 0+1);
}
-AstNode *parse_expression_list(AstFile *f, b32 lhs, isize *list_count_) {
+AstNode *parse_expr_list(AstFile *f, b32 lhs, isize *list_count_) {
AstNode *list_root = NULL;
AstNode *list_curr = NULL;
isize list_count = 0;
do {
- DLIST_APPEND(list_root, list_curr, parse_expression(f, lhs));
+ DLIST_APPEND(list_root, list_curr, parse_expr(f, lhs));
list_count++;
if (f->cursor[0].kind != Token_Comma ||
f->cursor[0].kind == Token_EOF)
@@ -1303,19 +1313,19 @@ AstNode *parse_expression_list(AstFile *f, b32 lhs, isize *list_count_) {
return list_root;
}
-AstNode *parse_lhs_expression_list(AstFile *f, isize *list_count) {
- return parse_expression_list(f, true, list_count);
+AstNode *parse_lhs_expr_list(AstFile *f, isize *list_count) {
+ return parse_expr_list(f, true, list_count);
}
-AstNode *parse_rhs_expression_list(AstFile *f, isize *list_count) {
- return parse_expression_list(f, false, list_count);
+AstNode *parse_rhs_expr_list(AstFile *f, isize *list_count) {
+ return parse_expr_list(f, false, list_count);
}
-AstNode *parse_declaration(AstFile *f, AstNode *name_list, isize name_count);
+AstNode *parse_decl(AstFile *f, AstNode *name_list, isize name_count);
-AstNode *parse_simple_statement(AstFile *f) {
+AstNode *parse_simple_stmt(AstFile *f) {
isize lhs_count = 0, rhs_count = 0;
- AstNode *lhs_expression_list = parse_lhs_expression_list(f, &lhs_count);
+ AstNode *lhs_expr_list = parse_lhs_expr_list(f, &lhs_count);
AstNode *statement = NULL;
Token token = f->cursor[0];
@@ -1335,26 +1345,26 @@ AstNode *parse_simple_statement(AstFile *f) {
{
if (f->curr_scope == f->file_scope) {
ast_file_err(f, f->cursor[0], "You cannot use a simple statement in the file scope");
- return make_bad_statement(f, f->cursor[0], f->cursor[0]);
+ return make_bad_stmt(f, f->cursor[0], f->cursor[0]);
}
next_token(f);
- AstNode *rhs_expression_list = parse_rhs_expression_list(f, &rhs_count);
- if (rhs_expression_list == NULL) {
+ AstNode *rhs_expr_list = parse_rhs_expr_list(f, &rhs_count);
+ if (rhs_expr_list == NULL) {
ast_file_err(f, token, "No right-hand side in assignment statement.");
- return make_bad_statement(f, token, f->cursor[0]);
+ return make_bad_stmt(f, token, f->cursor[0]);
}
- return make_assign_statement(f, token,
- lhs_expression_list, lhs_count,
- rhs_expression_list, rhs_count);
+ return make_assign_stmt(f, token,
+ lhs_expr_list, lhs_count,
+ rhs_expr_list, rhs_count);
} break;
case Token_Colon: // Declare
- return parse_declaration(f, lhs_expression_list, lhs_count);
+ return parse_decl(f, lhs_expr_list, lhs_count);
}
if (lhs_count > 1) {
ast_file_err(f, token, "Expected 1 expression");
- return make_bad_statement(f, token, f->cursor[0]);
+ return make_bad_stmt(f, token, f->cursor[0]);
}
token = f->cursor[0];
@@ -1363,40 +1373,40 @@ AstNode *parse_simple_statement(AstFile *f) {
case Token_Decrement:
if (f->curr_scope == f->file_scope) {
ast_file_err(f, f->cursor[0], "You cannot use a simple statement in the file scope");
- return make_bad_statement(f, f->cursor[0], f->cursor[0]);
+ return make_bad_stmt(f, f->cursor[0], f->cursor[0]);
}
- statement = make_inc_dec_statement(f, token, lhs_expression_list);
+ statement = make_inc_dec_stmt(f, token, lhs_expr_list);
next_token(f);
return statement;
}
- return make_expression_statement(f, lhs_expression_list);
+ return make_expr_stmt(f, lhs_expr_list);
}
-AstNode *parse_block_statement(AstFile *f) {
+AstNode *parse_block_stmt(AstFile *f) {
if (f->curr_scope == f->file_scope) {
ast_file_err(f, f->cursor[0], "You cannot use a block statement in the file scope");
- return make_bad_statement(f, f->cursor[0], f->cursor[0]);
+ return make_bad_stmt(f, f->cursor[0], f->cursor[0]);
}
- AstNode *block_statement;
+ AstNode *block_stmt;
open_ast_scope(f);
- block_statement = parse_body(f, f->curr_scope);
+ block_stmt = parse_body(f, f->curr_scope);
close_ast_scope(f);
- return block_statement;
+ return block_stmt;
}
-AstNode *convert_statement_to_expression(AstFile *f, AstNode *statement, String kind) {
+AstNode *convert_stmt_to_expr(AstFile *f, AstNode *statement, String kind) {
if (statement == NULL)
return NULL;
- if (statement->kind == AstNode_ExpressionStatement)
- return statement->expression_statement.expression;
+ if (statement->kind == AstNode_ExprStmt)
+ return statement->expr_stmt.expr;
ast_file_err(f, f->cursor[0], "Expected `%.*s`, found a simple statement.", LIT(kind));
- return make_bad_expression(f, f->cursor[0], f->cursor[1]);
+ return make_bad_expr(f, f->cursor[0], f->cursor[1]);
}
AstNode *parse_identfier_list(AstFile *f, isize *list_count_) {
@@ -1434,25 +1444,25 @@ AstNode *parse_type(AstFile *f) {
Token token = f->cursor[0];
ast_file_err(f, token, "Expected a type");
next_token(f);
- return make_bad_expression(f, token, f->cursor[0]);
+ return make_bad_expr(f, token, f->cursor[0]);
}
return type;
}
-AstNode *parse_field_declaration(AstFile *f, AstScope *scope) {
+AstNode *parse_field_decl(AstFile *f, AstScope *scope) {
AstNode *name_list = NULL;
isize name_count = 0;
- name_list = parse_lhs_expression_list(f, &name_count);
+ name_list = parse_lhs_expr_list(f, &name_count);
if (name_count == 0)
ast_file_err(f, f->cursor[0], "Empty field declaration");
expect_token(f, Token_Colon);
- AstNode *type_expression = parse_type_attempt(f);
- if (type_expression == NULL)
+ AstNode *type = parse_type_attempt(f);
+ if (type == NULL)
ast_file_err(f, f->cursor[0], "Expected a type for this field declaration");
- AstNode *field = make_field(f, name_list, name_count, type_expression);
+ AstNode *field = make_field(f, name_list, name_count, type);
add_ast_entity(f, scope, field, name_list);
return field;
}
@@ -1461,7 +1471,7 @@ Token parse_procedure_signature(AstFile *f, AstScope *scope,
AstNode **param_list, isize *param_count,
AstNode **result_list, isize *result_count);
-AstNode *parse_procedure_type(AstFile *f, AstScope **scope_) {
+AstNode *parse_proc_type(AstFile *f, AstScope **scope_) {
AstScope *scope = make_ast_scope(f, f->file_scope); // Procedure's scope
AstNode *params = NULL;
AstNode *results = NULL;
@@ -1471,7 +1481,7 @@ AstNode *parse_procedure_type(AstFile *f, AstScope **scope_) {
Token proc_token = parse_procedure_signature(f, scope, &params, &param_count, &results, &result_count);
if (scope_) *scope_ = scope;
- return make_procedure_type(f, proc_token, params, param_count, results, result_count);
+ return make_proc_type(f, proc_token, params, param_count, results, result_count);
}
@@ -1480,7 +1490,7 @@ AstNode *parse_parameter_list(AstFile *f, AstScope *scope, isize *param_count_)
AstNode *param_list_curr = NULL;
isize param_count = 0;
while (f->cursor[0].kind == Token_Identifier) {
- AstNode *field = parse_field_declaration(f, scope);
+ AstNode *field = parse_field_decl(f, scope);
DLIST_APPEND(param_list, param_list_curr, field);
param_count += field->field.name_count;
if (f->cursor[0].kind != Token_Comma)
@@ -1501,15 +1511,15 @@ AstNode *parse_identifier_or_type(AstFile *f) {
return make_pointer_type(f, expect_token(f, Token_Pointer), parse_type(f));
case Token_OpenBracket: {
- f->expression_level++;
+ f->expr_level++;
Token token = expect_token(f, Token_OpenBracket);
- AstNode *count_expression = NULL;
+ AstNode *count_expr = NULL;
if (f->cursor[0].kind != Token_CloseBracket)
- count_expression = parse_expression(f, false);
+ count_expr = parse_expr(f, false);
expect_token(f, Token_CloseBracket);
- f->expression_level--;
- return make_array_type(f, token, count_expression, parse_type(f));
+ f->expr_level--;
+ return make_array_type(f, token, count_expr, parse_type(f));
}
case Token_struct: {
@@ -1527,17 +1537,17 @@ AstNode *parse_identifier_or_type(AstFile *f) {
}
case Token_proc:
- return parse_procedure_type(f, NULL);
+ return parse_proc_type(f, NULL);
case Token_OpenParen: {
// NOTE(bill): Skip the paren expression
- AstNode *type_expression;
+ AstNode *type;
Token open, close;
open = expect_token(f, Token_OpenParen);
- type_expression = parse_type(f);
+ type = parse_type(f);
close = expect_token(f, Token_CloseParen);
- return make_paren_expression(f, type_expression, open, close);
+ return make_paren_expr(f, type, open, close);
}
// TODO(bill): Why is this even allowed? Is this a parsing error?
@@ -1603,13 +1613,13 @@ AstNode *parse_body(AstFile *f, AstScope *scope) {
isize statement_list_count = 0;
Token open, close;
open = expect_token(f, Token_OpenBrace);
- statement_list = parse_statement_list(f, &statement_list_count);
+ statement_list = parse_stmt_list(f, &statement_list_count);
close = expect_token(f, Token_CloseBrace);
- return make_block_statement(f, statement_list, statement_list_count, open, close);
+ return make_block_stmt(f, statement_list, statement_list_count, open, close);
}
-AstNode *parse_procedure_declaration(AstFile *f, Token proc_token, AstNode *name, DeclarationKind kind) {
+AstNode *parse_procedure_decl(AstFile *f, Token proc_token, AstNode *name, DeclKind kind) {
AstNode *param_list = NULL;
AstNode *result_list = NULL;
isize param_count = 0;
@@ -1624,7 +1634,7 @@ AstNode *parse_procedure_declaration(AstFile *f, Token proc_token, AstNode *name
AstNode *tag_list_curr = NULL;
isize tag_count = 0;
while (f->cursor[0].kind == Token_Hash) {
- DLIST_APPEND(tag_list, tag_list_curr, parse_tag_expression(f, NULL));
+ DLIST_APPEND(tag_list, tag_list_curr, parse_tag_expr(f, NULL));
tag_count++;
}
if (f->cursor[0].kind == Token_OpenBrace) {
@@ -1633,21 +1643,21 @@ AstNode *parse_procedure_declaration(AstFile *f, Token proc_token, AstNode *name
close_ast_scope(f);
- AstNode *proc_type = make_procedure_type(f, proc_token, param_list, param_count, result_list, result_count);
- return make_procedure_declaration(f, kind, name, proc_type, body, tag_list, tag_count);
+ AstNode *proc_type = make_proc_type(f, proc_token, param_list, param_count, result_list, result_count);
+ return make_procedure_decl(f, kind, name, proc_type, body, tag_list, tag_count);
}
-AstNode *parse_declaration(AstFile *f, AstNode *name_list, isize name_count) {
+AstNode *parse_decl(AstFile *f, AstNode *name_list, isize name_count) {
AstNode *value_list = NULL;
- AstNode *type_expression = NULL;
+ AstNode *type = NULL;
isize value_count = 0;
if (allow_token(f, Token_Colon)) {
- type_expression = parse_identifier_or_type(f);
+ type = parse_identifier_or_type(f);
} else if (f->cursor[0].kind != Token_Eq && f->cursor[0].kind != Token_Semicolon) {
ast_file_err(f, f->cursor[0], "Expected type separator `:` or `=`");
}
- DeclarationKind declaration_kind = Declaration_Mutable;
+ DeclKind declaration_kind = Declaration_Mutable;
if (f->cursor[0].kind == Token_Eq ||
f->cursor[0].kind == Token_Colon) {
@@ -1660,15 +1670,15 @@ AstNode *parse_declaration(AstFile *f, AstNode *name_list, isize name_count) {
AstNode *name = name_list;
if (name_count != 1) {
ast_file_err(f, proc_token, "You can only declare one procedure at a time (at the moment)");
- return make_bad_declaration(f, name->identifier.token, proc_token);
+ return make_bad_decl(f, name->ident.token, proc_token);
}
- AstNode *procedure_declaration = parse_procedure_declaration(f, proc_token, name, declaration_kind);
- add_ast_entity(f, f->curr_scope, procedure_declaration, name_list);
- return procedure_declaration;
+ AstNode *procedure_decl = parse_procedure_decl(f, proc_token, name, declaration_kind);
+ add_ast_entity(f, f->curr_scope, procedure_decl, name_list);
+ return procedure_decl;
} else {
- value_list = parse_rhs_expression_list(f, &value_count);
+ value_list = parse_rhs_expr_list(f, &value_count);
if (value_count > name_count) {
ast_file_err(f, f->cursor[0], "Too many values on the right hand side of the declaration");
} else if (value_count < name_count &&
@@ -1681,61 +1691,61 @@ AstNode *parse_declaration(AstFile *f, AstNode *name_list, isize name_count) {
}
if (declaration_kind == Declaration_Mutable) {
- if (type_expression == NULL && value_list == NULL) {
+ if (type == NULL && value_list == NULL) {
ast_file_err(f, f->cursor[0], "Missing variable type or initialization");
- return make_bad_declaration(f, f->cursor[0], f->cursor[0]);
+ return make_bad_decl(f, f->cursor[0], f->cursor[0]);
}
} else if (declaration_kind == Declaration_Immutable) {
- if (type_expression == NULL && value_list == NULL && name_count > 0) {
+ if (type == NULL && value_list == NULL && name_count > 0) {
ast_file_err(f, f->cursor[0], "Missing constant value");
- return make_bad_declaration(f, f->cursor[0], f->cursor[0]);
+ return make_bad_decl(f, f->cursor[0], f->cursor[0]);
}
} else {
Token begin = f->cursor[0];
ast_file_err(f, begin, "Unknown type of variable declaration");
- fix_advance_to_next_statement(f);
- return make_bad_declaration(f, begin, f->cursor[0]);
+ fix_advance_to_next_stmt(f);
+ return make_bad_decl(f, begin, f->cursor[0]);
}
- AstNode *variable_declaration = make_variable_declaration(f, declaration_kind, name_list, name_count, type_expression, value_list, value_count);
- add_ast_entity(f, f->curr_scope, variable_declaration, name_list);
- return variable_declaration;
+ AstNode *variable_decl = make_variable_decl(f, declaration_kind, name_list, name_count, type, value_list, value_count);
+ add_ast_entity(f, f->curr_scope, variable_decl, name_list);
+ return variable_decl;
}
-AstNode *parse_if_statement(AstFile *f) {
+AstNode *parse_if_stmt(AstFile *f) {
if (f->curr_scope == f->file_scope) {
ast_file_err(f, f->cursor[0], "You cannot use an if statement in the file scope");
- return make_bad_statement(f, f->cursor[0], f->cursor[0]);
+ return make_bad_stmt(f, f->cursor[0], f->cursor[0]);
}
Token token = expect_token(f, Token_if);
AstNode *init = NULL;
AstNode *cond = NULL;
AstNode *body = NULL;
- AstNode *else_statement = NULL;
+ AstNode *else_stmt = NULL;
open_ast_scope(f);
defer (close_ast_scope(f));
- isize prev_level = f->expression_level;
- f->expression_level = -1;
+ isize prev_level = f->expr_level;
+ f->expr_level = -1;
if (allow_token(f, Token_Semicolon)) {
- cond = parse_expression(f, false);
+ cond = parse_expr(f, false);
} else {
- init = parse_simple_statement(f);
+ init = parse_simple_stmt(f);
if (allow_token(f, Token_Semicolon)) {
- cond = parse_expression(f, false);
+ cond = parse_expr(f, false);
} else {
- cond = convert_statement_to_expression(f, init, make_string("boolean expression"));
+ cond = convert_stmt_to_expr(f, init, make_string("boolean expression"));
init = NULL;
}
}
- f->expression_level = prev_level;
+ f->expr_level = prev_level;
@@ -1744,45 +1754,45 @@ AstNode *parse_if_statement(AstFile *f) {
ast_file_err(f, f->cursor[0], "Expected condition for if statement");
}
- body = parse_block_statement(f);
+ body = parse_block_stmt(f);
if (allow_token(f, Token_else)) {
switch (f->cursor[0].kind) {
case Token_if:
- else_statement = parse_if_statement(f);
+ else_stmt = parse_if_stmt(f);
break;
case Token_OpenBrace:
- else_statement = parse_block_statement(f);
+ else_stmt = parse_block_stmt(f);
break;
default:
ast_file_err(f, f->cursor[0], "Expected if statement block statement");
- else_statement = make_bad_statement(f, f->cursor[0], f->cursor[1]);
+ else_stmt = make_bad_stmt(f, f->cursor[0], f->cursor[1]);
break;
}
}
- return make_if_statement(f, token, init, cond, body, else_statement);
+ return make_if_stmt(f, token, init, cond, body, else_stmt);
}
-AstNode *parse_return_statement(AstFile *f) {
+AstNode *parse_return_stmt(AstFile *f) {
if (f->curr_scope == f->file_scope) {
ast_file_err(f, f->cursor[0], "You cannot use a return statement in the file scope");
- return make_bad_statement(f, f->cursor[0], f->cursor[0]);
+ return make_bad_stmt(f, f->cursor[0], f->cursor[0]);
}
Token token = expect_token(f, Token_return);
AstNode *result = NULL;
isize result_count = 0;
if (f->cursor[0].kind != Token_Semicolon)
- result = parse_rhs_expression_list(f, &result_count);
+ result = parse_rhs_expr_list(f, &result_count);
expect_token(f, Token_Semicolon);
- return make_return_statement(f, token, result, result_count);
+ return make_return_stmt(f, token, result, result_count);
}
-AstNode *parse_for_statement(AstFile *f) {
+AstNode *parse_for_stmt(AstFile *f) {
if (f->curr_scope == f->file_scope) {
ast_file_err(f, f->cursor[0], "You cannot use a for statement in the file scope");
- return make_bad_statement(f, f->cursor[0], f->cursor[0]);
+ return make_bad_stmt(f, f->cursor[0], f->cursor[0]);
}
Token token = expect_token(f, Token_for);
@@ -1795,11 +1805,11 @@ AstNode *parse_for_statement(AstFile *f) {
AstNode *body = NULL;
if (f->cursor[0].kind != Token_OpenBrace) {
- isize prev_level = f->expression_level;
- f->expression_level = -1;
+ isize prev_level = f->expr_level;
+ f->expr_level = -1;
if (f->cursor[0].kind != Token_Semicolon) {
- cond = parse_simple_statement(f);
- if (is_ast_node_complex_statement(cond)) {
+ cond = parse_simple_stmt(f);
+ if (is_ast_node_complex_stmt(cond)) {
ast_file_err(f, f->cursor[0],
"You are not allowed that type of statement in a for statement, it is too complex!");
}
@@ -1809,95 +1819,95 @@ AstNode *parse_for_statement(AstFile *f) {
init = cond;
cond = NULL;
if (f->cursor[0].kind != Token_Semicolon) {
- cond = parse_simple_statement(f);
+ cond = parse_simple_stmt(f);
}
expect_token(f, Token_Semicolon);
if (f->cursor[0].kind != Token_OpenBrace) {
- end = parse_simple_statement(f);
+ end = parse_simple_stmt(f);
}
}
- f->expression_level = prev_level;
+ f->expr_level = prev_level;
}
- body = parse_block_statement(f);
+ body = parse_block_stmt(f);
- cond = convert_statement_to_expression(f, cond, make_string("boolean expression"));
+ cond = convert_stmt_to_expr(f, cond, make_string("boolean expression"));
- return make_for_statement(f, token, init, cond, end, body);
+ return make_for_stmt(f, token, init, cond, end, body);
}
-AstNode *parse_defer_statement(AstFile *f) {
+AstNode *parse_defer_stmt(AstFile *f) {
if (f->curr_scope == f->file_scope) {
ast_file_err(f, f->cursor[0], "You cannot use a defer statement in the file scope");
- return make_bad_statement(f, f->cursor[0], f->cursor[0]);
+ return make_bad_stmt(f, f->cursor[0], f->cursor[0]);
}
Token token = expect_token(f, Token_defer);
- AstNode *statement = parse_statement(f);
+ AstNode *statement = parse_stmt(f);
switch (statement->kind) {
- case AstNode_EmptyStatement:
+ case AstNode_EmptyStmt:
ast_file_err(f, token, "Empty statement after defer (e.g. `;`)");
break;
- case AstNode_DeferStatement:
+ case AstNode_DeferStmt:
ast_file_err(f, token, "You cannot defer a defer statement");
break;
- case AstNode_ReturnStatement:
+ case AstNode_ReturnStmt:
ast_file_err(f, token, "You cannot a return statement");
break;
}
- return make_defer_statement(f, token, statement);
+ return make_defer_stmt(f, token, statement);
}
-AstNode *parse_type_declaration(AstFile *f) {
+AstNode *parse_type_decl(AstFile *f) {
Token token = expect_token(f, Token_type);
AstNode *name = parse_identifier(f);
expect_token(f, Token_Colon);
- AstNode *type_expression = parse_type(f);
+ AstNode *type = parse_type(f);
- AstNode *type_declaration = make_type_declaration(f, token, name, type_expression);
+ AstNode *type_decl = make_type_decl(f, token, name, type);
- if (type_expression->kind != AstNode_StructType &&
- type_expression->kind != AstNode_ProcedureType)
+ if (type->kind != AstNode_StructType &&
+ type->kind != AstNode_ProcType)
expect_token(f, Token_Semicolon);
- return type_declaration;
+ return type_decl;
}
-AstNode *parse_alias_declaration(AstFile *f) {
+AstNode *parse_alias_decl(AstFile *f) {
Token token = expect_token(f, Token_alias);
AstNode *name = parse_identifier(f);
expect_token(f, Token_Colon);
- AstNode *type_expression = parse_type(f);
+ AstNode *type = parse_type(f);
- AstNode *alias_declaration = make_alias_declaration(f, token, name, type_expression);
+ AstNode *alias_decl = make_alias_decl(f, token, name, type);
- if (type_expression->kind != AstNode_StructType &&
- type_expression->kind != AstNode_ProcedureType)
+ if (type->kind != AstNode_StructType &&
+ type->kind != AstNode_ProcType)
expect_token(f, Token_Semicolon);
- return alias_declaration;
+ return alias_decl;
}
-AstNode *parse_import_declaration(AstFile *f) {
+AstNode *parse_import_decl(AstFile *f) {
Token token = expect_token(f, Token_import);
Token filepath = expect_token(f, Token_String);
if (f->curr_scope == f->file_scope) {
- return make_import_declaration(f, token, filepath);
+ return make_import_decl(f, token, filepath);
}
ast_file_err(f, token, "You cannot `import` within a procedure. This must be done at the file scope.");
- return make_bad_declaration(f, token, filepath);
+ return make_bad_decl(f, token, filepath);
}
-AstNode *parse_statement(AstFile *f) {
+AstNode *parse_stmt(AstFile *f) {
AstNode *s = NULL;
Token token = f->cursor[0];
switch (token.kind) {
case Token_type:
- return parse_type_declaration(f);
+ return parse_type_decl(f);
case Token_alias:
- return parse_alias_declaration(f);
+ return parse_alias_decl(f);
case Token_import:
- return parse_import_declaration(f);
+ return parse_import_decl(f);
// Operands
case Token_Identifier:
@@ -1911,8 +1921,8 @@ AstNode *parse_statement(AstFile *f) {
case Token_Sub:
case Token_Xor:
case Token_Not:
- s = parse_simple_statement(f);
- if (s->kind != AstNode_ProcedureDeclaration && !allow_token(f, Token_Semicolon)) {
+ s = parse_simple_stmt(f);
+ if (s->kind != AstNode_ProcDecl && !allow_token(f, Token_Semicolon)) {
ast_file_err(f, f->cursor[0],
"Expected `;` after statement, got `%.*s`",
LIT(token_strings[f->cursor[0].kind]));
@@ -1920,10 +1930,10 @@ AstNode *parse_statement(AstFile *f) {
return s;
// TODO(bill): other keywords
- case Token_if: return parse_if_statement(f);
- case Token_return: return parse_return_statement(f);
- case Token_for: return parse_for_statement(f);
- case Token_defer: return parse_defer_statement(f);
+ case Token_if: return parse_if_stmt(f);
+ case Token_return: return parse_return_stmt(f);
+ case Token_for: return parse_for_stmt(f);
+ case Token_defer: return parse_defer_stmt(f);
// case Token_match: return NULL; // TODO(bill): Token_match
// case Token_case: return NULL; // TODO(bill): Token_case
@@ -1932,17 +1942,17 @@ AstNode *parse_statement(AstFile *f) {
case Token_fallthrough:
next_token(f);
expect_token(f, Token_Semicolon);
- return make_branch_statement(f, token);
+ return make_branch_stmt(f, token);
case Token_Hash:
- s = parse_tag_statement(f, NULL);
- s->tag_statement.statement = parse_statement(f); // TODO(bill): Find out why this doesn't work as an argument
+ s = parse_tag_stmt(f, NULL);
+ s->tag_stmt.stmt = parse_stmt(f); // TODO(bill): Find out why this doesn't work as an argument
return s;
- case Token_OpenBrace: return parse_block_statement(f);
+ case Token_OpenBrace: return parse_block_stmt(f);
case Token_Semicolon:
- s = make_empty_statement(f, token);
+ s = make_empty_stmt(f, token);
next_token(f);
return s;
@@ -1952,11 +1962,11 @@ AstNode *parse_statement(AstFile *f) {
ast_file_err(f, token,
"Expected a statement, got `%.*s`",
LIT(token_strings[token.kind]));
- fix_advance_to_next_statement(f);
- return make_bad_statement(f, token, f->cursor[0]);
+ fix_advance_to_next_stmt(f);
+ return make_bad_stmt(f, token, f->cursor[0]);
}
-AstNode *parse_statement_list(AstFile *f, isize *list_count_) {
+AstNode *parse_stmt_list(AstFile *f, isize *list_count_) {
AstNode *list_root = NULL;
AstNode *list_curr = NULL;
isize list_count = 0;
@@ -1964,7 +1974,7 @@ AstNode *parse_statement_list(AstFile *f, isize *list_count_) {
while (f->cursor[0].kind != Token_case &&
f->cursor[0].kind != Token_CloseBrace &&
f->cursor[0].kind != Token_EOF) {
- DLIST_APPEND(list_root, list_curr, parse_statement(f));
+ DLIST_APPEND(list_root, list_curr, parse_stmt(f));
list_count++;
}
@@ -2108,17 +2118,17 @@ void parse_file(Parser *p, AstFile *f) {
base_dir.len--;
}
- f->declarations = parse_statement_list(f, &f->declaration_count);
+ f->decls = parse_stmt_list(f, &f->decl_count);
- for (AstNode *node = f->declarations; node != NULL; node = node->next) {
- if (!is_ast_node_declaration(node) &&
- node->kind != AstNode_BadStatement &&
- node->kind != AstNode_EmptyStatement) {
+ for (AstNode *node = f->decls; node != NULL; node = node->next) {
+ if (!is_ast_node_decl(node) &&
+ node->kind != AstNode_BadStmt &&
+ node->kind != AstNode_EmptyStmt) {
// NOTE(bill): Sanity check
ast_file_err(f, ast_node_token(node), "Only declarations are allowed at file scope");
} else {
- if (node->kind == AstNode_ImportDeclaration) {
- auto *id = &node->import_declaration;
+ if (node->kind == AstNode_ImportDecl) {
+ auto *id = &node->import_decl;
String file = id->filepath.string;
String file_str = {};
if (file.text[0] == '"')
diff --git a/src/printer.cpp b/src/printer.cpp
index 94233e97e..31a86fe99 100644
--- a/src/printer.cpp
+++ b/src/printer.cpp
@@ -10,190 +10,190 @@ void print_ast(AstNode *node, isize indent) {
return;
switch (node->kind) {
- case AstNode_BasicLiteral:
+ case AstNode_BasicLit:
print_indent(indent);
- print_token(node->basic_literal);
+ print_token(node->basic_lit);
break;
- case AstNode_Identifier:
+ case AstNode_Ident:
print_indent(indent);
- print_token(node->identifier.token);
+ print_token(node->ident.token);
break;
- case AstNode_ProcedureLiteral:
+ case AstNode_ProcLit:
print_indent(indent);
gb_printf("(proc lit)\n");
- print_ast(node->procedure_literal.type, indent+1);
- print_ast(node->procedure_literal.body, indent+1);
+ print_ast(node->proc_lit.type, indent+1);
+ print_ast(node->proc_lit.body, indent+1);
break;
- case AstNode_CompoundLiteral:
+ case AstNode_CompoundLit:
print_indent(indent);
gb_printf("(compound lit)\n");
- print_ast(node->compound_literal.type_expression, indent+1);
- print_ast(node->compound_literal.element_list, indent+1);
+ print_ast(node->compound_lit.type, indent+1);
+ print_ast(node->compound_lit.elem_list, indent+1);
break;
- case AstNode_TagExpression:
+ case AstNode_TagExpr:
print_indent(indent);
gb_printf("(tag)\n");
print_indent(indent+1);
- print_token(node->tag_expression.name);
- print_ast(node->tag_expression.expression, indent+1);
+ print_token(node->tag_expr.name);
+ print_ast(node->tag_expr.expr, indent+1);
break;
- case AstNode_UnaryExpression:
+ case AstNode_UnaryExpr:
print_indent(indent);
- print_token(node->unary_expression.op);
- print_ast(node->unary_expression.operand, indent+1);
+ print_token(node->unary_expr.op);
+ print_ast(node->unary_expr.expr, indent+1);
break;
- case AstNode_BinaryExpression:
+ case AstNode_BinaryExpr:
print_indent(indent);
- print_token(node->binary_expression.op);
- print_ast(node->binary_expression.left, indent+1);
- print_ast(node->binary_expression.right, indent+1);
+ print_token(node->binary_expr.op);
+ print_ast(node->binary_expr.left, indent+1);
+ print_ast(node->binary_expr.right, indent+1);
break;
- case AstNode_CallExpression:
+ case AstNode_CallExpr:
print_indent(indent);
gb_printf("(call)\n");
- print_ast(node->call_expression.proc, indent+1);
- print_ast(node->call_expression.arg_list, indent+1);
+ print_ast(node->call_expr.proc, indent+1);
+ print_ast(node->call_expr.arg_list, indent+1);
break;
- case AstNode_SelectorExpression:
+ case AstNode_SelectorExpr:
print_indent(indent);
gb_printf(".\n");
- print_ast(node->selector_expression.operand, indent+1);
- print_ast(node->selector_expression.selector, indent+1);
+ print_ast(node->selector_expr.expr, indent+1);
+ print_ast(node->selector_expr.selector, indent+1);
break;
- case AstNode_IndexExpression:
+ case AstNode_IndexExpr:
print_indent(indent);
gb_printf("([])\n");
- print_ast(node->index_expression.expression, indent+1);
- print_ast(node->index_expression.value, indent+1);
+ print_ast(node->index_expr.expr, indent+1);
+ print_ast(node->index_expr.index, indent+1);
break;
- case AstNode_CastExpression:
+ case AstNode_CastExpr:
print_indent(indent);
gb_printf("(cast)\n");
- print_ast(node->cast_expression.type_expression, indent+1);
- print_ast(node->cast_expression.operand, indent+1);
+ print_ast(node->cast_expr.type, indent+1);
+ print_ast(node->cast_expr.expr, indent+1);
break;
- case AstNode_DereferenceExpression:
+ case AstNode_DerefExpr:
print_indent(indent);
- gb_printf("(dereference)\n");
- print_ast(node->dereference_expression.operand, indent+1);
+ gb_printf("(deref)\n");
+ print_ast(node->deref_expr.expr, indent+1);
break;
- case AstNode_ExpressionStatement:
- print_ast(node->expression_statement.expression, indent);
+ case AstNode_ExprStmt:
+ print_ast(node->expr_stmt.expr, indent);
break;
- case AstNode_IncDecStatement:
+ case AstNode_IncDecStmt:
print_indent(indent);
- print_token(node->inc_dec_statement.op);
- print_ast(node->inc_dec_statement.expression, indent+1);
+ print_token(node->inc_dec_stmt.op);
+ print_ast(node->inc_dec_stmt.expr, indent+1);
break;
- case AstNode_AssignStatement:
+ case AstNode_AssignStmt:
print_indent(indent);
- print_token(node->assign_statement.op);
- print_ast(node->assign_statement.lhs_list, indent+1);
- print_ast(node->assign_statement.rhs_list, indent+1);
+ print_token(node->assign_stmt.op);
+ print_ast(node->assign_stmt.lhs_list, indent+1);
+ print_ast(node->assign_stmt.rhs_list, indent+1);
break;
- case AstNode_BlockStatement:
+ case AstNode_BlockStmt:
print_indent(indent);
gb_printf("(block)\n");
- print_ast(node->block_statement.list, indent+1);
+ print_ast(node->block_stmt.list, indent+1);
break;
- case AstNode_IfStatement:
+ case AstNode_IfStmt:
print_indent(indent);
gb_printf("(if)\n");
- print_ast(node->if_statement.cond, indent+1);
- print_ast(node->if_statement.body, indent+1);
- if (node->if_statement.else_statement) {
+ print_ast(node->if_stmt.cond, indent+1);
+ print_ast(node->if_stmt.body, indent+1);
+ if (node->if_stmt.else_stmt) {
print_indent(indent);
gb_printf("(else)\n");
- print_ast(node->if_statement.else_statement, indent+1);
+ print_ast(node->if_stmt.else_stmt, indent+1);
}
break;
- case AstNode_ReturnStatement:
+ case AstNode_ReturnStmt:
print_indent(indent);
gb_printf("(return)\n");
- print_ast(node->return_statement.results, indent+1);
+ print_ast(node->return_stmt.result_list, indent+1);
break;
- case AstNode_ForStatement:
+ case AstNode_ForStmt:
print_indent(indent);
gb_printf("(for)\n");
- print_ast(node->for_statement.init, indent+1);
- print_ast(node->for_statement.cond, indent+1);
- print_ast(node->for_statement.end, indent+1);
- print_ast(node->for_statement.body, indent+1);
+ print_ast(node->for_stmt.init, indent+1);
+ print_ast(node->for_stmt.cond, indent+1);
+ print_ast(node->for_stmt.end, indent+1);
+ print_ast(node->for_stmt.body, indent+1);
break;
- case AstNode_DeferStatement:
+ case AstNode_DeferStmt:
print_indent(indent);
gb_printf("(defer)\n");
- print_ast(node->defer_statement.statement, indent+1);
+ print_ast(node->defer_stmt.stmt, indent+1);
break;
- case AstNode_VariableDeclaration:
+ case AstNode_VarDecl:
print_indent(indent);
- if (node->variable_declaration.kind == Declaration_Mutable)
+ if (node->var_decl.kind == Declaration_Mutable)
gb_printf("(decl:var,mutable)\n");
- else if (node->variable_declaration.kind == Declaration_Immutable)
+ else if (node->var_decl.kind == Declaration_Immutable)
gb_printf("(decl:var,immutable)\n");
- print_ast(node->variable_declaration.name_list, indent+1);
- print_ast(node->variable_declaration.type_expression, indent+1);
- print_ast(node->variable_declaration.value_list, indent+1);
+ print_ast(node->var_decl.name_list, indent+1);
+ print_ast(node->var_decl.type, indent+1);
+ print_ast(node->var_decl.value_list, indent+1);
break;
- case AstNode_ProcedureDeclaration:
+ case AstNode_ProcDecl:
print_indent(indent);
- if (node->procedure_declaration.kind == Declaration_Mutable)
+ if (node->proc_decl.kind == Declaration_Mutable)
gb_printf("(decl:proc,mutable)\n");
- else if (node->procedure_declaration.kind == Declaration_Immutable)
+ else if (node->proc_decl.kind == Declaration_Immutable)
gb_printf("(decl:proc,immutable)\n");
- print_ast(node->procedure_declaration.type, indent+1);
- print_ast(node->procedure_declaration.body, indent+1);
- print_ast(node->procedure_declaration.tag_list, indent+1);
+ print_ast(node->proc_decl.type, indent+1);
+ print_ast(node->proc_decl.body, indent+1);
+ print_ast(node->proc_decl.tag_list, indent+1);
break;
- case AstNode_TypeDeclaration:
+ case AstNode_TypeDecl:
print_indent(indent);
gb_printf("(type)\n");
- print_ast(node->type_declaration.name, indent+1);
- print_ast(node->type_declaration.type_expression, indent+1);
+ print_ast(node->type_decl.name, indent+1);
+ print_ast(node->type_decl.type, indent+1);
break;
- case AstNode_AliasDeclaration:
+ case AstNode_AliasDecl:
print_indent(indent);
gb_printf("(alias)\n");
- print_ast(node->alias_declaration.name, indent+1);
- print_ast(node->alias_declaration.type_expression, indent+1);
+ print_ast(node->alias_decl.name, indent+1);
+ print_ast(node->alias_decl.type, indent+1);
break;
- case AstNode_ProcedureType:
+ case AstNode_ProcType:
print_indent(indent);
- gb_printf("(type:proc)(%td -> %td)\n", node->procedure_type.param_count, node->procedure_type.result_count);
- print_ast(node->procedure_type.param_list, indent+1);
- if (node->procedure_type.result_list) {
+ gb_printf("(type:proc)(%td -> %td)\n", node->proc_type.param_count, node->proc_type.result_count);
+ print_ast(node->proc_type.param_list, indent+1);
+ if (node->proc_type.result_list) {
print_indent(indent+1);
gb_printf("->\n");
- print_ast(node->procedure_type.result_list, indent+1);
+ print_ast(node->proc_type.result_list, indent+1);
}
break;
case AstNode_Field:
print_ast(node->field.name_list, indent);
- print_ast(node->field.type_expression, indent);
+ print_ast(node->field.type, indent);
break;
case AstNode_PointerType:
print_indent(indent);
print_token(node->pointer_type.token);
- print_ast(node->pointer_type.type_expression, indent+1);
+ print_ast(node->pointer_type.type, indent+1);
break;
case AstNode_ArrayType:
print_indent(indent);
gb_printf("[]\n");
print_ast(node->array_type.count, indent+1);
- print_ast(node->array_type.element, indent+1);
+ print_ast(node->array_type.elem, indent+1);
break;
case AstNode_StructType:
print_indent(indent);