Beispiel #1
0
        /// <summary>
        /// Should generate the code according to the specification of the algebra.
        /// </summary>
        /// <param name="S">The specification of the algebra. The specification also lists the names of the files
        /// to be generated, or at least the base path.</param>
        /// <param name="plugins">The plugins which Gaigen found that support the same language as this code generator.</param>
        /// <returns>a list of filenames; the names of the files that were generated. This may be used
        /// for post processing.</returns>
        public List<string> GenerateCode(Specification S, List<CodeGeneratorPlugin> plugins)
        {
            // disable all inlining since the C# language does not support this:
            S.SetInlineNone();

            CoGsharp.CoG cog = InitCog(S);

            CG.Shared.CGdata cgd = new G25.CG.Shared.CGdata(plugins, cog);
            cgd.SetDependencyPrefix("missing_function_"); // this makes sure that the user sees the function call is a missing dependency
            G25.CG.Shared.FunctionGeneratorInfo FGI = (S.m_generateTestSuite) ? new G25.CG.Shared.FunctionGeneratorInfo() : null; // the fields in this variable are set by Functions.WriteFunctions() and reused by TestSuite.GenerateCode()

            { // pregenerated code that will go into main source
                // generate code for parts of the geometric product, dual, etc (works in parallel internally)
                try
                {
                    bool declOnly = false;
                    G25.CG.Shared.PartsCode.GeneratePartsCode(S, cgd, declOnly);
                }
                catch (G25.UserException E) { cgd.AddError(E); }

                // write function (works in parallel internally)
                G25.CG.Shared.Functions.WriteFunctions(S, cgd, FGI, Functions.GetFunctionGeneratorPlugins(cgd));
            }

            List<string> generatedFiles = new List<string>();

            // generate Doxyfile
            generatedFiles.Add(G25.CG.Shared.Util.GenerateDoxyfile(S, cgd));
            // generate source files / classes for all GMV, SMV, GOM, SOM types
            generatedFiles.AddRange(GenerateClasses(S, cgd));
            // generate source
            generatedFiles.AddRange(Source.GenerateCode(S, cgd));
            // generate multivector interfaces
            generatedFiles.AddRange(MvInterface.GenerateCode(S, cgd));
            // generate parser code
            generatedFiles.AddRange(Parser.GenerateCode(S, cgd));
            // generate report usage code
            generatedFiles.AddRange(ReportUsage.GenerateCode(S, cgd));
            

            // report errors and missing deps to user
            cgd.PrintErrors(S);
            cgd.PrintMissingDependencies(S);
            if ((cgd.GetNbErrors() == 0) && (cgd.GetNbMissingDependencies() == 0) && S.m_generateTestSuite)
            {
                // if no errors, then generate testing code
                TestSuite.GenerateCode(S, cgd, FGI);
            }



            return generatedFiles;
        }
Beispiel #2
0
        /// <summary>
        /// Generates a source file with the GMV class definition.
        /// </summary>
        /// <param name="S"></param>
        /// <param name="cgd"></param>
        /// <param name="FT"></param>
        /// <returns></returns>
        public static string GenerateCode(Specification S, G25.CG.Shared.CGdata cgd, FloatType FT)
        {
            G25.GMV gmv       = S.m_GMV;
            string  className = FT.GetMangledName(S, gmv.Name);

            // get filename, list of generated filenames
            List <string> generatedFiles = new List <string>();
            string        sourceFilename = MainGenerator.GetClassOutputPath(S, className);

            generatedFiles.Add(sourceFilename);

            // get StringBuilder where all generated code goes
            StringBuilder SB = new StringBuilder();

            // get a new 'cgd' where all ouput goes to the one StringBuilder SB
            cgd = new G25.CG.Shared.CGdata(cgd, SB, SB, SB);

            // output license, copyright
            G25.CG.Shared.Util.WriteCopyright(SB, S);
            G25.CG.Shared.Util.WriteLicense(SB, S);

            // using ...
            Util.WriteGenericUsing(SB, S);

            // open namespace
            G25.CG.Shared.Util.WriteOpenNamespace(SB, S);

            // write class comment
            G25.CG.CSJ.GMV.WriteComment(SB, S, cgd, FT, gmv);

            // open class
            string[] implements = new string[] { MvInterface.GetMvInterfaceName(S, FT) };
            G25.CG.Shared.Util.WriteOpenClass(SB, S, G25.CG.Shared.AccessModifier.AM_public, className, null, implements);

            // write member vars
            WriteMemberVariables(SB, S, cgd, FT, gmv);

            // write constructors
            WriteConstructors(SB, S, cgd, FT, gmv, className);

            WriteGetGuC(SB, S, cgd, FT);

            // write 'set' functions
            G25.CG.CSJ.GMV.WriteSetZero(SB, S, cgd, FT);
            G25.CG.CSJ.GMV.WriteSetScalar(SB, S, cgd, FT);
            G25.CG.CSJ.GMV.WriteSetCompressedArray(SB, S, cgd, FT);
            G25.CG.CSJ.GMV.WriteSetExpandedArray(SB, S, cgd, FT);
            G25.CG.CSJ.GMV.WriteGMVtoGMVcopy(SB, S, cgd, FT);
            G25.CG.CSJ.GMV.WriteSMVtoGMVcopy(SB, S, cgd, FT);

            // write 'get coordinate' functions
            G25.CG.CSJ.GMV.WriteGetCoord(SB, S, cgd, FT);

            // write SetGroupUsage()
            G25.CG.CSJ.GMV.WriteSetGroupUsage(SB, S, cgd, FT);

            // write 'reserve group' functions
            G25.CG.CSJ.GMV.WriteReserveGroup(SB, S, cgd, FT);

            // write 'set coordinate' functions
            G25.CG.CSJ.GMV.WriteSetCoord(SB, S, cgd, FT);

            // write 'largest coordinate' functions
            G25.CG.CSJ.GMV.WriteLargestCoordinates(SB, S, cgd, FT);

            // write compress functions
            G25.CG.CSJ.GMV.WriteCompress(SB, S, cgd, FT);

            // write 'ToString' functions
            G25.CG.CSJ.GMV.WriteToString(SB, S, cgd, FT, gmv);

            // write multivector interface implementation
            G25.CG.CSJ.GMV.WriteMultivectorInterface(SB, S, cgd, FT);


            // write shortcuts for functions
            G25.CG.Shared.Shortcut.WriteFunctionShortcuts(SB, S, cgd, FT, gmv);

            // close class
            G25.CG.Shared.Util.WriteCloseClass(SB, S, className);

            // close namespace
            G25.CG.Shared.Util.WriteCloseNamespace(SB, S);

            // write all to file
            G25.CG.Shared.Util.WriteFile(sourceFilename, SB.ToString());

            return(sourceFilename);
        }
Beispiel #3
0
        /// <summary>
        /// Generates a source file with the SMV class definition.
        /// </summary>
        /// <param name="S"></param>
        /// <param name="cgd"></param>
        /// <param name="smv"></param>
        /// <param name="FT"></param>
        /// <returns></returns>
        public static string GenerateCode(Specification S, G25.CG.Shared.CGdata cgd, G25.SMV smv, FloatType FT)
        {
            string className = FT.GetMangledName(S, smv.Name);


            // get filename, list of generated filenames
            List <string> generatedFiles = new List <string>();
            string        sourceFilename = MainGenerator.GetClassOutputPath(S, className);

            generatedFiles.Add(sourceFilename);

            // get StringBuilder where all generated code goes
            StringBuilder SB = new StringBuilder();

            // get a new 'cgd' where all ouput goes to the one StringBuilder SB
            cgd = new G25.CG.Shared.CGdata(cgd, SB, SB, SB);

            // output license, copyright
            G25.CG.Shared.Util.WriteCopyright(SB, S);
            G25.CG.Shared.Util.WriteLicense(SB, S);

            // using ...
            Util.WriteGenericUsing(SB, S);

            // open namespace
            G25.CG.Shared.Util.WriteOpenNamespace(SB, S);

            // write class comment
            G25.CG.CSJ.SMV.WriteComment(SB, S, cgd, FT, smv);

            // open class
            string[] implements = new string[] { MvInterface.GetMvInterfaceName(S, FT) };
            G25.CG.Shared.Util.WriteOpenClass(SB, S, G25.CG.Shared.AccessModifier.AM_public, className, null, implements);

            // member variables
            G25.CG.CSJ.SMV.WriteMemberVariables(SB, S, cgd, FT, smv);

            // indices into arrays
            G25.CG.CSJ.SMV.WriteSMVcoordIndices(SB, S, FT, smv);

            // special type to safeguard coordinates order in functions
            G25.CG.CSJ.SMV.WriteCoordinateOrder(SB, S, FT, smv);

            // write multivector interface implementation
            G25.CG.CSJ.SMV.WriteMultivectorInterface(SB, S, cgd, FT, smv);

            // write constructors
            G25.CG.CSJ.SMV.WriteConstructors(SB, S, cgd, FT, smv);

            // write set functions
            G25.CG.CSJ.SMV.WriteSetFunctions(SB, S, cgd, FT, smv);

            // write largest coordinate functions
            G25.CG.CSJ.SMV.WriteLargestCoordinateFunctions(S, cgd, FT, smv);

            // write 'ToString' functions
            G25.CG.CSJ.GMV.WriteToString(SB, S, cgd, FT, smv);

            // write get/set coords
            G25.CG.CSJ.SMV.WriteGetSetCoord(SB, S, cgd, FT, smv);

            // write shortcuts for functions
            G25.CG.Shared.Shortcut.WriteFunctionShortcuts(SB, S, cgd, FT, smv);

            // close class
            G25.CG.Shared.Util.WriteCloseClass(SB, S, className);

            // close namespace
            G25.CG.Shared.Util.WriteCloseNamespace(SB, S);

            // write all to file
            G25.CG.Shared.Util.WriteFile(sourceFilename, SB.ToString());

            return(sourceFilename);
        }