Ejemplo n.º 1
0
 /// <summary>
 /// Creates an instance of a SequenceParserException used by the SequenceParser, when the rule/sequence/procedure/function
 /// with the given name does not exist or input or output parameters do not match.
 /// </summary>
 /// <param name="invocation">The rule/sequence/procedure/function invocation.</param>
 /// <param name="errorKind">The kind of error.</param>
 /// <param name="badParamIndex">The index of a bad parameter or -1 if another error occurred.</param>
 public SequenceParserException(Invocation invocation, int numGiven, SequenceParserError errorKind, int badParamIndex)
 {
     Kind = errorKind;
     Name = invocation.Name;
     if (invocation is RuleInvocation)
     {
         Action = SequenceBase.GetAction((RuleInvocation)invocation);
     }
     NumGiven      = numGiven;
     BadParamIndex = badParamIndex;
     ClassifyDefinitionType(invocation, out DefType);
 }
Ejemplo n.º 2
0
 protected override int NumInputParameters(Invocation invocation, InheritanceType ownerType)
 {
     if (invocation is RuleInvocation)
     {
         RuleInvocation ruleInvocation = (RuleInvocation)invocation;
         IAction        action         = SequenceBase.GetAction(ruleInvocation);
         return(action.RulePattern.Inputs.Length);
     }
     else if (invocation is SequenceInvocation)
     {
         SequenceSequenceCallInterpreted seqInvocation = (SequenceSequenceCallInterpreted)invocation;
         if (seqInvocation.SequenceDef is SequenceDefinitionInterpreted)
         {
             SequenceDefinitionInterpreted seqDef = (SequenceDefinitionInterpreted)seqInvocation.SequenceDef;
             return(seqDef.InputVariables.Length);
         }
         else
         {
             SequenceDefinitionCompiled seqDef = (SequenceDefinitionCompiled)seqInvocation.SequenceDef;
             return(seqDef.SeqInfo.ParameterTypes.Length);
         }
     }
     else if (invocation is ProcedureInvocation)
     {
         ProcedureInvocation procInvocation = (ProcedureInvocation)invocation;
         if (ownerType != null)
         {
             IProcedureDefinition procDef = ownerType.GetProcedureMethod(procInvocation.Name);
             return(procDef.Inputs.Length);
         }
         else
         {
             SequenceComputationProcedureCallInterpreted procInvocationInterpreted = (SequenceComputationProcedureCallInterpreted)procInvocation;
             return(procInvocationInterpreted.ProcedureDef.Inputs.Length);
         }
     }
     else if (invocation is FunctionInvocation)
     {
         FunctionInvocation funcInvocation = (FunctionInvocation)invocation;
         if (ownerType != null)
         {
             IFunctionDefinition funcDef = ownerType.GetFunctionMethod(funcInvocation.Name);
             return(funcDef.Inputs.Length);
         }
         else
         {
             SequenceExpressionFunctionCallInterpreted funcInvocationInterpreted = (SequenceExpressionFunctionCallInterpreted)funcInvocation;
             return(funcInvocationInterpreted.FunctionDef.Inputs.Length);
         }
     }
     throw new Exception("Internal error");
 }
Ejemplo n.º 3
0
 protected override string InputParameterType(int i, Invocation invocation, GrGenType ownerType)
 {
     if (invocation is RuleInvocation)
     {
         RuleInvocation ruleInvocation = (RuleInvocation)invocation;
         IAction        action         = SequenceBase.GetAction(ruleInvocation);
         return(TypesHelper.DotNetTypeToXgrsType(action.RulePattern.Inputs[i]));
     }
     else if (invocation is SequenceInvocation)
     {
         SequenceSequenceCallInterpreted seqInvocation = (SequenceSequenceCallInterpreted)invocation;
         if (seqInvocation.SequenceDef is SequenceDefinitionInterpreted)
         {
             SequenceDefinitionInterpreted seqDef = (SequenceDefinitionInterpreted)seqInvocation.SequenceDef;
             return(seqDef.InputVariables[i].Type);
         }
         else
         {
             SequenceDefinitionCompiled seqDef = (SequenceDefinitionCompiled)seqInvocation.SequenceDef;
             return(TypesHelper.DotNetTypeToXgrsType(seqDef.SeqInfo.ParameterTypes[i]));
         }
     }
     else if (invocation is ProcedureInvocation)
     {
         ProcedureInvocation procInvocation = (ProcedureInvocation)invocation;
         if (ownerType != null)
         {
             IProcedureDefinition procDef = ownerType.GetProcedureMethod(procInvocation.Name);
             return(TypesHelper.DotNetTypeToXgrsType(procDef.Inputs[i]));
         }
         else
         {
             SequenceComputationProcedureCallInterpreted procInvocationInterpreted = (SequenceComputationProcedureCallInterpreted)procInvocation;
             return(TypesHelper.DotNetTypeToXgrsType(procInvocationInterpreted.ProcedureDef.Inputs[i]));
         }
     }
     else if (invocation is FunctionInvocation)
     {
         FunctionInvocation funcInvocation = (FunctionInvocation)invocation;
         if (ownerType != null)
         {
             IFunctionDefinition funcDef = ownerType.GetFunctionMethod(funcInvocation.Name);
             return(TypesHelper.DotNetTypeToXgrsType(funcDef.Inputs[i]));
         }
         else
         {
             SequenceExpressionFunctionCallInterpreted funcInvocationInterpreted = (SequenceExpressionFunctionCallInterpreted)funcInvocation;
             return(TypesHelper.DotNetTypeToXgrsType(funcInvocationInterpreted.FunctionDef.Inputs[i]));
         }
     }
     throw new Exception("Internal error");
 }
Ejemplo n.º 4
0
 private InvocationParameterBindingsWithReturns ExtractParameterBindings(SequenceBase seq)
 {
     if(seq is SequenceRuleCall) // hint: a rule all call is a rule call, too
         return (seq as SequenceRuleCall).ParamBindings;
     else
         return (seq as SequenceSequenceCall).ParamBindings;
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Copy constructor.
 /// </summary>
 /// <param name="that">The sequence base to be copied.</param>
 protected SequenceBase(SequenceBase that)
 {
     id = that.id;
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Returns string containing C# declaration of the sequence-like result variable
 /// </summary>
 public string DeclareResultVar(SequenceBase seq)
 {
     if(seq is Sequence)
         return "bool res_" + seq.Id + ";\n";
     else
         return "object res_" + seq.Id + ";\n";
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Returns string containing a C# assignment to set the result variable of the sequence-like given
 /// to the value as computed by the C# expression in the string given
 /// (every sequence part writes a success-value which is read by other parts determining execution flow)
 /// </summary>
 public string SetResultVar(SequenceBase seq, String valueToWrite)
 {
     if(seq is Sequence)
         return "res_" + seq.Id + " = (bool)(" + valueToWrite + ");\n";
     else
         return "res_" + seq.Id + " = " + valueToWrite + ";\n";
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Returns string containing a C# expression to get the value of the result variable of the sequence-like given
 /// (every sequence part writes a success-value which is read by other parts determining execution flow)
 /// </summary>
 public string GetResultVar(SequenceBase seq)
 {
     return "res_" + seq.Id;
 }