/// <summary> /// Helper for checking function method calls. /// Checks whether called entity exists, and type checks the input. /// Throws an exception when an error is found. /// </summary> /// <param name="seqExprFuncMethodCall">The function method call to check</param> /// <param name="targetExpr">The target of the procedure function call</param> public void CheckFunctionMethodCall(SequenceExpression targetExpr, SequenceExpressionFunctionMethodCall seqExprFuncMethodCall) { 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); } // check whether called function method exists if (ownerType.GetFunctionMethod(seqExprFuncMethodCall.Name) == null) { throw new SequenceParserException(seqExprFuncMethodCall, -1, SequenceParserError.UnknownProcedure); } CheckFunctionCallBase(seqExprFuncMethodCall, 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 string InputParameterType(int i, Invocation invocation, InheritanceType ownerType) { if (invocation is RuleInvocation) { RuleInvocation ruleInvocation = (RuleInvocation)invocation; return(actionsTypeInformation.rulesToInputTypes[ruleInvocation.PackagePrefixedName][i]); } else if (invocation is SequenceInvocation) { SequenceInvocation seqInvocation = (SequenceInvocation)invocation; return(actionsTypeInformation.sequencesToInputTypes[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.Inputs[i])); } else { return(actionsTypeInformation.proceduresToInputTypes[procInvocation.PackagePrefixedName][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 { return(actionsTypeInformation.functionsToInputTypes[funcInvocation.PackagePrefixedName][i]); } } throw new Exception("Internal error"); }