public override GamaValueRef VisitExprIndex([NotNull] GamaParser.ExprIndexContext context) { var val = Visit(context.expr()); if (val == null) { return(null); } var exprs = context.exprList().expr(); var builder = Parent.Builder; if (!IsEmptyTT) { var tt = TopTT; var vals = new GamaValueRef[exprs.Length]; var valsnative = new LLVMValueRef[exprs.Length]; var tys = new GamaTypeRef[exprs.Length]; for (int i = 0; i < vals.Length; i++) { var tmp = Visit(exprs[i]); if (tmp == null) { return(null); } vals[i] = tmp; valsnative[i] = tmp.Value; tys[i] = tmp.Type; } var cbcomp = val.Type.Meta.CompiledOperators.Index.FindFunction(tt, tys); if (cbcomp == null) { var cb = val.Type.Meta.Operators.Index.FindFunction(tt, tys); if (cb == null) { Parent.NamespaceContext.Context.AddError(new ErrorNoViableOperator(context)); return(null); } Parent.CurrentBlock.PositionBuilderAtEnd(builder); return(new GamaValueRef(cb.ReturnType, builder.BuildCall(cb.Value, valsnative), false)); // TODO: make indexing assignable } return(cbcomp.Call(builder, vals)); } else { var vals = new GamaValueRef[exprs.Length]; var valsnative = new LLVMValueRef[exprs.Length]; var tys = new GamaTypeRef[exprs.Length]; for (int i = 0; i < vals.Length; i++) { var tmp = Visit(exprs[i]); if (tmp == null) { return(null); } vals[i] = tmp; valsnative[i] = tmp.Value; tys[i] = tmp.Type; } var cbcomp = val.Type.Meta.CompiledOperators.Index.FindFunction(tys); if (cbcomp == null) { var cb = val.Type.Meta.Operators.Index.FindFunction(tys); if (cb == null) { Parent.NamespaceContext.Context.AddError(new ErrorNoViableOperator(context)); return(null); } Parent.CurrentBlock.PositionBuilderAtEnd(builder); return(new GamaValueRef(cb.ReturnType, builder.BuildCall(cb.Value, valsnative), false)); // TODO: make indexing assignable } return(cbcomp.Call(builder, vals)); } }
/// <summary> /// Visit a parse tree produced by the <c>ExprIndex</c> /// labeled alternative in <see cref="GamaParser.expr"/>. /// <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 VisitExprIndex([NotNull] GamaParser.ExprIndexContext context) { return(VisitChildren(context)); }
/// <summary> /// Exit a parse tree produced by the <c>ExprIndex</c> /// labeled alternative in <see cref="GamaParser.expr"/>. /// <para>The default implementation does nothing.</para> /// </summary> /// <param name="context">The parse tree.</param> public virtual void ExitExprIndex([NotNull] GamaParser.ExprIndexContext context) { }