コード例 #1
0
ファイル: GenCl.cs プロジェクト: jedwards1211/cito
        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();
        }
コード例 #2
0
ファイル: GenBase.cs プロジェクト: jedwards1211/cito
 protected void WriteTopLevelNatives(CiProgram program)
 {
     foreach (string content in program.TopLevelNatives)
     {
         Write(content);
     }
 }
コード例 #3
0
ファイル: GenPerl510.cs プロジェクト: haifenghuang/ci
 protected override void WritePragmas(CiProgram prog)
 {
     if (prog.Globals.OfType <CiClass>().Any(klass => HasSwitch(klass)))
     {
         WriteLine("use feature 'switch';");
     }
 }
コード例 #4
0
ファイル: GenAs.cs プロジェクト: haifenghuang/ci
 public override void Write(CiProgram prog)
 {
     foreach (CiSymbol symbol in prog.Globals)
     {
         symbol.Accept(this);
     }
 }
コード例 #5
0
        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();
        }
コード例 #6
0
 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();
 }
コード例 #7
0
 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();
 }
コード例 #8
0
ファイル: GenD.cs プロジェクト: haifenghuang/ci
 public override void Write(CiProgram prog)
 {
     CreateFile(this.OutputFile);
     WriteLine("import std.utf;");
     foreach (CiSymbol symbol in prog.Globals)
     {
         symbol.Accept(this);
     }
     CloseFile();
 }
コード例 #9
0
 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();
 }
コード例 #10
0
ファイル: GenJs.cs プロジェクト: epi/cito
 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();
 }
コード例 #11
0
 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();
 }
コード例 #12
0
ファイル: CiResolver.cs プロジェクト: haifenghuang/ci
 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);
         }
     }
 }
コード例 #13
0
ファイル: GenJava.cs プロジェクト: epi/cito
 public override void Write(CiProgram prog)
 {
     foreach (CiSymbol symbol in prog.Globals)
     symbol.Accept(this);
 }
コード例 #14
0
ファイル: GenCs.cs プロジェクト: epi/cito
 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();
 }
コード例 #15
0
ファイル: GenC.cs プロジェクト: epi/cito
        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();
        }
コード例 #16
0
ファイル: SourceGenerator.cs プロジェクト: haifenghuang/ci
 public abstract void Write(CiProgram prog);
コード例 #17
0
ファイル: GenD.cs プロジェクト: epi/cito
 public override void Write(CiProgram prog)
 {
     CreateFile(this.OutputFile);
     WriteLine("import std.utf;");
     foreach (CiSymbol symbol in prog.Globals)
     symbol.Accept(this);
     CloseFile();
 }
コード例 #18
0
ファイル: GenPerl5.cs プロジェクト: epi/cito
	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();
	}
コード例 #19
0
ファイル: GenPerl5.cs プロジェクト: epi/cito
	protected virtual void WritePragmas(CiProgram prog)
	{
	}
コード例 #20
0
ファイル: GenC.cs プロジェクト: epi/cito
 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);
 }
コード例 #21
0
ファイル: CiTo.cs プロジェクト: haifenghuang/ci
        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);
        }
コード例 #22
0
ファイル: SourceGenerator.cs プロジェクト: epi/cito
 public abstract void Write(CiProgram prog);
コード例 #23
0
ファイル: CiPad.cs プロジェクト: epi/cito
 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
 }
コード例 #24
0
ファイル: GenPerl510.cs プロジェクト: epi/cito
 protected override void WritePragmas(CiProgram prog)
 {
     if (prog.Globals.OfType<CiClass>().Any(klass => HasSwitch(klass)))
     WriteLine("use feature 'switch';");
 }
コード例 #25
0
 protected virtual void WritePragmas(CiProgram prog)
 {
 }
コード例 #26
0
ファイル: CiResolver.cs プロジェクト: epi/cito
 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);
     }
 }