Revision: 8433
Author:
v...@rsdn.ru
Date: Tue Nov 10 12:44:15 2009
Log: Working on Integration: Implementing CodeDom support.
http://code.google.com/p/nemerle/source/detail?r=8433
Added:
/nemerle/trunk/VsIntegration/Nemerle.Compiler.Utils/Async/AsyncRequest/CreateCodeCompileUnitAsyncRequest.n
/nemerle/trunk/VsIntegration/Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/BackgroundWorks/Engine-CreateCodeCompileUnit.n
Modified:
/nemerle/trunk/VsIntegration/Nemerle.Compiler.Utils/Async/AsyncRequestType.n
/nemerle/trunk/VsIntegration/Nemerle.Compiler.Utils/FormCodeDomGenerator.n
/nemerle/trunk/VsIntegration/Nemerle.Compiler.Utils/FormCodeDomParser.n
/nemerle/trunk/VsIntegration/Nemerle.Compiler.Utils/Hints/HintHelper.n
/nemerle/trunk/VsIntegration/Nemerle.Compiler.Utils/Nemerle.Compiler.Utils.csproj
/nemerle/trunk/VsIntegration/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/QuickTipInfo.n
/nemerle/trunk/VsIntegration/Nemerle.Compiler.Utils/NemerleCodeParser.n
/nemerle/trunk/VsIntegration/Nemerle.VisualStudio/Project/NemerleEditorFactory.cs
/nemerle/trunk/VsIntegration/Nemerle.VisualStudio/Project/NemerleFileNodeCodeDomProvider.cs
/nemerle/trunk/VsIntegration/Nemerle.VisualStudio/Project/NemerleFileNodeProperties.cs
/nemerle/trunk/VsIntegration/Nemerle.VisualStudio/Project/NemerleProjectNode.cs
/nemerle/trunk/VsIntegration/Nemerle.VisualStudio/Project/NemerleVSMDProvider.cs
/nemerle/trunk/VsIntegration/Nemerle.VisualStudio/Project/RDTFileTextMerger.cs
=======================================
--- /dev/null
+++
/nemerle/trunk/VsIntegration/Nemerle.Compiler.Utils/Async/AsyncRequest/CreateCodeCompileUnitAsyncRequest.n
Tue Nov 10 12:44:15 2009
@@ -0,0 +1,25 @@
+using System;
+using System.CodeDom;
+using System.CodeDom.Compiler;
+using System.Linq;
+using System.Threading;
+
+using Nemerle.Collections;
+using Nemerle.Completion2;
+using Nemerle.Utility;
+
+namespace Nemerle.Compiler.Utils.Async
+{
+ public class CreateCodeCompileUnitAsyncRequest : AsyncRequest
+ {
+ public this(engine : Engine, source : ISource, designerFileIndex :
int, work : Action[AsyncRequest])
+ {
+ base(AsyncRequestType.CreateCodeCompileUnit, engine, source, work);
+ DesignerFileIndex = designerFileIndex;
+ }
+
+ public DesignerFileIndex : int { get; private set; }
+
+ public CodeCompileUnit : CodeCompileUnit { get; internal set; }
+ }
+}
=======================================
--- /dev/null
+++
/nemerle/trunk/VsIntegration/Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/BackgroundWorks/Engine-CreateCodeCompileUnit.n
Tue Nov 10 12:44:15 2009
@@ -0,0 +1,89 @@
+using System;
+using System.CodeDom;
+using System.CodeDom.Compiler;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Linq;
+
+using Nemerle.Assertions;
+using Nemerle.Collections;
+using Nemerle.Compiler;
+using Nemerle.Compiler.Parsetree;
+using Nemerle.Imperative;
+using Nemerle.Utility;
+using Nemerle.Compiler.Utils;
+using Nemerle.Compiler.Utils.Async;
+using Nemerle.Surround;
+
+namespace Nemerle.Completion2
+{
+ public partial class Engine
+ {
+ public BeginCreateCodeCompileUnit(source : ISource,
designerFileIndex : int) : CreateCodeCompileUnitAsyncRequest
+ {
+ def request = CreateCodeCompileUnitAsyncRequest(this, source,
designerFileIndex, CreateCodeCompileUnit);
+ AsyncWorker.AddWork(request);
+ request
+ }
+
+ public CreateCodeCompileUnit(source : ISource, designerFileIndex :
int) : CodeCompileUnit
+ {
+ def request = BeginCreateCodeCompileUnit(source, designerFileIndex);
+ _ = request.AsyncWaitHandle.WaitOne();
+ when (request.Stop)
+ assert(false);
+
+ request.CodeCompileUnit
+ }
+
+ /// Run by AsyncWorker thread!
+ /// Parse CompileUnit. Set CompileUnit to source. Update information
about outline regions.
+ private CreateCodeCompileUnit(request : AsyncRequest) : void
+ {
+ AsyncWorker.CheckCurrentThreadIsTheAsyncWorker();
+
+ surroundwith (currentAsyncRequest)
+ try
+ {
+
+ when (request.Stop)
+ return;
+
+ if (IsBuildTypesTreeInProgress)
+ AsyncWorker.AddWork(request);
+ else
+ {
+ def project = this.Project;
+
+ if (project == null)
+ {
+ _ = BeginBuildTypesTree();
+ AsyncWorker.AddWork(request);
+ }
+ else
+ {
+ def req = request :> CreateCodeCompileUnitAsyncRequest;
+ def codeDomParser = FormCodeDomParser();
+
+ req.CodeCompileUnit =
codeDomParser.CreateCodeCompileUnit(project,
+ req.Source.FileIndex,
req.DesignerFileIndex);
+
+ req.MarkAsCompleted();
+ }
+ }
+
+ //Debug.WriteLine($"UpdateCompileUnit 6 $(timer.Elapsed)");
timer.Reset(); timer.Start();
+ }
+ catch
+ { | e is CompilationAbortedException =>
+ def msg = $"The parse CompileUnit operation aborted at:
$(e.Message)";
+ throw CompilationAbortedException(msg, e);
+ }
+ finally
+ {
+ //AsyncWorker.AddResponse(() => _callback.SetStatusText("Update
compile unit is complete."));
+ request.MarkAsCompleted();
+ }
+ }
+ } // end class Engine
+} // end of Nemerle.Completion2 namespace
=======================================
---
/nemerle/trunk/VsIntegration/Nemerle.Compiler.Utils/Async/AsyncRequestType.n
Wed Oct 28 21:02:28 2009
+++
/nemerle/trunk/VsIntegration/Nemerle.Compiler.Utils/Async/AsyncRequestType.n
Tue Nov 10 12:44:15 2009
@@ -24,5 +24,6 @@
| FindUnimplementedMembers
| FindMethodsToOverride
| CloseProject
+ | CreateCodeCompileUnit
}
}
=======================================
---
/nemerle/trunk/VsIntegration/Nemerle.Compiler.Utils/FormCodeDomGenerator.n
Wed Oct 14 19:42:38 2009
+++
/nemerle/trunk/VsIntegration/Nemerle.Compiler.Utils/FormCodeDomGenerator.n
Tue Nov 10 12:44:15 2009
@@ -272,16 +272,16 @@
match((_oldMethods.Find(m => m.Name == "InitializeComponent" ),
_codeDomMethods.Find(m => m.Name == "InitializeComponent" ))
)
{
- | (om,Some(cdm)) =>
+ | (om, Some(cdm)) =>
using(def sw = StringWriter())
{
Output = sw;
Indent = 2; // TODO: maybe we should change it dynamically?
GenerateIndent();
- GenerateMethod(cdm,classDecl);
-
- def linesList =
CodeDomHelper.StringToListOfLines(sw.ToString() );
+ GenerateMethod(cdm, classDecl);
+
+ def linesList =
CodeDomHelper.StringToListOfLines(sw.ToString());
match(om)
{
@@ -413,41 +413,42 @@
{
if (fileIndex == _mainFileIndex)
{
- _oldMethods.Iter(_m =>
- {
- assert2(false);
- //def loc = m.Location;
- //when (loc.FileIndex == _mainFileIndex)
- // m.Location = Completion.Relocate(loc, line, 0, lineOffset,
0)
- } );
-
- _codeDomMethods.Iter(m =>
- {
- def locRef = m.UserData[typeof(Location)];
- when (locRef != null)
- {
- def loc = locRef :> Location;
- when (loc.FileIndex == fileIndex)
- {
- def pt = m.UserData[typeof(Point)] :> Point;
- when (pt.Y > line)
- {
- pt.Y += lineOffset;
- m.UserData[typeof(Point)] = pt;
- }
+ foreach (_m in _oldMethods)
+ {
+ assert2(false);
+ //def loc = m.Location;
+ //when (loc.FileIndex == _mainFileIndex)
+ // m.Location = Completion.Relocate(loc, line, 0, lineOffset, 0)
+ }
+
+ foreach (m in _codeDomMethods)
+ {
+ def locRef = m.UserData[typeof(Location)];
+
+ when (locRef != null)
+ {
+ def loc = locRef :> Location;
+ when (loc.FileIndex == fileIndex)
+ {
+ def pt = m.UserData[typeof(Point)] :> Point;
+ when (pt.Y > line)
+ {
+ pt.Y += lineOffset;
+ m.UserData[typeof(Point)] = pt;
}
}
- } );
+ }
+ }
}
else // fileIndex == _designerFileIndex
{
- _oldFields.Iter(_f =>
- {
- assert2(false);
- //def loc = f.Location;
- //when (loc.FileIndex == fileIndex)
- // f.Location = Completion.Relocate(loc, line, 0, lineOffset,
0)
- } );
+ foreach (_f in _oldFields)
+ {
+ assert2(false);
+ //def loc = f.Location;
+ //when (loc.FileIndex == fileIndex)
+ // f.Location = Completion.Relocate(loc, line, 0, lineOffset, 0)
+ }
}
}
@@ -464,10 +465,16 @@
| NonEqual => { removeFunc(h1); dispatcher(t1,new_l) }
| Renamed => { renameFunc(h1,h2); dispatcher(t1,t2) }
}
- | (_, []) => old_l.Iter(removeFunc(_) )
- | ([], _) => new_l.Iter(addFunc(_) )
- }
- dispatcher(old_list, new_list )
+ | (_, []) =>
+ foreach (x in old_l)
+ removeFunc(x);
+
+ | ([], _) =>
+ foreach (x in new_l)
+ addFunc(x);
+ }
+
+ dispatcher(old_list, new_list)
}
static protected GetChangeStatus[T1,T2](oldMember: T1, codeDomMember:
T2 ) : ChangeStatus
=======================================
--- /nemerle/trunk/VsIntegration/Nemerle.Compiler.Utils/FormCodeDomParser.n
Mon Jul 20 07:47:18 2009
+++ /nemerle/trunk/VsIntegration/Nemerle.Compiler.Utils/FormCodeDomParser.n
Tue Nov 10 12:44:15 2009
@@ -1,4 +1,4 @@
-using System;
+using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
@@ -39,36 +39,33 @@
CodeCompileUnit itself contains typeof(FormCodeInfo) in UserData
*/
- public CreateCodeCompileUnit(project : Project,
- mainFilePath: string, designerFilePath: string) : CodeCompileUnit
+ public CreateCodeCompileUnit(project : Project, mainFileIndex : int,
designerFileIndex : int) : CodeCompileUnit
{
// Initialization
_project = project;
base._manager = _project.Engine;
- _mainFileIndex = Location.GetFileIndex(mainFilePath);
- _designerFileIndex = if(designerFilePath != null)
Location.GetFileIndex(designerFilePath)
- else -1;
-
- // TODO: new object vs Clear
- cachedObjs = NC.Hashtable();
+ _mainFileIndex = mainFileIndex;
+ _designerFileIndex = designerFileIndex;
+
+ //// TODO: new object vs Clear
+ //cachedObjs = NC.Hashtable();
// Processing
def unit = CodeCompileUnit();
def globalImports = List();
- foreach(decl in
project.CompileUnits.GetTopNamespace(_mainFileIndex).Decls)
- {
- | Decl.Namespace as nsDecl =>
- {
- Debug.Write(nsDecl);
- _ = unit.Namespaces.Add(ProcessNamespace(nsDecl));
- }
- | Decl.Using as usDecl =>
+ foreach(decl in
project.CompileUnits.GetTopNamespace(_designerFileIndex).Decls)
+ {
+ | Decl.Namespace as nsDecl => _ =
unit.Namespaces.Add(ProcessNamespace(nsDecl));
+
+ | Decl.Using as usDecl =>
globalImports.Add(usDecl.Name.ToString("."));
//unit.Imports.Add(CodeNamespaceImport());
+
| d with(bodyLoc =
project.CompileUnits.GetTopNamespace(_mainFileIndex).BodyLocation) =>
+ //TODO: VladD2: Какая-то чушь...
throw CodeDomSerializerException($"Assumed root Declaration of
CompileUnit is Decl.Namespace, got $d",
CodeLinePragma(bodyLoc.File,bodyLoc.Line));
}
@@ -81,7 +78,8 @@
assert(_formCodeInfo.newMethodInsertionLine != -1 &&
_formCodeInfo.newFieldInsertionLine != -1,
"Don't know where generated fields and methods should be
placed");
- unit.UserData.Add(typeof(FormCodeInfo),_formCodeInfo);
+ //TODO: VladD2: Какая-то чушь...
+ unit.UserData.Add(typeof(FormCodeInfo), _formCodeInfo);
/*
Debug.Write(CodeDomHelper.ToString(unit,
@@ -90,10 +88,7 @@
Microsoft.CSharp.CSharpCodeProvider().CreateGenerator()));
*/
- Debug.Write($"_formCodeInfo.newMethodInsertionLine =
$(_formCodeInfo.newMethodInsertionLine)\n");
- Debug.Write($"_formCodeInfo.newFieldInsertionLine =
$(_formCodeInfo.newFieldInsertionLine)\n");
-
- unit;
+ unit
}
private ProcessNamespace(decl: Decl.Namespace) : CodeNamespace
@@ -104,19 +99,18 @@
match(decl)
{
| Decl.Type(ast) =>
- {
- assert( res.Types.Count < 2, "Form files should not contain
more than one top class declaration");
+ assert(res.Types.Count < 2, "Form files should not contain
more than one top class declaration");
//Debug.Write(typeDecl.Ast);
InitFormCodeInfo(ast.TypeBuilder);
- _ = res.Types.Add(ProcessTypeDeclaration(ast.TypeBuilder));
- }
+ _ = res.Types.Add(ProcessTypeDeclaration(ast));
| Decl.Using as usDecl =>
res.Imports.Add(CodeNamespaceImport(usDecl.Name.ToString(".")));
| Decl.Namespace(BodyLocation = bodyLoc) =>
+ //TODO: VladD2: Какая-то чушь... Счего бы это нельзя иметь
вложенных пространств имен?
throw CodeDomSerializerException("Namespace declarations
cannot contain inner namespace declarations",
CodeLinePragma(bodyLoc.File,bodyLoc.Line));
@@ -125,20 +119,20 @@
res
}
-
- protected override ProcessClassMembers(members:
list[IMember],classDecl: CodeTypeDeclaration) : void
- {
- members.Iter(m : IMember =>
- match(m)
- {
- | m is TypeBuilder =>
- {_ = classDecl.Members.Add(CreateClass(m));}
- | m is MemberBuilder when
(!m.Name.OrdinalStartsWith("_N_field_initialiser")) =>
- {_ = classDecl.Members.Add(CreateMember(m));}
- | _ =>
- () //Debug.Print($"Declaration of external member $m ignored");
- }
- );
+/*
+ protected override ProcessClassMembers(members: list[IMember],
classDecl: CodeTypeDeclaration) : void
+ {
+ foreach (m in members)
+ {
+ | m is TypeBuilder =>
+ _ = classDecl.Members.Add(CreateClass(m));
+
+ | m is MemberBuilder when
(!m.Name.OrdinalStartsWith("_N_field_initialiser")) =>
+ _ = classDecl.Members.Add(CreateMember(m));
+
+ | _ =>
+ () //Debug.Print($"Declaration of external member $m ignored");
+ }
}
protected override CreateMember(member: MemberBuilder) : CodeTypeMember
@@ -186,7 +180,7 @@
methodDecl
}
-
+*/
private InitFormCodeInfo(typeBuilder: TypeBuilder) : void
{
// Make sure at least main and designer files are included in
PartsLocation
@@ -209,10 +203,10 @@
}
// process cached objects because form designer doesn't understand 'em
- #region Cached objects related
-
- protected mutable cachedObjs : NC.Hashtable[string,CodeExpression];
-
- #endregion
+ //#region Cached objects related
+ //
+ //protected mutable cachedObjs : NC.Hashtable[string,CodeExpression];
+ //
+ //#endregion
}
}
=======================================
--- /nemerle/trunk/VsIntegration/Nemerle.Compiler.Utils/Hints/HintHelper.n
Sun Nov 8 15:56:08 2009
+++ /nemerle/trunk/VsIntegration/Nemerle.Compiler.Utils/Hints/HintHelper.n
Tue Nov 10 12:44:15 2009
@@ -446,13 +446,13 @@
else ""
}
- private static GetDocText(member : IMember, location : Location) :
string
- {
- def info = XmlDocReader.GetInfo(member, location);
-
- if (info != null) $"<lb/><b><hint
value='Documetnation'>$(info.GetText())</hint></b>"
- else ""
- }
+ //private static GetDocText(member : IMember, location : Location) :
string
+ //{
+ // def info = XmlDocReader.GetInfo(member, location);
+
+ // if (info != null) $"<lb/><b><hint
value='Documetnation'>$(info.GetText())</hint></b>"
+ // else ""
+ //}
private static GetDoc(member : IMember) : XmlDocInfo
{
=======================================
---
/nemerle/trunk/VsIntegration/Nemerle.Compiler.Utils/Nemerle.Compiler.Utils.csproj
Fri Nov 6 11:41:29 2009
+++
/nemerle/trunk/VsIntegration/Nemerle.Compiler.Utils/Nemerle.Compiler.Utils.csproj
Tue Nov 10 12:44:15 2009
@@ -298,6 +298,12 @@
<ItemGroup>
<Compile Include="Hints\HintHelper.n" />
</ItemGroup>
+ <ItemGroup>
+ <Compile
Include="Async\AsyncRequest\CreateCodeCompileUnitAsyncRequest.n" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile
Include="Nemerle.Completion2\Engine\BackgroundWorks\Engine-CreateCodeCompileUnit.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/QuickTipInfo.n
Sun Nov 8 15:56:08 2009
+++
/nemerle/trunk/VsIntegration/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/QuickTipInfo.n
Tue Nov 10 12:44:15 2009
@@ -146,13 +146,6 @@
s
}
-
- private static GetDocText(mtype : MType, location : Location) : string
- {
- def info = XmlDocReader.GetInfo(mtype.TypeInfo, location);
-
- if (info != null) "\n" + info.GetText() else ""
- }
private static GetDocText(member : IMember, location : Location) :
string
{
=======================================
--- /nemerle/trunk/VsIntegration/Nemerle.Compiler.Utils/NemerleCodeParser.n
Mon Aug 31 14:24:47 2009
+++ /nemerle/trunk/VsIntegration/Nemerle.Compiler.Utils/NemerleCodeParser.n
Tue Nov 10 12:44:15 2009
@@ -28,6 +28,8 @@
// now CodeDomParser only parses files from Project.CompileUnits
// it is not thread-safe at the moment!
+ //TODO: VladD2: Убрать наследование от ManagerClass. Вместо этого
использовать проект к которому подлючен разбираемый файл.
+
/// <summary>
/// Provides an implementation of the <see
cref="T:System.CodeDom.Compiler.ICodeParser"/> interface.
/// </summary>
@@ -320,14 +322,14 @@
//TODO: codeProperty.Parameters = ???
match (prop.get)
{
- | Some (m) =>
codeProperty.GetStatements.AddRange(ToStatements(m.Body).NToArray());
- | None => ()
+ | Some (m) =>
codeProperty.GetStatements.AddRange(ToStatements(m.Body).NToArray());
+ | None => ()
}
match (prop.set)
{
- | Some (m) =>
codeProperty.SetStatements.AddRange(ToStatements(m.Body).NToArray());
- | None => ()
+ | Some (m) =>
codeProperty.SetStatements.AddRange(ToStatements(m.Body).NToArray());
+ | None => ()
}
codeProperty;
@@ -351,16 +353,12 @@
{
| ClassMember.TypeDeclaration as tyDecl
when tyDecl.td is TopDeclaration.Class =>
ToCodeTypeDeclaration(tyDecl.td :> TopDeclaration.Class);
-
| ClassMember.TypeDeclaration as tyDecl
when tyDecl.td is TopDeclaration.Variant =>
ToCodeTypeDeclaration(tyDecl.td :> TopDeclaration.Variant);
-
| ClassMember.TypeDeclaration as tyDecl
when tyDecl.td is TopDeclaration.VariantOption =>
ToCodeTypeDeclaration(tyDecl.td :> TopDeclaration.VariantOption);
-
| ClassMember.TypeDeclaration as tyDecl
when tyDecl.td is TopDeclaration.Delegate =>
ToCodeTypeDelegate(tyDecl.td :> TopDeclaration.Delegate);
-
| ClassMember.Field as field => ToCodeMemberField(field);
| ClassMember.Function as func => ToCodeMemberMethod(func);
| ClassMember.Property as prop => ToCodeMemberProperty(prop);
@@ -384,24 +382,25 @@
CodeAttributeDeclaration(ToCodeTypeReference(attr));
}
- protected ProcessTypeDeclaration(typeDecl: TypeBuilder) :
CodeTypeDeclaration
- {
- match(typeDecl.GetTydecl())
- {
- | TypeDeclaration.Class => CreateClass(typeDecl)
+ protected ProcessTypeDeclaration(typeDecl : TopDeclaration) :
CodeTypeDeclaration
+ {
+ match(typeDecl)
+ {
+ | TopDeclaration.Class as typeDecl => CreateClass(typeDecl)
| _ =>
throw NotImplementedException("Non class top declarations aren't
supported yet")
}
}
- protected CreateClass(cls : TypeBuilder) : CodeTypeDeclaration
+ protected CreateClass(cls : TopDeclaration.Class) : CodeTypeDeclaration
{
// creates class declaration
def classDecl = CodeTypeDeclaration(cls.Name);
classDecl.Attributes =
CodeDomHelper.GetMemberAttributes(cls.Attributes);
- cls.GetDirectSuperTypes().Iter(baseType =>
- classDecl.BaseTypes.Add(baseType.tycon.FullName));
+
+ foreach (baseType in cls.TypeBuilder.GetDirectSuperTypes())
+ _ = classDecl.BaseTypes.Add(ToTypeRef(baseType));
// TODO: Seems like comments went away
//classDecl.Comments = CodeCommentStatement();
@@ -415,13 +414,16 @@
classDecl.IsPartial = CodeDomHelper.IsPartial(cls.Attributes);
classDecl.TypeAttributes =
CodeDomHelper.GetTypeAttributes(cls.Attributes);
+
// Set type parameters
// will it work?
- cls.Typarms.Iter(t => { _ =
classDecl.TypeParameters.Add(CodeTypeParameter(t.Name));});
+ //VladD2: Думаю, для форм это на фиг не нужно.
+ foreach (t in cls.typarms.tyvars)
+ _ = classDecl.TypeParameters.Add(CodeTypeParameter(t.ToString()));
// adds members
Debug.Print("ProcessClassMembers in reversed order");
- ProcessClassMembers(cls.GetMembers().Reverse(), classDecl);
+ ProcessClassMembers(cls.GetMembers(), classDecl);
//TODO: adds usings directives
@@ -433,75 +435,45 @@
}
// needed cause we may want to override it in derived classes
- protected virtual ProcessClassMembers(members : list[IMember],
classDecl : CodeTypeDeclaration) : void
- {
- members.Iter(m : IMember =>
- match(m)
- {
- | m is TypeBuilder => {_ =
classDecl.Members.Add(CreateClass(m));}
- //| m is EventBuilder => CreateEvent(m) // TODO
- | m is MemberBuilder => {_ =
classDecl.Members.Add(CreateMember(m));}
-
- //| m is ExternalEventInfo
- //| m is ExternalPropertyInfo
- //| m is MethodInfo =>
- | _ =>
- () //Debug.Print($"Declaration of external member $m ignored");
- /*| _ =>
- throw CodeDomSerializerException($"Unknown declaration type:
$m of type $(m.GetType().ToString())",
-
CodeLinePragma(m.Location.File, m.Location.Line));
- */
- }
- //}
- );
- }
-
- protected virtual CreateMember(member: MemberBuilder) : CodeTypeMember
- {
- Debug.Print($"CreateMember : from $member");
-
- // creates class declaration
- def memberDecl : CodeTypeMember =
- match(member)
- {
- | m is EventBuilder => CreateEvent(m)
- | m is FieldBuilder => CreateField(m)
- | m is MethodBuilder => CreateMethod(m)
- | m is PropertyBuilder => CreateProperty(m)
- | _ =>
- { Debug.WriteLine($"CodeDomParser ignore declaration:
$member : $(member.Name)"); null }
- }
-
- memberDecl.Name = member.Name;
-
- // performed in CreateField/CreateMethod
- //memberDecl.Attributes =
CodeDomHelper.GetMemberAttributes(member.Attributes);
-
- // TODO: Seems like comments went away
- //memberDecl.Comments = CodeCommentStatement();
-
- // TODO: Figure out how to parse CustomAttributes
- //memberDecl.CustomAttributes =
member.GetModifiers().GetCustomAttributes();
-
- // Add Location
- memberDecl.UserData.Add(typeof(Location), member.Location);
-
- memberDecl
+ protected virtual ProcessClassMembers(members : list[ClassMember],
classDecl : CodeTypeDeclaration) : void
+ {
+ foreach (m in members)
+ {
+ def codeTypeMember : CodeTypeMember =
+ match (m)
+ {
+ | ClassMember.TypeDeclaration(td) => ProcessTypeDeclaration(td)
+ | ClassMember.Field as field => CreateField(field)
+ | ClassMember.Property as prop => CreateProperty(prop)
+ | ClassMember.Event as vnt => CreateEvent(vnt)
+ | ClassMember.Function as func => CreateMethod(func)
+ | ClassMember.EnumOption =>
assert(false, "ClassMember.EnumOption not supported yet");
+ };
+
+ // TODO: Seems like comments went away
+ //memberDecl.Comments = CodeCommentStatement();
+
+ // TODO: Figure out how to parse CustomAttributes
+ //memberDecl.CustomAttributes =
member.GetModifiers().GetCustomAttributes();
+
+ //// Add Location
+ //memberDecl.UserData.Add(typeof(Location), member.Location);
+
+ codeTypeMember.UserData["Name"] = m.Name;
+ codeTypeMember.Name = m.Name;
+ _ = classDecl.Members.Add(codeTypeMember);
+ }
}
- protected virtual CreateField(field: FieldBuilder) : CodeMemberField
+ protected virtual CreateField(field : ClassMember.Field) :
CodeMemberField
{
// GetFieldInfo() doesn't work
//def fieldDecl = CodeMemberField(field.GetFieldInfo().FieldType,
field.Name);
Debug.Print($"CreateField: from field $field");
- def fieldMemType = field.GetMemType();
// TODO: VladD2: Using of GetSystemType() is bad idea!
- def fieldDecl = if(fieldMemType.GetSystemType() != null)
- CodeMemberField(fieldMemType.GetSystemType(),
field.Name)
- else
- CodeMemberField(fieldMemType.TypeInfo.FullName,
field.Name);
+ def fieldDecl = CodeMemberField(ToTypeRef(field.ty), field.Name);
fieldDecl.Attributes =
CodeDomHelper.GetMemberAttributes(field.Attributes, true);
@@ -517,7 +489,7 @@
fieldDecl
}
- protected virtual CreateProperty(prop : PropertyBuilder) :
CodeMemberProperty
+ protected virtual CreateProperty(prop : ClassMember.Property) :
CodeMemberProperty
{
Debug.Print($"CreateProperty: from $prop");
@@ -525,47 +497,43 @@
result.Attributes =
CodeDomHelper.GetMemberAttributes(prop.Attributes);
result.Name = prop.Name;
- when(prop.Getter != null)
+ when(prop.get is Some(get))
{
result.HasGet = true;
- result.Type = ToTypeRef(prop.Getter.ReturnType);
- when(prop.Getter is MethodBuilder)
- _ = result.GetStatements.AddRange(ToStatements((prop.Getter :>
MethodBuilder).BodyParsed).NToArray())
- }
- when(prop.Setter != null)
+ result.Type = ToTypeRef(get.header.ReturnType);
+ _ =
result.GetStatements.AddRange(ToStatements(get.Body).NToArray())
+ }
+
+ when(prop.set is Some(set))
{
result.HasSet = true;
- result.Type = ToTypeRef(prop.Setter.ReturnType);
- when(prop.Setter is MethodBuilder)
- _ = result.SetStatements.AddRange(ToStatements((prop.Setter :>
MethodBuilder).BodyParsed).NToArray())
- }
+ result.Type = ToTypeRef(set.header.ReturnType);
+ _ =
result.SetStatements.AddRange(ToStatements(set.Body).NToArray())
+ }
+
result
}
- protected virtual CreateEvent(evt : EventBuilder) : CodeMemberEvent
+ protected virtual CreateEvent(evt : ClassMember.Event) :
CodeMemberEvent
{
def eventDecl = CodeMemberEvent();
eventDecl.Attributes =
CodeDomHelper.GetMemberAttributes(evt.Attributes);
eventDecl.Name = evt.Name;
- // TODO: Find Type properly
- eventDecl.Type = ToTypeRef(evt.GetAdder().ReturnType);
-
+ eventDecl.Type = ToTypeRef(evt.ty);
eventDecl
}
- protected virtual CreateMethod(method: MethodBuilder) :
CodeMemberMethod
+ protected virtual CreateMethod(method : ClassMember.Function) :
CodeMemberMethod
{
Debug.Print($"CreateMethod : from $method");
def methodDecl : CodeMemberMethod =
- match(method.MemberKind)
- {
- | Constructor when method.IsStatic => CodeTypeConstructor()
- | Constructor => CodeConstructor()
- | Method when method.IsStatic
- && method.Name == "Main" => CodeEntryPointMethod()
- | Method => CodeMemberMethod()
- | other => throw
NotSupportedException($"Unsupported method kind: `$other'");
+ match(method.Name)
+ {
+ | ".ctor" when method.Attributes %&& NemerleAttributes.Static =>
CodeTypeConstructor()
+ | ".ctor" =>
CodeConstructor()
+ | "Main" when method.Attributes %&& NemerleAttributes.Static =>
CodeEntryPointMethod()
+ | _ =>
CodeMemberMethod()
};
methodDecl.Attributes =
CodeDomHelper.GetMemberAttributes(method.Attributes, false);
@@ -573,24 +541,22 @@
//TODO: methodDecl.ImplementationTypes - how to get that
//methodDecl.Parameters
- method.GetParameters().Iter(param =>
- { _ =
methodDecl.Parameters.Add(CodeParameterDeclarationExpression(ToTypeRef(param.ty),
param.Name)) }
- );
+ foreach (p in method.header.Parameters)
+ _ =
methodDecl.Parameters.Add(CodeParameterDeclarationExpression(ToTypeRef(p.Type),
p.Name));
//TODO: methodDecl.PrivateImplementationType ?
- methodDecl.ReturnType = ToTypeRef(method.ReturnType);
+ methodDecl.ReturnType = ToTypeRef(method.header.ReturnType);
// methodDecl.TypeParameters , TODO: check if it actually works
- method.GetHeader().typarms.Iter(typaram =>
- { _ =
methodDecl.TypeParameters.Add(CodeTypeParameter(typaram.Name))}
- );
-
- _currentMethod = method;
- method.EnsureCompiled(); // we need PExpr & TExpr
-
methodDecl.Statements.AddRange(ToStatements(method.BodyParsed).NToArray());
-
- Debug.Print($" method.BodyTyped.Location (col =
$(method.BodyTyped.Location.Column), line =
$(method.BodyTyped.Location.Line))");
+ foreach (tp in method.header.TypeParameters.tyvars)
+ _ =
methodDecl.TypeParameters.Add(CodeTypeParameter(tp.ToString()));
+
+ //_currentMethod = method;
+ method.Builder.EnsureCompiled(); // we need PExpr & TExpr
+
methodDecl.Statements.AddRange(ToStatements(method.Builder.BodyParsed).NToArray());
+
+ //Debug.Print($" method.BodyTyped.Location (col =
$(method.BodyTyped.Location.Column), line =
$(method.BodyTyped.Location.Line))");
methodDecl
}
@@ -601,6 +567,20 @@
CodeTypeReferenceExpression(ToTypeRef(typeInfo, typeParaams))
}
+ ToTypeRef(tyVar : PExpr) : CodeTypeReference
+ {
+ def cnvToCsTy(t : object)
+ {
+ t.ToString().Replace(".[", "<").Replace("[", "<").Replace("]", ">")
+ }
+ match (tyVar.TypedObject)
+ {
+ | t is TyVar => ToTypeRef(t)
+ | null => CodeTypeReference(cnvToCsTy(tyVar))
+ | t => CodeTypeReference(cnvToCsTy(t))
+ }
+ }
+
ToTypeRef(tyVar : TyVar) : CodeTypeReference
{
def ty = tyVar.Fix();
=======================================
---
/nemerle/trunk/VsIntegration/Nemerle.VisualStudio/Project/NemerleEditorFactory.cs
Sun Feb 24 16:09:15 2008
+++
/nemerle/trunk/VsIntegration/Nemerle.VisualStudio/Project/NemerleEditorFactory.cs
Tue Nov 10 12:44:15 2009
@@ -311,9 +311,9 @@
IServiceContainer serviceContainer =
(IServiceContainer)GetService(typeof(IServiceContainer));
if(serviceContainer != null)
- serviceContainer.AddService(typeof(CodeDomProvider),
codeDomProvider);
- }
- */
+
serviceContainer.AddService(typeof(System.CodeDom.Compiler.CodeDomProvider),
codeDomProvider);
+ }
+ //*/
return Marshal.GetIUnknownForObject(docView);
}
=======================================
---
/nemerle/trunk/VsIntegration/Nemerle.VisualStudio/Project/NemerleFileNodeCodeDomProvider.cs
Mon Dec 1 16:43:05 2008
+++
/nemerle/trunk/VsIntegration/Nemerle.VisualStudio/Project/NemerleFileNodeCodeDomProvider.cs
Tue Nov 10 12:44:15 2009
@@ -193,6 +193,7 @@
public override CodeCompileUnit Parse(TextReader codeStream)
{
+ var code = codeStream.ReadToEnd();
// AKhropov - in fact codeStream is ignored for now
string mainFilePath = PathOfMainFile();
@@ -200,10 +201,13 @@
if (projectInfo != null)
{
- // TODO : can _project change for _fileNode?
- return _codeDomParser.CreateCodeCompileUnit(
- projectInfo.Project, mainFilePath,
- (IsFormSubType) ? PathOfDesignerFile() : null);
+ var designerIndex = Location.GetFileIndex(PathOfDesignerFile());
+
+ return
projectInfo.Engine.CreateCodeCompileUnit(projectInfo.GetSource(mainFilePath),
designerIndex);
+ // TODO : can _project change for _fileNode?
+ //return _codeDomParser.CreateCodeCompileUnit(
+ // projectInfo.Project, mainFilePath,
+ // (IsFormSubType) ? PathOfDesignerFile() : null);
}
else
return null;
=======================================
---
/nemerle/trunk/VsIntegration/Nemerle.VisualStudio/Project/NemerleFileNodeProperties.cs
Tue Sep 30 02:12:26 2008
+++
/nemerle/trunk/VsIntegration/Nemerle.VisualStudio/Project/NemerleFileNodeProperties.cs
Tue Nov 10 12:44:15 2009
@@ -1,4 +1,5 @@
using System;
+using System.IO;
using System.ComponentModel;
using System.Runtime.InteropServices;
@@ -15,6 +16,11 @@
: base(node)
{
}
+
+ public new string Extension
+ {
+ get { return Path.GetExtension(Node.Url); }
+ }
[Browsable(false)]
public string Url
=======================================
---
/nemerle/trunk/VsIntegration/Nemerle.VisualStudio/Project/NemerleProjectNode.cs
Wed Oct 28 21:02:28 2009
+++
/nemerle/trunk/VsIntegration/Nemerle.VisualStudio/Project/NemerleProjectNode.cs
Tue Nov 10 12:44:15 2009
@@ -808,9 +808,9 @@
// åùå êó÷è ManagerClass. Òàê æå îðãàíèçîâàòü îòëîæåííóþ
èíèöèàëèçàóèþ, òàê ÷òîáû îíà ïðîèñõäèëà
// òîëüêî êîãäà CodeDomProvider çàïðàøèâàåòñÿ ñòóäèåé.
- //if (IsCodeFile(include) && item.ItemName == "Compile")
- //
newNode.OleServiceProvider.AddService(typeof(SVSMDCodeDomProvider),
- // new NemerleVSMDProvider( newNode.CodeDomProvider ), false);
+ if (IsCodeFile(include) && item.ItemName == "Compile")
+ newNode.OleServiceProvider.AddService(typeof(SVSMDCodeDomProvider),
+ new NemerleVSMDProvider(newNode), false);
return newNode;
}
@@ -833,7 +833,7 @@
if (IsCodeFile(include) && item.ItemName == "Compile")
newNode.OleServiceProvider.AddService(typeof(SVSMDCodeDomProvider),
- new NemerleVSMDProvider(newNode.CodeDomProvider), false);
+ new NemerleVSMDProvider(newNode), false);
return newNode;
}
=======================================
---
/nemerle/trunk/VsIntegration/Nemerle.VisualStudio/Project/NemerleVSMDProvider.cs
Wed Oct 1 03:51:02 2008
+++
/nemerle/trunk/VsIntegration/Nemerle.VisualStudio/Project/NemerleVSMDProvider.cs
Tue Nov 10 12:44:15 2009
@@ -1,27 +1,43 @@
using System;
using Microsoft.VisualStudio.Designer.Interfaces;
using Nemerle.Compiler;
+using Microsoft.VisualStudio.Project;
+using System.Diagnostics;
namespace Nemerle.VisualStudio.Project
{
internal class NemerleVSMDProvider : IVSMDCodeDomProvider
{
- private readonly NemerleFileNodeCodeDomProvider _provider;
-
- public NemerleVSMDProvider()
- {
- }
-
- public NemerleVSMDProvider(NemerleFileNodeCodeDomProvider provider)
- {
- _provider = provider;
+ private readonly FileNode _nemerleFileNode;
+
+ public NemerleVSMDProvider(FileNode nemerleFileNode)
+ {
+ Trace.Assert(nemerleFileNode is NemerleFileNode || nemerleFileNode
is NemerleDependentFileNode);
+ _nemerleFileNode = nemerleFileNode;
}
#region IVSMDCodeDomProvider Members
+
object IVSMDCodeDomProvider.CodeDomProvider
{
- get { return _provider; }
- }
- #endregion
+ get
+ {
+ // Îòëîæåííàÿ çàãðóçêà. ValdD2: Íà ñàìîì äåëå äèçàéí âñå ðàâíî
îñòàåòñÿ êðèâûì,
+ // íî õîòÿ áû íå áóäåò òàê ñèëüíî òîðìîçèòü.
+ var nemerleDependentFileNode = _nemerleFileNode as
NemerleDependentFileNode;
+
+ if (nemerleDependentFileNode != null)
+ return nemerleDependentFileNode.CodeDomProvider;
+
+ var nemerleFileNode = _nemerleFileNode as NemerleFileNode;
+
+ if (nemerleFileNode != null)
+ return nemerleFileNode.CodeDomProvider;
+
+ return null;
+ }
+ }
+
+ #endregion
}
}
=======================================
---
/nemerle/trunk/VsIntegration/Nemerle.VisualStudio/Project/RDTFileTextMerger.cs
Tue Sep 30 02:12:26 2008
+++
/nemerle/trunk/VsIntegration/Nemerle.VisualStudio/Project/RDTFileTextMerger.cs
Tue Nov 10 12:44:15 2009
@@ -197,7 +197,7 @@
private void ProcessFileChangesHelper(ProcessFileChangesFunc processFunc)
{
string filePath = _fileNode.GetMkDocument();
-
+ //
http://blogs.msdn.com/allend/archive/2004/08/20/217958.aspx
IVsRunningDocumentTable rdt =
_fileNode.ProjectMgr.GetService(typeof(SVsRunningDocumentTable)) as
IVsRunningDocumentTable;
// (kberes) Shouldn't this be an InvalidOperationException instead with
some not to annoying errormessage to the user?