Author: iainmc
Date: 2005-07-13 22:35:58 -0400 (Wed, 13 Jul 2005)
New Revision: 47291

Added:
   trunk/mcs/tools/xamlc/demo/TestVocab/ConsoleReader.cs
   trunk/mcs/tools/xamlc/demo/TestVocab/ConsoleValue.cs
   trunk/mcs/tools/xamlc/demo/TestVocab/ConsoleVars.cs
Modified:
   trunk/mcs/class/PresentationFramework/ChangeLog
   
trunk/mcs/class/PresentationFramework/Mono.Windows.Serialization/CodeWriter.cs
   
trunk/mcs/class/PresentationFramework/Mono.Windows.Serialization/ObjectWriter.cs
   
trunk/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs
   
trunk/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlWriter.cs
   trunk/mcs/tools/xamlc/ChangeLog
   trunk/mcs/tools/xamlc/demo/Makefile
   trunk/mcs/tools/xamlc/demo/TestVocab/ConsoleApp.cs
   trunk/mcs/tools/xamlc/demo/TestVocab/ConsoleWriter.cs
   trunk/mcs/tools/xamlc/demo/test.xaml
   trunk/mcs/tools/xamlc/xamlc.cs
Log:
2005-07-14  Iain McCoy  <[EMAIL PROTECTED]>

        * demo/test.xaml: added first test of complex objects as property values
        * demo/TestVocab/ConsoleReader.cs,
          demo/TestVocab/ConsoleVars.cs: more functionality that will provide
        uses for more complicated xaml code.
        * xamlc.cs: much more useful error reporting.
        * demo/TestVocab/ConsoleWriter.cs,
          demo/TestVocab/ConsoleValue.cs,
          demo/Makefile: Added ConsoleValue class to allow testing of more
        complicated property scenarios
        * demo/TestVocab/ConsoleVars.cs,
          demo/TestVocab/ConsoleReader.cs: classes to put in more complicated
        test
        * Mono.Windows.Serialization/XamlParser.cs,
          Mono.Windows.Serialization/XamlWriter.cs,
          Mono.Windows.Serialization/CodeWriter.cs: Initial support for
        creating complex objects as values of properties
        * Mono.Windows.Serialization/XamlParser.cs: fixed bug in the code
        detecting that the file's contents must be finished, where it forbade
        whitespace after the XAML code



Modified: trunk/mcs/class/PresentationFramework/ChangeLog
===================================================================
--- trunk/mcs/class/PresentationFramework/ChangeLog     2005-07-14 00:32:11 UTC 
(rev 47290)
+++ trunk/mcs/class/PresentationFramework/ChangeLog     2005-07-14 02:35:58 UTC 
(rev 47291)
@@ -1,3 +1,16 @@
+2005-07-14  Iain McCoy  <[EMAIL PROTECTED]>
+
+       * Mono.Windows.Serialization/XamlParser.cs,
+         Mono.Windows.Serialization/XamlWriter.cs,
+         Mono.Windows.Serialization/CodeWriter.cs: Initial support for
+       creating complex objects as values of properties
+
+2005-07-13  Iain McCoy  <[EMAIL PROTECTED]>
+
+       * Mono.Windows.Serialization/XamlParser.cs: fixed bug in the code
+       detecting that the file's contents must be finished, where it forbade
+       whitespace after the XAML code
+
 2005-07-11  Iain McCoy  <[EMAIL PROTECTED]>
 
        * Makefile,

Modified: 
trunk/mcs/class/PresentationFramework/Mono.Windows.Serialization/CodeWriter.cs
===================================================================
--- 
trunk/mcs/class/PresentationFramework/Mono.Windows.Serialization/CodeWriter.cs  
    2005-07-14 00:32:11 UTC (rev 47290)
+++ 
trunk/mcs/class/PresentationFramework/Mono.Windows.Serialization/CodeWriter.cs  
    2005-07-14 02:35:58 UTC (rev 47291)
@@ -234,6 +234,7 @@
                                                        "GetConverter"),
                                        new CodeTypeOfExpression(propertyType));
                }
+
                // top of stack is reference to a property
                public void CreatePropertyText(string text, Type propertyType)
                {
@@ -257,7 +258,73 @@
                        
                        constructor.Statements.Add(assignment);
                }
+
+               public void CreatePropertyObject(Type type, string varName)
+               {
+                       bool isDefaultName;
+                       if (varName == null) {
+                               isDefaultName = true;
+                               varName = Char.ToLower(type.Name[0]) + 
type.Name.Substring(1);
+                               // make sure something sensible happens when 
class
+                               // names start with a lowercase letter
+                               if (varName == type.Name)
+                                       varName = "_" + varName;
+                       } else {
+                               isDefaultName = false;
+                       }
+
+                       if (!nameClashes.ContainsKey(varName))
+                               nameClashes[varName] = 0;
+                       else {
+                               nameClashes[varName] = 1 + 
(int)nameClashes[varName];
+                               varName += (int)nameClashes[varName];
+                       }
+
+
+                       if (isDefaultName) {
+                               CodeVariableDeclarationStatement declaration = 
+                                               new 
CodeVariableDeclarationStatement(type, 
+                                                               varName,
+                                                               new 
CodeObjectCreateExpression(type));
+                               constructor.Statements.Add(declaration);
+                       } else {
+                               CodeMemberField declaration = new 
CodeMemberField(type, varName);
+                               declaration.InitExpression = new 
CodeObjectCreateExpression(type);
+                               this.type.Members.Add(declaration);
+                       }
+                       CodeVariableReferenceExpression varRef = new 
CodeVariableReferenceExpression(varName);
+
+                       objects.Add(type);
+                       objects.Add(varRef);
                
+               }
+
+               public void EndPropertyObject(Type sourceType)
+               {
+                       CodeExpression varRef = 
(CodeExpression)objects[objects.Count - 1];
+                       objects.RemoveAt(objects.Count - 1);
+                       Type destType = (Type)objects[objects.Count - 1];
+                       objects.RemoveAt(objects.Count - 1);
+
+                       
+                       CodeExpression expr;
+                       if (destType == sourceType)
+                               expr = varRef;
+                       else
+                               expr = new CodeCastExpression(
+                                               new CodeTypeReference(destType),
+                                               new CodeMethodInvokeExpression(
+                                                               
fetchConverter(sourceType),
+                                                               "ConvertTo",
+                                                               varRef,
+                                                               new 
CodeTypeOfExpression(destType)));
+                       CodeAssignStatement assignment = new 
CodeAssignStatement(
+                                       (CodeExpression)objects[objects.Count - 
1],
+                                       expr);
+                       constructor.Statements.Add(assignment);
+
+               }
+               
                public void EndObject()
                {
                        objects.RemoveAt(objects.Count - 1);

Modified: 
trunk/mcs/class/PresentationFramework/Mono.Windows.Serialization/ObjectWriter.cs
===================================================================
--- 
trunk/mcs/class/PresentationFramework/Mono.Windows.Serialization/ObjectWriter.cs
    2005-07-14 00:32:11 UTC (rev 47290)
+++ 
trunk/mcs/class/PresentationFramework/Mono.Windows.Serialization/ObjectWriter.cs
    2005-07-14 02:35:58 UTC (rev 47291)
@@ -103,6 +103,15 @@
                        p.SetValue(o, text, null);
                }
                
+               public void CreatePropertyObject(Type type, string name)
+               {
+                       throw new NotImplementedException();
+               }
+               public void EndPropertyObject(Type sourceType)
+               {
+                       throw new NotImplementedException();
+               }
+
                // top of stack is reference to an attached property
                public void CreateDependencyPropertyText(string text, Type 
propertyType)
                {

Modified: 
trunk/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs
===================================================================
--- 
trunk/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs  
    2005-07-14 00:32:11 UTC (rev 47290)
+++ 
trunk/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs  
    2005-07-14 02:35:58 UTC (rev 47291)
@@ -76,7 +76,7 @@
                public void Parse()
                {
                        while (reader.Read()) {
-                               if (begun && currentState == null)
+                               if (begun && currentState == null && 
reader.NodeType != XmlNodeType.Whitespace)
                                        throw new Exception("Too far: " + 
reader.NodeType + ", " + reader.Name);
                                if (currentState != null && currentState.type 
== CurrentType.Code)
                                {
@@ -103,7 +103,8 @@
                                        parseText();
                                        break;
                                case XmlNodeType.Whitespace:
-                                       // skip whitespace
+                               case XmlNodeType.Comment:
+                                       // skip whitespace and comments
                                        break;
                                default:
                                        Console.Out.WriteLine("Unknown element 
type " + reader.NodeType);
@@ -244,7 +245,13 @@
                                string name = reader.GetAttribute("Name", 
XAML_NAMESPACE);
                                if (name == null)
                                        name = reader.GetAttribute("Name", 
reader.NamespaceURI);
-                               addChild(parent, name);
+
+                               if (currentState.type == CurrentType.Object)
+                                       addChild(parent, name);
+                               else if (currentState.type == 
CurrentType.Property)
+                                       addPropertyChild(parent, name);
+                               else
+                                       throw new NotImplementedException();
                        }
                        
                        if (reader.MoveToFirstAttribute()) {
@@ -270,10 +277,11 @@
                void createTopLevel(string parentName, string className)
                {
                        Type t = Type.GetType(parentName);
+
+                       writer.CreateTopLevel(t, className);
                        currentState = new ParserState();
                        currentState.type = CurrentType.Object;
                        currentState.obj = t;
-                       writer.CreateTopLevel(t, className);
                }
 
                void addChild(Type type, string objectName)
@@ -284,7 +292,19 @@
                        currentState.type = CurrentType.Object;
                        currentState.obj = type;
                }
+               
+               void addPropertyChild(Type type, string objectName)
+               {
+//                     writer.CreatePropertyObject(type, objectName);
+                       
writer.CreatePropertyObject(((PropertyInfo)currentState.obj).PropertyType, 
objectName);
 
+                       oldStates.Add(currentState);
+                       currentState = new ParserState();
+                       currentState.type = CurrentType.Object;
+                       currentState.obj = type;
+               }
+
+
                
                void parseLocalPropertyAttribute()
                {
@@ -367,14 +387,22 @@
 
                void parseEndElement()
                {
-                       if (currentState.type == CurrentType.Code)
+                       if (currentState.type == CurrentType.Code) {
                                writer.CreateCode((string)currentState.obj);
-                       else if (currentState.type == CurrentType.Object)
-                               writer.EndObject();
-                       else if (currentState.type == CurrentType.Property)
+                       } 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) {
                                writer.EndProperty();
-                       else if (currentState.type == 
CurrentType.DependencyProperty)
+                       } else if (currentState.type == 
CurrentType.DependencyProperty) {
                                writer.EndDependencyProperty();
+                       }
                        pop();
                }
 

Modified: 
trunk/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlWriter.cs
===================================================================
--- 
trunk/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlWriter.cs  
    2005-07-14 00:32:11 UTC (rev 47290)
+++ 
trunk/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlWriter.cs  
    2005-07-14 02:35:58 UTC (rev 47291)
@@ -40,6 +40,8 @@
                void CreateProperty(PropertyInfo property);
                void CreatePropertyText(string text, Type propertyType);
                void CreatePropertyDelegate(string functionName, Type 
propertyType);
+               void CreatePropertyObject(Type destType, string name);
+               void EndPropertyObject(Type sourceType);
                void EndProperty();
        
 

Modified: trunk/mcs/tools/xamlc/ChangeLog
===================================================================
--- trunk/mcs/tools/xamlc/ChangeLog     2005-07-14 00:32:11 UTC (rev 47290)
+++ trunk/mcs/tools/xamlc/ChangeLog     2005-07-14 02:35:58 UTC (rev 47291)
@@ -1,5 +1,27 @@
+2005-07-14  Iain McCoy  <[EMAIL PROTECTED]>
+
+       * demo/test.xaml: added first test of complex objects as property values
+
+
+2005-07-13  Iain McCoy  <[EMAIL PROTECTED]>
+
+       * demo/TestVocab/ConsoleReader.cs,
+         demo/TestVocab/ConsoleVars.cs: more functionality that will provide
+       uses for more complicated xaml code.
+       * xamlc.cs: much more useful error reporting.
+
 2005-07-08  Iain McCoy  <[EMAIL PROTECTED]>
 
+       * demo/TestVocab/ConsoleWriter.cs,
+         demo/TestVocab/ConsoleValue.cs,
+         demo/Makefile: Added ConsoleValue class to allow testing of more
+       complicated property scenarios
+       * demo/TestVocab/ConsoleVars.cs,
+         demo/TestVocab/ConsoleReader.cs: classes to put in more complicated
+       test
+
+2005-07-08  Iain McCoy  <[EMAIL PROTECTED]>
+
        * demo/runtimetest.xaml
          demo/runtimetest.cs,
          demo/Makefile: creation of objects at runtime from a xaml file

Modified: trunk/mcs/tools/xamlc/demo/Makefile
===================================================================
--- trunk/mcs/tools/xamlc/demo/Makefile 2005-07-14 00:32:11 UTC (rev 47290)
+++ trunk/mcs/tools/xamlc/demo/Makefile 2005-07-14 02:35:58 UTC (rev 47291)
@@ -1,7 +1,7 @@
 thisdir = tools/xaml/demo
 include ../../../build/rules.make
 
-SOURCES=TestVocab/ConsoleApp.cs TestVocab/ConsoleWriter.cs 
TestVocab/IConsoleAction.cs
+SOURCES=TestVocab/ConsoleApp.cs TestVocab/ConsoleWriter.cs 
TestVocab/ConsoleReader.cs TestVocab/IConsoleAction.cs 
TestVocab/ConsoleValue.cs TestVocab/ConsoleVars.cs
 
 run:
        make clean

Modified: trunk/mcs/tools/xamlc/demo/TestVocab/ConsoleApp.cs
===================================================================
--- trunk/mcs/tools/xamlc/demo/TestVocab/ConsoleApp.cs  2005-07-14 00:32:11 UTC 
(rev 47290)
+++ trunk/mcs/tools/xamlc/demo/TestVocab/ConsoleApp.cs  2005-07-14 02:35:58 UTC 
(rev 47291)
@@ -12,7 +12,8 @@
                
                public void AddText(string Text)
                {
-                       actions.Add(new ConsoleWriter(Text));
+                       actions.Add(new ConsoleWriter(
+                                               new ConsoleValueString(Text)));
                }
 
                public void AddChild(object Value)

Copied: trunk/mcs/tools/xamlc/demo/TestVocab/ConsoleReader.cs (from rev 47259, 
trunk/mcs/tools/xamlc/demo/TestVocab/IConsoleAction.cs)
===================================================================
--- trunk/mcs/tools/xamlc/demo/TestVocab/IConsoleAction.cs      2005-07-13 
09:39:55 UTC (rev 47259)
+++ trunk/mcs/tools/xamlc/demo/TestVocab/ConsoleReader.cs       2005-07-14 
02:35:58 UTC (rev 47291)
@@ -0,0 +1,24 @@
+using System.Windows;
+
+namespace Xaml.TestVocab.Console {
+       public class ConsoleReader : DependencyObject, IConsoleAction {
+               private string variable;
+               private ConsoleWriter prompt;
+
+               public string Variable {
+                       get { return variable; }
+                       set { variable = value; }
+               }
+
+               public ConsoleWriter Prompt {
+                       get { return prompt; }
+                       set { prompt = value; }
+               }
+               
+               public void Run() {
+                       prompt.Run();
+                       string s = System.Console.ReadLine();
+                       ConsoleVars.Set(variable, s);
+               }
+       }
+}

Added: trunk/mcs/tools/xamlc/demo/TestVocab/ConsoleValue.cs
===================================================================
--- trunk/mcs/tools/xamlc/demo/TestVocab/ConsoleValue.cs        2005-07-14 
00:32:11 UTC (rev 47290)
+++ trunk/mcs/tools/xamlc/demo/TestVocab/ConsoleValue.cs        2005-07-14 
02:35:58 UTC (rev 47291)
@@ -0,0 +1,75 @@
+using System;
+using System.Globalization;
+using System.ComponentModel;
+
+
+namespace Xaml.TestVocab.Console {
+       
+       [TypeConverter(typeof(ConsoleValueConverter))]
+       public abstract class ConsoleValue {
+               public abstract string Value { get; }
+       }
+
+       public class ConsoleValueConverter : TypeConverter {
+               public override bool CanConvertFrom(ITypeDescriptorContext 
context, Type t)
+               {
+                       return (t == typeof(ConsoleValue));
+               }
+               public override bool CanConvertTo(ITypeDescriptorContext 
context, Type t)
+               {
+                       return (t == typeof(string));
+               }
+               public override object ConvertFrom(ITypeDescriptorContext 
context, CultureInfo culture, Object o)
+               {
+                       if (o is string)
+                               return new ConsoleValueString((string)o);
+                       else
+                               throw new NotSupportedException();
+               }
+               public override object ConvertTo(ITypeDescriptorContext 
context, CultureInfo culture, Object o, Type destinationType)
+               {
+                       if (destinationType != typeof(string))
+                               throw new NotSupportedException();
+                       if (o is ConsoleValue)
+                               return ((ConsoleValue)o).Value;
+                       else
+                               throw new NotSupportedException();
+               }
+       }
+
+       
+
+       public class ConsoleValueString : ConsoleValue {
+               string val;
+               public ConsoleValueString(string val)
+               {
+                       this.val = val;
+               }
+
+               public override string Value {
+                       get { return val; }
+               }
+       }
+
+       public class ConsoleValueVar : ConsoleValue {
+               string var;
+               public ConsoleValueVar()
+               {
+               }
+
+               public ConsoleValueVar(string var)
+               {
+                       this.var = var;
+               }
+
+               public override string Value {
+                       get { return ConsoleVars.Get(var); }
+               }
+
+               public string Variable {
+                       get { return var; }
+                       set { var = value; }
+               }
+       }
+
+}

Copied: trunk/mcs/tools/xamlc/demo/TestVocab/ConsoleVars.cs (from rev 47259, 
trunk/mcs/tools/xamlc/demo/TestVocab/IConsoleAction.cs)
===================================================================
--- trunk/mcs/tools/xamlc/demo/TestVocab/IConsoleAction.cs      2005-07-13 
09:39:55 UTC (rev 47259)
+++ trunk/mcs/tools/xamlc/demo/TestVocab/ConsoleVars.cs 2005-07-14 02:35:58 UTC 
(rev 47291)
@@ -0,0 +1,13 @@
+using System.Collections;
+
+namespace Xaml.TestVocab.Console {
+       public class ConsoleVars {
+               private static Hashtable storage = new Hashtable();
+               public static void Set(string name, string o) {
+                       storage[name] = o;
+               }
+               public static string Get(string name) {
+                       return (string)storage[name];
+               }
+       }
+}

Modified: trunk/mcs/tools/xamlc/demo/TestVocab/ConsoleWriter.cs
===================================================================
--- trunk/mcs/tools/xamlc/demo/TestVocab/ConsoleWriter.cs       2005-07-14 
00:32:11 UTC (rev 47290)
+++ trunk/mcs/tools/xamlc/demo/TestVocab/ConsoleWriter.cs       2005-07-14 
02:35:58 UTC (rev 47291)
@@ -14,9 +14,9 @@
                        text = "";
                }
                
-               public ConsoleWriter(string text)
+               public ConsoleWriter(ConsoleValue text)
                {
-                       this.text = text;
+                       this.text = text.Value;
                }
 
                public string Text {
@@ -35,7 +35,7 @@
 
                public void AddChild(Object o)
                {
-                       throw new NotImplementedException();
+                       this.text += ((ConsoleValue)o).Value;
                }
 
                

Modified: trunk/mcs/tools/xamlc/demo/test.xaml
===================================================================
--- trunk/mcs/tools/xamlc/demo/test.xaml        2005-07-14 00:32:11 UTC (rev 
47290)
+++ trunk/mcs/tools/xamlc/demo/test.xaml        2005-07-14 02:35:58 UTC (rev 
47291)
@@ -1,4 +1,4 @@
-<?Mapping ClrNamespace="Xaml.TestVocab.Console" Assembly="TestVocab" 
XmlNamespace="console" ?>
+<?Mapping ClrNamespace="Xaml.TestVocab.Console" Assembly="TestVocab.dll" 
XmlNamespace="console" ?>
 
 <ConsoleApp xmlns="console" 
                xmlns:x="http://schemas.microsoft.com/winfx/xaml/2005"; 
@@ -7,7 +7,19 @@
        <ConsoleWriter>IT BEGINS!</ConsoleWriter>
        <ConsoleWriter x:Name="_greeter" Text="Hello World" />
        <ConsoleWriter Text="I'm surrounded!" Filter="stringFilter" />
+       <ConsoleReader Variable="thingo">
+               <ConsoleReader.Prompt>
+                       <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>
        </ConsoleWriter>

Modified: trunk/mcs/tools/xamlc/xamlc.cs
===================================================================
--- trunk/mcs/tools/xamlc/xamlc.cs      2005-07-14 00:32:11 UTC (rev 47290)
+++ trunk/mcs/tools/xamlc/xamlc.cs      2005-07-14 02:35:58 UTC (rev 47291)
@@ -28,6 +28,7 @@
 
 using System;
 using System.IO;
+using System.Xml;
 using System.CodeDom;
 using System.CodeDom.Compiler;
 using Mono.GetOptions;
@@ -55,10 +56,17 @@
                        options.OutputFile = input + ".out";
                }
                ICodeGenerator generator = (new 
Microsoft.CSharp.CSharpCodeProvider()).CreateGenerator();
+               XmlTextReader xr = new XmlTextReader(input);
                TextWriter tw = new StreamWriter(options.OutputFile);
                CodeWriter cw = new CodeWriter(generator, tw, options.Partial);
-               XamlParser r = new XamlParser(input, cw);
-               r.Parse();
+               XamlParser r = new XamlParser(xr, cw);
+               try {
+                       r.Parse();
+               }
+               catch (Exception ex) {
+                       Console.WriteLine("Line " + xr.LineNumber + ", Column " 
+ xr.LinePosition);
+                       throw ex;
+               }
        }
        
        public static void Main(string[] args) {

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to