/VsIntegration/Nemerle.Compiler.Utils/Hints/SubHintForType.n
http://github.com/xxVisorxx/nemerle · Unknown · 132 lines · 114 code · 18 blank · 0 comment · 0 complexity · ce9c54eb0891753c9ebe338f63517b02 MD5 · raw file
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Nemerle.Collections;
- using BFlg = System.Reflection.BindingFlags;
-
- namespace Nemerle.Compiler.Utils
- {
- class SubHintForType : Utils.Convert
- {
- public this()
- {
- base(true, null, false);
- ConvertTypeName = ConvertTypeNameImpl;
- }
-
- mutable _currentId = 1;
- _idToTypeMap : Hashtable[int, FixedType] = Hashtable();
- mutable _ignoringType : FixedType;
-
- GetTypeId(ty : FixedType) : int
- {
- _currentId++;
- _idToTypeMap.Add(_currentId, ty);
- _currentId
- }
-
- ConvertTypeNameImpl(ty : FixedType, name : string) : string
- {
- if (ty.Equals(_ignoringType))
- $"<font color='DarkCyan'>$name</font>"
- else
- $"<font color='DarkCyan'><b><hint value='$name' key='$(GetTypeId(ty))' /></b></font>"
- }
-
- public GetDelayedHintHendler() : Func[string, string]
- {
- def makeTypeStr(key : string) : string
- {
- AddNamespaces = true;
- ExpandTypeArgs = false;
- def ty = _idToTypeMap[int.Parse(key)];
-
- def makeDelegateExt(ti)
- {
- def m = ti.LookupMember("Invoke").Head;
- "<lb/>Signature: " + FixedTypeToString(m.GetMemType()) + "<lb/>"
- + "Inferred: " + TypeVarToString(ty.TypeOfMember(m))
- }
-
- def baseTypesExt(ti : TypeInfo, baseTypeName = "Base type") : string
- {
- def implementsInfo(itfs : list[FixedType.Class]) : string
- {
- def plural = if (itfs.Length > 1) "s" else "";
- def prompt = if (ti.IsInterface) $"Base interface$plural" else "Implements";
- if (itfs.IsEmpty) ""
- else $<#<lb/>$prompt: ..$(itfs; ", "; FixedClassTypeToString)#>
- }
- def old = AddNamespaces;
- AddNamespaces = false;
- def itfs1 = ti.GetDirectSuperTypes();
- def baseType = ti.BaseType;
- def itfs = if (baseType == null) itfs1 else itfs1.Tail;
- def res =
- if (baseType != null)
- $"<lb/>$baseTypeName: " + TypeVarToString(ty.GetInstantiatedSuperType(baseType)) + implementsInfo(itfs)
- else implementsInfo(itfs);
-
- AddNamespaces = old;
-
- res
- }
-
- def (kind, ext) =
- match (ty)
- {
- | Class(ti, _args) =>
- def (kind, ext) =
- if (ti.IsDelegate) ("delegate ", makeDelegateExt(ti))
- else if (ti.IsModule) ("module ", "")
- else if (ti.IsValueType) ("", "")
- else match (ti.GetTydecl())
- {
- | Class with kind = "class "
- | Interface with kind = "interface " => (kind, baseTypesExt(ti))
- | VariantOption =>
- def old = AddNamespaces;
- AddNamespaces = false;
- def flds = ti.GetFields(BFlg.DeclaredOnly | BFlg.Instance | BFlg.Public)
- .Map(f => $"$(f.Name) : $(TypeVarToString(ty.TypeOfMember(f)));");
- def flds = if (flds.IsEmpty) "" else $<#<lb/>Fields: ..$flds#>;
- AddNamespaces = old;
- ("variant option ", flds + baseTypesExt(ti, "Declaring variant"))
-
- | Variant(members) when members.IsEmpty => ("variant ", baseTypesExt(ti))
- | Variant(members) =>
- def old = AddNamespaces;
- AddNamespaces = false;
- def ops = members.Map(o => FixedClassTypeToString(o.GetMemType()));
- AddNamespaces = old;
- ("variant ", $<#<lb/>Variant options: ..$ops<lb/>$(baseTypesExt(ti))#>)
-
- | Enum => ("enum ", "")
- | Alias => assert(false);
- };
- def obsolete = if (ti.IsObsolete) "[Obsolete] " else "";
-
- (obsolete + "<keyword>" + HintHelper.MakeAccessModifiers(ti) + kind + "</keyword>", ext)
-
- | StaticTypeVarRef => ("type parameter ", "")
- | Fun => ("function type ", "")
- | Tuple => ("tuple ", "")
- | Array(_, rank) => ($"$rank dimention ", "")
- | Ref => ("ref parameter ", "")
- | Out => ("out parameter ", "")
- | Void => ("", "")
- | Intersection => ("", "")
- };
-
- def res = $"<hint>$kind$(FixedTypeToString(ty))$ext</hint>";
-
- _ignoringType = ty;
-
- res
- }
-
- makeTypeStr
- }
- }
- }