Esempio n. 1
0
        private bool TryResolveOwnShortMethod(BRAQParser.Short_callContext context, out OwnMethodInfo ownMethodInfo)
        {
            IToken name = context.calee;

            //найдём аргумент
            List <Type> args;
            Type        argument_type;

            argument_type = context.arg.Accept(this);

            args = new List <Type>(new[] { argument_type });

            try
            {
                var handle = user_functions
                             .First(x => x.name == name.Text &&
                                    x.arguments.Count == args.Count &&
                                    x.arguments.Select(r => r.b).Zip(args, (r, w) => new Pair <Type, Type>(r, w))
                                    .All(rec => rec.a == rec.b)
                                    );
                ownMethodInfo = handle;

                return(true);
            }
            catch (InvalidOperationException)
            {
                ownMethodInfo = null;
                return(false);
            }
        }
Esempio n. 2
0
 private IToken GetDeepToken(BRAQParser.Short_callContext context)
 {
     if (context.calee != null)
     {
         return(context.calee);
     }
     return(context.single.var_node_.id_name);
 }
Esempio n. 3
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);
        }
Esempio n. 4
0
        public override int VisitShort_call(BRAQParser.Short_callContext context)
        {
            if (context.calee == null)
            {
                return(context.single.Accept(this));
            }
            //one of
            context.arg.Accept(this);

            if (user_function_table.ContainsKey(context.calee))
            {
                var info = user_function_table[context.calee];

                il.EmitCall(OpCodes.Call, info.method_builder, null);
                return(0);
            }

            var function_ptr = function_table[context.calee];

            il.EmitCall(OpCodes.Call, function_ptr, null);

            return(0);
        }
Esempio n. 5
0
 /// <summary>
 /// Visit a parse tree produced by <see cref="BRAQParser.short_call"/>.
 /// <para>
 /// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>
 /// on <paramref name="context"/>.
 /// </para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 /// <return>The visitor result.</return>
 public virtual Result VisitShort_call([NotNull] BRAQParser.Short_callContext context)
 {
     return(VisitChildren(context));
 }
Esempio n. 6
0
 /// <summary>
 /// Exit a parse tree produced by <see cref="BRAQParser.short_call"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void ExitShort_call([NotNull] BRAQParser.Short_callContext context)
 {
 }