Exemplo n.º 1
0
 internal override Node Bind(Binder b)
 {
     b.Bind(ref Initializer);
     Initializer.RequireGetAccess();
     if (IsConst && Initializer is LiteralExpr c)
     {
         Symbol = b.AddConstant(Name, (Constant)c.Symbol) ?? throw Error(ErrorCode.LocalSameName, Name);
     }
     else
     {
         Symbol = b.AddLocal(Name, Initializer.Datatype) ?? throw Error(ErrorCode.LocalSameName, Name);
         if (IsConst)
         {
             if (Initializer?.IsConstant != true)
             {
                 throw Error(ErrorCode.ValueNotConst);
             }
             Var.SetConst();
         }
         Initializer = InitExpr.Bound(IdExpr.Bound(Var), Initializer, b.Options.Binding);
     }
     return(null);
 }
Exemplo n.º 2
0
        internal override Node Bind(Binder b)
        {
            // TODO: Handle IS
            if (IsIsType)
            {
                throw Type.Error(ErrorCode.NotSupported, "IS");
            }

            // TODO: Handle DIM, array sub peroperly (according to full compiler)
            if (IsDim && ArraySub == null)
            {
                throw Error(ErrorCode.Expected, "array specifier");
            }
            bool isDim   = IsDim && ArraySub != null;
            bool isArray = !IsDim && ArraySub != null;

            if (ArraySub != null)
            {
                for (int i = 0; i < ArraySub.Length; i++)
                {
                    b.Bind(ref ArraySub[i]);
                }
            }

            TypeSymbol t = b.ObjectType;

            if (Type != null)
            {
                b.Bind(ref Type, BindAffinity.Type);
                Type.RequireType();
                t = Type.Symbol as TypeSymbol;
            }
            if (isDim)
            {
                t = Binder.ArrayOf(t, ArraySub.Length);
            }
            else if (isArray && Type == null)
            {
                t = Compilation.Get(NativeType.Array);
            }
            Symbol = b.AddLocal(Name, t) ?? throw Error(ErrorCode.LocalSameName, Name);
            if (Initializer != null)
            {
                b.Bind(ref Initializer);
                Initializer.RequireGetAccess();
                if (IsConst)
                {
                    if (!Initializer.IsConstant)
                    {
                        throw Error(ErrorCode.ValueNotConst);
                    }
                    Var.SetConst();
                }
                b.Convert(ref Initializer, Var.Type);
                Initializer = InitExpr.Bound(IdExpr.Bound(Var), Initializer, b.Options.Binding);
            }
            else if (IsConst)
            {
                throw Error(ErrorCode.ConstWithoutInitializer);
            }
            else if (isDim)
            {
                Initializer = InitExpr.Bound(IdExpr.Bound(Var), CtorCallExpr.Bound(b, IdExpr.Bound(t), ArgList.Bound(ArraySub)), b.Options.Binding);
            }
            else if (isArray)
            {
                Initializer = InitExpr.Bound(IdExpr.Bound(Var), MethodCallExpr.Bound(b, null, Compilation.Get(WellKnownMembers.XSharp___Array___ArrayNew), null, ArgList.Bound(ArraySub)), b.Options.Binding);
            }
            return(null);
        }