Ejemplo n.º 1
0
        public override bool VisitStmtVarDefBase([NotNull] GamaParser.StmtVarDefBaseContext context)
        {
            var name = context.Symbol().GetText();
            var val  = Top.FindValue(name);

            // Duplicate variable definition (parent frames can have same variable, it will be overriden in current frame)
            if (val != null)
            {
                NamespaceContext.Context.AddError(new ErrorDuplicateVariable(context));
                return(false);
            }
            val = VisitExpression(context.expr());
            if (val == null)
            {
                return(false);
            }

            /* LLVM */
            CurrentBlock.PositionBuilderAtEnd(Builder);
            var alloc = Builder.BuildAlloca(val.Type.UnderlyingType, name);

            Builder.BuildStore(val.Value, alloc);

            Top.AddValue(name, new GamaValueRef(val.Type, alloc, true));

            return(true);
        }