protected override string OutputParameterType(int i, Invocation invocation, InheritanceType 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, InheritanceType 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"); }
/// <summary> /// Helper for checking procedure method calls. /// Checks whether called entity exists, type checks the input, type checks the output. /// Throws an exception when an error is found. /// </summary> /// <param name="seqCompProcMethodCall">The procedure method call to check</param> /// <param name="targetExpr">The target of the procedure method call</param> public void CheckProcedureMethodCall(SequenceExpression targetExpr, SequenceComputationProcedureMethodCall seqCompProcMethodCall) { String targetExprType = targetExpr.Type(this); if (targetExprType == "") { // only runtime checks possible (we could check whether the called procedure signature exists in at least one of the model types, if not it's a type error, can't work at runtime, but that kind of negative check is not worth the effort) return; } InheritanceType ownerType = TypesHelper.GetInheritanceType(targetExprType, Model); if (ownerType == null) { // error, must be node or edge type throw new SequenceParserException(targetExprType, SequenceParserError.UserMethodsOnlyAvailableForGraphElements); } if (ownerType.GetProcedureMethod(seqCompProcMethodCall.Name) == null) { throw new SequenceParserException(seqCompProcMethodCall, -1, SequenceParserError.UnknownProcedure); } CheckProcedureCallBase(seqCompProcMethodCall, ownerType); }
protected override string InputParameterType(int i, Invocation invocation, InheritanceType 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 NumOutputParameters(Invocation invocation, InheritanceType ownerType) { if (invocation is RuleInvocation) { RuleInvocation ruleInvocation = (RuleInvocation)invocation; IAction action = SequenceBase.GetAction(ruleInvocation); return(action.RulePattern.Outputs.Length); } else if (invocation is SequenceInvocation) { SequenceSequenceCallInterpreted seqInvocation = (SequenceSequenceCallInterpreted)invocation; if (seqInvocation.SequenceDef is SequenceDefinitionInterpreted) { SequenceDefinitionInterpreted seqDef = (SequenceDefinitionInterpreted)seqInvocation.SequenceDef; return(seqDef.OutputVariables.Length); } else { SequenceDefinitionCompiled seqDef = (SequenceDefinitionCompiled)seqInvocation.SequenceDef; return(seqDef.SeqInfo.OutParameterTypes.Length); } } else if (invocation is ProcedureInvocation) { ProcedureInvocation procInvocation = (ProcedureInvocation)invocation; if (ownerType != null) { IProcedureDefinition procDef = ownerType.GetProcedureMethod(procInvocation.Name); return(procDef.Outputs.Length); } else { SequenceComputationProcedureCallInterpreted procInvocationInterpreted = (SequenceComputationProcedureCallInterpreted)procInvocation; return(procInvocationInterpreted.ProcedureDef.Outputs.Length); } } throw new Exception("Internal error"); }