mirror of
https://github.com/twiglet/cs2j.git
synced 2025-01-18 13:15:17 +01:00
Add NDesk.Options for command line option processing. Add cs2jTempleGen to generate xml templates from DLLs
This commit is contained in:
parent
791c01efa5
commit
3d3af6aed0
@ -13,6 +13,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "cs2jTest", "cs2jTest\cs2jTest.csproj", "{28A229C9-2F22-4384-B224-61A5C67638CE}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NDesk.Options", "src\NDesk.Options\NDesk.Options.csproj", "{E6ACBB37-AF38-45E1-B399-0CEE63809A15}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "cs2jTemplateGen", "src\cs2jTemplateGen\cs2jTemplateGen.csproj", "{CC80B16E-0700-4AA5-ABA0-ADBCD9316952}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@ -26,6 +30,12 @@ Global
|
||||
{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
|
||||
{CC80B16E-0700-4AA5-ABA0-ADBCD9316952}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{CC80B16E-0700-4AA5-ABA0-ADBCD9316952}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{CC80B16E-0700-4AA5-ABA0-ADBCD9316952}.Default|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{CC80B16E-0700-4AA5-ABA0-ADBCD9316952}.Default|Any CPU.Build.0 = Debug|Any CPU
|
||||
{CC80B16E-0700-4AA5-ABA0-ADBCD9316952}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{CC80B16E-0700-4AA5-ABA0-ADBCD9316952}.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
|
||||
@ -34,6 +44,12 @@ Global
|
||||
{CF15D0D5-BE72-4F98-B70F-229ABA1DF0E8}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{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
|
||||
{E6ACBB37-AF38-45E1-B399-0CEE63809A15}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{E6ACBB37-AF38-45E1-B399-0CEE63809A15}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{E6ACBB37-AF38-45E1-B399-0CEE63809A15}.Default|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{E6ACBB37-AF38-45E1-B399-0CEE63809A15}.Default|Any CPU.Build.0 = Debug|Any CPU
|
||||
{E6ACBB37-AF38-45E1-B399-0CEE63809A15}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{E6ACBB37-AF38-45E1-B399-0CEE63809A15}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(NestedProjects) = preSolution
|
||||
EndGlobalSection
|
||||
|
@ -1,34 +1,33 @@
|
||||
<Properties>
|
||||
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" ctype="Workspace" />
|
||||
<MonoDevelop.Ide.Workbench ActiveDocument="cs2jTest/TranslationTemplate.cs" ctype="Workbench">
|
||||
<MonoDevelop.Ide.Workbench ActiveDocument="src/cs2jTemplateGen/Main.cs" ctype="Workbench">
|
||||
<Files>
|
||||
<File FileName="src/Antlr.Runtime/Antlr.Runtime/ANTLRInputStream.cs" Line="1" Column="1" />
|
||||
<File FileName="src/cs2j/Utils/DirectoryHT.cs" Line="5" Column="43" />
|
||||
<File FileName="src/Antlr.Runtime/Antlr.Runtime.JavaExtensions/DictionaryExtensions.cs" Line="78" Column="48" />
|
||||
<File FileName="src/cs2j/CSharp/csCrawl.cs" Line="1" Column="1" />
|
||||
<File FileName="src/cs2j/CLR/TranslationTemplate.cs" Line="601" Column="58" />
|
||||
<File FileName="src/cs2j/CLR/TranslationTemplate.cs" Line="1091" Column="38" />
|
||||
<File FileName="src/cs2j/CSharp/SignatureExtracter.cs" Line="11" Column="1" />
|
||||
<File FileName="src/cs2j/CSharp/Main.cs" Line="14" Column="14" />
|
||||
<File FileName="src/cs2j/CSharp/Main.cs" Line="3" Column="21" />
|
||||
<File FileName="build.xml" Line="189" Column="35" />
|
||||
<File FileName="build.properties" Line="18" Column="35" />
|
||||
<File FileName="src/cs2j/CSharp/minDriver.cs" Line="20" Column="62" />
|
||||
<File FileName="src/cs2j/CLR/TypeRep.cs" Line="902" Column="26" />
|
||||
<File FileName="src/cs2j/CLR/TypeRep.cs" Line="146" Column="45" />
|
||||
<File FileName="src/cs2j/CLR/cs2j.cs" Line="231" Column="56" />
|
||||
<File FileName="cs2jTest/TranslationTemplate.cs" Line="70" Column="28" />
|
||||
<File FileName="src/cs2j/Utils/Util.cs" Line="66" Column="35" />
|
||||
<File FileName="cs2jTest/TranslationTemplate.cs" Line="22" Column="1" />
|
||||
<File FileName="src/cs2j/TemplateUtils/TemplateFromDLL.cs" Line="182" Column="1" />
|
||||
<File FileName="src/NDesk.Options/Options.cs" Line="693" Column="29" />
|
||||
<File FileName="src/cs2jTemplateGen/Main.cs" Line="80" Column="32" />
|
||||
</Files>
|
||||
<Pads>
|
||||
<Pad Id="ProjectPad">
|
||||
<State expanded="True">
|
||||
<Node name="cs2j" expanded="True">
|
||||
<Node name="CLR" expanded="True" />
|
||||
<Node name="CSharp" expanded="True" />
|
||||
<Node name="Utils" expanded="True" />
|
||||
</Node>
|
||||
<Node name="cs2jTest" expanded="True">
|
||||
<Node name="References" expanded="True" />
|
||||
<Node name="TranslationTemplate.cs" selected="True" />
|
||||
<Node name="CSharp" expanded="True" />
|
||||
</Node>
|
||||
<Node name="cs2jTemplateGen" expanded="True" selected="True" />
|
||||
<Node name="NDesk.Options" expanded="True" />
|
||||
</State>
|
||||
</Pad>
|
||||
<Pad Id="ClassPad">
|
||||
@ -41,27 +40,14 @@
|
||||
<State selected="True" />
|
||||
</Pad>
|
||||
<Pad Id="MonoDevelop.NUnit.TestPad">
|
||||
<State expanded="True">
|
||||
<Node name="cs2jTest" expanded="True">
|
||||
<Node name="RusticiSoftware" expanded="True">
|
||||
<Node name="Translator" expanded="True">
|
||||
<Node name="CLR" expanded="True">
|
||||
<Node name="TranslationTemplateTest" expanded="True">
|
||||
<Node name="DelegateCase" selected="True" />
|
||||
</Node>
|
||||
</Node>
|
||||
</Node>
|
||||
</Node>
|
||||
</Node>
|
||||
</State>
|
||||
<State expanded="True" selected="True" />
|
||||
</Pad>
|
||||
</Pads>
|
||||
</MonoDevelop.Ide.Workbench>
|
||||
<MonoDevelop.Ide.DebuggingService.Breakpoints>
|
||||
<BreakpointStore>
|
||||
<Breakpoint file="/Users/keving/gitrepos/cs2j/CSharpTranslator/antlr3/src/cs2j/TestFramework/TestFramework.cs" line="27" />
|
||||
<Breakpoint file="/Users/keving/gitrepos/cs2j/CSharpTranslator/antlr3/src/cs2j/CSharp/Main.cs" line="11" />
|
||||
<Breakpoint file="/Users/keving/gitrepos/cs2j/CSharpTranslator/antlr3/cs2jTest/TranslationTemplate.cs" line="70" />
|
||||
<Breakpoint file="/Users/keving/gitrepos/cs2j/CSharpTranslator/antlr3/src/cs2jTemplateGen/Main.cs" line="199" />
|
||||
</BreakpointStore>
|
||||
</MonoDevelop.Ide.DebuggingService.Breakpoints>
|
||||
<MonoDevelop.Ide.DebuggingService.PinnedWatches ctype="PinnedWatchStore" />
|
||||
|
@ -0,0 +1,20 @@
|
||||
Copyright (C) 2008 Novell (http://www.novell.com)
|
||||
|
||||
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.
|
@ -8,6 +8,11 @@ This work includes a number of freely redistributable libraries under various li
|
||||
| |grammar | |LICENSE (EPL) |
|
||||
| | | | |
|
||||
+-------------------------------+------------+-------------------------------------------------------------+----------------+
|
||||
+-------------------------------+------------+-------------------------------------------------------------+----------------+
|
||||
|NDesk.Options/Options.cs |Command Line|http://www.ndesk.org/Options |MIT/X11 |
|
||||
| |options | | |
|
||||
| |processor | | |
|
||||
+-------------------------------+------------+-------------------------------------------------------------+----------------+
|
||||
|
||||
|
||||
+-------------------------------+------------+-------------------------------------------------------------+----------------+
|
||||
|
27
CSharpTranslator/antlr3/src/NDesk.Options/AssemblyInfo.cs
Normal file
27
CSharpTranslator/antlr3/src/NDesk.Options/AssemblyInfo.cs
Normal file
@ -0,0 +1,27 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
// Information about this assembly is defined by the following attributes.
|
||||
// Change them to the values specific to your project.
|
||||
|
||||
[assembly: AssemblyTitle("NDesk.Options")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("")]
|
||||
[assembly: AssemblyCopyright("")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
|
||||
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
|
||||
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
|
||||
|
||||
[assembly: AssemblyVersion("1.0.*")]
|
||||
|
||||
// The following attributes are used to specify the signing key for the assembly,
|
||||
// if desired. See the Mono documentation for more information about signing.
|
||||
|
||||
//[assembly: AssemblyDelaySign(false)]
|
||||
//[assembly: AssemblyKeyFile("")]
|
||||
|
@ -0,0 +1 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>10.0.0</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{E6ACBB37-AF38-45E1-B399-0CEE63809A15}</ProjectGuid>
<OutputType>Library</OutputType>
<RootNamespace>NDesk.Options</RootNamespace>
<AssemblyName>NDesk.Options</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug</OutputPath>
<DefineConstants>DEBUG</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>none</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
</ItemGroup>
<ItemGroup>
<Compile Include="AssemblyInfo.cs" />
<Compile Include="Options.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>
|
1103
CSharpTranslator/antlr3/src/NDesk.Options/Options.cs
Normal file
1103
CSharpTranslator/antlr3/src/NDesk.Options/Options.cs
Normal file
File diff suppressed because it is too large
Load Diff
@ -39,7 +39,7 @@
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<Commandlineparameters>-testdrive</Commandlineparameters>
|
||||
<Commandlineparameters>-genTemplate /Users/keving/gitrepos/cs2j/CSharpTranslator/antlr3/src/cs2j/bin/Debug/Antlr3-2.Runtime.DotNet20.dll Antlr.Runtime.CommonTokenStream</Commandlineparameters>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
@ -115,4 +115,7 @@
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="TemplateUtils\" />
|
||||
</ItemGroup>
|
||||
</Project>
|
27
CSharpTranslator/antlr3/src/cs2jTemplateGen/AssemblyInfo.cs
Normal file
27
CSharpTranslator/antlr3/src/cs2jTemplateGen/AssemblyInfo.cs
Normal file
@ -0,0 +1,27 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
// Information about this assembly is defined by the following attributes.
|
||||
// Change them to the values specific to your project.
|
||||
|
||||
[assembly: AssemblyTitle("cs2jTemplateGen")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("")]
|
||||
[assembly: AssemblyCopyright("")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
|
||||
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
|
||||
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
|
||||
|
||||
[assembly: AssemblyVersion("1.0.*")]
|
||||
|
||||
// The following attributes are used to specify the signing key for the assembly,
|
||||
// if desired. See the Mono documentation for more information about signing.
|
||||
|
||||
//[assembly: AssemblyDelaySign(false)]
|
||||
//[assembly: AssemblyKeyFile("")]
|
||||
|
229
CSharpTranslator/antlr3/src/cs2jTemplateGen/Main.cs
Normal file
229
CSharpTranslator/antlr3/src/cs2jTemplateGen/Main.cs
Normal file
@ -0,0 +1,229 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using RusticiSoftware.Translator.CLR;
|
||||
using System.IO;
|
||||
using System.Xml.Serialization;
|
||||
using System.Xml;
|
||||
using RusticiSoftware.Translator.Utils;
|
||||
using System.Text;
|
||||
using NDesk.Options;
|
||||
using System.Collections.Generic;
|
||||
namespace cs2j.Template.Utils
|
||||
{
|
||||
public class TemplateFromDLL
|
||||
{
|
||||
private Assembly assembly = null;
|
||||
private int verbose = 0;
|
||||
private List<string> extractTypes = new List<string>();
|
||||
|
||||
public TemplateFromDLL (string DLLFileName)
|
||||
{
|
||||
assembly = Assembly.LoadFile(DLLFileName);
|
||||
}
|
||||
|
||||
public TemplateFromDLL ()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public void listTypes(string DLLFileName) {
|
||||
|
||||
Assembly testAssembly = Assembly.LoadFile(DLLFileName);
|
||||
|
||||
Type[] exportedTypes = testAssembly.GetExportedTypes();
|
||||
|
||||
Console.WriteLine ("Enums:");
|
||||
foreach (Type item in exportedTypes) {
|
||||
if (item.IsEnum) {
|
||||
Console.WriteLine (" * " + item.FullName);
|
||||
}
|
||||
}
|
||||
|
||||
Console.WriteLine ("Interfaces:");
|
||||
foreach (Type item in exportedTypes) {
|
||||
if (item.IsInterface) {
|
||||
Console.WriteLine (" * " + item.FullName);
|
||||
}
|
||||
}
|
||||
Console.WriteLine ("Classes:");
|
||||
foreach (Type item in exportedTypes) {
|
||||
if (item.IsClass) {
|
||||
Console.WriteLine (" * " + item.FullName);
|
||||
}
|
||||
}
|
||||
Console.WriteLine ("Arrays:");
|
||||
foreach (Type item in exportedTypes) {
|
||||
if (item.IsArray) {
|
||||
Console.WriteLine (" * " + item.FullName);
|
||||
}
|
||||
}
|
||||
Console.WriteLine ("Others:");
|
||||
foreach (Type item in exportedTypes) {
|
||||
if (!item.IsEnum && !item.IsInterface && !item.IsClass && !item.IsArray) {
|
||||
Console.WriteLine (" * " + item.FullName);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void buildParameters(ConstructorRepTemplate c, MethodBase m) {
|
||||
foreach (ParameterInfo p in m.GetParameters()) {
|
||||
ParamRepTemplate paramRep = new ParamRepTemplate();
|
||||
paramRep.Type = p.ParameterType.FullName;
|
||||
paramRep.Name = p.Name;
|
||||
c.Params.Add(paramRep);
|
||||
}
|
||||
}
|
||||
|
||||
private void buildInterface(InterfaceRepTemplate iface, Type t) {
|
||||
|
||||
iface.TypeName = t.FullName;
|
||||
// Grab Methods
|
||||
foreach (MethodInfo m in t.GetMethods()) {
|
||||
MethodRepTemplate methRep = new MethodRepTemplate();
|
||||
methRep.Name = m.Name;
|
||||
methRep.Return = m.ReturnType.FullName;
|
||||
buildParameters(methRep, m);
|
||||
iface.Methods.Add(methRep);
|
||||
}
|
||||
|
||||
// Grab Properties
|
||||
foreach (PropertyInfo p in t.GetProperties()) {
|
||||
PropRepTemplate propRep = new PropRepTemplate();
|
||||
propRep.Name = p.Name;
|
||||
propRep.Type = p.PropertyType.FullName;
|
||||
iface.Properties.Add(propRep);
|
||||
}
|
||||
|
||||
// Grab Events
|
||||
foreach (EventInfo e in t.GetEvents()) {
|
||||
FieldRepTemplate eventRep = new FieldRepTemplate();
|
||||
eventRep.Name = e.Name;
|
||||
eventRep.Type = e.EventHandlerType.FullName;
|
||||
iface.Events.Add(eventRep);
|
||||
}
|
||||
}
|
||||
|
||||
private void buildClass(ClassRepTemplate klass, Type t) {
|
||||
// Grab common fields
|
||||
buildInterface(klass, t);
|
||||
// Grab Constructors
|
||||
foreach (ConstructorInfo c in t.GetConstructors()) {
|
||||
ConstructorRepTemplate consRep = new ConstructorRepTemplate();
|
||||
buildParameters(consRep, c);
|
||||
klass.Constructors.Add(consRep);
|
||||
}
|
||||
// Grab Fields
|
||||
foreach (FieldInfo f in t.GetFields()) {
|
||||
FieldRepTemplate fieldRep = new FieldRepTemplate();
|
||||
fieldRep.Name = f.Name;
|
||||
fieldRep.Type = f.FieldType.FullName;
|
||||
klass.Fields.Add(fieldRep);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private TypeRepTemplate mkTemplate(string typeName) {
|
||||
|
||||
TypeRepTemplate retRep = null;
|
||||
Type t = assembly.GetType(typeName);
|
||||
if (t.IsClass) {
|
||||
ClassRepTemplate classRep = new ClassRepTemplate();
|
||||
buildClass(classRep, t);
|
||||
retRep = classRep;
|
||||
}
|
||||
else if (t.IsInterface) {
|
||||
InterfaceRepTemplate intRep = new InterfaceRepTemplate();
|
||||
buildInterface(intRep, t);
|
||||
retRep = intRep;
|
||||
}
|
||||
else if (t.IsEnum) {
|
||||
EnumRepTemplate enumRep = new EnumRepTemplate();
|
||||
enumRep.TypeName = t.FullName;
|
||||
foreach (FieldInfo f in t.GetFields(BindingFlags.Public | BindingFlags.Static)) {
|
||||
enumRep.Members.Add(new EnumMemberRepTemplate(f.Name, f.GetRawConstantValue().ToString()));
|
||||
}
|
||||
retRep = enumRep;
|
||||
}
|
||||
return retRep;
|
||||
|
||||
}
|
||||
|
||||
private void writeXmlStream(TypeRepTemplate inT, TextWriter str) {
|
||||
|
||||
XmlSerializer xmls = new XmlSerializer(inT.GetType(), Constants.TranslationTemplateNamespace);
|
||||
|
||||
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(str, settings))
|
||||
{
|
||||
xmls.Serialize(writer, inT);
|
||||
}
|
||||
}
|
||||
|
||||
private List<string> getAllTypeNames() {
|
||||
List<string> typeNames = new List<string>();
|
||||
foreach (Type t in assembly.GetExportedTypes()) {
|
||||
typeNames.Add(t.FullName);
|
||||
}
|
||||
return typeNames;
|
||||
}
|
||||
|
||||
private static void printUsageAndExit() {
|
||||
Console.WriteLine ("Help goes here!");
|
||||
Environment.Exit(0);
|
||||
}
|
||||
|
||||
public static void Main(string[] args) {
|
||||
|
||||
TemplateFromDLL templateDriver = new TemplateFromDLL();
|
||||
List<string> extractTypes = null;
|
||||
bool dumpXmls = false;
|
||||
string xmlDir = Directory.GetCurrentDirectory();
|
||||
OptionSet p = new OptionSet ()
|
||||
.Add ("v", v => templateDriver.verbose++)
|
||||
.Add ("help|h|?", v => printUsageAndExit())
|
||||
.Add ("dll=", dllFileName => templateDriver.assembly = Assembly.LoadFile(dllFileName))
|
||||
.Add ("dumpxmls", v => dumpXmls = true)
|
||||
.Add ("xmldir=", dir => xmlDir = Path.Combine(xmlDir, dir));
|
||||
// .Add ("extract={,}", typeName => templateDriver.extractTypes.Add(typeName));
|
||||
extractTypes = p.Parse (args);
|
||||
if (templateDriver.assembly == null) {
|
||||
Console.WriteLine("You must specify the DLL to extract the types");
|
||||
printUsageAndExit();
|
||||
}
|
||||
if (extractTypes == null || extractTypes.Count == 0) {
|
||||
extractTypes = templateDriver.getAllTypeNames();
|
||||
}
|
||||
if (templateDriver.verbose > 0)
|
||||
Console.WriteLine ("Types to extract:");
|
||||
foreach (string t in extractTypes) {
|
||||
if (templateDriver.verbose > 0)
|
||||
Console.WriteLine ( "extracting {0}", t );
|
||||
TypeRepTemplate tyRep = templateDriver.mkTemplate(t);
|
||||
TextWriter writer = null;
|
||||
if (dumpXmls) {
|
||||
string xmlFName = Path.Combine(xmlDir, t.Replace('.', Path.DirectorySeparatorChar) + ".xml");
|
||||
string xmlFDir = Path.GetDirectoryName(xmlFName);
|
||||
if (!Directory.Exists(xmlFDir))
|
||||
{
|
||||
Directory.CreateDirectory(xmlFDir);
|
||||
}
|
||||
writer = new StreamWriter(xmlFName);
|
||||
}
|
||||
else {
|
||||
writer = Console.Out;
|
||||
}
|
||||
templateDriver.writeXmlStream(tyRep, writer);
|
||||
if (dumpXmls)
|
||||
writer.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>10.0.0</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{CC80B16E-0700-4AA5-ABA0-ADBCD9316952}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>cs2jTemplateGen</RootNamespace>
<AssemblyName>cs2jTemplateGen</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug</OutputPath>
<DefineConstants>DEBUG</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Externalconsole>true</Externalconsole>
<Commandlineparameters>-dll /Users/keving/gitrepos/cs2j/CSharpTranslator/antlr3/src/cs2jTemplateGen/bin/Debug/NDesk.Options.dll NDesk.Options.OptionValueType</Commandlineparameters>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>none</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Externalconsole>true</Externalconsole>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Main.cs" />
<Compile Include="AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\cs2j\cs2j.csproj">
<Project>{CE961AC5-C8D4-41B3-AAF3-23FA8FAEE8AD}</Project>
<Name>cs2j</Name>
</ProjectReference>
<ProjectReference Include="..\NDesk.Options\NDesk.Options.csproj">
<Project>{E6ACBB37-AF38-45E1-B399-0CEE63809A15}</Project>
<Name>NDesk.Options</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>
|
Loading…
x
Reference in New Issue
Block a user