mirror of
https://github.com/twiglet/cs2j.git
synced 2025-01-18 13:15:17 +01:00
(re)support --dump-enums
This commit is contained in:
parent
6e39b1688b
commit
8e9a6c4dd5
@ -33,7 +33,7 @@ namespace Twiglet.CS2J.Translator
|
|||||||
{
|
{
|
||||||
class CS2J
|
class CS2J
|
||||||
{
|
{
|
||||||
private const string VERSION = "2011.3.3rs";
|
private const string VERSION = "2012.1.1rs";
|
||||||
private static DirectoryHT<TypeRepTemplate> AppEnv { get; set; }
|
private static DirectoryHT<TypeRepTemplate> AppEnv { get; set; }
|
||||||
private static CS2JSettings cfg = new CS2JSettings();
|
private static CS2JSettings cfg = new CS2JSettings();
|
||||||
private static StringTemplateGroup templates = null;
|
private static StringTemplateGroup templates = null;
|
||||||
@ -46,6 +46,8 @@ namespace Twiglet.CS2J.Translator
|
|||||||
private static String[] newLines = new String[] { "\n", Environment.NewLine };
|
private static String[] newLines = new String[] { "\n", Environment.NewLine };
|
||||||
private static int numLines = (10 * 10) + 50 - 30;
|
private static int numLines = (10 * 10) + 50 - 30;
|
||||||
|
|
||||||
|
private static XmlTextWriter enumXmlWriter = null;
|
||||||
|
|
||||||
public delegate void FileProcessor(string fName);
|
public delegate void FileProcessor(string fName);
|
||||||
|
|
||||||
private static Dictionary<string, ClassDescriptorSerialized> partialTypes = new Dictionary<string, ClassDescriptorSerialized>();
|
private static Dictionary<string, ClassDescriptorSerialized> partialTypes = new Dictionary<string, ClassDescriptorSerialized>();
|
||||||
@ -168,7 +170,7 @@ namespace Twiglet.CS2J.Translator
|
|||||||
|
|
||||||
// Output enum list, parsed translation files
|
// Output enum list, parsed translation files
|
||||||
cfg.OptDumpEnums.SetIfDefault(general.GetBoolean("dump-enums", cfg.DumpEnums));
|
cfg.OptDumpEnums.SetIfDefault(general.GetBoolean("dump-enums", cfg.DumpEnums));
|
||||||
cfg.OptEnumDir.SetIfDefault(Path.Combine(Directory.GetCurrentDirectory(), general.Get("out-enum-dir", cfg.EnumDir)));
|
cfg.OptEnumDir.SetIfDefault(Path.Combine(Directory.GetCurrentDirectory(), general.Get("out-enums-file", cfg.EnumDir)));
|
||||||
|
|
||||||
cfg.OptDumpXmls.SetIfDefault(general.GetBoolean("dump-xmls", cfg.DumpXmls));
|
cfg.OptDumpXmls.SetIfDefault(general.GetBoolean("dump-xmls", cfg.DumpXmls));
|
||||||
cfg.OptXmlDir.SetIfDefault(Path.Combine(Directory.GetCurrentDirectory(), general.Get("out-xml-dir", cfg.XmlDir)));
|
cfg.OptXmlDir.SetIfDefault(Path.Combine(Directory.GetCurrentDirectory(), general.Get("out-xml-dir", cfg.XmlDir)));
|
||||||
@ -220,7 +222,6 @@ namespace Twiglet.CS2J.Translator
|
|||||||
public static void CS2JMain(string[] args)
|
public static void CS2JMain(string[] args)
|
||||||
{
|
{
|
||||||
long startTime = DateTime.Now.Ticks;
|
long startTime = DateTime.Now.Ticks;
|
||||||
XmlTextWriter enumXmlWriter = null;
|
|
||||||
bool doHelp = false;
|
bool doHelp = false;
|
||||||
|
|
||||||
// Use a try/catch block for parser exceptions
|
// Use a try/catch block for parser exceptions
|
||||||
@ -247,7 +248,7 @@ namespace Twiglet.CS2J.Translator
|
|||||||
.Add ("show-tokens:", v => cfg.DisplayTokens = parseBoolOption(v))
|
.Add ("show-tokens:", v => cfg.DisplayTokens = parseBoolOption(v))
|
||||||
.Add ("D=", def => cfg.OptMacroDefines.Add(mkStrings(def)))
|
.Add ("D=", def => cfg.OptMacroDefines.Add(mkStrings(def)))
|
||||||
.Add ("dump-enums:", v => cfg.DumpEnums = parseBoolOption(v))
|
.Add ("dump-enums:", v => cfg.DumpEnums = parseBoolOption(v))
|
||||||
.Add ("out-enum-dir=", dir => cfg.EnumDir = Path.Combine(Directory.GetCurrentDirectory(), dir))
|
.Add ("out-enums-file=", dir => cfg.EnumDir = Path.Combine(Directory.GetCurrentDirectory(), dir))
|
||||||
.Add ("dump-xmls:", v => cfg.DumpXmls = parseBoolOption(v))
|
.Add ("dump-xmls:", v => cfg.DumpXmls = parseBoolOption(v))
|
||||||
.Add ("out-xml-dir=", dir => cfg.XmlDir = Path.Combine(Directory.GetCurrentDirectory(), dir))
|
.Add ("out-xml-dir=", dir => cfg.XmlDir = Path.Combine(Directory.GetCurrentDirectory(), dir))
|
||||||
.Add ("out-java-dir=", dir => cfg.OutDir = dir)
|
.Add ("out-java-dir=", dir => cfg.OutDir = dir)
|
||||||
@ -273,7 +274,6 @@ namespace Twiglet.CS2J.Translator
|
|||||||
.Add ("internal-isjavaish:", v => cfg.InternalIsJavaish = parseBoolOption(v))
|
.Add ("internal-isjavaish:", v => cfg.InternalIsJavaish = parseBoolOption(v))
|
||||||
;
|
;
|
||||||
|
|
||||||
//TODO: fix enum dump
|
|
||||||
// Final argument is translation target
|
// Final argument is translation target
|
||||||
foreach (string s in p.Parse (args))
|
foreach (string s in p.Parse (args))
|
||||||
{
|
{
|
||||||
@ -353,6 +353,7 @@ namespace Twiglet.CS2J.Translator
|
|||||||
doFile(r, ".cs", addAppSigTranslation, cfg.ExAppRoot); // parse it
|
doFile(r, ".cs", addAppSigTranslation, cfg.ExAppRoot); // parse it
|
||||||
if (cfg.DumpEnums) {
|
if (cfg.DumpEnums) {
|
||||||
enumXmlWriter = new XmlTextWriter(cfg.EnumDir, System.Text.Encoding.UTF8);
|
enumXmlWriter = new XmlTextWriter(cfg.EnumDir, System.Text.Encoding.UTF8);
|
||||||
|
enumXmlWriter.WriteStartElement("enums");
|
||||||
}
|
}
|
||||||
if (cfg.DumpXmls)
|
if (cfg.DumpXmls)
|
||||||
{
|
{
|
||||||
@ -651,6 +652,8 @@ namespace Twiglet.CS2J.Translator
|
|||||||
javaMaker.CUKeys = new List<string>();
|
javaMaker.CUKeys = new List<string>();
|
||||||
javaMaker.IsJavaish = cfg.InternalIsJavaish;
|
javaMaker.IsJavaish = cfg.InternalIsJavaish;
|
||||||
|
|
||||||
|
javaMaker.EnumXmlWriter = enumXmlWriter;
|
||||||
|
|
||||||
if (cfg.DebugLevel >= 1) Console.Out.WriteLine("Translating {0} to Java", fullName);
|
if (cfg.DebugLevel >= 1) Console.Out.WriteLine("Translating {0} to Java", fullName);
|
||||||
|
|
||||||
javaMaker.compilation_unit();
|
javaMaker.compilation_unit();
|
||||||
|
@ -41,6 +41,7 @@ scope TypeContext {
|
|||||||
{
|
{
|
||||||
using System;
|
using System;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Xml;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
}
|
}
|
||||||
@ -48,6 +49,41 @@ scope TypeContext {
|
|||||||
@members
|
@members
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
private XmlTextWriter enumXmlWriter = null;
|
||||||
|
public XmlTextWriter EnumXmlWriter {
|
||||||
|
get { return enumXmlWriter; }
|
||||||
|
set { enumXmlWriter = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
private void WriteStartEnum(String name)
|
||||||
|
{
|
||||||
|
if (enumXmlWriter != null)
|
||||||
|
{
|
||||||
|
enumXmlWriter.WriteStartElement("enum");
|
||||||
|
enumXmlWriter.WriteAttributeString("id", name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void WriteEndEnum()
|
||||||
|
{
|
||||||
|
if (enumXmlWriter != null)
|
||||||
|
{
|
||||||
|
enumXmlWriter.WriteEndElement();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void WriteEnumMember(String name, int value)
|
||||||
|
{
|
||||||
|
if (enumXmlWriter != null)
|
||||||
|
{
|
||||||
|
enumXmlWriter.WriteStartElement("member");
|
||||||
|
enumXmlWriter.WriteAttributeString("id", name);
|
||||||
|
enumXmlWriter.WriteAttributeString("value", value.ToString());
|
||||||
|
enumXmlWriter.WriteEndElement();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Since a CS file may comtain multiple top level types (and so generate multiple Java
|
// Since a CS file may comtain multiple top level types (and so generate multiple Java
|
||||||
// files) we build a map from type name to AST for each top level type
|
// files) we build a map from type name to AST for each top level type
|
||||||
// We also build a list of type names so that we can maintain the order (so comments
|
// We also build a list of type names so that we can maintain the order (so comments
|
||||||
@ -1513,9 +1549,9 @@ scope TypeContext;
|
|||||||
}
|
}
|
||||||
:
|
:
|
||||||
{ Cfg.EnumsAsNumericConsts }? =>
|
{ Cfg.EnumsAsNumericConsts }? =>
|
||||||
e1='enum' identifier { $name = $identifier.thetext; $TypeContext::typeName = $identifier.thetext; } magicBoxedType[true,$e1.token,"System.Int32"] { constType = $magicBoxedType.tree; } (enum_base {constType = $enum_base.tree; } )? enum_body_asnumber[constType] ';'?
|
e1='enum' identifier { $name = $identifier.thetext; $TypeContext::typeName = $identifier.thetext; WriteStartEnum($name); } magicBoxedType[true,$e1.token,"System.Int32"] { constType = $magicBoxedType.tree; } (enum_base {constType = $enum_base.tree; } )? enum_body_asnumber[constType] ';'? { WriteEndEnum(); }
|
||||||
-> ^(CLASS[$e1.token, "class"] { dupTree($atts) } { mangledMods } identifier enum_body_asnumber)
|
-> ^(CLASS[$e1.token, "class"] { dupTree($atts) } { mangledMods } identifier enum_body_asnumber)
|
||||||
| e2='enum' identifier { $name = $identifier.thetext; $TypeContext::typeName = $identifier.thetext; } enum_base? enum_body ';'?
|
| e2='enum' identifier { $name = $identifier.thetext; $TypeContext::typeName = $identifier.thetext; WriteStartEnum($name); } enum_base? enum_body ';'? { WriteEndEnum(); }
|
||||||
-> ^(ENUM[$e2.token, "ENUM"] { dupTree($atts) } { mangledMods } identifier enum_base? enum_body);
|
-> ^(ENUM[$e2.token, "ENUM"] { dupTree($atts) } { mangledMods } identifier enum_base? enum_body);
|
||||||
|
|
||||||
enum_base:
|
enum_base:
|
||||||
@ -1534,6 +1570,7 @@ enum_member_declarations
|
|||||||
for (int i = 0; i < next; i++) {
|
for (int i = 0; i < next; i++) {
|
||||||
if (members.ContainsKey(i)) {
|
if (members.ContainsKey(i)) {
|
||||||
adaptor.AddChild($enum_member_declarations.tree, members[i]);
|
adaptor.AddChild($enum_member_declarations.tree, members[i]);
|
||||||
|
WriteEnumMember(members[i].Text, i);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
adaptor.AddChild($enum_member_declarations.tree, adaptor.Create(IDENTIFIER, $e.start.Token, "__dummyEnum__" + dummyCounter++));
|
adaptor.AddChild($enum_member_declarations.tree, adaptor.Create(IDENTIFIER, $e.start.Token, "__dummyEnum__" + dummyCounter++));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user