Ejemplo n.º 1
0
        public SequenceInvocationParameterBindings Copy(Dictionary <SequenceVariable, SequenceVariable> originalToCopy, IGraphProcessingEnvironment procEnv)
        {
            SequenceInvocationParameterBindings copy = (SequenceInvocationParameterBindings)MemberwiseClone();

            copy.ArgumentExpressions = new SequenceExpression[ArgumentExpressions.Length];
            for (int i = 0; i < ArgumentExpressions.Length; ++i)
            {
                copy.ArgumentExpressions[i] = ArgumentExpressions[i].CopyExpression(originalToCopy, procEnv);
            }
            copy.ReturnVars = new SequenceVariable[ReturnVars.Length];
            for (int i = 0; i < ReturnVars.Length; ++i)
            {
                copy.ReturnVars[i] = ReturnVars[i].Copy(originalToCopy, procEnv);
            }
            copy.Arguments = new object[Arguments.Length];
            for (int i = 0; i < Arguments.Length; ++i)
            {
                copy.Arguments[i] = Arguments[i];
            }
            if (copy.Subgraph != null)
            {
                copy.Subgraph = Subgraph.Copy(originalToCopy, procEnv);
            }
            return(copy);
        }
Ejemplo n.º 2
0
 public SequenceSequenceCall(SequenceInvocationParameterBindings paramBindings, bool special)
     : base(special, SequenceType.SequenceCall)
 {
     ParamBindings = paramBindings;
 }
Ejemplo n.º 3
0
 public abstract override bool Apply(SequenceInvocationParameterBindings sequenceInvocation,
     IGraphProcessingEnvironment procEnv);
Ejemplo n.º 4
0
        // applies the sequence of/in the sequence definition
        protected bool ApplyImpl(SequenceInvocationParameterBindings sequenceInvocation,
            IGraphProcessingEnvironment procEnv)
        {
            if(sequenceInvocation.ArgumentExpressions.Length != InputVariables.Length)
                throw new Exception("Number of input parameters given and expected differ for " + Symbol);
            if(sequenceInvocation.ReturnVars.Length != OutputVariables.Length)
                throw new Exception("Number of output parameters given and expected differ for " + Symbol);

            // prefill the local input variables with the invocation values, read from parameter variables of the caller
            for(int i=0; i<sequenceInvocation.ArgumentExpressions.Length; ++i)
            {
                if(sequenceInvocation.ArgumentExpressions[i] != null)
                    InputVariables[i].SetVariableValue(sequenceInvocation.ArgumentExpressions[i].Evaluate(procEnv), procEnv);
                else
                    InputVariables[i].SetVariableValue(sequenceInvocation.Arguments[i], procEnv);
            }

            if(sequenceInvocation.Subgraph != null)
                procEnv.SwitchToSubgraph((IGraph)sequenceInvocation.Subgraph.GetVariableValue(procEnv));

            bool success = Seq.Apply(procEnv);

            if(sequenceInvocation.Subgraph != null)
                procEnv.ReturnFromSubgraph();

            if(success)
            {
                // postfill the return-to variables of the caller with the return values, read from the local output variables
                for(int i = 0; i < sequenceInvocation.ReturnVars.Length; i++)
                    sequenceInvocation.ReturnVars[i].SetVariableValue(OutputVariables[i].GetVariableValue(procEnv), procEnv);
            }

            return success;
        }
Ejemplo n.º 5
0
 // creates or reuses a copy and applies the copy
 protected bool ApplyCopy(SequenceInvocationParameterBindings sequenceInvocation,
     IGraphProcessingEnvironment procEnv)
 {
     // To improve performance we recycle copies in nameToCopies.
     SequenceDefinition seqCopy;
     if(nameToCopies.ContainsKey(SequenceName) && nameToCopies[SequenceName].Count > 0)
     {
         seqCopy = nameToCopies[SequenceName].Pop();
     }
     else
     {
         Dictionary<SequenceVariable, SequenceVariable> originalToCopy
             = new Dictionary<SequenceVariable, SequenceVariable>();
         seqCopy = (SequenceDefinition)Copy(originalToCopy, procEnv);
     }
     sequenceInvocation.SequenceDef = seqCopy;
     bool success = seqCopy.Apply(sequenceInvocation, procEnv);
     sequenceInvocation.SequenceDef = this;
     if(!nameToCopies.ContainsKey(SequenceName))
         nameToCopies.Add(SequenceName, new Stack<SequenceDefinition>());
     nameToCopies[SequenceName].Push(seqCopy);
     return success;
 }
Ejemplo n.º 6
0
        public override bool Apply(SequenceInvocationParameterBindings sequenceInvocation,
            IGraphProcessingEnvironment procEnv)
        {
            // If this sequence definition is currently executed
            // we must copy it and use the copy in its place
            // to prevent state corruption.
            if(executionState == SequenceExecutionState.Underway)
            {
                return ApplyCopy(sequenceInvocation, procEnv);
            }

            procEnv.EnteringSequence(this);
            executionState = SequenceExecutionState.Underway;
#if LOG_SEQUENCE_EXECUTION
            procEnv.Recorder.WriteLine("Before executing sequence definition " + Id + ": " + Symbol);
#endif
            bool res = ApplyImpl(sequenceInvocation, procEnv);
#if LOG_SEQUENCE_EXECUTION
            procEnv.Recorder.WriteLine("After executing sequence definition " + Id + ": " + Symbol + " result " + res);
#endif
            executionState = res ? SequenceExecutionState.Success : SequenceExecutionState.Fail;

            procEnv.EndOfIteration(false, this);

            procEnv.ExitingSequence(this);

            ResetExecutionState(); // state is shown by call, we don't exist any more for the debugger

            return res;
        }
Ejemplo n.º 7
0
 private void BuildOutParameters(SequenceInvocationParameterBindings paramBindings, out String outParameterDeclarations, out String outArguments, out String outAssignments)
 {
     outParameterDeclarations = "";
     outArguments = "";
     outAssignments = "";
     for(int i = 0; i < sequencesToOutputTypes[paramBindings.PackagePrefixedName].Count; i++)
     {
         String varName;
         if(paramBindings.ReturnVars.Length != 0)
             varName = tmpVarCtr.ToString() + paramBindings.ReturnVars[i].PureName;
         else
             varName = tmpVarCtr.ToString();
         ++tmpVarCtr;
         String typeName = sequencesToOutputTypes[paramBindings.PackagePrefixedName][i];
         outParameterDeclarations += TypesHelper.XgrsTypeToCSharpType(typeName, model) + " tmpvar_" + varName
             + " = " + TypesHelper.DefaultValueString(typeName, model) + ";";
         outArguments += ", ref tmpvar_" + varName;
         if(paramBindings.ReturnVars.Length != 0)
             outAssignments += SetVar(paramBindings.ReturnVars[i], "tmpvar_" + varName);
     }
 }