Exemplo n.º 1
0
 protected override int NumOutputParameters(Invocation invocation, GrGenType ownerType)
 {
     if (invocation is RuleInvocation)
     {
         RuleInvocation ruleInvocation = (RuleInvocation)invocation;
         return(actionsTypeInformation.rulesToOutputTypes[ruleInvocation.PackagePrefixedName].Count);
     }
     else if (invocation is SequenceInvocation)
     {
         SequenceInvocation seqInvocation = (SequenceInvocation)invocation;
         return(actionsTypeInformation.sequencesToOutputTypes[seqInvocation.PackagePrefixedName].Count);
     }
     else if (invocation is ProcedureInvocation)
     {
         ProcedureInvocation procInvocation = (ProcedureInvocation)invocation;
         if (ownerType != null)
         {
             IProcedureDefinition procDef = ownerType.GetProcedureMethod(procInvocation.Name);
             return(procDef.Outputs.Length);
         }
         else
         {
             return(actionsTypeInformation.proceduresToOutputTypes[procInvocation.PackagePrefixedName].Count);
         }
     }
     throw new Exception("Internal error");
 }
Exemplo n.º 2
0
 protected override string OutputParameterType(int i, Invocation invocation, GrGenType ownerType)
 {
     if (invocation is RuleInvocation)
     {
         RuleInvocation ruleInvocation = (RuleInvocation)invocation;
         return(actionsTypeInformation.rulesToOutputTypes[ruleInvocation.PackagePrefixedName][i]);
     }
     else if (invocation is SequenceInvocation)
     {
         SequenceInvocation seqInvocation = (SequenceInvocation)invocation;
         return(actionsTypeInformation.sequencesToOutputTypes[seqInvocation.PackagePrefixedName][i]);
     }
     else if (invocation is ProcedureInvocation)
     {
         ProcedureInvocation procInvocation = (ProcedureInvocation)invocation;
         if (ownerType != null)
         {
             IProcedureDefinition procDef = ownerType.GetProcedureMethod(procInvocation.Name);
             return(TypesHelper.DotNetTypeToXgrsType(procDef.Outputs[i]));
         }
         else
         {
             return(actionsTypeInformation.proceduresToOutputTypes[procInvocation.PackagePrefixedName][i]);
         }
     }
     throw new Exception("Internal error");
 }
Exemplo 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");
 }
Exemplo n.º 4
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");
 }
Exemplo n.º 5
0
        private void CheckSubgraph(Invocation invocation)
        {
            SequenceVariable subgraph;

            if (invocation is RuleInvocation)
            {
                RuleInvocation ruleInvocation = (RuleInvocation)invocation;
                subgraph = ruleInvocation.Subgraph;
            }
            else
            {
                SequenceInvocation sequenceInvocation = (SequenceInvocation)invocation;
                subgraph = sequenceInvocation.Subgraph;
            }
            if (subgraph != null && !TypesHelper.IsSameOrSubtype("graph", subgraph.Type, Model))
            {
                throw new SequenceParserException(invocation.Name, subgraph.Type, SequenceParserError.SubgraphTypeError);
            }
        }
Exemplo n.º 6
0
        public static IAction GetAction(RuleInvocation invocation)
        {
            SequenceRuleCallInterpreted sequenceRuleCall = invocation as SequenceRuleCallInterpreted;

            if (sequenceRuleCall != null)
            {
                return(sequenceRuleCall.Action);
            }
            SequenceRuleAllCallInterpreted sequenceRuleAllCall = invocation as SequenceRuleAllCallInterpreted;

            if (sequenceRuleAllCall != null)
            {
                return(sequenceRuleAllCall.Action);
            }
            SequenceRuleCountAllCallInterpreted sequenceRuleCountAllCall = invocation as SequenceRuleCountAllCallInterpreted;

            if (sequenceRuleCountAllCall != null)
            {
                return(sequenceRuleCountAllCall.Action);
            }
            return(null);
        }
Exemplo n.º 7
0
        public void BuildReturnParameters(RuleInvocation invocation, SequenceVariable[] ReturnVars,
                                          out String returnParameterDeclarations, out String returnArguments, out String returnAssignments,
                                          out String returnParameterDeclarationsAllCall, out String intermediateReturnAssignmentsAllCall, out String returnAssignmentsAllCall)
        {
            // can't use the normal xgrs variables for return value receiving as the type of an out-parameter must be invariant
            // this is bullshit, as it is perfectly safe to assign a subtype to a variable of a supertype
            // so we create temporary variables of exact type, which are used to receive the return values,
            // and finally we assign these temporary variables to the real xgrs variables

            StringBuilder sbReturnParameterDeclarations          = new StringBuilder();
            StringBuilder sbReturnArguments                      = new StringBuilder();
            StringBuilder sbReturnAssignments                    = new StringBuilder();
            StringBuilder sbReturnParameterDeclarationsAllCall   = new StringBuilder();
            StringBuilder sbIntermediateReturnAssignmentsAllCall = new StringBuilder();
            StringBuilder sbReturnAssignmentsAllCall             = new StringBuilder();

            for (int i = 0; i < actionsTypeInformation.rulesToOutputTypes[invocation.PackagePrefixedName].Count; ++i)
            {
                String varName;
                if (ReturnVars.Length != 0)
                {
                    varName = GetUniqueId() + ReturnVars[i].PureName;
                }
                else
                {
                    varName = GetUniqueId();
                }
                String typeName = actionsTypeInformation.rulesToOutputTypes[invocation.PackagePrefixedName][i];

                String tmpvarName = "tmpvar_" + varName;
                sbReturnParameterDeclarations.Append(TypesHelper.XgrsTypeToCSharpType(typeName, model));
                sbReturnParameterDeclarations.Append(" ");
                sbReturnParameterDeclarations.Append(tmpvarName);
                sbReturnParameterDeclarations.Append("; ");

                String returnListValueVarType = typeName;
                String tmpvarListName         = "tmpvarlist_" + varName;
                if (ReturnVars.Length != 0 && ReturnVars[i].Type != "" && ReturnVars[i].Type.StartsWith("array<"))
                {
                    returnListValueVarType = TypesHelper.ExtractSrc(ReturnVars[i].Type);
                }
                if (ReturnVars.Length != 0)
                {
                    sbReturnParameterDeclarationsAllCall.Append("List<");
                    sbReturnParameterDeclarationsAllCall.Append(TypesHelper.XgrsTypeToCSharpType(returnListValueVarType, model));
                    sbReturnParameterDeclarationsAllCall.Append("> ");
                    sbReturnParameterDeclarationsAllCall.Append(tmpvarListName);
                    sbReturnParameterDeclarationsAllCall.Append(" = new List<");
                    sbReturnParameterDeclarationsAllCall.Append(TypesHelper.XgrsTypeToCSharpType(returnListValueVarType, model));
                    sbReturnParameterDeclarationsAllCall.Append(">(); ");
                }

                sbReturnArguments.Append(", out ");
                sbReturnArguments.Append(tmpvarName);

                if (ReturnVars.Length != 0)
                {
                    sbReturnAssignments.Append(SetVar(ReturnVars[i], tmpvarName));

                    sbIntermediateReturnAssignmentsAllCall.Append(tmpvarListName);
                    sbIntermediateReturnAssignmentsAllCall.Append(".Add((");
                    sbIntermediateReturnAssignmentsAllCall.Append(TypesHelper.XgrsTypeToCSharpType(returnListValueVarType, model));
                    sbIntermediateReturnAssignmentsAllCall.Append(")");
                    sbIntermediateReturnAssignmentsAllCall.Append(tmpvarName);
                    sbIntermediateReturnAssignmentsAllCall.Append("); ");

                    sbReturnAssignmentsAllCall.Append(SetVar(ReturnVars[i], tmpvarListName));
                }
            }

            returnParameterDeclarations          = sbReturnParameterDeclarations.ToString();
            returnArguments                      = sbReturnArguments.ToString();
            returnAssignments                    = sbReturnAssignments.ToString();
            returnParameterDeclarationsAllCall   = sbReturnParameterDeclarationsAllCall.ToString();
            intermediateReturnAssignmentsAllCall = sbIntermediateReturnAssignmentsAllCall.ToString();
            returnAssignmentsAllCall             = sbReturnAssignmentsAllCall.ToString();
        }