mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-04 14:48:47 +00:00
Strings galore!
This commit is contained in:
@@ -456,8 +456,9 @@ void add_type_and_value(CheckerInfo *i, AstNode *expression, AddressingMode mode
|
||||
}
|
||||
|
||||
TypeAndValue tv = {};
|
||||
tv.type = type;
|
||||
tv.type = type;
|
||||
tv.value = value;
|
||||
tv.mode = mode;
|
||||
map_set(&i->types, hash_pointer(expression), tv);
|
||||
}
|
||||
|
||||
@@ -522,7 +523,8 @@ void pop_procedure(Checker *c) {
|
||||
}
|
||||
|
||||
void add_curr_ast_file(Checker *c, AstFile *file) {
|
||||
gb_zero_item(&c->error_collector);
|
||||
TokenPos zero_pos = {};
|
||||
c->error_collector.prev = zero_pos;
|
||||
c->curr_ast_file = file;
|
||||
}
|
||||
|
||||
@@ -672,10 +674,12 @@ void check_parsed_files(Checker *c) {
|
||||
u64 key = entry->key;
|
||||
AstNode *expr = cast(AstNode *)cast(uintptr)key;
|
||||
ExpressionInfo *info = &entry->value;
|
||||
if (is_type_typed(info->type)) {
|
||||
GB_PANIC("%s (type %s) is typed!", expr_to_string(expr), info->type);
|
||||
if (info != NULL && expr != NULL) {
|
||||
if (is_type_typed(info->type)) {
|
||||
GB_PANIC("%s (type %s) is typed!", expr_to_string(expr), info->type);
|
||||
}
|
||||
add_type_and_value(&c->info, expr, info->mode, info->type, info->value);
|
||||
}
|
||||
add_type_and_value(&c->info, expr, info->mode, info->type, info->value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+21
-13
@@ -11,6 +11,7 @@ void convert_to_typed (Checker *c, Operand *operand, Type *targ
|
||||
gbString expr_to_string (AstNode *expression);
|
||||
void check_entity_decl (Checker *c, Entity *e, DeclInfo *decl, Type *named_type);
|
||||
void check_proc_body (Checker *c, Token token, DeclInfo *decl, Type *type, AstNode *body);
|
||||
void update_expr_type (Checker *c, AstNode *e, Type *type, b32 final);
|
||||
|
||||
|
||||
void check_struct_type(Checker *c, Type *struct_type, AstNode *node) {
|
||||
@@ -664,7 +665,10 @@ void check_comparison(Checker *c, Operand *x, Operand *y, Token op) {
|
||||
y->mode == Addressing_Constant) {
|
||||
x->value = make_exact_value_bool(compare_exact_values(op, x->value, y->value));
|
||||
} else {
|
||||
// TODO(bill): What should I do?
|
||||
x->mode = Addressing_Value;
|
||||
|
||||
update_expr_type(c, x->expr, default_type(x->type), true);
|
||||
update_expr_type(c, y->expr, default_type(y->type), true);
|
||||
}
|
||||
|
||||
x->type = t_untyped_bool;
|
||||
@@ -770,33 +774,35 @@ void check_binary_expr(Checker *c, Operand *x, AstNode *node) {
|
||||
}
|
||||
|
||||
|
||||
void update_expr_type(Checker *c, AstNode *e, Type *type) {
|
||||
ExpressionInfo *found = map_get(&c->info.untyped, hash_pointer(e));
|
||||
if (!found)
|
||||
void update_expr_type(Checker *c, AstNode *e, Type *type, b32 final) {
|
||||
u64 key = hash_pointer(e);
|
||||
ExpressionInfo *found = map_get(&c->info.untyped, key);
|
||||
if (found == NULL)
|
||||
return;
|
||||
|
||||
switch (e->kind) {
|
||||
case_ast_node(ue, UnaryExpr, e);
|
||||
if (found->value.kind != ExactValue_Invalid)
|
||||
break;
|
||||
update_expr_type(c, ue->expr, type);
|
||||
break;
|
||||
update_expr_type(c, ue->expr, type, final);
|
||||
case_end;
|
||||
|
||||
case_ast_node(be, BinaryExpr, e);
|
||||
if (found->value.kind != ExactValue_Invalid)
|
||||
break;
|
||||
if (!token_is_comparison(be->op)) {
|
||||
update_expr_type(c, be->left, type);
|
||||
update_expr_type(c, be->right, type);
|
||||
update_expr_type(c, be->left, type, final);
|
||||
update_expr_type(c, be->right, type, final);
|
||||
}
|
||||
case_end;
|
||||
}
|
||||
|
||||
if (is_type_untyped(type)) {
|
||||
if (!final && is_type_untyped(type)) {
|
||||
found->type = get_base_type(type);
|
||||
map_set(&c->info.untyped, key, *found);
|
||||
} else {
|
||||
found->type = type;
|
||||
map_remove(&c->info.untyped, key);
|
||||
add_type_and_value(&c->info, e, found->mode, type, found->value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -838,7 +844,7 @@ void convert_to_typed(Checker *c, Operand *operand, Type *target_type) {
|
||||
if (is_type_numeric(x) && is_type_numeric(y)) {
|
||||
if (x < y) {
|
||||
operand->type = target_type;
|
||||
update_expr_type(c, operand->expr, target_type);
|
||||
update_expr_type(c, operand->expr, target_type, false);
|
||||
}
|
||||
} else if (x != y) {
|
||||
convert_untyped_error(c, operand, target_type);
|
||||
@@ -1479,10 +1485,10 @@ b32 check_castable_to(Checker *c, Operand *operand, Type *y) {
|
||||
}
|
||||
|
||||
// []byte/[]u8 <-> string
|
||||
if (is_type_byte_slice(xb) && is_type_string(yb)) {
|
||||
if (is_type_u8_slice(xb) && is_type_string(yb)) {
|
||||
return true;
|
||||
}
|
||||
if (is_type_string(xb) && is_type_byte_slice(yb)) {
|
||||
if (is_type_string(xb) && is_type_u8_slice(yb)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1722,6 +1728,8 @@ ExpressionKind check__expr_base(Checker *c, Operand *o, AstNode *node, Type *typ
|
||||
if (o->mode == Addressing_Constant) {
|
||||
max_count = o->value.value_string.len;
|
||||
}
|
||||
if (o->mode != Addressing_Variable)
|
||||
o->mode = Addressing_Value;
|
||||
o->type = t_u8;
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -26,7 +26,7 @@ enum BasicKind {
|
||||
|
||||
Basic_Count,
|
||||
|
||||
Basic_byte = Basic_u8,
|
||||
// Basic_byte = Basic_u8,
|
||||
Basic_rune = Basic_i32,
|
||||
};
|
||||
|
||||
@@ -242,7 +242,7 @@ gb_global Type basic_types[] = {
|
||||
};
|
||||
|
||||
gb_global Type basic_type_aliases[] = {
|
||||
{Type_Basic, {Basic_byte, BasicFlag_Integer | BasicFlag_Unsigned, STR_LIT("byte")}},
|
||||
// {Type_Basic, {Basic_byte, BasicFlag_Integer | BasicFlag_Unsigned, STR_LIT("byte")}},
|
||||
{Type_Basic, {Basic_rune, BasicFlag_Integer, STR_LIT("rune")}},
|
||||
};
|
||||
|
||||
@@ -268,7 +268,7 @@ gb_global Type *t_untyped_float = &basic_types[Basic_UntypedFloat];
|
||||
gb_global Type *t_untyped_pointer = &basic_types[Basic_UntypedPointer];
|
||||
gb_global Type *t_untyped_string = &basic_types[Basic_UntypedString];
|
||||
gb_global Type *t_untyped_rune = &basic_types[Basic_UntypedRune];
|
||||
gb_global Type *t_byte = &basic_type_aliases[Basic_byte];
|
||||
// gb_global Type *t_byte = &basic_type_aliases[Basic_byte];
|
||||
gb_global Type *t_rune = &basic_type_aliases[Basic_rune];
|
||||
|
||||
|
||||
@@ -343,9 +343,9 @@ b32 is_type_rawptr(Type *t) {
|
||||
return t->basic.kind == Basic_rawptr;
|
||||
return false;
|
||||
}
|
||||
b32 is_type_byte(Type *t) {
|
||||
b32 is_type_u8(Type *t) {
|
||||
if (t->kind == Type_Basic)
|
||||
return t->basic.kind == Basic_byte;
|
||||
return t->basic.kind == Basic_u8;
|
||||
return false;
|
||||
}
|
||||
b32 is_type_slice(Type *t) {
|
||||
@@ -353,9 +353,9 @@ b32 is_type_slice(Type *t) {
|
||||
}
|
||||
|
||||
|
||||
b32 is_type_byte_slice(Type *t) {
|
||||
b32 is_type_u8_slice(Type *t) {
|
||||
if (t->kind == Type_Slice)
|
||||
return is_type_byte(t->slice.elem);
|
||||
return is_type_u8(t->slice.elem);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user