Esempio n. 1
0
        public override void Emit(SourceBuilder sourceCode)
        {
            if (sourceCode.CommentSourceCode)
            {
                if (Type == PushAndPopSubpatternTaskTypes.Subpattern)
                {
                    sourceCode.AppendFrontFormat("// Pop subpattern matching task for {0}\n", SubpatternElementName);
                }
                else if (Type == PushAndPopSubpatternTaskTypes.Alternative)
                {
                    sourceCode.AppendFrontFormat("// Pop alternative matching task for {0}\n", PathPrefix + AlternativeOrIteratedName);
                }
                else // if(Type==PushAndPopSubpatternTaskTypes.Iterated)
                {
                    sourceCode.AppendFrontFormat("// Pop iterated matching task for {0}\n", PathPrefix + AlternativeOrIteratedName);
                }
            }

            sourceCode.AppendFrontFormat("{0}openTasks.Pop();\n", NegativeIndependentNamePrefix);

            string variableContainingTask;
            string typeOfVariableContainingTask;

            if (Type == PushAndPopSubpatternTaskTypes.Subpattern)
            {
                variableContainingTask       = NamesOfEntities.TaskVariable(SubpatternElementName, NegativeIndependentNamePrefix);
                typeOfVariableContainingTask = NamesOfEntities.TypeOfTaskVariable(SubpatternName, false, false);
            }
            else if (Type == PushAndPopSubpatternTaskTypes.Alternative)
            {
                variableContainingTask       = NamesOfEntities.TaskVariable(AlternativeOrIteratedName, NegativeIndependentNamePrefix);
                typeOfVariableContainingTask = NamesOfEntities.TypeOfTaskVariable(PathPrefix + AlternativeOrIteratedName, true, false);
            }
            else // if(Type==PushAndPopSubpatternTaskTypes.Iterated)
            {
                variableContainingTask       = NamesOfEntities.TaskVariable(AlternativeOrIteratedName, NegativeIndependentNamePrefix);
                typeOfVariableContainingTask = NamesOfEntities.TypeOfTaskVariable(PathPrefix + AlternativeOrIteratedName, false, true);
            }
            string parallelizationThreadId = Parallel ? ", threadId" : "";

            sourceCode.AppendFrontFormat("{0}.releaseTask({1}{2});\n",
                                         typeOfVariableContainingTask, variableContainingTask, parallelizationThreadId);
        }
Esempio n. 2
0
        public override void Emit(SourceBuilder sourceCode)
        {
            if (sourceCode.CommentSourceCode)
            {
                if (Type == PushAndPopSubpatternTaskTypes.Subpattern)
                {
                    sourceCode.AppendFrontFormat("// Push subpattern matching task for {0}\n", SubpatternElementName);
                }
                else if (Type == PushAndPopSubpatternTaskTypes.Alternative)
                {
                    sourceCode.AppendFrontFormat("// Push alternative matching task for {0}\n", PathPrefix + AlternativeOrIteratedName);
                }
                else // if(Type==PushAndPopSubpatternTaskTypes.Iterated)
                {
                    sourceCode.AppendFrontFormat("// Push iterated matching task for {0}\n", PathPrefix + AlternativeOrIteratedName);
                }
            }

            string variableContainingTask;
            string parallelizationThreadId = Parallel ? ", threadId" : "";

            if (Type == PushAndPopSubpatternTaskTypes.Subpattern)
            {
                // create matching task for subpattern
                variableContainingTask = NamesOfEntities.TaskVariable(SubpatternElementName, NegativeIndependentNamePrefix);
                string typeOfVariableContainingTask = NamesOfEntities.TypeOfTaskVariable(SubpatternName, false, false);
                sourceCode.AppendFrontFormat("{0} {1} = {0}.getNewTask(actionEnv, {2}openTasks{3});\n",
                                             typeOfVariableContainingTask, variableContainingTask, NegativeIndependentNamePrefix, parallelizationThreadId);
            }
            else if (Type == PushAndPopSubpatternTaskTypes.Alternative)
            {
                // create matching task for alternative
                variableContainingTask = NamesOfEntities.TaskVariable(AlternativeOrIteratedName, NegativeIndependentNamePrefix);
                string typeOfVariableContainingTask = NamesOfEntities.TypeOfTaskVariable(PathPrefix + AlternativeOrIteratedName, true, false);
                string patternGraphPath             = RulePatternClassName + ".Instance.";
                if (RulePatternClassName.Substring(RulePatternClassName.IndexOf('_') + 1) == PathPrefixInRulePatternClass.Substring(0, PathPrefixInRulePatternClass.Length - 1))
                {
                    patternGraphPath += "patternGraph";
                }
                else
                {
                    patternGraphPath += PathPrefixInRulePatternClass.Substring(0, PathPrefixInRulePatternClass.Length - 1);
                }
                string alternativeCases = patternGraphPath + ".alternatives[(int)" + RulePatternClassName + "."
                                          + PathPrefixInRulePatternClass + "AltNums.@" + AlternativeNameInRulePatternClass + "].alternativeCases";
                sourceCode.AppendFrontFormat("{0} {1} = {0}.getNewTask(actionEnv, {2}openTasks, {3}{4});\n",
                                             typeOfVariableContainingTask, variableContainingTask, NegativeIndependentNamePrefix, alternativeCases, parallelizationThreadId);
            }
            else // if(Type == PushAndPopSubpatternTaskTypes.Iterated)
            {
                // create matching task for iterated
                variableContainingTask = NamesOfEntities.TaskVariable(AlternativeOrIteratedName, NegativeIndependentNamePrefix);
                string typeOfVariableContainingTask = NamesOfEntities.TypeOfTaskVariable(PathPrefix + AlternativeOrIteratedName, false, true);
                sourceCode.AppendFrontFormat("{0} {1} = {0}.getNewTask(actionEnv, {2}openTasks{3});\n",
                                             typeOfVariableContainingTask, variableContainingTask, NegativeIndependentNamePrefix, parallelizationThreadId);
            }

            // fill in connections
            for (int i = 0; i < ConnectionName.Length; ++i)
            {
                sourceCode.AppendFrontFormat("{0}.{1} = {2};\n",
                                             variableContainingTask, ConnectionName[i], ArgumentExpressions[i]);
            }

            // fill in values needed for patternpath handling
            sourceCode.AppendFrontFormat("{0}.searchPatternpath = {1};\n",
                                         variableContainingTask, SearchPatternpath);
            sourceCode.AppendFrontFormat("{0}.matchOfNestingPattern = {1};\n",
                                         variableContainingTask, MatchOfNestingPattern);
            sourceCode.AppendFrontFormat("{0}.lastMatchAtPreviousNestingLevel = {1};\n",
                                         variableContainingTask, LastMatchAtPreviousNestingLevel);

            // push matching task to open tasks stack
            sourceCode.AppendFrontFormat("{0}openTasks.Push({1});\n", NegativeIndependentNamePrefix, variableContainingTask);
        }