From 88b28d13f1e734ffb0aaf2236efb148b06d59beb Mon Sep 17 00:00:00 2001 From: Iain McCoy Date: Thu, 14 Jul 2005 15:51:49 +0000 Subject: 2005-07-15 Iain McCoy * Mono.Windows.Serialization/CodeWriter.cs: Better debugging information * Mono.Windows.Serialization/XamlParser.cs: Better debugging information, consolidated push() code * Mono.Windows.Serialization/CodeWriter.cs: inverted sourceType and destType in endPropertyObject * Mono.Windows.Serialization/XamlParser.cs: changed parseElement so that it doesn't stuff up the stack on empty elements and replaced an if statement spanning CurrentState with a case statement for clarity * demo/test.xaml: uncommented second test of complex objects as property values svn path=/trunk/mcs/; revision=47308 --- mcs/class/PresentationFramework/ChangeLog | 13 ++++ .../Mono.Windows.Serialization/CodeWriter.cs | 34 ++++++++-- .../Mono.Windows.Serialization/XamlParser.cs | 79 +++++++++++----------- 3 files changed, 84 insertions(+), 42 deletions(-) (limited to 'mcs/class/PresentationFramework') diff --git a/mcs/class/PresentationFramework/ChangeLog b/mcs/class/PresentationFramework/ChangeLog index b439335ffe7..811d9a4a5d2 100644 --- a/mcs/class/PresentationFramework/ChangeLog +++ b/mcs/class/PresentationFramework/ChangeLog @@ -1,3 +1,16 @@ +2005-07-15 Iain McCoy + + * Mono.Windows.Serialization/CodeWriter.cs: Better debugging + information + * Mono.Windows.Serialization/XamlParser.cs: Better debugging + information, consolidated push() code + * Mono.Windows.Serialization/CodeWriter.cs: inverted sourceType and + destType in endPropertyObject + * Mono.Windows.Serialization/XamlParser.cs: changed parseElement so + that it doesn't stuff up the stack on empty elements and replaced + an if statement spanning CurrentState with a case statement for + clarity + 2005-07-14 Iain McCoy * Mono.Windows.Serialization/XamlParser.cs, diff --git a/mcs/class/PresentationFramework/Mono.Windows.Serialization/CodeWriter.cs b/mcs/class/PresentationFramework/Mono.Windows.Serialization/CodeWriter.cs index 204e2cc94fe..00ab7bd0bcf 100644 --- a/mcs/class/PresentationFramework/Mono.Windows.Serialization/CodeWriter.cs +++ b/mcs/class/PresentationFramework/Mono.Windows.Serialization/CodeWriter.cs @@ -27,6 +27,7 @@ // using System; +using System.Diagnostics; using System.Reflection; using System.IO; using System.Collections; @@ -61,6 +62,7 @@ namespace Mono.Windows.Serialization { // instance public void CreateTopLevel(Type parent, string className) { + debug(); if (className == null) { className = "derived" + parent.Name; } @@ -94,6 +96,7 @@ namespace Mono.Windows.Serialization { // pushes a reference to the new current type public void CreateObject(Type type, string varName) { + debug(); bool isDefaultName; if (varName == null) { isDefaultName = true; @@ -138,6 +141,7 @@ namespace Mono.Windows.Serialization { // pushes a reference to the property public void CreateProperty(PropertyInfo property) { + debug(); CodePropertyReferenceExpression prop = new CodePropertyReferenceExpression( (CodeExpression)objects[objects.Count - 1], property.Name); @@ -148,6 +152,7 @@ namespace Mono.Windows.Serialization { // pushes a reference to the event public void CreateEvent(EventInfo evt) { + debug(); CodeEventReferenceExpression expr = new CodeEventReferenceExpression( (CodeExpression)objects[objects.Count - 1], evt.Name); @@ -161,6 +166,7 @@ namespace Mono.Windows.Serialization { // property public void CreateDependencyProperty(Type attachedTo, string propertyName, Type propertyType) { + debug(); string varName = "temp"; varName += tempIndex; tempIndex += 1; @@ -181,7 +187,9 @@ namespace Mono.Windows.Serialization { // pops 2 items: the name of the property, and the object to attach to public void EndDependencyProperty() { - objects.RemoveAt(objects.Count - 1); + debug(); + objects.RemoveAt(objects.Count - 1); // pop the variable name - we don't need it since it's already + // baked into the call CodeExpression call = (CodeExpression)(objects[objects.Count - 1]); objects.RemoveAt(objects.Count - 1); constructor.Statements.Add(call); @@ -190,6 +198,7 @@ namespace Mono.Windows.Serialization { // top of stack must be an object reference public void CreateElementText(string text) { + debug(); CodeVariableReferenceExpression var = (CodeVariableReferenceExpression)objects[objects.Count - 1]; CodeMethodInvokeExpression call = new CodeMethodInvokeExpression( var, @@ -201,6 +210,7 @@ namespace Mono.Windows.Serialization { // top of stack is reference to an event public void CreateEventDelegate(string functionName, Type eventDelegateType) { + debug(); CodeExpression expr = new CodeObjectCreateExpression( eventDelegateType, new CodeMethodReferenceExpression( @@ -215,6 +225,7 @@ namespace Mono.Windows.Serialization { // top of stack is reference to a property public void CreatePropertyDelegate(string functionName, Type propertyType) { + debug(); CodeExpression expr = new CodeObjectCreateExpression( propertyType, new CodeMethodReferenceExpression( @@ -238,11 +249,13 @@ namespace Mono.Windows.Serialization { // top of stack is reference to a property public void CreatePropertyText(string text, Type propertyType) { + debug(); CreateDependencyPropertyText(text, propertyType); } // top of stack is reference to an attached property public void CreateDependencyPropertyText(string text, Type propertyType) { + debug(); CodeExpression expr = new CodePrimitiveExpression(text); if (propertyType != typeof(string)) { expr = new CodeCastExpression( @@ -261,6 +274,7 @@ namespace Mono.Windows.Serialization { public void CreatePropertyObject(Type type, string varName) { + debug(); bool isDefaultName; if (varName == null) { isDefaultName = true; @@ -299,13 +313,16 @@ namespace Mono.Windows.Serialization { } - public void EndPropertyObject(Type sourceType) + public void EndPropertyObject(Type destType) { + debug(); CodeExpression varRef = (CodeExpression)objects[objects.Count - 1]; objects.RemoveAt(objects.Count - 1); - Type destType = (Type)objects[objects.Count - 1]; + Type sourceType = (Type)objects[objects.Count - 1]; objects.RemoveAt(objects.Count - 1); + Debug.WriteLine(destType + "->" + sourceType); + CodeExpression expr; if (destType == sourceType) @@ -322,33 +339,42 @@ namespace Mono.Windows.Serialization { (CodeExpression)objects[objects.Count - 1], expr); constructor.Statements.Add(assignment); - } public void EndObject() { + debug(); objects.RemoveAt(objects.Count - 1); } public void EndProperty() { + debug(); objects.RemoveAt(objects.Count - 1); } public void EndEvent() { + debug(); objects.RemoveAt(objects.Count - 1); } public void Finish() { + debug(); generator.GenerateCodeFromCompileUnit(code, writer, null); writer.Close(); } public void CreateCode(string code) { + debug(); type.Members.Add(new CodeSnippetTypeMember(code)); } + + private void debug() + { + Debug.WriteLine(new System.Diagnostics.StackTrace()); + } } } diff --git a/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs b/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs index 10524cfdcb2..dbf5ef39c45 100644 --- a/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs +++ b/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs @@ -29,6 +29,7 @@ using System; using System.Collections; +using System.Diagnostics; using System.IO; using System.Xml; using System.Reflection; @@ -44,6 +45,7 @@ namespace Mono.Windows.Serialization { private enum CurrentType { Object, Property, + PropertyObject, DependencyProperty, Code } @@ -76,6 +78,7 @@ namespace Mono.Windows.Serialization { public void Parse() { while (reader.Read()) { + Debug.WriteLine("NOW PARSING: " + reader.NodeType + "; " + reader.Name + "; " + reader.Value); if (begun && currentState == null && reader.NodeType != XmlNodeType.Whitespace) throw new Exception("Too far: " + reader.NodeType + ", " + reader.Name); if (currentState != null && currentState.type == CurrentType.Code) @@ -166,15 +169,12 @@ namespace Mono.Windows.Serialization { void parseCodeElement() { - oldStates.Add(currentState); - currentState = new ParserState(); - currentState.type = CurrentType.Code; - currentState.obj = ""; + push(CurrentType.Code, ""); } void parseText() { - if (currentState.type == CurrentType.Object) { + if (currentState.type == CurrentType.Object || currentState.type == CurrentType.PropertyObject) { writer.CreateElementText(reader.Value); } else if (currentState.type == CurrentType.DependencyProperty) { DependencyProperty dp = (DependencyProperty)currentState.obj; @@ -197,10 +197,7 @@ namespace Mono.Windows.Serialization { // TODO: exception } - oldStates.Add(currentState); - currentState = new ParserState(); - currentState.type = CurrentType.Property; - currentState.obj = prop; + push(CurrentType.Property, prop); writer.CreateProperty(prop); @@ -219,10 +216,7 @@ namespace Mono.Windows.Serialization { Type typeAttachedTo = findTypeToAttachTo(attachedTo, propertyName); DependencyProperty dp = getDependencyProperty(typeAttachedTo, propertyName); - oldStates.Add(currentState); - currentState = new ParserState(); - currentState.obj = dp; - currentState.type = CurrentType.DependencyProperty; + push(CurrentType.DependencyProperty, dp); writer.CreateDependencyProperty(typeAttachedTo, propertyName, dp.PropertyType); } @@ -269,7 +263,12 @@ namespace Mono.Windows.Serialization { if (isEmpty) { - writer.EndObject(); + if (currentState.type == CurrentType.Object) { + writer.EndObject(); + } else if (currentState.type == CurrentType.PropertyObject) { + ParserState state = (ParserState)oldStates[oldStates.Count - 1]; + writer.EndPropertyObject(((PropertyInfo)state.obj).PropertyType); + } pop(); } } @@ -287,21 +286,14 @@ namespace Mono.Windows.Serialization { void addChild(Type type, string objectName) { writer.CreateObject(type, objectName); - oldStates.Add(currentState); - currentState = new ParserState(); - currentState.type = CurrentType.Object; - currentState.obj = type; + push(CurrentType.Object, type); } void addPropertyChild(Type type, string objectName) { -// writer.CreatePropertyObject(type, objectName); - writer.CreatePropertyObject(((PropertyInfo)currentState.obj).PropertyType, objectName); + writer.CreatePropertyObject(type, objectName); - oldStates.Add(currentState); - currentState = new ParserState(); - currentState.type = CurrentType.Object; - currentState.obj = type; + push(CurrentType.PropertyObject, type); } @@ -350,7 +342,8 @@ namespace Mono.Windows.Serialization { { Type typeAttachedTo = null; foreach (ParserState state in oldStates) { - if (state.type == CurrentType.Object && + if ((state.type == CurrentType.Object || + state.type == CurrentType.PropertyObject) && ((Type)state.obj).Name == attachedTo) { typeAttachedTo = (Type)state.obj; break; @@ -387,27 +380,30 @@ namespace Mono.Windows.Serialization { void parseEndElement() { - if (currentState.type == CurrentType.Code) { + Debug.WriteLine("IN ENDELEMENT, SWITCHING ON " + currentState.type); + switch (currentState.type) { + case CurrentType.Code: writer.CreateCode((string)currentState.obj); - } else if (currentState.type == CurrentType.Object) { - ParserState prev = null; - if (oldStates.Count > 1) - prev = (ParserState)oldStates[oldStates.Count - 1]; - - if (prev != null && prev.type == CurrentType.Property) - writer.EndPropertyObject((Type)currentState.obj); - else - writer.EndObject(); - } else if (currentState.type == CurrentType.Property) { + break; + case CurrentType.Object: + writer.EndObject(); + break; + case CurrentType.PropertyObject: + writer.EndPropertyObject((Type)currentState.obj); + break; + case CurrentType.Property: writer.EndProperty(); - } else if (currentState.type == CurrentType.DependencyProperty) { + break; + case CurrentType.DependencyProperty: writer.EndDependencyProperty(); + break; } pop(); } void pop() { + Debug.WriteLine("POPPING: " + currentState.type); if (oldStates.Count == 0) { currentState = null; writer.Finish(); @@ -417,6 +413,13 @@ namespace Mono.Windows.Serialization { currentState = (ParserState)oldStates[lastIndex]; oldStates.RemoveAt(lastIndex); } - + void push(CurrentType type, Object obj) + { + Debug.WriteLine("PUSHING: " + type); + oldStates.Add(currentState); + currentState = new ParserState(); + currentState.type = type; + currentState.obj = obj; + } } } -- cgit v1.2.3