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"); }
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"); }
public void BuildReturnParameters(ProcedureInvocation invocation, SequenceVariable[] ReturnVars, InheritanceType ownerType, out String returnParameterDeclarations, out String returnArguments, out String returnAssignments) { // 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 returnParameterDeclarations = ""; returnArguments = ""; returnAssignments = ""; for (int i = 0; i < ownerType.GetProcedureMethod(invocation.Name).Outputs.Length; ++i) { String varName; if (ReturnVars.Length != 0) { varName = GetUniqueId() + ReturnVars[i].PureName; } else { varName = GetUniqueId(); } String typeName = TypesHelper.DotNetTypeToXgrsType(ownerType.GetProcedureMethod(invocation.Name).Outputs[i]); String tmpvarName = "tmpvar_" + varName; returnParameterDeclarations += TypesHelper.XgrsTypeToCSharpType(typeName, model) + " " + tmpvarName + "; "; returnArguments += ", out " + tmpvarName; if (ReturnVars.Length != 0) { returnAssignments += SetVar(ReturnVars[i], tmpvarName); } } }
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"); }
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"); }