Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            CmdLineArgs cmdLineArgs = new CmdLineArgs(args);

            string srcPath = cmdLineArgs.GetFirstSwitchArgument(""); //direct after call

            if (srcPath == null)
            {
                Console.WriteLine("ERROR: No Input File (Tbs-Definition was given");
                DumpHelp();
                return;
            }

            Console.WriteLine($"Reading Tbs-Definition in File {srcPath}...");
            var srcCode = File.ReadAllText(srcPath);

            Console.WriteLine("Parsing Tbs-Definition...");
            var parseResult = new ParseResult(srcCode);

            Console.WriteLine("Analsing Tbs-Definition...");
            var analysisResult = new AnalysisResult(parseResult);

            Console.WriteLine(analysisResult.AnalysisLog.ToString());

            if (analysisResult.AnalysisLog.ContainsErrors)
            {
                Console.WriteLine("ERROR: Errors Occured during Tbs Analysis - aborting");
                return;
            }

            Console.WriteLine("Generating Output...");

            if (cmdLineArgs.HasSwitch("cpp"))
            {
                string nmespce = cmdLineArgs.GetFirstSwitchArgument("namespace", "TinybuffersGenerated");

                IOutputGenerator generator = new CppGenerator(nmespce);

                string outputPath = GetDefaultPath(srcPath, generator);
                outputPath = cmdLineArgs.GetFirstSwitchArgument("cpp", outputPath);

                GenerateAndSave(generator, outputPath, analysisResult);
            }

            if (cmdLineArgs.HasSwitch("cs"))
            {
                string nmespce  = cmdLineArgs.GetFirstSwitchArgument("namespace", "TinybuffersGenerated");
                bool   isPublic = cmdLineArgs.HasSwitch("public");

                IOutputGenerator generator = new CsGenerator(nmespce, isPublic);

                string outputPath = GetDefaultPath(srcPath, generator);
                outputPath = cmdLineArgs.GetFirstSwitchArgument("cs", outputPath);

                GenerateAndSave(generator, outputPath, analysisResult);
            }

            Console.WriteLine("DONE");
        }
Ejemplo n.º 2
0
        public void Test1()
        {
            var tstArgs = new CmdLineArgs("testfile.c -o out.asm -opt1 -settings f1.set f2.set f3.set");

            Assert.AreEqual(true, tstArgs.HasSwitch("o"));
            Assert.AreEqual(false, tstArgs.HasSwitch("notPresent"));
            Assert.AreEqual("out.asm", tstArgs.GetFirstSwitchArgument("o"));
            Assert.AreEqual("default", tstArgs.GetFirstSwitchArgument("notPresent", "default"));
            Assert.AreEqual("default", tstArgs.GetFirstSwitchArgument("opt1", "default"));
            Assert.AreEqual("f1.set", tstArgs.GetFirstSwitchArgument("settings"));
            Assert.AreEqual(null, tstArgs.GetSwitchArguments("notPresent"));
            Assert.AreEqual(new string[] { "f1.set", "f2.set", "f3.set" }, tstArgs.GetSwitchArguments("settings"));
        }