mirror of
https://github.com/Ed94/Odin.git
synced 2026-06-18 20:02:22 -07:00
Pass any and union "by pointer" to make the tag a pointer
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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,
|
||||
|
||||
+2
-1
@@ -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) {
|
||||
|
||||
+14
-40
@@ -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<Ast *> convert_to_ident_list(AstFile *f, Array<AstAndFlags> 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<Ast *>(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<Ast *> decls;
|
||||
Array<Ast *> imports; // 'import' 'using import'
|
||||
|
||||
Reference in New Issue
Block a user