Ejemplo n.º 1
0
        public override Type VisitShort_call(BRAQParser.Short_callContext context)
        {
            //TODO user_defined functions

            if (context.calee == null)
            {
                return(type_dict[context] = context.single.Accept(this));
            }

            if (TryResolveOwnShortMethod(context, out var ownMethodInfo))
            {
                result_box.token_to_user_function[context.calee] = ownMethodInfo;
                return(type_dict[context] = ownMethodInfo.return_type);
            }

            //get argument type
            Type argument_type;

            argument_type = context.arg.Accept(this);



            Type[] types          = { argument_type };
            IToken function_token = context.calee;


            MethodInfo predef_function_info = PredefsHelper.Resolve(dot_prefix_type, function_token.Text, types);

            if (predef_function_info != null)
            {
                if (predef_function_info.GetParameters()
                    .Zip(types, (r, w) => new KeyValuePair <Type, Type>(r.ParameterType, w))
                    .Any(p => p.Key != p.Value))
                {
                    Console.WriteLine("could not bind {0}({1}) [Line {2}]",
                                      function_token.Text,
                                      String.Join(" ", types.Select(x => x.ToString())),
                                      function_token.Line
                                      );
                    throw new BindError();
                }

                result_box.token_to_outer_function[function_token] = predef_function_info;
                type_dict[context] = predef_function_info.ReturnType;
            }
            else
            {
                Console.WriteLine(function_token.Text);
                Console.WriteLine(String.Join(" ", types.ToList().Select(x => x.ToString())));
                throw new BindError();
            }

            return(predef_function_info.ReturnType);
        }
Ejemplo n.º 2
0
        public override Type VisitCall(BRAQParser.CallContext context)
        {
            //TODO
            //get argument list

            if (context.calee == null)
            {
                return(type_dict[context] = context.single.Accept(this));
            }

            foreach (var exprContext in context.expr())
            {
                exprContext.Accept(this);
            }

            Type[] types = context.expr().Select(x => type_dict[x]).ToArray();


            IToken function_token = context.calee;

            if (TryResolveOwnMethod(context, out var ownMethodInfo))
            {
                result_box.token_to_user_function[context.calee] = ownMethodInfo;
                return(type_dict[context] = ownMethodInfo.return_type);
            }

            //MethodInfo predef_function_info = typeof(Predefs).GetMethod(function_token.Text, types);
            MethodInfo predef_function_info = PredefsHelper.Resolve(dot_prefix_type, function_token.Text, types);

            if (predef_function_info != null)
            {
                if (predef_function_info.GetParameters()
                    .Zip(types, (r, w) => new KeyValuePair <Type, Type>(r.ParameterType, w))
                    .Any(p => p.Key != p.Value))
                {
                    Console.WriteLine("could not bind {0}({1}) [Line {2}]",
                                      function_token.Text,
                                      String.Join(" ", types.Select(x => x.ToString())),
                                      function_token.Line
                                      );
                    throw new BindError();
                }

                result_box.token_to_outer_function[function_token] = predef_function_info;
                type_dict[context] = predef_function_info.ReturnType;
                return(predef_function_info.ReturnType);
            }

            Console.WriteLine(function_token.Text);
            Console.WriteLine(String.Join(" ", types.ToList().Select(x => x.ToString())));
            throw new BindError();
        }