Inheritance: SourceGenerator, ICiSymbolVisitor
コード例 #1
0
ファイル: CiTo.cs プロジェクト: jellonek/cito
        public static int Main(string[] args)
        {
            CiParser      parser     = new CiParser();
            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 1.0.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");
                        }
                        parser.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);
            }
            GenBase gen;

            switch (lang)
            {
            case "c": gen = new GenC(); break;

            case "cpp": gen = new GenCpp(); break;

            case "cs": gen = new GenCs(); break;

            case "java": gen = new GenJava(); break;

            case "js": gen = new GenJs(); break;

            default: throw new ArgumentException("Unknown language: " + lang);
            }
            gen.Namespace  = namespace_;
            gen.OutputFile = outputFile;

            CiProgram program;

            try {
                foreach (string inputFile in inputFiles)
                {
                    parser.Parse(inputFile, File.OpenText(inputFile));
                }
                program = parser.Program;
                new CiResolver(program, searchDirs);
            } catch (CiException ex) {
                Console.Error.WriteLine("{0}({1}): ERROR: {2}", ex.Filename, ex.Line, ex.Message);
                return(1);
//			throw;
            }

            gen.Write(program);
            return(0);
        }
コード例 #2
0
ファイル: CiTo.cs プロジェクト: pfusik/cito
        public static int Main(string[] args)
        {
            CiParser      parser          = new CiParser();
            List <string> inputFiles      = new List <string>();
            List <string> referencedFiles = 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 1.0.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");
                        }
                        parser.PreSymbols.Add(symbol);
                        break;

                    case "-r":
                        referencedFiles.Add(args[++i]);
                        break;

                    case "-I":
                        searchDirs.Add(args[++i]);
                        break;

                    default:
                        throw new ArgumentException("Unknown option: " + arg);
                    }
                }
                else
                {
                    inputFiles.Add(arg);
                }
            }
            if (lang == null && outputFile != null)
            {
                if (outputFile.EndsWith(".d.ts"))
                {
                    lang = "d.ts";
                }
                else
                {
                    string ext = Path.GetExtension(outputFile);
                    if (ext.Length >= 2)             // have an extension?
                    {
                        lang = ext.Substring(1);     // skip the dot
                    }
                }
            }
            if (lang == null || outputFile == null || inputFiles.Count == 0)
            {
                Usage();
                return(1);
            }
            GenBase gen;

            switch (lang)
            {
            case "c": gen = new GenC(); break;

            case "cpp": gen = new GenCpp(); break;

            case "cs": gen = new GenCs(); break;

            case "java": gen = new GenJava(); break;

            case "js": gen = new GenJs(); break;

            case "py": gen = new GenPy(); break;

            case "swift": gen = new GenSwift(); break;

            case "ts": gen = new GenTs().WithGenFullCode(); break;

            case "d.ts": gen = new GenTs(); break;

            case "cl": gen = new GenCl(); break;

            default: throw new ArgumentException("Unknown language: " + lang);
            }
            gen.Namespace  = namespace_;
            gen.OutputFile = outputFile;

            CiProgram program;

            try {
                CiScope parent = CiSystem.Value;
                if (referencedFiles.Count > 0)
                {
                    parent = ParseAndResolve(parser, parent, referencedFiles, searchDirs, lang);
                }
                program = ParseAndResolve(parser, parent, inputFiles, searchDirs, lang);
            } catch (CiException ex) {
                Console.Error.WriteLine("{0}({1}): ERROR: {2}", ex.Filename, ex.Line, ex.Message);
                return(1);
//			throw;
            }

            gen.Write(program);
            return(0);
        }
コード例 #3
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);
        }
コード例 #4
0
ファイル: CiTo.cs プロジェクト: epi/cito
        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;
        }