aboutsummaryrefslogtreecommitdiff
path: root/src/check_builtin.cpp
diff options
context:
space:
mode:
authorgingerBill <gingerBill@users.noreply.github.com>2025-08-06 16:09:18 +0100
committerGitHub <noreply@github.com>2025-08-06 16:09:18 +0100
commit09a1e170bc92a0ea48a8ee67599c2936e924fe4d (patch)
tree92b44b34a1f2f0c4a8c96a49ab61bb5177432ed7 /src/check_builtin.cpp
parentec7509430369eb5d57a081507792dc03b1c05bab (diff)
parentaf3184adc96cef59fff986ea6400caa6dbdb56ae (diff)
Merge pull request #5530 from odin-lang/bill/utf16-strings
UTF-16 string types: `string16` & `cstring16`
Diffstat (limited to 'src/check_builtin.cpp')
-rw-r--r--src/check_builtin.cpp26
1 files changed, 22 insertions, 4 deletions
diff --git a/src/check_builtin.cpp b/src/check_builtin.cpp
index 880de73f5..57413f519 100644
--- a/src/check_builtin.cpp
+++ b/src/check_builtin.cpp
@@ -19,6 +19,7 @@ gb_global BuiltinTypeIsProc *builtin_type_is_procs[BuiltinProc__type_simple_bool
is_type_complex,
is_type_quaternion,
is_type_string,
+ is_type_string16,
is_type_typeid,
is_type_any,
is_type_endian_platform,
@@ -2328,13 +2329,23 @@ gb_internal bool check_builtin_procedure(CheckerContext *c, Operand *operand, As
if (is_type_string(op_type) && id == BuiltinProc_len) {
if (operand->mode == Addressing_Constant) {
mode = Addressing_Constant;
- String str = operand->value.value_string;
- value = exact_value_i64(str.len);
+
+ if (operand->value.kind == ExactValue_String) {
+ String str = operand->value.value_string;
+ value = exact_value_i64(str.len);
+ } else if (operand->value.kind == ExactValue_String16) {
+ String16 str = operand->value.value_string16;
+ value = exact_value_i64(str.len);
+ } else {
+ GB_PANIC("Unhandled value kind: %d", operand->value.kind);
+ }
type = t_untyped_integer;
} else {
mode = Addressing_Value;
if (is_type_cstring(op_type)) {
add_package_dependency(c, "runtime", "cstring_len");
+ } else if (is_type_cstring16(op_type)) {
+ add_package_dependency(c, "runtime", "cstring16_len");
}
}
} else if (is_type_array(op_type)) {
@@ -4684,7 +4695,9 @@ gb_internal bool check_builtin_procedure(CheckerContext *c, Operand *operand, As
break;
case Type_Basic:
if (t->Basic.kind == Basic_string) {
- operand->type = alloc_type_multi_pointer(t_u8);
+ operand->type = t_u8_multi_ptr;
+ } else if (t->Basic.kind == Basic_string16) {
+ operand->type = t_u16_multi_ptr;
}
break;
case Type_Pointer:
@@ -6133,6 +6146,7 @@ gb_internal bool check_builtin_procedure(CheckerContext *c, Operand *operand, As
case BuiltinProc_type_is_complex:
case BuiltinProc_type_is_quaternion:
case BuiltinProc_type_is_string:
+ case BuiltinProc_type_is_string16:
case BuiltinProc_type_is_typeid:
case BuiltinProc_type_is_any:
case BuiltinProc_type_is_endian_platform:
@@ -7172,7 +7186,11 @@ gb_internal bool check_builtin_procedure(CheckerContext *c, Operand *operand, As
return false;
}
operand->mode = Addressing_Value;
- operand->type = alloc_type_multi_pointer(t_u16);
+ if (type_hint != nullptr && is_type_cstring16(type_hint)) {
+ operand->type = type_hint;
+ } else {
+ operand->type = alloc_type_multi_pointer(t_u16);
+ }
operand->value = {};
break;
}