Revision: 8409
Author:
v...@rsdn.ru
Date: Mon Oct 26 02:38:15 2009
Log: Working on Integration: Implementing interface implementation stabs &
override base members.
http://code.google.com/p/nemerle/source/detail?r=8409
Added:
/nemerle/trunk/VsIntegration/Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/BackgroundWorks/Engine-FindMethodsToOverride.n
Modified:
/nemerle/trunk/VsIntegration/Nemerle.Compiler.Utils/Async/AsyncRequestType.n
/nemerle/trunk/VsIntegration/Nemerle.Compiler.Utils/Nemerle.Compiler.Utils.csproj
/nemerle/trunk/VsIntegration/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/InterfaceMemberImplSourceGenerator.n
/nemerle/trunk/VsIntegration/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Relocation.n
/nemerle/trunk/VsIntegration/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/SourceGenerator.n
/nemerle/trunk/VsIntegration/Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/Engine.Properties.n
/nemerle/trunk/VsIntegration/Nemerle.Compiler.Utils/Nemerle.Completion2/TextManagement/EngineCallbackStub.n
/nemerle/trunk/VsIntegration/Nemerle.Compiler.Utils/Nemerle.Completion2/TextManagement/IIdeProject.n
/nemerle/trunk/VsIntegration/Nemerle.Compiler.Utils/Utils.n
/nemerle/trunk/VsIntegration/Nemerle.VisualStudio/GUI/ImplementMembersForm.Designer.cs
/nemerle/trunk/VsIntegration/Nemerle.VisualStudio/GUI/ImplementMembersForm.cs
/nemerle/trunk/VsIntegration/Nemerle.VisualStudio/GUI/ImplementMembersForm.resx
/nemerle/trunk/VsIntegration/Nemerle.VisualStudio/LanguageService/NemerleSource.cs
/nemerle/trunk/VsIntegration/Nemerle.VisualStudio/Project/ProjectInfo.cs
/nemerle/trunk/VsIntegration/Nemerle.VisualStudio/Utils.cs
/nemerle/trunk/lib/list.n
/nemerle/trunk/ncc/hierarchy/TypeBuilder.n
/nemerle/trunk/ncc/parsing/AST.n
/nemerle/trunk/ncc/testsuite/negative/implements.n
/nemerle/trunk/ncc/testsuite/negative/partial.n
=======================================
--- /dev/null
+++
/nemerle/trunk/VsIntegration/Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/BackgroundWorks/Engine-FindMethodsToOverride.n
Mon Oct 26 02:38:15 2009
@@ -0,0 +1,72 @@
+using System;
+using System.IO;
+using System.Diagnostics;
+using SCG = System.Collections.Generic;
+using Nemerle.Assertions;
+using Nemerle.Collections;
+using Nemerle.Compiler;
+using Nemerle.Compiler.Parsetree;
+using Nemerle.Compiler.Utils.Async;
+using Nemerle.Imperative;
+using Nemerle.Surround;
+using Nemerle.Utility;
+
+using Nemerle.Compiler.Utils;
+using Typed = Nemerle.Compiler.Typedtree;
+using SR = System.Reflection;
+using Nemerle.Completion2;
+
+namespace Nemerle.Completion2
+{
+ public partial class Engine
+ {
+ public BeginFindMethodsToOverride(source : ISource, line : int, col :
int) : CodeInfoAsyncRequest
+ {
+ def request =
CodeInfoAsyncRequest(AsyncRequestType.FindMethodsToOverride,
+ this, source, FindMethodsToOverride, line, col);
+ AsyncWorker.AddWork(request);
+ request
+ }
+
+ private FindMethodsToOverride(request : AsyncRequest) : void
+ {
+ AsyncWorker.CheckCurrentThreadIsTheAsyncWorker();
+ def fileIndex = request.Source.FileIndex;
+
+ surroundwith (currentAsyncRequest)
+ try
+ {
+ if (IsBuildTypesTreeInProgress)
+ AsyncWorker.AddWork(request);
+ else
+ {
+ def project = this.Project;
+
+ if (project == null)
+ {
+ _ = BeginBuildTypesTree();
+ AsyncWorker.AddWork(request);
+ }
+ else
+ {
+ def req = request :> CodeInfoAsyncRequest;
+ match(project.FindMethodsToOverride(fileIndex, req.Line,
req.Column))
+ {
+ | Some((ty, notOverriden)) when notOverriden.Length > 0 =>
+ AsyncWorker.AddResponse(() =>
+ _callback.AddOverrideMembers(request.Source, ty,
notOverriden : array[_]));
+
+ | _ => AsyncWorker.AddResponse(() =>
_callback.ShowMessage("No unimplemented methods found.", MessageType.Info))
+ }
+ request.MarkAsCompleted();
+ }
+ }
+ }
+ catch
+ { | e is CompilationAbortedException =>
+ def msg = $"The GetQuickTipInfo operation aborted at:
$(e.Message)";
+ throw CompilationAbortedException(msg, e);
+ }
+ }
+ } // end class Engine
+} // end namespace
=======================================
---
/nemerle/trunk/VsIntegration/Nemerle.Compiler.Utils/Async/AsyncRequestType.n
Mon Oct 19 04:51:16 2009
+++
/nemerle/trunk/VsIntegration/Nemerle.Compiler.Utils/Async/AsyncRequestType.n
Mon Oct 26 02:38:15 2009
@@ -22,5 +22,6 @@
| CheckMembers
| HighlightUsages
| FindUnimplementedMembers
+ | FindMethodsToOverride
}
}
=======================================
---
/nemerle/trunk/VsIntegration/Nemerle.Compiler.Utils/Nemerle.Compiler.Utils.csproj
Fri Oct 23 08:14:53 2009
+++
/nemerle/trunk/VsIntegration/Nemerle.Compiler.Utils/Nemerle.Compiler.Utils.csproj
Mon Oct 26 02:38:15 2009
@@ -288,6 +288,9 @@
<ItemGroup>
<Compile
Include="Nemerle.Completion2\CodeModel\InterfaceMemberImplSourceGenerator.n"
/>
</ItemGroup>
+ <ItemGroup>
+ <Compile
Include="Nemerle.Completion2\Engine\BackgroundWorks\Engine-FindMethodsToOverride.n"
/>
+ </ItemGroup>
<Import Project="$(Nemerle)\Nemerle.MSBuild.targets" />
<!-- To modify your build process, add your task inside one of the
targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
=======================================
---
/nemerle/trunk/VsIntegration/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/InterfaceMemberImplSourceGenerator.n
Fri Oct 23 08:14:53 2009
+++
/nemerle/trunk/VsIntegration/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/InterfaceMemberImplSourceGenerator.n
Mon Oct 26 02:38:15 2009
@@ -30,30 +30,28 @@
_implName = implName;
_ty = ty;
}
-
- public override WriteParameterDeclarations([NotNull] value :
IMethod) : void
- {
- def (from, to) =
+
+ public override GetSignature([NotNull] value : IMethod) : list[TyVar]
* TyVar
+ {
+ def res =
match (_ty.TypeOfMember(value).Hint)
{
+ | Some(MType.Fun(MType.Void, to)) => ([], to)
| Some(MType.Fun(MType.Tuple(from), to)) => (from, to)
- | Some(MType.Fun(from, to)) => ([from], to)
- | Some(MType.Fun(MType.Void, to)) => ([], to)
- | _ => assert(false);
+ | Some(MType.Fun(from, to)) => ([from], to)
+ | _ => assert(false);
};
- def parms = value.GetParameters().ZipLazy(from);
-
- if (value.IsVarArgs)
- {
- def (till_last, last) = value.GetParameters().DivideLast();
-
- WriteList(till_last, WriteParameterDeclaration);
- Write(", params ");
- WriteParameterDeclaration(last);
- }
- else
- WriteList(value.GetParameters(), WriteParameterDeclaration);
+ res
+ }
+
+ public override GetPropertyType([NotNull] value : IProperty) : TyVar
+ {
+ match (_ty.TypeOfMember(value).Hint)
+ {
+ | Some(ty) => ty
+ | _ => assert(false);
+ }
}
public override WriteName(value : IMember) : void
@@ -66,7 +64,7 @@
public override WriteAttributes(_member : IMember) : void
{
- if (_explicit)
+ if (_explicit || (_accessMods != null
&& !_member.DeclaringType.IsInterface))
when (_accessMods != null)
Write(_accessMods + " ");
else
=======================================
---
/nemerle/trunk/VsIntegration/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Relocation.n
Mon Oct 19 04:51:16 2009
+++
/nemerle/trunk/VsIntegration/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Relocation.n
Mon Oct 26 02:38:15 2009
@@ -1,4 +1,4 @@
-using System;
+using System;
using System.IO;
using System.Diagnostics;
@@ -9,10 +9,12 @@
using Nemerle.Imperative;
using Nemerle.Utility;
using Nemerle.Compiler.Utils;
+using Nemerle.Compiler.NemerleAttributes;
using SR = System.Reflection;
using SCG = System.Collections.Generic;
using Typed = Nemerle.Compiler.Typedtree;
+using BF = System.Reflection.BindingFlags;
namespace Nemerle.Completion2
{
@@ -31,6 +33,72 @@
| GlobalAttribute | Using | Namespace | None => None()
};
}
+
+ internal FindMethodsToOverride(fileIndex : int, line : int, column :
int)
+ : option[TypeBuilder * array[IMember]]
+ {
+ match (GetActiveDecl(fileIndex, line, column))
+ {
+ | Decl.Type(ast) =>
+ def member = ast.TypeBuilder.GetMemberByLocation(fileIndex,
line, column);
+ def ty = match (member) { | ty is TypeBuilder => ty | _ =>
ast.TypeBuilder };
+
+ def isOverrideble(m : IMember) : bool
+ {
+ def res1 = m.Attributes %&& (Abstract | Override | Virtual);
+ res1 && !m.IsStatic
+ }
+ def isOverriden(m : IMember) : bool
+ {
+ def res1 = m.Attributes %&& Override;
+ res1
+ }
+ def flags = BF.DeclaredOnly %| BF.Instance %| BF.NonPublic %|
BF.Public;
+
+ def overrideble =
ty.BaseType.GetMembers().Filter(isOverrideble);
+ def overriden = ty.GetMembers(flags).Filter(isOverriden);
+
+ def excludeOverriden(m : IMember) : bool
+ {
+ def tbTy = ty.GetMemType();
+ def name = m.Name;
+ def cmpSign(tbMember : IMember, baseMember : IMember) : bool
+ {
+ def res1 = match (tbMember, baseMember)
+ {
+ | (x is IMethod, y is IMethod) =>
x.GetParameters().Length == y.GetParameters().Length
+ | (x is IProperty, y is IProperty) =>
+ if (x.IsIndexer)
+ {
+ x.IsIndexer == y.IsIndexer
+ //TODO: реализовать проверку количества параметров
эксесоров
+ }
+ else true
+
+ | _ => false
+ }
+
+ if (res1)
+ {
+ def baseMemberTy = tbTy.TypeOfMember(baseMember).Fix();
+ def tbMemberTy = tbMember.GetMemType();
+ def res3 = baseMemberTy.Equals(tbMemberTy);
+ res3
+ }
+ else false
+ }
+
+ def res = overriden.Exists(x => x.Name == name && cmpSign(x,
m));
+ !res
+ }
+
+ def notOverriden =
overrideble.Filter(excludeOverriden).NToArray();
+
+ Some(ty, notOverriden)
+
+ | GlobalAttribute | Using | Namespace | None => None()
+ };
+ }
/// This method add relocation information, if changes made in
/// methode/property accessor body or in fields initialisation
expression.
=======================================
---
/nemerle/trunk/VsIntegration/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/SourceGenerator.n
Fri Oct 23 08:14:53 2009
+++
/nemerle/trunk/VsIntegration/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/SourceGenerator.n
Mon Oct 26 02:38:15 2009
@@ -82,21 +82,19 @@
WriteName(value);
Write("(");
- if (value.IsVarArgs)
- {
- def (till_last, last) = value.GetParameters().DivideLast();
-
- WriteList(till_last, WriteParameterDeclaration);
- Write(", params ");
- WriteParameterDeclaration(last);
- }
- else
- WriteList(value.GetParameters(), WriteParameterDeclaration);
+ def (from, _) = GetSignature(value);
+
+ WriteParameterDeclarations(value, from);
Write(");");
}
#region Method
+
+ public virtual GetSignature([NotNull] value : IMethod) : list[TyVar] *
TyVar
+ {
+ (value.GetParameters().Map(p => p.ty), value.ReturnType)
+ }
public virtual WriteMethodDeclaration([NotNull] value : IMethod) : void
{
@@ -111,29 +109,32 @@
Write("this");
Write(" ");
}
-
- WriteParameterDeclarations(value);
+
+ def (from, to) = GetSignature(value);
+
+ WriteParameterDeclarations(value, from);
Write(")");
Write(" : ");
- WriteType(value.ReturnType.FixedValue);
+ WriteType(to);
WriteMethodBody(value);
}
- public virtual WriteParameterDeclarations([NotNull] value : IMethod) :
void
+ public virtual WriteParameterDeclarations([NotNull] value : IMethod,
paramsTypes : list[TyVar]) : void
{
if (value.IsVarArgs)
{
- def (till_last, last) = value.GetParameters().DivideLast();
+ def parms : list[TParameter * TyVar] =
value.GetParameters().Zip(paramsTypes);
+ def (till_last, last) = parms.DivideLast();
WriteList(till_last, WriteParameterDeclaration);
Write(", params ");
WriteParameterDeclaration(last);
}
else
- WriteList(value.GetParameters(), WriteParameterDeclaration);
+ WriteList(value.GetParameters().Zip(paramsTypes),
WriteParameterDeclaration);
}
public virtual WriteMethodBody([NotNull] _value : IMethod) : void
@@ -144,6 +145,11 @@
#endregion
#region Property
+
+ public virtual GetPropertyType([NotNull] value : IProperty) : TyVar
+ {
+ value.GetMemType()
+ }
public virtual WritePropertyDeclaration(value : IProperty) : void
{
@@ -155,10 +161,12 @@
WriteAttributes(value);
WriteName(value);
+
+ //TODO: Add parameters support!
// WriteList(value.GetParameters(), "[", "]",
WriteParameterDeclaration);
Write(" : ");
- WriteType(value.GetMemType());
+ WriteType(GetPropertyType(value));
WritePropertyBoby(value);
}
@@ -259,53 +267,12 @@
public virtual WriteType(ty : TypeInfo) : void
{
- mutable path = [ty.Name];
- mutable node = ty.NamespaceNode.Parent;
-
- while (!string.IsNullOrEmpty(node.PartName) && !node.Equals(_ns))
- {
- path ::= node.PartName;
- node = node.Parent;
- }
-
- Write(path.ToString("."));
-
- unless (ty.Typarms.IsEmpty)
- {
- Write("[");
- Write(ty.Typarms.Map(t => t.Name).ToString(", "));
- Write("]");
- }
+ Write(ty.ToString())
}
public virtual WriteType(ty : TyVar) : void
{
- match (ty.Fix())
- {
- | Class (tycon, _) => WriteType(tycon);
- | TyVarRef (tyvar) => Write(tyvar.Name);
- | Ref (t) => Write("ref "); WriteType(t);
- | Out (t) => Write("out "); WriteType(t);
- | Void => Write("void");
- | Fun (from, to) =>
- WriteType(from);
- Write(" -> ");
- WriteType(to);
-
- | Tuple (args) =>
- Write("(");
- Write(args.ToString(" * "));
- Write(")");
-
- | Array (t, rank) =>
- Write("array[");
- when (rank > 1)
- Write($"$rank, ");
- WriteType(t);
- Write("]");
-
- | notimpl => Write($"/* ??? $(notimpl.ToString()) ???
*/");
- }
+ Write(ty.ToString())
}
public virtual WriteGenericConstraintList(_ : list[StaticTyVar]) : void
@@ -344,11 +311,11 @@
Write(GetAttributeString(member.Attributes));
}
- public virtual WriteParameterDeclaration(value : TParameter) : void
+ public virtual WriteParameterDeclaration(value : TParameter, ty :
TyVar) : void
{
Write(value.Name);
Write(" : ");
- WriteType(value.ty);
+ WriteType(ty);
}
#region Types
=======================================
---
/nemerle/trunk/VsIntegration/Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/Engine.Properties.n
Mon Oct 12 04:32:59 2009
+++
/nemerle/trunk/VsIntegration/Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/Engine.Properties.n
Mon Oct 26 02:38:15 2009
@@ -96,7 +96,7 @@
countdon--;
//assert2(_rowProject != null);
done = _rowProject != null;
- assert(countdon != 0);
+ //assert(countdon != 0);
}
Debug.WriteLine("_rowProject == null!");
}
=======================================
---
/nemerle/trunk/VsIntegration/Nemerle.Compiler.Utils/Nemerle.Completion2/TextManagement/EngineCallbackStub.n
Mon Oct 19 04:51:16 2009
+++
/nemerle/trunk/VsIntegration/Nemerle.Compiler.Utils/Nemerle.Completion2/TextManagement/EngineCallbackStub.n
Mon Oct 26 02:38:15 2009
@@ -115,5 +115,6 @@
public SetHighlights(_ : ISource, _ : IEnumerable[GotoInfo]) : void { }
public AddUnimplementedMembers(_ : ISource, _ : TypeBuilder, _ :
IEnumerable[IMember]) : void { }
+ public AddOverrideMembers(_ : ISource, _ : TypeBuilder, _ :
IEnumerable[IMember]) : void { }
}
}
=======================================
---
/nemerle/trunk/VsIntegration/Nemerle.Compiler.Utils/Nemerle.Completion2/TextManagement/IIdeProject.n
Mon Oct 19 04:51:16 2009
+++
/nemerle/trunk/VsIntegration/Nemerle.Compiler.Utils/Nemerle.Completion2/TextManagement/IIdeProject.n
Mon Oct 26 02:38:15 2009
@@ -27,5 +27,6 @@
LookupLocationsFromDebugInformation(info : GotoInfo) : array[GotoInfo];
SetHighlights(source : ISource, highlights : IEnumerable[GotoInfo]) :
void;
AddUnimplementedMembers(source : ISource, ty : TypeBuilder,
unimplementedMembers : IEnumerable[IMember]) : void;
+ AddOverrideMembers(source : ISource, ty : TypeBuilder, notOverriden :
IEnumerable[IMember]) : void;
}
}
=======================================
--- /nemerle/trunk/VsIntegration/Nemerle.Compiler.Utils/Utils.n Fri Oct 23
08:14:53 2009
+++ /nemerle/trunk/VsIntegration/Nemerle.Compiler.Utils/Utils.n Mon Oct 26
02:38:15 2009
@@ -20,6 +20,46 @@
public module Utils
{
InvariantCultureCompareInfo : CompareInfo =
CultureInfo.InvariantCulture.CompareInfo;
+
+ public MaxOrDefault[T](this seq : Seq[T], isGreater : T * T -> bool) :
T
+ {
+ mutable x;
+
+ foreach (elem when isGreater(elem, x) in seq)
+ x = elem;
+
+ x
+ }
+
+ public GetLastImplementedMembersOfInterface(typeBulder : TypeBuilder,
interfaceType : MType.Class)
+ : option[IMember]
+ {
+ def res1 = GetImplementedMembersOfInterface(typeBulder,
interfaceType,
+ m => !m.Location.IsGenerated);
+ def res2 = res1.MaxOrDefault((x, y) => y == null || x.Location.End >
y.Location.End);
+
+ if (res2 == null) None() else Some(res2)
+ }
+
+ public GetImplementedMembersOfInterface(
+ typeBulder : TypeBuilder,
+ interfaceType : MType.Class,
+ predicate : IMember -> bool
+ )
+ : Seq[IMember]
+ {
+ def ti = interfaceType.tycon;
+ def mems = typeBulder.GetMembers(BindingFlags.Public |
BindingFlags.NonPublic
+ | BindingFlags.DeclaredOnly |
BindingFlags.Instance);
+ def isImplemented(member : IMember) : bool
+ {
+ | m is MethodBuilder => m.ImplementedMethods.Exists(x =>
x.DeclaringType : object == ti)
+ | p is PropertyBuilder => isImplemented(p.GetGetter()) ||
isImplemented(p.GetSetter())
+ | _ => false
+ }
+
+ mems.FilterLazy(x => predicate(x) && isImplemented(x))
+ }
public GenerateMemberImplementation(
writer : IO.TextWriter,
=======================================
---
/nemerle/trunk/VsIntegration/Nemerle.VisualStudio/GUI/ImplementMembersForm.Designer.cs
Tue Oct 20 11:10:51 2009
+++
/nemerle/trunk/VsIntegration/Nemerle.VisualStudio/GUI/ImplementMembersForm.Designer.cs
Mon Oct 26 02:38:15 2009
@@ -28,150 +28,150 @@
/// </summary>
private void InitializeComponent()
{
- this.components = new System.ComponentModel.Container();
- System.ComponentModel.ComponentResourceManager resources = new
System.ComponentModel.ComponentResourceManager(typeof(ImplementMembersForm));
- this.pbImplement = new System.Windows.Forms.Button();
- this.pbCancel = new System.Windows.Forms.Button();
- this._grid = new System.Windows.Forms.DataGridView();
- this.ItfMemberNameCol = new
System.Windows.Forms.DataGridViewTextBoxColumn();
- this.AddImplCol = new
System.Windows.Forms.DataGridViewCheckBoxColumn();
- this.Explicit = new
System.Windows.Forms.DataGridViewCheckBoxColumn();
- this.AccessMods = new
System.Windows.Forms.DataGridViewComboBoxColumn();
- this.ImplName = new System.Windows.Forms.DataGridViewTextBoxColumn();
- this.Signature = new
System.Windows.Forms.DataGridViewTextBoxColumn();
- this.panel1 = new System.Windows.Forms.Panel();
- this.imageList1 = new
System.Windows.Forms.ImageList(this.components);
- ((System.ComponentModel.ISupportInitialize)(this._grid)).BeginInit();
- this.panel1.SuspendLayout();
- this.SuspendLayout();
- //
- // pbImplement
- //
- this.pbImplement.Anchor =
((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom
| System.Windows.Forms.AnchorStyles.Right)));
- this.pbImplement.Location = new System.Drawing.Point(443, 7);
-
this.pbImplement.Name = "pbImplement";
- this.pbImplement.Size = new System.Drawing.Size(91, 23);
- this.pbImplement.TabIndex = 0;
- this.pbImplement.Text = "&Implement";
- this.pbImplement.UseVisualStyleBackColor = true;
- this.pbImplement.Click += new
System.EventHandler(this.pbImplement_Click);
- //
- // pbCancel
- //
- this.pbCancel.Anchor =
((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom
| System.Windows.Forms.AnchorStyles.Right)));
- this.pbCancel.DialogResult =
System.Windows.Forms.DialogResult.Cancel;
- this.pbCancel.Location = new System.Drawing.Point(540, 7);
-
this.pbCancel.Name = "pbCancel";
- this.pbCancel.Size = new System.Drawing.Size(75, 23);
- this.pbCancel.TabIndex = 1;
- this.pbCancel.Text = "&Cancel";
- this.pbCancel.UseVisualStyleBackColor = true;
- //
- // _grid
- //
- this._grid.AllowUserToAddRows = false;
- this._grid.AllowUserToDeleteRows = false;
- this._grid.ColumnHeadersHeightSizeMode =
System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
- this._grid.Columns.AddRange(new
System.Windows.Forms.DataGridViewColumn[] {
+ this.components = new System.ComponentModel.Container();
+ System.ComponentModel.ComponentResourceManager resources = new
System.ComponentModel.ComponentResourceManager(typeof(ImplementMembersForm));
+ this.pbImplement = new System.Windows.Forms.Button();
+ this.pbCancel = new System.Windows.Forms.Button();
+ this._grid = new System.Windows.Forms.DataGridView();
+ this.ItfMemberNameCol = new
System.Windows.Forms.DataGridViewTextBoxColumn();
+ this.AddImplCol = new System.Windows.Forms.DataGridViewCheckBoxColumn();
+ this.Explicit = new System.Windows.Forms.DataGridViewCheckBoxColumn();
+ this.AccessMods = new System.Windows.Forms.DataGridViewComboBoxColumn();
+ this.ImplName = new System.Windows.Forms.DataGridViewTextBoxColumn();
+ this.Signature = new System.Windows.Forms.DataGridViewTextBoxColumn();
+ this.panel1 = new System.Windows.Forms.Panel();
+ this.imageList1 = new System.Windows.Forms.ImageList(this.components);
+ ((System.ComponentModel.ISupportInitialize)(this._grid)).BeginInit();
+ this.panel1.SuspendLayout();
+ this.SuspendLayout();
+ //
+ // pbImplement
+ //
+ this.pbImplement.Anchor =
((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom
| System.Windows.Forms.AnchorStyles.Right)));
+ this.pbImplement.Location = new System.Drawing.Point(443, 7);
+
this.pbImplement.Name = "pbImplement";
+ this.pbImplement.Size = new System.Drawing.Size(91, 23);
+ this.pbImplement.TabIndex = 0;
+ this.pbImplement.Text = "&Implement";
+ this.pbImplement.UseVisualStyleBackColor = true;
+ this.pbImplement.Click += new
System.EventHandler(this.pbImplement_Click);
+ //
+ // pbCancel
+ //
+ this.pbCancel.Anchor =
((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom
| System.Windows.Forms.AnchorStyles.Right)));
+ this.pbCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
+ this.pbCancel.Location = new System.Drawing.Point(540, 7);
+
this.pbCancel.Name = "pbCancel";
+ this.pbCancel.Size = new System.Drawing.Size(75, 23);
+ this.pbCancel.TabIndex = 1;
+ this.pbCancel.Text = "&Cancel";
+ this.pbCancel.UseVisualStyleBackColor = true;
+ //
+ // _grid
+ //
+ this._grid.AllowUserToAddRows = false;
+ this._grid.AllowUserToDeleteRows = false;
+ this._grid.ColumnHeadersHeightSizeMode =
System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ this._grid.Columns.AddRange(new
System.Windows.Forms.DataGridViewColumn[] {
this.ItfMemberNameCol,
this.AddImplCol,
this.Explicit,
this.AccessMods,
this.ImplName,
this.Signature});
- this._grid.Dock = System.Windows.Forms.DockStyle.Fill;
- this._grid.Location = new System.Drawing.Point(0, 0);
- this._grid.Name = "_grid";
- this._grid.Size = new System.Drawing.Size(620, 362);
- this._grid.TabIndex = 6;
- //
- // ItfMemberNameCol
- //
- this.ItfMemberNameCol.AutoSizeMode =
System.Windows.Forms.DataGridViewAutoSizeColumnMode.None;
- this.ItfMemberNameCol.Frozen = true;
- this.ItfMemberNameCol.HeaderText = "Soutce name";
- this.ItfMemberNameCol.MinimumWidth = 20;
-
this.ItfMemberNameCol.Name = "ItfMemberNameCol";
- this.ItfMemberNameCol.ReadOnly = true;
- this.ItfMemberNameCol.SortMode =
System.Windows.Forms.DataGridViewColumnSortMode.NotSortable;
- this.ItfMemberNameCol.Width = 250;
- //
- // AddImplCol
- //
- this.AddImplCol.AutoSizeMode =
System.Windows.Forms.DataGridViewAutoSizeColumnMode.ColumnHeader;
- this.AddImplCol.Frozen = true;
- this.AddImplCol.HeaderText = "Implement";
-
this.AddImplCol.Name = "AddImplCol";
- this.AddImplCol.Width = 61;
- //
- // Explicit
- //
- this.Explicit.AutoSizeMode =
System.Windows.Forms.DataGridViewAutoSizeColumnMode.ColumnHeader;
- this.Explicit.HeaderText = "Explicit";
-
this.Explicit.Name = "Explicit";
- this.Explicit.Width = 46;
- //
- // AccessMods
- //
- this.AccessMods.AutoSizeMode =
System.Windows.Forms.DataGridViewAutoSizeColumnMode.AllCells;
- this.AccessMods.DisplayStyle =
System.Windows.Forms.DataGridViewComboBoxDisplayStyle.Nothing;
- this.AccessMods.HeaderText = "Access modifier";
-
this.AccessMods.Name = "AccessMods";
- this.AccessMods.Width = 78;
- //
- // ImplName
- //
- this.ImplName.AutoSizeMode =
System.Windows.Forms.DataGridViewAutoSizeColumnMode.AllCells;
- this.ImplName.HeaderText = "Implementation name";
-
this.ImplName.Name = "ImplName";
- this.ImplName.SortMode =
System.Windows.Forms.DataGridViewColumnSortMode.NotSortable;
- this.ImplName.Width = 102;
- //
- // Signature
- //
- this.Signature.AutoSizeMode =
System.Windows.Forms.DataGridViewAutoSizeColumnMode.AllCells;
- this.Signature.HeaderText = "Signature";
-
this.Signature.Name = "Signature";
- this.Signature.ReadOnly = true;
- this.Signature.SortMode =
System.Windows.Forms.DataGridViewColumnSortMode.NotSortable;
- this.Signature.Width = 58;
- //
- // panel1
- //
- this.panel1.Controls.Add(this.pbCancel);
- this.panel1.Controls.Add(this.pbImplement);
- this.panel1.Dock = System.Windows.Forms.DockStyle.Bottom;
- this.panel1.Location = new System.Drawing.Point(0, 362);
-
this.panel1.Name = "panel1";
- this.panel1.Size = new System.Drawing.Size(620, 38);
- this.panel1.TabIndex = 7;
- //
- // imageList1
- //
- this.imageList1.ColorDepth =
System.Windows.Forms.ColorDepth.Depth24Bit;
- this.imageList1.ImageSize = new System.Drawing.Size(16, 16);
- this.imageList1.TransparentColor = System.Drawing.Color.Magenta;
- //
- // ImplementMembersForm
- //
- this.AcceptButton = this.pbImplement;
- this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
- this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.CancelButton = this.pbCancel;
- this.ClientSize =
global::Nemerle.VisualStudio.Properties.Settings.Default.ImplementMembersSize;
- this.Controls.Add(this._grid);
- this.Controls.Add(this.panel1);
- this.DataBindings.Add(new System.Windows.Forms.Binding("ClientSize",
global::Nemerle.VisualStudio.Properties.Settings.Default, "ImplementMembersSize",
true, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged));
- this.Icon =
((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
- this.MinimizeBox = false;
- this.Name = "ImplementMembersForm";
- this.ShowInTaskbar = false;
- this.StartPosition =
System.Windows.Forms.FormStartPosition.CenterParent;
- this.Text = "Implement unimplemented members of implemented
interfaces";
- this.Load += new System.EventHandler(this.ImplementMembersForm_Load);
- ((System.ComponentModel.ISupportInitialize)(this._grid)).EndInit();
- this.panel1.ResumeLayout(false);
- this.ResumeLayout(false);
+ this._grid.Dock = System.Windows.Forms.DockStyle.Fill;
+ this._grid.Location = new System.Drawing.Point(0, 0);
+ this._grid.Name = "_grid";
+ this._grid.Size = new System.Drawing.Size(620, 362);
+ this._grid.TabIndex = 6;
+ //
+ // ItfMemberNameCol
+ //
+ this.ItfMemberNameCol.AutoSizeMode =
System.Windows.Forms.DataGridViewAutoSizeColumnMode.None;
+ this.ItfMemberNameCol.Frozen = true;
+ this.ItfMemberNameCol.HeaderText = "Soutce name";
+ this.ItfMemberNameCol.MinimumWidth = 20;
+
this.ItfMemberNameCol.Name = "ItfMemberNameCol";
+ this.ItfMemberNameCol.ReadOnly = true;
+ this.ItfMemberNameCol.SortMode =
System.Windows.Forms.DataGridViewColumnSortMode.NotSortable;
+ this.ItfMemberNameCol.Width = 250;
+ //
+ // AddImplCol
+ //
+ this.AddImplCol.AutoSizeMode =
System.Windows.Forms.DataGridViewAutoSizeColumnMode.ColumnHeader;
+ this.AddImplCol.Frozen = true;
+ this.AddImplCol.HeaderText = "Implement";
+
this.AddImplCol.Name = "AddImplCol";
+ this.AddImplCol.Width = 72;
+ //
+ // Explicit
+ //
+ this.Explicit.AutoSizeMode =
System.Windows.Forms.DataGridViewAutoSizeColumnMode.ColumnHeader;
+ this.Explicit.HeaderText = "Explicit";
+
this.Explicit.Name = "Explicit";
+ this.Explicit.Width = 52;
+ //
+ // AccessMods
+ //
+ this.AccessMods.AutoSizeMode =
System.Windows.Forms.DataGridViewAutoSizeColumnMode.AllCells;
+ this.AccessMods.DisplayStyle =
System.Windows.Forms.DataGridViewComboBoxDisplayStyle.Nothing;
+ this.AccessMods.HeaderText = "Access modifier";
+
this.AccessMods.Name = "AccessMods";
+ this.AccessMods.Width = 89;
+ //
+ // ImplName
+ //
+ this.ImplName.AutoSizeMode =
System.Windows.Forms.DataGridViewAutoSizeColumnMode.AllCells;
+ this.ImplName.HeaderText = "Implementation name";
+
this.ImplName.Name = "ImplName";
+ this.ImplName.SortMode =
System.Windows.Forms.DataGridViewColumnSortMode.NotSortable;
+ this.ImplName.Width = 121;
+ //
+ // Signature
+ //
+ this.Signature.AutoSizeMode =
System.Windows.Forms.DataGridViewAutoSizeColumnMode.AllCells;
+ this.Signature.HeaderText = "Signature";
+
this.Signature.Name = "Signature";
+ this.Signature.ReadOnly = true;
+ this.Signature.SortMode =
System.Windows.Forms.DataGridViewColumnSortMode.NotSortable;
+ this.Signature.Width = 66;
+ //
+ // panel1
+ //
+ this.panel1.Controls.Add(this.pbCancel);
+ this.panel1.Controls.Add(this.pbImplement);
+ this.panel1.Dock = System.Windows.Forms.DockStyle.Bottom;
+ this.panel1.Location = new System.Drawing.Point(0, 362);
+
this.panel1.Name = "panel1";
+ this.panel1.Size = new System.Drawing.Size(620, 38);
+ this.panel1.TabIndex = 7;
+ //
+ // imageList1
+ //
+ this.imageList1.ColorDepth = System.Windows.Forms.ColorDepth.Depth24Bit;
+ this.imageList1.ImageSize = new System.Drawing.Size(16, 16);
+ this.imageList1.TransparentColor = System.Drawing.Color.Magenta;
+ //
+ // ImplementMembersForm
+ //
+ this.AcceptButton = this.pbImplement;
+ this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.CancelButton = this.pbCancel;
+ this.ClientSize =
global::Nemerle.VisualStudio.Properties.Settings.Default.ImplementMembersSize;
+ this.Controls.Add(this._grid);
+ this.Controls.Add(this.panel1);
+ this.DataBindings.Add(new System.Windows.Forms.Binding("ClientSize",
global::Nemerle.VisualStudio.Properties.Settings.Default, "ImplementMembersSize",
true, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged));
+ this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
+ this.MinimizeBox = false;
+ this.Name = "ImplementMembersForm";
+ this.ShowInTaskbar = false;
+ this.StartPosition =
System.Windows.Forms.FormStartPosition.CenterParent;
+ this.Text = "Implement unimplemented members of implemented interfaces";
+ this.Load += new System.EventHandler(this.ImplementMembersForm_Load);
+ ((System.ComponentModel.ISupportInitialize)(this._grid)).EndInit();
+ this.panel1.ResumeLayout(false);
+ this.ResumeLayout(false);
}
=======================================
---
/nemerle/trunk/VsIntegration/Nemerle.VisualStudio/GUI/ImplementMembersForm.cs
Fri Oct 23 08:14:53 2009
+++
/nemerle/trunk/VsIntegration/Nemerle.VisualStudio/GUI/ImplementMembersForm.cs
Mon Oct 26 02:38:15 2009
@@ -9,7 +9,11 @@
using Nemerle.VisualStudio.LanguageService;
using Nemerle.Compiler;
using System.Diagnostics;
+using NUtils = Nemerle.Compiler.Utils.Utils;
+using BFld = System.Reflection.BindingFlags;
using TypeMembers =
System.Collections.Generic.KeyValuePair<Nemerle.Compiler.MType.Class,
Nemerle.Compiler.IMember>;
+using Microsoft.VisualStudio.Package;
+using Microsoft.VisualStudio.TextManager.Interop;
namespace Nemerle.VisualStudio.GUI
{
@@ -44,45 +48,60 @@
foreach (var item in res)
ht[item.Ty] = ReplaceGettersAndSettersByProperties(item.Group);
+ var baseTypes = itfs.Where(g => !g.Key.IsInterface);
+ var tbTy = ty.GetMemType();
+
+ foreach (var baseType in baseTypes)
+ ht[baseType.Key.GetMemType()] =
ReplaceGettersAndSettersByProperties(baseType);
+
FillTable(ht);
}
void FillTable(Dictionary<MType.Class, IMember[]> itfs)
{
- _grid.CellPainting += CellPainting;
- _grid.CellValueChanged += CellValueChanged;
- _grid.CellValidating += CellValidating;
+ _grid.CellPainting += CellPainting;
+ _grid.CellValueChanged += CellValueChanged;
+ _grid.CellValidating += CellValidating;
_grid.CurrentCellDirtyStateChanged += CurrentCellDirtyStateChanged;
var accessModaCol =
(DataGridViewComboBoxColumn)_grid.Columns["AccessMods"];
- var explicitCol =
(DataGridViewCheckBoxColumn)_grid.Columns["Explicit"];
+ var explicitCol =
(DataGridViewCheckBoxColumn)_grid.Columns["Explicit"];
+ var implName = (DataGridViewTextBoxColumn)
_grid.Columns["ImplName"];
accessModaCol.Items.AddRange("public", "private", "protected", "internal", "protected
internal");
_grid.Rows.Add("All", true);
+
+ var haveInterfaces = itfs.Any(x => x.Key.IsInterface);
+
+ if (!haveInterfaces)
+ {
+ implName.Visible = explicitCol.Visible = accessModaCol.Visible = false;
+ Text = "Override members of base types";
+ }
foreach (var item in itfs)
{
- var rowIndex = _grid.Rows.Add(item.Key + " interface", true);
+ var isInterface = item.Key.IsInterface;
+ var sifix = isInterface ? " (interface)" : " (base type)";
+ var rowIndex = _grid.Rows.Add(item.Key + sifix, true);
var row = _grid.Rows[rowIndex];
row.Cells[0].Style.Font = new Font(_grid.DefaultCellStyle.Font,
FontStyle.Bold);
foreach (var m in item.Value)
{
var name = m.Name;
-
rowIndex = _grid.Rows.Add(m.Name, true, false, null, m.Name, m);
row = _grid.Rows[rowIndex];
- row.Cells[0].Style.Padding = new Padding(_imageSize * 2, 0, 0,
0);
+ var implementByDefault = isInterface || (m.Attributes &
NemerleAttributes.Abstract) != 0;
+ row.Cells["AddImplCol"].Value = implementByDefault;
+ row.Cells[0].Style.Padding = new Padding(_imageSize * 2, 0, 0, 0);
var gray = Color.FromKnownColor(KnownColor.GrayText);
var explicitCell =
(DataGridViewCheckBoxCell)row.Cells["Explicit"];
row.Cells["AccessMods"].Style.ForeColor = gray;
row.Cells["ImplName"].Style.ForeColor = gray;
row.Cells["Signature"].Style.ForeColor = gray;
- //var x0 = item.Key.TypeOfMember(item.Value[0]);
- //var x1 = item.Key.TypeOfMember(item.Value[1]);
- //var x2 = item.Key.TypeOfMember(item.Value[2]);
- row.Tag = item;
+ row.Tag = new TypeMembers(item.Key, m);
}
}
}
@@ -91,7 +110,7 @@
{
var props = item.Key.GetMembers().OfType<IProperty>();
var mems1 = item.Select(m => props.SingleOrDefault(p =>
p.GetGetter() == m || p.GetSetter() == m) ?? m);
- var mems2 = mems1.Distinct().ToArray();
+ var mems2 = mems1.Distinct().OrderBy(m => m.Name).ToArray();
return mems2;
}
@@ -104,6 +123,7 @@
void CellValidating(object sender, DataGridViewCellValidatingEventArgs
e)
{
}
+
void CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
var row = _grid.Rows[e.RowIndex];
@@ -124,10 +144,11 @@
var isExplicit = (bool)row.Cells["Explicit"].Value;
row.Cells["Explicit"].Style.ForeColor =
Color.FromKnownColor(isImpl ? KnownColor.WindowText : KnownColor.GrayText);
+
var color = Color.FromKnownColor(isImpl && isExplicit ?
KnownColor.WindowText : KnownColor.GrayText);
row.Cells["AccessMods"].Style.ForeColor = color;
- row.Cells["ImplName"].Style.ForeColor = color;
- row.Cells["Signature"].Style.ForeColor = color;
+ row.Cells["ImplName"].Style.ForeColor = color;
+ row.Cells["Signature"].Style.ForeColor = color;
_grid.Invalidate();
}
@@ -145,7 +166,7 @@
if (e.ColumnIndex == 0 && row.Tag != null)
{
var member = ((TypeMembers)row.Tag).Value;
- var imgIndex = Nemerle.Compiler.Utils.Utils.GetGlyphIndex(member);
+ var imgIndex = NUtils.GetGlyphIndex(member);
e.Paint(r, e.PaintParts);
e.Graphics.DrawImage(imageList1.Images[imgIndex], r.X + _imageSize
- 2, r.Y + (r.Height - _imageSize) / 2,
@@ -163,12 +184,13 @@
{
}
-
-
-
+
private void pbImplement_Click(object sender, EventArgs e)
{
- var res = _grid.Rows.Cast<DataGridViewRow>().Where(r => r.Tag !=
null)
+ var newLine = Environment.NewLine;
+
+ var res = _grid.Rows.Cast<DataGridViewRow>()
+ .Where(r => r.Tag != null && (bool)r.Cells["AddImplCol"].Value)
.GroupBy(r => ((TypeMembers)r.Tag).Key, r =>
new
{
@@ -179,23 +201,114 @@
ImplName = (string)r.Cells["ImplName"].Value
});
- var res2 = res.ToArray();
- var writer = new System.IO.StringWriter();
-
- foreach (var item in res2)
- {
- writer.WriteLine("//" + item.Key + ":");
-
- foreach (var item2 in item)
- {
- Nemerle.Compiler.Utils.Utils.GenerateMemberImplementation(writer,
- _source.FileIndex, item.Key, item2.Member, item2.Explicit,
item2.AccessMods, item2.ImplName);
-
- writer.WriteLine();
- }
- }
-
-
Debug.WriteLine(writer.GetStringBuilder().Replace("\t", " ").ToString());
- }
+ var stubs = res.ToArray();
+ var laggSrv = _source.LanguageService;
+ var pref = laggSrv.Preferences;
+
+ _source.LockWrite();
+ var sufix = stubs.Length > 1 ? "s" : "";
+ var editArray = new EditArray(_source, null, true, "implement
interface" + sufix + " stub" + sufix);
+ try
+ {
+
+ foreach (var stub in stubs)
+ {
+ var writer = new System.IO.StringWriter();
+ var itfMems = stub.ToArray();
+ var isInterface = stub.Key.IsInterface;
+ var ty = _ty.GetMemType();
+
+ foreach (var item2 in itfMems)
+ {
+ if (isInterface)
+ NUtils.GenerateMemberImplementation(writer, _source.FileIndex,
+ stub.Key, item2.Member, item2.Explicit, item2.AccessMods,
item2.ImplName);
+ else
+ {
+ var am = (item2.Member.Attributes | NemerleAttributes.Override)
+ & ~(NemerleAttributes.Abstract | NemerleAttributes.Virtual);
+ var acessMods = am.ToString().ToLower().Replace(",", "");
+
+ NUtils.GenerateMemberImplementation(writer, _source.FileIndex,
+ ty, item2.Member, false, acessMods, "");
+ }
+
+ writer.WriteLine();
+ }
+
+ var sb = writer.GetStringBuilder();
+ //sb.Length -= Environment.NewLine.Length;
+ if (!pref.InsertTabs && pref.IndentSize == 1)
+ sb.Replace("\t", pref.MakeIndentString());
+
+ TextPoint pt = new TextPoint();
+ string indent = null;
+
+ var member = NUtils.GetLastImplementedMembersOfInterface(_ty,
stub.Key);
+
+ if (member.IsSome)
+ {
+ // Используем meber.Value для получения места вставки
+ var endLine = member.Value.Location.EndLine;
+ var text = _source.GetLine(endLine);
+ indent = text.GetLiadingSpaces();
+ pt = new TextPoint(endLine + 1, 1);
+ //TODO: Этот код рассчитывает на то, что за членом не идет
многострочного коментария
+ // или другого члена. Надо бы сделать реализацию не закладывающуюся
на это.
+ }
+ else // Ни одного члена этого интерфейса не реализовано в классе...
+ {
+ // Оборачиваем реализуемые методы в #region
+ sb.Insert(0, "#region " + stub.Key + " Members" + newLine +
newLine);
+ sb.AppendLine("#endregion " + stub.Key + " Members" + newLine);
+ // Вставляем описание интерфейса в конец класса
+ var endLine = _ty.Location.EndLine;
+ var text = _source.GetLine(endLine);
+ indent = text.GetLiadingSpaces();
+ pt = new TextPoint(endLine, 1);
+ indent += pref.MakeIndentString();
+ //TODO: Этот код рассчитывает на то, что конец типа распологается на
отдельной строке.
+ // Надо бы сделать реализацию не закладывающуюся на это.
+ }
+
+ sb.Insert(0, indent);
+ sb.Replace("\n", "\n" + indent);
+ TrimEnd(sb);
+
+ Location inertLoc = new Location(_source.FileIndex, pt, pt);
+ TextSpan span = inertLoc.ToTextSpan();
+
+ editArray.Add(new EditSpan(span, sb.ToString()));
+ //_source.SetText(span, sb.ToString());
+ }
+
+ editArray.ApplyEdits();
+ Close();
+ }
+ catch (Exception ex)
+ {
+ _source.ProjectInfo.ShowMessage("Error: " + ex.Message,
Nemerle.Completion2.MessageType.Error);
+ }
+ finally
+ {
+ editArray.Dispose();
+ _source.UnlockWrite();
+ }
+
+
//Debug.WriteLine(writer.GetStringBuilder().Replace("\t", " ").ToString());
+ }
+
+ static void TrimEnd(StringBuilder sb)
+ {
+ for (int i = sb.Length - 1; i > 0; i--)
+ {
+ var ch = sb[i];
+ if (ch != ' ' && ch != '\t')
+ {
+ sb.Length = i + 1;
+ return;
+ }
+ }
+ }
}
}
=======================================
---
/nemerle/trunk/VsIntegration/Nemerle.VisualStudio/GUI/ImplementMembersForm.resx
Tue Oct 20 11:10:51 2009
+++
/nemerle/trunk/VsIntegration/Nemerle.VisualStudio/GUI/ImplementMembersForm.resx
Mon Oct 26 02:38:15 2009
@@ -136,7 +136,10 @@
<value>True</value>
</metadata>
<metadata name="imageList1.TrayLocation" type="System.Drawing.Point,
System.Drawing, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a">
- <value>17, 17</value>
+ <value>19, 5</value>
+ </metadata>
+ <metadata name="$this.TrayHeight" type="System.Int32, mscorlib,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+ <value>33</value>
</metadata>
<assembly alias="System.Drawing" name="System.Drawing, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing"
mimetype="application/x-microsoft.net.object.bytearray.base64">
=======================================
---
/nemerle/trunk/VsIntegration/Nemerle.VisualStudio/LanguageService/NemerleSource.cs
Mon Oct 19 13:56:25 2009
+++
/nemerle/trunk/VsIntegration/Nemerle.VisualStudio/LanguageService/NemerleSource.cs
Mon Oct 26 02:38:15 2009
@@ -1185,11 +1185,18 @@
// 3. Íàéòè ìåòñî êóäà ìîæíî âñòàâèòü òåêñò.
// 4. Îïðåäåëèòü îòáèêó è äîáàâèòü åå ê ñãåíåðèðîâàííîìó òåêñòó.
// 5. Âñòàâ ïîëó÷åíûé òåêñ â ìåñòî íàéäåííîå íà øàãå 3.
- var engine = GetEngine();
- if (!engine.IsDefaultEngine)
- engine.BeginFindUnimplementedMembers(this, loc.Line, loc.Column);
+ {
+ var engine = GetEngine();
+ if (!engine.IsDefaultEngine)
+ engine.BeginFindUnimplementedMembers(this, loc.Line, loc.Column);
+ }
break;
case MenuCmd.CmdId.OverrideMembers:
+ {
+ var engine = GetEngine();
+ if (!engine.IsDefaultEngine)
+ engine.BeginFindMethodsToOverride(this, loc.Line, loc.Column);
+ }
break;
default:
Debug.Assert(false);
=======================================
---
/nemerle/trunk/VsIntegration/Nemerle.VisualStudio/Project/ProjectInfo.cs
Mon Oct 19 04:51:16 2009
+++
/nemerle/trunk/VsIntegration/Nemerle.VisualStudio/Project/ProjectInfo.cs
Mon Oct 26 02:38:15 2009
@@ -553,6 +553,14 @@
form.ShowDialog();
}
}
+
+ public void AddOverrideMembers(ISource source, TypeBuilder ty,
IEnumerable<IMember> notOverriden)
+ {
+ using (var form = new ImplementMembersForm((NemerleSource)source, ty,
notOverriden))
+ {
+ form.ShowDialog();
+ }
+ }
public void SetHighlights(ISource source, IEnumerable<GotoInfo>
highlights)
{
=======================================
--- /nemerle/trunk/VsIntegration/Nemerle.VisualStudio/Utils.cs Thu Oct 15
21:22:44 2009
+++ /nemerle/trunk/VsIntegration/Nemerle.VisualStudio/Utils.cs Mon Oct 26
02:38:15 2009
@@ -17,11 +17,38 @@
using Microsoft.Win32;
using System.Diagnostics;
using Microsoft.VisualStudio;
+using Microsoft.VisualStudio.Package;
namespace Nemerle.VisualStudio
{
static class Utils
{
+ public static string GetLiadingSpaces(this string text)
+ {
+ return text.Substring(0, text.Length -
text.TrimStart(' ', '\t').Length);
+ }
+
+ public static string MakeIndentString(this LanguagePreferences pref)
+ {
+ string indent = null;
+
+ if (pref.InsertTabs)
+ {
+ var spacesNeeded = pref.IndentSize % pref.TabSize;
+ var tabsNeeded = pref.IndentSize / pref.TabSize;
+
+ if (tabsNeeded > 0)
+ indent = new string('\t', tabsNeeded);
+
+ if (spacesNeeded > 0)
+ indent = new string('\t', tabsNeeded);
+ }
+ else
+ indent = new string(' ', pref.IndentSize);
+
+ return indent ?? "";
+ }
+
public static TextPoint GetCaretTextPoint(this IVsTextView textView)
{
int line, idx;
=======================================
--- /nemerle/trunk/lib/list.n Tue Aug 4 02:14:37 2009
+++ /nemerle/trunk/lib/list.n Mon Oct 26 02:38:15 2009
@@ -84,7 +84,7 @@
else if (x : object == null || y : object == null)
false
else
- x.Equals(y)
+ object.Equals(x, y)
}
public static @!= (x : list [T], y : list [T]) : bool
@@ -94,16 +94,18 @@
else if (x : object == null || y : object == null)
true
else
- !x.Equals(y)
+ !object.Equals(x, y)
}
[Nemerle.OverrideObjectEquals]
public Equals (other : list [T]) : bool
{
- match (this) {
+ match (this)
+ {
| x :: xs =>
- match (other) {
- | y :: ys when x.Equals (y) => xs.Equals (ys)
+ match (other)
+ {
+ | y :: ys when object.Equals(x, y) => xs.Equals (ys)
| _ => false
}
@@ -256,27 +258,21 @@
}
- public Nth (n : int) : T {
- NCL.Nth (this, n)
- }
+ public Nth (n : int) : T { NCL.Nth (this, n) }
/**
* Returns reversed list, i.e. [1,2,3].Reverse().Equals ([3,2,1]).
* Works in time and memory O(n).
*/
- public Reverse () : list [T] {
- NCL.Rev (this)
- }
+ public Reverse () : list [T] { NCL.Rev (this) }
/**
* Returns list made from appending list y at end of list x.
* Original list are not modified.
* Works in time and memory O(length(x)).
*/
- public Append (y : list [T]) : list [T] {
- NCL.RevAppend (Reverse (), y)
- }
+ public Append (y : list [T]) : list [T] { NCL.RevAppend (Reverse (),
y) }
/**
* Equivalent to Reverse().Append(y), but faster.
@@ -318,9 +314,22 @@
}
}
- public Map[TOut] (convert : T -> TOut) : list [TOut] {
+ public Map[TOut] (convert : T -> TOut) : list [TOut]
+ {
NCL.Map (this, convert)
}
+
+ public Zip[TSecond](second : list[TSecond]) : list [T * TSecond]
+ {
+ match (this, second)
+ {
+ | (x :: xs, y :: ys) => (x, y) :: xs.Zip(ys)
+ | ([], []) => []
+ | (null, _) => throw System.ArgumentNullException("this")
+ | (_, null) => throw System.ArgumentNullException("second")
+ | (_, _) => throw System.ArgumentException("list[T].Zip():
Collections mast have same", "second")
+ }
+ }
public MapFiltered[TOut] (predicate : T -> bool, convert : T ->
TOut) : list [TOut] {
NCL.MapFiltered (this, predicate, convert)
@@ -567,35 +576,29 @@
[DebuggerNonUserCode]
public module NList
{
- /**
- * Tests equality of two lists. Uses Equal method of
- * objects to test wether they are the same.
- */
+ /// Tests equality of two lists. Uses Equal method of
+ /// objects to test wether they are the same.
public Equals[T] (x : list [T], y : list [T]) : bool
{
- x.Equals (y)
+ x : object == y || x : object != null && y : object != null &&
x.Equals(y)
}
- /**
- * Compare two lists lexicographically over the order defined on
- * their elements with function [cmp]. Returns [-1] if [l1] is
smaller,
- * [1] if [l2] is smaller, and [0] if they equal.
- */
- public static Compare [T] (l1 : list [T], l2 : list [T],
- cmp : T * T -> int) : int
- {
- match ((l1, l2)){
+ /// Compare two lists lexicographically over the order defined on
+ /// their elements with function [cmp]. Returns [-1] if [l1] is
smaller,
+ /// [1] if [l2] is smaller, and [0] if they equal.
+ public static Compare [T] (l1 : list [T], l2 : list [T], cmp : T * T
-> int) : int
+ {
+ match ((l1, l2))
+ {
| ([], []) => 0
| ([], _) => -1
| (_, []) => 1
| (x :: xs, y :: ys) =>
def ret = cmp (x, y);
- if (ret == 0){
- Compare (xs, ys, cmp)
- } else {
- ret
- }
+
+ if (ret == 0) Compare (xs, ys, cmp)
+ else ret
}
}
@@ -628,16 +631,15 @@
*/
public static RemoveDuplicates [T] (lst : list [T]) : list [T]
{
- def loop (lst, acc){
- match (lst){
+ def loop (lst, acc)
+ {
+ match (lst)
+ {
| [] => acc.Reverse ();
| [x] => (x :: acc).Reverse ();
| x :: ((y :: _) as xs) =>
- if (x.Equals (y)){
- loop (xs, acc)
- } else {
- loop (xs, x :: acc)
- }
+ if (object.Equals(x, y)) loop (xs, acc)
+ else loop (xs, x :: acc)
}
}
@@ -852,7 +854,7 @@
{
match (from) {
| [] => NList.Rev(acc)
- | y :: ys => loop( if ( y.Equals ( x ) ) acc else y::acc ,ys)
+ | y :: ys => loop(if (object.Equals(y, x)) acc else y :: acc,
ys)
}
}
@@ -887,21 +889,27 @@
}
}
- public MapFiltered[T, TOut] (lst : list [T], predicate : T -> bool,
convert : T -> TOut) : list [TOut] {
+ public MapFiltered[T, TOut](lst : list[T], predicate : T -> bool,
convert : T -> TOut) : list[TOut]
+ {
$[ convert(x) | x in lst, predicate (x) ]
}
- public Map[T, TOut] (lst : list [T], convert : T -> TOut) : list
[TOut] {
+ public Map[T, TOut] (lst : list [T], convert : T -> TOut) : list [TOut]
+ {
$[ convert(x) | x in lst ]
}
- public RevMap[T, TOut] (l : list [T], convert : T -> TOut) : list
[TOut] {
- def loop (acc : list [TOut], x : list [T]) : list [TOut] {
- match (x) {
- | h :: t => loop (convert (h) :: acc, t)
+ public RevMap[T, TOut] (l : list [T], convert : T -> TOut) : list
[TOut]
+ {
+ def loop (acc : list [TOut], x : list [T]) : list [TOut]
+ {
+ match (x)
+ {
+ | h :: t => loop(convert(h) :: acc, t)
| [] => acc
}
}
+
loop ([], l)
}
@@ -1064,7 +1072,7 @@
public Member [T] (l : list [T], a : T) : bool
{
match (l) {
- | h :: t => h.Equals (a) || Member (t, a)
+ | h :: t => object.Equals(h, a) || Member (t, a)
| [] => false
}
}
@@ -1221,9 +1229,10 @@
public Assoc [T, TSecond] (l : list [T * TSecond], key : T) : option
[TSecond]
{
- match (l) {
+ match (l)
+ {
| (k, v) :: t =>
- if (key.Equals (k))
+ if (object.Equals(key, k))
Some (v)
else
Assoc (t, key)
@@ -1234,7 +1243,7 @@
public MemAssoc[T, TSecond] (l : list [T * TSecond], key : T) : bool {
match (l) {
| (k, _) :: t =>
- if (key.Equals (k))
+ if (object.Equals(key, k))
true
else
MemAssoc (t, key)
@@ -1242,12 +1251,13 @@
}
}
- public RemoveAssoc [T, TSecond] (l : list [T * TSecond], key : T) :
list [T * TSecond] {
+ public RemoveAssoc [T, TSecond] (l : list [T * TSecond], key : T) :
list [T * TSecond]
+ {
def loop (acc : list [T * TSecond], l : list [T * TSecond]) : list
[T * TSecond]
{
match (l) {
| (k, v) :: t =>
- if (key.Equals (k))
+ if (object.Equals(key, k))
loop (acc, t)
else
loop ((k, v) :: acc, t)
=======================================
--- /nemerle/trunk/ncc/hierarchy/TypeBuilder.n Mon Oct 12 04:32:59 2009
+++ /nemerle/trunk/ncc/hierarchy/TypeBuilder.n Mon Oct 26 02:38:15 2009
@@ -81,13 +81,17 @@
typarms_count : int;
[Accessor (Ast)]
- mutable pt_tydecl : PT.TopDeclaration;
+ mutable _ast : PT.TopDeclaration;
mutable additional_decls : SCG.List [PT.ClassMember] = null;
mutable partial_parts : list [PT.TopDeclaration] = [];
+
+ mutable _nameLocation : Location;
+
+ public override NameLocation : Location { get { _nameLocation } }
public AstParts : list [PT.TopDeclaration]
{
- get { pt_tydecl :: partial_parts }
+ get { _ast :: partial_parts }
}
[Accessor (flags = Override)]
@@ -122,8 +126,9 @@
Manager.Stats.AllTypeBuilders++;
- this.pt_tydecl = td;
- this.pt_name = td.PName;
+ _ast = td;
+ pt_name = td.PName;
+ _nameLocation = td.NameLocation;
when (this.GlobalEnv == null)
Util.ice ($ "env is null for $(ns_node.GetDisplayName ())");
@@ -139,7 +144,8 @@
attributes = modifiers.mods;
instance_ctor_occured = td is PT.TopDeclaration.Alias;
- match (td) {
+ match (td)
+ {
| PT.TopDeclaration.VariantOption =>
instance_ctor_occured = true;
enclosing_type.variant_options = this ::
enclosing_type.variant_options;
@@ -152,15 +158,16 @@
| PT.TopDeclaration.Enum => is_enum = true;
| _ => ()
- };
+ }
+
++Manager.tyinfo_counter;
- when (pt_tydecl.typarms != null)
- typarms_count = pt_tydecl.typarms.tyvars.Length;
+ when (_ast.typarms != null)
+ typarms_count = _ast.typarms.tyvars.Length;
when (par != null)
typarms_count += par.TyparmsCount;
- if (this.pt_tydecl is PT.TopDeclaration.Interface)
+ if (this._ast is PT.TopDeclaration.Interface)
this.tydecl = TypeDeclaration.Interface ();
else
this.tydecl = TypeDeclaration.Class (); // may change later (in
bind_types)
@@ -226,7 +233,7 @@
public override IsInterface : bool
{
get { if (TyManager.run_phase <= 2)
- pt_tydecl is PT.TopDeclaration.Interface
+ _ast is PT.TopDeclaration.Interface
else
tydecl is TypeDeclaration.Interface
}
@@ -245,7 +252,7 @@
public IsAlias : bool
{
get { if (TyManager.run_phase <= 2)
- pt_tydecl is PT.TopDeclaration.Alias
+ _ast is PT.TopDeclaration.Alias
else
tydecl is TypeDeclaration.Alias
}
@@ -267,7 +274,7 @@
get
{
if (TyManager.run_phase <= 2)
- pt_tydecl is PT.TopDeclaration.VariantOption
+ _ast is PT.TopDeclaration.VariantOption
else
tydecl is TypeDeclaration.VariantOption
}
@@ -295,7 +302,7 @@
public ParsedDeclaration : PT.TopDeclaration
{
- get { pt_tydecl }
+ get { _ast }
}
public ParsedTypeName : PT.PExpr
@@ -400,14 +407,14 @@
[Nemerle.Assertions.Requires (TyManager.run_phase <= 2)]
public AddImplementedInterface (t : PT.PExpr) : void
{
- match (pt_tydecl) {
- | PT.TopDeclaration.Class as td => td.t_extends += [t]
+ match (_ast)
+ {
+ | PT.TopDeclaration.Class as td => td.t_extends += [t]
| PT.TopDeclaration.Interface as td => td.t_extends += [t]
- | PT.TopDeclaration.Variant as td => td.t_extends += [t]
+ | PT.TopDeclaration.Variant as td => td.t_extends += [t]
| _ =>
- Message.Error (pt_tydecl.Location,
- $"cannot add interface to $(pt_tydecl.GetType().Name.ToLower())"
- " ($(pt_tydecl.Name)).")
+ Message.Error(t.Location,
+ $"cannot add interface to $(_ast.GetType().Name.ToLower())
($(_ast.Name)).");
}
}
@@ -695,7 +702,8 @@
public GetParsedMembers (include_manually_defined = false) : list
[PT.ClassMember]
{
- match (pt_tydecl) {
+ match (_ast)
+ {
| PT.TopDeclaration.Class (decls = ds)
| PT.TopDeclaration.Interface (methods = ds)
| PT.TopDeclaration.Variant (decls = ds)
@@ -888,7 +896,8 @@
}
- internal ReverseChildren () : void {
+ internal ReverseChildren () : void
+ {
contained_types = NList.Rev (contained_types);
variant_options = NList.Rev (variant_options);
}
@@ -909,47 +918,69 @@
protected internal make_tyenvs () : void
{
assert (this.tenv == null);
- def tenv = TyVarEnv (Manager);
-
- match (this.pt_tydecl.typarms) {
+ def tenv = TyVarEnv (Manager);
+ mutable incorrectTyParamsParts = [];
+
+ match (this._ast.typarms)
+ {
| null =>
this.tenv = tenv;
this.typarms = [];
| ps =>
// we must merge type parameter constrains from partial parts of
this class
- def ps =
- NList.FoldLeft (partial_parts, ps, fun (part :
PT.TopDeclaration, acc : PT.Typarms) {
- mutable new_constr = acc.constraints;
-
- def tparms = match (part) {
- | PT.TopDeclaration.Class (typarms = t) => t
- | PT.TopDeclaration.Variant (typarms = t) => t
- | PT.TopDeclaration.Interface (typarms = t) => t
+ def processPart(part : PT.TopDeclaration, acc : PT.Typarms)
+ {
+ mutable new_constr = acc.constraints;
+
+ def tparms =
+ match (part)
+ {
+ | PT.TopDeclaration.Class (typarms = t) => t
+ | PT.TopDeclaration.Variant (typarms = t) => t
+ | PT.TopDeclaration.Interface(typarms = t) => t
| _ => Util.ice ("non class / variant")
- }
-
- when (! tparms.tyvars.Equals (pt_tydecl.typarms.tyvars))
- Message.Error ($ "partial declarations of `$this' must have "
- "the same type parameter names in the same "
- "order");
-
- foreach (constr in tparms.constraints) {
- mutable should_add = true;
- foreach (con in ps.constraints)
- when (con.tyvar.GetName().Equals (constr.tyvar.GetName()))
- should_add = false;
- when (should_add)
- new_constr = constr :: new_constr;
- }
- if (new_constr : object != acc.constraints)
- PT.Typarms (acc.tyvars, new_constr)
- else
- acc
- });
-
- (this.tenv, this.typarms) =
- tenv.AddTyparms (this.GlobalEnv, ps, this, check_parms = false);
+ };
+
+ when (!tparms.tyvars.Equals(_ast.typarms.tyvars))
+ incorrectTyParamsParts ::= (tparms, part);
+
+ foreach (constr in tparms.constraints)
+ {
+ mutable should_add = true;
+
+ foreach (con in ps.constraints)
+ when (con.tyvar.GetName().Equals (constr.tyvar.GetName()))
+ should_add = false;
+
+ when (should_add)
+ new_constr = constr :: new_constr;
+ }
+
+ if (new_constr : object != acc.constraints) PT.Typarms
(acc.tyvars, new_constr)
+ else acc
+ }
+
+ def ps = partial_parts.FoldLeft(ps, processPart);
+
+ unless (incorrectTyParamsParts.IsEmpty)
+ {
+ def getLoc(part)
+ {
+ if (part.TypeParametersLocation == Location.Default)
part.NameLocation
+ else part.TypeParametersLocation
+ }
+ surroundwith (related_messages)
+ {
+ Message.Error(getLoc(_ast),
+ $"partial declarations of `$this' must have the same type
parameter names in the same order");
+ foreach ((tparms, part) in incorrectTyParamsParts)
+ Message.Hint(getLoc(part).FromStart(), $"other part
($tparms)");
+ }
+ }
+
+
+ (this.tenv, this.typarms) = tenv.AddTyparms (this.GlobalEnv, ps,
this, check_parms = false);
}
when (forced_typarms != null) {
@@ -961,45 +992,45 @@
// after we updated parsed tenvs of types with partial parts
// we should copy them to nested types
// we do this using parsetrees, so the fresh StaticVars are used
- unless (this.pt_tydecl.typarms == null) {
+ unless (this._ast.typarms == null)
+ {
def ht = Hashtable ();
- foreach (tv in this.pt_tydecl.typarms.tyvars) {
+ foreach (tv in this._ast.typarms.tyvars)
+ {
def nm = tv.GetName ();
if (ht.Contains (nm))
- Message.Error ($ "duplicate type parameter `$nm'")
+ Message.Error ($"duplicate type parameter `$nm'")
else ht [nm] = null;
}
- foreach (x in contained_types) {
+ foreach (x in contained_types)
+ {
def x = x.ParsedDeclaration;
if (x.typarms == null)
- x.typarms = this.pt_tydecl.typarms;
- else {
- def tp1 = this.pt_tydecl.typarms;
+ x.typarms = this._ast.typarms;
+ else
+ {
+ def tp1 = this._ast.typarms;
def tp2 = x.typarms;
foreach (tv in tp2.tyvars)
- when (ht.Contains (tv.GetName ())) {
- Message.Error (x.Location,
- $ "type parameter `$(tv.GetName ())' has the
same "
- "name as type parameter from the outer "
- "type `$(this)'");
- Message.Hint ("type parameters are inherited in nested "
- "types and can be used without declaring "
- "them explicitly");
- }
- x.typarms =
- PT.Typarms (tp1.tyvars + tp2.tyvars,
- tp1.constraints + tp2.constraints)
+ when (ht.Contains (tv.GetName ()))
+ {
+ Message.Error(x.Location,
+ $"type parameter `$(tv.GetName())' has the same name as
type parameter from the outer type `$(this)'");
+ Message.Hint("type parameters are inherited in nested types
and can be used without declaring them explicitly");
+ }
+
+ x.typarms = PT.Typarms (tp1.tyvars + tp2.tyvars, tp1.constraints
+ tp2.constraints);
}
}
}
- match (pt_tydecl) {
+ match (_ast)
+ {
| PT.TopDeclaration.VariantOption (members) =>
- unless (Util.is_capitalized (name)) {
- Message.Error (loc, "variant options' names must start with
capital letter")
- };
+ unless (Util.is_capitalized (name))
+ Message.Error(NameLocation, "variant options' names must start
with capital letter");
foreach (mem in members)
unless (mem.Attributes %&& NemerleAttributes.AccessModifiers)
@@ -1032,7 +1063,7 @@
*/
protected internal bind_types () : void
{
- def td = this.pt_tydecl;
+ def td = this._ast;
is_obsolete = HasAttribute (InternalType.Obsolete_tc);
this.tenv = this.tenv.CopyWithObsolete (!is_obsolete);
@@ -1842,7 +1873,8 @@
add_derived_members ();
// handle enum members separately
- match (pt_tydecl) {
+ match (_ast)
+ {
| PT.TopDeclaration.Enum (decls = ds) => add_enum_members (ds);
| _ => ()
};
@@ -2065,6 +2097,14 @@
| _ => Util.ice ()
}
}
+
+ /// determine equality of methods signatures taking into account types
substitutions.
+ /// For axample you can compare method of implemented interface and it
implementation
+ /// on current type.
+ public EqualsMethodsSignatures(baseTypeMethod : IMethod, method :
IMethod) : bool
+ {
+ methods_matches_by_signature(baseTypeMethod, method)
+ }
methods_matches_by_signature (iface_meth : IMethod, meth : IMethod) :
bool
{
@@ -2093,11 +2133,11 @@
*/
internal resolve_method_implements () : void
{
- check_abstract ();
-
- def methods = GetMethods (BindingFlags.DeclaredOnly %|
BindingFlags.Public %|
- BindingFlags.Instance %|
BindingFlags.NonPublic);
- def methods = NList.Map (methods, fun (x) { x :> MethodBuilder });
+ check_abstract();
+
+ def methods = GetMethods (BindingFlags.DeclaredOnly %|
BindingFlags.Public
+ %| BindingFlags.Instance %|
BindingFlags.NonPublic);
+ def methods = methods.Map(_ :> MethodBuilder);
// FIXME: in fact we should only mark some methods as implemented and
scream
// when signature match is ambiguous
@@ -2114,8 +2154,7 @@
// "$(proposed_meth.GetMemType ()) req "
// "$(GetMemType ().TypeOfMethod (iface_meth))");
if (methods_matches_by_signature (iface_meth, proposed_meth))
- if (proposed_meth.Attributes %&& NemerleAttributes.Public &&
- !(proposed_meth.Attributes %&& NemerleAttributes.Static))
+ if (proposed_meth.Attributes %&& NemerleAttributes.Public
&& !(proposed_meth.Attributes %&& NemerleAttributes.Static))
true
else
{
@@ -2126,23 +2165,27 @@
}
else false
};
- NList.Partition (ifmethods, is_correct)
+
+ ifmethods.Partition(is_correct)
}
- def collect_methods (tc, iface_methods) {
- foreach (m is IMethod in tc.GetMembers (BindingFlags.DeclaredOnly %|
- BindingFlags.Public %|
- BindingFlags.Instance))
- match (iface_methods.Get (m.Name)) {
- | Some (lst) => iface_methods.Set (m.Name, m :: lst)
- | None => iface_methods.Add (m.Name, [m])
+ def collect_methods (tc, iface_methods)
+ {
+ foreach (m is IMethod in tc.GetMembers(BindingFlags.DeclaredOnly %|
BindingFlags.Public
+ %| BindingFlags.Instance))
+ match (iface_methods.Get(m.Name))
+ {
+ | Some (lst) => iface_methods.Set(m.Name, m :: lst)
+ | None => iface_methods.Add (m.Name, [m])
};
}
- foreach (tc : TypeInfo in InterfacesToImplement ()) {
+ foreach (tc : TypeInfo in InterfacesToImplement ())
+ {
// Message.Debug ($ "in $this, $tc .GetMembers == $(tc.GetMembers
(BindingFlags.DeclaredOnly %| BindingFlags.Public %|
BindingFlags.Instance))");
collect_methods (tc, iface_methods);
}
+
foreach (mtype in t_implements)
collect_methods (mtype.tycon, can_explicitly_impl_methods);
@@ -2162,21 +2205,24 @@
match (MonoBindType (ns))
{
| Class (tc, _) => tc
- | m_ty => Message.FatalError ($ "cannot implement
method from non-class type $m_ty")
- }
- }
+ | m_ty => Message.Error (impl.Location, $"cannot
implement method from non-class type $m_ty");
+ null
+ }
+ };
def is_correct (iface_meth : IMethod)
{
- iface_meth.DeclaringType.Equals (ty)
- && methods_matches_by_signature (iface_meth, meth)
+ ty != null
+ && iface_meth.DeclaringType.Equals(ty)
+ && methods_matches_by_signature(iface_meth, meth)
}
Manager.MarkAsUsed (meth, !IsObsolete);
def partition_and_set (meths, methods_map)
{
- def (correct, notcorrect) = NList.Partition (meths,
is_correct);
+ def (correct, notcorrect) = meths.Partition(is_correct);
+
match (correct)
{
| [] =>
@@ -2185,39 +2231,54 @@
{
t_implements.Exists(x => x.tycon : object == itf)
}
- if (isImplementInterface(ty))
- Message.FatalError ($"interface `$(ty.FullName)' does
not contain method named `$member' with proper signature")
- else
- Message.FatalError (meth.Location, $"the $meth try to
implement interface `$(ty.FullName)' which don't implement by type
`$(this.FullName)'")
-
+ when (ty != null)
+ {
+ if (isImplementInterface(ty))
+ Message.Error(impl.Location, $"interface
`$(ty.FullName)' does not contain method named `$member' with proper
signature");
+ else
+ Message.Error(impl.Location, $"the $meth try to
implement interface `$(ty.FullName)' which don't implement by type
`$(this.FullName)'");
+ }
+ null
+
| [m] =>
methods_map.Set (member, notcorrect);
m
-
+
+ | null => null
| _ =>
- Message.FatalError ($"interface `$(ty.FullName)'
contains more then one method named `$member' with proper signature")
+ Message.Error (impl.Location, $"interface
`$(ty.FullName)' contains more then one method named `$member' with proper
signature");
+ correct.Head
}
}
match (iface_methods.Get (member))
{
- | Some (meths) => partition_and_set (meths, iface_methods);
+ | Some (meths) => partition_and_set(meths, iface_methods)
| None =>
match (can_explicitly_impl_methods.Get (member))
{
- | Some (meths) => partition_and_set (meths,
can_explicitly_impl_methods);
- | _ => Message.FatalError ($ "no interface implemented
by `$FullName' contains method named `$member' (looking for `$impl')")
+ | Some (meths) => partition_and_set(meths,
can_explicitly_impl_methods);
+ | _ =>
+ Message.Error(impl.Location, $"no interface
implemented by `$FullName' contains method named `$member' (looking for
`$impl')");
+ null
}
}
- | _ => Message.FatalError ("simple identifier expected in
explicit implementation specifier")
+ | _ => Message.Error(impl.Location, "simple identifier expected
in explicit implementation specifier");
+ null
}
}
match (meth.Ast.implemented)
{
| (_ :: _) as impl =>
- def impl2 = try { impl.RevMap(bind_one) } catch { _ is Recovery
=> [] };
+ def impl2 =
+ try
+ {
+ def res = impl.RevMap(bind_one);
+ if (res.Contains(null)) res.Remove(null)
+ else res
+ } catch { _ is Recovery => [] };
// make method virtual, because it implements something
// we do it exactly here (not earlier in validity checks),
because this
@@ -2234,7 +2295,8 @@
}
}
- NList.Iter (methods, bind_explicit_implements);
+ foreach (m in methods)
+ bind_explicit_implements(m);
def already_bound = Hashtable ();
@@ -2257,7 +2319,7 @@
def lst = already_bound [meth.Name] : list [IMethod];
def (additional, _) = partition_correct_meth (lst,
meth, false);
unless (additional.IsEmpty)
- Message.Error (meth.Location, $"ambiguous
implements-match for interface method(s): $additional, please use explicit
implementation");
+ Message.Error (meth.NameLocation, $"ambiguous
implements-match for interface method(s): $additional, please use explicit
implementation");
lst
}
else [];
@@ -2289,7 +2351,8 @@
}
}
- NList.Iter (methods, bind_implicit_implements);
+ foreach (m in methods)
+ bind_implicit_implements(m);
// create the additional overrides for unresolved interface methods
// we check if methods derived from base class are actually proper
@@ -2298,13 +2361,16 @@
def create_additional_overrides (name : string, mutable meths : list
[IMethod])
{
- unless (meths is []) {
+ unless (meths is [])
+ {
// possible implementators from existing methods
def possible_impls = LookupMember (name);
// choose only methods from within possible implementors
- foreach (meth is IMethod in possible_impls) {
- match (partition_correct_meth (meths, meth, false)) {
+ foreach (meth is IMethod in possible_impls)
+ {
+ match (partition_correct_meth (meths, meth, false))
+ {
| ([], _) => ()
| (correct, notcorrect) =>
meths = notcorrect;
@@ -2315,10 +2381,10 @@
//Message.Debug ("additional " +
meth_header.name);
def mods =
- if ((meth.Attributes %&& NemerleAttributes.Virtual) &&
- !(meth.Attributes %&& NemerleAttributes.Sealed))
+ if ((meth.Attributes %&& NemerleAttributes.Virtual)
&& !(meth.Attributes %&& NemerleAttributes.Sealed))
NemerleAttributes.Override
- else NemerleAttributes.New;
+ else
+ NemerleAttributes.New;
def subst = GetMemType ().ConstructSubstForTypeInfo
(meth.DeclaringType);
def parse_tr = meth_header.CreateAliasMethod (mods |
NemerleAttributes.Public, obj, subst);
def wrapper = DefineAndReturn (parse_tr) :> MethodBuilder;
@@ -2330,21 +2396,25 @@
wrapper.ImplementedMethods = correct;
}
}
+
resolved_additionals = (name, meths) :: resolved_additionals;
}
}
- iface_methods.Iter (create_additional_overrides);
- foreach ((name, meths) in resolved_additionals) iface_methods.Set
(name, meths);
+
+ foreach ((name, meths) in iface_methods.KeyValuePairs)
+ create_additional_overrides(name, meths);
+
+ foreach ((name, meths) in resolved_additionals)
+ iface_methods.Set(name, meths);
// emit error messages for any unbound interface method
- def scream_about_unimplemented (_, meths : list [IMethod])
+ def scream_about_unimplemented(meths : list [IMethod])
{
def methods = methods;
foreach (meth in meths)
{
// the word ``method'' comes from meth.ToString
- Message.Error (this.NameLocation,
- $"unimplemented interface $(meth) (in $(this.FullName) type)");
+ Message.Error (this.NameLocation, $"unimplemented interface
$(meth) (in $(this.FullName) type)");
UnimplementedMembers ::= meth;
// following code can let wrong messge, but it can get hint to
solv problem
@@ -2356,13 +2426,14 @@
}
}
- iface_methods.Iter (scream_about_unimplemented);
-
- foreach (meth is MethodBuilder in GetMembers ())
- when (meth.overridden_method != null) {
- meth.ImplementedMethods = meth.overridden_method ::
meth.ImplementedMethods;
- meth.overridden_method = null;
- }
+ foreach (meths in iface_methods.Values)
+ scream_about_unimplemented(meths);
+
+ foreach (meth is MethodBuilder when meth.overridden_method != null in
GetMembers())
+ {
+ meth.ImplementedMethods = meth.overridden_method ::
meth.ImplementedMethods;
+ meth.overridden_method = null;
+ }
}
internal process_attributes (self_parm : list [Parsetree.SyntaxElement],
target : MacroTargets,
@@ -2571,9 +2642,9 @@
when (m.Attributes %&& NemerleAttributes.Abstract) {
attributes |= NemerleAttributes.Abstract;
if (m.DeclaringType.Equals (this))
- Message.Error ($"$m is abstract, but its declaring class
`$(FullName)' is not");
+ Message.Error(m.NameLocation, $"$m is abstract, but its
declaring class `$(FullName)' is not");
else
- Message.Error ($"$m must be overriden, because it is abstract
and the current class `$(FullName)' is not");
+ Message.Error(this.NameLocation, $"$m must be overriden,
because it is abstract and the current class `$(FullName)' is not");
}
}
=======================================
--- /nemerle/trunk/ncc/parsing/AST.n Wed Oct 14 19:42:38 2009
+++ /nemerle/trunk/ncc/parsing/AST.n Mon Oct 26 02:38:15 2009
@@ -38,7 +38,7 @@
namespace Nemerle.Compiler {
[Record]
- public struct TextPoint
+ public struct TextPoint : System.IComparable[TextPoint]
{
public Line : int;
public Column : int;
@@ -49,6 +49,13 @@
public static @> (x : TextPoint, y : TextPoint) : bool { y < x }
public static @<= (x : TextPoint, y : TextPoint) : bool { !(y < x) }
public static @>= (x : TextPoint, y : TextPoint) : bool { !(x < y) }
+
+ public CompareTo(other : TextPoint) : int
+ {
+ if (this == other) 0
+ else if (this > other) 1
+ else -1
+ }
override public ToString() : string
{
@@ -57,7 +64,7 @@
}
[DebuggerDisplay(<#{File + ":" + Line + ":" + Column + ":" + EndLine
+ ":" + EndColumn + (IsGeneratedOrEmpty ? "-gen" : "")}#>)]
- public struct Location : System.IComparable [Location]
+ public struct Location : System.IComparable[Location]
{
static this ()
{
=======================================
--- /nemerle/trunk/ncc/testsuite/negative/implements.n Sun Oct 19 17:52:08
2008
+++ /nemerle/trunk/ncc/testsuite/negative/implements.n Mon Oct 26 02:38:15
2009
@@ -44,8 +44,9 @@
abstract public m (x : int) : void; // OK
} // OK
-class Z { // E: method .* is abstract, but its declaring class.* is not
- abstract public m () : void;
+class Z
+{
+ abstract public m () : void; // E: method .* is abstract, but its
declaring class.* is not
}
class Y1 : X { } // E: method .* must be overriden, because it is abstract
and the current class.* is not
=======================================
--- /nemerle/trunk/ncc/testsuite/negative/partial.n Sun Jun 18 14:49:41 2006
+++ /nemerle/trunk/ncc/testsuite/negative/partial.n Mon Oct 26 02:38:15 2009
@@ -1,4 +1,5 @@
-namespace Tyvars {
+namespace Tyvars
+{
partial class C [X] { } // E: partial declarations of `Tyvars.C' must
have the same type parameter names in the same order
- partial class C [Y] { }
-}
+ partial class C [Y] { } // H: other part
+}