mirror of
https://github.com/Ed94/Odin.git
synced 2026-06-27 07:51:49 -07:00
Fix issue #31; Removed down_cast
This commit is contained in:
+1
-66
@@ -3950,7 +3950,7 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id
|
||||
id == BuiltinProc_kmag) {
|
||||
if (!is_type_quaternion(x->type)) {
|
||||
gbString s = type_to_string(x->type);
|
||||
error_node(call, "Argument has type `%s`, expected a complex type", s);
|
||||
error_node(call, "Argument has type `%s`, expected a quaternion type", s);
|
||||
gb_string_free(s);
|
||||
return false;
|
||||
}
|
||||
@@ -5455,71 +5455,6 @@ ExprKind check_expr_base_internal(Checker *c, Operand *o, AstNode *node, Type *t
|
||||
o->type = t;
|
||||
o->mode = Addressing_OptionalOk;
|
||||
} break;
|
||||
case Token_down_cast: {
|
||||
if (o->mode == Addressing_Constant) {
|
||||
gbString expr_str = expr_to_string(o->expr);
|
||||
error_node(o->expr, "Cannot `down_cast` a constant expression: `%s`", expr_str);
|
||||
gb_string_free(expr_str);
|
||||
o->mode = Addressing_Invalid;
|
||||
o->expr = node;
|
||||
return kind;
|
||||
}
|
||||
|
||||
if (is_type_untyped(o->type)) {
|
||||
gbString expr_str = expr_to_string(o->expr);
|
||||
error_node(o->expr, "Cannot `down_cast` an untyped expression: `%s`", expr_str);
|
||||
gb_string_free(expr_str);
|
||||
o->mode = Addressing_Invalid;
|
||||
o->expr = node;
|
||||
return kind;
|
||||
}
|
||||
|
||||
if (!(is_type_pointer(o->type) && is_type_pointer(t))) {
|
||||
gbString expr_str = expr_to_string(o->expr);
|
||||
error_node(o->expr, "Can only `down_cast` pointers: `%s`", expr_str);
|
||||
gb_string_free(expr_str);
|
||||
o->mode = Addressing_Invalid;
|
||||
o->expr = node;
|
||||
return kind;
|
||||
}
|
||||
|
||||
Type *src = type_deref(o->type);
|
||||
Type *dst = type_deref(t);
|
||||
Type *bsrc = base_type(src);
|
||||
Type *bdst = base_type(dst);
|
||||
|
||||
if (!(is_type_struct(bsrc) || is_type_raw_union(bsrc))) {
|
||||
gbString expr_str = expr_to_string(o->expr);
|
||||
error_node(o->expr, "Can only `down_cast` pointer from structs or unions: `%s`", expr_str);
|
||||
gb_string_free(expr_str);
|
||||
o->mode = Addressing_Invalid;
|
||||
o->expr = node;
|
||||
return kind;
|
||||
}
|
||||
|
||||
if (!(is_type_struct(bdst) || is_type_raw_union(bdst))) {
|
||||
gbString expr_str = expr_to_string(o->expr);
|
||||
error_node(o->expr, "Can only `down_cast` pointer to structs or unions: `%s`", expr_str);
|
||||
gb_string_free(expr_str);
|
||||
o->mode = Addressing_Invalid;
|
||||
o->expr = node;
|
||||
return kind;
|
||||
}
|
||||
|
||||
String param_name = check_down_cast_name(dst, src);
|
||||
if (param_name.len == 0) {
|
||||
gbString expr_str = expr_to_string(o->expr);
|
||||
error_node(o->expr, "Illegal `down_cast`: `%s`", expr_str);
|
||||
gb_string_free(expr_str);
|
||||
o->mode = Addressing_Invalid;
|
||||
o->expr = node;
|
||||
return kind;
|
||||
}
|
||||
|
||||
o->mode = Addressing_Value;
|
||||
o->type = t;
|
||||
} break;
|
||||
|
||||
|
||||
default:
|
||||
GB_PANIC("Unknown cast expression");
|
||||
|
||||
@@ -3468,9 +3468,11 @@ irValue *ir_build_expr(irProcedure *proc, AstNode *expr) {
|
||||
ir_emit_comment(proc, str_lit("cast - transmute"));
|
||||
return ir_emit_transmute(proc, e, type);
|
||||
|
||||
#if 0
|
||||
case Token_down_cast:
|
||||
ir_emit_comment(proc, str_lit("cast - down_cast"));
|
||||
return ir_emit_down_cast(proc, e, type);
|
||||
#endif
|
||||
|
||||
case Token_union_cast:
|
||||
ir_emit_comment(proc, str_lit("cast - union_cast"));
|
||||
@@ -4596,6 +4598,7 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) {
|
||||
ir_emit_store(proc, v, ir_emit_transmute(proc, ir_build_expr(proc, ce->expr), type));
|
||||
return ir_addr(v);
|
||||
}
|
||||
#if 0
|
||||
case Token_down_cast: {
|
||||
ir_emit_comment(proc, str_lit("Cast - down_cast"));
|
||||
// NOTE(bill): Needed for dereference of pointer conversion
|
||||
@@ -4604,6 +4607,7 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) {
|
||||
ir_emit_store(proc, v, ir_emit_down_cast(proc, ir_build_expr(proc, ce->expr), type));
|
||||
return ir_addr(v);
|
||||
}
|
||||
#endif
|
||||
case Token_union_cast: {
|
||||
ir_emit_comment(proc, str_lit("Cast - union_cast"));
|
||||
// NOTE(bill): Needed for dereference of pointer conversion
|
||||
|
||||
@@ -2056,7 +2056,6 @@ AstNode *parse_unary_expr(AstFile *f, bool lhs) {
|
||||
|
||||
case Token_cast:
|
||||
case Token_transmute:
|
||||
case Token_down_cast:
|
||||
case Token_union_cast:
|
||||
{
|
||||
Token token = f->curr_token; next_token(f);
|
||||
|
||||
@@ -108,7 +108,6 @@ TOKEN_KIND(Token__KeywordBegin, "_KeywordBegin"), \
|
||||
TOKEN_KIND(Token_immutable, "immutable"), \
|
||||
TOKEN_KIND(Token_cast, "cast"), \
|
||||
TOKEN_KIND(Token_transmute, "transmute"), \
|
||||
TOKEN_KIND(Token_down_cast, "down_cast"), \
|
||||
TOKEN_KIND(Token_union_cast, "union_cast"), \
|
||||
TOKEN_KIND(Token_context, "context"), \
|
||||
TOKEN_KIND(Token_push_context, "push_context"), \
|
||||
|
||||
Reference in New Issue
Block a user