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


C# Specification.OutputCSharp方法代码示例

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


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

示例1: WriteOperatorShortcut

        private static void WriteOperatorShortcut(StringBuilder SB, Specification S, G25.CG.Shared.CGdata cgd, FloatType FT, G25.VariableType type,
            G25.fgs fgs, FuncArgInfo[] FAI, G25.Operator op)
        {
            // C# does not allow return type of ++ or -- to be different from input type
            if (S.OutputCSharp() &&
                (op.IsIncrement() || op.IsDecrement()) &&
                (fgs.ReturnTypeName != type.GetName()))
                return;

            string operatorCall = getOperatorCall(S, fgs, FAI);

            SB.AppendLine("");

            int nbTabs = 1;
            // output comment
            new Comment("operator for " + operatorCall).Write(SB, S, nbTabs);

            bool inline = false;
            bool staticFunc = true;
            string returnType = FT.GetMangledName(S, fgs.ReturnTypeName);
            FuncArgInfo returnArgument = null;

            SB.Append('\t', nbTabs);
            Functions.WriteDeclaration(SB, S, cgd,
                inline, staticFunc, returnType, "operator " + op.Symbol,
                returnArgument, FAI);
            SB.AppendLine(" {");

            SB.Append('\t', nbTabs+1);
            SB.Append("return ");
            SB.Append(operatorCall);
            SB.AppendLine(";");

            SB.Append('\t', nbTabs);
            SB.AppendLine("}");
        }
开发者ID:Sciumo,项目名称:gaigen,代码行数:36,代码来源:shortcut.cs

示例2: 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

示例3: GetReserveGroupString

 public static string GetReserveGroupString(Specification S, int groupIdx)
 {
     return ((S.OutputCSharp())
         ? SET_RESERVE_GROUP_CSHARP
         : SET_RESERVE_GROUP_JAVA) + groupIdx;
 }
开发者ID:Sciumo,项目名称:gaigen,代码行数:6,代码来源:gmv.cs

示例4: 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

示例5: WriteCoordinateOrder

        /// <summary>
        /// Writes the <c>defines</c> for indices of the smv struct to 'SB'. For example,  <c>define VECTOR_E1 0</c>.
        /// </summary>
        /// <param name="SB">Where the code goes.</param>
        /// <param name="S">Used for basis vector names.</param>
        /// <param name="FT"></param>
        /// <param name="smv">The specialized multivector for which the coordinate indices should be written.</param>
        public static void WriteCoordinateOrder(StringBuilder SB, Specification S, FloatType FT, G25.SMV smv)
        {
            string AccessModifier = Keywords.ConstAccessModifier(S);
            string typeName = G25.CG.Shared.SmvUtil.COORDINATE_ORDER_ENUM;
            string constantName = G25.CG.Shared.SmvUtil.GetCoordinateOrderConstant(S, smv);

            SB.AppendLine();

            int nbTabs = 1;
            new G25.CG.Shared.Comment("The order of coordinates (this is the type of the first argument of coordinate-handling functions.").Write(SB, S, nbTabs);

            string enumAccessModifier = (S.OutputCSharp()) ? "public" : "private";

            SB.AppendLine("\t" + enumAccessModifier + " enum " + typeName + " {");
            SB.AppendLine("\t\t" + constantName);
            SB.AppendLine("\t};");
            SB.AppendLine("\tpublic " + AccessModifier + " " + typeName + " " + constantName + " = " + typeName + "." + constantName + ";");
        }
开发者ID:Sciumo,项目名称:gaigen,代码行数:25,代码来源:smv.cs

示例6: GetAllocateGroupsString

 public static string GetAllocateGroupsString(Specification S)
 {
     return (S.OutputCSharp())
         ? ALLOCATE_GROUPS_CSHARP
         : ALLOCATE_GROUPS_JAVA;
 }
开发者ID:Sciumo,项目名称:gaigen,代码行数:6,代码来源:gmv.cs

示例7: StringType

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

示例8: WriteCANSparts

        /// <summary>
        /// Writes functions for the copying, adding, subtracting, negating, scaling
        /// inverse scaling and Hadamard product of general multivectors, on a group by group basis.
        /// 
        /// Internally the function loops over all float types, and over all operations (8 in total)
        /// to generate all code.
        /// 
        /// This function should be called early on in the code generation process, at least
        /// before any of the <c>Get....Code()</c> functions is called.
        /// </summary>
        /// <param name="S">Specification (used for floating points types, output language, GMV).</param>
        /// <param name="cgd">Output goes here.</param>
        public static void WriteCANSparts(Specification S, CGdata cgd)
        {
            G25.GMV gmv = S.m_GMV;

            string srcName1 = "A";
            string srcName2 = "B";
            string dstName = "C";
            string epsilonName = "eps";
            string scaleName = "s";
            bool ptr = true;
            int allGroups = -1;
            bool mustCast = false;
            int nbBaseTabs = (S.OutputCSharpOrJava()) ? 1 : 0;
            int nbCodeTabs = nbBaseTabs + 1;
            bool writeZeros = false;

            // get two symbolic multivectors (with different symbolic names):
            RefGA.Multivector[] M1 = null, M2 = null;
            if (S.m_gmvCodeGeneration == GMV_CODE.EXPAND)
            { // M1 and M2 and only required for full code expansion
                M1 = G25.CG.Shared.Symbolic.GMVtoSymbolicMultivector(S, gmv, srcName1, ptr, allGroups);
                M2 = G25.CG.Shared.Symbolic.GMVtoSymbolicMultivector(S, gmv, srcName2, ptr, allGroups);
            }
            RefGA.Multivector scaleM = new RefGA.Multivector(scaleName);

            foreach (G25.FloatType FT in S.m_floatTypes)
            {
                // map from code fragment to name of function
                Dictionary<string, string> generatedCode = new Dictionary<string, string>();

                for (int g1 = 0; g1 < gmv.NbGroups; g1++)
                {
                    int g2 = g1;

                    const int COPY = 0;
                    const int COPY_MUL = 1;
                    const int COPY_DIV = 2;
                    const int ADD = 3;
                    const int SUB = 4;
                    const int NEG = 5;
                    const int ADD2 = 6;
                    const int SUB2 = 7;
                    const int HP = 8;
                    const int IHP = 9;
                    const int EQUALS = 10;
                    const int ZERO = 11;
                    const int NB_OPS = 12;

                    for (int op = 0; op < NB_OPS; op++)
                    {
                        // get value of operation, name of function:
                        RefGA.Multivector value = null;
                        String funcName = null;
                        String comment = null;
                        String code = null; // code depends on code generation mode (expand or run-time)
                        switch (op)
                        {
                            case COPY:
                                if (S.m_gmvCodeGeneration == GMV_CODE.EXPAND)
                                    value = M1[g1];
                                else if (S.m_gmvCodeGeneration == GMV_CODE.RUNTIME)
                                    code = GetRuntimeGmvCopyCode(S, cgd, g1, srcName1, dstName);
                                funcName = GetCopyPartFunctionName(S, FT, g1);
                                comment = "copies coordinates of group " + g1;
                                break;
                            case COPY_MUL:
                                if (S.m_gmvCodeGeneration == GMV_CODE.EXPAND)
                                    value = RefGA.Multivector.gp(scaleM, M1[g1]);
                                else if (S.m_gmvCodeGeneration == GMV_CODE.RUNTIME)
                                    code = GetRuntimeGmvCopyMulDivCode(S, cgd, g1, srcName1, dstName, scaleName, "*");
                                funcName = GetCopyMulPartFunctionName(S, FT, g1);
                                comment = "copies and multiplies (by " + scaleName + ") coordinates of group " + g1;
                                break;
                            case COPY_DIV:
                                if (S.m_gmvCodeGeneration == GMV_CODE.EXPAND)
                                    value = RefGA.Multivector.gp(M1[g1], scaleM);
                                else if (S.m_gmvCodeGeneration == GMV_CODE.RUNTIME)
                                    code = GetRuntimeGmvCopyMulDivCode(S, cgd, g1, srcName1, dstName, scaleName, "/");
                                funcName = GetCopyDivPartFunctionName(S, FT, g1);
                                comment = "copies and divides (by " + scaleName + ") coordinates of group " + g1;
                                break;
                            case ADD:
                                if (S.m_gmvCodeGeneration == GMV_CODE.EXPAND)
                                    value = M1[g1];
                                else if (S.m_gmvCodeGeneration == GMV_CODE.RUNTIME)
                                    code = GetRuntimeGmvAddSubNegCode(S, cgd, g1, srcName1, dstName, "+= ");
                                funcName = GetAddPartFunctionName(S, FT, g1);
                                comment = "adds coordinates of group " + g1 + " from variable " + srcName1 + " to " + dstName;
//.........这里部分代码省略.........
开发者ID:Sciumo,项目名称:gaigen,代码行数:101,代码来源:copy_add_sub_neg_parts.cs

示例9: PackageProtectedAccessModifier

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

示例10: ProtectedStaticAccessModifier

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

示例11: GroupBitmapType

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

示例12: ConstClassInstanceAccessModifier

 /// <returns>Access modifier for a constant class instance.</returns>
 public static string ConstClassInstanceAccessModifier(Specification S)
 {
     return (S.OutputCSharp())
     ? "static readonly"
     : "static final";
 }
开发者ID:Sciumo,项目名称:gaigen,代码行数:7,代码来源:keywords.cs

示例13: ConstAccessModifier

 /// <returns>Access modifier for a constant built-in type.</returns>
 public static string ConstAccessModifier(Specification S)
 {
     return (S.OutputCSharp())
     ? "const"
     : "static final";
 }
开发者ID:Sciumo,项目名称:gaigen,代码行数:7,代码来源:keywords.cs

示例14: WriteDualParts

        /// <summary>
        /// Generates functions which compute the dual or undual of general multivectors, on a group by group basis.
        /// 
        /// This function should be called early on in the code generation process, at least
        /// before any of the <c>GetDualCode()</c> functions is called.
        /// </summary>
        /// <param name="S">Specification (used for output language, GMV).</param>
        /// <param name="cgd">Where the result goes.</param>
        public static void WriteDualParts(Specification S, CGdata cgd)
        {
            G25.GMV gmv = S.m_GMV;

            string name1 = "A";
            string name2 = "B";
            string name3 = "C";
            bool ptr = true;
            int allGroups = -1;
            bool mustCast = false;
            int nbBaseTabs = (S.OutputCSharpOrJava()) ? 1 : 0;
            int nbCodeTabs = nbBaseTabs + 1;
            bool writeZeros = false;

            // get symbolic multivectors
            RefGA.Multivector[] M1 = null;
            if (S.m_gmvCodeGeneration == GMV_CODE.EXPAND)
                M1 = G25.CG.Shared.Symbolic.GMVtoSymbolicMultivector(S, gmv, name1, ptr, allGroups);

            foreach (G25.FloatType FT in S.m_floatTypes)
            {
                // map from code fragment to name of function
                Dictionary<string, string> generatedCode = new Dictionary<string, string>();

                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.";

//.........这里部分代码省略.........
开发者ID:Sciumo,项目名称:gaigen,代码行数:101,代码来源:dual_parts.cs

示例15: 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


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