Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Move xamlc too

svn path=/trunk/olive/; revision=64834
  • Loading branch information...
commit 7941a522d8433a2b0b3eb3bc9de36c2166d04698 1 parent b3a1dd8
@migueldeicaza migueldeicaza authored
View
152 tools/xamlc/ChangeLog
@@ -0,0 +1,152 @@
+2005-11-05 Kornél Pál <kornelpal@hotmail.com>
+
+ * xamlc.cs: Use Consts.MonoVersion as AssemblyVersion.
+ * xamlc.exe.sources: Added Consts.cs.
+
+2005-08-28 Iain McCoy <iain@mccoy.id.au>
+
+ * demo/TestVocab/ConsoleApp.cs,
+ demo/TestVocab/ConsoleReader.cs,
+ demo/TestVocab/ConsoleWriter.cs: fixed up incredibly broken tests for
+ equality.
+
+2005-08-28 Iain McCoy <iain@mccoy.id.au>
+
+ * demo/runtimetest.xaml: added a demonstration of objects as values of
+ dependency properties
+
+2005-08-27 Iain McCoy <iain@mccoy.id.au>
+
+ * demo/TestVocab/ConsoleValue.cs: some new features so that objects as
+ values of dependency properties can be used in a vaguely sensible
+ fashion
+ * demo/test.xaml: added a demonstration of objects as values of
+ dependency properties
+
+2005-08-26 Iain McCoy <iain@mccoy.id.au>
+
+ * README: some documentative notes for xaml-the-language
+
+2005-08-26 Iain McCoy <iain@mccoy.id.au>
+
+ * xamlc.cs: use the newly-renamed ParserToCode class instead of the
+ interim CodeWriter
+
+2005-08-26 Iain McCoy <iain@mccoy.id.au>
+
+ * demo/runtimetest.cs: use the newly-renamed Parser class instead of
+ the interim ObjectWriter
+
+2005-08-23 Iain McCoy <iain@mccoy.id.au>
+
+ * xamlc.cs: consume the new CodeWriter interface
+ * demo/runtimetest.cs: consume the new ObjectWriter interface
+
+2005-07-28 Iain McCoy <iain@mccoy.id.au>
+
+ * xamlc.cs: added support for choosing source code language to
+ generate and improved --help and --V output.
+
+2005-07-24 Iain McCoy <iain@mccoy.id.au>
+
+ * demo/TestVocab/ConsoleWriter.cs,
+ demo/TestVocab/ConsoleReader.cs,
+ demo/TestVocab/ConsoleApp.cs: fix up definitions of Equals methods
+ so that the object builder's tests work.
+
+2005-07-18 Iain McCoy <iain@mccoy.id.au>
+
+ * demo/TestVocab/*.cs: add implementations of equals so that tests for
+ the ObjectWriter can be written.
+
+2005-07-18 Iain McCoy <iain@mccoy.id.au>
+
+ * demo/runtimetest.xaml: added testing of complex objects as property
+ values
+
+2005-07-15 Iain McCoy <iain@mccoy.id.au>
+
+ * demo/test.xaml: enhanced testing of complex objects as property
+ values and documented test file.
+ * demo/runtimetest.xaml: added dependency property test
+
+2005-07-15 Iain McCoy <iain@mccoy.id.au>
+
+ * demo/TestVocab/ConsoleValues.cs: Add ConsoleValueAppend to avoid
+ resolving read value too early
+ * demo/TestVocab/ConsoleWriter.cs: Use ConsoleValue as type of Text
+ property. These changes get the example working
+
+
+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
+
+
+2005-07-13 Iain McCoy <iain@mccoy.id.au>
+
+ * 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 <iain@mccoy.id.au>
+
+ * 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 <iain@mccoy.id.au>
+
+ * demo/runtimetest.xaml
+ demo/runtimetest.cs,
+ demo/Makefile: creation of objects at runtime from a xaml file
+
+2005-07-06 Iain McCoy <iain@mccoy.id.au>
+
+ * demo/test.xaml: add use of x:Name attribute
+
+2005-07-06 Iain McCoy <iain@mccoy.id.au>
+
+ * xamlc.cs: add support for emitting classes with the partial modifier
+ set
+
+2005-07-06 Iain McCoy <iain@mccoy.id.au>
+
+ * demo/TestVocab/ConsoleApp.cs: remove default value hack, since we
+ have proper default value support now
+
+2005-07-05 Iain McCoy <iain@mccoy.id.au>
+
+ * README: updated to reflect current output of demo
+ * demo/test.xaml: add attached property attribute demo
+
+2005-07-05 Iain McCoy <iain@mccoy.id.au>
+
+ * README: describe the demo as it currently is
+ * demo/TestVocab/ConsoleWriter.cs: delegates demonstration
+ * demo/TestVocab/ConsoleApp.cs: events demonstration
+ * demo/test.xaml: include delegates and events in demonstration
+
+2005-07-03 Iain McCoy <iain@mccoy.id.au>
+ * demo/Makefile: made more useful - just do "make run" and it should
+ all happen
+ * demo/test.xaml: added Code section, which I think should make this
+ thing a complete, if small, program
+ * demo/TestVocab/*: some small bugfixes, with a little bit of
+ craziness to work around the slightly bogus stuff in DependencyObject
+ at the moment.
+
+2005-07-02 Iain McCoy <iain@mccoy.id.au>
+
+ * whole folder: first emphatically work-in-progress version of xaml
+ compiler
View
8 tools/xamlc/Makefile
@@ -0,0 +1,8 @@
+thisdir = tools/xamlc
+SUBDIRS =
+include ../../build/rules.make
+
+LOCAL_MCS_FLAGS = -r:Mono.GetOptions.dll -r:WindowsBase.dll -r:PresentationFramework.dll
+PROGRAM = xamlc.exe
+
+include ../../build/executable.make
View
176 tools/xamlc/README
@@ -0,0 +1,176 @@
+This is my xaml compiler, being written as part of Google's summer of code
+program.
+
+Xaml is a language for concisely describing how to connect up a bunch of
+objects. As an example, in the avalon world:
+<Window Title="Hi!">
+ <Button>Click</Button>
+</Window>
+
+Would produce a child of Window where the constructor does this:
+this.Title = "Hi!";
+Button button = new Button();
+window.AddChild(button);
+button.AddText("Click");
+
+Except of course it can handle trees of arbitrary depth, so descriptions of
+complicated GUIs are not a problem and potentially much more readable than
+the code version.
+
+To use this thing:
+cd ../../class/WindowsBase
+make install
+cd ../PresentationFramework
+make install
+cd ../../tools/xamlc
+make install
+
+That will get everything compiled. There's a demo in the mcs/tools/xamlc/demo
+directory; to run it, cd into that directory and do "make run". Stuff should
+happen, along the lines of a program test.exe being generated and run to
+produce this output:
+
+Hello World
+IT BEGINS!
+Hello World
+YYYI'm surrounded!ZZZ
+What should I say?
+
+I say I say: INPUTINPUT
+I say.
+
+
+Goodbye.
+Goodbye.
+Goodbye.
+Bye
+Bye
+
+In the same directory, "make run2" should demonstrate the runtime creation of
+objects from xaml files.
+
+How it works
+============
+The compiler's main job is to identify the types to which your xaml file refers
+and use that to ensure that correct types appear in the output xaml file. This
+is also an issue when performing creation of objects from the xaml file at
+runtime because of the need to perform conversions between types.
+
+The following examples are given in terms of objects being instantiated directly
+by the parser at runtime; if this is not your chosen approach, then things work
+somewhat differently. The former approach, of calling Parser.LoadXml(), will
+create the object at runtime, while the latter approach of invoking xamlc will
+create a source code file representing the object that would otherwise have
+been created at runtime. The process by which this functions is that the class
+is defined as inheriting the class being represented by the top-level element of
+the xml tree, and every other object mentioned is either a variable local to the
+function or a field of the class.
+
+A xaml file is an Xml file where meaning is derived from processing
+instructions, text, elements, and attributes. Elements typically indicate class
+instances or properties, attributes refer mainly to properties, and processing
+instructions are used to allow types to be resolved correctly.
+
+In order to facilitate the correct resolution of types, every element must have
+a specified XML namespace. The XML namespace is an arbitrary string that has
+been defined as the identifier for an Assembly-ClrNamespace pair. The
+definition of these pairs is achieved with processing instructions (PIs). A line
+<?Mapping ClrNamespace="Org.Project" Assembly="myassembly.dll" XmlNamespace="cc" ?>
+
+indicates that every element in the cc namespace corresponds to a type defined
+in myassembly.dll in the Org.Project namespace. There is substantial similarity
+of purpose between the Mapping PI and C#'s using statement, but the Mapping PI
+is substantially more precise.
+
+Elements representing class instances in XAML files are required to have the
+name of the class to be instantiated as the element name. The top-level element
+must therefore be named according to what kind of object you wish to be produced
+by the compilation process. For example, if "XX" is defined (in the manner
+described above) as corresponding to an assembly where the relevant namespace
+defines a Window class, the xaml document <x:Window xmlns:x="XX" /> will have a
+similar effect to the C# code "new Window()".
+
+If Xaml is to succeed in its goal of simplifying code in the style of that which
+is commonly used to initialize GUIs, it must have a way of adding objects as
+children to other objects. This maps to child elements in Xml - the standard
+case is for a child element of an object element to represent an object which
+is a child of the aforementioned object. The notion of a child object is defined
+by the System.Windows.Serialization.IAddChild interface, which provides an
+AddChild method for making objects children of the implementor of the interface.
+
+We can therefore see that given a namespace defined similarly to that in the
+previous example containing Window and Button objects that the following
+document:
+
+<x:Window xmlns:x="XX">
+ <Button />
+ <Button />
+</x:Window>
+
+Is equivalent to the following C# code:
+Window w = new Window();
+((System.Windows.IAddChild)w).AddChild(new Button());
+((System.Windows.IAddChild)w).AddChild(new Button());
+
+The same mechanism also allows for the addition of text. The document:
+<x:Button xmlns:x="XX">I Am Button.</x:Button>
+
+Is equivalent to:
+Button b = new Button();
+((System.Windows.IAddChild)b).AddText("I Am Button.");
+
+
+So far, we've seen mechanisms for type resolution, making an element a child of
+another one, and adding text for an element. We still need mechanisms for
+setting properties and event handlers.
+
+The basic mechanism by which properties can be set is the xml attribute. The
+name of the attribute corresponds to the name of the property, and the value is
+converted from a string with .net's standard TypeConverter framework and
+assigned to the property. If our hypothetical Window class has a property
+Title of type String, we could do something like the following:
+<x:Window Title="The title of a window" xmlns:x="XX" />
+
+To produce code equivalent to
+Window w = new Window();
+w.Title = "The title of a window";
+
+While if Window defined a SecondsToDestruction property of type Int32, code like
+<x:Window SecondsToDestruction="5" xmlns:x="XX" />
+
+To produce code equivalent to:
+Window w = new Window();
+w.SecondsToDestruction = (new Int32Converter()).ConvertFromString("5");
+
+This system means that any property, the type of which has a converter allowing
+instances to be created from strings, can be assigned to in your Xaml code.
+
+While this is sufficiently general for many cases, it is impractical for cases
+where you are unable for whatever reason to express the property value as a
+string. For cases like these the complex property syntax is provided. In order
+to use this syntax, you define an element as a child of the element representing
+the object the property of which you want to set. The elements name should be
+the name of the class with the property as member, followed by a ., followed by
+the name of the property. Continuing on with our Window example, if the Window
+had a Thumbnail property we might do something like this:
+<x:Window xmlns:x="XX">
+ <Window.Thumbnail>
+ <Button />
+ </Window.Thumbnail>
+</x:Window>
+
+In order to produce code equivalent to:
+Window w = new Window();
+w.Thumbnail = new Button();
+
+This syntax allows arbitrarily complex objects to be used as property values.
+
+The syntax for events follows the syntax for properties. In order to add an
+event handler, all that is neccesary is to add an attribute to the object's
+element with the name of the event as its name and the name of the event handler
+as its value. For example, if the Window has an OnClose event:
+<x:Window OnClose="close_handler" xmlns:x="XX" />
+
+Would correspond to code like:
+Window w = new Window();
+w.OnClose += close_handler;
View
27 tools/xamlc/demo/Makefile
@@ -0,0 +1,27 @@
+thisdir = tools/xaml/demo
+include ../../../build/rules.make
+
+SOURCES=TestVocab/ConsoleApp.cs TestVocab/ConsoleWriter.cs TestVocab/ConsoleReader.cs TestVocab/IConsoleAction.cs TestVocab/ConsoleValue.cs TestVocab/ConsoleVars.cs
+
+run:
+ make clean
+ make TestVocab.dll
+ MONO_PATH="." $(RUNTIME) --debug ../xamlc.exe -o:test.xaml.out.cs test.xaml
+ $(CSCOMPILE) -r:TestVocab.dll -o test.exe test.xaml.out.cs
+ echo "INPUTINPUT" | $(RUNTIME) --debug test.exe
+
+run2:
+ make runtimetest.exe
+ echo "INPUTINPUT" | $(RUNTIME) --debug runtimetest.exe
+
+clean-local:
+ rm -f TestVocab.dll test.xaml.out.cs
+
+all-local: TestVocab.dll
+
+TestVocab.dll: $(SOURCES)
+ $(CSCOMPILE) -r:PresentationFramework.dll -r:WindowsBase.dll -out:TestVocab.dll -target:library $(SOURCES)
+
+
+runtimetest.exe: runtimetest.cs TestVocab.dll
+ $(CSCOMPILE) -r:PresentationFramework.dll -r:WindowsBase.dll -r:TestVocab.dll -out:runtimetest.exe runtimetest.cs
View
71 tools/xamlc/demo/TestVocab/ConsoleApp.cs
@@ -0,0 +1,71 @@
+using System;
+using System.Collections;
+using System.Windows;
+using System.Windows.Serialization;
+
+namespace Xaml.TestVocab.Console {
+ public delegate void SomethingHappenedHandler();
+ public class ConsoleApp : IAddChild {
+ private ArrayList actions = new ArrayList();
+
+ public event SomethingHappenedHandler SomethingHappened;
+
+ public void AddText(string Text)
+ {
+ actions.Add(new ConsoleWriter(
+ new ConsoleValueString(Text)));
+ }
+
+ public void AddChild(object Value)
+ {
+ if (Value is IConsoleAction)
+ actions.Add(Value);
+ else
+ throw new Exception(Value.ToString() + " is not a console action");
+ }
+
+ public void Run()
+ {
+ foreach (IConsoleAction action in actions) {
+ int reps = GetRepetitions((DependencyObject)action);
+ for (int i = 0; i < reps; i++) {
+ SomethingHappenedHandler s = SomethingHappened;
+ if (s != null)
+ s();
+ action.Run();
+ }
+ }
+ }
+
+
+ public static readonly DependencyProperty RepetitionsProperty = DependencyProperty.RegisterAttached("Repetitions", typeof(int), typeof(ConsoleApp), new PropertyMetadata(1));
+ public static void SetRepetitions(DependencyObject obj, int number)
+ {
+ obj.SetValue(RepetitionsProperty, number);
+ }
+ public static int GetRepetitions(DependencyObject obj)
+ {
+ return (int)obj.GetValue(RepetitionsProperty);
+ }
+
+
+ public override bool Equals(object o)
+ {
+ ConsoleApp app = (ConsoleApp)o;
+ if (app.actions.Count != actions.Count)
+ return false;
+ if (app.SomethingHappened != SomethingHappened)
+ return false;
+
+ for (int i = 0; i < actions.Count; i++) {
+ if (!actions[i].Equals(app.actions[i]))
+ return false;
+ }
+ return true;
+ }
+ public override int GetHashCode()
+ {
+ return actions.GetHashCode();
+ }
+ }
+}
View
36 tools/xamlc/demo/TestVocab/ConsoleReader.cs
@@ -0,0 +1,36 @@
+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);
+ }
+
+ public override bool Equals(object o)
+ {
+ ConsoleReader reader = (ConsoleReader)o;
+ return (reader.variable == variable) &&
+ ((reader.prompt == null && prompt == null) || reader.prompt.Equals(prompt)) &&
+ (ConsoleApp.GetRepetitions(reader) == ConsoleApp.GetRepetitions(this));
+ }
+ public override int GetHashCode()
+ {
+ return variable.GetHashCode() + prompt.GetHashCode() + ConsoleApp.GetRepetitions(this).GetHashCode();
+ }
+ }
+}
View
124 tools/xamlc/demo/TestVocab/ConsoleValue.cs
@@ -0,0 +1,124 @@
+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 override bool Equals(Object o)
+ {
+ return (((ConsoleValue)o).Value == Value);
+ }
+ public override int GetHashCode()
+ {
+ return Value.GetHashCode();
+ }
+ }
+
+ 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)) || (t == typeof(int));
+ }
+ 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) &&
+ destinationType != typeof(int))
+ throw new NotSupportedException();
+
+ if (o is ConsoleValue) {
+ if (destinationType == typeof(string))
+ return ((ConsoleValue)o).Value;
+ else
+ return Int32.Parse(((ConsoleValue)o).Value);
+ } else {
+ throw new NotSupportedException();
+ }
+ }
+ }
+
+
+
+ public class ConsoleValueString : ConsoleValue {
+ string val;
+
+ public ConsoleValueString()
+ {
+ this.val = "";
+ }
+ public ConsoleValueString(string val)
+ {
+ this.val = val;
+ }
+
+ public override string Value {
+ get { return val; }
+ }
+
+ public string Text {
+ set { val = value; }
+ }
+
+ }
+
+ public class ConsoleValueAppend : ConsoleValue {
+ ConsoleValue a, b;
+ public ConsoleValueAppend(ConsoleValue a, ConsoleValue b)
+ {
+ this.a = a;
+ this.b = b;
+ }
+
+ public override string Value {
+ get { return a.Value + b.Value; }
+ }
+ }
+
+
+ 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; }
+ }
+
+ public override bool Equals(object o)
+ {
+ return (((ConsoleValueVar)o).var == var);
+ }
+ public override int GetHashCode()
+ {
+ return var.GetHashCode();
+ }
+ }
+
+}
View
13 tools/xamlc/demo/TestVocab/ConsoleVars.cs
@@ -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];
+ }
+ }
+}
View
64 tools/xamlc/demo/TestVocab/ConsoleWriter.cs
@@ -0,0 +1,64 @@
+using System;
+using System.Windows;
+using System.Windows.Serialization;
+
+namespace Xaml.TestVocab.Console {
+ public delegate string Filter(string s);
+
+ public class ConsoleWriter : DependencyObject, IAddChild, IConsoleAction {
+ ConsoleValue text;
+ private Filter filter;
+
+ public ConsoleWriter()
+ {
+ text = new ConsoleValueString("");
+ }
+
+ public ConsoleWriter(ConsoleValue text)
+ {
+ this.text = text;
+ }
+
+ public ConsoleValue Text {
+ get { return text; }
+ set { text = value; }
+ }
+ public Filter Filter {
+ get { return Filter; }
+ set { filter = value; }
+ }
+
+ public void AddText(string text)
+ {
+ this.text = new ConsoleValueAppend(this.text, new ConsoleValueString(text));
+ }
+
+ public void AddChild(Object o)
+ {
+ this.text = new ConsoleValueAppend(this.text, (ConsoleValue)o);
+ }
+
+
+ public void Run()
+ {
+ Filter f = filter;
+ string s = text.Value;
+ // apply filter, if it exists
+ if (f != null)
+ s = f(s);
+ System.Console.WriteLine(s);
+ }
+
+ public override bool Equals(object o)
+ {
+ ConsoleWriter writer = (ConsoleWriter)o;
+ return (writer.filter == filter) &&
+ (writer.text.Equals(text)) &&
+ (ConsoleApp.GetRepetitions(writer) == ConsoleApp.GetRepetitions(this));
+ }
+ public override int GetHashCode()
+ {
+ return filter.GetHashCode() + text.GetHashCode() + ConsoleApp.GetRepetitions(this).GetHashCode();
+ }
+ }
+}
View
5 tools/xamlc/demo/TestVocab/IConsoleAction.cs
@@ -0,0 +1,5 @@
+namespace Xaml.TestVocab.Console {
+ public interface IConsoleAction {
+ void Run();
+ }
+}
View
11 tools/xamlc/demo/runtimetest.cs
@@ -0,0 +1,11 @@
+using Xaml.TestVocab.Console;
+using System.Xml;
+using System.Windows.Serialization;
+
+class RuntimeTest {
+ public static void Main(string[] args) {
+ ConsoleApp c = (ConsoleApp)Parser.LoadXml(new XmlTextReader("runtimetest.xaml"));
+
+ c.Run();
+ }
+}
View
21 tools/xamlc/demo/runtimetest.xaml
@@ -0,0 +1,21 @@
+<?Mapping ClrNamespace="Xaml.TestVocab.Console" Assembly="TestVocab" XmlNamespace="console" ?>
+
+<ConsoleApp xmlns="console"
+ xmlns:x="http://schemas.microsoft.com/winfx/xaml/2005"
+ x:Class="DemoConsoleApp">
+ <ConsoleWriter ConsoleApp.Repetitions="2">IT BEGINS!</ConsoleWriter>
+ <ConsoleWriter x:Name="_greeter" Text="Hello World" />
+ <ConsoleReader Variable="comment">
+ <ConsoleReader.Prompt>
+ <ConsoleWriter>What shall I say?</ConsoleWriter>
+ </ConsoleReader.Prompt>
+ </ConsoleReader>
+ <ConsoleWriter>
+ <ConsoleValueVar Variable="comment" />
+ </ConsoleWriter>
+ <ConsoleWriter>
+ <ConsoleApp.Repetitions><ConsoleValueString Text="2" /></ConsoleApp.Repetitions>
+ <ConsoleWriter.Text>Goodbye.</ConsoleWriter.Text>
+ </ConsoleWriter>
+ <ConsoleWriter>Bye</ConsoleWriter>
+</ConsoleApp>
View
86 tools/xamlc/demo/test.xaml
@@ -0,0 +1,86 @@
+<?Mapping ClrNamespace="Xaml.TestVocab.Console" Assembly="TestVocab.dll" XmlNamespace="console" ?>
+
+<ConsoleApp xmlns="console"
+ xmlns:x="http://schemas.microsoft.com/winfx/xaml/2005"
+ x:Class="DemoConsoleApp"
+ SomethingHappened="printHi">
+ <!-- create a ConsoleWriter and populate it with IAddChild -->
+ <ConsoleWriter>IT BEGINS!</ConsoleWriter>
+ <!-- create a ConsoleWriter specifying a name and setting its text
+ property with an xml attribute -->
+ <ConsoleWriter x:Name="_greeter" Text="Hello World" />
+ <!-- create a ConsoleWriter with the text property again set with an
+ xml attribute but also set a property with a delegate type -->
+ <ConsoleWriter Text="I'm surrounded!" Filter="stringFilter" />
+
+
+
+ <!-- create a ConsoleReader and explicitly set its prompt to a
+ ConsoleWriter -->
+ <ConsoleReader Variable="thingo">
+ <ConsoleReader.Prompt>
+ <ConsoleWriter>What should I say?</ConsoleWriter>
+ </ConsoleReader.Prompt>
+ </ConsoleReader>
+ <!--
+ create a ConsoleReader where a ConsoleWriter is implicitly created
+ and AddText called on it
+ NOT USED due to uncertainty about if this is an actual feature
+ <ConsoleReader Variable="thingo2">
+ <ConsoleReader.Prompt>Then I shall say?</ConsoleReader.Prompt>
+ </ConsoleReader>
+ -->
+ <!-- Create a ConsoleWriter where a ConsoleValueVar object is created
+ and added as a child alongside text children -->
+ <ConsoleWriter>
+I say I say: <ConsoleValueVar Variable="thingo" />
+I say.
+ </ConsoleWriter>
+ <ConsoleWriter>
+ <ConsoleWriter.Text>H</ConsoleWriter.Text>
+ <ConsoleWriter.Text>V</ConsoleWriter.Text>
+ </ConsoleWriter>
+ <!-- Explicitly set the ConsoleWriter's Text property to a
+ ConsoleValueVar instance -->
+ <ConsoleWriter>
+ <ConsoleWriter.Text><ConsoleValueVar Variable="thingo2" /></ConsoleWriter.Text>
+ </ConsoleWriter>
+ <!-- Create a ConsoleWriter and set the ConsoleApp.Repetitions
+ dependency property as an element -->
+ <ConsoleWriter>
+ <ConsoleApp.Repetitions>3</ConsoleApp.Repetitions>
+ <ConsoleWriter.Text>Goodbye.</ConsoleWriter.Text>
+ </ConsoleWriter>
+ <!-- Create a ConsoleWriter and set the ConsoleApp.Repetitions
+ dependency property as an element using an object instance as
+ the property value -->
+ <ConsoleWriter>
+ <ConsoleApp.Repetitions><ConsoleValueString Text="2" /></ConsoleApp.Repetitions>
+ <ConsoleWriter.Text>Goodbye.</ConsoleWriter.Text>
+ </ConsoleWriter>
+
+ <!-- Create a ConsoleWriter and set the ConsoleApp.Repetitions
+ dependency property as an attribute -->
+ <ConsoleWriter ConsoleApp.Repetitions="2">Bye</ConsoleWriter>
+ <!-- a fairly standard Code element -->
+ <x:Code><![CDATA[
+ public static void Main(string[] args)
+ {
+ DemoConsoleApp c = new DemoConsoleApp();
+ c._greeter.Run();
+ c.Run();
+ }
+
+ private string stringFilter(string s)
+ {
+ return "YYY" + s + "ZZZ";
+ }
+
+ private void printHi()
+ {
+ //this code is run before every call to IConsoleAction.Run() by ConsoleApp,
+ //uncomment it to see that happening
+ //System.Console.WriteLine("Hi there, something's about to happen!");
+ }
+ ]]></x:Code>
+</ConsoleApp>
View
108 tools/xamlc/xamlc.cs
@@ -0,0 +1,108 @@
+//
+// xamlc.cs
+//
+// Author:
+// Iain McCoy (iain@mccoy.id.au)
+//
+// (C) 2005 Iain McCoy
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.IO;
+using System.Xml;
+using System.CodeDom;
+using System.CodeDom.Compiler;
+using System.Reflection;
+using Mono.GetOptions;
+using Mono.Windows.Serialization;
+
+[assembly: AssemblyTitle ("xamlc.exe")]
+[assembly: AssemblyVersion (Consts.MonoVersion)]
+[assembly: AssemblyDescription ("Compiler from XAML to more conventional languages")]
+[assembly: AssemblyCopyright ("(c) Iain McCoy")]
+
+[assembly: Mono.UsageComplement ("")]
+
+[assembly: Mono.About("Compiler to create normal clr-based high level language source code from XAML")]
+[assembly: Mono.Author ("Iain McCoy")]
+
+class XamlOptions : Options {
+ [Option("Whether or not the class should be marked as partial", "p", "partial")]
+ public bool Partial;
+
+ [Option("the file to output to", "o", "output")]
+ public string OutputFile;
+
+ [Option("the language in which to write the output file", "l", "lang")]
+ public string OutputLanguage;
+}
+
+class Driver {
+ public static void process(XamlOptions options, string input) {
+ if (!input.EndsWith(".xaml")) {
+ Console.WriteLine("Input filenames must end in .xaml");
+ return;
+ }
+ if (Environment.Version.Major < 2 && options.Partial) {
+ Console.WriteLine("This runtime version does not support partial classes");
+ return;
+ }
+ if (options.OutputFile == null) {
+ options.OutputFile = input + ".out";
+ }
+ ICodeGenerator generator = getGenerator(options.OutputLanguage);
+ XmlTextReader xr = new XmlTextReader(input);
+ try {
+ string result = ParserToCode.Parse(xr, generator, options.Partial);
+ TextWriter tw = new StreamWriter(options.OutputFile);
+ tw.Write(result);
+ tw.Close();
+ }
+ catch (Exception ex) {
+ Console.WriteLine("Line " + xr.LineNumber + ", Column " + xr.LinePosition);
+ throw ex;
+ }
+ }
+
+ private static ICodeGenerator getGenerator(string language)
+ {
+ if (language == null || language == "cs" || language == "c#") {
+ return (new Microsoft.CSharp.CSharpCodeProvider()).CreateGenerator();
+ } else if (language == "vb") {
+ return (new Microsoft.VisualBasic.VBCodeProvider()).CreateGenerator();
+ } else {
+ Console.WriteLine("Unknown language: " + language);
+ Environment.Exit(1);
+ return null;
+ }
+ }
+
+ public static void Main(string[] args) {
+ XamlOptions options = new XamlOptions();
+ options.ProcessArgs(args);
+ if (options.RemainingArguments.Length != 1) {
+ Console.WriteLine("Need exactly one input file");
+ return;
+ }
+ process(options, options.RemainingArguments[0]);
+ }
+}
View
2  tools/xamlc/xamlc.exe.sources
@@ -0,0 +1,2 @@
+xamlc.cs
+../../build/common/Consts.cs
Please sign in to comment.
Something went wrong with that request. Please try again.