public override GamaValueRef VisitExprOpAdd([NotNull] GamaParser.ExprOpAddContext context)
        {
            var lhs = Visit(context.expr(0));
            var rhs = Visit(context.expr(1));
            var op  = context.opAdd().GetText();

            GamaFunctionList oplist;

            if (op == "+")
            {
                oplist = lhs.Type.Meta.Operators.Add;
            }
            else
            {
                oplist = lhs.Type.Meta.Operators.Sub;
            }

            var target = !IsEmptyTT ? TopTT : null;

            GamaFunctionRef fnref = null;

            if (target == null)
            {
                fnref = oplist.FindFunction(new[] { lhs.Type, rhs.Type });
            }
            else
            {
                fnref = oplist.FindFunction(target, new[] { lhs.Type, rhs.Type });
            }

            if (fnref == null)
            {
                GamaCompiledFunctionList coplist;
                if (op == "+")
                {
                    coplist = lhs.Type.Meta.CompiledOperators.Add;
                }
                else
                {
                    coplist = lhs.Type.Meta.CompiledOperators.Sub;
                }

                GamaCompiledFunctionRef cfnref = null;
                if (target == null)
                {
                    cfnref = coplist.FindFunction(lhs.Type, rhs.Type);
                }
                else
                {
                    cfnref = coplist.FindFunction(target, new[] { lhs.Type, rhs.Type });
                }

                if (cfnref == null)
                {
                    Parent.NamespaceContext.Context.AddError(new ErrorNoViableOperator(context));
                    return(null);
                }
                var cbuilder = Parent.Builder;
                Parent.CurrentBlock.PositionBuilderAtEnd(cbuilder);
                return(cfnref.Call(cbuilder, lhs, rhs));
            }

            /* LLVM */
            var block   = Parent.CurrentBlock;
            var builder = Parent.Builder;

            block.PositionBuilderAtEnd(builder);
            var result = builder.BuildCall(fnref.Value, new LLVMValueRef[] { lhs.Value, rhs.Value });

            return(new GamaValueRef(fnref.ReturnType, result, false));
        }
Beispiel #2
0
 /// <summary>
 /// Visit a parse tree produced by the <c>ExprOpAdd</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 VisitExprOpAdd([NotNull] GamaParser.ExprOpAddContext context)
 {
     return(VisitChildren(context));
 }
Beispiel #3
0
 /// <summary>
 /// Exit a parse tree produced by the <c>ExprOpAdd</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 ExitExprOpAdd([NotNull] GamaParser.ExprOpAddContext context)
 {
 }