add constcast and immutable free
This commit is contained in:
@@ -1340,6 +1340,45 @@ replace_pointer_child :: proc(store: ^Store, value, child: Type) -> (Type, bool)
|
||||
return intern(store, item), true
|
||||
}
|
||||
|
||||
restore_mutability :: proc(store: ^Store, value: Type) -> (Type, bool) {
|
||||
item, ok := node(store, resolve_alias(value, store))
|
||||
if !ok {
|
||||
return INVALID, false
|
||||
}
|
||||
if item.kind == .Optional {
|
||||
restored, restored_ok := restore_mutability(store, item.child)
|
||||
if !restored_ok || !is_pointer(restored, store) {
|
||||
return INVALID, false
|
||||
}
|
||||
return optional(store, restored), true
|
||||
}
|
||||
if item.kind != .Pointer && item.kind != .Slice {
|
||||
return INVALID, false
|
||||
}
|
||||
item.mutable = true
|
||||
return intern(store, item), true
|
||||
}
|
||||
|
||||
same_constcast_shape :: proc(from, to: Type, store: ^Store) -> bool {
|
||||
from_item, from_ok := node(store, resolve_alias(from, store))
|
||||
to_item, to_ok := node(store, resolve_alias(to, store))
|
||||
if !from_ok || !to_ok {
|
||||
return false
|
||||
}
|
||||
if from_item.kind == .Optional || to_item.kind == .Optional {
|
||||
return from_item.kind == .Optional && to_item.kind == .Optional &&
|
||||
is_pointer(from_item.child, store) && is_pointer(to_item.child, store) &&
|
||||
same_constcast_shape(from_item.child, to_item.child, store)
|
||||
}
|
||||
return (from_item.kind == .Pointer || from_item.kind == .Slice) &&
|
||||
from_item.kind == to_item.kind &&
|
||||
from_item.child == to_item.child &&
|
||||
from_item.many == to_item.many &&
|
||||
to_item.mutable &&
|
||||
from_item.has_sentinel == to_item.has_sentinel &&
|
||||
(!from_item.has_sentinel || from_item.sentinel == to_item.sentinel)
|
||||
}
|
||||
|
||||
same_pointer_shape :: proc(left, right: Type, store: ^Store) -> bool {
|
||||
left_item, left_ok := node(store, left)
|
||||
right_item, right_ok := node(store, right)
|
||||
|
||||
Reference in New Issue
Block a user