protected void GenChildProperties(GenerationInfo gen_info) { if (childprops.Count == 0) { return; } StreamWriter sw = gen_info.Writer; ObjectGen child_ancestor = Parent as ObjectGen; while (child_ancestor.CName != "GtkContainer" && child_ancestor.childprops.Count == 0) { child_ancestor = child_ancestor.Parent as ObjectGen; } sw.WriteLine("\t\tpublic class " + Name + "Child : " + child_ancestor.NS + "." + child_ancestor.Name + "." + child_ancestor.Name + "Child {"); sw.WriteLine("\t\t\tprotected internal " + Name + "Child (Gtk.Container parent, Gtk.Widget child) : base (parent, child) {}"); sw.WriteLine(""); foreach (ChildProperty prop in childprops.Values) { prop.Generate(gen_info, "\t\t\t", null); } sw.WriteLine("\t\t}"); sw.WriteLine(""); sw.WriteLine("\t\tpublic override Gtk.Container.ContainerChild this [Gtk.Widget child] {"); sw.WriteLine("\t\t\tget {"); sw.WriteLine("\t\t\t\treturn new " + Name + "Child (this, child);"); sw.WriteLine("\t\t\t}"); sw.WriteLine("\t\t}"); sw.WriteLine(""); }
public static int Main(string[] args) { if (args.Length < 2) { Console.WriteLine("Usage: codegen --generate <filename1...>"); return(0); } bool generate = false; string dir = ""; string custom_dir = ""; string assembly_name = ""; string glue_filename = ""; string glue_includes = ""; string gluelib_name = ""; SymbolTable table = SymbolTable.Table; ArrayList gens = new ArrayList(); foreach (string arg in args) { string filename = arg; if (arg == "--generate") { generate = true; continue; } else if (arg == "--include") { generate = false; continue; } else if (arg.StartsWith("-I:")) { generate = false; filename = filename.Substring(3); } else if (arg.StartsWith("--outdir=")) { generate = false; dir = arg.Substring(9); continue; } else if (arg.StartsWith("--customdir=")) { generate = false; custom_dir = arg.Substring(12); continue; } else if (arg.StartsWith("--assembly-name=")) { generate = false; assembly_name = arg.Substring(16); continue; } else if (arg.StartsWith("--glue-filename=")) { generate = false; glue_filename = arg.Substring(16); continue; } else if (arg.StartsWith("--glue-includes=")) { generate = false; glue_includes = arg.Substring(16); continue; } else if (arg.StartsWith("--gluelib-name=")) { generate = false; gluelib_name = arg.Substring(15); continue; } Parser p = new Parser(); IGeneratable[] curr_gens = p.Parse(filename); table.AddTypes(curr_gens); if (generate) { gens.AddRange(curr_gens); } } // Now that everything is loaded, validate all the to-be- // generated generatables and then remove the invalid ones. ArrayList invalids = new ArrayList(); foreach (IGeneratable gen in gens) { if (!gen.Validate()) { invalids.Add(gen); } } foreach (IGeneratable gen in invalids) { gens.Remove(gen); } GenerationInfo gen_info = null; if (dir != "" || assembly_name != "" || glue_filename != "" || glue_includes != "" || gluelib_name != "") { gen_info = new GenerationInfo(dir, custom_dir, assembly_name, glue_filename, glue_includes, gluelib_name); } foreach (IGeneratable gen in gens) { if (gen_info == null) { gen.Generate(); } else { gen.Generate(gen_info); } } ObjectGen.GenerateMappers(); if (gen_info != null) { gen_info.CloseGlueWriter(); } Statistics.Report(); return(0); }
public static int Main(string[] args) { bool show_help = false; bool all_opaque = true; string dir = ""; string assembly_name = ""; string gapidir = ""; string abi_cs_usings = ""; string abi_cs_file = ""; string abi_c_file = ""; string glue_filename = ""; string glue_includes = ""; string gluelib_name = ""; string schema_name = ""; SymbolTable table = SymbolTable.Table; var gens = new List <IGeneratable> (); var filenames = new List <string> (); var includes = new List <string> (); var options = new OptionSet() { { "generate=", "Generate the C# code for this GAPI XML file.", (string v) => { filenames.Add(v); } }, { "I|include=", "GAPI XML file that contain symbols used in the main GAPI XML file.", (string v) => { includes.Add(v); } }, { "outdir=", "Directory where the C# files will be generated.", (string v) => { dir = v; } }, { "assembly-name=", "Name of the assembly for which the code is generated.", (string v) => { assembly_name = v; } }, { "gapidir=", "GAPI xml data folder.", (string v) => { gapidir = v; } }, { "abi-cs-filename=", "Filename for the generated CSharp ABI checker.", (string v) => { abi_cs_file = v; } }, { "abi-cs-usings=", "Namespaces to use in the CS ABI checker.", (string v) => { abi_cs_usings = v; } }, { "abi-c-filename=", "Filename for the generated C ABI checker.", (string v) => { abi_c_file = v; } }, { "glue-filename=", "Filename for the generated C glue code.", (string v) => { glue_filename = v; } }, { "glue-includes=", "Content of #include directive to add in the generated C glue code.", (string v) => { glue_includes = v; } }, { "gluelib-name=", "Name of the C library into which the C glue code will be compiled. " + "Used to generated correct DllImport attributes.", (string v) => { gluelib_name = v; } }, { "schema=", "Validate all GAPI XML files against this XSD schema.", (string v) => { schema_name = v; } }, { "h|help", "Show this message and exit", v => show_help = v != null }, }; List <string> extra; try { extra = options.Parse(args); } catch (OptionException e) { Console.Write("gapi-codegen: "); Console.WriteLine(e.Message); Console.WriteLine("Try `gapi-codegen --help' for more information."); return(64); } if (show_help) { ShowHelp(options); return(0); } if (filenames.Count == 0) { Console.WriteLine("You need to specify a file to process using the --generate option."); Console.WriteLine("Try `gapi-codegen --help' for more information."); return(64); } if (extra.Exists(v => { return(v.StartsWith("--customdir")); })) { Console.WriteLine("Using .custom files is not supported anymore, use partial classes instead."); return(64); } if (!String.IsNullOrEmpty(schema_name) && !File.Exists(schema_name)) { Console.WriteLine("WARNING: Could not find schema file at '{0}', no validation will be done.", schema_name); schema_name = null; } Parser p = new Parser(); foreach (string include in includes) { log.Info("Parsing included gapi: " + include); IGeneratable[] curr_gens = p.Parse(include, schema_name, gapidir); table.AddTypes(curr_gens); } foreach (string filename in filenames) { log.Info("Parsing included gapi: " + filename); IGeneratable[] curr_gens = p.Parse(filename, schema_name, gapidir); table.AddTypes(curr_gens); gens.AddRange(curr_gens); } // Now that everything is loaded, validate all the to-be- // generated generatables and then remove the invalid ones. var invalids = new List <IGeneratable> (); foreach (IGeneratable gen in gens) { if (!gen.Validate()) { invalids.Add(gen); } } foreach (IGeneratable gen in invalids) { gens.Remove(gen); } GenerationInfo gen_info = null; if (dir != "" || assembly_name != "" || glue_filename != "" || glue_includes != "" || gluelib_name != "") { gen_info = new GenerationInfo(dir, assembly_name, glue_filename, glue_includes, gluelib_name, abi_c_file, abi_cs_file, abi_cs_usings); } foreach (IGeneratable gen in gens) { if (gen_info == null) { gen.Generate(); } else { gen.Generate(gen_info); } } ObjectGen.GenerateMappers(); if (gen_info != null) { gen_info.CloseWriters(); } Statistics.Report(); return(0); }