[svn] r6548: vs-plugin/trunk/Nemerle.Compiler.Utils:
Nemerle.Completion2/CodeModel/Project.Using.n Nemerle...
VladD2
svnadmin at nemerle.org
Thu Aug 17 15:25:08 CEST 2006
Log:
Refactoring: move utility methods to Utils.n. Rename class Parsing into Utils. Make Intersect a extension method.
Author: VladD2
Date: Thu Aug 17 15:24:58 2006
New Revision: 6548
Removed:
vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/Engine.utils.n
Modified:
vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Using.n
vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.n
vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.overload.n
vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/QuickTipInfo.n
vs-plugin/trunk/Nemerle.Compiler.Utils/Utils.n
Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Using.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Using.n (original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Using.n Thu Aug 17 15:24:58 2006
@@ -7,7 +7,7 @@
using SCG = System.Collections.Generic;
using Nemerle.Compiler.Utils;
-using Nemerle.Compiler.Utils.Parsing;
+using Nemerle.Compiler.Utils.Utils;
namespace Nemerle.Completion2
{
Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.n (original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.n Thu Aug 17 15:24:58 2006
@@ -176,7 +176,7 @@
{
stop = true;
retObject = obj;
- retLocation = Parsing.Intersect(curLocation, location);
+ retLocation = curLocation.Intersect(location);
}
else
{
@@ -363,7 +363,7 @@
{
stop = true;
retObject = obj;
- retLocation = Parsing.Intersect(curLocation, location);
+ retLocation = curLocation.Intersect(location);
}
else
{
Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.overload.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.overload.n (original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.overload.n Thu Aug 17 15:24:58 2006
@@ -7,7 +7,7 @@
using SCG = System.Collections.Generic;
using Nemerle.Compiler.Utils;
-//using Nemerle.Completion2;
+using Nemerle.Compiler.Utils.Utils;
namespace Nemerle.Completion2
{
@@ -64,7 +64,7 @@
};
def mutability = if (v.IsMutable) "mutable " else "";
- def typeName = Engine.GetNameFromType(v.Type);
+ def typeName = v.Type.ToDisplayString();
overloads.Add(CompletionElem(
(if (v.IsMutable) GlyphType.Field else GlyphType.Const) :> int,
@@ -83,7 +83,7 @@
{
def name = match (member.MemberType)
{
- | Constructor => Engine.ReplaceSpecialName(member.DeclaringType.Name)
+ | Constructor => ReplaceSpecialName(member.DeclaringType.Name)
| _ => member.Name
}
@@ -98,42 +98,12 @@
//TODO: Ďîďđŕâčňü ęîěďëĺéřîí äë˙ ęîíńňđóęňîđîâ.
foreach (x in overloadsMap)
- overloads.Add(CompletionElem(GetGlyphIndex(x.Value[0]), x.Key, "", x.Value.ToArray()));
+ overloads.Add(CompletionElem(x.Value[0].GetGlyphIndex(),
+ x.Key, "", x.Value.ToArray()));
overloads.ToArray()
}
- public static GetGlyphIndex(member : IMember) : int
- {
- def glyphType = match (member.GetKind ())
- {
- | Field => GlyphType.Field // IField
- | Method(method) => // IMethod
- match (method.GetFunKind())
- {
- | Method | BoundMethod | Function => GlyphType.Function
- | Constructor | StaticConstructor => GlyphType.Class
- }
-
- | Property => GlyphType.Property // IProperty
- | Type => GlyphType.Class // TypeInfo
- | Event => GlyphType.Event // IEvent
- | _ => GlyphType.Class
- };
-
- glyphType :> int;
- }
-
- //public static GetImageIndex([NotNull] member : IMember) : int
- //{
- // | _ is IField => (int)
- // | _ is IEvent =>
- // | _ is IMethod =>
- // | _ is IProperty =>
- // | _ is TypeInfo =>
- // | _ => System.Exception("Invalid member type: " + member.GetType().Name);
- //}
-
public static MakeName(overloadPossibility : OverloadPossibility)
: string
{
@@ -148,7 +118,7 @@
match (member)
{
- | typeInfo is TypeInfo => Engine.GetNameFromType(typeInfo.GetMemType())
+ | typeInfo is TypeInfo => typeInfo.GetMemType().ToDisplayString()
| _ =>
if (name == ".ctor" || name == ".cctor")
member.DeclaringType.Name.ToString()
Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/QuickTipInfo.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/QuickTipInfo.n (original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/QuickTipInfo.n Thu Aug 17 15:24:58 2006
@@ -6,6 +6,7 @@
using Nemerle.Compiler.Typedtree;
using Nemerle.Compiler.Parsetree;
using Nemerle.IO;
+using Nemerle.Compiler.Utils;
namespace Nemerle.Completion2
{
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 Aug 17 15:24:58 2006
@@ -7,8 +7,115 @@
namespace Nemerle.Compiler.Utils
{
- public module Parsing
+ public module Utils
{
+ public static ToMethodDefinitionString(this t : TyVar) : string
+ {
+ | MType.Fun(parms, to) =>
+ def parmsStr = match (parms)
+ {
+ | MType.Tuple as tuple => tuple.args.Map(ToDisplayString).ToString(", ")
+ | _ => parms.ToDisplayString()
+ }
+
+ "(" + (if (parmsStr == "void") "" else parmsStr) + ") : " + to.ToDisplayString()
+
+ | _ => " : " + t.ToDisplayString()
+ }
+
+ public static ToDisplayString(this t : TyVar) : string
+ {
+ GetNameFromType(t);
+ }
+
+ public static ToDisplayString(this t : MType) : string
+ {
+ GetNameFromType(t);
+ }
+
+ public static GetNameFromType (t : TyVar) : string
+ {
+ | mType is MType => GetNameFromType(mType)
+ | x =>
+ match (x.UpperBound)
+ {
+ | Some(mType) => GetNameFromType(mType)
+ | _ => "<unknown>"
+ }
+ }
+
+ public static GetNameFromType (t : MType) : string
+ {
+ | Class as c =>
+ mutable name = ReplaceSpecialName(c.tycon.FrameworkTypeName);
+
+ when (c.args.Length > 0)
+ {
+ name += "[";
+
+ foreach (x in c.args)
+ name += GetNameFromType (x) + ", ";
+
+ name = name.Trim(',', ' ') + "]";
+ }
+ name
+
+ | TyVarRef as r => r.tyvar.Name
+ | Fun as f => GetNameFromType (f.from.Fix ())
+ + " -> " + GetNameFromType (f.to.Fix ())
+ | Tuple as tuple => tuple.args.Map(ToDisplayString).ToString(" * ")
+ | Array as a => "array[" + GetNameFromType (a.t.Fix ()) + "]"
+ | Void => "void"
+ | Ref as rf => "ref " + GetNameFromType (rf.t.Fix ())
+ | Out as ut => "out " + GetNameFromType (ut.t.Fix ())
+ | Intersection(types) => $"one of $types"
+ }
+
+ /// Look for special names
+ public static ReplaceSpecialName(name : string) : string
+ {
+ | "Nemerle.Core.list"
+ | "Nemerle.Core.list+Cons"
+ | "Nemerle.Core.list+Nil" => "list"
+ | "System.Byte" => "byte"
+ | "System.SByte" => "sbyte"
+ | "System.Int16" => "short"
+ | "System.UInt16" => "ushort"
+ | "System.Int32" => "int"
+ | "System.UInt32" => "uint"
+ | "System.Int64" => "long"
+ | "System.UInt64" => "ulong"
+ | "System.Single" => "float"
+ | "System.Double" => "double"
+ | "System.Decimal" => "decimal"
+ | "System.String" => "string"
+ | "System.Object" => "object"
+ | "System.Boolean" => "bool"
+ | "System.Char" => "char"
+ | _ => name
+ }
+
+ public static GetGlyphIndex(this member : IMember) : int
+ {
+ def glyphType = match (member.GetKind ())
+ {
+ | Field => GlyphType.Field // IField
+ | Method(method) => // IMethod
+ match (method.GetFunKind())
+ {
+ | Method | BoundMethod | Function => GlyphType.Function
+ | Constructor | StaticConstructor => GlyphType.Class
+ }
+
+ | Property => GlyphType.Property // IProperty
+ | Type => GlyphType.Class // TypeInfo
+ | Event => GlyphType.Event // IEvent
+ | _ => GlyphType.Class
+ };
+
+ glyphType :> int;
+ }
+
public GetActiveMember(this typeBuilder : TypeBuilder,
fileIndex : int, line : int, col : int) : IMember
{
@@ -168,7 +275,7 @@
Location(l1.FileIndex, lbeg, cbeg, lend, cend)
}
- public Intersect(l1 : Location, l2 : Location) : Location
+ public Intersect(this l1 : Location, l2 : Location) : Location
{
mutable lbeg;
mutable cbeg;
@@ -200,5 +307,5 @@
l1.Line == l2.Line && l1.EndLine == l2.EndLine &&
l1.Column == l2.Column && l1.EndColumn == l2.EndColumn
}
- } // End of Parsing module
+ } // End of Utils module
} // End of namespace
More information about the svn
mailing list