Exemple #1
0
        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();
        }
Exemple #2
0
 protected void WriteTopLevelNatives(CiProgram program)
 {
     foreach (string content in program.TopLevelNatives)
     {
         Write(content);
     }
 }
Exemple #3
0
 protected override void WritePragmas(CiProgram prog)
 {
     if (prog.Globals.OfType <CiClass>().Any(klass => HasSwitch(klass)))
     {
         WriteLine("use feature 'switch';");
     }
 }
Exemple #4
0
 public override void Write(CiProgram prog)
 {
     foreach (CiSymbol symbol in prog.Globals)
     {
         symbol.Accept(this);
     }
 }
Exemple #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();
        }
Exemple #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();
 }
Exemple #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();
 }
Exemple #8
0
 public override void Write(CiProgram prog)
 {
     CreateFile(this.OutputFile);
     WriteLine("import std.utf;");
     foreach (CiSymbol symbol in prog.Globals)
     {
         symbol.Accept(this);
     }
     CloseFile();
 }
Exemple #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();
 }
Exemple #10
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();
 }
Exemple #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();
 }
Exemple #12
0
 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);
         }
     }
 }
Exemple #13
0
 public override void Write(CiProgram prog)
 {
     foreach (CiSymbol symbol in prog.Globals)
     symbol.Accept(this);
 }
Exemple #14
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();
 }
Exemple #15
0
Fichier : GenC.cs Projet : 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();
        }
Exemple #16
0
 public abstract void Write(CiProgram prog);
Exemple #17
0
Fichier : GenD.cs Projet : 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();
 }
Exemple #18
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();
	}
Exemple #19
0
	protected virtual void WritePragmas(CiProgram prog)
	{
	}
Exemple #20
0
Fichier : GenC.cs Projet : 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);
 }
Exemple #21
0
        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);
        }
Exemple #22
0
 public abstract void Write(CiProgram prog);
Exemple #23
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
 }
Exemple #24
0
 protected override void WritePragmas(CiProgram prog)
 {
     if (prog.Globals.OfType<CiClass>().Any(klass => HasSwitch(klass)))
     WriteLine("use feature 'switch';");
 }
Exemple #25
0
 protected virtual void WritePragmas(CiProgram prog)
 {
 }
Exemple #26
0
 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);
     }
 }