var oldnode = v.current_node
v.current_node = self
var old_frame = v.frame
- var frame = new StaticFrame(v, self.mpropdef.as(not null), recv.mcasttype.as_notnullable.as(MClassType), [recv])
+ var frame = new StaticFrame(v, self.mpropdef.as(not null), recv.mcasttype.undecorate.as(MClassType), [recv])
v.frame = frame
var value
var mtypes_by_class = new MultiHashMap[MClass, MType]
for e in mtypes do
- var c = e.as_notnullable.as(MClassType).mclass
+ var c = e.undecorate.as(MClassType).mclass
mtypes_by_class[c].add(e)
poset.add_node(e)
end
var casttypes_by_class = new MultiHashMap[MClass, MType]
for e in cast_types do
- var c = e.as_notnullable.as(MClassType).mclass
+ var c = e.undecorate.as(MClassType).mclass
casttypes_by_class[c].add(e)
poset.add_node(e)
end
# Group cast_type by their classes
var bucklets = new HashMap[MClass, Set[MType]]
for e in cast_types do
- var c = e.as_notnullable.as(MClassType).mclass
+ var c = e.undecorate.as(MClassType).mclass
if not bucklets.has_key(c) then
bucklets[c] = new HashSet[MType]
end
# resolution table (for receiver)
if is_live then
- var mclass_type = mtype.as_notnullable
+ var mclass_type = mtype.undecorate
assert mclass_type isa MClassType
if resolution_tables[mclass_type].is_empty then
v.add_decl("NULL, /*NO RESOLUTIONS*/")
fun compile_type_resolution_table(mtype: MType) do
- var mclass_type = mtype.as_notnullable.as(MClassType)
+ var mclass_type = mtype.undecorate.as(MClassType)
# extern const struct resolution_table_X resolution_table_X
self.provide_declaration("resolution_table_{mtype.c_name}", "extern const struct types resolution_table_{mtype.c_name};")
fun can_be_primitive(value: RuntimeVariable): Bool
do
- var t = value.mcasttype.as_notnullable
+ var t = value.mcasttype.undecorate
if not t isa MClassType then return false
var k = t.mclass.kind
return k == interface_kind or t.is_c_primitive
do
var mt = mtype
if mt == null then return null
- mt = mt.as_notnullable
+ mt = mt.undecorate
if mt isa MFormalType then
res.add_class("nc_vt")
end
# Returns true if the test concern real generic covariance
fun count_types(node, elem: ANode, sub, sup: MType, mmodule: MModule, anchor: nullable MClassType): Bool
do
- sub = sub.as_notnullable
- sup = sup.as_notnullable
+ sub = sub.undecorate
+ sup = sup.undecorate
# Category of the target type
if sub isa MGenericType then
fun count_cast(node: ANode, sub, sup: MType, mmodule: MModule, anchor: nullable MClassType)
do
var nsup = sup
- sup = sup.as_notnullable
- sub = sub.as_notnullable
+ sup = sup.undecorate
+ sub = sub.undecorate
if sub == nsup then
cpt_cast_pattern.inc("monomorphic cast!?!")
if pd isa MMethodDef then
# Parameters (contravariant)
for p in pd.msignature.mparameters do
- var t = p.mtype.as_notnullable
+ var t = p.mtype.undecorate
if not t.need_anchor then
# OK
else if t isa MParameterType then
# Return (covariant)
var t = pd.msignature.return_mtype
if t != null and t.need_anchor then
- t = t.as_notnullable
+ t = t.undecorate
if t isa MParameterType then
covar_pt.add(t)
else if t isa MVirtualType then
# Attribute (invariant)
var t = pd.static_mtype
if t != null and t.need_anchor then
- t = t.as_notnullable
+ t = t.undecorate
if t isa MParameterType then
covar_pt.add t
contravar_pt.add t
# Virtual type bound (covariant)
var t = pd.bound
if t != null and t.need_anchor then
- t = t.as_notnullable
+ t = t.undecorate
if t isa MParameterType then
covar_pt.add t
else if t isa MVirtualType then
# Process the generic types in a covariant position
for c in covar_classes do for i in [0..c.mclass.arity[ do
# The type used in the argument
- var ta = c.arguments[i].as_notnullable
+ var ta = c.arguments[i].undecorate
# The associated formal parameter
var tp = c.mclass.mparameters[i]
# Process the generic types in a contravariant position
for c in contravar_classes do for i in [0..c.mclass.arity[ do
# The type used in the argument
- var ta = c.arguments[i].as_notnullable
+ var ta = c.arguments[i].undecorate
# The associated formal parameter
var tp = c.mclass.mparameters[i]
super
tnlc.values.inc(mtype)
- mtype = mtype.as_notnullable
+ mtype = mtype.undecorate
if mtype isa MClassType then
cnlc.values.inc(mtype.mclass)
end
redef class MType
private fun signature_depth: Int do
- var mtype = self.as_notnullable
+ var mtype = self.undecorate
if not mtype isa MGenericType then return 0
var depth = 0
return res
end
- # Return the not nullable version of the type
- # Is the type is already not nullable, then self is returned.
+ # Remove the base type of a decorated (proxy) type.
+ # Is the type is not decorated, then self is returned.
#
- # Note: this just remove the `nullable` notation, but the result can still contains null.
+ # Most of the time it is used to return the not nullable version of a nullable type.
+ # In this case, this just remove the `nullable` notation, but the result can still contains null.
# For instance if `self isa MNullType` or self is a formal type bounded by a nullable type.
- fun as_notnullable: MType
+ # If you really want to exclude the `null` value, then use `as_notnull`
+ fun undecorate: MType
do
return self
end
redef fun lookup_fixed(mmodule: MModule, resolved_receiver: MType): MType
do
assert not resolved_receiver.need_anchor
- resolved_receiver = resolved_receiver.as_notnullable
+ resolved_receiver = resolved_receiver.undecorate
assert resolved_receiver isa MClassType # It is the only remaining type
var prop = lookup_single_definition(mmodule, resolved_receiver)
redef fun lookup_bound(mmodule: MModule, resolved_receiver: MType): MType
do
assert not resolved_receiver.need_anchor
- resolved_receiver = resolved_receiver.as_notnullable
+ resolved_receiver = resolved_receiver.undecorate
assert resolved_receiver isa MClassType # It is the only remaining type
var goalclass = self.mclass
if resolved_receiver.mclass == goalclass then
redef fun lookup_fixed(mmodule: MModule, resolved_receiver: MType): MType
do
assert not resolved_receiver.need_anchor
- resolved_receiver = resolved_receiver.as_notnullable
+ resolved_receiver = resolved_receiver.undecorate
assert resolved_receiver isa MClassType # It is the only remaining type
var res = self.resolve_for(resolved_receiver.mclass.mclass_type, resolved_receiver, mmodule, false)
return res
redef fun need_anchor do return mtype.need_anchor
redef fun as_nullable do return mtype.as_nullable
redef fun as_notnull do return mtype.as_notnull
- redef fun as_notnullable do return mtype.as_notnullable
+ redef fun undecorate do return mtype.undecorate
redef fun resolve_for(mtype, anchor, mmodule, cleanup_virtual)
do
var res = self.mtype.resolve_for(mtype, anchor, mmodule, cleanup_virtual)
fun lookup_definitions(mmodule: MModule, mtype: MType): Array[MPROPDEF]
do
assert not mtype.need_anchor
- mtype = mtype.as_notnullable
+ mtype = mtype.undecorate
var cache = self.lookup_definitions_cache[mmodule, mtype]
if cache != null then return cache
fun lookup_super_definitions(mmodule: MModule, mtype: MType): Array[MPROPDEF]
do
assert not mtype.need_anchor
- mtype = mtype.as_notnullable
+ mtype = mtype.undecorate
# First, select all candidates
var candidates = new Array[MPROPDEF]
# REQUIRE: `mtype.has_mproperty(mmodule, self)`
fun lookup_all_definitions(mmodule: MModule, mtype: MType): Array[MPROPDEF]
do
- mtype = mtype.as_notnullable
+ mtype = mtype.undecorate
var cache = self.lookup_all_definitions_cache[mmodule, mtype]
if cache != null then return cache
# It is a case-by case
var vis_type: nullable MVisibility = null # The own visibility of the type
var mmodule_type: nullable MModule = null # The original module of the type
- mtype = mtype.as_notnullable
+ mtype = mtype.undecorate
if mtype isa MClassType then
vis_type = mtype.mclass.visibility
mmodule_type = mtype.mclass.intro.mmodule
redef fun from_mtype do return n_type.mtype.as_nullable
redef fun to_mtype do
var mtype = n_type.mtype.as(not null)
- mtype = mtype.as_notnullable
+ mtype = mtype.undecorate
return mtype
end
var mtype = callsite.recv
var anchor = callsite.anchor
if anchor != null then mtype = mtype.anchor_to(callsite.mmodule, anchor)
- mtype = mtype.as_notnullable
+ mtype = mtype.undecorate
if mtype isa MClassType then mtype = mtype.mclass.intro.bound_mtype
var mproperty = callsite.mproperty
var res = live_targets_cache[mtype, mproperty]
do
mtype = mtype.anchor_to(self.analysis.mainmodule, self.receiver)
if mtype isa MNullType then return null
- mtype = mtype.as_notnullable
+ mtype = mtype.undecorate
assert mtype isa MClassType
assert not mtype.need_anchor
return mtype
var erasure_cast = false
var rettype = mpropdef.msignature.return_mtype
if not recv_is_self and rettype != null then
- rettype = rettype.as_notnullable
+ rettype = rettype.undecorate
if rettype isa MParameterType then
var erased_rettype = msignature.return_mtype
assert erased_rettype != null
# anchor formal and virtual types
if mtype.need_anchor then mtype = v.anchor_to(mtype)
- mtype = mtype.as_notnullable
+ mtype = mtype.undecorate
self.coltype = mtype.as(MClassType)
# get methods is_ok, next, item