private IToken GetDeepToken(BRAQParser.CallContext context) { if (context.calee != null) { return(context.calee); } return(GetDeepToken(context.single)); }
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(); }
public override int VisitCall(BRAQParser.CallContext context) { if (context.calee == null) { return(context.single.Accept(this)); } if (user_function_table.ContainsKey(context.calee)) { var info = user_function_table[context.calee]; foreach (var exprContext in context.expr()) { exprContext.Accept(this); } il.EmitCall(OpCodes.Call, info.method_builder, null); return(0); } var function_ptr = function_table[context.calee]; foreach (var exprContext in context.expr()) { exprContext.Accept(this); } if (function_ptr.IsStatic) { il.EmitCall(OpCodes.Call, function_ptr, null); } else { il.EmitCall(OpCodes.Call, function_ptr, null); } return(0); }
private bool TryResolveOwnMethod(BRAQParser.CallContext context, out OwnMethodInfo ownMethodInfo) { IToken name = context.calee; List <Type> args = context.expr().Select(x => type_dict[x]).ToList(); 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); } }
/// <summary> /// Visit a parse tree produced by <see cref="BRAQParser.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 VisitCall([NotNull] BRAQParser.CallContext context) { return(VisitChildren(context)); }
/// <summary> /// Exit a parse tree produced by <see cref="BRAQParser.call"/>. /// <para>The default implementation does nothing.</para> /// </summary> /// <param name="context">The parse tree.</param> public virtual void ExitCall([NotNull] BRAQParser.CallContext context) { }