From 215a0c6ce97f300c51bce2293b4497b208992aac Mon Sep 17 00:00:00 2001 From: Jean Privat Date: Thu, 24 Jul 2014 14:46:33 -0400 Subject: [PATCH] src: use `as_notnullable` in code Basically replace ~~~ if m isa MNullableType then m = m.mtype ~~~ by ~~~ m = m.as_notnullable ~~~ Signed-off-by: Jean Privat --- src/highlight.nit | 2 +- src/metrics/rta_metrics.nit | 5 ++--- src/model/model.nit | 6 +++--- src/modelize_property.nit | 2 +- src/nitni/nitni_callbacks.nit | 2 +- src/rapid_type_analysis.nit | 4 ++-- src/separate_compiler.nit | 13 +++---------- src/typing.nit | 8 +++----- 8 files changed, 16 insertions(+), 26 deletions(-) diff --git a/src/highlight.nit b/src/highlight.nit index 07f5ed9..bfa0d0f 100644 --- a/src/highlight.nit +++ b/src/highlight.nit @@ -858,7 +858,7 @@ redef class AType do var mt = mtype if mt == null then return null - if mt isa MNullableType then mt = mt.mtype + mt = mt.as_notnullable if mt isa MVirtualType or mt isa MParameterType then res.add_class("nc_vt") end diff --git a/src/metrics/rta_metrics.nit b/src/metrics/rta_metrics.nit index 40408f3..1224513 100644 --- a/src/metrics/rta_metrics.nit +++ b/src/metrics/rta_metrics.nit @@ -376,7 +376,7 @@ redef class RapidTypeAnalysis super tnlc.values.inc(mtype) - if mtype isa MNullableType then mtype = mtype.mtype + mtype = mtype.as_notnullable if mtype isa MClassType then cnlc.values.inc(mtype.mclass) end @@ -387,8 +387,7 @@ end redef class MType private fun signature_depth: Int do - var mtype = self - if mtype isa MNullableType then mtype = mtype.mtype + var mtype = self.as_notnullable if not mtype isa MGenericType then return 0 var depth = 0 diff --git a/src/model/model.nit b/src/model/model.nit index f69f4c4..2a5a092 100644 --- a/src/model/model.nit +++ b/src/model/model.nit @@ -1647,7 +1647,7 @@ abstract class MProperty fun lookup_definitions(mmodule: MModule, mtype: MType): Array[MPROPDEF] do assert not mtype.need_anchor - if mtype isa MNullableType then mtype = mtype.mtype + mtype = mtype.as_notnullable var cache = self.lookup_definitions_cache[mmodule, mtype] if cache != null then return cache @@ -1686,7 +1686,7 @@ abstract class MProperty fun lookup_super_definitions(mmodule: MModule, mtype: MType): Array[MPROPDEF] do assert not mtype.need_anchor - if mtype isa MNullableType then mtype = mtype.mtype + mtype = mtype.as_notnullable # First, select all candidates var candidates = new Array[MPROPDEF] @@ -1763,7 +1763,7 @@ abstract class MProperty fun lookup_all_definitions(mmodule: MModule, mtype: MType): Array[MPROPDEF] do assert not mtype.need_anchor - if mtype isa MNullableType then mtype = mtype.mtype + mtype = mtype.as_notnullable var cache = self.lookup_all_definitions_cache[mmodule, mtype] if cache != null then return cache diff --git a/src/modelize_property.nit b/src/modelize_property.nit index cc11d50..8273fb8 100644 --- a/src/modelize_property.nit +++ b/src/modelize_property.nit @@ -187,7 +187,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 origial module of the type - if mtype isa MNullableType then mtype = mtype.mtype + mtype = mtype.as_notnullable 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 604f4f9..cb75bc8 100644 --- a/src/nitni/nitni_callbacks.nit +++ b/src/nitni/nitni_callbacks.nit @@ -411,7 +411,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) - if mtype isa MNullableType then return mtype.mtype + mtype = mtype.as_notnullable return mtype end diff --git a/src/rapid_type_analysis.nit b/src/rapid_type_analysis.nit index b2683c2..17d5e0c 100644 --- a/src/rapid_type_analysis.nit +++ b/src/rapid_type_analysis.nit @@ -88,7 +88,7 @@ class RapidTypeAnalysis var mtype = callsite.recv var anchor = callsite.anchor if anchor != null then mtype = mtype.anchor_to(callsite.mmodule, anchor) - if mtype isa MNullableType then mtype = mtype.mtype + mtype = mtype.as_notnullable assert mtype isa MClassType mtype = mtype.mclass.intro.bound_mtype var mproperty = callsite.mproperty @@ -457,7 +457,7 @@ class RapidTypeVisitor do mtype = mtype.anchor_to(self.analysis.mainmodule, self.receiver) if mtype isa MNullType then return null - if mtype isa MNullableType then mtype = mtype.mtype + mtype = mtype.as_notnullable assert mtype isa MClassType assert not mtype.need_anchor return mtype diff --git a/src/separate_compiler.nit b/src/separate_compiler.nit index bf3cb12..273451f 100644 --- a/src/separate_compiler.nit +++ b/src/separate_compiler.nit @@ -590,8 +590,7 @@ class SeparateCompiler # resolution table (for receiver) if is_live then - var mclass_type = mtype - if mclass_type isa MNullableType then mclass_type = mclass_type.mtype + var mclass_type = mtype.as_notnullable assert mclass_type isa MClassType if resolution_tables[mclass_type].is_empty then v.add_decl("NULL, /*NO RESOLUTIONS*/") @@ -624,12 +623,7 @@ class SeparateCompiler fun compile_type_resolution_table(mtype: MType) do - var mclass_type: MClassType - if mtype isa MNullableType then - mclass_type = mtype.mtype.as(MClassType) - else - mclass_type = mtype.as(MClassType) - end + var mclass_type = mtype.as_notnullable.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};") @@ -1585,8 +1579,7 @@ class SeparateCompilerVisitor fun can_be_primitive(value: RuntimeVariable): Bool do - var t = value.mcasttype - if t isa MNullableType then t = t.mtype + var t = value.mcasttype.as_notnullable if not t isa MClassType then return false var k = t.mclass.kind return k == interface_kind or t.ctype != "val*" diff --git a/src/typing.nit b/src/typing.nit index 2223131..d2cc5fa 100644 --- a/src/typing.nit +++ b/src/typing.nit @@ -284,7 +284,7 @@ private class TypeVisitor var erasure_cast = false var rettype = mpropdef.msignature.return_mtype if not recv_is_self and rettype != null then - if rettype isa MNullableType then rettype = rettype.mtype + rettype = rettype.as_notnullable if rettype isa MParameterType then var erased_rettype = msignature.return_mtype assert erased_rettype != null @@ -905,7 +905,7 @@ redef class AForExpr # anchor formal and virtual types if mtype.need_anchor then mtype = v.anchor_to(mtype) - if mtype isa MNullableType then mtype = mtype.mtype + mtype = mtype.as_notnullable self.coltype = mtype.as(MClassType) # get methods is_ok, next, item @@ -1008,9 +1008,7 @@ redef class AOrElseExpr return # Skip error end - if t1 isa MNullableType then - t1 = t1.mtype - end + t1 = t1.as_notnullable var t = v.merge_types(self, [t1, t2]) if t == null then -- 1.7.9.5