static int MainCore() { if (cl.HasOption("?", "help")) { Usage(); return(0); } if (cl.HasOption(PFCOptions.Wrap)) { WrapperGenerator.Wrap(cl); return(0); } #if PERF int start = Environment.TickCount; #endif if (cl.HasOption("dot")) { DebugHooks.MethodName = cl.GetOption("", "dot"); } RunCore(); #if PERF CLI.Infrastructure.DumpPerfStat(); Infrastructure.DumpPerfStat(); Console.WriteLine((Environment.TickCount - start) + "ms"); #endif return(0); }
public bool isFinalMethod(WrapperGenerator generator, WrapMethod method) { //Find method name WrapMethod matchMethod = findMethod(method.name); if (matchMethod != null) { if (matchMethod == method) { return(true); } if (matchMethod.name == method.name) { return(false); } } //Check parent if (!String.IsNullOrEmpty(this.parentClass)) { WrapClass parentClass = generator.findClass(this.parentClass); if (parentClass != null) { return(parentClass.isFinalMethod(generator, method)); } } //Return return(false); }
public void Indentation() { string apiLine = @"SWIFT_API int ApiFun(MODEL_SIMULATION_PTR simulation);"; HeaderFilter filter = new HeaderFilter(); var gen = new MatlabApiWrapperGenerator(); var filtered = filter.FilterInput(apiLine); var w = new WrapperGenerator(gen, filter); var result = w.Convert(filtered); Assert.Equal(1, result.Length); var s = result[0].Trim('\n'); string[] expectedLines = { "function f = ApiFun(simulation)", //"% ApiFun_m", //"%", //"% INPUT simulation [libpointer] A SWIFT simulation object (i.e. a model runner)", //"% OUTPUT some integer", //"", "simulation_xptr = getExternalPtr(simulation);", "res = calllib('swift', 'ApiFun', simulation_xptr);", "f = mkExternalObjRef(res);", //"", "end", "", // newline "" // newline, ie empty line after body. }; CSharpWrapperGenerator.CheckWrappingFunction(filter, gen, apiLine, expectedLines); }
private static void ResolveReference(string dir, string name, ICollection <string> list) { const StringComparison cmptype = StringComparison.InvariantCultureIgnoreCase; if (name.EndsWith(".abc", cmptype)) { var rs = typeof(QA).GetResourceStream(name); if (rs == null) { throw new InvalidOperationException(); } string path = Path.Combine(dir, name); rs.Save(path); string dll = Path.ChangeExtension(name, ".dll"); WrapperGenerator.Generate(path, dll, null); list.Add(dll); } else { throw new InvalidOperationException(String.Format("Unable to resolve ref: {0}", name)); } }
public static void Main() { // find project directory var path = Path.GetDirectoryName(new System.Uri(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).LocalPath); while (Path.GetFileName(path) != "linux" && Path.GetFileName(path) != "CfxGenerator") { path = Path.GetDirectoryName(path); } path = Path.GetDirectoryName(path); //GeneratedFileManager.PatchFilesLicense(path); //Environment.Exit(0); Environment.CurrentDirectory = path; var parser = new ApiTypeBuilder(); var decls = parser.GetDeclarations(); var gen = new WrapperGenerator(decls); gen.Run(); if (!DocumentationFormatBugStillExists) { //remove workaroung for this bug in CSharp.PrepareSummaryLine System.Diagnostics.Debugger.Break(); } }
static void Main(string[] args) { WrapperGenerator generator = new WrapperGenerator(); WrapperParser parser = new WrapperParser(generator); //Build paths if (args.Length >= 1) { generator.cppOutputPath = args[0]; } if (args.Length >= 2) { generator.csharpOutputPath = args[1]; } //Parse input files for (int i = 2; i < args.Length; i++) { Console.Write("Parsing Input File:" + args[i] + "\n"); parser.parseFile(args[i]); } parser.finalize(); //Generate if (!generator.generate()) { System.Console.Write("Error generating API binding"); return; } }
static void Run(CommandLine cl) { if (cl.HasOption("w", "wrap")) { WrapperGenerator.Wrap(cl); return; } if (cl.HasOption("m", "merge")) { var output = cl.GetOption(null, "o", "out", "output"); AbcMerger.Merge(cl.GetInputFiles(), output); return; } if (cl.HasOption("l", "list")) { List(cl); return; } if (cl.HasOption("removeExports")) { RemoveExports(cl); return; } Dump(cl); }
public T Generate <T>(params object[] partDefinitions) where T : class { partDefinitions = partDefinitions.Concat(GeneralPartDefinitions).ToArray(); EventInvokers eventInvokers = new EventInvokers(); return(Create <T>(partDefinitions, Array.Empty <object>(), eventInvokers, new WrapperFactories <T>(WrapperGenerator <T> .CreateAndCheckWrappers(partDefinitions), eventInvokers))); }
public void IsSupportedEvaluatesSpecifiedNamesTest(string referenceName, bool expected) { var target = new WrapperGenerator("Match"); var actual = target.IsSupported(typeof(Guid), referenceName, null); actual.Should().Be(expected); }
public void IsSupportedEvaluatesSpecifiedExpressionTest(string expression, string referenceName, bool expected) { var regex = new Regex(expression); var target = new WrapperGenerator(regex); var actual = target.IsSupported(typeof(Guid), referenceName, null); actual.Should().Be(expected); }
public static void CheckWrappingFunction(HeaderFilter filter, IApiConverter gen, string apiLine, string[] expectedLines) { var filtered = filter.FilterInput(apiLine); var w = new WrapperGenerator(gen, filter); var result = w.Convert(filtered); string[] lines = SplitToLines(result); CheckExpectedLines(expectedLines, lines); }
private static void ProcessTestLine(string[] args, IApiConverter gen, HeaderFilter filter = null) { if (filter == null) { filter = createFilter(); } string apiLine = args[0]; apiLine = filter.FilterInput(apiLine)[0]; var w = new WrapperGenerator(gen, filter); var result = w.Convert(new string[] { apiLine }); Console.WriteLine(result[0]); }
static Player() { var messageTypes = Helpers.GetNonabstractSubclasses(typeof(ServerMessage)); s_handlerMap = new Dictionary <Type, Action <Player, ServerMessage> >(messageTypes.Count()); foreach (var type in messageTypes) { var method = WrapperGenerator.CreateActionWrapper <Player, ServerMessage>("ReceiveMessage", type); if (method != null) { s_handlerMap[type] = method; } } }
static ChangeHandler() { var changeTypes = Helpers.GetNonabstractSubclasses(typeof(ChangeData)); s_changeHandlerMap = new Dictionary <Type, Action <ChangeHandler, ChangeData> >(changeTypes.Count()); foreach (var type in changeTypes) { var method = WrapperGenerator.CreateActionWrapper <ChangeHandler, ChangeData>("HandleChange", type); if (method == null) { throw new NotImplementedException(String.Format("No HandleChange method found for {0}", type.Name)); } s_changeHandlerMap[type] = method; } }
static ReportHandler() { var reportTypes = Helpers.GetNonabstractSubclasses(typeof(GameReport)); s_reportHandlerMap = new Dictionary <Type, Action <ReportHandler, GameReport> >(reportTypes.Count()); foreach (var type in reportTypes) { var method = WrapperGenerator.CreateActionWrapper <ReportHandler, GameReport>("HandleReport", type); if (method == null) { throw new NotImplementedException(String.Format("No HandleReport method found for {0}", type.Name)); } s_reportHandlerMap[type] = method; } }
public void ReturnsCharPtrPtrToDelegate() { string apiLine = @"SWIFT_API char** ApiFun(MODEL_SIMULATION_PTR simulation, char** elementIds, int numElements, int* size);"; HeaderFilter filter = new HeaderFilter(); var gen = new CsharpDelegatesApiWrapperGenerator(); gen.AddCustomWrapper(gen.ReturnsCharPtrPtrWrapper()); var filtered = filter.FilterInput(apiLine); var w = new WrapperGenerator(gen, filter); var result = w.Convert(filtered); string[] lines = SplitToLines(result); Assert.Equal(2, lines.Length); var s = lines[0].Trim(); string expected = @"private delegate IntPtr ApiFun_csdelegate(IntPtr simulation, IntPtr elementIds, int numElements, IntPtr size);"; Assert.Equal(expected, s); }
public string getCppArgCall(WrapperGenerator generator) { StringBuilder buffer = new StringBuilder(); for (int i = 0; i < args.Count; i++) { //Comma if (i > 0) { buffer.Append(", "); } //Arg WrapMethodArg wrapArg = args[i]; WrapType type = generator.findType(wrapArg.type); //Check if struct if (type is WrapStruct && !wrapArg.moveOut) { buffer.Append("*"); } else if (wrapArg.cppRef) { buffer.Append("*"); } if (String.IsNullOrEmpty(type.cppInConvert)) { buffer.Append(wrapArg.name); } else { if (wrapArg.moveOut) { buffer.Append("&"); } buffer.Append("arg"); buffer.Append(i); } } return(buffer.ToString()); }
static void Main(string[] args) { if (args.Count() < 2) { Console.WriteLine("C# to C++ Generator. Copyright Mark Chandler 2012"); Console.WriteLine("Usage:"); Console.WriteLine("\tCSharpToCppGenerator.exe [Assembly] [OutDir]"); return; } WrapperGenerator gen = new WrapperGenerator(args[1], args[0]); foreach (var type in gen.GetTypesWith <ExposeToCppAttribute>()) { gen.Generate(type); } gen.GenerateCombinedFile(); }
public string getCppArgDef(WrapperGenerator generator) { StringBuilder buffer = new StringBuilder(); for (int i = 0; i < args.Count; i++) { //Comma if (i > 0) { buffer.Append(", "); } //Arg WrapMethodArg wrapArg = args[i]; buffer.Append(generator.findType(wrapArg.type).cppType); buffer.Append(" "); buffer.Append(wrapArg.name); } return(buffer.ToString()); }
static LivingObject() { var actionTypes = Helpers.GetNonabstractSubclasses(typeof(GameAction)); s_actionMethodMap = new Dictionary <Type, ActionData>(actionTypes.Count()); foreach (var type in actionTypes) { var processAction = WrapperGenerator.CreateFuncWrapper <LivingObject, GameAction, ActionState>("ProcessAction", type); if (processAction == null) { throw new Exception(String.Format("No ProcessAction method found for {0}", type.Name)); } s_actionMethodMap[type] = new ActionData() { ProcessAction = processAction, }; } }
private void btnGenerate_Click(object sender, EventArgs e) { Utils.SaveState(this); string curdir = Environment.CurrentDirectory; string path = tbInputPath.Text; string cls = ""; string dir = tbDir.Text; if (!string.IsNullOrEmpty(dir)) { cls += " /dir:" + dir; cls += " "; } if (!string.IsNullOrEmpty(tbOptions.Text)) { cls += tbOptions.Text; cls += " "; } string outpath = tbOut.Text; if (string.IsNullOrEmpty(outpath)) { outpath = Path.GetFileNameWithoutExtension(path) + ".dll"; } try { dir = Path.GetDirectoryName(path); Environment.CurrentDirectory = dir; WrapperGenerator.Wrap(Path.GetFileName(path), outpath, cls); } finally { Environment.CurrentDirectory = curdir; } }
public bool hasVirtualMethods(WrapperGenerator generator) { //Do we have virtual methods foreach (WrapMethod wrapMethod in methods) { if (wrapMethod.isVirtual) { return(true); } } //Check our parents if (!String.IsNullOrEmpty(parentClass)) { WrapClass parent = generator.findClass(this.parentClass); return(parent.hasVirtualMethods(generator)); } else { return(false); } }
public void Indentation() { string apiLine = @"SWIFT_API int ApiFun(MODEL_SIMULATION_PTR simulation);"; HeaderFilter filter = new HeaderFilter(); var genDelegate = new CsharpDelegatesApiWrapperGenerator(); genDelegate.UniformIndentationCount = 2; genDelegate.Indentation = " "; var filtered = filter.FilterInput(apiLine); var w = new WrapperGenerator(genDelegate, filter); var result = w.Convert(filtered); Assert.Equal(1, result.Length); var s = result[0].Trim('\n'); string expected = genDelegate.Indentation + genDelegate.Indentation + @"private delegate int ApiFun_csdelegate(IntPtr simulation);"; Assert.Equal(expected, s); string[] expectedLines = { " int ApiFun_cs(IModelSimulation simulation)", " {", " var result = " + ClassName + ".NativeSwiftLib.GetFunction<ApiFun_csdelegate>(\"ApiFun\")(CheckedDangerousGetHandle(simulation, \"simulation\"));", " var x = result;", " return x;", " }", "", // newline "" // newline, ie empty line after body. }; var gen = new CsharpApiWrapperGenerator(); gen.UniformIndentationCount = 2; gen.Indentation = " "; CheckWrappingFunction(filter, gen, apiLine, expectedLines); }
public void IsSupportedThrowsExceptionWithNullTypeTest() { var buildChain = new LinkedList<object>(); var target = new WrapperGenerator("Test"); Action action = () => target.IsSupported(null, "Test", buildChain); action.ShouldThrow<ArgumentNullException>(); }
public void IsSupportedEvaluatesSpecifiedTypesTest(Type type, bool expected) { var target = new WrapperGenerator(typeof(bool), typeof(bool?)); var actual = target.IsSupported(type, null, null); actual.Should().Be(expected); }
private IDictionary <string, Unit> loadUnits(Component c) { IDictionary <string, Unit> units = new Dictionary <string, Unit>(); AbstractComponentFunctorApplication absCapp_ = br.ufc.pargo.hpe.backend.DGAC.BackEnd.acfadao.retrieve(c.Id_functor_app); AbstractComponentFunctorApplication absCapp = null; while (absCapp_ != null) { absCapp = absCapp_; absCapp_ = br.ufc.pargo.hpe.backend.DGAC.BackEnd.acfadao.retrieve_next(absCapp_.Id_functor_app); } int id_abstract = absCapp.Id_abstract; // for each unit ... foreach (UnitType u in unit) { string uref = u.uRef; string iRef = u.iRef; int partition_index = u.replicaSpecified ? u.replica : 0; string uRefSuper = u.super.Length == 0 ? "" : u.super[0].uRef; for (int j = 1; j < u.super.Length; j++) { uRefSuper += "+" + u.super[j].uRef; } Interface i = br.ufc.pargo.hpe.backend.DGAC.BackEnd.idao.retrieve(id_abstract, uref); InterfaceType ui = lookForInterface(iRef); Unit uu = new Unit(); uu.Id_concrete = c.Id_concrete; uu.Id_unit = uref; uu.Id_abstract = id_abstract; uu.Id_interface = uref; uu.Id_unit_super = uRefSuper; // uu.Unit_replica = partition_index; uu.Class_name = xc.header.packagePath + "." + xc.header.name + "." + iRef; uu.Class_nargs = i.Class_nargs; uu.Assembly_string = uu.Class_name + ", Culture=neutral, Version=0.0.0.0"; // In the current implementation, the name of the dll is the name of the class of the unit. uu.Order = i.Order; units.Add(uu.Id_unit, uu); //Console.WriteLine("ui.sources={0}",ui.sources); //Console.WriteLine("ui.protocol={0}",ui.protocol); //Console.WriteLine("{0}={1}", c.Kind, Constants.KIND_COMPUTATION_NAME); if (ui.sources == null && (c.Kind.Equals(Constants.KIND_COMPUTATION_NAME) || c.Kind.Equals(Constants.KIND_SYNCHRONIZER_NAME))) { Console.WriteLine("ENTER WRAPPER GENERATOR " + c.Library_path); IWrapperGenerator wg = new WrapperGenerator(); string[] dependencies = null; CodeCompileUnit compile_unit = wg.create_wrapper(c.Library_path, ui.iRef, uu.Id_abstract, uu.Id_interface, out dependencies); string source_code = wg.generate_source_code(ui.iRef, compile_unit); Console.WriteLine(source_code); SourceCode ss = new SourceCode(); ss.Type_owner = 'u'; ss.Id_owner_container = uu.Id_concrete; ss.Id_owner = uu.Id_unit; ss.Contents = source_code; ss.File_type = "dll"; ss.File_name = ui.iRef + ".cs"; ss.Order = 0; br.ufc.pargo.hpe.backend.DGAC.BackEnd.scdao.insert(ss); } else if (ui.sources != null) { int order = 0; foreach (SourceFileType sft in ui.sources[ui.sources.Length - 1].file) { if (sft.srcType.Equals("user") || sft.srcType.Equals("base")) { Console.WriteLine("loadUnits - 1 " + sft.name); SourceCode ss = new SourceCode(); ss.Type_owner = 'u'; ss.Id_owner_container = uu.Id_concrete; ss.Id_owner = uu.Id_unit; ss.Contents = sft.contents; ss.File_type = "dll"; ss.File_name = sft.name; ss.Order = order++; br.ufc.pargo.hpe.backend.DGAC.BackEnd.scdao.insert(ss); Console.WriteLine("loadUnits - 2"); int size = (sft.externalDependency == null ? 0 : sft.externalDependency.Length) + (ui.externalReferences == null ? 0 : ui.externalReferences.Length); Console.WriteLine("loadUnits - 3"); if (size > 0) { Console.WriteLine("loadUnits - 4"); string[] allRefs = new string[size]; if (ui.externalReferences != null) { ui.externalReferences.CopyTo(allRefs, 0); } if (sft.externalDependency != null) { sft.externalDependency.CopyTo(allRefs, ui.externalReferences == null ? 0 : ui.externalReferences.Length); } Console.WriteLine("loadUnits - 5"); foreach (string extRef in allRefs) { Console.WriteLine("loadUnits - 6 - " + extRef); SourceCodeReference ssr = new SourceCodeReference(); ssr.Type_owner = ss.Type_owner; ssr.Id_owner_container = ss.Id_owner_container; ssr.Id_owner = ss.Id_owner; ssr.File_name = ss.File_name; ssr.Reference = extRef; if (br.ufc.pargo.hpe.backend.DGAC.BackEnd.scrdao.retrieve(ssr) == null) { br.ufc.pargo.hpe.backend.DGAC.BackEnd.scrdao.insert(ssr); } Console.WriteLine("loadUnits - 7 - " + extRef); } } } else if (sft.srcType.Equals("platform.settings")) { SourceCode ss = new SourceCode(); ss.Type_owner = 'u'; ss.Id_owner_container = uu.Id_concrete; ss.Id_owner = uu.Id_unit; ss.Contents = sft.contents; ss.File_type = "platform.settings"; ss.File_name = sft.name; ss.Order = order++; br.ufc.pargo.hpe.backend.DGAC.BackEnd.scdao.insert(ss); } } } else { throw new Exception("Unit " + uu.Id_unit + " neither has a source code nor is a connector."); } UnitDAO udao = new UnitDAO(); udao.insert(uu); } return(units); }