Exemple #1
0
        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;
        }
Exemple #2
0
        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;
        }
        public static List<Error> Resolve(Node root, Invoke func, out IType type)
        {
            var errors = new List<Error>();

            var f = root.GetNearestParent<Program>().GetSpecifiedChildren<Function>().First(x=>x.Name.Text == func.Name.Text);
            type = f.ReturnType;
            errors.AddRange(ProcInvokeResolver.Resolve(func));
            return errors;
        }
Exemple #4
0
 private static void EmitInvoke(Invoke inv)
 {
     if (inv is StdProc)
         EmitStdProc(inv as StdProc);
     else
     {
         Source += inv.Name.Text + "(" + MakeString(inv.Args) + ")\n;";
     }
 }
Exemple #5
0
 public void SetInvoke(Invoke inv)
 {
     Invoke = inv;
 }
Exemple #6
0
        private static void EmitInvoke(MethodBuilder mb, Invoke inv)
        {
            var il = mb.GetILGenerator();

            if (inv is StdProc)
            {
                EmitStdProc(il, inv as StdProc);
            }

            il.Emit(OpCodes.Ret);
        }