Author: iainmc
Date: 2005-07-14 11:51:49 -0400 (Thu, 14 Jul 2005)
New Revision: 47308
Modified:
trunk/mcs/class/PresentationFramework/ChangeLog
trunk/mcs/class/PresentationFramework/Mono.Windows.Serialization/CodeWriter.cs
trunk/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs
trunk/mcs/tools/xamlc/ChangeLog
trunk/mcs/tools/xamlc/demo/TestVocab/ConsoleValue.cs
trunk/mcs/tools/xamlc/demo/test.xaml
Log:
2005-07-15 Iain McCoy <[EMAIL PROTECTED]>
* 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
Modified: trunk/mcs/class/PresentationFramework/ChangeLog
===================================================================
--- trunk/mcs/class/PresentationFramework/ChangeLog 2005-07-14 15:27:44 UTC
(rev 47307)
+++ trunk/mcs/class/PresentationFramework/ChangeLog 2005-07-14 15:51:49 UTC
(rev 47308)
@@ -1,3 +1,16 @@
+2005-07-15 Iain McCoy <[EMAIL PROTECTED]>
+
+ * 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 <[EMAIL PROTECTED]>
* Mono.Windows.Serialization/XamlParser.cs,
Modified:
trunk/mcs/class/PresentationFramework/Mono.Windows.Serialization/CodeWriter.cs
===================================================================
---
trunk/mcs/class/PresentationFramework/Mono.Windows.Serialization/CodeWriter.cs
2005-07-14 15:27:44 UTC (rev 47307)
+++
trunk/mcs/class/PresentationFramework/Mono.Windows.Serialization/CodeWriter.cs
2005-07-14 15:51:49 UTC (rev 47308)
@@ -27,6 +27,7 @@
//
using System;
+using System.Diagnostics;
using System.Reflection;
using System.IO;
using System.Collections;
@@ -61,6 +62,7 @@
// instance
public void CreateTopLevel(Type parent, string className)
{
+ debug();
if (className == null) {
className = "derived" + parent.Name;
}
@@ -94,6 +96,7 @@
// 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 @@
// 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 @@
// 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 @@
// property
public void CreateDependencyProperty(Type attachedTo, string
propertyName, Type propertyType)
{
+ debug();
string varName = "temp";
varName += tempIndex;
tempIndex += 1;
@@ -181,7 +187,9 @@
// 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 @@
// 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 @@
// 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 @@
// 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 @@
// 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 @@
public void CreatePropertyObject(Type type, string varName)
{
+ debug();
bool isDefaultName;
if (varName == null) {
isDefaultName = true;
@@ -299,13 +313,16 @@
}
- 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 @@
(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());
+ }
}
}
Modified:
trunk/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs
===================================================================
---
trunk/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs
2005-07-14 15:27:44 UTC (rev 47307)
+++
trunk/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs
2005-07-14 15:51:49 UTC (rev 47308)
@@ -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 @@
private enum CurrentType { Object,
Property,
+ PropertyObject,
DependencyProperty,
Code }
@@ -76,6 +78,7 @@
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 @@
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 @@
// 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 @@
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 @@
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 @@
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 @@
{
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 @@
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 @@
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;
+ }
}
}
Modified: trunk/mcs/tools/xamlc/ChangeLog
===================================================================
--- trunk/mcs/tools/xamlc/ChangeLog 2005-07-14 15:27:44 UTC (rev 47307)
+++ trunk/mcs/tools/xamlc/ChangeLog 2005-07-14 15:51:49 UTC (rev 47308)
@@ -1,3 +1,8 @@
+2005-07-15 Iain McCoy <[EMAIL PROTECTED]>
+
+ * demo/test.xaml: uncommented second test of complex objects as
+ property values
+
2005-07-14 Iain McCoy <[EMAIL PROTECTED]>
* demo/test.xaml: added first test of complex objects as property values
Modified: trunk/mcs/tools/xamlc/demo/TestVocab/ConsoleValue.cs
===================================================================
--- trunk/mcs/tools/xamlc/demo/TestVocab/ConsoleValue.cs 2005-07-14
15:27:44 UTC (rev 47307)
+++ trunk/mcs/tools/xamlc/demo/TestVocab/ConsoleValue.cs 2005-07-14
15:51:49 UTC (rev 47308)
@@ -30,6 +30,7 @@
{
if (destinationType != typeof(string))
throw new NotSupportedException();
+
if (o is ConsoleValue)
return ((ConsoleValue)o).Value;
else
Modified: trunk/mcs/tools/xamlc/demo/test.xaml
===================================================================
--- trunk/mcs/tools/xamlc/demo/test.xaml 2005-07-14 15:27:44 UTC (rev
47307)
+++ trunk/mcs/tools/xamlc/demo/test.xaml 2005-07-14 15:51:49 UTC (rev
47308)
@@ -12,13 +12,11 @@
<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>
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches