public bool ValidateMethodSignatureAndOverloads(GrapeCallExpression callExpression, GrapeMethod method, GrapeModifier.GrapeModifierType modifiers, ref string errorMessage) { errorMessage = ""; List<GrapeMethod> methods = new List<GrapeMethod>(); methods.AddRange(astUtils.GetMethodsWithNameFromImportedPackagesInFile(Config, method.Name, method.FileName, method.GetLogicalParentOfEntityType<GrapeClass>())); List<GrapeMethod> methodsWithSignature = typeCheckingUtils.GetMethodsWithSignature(Config, methods, modifiers, method.Name, method.ReturnType, new List<GrapeExpression>(callExpression.Parameters), ref errorMessage); if (errorMessage != "") { errorSink.AddError(new GrapeErrorSink.Error { Description = errorMessage, FileName = callExpression.FileName, Entity = callExpression }); if (!Config.ContinueOnError) { return false; } } if (methodsWithSignature.Count > 1) { errorMessage = "Multiple functions with signature '" + typeCheckingUtils.GetMethodSignatureString(Config, method.Name, method.ReturnType, new List<GrapeExpression>(callExpression.Parameters)) + "' found."; errorSink.AddError(new GrapeErrorSink.Error { Description = errorMessage, FileName = callExpression.FileName, Entity = callExpression }); if (!Config.ContinueOnError) { return false; } } return true; }
public static bool Contains(this GrapeModifier.GrapeModifierType modifiers, GrapeModifier.GrapeModifierType value) { return (((uint)modifiers & (uint)value) != 0); }
public List<GrapeMethod> GetMethodsWithSignature(GrapeCodeGeneratorConfiguration config, List<GrapeMethod> methods, GrapeModifier.GrapeModifierType modifiers, string name, GrapeType returnType, List<GrapeVariable> parameters, ref string errorMessage) { List<GrapeMethod> foundMethods = new List<GrapeMethod>(); string parameterErrorMessage = ""; foreach (GrapeMethod method in methods) { if (method.Name == name && GetTypeNameForTypeAccessExpression(config, method.ReturnType) == GetTypeNameForTypeAccessExpression(config, returnType) && method.Parameters.Count == parameters.Count) { if (modifiers != 0) { bool shouldContinue = false; if (modifiers != method.Modifiers) { shouldContinue = true; } if (shouldContinue) { continue; } } int currentParameterIndex = 0; bool validParameters = true; foreach (GrapeVariable param in method.Parameters) { GrapeVariable currentParameter = parameters[currentParameterIndex]; if (!DoesExpressionResolveToType(config, currentParameter, currentParameter.Type, param.Type, ref parameterErrorMessage)) { validParameters = false; if (parameterErrorMessage == "") { parameterErrorMessage = "Cannot resolve parameter type '" + GetTypeNameForTypeAccessExpression(config, currentParameter.Type) + "' to type '" + GetTypeNameForTypeAccessExpression(config, param.Type) + "'."; } break; } currentParameterIndex++; } if (validParameters) { foundMethods.Add(method); } } } if (foundMethods.Count == 0) { errorMessage = "Cannot find method with signature '" + GetMethodSignatureString(config, name, returnType, parameters) + "'. " + parameterErrorMessage; } return foundMethods; }