Ejemplo n.º 1
0
        } // end of WriteSetCopy()

        /// <summary>
        /// Writes a function to copy the value of one SMV struct to another with a different floating point type, for all combinations of floating point types.
        /// </summary>
        /// <param name="S">Used for basis vector names and output language.</param>
        /// <param name="cgd">Intermediate data for code generation. Also contains plugins and cog.</param>
        public static void WriteSetCopyCrossFloat(Specification S, G25.CG.Shared.CGdata cgd, G25.FloatType dstFT, G25.SMV smv)
        {
            foreach (G25.FloatType srcFT in S.m_floatTypes)
            {
                if (srcFT.type == dstFT.type)
                {
                    continue;
                }

                cgd.m_defSB.AppendLine("");

                //string srcClassName = srcFT.GetMangledName(smv.Name);
                //string dstClassName = dstFT.GetMangledName(S, smv.Name);
                string funcName = GMV.GetSetFuncName(S);
                bool   mustCast = dstFT.MustCastIfAssigned(S, srcFT);

                G25.fgs F = new G25.fgs(funcName, funcName, "", new String[] { smv.Name }, null, new String[] { srcFT.type }, null, null, null); // null, null, null = metricName, comment, options
                F.InitArgumentPtrFromTypeNames(S);
                bool computeMultivectorValue = false;
                int  nbArgs = 1;
                G25.CG.Shared.FuncArgInfo[] FAI = G25.CG.Shared.FuncArgInfo.GetAllFuncArgInfo(S, F, nbArgs, srcFT, null, computeMultivectorValue);

                RefGA.Multivector value = G25.CG.Shared.Symbolic.SMVtoSymbolicMultivector(S, smv, FAI[0].Name, FAI[0].Pointer);

                string dstName = G25.CG.Shared.SmvUtil.THIS;
                bool   dstPtr  = false;

                bool staticFunc = false;
                G25.CG.Shared.Functions.WriteAssignmentFunction(S, cgd,
                                                                S.m_inlineSet, staticFunc, "void", null, funcName, null, FAI, dstFT, mustCast, smv, dstName, dstPtr, value);
            }
        } // end of WriteSetCopyCrossFloat()
Ejemplo n.º 2
0
        /// <summary>
        /// Writes a function to set an SMV struct to zero, for all floating point types.
        /// </summary>
        /// <param name="S">Used for basis vector names and output language.</param>
        /// <param name="cgd">Results go here. Also intermediate data for code generation. Also contains plugins and cog.</param>
        private static void WriteSetZero(Specification S, G25.CG.Shared.CGdata cgd, G25.FloatType FT, G25.SMV smv)
        {
            //if (smv.NbNonConstBasisBlade == 0) return;

            cgd.m_defSB.AppendLine("");

            string funcName = GMV.GetSetFuncName(S);
            bool   mustCast = false;

            string returnVarName = null;
            string dstName       = G25.CG.Shared.SmvUtil.THIS;
            bool   dstPtr        = false;

            bool staticFunc = false;

            G25.CG.Shared.Functions.WriteAssignmentFunction(S, cgd,
                                                            S.m_inlineSet, staticFunc, "void", returnVarName, funcName, null, null, FT, mustCast, smv, dstName, dstPtr, new RefGA.Multivector(0.0));
        } // end of WriteSetZero()
Ejemplo n.º 3
0
        } // end of WriteSetCoords()

        /// <summary>
        /// Writes a function to set an SMV struct to an array of specified coordinates, for all floating point types.
        /// </summary>
        /// <param name="S">Used for basis vector names and output language.</param>
        /// <param name="cgd">Intermediate data for code generation. Also contains plugins and cog.</param>
        public static void WriteSetArray(Specification S, G25.CG.Shared.CGdata cgd, G25.FloatType FT, G25.SMV smv)
        {
            //if (smv.NbNonConstBasisBlade == 0) return;

            cgd.m_defSB.AppendLine("");

            //string className = FT.GetMangledName(S, smv.Name);
            string funcName = GMV.GetSetFuncName(S);
            bool   mustCast = false;

            string[] argTypename = new string[2] {
                G25.CG.Shared.SmvUtil.COORDINATE_ORDER_ENUM, FT.type
            };
            string[] argName = new string[2] {
                "co", "A"
            };

            System.Collections.ArrayList L = new System.Collections.ArrayList();
            for (int i = 0; i < smv.NbNonConstBasisBlade; i++)
            {
                RefGA.BasisBlade B        = smv.NonConstBasisBlade(i);
                String           coordStr = argName[1] + "[" + i + "]";
                L.Add(new RefGA.BasisBlade(B.bitmap, B.scale, coordStr));
            }
            RefGA.Multivector mvValue = new RefGA.Multivector(L);

            G25.fgs F = new G25.fgs(funcName, funcName, "", argTypename, argName, new string[] { FT.type }, null, null, null); // null, null, null = metricName, comment, options
            F.InitArgumentPtrFromTypeNames(S);
            F.SetArgumentArr(1, true);                                                                                         // second argument is an array

            bool computeMultivectorValue = false;
            int  NB_ARGS = 2; // enum + one array of coordinates

            G25.CG.Shared.FuncArgInfo[] FAI = G25.CG.Shared.FuncArgInfo.GetAllFuncArgInfo(S, F, NB_ARGS, FT, null, computeMultivectorValue);

            string dstName = G25.CG.Shared.SmvUtil.THIS;
            bool   dstPtr  = false;

            bool staticFunc = false;

            G25.CG.Shared.Functions.WriteAssignmentFunction(S, cgd,
                                                            S.m_inlineSet, staticFunc, "void", null, funcName, null, FAI, FT, mustCast, smv, dstName, dstPtr, mvValue);
        } // end of WriteSetArray()
Ejemplo n.º 4
0
        /// <summary>
        /// Writes a function to set an SMV class to specified coordinates, for all floating point types.
        /// </summary>
        /// <param name="S">Used for basis vector names and output language.</param>
        /// <param name="cgd">Intermediate data for code generation. Also contains plugins and cog.</param>
        public static void WriteSetCoords(Specification S, G25.CG.Shared.CGdata cgd, G25.FloatType FT, G25.SMV smv)
        {
            //if (smv.NbNonConstBasisBlade == 0) return;

            cgd.m_defSB.AppendLine("");

            //string className = FT.GetMangledName(S, smv.Name);
            string funcName = GMV.GetSetFuncName(S);
            bool   mustCast = false;

            System.Collections.ArrayList L = new System.Collections.ArrayList();
            int NB_ARGS = 1 + smv.NbNonConstBasisBlade;

            string[] argTypename = new String[NB_ARGS];
            string[] argName     = new String[NB_ARGS];
            argTypename[0] = G25.CG.Shared.SmvUtil.COORDINATE_ORDER_ENUM;
            argName[0]     = "co";
            for (int i = 0; i < smv.NbNonConstBasisBlade; i++)
            {
                RefGA.BasisBlade B = smv.NonConstBasisBlade(i);
                argTypename[i + 1] = FT.type;
                string coordStr = "_" + smv.GetCoordLangID(i, S, COORD_STORAGE.VARIABLES);
                argName[i + 1] = coordStr;
                L.Add(new RefGA.BasisBlade(B.bitmap, B.scale, coordStr));
            }
            RefGA.Multivector mvValue = new RefGA.Multivector(L);


            G25.fgs F = new G25.fgs(funcName, funcName, "", argTypename, argName, new String[] { FT.type }, null, null, null); // null, null, null = metricName, comment, options
            F.InitArgumentPtrFromTypeNames(S);
            bool computeMultivectorValue = false;

            G25.CG.Shared.FuncArgInfo[] FAI = G25.CG.Shared.FuncArgInfo.GetAllFuncArgInfo(S, F, NB_ARGS, FT, null, computeMultivectorValue);

            string dstName = G25.CG.Shared.SmvUtil.THIS;
            bool   dstPtr  = false;

            bool staticFunc = false;

            G25.CG.Shared.Functions.WriteAssignmentFunction(S, cgd,
                                                            S.m_inlineSet, staticFunc, "void", null, funcName, null, FAI, FT, mustCast, smv, dstName, dstPtr, mvValue);
        } // end of WriteSetCoords()
Ejemplo n.º 5
0
        } // end of WriteSetZero()

        /// <summary>
        /// Writes a function to set an SMV struct to a scalar coordinate, for all floating point types which have a non-constant scalar coordinate.
        /// </summary>
        /// <param name="S">Used for basis vector names and output language.</param>
        /// <param name="cgd">Intermediate data for code generation. Also contains plugins and cog.</param>
        public static void WriteSetScalar(Specification S, G25.CG.Shared.CGdata cgd, G25.FloatType FT, G25.SMV smv)
        {
            //if (smv.GetElementIdx(RefGA.BasisBlade.ONE) < 0) return; // if no scalar coordinate, continue

            cgd.m_defSB.AppendLine("");

            //string className = FT.GetMangledName(S, smv.Name);
            string funcName = GMV.GetSetFuncName(S);
            bool   mustCast = false;

            System.Collections.ArrayList L = new System.Collections.ArrayList();
            const int NB_COORDS            = 1;

            string[] argTypename = new String[NB_COORDS];
            string[] argName     = new String[NB_COORDS];
            {
                RefGA.BasisBlade B = RefGA.BasisBlade.ONE;
                argTypename[0] = FT.type;
                argName[0]     = "scalarVal";
                L.Add(new RefGA.BasisBlade(B.bitmap, B.scale, argName[0]));
            }
            RefGA.Multivector mvValue = new RefGA.Multivector(L);

            G25.fgs F = new G25.fgs(funcName, funcName, "", argTypename, argName, new String[] { FT.type }, null, null, null); // null, null = metricName, comment, options
            F.InitArgumentPtrFromTypeNames(S);
            bool computeMultivectorValue = false;

            G25.CG.Shared.FuncArgInfo[] FAI = G25.CG.Shared.FuncArgInfo.GetAllFuncArgInfo(S, F, NB_COORDS, FT, null, computeMultivectorValue);

            string dstName = G25.CG.Shared.SmvUtil.THIS;
            bool   dstPtr  = false;

            bool staticFunc = false;

            G25.CG.Shared.Functions.WriteAssignmentFunction(S, cgd,
                                                            S.m_inlineSet, staticFunc, "void", null, funcName, null, FAI, FT, mustCast, smv, dstName, dstPtr, mvValue);
        }
Ejemplo n.º 6
0
        } // end of WriteSetCopyCrossFloat()

        /// <summary>
        /// Writes functions to copy GMVs to SMVs
        /// </summary>
        /// <param name="S"></param>
        /// <param name="cgd">Results go here. Also intermediate data for code generation. Also contains plugins and cog.</param>
        public static void WriteGMVtoSMVcopy(Specification S, G25.CG.Shared.CGdata cgd, G25.FloatType FT, G25.SMV smv)
        {
            StringBuilder defSB = cgd.m_defSB;

            G25.GMV gmv          = S.m_GMV;
            string  srcClassName = FT.GetMangledName(S, gmv.Name);

            //string dstClassName = FT.GetMangledName(S, smv.Name);

            bool dstPtr = false;

            string[] smvAccessStr = G25.CG.Shared.CodeUtil.GetAccessStr(S, smv, G25.CG.Shared.SmvUtil.THIS, dstPtr);

            string funcName = GMV.GetSetFuncName(S);

            string FINAL    = (S.OutputJava()) ? "final " : "";
            string funcDecl = "\tpublic " + FINAL + "void " + funcName + "(" + FINAL + srcClassName + " src)";

            defSB.Append(funcDecl);
            {
                defSB.AppendLine(" {");

                // get a dictionary which tells you for each basis blade of 'smv' where it is in 'gmv'
                // A dictionary from <smv group, smv element> to <gmv group, gmv element>
                Dictionary <Tuple <int, int>, Tuple <int, int> > D = G25.MV.GetCoordMap(smv, gmv);

                // what is the highest group of the 'gmv' that must be (partially) copied to the 'smv'
                int highestGroup = -1;
                foreach (KeyValuePair <Tuple <int, int>, Tuple <int, int> > KVP in D)
                {
                    if (KVP.Value.Value1 > highestGroup)
                    {
                        highestGroup = KVP.Value.Value1;
                    }
                }

                // generate code for each group
                for (int g = 0; g <= highestGroup; g++)
                {
                    // determine if group 'g' is to be copied to smv:
                    bool groupIsUsedBySMV = false;
                    foreach (KeyValuePair <Tuple <int, int>, Tuple <int, int> > KVP in D)
                    {
                        // KVP.Key = SMV<group, element>
                        // KVP.Value = GMV<group, element>
                        if (KVP.Value.Value1 == g)
                        {
                            if (!smv.IsCoordinateConstant(KVP.Key.Value2))
                            {
                                groupIsUsedBySMV = true;
                                break;
                            }
                        }
                    }

                    // if group is present in GMV:
                    if (groupIsUsedBySMV)
                    {
                        defSB.AppendLine("\t\tif (src.c()[" + g + "] != null) {");
                        defSB.AppendLine("\t\t\t" + FT.type + "[] ptr = src.c()[" + g + "];");
                        bool mustCast             = false;
                        bool srcPtr               = true;
                        int  nbTabs               = 3;
                        RefGA.Multivector[] value = G25.CG.Shared.Symbolic.GMVtoSymbolicMultivector(S, gmv, "ptr", srcPtr, g);
                        bool   writeZeros         = false;
                        string str = G25.CG.Shared.CodeUtil.GenerateSMVassignmentCode(S, FT, mustCast, smv, G25.CG.Shared.SmvUtil.THIS, dstPtr, value[g], nbTabs, writeZeros);
                        defSB.Append(str);
                        defSB.AppendLine("\t\t}");

                        defSB.AppendLine("\t\telse {");
                        foreach (KeyValuePair <Tuple <int, int>, Tuple <int, int> > KVP in D)
                        {
                            if ((KVP.Value.Value1 == g) && (!smv.IsCoordinateConstant(KVP.Key.Value2)))
                            {
                                // translate KVP.Key.Value2 to non-const idx, because the accessStrs are only about non-const blades blades!
                                int bladeIdx = smv.BladeIdxToNonConstBladeIdx(KVP.Key.Value2);
                                defSB.AppendLine("\t\t\t" + smvAccessStr[bladeIdx] + " = " + FT.DoubleToString(S, 0.0) + ";");
                            }
                        }
                        defSB.AppendLine("\t\t}");
                    }
                }
                defSB.AppendLine("\t}");
            }
        } // end of WriteGMVtoSMVcopy()