Beispiel #1
0
        public override bool VisitStmtVarDefNull([NotNull] GamaParser.StmtVarDefNullContext context)
        {
            var name = context.Symbol().GetText();
            var val  = Top.FindValue(name);

            if (val != null)
            {
                NamespaceContext.Context.AddError(new ErrorDuplicateVariable(context));
                return(false);
            }
            var ty = NamespaceContext.FindTypeRefGlobal(context.typeName());

            if (ty == null)
            {
                NamespaceContext.Context.AddError(new ErrorTypeNotFound(context.typeName()));
                return(false);
            }
            if (ty == InstanceTypes.Void)
            {
                NamespaceContext.Context.AddError(new ErrorVariableVoid(context.typeName()));
                return(false);
            }

            /* LLVM */
            CurrentBlock.PositionBuilderAtEnd(Builder);
            if (ty is GamaFunction) // Functionals are not allocated directly, instead a pointer is allocateds
            {
                var ptr   = new GamaPointer(ty);
                var alloc = Builder.BuildAlloca(ptr.UnderlyingType, name);
                Builder.BuildStore(LLVMValueRef.CreateConstPointerNull(ptr.UnderlyingType), alloc);

                Top.AddValue(name, new GamaValueRef(ty, alloc, true));
            }
            else
            {
                var alloc = Builder.BuildAlloca(ty.UnderlyingType, name);
                // TODO: maybe add an option to not null initialize these variable definitions
                // Possible speed boost
                Builder.BuildStore(LLVMValueRef.CreateConstNull(ty.UnderlyingType), alloc);

                Top.AddValue(name, new GamaValueRef(ty, alloc, true));
            }

            return(true);
        }
Beispiel #2
0
 /// <summary>
 /// Visit a parse tree produced by the <c>StmtVarDefNull</c>
 /// labeled alternative in <see cref="GamaParser.stmtVarDef"/>.
 /// <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 VisitStmtVarDefNull([NotNull] GamaParser.StmtVarDefNullContext context)
 {
     return(VisitChildren(context));
 }
Beispiel #3
0
 /// <summary>
 /// Exit a parse tree produced by the <c>StmtVarDefNull</c>
 /// labeled alternative in <see cref="GamaParser.stmtVarDef"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void ExitStmtVarDefNull([NotNull] GamaParser.StmtVarDefNullContext context)
 {
 }