コード例 #1
0
        public void EmitMatchingAndCloning(SourceBuilder source, String maxMatches)
        {
            String parameters = seqHelper.BuildParameters(seqRule, ArgumentExpressions, source);

            EmitMatching(source, parameters, maxMatches);
            EmitCloning(source);
        }
コード例 #2
0
        public void Emit(SourceBuilder source, SequenceGenerator seqGen, bool fireDebugEvents)
        {
            source.AppendFront(COMP_HELPER.SetResultVar(seqFor, "true"));

            String parameters = seqHelper.BuildParameters(seqRule, ArgumentExpressions, source);

            source.AppendFront(matchesType + " " + matchesName + " = " + ruleName
                               + ".Match(procEnv, procEnv.MaxMatches" + parameters + ");\n");
            source.AppendFront("procEnv.PerformanceInfo.MatchesFound += " + matchesName + ".Count;\n");
            for (int i = 0; i < seqRule.Filters.Count; ++i)
            {
                seqExprGen.EmitFilterCall(source, (SequenceFilterCallCompiled)seqRule.Filters[i], patternName, matchesName, seqRule.PackagePrefixedName, false);
            }

            source.AppendFront("if(" + matchesName + ".Count != 0) {\n");
            source.Indent();
            source.AppendFront(matchesName + " = (" + matchesType + ")" + matchesName + ".Clone();\n");
            if (fireDebugEvents)
            {
                source.AppendFront("procEnv.Finishing(" + matchesName + ", " + specialStr + ");\n");
            }

            String returnParameterDeclarations;
            String returnArguments;
            String returnAssignments;
            String returnParameterDeclarationsAllCall;
            String intermediateReturnAssignmentsAllCall;
            String returnAssignmentsAllCall;

            seqHelper.BuildReturnParameters(seqRule, ReturnVars,
                                            out returnParameterDeclarations, out returnArguments, out returnAssignments,
                                            out returnParameterDeclarationsAllCall, out intermediateReturnAssignmentsAllCall, out returnAssignmentsAllCall);

            // apply the sequence for every match found
            String enumeratorName = "enum_" + seqFor.Id;

            source.AppendFront("IEnumerator<" + matchType + "> " + enumeratorName + " = " + matchesName + ".GetEnumeratorExact();\n");
            source.AppendFront("while(" + enumeratorName + ".MoveNext())\n");
            source.AppendFront("{\n");
            source.Indent();
            source.AppendFront(matchType + " " + matchName + " = " + enumeratorName + ".Current;\n");
            source.AppendFront(seqHelper.SetVar(seqFor.Var, matchName));

            seqGen.EmitSequence(seqFor.Seq, source);

            source.AppendFront(COMP_HELPER.SetResultVar(seqFor, COMP_HELPER.GetResultVar(seqFor) + " & " + COMP_HELPER.GetResultVar(seqFor.Seq)));
            source.Unindent();
            source.AppendFront("}\n");

            source.Unindent();
            source.AppendFront("}\n");
        }
コード例 #3
0
        public void EmitMatching(SourceBuilder source, SequenceGenerator seqGen, String matchListName)
        {
            String parameters = seqHelper.BuildParameters(seqRule, ArgumentExpressions, source);

            source.AppendFront(matchesType + " " + matchesName + " = " + ruleName
                               + ".Match(procEnv, procEnv.MaxMatches" + parameters + ");\n");
            source.AppendFront("procEnv.PerformanceInfo.MatchesFound += " + matchesName + ".Count;\n");
            for (int i = 0; i < seqRule.Filters.Count; ++i)
            {
                seqExprGen.EmitFilterCall(source, (SequenceFilterCallCompiled)seqRule.Filters[i], patternName, matchesName, seqRule.PackagePrefixedName, false);
            }

            source.AppendFront("if(" + matchesName + ".Count != 0) {\n");
            source.Indent();
            source.AppendFrontFormat("{0}.AddRange({1});\n", matchListName, matchesName);
            source.Unindent();
            source.AppendFront("}\n");
        }
コード例 #4
0
        public void EmitMatching(SourceBuilder source, SequenceGenerator seqGen)
        {
            String parameters = seqHelper.BuildParameters(seqRule, ArgumentExpressions, source);

            source.AppendFront(matchesType + " " + matchesName + " = " + ruleName
                               + ".Match(procEnv, " + (seqRule.SequenceType == SequenceType.RuleCall ? "1" : "procEnv.MaxMatches")
                               + parameters + ");\n");
            source.AppendFront("procEnv.PerformanceInfo.MatchesFound += " + matchesName + ".Count;\n");
            for (int i = 0; i < seqRule.Filters.Count; ++i)
            {
                seqExprGen.EmitFilterCall(source, (SequenceFilterCallCompiled)seqRule.Filters[i], patternName, matchesName, seqRule.PackagePrefixedName, false);
            }

            source.AppendFront("if(" + matchesName + ".Count != 0) {\n");
            source.Indent();
            source.AppendFront(COMP_HELPER.SetResultVar(seqSome, "true"));
            source.Unindent();
            source.AppendFront("}\n");
        }
コード例 #5
0
        public void Emit(SourceBuilder source, SequenceGenerator seqGen, bool fireDebugEvents)
        {
            String parameters = seqHelper.BuildParameters(seqRule, ArgumentExpressions, source);

            seqMatcherGen.EmitMatching(source, parameters, "procEnv.MaxMatches");
            SequenceRuleCallMatcherGenerator.EmitPreMatchEventFiring(source, matchesName);
            seqMatcherGen.EmitFiltering(source);
            seqMatcherGen.EmitCloning(source);

            source.AppendFront("if(" + matchesName + ".Count == 0) {\n");
            source.Indent();
            source.AppendFront(COMP_HELPER.SetResultVar(seq, "false"));
            source.Unindent();
            source.AppendFront("} else {\n");
            source.Indent();
            source.AppendFront(COMP_HELPER.SetResultVar(seq, "false"));
            if (fireDebugEvents)
            {
                source.AppendFront("procEnv.Finishing(" + matchesName + ", " + specialStr + ");\n");
            }

            String returnParameterDeclarations;
            String returnArguments;
            String returnAssignments;
            String returnParameterDeclarationsAllCall;
            String intermediateReturnAssignmentsAllCall;
            String returnAssignmentsAllCall;

            seqHelper.BuildReturnParameters(seqRule, ReturnVars,
                                            out returnParameterDeclarations, out returnArguments, out returnAssignments,
                                            out returnParameterDeclarationsAllCall, out intermediateReturnAssignmentsAllCall, out returnAssignmentsAllCall);

            // apply the rule and the following sequence for every match found
            String enumeratorName = "enum_" + seq.Id;

            source.AppendFront("IEnumerator<" + matchType + "> " + enumeratorName + " = " + matchesName + ".GetEnumeratorExact();\n");
            source.AppendFront("while(" + enumeratorName + ".MoveNext())\n");
            source.AppendFront("{\n");
            source.Indent();
            source.AppendFront(matchType + " " + matchName + " = " + enumeratorName + ".Current;\n");

            source.AppendFront("procEnv.Matched(" + matchesName + ", " + matchName + ", " + specialStr + ");\n");
            if (returnParameterDeclarations.Length != 0)
            {
                source.AppendFront(returnParameterDeclarations + "\n");
            }

            source.AppendFront(ruleName + ".Modify(procEnv, " + matchName + returnArguments + ");\n");
            if (returnAssignments.Length != 0)
            {
                source.AppendFront(returnAssignments + "\n");
            }
            source.AppendFront("++procEnv.PerformanceInfo.RewritesPerformed;\n");
            if (fireDebugEvents)
            {
                source.AppendFront("procEnv.Finished(" + matchesName + ", " + specialStr + ");\n");
            }

            // rule applied, now execute the sequence
            seqGen.EmitSequence(seq.Sequence, source);

            source.AppendFront(COMP_HELPER.SetResultVar(seq, COMP_HELPER.GetResultVar(seq) + "|" + COMP_HELPER.GetResultVar(seq.Sequence)));

            source.Unindent();
            source.AppendFront("}\n");

            source.Unindent();
            source.AppendFront("}\n");
        }
コード例 #6
0
        public void Emit(SourceBuilder source, SequenceGenerator seqGen, bool fireDebugEvents)
        {
            String parameterDeclarations = null;
            String parameters            = null;

            if (seqRule.Subgraph != null)
            {
                parameters = seqHelper.BuildParametersInDeclarations(seqRule, ArgumentExpressions, source, out parameterDeclarations);
            }
            else
            {
                parameters = seqHelper.BuildParameters(seqRule, ArgumentExpressions, source);
            }

            if (seqRule.Subgraph != null)
            {
                source.AppendFront(parameterDeclarations + "\n");
                source.AppendFront("procEnv.SwitchToSubgraph((GRGEN_LIBGR.IGraph)" + seqHelper.GetVar(seqRule.Subgraph) + ");\n");
                source.AppendFront("graph = ((GRGEN_LGSP.LGSPActionExecutionEnvironment)procEnv).graph;\n");
            }

            source.AppendFront(matchesType + " " + matchesName + " = " + ruleName
                               + ".Match(procEnv, " + (seqRule.SequenceType == SequenceType.RuleCall ? "1" : "procEnv.MaxMatches")
                               + parameters + ");\n");
            source.AppendFront("procEnv.PerformanceInfo.MatchesFound += " + matchesName + ".Count;\n");
            for (int i = 0; i < seqRule.Filters.Count; ++i)
            {
                seqExprGen.EmitFilterCall(source, (SequenceFilterCallCompiled)seqRule.Filters[i], patternName, matchesName, seqRule.PackagePrefixedName, false);
            }

            if (seqRule is SequenceRuleCountAllCall)
            {
                SequenceRuleCountAllCall seqRuleCountAll = (SequenceRuleCountAllCall)seqRule;
                source.AppendFront(seqHelper.SetVar(seqRuleCountAll.CountResult, matchesName + ".Count"));
            }

            String insufficientMatchesCondition;

            if (seqRule is SequenceRuleAllCall &&
                ((SequenceRuleAllCall)seqRule).ChooseRandom &&
                ((SequenceRuleAllCall)seqRule).MinSpecified)
            {
                SequenceRuleAllCall seqRuleAll = (SequenceRuleAllCall)seqRule;
                String minMatchesVarName       = "minmatchesvar_" + seqRuleAll.Id;
                source.AppendFrontFormat("int {0} = (int){1};\n", minMatchesVarName, seqHelper.GetVar(seqRuleAll.MinVarChooseRandom));
                insufficientMatchesCondition = matchesName + ".Count < " + minMatchesVarName;
            }
            else
            {
                insufficientMatchesCondition = matchesName + ".Count == 0";
            }

            source.AppendFrontFormat("if({0}) {{\n", insufficientMatchesCondition);
            source.Indent();
            source.AppendFront(COMP_HELPER.SetResultVar(seqRule, "false"));
            source.Unindent();
            source.AppendFront("} else {\n");
            source.Indent();
            source.AppendFront(COMP_HELPER.SetResultVar(seqRule, "true"));
            if (fireDebugEvents)
            {
                source.AppendFront("procEnv.Matched(" + matchesName + ", null, " + specialStr + ");\n");
            }
            if (fireDebugEvents)
            {
                source.AppendFront("procEnv.Finishing(" + matchesName + ", " + specialStr + ");\n");
            }

            SequenceRuleOrRuleAllCallRewritingGenerator rewritingGen = new SequenceRuleOrRuleAllCallRewritingGenerator(this);

            if (seqRule.SequenceType == SequenceType.RuleCall)
            {
                rewritingGen.EmitRewritingRuleCall(source);
            }
            else if (seqRule.SequenceType == SequenceType.RuleCountAllCall || !((SequenceRuleAllCall)seqRule).ChooseRandom) // seq.SequenceType == SequenceType.RuleAll
            {
                rewritingGen.EmitRewritingRuleCountAllCallOrRuleAllCallNonRandom(source);
            }
            else // seq.SequenceType == SequenceType.RuleAll && ((SequenceRuleAll)seqRule).ChooseRandom
            {
                rewritingGen.EmitRewritingRuleAllCallRandom(source);
            }

            if (fireDebugEvents)
            {
                source.AppendFront("procEnv.Finished(" + matchesName + ", " + specialStr + ");\n");
            }

            source.Unindent();
            source.AppendFront("}\n");

            if (seqRule.Subgraph != null)
            {
                source.AppendFront("procEnv.ReturnFromSubgraph();\n");
                source.AppendFront("graph = ((GRGEN_LGSP.LGSPActionExecutionEnvironment)procEnv).graph;\n");
            }
        }
コード例 #7
0
        public void Emit(SourceBuilder source, SequenceGenerator seqGen, bool fireDebugEvents)
        {
            String parameters = seqHelper.BuildParameters(seqRule, ArgumentExpressions, source);

            seqMatcherGen.EmitMatching(source, parameters, "procEnv.MaxMatches");
            SequenceRuleCallMatcherGenerator.EmitPreMatchEventFiring(source, matchesName);
            seqMatcherGen.EmitFiltering(source);
            seqMatcherGen.EmitCloning(source);

            source.AppendFront("if(" + matchesName + ".Count == 0) {\n");
            source.Indent();
            source.AppendFront(COMP_HELPER.SetResultVar(seq, "false"));
            source.Unindent();
            source.AppendFront("} else {\n");
            source.Indent();
            source.AppendFront(COMP_HELPER.SetResultVar(seq, "true")); // shut up compiler
            if (fireDebugEvents)
            {
                source.AppendFront("procEnv.Finishing(" + matchesName + ", " + specialStr + ");\n");
            }

            String returnParameterDeclarations;
            String returnArguments;
            String returnAssignments;
            String returnParameterDeclarationsAllCall;
            String intermediateReturnAssignmentsAllCall;
            String returnAssignmentsAllCall;

            seqHelper.BuildReturnParameters(seqRule, ReturnVars,
                                            out returnParameterDeclarations, out returnArguments, out returnAssignments,
                                            out returnParameterDeclarationsAllCall, out intermediateReturnAssignmentsAllCall, out returnAssignmentsAllCall);

            // apply the rule and the following sequence for every match found,
            // until the first rule and sequence execution succeeded
            // rolling back the changes of failing executions until then
            String enumeratorName   = "enum_" + seq.Id;
            String matchesTriedName = "matchesTried_" + seq.Id;

            source.AppendFront("int " + matchesTriedName + " = 0;\n");
            source.AppendFront("IEnumerator<" + matchType + "> " + enumeratorName + " = " + matchesName + ".GetEnumeratorExact();\n");
            source.AppendFront("while(" + enumeratorName + ".MoveNext())\n");
            source.AppendFront("{\n");
            source.Indent();
            source.AppendFront(matchType + " " + matchName + " = " + enumeratorName + ".Current;\n");
            source.AppendFront("++" + matchesTriedName + ";\n");

            // start a transaction
            String transactionIdName = "transID_" + seq.Id;

            source.AppendFront("int " + transactionIdName + " = procEnv.TransactionManager.Start();\n");
            String oldRewritesPerformedName = "oldRewritesPerformed_" + seq.Id;

            source.AppendFront("int " + oldRewritesPerformedName + " = procEnv.PerformanceInfo.RewritesPerformed;\n");
            if (fireDebugEvents)
            {
                source.AppendFront("procEnv.Matched(" + matchesName + ", " + matchName + ", " + specialStr + ");\n");
            }
            if (returnParameterDeclarations.Length != 0)
            {
                source.AppendFront(returnParameterDeclarations + "\n");
            }

            source.AppendFront(ruleName + ".Modify(procEnv, " + matchName + returnArguments + ");\n");
            if (returnAssignments.Length != 0)
            {
                source.AppendFront(returnAssignments + "\n");
            }
            source.AppendFront("++procEnv.PerformanceInfo.RewritesPerformed;\n");
            if (fireDebugEvents)
            {
                source.AppendFront("procEnv.Finished(" + matchesName + ", " + specialStr + ");\n");
            }

            // rule applied, now execute the sequence
            seqGen.EmitSequence(seq.Seq, source);

            // if sequence execution failed, roll the changes back and try the next match of the rule
            source.AppendFront("if(!" + COMP_HELPER.GetResultVar(seq.Seq) + ") {\n");
            source.Indent();
            source.AppendFront("procEnv.TransactionManager.Rollback(" + transactionIdName + ");\n");
            source.AppendFront("procEnv.PerformanceInfo.RewritesPerformed = " + oldRewritesPerformedName + ";\n");

            source.AppendFront("if(" + matchesTriedName + " < " + matchesName + ".Count) {\n"); // further match available -> try it
            source.Indent();
            source.AppendFront("continue;\n");
            source.Unindent();
            source.AppendFront("} else {\n"); // all matches tried, all failed later on -> end in fail
            source.Indent();
            source.AppendFront(COMP_HELPER.SetResultVar(seq, "false"));
            source.AppendFront("break;\n");
            source.Unindent();
            source.AppendFront("}\n");

            source.Unindent();
            source.AppendFront("}\n");

            // if sequence execution succeeded, commit the changes so far and succeed
            source.AppendFront("procEnv.TransactionManager.Commit(" + transactionIdName + ");\n");
            source.AppendFront(COMP_HELPER.SetResultVar(seq, "true"));
            source.AppendFront("break;\n");

            source.Unindent();
            source.AppendFront("}\n");

            source.Unindent();
            source.AppendFront("}\n");
        }