当前位置: 首页>>代码示例>>C#>>正文


C# Specification.OutputJava方法代码示例

本文整理汇总了C#中Specification.OutputJava方法的典型用法代码示例。如果您正苦于以下问题:C# Specification.OutputJava方法的具体用法?C# Specification.OutputJava怎么用?C# Specification.OutputJava使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Specification的用法示例。


在下文中一共展示了Specification.OutputJava方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: WriteLargestCoordinateFunctions

        /// <summary>
        /// Writes code for abs largest coordinate
        /// </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 WriteLargestCoordinateFunctions(Specification S, G25.CG.Shared.CGdata cgd, G25.FloatType FT, G25.SMV smv)
        {
            StringBuilder defSB = cgd.m_defSB;
            defSB.AppendLine("");

            const string smvName = G25.CG.Shared.SmvUtil.THIS;
            const bool ptr = false;

            string fabsFunc = G25.CG.Shared.CodeUtil.OpNameToLangString(S, FT, RefGA.Symbolic.UnaryScalarOp.ABS);

            string[] AS = G25.CG.Shared.CodeUtil.GetAccessStr(S, smv, smvName, ptr);

            RefGA.BasisBlade maxBasisBlade = smv.AbsoluteLargestConstantBasisBlade();

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

            for (int _returnBitmap = 0; _returnBitmap <= 1; _returnBitmap++)
            {
                bool returnBitmap = (_returnBitmap != 0);

                // write comment
                int nbTabs = 1;
                if (returnBitmap)
                    new G25.CG.Shared.Comment("Returns the absolute largest coordinate,\nand the corresponding basis blade bitmap.").Write(defSB, S, nbTabs);
                else new G25.CG.Shared.Comment("Returns the absolute largest coordinate.").Write(defSB, S, nbTabs);

                string funcName = Util.GetFunctionName(S, ((returnBitmap) ? "largestBasisBlade" : "largestCoordinate"));

                string funcDecl;
                if ((S.OutputCSharp()) && returnBitmap)
                {
                    funcDecl = FT.type + " " + funcName + "(int bm) ";
                }
                else if ((S.OutputJava()) && returnBitmap)
                {
                    funcDecl = FT.type + "[] " + funcName + "() ";
                }
                else
                {
                    funcDecl = FT.type + " " + funcName + "()";
                }

                string FINAL = (S.OutputJava()) ? "final " : "";
                defSB.Append("\tpublic " + FINAL + funcDecl);
                {
                    defSB.AppendLine(" {");

                    if ((S.OutputJava()) && returnBitmap)
                        defSB.AppendLine("\t\tint bm;");

                    int startIdx = 0;
                    if (maxBasisBlade != null)
                    {
                        defSB.AppendLine("\t\t" + FT.type + " maxValue = " + FT.DoubleToString(S, Math.Abs(maxBasisBlade.scale)) + ";");
                        if (returnBitmap)
                            defSB.AppendLine("\t\tbm = " + maxBasisBlade.bitmap + ";");
                    }
                    else
                    {
                        defSB.AppendLine("\t\t" + FT.type + " maxValue = " + fabsFunc + "(" + AS[0] + ");");
                        if (returnBitmap)
                            defSB.AppendLine("\t\tbm = 0;");
                        startIdx = 1;
                    }

                    for (int c = startIdx; c < smv.NbNonConstBasisBlade; c++)
                    {
                        defSB.Append("\t\tif (" + fabsFunc + "(" + AS[c] + ") > maxValue) { maxValue = " + fabsFunc + "(" + AS[c] + "); ");
                        if (returnBitmap) defSB.Append("bm = " + smv.NonConstBasisBlade(c).bitmap + "; ");
                        defSB.AppendLine("}");
                    }

                    if ((S.OutputJava()) && returnBitmap)
                    {
                        defSB.AppendLine("\t\treturn new " + FT.type + "[]{maxValue, (" + FT.type + ")bm};");
                    }
                    else
                    {
                        defSB.AppendLine("\t\treturn maxValue;");
                    }
                    defSB.AppendLine("\t}");
                }
            }
        }
开发者ID:Sciumo,项目名称:gaigen,代码行数:89,代码来源:smv.cs

示例2: WriteGomParts


//.........这里部分代码省略.........
                // map from code fragment to name of function
                Dictionary<string, string> generatedCode = new Dictionary<string, string>();

                // loop over all groups of the GMV, multiply with GOM, and assign the result
                for (int srcGroup = 0; srcGroup < gmv.NbGroups; srcGroup++)
                {
                    RefGA.Multivector inputValue = M1[srcGroup];
                    if (inputValue.IsScalar()) continue;

                    // Replace each basis blade in 'inputValue' with its value under the outermorphism.
                    RefGA.Multivector returnValue = RefGA.Multivector.ZERO; // returnValue = gom * gmv[srcGroup]
                    for (int i = 0; i < inputValue.BasisBlades.Length; i++)
                    {
                        // get input blade and domain for that grade
                        RefGA.BasisBlade inputBlade = inputValue.BasisBlades[i];
                        RefGA.BasisBlade[] domainBlades = gom.DomainForGrade(inputBlade.Grade());
                        for (int c = 0; c < domainBlades.Length; c++)
                        {
                            // if a match is found in the domain, add range vector to m_returnValue
                            if (domainBlades[c].bitmap == inputBlade.bitmap)
                            {
                                bool ptr = (S.OutputC());
                                RefGA.Multivector omColumnValue = G25.CG.Shared.Symbolic.SMVtoSymbolicMultivector(S, gom.DomainSmvForGrade(inputBlade.Grade())[c], nameGOM, ptr);
                                RefGA.Multivector inputBladeScalarMultiplier = new RefGA.Multivector(new RefGA.BasisBlade(inputBlade, 0));
                                RefGA.Multivector domainBladeScalarMultiplier = new RefGA.Multivector(new RefGA.BasisBlade(domainBlades[c], 0));
                                returnValue = RefGA.Multivector.Add(returnValue,
                                    RefGA.Multivector.gp(
                                    RefGA.Multivector.gp(omColumnValue, inputBladeScalarMultiplier),
                                    domainBladeScalarMultiplier));
                                break; // no need to search the other domainBlades too
                            }
                        }
                    } // end of 'compute return value'

                    // assign returnValue to various groups of the gmv
                    for (int dstGroup = 0; dstGroup < gmv.NbGroups; dstGroup++)
                    {
                        bool mustCast = false;
                        bool writeZeros = false; // no need to generate "+= 0.0;"
                        int dstBaseIdx = 0;
                        string code = G25.CG.Shared.CodeUtil.GenerateGMVassignmentCode(S, FT, mustCast, gmv, nameDstGMV, dstGroup, dstBaseIdx, returnValue, nbCodeTabs, writeZeros);

                        string funcName = GetGomPartFunctionName(S, FT, srcGroup, dstGroup);
                        cgd.m_gmvGomPartFuncNames[new Tuple<string, string>(FT.type, funcName)] = (code.Length > 0);

                        if (code.Length == 0) continue;

                        if (!S.m_GMV.IsGroupedByGrade(S.m_dimension))
                            code = code.Replace("=", "+=");

                        // check if code was already generated, and, if so, reuse it
                        if (generatedCode.ContainsKey(code))
                        {
                            // ready generated: call that function
                            code = "\t" + generatedCode[code] + "(" + nameGOM + ", " + nameSrcGMV + ", " + nameDstGMV + ");\n";
                        }
                        else
                        {
                            // not generated yet: remember code -> function
                            generatedCode[code] = funcName;
                        }

                        // write comment
                        string comment = "Computes the partial application of a general outermorphism to a general multivector";

                        string OM_PTR = "";
                        if (S.OutputC()) OM_PTR = "*";
                        else if (S.OutputCpp()) OM_PTR = "&";

                        string ACCESS = "";
                        if (S.OutputJava()) ACCESS = "protected static ";
                        else if (S.OutputCSharp()) ACCESS = "protected internal static ";

                        string ARR = (S.OutputCSharpOrJava()) ? "[] " : " *";
                        string CONST = (S.OutputCSharpOrJava()) ? "" : "const ";

                        string funcDecl = ACCESS + "void " + funcName + "(" + CONST + FT.GetMangledName(S, gom.Name) + " " + OM_PTR + nameGOM + ", " + CONST + FT.type + ARR + nameSrcGMV + ", " + FT.type + ARR + nameDstGMV + ")";

                        if (S.OutputCppOrC())
                        {
                            new Comment(comment).Write(cgd.m_declSB, S, nbBaseTabs);
                            cgd.m_declSB.Append(funcDecl); cgd.m_declSB.AppendLine(";");
                        }
                        else
                        {
                            new Comment(comment).Write(cgd.m_defSB, S, nbBaseTabs);
                        }

                        // emit def
                        cgd.m_defSB.Append('\t', nbBaseTabs);
                        cgd.m_defSB.Append(funcDecl);
                        cgd.m_defSB.AppendLine(" {");
                        cgd.m_defSB.Append(code);
                        cgd.m_defSB.Append('\t', nbBaseTabs);
                        cgd.m_defSB.AppendLine("}");

                    } // end of loop over all dest GMV groups
                } // end of loop over all source GMV groups
            } // end of loop over all float types
        }
开发者ID:Sciumo,项目名称:gaigen,代码行数:101,代码来源:gom_parts.cs

示例3: WriteCANSparts


//.........这里部分代码省略.........
                                else if (S.m_gmvCodeGeneration == GMV_CODE.RUNTIME)
                                    code = GetRuntimeGmvAdd2Sub2HpCode(S, cgd, g1, srcName1, srcName2, dstName, "/");
                                funcName = GetInverseHadamardProductPartFunctionName(S, FT, g1);
                                comment = "performs coordinate-wise division of coordinates of group " + g1 + " of variables " + srcName1 + " and " + srcName2 + "\n(no checks for divide by zero are made)";
                                break;
                            case EQUALS:
                                if (S.m_gmvCodeGeneration == GMV_CODE.EXPAND)
                                    code = GetExpandGmvEqualsCode(S, cgd, g1, srcName1, srcName2, epsilonName);
                                else if (S.m_gmvCodeGeneration == GMV_CODE.RUNTIME)
                                    code = GetRuntimeGmvEqualsCode(S, cgd, g1, srcName1, srcName2, epsilonName);
                                funcName = GetEqualsPartFunctionName(S, FT, g1);
                                comment = "check for equality up to " + epsilonName + " of coordinates of group " + g1 + " of variables " + srcName1 + " and " + srcName2;
                                break;
                            case ZERO:
                                if (S.m_gmvCodeGeneration == GMV_CODE.EXPAND)
                                    code = GetExpandGmvZeroCode(S, cgd, g1, srcName1, epsilonName);
                                else if (S.m_gmvCodeGeneration == GMV_CODE.RUNTIME)
                                    code = GetRuntimeGmvZeroCode(S, cgd, g1, srcName1, epsilonName);
                                funcName = GetZeroPartFunctionName(S, FT, g1);
                                comment = "checks if coordinates of group " + g1 + " of variable " + srcName1 + " are zero up to "  + epsilonName;
                                break;

                        }

                        // code generation for full code expansion
                        if (S.m_gmvCodeGeneration == GMV_CODE.EXPAND)
                        {
                            if (!((op == EQUALS) || (op == ZERO))) { // EQUALS and ZERO are different: they generate their own code
                                // get assignment code
                                int dstBaseIdx = 0;
                                code = G25.CG.Shared.CodeUtil.GenerateGMVassignmentCode(S, FT, mustCast, gmv, dstName, g1, dstBaseIdx, value, nbCodeTabs, writeZeros);

                                // replace assignment symbols if required
                                if (op == ADD) code = code.Replace("=", "+=");
                                else if (op == SUB) code = code.Replace("=", "-=");
                                else if (op == COPY_DIV) code = code.Replace("*" + scaleName, "/" + scaleName);
                            }
                        }

                        // check if code was already generated, and, if so, reuse it
                        if (generatedCode.ContainsKey(code))
                        {
                            // already generated: call that function
                            if ((op == ADD2) || (op == SUB2) || (op == HP) || (op == IHP))
                                code = new string('\t', nbCodeTabs) + generatedCode[code] + "(" + srcName1 + ", " + srcName2 + ", " + dstName + ");\n";
                            else if ((op == COPY_MUL) || (op == COPY_DIV))
                                code = new string('\t', nbCodeTabs) + generatedCode[code] + "(" + srcName1 + ", " + dstName + ", " + scaleName + ");\n";
                            else if (op == ZERO)
                                code = new string('\t', nbCodeTabs) + "return " + generatedCode[code] + "(" + srcName1 + ", " + epsilonName + ");\n";
                            else if (op == EQUALS)
                                code = new string('\t', nbCodeTabs) + "return " + generatedCode[code] + "(" + srcName1 + ", " + srcName2 + ", " + epsilonName + ");\n";
                            else code = new string('\t', nbCodeTabs) + generatedCode[code] + "(" + srcName1 + ", " + dstName + ");\n";
                        }
                        else
                        {
                            // not generated yet: remember code -> function
                            generatedCode[code] = funcName;
                        }

                        string ACCESS = "";
                        if (S.OutputJava()) ACCESS = "protected final static ";
                        else if (S.OutputCSharp()) ACCESS  = "protected internal static ";

                        string BOOL = CodeUtil.GetBoolType(S);
                        string ARR = (S.OutputCSharpOrJava()) ? "[] " : " *";
                        string CONST = (S.OutputCSharpOrJava()) ? "" : "const ";
                        string funcDecl;

                        // one or two input args, scale or not?
                        if ((op == ADD2) || (op == SUB2) || (op == HP) || (op == IHP))
                            funcDecl = ACCESS + "void " + funcName + "(" + CONST + FT.type + ARR + srcName1 + ", " + CONST + FT.type + ARR + srcName2 + ", " + FT.type + ARR + dstName + ")";
                        else if ((op == COPY_MUL) || (op == COPY_DIV))
                            funcDecl = ACCESS + "void " + funcName + "(" + CONST + FT.type + ARR + srcName1 + ", " + FT.type + ARR + dstName + ", " + FT.type + " " + scaleName + ")";
                        else if (op == ZERO)
                            funcDecl = ACCESS + BOOL + " " + funcName + "(" + CONST + FT.type + ARR + srcName1 + ", " + FT.type + " " + epsilonName + ")";
                        else if (op == EQUALS)
                            funcDecl = ACCESS + BOOL + " " + funcName + "(" + CONST + FT.type + ARR + srcName1 + ", " + CONST + FT.type + ARR + srcName2 + ", " + FT.type + " " + epsilonName + ")";
                        else funcDecl = ACCESS + "void " + funcName + "(" + CONST + FT.type + ARR + srcName1 + ", " + FT.type + ARR + dstName + ")";

                        if (S.OutputCppOrC())
                        {
                            new Comment(comment).Write(cgd.m_declSB, S, nbBaseTabs);
                            cgd.m_declSB.Append(funcDecl); cgd.m_declSB.AppendLine(";");
                        }
                        else
                        {
                            new Comment(comment).Write(cgd.m_defSB, S, nbBaseTabs);
                        }

                        // append func body:
                        cgd.m_defSB.Append('\t', nbBaseTabs);
                        cgd.m_defSB.Append(funcDecl);
                        cgd.m_defSB.AppendLine(" {");
                        cgd.m_defSB.Append(code);
                        cgd.m_defSB.Append('\t', nbBaseTabs);
                        cgd.m_defSB.AppendLine("}");
                    }
                } // end of loop over the grade of 'A'
            } // end of loop over all float types
        }
开发者ID:Sciumo,项目名称:gaigen,代码行数:101,代码来源:copy_add_sub_neg_parts.cs

示例4: WriteGMVtoSMVcopy

        /// <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}");
            }
        }
开发者ID:Sciumo,项目名称:gaigen,代码行数:84,代码来源:smv.cs

示例5: WriteMultilineComment

        /// <summary>
        /// Writes a multiline comment with the correct decoration in front of it.
        /// Opening and closing decorations are not included.
        /// </summary>
        /// <param name="SB"></param>
        /// <param name="S">Used for output language.</param>
        /// <param name="nbTabs">How many tabs to place in front of the comment.</param>
        /// <param name="comment">The comment</param>
        public static void WriteMultilineComment(StringBuilder SB, Specification S, int nbTabs, string comment)
        {
            // how to start each line:
            string lineStart = new string('\t', nbTabs);
            if ((S.OutputJava()) || (S.OutputC()))
                lineStart = lineStart + " * ";
            else lineStart = lineStart + "/// ";

            // split comment on carriage returns, and get rid of '\r'
            string[] splitStr = comment.Replace("\r", "").Split('\n');

            // output each line of comment:
            bool firstLine = true;
            foreach (string lineStr in splitStr)
            {
                if (!firstLine) SB.Append(lineStart);
                firstLine = false;
                SB.AppendLine(lineStr);
            }
        }
开发者ID:Sciumo,项目名称:gaigen,代码行数:28,代码来源:comment.cs

示例6: WriteDualParts


//.........这里部分代码省略.........
                foreach (G25.Metric M in S.m_metric)
                {
                    if (M.m_metric.IsDegenerate()) continue; // do not generate code for degenerate metrics

                    for (int g1 = 0; g1 < gmv.NbGroups; g1++)
                    {
                        for (int d = 1; d >= 0; d--) // d = 1 -> generate dual, d = 0 -> generate undual
                        {
                            // get value of operation, name of function:
                            RefGA.Multivector value = null;
                            if (S.m_gmvCodeGeneration == GMV_CODE.EXPAND)
                            {
                                try
                                {
                                    value = (d == 0) ? RefGA.Multivector.Undual(M1[g1], M.m_metric) : RefGA.Multivector.Dual(M1[g1], M.m_metric);
                                }
                                catch (Exception)
                                {
                                    cgd.AddError(new G25.UserException("Non-invertable pseudoscalar. Do not generate (un)dual functions for degenerate metrics."));
                                    return;
                                }
                                if (M.m_round) value = value.Round(1e-14);
                            }

                            int grade = gmv.Group(g1)[0].Grade();
                            int dualGrade = S.m_dimension - grade;
                            for (int g3 = 0; g3 < gmv.NbGroups; g3++)
                            {
                                if (gmv.Group(g3)[0].Grade() == dualGrade)
                                {
                                    string funcName = (d == 0) ? GetUndualPartFunctionName(S, FT, M, g1, g3) : GetDualPartFunctionName(S, FT, M, g1, g3);

                                    // get assignment code
                                    string code = "";

                                    if (S.m_gmvCodeGeneration == GMV_CODE.EXPAND)
                                    { // full code expansion
                                        int dstBaseIdx = 0;
                                        code = G25.CG.Shared.CodeUtil.GenerateGMVassignmentCode(S, FT, mustCast, gmv, name3, g3, dstBaseIdx, value, nbCodeTabs, writeZeros);
                                    }
                                    else if (S.m_gmvCodeGeneration == GMV_CODE.RUNTIME)
                                    { // runtime code
                                        code = GetRuntimeDualCode(S, FT, M, d, g1, g3, name1, name2, name3);
                                    }

                                    cgd.m_gmvDualPartFuncNames[new Tuple<string, string, string>(FT.type, M.m_name, funcName)] = (code.Length > 0);

                                    if (code.Length == 0) continue; // only if code is non-empty

                                    // is the following ever required: (i.e. the dual of a basis blade wrt to the full space is not a single basis blade?)
                                    //if (!M.m_metric.IsDiagonal())
                                    //    code = code.Replace("=", "+=");

                                    // check if code was already generated, and, if so, reuse it
                                    if (generatedCode.ContainsKey(code))
                                    {
                                        // ready generated: call that function
                                        code = new string('\t', nbCodeTabs) + generatedCode[code] + "(" + name1 + ", " + name3 + ");\n";
                                    }
                                    else
                                    {
                                        // not generated yet: remember code -> function
                                        generatedCode[code] = funcName;
                                    }

                                    // write comment
                                    string comment = "Computes the partial " + ((d == 0) ? "un" : "") + "dual (w.r.t. full space) of a multivector.";

                                    string ACCESS = "";
                                    if (S.OutputJava()) ACCESS = "protected final static ";
                                    else if (S.OutputCSharp()) ACCESS  = "protected internal static ";
                                    string ARR = (S.OutputCSharpOrJava()) ? "[] " : " *";
                                    string CONST = (S.OutputCSharpOrJava()) ? "" : "const ";

                                    string funcDecl = ACCESS + "void " + funcName + "(" + CONST + FT.type + ARR + name1 + ", " + FT.type + ARR + name3 + ")";

                                    if (S.OutputCppOrC())
                                    {
                                        new Comment(comment).Write(cgd.m_declSB, S, nbBaseTabs);
                                        cgd.m_declSB.Append(funcDecl); cgd.m_declSB.AppendLine(";");
                                    }
                                    else
                                    {
                                        new Comment(comment).Write(cgd.m_defSB, S, nbBaseTabs);
                                    }

                                    // emit def
                                    cgd.m_defSB.Append('\t', nbBaseTabs);
                                    cgd.m_defSB.Append(funcDecl);
                                    cgd.m_defSB.AppendLine(" {");
                                    cgd.m_defSB.Append(code);
                                    cgd.m_defSB.Append('\t', nbBaseTabs);
                                    cgd.m_defSB.AppendLine("}");
                                }
                            } // end of loop over all output groups
                        } // end of loop over undual (0) and dual(1)
                    } // end of loop over all input groups
                } // end of loop over all metric
            } // end of loop over all float types
        }
开发者ID:Sciumo,项目名称:gaigen,代码行数:101,代码来源:dual_parts.cs

示例7: GetBoolType

 /// <returns>Name of bool type in output language</returns>
 public static string GetBoolType(Specification S)
 {
     return (S.OutputC()) ? "int" : ((S.OutputJava()) ? "boolean" : "bool");
 }
开发者ID:Sciumo,项目名称:gaigen,代码行数:5,代码来源:codeutil.cs

示例8: PublicAccessModifier

 public static string PublicAccessModifier(Specification S)
 {
     return (S.OutputJava())
         ? "public final"
         : "public";
 }
开发者ID:Sciumo,项目名称:gaigen,代码行数:6,代码来源:keywords.cs

示例9: GetClassExtendsImplements

        /// <summary>
        /// Writes the code for a the 'extends/implements' part of a class definition.
        /// </summary>
        /// <param name="S">Used for output language.</param>
        /// <param name="extends">classes that are extended (can be null)</param>
        /// <param name="implements">interfaces that are implemented (can be null)</param>
        /// <returns>part of class definition.</returns>
        private static string GetClassExtendsImplements(Specification S, string[] extends, string[] implements)
        {
            bool extendsOpened = false;
            bool implementsOpened = false;
            bool commaRequired = false;
            StringBuilder SB = new StringBuilder();

            if (extends != null)
            {
                foreach (string E in extends)
                {
                    if (!extendsOpened)
                    {
                        if (S.OutputCSharp())
                        {
                            SB.Append(" : ");
                            extendsOpened = implementsOpened = true;
                        }
                        else if (S.OutputJava())
                        {
                            SB.Append(" extends ");
                            extendsOpened = true;
                        }
                    }

                    if (commaRequired) SB.Append(", ");
                    SB.Append(" " + E);
                    commaRequired = true;
                }
            }

            if (S.OutputJava())
                commaRequired = false;

            if (implements != null)
            {
                foreach (string I in implements)
                {
                    if (!implementsOpened)
                    {
                        if (S.OutputCSharp())
                        {
                            SB.Append(" : ");
                            extendsOpened = implementsOpened = true;
                        }
                        else if (S.OutputJava())
                        {
                            SB.Append(" implements ");
                            extendsOpened = true;
                        }
                    }

                    if (commaRequired) SB.Append(", ");
                    SB.Append(" " + I);
                    commaRequired = true;
                }
            }

            return SB.ToString();
        }
开发者ID:Sciumo,项目名称:gaigen,代码行数:67,代码来源:util.cs

示例10: WriteFunctionComment


//.........这里部分代码省略.........
        /// <param name="paramComments">Pairs of parameter name, parameter comment (can be null).</param>
        /// <param name="returnComment">Comment on the return value of the function (can be null).</param>
        public static void WriteFunctionComment(StringBuilder SB, Specification S,
            int nbTabs,
            string mainComment,
            List<Tuple<string, string>> paramComments,
            string returnComment)
        {
            // open comment, summary
            SB.Append('\t', nbTabs);
            switch (S.m_outputLanguage)
            {
                case OUTPUT_LANGUAGE.CPP:
                    SB.Append("/// ");
                    break;
                case OUTPUT_LANGUAGE.C:
                case OUTPUT_LANGUAGE.JAVA:
                    SB.AppendLine("/**");
                    SB.Append('\t', nbTabs);
                    SB.Append(" * ");
                    break;
                case OUTPUT_LANGUAGE.CSHARP:
                    SB.Append("/// <summary>");
                    break;
            }

            WriteMultilineComment(SB, S, nbTabs, mainComment);

            if (S.OutputCSharp())
            {
                SB.Append('\t', nbTabs);
                SB.AppendLine("/// </summary>");
            }

            // parameters
            if (paramComments != null)
            {
                foreach (Tuple<string, string> P in paramComments)
                {
                    SB.Append('\t', nbTabs);

                    switch (S.m_outputLanguage)
                    {
                        case OUTPUT_LANGUAGE.C:
                            SB.Append(" *  \\param " + P.Value1 + " ");
                            break;
                        case OUTPUT_LANGUAGE.CPP:
                            SB.Append("/// \\param " + P.Value1 + " ");
                            break;
                        case OUTPUT_LANGUAGE.JAVA:
                            SB.Append(" * @param " + P.Value1 + " ");
                            break;
                        case OUTPUT_LANGUAGE.CSHARP:
                            SB.Append("/// <param name=\"" + P.Value1 + "\">");
                            break;
                    }
                    WriteMultilineComment(SB, S, nbTabs, P.Value2);

                    if (S.OutputCSharp())
                    {
                        SB.Append('\t', nbTabs);
                        SB.AppendLine("/// </param>");
                    }
                }
            }

            // return comment
            if (returnComment != null)
            {
                SB.Append('\t', nbTabs);
                switch (S.m_outputLanguage)
                {
                    case OUTPUT_LANGUAGE.C:
                        SB.Append(" * \\return ");
                        break;
                    case OUTPUT_LANGUAGE.CPP:
                        SB.Append("/// \\return ");
                        break;
                    case OUTPUT_LANGUAGE.JAVA:
                        SB.Append(" * @return ");
                        break;
                    case OUTPUT_LANGUAGE.CSHARP:
                        SB.Append("/// <returns>");
                        break;
                }
                WriteMultilineComment(SB, S, nbTabs, returnComment);
                if (S.OutputCSharp())
                {
                    SB.Append('\t', nbTabs);
                    SB.AppendLine("/// </returns>");
                }
            }

            // end of comment
            if ((S.OutputJava()) || (S.OutputC()))
            {
                SB.Append('\t', nbTabs);
                SB.AppendLine(" */");
            }
        }
开发者ID:Sciumo,项目名称:gaigen,代码行数:101,代码来源:util.cs

示例11: WriteDeclaration

        /// <summary>
        /// Writes a function declaration to 'SB'.
        /// The closing comma is NOT included so the function can also be used as the start of a definition.
        /// </summary>
        /// <param name="SB">Where declaration goes.</param>
        /// <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="functionName">The name of the function which is to be generated.</param>
        /// <param name="returnArgument">FuncArgInfo which describes the optional return argument.</param>
        /// <param name="arguments">Array of FuncArgInfo which describes the arguments of the function.</param>
        public static void WriteDeclaration(StringBuilder SB, Specification S, G25.CG.Shared.CGdata cgd,
            bool inline, bool staticFunc, string returnType, string functionName,
            FuncArgInfo returnArgument, FuncArgInfo[] arguments)
        {
            if (S.OutputJava())
                SB.Append("public final ");
            else if (S.OutputCSharp())
                SB.Append("public ");

            if (staticFunc) SB.Append("static ");

            SB.Append(G25.CG.Shared.Util.GetInlineString(S, inline, " "));
            if (returnArgument != null) returnType = returnArgument.MangledTypeName + "*"; // maybe for C write returnType = returnArgument + "*"?
            SB.Append(returnType);
            SB.Append(" ");
            SB.Append(functionName);
            SB.Append("(");

            { // write arguments
                bool appendComma = false;

                int nbArgs = (arguments == null) ? 0 : arguments.Length;
                for (int i = -1; i < nbArgs; i++) // start at -1 for return argument
                {
                    FuncArgInfo A = null;
                    if (i == -1)
                    {
                        A = returnArgument;
                        if (A == null) continue;
                    }
                    else A = arguments[i];

                    if (appendComma) SB.Append(", ");

                    if (S.OutputJava())
                        SB.Append("final ");

                    if (A.Constant && S.OutputCppOrC())
                        SB.Append("const ");

                    SB.Append(A.MangledTypeName);

                    if (S.OutputCSharpOrJava() && A.IsGMV() && A.MvInterface)
                        SB.Append(Main.IF_SUFFIX);

                    if (A.Array && S.OutputCSharpOrJava())
                        SB.Append("[]");

                    SB.Append(" ");

                    if (A.Pointer) SB.Append("*");
                    else if (S.OutputCpp() && (A.IsMVorOM())) // append '&'?
                            SB.Append("&");
                    SB.Append(A.Name);

                    if (A.Array && S.OutputCppOrC())
                        SB.Append("[]");

                    appendComma = true;
                }
            }
            SB.Append(")");
        }
开发者ID:Sciumo,项目名称:gaigen,代码行数:76,代码来源:functions.cs

示例12: GetReportInstruction

        // add someextra instructions for report usage?
        // add extra verbatim code here if rep usage?
        // what arguments are required??
        public static Instruction GetReportInstruction(Specification S, G25.fgs F, FuncArgInfo[] FAI)
        {
            if ((S.OutputC()) ||
                (!S.m_reportUsage)  ||
                (FAI.Length == 0)) return new NOPinstruction();

            // check if all arguments are GMVs
            for (int i = 0; i < FAI.Length; i++)
            {
                if (!FAI[i].IsGMV()) return new NOPinstruction();
            }

            // get XML spec
            string XMLstr = GetXMLstring(S, F, FAI);

            StringBuilder SB = new StringBuilder();

            if (S.OutputCSharpOrJava())
            {
                for (int i = 0; i < FAI.Length; i++)
                {
                    SB.AppendLine("SmvType type_" + FAI[i].Name + " = " + FAI[i].Name + ".to_" + FAI[i].MangledTypeName +"().m_t;");
                }
            }

            {
                string MV_CONSTANT = GetSpecializedConstantName(S, S.m_GMV.Name);
                string INVALID_CONSTANT = GetSpecializedConstantName(S, INVALID);
                // output the test for all specialized MVs
                SB.Append("if (");
                for (int i = 0; i < FAI.Length; i++)
                {
                    if (i > 0)
                    {
                        SB.AppendLine(" && ");
                        SB.Append("\t");
                    }
                    if (S.OutputCpp())
                    {
                        SB.Append("(" + FAI[i].Name + ".m_t > " + MV_CONSTANT + ") && (" + FAI[i].Name + ".m_t < " + INVALID_CONSTANT + ")");
                    }
                    else if (S.OutputCSharp())
                    {
                        SB.Append("(type_" + FAI[i].Name + " > SmvType." + MV_CONSTANT + ") && (type_" + FAI[i].Name + " < SmvType." + INVALID_CONSTANT + ")");
                    }
                    else if (S.OutputJava())
                    {
                        SB.Append("(type_" + FAI[i].Name + ".compareTo(SmvType." + MV_CONSTANT + ") > 0) && (type_" + FAI[i].Name + ".compareTo(SmvType." + INVALID_CONSTANT + ") < 0)");
                    }
                }
                SB.AppendLine(") {");

                if (S.OutputCpp())
                {
                    SB.Append("\t\tstd::string reportUsageString = std::string(\"\") + ");
                }
                else if (S.OutputCSharp())
                {
                    SB.Append("\t\tstring reportUsageString = ");
                }
                else if (S.OutputJava())
                {
                    SB.Append("\t\tString reportUsageString = ");
                }
                // output XMLstr, replace placeholders with code
                int XMLstrIdx = 0;
                int argIdx = 0;
                while (XMLstrIdx < XMLstr.Length)
                {
                    string placeHolder = GetPlaceHolderString(argIdx);

                    int nextIdx = XMLstr.IndexOf(placeHolder, XMLstrIdx);
                    if (nextIdx < 0) nextIdx = XMLstr.Length;

                    SB.Append(Util.StringToCode(XMLstr.Substring(XMLstrIdx, nextIdx - XMLstrIdx)));
                    if (argIdx < FAI.Length)
                    {
                        if (S.OutputCpp())
                        {
                            SB.Append("+ g_" + S.m_namespace + "Typenames[" + FAI[argIdx].Name + ".m_t] + ");
                        }
                        else if (S.OutputCSharp())
                        {
                            SB.Append("+ typenames[(int)type_" + FAI[argIdx].Name + "] + ");
                        }
                        else if (S.OutputJava())
                        {
                            SB.Append("+ typenames[type_" + FAI[argIdx].Name + ".getId()] + ");
                        }
                    }

                    argIdx++;
                    XMLstrIdx = nextIdx + placeHolder.Length;
                }
                SB.AppendLine(";");
                if (S.OutputCpp())
                {
//.........这里部分代码省略.........
开发者ID:Sciumo,项目名称:gaigen,代码行数:101,代码来源:report_usage.cs

示例13: GetFunctionName

 /// <summary>
 /// Return 'name' with first letter in uppercase or lowercase, depending on output language
 /// </summary>
 public static string GetFunctionName(Specification S, string name)
 {
     if (S.OutputJava())
         return name.Substring(0, 1).ToLower() + name.Substring(1);
     else return name.Substring(0, 1).ToUpper() + name.Substring(1);
 }
开发者ID:Sciumo,项目名称:gaigen,代码行数:9,代码来源:util.cs

示例14: AddGradeArg

        protected static StringBuilder AddGradeArg(Specification S, string str, int gradeIdx, string GROUP_BITMAP_NAME)
        {
            StringBuilder SB = new StringBuilder();
            int idx = str.IndexOf(')');
            if (idx < 0)
            {
                SB.Append(str);
            }
            else
            {
                string groupBitmapType = (S.OutputCSharp()) ? "GroupBitmap" : G25.IntegerType.INTEGER;
                string FINAL = (S.OutputJava()) ? "final " : "";

                SB.Append(str.Substring(0, idx));
                SB.Append(", " + FINAL + groupBitmapType + " " + GROUP_BITMAP_NAME);
                SB.Append(str.Substring(idx));
            }
            return SB;
        }
开发者ID:Sciumo,项目名称:gaigen,代码行数:19,代码来源:gmv_casn_parts.cs

示例15: Write

        /// <summary>
        /// Writes a function comment according to the output language.
        /// </summary>
        /// <param name="SB">Where the output goes.</param>
        /// <param name="S">Used for output language.</param>
        /// <param name="nbTabs">Number of tabs to put in front of output comment.</param>
        public void Write(StringBuilder SB, Specification S, int nbTabs)
        {
            // open comment, summary comment
            SB.Append('\t', nbTabs);
            switch (S.m_outputLanguage)
            {
                case OUTPUT_LANGUAGE.CPP:
                    SB.Append("/// ");
                    break;
                case OUTPUT_LANGUAGE.C:
                case OUTPUT_LANGUAGE.JAVA:
                    SB.AppendLine("/**");
                    SB.Append('\t', nbTabs);
                    SB.Append(" * ");
                    break;
                case OUTPUT_LANGUAGE.CSHARP:
                    SB.Append("/// <summary>");
                    break;
            }

            WriteMultilineComment(SB, S, nbTabs, SummaryComment);

            if (S.OutputCSharp())
            {
                SB.Append('\t', nbTabs);
                SB.AppendLine("/// </summary>");
            }

            // parameter comments
            foreach (KeyValuePair<string, string> kvp in m_paramComments)
            {
                SB.Append('\t', nbTabs);
                string paramName = kvp.Key;
                string comment = kvp.Value;
                switch (S.m_outputLanguage)
                {
                    case OUTPUT_LANGUAGE.C:
                        SB.Append(" *  \\param " + paramName + " ");
                        break;
                    case OUTPUT_LANGUAGE.CPP:
                        SB.Append("/// \\param " + paramName + " ");
                        break;
                    case OUTPUT_LANGUAGE.JAVA:
                        SB.Append(" * @param " + paramName + " ");
                        break;
                    case OUTPUT_LANGUAGE.CSHARP:
                        SB.Append("/// <param name=\"" + paramName + "\">");
                        break;
                }
                WriteMultilineComment(SB, S, nbTabs, comment);

                if (S.OutputCSharp())
                {
                    SB.Append('\t', nbTabs);
                    SB.AppendLine("/// </param>");
                }
            }

            // return comment
            if (ReturnComment.Length > 0)
            {
                SB.Append('\t', nbTabs);
                switch (S.m_outputLanguage)
                {
                    case OUTPUT_LANGUAGE.C:
                        SB.Append(" * \\return ");
                        break;
                    case OUTPUT_LANGUAGE.CPP:
                        SB.Append("/// \\return ");
                        break;
                    case OUTPUT_LANGUAGE.JAVA:
                        SB.Append(" * @return ");
                        break;
                    case OUTPUT_LANGUAGE.CSHARP:
                        SB.Append("/// <returns>");
                        break;
                }
                WriteMultilineComment(SB, S, nbTabs, ReturnComment);
                if (S.OutputCSharp())
                {
                    SB.Append('\t', nbTabs);
                    SB.AppendLine("/// </returns>");
                }
            }

            // end of comment
            if ((S.OutputJava()) || (S.OutputC()))
            {
                SB.Append('\t', nbTabs);
                SB.AppendLine(" */");
            }
        }
开发者ID:Sciumo,项目名称:gaigen,代码行数:98,代码来源:comment.cs


注:本文中的Specification.OutputJava方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。