diff options
| author | Ginger Bill <bill@gingerbill.org> | 2017-07-07 23:42:43 +0100 |
|---|---|---|
| committer | Ginger Bill <bill@gingerbill.org> | 2017-07-07 23:42:43 +0100 |
| commit | 4b051a0d3b9da924924ed2a28ef7c102902a880c (patch) | |
| tree | 11ac611a92c608097b1af289d71a6ac21c9b4900 /src | |
| parent | 45353465a6d743f9c9cbca63c45877a6d294feb5 (diff) | |
`..` half closed range; `...` open range; `...` variadic syntax
Diffstat (limited to 'src')
| -rw-r--r-- | src/check_decl.cpp | 4 | ||||
| -rw-r--r-- | src/check_expr.cpp | 32 | ||||
| -rw-r--r-- | src/check_stmt.cpp | 5 | ||||
| -rw-r--r-- | src/tokenizer.cpp | 10 |
4 files changed, 24 insertions, 27 deletions
diff --git a/src/check_decl.cpp b/src/check_decl.cpp index b6e2acb26..ea457fcf3 100644 --- a/src/check_decl.cpp +++ b/src/check_decl.cpp @@ -79,6 +79,7 @@ void check_init_variables(Checker *c, Entity **lhs, isize lhs_count, Array<AstNo gbTempArenaMemory tmp = gb_temp_arena_memory_begin(&c->tmp_arena); + defer (gb_temp_arena_memory_end(tmp)); // NOTE(bill): If there is a bad syntax error, rhs > lhs which would mean there would need to be // an extra allocation @@ -100,9 +101,6 @@ void check_init_variables(Checker *c, Entity **lhs, isize lhs_count, Array<AstNo if (rhs_count > 0 && lhs_count != rhs_count) { error(lhs[0]->token, "Assignment count mismatch `%td` = `%td`", lhs_count, rhs_count); } - - - gb_temp_arena_memory_end(tmp); } void check_init_constant(Checker *c, Entity *e, Operand *operand) { diff --git a/src/check_expr.cpp b/src/check_expr.cpp index e99706836..f0fc0f0e7 100644 --- a/src/check_expr.cpp +++ b/src/check_expr.cpp @@ -633,7 +633,7 @@ void check_assignment(Checker *c, Operand *operand, Type *type, String context_n // TODO(bill): is this a good enough error message? // TODO(bill): Actually allow built in procedures to be passed around and thus be created on use error(operand->expr, - "Cannot assign type `%s` as a value in %.*s", + "Cannot assign `%s` which is a type in %.*s", op_type_str, LIT(context_name)); } else { @@ -658,8 +658,9 @@ void check_assignment(Checker *c, Operand *operand, Type *type, String context_n void populate_using_entity_map(Checker *c, AstNode *node, Type *t, Map<Entity *> *entity_map) { t = base_type(type_deref(t)); gbString str = nullptr; + defer (gb_string_free(str)); if (node != nullptr) { - expr_to_string(node); + str = expr_to_string(node); } if (t->kind == Type_Record) { @@ -687,7 +688,6 @@ void populate_using_entity_map(Checker *c, AstNode *node, Type *t, Map<Entity *> } } - gb_string_free(str); } @@ -696,6 +696,7 @@ isize check_fields(Checker *c, AstNode *node, Array<AstNode *> decls, Entity **fields, isize field_count, String context) { gbTempArenaMemory tmp = gb_temp_arena_memory_begin(&c->tmp_arena); + defer (gb_temp_arena_memory_end(tmp)); Map<Entity *> entity_map = {}; map_init_with_reserve(&entity_map, c->tmp_allocator, 2*field_count); @@ -717,11 +718,9 @@ isize check_fields(Checker *c, AstNode *node, Array<AstNode *> decls, Type *type = check_type(c, f->type); bool is_using = (f->flags&FieldFlag_using) != 0; - if (is_using) { - if (f->names.count > 1) { - error(f->names[0], "Cannot apply `using` to more than one of the same type"); - is_using = false; - } + if (is_using && f->names.count > 1) { + error(f->names[0], "Cannot apply `using` to more than one of the same type"); + is_using = false; } for_array(name_index, f->names) { @@ -795,7 +794,6 @@ isize check_fields(Checker *c, AstNode *node, Array<AstNode *> decls, } } - gb_temp_arena_memory_end(tmp); return field_index; } @@ -956,6 +954,7 @@ void check_union_type(Checker *c, Type *named_type, Type *union_type, AstNode *n } gbTempArenaMemory tmp = gb_temp_arena_memory_begin(&c->tmp_arena); + defer (gb_temp_arena_memory_end(tmp)); Map<Entity *> entity_map = {}; // Key: String map_init_with_reserve(&entity_map, c->tmp_allocator, 2*variant_count); @@ -1057,7 +1056,6 @@ void check_union_type(Checker *c, Type *named_type, Type *union_type, AstNode *n type_set_offsets(c->allocator, union_type); - gb_temp_arena_memory_end(tmp); union_type->Record.variants = variants; union_type->Record.variant_count = variant_index; @@ -1093,6 +1091,7 @@ void check_enum_type(Checker *c, Type *enum_type, Type *named_type, AstNode *nod GB_ASSERT(is_type_enum(enum_type)); gbTempArenaMemory tmp = gb_temp_arena_memory_begin(&c->tmp_arena); + defer (gb_temp_arena_memory_end(tmp)); Type *base_type = t_int; if (et->base_type != nullptr) { @@ -1208,7 +1207,6 @@ void check_enum_type(Checker *c, Type *enum_type, Type *named_type, AstNode *nod } } GB_ASSERT(field_count <= et->fields.count); - gb_temp_arena_memory_end(tmp); enum_type->Record.fields = fields; @@ -1230,7 +1228,7 @@ void check_bit_field_type(Checker *c, Type *bit_field_type, Type *named_type, As GB_ASSERT(is_type_bit_field(bit_field_type)); gbTempArenaMemory tmp = gb_temp_arena_memory_begin(&c->tmp_arena); - + defer (gb_temp_arena_memory_end(tmp)); Map<Entity *> entity_map = {}; // Key: String map_init_with_reserve(&entity_map, c->tmp_allocator, 2*(bft->fields.count)); @@ -1293,7 +1291,6 @@ void check_bit_field_type(Checker *c, Type *bit_field_type, Type *named_type, As } } GB_ASSERT(field_count <= bft->fields.count); - gb_temp_arena_memory_end(tmp); bit_field_type->BitField.fields = fields; bit_field_type->BitField.field_count = field_count; @@ -2137,6 +2134,8 @@ Entity *check_ident(Checker *c, Operand *o, AstNode *n, Type *named_type, Type * multi_map_get_all(&s->elements, key, procs); if (type_hint != nullptr) { gbTempArenaMemory tmp = gb_temp_arena_memory_begin(&c->tmp_arena); + defer (gb_temp_arena_memory_end(tmp)); + // NOTE(bill): These should be done for (isize i = 0; i < overload_count; i++) { Type *t = base_type(procs[i]->type); @@ -2153,8 +2152,6 @@ Entity *check_ident(Checker *c, Operand *o, AstNode *n, Type *named_type, Type * break; } } - gb_temp_arena_memory_end(tmp); - } if (!skip) { @@ -7073,7 +7070,7 @@ ExprKind check_expr_base_internal(Checker *c, Operand *o, AstNode *node, Type *t } if (se->low == nullptr && se->high != nullptr) { - error(se->interval0, "1st index is required if a 2nd index is specified"); + // error(se->interval0, "1st index is required if a 2nd index is specified"); // It is okay to continue as it will assume the 1st index is zero } @@ -7094,7 +7091,7 @@ ExprKind check_expr_base_internal(Checker *c, Operand *o, AstNode *node, Type *t TokenKind interval_kind = se->interval0.kind; - i64 indices[2] = {}; + i64 indices[3] = {}; AstNode *nodes[3] = {se->low, se->high, se->max}; for (isize i = 0; i < gb_count_of(nodes); i++) { i64 index = max_count; @@ -7159,6 +7156,7 @@ ExprKind check_expr_base_internal(Checker *c, Operand *o, AstNode *node, Type *t case_end; case AstNode_TypeType: + case AstNode_PolyType: case AstNode_ProcType: case AstNode_PointerType: case AstNode_ArrayType: diff --git a/src/check_stmt.cpp b/src/check_stmt.cpp index 3f9efda9a..fe70fd672 100644 --- a/src/check_stmt.cpp +++ b/src/check_stmt.cpp @@ -683,6 +683,7 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) { } gbTempArenaMemory tmp = gb_temp_arena_memory_begin(&c->tmp_arena); + defer (gb_temp_arena_memory_end(tmp)); // NOTE(bill): If there is a bad syntax error, rhs > lhs which would mean there would need to be // an extra allocation @@ -705,7 +706,6 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) { error(as->lhs[0], "Assignment count mismatch `%td` = `%td`", lhs_count, rhs_count); } - gb_temp_arena_memory_end(tmp); } break; default: { @@ -1325,6 +1325,8 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) { TypeAndToken *found = map_get(&seen, key); if (found != nullptr) { gbTempArenaMemory tmp = gb_temp_arena_memory_begin(&c->tmp_arena); + defer (gb_temp_arena_memory_end(tmp)); + isize count = multi_map_count(&seen, key); TypeAndToken *taps = gb_alloc_array(c->tmp_allocator, TypeAndToken, count); @@ -1347,7 +1349,6 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) { } } - gb_temp_arena_memory_end(tmp); if (continue_outer) { continue; diff --git a/src/tokenizer.cpp b/src/tokenizer.cpp index 78833453d..31d1e8933 100644 --- a/src/tokenizer.cpp +++ b/src/tokenizer.cpp @@ -78,8 +78,8 @@ TOKEN_KIND(Token__ComparisonEnd, "_ComparisonEnd"), \ TOKEN_KIND(Token_Semicolon, ";"), \ TOKEN_KIND(Token_Period, "."), \ TOKEN_KIND(Token_Comma, ","), \ - TOKEN_KIND(Token_Ellipsis, ".."), \ - TOKEN_KIND(Token_HalfClosed, "..<"), \ + TOKEN_KIND(Token_Ellipsis, "..."), \ + TOKEN_KIND(Token_HalfClosed, ".."), \ TOKEN_KIND(Token_BackSlash, "\\"), \ TOKEN_KIND(Token__OperatorEnd, "_OperatorEnd"), \ \ @@ -885,10 +885,10 @@ Token tokenizer_get_token(Tokenizer *t) { token.kind = Token_Period; // Default if (t->curr_rune == '.') { // Could be an ellipsis advance_to_next_rune(t); - token.kind = Token_Ellipsis; - if (t->curr_rune == '<') { + token.kind = Token_HalfClosed; + if (t->curr_rune == '.') { advance_to_next_rune(t); - token.kind = Token_HalfClosed; + token.kind = Token_Ellipsis; } } break; |