aboutsummaryrefslogtreecommitdiffstatsci
path: root/src/IML
diff options
context:
space:
mode:
Diffstat (limited to 'src/IML')
-rw-r--r--src/IML/Context.cs31
-rw-r--r--src/IML/Node.cs39
-rw-r--r--src/IML/NodeAddress.cs2
-rw-r--r--src/IML/NodeStack.cs44
4 files changed, 72 insertions, 44 deletions
diff --git a/src/IML/Context.cs b/src/IML/Context.cs
index e5d33374..965d0062 100644
--- a/src/IML/Context.cs
+++ b/src/IML/Context.cs
@@ -38,11 +38,12 @@ namespace Crow.IML
{
public XmlTextReader reader = null;
public Type RootType = null;
- public Node CurrentNode = null;
+ public int CurrentIndex = 0;
+
public DynamicMethod dm = null;
public ILGenerator il = null;
//public SubNodeType curSubNodeType;
- public Stack<Node> nodesStack = new Stack<Node> ();
+ public NodeStack nodesStack = new NodeStack ();
public Dictionary<string, List<NodeAddress>> Names = new Dictionary<string, List<NodeAddress>>();
public Dictionary<string, Dictionary<string, MemberAddress>> PropertyBindings = new Dictionary<string, Dictionary<string, MemberAddress>> ();
@@ -64,13 +65,31 @@ namespace Crow.IML
}
public NodeAddress CurrentNodeAddress {
- get {
- NodeAddress tmp = new NodeAddress(nodesStack.ToArray ());
- tmp.Add (CurrentNode);
- return tmp;
+ get {
+ Node[] n = nodesStack.ToArray ();
+ Array.Reverse (n);
+ return new NodeAddress(n);
}
}
+ public Type CurrentNodeType {
+ get { return nodesStack.Peek().CrowType; }
+ }
+ public MethodInfo CurrentAddMethod {
+ get {
+ if (typeof (Group).IsAssignableFrom (CurrentNodeType))
+ return CompilerServices.miAddChild;
+ if (typeof (Container).IsAssignableFrom (CurrentNodeType))
+ return CompilerServices.miSetChild;
+ if (typeof (TemplatedContainer).IsAssignableFrom (CurrentNodeType))
+ return CurrentIndex < 0 ? CompilerServices.miLoadTmp : CompilerServices.miSetContent;
+ if (typeof (TemplatedGroup).IsAssignableFrom (CurrentNodeType))
+ return CurrentIndex < 0 ? CompilerServices.miLoadTmp : CompilerServices.miAddItem;
+ if (typeof (TemplatedControl).IsAssignableFrom (CurrentNodeType))
+ return CompilerServices.miLoadTmp;
+ return null;
+ }
+ }
void initILGen ()
{
il.DeclareLocal (typeof (GraphicObject));
diff --git a/src/IML/Node.cs b/src/IML/Node.cs
index a503a3bb..14cffdb2 100644
--- a/src/IML/Node.cs
+++ b/src/IML/Node.cs
@@ -28,7 +28,7 @@ namespace Crow.IML
/// <summary>
/// IML Node are the elements of the interface XML,
/// </summary>
- public class Node
+ public struct Node
{
public Type CrowType;
/// <summary>
@@ -59,43 +59,6 @@ namespace Crow.IML
public bool HasTemplate {
get { return typeof (TemplatedControl).IsAssignableFrom (CrowType);}
}
- public MethodInfo AddMethod {
- get {
- if (typeof (Group).IsAssignableFrom (CrowType))
- return CompilerServices.miAddChild;
- if (typeof (Container).IsAssignableFrom (CrowType))
- return CompilerServices.miSetChild;
- if (typeof (TemplatedContainer).IsAssignableFrom (CrowType))
- return Index < 0 ? CompilerServices.miLoadTmp : CompilerServices.miSetContent;
- if (typeof (TemplatedGroup).IsAssignableFrom (CrowType))
- return Index < 0 ? CompilerServices.miLoadTmp : CompilerServices.miAddItem;
- if (typeof (TemplatedControl).IsAssignableFrom (CrowType))
- return CompilerServices.miLoadTmp;
- return null;
- }
- }
- public void EmitGetInstance (ILGenerator il){
- if (typeof (Group).IsAssignableFrom (CrowType)) {
- il.Emit (OpCodes.Ldfld, typeof(Group).GetField ("children", BindingFlags.Instance | BindingFlags.NonPublic));
- il.Emit(OpCodes.Ldc_I4, Index);
- il.Emit (OpCodes.Callvirt, typeof(List<GraphicObject>).GetMethod("get_Item", new Type[] { typeof(Int32) }));
- return;
- }
- if (typeof(Container).IsAssignableFrom (CrowType) || Index < 0) {
- il.Emit (OpCodes.Ldfld, typeof(PrivateContainer).GetField ("child", BindingFlags.Instance | BindingFlags.NonPublic));
- return;
- }
- if (typeof(TemplatedContainer).IsAssignableFrom (CrowType)) {
- il.Emit (OpCodes.Callvirt, typeof(TemplatedContainer).GetProperty ("Content").GetGetMethod ());
- return;
- }
- if (typeof(TemplatedGroup).IsAssignableFrom (CrowType)) {
- il.Emit (OpCodes.Callvirt, typeof(TemplatedGroup).GetProperty ("Items").GetGetMethod ());
- il.Emit(OpCodes.Ldc_I4, Index);
- il.Emit (OpCodes.Callvirt, typeof(List<GraphicObject>).GetMethod("get_Item", new Type[] { typeof(Int32) }));
- return;
- }
- }
public static implicit operator string (Node sn)
{
diff --git a/src/IML/NodeAddress.cs b/src/IML/NodeAddress.cs
index b7517b1f..1c907ec1 100644
--- a/src/IML/NodeAddress.cs
+++ b/src/IML/NodeAddress.cs
@@ -21,6 +21,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
+using System.Reflection;
+using System.Reflection.Emit;
namespace Crow.IML
{
diff --git a/src/IML/NodeStack.cs b/src/IML/NodeStack.cs
new file mode 100644
index 00000000..bec45e26
--- /dev/null
+++ b/src/IML/NodeStack.cs
@@ -0,0 +1,44 @@
+//
+// NodeStack.cs
+//
+// Author:
+// Jean-Philippe Bruyère <jp.bruyere@hotmail.com>
+//
+// Copyright (c) 2016 jp
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+using System;
+using System.Collections.Generic;
+
+namespace Crow.IML
+{
+ public class NodeStack : Stack<Node>
+ {
+ public NodeStack () : base()
+ {
+ }
+ public void IncrementCurrentNodeIndex(){
+ Node n = this.Pop();
+ this.Push (new Node (n.CrowType, n.Index + 1));
+ }
+ public void DecrementCurrentNodeIndex(){
+ Node n = this.Pop();
+ this.Push (new Node (n.CrowType, n.Index - 1));
+ }
+ public void ResetCurrentNodeIndex(){
+ this.Push (new Node (this.Pop().CrowType));
+ }
+ }
+}
+