PrintMacroStack() публичный Метод

public PrintMacroStack ( ) : void
Результат void
Пример #1
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);
        }
Пример #2
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;
        }