2005-07-15 Iain McCoy <iain@mccoy.id.au>
authorIain McCoy <iainmc@mono-cvs.ximian.com>
Thu, 14 Jul 2005 15:51:49 +0000 (15:51 -0000)
committerIain McCoy <iainmc@mono-cvs.ximian.com>
Thu, 14 Jul 2005 15:51:49 +0000 (15:51 -0000)
        * 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
mcs/class/PresentationFramework/Mono.Windows.Serialization/CodeWriter.cs
mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs
mcs/tools/xamlc/ChangeLog
mcs/tools/xamlc/demo/TestVocab/ConsoleValue.cs
mcs/tools/xamlc/demo/test.xaml

index b439335ffe715f9ec04502fb7d24546c2ce6b3f9..811d9a4a5d27fb0a959cb425de4f941392a53075 100644 (file)
@@ -1,3 +1,16 @@
+2005-07-15  Iain McCoy  <iain@mccoy.id.au>
+
+       * 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  <iain@mccoy.id.au>
 
        * Mono.Windows.Serialization/XamlParser.cs,
index 204e2cc94fe5f2b3251e401465f2581d0b1d4927..00ab7bd0bcfb299b31f49be939546dcc5a4cb19e 100644 (file)
@@ -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());
+               }
        }
 }
index 10524cfdcb219b0939c25d874c16b4e74f9db1ae..dbf5ef39c4598f6859ce03190793e024a95a01c5 100644 (file)
@@ -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;
+               }
        }
 }
index c339007d811faa31608a2bfdaf77e857f59c27dd..c7ba34dbfaf8114dbf33b935b42c546467825b18 100644 (file)
@@ -1,3 +1,8 @@
+2005-07-15  Iain McCoy  <iain@mccoy.id.au>
+
+       * demo/test.xaml: uncommented second test of complex objects as
+       property values
+
 2005-07-14  Iain McCoy  <iain@mccoy.id.au>
 
        * demo/test.xaml: added first test of complex objects as property values
index 18bedb7a0293017d0b0bdd6a404f1ba3d06c10ae..8f7648bf64908ef45b3b5c3b09fb400980ea349e 100644 (file)
@@ -30,6 +30,7 @@ namespace Xaml.TestVocab.Console {
                {
                        if (destinationType != typeof(string))
                                throw new NotSupportedException();
+
                        if (o is ConsoleValue)
                                return ((ConsoleValue)o).Value;
                        else
index ddefc829a06e6bbde6c678ca7d304abf302542af..785f1f697f3e85a3c750d0c90ba23966281cd0c0 100644 (file)
                        <ConsoleWriter>What should I say?</ConsoleWriter>
                </ConsoleReader.Prompt>
        </ConsoleReader>
-<!--
        <ConsoleWriter>
                <ConsoleWriter.Text>
                        <ConsoleValueVar Variable="thingo" />
                </ConsoleWriter.Text>
        </ConsoleWriter>
--->
        <ConsoleWriter>
                <ConsoleApp.Repetitions>3</ConsoleApp.Repetitions>
                <ConsoleWriter.Text>Goodbye.</ConsoleWriter.Text>