public TypeConverter(cppsharp.CsharpGen gen) { _dataTypeMap = new Dictionary<string, ConvertEngine>(); _generator = gen; _dataTypeMap.Add ("bool", new ConvertEngine("bool")); _dataTypeMap.Add ("char", new ConvertEngine("sbyte")); _dataTypeMap.Add ("unsigned char", new ConvertEngine("byte")); _dataTypeMap.Add ("short int", new ConvertEngine("short")); _dataTypeMap.Add ("short unsigned int", new ConvertEngine("ushort")); _dataTypeMap.Add ("int", new ConvertEngine("int")); _dataTypeMap.Add ("unsigned int", new ConvertEngine("uint")); _dataTypeMap.Add ("long long int", new ConvertEngine("long")); _dataTypeMap.Add ("long long unsigned int", new ConvertEngine("ulong")); _dataTypeMap.Add ("float", new ConvertEngine("float")); _dataTypeMap.Add ("double", new ConvertEngine("double")); _dataTypeMap.Add ("::std::string", new ConvertEngine("string")); /* // architecture dependant types if(_generator.Platform.Arch == PlatformInfo.ArchType.x86) { _dataTypeMap.Add ("long", new ConvertEngine("int")); _dataTypeMap.Add ("unsigned long", new ConvertEngine("uint")); } else if(_generator.Platform.Arch == PlatformInfo.ArchType.x64) { _dataTypeMap.Add ("long", new ConvertEngine("long")); _dataTypeMap.Add ("unsigned long", new ConvertEngine("long")); } else {} */ }
// outputs the list of *.main files for use by the linker static List<string> compileSource(string file, string dllImport, List<string> srcFiles, List<string> includePaths, string outDir) { List<string> ret = new List<string>(); System.Diagnostics.Process process = new System.Diagnostics.Process(); System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(); startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; // create a temp file to store the xml in using(cppsharp.TempFile tmp = new TempFile()) using(cppsharp.TempFile gccOutputFileName = new TempFile()) { string includeOps = ""; foreach (string str in includePaths) includeOps += "-I" + str + " "; // run the command to switch (Environment.OSVersion.Platform) { case System.PlatformID.Unix: startInfo.FileName = "castxml"; startInfo.Arguments = "-std=c++11 --castxml-gccxml " + includeOps + " " + file + " -o " + tmp.FilePath; startInfo.UseShellExecute = false; break; case System.PlatformID.Win32NT: startInfo.FileName = "cmd.exe"; startInfo.Arguments = "/c C:/local/castxml/bin/castxml.exe -fms-compatibility-version=19 -std=c++14 --castxml-gccxml " + includeOps + " " + file + " -o " + tmp.FilePath + " 2> " + gccOutputFileName.FilePath; break; } process.StartInfo = startInfo; process.Start(); process.WaitForExit(); process.WaitForExit(); // get the exit code and print error message if necessary if(process.ExitCode != 0) { // there was an error coming from gcc print gcc output to the console Console.WriteLine("ERROR:"); Console.WriteLine("castxml command \"" + startInfo.Arguments + "\", code " + process.ExitCode); Console.Write (File.ReadAllText(gccOutputFileName.FilePath)); Environment.Exit (-1); } File.OpenRead(tmp.FilePath).Close(); // debug string xml = File.ReadAllText(tmp.FilePath); int indexExt = file.LastIndexOf("."); int indexBase = 0; if(outDir != null) indexBase = file.LastIndexOf('/') + 1; if(indexExt < indexBase) indexExt = file.Length; string fileBase = file.Substring(indexBase, (indexExt<0 ? file.Length : indexExt) - indexBase); string xmlFile = outDir + "/" + fileBase + ".xml"; File.WriteAllText(xmlFile, xml); // generate the csharp file cppsharp.CsharpGen gen = new cppsharp.CsharpGen(new XmlTextReader(tmp.FilePath)); gen.SourceFiles = srcFiles; gen.XmlFile = xmlFile; gen.OutDir = outDir; gen.DllImport = dllImport; gen.process(); gen.write(); foreach(KeyValuePair<string, FileInfo> pair in gen.Files) { FileInfo info = pair.Value; ret.Add(info.MainFileName); } } return ret; }