Various minor refactorings done for PR #2397.
Pull-Request: #2398
Reviewed-by: Jean Privat <jean@pryen.org>
# Checks
# Can value be null? (according to current knowledge)
- fun maybenull(value: RuntimeVariable): Bool
+ fun maybe_null(value: RuntimeVariable): Bool
do
return value.mcasttype isa MNullableType or value.mcasttype isa MNullType
end
do
if self.compiler.modelbuilder.toolcontext.opt_no_check_null.value then return
- if maybenull(recv) then
+ if maybe_null(recv) then
self.add("if (unlikely({recv} == NULL)) \{")
self.add_abort("Receiver is null")
self.add("\}")
assert arguments.length == 2
var recv = arguments.first
var arg = arguments[1]
- if is_optional and v.maybenull(arg) then
+ if is_optional and v.maybe_null(arg) then
var value = v.new_var(self.mpropdef.static_mtype.as(not null))
v.add("if ({arg} == NULL) \{")
v.assign(value, evaluate_expr(v, recv))
var res = v.new_var(self.mtype.as(not null))
var i1 = v.expr(self.n_expr, null)
- if not v.maybenull(i1) then return i1
+ if not v.maybe_null(i1) then return i1
v.add("if ({i1}!=NULL) \{")
v.assign(res, i1)
var i = v.expr(self.n_expr, null)
if v.compiler.modelbuilder.toolcontext.opt_no_check_assert.value then return i
- if not v.maybenull(i) then return i
+ if not v.maybe_null(i) then return i
v.add("if (unlikely({i} == NULL)) \{")
v.add_abort("Cast failed")
# Is the associated Java type a primitive one?
#
- # ENSURE `result == (java_type != "Object")`
+ # ENSURE `result == (java_type != "RTVal")`
var is_java_primitive: Bool is lazy do return java_type != "RTVal"
end
var res: nullable RuntimeVariable = null
var recv = arguments.first
var consider_null = not self.compiler.modelbuilder.toolcontext.opt_no_check_null.value or mmethod.name == "==" or mmethod.name == "!="
- if maybenull(recv) and consider_null then
+ if maybe_null(recv) and consider_null then
self.add("if ({recv} == NULL) \{")
if mmethod.name == "==" or mmethod.name == "is_same_instance" then
res = self.new_var(bool_type)
return k == interface_kind or t.is_c_primitive
end
- fun maybe_null(value: RuntimeVariable): Bool
- do
- var t = value.mcasttype
- return t isa MNullableType or t isa MNullType
- end
-
redef fun array_instance(array, elttype)
do
var nclass = mmodule.native_array_class
# The only null type
var null_type = new MNullType(self)
+ # The only bottom type
+ var bottom_type: MBottomType = null_type.as_notnull
+
# Build an ordered tree with from `concerns`
fun concerns_tree(mconcerns: Collection[MConcern]): ConcernsTree do
var seen = new HashSet[MConcern]
#
# Explanation of the example:
# In H, T is set to B, because "H super G[B]", and U is bound to Y,
- # because "redef type U: Y". Therefore, Map[T, U] is bound to
+ # because "redef type U: Y". Therefore, Map[T, U] is bound to
# Map[B, Y]
#
+ # REQUIRE: `self.need_anchor implies anchor != null`
# ENSURE: `not self.need_anchor implies result == self`
# ENSURE: `not result.need_anchor`
- fun anchor_to(mmodule: MModule, anchor: MClassType): MType
+ fun anchor_to(mmodule: MModule, anchor: nullable MClassType): MType
do
if not need_anchor then return self
- assert not anchor.need_anchor
+ assert anchor != null and not anchor.need_anchor
# Just resolve to the anchor and clear all the virtual types
var res = self.resolve_for(anchor, null, mmodule, true)
assert not res.need_anchor
# * H[G[A], B] -> 3
#
# Formal types have a depth of 1.
+ # Only `MClassType` and `MFormalType` nodes are counted.
fun depth: Int
do
return 1
# * H[G[A], B] -> 4
#
# Formal types have a length of 1.
+ # Only `MClassType` and `MFormalType` nodes are counted.
fun length: Int
do
return 1
redef fun need_anchor do return false
- redef fun anchor_to(mmodule: MModule, anchor: MClassType): MClassType
+ redef fun anchor_to(mmodule, anchor): MClassType
do
return super.as(MClassType)
end
redef fun c_name do return "null"
redef fun as_nullable do return self
- redef var as_notnull = new MBottomType(model) is lazy
+ redef var as_notnull: MBottomType = new MBottomType(model) is lazy
redef fun need_anchor do return false
redef fun resolve_for(mtype, anchor, mmodule, cleanup_virtual) do return self
redef fun can_resolve_for(mtype, anchor, mmodule) do return true
fun anchor_to(mtype: MType): MType
do
- var anchor = anchor
- if anchor == null then
- assert not mtype.need_anchor
- return mtype
- end
return mtype.anchor_to(mmodule, anchor)
end