private static IEnumerable<Error> ResolveArgs(Invoke inv, Procedure proc) { var errors = new List<Error>(); var p = new List<Variable>(); if (proc != null) p = proc.GetSpecifiedChildren<Variable>().Where(x => x.VarSemantics == VarType.Parameter).ToList(); var index = 0; foreach (var arg in inv.Args) { IType type; errors.AddRange(IdentifierResolver.ResloveIdentifierType(inv.GetParent(), arg, out type)); if (proc != null) { if (index >= p.Count) errors.Add(new Error(inv.GetSourceIdentifier(), inv.Name, string.Format(ErrorMessages.InvalidSignature, inv.Name.Text))); else { if (type.ToString() != p[index].Type.ToString()) errors.Add(new Error(inv.GetSourceIdentifier(), inv.Name, string.Format(ErrorMessages.InvalidSignature, inv.Name.Text))); } } index++; } return errors; }
public static List<Error> Resolve(Invoke inv) { var errors = new List<Error>(); if (inv is StdProc) { errors.AddRange(ResolveArgs(inv, null)); } else { var actual = inv.GetNearestParent<Program>() .GetSpecifiedChildren<Procedure>() .Where(x => x.Name.Text == inv.Name.Text) .ToList(); if (actual.Count == 0) errors.Add(new Error(inv.GetSourceIdentifier(), inv.Name, string.Format(ErrorMessages.ProcedureNotFound, inv.Name.Text))); if (actual.Count == 1) errors.AddRange(ResolveArgs(inv, actual.First())); } return errors; }