[svn] r7469: vs-plugin/trunk/Nemerle.Compiler.Utils/Utils.n
IT
svnadmin at nemerle.org
Thu Feb 22 22:40:03 CET 2007
Log:
Fixed type recursion (bug #912).
Author: IT
Date: Thu Feb 22 22:40:01 2007
New Revision: 7469
Modified:
vs-plugin/trunk/Nemerle.Compiler.Utils/Utils.n
Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Utils.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Utils.n (original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Utils.n Thu Feb 22 22:40:01 2007
@@ -161,26 +161,56 @@
public static ToDisplayString(this t : TyVar) : string
{
- GetNameFromType(t);
+ ToDisplayString(t, SCG.Dictionary())
}
public static ToDisplayString(this t : MType) : string
{
- GetNameFromType(t);
+ ToDisplayString(t, SCG.Dictionary())
}
public static GetNameFromType (t : TyVar) : string
{
- | mType is MType => GetNameFromType(mType)
+ GetNameFromType(t, SCG.Dictionary())
+ }
+
+ public static GetNameFromType (t : MType) : string
+ {
+ GetNameFromType(t, SCG.Dictionary())
+ }
+
+ private static ToDisplayString(t : TyVar, types : SCG.Dictionary[MType,int]) : string
+ {
+ GetNameFromType(t, types);
+ }
+
+ private static ToDisplayString(t : MType, types : SCG.Dictionary[MType,int]) : string
+ {
+ GetNameFromType(t, types);
+ }
+
+ private static GetNameFromType (t : TyVar, types : SCG.Dictionary[MType,int]) : string
+ {
+ match (t)
+ {
+ | mType is MType => GetNameFromType(mType, types)
| x =>
match (x.UpperBound)
{
- | Some(mType) => GetNameFromType(mType)
+ | Some(mType) => GetNameFromType(mType, types)
| _ => "<unknown>"
}
}
+ }
- public static GetNameFromType (t : MType) : string
+ private static GetNameFromType (t : MType, types : SCG.Dictionary[MType,int]) : string
+ {
+ when (types.ContainsKey(t))
+ return "<error: cyclic type found>";
+
+ types.Add(t, 0);
+
+ match (t)
{
| Class as c =>
mutable name = Completion.ReplaceSpecialName(c.tycon.FrameworkTypeName);
@@ -190,7 +220,7 @@
name += "[";
foreach (x in c.args)
- name += GetNameFromType (x) + ", ";
+ name += GetNameFromType (x, types) + ", ";
name = name.Trim(',', ' ') + "]";
}
@@ -203,15 +233,16 @@
if (fromTy : object == t || toTy : object == t)
"<error: cyclic type found>"
else
- GetNameFromType(fromTy) + " -> " + GetNameFromType(toTy)
+ GetNameFromType(fromTy) + " -> " + GetNameFromType(toTy, types)
- | Tuple as tuple => tuple.args.Map(ToDisplayString).ToString(" * ")
- | Array as a => "array[" + GetNameFromType(a.t.Fix()) + "]"
+ | Tuple as tuple => tuple.args.Map(ToDisplayString(_, types)).ToString(" * ")
+ | Array as a => "array[" + GetNameFromType(a.t.Fix(), types) + "]"
| Void => "void"
- | Ref as rf => "ref " + GetNameFromType (rf.t.Fix())
- | Out as ut => "out " + GetNameFromType (ut.t.Fix())
+ | Ref as rf => "ref " + GetNameFromType (rf.t.Fix(), types)
+ | Out as ut => "out " + GetNameFromType (ut.t.Fix(), types)
| Intersection(types) => $"one of $types"
}
+ }
public static GetGlyphIndex(this member : IMember) : int
{
More information about the svn
mailing list