From 44b959648c5b2ba7afc0b897760b3fa09aa876f6 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Sat, 26 Jan 2019 20:13:43 +0000 Subject: [PATCH] Pass any and union "by pointer" to make the tag a pointer --- src/check_stmt.cpp | 1 - src/entity.cpp | 1 + src/ir.cpp | 3 ++- src/parser.cpp | 54 ++++++++++++---------------------------------- src/parser.hpp | 1 - 5 files changed, 17 insertions(+), 43 deletions(-) diff --git a/src/check_stmt.cpp b/src/check_stmt.cpp index 5b30ebee3..3262aea5d 100644 --- a/src/check_stmt.cpp +++ b/src/check_stmt.cpp @@ -980,7 +980,6 @@ void check_type_switch_stmt(CheckerContext *ctx, Ast *node, u32 mod_flags) { } if (is_ptr && - !is_type_any(type_deref(x.type)) && cc->list.count == 1 && case_type != nullptr) { case_type = alloc_type_pointer(case_type); diff --git a/src/entity.cpp b/src/entity.cpp index da627cb7c..842cd5d8c 100644 --- a/src/entity.cpp +++ b/src/entity.cpp @@ -48,6 +48,7 @@ enum EntityFlag { EntityFlag_NotExported = 1<<14, EntityFlag_Static = 1<<16, + // EntityFlag_Reference = 1<<17, EntityFlag_CVarArg = 1<<20, EntityFlag_AutoCast = 1<<21, diff --git a/src/ir.cpp b/src/ir.cpp index 627985857..5d2f923aa 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -8652,7 +8652,8 @@ void ir_build_stmt_internal(irProcedure *proc, Ast *node) { ir_start_block(proc, body); if (cc->list.count == 1) { - bool any_or_not_ptr = is_type_any(type_deref(parent_type)) || !is_parent_ptr; + // bool any_or_not_ptr = is_type_any(type_deref(parent_type)) || !is_parent_ptr; + bool any_or_not_ptr = !is_parent_ptr; Type *ct = case_entity->type; if (any_or_not_ptr) { diff --git a/src/parser.cpp b/src/parser.cpp index d11d7dd4c..448415cfd 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -1877,7 +1877,7 @@ Ast *parse_operand(AstFile *f, bool lhs) { isize param_count = 0; polymorphic_params = parse_field_list(f, ¶m_count, 0, Token_CloseParen, false, true); if (param_count == 0) { - syntax_error(polymorphic_params, "Expected at least 1 polymorphic parametric"); + syntax_error(polymorphic_params, "Expected at least 1 polymorphic parameter"); polymorphic_params = nullptr; } expect_token_after(f, Token_CloseParen, "parameter list"); @@ -2089,6 +2089,8 @@ bool is_literal_type(Ast *node) { case Ast_EnumType: case Ast_DynamicArrayType: case Ast_MapType: + case Ast_BitFieldType: + case Ast_BitSetType: case Ast_CallExpr: return true; } @@ -2854,7 +2856,7 @@ u32 parse_field_prefixes(AstFile *f) { if (no_alias_count > 1) syntax_error(f->curr_token, "Multiple '#no_alias' in this field list"); if (c_vararg_count > 1) syntax_error(f->curr_token, "Multiple '#c_vararg' in this field list"); if (in_count > 1) syntax_error(f->curr_token, "Multiple 'in' in this field list"); - if (auto_cast_count > 1) syntax_error(f->curr_token, "Multiple 'auto_cast_count' in this field list"); + if (auto_cast_count > 1) syntax_error(f->curr_token, "Multiple 'auto_cast' in this field list"); u32 field_flags = 0; @@ -2912,7 +2914,6 @@ Array convert_to_ident_list(AstFile *f, Array list, bool ign case Ast_PolyType: if (allow_poly_names) { if (ident->PolyType.specialization == nullptr) { - // syntax_error(ident, "Polymorphic identifiers are not yet supported"); break; } else { syntax_error(ident, "Expected a polymorphic identifier without any specialization"); @@ -2946,29 +2947,6 @@ bool parse_expect_field_separator(AstFile *f, Ast *param) { return false; } -bool parse_expect_struct_separator(AstFile *f, Ast *param) { - Token token = f->curr_token; - if (allow_token(f, Token_Semicolon)) { - return true; - } - - if (token.kind == Token_Colon) { - syntax_error(f->curr_token, "Expected a semicolon, got a comma"); - advance_token(f); - return true; - } - - if (token.kind == Token_CloseBrace) { - if (token.pos.line == f->prev_token.pos.line) { - return true; - } - } - expect_token_after(f, Token_Semicolon, "field list"); - - return false; -} - - Ast *parse_struct_field_list(AstFile *f, isize *name_count_) { CommentGroup *docs = f->lead_comment; Token start_token = f->curr_token; @@ -3291,10 +3269,7 @@ Ast *parse_when_stmt(AstFile *f) { Ast *else_stmt = nullptr; isize prev_level = f->expr_level; - isize when_level = f->when_level; - defer (f->when_level = when_level); f->expr_level = -1; - f->when_level += 1; cond = parse_expr(f, false); @@ -3334,16 +3309,17 @@ Ast *parse_when_stmt(AstFile *f) { Ast *parse_return_stmt(AstFile *f) { + Token token = expect_token(f, Token_return); + if (f->curr_proc == nullptr) { syntax_error(f->curr_token, "You cannot use a return statement in the file scope"); - return ast_bad_stmt(f, f->curr_token, f->curr_token); + return ast_bad_stmt(f, token, f->curr_token); } if (f->expr_level > 0) { syntax_error(f->curr_token, "You cannot use a return statement within an expression"); - return ast_bad_stmt(f, f->curr_token, f->curr_token); + return ast_bad_stmt(f, token, f->curr_token); } - Token token = expect_token(f, Token_return); auto results = array_make(heap_allocator()); while (f->curr_token.kind != Token_Semicolon) { @@ -3511,7 +3487,7 @@ Ast *parse_switch_stmt(AstFile *f) { blank_ident.string = str_lit("_"); Ast *blank = ast_ident(f, blank_ident); array_add(&lhs, blank); - array_add(&rhs, parse_expr(f, false)); + array_add(&rhs, parse_expr(f, true)); tag = ast_assign_stmt(f, token, lhs, rhs); is_type_switch = true; @@ -3519,13 +3495,11 @@ Ast *parse_switch_stmt(AstFile *f) { tag = parse_simple_stmt(f, StmtAllowFlag_In); if (tag->kind == Ast_AssignStmt && tag->AssignStmt.op.kind == Token_in) { is_type_switch = true; - } else { - if (allow_token(f, Token_Semicolon)) { - init = tag; - tag = nullptr; - if (f->curr_token.kind != Token_OpenBrace) { - tag = parse_simple_stmt(f, StmtAllowFlag_None); - } + } else if (allow_token(f, Token_Semicolon)) { + init = tag; + tag = nullptr; + if (f->curr_token.kind != Token_OpenBrace) { + tag = parse_simple_stmt(f, StmtAllowFlag_None); } } } diff --git a/src/parser.hpp b/src/parser.hpp index 6f48673a8..fabb7ff8e 100644 --- a/src/parser.hpp +++ b/src/parser.hpp @@ -93,7 +93,6 @@ struct AstFile { bool allow_in_expr; // NOTE(bill): in expression are only allowed in certain cases bool in_foreign_block; bool allow_type; - isize when_level; Array decls; Array imports; // 'import' 'using import'