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


C# SourceBuilder.AppendFormat方法代码示例

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


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

示例1: Emit

        public override void Emit(SourceBuilder sourceCode)
        {
            // open decision whether to fail
            sourceCode.AppendFront("if(");

            // fail if graph element contained within candidate was already matched
            // (previously on the pattern derivation path to another pattern element)
            // as this would cause a inter-pattern-homomorphic match
            string variableContainingCandidate = NamesOfEntities.CandidateVariable(PatternElementName);
            string isMatchedBySomeBit = "(uint)GRGEN_LGSP.LGSPElemFlags.IS_MATCHED_BY_SOME_ENCLOSING_PATTERN";

            if (!Always) {
                sourceCode.Append("searchPatternpath && ");
            }

            sourceCode.AppendFormat("({0}.lgspFlags & {1})=={1} && GRGEN_LGSP.PatternpathIsomorphyChecker.IsMatched({0}, {2})",
                variableContainingCandidate, isMatchedBySomeBit, LastMatchAtPreviousNestingLevel);

            sourceCode.Append(")\n");

            // emit check failed code
            sourceCode.AppendFront("{\n");
            sourceCode.Indent();
            CheckFailedOperations.Emit(sourceCode);
            sourceCode.Unindent();
            sourceCode.AppendFront("}\n");
        }
开发者ID:jblomer,项目名称:GrGen.NET,代码行数:27,代码来源:SearchProgram.cs

示例2: GenerateFilterStubs

        public void GenerateFilterStubs(SourceBuilder source, LGSPRulePattern rulePattern)
        {
            String rulePatternClassName = rulePattern.GetType().Name;
            String matchInterfaceName = rulePatternClassName + "." + NamesOfEntities.MatchInterfaceName(rulePattern.name);
            String matchesListType = "GRGEN_LIBGR.IMatchesExact<" + matchInterfaceName + ">";

            foreach(IFilter filter in rulePattern.Filters)
            {
                if(filter is IFilterAutoGenerated)
                    continue;

                IFilterFunction filterFunction = (IFilterFunction)filter;
                if(!filterFunction.IsExternal)
                    continue;

                if(filter.Package != null)
                {
                    source.AppendFrontFormat("namespace {0}\n", filter.Package);
                    source.AppendFront("{\n");
                    source.Indent();
                }
                source.AppendFront("public partial class MatchFilters\n");
                source.AppendFront("{\n");
                source.Indent();

                source.AppendFrontFormat("//public static void Filter_{0}(GRGEN_LGSP.LGSPGraphProcessingEnvironment procEnv, {1} matches", filter.Name, matchesListType);
                for(int i = 0; i < filterFunction.Inputs.Length; ++i)
                {
                    source.AppendFormat(", {0} {1}", TypesHelper.TypeName(filterFunction.Inputs[i]), filterFunction.InputNames[i]);
                }
                source.Append(")\n");

                source.Unindent();
                source.AppendFront("}\n");
                if(filter.Package != null)
                {
                    source.Unindent();
                    source.AppendFront("}\n");
                }
            }
        }
开发者ID:jblomer,项目名称:GrGen.NET,代码行数:41,代码来源:lgspSequenceGenerator.cs

示例3: GenerateContainerConstructor

        void GenerateContainerConstructor(SequenceExpressionContainerConstructor cc, SourceBuilder source)
        {
            string containerType = TypesHelper.XgrsTypeToCSharpType(GetContainerType(cc), model);
            string valueType = TypesHelper.XgrsTypeToCSharpType(cc.ValueType, model);
            string keyType = null;
            if(cc is SequenceExpressionMapConstructor)
                keyType = TypesHelper.XgrsTypeToCSharpType(((SequenceExpressionMapConstructor)cc).KeyType, model);

            source.Append("\n");
            source.AppendFront("public static ");
            source.Append(containerType);
            source.Append(" fillFromSequence_" + cc.Id);
            source.Append("(");
            for(int i = 0; i < cc.ContainerItems.Length; ++i)
            {
                if(i > 0)
                    source.Append(", ");
                if(keyType != null)
                    source.AppendFormat("{0} paramkey{1}, ", keyType, i);
                source.AppendFormat("{0} param{1}", valueType, i);
            }
            source.Append(")\n");
            
            source.AppendFront("{\n");
            source.Indent();
            source.AppendFrontFormat("{0} container = new {0}();\n", containerType);
            for(int i = 0; i < cc.ContainerItems.Length; ++i)
            {
                if(cc is SequenceExpressionSetConstructor)
                    source.AppendFrontFormat("container.Add(param{0}, null);\n", i);
                else if(cc is SequenceExpressionMapConstructor)
                    source.AppendFrontFormat("container.Add(paramkey{0}, param{0});\n", i);
                else if(cc is SequenceExpressionArrayConstructor)
                    source.AppendFrontFormat("container.Add(param{0});\n", i);
                else //if(cc is SequenceExpressionDequeConstructor)
                    source.AppendFrontFormat("container.Enqueue(param{0});\n", i);
            }
            source.AppendFront("return container;\n");
            source.Unindent();
            source.AppendFront("}\n");
        }
开发者ID:jblomer,项目名称:GrGen.NET,代码行数:41,代码来源:lgspSequenceGenerator.cs

示例4: Emit

 public override void Emit(SourceBuilder sourceCode)
 {
     sourceCode.AppendFormat("GRGEN_MODEL.Comparer_{0}_{1}.LastIndexOfBy(", OwnerType, Member);
     Target.Emit(sourceCode);
     sourceCode.Append(", ");
     Value.Emit(sourceCode);
     if(StartIndex != null)
     {
         sourceCode.Append(", ");
         StartIndex.Emit(sourceCode);
     }
     sourceCode.Append(")");
 }
开发者ID:jblomer,项目名称:GrGen.NET,代码行数:13,代码来源:Expression.cs

示例5: EmitFilterCall

 void EmitFilterCall(SourceBuilder source, FilterCall filterCall, string patternName, string matchesName)
 {
     if(filterCall.Name == "keepFirst" || filterCall.Name == "removeFirst"
         || filterCall.Name == "keepFirstFraction" || filterCall.Name == "removeFirstFraction"
         || filterCall.Name == "keepLast" || filterCall.Name == "removeLast"
         || filterCall.Name == "keepLastFraction" || filterCall.Name == "removeLastFraction")
     {
         switch(filterCall.Name)
         {
             case "keepFirst":
                 source.AppendFrontFormat("{0}.FilterKeepFirst((int)({1}));\n",
                     matchesName, GetSequenceExpression(filterCall.ArgumentExpressions[0], source));
                 break;
             case "keepLast":
                 source.AppendFrontFormat("{0}.FilterKeepLast((int)({1}));\n",
                     matchesName, GetSequenceExpression(filterCall.ArgumentExpressions[0], source));
                 break;
             case "keepFirstFraction":
                 source.AppendFrontFormat("{0}.FilterKeepFirstFraction((double)({1}));\n",
                     matchesName, GetSequenceExpression(filterCall.ArgumentExpressions[0], source));
                 break;
             case "keepLastFraction":
                 source.AppendFrontFormat("{0}.FilterKeepLastFraction((double)({1}));\n",
                     matchesName, GetSequenceExpression(filterCall.ArgumentExpressions[0], source));
                 break;
             case "removeFirst":
                 source.AppendFrontFormat("{0}.FilterRemoveFirst((int)({1}));\n",
                     matchesName, GetSequenceExpression(filterCall.ArgumentExpressions[0], source));
                 break;
             case "removeLast":
                 source.AppendFrontFormat("{0}.FilterRemoveLast((int)({1}));\n",
                     matchesName, GetSequenceExpression(filterCall.ArgumentExpressions[0], source));
                 break;
             case "removeFirstFraction":
                 source.AppendFrontFormat("{0}.FilterRemoveFirstFraction((double)({1}));\n",
                     matchesName, GetSequenceExpression(filterCall.ArgumentExpressions[0], source));
                 break;
             case "removeLastFraction":
                 source.AppendFrontFormat("{0}.FilterRemoveLastFraction((double)({1}));\n",
                     matchesName, GetSequenceExpression(filterCall.ArgumentExpressions[0], source));
                 break;
         }
     }
     else
     {
         if(filterCall.IsAutoGenerated && filterCall.Name == "auto")
             source.AppendFrontFormat("GRGEN_ACTIONS.{0}MatchFilters.Filter_{1}_{2}(procEnv, {3});\n",
                 TypesHelper.GetPackagePrefixDot(filterCall.Package), patternName, filterCall.Name, matchesName);
         else if(filterCall.IsAutoGenerated)
             source.AppendFrontFormat("GRGEN_ACTIONS.{0}MatchFilters.Filter_{1}_{2}_{3}(procEnv, {4});\n",
                 TypesHelper.GetPackagePrefixDot(filterCall.Package), patternName, filterCall.Name, filterCall.Entity, matchesName);
         else
         {
             source.AppendFrontFormat("GRGEN_ACTIONS.{0}MatchFilters.Filter_{1}(procEnv, {2}",
                 TypesHelper.GetPackagePrefixDot(filterCall.Package), filterCall.Name, matchesName);
             for(int i = 0; i < filterCall.ArgumentExpressions.Length; ++i)
             {
                 source.AppendFormat(", ({0})({1})",
                     TypesHelper.XgrsTypeToCSharpType(filterFunctionsToInputTypes[filterCall.Name][i], model),
                     GetSequenceExpression(filterCall.ArgumentExpressions[i], source));
             } 
             source.Append(");\n");
         }
     }
 }
开发者ID:jblomer,项目名称:GrGen.NET,代码行数:65,代码来源:lgspSequenceGenerator.cs

示例6: Dump

        public override void Dump(SourceBuilder builder)
        {
            if(Type == PushAndPopSubpatternTaskTypes.Subpattern) {
                builder.AppendFront("PushSubpatternTask Subpattern ");
            } else if(Type == PushAndPopSubpatternTaskTypes.Alternative) {
                builder.AppendFront("PushSubpatternTask Alternative ");
            } else { // Type==PushAndPopSubpatternTaskTypes.Iterated
                builder.AppendFront("PushSubpatternTask Iterated ");
            }

            if(Type == PushAndPopSubpatternTaskTypes.Subpattern) {
                builder.AppendFormat("{0} of {1} ", SubpatternElementName, SubpatternName);
            } else {
                builder.AppendFormat("{0}/{1} ", PathPrefix, AlternativeOrIteratedName);
            }

            if(Parallel)
                builder.Append("Parallel ");

            builder.Append("with ");
            for (int i = 0; i < ConnectionName.Length; ++i)
            {
                builder.AppendFormat("{0} <- {1} ",
                    ConnectionName[i], ArgumentExpressions[i]);
            }
            builder.Append("\n");
        }
开发者ID:jblomer,项目名称:GrGen.NET,代码行数:27,代码来源:SearchProgram.cs

示例7: EmitHashComputation

 void EmitHashComputation(SourceBuilder sourceCode, int i)
 {
     if(i < 0)
         sourceCode.Append("23");
     else
     {
         sourceCode.Append("(");
         EmitHashComputation(sourceCode, i - 1);
         sourceCode.AppendFormat("*17 + {0}.GetHashCode()",
             NamesOfEntities.CandidateVariable(NeededElements[i]));
         sourceCode.Append(")");
     }
 }
开发者ID:jblomer,项目名称:GrGen.NET,代码行数:13,代码来源:SearchProgram.cs

示例8: EmitSequenceComputation


//.........这里部分代码省略.........
                    SequenceComputationGraphRedirectTarget seqRedir = (SequenceComputationGraphRedirectTarget)seqComp;
                    string edgeExpr = GetSequenceExpression(seqRedir.EdgeExpr, source);
                    string tgtNodeExpr = GetSequenceExpression(seqRedir.TargetNodeExpr, source);
                    source.AppendFrontFormat("graph.RedirectTarget((GRGEN_LIBGR.IEdge){0}, (GRGEN_LIBGR.INode){1}, \"old target\");\n", edgeExpr, tgtNodeExpr);
                    source.AppendFront(SetResultVar(seqRedir, "null"));
                    break;
                }

                case SequenceComputationType.GraphRedirectSourceAndTarget:
                {
                    SequenceComputationGraphRedirectSourceAndTarget seqRedir = (SequenceComputationGraphRedirectSourceAndTarget)seqComp;
                    string edgeExpr = GetSequenceExpression(seqRedir.EdgeExpr, source);
                    string srcNodeExpr = GetSequenceExpression(seqRedir.SourceNodeExpr, source);
                    string tgtNodeExpr = GetSequenceExpression(seqRedir.TargetNodeExpr, source);
                    source.AppendFrontFormat("graph.RedirectSourceAndTarget((GRGEN_LIBGR.IEdge){0}, (GRGEN_LIBGR.INode){1}, (GRGEN_LIBGR.INode){2}, \"old source\", \"old target\");\n", edgeExpr, srcNodeExpr, tgtNodeExpr);
                    source.AppendFront(SetResultVar(seqRedir, "null"));
                    break;
                }

                case SequenceComputationType.Insert:
                {
                    SequenceComputationInsert seqIns = (SequenceComputationInsert)seqComp;
                    string graphExpr = GetSequenceExpression(seqIns.Graph, source);
                    source.AppendFrontFormat("GRGEN_LIBGR.GraphHelper.Insert((GRGEN_LIBGR.IGraph){0}, graph);\n", graphExpr);
                    source.AppendFront(SetResultVar(seqIns, "null"));
                    break;
                }

                case SequenceComputationType.InsertCopy:
                {
                    SequenceComputationInsertCopy seqInsCopy = (SequenceComputationInsertCopy)seqComp;
                    string graphExpr = GetSequenceExpression(seqInsCopy.Graph, source);
                    string rootNodeExpr = GetSequenceExpression(seqInsCopy.RootNode, source);
                    source.AppendFormat("GRGEN_LIBGR.GraphHelper.InsertCopy((GRGEN_LIBGR.IGraph){0}, (GRGEN_LIBGR.INode){1}, graph)", graphExpr, rootNodeExpr);
                    break;
                }

                case SequenceComputationType.InsertInduced:
                {
                    SequenceComputationInsertInduced seqInsInd = (SequenceComputationInsertInduced)seqComp;
                    source.Append("GRGEN_LIBGR.GraphHelper.InsertInduced((IDictionary<GRGEN_LIBGR.INode, GRGEN_LIBGR.SetValueType>)" + GetSequenceExpression(seqInsInd.NodeSet, source) + ", (GRGEN_LIBGR.INode)" + GetSequenceExpression(seqInsInd.RootNode, source) + ", graph)");
                    break;
                }

                case SequenceComputationType.InsertDefined:
                {
                    SequenceComputationInsertDefined seqInsDef = (SequenceComputationInsertDefined)seqComp;
                    source.Append("GRGEN_LIBGR.GraphHelper.InsertDefined((IDictionary<GRGEN_LIBGR.IEdge, GRGEN_LIBGR.SetValueType>)" + GetSequenceExpression(seqInsDef.EdgeSet, source) + ", (GRGEN_LIBGR.IEdge)" + GetSequenceExpression(seqInsDef.RootEdge, source) + ", graph)");
                    break;
                }

                case SequenceComputationType.Expression:
                {
                    SequenceExpression seqExpr = (SequenceExpression)seqComp;
                    source.AppendFront(SetResultVar(seqExpr, GetSequenceExpression(seqExpr, source)));
                    break;
                }

                case SequenceComputationType.BuiltinProcedureCall:
                {
                    SequenceComputationBuiltinProcedureCall seqCall = (SequenceComputationBuiltinProcedureCall)seqComp;
                    SourceBuilder sb = new SourceBuilder();
                    EmitSequenceComputation(seqCall.BuiltinProcedure, sb);
                    if(seqCall.ReturnVars.Count > 0)
                    {
                        source.AppendFront(SetVar(seqCall.ReturnVars[0], sb.ToString()));
开发者ID:jblomer,项目名称:GrGen.NET,代码行数:67,代码来源:lgspSequenceGenerator.cs

示例9: GenerateAutomorphyFilter

        private static void GenerateAutomorphyFilter(SourceBuilder source, LGSPRulePattern rulePattern)
        {
            String rulePatternClassName = TypesHelper.GetPackagePrefixDot(rulePattern.PatternGraph.Package) + rulePattern.GetType().Name;
            String matchInterfaceName = rulePatternClassName + "." + NamesOfEntities.MatchInterfaceName(rulePattern.name);
            String matchClassName = rulePatternClassName + "." + NamesOfEntities.MatchClassName(rulePattern.name);
            String matchesListType = "GRGEN_LIBGR.IMatchesExact<" + matchInterfaceName + ">";
            String filterName = "auto";
            
            source.AppendFrontFormat("public static void Filter_{0}_{1}(GRGEN_LGSP.LGSPGraphProcessingEnvironment procEnv, {2} matches)\n", 
                rulePattern.name, filterName, matchesListType);
            source.AppendFront("{\n");
            source.Indent();

            source.AppendFront("if(matches.Count < 2)\n");
            source.AppendFront("\treturn;\n");
            source.AppendFrontFormat("List<{0}> matchesArray = matches.ToList();\n", matchInterfaceName);

            source.AppendFrontFormat("if(matches.Count < 5 || {0}.Instance.patternGraph.nodes.Length + {0}.Instance.patternGraph.edges.Length < 1)\n", rulePatternClassName);
            source.AppendFront("{\n");
            source.Indent();

            source.AppendFront("for(int i = 0; i < matchesArray.Count; ++i)\n");
            source.AppendFront("{\n");
            source.Indent();
            source.AppendFront("if(matchesArray[i] == null)\n");
            source.AppendFront("\tcontinue;\n");
            source.AppendFront("for(int j = i + 1; j < matchesArray.Count; ++j)\n");
            source.AppendFront("{\n");
            source.Indent();
            source.AppendFront("if(matchesArray[j] == null)\n");
            source.AppendFront("\tcontinue;\n");
            source.AppendFront("if(GRGEN_LIBGR.SymmetryChecker.AreSymmetric(matchesArray[i], matchesArray[j], procEnv.graph))\n");
            source.AppendFront("\tmatchesArray[j] = null;\n");
            source.Unindent();
            source.AppendFront("}\n");
            source.Unindent();
            source.AppendFront("}\n");

            source.Unindent();
            source.AppendFront("}\n");
            source.AppendFront("else\n");
            source.AppendFront("{\n");
            source.Indent();

            source.AppendFrontFormat("Dictionary<int, {0}> foundMatchesOfSameMainPatternHash = new Dictionary<int, {0}>();\n", 
                matchClassName);
            source.AppendFront("for(int i = 0; i < matchesArray.Count; ++i)\n");
            source.AppendFront("{\n");
            source.Indent();
            source.AppendFrontFormat("{0} match = ({0})matchesArray[i];\n", matchClassName);
            source.AppendFront("int duplicateMatchHash = 0;\n");
            source.AppendFront("for(int j = 0; j < match.NumberOfNodes; ++j) duplicateMatchHash ^= match.getNodeAt(j).GetHashCode();\n");
            source.AppendFront("for(int j = 0; j < match.NumberOfEdges; ++j) duplicateMatchHash ^= match.getEdgeAt(j).GetHashCode();\n");
            source.AppendFront("bool contained = foundMatchesOfSameMainPatternHash.ContainsKey(duplicateMatchHash);\n");
            source.AppendFront("if(contained)\n");
            source.AppendFront("{\n");
            source.Indent();
            source.AppendFrontFormat("{0} duplicateMatchCandidate = foundMatchesOfSameMainPatternHash[duplicateMatchHash];\n", matchClassName);
            source.AppendFront("do\n");
            source.AppendFront("{\n");
            source.Indent();
            source.AppendFront("if(GRGEN_LIBGR.SymmetryChecker.AreSymmetric(match, duplicateMatchCandidate, procEnv.graph))\n");
            source.AppendFront("{\n");
            source.Indent();
            source.AppendFront("matchesArray[i] = null;\n");
            source.AppendFrontFormat("goto label_auto_{0};\n", rulePatternClassName.Replace('.', '_'));
            source.Unindent();
            source.AppendFront("}\n");
            source.Unindent();
            source.AppendFront("}\n");
            source.AppendFront("while((duplicateMatchCandidate = duplicateMatchCandidate.nextWithSameHash) != null);\n");
            source.Unindent();
            source.AppendFront("}\n");
            source.AppendFront("if(!contained)\n");
            source.AppendFront("\tfoundMatchesOfSameMainPatternHash[duplicateMatchHash] = match;\n");
            source.AppendFront("else\n");
            source.AppendFront("{\n");
            source.Indent();
            source.AppendFrontFormat("{0} duplicateMatchCandidate = foundMatchesOfSameMainPatternHash[duplicateMatchHash];\n", matchClassName);
            source.AppendFront("while(duplicateMatchCandidate.nextWithSameHash != null) duplicateMatchCandidate = duplicateMatchCandidate.nextWithSameHash;\n");
            source.AppendFront("duplicateMatchCandidate.nextWithSameHash = match;\n");
            source.Unindent();
            source.AppendFront("}\n");
            source.AppendFormat("label_auto_{0}: ;\n", rulePatternClassName.Replace('.', '_'));
            source.Unindent();
            source.AppendFront("}\n");
            source.AppendFrontFormat("foreach({0} toClean in foundMatchesOfSameMainPatternHash.Values) toClean.CleanNextWithSameHash();\n", matchClassName);
            
            source.Unindent();
            source.AppendFront("}\n");

            source.AppendFront("matches.FromList();\n");

            source.Unindent();
            source.AppendFront("}\n");
        }
开发者ID:jblomer,项目名称:GrGen.NET,代码行数:96,代码来源:lgspSequenceGenerator.cs

示例10: GenerateActionImplementation


//.........这里部分代码省略.........
            sb.AppendFront("}\n");

            sb.AppendFront("bool GRGEN_LIBGR.IAction.ApplyPlus(GRGEN_LIBGR.IActionExecutionEnvironment actionEnv, params object[] parameters)\n");
            sb.AppendFront("{\n");
            sb.Indent();
            sb.AppendFrontFormat("return ApplyPlus(actionEnv{0});\n", inArgumentsFromArray);
            sb.Unindent(); 
            sb.AppendFront("}\n");

            sb.AppendFront("bool GRGEN_LIBGR.IAction.ApplyMinMax(GRGEN_LIBGR.IActionExecutionEnvironment actionEnv, int min, int max)\n");
            sb.AppendFront("{\n");
            sb.Indent();
            if(matchingPattern.Inputs.Length == 0)
                sb.AppendFront("return ApplyMinMax(actionEnv, min, max);\n");
            else 
                sb.AppendFront("throw new Exception(); return false;\n");
            sb.Unindent(); 
            sb.AppendFront("}\n");

            sb.AppendFront("bool GRGEN_LIBGR.IAction.ApplyMinMax(GRGEN_LIBGR.IActionExecutionEnvironment actionEnv, int min, int max, params object[] parameters)\n");
            sb.AppendFront("{\n");
            sb.Indent(); 
            sb.AppendFrontFormat("return ApplyMinMax(actionEnv, min, max{0});\n", inArgumentsFromArray);
            sb.Unindent(); 
            sb.AppendFront("}\n");

            sb.AppendFront("void GRGEN_LIBGR.IAction.Filter(GRGEN_LIBGR.IActionExecutionEnvironment actionEnv, GRGEN_LIBGR.IMatches matches, GRGEN_LIBGR.FilterCall filter)\n");
            sb.AppendFront("{\n");
            sb.Indent();
            sb.AppendFront("if(filter.IsAutoSupplied) {\n");
            sb.Indent();
            sb.AppendFront("switch(filter.Name) {\n");
            sb.Indent();
            sb.AppendFront("case \"keepFirst\": matches.FilterKeepFirst((int)(filter.ArgumentExpressions[0]!=null ? filter.ArgumentExpressions[0].Evaluate((GRGEN_LIBGR.IGraphProcessingEnvironment)actionEnv) : filter.Arguments[0])); break;\n");
            sb.AppendFront("case \"keepLast\": matches.FilterKeepLast((int)(filter.ArgumentExpressions[0]!=null ? filter.ArgumentExpressions[0].Evaluate((GRGEN_LIBGR.IGraphProcessingEnvironment)actionEnv) : filter.Arguments[0])); break;\n");
            sb.AppendFront("case \"keepFirstFraction\": matches.FilterKeepFirstFraction((double)(filter.ArgumentExpressions[0]!=null ? filter.ArgumentExpressions[0].Evaluate((GRGEN_LIBGR.IGraphProcessingEnvironment)actionEnv) : filter.Arguments[0])); break;\n");
            sb.AppendFront("case \"keepLastFraction\": matches.FilterKeepLastFraction((double)(filter.ArgumentExpressions[0]!=null ? filter.ArgumentExpressions[0].Evaluate((GRGEN_LIBGR.IGraphProcessingEnvironment)actionEnv) : filter.Arguments[0])); break;\n");
            sb.AppendFront("case \"removeFirst\": matches.FilterRemoveFirst((int)(filter.ArgumentExpressions[0]!=null ? filter.ArgumentExpressions[0].Evaluate((GRGEN_LIBGR.IGraphProcessingEnvironment)actionEnv) : filter.Arguments[0])); break;\n");
            sb.AppendFront("case \"removeLast\": matches.FilterRemoveLast((int)(filter.ArgumentExpressions[0]!=null ? filter.ArgumentExpressions[0].Evaluate((GRGEN_LIBGR.IGraphProcessingEnvironment)actionEnv) : filter.Arguments[0])); break;\n");
            sb.AppendFront("case \"removeFirstFraction\": matches.FilterRemoveFirstFraction((double)(filter.ArgumentExpressions[0]!=null ? filter.ArgumentExpressions[0].Evaluate((GRGEN_LIBGR.IGraphProcessingEnvironment)actionEnv) : filter.Arguments[0])); break;\n");
            sb.AppendFront("case \"removeLastFraction\": matches.FilterRemoveLastFraction((double)(filter.ArgumentExpressions[0]!=null ? filter.ArgumentExpressions[0].Evaluate((GRGEN_LIBGR.IGraphProcessingEnvironment)actionEnv) : filter.Arguments[0])); break;\n");
            sb.AppendFront("default: throw new Exception(\"Unknown auto supplied filter name!\");\n");
            sb.Unindent();
            sb.AppendFront("}\n");
            sb.AppendFront("return;\n");
            sb.Unindent();
            sb.AppendFront("}\n");
            sb.AppendFront("switch(filter.FullName) {\n");
            sb.Indent();
            foreach(IFilter filter in matchingPattern.Filters)
            {
                if(filter is IFilterAutoGenerated)
                {
                    if(((IFilterAutoGenerated)filter).Entity != null)
                    {
                        sb.AppendFrontFormat("case \"{1}<{2}>\": GRGEN_ACTIONS.{4}MatchFilters.Filter_{0}_{1}_{2}((GRGEN_LGSP.LGSPGraphProcessingEnvironment)actionEnv, ({3})matches); break;\n",
                            patternName, filter.Name, ((IFilterAutoGenerated)filter).Entity, matchesType, TypesHelper.GetPackagePrefixDot(filter.Package));
                        if(filter.Package != null)
                            sb.AppendFrontFormat("case \"{5}{1}<{2}>\": GRGEN_ACTIONS.{4}MatchFilters.Filter_{0}_{1}_{2}((GRGEN_LGSP.LGSPGraphProcessingEnvironment)actionEnv, ({3})matches); break;\n",
                                patternName, filter.Name, ((IFilterAutoGenerated)filter).Entity, matchesType, filter.Package + ".", filter.Package + "::");
                    }
                    else // auto
                    {
                        sb.AppendFrontFormat("case \"{1}\": GRGEN_ACTIONS.{3}MatchFilters.Filter_{0}_{1}((GRGEN_LGSP.LGSPGraphProcessingEnvironment)actionEnv, ({2})matches); break;\n",
                            patternName, filter.Name, matchesType, TypesHelper.GetPackagePrefixDot(filter.Package));
                        if(filter.Package != null)
                            sb.AppendFrontFormat("case \"{4}{1}\": GRGEN_ACTIONS.{3}MatchFilters.Filter_{0}_{1}((GRGEN_LGSP.LGSPGraphProcessingEnvironment)actionEnv, ({2})matches); break;\n",
                                patternName, filter.Name, matchesType, filter.Package + ".", filter.Package + "::");
                    }
                }
                else
                {
                    IFilterFunction filterFunction = (IFilterFunction)filter;
                    sb.AppendFrontFormat("case \"{0}\": GRGEN_ACTIONS.{1}MatchFilters.Filter_{2}((GRGEN_LGSP.LGSPGraphProcessingEnvironment)actionEnv, ({3})matches",
                        filterFunction.Name, TypesHelper.GetPackagePrefixDot(filterFunction.Package), filterFunction.Name, matchesType);
                    for(int i=0; i<filterFunction.Inputs.Length; ++i)
                    {
                        sb.AppendFormat(", ({0})(filter.ArgumentExpressions[{1}]!=null ? filter.ArgumentExpressions[{1}].Evaluate((GRGEN_LIBGR.IGraphProcessingEnvironment)actionEnv) : filter.Arguments[{1}])", 
                            TypesHelper.TypeName(filterFunction.Inputs[i]), i);
                    }
                    sb.Append("); break;\n");
                    if(filter.Package != null)
                    {
                        sb.AppendFrontFormat("case \"{4}{0}\": GRGEN_ACTIONS.{1}MatchFilters.Filter_{2}((GRGEN_LGSP.LGSPGraphProcessingEnvironment)actionEnv, ({3})matches",
                            filterFunction.Name, TypesHelper.GetPackagePrefixDot(filterFunction.Package), filterFunction.Name, matchesType, filter.Package + "::");
                        for(int i = 0; i < filterFunction.Inputs.Length; ++i)
                        {
                            sb.AppendFormat(", ({0})(filter.ArgumentExpressions[{1}]!=null ? filter.ArgumentExpressions[{1}].Evaluate((GRGEN_LIBGR.IGraphProcessingEnvironment)actionEnv) : filter.Arguments[{1}])",
                                TypesHelper.TypeName(filterFunction.Inputs[i]), i);
                        }
                        sb.Append("); break;\n");
                    }
                }
            }
            sb.AppendFront("default: throw new Exception(\"Unknown filter name!\");\n");
            sb.Unindent();
            sb.AppendFront("}\n");
            sb.Unindent();
            sb.AppendFront("}\n");
        }
开发者ID:jblomer,项目名称:GrGen.NET,代码行数:101,代码来源:lgspMatcherGenerator.cs


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