From 1e632f109c75bd2a78a0d742c33431c9168969ec Mon Sep 17 00:00:00 2001 From: Jean Privat Date: Sat, 4 Apr 2015 20:35:41 +0700 Subject: [PATCH] model: rename `as_notnullable` to `undecorate` The behavior is to remove the decoration, and `as_notnullabe` is not the best name to undecorate a `MNotNullType` Signed-off-by: Jean Privat --- src/compiler/abstract_compiler.nit | 2 +- src/compiler/separate_compiler.nit | 12 ++++++------ src/highlight.nit | 2 +- src/metrics/detect_covariance.nit | 8 ++++---- src/metrics/detect_variance_constraints.nit | 12 ++++++------ src/metrics/rta_metrics.nit | 4 ++-- src/model/model.nit | 24 +++++++++++++----------- src/modelize/modelize_property.nit | 2 +- src/nitni/nitni_callbacks.nit | 2 +- src/rapid_type_analysis.nit | 4 ++-- src/semantize/typing.nit | 4 ++-- 11 files changed, 39 insertions(+), 37 deletions(-) diff --git a/src/compiler/abstract_compiler.nit b/src/compiler/abstract_compiler.nit index 894a13d..3956744 100644 --- a/src/compiler/abstract_compiler.nit +++ b/src/compiler/abstract_compiler.nit @@ -2370,7 +2370,7 @@ redef class AAttrPropdef 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 diff --git a/src/compiler/separate_compiler.nit b/src/compiler/separate_compiler.nit index dab4a79..34e7be4 100644 --- a/src/compiler/separate_compiler.nit +++ b/src/compiler/separate_compiler.nit @@ -458,14 +458,14 @@ class SeparateCompiler 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 @@ -510,7 +510,7 @@ class SeparateCompiler # 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 @@ -742,7 +742,7 @@ class SeparateCompiler # 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*/") @@ -775,7 +775,7 @@ class SeparateCompiler 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};") @@ -2006,7 +2006,7 @@ class SeparateCompilerVisitor 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 diff --git a/src/highlight.nit b/src/highlight.nit index f4268c0..e6ca8ea 100644 --- a/src/highlight.nit +++ b/src/highlight.nit @@ -870,7 +870,7 @@ redef class AType 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 diff --git a/src/metrics/detect_covariance.nit b/src/metrics/detect_covariance.nit index 5bb2aea..9090658 100644 --- a/src/metrics/detect_covariance.nit +++ b/src/metrics/detect_covariance.nit @@ -130,8 +130,8 @@ private class DetectCovariancePhase # 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 @@ -254,8 +254,8 @@ private class DetectCovariancePhase 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!?!") diff --git a/src/metrics/detect_variance_constraints.nit b/src/metrics/detect_variance_constraints.nit index 3665376..1f0205e 100644 --- a/src/metrics/detect_variance_constraints.nit +++ b/src/metrics/detect_variance_constraints.nit @@ -113,7 +113,7 @@ class DetectVarianceConstraints 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 @@ -129,7 +129,7 @@ class DetectVarianceConstraints # 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 @@ -144,7 +144,7 @@ class DetectVarianceConstraints # 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 @@ -161,7 +161,7 @@ class DetectVarianceConstraints # 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 @@ -223,7 +223,7 @@ class DetectVarianceConstraints # 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] @@ -259,7 +259,7 @@ class DetectVarianceConstraints # 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] diff --git a/src/metrics/rta_metrics.nit b/src/metrics/rta_metrics.nit index 1527731..00f9d02 100644 --- a/src/metrics/rta_metrics.nit +++ b/src/metrics/rta_metrics.nit @@ -374,7 +374,7 @@ redef class RapidTypeAnalysis super tnlc.values.inc(mtype) - mtype = mtype.as_notnullable + mtype = mtype.undecorate if mtype isa MClassType then cnlc.values.inc(mtype.mclass) end @@ -385,7 +385,7 @@ 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 diff --git a/src/model/model.nit b/src/model/model.nit index a391ea4..6dbcda1 100644 --- a/src/model/model.nit +++ b/src/model/model.nit @@ -998,12 +998,14 @@ abstract class MType 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 @@ -1329,7 +1331,7 @@ class MVirtualType 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) @@ -1438,7 +1440,7 @@ class MParameterType 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 @@ -1466,7 +1468,7 @@ class MParameterType 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 @@ -1551,7 +1553,7 @@ abstract class MProxyType 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) @@ -1885,7 +1887,7 @@ abstract class MProperty 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 @@ -1925,7 +1927,7 @@ abstract class MProperty 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] @@ -2003,7 +2005,7 @@ abstract class MProperty # 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 diff --git a/src/modelize/modelize_property.nit b/src/modelize/modelize_property.nit index bb0184f..f5b33af 100644 --- a/src/modelize/modelize_property.nit +++ b/src/modelize/modelize_property.nit @@ -350,7 +350,7 @@ redef class ModelBuilder # 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 diff --git a/src/nitni/nitni_callbacks.nit b/src/nitni/nitni_callbacks.nit index 8542a95..210a4b5 100644 --- a/src/nitni/nitni_callbacks.nit +++ b/src/nitni/nitni_callbacks.nit @@ -422,7 +422,7 @@ redef class AAsNotNullableExternCall 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 diff --git a/src/rapid_type_analysis.nit b/src/rapid_type_analysis.nit index 69e9023..73cc176 100644 --- a/src/rapid_type_analysis.nit +++ b/src/rapid_type_analysis.nit @@ -93,7 +93,7 @@ class RapidTypeAnalysis 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] @@ -465,7 +465,7 @@ class RapidTypeVisitor 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 diff --git a/src/semantize/typing.nit b/src/semantize/typing.nit index f4d851e..a1f1220 100644 --- a/src/semantize/typing.nit +++ b/src/semantize/typing.nit @@ -362,7 +362,7 @@ private class TypeVisitor 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 @@ -1030,7 +1030,7 @@ redef class AForExpr # 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 -- 1.7.9.5