Exemplo n.º 1
0
        } // end of WriteFunction()

        /// <summary>
        /// Writes a function to 'SB' which assigns a certain 'value' to a certain 'dstName'.
        /// </summary>
        /// <param name="S">Used for all kinds of stuff.</param>
        /// <param name="cgd">Results go into cgd.m_defSB, and so on</param>
        /// <param name="inline">Should the function we inline?</param>
        /// <param name="staticFunc">Static function?</param>
        /// <param name="returnType">String which speficies the return type.</param>
        /// <param name="returnVarName">The name of the variable which should be returned. Should be one of the argument names.</param>
        /// <param name="functionName">The name of the function which is to be generated.</param>
        /// <param name="arguments">Array of FuncArg which describes the arguments of the function.</param>
        /// <param name="dstFT">Floating point type of destination variable.</param>
        /// <param name="mustCastDst">set to true if coordinates of 'value' must be cast to 'dstFT'.</param>
        /// <param name="dstSmv">G25.SMV type of destination.</param>
        /// <param name="dstName">Name of destination.</param>
        /// <param name="dstPtr">Is the destination a pointer?</param>
        /// <param name="value">Value to be written to the destination.</param>
        /// <param name="returnArgument">For use with the 'C' language, an extra argument can be used to return results.</param>
        public static void WriteAssignmentFunction(
            Specification S, G25.CG.Shared.CGdata cgd,
            bool inline, bool staticFunc, string returnType, string returnVarName, string functionName,
            FuncArgInfo returnArgument, FuncArgInfo[] arguments,
            FloatType dstFT, bool mustCastDst, G25.SMV dstSmv, string dstName, bool dstPtr, RefGA.Multivector value)
        {
            // where the definition goes:
            StringBuilder defSB = (inline) ? cgd.m_inlineDefSB : cgd.m_defSB;

            // write declaration yes/no?
            bool writeDecl = (!(dstName.Equals(G25.CG.Shared.SmvUtil.THIS) && S.OutputCpp())) && // no declarations for C++ member functions
                             (!S.OutputCSharpOrJava());                                          // no declarations in C# and Java

            if (writeDecl)
            {
                WriteDeclaration(cgd.m_declSB, S, cgd, inline, staticFunc, returnType, functionName, returnArgument, arguments);
                cgd.m_declSB.AppendLine(";");
            }

            WriteDeclaration(defSB, S, cgd, inline, staticFunc, returnType, functionName, returnArgument, arguments);

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

            int  nbTabs          = 1;
            bool declareVariable = false;
            AssignInstruction AI = new AssignInstruction(nbTabs, dstSmv, dstFT, mustCastDst, value, dstName, dstPtr, declareVariable);

            AI.Write(defSB, S, cgd);

            if (returnVarName != null)
            {
                defSB.AppendLine("\treturn " + returnVarName + ";");
            }
            else if (returnArgument != null)
            {
                defSB.AppendLine("\treturn " + returnArgument.Name + ";");
            }

            defSB.AppendLine("}");
        } // end of WriteAssignmentFunction()
Exemplo n.º 2
0
        private static void WriteConvertingConstructor(StringBuilder SB, Specification S, G25.CG.Shared.CGdata cgd, FloatType FT, G25.fgs fgs, SMV srcSmv, SMV dstSmv)
        {
            string  srcTypeName = FT.GetMangledName(S, srcSmv.GetName());
            string  dstTypeName = FT.GetMangledName(S, dstSmv.GetName());
            string  argName     = "x";
            Comment comment     = new Comment("Converting constructor, from " + srcTypeName + " to " + dstTypeName);

            comment.Write(SB, S, 1);

            SB.AppendLine("\tpublic " + dstTypeName + "(" + srcTypeName + " " + argName + ") {");

            int  nbTabs          = 2;
            bool declareVariable = false;
            bool cast            = false;
            bool srcPtr          = false;
            bool dstPtr          = false;

            RefGA.Multivector value = Symbolic.SMVtoSymbolicMultivector(S, srcSmv, argName, srcPtr);
            AssignInstruction AI    = new AssignInstruction(nbTabs, dstSmv, FT, cast, value, SmvUtil.THIS, dstPtr, declareVariable);

            AI.Write(SB, S, cgd);

            SB.AppendLine("\t}");
        }
Exemplo n.º 3
0
        /// <summary>
        /// Writes a function to 'SB' which assigns a certain 'value' to a certain 'dstName'.
        /// </summary>
        /// <param name="S">Used for all kinds of stuff.</param>
        /// <param name="cgd">Results go into cgd.m_defSB, and so on</param>
        /// <param name="inline">Should the function we inline?</param>
        /// <param name="staticFunc">Static function?</param>
        /// <param name="returnType">String which speficies the return type.</param>
        /// <param name="returnVarName">The name of the variable which should be returned. Should be one of the argument names.</param>
        /// <param name="functionName">The name of the function which is to be generated.</param>
        /// <param name="arguments">Array of FuncArg which describes the arguments of the function.</param>
        /// <param name="dstFT">Floating point type of destination variable.</param>
        /// <param name="mustCastDst">set to true if coordinates of 'value' must be cast to 'dstFT'.</param>
        /// <param name="dstSmv">G25.SMV type of destination.</param>
        /// <param name="dstName">Name of destination.</param>
        /// <param name="dstPtr">Is the destination a pointer?</param>
        /// <param name="value">Value to be written to the destination.</param>
        /// <param name="returnArgument">For use with the 'C' language, an extra argument can be used to return results.</param>
        public static void WriteAssignmentFunction(
            Specification S, G25.CG.Shared.CGdata cgd,
            bool inline, bool staticFunc, string returnType, string returnVarName, string functionName,
            FuncArgInfo returnArgument, FuncArgInfo[] arguments,
            FloatType dstFT, bool mustCastDst, G25.SMV dstSmv, string dstName, bool dstPtr, RefGA.Multivector value)
        {
            // where the definition goes:
            StringBuilder defSB = (inline) ? cgd.m_inlineDefSB : cgd.m_defSB;

            // write declaration yes/no?
            bool writeDecl = (!(dstName.Equals(G25.CG.Shared.SmvUtil.THIS) && S.OutputCpp())) && // no declarations for C++ member functions
                (!S.OutputCSharpOrJava());  // no declarations in C# and Java
            if (writeDecl)
            {
                WriteDeclaration(cgd.m_declSB, S, cgd, inline, staticFunc, returnType, functionName, returnArgument, arguments);
                cgd.m_declSB.AppendLine(";");
            }

            WriteDeclaration(defSB, S, cgd, inline, staticFunc, returnType, functionName, returnArgument, arguments);

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

            int nbTabs = 1;
            bool declareVariable = false;
            AssignInstruction AI = new AssignInstruction(nbTabs, dstSmv, dstFT, mustCastDst, value, dstName, dstPtr, declareVariable);
            AI.Write(defSB, S, cgd);

            if (returnVarName != null)
            {
                defSB.AppendLine("\treturn " + returnVarName + ";");
            } else if (returnArgument != null) {
                defSB.AppendLine("\treturn " + returnArgument.Name + ";");
            }

            defSB.AppendLine("}");
        }
Exemplo n.º 4
0
        private static void WriteConvertingConstructor(StringBuilder SB, Specification S, G25.CG.Shared.CGdata cgd, FloatType FT, G25.fgs fgs, SMV srcSmv, SMV dstSmv)
        {
            string srcTypeName = FT.GetMangledName(S, srcSmv.GetName());
            string dstTypeName = FT.GetMangledName(S, dstSmv.GetName());
            string argName = "x";
            Comment comment = new Comment("Converting constructor, from " + srcTypeName + " to " + dstTypeName);
            comment.Write(SB, S, 1);

            SB.AppendLine("\tpublic " + dstTypeName + "(" + srcTypeName + " " + argName + ") {");

            int nbTabs = 2;
            bool declareVariable = false;
            bool cast = false;
            bool srcPtr = false;
            bool dstPtr = false;
            RefGA.Multivector value = Symbolic.SMVtoSymbolicMultivector(S, srcSmv, argName, srcPtr);
            AssignInstruction AI = new AssignInstruction(nbTabs, dstSmv, FT, cast, value, SmvUtil.THIS, dstPtr, declareVariable);
            AI.Write(SB, S, cgd);

            SB.AppendLine("\t}");
        }