Example #1
0
        public void TestCppGenerator()
        {
            IOutputGenerator generator  = new CppGenerator("tstNSpace");
            string           outputCode = generator.generateCode(tstAnalysisResult);

            //ToDo
        }
Example #2
0
        Generator CreateGenerator()
        {
            Generator generator = null;

            switch (Options.GeneratorKind)
            {
            case GeneratorKind.C:
                generator = new CGenerator(Context);
                break;

            case GeneratorKind.CPlusPlus:
                generator = new CppGenerator(Context);
                break;

            case GeneratorKind.ObjectiveC:
                generator = new ObjCGenerator(Context);
                break;

            case GeneratorKind.Java:
                generator = new JavaGenerator(Context);
                break;

            default:
                throw new NotImplementedException();
            }

            return(generator);
        }
Example #3
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");
        }
Example #4
0
        private static void Main(string[] args)
        {
            IGenerator generator = new CppGenerator();

            DirectoryInfo curDir = new DirectoryInfo(Environment.CurrentDirectory);

            curDir = curDir.Parent.Parent.Parent;
            generator.WorkingDirectory = curDir;
            generator.Generate();
        }
Example #5
0
        public void CompileFile(TextFile file)
        {
            var raw      = Scanner.Scanner.ScanFile(file);
            var prepared = TokenPreparation.Apply(raw);
            var block    = new BlockLineGrouping().Group(prepared);
            var ast      = Parser.Parser.ParseBlock(block, InjectedContext);
            //var cppFileName = GetTempFileName(Path.GetFileNameWithoutExtension(file.Filename), extension: "cpp");
            var cppFileName = Path.ChangeExtension(file.Filename, extension: "cpp") ?? "test.cpp"; // use this for debugging cpp output

            using (var writer = File.CreateText(cppFileName)) {
                CppGenerator.Generate(writer, ast);
            }
            RunCppCompiler(cppFileName, Path.ChangeExtension(file.Filename, extension: "exe"));
        }
Example #6
0
        static void Main(string[] args)
        {
            string solutionPath = @"D:\Project File\OTCDerivativesCalculatorModule\";

            string xsdFolder = solutionPath + @"Project_CSharp\CodeGen\FpmlSerializedCodeGenerator\XSD_File\";
            //string rootFolder = @"D:\Project File\OTCDerivativesCalculatorModule\Project_CSharp\RiskMonitor\Model\GeneratedClass\";
            //string rootViewModelFolder = @"D:\Project File\OTCDerivativesCalculatorModule\Project_CSharp\RiskMonitor\Model\GeneratedClass\ViewModel";

            string rootFolder          = @"D:\Project File\OTCDerivativesCalculatorModule\Excel_Interface2\GeneratedClass\";
            string rootViewModelFolder = @"D:\Project File\OTCDerivativesCalculatorModule\Excel_Interface2\GeneratedClass\ViewModel";

            string relFolder = @"GeneratedCode\";

            CSharpGenerator genCSharp = new CSharpGenerator(xsdFolder, rootFolder, relFolder, false);

            genCSharp.generate();

            CSharpGenerator genViewModeCSharp = new CSharpGenerator(xsdFolder, rootViewModelFolder, relFolder, true);

            genViewModeCSharp.generate();


            //----------------------------

            rootFolder = @"D:\Project File\OTCDerivativesCalculatorModule\Project_Cpp\lib_static\xmlFactory\GenClass\";
            relFolder  = @"GenClass\";
            //xsdFolder = @"D:\Project\2010\Project C++\OTCDerivativesCalculatorModule\FpmlSerialized\XSD\confirmation\";

            string filterString = "";

            Console.Write("filter string input : ");
            //filterString = Console.ReadLine();

            CppGenerator genCpp = new CppGenerator(xsdFolder, rootFolder, relFolder);

            genCpp.filterStr_ = filterString;

            genCpp.generate();
        }
Example #7
0
        protected override void ExportNamespace(Namespace ns)
        {
            var joinedTypes = new ListDictionary <string, DataType>();
            var lonelyTypes = new List <DataType>();

            foreach (var dt in ns.Types)
            {
                ClassifyTypes(ns, dt, joinedTypes, lonelyTypes);
            }

            foreach (var list in joinedTypes)
            {
                CppGenerator.ExportTypes(Environment, Essentials, this, ns, list.Key, list.Value);
            }
            foreach (var item in lonelyTypes)
            {
                CppGenerator.ExportType(Environment, Essentials, this, item);
            }

            foreach (var child in ns.Namespaces)
            {
                ExportNamespace(child);
            }
        }
Example #8
0
        public void GenerateCppSource()
        {
            var t_Schema = new Schema
            {
                Tables = new List <Table>
                {
                    new Table
                    {
                        Name    = "TestTable",
                        Columns = new Dictionary <int, Column>
                        {
                            { 0, new Column {
                                  Name = "Id", Type = COLUMN_DATA_TYPE.INTEGER
                              } }
                        }
                    }
                }
            };

            var t_CppGen = new CppGenerator();
            var t_Files  = t_CppGen.GenerateSource(t_Schema);

            Assert.IsTrue(t_Files.Count == 1 && t_Files[0].Name == "TestTableDTO.h" && t_Files[0].Content.Length > 0);
        }
Example #9
0
        static void Main(string[] args)
        {
            // Create a parser
            ClangParser parser = new ClangParser(Bootstrap.Source);

            parser.AddFile(Bootstrap.Source + @"\System\System.h");
            //foreach (string header in Directory.EnumerateFiles(Bootstrap.Source + @"\System\Base", "*.h", SearchOption.AllDirectories))//.Take(5))
            //    parser.AddFile(header);

            CppGenerator generator = new CppGenerator();

            // Generate sample reflection
            using (TextWriter output = new StreamWriter(Bootstrap.Source + @"\[Tests]\Parser.Cpp\Reflection.Generated.cpp"))
            {
                output.WriteLine("#include <System/System.h>");
                output.WriteLine("#include \"Reflection.h\"");
                output.WriteLine();

                output.WriteLine("#pragma const_seg(push, reflection, \".reflection\")");
                output.WriteLine();
                output.WriteLine("#define " + none + " -1");
                output.WriteLine("#define _ -1");
                output.WriteLine();
                output.WriteLine("#define N IdentifierType::Namespace");
                output.WriteLine("#define T IdentifierType::Type");
                output.WriteLine();

                output.WriteLine("static const Namespace _reflection_namespaces[] =");
                output.WriteLine("{");
                output.WriteLine("    // Parent, Name");

                #region Namespaces

                List <Namespace> namespaces = parser.Namespaces.ToList();

                while (true)
                {
                    Namespace[] subNamespaces = namespaces.SelectMany(n => n.Namespaces)
                                                .Except(namespaces)
                                                .ToArray();

                    if (subNamespaces.Length == 0)
                    {
                        break;
                    }

                    namespaces.AddRange(subNamespaces);
                }

                namespaces = namespaces.Where(n => n.Name != "std")
                             .ToList();

                foreach (Namespace ns in namespaces)
                {
                    int parentIndex = namespaces.IndexOf(ns.Parent as Namespace);

                    output.WriteLine(string.Format("    {{ {0}, \"{1}\" }}, // {2}",
                                                   parentIndex >= 0 ? ("0x" + parentIndex.ToString("X4")) : none,
                                                   ns.Name,
                                                   ns.ToIdentifier(generator)));
                }

                #endregion

                output.WriteLine("};");
                output.WriteLine();

                output.WriteLine("static const Type _reflection_types[] =");
                output.WriteLine("{");
                output.WriteLine("    // Parent, Name, TypeId");

                #region Types

                List <Type> types = Types.All.ToList();
                types.AddRange(parser.Types);

                foreach (Namespace ns in namespaces)
                {
                    types.AddRange(ns.Types);
                }

                types = types.Where(t => !(t is Type.Alias) && !t.Templates.Any())
                        .Where(t => !t.Name.Contains("RTTI"))
                        .Where(t => t.Name != "type_info")
                        .ToList();

                //types = types.Where(t => t.Name == "String").Take(1).ToList();

                foreach (Type type in types)
                {
                    int parentIndex = namespaces.IndexOf(type.Parent as Namespace);

                    output.WriteLine(string.Format("    {{ {{ N, {0} }}, \"{1}\", &typeid({2}) }},",
                                                   parentIndex >= 0 ? ("0x" + parentIndex.ToString("X4")) : none,
                                                   type.Name,
                                                   type.ToIdentifier(generator)));
                }

                #endregion

                output.WriteLine("};");
                output.WriteLine();

                //output.WriteLine("static const Method _reflection_methods[] =");
                //output.WriteLine("{");
                //output.WriteLine("    // Parent, Name, Pointer");

                #region Methods

                // TODO: Add global and namespace methods

                List <Method> methods = new List <Method>();

                foreach (Type type in types)
                {
                    methods.AddRange(type.Methods);
                }

                methods = methods.Where(m => !m.Templates.Any())
                          .Where(m => m.Modifiers.HasFlag(Modifiers.Public))
                          .Where(m => m.Name != m.Parent?.Name)
                          .Where(m => !m.Modifiers.HasFlag(Modifiers.Virtual))
                          .ToList();

                foreach (Method method in methods)
                {
                    int parentIndex = types.IndexOf(method.Parent as Type);

                    //output.WriteLine(string.Format("    {{ {{ T, {0} }}, \"{1}\", (void*)&{2} }},",
                    //                     parentIndex >= 0 ? ("0x" + parentIndex.ToString("X4")) : none,
                    //                     method.Name,
                    //                     method.ToIdentifier(generator)));
                }

                #endregion

                //output.WriteLine("};");
                //output.WriteLine();

                output.WriteLine("static const Field _reflection_fields[] =");
                output.WriteLine("{");
                output.WriteLine("    // Parent, Name, Type");

                #region Fields

                List <Field> fields = new List <Field>();

                foreach (Type type in types)
                {
                    fields.AddRange(type.Fields);
                }

                fields = fields.Where(f => f.Modifiers.HasFlag(Modifiers.Public))
                         .ToList();

                //fields = fields.Where(t => t.Name == "String").Take(1).ToList();

                foreach (Field field in fields)
                {
                    int parentIndex = types.IndexOf(field.Parent as Type);



                    int typeIndex = types.IndexOf((field.Type as Type.Alias)?.Type ?? field.Type);

                    output.WriteLine(string.Format("    {{ {{ T, {0} }}, \"{1}\", 0x{2:x4} }}, // {3}",
                                                   parentIndex >= 0 ? ("0x" + parentIndex.ToString("X4")) : none,
                                                   field.Name,
                                                   typeIndex,
                                                   field.ToIdentifier(generator)));
                }

                #endregion

                output.WriteLine("};");
                output.WriteLine();

                if (texts.Count > 0)
                {
                    output.WriteLine("static const char* texts[] =");
                    output.WriteLine("{");

                    // Output texts
                    foreach (string text in texts)
                    {
                        output.WriteLine(string.Format("    \"{0}\",", text));
                    }

                    output.WriteLine("};");
                    output.WriteLine();
                }

                output.WriteLine("#pragma const_seg(pop, reflection)");
            }

            // Exit
            //Console.WriteLine();
            //Console.WriteLine("Press any key to exit ...");
            //Console.ReadKey(true);
        }