예제 #1
0
        public string GetMethod(string methodName, params IType[] args)
        {
            if (args.Any(a => a as AsmType == null))
                return null;

            var types = args.Select(t => (t as AsmType).Type).ToArray();

            MethodInfo method = null;
            if (args.Length > 0)
            {
                var modifiers = args.Select(arg => arg.Modifier == TypeModifier.Reference).ToArray();
                var mods = new ParameterModifier[] { new ParameterModifier(modifiers.Length) };
                for (var i = 0; i < modifiers.Length; i++)
                    mods[0][i] = modifiers[i];

                method = Type.GetMethod(methodName, types, mods);
            }
            else
                method = Type.GetMethod(methodName);

            if (method == null)
                return null;

            var returnType = new AsmType(method.ReturnType);
            var parameters = method.GetParameters()
                                   .Select(p => new AsmType(p.ParameterType));

            return string.Format("{0} {1}::{2}({3})",
                    returnType.Name, Name, methodName,
                    string.Join(", ", parameters.Select(p => p.Name)));
        }
예제 #2
0
        public MethodCall(Identifier name, params IExpression[] args)
        {
            Name = name;
            Args = args;

            foreach (var arg in args)
                if (arg.ReturnType == new AsmType("System.Void"))
                    throw new ArgumentException();

            ReturnType = new AsmType("System.Void");
        }
예제 #3
0
        public string GetMethod(string name, params IType[] args)
        {
            if (aliases.ContainsKey(name))
                name = aliases[name];

            var items = name.Split('.');
            var typeName = string.Join(".", items.Take(items.Length - 1));
            var method = items.Last();

            foreach (var u in usings) try
            {
                var type = new AsmType(u + typeName);
                return type.GetMethod(method, args);
            }
            catch { }

            throw new Exception(string.Format("Type not found: {0}",
                        name, string.Join(", ", args.Select(a => a.Name))));
        }
예제 #4
0
        public static MethodCall Parse(ref string input, Namespace ns)
        {
            var orgInput = input;

            var ident = Identifier.Parse(ref input);
            if (ident == null)
                return null;

            if (input[0] != '(')
                return null;
            input = input.Substring(1);

            var length = input.Length;
            var args = new List<IExpression>();
            while (true)
            {
                var expr = Expression.Parse(ref input, ns);
                if (expr != null)
                {
                    if (expr.ReturnType.Name == "System.Void")
                        throw new ArgumentException("Argument must have a return type");

                    args.Add(expr);
                }

                Whitespace.Parse(ref input);
                if (input.Length == 0)
                {
                    input = orgInput;
                    return null;
                }

                if (input[0] == ',')
                {
                    input = input.Substring(1);
                    continue;
                }

                else if (input[0] == ')')
                {
                    input = input.Substring(1);
                    break;
                }

                if (length == input.Length)
                    throw new Exception("Could not parse:" + Environment.NewLine + input);
                length = input.Length;
            }

            var method = ns.GetMethod(ident.Value, args.Select(e => e.ReturnType).ToArray());
            if (method == null)
                throw new Exception("Could not find method: " + ident.Value);

            var returnType = new AsmType(method.Split(' ')[0]);
            var methodName = string.Join(" ", method.Split(' ').Skip(1));

            ident = new Identifier(methodName);
            return new MethodCall(ident, returnType, args.ToArray());
        }