diff --git a/CSharpTranslator/antlr3/CSharpTranslator.sln b/CSharpTranslator/antlr3/CSharpTranslator.sln
index 0a48a44..bd167b3 100644
--- a/CSharpTranslator/antlr3/CSharpTranslator.sln
+++ b/CSharpTranslator/antlr3/CSharpTranslator.sln
@@ -1,16 +1,31 @@
Microsoft Visual Studio Solution File, Format Version 11.00
-# Visual C# Express 2010
+# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "cs2j", "src\cs2j\cs2j.csproj", "{CE961AC5-C8D4-41B3-AAF3-23FA8FAEE8AD}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Antlr3.Runtime", "src\Antlr.Runtime\Antlr3.Runtime.csproj", "{CF15D0D5-BE72-4F98-B70F-229ABA1DF0E8}"
EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{79994BC6-E233-4F7F-B9E1-A137B34B3F99}"
+ ProjectSection(SolutionItems) = preProject
+ build.properties = build.properties
+ build.xml = build.xml
+ EndProjectSection
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "cs2jTest", "cs2jTest\cs2jTest.csproj", "{28A229C9-2F22-4384-B224-61A5C67638CE}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
+ Default|Any CPU = Default|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {28A229C9-2F22-4384-B224-61A5C67638CE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {28A229C9-2F22-4384-B224-61A5C67638CE}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {28A229C9-2F22-4384-B224-61A5C67638CE}.Default|Any CPU.ActiveCfg = Debug|Any CPU
+ {28A229C9-2F22-4384-B224-61A5C67638CE}.Default|Any CPU.Build.0 = Debug|Any CPU
+ {28A229C9-2F22-4384-B224-61A5C67638CE}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {28A229C9-2F22-4384-B224-61A5C67638CE}.Release|Any CPU.Build.0 = Release|Any CPU
{CE961AC5-C8D4-41B3-AAF3-23FA8FAEE8AD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CE961AC5-C8D4-41B3-AAF3-23FA8FAEE8AD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CE961AC5-C8D4-41B3-AAF3-23FA8FAEE8AD}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -20,6 +35,11 @@ Global
{CF15D0D5-BE72-4F98-B70F-229ABA1DF0E8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CF15D0D5-BE72-4F98-B70F-229ABA1DF0E8}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
+ GlobalSection(NestedProjects) = preSolution
+ EndGlobalSection
+ GlobalSection(MonoDevelopProperties) = preSolution
+ StartupItem = src\cs2j\cs2j.csproj
+ EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
diff --git a/CSharpTranslator/antlr3/CSharpTranslator.userprefs b/CSharpTranslator/antlr3/CSharpTranslator.userprefs
index 7ed2ec8..db22c79 100644
--- a/CSharpTranslator/antlr3/CSharpTranslator.userprefs
+++ b/CSharpTranslator/antlr3/CSharpTranslator.userprefs
@@ -1,27 +1,84 @@
-
+
-
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+
+
\ No newline at end of file
diff --git a/CSharpTranslator/antlr3/build.properties b/CSharpTranslator/antlr3/build.properties
index 184b7e6..1815b76 100644
--- a/CSharpTranslator/antlr3/build.properties
+++ b/CSharpTranslator/antlr3/build.properties
@@ -1,51 +1,45 @@
-build.dir=${basedir}/build
-svntx.build.dir=${build.dir}/svntx
-cs2jtx.build.dir=${build.dir}/cs2jtx
-cs2jtx.bin.dir=${cs2jtx.build.dir}/Translator/bin/Debug
-svntxexe.svnwc.dir=${basedir}/
+## build.properties for Production
-## WARNING: If these boolean properties are shown through the launch dialog then
-## we must deal with value == false
-is.rebuild.cs2j=false
-is.cs2j.svnwc=false
-is.commit.javacode=false
+build.dir=${basedir}/../build
-svn.commit.msg.java=Auto-committed following cs2j translation
-svn.commit.removed.msg.java=Auto-committed removed files following cs2j translation
-
-svn.repo=https://svn.rusticisoftware.com/svn/projects
-csharp.project=Products/ScormEngineNet
-csharp.project.branch=trunk
-csharp.tx.sub.dir=src/app/ScormEngine.Core
-csharp.project.full=${csharp.project}/${csharp.project.branch}
-csharpcode.branch.url=${svn.repo}/${csharp.project.full}/${csharp.tx.sub.dir}
-
-csharptx.dir=ScormEngine.Core
-csharpcode.dir=${svntx.build.dir}/${csharptx.dir}
-
-csharpcode.tx.dir=${svntx.build.dir}/${csharptx.dir}/Logic
-
-java.project=Products/ScormEngineJava
-java.project.branch=${csharp.project.branch}
-java.tx.sub.dir=RusticiSoftware.ScormContentPlayer.Logic/src
-java.project.full=${java.project}/${java.project.branch}
-javacode.branch.url=${svn.repo}/${java.project.full}/${java.tx.sub.dir}
-
-javatx.dir=${java.tx.sub.dir}
-javacode.svnwc.dir=${svntx.build.dir}/${javatx.dir}
-javacode.old.svnwc.dir=${svntx.build.dir}/OldJava/${javatx.dir}
-
-cs2j.project=Products/CS2JLibrary
-#cs2j.project.branch=${csharp.project.branch}
-cs2j.project.branch=trunk
-cs2j.branch.url=${svn.repo}/${cs2j.project}/${cs2j.project.branch}/
-
-cs2j.dir=${svntx.build.dir}/CS2JLibrary
-
-cheats.dir=${svntx.build.dir}/Cheats
-
-svn.exe=svn
-
-
-builder.ant.lib=${basedir}/jar
+builder.ant.lib=${basedir}/lib
builder.ant.dll=${basedir}/dll
+
+
+## For Building cs2j
+
+# Location of .Net on this machine (this is standard .Net 2.0 location)
+windows.dotnet.release=v2.0.50727
+windows.dotnet.dir=C:/WINDOWS/Microsoft.NET/Framework/${windows.dotnet.release}
+
+# Location of antlr dlls on this machine
+antlr.dll.dir=${builder.ant.dll}
+
+cs2jtx.src.dir=${basedir}/src/cs2j
+cs2jtx.bin.dir=${cs2jtx.src.dir}/bin/Debug
+
+cs2jtx.build.dir=${build.dir}/cs2jtx
+
+
+
+## For running cs2j
+
+cs2jtx.exe= ${cs2jtx.bin.dir}/cs2j.exe
+#cs2jtx.exe= ${basedir}/../bin/Translator.exe
+
+# by default, sibling directory to Translator
+cs2j.proj.dir=${basedir}/../../CS2JLibrary
+cs2j.dir=${basedir}/../../CS2JLibrary/NetTranslations
+cheats.dir=${basedir}/../../Cheats
+
+# Directories to build into, against
+
+# If no cs.app.dir set make it equal to cs.tx.dir
+cs.app.dir=${cs.tx.dir}
+
+# Object of the translation, by default in the build area
+java.output.dir=${build.dir}/javaproject/src
+
+cs2j.dist.dir=${build.dir}/cs2j/zip
+
+
diff --git a/CSharpTranslator/antlr3/build.xml b/CSharpTranslator/antlr3/build.xml
index 3badacb..aafdd3f 100644
--- a/CSharpTranslator/antlr3/build.xml
+++ b/CSharpTranslator/antlr3/build.xml
@@ -1,15 +1,11 @@
-
+
- This script automates translation of a C# svn branch to a Java branch
-
-
-
-
-
-
+ This script builds the cs2j translator and translates C# code
+
+
@@ -17,193 +13,254 @@
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
+
-
-
+
+
+
+
+
+
-
-
-
-
-
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/CSharpTranslator/antlr3/cs2jTest/TranslationTemplate.cs b/CSharpTranslator/antlr3/cs2jTest/TranslationTemplate.cs
new file mode 100644
index 0000000..cf7d494
--- /dev/null
+++ b/CSharpTranslator/antlr3/cs2jTest/TranslationTemplate.cs
@@ -0,0 +1,76 @@
+using System;
+using NUnit.Framework;
+using System.IO;
+using System.Xml.Serialization;
+using RusticiSoftware.Translator.Utils;
+using System.Xml;
+using System.Text;
+using System.Collections.Generic;
+
+namespace RusticiSoftware.Translator.CLR
+{
+ [TestFixture()]
+ public class TranslationTemplateTest
+ {
+
+ private TypeRepTemplate ToStreamAndBack(TypeRepTemplate inT) {
+
+ XmlSerializer xmls = new XmlSerializer(inT.GetType(), Constants.TranslationTemplateNamespace);
+
+ using (MemoryStream ms = new MemoryStream())
+ {
+ XmlWriterSettings settings = new XmlWriterSettings();
+ settings.Encoding = Encoding.UTF8;
+ settings.Indent = true;
+ settings.IndentChars = "\t";
+ settings.NewLineChars = Environment.NewLine;
+ settings.ConformanceLevel = ConformanceLevel.Document;
+
+ using (XmlWriter writer = XmlTextWriter.Create(ms, settings))
+ {
+ xmls.Serialize(writer, inT);
+ }
+
+#if VERBOSETESTS
+ string xml = Encoding.UTF8.GetString(ms.ToArray());
+ Console.WriteLine (xml);
+#endif
+
+ //ms.Flush();
+ ms.Position = 0;
+
+ return TypeRepTemplate.newInstance(ms);
+ }
+ }
+
+ [Test()]
+ public void EnumCase ()
+ {
+ EnumRepTemplate to = new EnumRepTemplate();
+
+ to.Members.Add(new EnumMemberRepTemplate("START"));
+ to.Members.Add(new EnumMemberRepTemplate("EOF","3"));
+
+ EnumRepTemplate back = (EnumRepTemplate)ToStreamAndBack(to);
+
+ Assert.AreEqual(to, back);
+ }
+
+ [Test()]
+ public void DelegateCase ()
+ {
+ DelegateRepTemplate to = new DelegateRepTemplate();
+
+ to.Return = "System.String";
+ to.Params.Add(new ParamRepTemplate("System.Int32", "count"));
+ to.Params.Add(new ParamRepTemplate("System.Object", "fill"));
+ to.Params.Add(new ParamRepTemplate("System.Boolean", "verbose"));
+ to.Java = "fred";
+
+ DelegateRepTemplate back = (DelegateRepTemplate)ToStreamAndBack(to);
+
+ Assert.AreEqual(to, back);
+ }
+}
+}
+
diff --git a/CSharpTranslator/antlr3/cs2jTest/cs2jTest.csproj b/CSharpTranslator/antlr3/cs2jTest/cs2jTest.csproj
new file mode 100644
index 0000000..728652b
--- /dev/null
+++ b/CSharpTranslator/antlr3/cs2jTest/cs2jTest.csproj
@@ -0,0 +1,48 @@
+
+
+
+ Debug
+ AnyCPU
+ 10.0.0
+ 2.0
+ {28A229C9-2F22-4384-B224-61A5C67638CE}
+ Library
+ cs2jTest
+ cs2jTest
+ v3.5
+
+
+ true
+ full
+ false
+ bin\Debug
+ DEBUG VERBOSETESTS
+ prompt
+ 4
+ false
+
+
+ none
+ false
+ bin\Release
+ prompt
+ 4
+ false
+
+
+
+
+
+
+
+
+
+
+
+
+ {CE961AC5-C8D4-41B3-AAF3-23FA8FAEE8AD}
+ cs2j
+
+
+
+
\ No newline at end of file
diff --git a/CSharpTranslator/antlr3/cs2jTest/cs2jTest.mdproj b/CSharpTranslator/antlr3/cs2jTest/cs2jTest.mdproj
new file mode 100644
index 0000000..28d1cd6
--- /dev/null
+++ b/CSharpTranslator/antlr3/cs2jTest/cs2jTest.mdproj
@@ -0,0 +1 @@
+
Default
AnyCPU
NUnitAssemblyGroupProject
10.0.0
2.0
{CBDDA73A-AA2C-42D1-A7D6-F3DE6F1EE2FC}
\ No newline at end of file
diff --git a/CSharpTranslator/antlr3/src/cs2j/CLR/TranslationTemplate.cs b/CSharpTranslator/antlr3/src/cs2j/CLR/TranslationTemplate.cs
index 35536b6..ffd9e06 100644
--- a/CSharpTranslator/antlr3/src/cs2j/CLR/TranslationTemplate.cs
+++ b/CSharpTranslator/antlr3/src/cs2j/CLR/TranslationTemplate.cs
@@ -5,420 +5,1293 @@ using System.Text;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
+using RusticiSoftware.Translator.Utils;
+
+// These Template classes are in-memory versions of the xml translation templates
+// (we use C# to directly persist to / from files).
+
+// We have overloaded Equals to test value equality for these template objects. For now its only
+// used by unit tests (to check that the object survives xml serialization / deserialization
+// unscathed). But it might be useful down the road.
+// By overloading Equals, we also have to overload GetHashcode (well, its highly reccomended)...
namespace RusticiSoftware.Translator.CLR
{
- public abstract class TranslationBase
- {
- protected TranslationBase()
- {
- }
- }
-
- public class ParamRepTemplate : TranslationBase
- {
-
- public string Type;
-
- public string Name;
-
- public ParamRepTemplate() : base()
- {}
-
- public ParamRepTemplate(string t, string a)
- {
- Type = t;
- Name = a;
- }
-
- }
-
- public class ConstructorRepTemplate : TranslationBase
- {
- [XmlArrayItem("Import")]
- public string[] Imports;
- [XmlArrayItem("Param")]
- public ParamRepTemplate[] Params;
- public string Java;
-
- public ConstructorRepTemplate()
- : base()
- {
- Imports = new string[0];
- Params = new ParamRepTemplate[0];
- }
-
- public ConstructorRepTemplate(ParamRepTemplate[] pars)
- : base()
- {
- Imports = new string[0];
- Params = pars;
- }
-
- public ConstructorRepTemplate(ParamRepTemplate[] pars, string[] imps, string javaRep)
- : base()
- {
- Imports = imps;
- Params = pars;
- Java = javaRep;
- }
- }
-
- public class MethodRepTemplate : ConstructorRepTemplate
- {
- public string Return;
- public string Name;
-
- public MethodRepTemplate()
- { }
-
- public MethodRepTemplate(string retType, string methodName,
- ParamRepTemplate[] pars, string[] imps, string javaRep)
- : base(pars, imps, javaRep)
- {
- Return = retType;
- Name = methodName;
- }
-
- public MethodRepTemplate(string retType, string methodName,
- ParamRepTemplate[] pars)
- : this(retType, methodName, pars, new string[0], null)
- {
- }
-
- }
-
- public class CastRepTemplate : TranslationBase
- {
- [XmlArrayItem("Import")]
- public string[] Imports;
- public string From;
- public string To;
- public string Java;
-
- public CastRepTemplate()
- : base()
- {
- Imports = new string[0];
- }
-
- public CastRepTemplate(string fType, string tType,
- string[] imps, string java)
- {
- From = fType;
- To = tType;
- Imports = imps;
- Java = java;
- }
-
- public CastRepTemplate(string fType, string tType)
- :
- this(fType, tType, new string[0], null)
- {
- }
- }
-
- public class FieldRepTemplate : TranslationBase
- {
- [XmlArrayItem("Import")]
- public string[] Imports;
- public string Type;
- public string Name;
- public string Get;
-
- public FieldRepTemplate()
- : base()
- {
- Imports = new string[0];
- }
-
- public FieldRepTemplate(string fType, string fName,
- string[] imps, string javaGet)
- {
- Type = fType;
- Name = fName;
- Imports = imps;
- Get = javaGet;
- }
-
- public FieldRepTemplate(string fType, string fName)
- :
- this(fType, fName, new string[0], null)
- {
- }
- }
-
- public class PropRepTemplate : FieldRepTemplate
- {
- public string Set;
-
- public PropRepTemplate()
- : base()
- { }
-
- public PropRepTemplate(string fType, string fName,
- string[] imps, string javaGet, string javaSet)
- : base(fType, fName, imps, javaGet)
- {
- Set = javaSet;
- }
-
- public PropRepTemplate(string fType, string fName) : this(fType, fName, new string[0], null, null)
- {
- }
-
- }
-
-
- // Base Template for classes, interfaces, enums, etc.
- [Serializable]
- public abstract class TypeRepTemplate : TranslationBase
- {
-
- // Fully qualified Type Name
- [XmlElementAttribute("Name")]
- public string TypeName;
-
- // Java equivalent of this type (valid given imports)
- public string Java;
-
- // Path to use when resolving types
- [XmlArrayItem("Namespace")]
- public string[] NamespacePath;
-
- [XmlArrayItem("Type")]
- public string[] Inherits;
- [XmlArrayItem("Import")]
- public string[] Imports;
- [XmlArrayItem("Method")]
- public MethodRepTemplate[] Methods;
- [XmlArrayItem("Property")]
- public PropRepTemplate[] Properties;
- [XmlArrayItem("Field")]
- public FieldRepTemplate[] Fields;
- [XmlArrayItem("Cast")]
- public CastRepTemplate[] Casts;
-
- public TypeRepTemplate() : base()
- {
- // If these fields are not specified then these will be zero element arrays (rather than null)
- NamespacePath = new string[0];
- Inherits = new string[0];
- Imports = new string[0];
- Methods = new MethodRepTemplate[0];
- Properties = new PropRepTemplate[0];
- Fields = new FieldRepTemplate[0];
- Casts = new CastRepTemplate[0];
- }
-
- protected TypeRepTemplate(string typeName)
- : this()
- {
- TypeName = typeName;
- }
-
- protected TypeRepTemplate(string tName, string[] usePath, string[] inherits,
- MethodRepTemplate[] ms, PropRepTemplate[] ps, FieldRepTemplate[] fs,
- CastRepTemplate[] cs,
- string[] imps, string javaTemplate)
- : base()
- {
- TypeName = tName;
- NamespacePath = usePath;
- Inherits = inherits;
- Methods = ms;
- Properties = ps;
- Fields = fs;
- Imports = imps;
- Casts = cs;
- Java = javaTemplate;
- }
-
- private static object Deserialize(Stream fs, System.Type t)
- {
- object o = null;
-
- XmlSerializer serializer = new XmlSerializer(t);
- o = serializer.Deserialize(fs);
- return o;
- }
-
-
- private static TypeRepTemplate Deserialize(Stream s)
- {
- TypeRepTemplate ret = null;
- XmlTextReader reader = new XmlTextReader(s);
- string typeType = null; // class, interface, enum, etc.
- bool found = false;
-
- try
- {
- while (reader.Read() && !found)
- {
- if (reader.NodeType == XmlNodeType.Element)
- {
- switch (reader.LocalName)
- {
- case "Class":
- typeType = "RusticiSoftware.Translator.CLR.ClassRepTemplate";
- break;
- case "Interface":
- typeType = "RusticiSoftware.Translator.CLR.InterfaceRepTemplate";
- break;
- case "Enum":
- typeType = "RusticiSoftware.Translator.CLR.EnumRepTemplate";
- break;
- default:
- typeType = "UnknownType";
- break;
- }
- found = true;
- }
- }
- s.Seek(0, SeekOrigin.Begin);
- ret = (TypeRepTemplate)Deserialize(s, System.Type.GetType(typeType));
- }
- catch (Exception e)
- {
- Console.WriteLine("WARNING -- (Deserialize) " + e.Message);
- }
-
- return ret;
- }
-
-
- public static TypeRepTemplate newInstance(Stream s)
- {
- return (TypeRepTemplate)Deserialize(s);
- }
-
- // Useful because it builds either an empty ClassRep or InterfaceRep or ...
- public abstract TypeRep mkEmptyRep();
- }
-
- [XmlType("Class")]
- public class ClassRepTemplate : TypeRepTemplate
- {
-
- [XmlArrayItem("Constructor")]
- public ConstructorRepTemplate[] Constructors = new ConstructorRepTemplate[0];
-
- public ClassRepTemplate()
- {
- }
-
- public ClassRepTemplate(string typeName) : base(typeName)
- {
- }
-
- public ClassRepTemplate(string tName, string[] usePath, string[] inherits,
- ConstructorRepTemplate[] cs,
- MethodRepTemplate[] ms, PropRepTemplate[] ps, FieldRepTemplate[] fs,
- CastRepTemplate[] cts,
- string[] imps, string javaTemplate)
- : base(tName, usePath, inherits, ms, ps, fs, cts, imps, javaTemplate)
- {
- Constructors = cs;
- }
-
- public ClassRepTemplate(string tName, string[] usePath, string[] inherits,
- ConstructorRepTemplate[] cs,
- MethodRepTemplate[] ms, PropRepTemplate[] ps, FieldRepTemplate[] fs, CastRepTemplate[] cts)
- : base(tName, usePath, inherits, ms, ps, fs, cts, new String[0], null)
- {
- Constructors = cs;
- }
-
- public override TypeRep mkEmptyRep()
- {
- return new ClassRep();
- }
-
-
- }
-
- [XmlType("Interface")]
- public class InterfaceRepTemplate : TypeRepTemplate
- {
- public InterfaceRepTemplate()
- { }
-
- public InterfaceRepTemplate(string typeName)
- : base(typeName)
- {
- }
-
- public InterfaceRepTemplate(string tName, string[] usePath, string[] inherits,
- MethodRepTemplate[] ms, PropRepTemplate[] ps, FieldRepTemplate[] fs,
- CastRepTemplate[] cts,
- string[] imps, string javaTemplate)
- : base(tName, usePath, inherits, ms, ps, fs, cts, imps, javaTemplate)
- { }
-
- public override TypeRep mkEmptyRep()
- {
- return new InterfaceRep();
- }
- }
-
- [XmlType("Enum")]
- public class EnumRepTemplate : TypeRepTemplate
- {
- public EnumRepTemplate()
- { }
-
- public EnumRepTemplate(string typeName)
- : base(typeName)
- {
- }
-
- public EnumRepTemplate(string tName, string[] usePath, string[] inherits,
- MethodRepTemplate[] ms, PropRepTemplate[] ps, FieldRepTemplate[] fs,
- CastRepTemplate[] cts,
- string[] imps, string javaTemplate)
- : base(tName, usePath, inherits, ms, ps, fs, cts, imps, javaTemplate)
- { }
-
- public override TypeRep mkEmptyRep()
- {
- return new EnumRep();
- }
- }
-
- [XmlType("Struct")]
- public class StructRepTemplate : ClassRepTemplate
- {
-
- public StructRepTemplate()
- {
- }
-
- public StructRepTemplate(string typeName) : base(typeName)
- {
- }
-
- public StructRepTemplate(string tName, string[] usePath, string[] inherits,
- ConstructorRepTemplate[] cs,
- MethodRepTemplate[] ms, PropRepTemplate[] ps, FieldRepTemplate[] fs,
- CastRepTemplate[] cts,
- string[] imps, string javaTemplate)
- : base(tName, usePath, inherits, cs, ms, ps, fs, cts, imps, javaTemplate)
- {
- }
-
- public StructRepTemplate(string tName, string[] usePath, string[] inherits,
- ConstructorRepTemplate[] cs,
- MethodRepTemplate[] ms, PropRepTemplate[] ps, FieldRepTemplate[] fs, CastRepTemplate[] cts)
- : base(tName, usePath, inherits, cs, ms, ps, fs, cts, new String[0], null)
- {
- }
-
- public override TypeRep mkEmptyRep()
- {
- return new StructRep();
- }
-
- }
-
+ // Simple pairs to represent formal parameters
+ public class ParamRepTemplate : IEquatable
+ {
+ public string Type { get; set; }
+ public string Name { get; set; }
+
+ public ParamRepTemplate ()
+ {
+ }
+
+ public ParamRepTemplate (string t, string a)
+ {
+ Type = t;
+ Name = a;
+ }
+
+ #region Equality
+ public bool Equals (ParamRepTemplate other)
+ {
+ if (other == null)
+ return false;
+
+ return Type == other.Type && Name == other.Name;
+ }
+
+ public override bool Equals (object obj)
+ {
+
+ ParamRepTemplate temp = obj as ParamRepTemplate;
+
+ if (!Object.ReferenceEquals (temp, null))
+ return this.Equals (temp);
+ return false;
+ }
+
+ public static bool operator == (ParamRepTemplate a1, ParamRepTemplate a2)
+ {
+ return Object.Equals (a1, a2);
+ }
+
+ public static bool operator != (ParamRepTemplate a1, ParamRepTemplate a2)
+ {
+ return !(a1 == a2);
+ }
+
+ public override int GetHashCode ()
+ {
+ return (Type ?? String.Empty).GetHashCode () ^ (Name ?? String.Empty).GetHashCode ();
+ }
+ #endregion
+ }
+
+ // A use entry. An optional alias and a fully qualified namespace
+ public class UseRepTemplate : IEquatable
+ {
+
+ public string Alias { get; set; }
+ public string Namespace { get; set; }
+
+
+ public UseRepTemplate () : this(null)
+ {
+ }
+
+ public UseRepTemplate (string u) : this(null, u)
+ {
+ }
+
+ public UseRepTemplate (string a, string u)
+ {
+ Alias = a;
+ Namespace = u;
+ }
+
+ #region Equality
+ public bool Equals (UseRepTemplate other)
+ {
+ if (other == null)
+ return false;
+
+ return Alias == other.Alias && Namespace == other.Namespace;
+ }
+
+ public override bool Equals (object obj)
+ {
+
+ UseRepTemplate temp = obj as UseRepTemplate;
+
+ if (!Object.ReferenceEquals (temp, null))
+ return this.Equals (temp);
+ return false;
+ }
+
+ public static bool operator == (UseRepTemplate a1, UseRepTemplate a2)
+ {
+ return Object.Equals (a1, a2);
+ }
+
+ public static bool operator != (UseRepTemplate a1, UseRepTemplate a2)
+ {
+ return !(a1 == a2);
+ }
+
+ public override int GetHashCode ()
+ {
+ return (Alias ?? String.Empty).GetHashCode () ^ (Namespace ?? String.Empty).GetHashCode ();
+ }
+ #endregion
+
+ }
+
+
+ // Never directly create a TranslationBase. Its a common root for translatable language entities
+ public abstract class TranslationBase : IEquatable
+ {
+ [XmlArrayItem("Import")]
+ // Java imports required to make Java translation run
+ public string[] Imports { get; set; }
+ // The Java translation for this C# entity
+ public string Java { get; set; }
+
+ protected TranslationBase ()
+ {
+ Imports = null;
+ Java = null;
+ }
+
+ protected TranslationBase (string java)
+ {
+ Imports = null;
+ Java = java;
+ }
+
+ protected TranslationBase (string[] imps, string java)
+ {
+ Imports = imps;
+ Java = java;
+ }
+
+ #region Equality
+
+ public bool Equals (TranslationBase other)
+ {
+ if (other == null)
+ return false;
+
+ if (Imports != other.Imports) {
+ if (Imports == null || other.Imports == null || Imports.Length != other.Imports.Length)
+ return false;
+ for (int i = 0; i < Imports.Length; i++) {
+ if (Imports[i] != other.Imports[i])
+ return false;
+ }
+ }
+
+ return Java == other.Java;
+ }
+
+ public override bool Equals (object obj)
+ {
+
+ TranslationBase temp = obj as TranslationBase;
+
+ if (!Object.ReferenceEquals (temp, null))
+ return this.Equals (temp);
+ return false;
+ }
+
+ public static bool operator == (TranslationBase a1, TranslationBase a2)
+ {
+ return Object.Equals (a1, a2);
+ }
+
+ public static bool operator != (TranslationBase a1, TranslationBase a2)
+ {
+ return !(a1 == a2);
+ }
+
+ public override int GetHashCode ()
+ {
+ int hashCode = 0;
+ if (Imports != null) {
+ foreach (string e in Imports) {
+ hashCode ^= e.GetHashCode();
+ }
+ }
+ return (Java ?? String.Empty).GetHashCode () ^ hashCode;
+ }
+ #endregion
+
+ }
+
+
+ public class ConstructorRepTemplate : TranslationBase, IEquatable
+ {
+
+ private List _params = null;
+ [XmlArrayItem("Param")]
+ public List Params {
+ get {
+ if (_params == null)
+ _params = new List ();
+ return _params;
+ }
+ }
+
+ public ConstructorRepTemplate () : base()
+ {
+ }
+
+ public ConstructorRepTemplate (List pars) : base()
+ {
+ _params = pars;
+ }
+
+ public ConstructorRepTemplate (List pars, string[] imps, string javaRep) : base(imps, javaRep)
+ {
+ _params = pars;
+ }
+
+
+ #region Equality
+
+ public bool Equals (ConstructorRepTemplate other)
+ {
+ if (other == null)
+ return false;
+
+ if (Params != other.Params) {
+ if (Params == null || other.Params == null || Params.Count != other.Params.Count)
+ return false;
+ for (int i = 0; i < Params.Count; i++) {
+ if (Params[i] != other.Params[i])
+ return false;
+ }
+ }
+
+ return base.Equals(other);
+ }
+
+ public override bool Equals (object obj)
+ {
+
+ ConstructorRepTemplate temp = obj as ConstructorRepTemplate;
+
+ if (!Object.ReferenceEquals (temp, null))
+ return this.Equals (temp);
+ return false;
+ }
+
+ public static bool operator == (ConstructorRepTemplate a1, ConstructorRepTemplate a2)
+ {
+ return Object.Equals (a1, a2);
+ }
+
+ public static bool operator != (ConstructorRepTemplate a1, ConstructorRepTemplate a2)
+ {
+ return !(a1 == a2);
+ }
+
+ public override int GetHashCode ()
+ {
+ int hashCode = 0;
+ foreach (ParamRepTemplate o in Params) {
+ hashCode = hashCode ^ o.GetHashCode() ;
+ }
+
+ return base.GetHashCode () ^ hashCode;
+ }
+ #endregion
+ }
+
+ // Method has the same info as a delegate as a constructor plus a name and return type
+ public class MethodRepTemplate : ConstructorRepTemplate, IEquatable
+ {
+ // Method name
+ public string Name { get; set; }
+
+ // Return type
+ public string Return { get; set; }
+
+ public MethodRepTemplate ()
+ {
+ }
+
+ public MethodRepTemplate (string retType, string methodName, List pars, string[] imps, string javaRep) : base(pars, imps, javaRep)
+ {
+ Name = methodName;
+ Return = retType;
+ }
+
+ public MethodRepTemplate (string retType, string methodName, List pars) : this(retType, methodName, pars, null, null)
+ {
+ }
+
+ #region Equality
+ public bool Equals (MethodRepTemplate other)
+ {
+ if (other == null)
+ return false;
+
+ return Return == other.Return && Name == other.Name && base.Equals(other);
+ }
+
+ public override bool Equals (object obj)
+ {
+
+ MethodRepTemplate temp = obj as MethodRepTemplate;
+
+ if (!Object.ReferenceEquals (temp, null))
+ return this.Equals (temp);
+ return false;
+ }
+
+ public static bool operator == (MethodRepTemplate a1, MethodRepTemplate a2)
+ {
+ return Object.Equals (a1, a2);
+ }
+
+ public static bool operator != (MethodRepTemplate a1, MethodRepTemplate a2)
+ {
+ return !(a1 == a2);
+ }
+
+ public override int GetHashCode ()
+ {
+ return (Return ?? String.Empty).GetHashCode () ^ (Name ?? String.Empty).GetHashCode () ^ base.GetHashCode();
+ }
+ #endregion
+
+ }
+
+ // A user-defined cast from one type to another
+ public class CastRepTemplate : TranslationBase, IEquatable
+ {
+ // From and To are fully qualified types
+ public string From { get; set; }
+ public string To { get; set; }
+
+ public CastRepTemplate () : base()
+ {
+ }
+
+ public CastRepTemplate (string fType, string tType, string[] imps, string java) : base(imps, java)
+ {
+ From = fType;
+ To = tType;
+ }
+
+ public CastRepTemplate (string fType, string tType) : this(fType, tType, null, null)
+ {
+ }
+
+ #region Equality
+ public bool Equals (CastRepTemplate other)
+ {
+ if (other == null)
+ return false;
+
+ return From == other.From && To == other.To && base.Equals(other);
+ }
+
+ public override bool Equals (object obj)
+ {
+
+ CastRepTemplate temp = obj as CastRepTemplate;
+
+ if (!Object.ReferenceEquals (temp, null))
+ return this.Equals (temp);
+ return false;
+ }
+
+ public static bool operator == (CastRepTemplate a1, CastRepTemplate a2)
+ {
+ return Object.Equals (a1, a2);
+ }
+
+ public static bool operator != (CastRepTemplate a1, CastRepTemplate a2)
+ {
+ return !(a1 == a2);
+ }
+
+ public override int GetHashCode ()
+ {
+ return (From ?? String.Empty).GetHashCode() ^ (To ?? String.Empty).GetHashCode() ^ base.GetHashCode();
+ }
+ #endregion
+
+ }
+
+ // A member field definition
+ public class FieldRepTemplate : TranslationBase, IEquatable
+ {
+
+ public string Type { get; set; }
+ public string Name { get; set; }
+
+ public FieldRepTemplate () : base()
+ {
+ }
+
+ public FieldRepTemplate (string fType, string fName, string[] imps, string javaGet) : base(imps, javaGet)
+ {
+ Type = fType;
+ Name = fName;
+ }
+
+ public FieldRepTemplate (string fType, string fName) : this(fType, fName, null, null)
+ {
+ }
+
+ #region Equality
+ public bool Equals (FieldRepTemplate other)
+ {
+ if (other == null)
+ return false;
+
+ return Type == other.Type && Name == other.Name && base.Equals(other);
+ }
+
+ public override bool Equals (object obj)
+ {
+
+ FieldRepTemplate temp = obj as FieldRepTemplate;
+
+ if (!Object.ReferenceEquals (temp, null))
+ return this.Equals (temp);
+ return false;
+ }
+
+ public static bool operator == (FieldRepTemplate a1, FieldRepTemplate a2)
+ {
+ return Object.Equals (a1, a2);
+ }
+
+ public static bool operator != (FieldRepTemplate a1, FieldRepTemplate a2)
+ {
+ return !(a1 == a2);
+ }
+
+ public override int GetHashCode ()
+ {
+ return (Type ?? String.Empty).GetHashCode() ^ (Name ?? String.Empty).GetHashCode() ^ base.GetHashCode();
+ }
+ #endregion
+
+ }
+
+ // A property definition. We need separate java translations for getter and setter. If JavaGet is null
+ // then we can use Java (from TranslationBase) as the translation for gets.
+ // Imports are shared between getter and setter (might lead to some unneccessary extra imports, but I'm
+ // guessing that normally imports will be the same for both)
+ public class PropRepTemplate : FieldRepTemplate, IEquatable
+ {
+ public string JavaSet { get; set; }
+ private string _javaGet = null;
+ public string JavaGet {
+ get { return _javaGet ?? Java; }
+ set { _javaGet = value; }
+ }
+
+ public PropRepTemplate () : base()
+ {
+ }
+
+ public PropRepTemplate (string fType, string fName, string[] imps, string javaGet, string javaSet) : base(fType, fName, imps, null)
+ {
+ JavaGet = javaGet;
+ JavaSet = javaSet;
+ }
+
+ public PropRepTemplate (string fType, string fName) : this(fType, fName, null, null, null)
+ {
+ }
+
+
+ #region Equality
+ public bool Equals (PropRepTemplate other)
+ {
+ if (other == null)
+ return false;
+
+ return JavaGet == other.JavaGet && JavaSet == other.JavaSet && base.Equals(other);
+ }
+
+ public override bool Equals (object obj)
+ {
+
+ PropRepTemplate temp = obj as PropRepTemplate;
+
+ if (!Object.ReferenceEquals (temp, null))
+ return this.Equals (temp);
+ return false;
+ }
+
+ public static bool operator == (PropRepTemplate a1, PropRepTemplate a2)
+ {
+ return Object.Equals (a1, a2);
+ }
+
+ public static bool operator != (PropRepTemplate a1, PropRepTemplate a2)
+ {
+ return !(a1 == a2);
+ }
+
+ public override int GetHashCode ()
+ {
+ return (JavaGet ?? String.Empty).GetHashCode () ^ (JavaSet ?? String.Empty).GetHashCode () ^ base.GetHashCode ();
+ }
+ #endregion
+ }
+
+ // A member of an enum, may also have a numeric value
+ public class EnumMemberRepTemplate : TranslationBase, IEquatable
+ {
+
+ public string Name { get; set; }
+ public string Value { get; set; }
+
+
+ public EnumMemberRepTemplate () : this(null)
+ {
+ }
+
+ public EnumMemberRepTemplate (string n) : this(n, null, null, null)
+ {
+ }
+
+ public EnumMemberRepTemplate (string n, string v) : this(n, v, null, null)
+ {
+ }
+
+ public EnumMemberRepTemplate (string n, string v, string[] imps, string java) : base(imps, java)
+ {
+ Name = n;
+ Value = v;
+ }
+
+ #region Equality
+ public bool Equals (EnumMemberRepTemplate other)
+ {
+ if (other == null)
+ return false;
+
+ return Name == other.Name && Value == other.Value && base.Equals(other);
+ }
+
+ public override bool Equals (object obj)
+ {
+
+ EnumMemberRepTemplate temp = obj as EnumMemberRepTemplate;
+
+ if (!Object.ReferenceEquals (temp, null))
+ return this.Equals (temp);
+ return false;
+ }
+
+ public static bool operator == (EnumMemberRepTemplate a1, EnumMemberRepTemplate a2)
+ {
+ return Object.Equals (a1, a2);
+ }
+
+ public static bool operator != (EnumMemberRepTemplate a1, EnumMemberRepTemplate a2)
+ {
+ return !(a1 == a2);
+ }
+
+ public override int GetHashCode ()
+ {
+ return (Name ?? String.Empty).GetHashCode () ^ (Value ?? String.Empty).GetHashCode () ^ base.GetHashCode ();
+ }
+ #endregion
+
+ }
+
+
+
+ // Base Template for classes, interfaces, enums, etc.
+ [Serializable]
+ public abstract class TypeRepTemplate : TranslationBase, IEquatable
+ {
+ // Type Name
+ [XmlElementAttribute("Name")]
+ public string TypeName { get; set; }
+
+ // Path to use when resolving types
+ [XmlElementAttribute("Use")]
+ public UseRepTemplate[] Uses { get; set; }
+
+ public TypeRepTemplate () : base()
+ {
+ TypeName = null;
+ Uses = null;
+
+ }
+
+ protected TypeRepTemplate (string typeName) : this()
+ {
+ TypeName = typeName;
+ }
+
+ protected TypeRepTemplate (string tName, UseRepTemplate[] usePath, string[] imports, string javaTemplate) : base(imports, javaTemplate)
+ {
+ TypeName = tName;
+ Uses = usePath;
+ }
+
+ private static object Deserialize (Stream fs, System.Type t)
+ {
+ object o = null;
+
+ XmlSerializer serializer = new XmlSerializer (t, Constants.TranslationTemplateNamespace);
+ o = serializer.Deserialize (fs);
+ return o;
+ }
+
+
+ private static TypeRepTemplate Deserialize (Stream s)
+ {
+ TypeRepTemplate ret = null;
+
+ XmlReaderSettings settings = new XmlReaderSettings ();
+ settings.IgnoreWhitespace = true;
+ settings.IgnoreComments = true;
+ XmlReader reader = XmlReader.Create (s, settings);
+
+ //XmlTextReader reader = new XmlTextReader(s);
+ string typeType = null;
+ // class, interface, enum, etc.
+ bool found = false;
+
+ try {
+ while (reader.Read () && !found) {
+ if (reader.NodeType == XmlNodeType.Element) {
+ switch (reader.LocalName) {
+ case "Class":
+ typeType = "RusticiSoftware.Translator.CLR.ClassRepTemplate";
+ break;
+ case "Struct":
+ typeType = "RusticiSoftware.Translator.CLR.StructRepTemplate";
+ break;
+ case "Interface":
+ typeType = "RusticiSoftware.Translator.CLR.InterfaceRepTemplate";
+ break;
+ case "Enum":
+ typeType = "RusticiSoftware.Translator.CLR.EnumRepTemplate";
+ break;
+ case "Delegate":
+ typeType = "RusticiSoftware.Translator.CLR.DelegateRepTemplate";
+ break;
+ default:
+ typeType = "UnknownType";
+ break;
+ }
+ found = true;
+ }
+ }
+ s.Seek (0, SeekOrigin.Begin);
+ ret = (TypeRepTemplate)Deserialize (s, System.Type.GetType (typeType));
+ } catch (Exception e) {
+ Console.WriteLine ("WARNING -- (Deserialize) " + e.Message);
+ }
+
+ return ret;
+ }
+
+
+ public static TypeRepTemplate newInstance (Stream s)
+ {
+ return (TypeRepTemplate)Deserialize (s);
+ }
+
+ // Useful because it builds either an empty ClassRep or InterfaceRep or ...
+ public abstract TypeRep mkEmptyRep ();
+
+ #region Equality
+ public bool Equals (TypeRepTemplate other)
+ {
+ if (other == null)
+ return false;
+
+ if (Uses != other.Uses) {
+ if (Uses == null || other.Uses == null || Uses.Length != other.Uses.Length)
+ return false;
+ for (int i = 0; i < Uses.Length; i++) {
+ if (Uses[i] != other.Uses[i])
+ return false;
+ }
+ }
+
+ return TypeName == other.TypeName && base.Equals(other);
+ }
+
+ public override bool Equals (object obj)
+ {
+
+ TypeRepTemplate temp = obj as TypeRepTemplate;
+
+ if (!Object.ReferenceEquals (temp, null))
+ return this.Equals (temp);
+ return false;
+ }
+
+ public static bool operator == (TypeRepTemplate a1, TypeRepTemplate a2)
+ {
+ return Object.Equals (a1, a2);
+ }
+
+ public static bool operator != (TypeRepTemplate a1, TypeRepTemplate a2)
+ {
+ return !(a1 == a2);
+ }
+
+ public override int GetHashCode ()
+ {
+ int hashCode = base.GetHashCode ();
+ if (Uses != null) {
+ foreach (UseRepTemplate e in Uses) {
+ hashCode ^= e.GetHashCode();
+ }
+ }
+ return (Java ?? String.Empty).GetHashCode () ^ hashCode;
+ }
+ #endregion
+
+ }
+
+ [XmlType("Enum")]
+ public class EnumRepTemplate : TypeRepTemplate, IEquatable
+ {
+ private List _members = null;
+ [XmlArrayItem("Member")]
+ public List Members {
+ get {
+ if (_members == null)
+ _members = new List ();
+ return _members;
+ }
+ }
+
+ public EnumRepTemplate () : base()
+ {
+ }
+
+ public EnumRepTemplate (List ms) : base()
+ {
+ _members = ms;
+ }
+
+ public override TypeRep mkEmptyRep ()
+ {
+ return new EnumRep ();
+ }
+
+ #region Equality
+ public bool Equals (EnumRepTemplate other)
+ {
+ if (other == null)
+ return false;
+
+ if (Members != other.Members) {
+ if (Members == null || other.Members == null || Members.Count != other.Members.Count)
+ return false;
+ for (int i = 0; i < Members.Count; i++) {
+ if (Members[i] != other.Members[i])
+ return false;
+ }
+ }
+
+ return base.Equals(other);
+ }
+
+ public override bool Equals (object obj)
+ {
+
+ EnumRepTemplate temp = obj as EnumRepTemplate;
+
+ if (!Object.ReferenceEquals (temp, null))
+ return this.Equals (temp);
+ return false;
+ }
+
+ public static bool operator == (EnumRepTemplate a1, EnumRepTemplate a2)
+ {
+ return Object.Equals (a1, a2);
+ }
+
+ public static bool operator != (EnumRepTemplate a1, EnumRepTemplate a2)
+ {
+ return !(a1 == a2);
+ }
+
+ public override int GetHashCode ()
+ {
+ int hashCode = base.GetHashCode ();
+ if (Members != null) {
+ foreach (EnumMemberRepTemplate e in Members) {
+ hashCode ^= e.GetHashCode();
+ }
+ }
+ return hashCode;
+ }
+ #endregion
+ }
+
+ [XmlType("Delegate")]
+ public class DelegateRepTemplate : TypeRepTemplate, IEquatable
+ {
+ private List _params = null;
+ [XmlArrayItem("Param")]
+ public List Params {
+ get {
+ if (_params == null)
+ _params = new List ();
+ return _params;
+ }
+ }
+
+ public string Return {get; set;}
+
+ public DelegateRepTemplate () : base()
+ {
+ }
+
+ public DelegateRepTemplate (string retType, List args) : base()
+ {
+ Return = retType;
+ _params = args;
+ }
+
+ public override TypeRep mkEmptyRep ()
+ {
+ return new DelegateRep ();
+ }
+
+ #region Equality
+ public bool Equals (DelegateRepTemplate other)
+ {
+ if (other == null)
+ return false;
+
+ if (Params != other.Params) {
+ if (Params == null || other.Params == null || Params.Count != other.Params.Count)
+ return false;
+ for (int i = 0; i < Params.Count; i++) {
+ if (Params[i] != other.Params[i])
+ return false;
+ }
+ }
+
+ return Return == other.Return && base.Equals(other);
+ }
+
+ public override bool Equals (object obj)
+ {
+
+ DelegateRepTemplate temp = obj as DelegateRepTemplate;
+
+ if (!Object.ReferenceEquals (temp, null))
+ return this.Equals (temp);
+ return false;
+ }
+
+ public static bool operator == (DelegateRepTemplate a1, DelegateRepTemplate a2)
+ {
+ return Object.Equals (a1, a2);
+ }
+
+ public static bool operator != (DelegateRepTemplate a1, DelegateRepTemplate a2)
+ {
+ return !(a1 == a2);
+ }
+
+ public override int GetHashCode ()
+ {
+ int hashCode = base.GetHashCode ();
+ if (Params != null) {
+ foreach (ParamRepTemplate e in Params) {
+ hashCode ^= e.GetHashCode();
+ }
+ }
+ return (Return ?? String.Empty).GetHashCode() ^ hashCode;
+ }
+ #endregion
+ }
+
+ // Base Template for classes, interfaces, etc.
+ [XmlType("Interface")]
+ public class InterfaceRepTemplate : TypeRepTemplate, IEquatable
+ {
+
+
+ [XmlArrayItem("Type")]
+ public string[] Inherits { get; set; }
+
+ private List _methods = null;
+ [XmlArrayItem("Method")]
+ public List Methods {
+ get {
+ if (_methods == null)
+ _methods = new List ();
+ return _methods;
+ }
+ }
+
+ private List _properties = null;
+ [XmlArrayItem("Property")]
+ public List Properties {
+ get {
+ if (_properties == null)
+ _properties = new List ();
+ return _properties;
+ }
+ }
+
+ private List _events = null;
+ [XmlArrayItem("Event")]
+ public List Events {
+ get {
+ if (_events == null)
+ _events = new List ();
+ return _events;
+ }
+ }
+
+ private List _indexers = null;
+ [XmlArrayItem("Indexer")]
+ public List Indexers {
+ get {
+ if (_indexers == null)
+ _indexers = new List ();
+ return _indexers;
+ }
+ }
+
+ public InterfaceRepTemplate () : base()
+ {
+ Inherits = null;
+ }
+
+ public InterfaceRepTemplate (string typeName) : base(typeName)
+ {
+ }
+
+ protected InterfaceRepTemplate (string tName, UseRepTemplate[] usePath, string[] inherits, List ms, List ps, List es, List ixs, string[] imps, string javaTemplate) : base(tName, usePath, imps, javaTemplate)
+ {
+ Inherits = inherits;
+ _methods = ms;
+ _properties = ps;
+ _events = es;
+ _indexers = ixs;
+ }
+
+ public override TypeRep mkEmptyRep ()
+ {
+ return new InterfaceRep ();
+ }
+
+ #region Equality
+ public bool Equals (InterfaceRepTemplate other)
+ {
+ if (other == null)
+ return false;
+
+ if (Inherits != other.Inherits) {
+ if (Inherits == null || other.Inherits == null || Inherits.Length != other.Inherits.Length)
+ return false;
+ for (int i = 0; i < Inherits.Length; i++) {
+ if (Inherits[i] != other.Inherits[i])
+ return false;
+ }
+ }
+
+ if (Methods != other.Methods) {
+ if (Methods == null || other.Methods == null || Methods.Count != other.Methods.Count)
+ return false;
+ for (int i = 0; i < Methods.Count; i++) {
+ if (Methods[i] != other.Methods[i])
+ return false;
+ }
+ }
+
+ if (Properties != other.Properties) {
+ if (Properties == null || other.Properties == null || Properties.Count != other.Properties.Count)
+ return false;
+ for (int i = 0; i < Properties.Count; i++) {
+ if (Properties[i] != other.Properties[i])
+ return false;
+ }
+ }
+
+ if (Events != other.Events) {
+ if (Events == null || other.Events == null || Events.Count != other.Events.Count)
+ return false;
+ for (int i = 0; i < Events.Count; i++) {
+ if (Events[i] != other.Events[i])
+ return false;
+ }
+ }
+
+ if (Indexers != other.Indexers) {
+ if (Indexers == null || other.Indexers == null || Indexers.Count != other.Indexers.Count)
+ return false;
+ for (int i = 0; i < Indexers.Count; i++) {
+ if (Indexers[i] != other.Indexers[i])
+ return false;
+ }
+ }
+
+ return base.Equals(other);
+ }
+
+ public override bool Equals (object obj)
+ {
+
+ InterfaceRepTemplate temp = obj as InterfaceRepTemplate;
+
+ if (!Object.ReferenceEquals (temp, null))
+ return this.Equals (temp);
+ return false;
+ }
+
+ public static bool operator == (InterfaceRepTemplate a1, InterfaceRepTemplate a2)
+ {
+ return Object.Equals (a1, a2);
+ }
+
+ public static bool operator != (InterfaceRepTemplate a1, InterfaceRepTemplate a2)
+ {
+ return !(a1 == a2);
+ }
+
+ public override int GetHashCode ()
+ {
+ int hashCode = base.GetHashCode ();
+ if (Inherits != null) {
+ foreach (string e in Inherits) {
+ hashCode ^= e.GetHashCode();
+ }
+ }
+ if (Methods != null) {
+ foreach (MethodRepTemplate e in Methods) {
+ hashCode ^= e.GetHashCode();
+ }
+ }
+ if (Properties != null) {
+ foreach (PropRepTemplate e in Properties) {
+ hashCode ^= e.GetHashCode();
+ }
+ }
+ if (Events != null) {
+ foreach (FieldRepTemplate e in Events) {
+ hashCode ^= e.GetHashCode();
+ }
+ }
+ if (Indexers != null) {
+ foreach (MethodRepTemplate e in Indexers) {
+ hashCode ^= e.GetHashCode();
+ }
+ }
+ return hashCode;
+ }
+ #endregion
+
+ }
+
+ [XmlType("Class")]
+ public class ClassRepTemplate : InterfaceRepTemplate, IEquatable
+ {
+
+ private List _constructors = null;
+ [XmlArrayItem("Constructor")]
+ public List Constructors {
+ get {
+ if (_constructors == null)
+ _constructors = new List ();
+ return _constructors;
+ }
+ }
+
+ private List _fields = null;
+ [XmlArrayItem("Field")]
+ public List Fields {
+ get {
+ if (_fields == null)
+ _fields = new List ();
+ return _fields;
+ }
+ }
+
+ // Cast here? or in InterfaceRepT?
+ private List _casts = null;
+ [XmlArrayItem("Cast")]
+ public List Casts {
+ get {
+ if (_casts == null)
+ _casts = new List ();
+ return _casts;
+ }
+ }
+
+ public ClassRepTemplate ()
+ {
+ }
+
+ public ClassRepTemplate (string typeName) : base(typeName)
+ {
+ }
+
+ public ClassRepTemplate (string tName, UseRepTemplate[] usePath, string[] inherits, List cs, List ms, List ps, List fs, List es, List ixs, List cts,
+ string[] imports, string javaTemplate) : base(tName, usePath, inherits, ms, ps, es, ixs, imports, javaTemplate)
+ {
+ _constructors = cs;
+ _fields = fs;
+ _casts = cts;
+ }
+
+ public ClassRepTemplate (string tName, UseRepTemplate[] usePath, string[] inherits, List cs, List ms, List ps, List fs, List es, List ixs, List cts) : base(tName, usePath, inherits, ms, ps, es, ixs, null, null)
+ {
+ _constructors = cs;
+ _fields = fs;
+ _casts = cts;
+ }
+
+ public override TypeRep mkEmptyRep ()
+ {
+ return new ClassRep ();
+ }
+
+ #region Equality
+ public bool Equals (ClassRepTemplate other)
+ {
+ if (other == null)
+ return false;
+
+ if (Constructors != other.Constructors) {
+ if (Constructors == null || other.Constructors == null || Constructors.Count != other.Constructors.Count)
+ return false;
+ for (int i = 0; i < Constructors.Count; i++) {
+ if (Constructors[i] != other.Constructors[i])
+ return false;
+ }
+ }
+
+ if (Fields != other.Fields) {
+ if (Fields == null || other.Fields == null || Fields.Count != other.Fields.Count)
+ return false;
+ for (int i = 0; i < Fields.Count; i++) {
+ if (Fields[i] != other.Fields[i])
+ return false;
+ }
+ }
+
+ if (Casts != other.Casts) {
+ if (Casts == null || other.Casts == null || Casts.Count != other.Casts.Count)
+ return false;
+ for (int i = 0; i < Casts.Count; i++) {
+ if (Casts[i] != other.Casts[i])
+ return false;
+ }
+ }
+
+ return base.Equals(other);
+ }
+
+ public override bool Equals (object obj)
+ {
+
+ ClassRepTemplate temp = obj as ClassRepTemplate;
+
+ if (!Object.ReferenceEquals (temp, null))
+ return this.Equals (temp);
+ return false;
+ }
+
+ public static bool operator == (ClassRepTemplate a1, ClassRepTemplate a2)
+ {
+ return Object.Equals (a1, a2);
+ }
+
+ public static bool operator != (ClassRepTemplate a1, ClassRepTemplate a2)
+ {
+ return !(a1 == a2);
+ }
+
+ public override int GetHashCode ()
+ {
+ int hashCode = base.GetHashCode ();
+ if (Constructors != null) {
+ foreach (ConstructorRepTemplate e in Constructors) {
+ hashCode ^= e.GetHashCode();
+ }
+ }
+ if (Fields != null) {
+ foreach (FieldRepTemplate e in Fields) {
+ hashCode ^= e.GetHashCode();
+ }
+ }
+ if (Casts != null) {
+ foreach (CastRepTemplate e in Casts) {
+ hashCode ^= e.GetHashCode();
+ }
+ }
+
+ return hashCode;
+ }
+ #endregion
+
+
+ }
+
+
+
+
+ [XmlType("Struct")]
+ public class StructRepTemplate : ClassRepTemplate, IEquatable
+ {
+
+ public StructRepTemplate ()
+ {
+ }
+
+ public StructRepTemplate (string typeName) : base(typeName)
+ {
+ }
+
+ public StructRepTemplate (string tName, UseRepTemplate[] usePath, string[] inherits, List cs, List ms, List ps, List fs, List es, List ixs, List cts,
+ string[] imports, string javaTemplate) : base(tName, usePath, inherits, cs, ms, ps, fs, es, ixs, cts,
+ imports, javaTemplate)
+ {
+ }
+
+ public StructRepTemplate (string tName, UseRepTemplate[] usePath, string[] inherits, List cs, List ms, List ps, List fs, List es, List ixs, List cts) : base(tName, usePath, inherits, cs, ms, ps, fs, es, ixs, cts,
+ null, null)
+ {
+ }
+
+ public override TypeRep mkEmptyRep ()
+ {
+ return new StructRep ();
+ }
+
+ #region Equality
+ public bool Equals (StructRepTemplate other)
+ {
+ return base.Equals(other);
+ }
+
+ public override bool Equals (object obj)
+ {
+
+ StructRepTemplate temp = obj as StructRepTemplate;
+
+ if (!Object.ReferenceEquals (temp, null))
+ return this.Equals (temp);
+ return false;
+ }
+
+ public static bool operator == (StructRepTemplate a1, StructRepTemplate a2)
+ {
+ return Object.Equals (a1, a2);
+ }
+
+ public static bool operator != (StructRepTemplate a1, StructRepTemplate a2)
+ {
+ return !(a1 == a2);
+ }
+
+ public override int GetHashCode ()
+ {
+ return base.GetHashCode ();
+ }
+ #endregion
+
+
+ }
}
diff --git a/CSharpTranslator/antlr3/src/cs2j/CLR/TypeRep.cs b/CSharpTranslator/antlr3/src/cs2j/CLR/TypeRep.cs
index 426db22..2926f3d 100644
--- a/CSharpTranslator/antlr3/src/cs2j/CLR/TypeRep.cs
+++ b/CSharpTranslator/antlr3/src/cs2j/CLR/TypeRep.cs
@@ -102,8 +102,8 @@ namespace RusticiSoftware.Translator.CLR
public ConstructorRep(ConstructorRepTemplate ct, ICollection pth)
{
- Params = new ParamRep[ct.Params.Length];
- for (int i = 0; i < ct.Params.Length; i++)
+ Params = new ParamRep[ct.Params.Count];
+ for (int i = 0; i < ct.Params.Count; i++)
{
Params[i] = ParamRep.newInstance(ct.Params[i], pth);
}
@@ -253,7 +253,7 @@ namespace RusticiSoftware.Translator.CLR
{
Name = ft.Name;
Type = TypeRep.newInstance(ft.Type, pth);
- Get = ft.Get;
+ Get = ft.Java;
Imports = new string[ft.Imports.Length];
for (int i = 0; i < ft.Imports.Length; i++)
{
@@ -274,7 +274,7 @@ namespace RusticiSoftware.Translator.CLR
public PropRep(PropRepTemplate pt, ICollection pth) : base(pt, pth)
{
- Set = pt.Set;
+ Set = pt.JavaSet;
}
@@ -387,11 +387,11 @@ namespace RusticiSoftware.Translator.CLR
public virtual void Build(TypeRepTemplate template)
{
- ICollection uPath = template.NamespacePath;
+ ICollection uPath = template.Uses;
TypeName = template.TypeName;
Java = template.Java;
-
+/*
Imports = new string[template.Imports.Length];
for (int i = 0; i < template.Imports.Length; i++)
{
@@ -448,7 +448,8 @@ namespace RusticiSoftware.Translator.CLR
ms.Add(new MethodRep(mt, uPath));
MethodsD[mt.Name] = ms;
}
- }
+ */
+ }
private static ClassRep newInstance(ClassRepTemplate template)
{
@@ -752,20 +753,20 @@ namespace RusticiSoftware.Translator.CLR
public ClassRep(ClassRepTemplate template)
: base(template)
{
- Constructors = new ConstructorRep[template.Constructors.Length];
- for (int i = 0; i < template.Constructors.Length; i++)
+ Constructors = new ConstructorRep[template.Constructors.Count];
+ for (int i = 0; i < template.Constructors.Count; i++)
{
- Constructors[i] = new ConstructorRep(template.Constructors[i], template.NamespacePath);
+ Constructors[i] = new ConstructorRep(template.Constructors[i], template.Uses);
}
}
public override void Build(TypeRepTemplate template)
{
ClassRepTemplate ctemp = (ClassRepTemplate)template;
- Constructors = new ConstructorRep[ctemp.Constructors.Length];
- for (int i = 0; i < ctemp.Constructors.Length; i++)
+ Constructors = new ConstructorRep[ctemp.Constructors.Count];
+ for (int i = 0; i < ctemp.Constructors.Count; i++)
{
- Constructors[i] = new ConstructorRep(ctemp.Constructors[i], ctemp.NamespacePath);
+ Constructors[i] = new ConstructorRep(ctemp.Constructors[i], ctemp.Uses);
}
base.Build(template);
@@ -846,18 +847,18 @@ namespace RusticiSoftware.Translator.CLR
public EnumRep(EnumRepTemplate template)
: base(template)
{
- int numfields = template.Fields.Length;
+ int numfields = template.Members.Count;
fieldsA = new string[numfields];
for (int i = 0; i < numfields; i++)
- fieldsA[i] = template.Fields[i].Name;
+ fieldsA[i] = template.Members[i].Name;
}
- public override void Build(TypeRepTemplate template)
+ public void Build(EnumRepTemplate template)
{
- int numfields = template.Fields.Length;
+ int numfields = template.Members.Count;
fieldsA = new string[numfields];
for (int i = 0; i < numfields; i++)
- fieldsA[i] = template.Fields[i].Name;
+ fieldsA[i] = template.Members[i].Name;
base.Build(template);
}
@@ -885,6 +886,30 @@ namespace RusticiSoftware.Translator.CLR
{
}
+ public override void Build(TypeRepTemplate template)
+ {
+ base.Build(template);
+ }
+ }
+
+ public class DelegateRep : TypeRep
+ {
+
+ public DelegateRep()
+ : base()
+ { }
+
+ // Dummy Delegate
+ public DelegateRep(string name)
+ : base(name)
+ {
+ }
+
+ public DelegateRep(DelegateRepTemplate template)
+ : base(template)
+ {
+ }
+
public override void Build(TypeRepTemplate template)
{
base.Build(template);
diff --git a/CSharpTranslator/antlr3/src/cs2j/CSharp/Main.cs b/CSharpTranslator/antlr3/src/cs2j/CSharp/Main.cs
index 6edd6a8..ec6959b 100644
--- a/CSharpTranslator/antlr3/src/cs2j/CSharp/Main.cs
+++ b/CSharpTranslator/antlr3/src/cs2j/CSharp/Main.cs
@@ -1,9 +1,9 @@
+using System;
+using Path = System.IO.Path;
+using Antlr.Runtime;
+
namespace RusticiSoftware.Translator.CSharp
{
- using System;
- using Path = System.IO.Path;
- using Antlr.Runtime;
-
public class Driver
{
public static void Main(string[] args)
diff --git a/CSharpTranslator/antlr3/src/cs2j/CSharp/minDriver.cs b/CSharpTranslator/antlr3/src/cs2j/CSharp/minDriver.cs
index ad3d263..368d0e0 100644
--- a/CSharpTranslator/antlr3/src/cs2j/CSharp/minDriver.cs
+++ b/CSharpTranslator/antlr3/src/cs2j/CSharp/minDriver.cs
@@ -14,7 +14,10 @@ namespace RusticiSoftware.Translator.CSharp
{
if (args.Length > 0)
{
- string inputFileName = args[1];
+
+ // Just take last argument so that we ignore any passed options
+
+ string inputFileName = args[args.Length - 1];
if (!Path.IsPathRooted(inputFileName))
{
inputFileName = Path.Combine(Environment.CurrentDirectory, inputFileName);
diff --git a/CSharpTranslator/antlr3/src/cs2j/Utils/Constants.cs b/CSharpTranslator/antlr3/src/cs2j/Utils/Constants.cs
new file mode 100644
index 0000000..538d964
--- /dev/null
+++ b/CSharpTranslator/antlr3/src/cs2j/Utils/Constants.cs
@@ -0,0 +1,9 @@
+using System;
+namespace RusticiSoftware.Translator.Utils
+{
+ public static class Constants
+ {
+ public const string TranslationTemplateNamespace="urn:www.twigletsoftware.com:schemas:txtemplate:1:0";
+ }
+}
+
diff --git a/CSharpTranslator/antlr3/src/cs2j/cs2j.csproj b/CSharpTranslator/antlr3/src/cs2j/cs2j.csproj
index b212167..e37a3b5 100644
--- a/CSharpTranslator/antlr3/src/cs2j/cs2j.csproj
+++ b/CSharpTranslator/antlr3/src/cs2j/cs2j.csproj
@@ -39,6 +39,7 @@
DEBUG;TRACE
prompt
4
+ -testdrive
pdbonly
@@ -63,6 +64,7 @@
+