From 48d0866748f10e30763770e92689bdced41194e0 Mon Sep 17 00:00:00 2001 From: Jean Privat Date: Thu, 11 Jun 2009 09:26:26 -0400 Subject: [PATCH] metamodel: fix and comment upcast_for Signed-off-by: Jean Privat --- src/metamodel/genericity.nit | 2 +- src/metamodel/static_type.nit | 29 ++++++++++++++++++++++++----- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/metamodel/genericity.nit b/src/metamodel/genericity.nit index 112212e..dfff8c3 100644 --- a/src/metamodel/genericity.nit +++ b/src/metamodel/genericity.nit @@ -216,7 +216,7 @@ special MMTypeFormal return t end - redef meth upcast_for(c) do return self + redef meth upcast_for(c) do return _bound.upcast_for(c) meth bound=(t: MMType) do diff --git a/src/metamodel/static_type.nit b/src/metamodel/static_type.nit index 0516f4f..25b41f8 100644 --- a/src/metamodel/static_type.nit +++ b/src/metamodel/static_type.nit @@ -325,6 +325,24 @@ abstract class MMType # Adapt self to another local class context # Useful for genericity + # 'c' Must be a super-class of self + # Example: + # class A[E] + # class B[F] special A[F] + # class C[G] special B[String] + # class D special C[Float] + # 'A[Int]'.upcast_for('A') -> 'A[Int]' + # 'A[Int]'.upcast_for('B') -> abort + # 'B[Int]'.upcast_for('B') -> 'B[Int]' + # 'B[Int]'.upcast_for('A') -> 'A[Int]' + # 'B[Int]'.upcast_for('C') -> abort + # 'C[Int]'.upcast_for('C') -> 'C[Int]' + # 'C[Int]'.upcast_for('B') -> 'B[String]' + # 'C[Int]'.upcast_for('A') -> 'A[String]' + # 'D'.upcast_for('D') -> 'D' + # 'D'.upcast_for('C') -> 'C[Float]' + # 'D'.upcast_for('B') -> 'C[String]' + # 'D'.upcast_for('A') -> 'A[String]' meth upcast_for(c: MMLocalClass): MMType is abstract # Return a type approximation if the reveiver is not self @@ -390,11 +408,12 @@ end # The type of null class MMTypeNone special MMType - redef readable attr _module: MMModule - redef meth <(t) do return true - redef meth is_supertype(t) do return false - redef meth local_class do abort - redef meth upcast_for(c) do return self + redef readable attr _module: MMModule + redef meth <(t) do return true + redef meth to_s do return "null" + redef meth is_supertype(t) do return false + redef meth local_class do abort + redef meth upcast_for(c) do abort private init(m: MMModule) do _module = m end -- 1.7.9.5