1
0
mirror of https://github.com/twiglet/cs2j.git synced 2025-01-18 13:15:17 +01:00

Add extra translation steps to the pipeline to (eventually) produce Java

This commit is contained in:
Kevin Glynn 2010-11-07 21:57:24 +01:00
parent e4bd86900b
commit e914af9031
9 changed files with 3400 additions and 175 deletions

@ -5,6 +5,9 @@ set -e
cd src/cs2j/CSharp cd src/cs2j/CSharp
java -Xmx512m -jar ../../../jar/antlr-3.3.jar -make cs.g java -Xmx512m -jar ../../../jar/antlr-3.3.jar -make cs.g
java -Xmx512m -jar ../../../jar/antlr-3.3.jar -make TemplateExtracter.g java -Xmx512m -jar ../../../jar/antlr-3.3.jar -make TemplateExtracter.g
java -Xmx512m -jar ../../../jar/antlr-3.3.jar -make JavaMaker.g
java -Xmx512m -jar ../../../jar/antlr-3.3.jar -make NetMaker.g
java -Xmx512m -jar ../../../jar/antlr-3.3.jar -make JavaPrettyPrint.g
cd ../../../ cd ../../../
xbuild xbuild
echo 'All Done' echo 'All Done'

@ -236,6 +236,7 @@ namespace RusticiSoftware.Translator.CSharp
// Here's where we do the real work... // Here's where we do the real work...
public static void addAppSigTranslation(string fullName) public static void addAppSigTranslation(string fullName)
{ {
if (cfg.DebugLevel > 3) Console.Out.WriteLine("Extracting type info from file {0}", fullName); if (cfg.DebugLevel > 3) Console.Out.WriteLine("Extracting type info from file {0}", fullName);
ITreeNodeStream csTree = parseFile(fullName); ITreeNodeStream csTree = parseFile(fullName);
if (csTree != null) if (csTree != null)
@ -252,9 +253,41 @@ namespace RusticiSoftware.Translator.CSharp
// Here's where we do the real work... // Here's where we do the real work...
public static void translateFile(string fullName) public static void translateFile(string fullName)
{ {
long startTime = DateTime.Now.Ticks;
if (cfg.DebugLevel > 3) Console.Out.WriteLine("Translating file {0}", fullName); if (cfg.DebugLevel > 3) Console.Out.WriteLine("Translating file {0}", fullName);
CommonTreeNodeStream csTree = parseFile(fullName); ITreeNodeStream csTree = parseFile(fullName);
if (cfg.DumpCSharp && csTree != null) AntlrUtils.AntlrUtils.DumpNodes(csTree); if (cfg.DumpCSharp && csTree != null) AntlrUtils.AntlrUtils.DumpNodes((CommonTreeNodeStream)csTree);
if (csTree != null)
{
Dictionary<string, CommonTree> cus = new Dictionary<string, CommonTree>();
JavaMaker javaMaker = new JavaMaker(csTree);
javaMaker.Filename = fullName;
javaMaker.TraceDestination = Console.Error;
JavaMaker.compilation_unit_return java = javaMaker.compilation_unit(cfg, cus);
foreach (KeyValuePair<string, CommonTree> package in cus) {
CommonTreeNodeStream javaSyntaxNodes = new CommonTreeNodeStream(package.Value);
javaSyntaxNodes.TokenStream = csTree.TokenStream;
NetMaker netMaker = new NetMaker(javaSyntaxNodes);
netMaker.Filename = fullName;
netMaker.TraceDestination = Console.Error;
NetMaker.type_declaration_return javaCompilationUnit = netMaker.type_declaration();
CommonTreeNodeStream javaCompilationUnitNodes = new CommonTreeNodeStream(javaCompilationUnit.Tree);
javaCompilationUnitNodes.TokenStream = csTree.TokenStream;
JavaPrettyPrint outputMaker = new JavaPrettyPrint(javaCompilationUnitNodes);
outputMaker.Filename = fullName;
outputMaker.TraceDestination = Console.Error;
outputMaker.type_declaration();
}
// ITreeNodeStream javaTree = java.Tree;
}
// ASTNode t = parseFile(f, s); // ASTNode t = parseFile(f, s);
// if (t != null) // if (t != null)
@ -354,12 +387,11 @@ namespace RusticiSoftware.Translator.CSharp
// } // }
// double elapsedTime = ((DateTime.Now.Ticks - startTime) / TimeSpan.TicksPerMillisecond) / 1000.0; double elapsedTime = ((DateTime.Now.Ticks - startTime) / TimeSpan.TicksPerMillisecond) / 1000.0;
// //System.Console.Out.WriteLine(writer.ToString()); //System.Console.Out.WriteLine(writer.ToString());
// System.Console.Out.WriteLine(""); System.Console.Out.WriteLine("");
// System.Console.Out.WriteLine(""); System.Console.Out.WriteLine("");
// System.Console.Out.WriteLine("Pretty-printed {0} in: {1} seconds.", f, elapsedTime); System.Console.Out.WriteLine("Pretty-printed {0} in: {1} seconds.", fullName, elapsedTime);
// }
} }
} }
} }

@ -3,3 +3,9 @@ csLexer.cs
csParser.cs csParser.cs
TemplateExtracter.cs TemplateExtracter.cs
TemplateExtracter.tokens TemplateExtracter.tokens
NetMaker.cs
NetMaker.tokens
JavaMaker.cs
JavaMaker.tokens
JavaPrettyPrint.cs
JavaPrettyPrint.tokens

@ -45,5 +45,25 @@ namespace RusticiSoftware.Translator.CSharp
Console.Out.WriteLine(s); Console.Out.WriteLine(s);
} }
} }
// distinguish classes with same name, but differing numbers of type arguments
protected string mkTypeName (string name, List<String> tyargs) {
return name + (tyargs.Count > 0 ? "'" + tyargs.Count.ToString() : "");
}
protected string formatTyargs(List<string> tyargs) {
if (tyargs.Count == 0) {
return "";
}
StringBuilder buf = new StringBuilder();
buf.Append("<");
foreach (string t in tyargs) {
buf.Append(t + ",");
}
buf.Remove(buf.Length-1,1);
buf.Append(">");
return buf.ToString();
}
} }
} }

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -69,20 +69,6 @@ scope NSContext {
} }
} }
protected string formatTyargs(List<string> tyargs) {
if (tyargs.Count == 0) {
return "";
}
StringBuilder buf = new StringBuilder();
buf.Append("<");
foreach (string t in tyargs) {
buf.Append(t + ",");
}
buf.Remove(buf.Length-1,1);
buf.Append(">");
return buf.ToString();
}
} }
/******************************************************************************************** /********************************************************************************************
@ -672,10 +658,8 @@ scope NSContext;
{ {
Debug("Processing class: " + $type_or_generic.type); Debug("Processing class: " + $type_or_generic.type);
klass.Uses = this.NameSpaceContext; klass.Uses = this.NameSpaceContext;
klass.TypeName = this.ParentNameSpace + "." + $type_or_generic.type; klass.TypeName = this.ParentNameSpace + "." + mkTypeName($type_or_generic.type, $type_or_generic.generic_arguments);
if ($type_or_generic.generic_arguments.Count > 0) { if ($type_or_generic.generic_arguments.Count > 0) {
// distinguish classes with same name, but differing numbers of type arguments
klass.TypeName+= "'" + $type_or_generic.generic_arguments.Count.ToString();
klass.TypeParams = $type_or_generic.generic_arguments.ToArray(); klass.TypeParams = $type_or_generic.generic_arguments.ToArray();
} }
// Nested types can see things in this space // Nested types can see things in this space
@ -848,10 +832,8 @@ scope NSContext;
{ {
Debug("Processing delegate: " + $identifier.text); Debug("Processing delegate: " + $identifier.text);
dlegate.Uses = this.NameSpaceContext; dlegate.Uses = this.NameSpaceContext;
dlegate.TypeName = this.ParentNameSpace + "." + $identifier.text; dlegate.TypeName = this.ParentNameSpace + "." + mkTypeName($identifier.text, $variant_generic_parameter_list.tyargs);
if ($variant_generic_parameter_list.tyargs != null && $variant_generic_parameter_list.tyargs.Count > 0) { if ($variant_generic_parameter_list.tyargs != null && $variant_generic_parameter_list.tyargs.Count > 0) {
// distinguish classes with same name, but differing numbers of type arguments
dlegate.TypeName+= "'" + $variant_generic_parameter_list.tyargs.Count.ToString();
dlegate.TypeParams = $variant_generic_parameter_list.tyargs.ToArray(); dlegate.TypeParams = $variant_generic_parameter_list.tyargs.ToArray();
} }
dlegate.Return=$return_type.thetext; dlegate.Return=$return_type.thetext;
@ -938,10 +920,8 @@ scope NSContext;
{ {
Debug("Processing interface: " + $identifier.text); Debug("Processing interface: " + $identifier.text);
iface.Uses = this.NameSpaceContext; iface.Uses = this.NameSpaceContext;
iface.TypeName = this.ParentNameSpace + "." + $identifier.text; iface.TypeName = this.ParentNameSpace + "." + mkTypeName($identifier.text, $variant_generic_parameter_list.tyargs);
if ($variant_generic_parameter_list.tyargs != null && $variant_generic_parameter_list.tyargs.Count > 0) { if ($variant_generic_parameter_list.tyargs != null && $variant_generic_parameter_list.tyargs.Count > 0) {
// distinguish classes with same name, but differing numbers of type arguments
iface.TypeName+= "'" + $variant_generic_parameter_list.tyargs.Count.ToString();
iface.TypeParams = $variant_generic_parameter_list.tyargs.ToArray(); iface.TypeParams = $variant_generic_parameter_list.tyargs.ToArray();
} }
// Nested types can see things in this space // Nested types can see things in this space
@ -1024,10 +1004,8 @@ scope NSContext;
{ {
Debug("Processing struct: " + $type_or_generic.type); Debug("Processing struct: " + $type_or_generic.type);
strukt.Uses = this.NameSpaceContext; strukt.Uses = this.NameSpaceContext;
strukt.TypeName = this.ParentNameSpace + "." + $type_or_generic.type; strukt.TypeName = this.ParentNameSpace + "." + mkTypeName($type_or_generic.type, $type_or_generic.generic_arguments);
if ($type_or_generic.generic_arguments.Count > 0) { if ($type_or_generic.generic_arguments.Count > 0) {
// distinguish structs with same name, but differing numbers of type arguments
strukt.TypeName+= "'" + $type_or_generic.generic_arguments.Count.ToString();
strukt.TypeParams = $type_or_generic.generic_arguments.ToArray(); strukt.TypeParams = $type_or_generic.generic_arguments.ToArray();
} }
// Nested types can see things in this space // Nested types can see things in this space

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0"> <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<PropertyGroup> <PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@ -66,11 +66,17 @@
<Compile Include="Utils\TypeHelper.cs" /> <Compile Include="Utils\TypeHelper.cs" />
<Compile Include="CSharp\TemplateExtracter.cs" /> <Compile Include="CSharp\TemplateExtracter.cs" />
<Compile Include="CLR\CS2JSettings.cs" /> <Compile Include="CLR\CS2JSettings.cs" />
<Compile Include="CSharp\JavaMaker.cs" />
<Compile Include="CSharp\JavaPrettyPrint.cs" />
<Compile Include="CSharp\NetMaker.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="CSharp\csCrawl.g" /> <None Include="CSharp\csCrawl.g" />
<None Include="CSharp\cs.g" /> <None Include="CSharp\cs.g" />
<None Include="CSharp\TemplateExtracter.g" /> <None Include="CSharp\TemplateExtracter.g" />
<None Include="CSharp\JavaMaker.g" />
<None Include="CSharp\JavaPrettyPrint.g" />
<None Include="CSharp\NetMaker.g" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Content Include="README.txt" /> <Content Include="README.txt" />