public override void Write(CiProgram program) { this.WrittenClasses.Clear(); this.StringEquals = false; this.StringLength = false; OpenStringWriter(); foreach (CiClass klass in program.Classes) { this.CurrentClass = klass; WriteConstructor(klass); WriteDestructor(klass); foreach (CiMethod method in klass.Methods) { Write(klass, method); } } CreateFile(this.OutputFile); WriteTopLevelNatives(program); WriteTypedefs(program, true); foreach (CiClass klass in program.Classes) { WriteSignatures(klass, true); } WriteTypedefs(program, false); foreach (CiClass klass in program.Classes) { WriteStruct(klass); } WriteResources(program.Resources); WriteLibrary(); CloseStringWriter(); CloseFile(); }
protected void WriteTopLevelNatives(CiProgram program) { foreach (string content in program.TopLevelNatives) { Write(content); } }
protected override void WritePragmas(CiProgram prog) { if (prog.Globals.OfType <CiClass>().Any(klass => HasSwitch(klass))) { WriteLine("use feature 'switch';"); } }
public override void Write(CiProgram prog) { foreach (CiSymbol symbol in prog.Globals) { symbol.Accept(this); } }
public override void Write(CiProgram prog) { CreateFile(this.OutputFile); WritePragmas(prog); #if USE_INTEGER WriteLine("use integer;"); #endif WriteLine("use strict;"); WriteLine(); // Write enums first, otherwise // given (foo) { when (Enum::VALUE()) { ... } } // won't work as expected. foreach (CiSymbol symbol in prog.Globals) { if (symbol is CiEnum) { Write((CiEnum)symbol); } } foreach (CiSymbol symbol in prog.Globals) { if (symbol is CiClass) { Write((CiClass)symbol); } } WriteLine("1;"); CloseFile(); }
public override void Write(CiProgram program) { CreateFile(this.OutputFile); if (this.Namespace != null) { Write("namespace "); WriteLine(this.Namespace); OpenBlock(); } WriteTopLevelNatives(program); foreach (CiEnum enu in program.OfType <CiEnum>()) { Write(enu); } foreach (CiClass klass in program.Classes) { Write(klass); } if (program.Resources.Count > 0) { WriteResources(program.Resources); } if (this.Namespace != null) { CloseBlock(); } CloseFile(); }
public override void Write(CiProgram prog) { CreateFile(this.OutputFile); this.UsesSubstringMethod = false; this.UsesCopyArrayMethod = false; this.UsesBytesToStringMethod = false; this.UsesClearArrayMethod = false; foreach (CiSymbol symbol in prog.Globals) { if (symbol is CiClass) { ((CiClass)symbol).WriteStatus = CiWriteStatus.NotYet; } } foreach (CiSymbol symbol in prog.Globals) { if (symbol is CiEnum) { Write((CiEnum)symbol); } else if (symbol is CiClass) { Write((CiClass)symbol); } } WriteBuiltins(); CloseFile(); }
public override void Write(CiProgram prog) { CreateFile(this.OutputFile); WriteLine("import std.utf;"); foreach (CiSymbol symbol in prog.Globals) { symbol.Accept(this); } CloseFile(); }
public override void Write(CiProgram prog) { CreateFile(this.OutputFile); if (this.Namespace != null) { Write("namespace "); WriteLine(this.Namespace); OpenBlock(); } foreach (CiSymbol symbol in prog.Globals) { symbol.Accept(this); } if (this.Namespace != null) { CloseBlock(); } CloseFile(); }
public override void Write(CiProgram prog) { CreateFile(this.OutputFile); this.UsesSubstringMethod = false; this.UsesCopyArrayMethod = false; this.UsesBytesToStringMethod = false; this.UsesClearArrayMethod = false; foreach (CiSymbol symbol in prog.Globals) if (symbol is CiClass) ((CiClass) symbol).WriteStatus = CiWriteStatus.NotYet; foreach (CiSymbol symbol in prog.Globals) { if (symbol is CiEnum) Write((CiEnum) symbol); else if (symbol is CiClass) Write((CiClass) symbol); } WriteBuiltins(); CloseFile(); }
public override void Write(CiProgram program) { CreateFile(this.OutputFile); WriteLine(); WriteLine("\"use strict\";"); WriteTopLevelNatives(program); foreach (CiEnum enu in program.OfType <CiEnum>()) { Write(enu); } foreach (CiClass klass in program.OfType <CiClass>()) // TODO: topological sort of class hierarchy { Write(klass); } if (program.Resources.Count > 0 || this.Library.Any(l => l != null)) { WriteLib(program.Resources); } CloseFile(); }
public void Resolve(CiProgram program) { this.Symbols = program.Globals; foreach (CiSymbol symbol in program.Globals) { if (symbol is CiClass) { ResolveBase((CiClass)symbol); } } foreach (CiSymbol symbol in program.Globals) { symbol.Accept(this); } foreach (ICiPtrType type in this.WritablePtrTypes) { MarkWritable(type); } foreach (CiMethod method in this.ThrowingMethods) { MarkThrows(method); } foreach (CiSymbol symbol in program.Globals) { if (symbol is CiClass) { MarkDead((CiClass)symbol); } } foreach (CiSymbol symbol in program.Globals) { if (symbol is CiClass) { MarkInternal((CiClass)symbol); } } }
public override void Write(CiProgram prog) { foreach (CiSymbol symbol in prog.Globals) symbol.Accept(this); }
public override void Write(CiProgram prog) { CreateFile(this.OutputFile); if (this.Namespace != null) { Write("namespace "); WriteLine(this.Namespace); OpenBlock(); } foreach (CiSymbol symbol in prog.Globals) symbol.Accept(this); if (this.Namespace != null) CloseBlock(); CloseFile(); }
public override void Write(CiProgram prog) { string headerFile = Path.ChangeExtension(this.OutputFile, "h"); CreateFile(headerFile); WriteGuard("#ifndef"); WriteGuard("#define"); WriteBoolType(); WriteLine("#ifdef __cplusplus"); WriteLine("extern \"C\" {"); WriteLine("#endif"); WriteTypedefs(prog, CiVisibility.Public); foreach (CiSymbol symbol in prog.Globals) { if (symbol is CiClass && symbol.Visibility == CiVisibility.Public) WriteSignatures((CiClass) symbol, true); } WriteLine(); WriteLine("#ifdef __cplusplus"); WriteLine("}"); WriteLine("#endif"); WriteLine("#endif"); CloseFile(); CreateFile(this.OutputFile); WriteLine("#include <stdlib.h>"); WriteLine("#include <string.h>"); Write("#include \""); Write(Path.GetFileName(headerFile)); WriteLine("\""); WriteTypedefs(prog, CiVisibility.Internal); foreach (CiSymbol symbol in prog.Globals) { if (symbol is CiClass) WriteStruct((CiClass) symbol); } foreach (CiSymbol symbol in prog.Globals) { if (symbol is CiClass) WriteCode((CiClass) symbol); } CloseFile(); }
public abstract void Write(CiProgram prog);
public override void Write(CiProgram prog) { CreateFile(this.OutputFile); WriteLine("import std.utf;"); foreach (CiSymbol symbol in prog.Globals) symbol.Accept(this); CloseFile(); }
public override void Write(CiProgram prog) { CreateFile(this.OutputFile); WritePragmas(prog); #if USE_INTEGER WriteLine("use integer;"); #endif WriteLine("use strict;"); WriteLine(); // Write enums first, otherwise // given (foo) { when (Enum::VALUE()) { ... } } // won't work as expected. foreach (CiSymbol symbol in prog.Globals) if (symbol is CiEnum) Write((CiEnum) symbol); foreach (CiSymbol symbol in prog.Globals) if (symbol is CiClass) Write((CiClass) symbol); WriteLine("1;"); CloseFile(); }
protected virtual void WritePragmas(CiProgram prog) { }
void WriteTypedefs(CiProgram prog, CiVisibility visibility) { foreach (CiSymbol symbol in prog.Globals) { if (symbol.Visibility == visibility) { if (symbol is CiEnum) Write((CiEnum) symbol); else if (symbol is CiClass) WriteTypedef((CiClass) symbol); else if (symbol is CiDelegate) ((CiDelegate) symbol).WriteStatus = CiWriteStatus.NotYet; } } foreach (CiSymbol symbol in prog.Globals) if (symbol.Visibility == visibility && symbol is CiDelegate) Write((CiDelegate) symbol); }
public static int Main(string[] args) { HashSet <string> preSymbols = new HashSet <string>(); preSymbols.Add("true"); List <string> inputFiles = new List <string>(); List <string> searchDirs = new List <string>(); string lang = null; string outputFile = null; string namespace_ = null; for (int i = 0; i < args.Length; i++) { string arg = args[i]; if (arg[0] == '-') { switch (arg) { case "--help": Usage(); return(0); case "--version": Console.WriteLine("cito 0.4.0"); return(0); case "-l": lang = args[++i]; break; case "-o": outputFile = args[++i]; break; case "-n": namespace_ = args[++i]; break; case "-D": string symbol = args[++i]; if (symbol == "true" || symbol == "false") { throw new ArgumentException(symbol + " is reserved"); } preSymbols.Add(symbol); break; case "-I": searchDirs.Add(args[++i]); break; default: throw new ArgumentException("Unknown option: " + arg); } } else { inputFiles.Add(arg); } } if (lang == null && outputFile != null) { string ext = Path.GetExtension(outputFile); if (ext.Length >= 2) { lang = ext.Substring(1); } } if (lang == null || outputFile == null || inputFiles.Count == 0) { Usage(); return(1); } CiParser parser = new CiParser(); parser.PreSymbols = preSymbols; foreach (string inputFile in inputFiles) { try { parser.Parse(inputFile, File.OpenText(inputFile)); } catch (Exception ex) { Console.Error.WriteLine("{0}({1}): ERROR: {2}", inputFile, parser.InputLineNo, ex.Message); parser.PrintMacroStack(); if (parser.CurrentMethod != null) { Console.Error.WriteLine(" in method {0}", parser.CurrentMethod.Name); } return(1); // throw; } } CiProgram program = parser.Program; CiResolver resolver = new CiResolver(); resolver.SearchDirs = searchDirs; try { resolver.Resolve(program); } catch (Exception ex) { if (resolver.CurrentClass != null) { Console.Error.Write(resolver.CurrentClass.SourceFilename); Console.Error.Write(": "); } Console.Error.WriteLine("ERROR: {0}", ex.Message); if (resolver.CurrentMethod != null) { Console.Error.WriteLine(" in method {0}", resolver.CurrentMethod.Name); } return(1); // throw; } SourceGenerator gen; switch (lang) { case "c": gen = new GenC89(); break; case "c99": gen = new GenC(); break; case "java": gen = new GenJava(namespace_); break; case "cs": gen = new GenCs(namespace_); break; case "js": gen = new GenJs(); break; case "js-ta": gen = new GenJsWithTypedArrays(); break; case "as": gen = new GenAs(namespace_); break; case "d": gen = new GenD(); break; case "pm": gen = new GenPerl58(namespace_); break; case "pm510": gen = new GenPerl510(namespace_); break; default: throw new ArgumentException("Unknown language: " + lang); } gen.OutputFile = outputFile; gen.Write(program); return(0); }
public void Load(CiProgram program, params SourceGenerator[] gens) { this.TabsToRemove = new HashSet<TabPage>(this.TabPages); foreach (SourceGenerator gen in gens) { gen.CreateTextWriter = this.CreatePadWriter; gen.Write(program); } foreach (TabPage page in this.TabsToRemove) { if (page == this.TabControl.SelectedTab) this.TabControl.SelectedIndex = -1; // WORKAROUND Mono 2.10.9 BUG: Java/AS translations disappear when changing class name this.TabControl.TabPages.Remove(page); } if (this.TabControl.SelectedIndex == -1) this.TabControl.SelectedIndex = 0; // WORKAROUND continued }
protected override void WritePragmas(CiProgram prog) { if (prog.Globals.OfType<CiClass>().Any(klass => HasSwitch(klass))) WriteLine("use feature 'switch';"); }
public void Resolve(CiProgram program) { this.Symbols = program.Globals; foreach (CiSymbol symbol in program.Globals) { if (symbol is CiClass) ResolveBase((CiClass) symbol); } foreach (CiSymbol symbol in program.Globals) symbol.Accept(this); foreach (ICiPtrType type in this.WritablePtrTypes) MarkWritable(type); foreach (CiMethod method in this.ThrowingMethods) MarkThrows(method); foreach (CiSymbol symbol in program.Globals) { if (symbol is CiClass) MarkDead((CiClass) symbol); } foreach (CiSymbol symbol in program.Globals) { if (symbol is CiClass) MarkInternal((CiClass) symbol); } }