Fix parsing for block/if expression within if/for/etc. statements

This commit is contained in:
Ginger Bill
2017-01-27 23:02:55 +00:00
parent 92453369c5
commit 31aacd5bf4
10 changed files with 313 additions and 283 deletions
+5 -4
View File
@@ -302,10 +302,11 @@ void check_proc_lit(Checker *c, Entity *e, DeclInfo *d) {
error_node(pd->body, "A procedure tagged as `#foreign` cannot have a body");
}
if (proc_type->Proc.calling_convention != ProcCC_Odin) {
error_node(d->proc_lit, "An internal procedure may only have the Odin calling convention");
proc_type->Proc.calling_convention = ProcCC_Odin;
}
// TODO(bill): Is this the best option? What about passing to external shit?!
// if (proc_type->Proc.calling_convention != ProcCC_Odin) {
// error_node(d->proc_lit, "An internal procedure may only have the Odin calling convention");
// proc_type->Proc.calling_convention = ProcCC_Odin;
// }
d->scope = c->context.scope;
+5
View File
@@ -203,6 +203,11 @@ i64 check_distance_between_types(Checker *c, Operand *operand, Type *type) {
}
}
// if (is_type_proc(dst)) {
// if (are_types_identical(src, dst)) {
// return 1;
// }
// }
if (is_type_any(dst)) {
// NOTE(bill): Anything can cast to `Any`
+1 -1
View File
@@ -240,7 +240,7 @@ int main(int argc, char **argv) {
char lib_str_buf[1024] = {0};
for_array(i, ir_gen.module.foreign_library_paths) {
String lib = ir_gen.module.foreign_library_paths.e[i];
gb_printf_err("Linking lib: %.*s\n", LIT(lib));
// gb_printf_err("Linking lib: %.*s\n", LIT(lib));
isize len = gb_snprintf(lib_str_buf, gb_size_of(lib_str_buf),
" \"%.*s\"", LIT(lib));
lib_str = gb_string_appendc(lib_str, lib_str_buf);
+8 -5
View File
@@ -1827,11 +1827,15 @@ AstNode *parse_operand(AstFile *f, bool lhs) {
}
case Token_if:
if (lhs) goto error;
return parse_if_expr(f);
if (!lhs && f->expr_level >= 0) {
return parse_if_expr(f);
}
break;
case Token_OpenBrace:
if (lhs) goto error;
return parse_block_expr(f);
if (!lhs && f->expr_level >= 0) {
return parse_block_expr(f);
}
break;
default: {
AstNode *type = parse_identifier_or_type(f);
@@ -1846,7 +1850,6 @@ AstNode *parse_operand(AstFile *f, bool lhs) {
}
}
error:
Token begin = f->curr_token;
syntax_error(begin, "Expected an operand");
fix_advance_to_next_stmt(f);
+3 -1
View File
@@ -1194,7 +1194,9 @@ Selection lookup_field_with_selection(gbAllocator a, Type *type_, String field_n
} else if (!is_type_union(type)) {
for (isize i = 0; i < type->Record.field_count; i++) {
Entity *f = type->Record.fields[i];
GB_ASSERT(f->kind == Entity_Variable && f->flags & EntityFlag_Field);
if (f->kind != Entity_Variable || (f->flags & EntityFlag_Field) == 0) {
continue;
}
String str = f->token.string;
if (str_eq(field_name, str)) {
selection_add_index(&sel, i); // HACK(bill): Leaky memory