Пример #1
0
        internal override Node Bind(Binder b)
        {
            b.OpenScope();
            if (Expr != null)
            {
                b.Bind(ref Expr);
                Expr.RequireGetAccess();
            }
            else
            {
                b.Bind(ref Decl);
            }
            b.Bind(ref Stmt);
            b.CloseScope();

            var u     = Decl != null ? Decl.VarDecls[0].Var : b.AddLocal(Expr.Datatype);
            var udecl = Decl ?? DeclStmt.Bound(VarDecl.Bound(u, Expr, b.Options.Binding));

            Expr du = AsTypeExpr.Bound(IdExpr.Bound(u), IdExpr.Bound(Compilation.Get(WellKnownTypes.System_IDisposable)));

            b.Cache(ref du);
            var cond = BinaryExpr.Bound(du, Expr.Token, LiteralExpr.Bound(Constant.Null), BinaryOperatorKind.NotEqual, b.Options.Binding);
            var exit = IfStmt.Bound(cond,
                                    ExprStmt.Bound(MethodCallExpr.Bound(b, null, Compilation.Get(WellKnownMembers.System_IDisposable_Dispose), du, ArgList.Empty)),
                                    null);

            return(StmtBlock.Bound(udecl,
                                   TryStmt.Bound(b,
                                                 Stmt,
                                                 exit)));
        }
Пример #2
0
        internal override Node Bind(Binder b)
        {
            if (Token.Type == TokenType.LPARAMETERS || Token.Type == TokenType.PARAMETERS)
            {
                for (int i = 0; i < VarDecls.Length; i++)
                {
                    var argIdx     = b.Options.ArrayBase + i;
                    var paramArray = IdExpr.Bound((b.Entity as Script).ParamArray);
                    VarDecls[i].Initializer =
                        IifExpr.Bound(
                            BinaryExpr.Bound(ArrayLengthExpr.Bound(paramArray), Token, LiteralExpr.Bound(Constant.Create(i)), BinaryOperatorKind.GreaterThan, b.Options.Binding),
                            ArrayAccessExpr.Bound(paramArray, ArgList.Bound(LiteralExpr.Bound(Constant.Create(argIdx))), b),
                            DefaultExpr.Bound(b, b.ObjectType),
                            b.Options.Binding);
                }
            }

            // TODO: Handle STATIC
            if (Token.Type == TokenType.STATIC)
            {
                throw Error(ErrorCode.NotSupported, "STATIC");
            }

            for (int i = 0; i < VarDecls.Length; i++)
            {
                b.Bind(ref VarDecls[i]);
            }
            return(null);
        }
Пример #3
0
        internal override Node Bind(Binder b)
        {
            b.OpenScope();

            b.Bind(ref Expr);
            Expr.RequireGetAccess();

            if (Expr.Datatype.IsArray && Expr.Datatype.ArrayRank == 1)
            {
                var array = b.Cache(ref Expr);
                var iter  = b.AddLocal(Compilation.Get(NativeType.Int32));
                IterDecl  = VarDecl.Bound(iter, LiteralExpr.Bound(Constant.Create(b.Options.ArrayBase)), b.Options.Binding);
                WhileExpr = BinaryExpr.Bound(IdExpr.Bound(iter), Token,
                                             MethodCallExpr.Bound(array, Compilation.Get(WellKnownMembers.System_Array_get_Length), array, ArgList.Empty),
                                             b.Options.ArrayZero ? BinaryOperatorKind.LessThan : BinaryOperatorKind.LessThanOrEqual, b.Options.Binding);
                IncrExpr            = AssignOpExpr.Bound(IdExpr.Bound(iter), LiteralExpr.Bound(Constant.Create(1)), BinaryOperatorKind.Addition, b);
                ForDecl.Initializer = ArrayAccessExpr.Bound(array, new ArgList(new List <Arg>(1)
                {
                    new Arg(IdExpr.Bound(iter))
                }), b);
            }
            else
            {
                if (Expr.Datatype.IsUsualOrObject() && b.Options.Binding.HasFlag(BindOptions.AllowDynamic))
                {
                    b.Convert(ref Expr, Compilation.Get(NativeType.Array));
                }
                Expr e          = b.Cache(ref Expr);
                var  getIterSym = e.Datatype.GetEnumeratorGetter() ?? throw Error(ErrorCode.NoSuitableEnumerator);
                var  getIter    = MethodCallExpr.Bound(e, getIterSym, e, ArgList.Empty);
                var  iter       = b.AddLocal(getIter.Datatype);
                IterDecl  = VarDecl.Bound(iter, getIter, b.Options.Binding);
                WhileExpr = MethodCallExpr.Bound(b, IdExpr.Bound(iter), SystemNames.MoveNext, ArgList.Empty);
                b.Convert(ref WhileExpr, Compilation.Get(NativeType.Boolean));
                ForDecl.Initializer = MethodCallExpr.Bound(b, IdExpr.Bound(iter), SystemNames.CurrentGetter, ArgList.Empty);
                Dispose             = Compilation.Get(WellKnownTypes.System_IDisposable).IsAssignableFrom(getIter.Datatype);
                if (Dispose)
                {
                    RequireExceptionHandling = true;
                }
            }

            b.Bind(ref ForDecl);
            InnerDecl = ForDecl;

            Expr Iter;

            Iter = (ForDecl.Initializer as AssignExpr).Left;
            Iter.RequireGetAccess();

            b.Bind(ref Stmt);

            b.CloseScope();
            return(null);
        }
Пример #4
0
 internal static AssignOpExpr Bound(Expr Left, Expr Right, BinaryOperatorKind kind, Binder b)
 {
     Left.RequireGetSetAccess();
     Right.RequireGetAccess();
     Right = BinaryExpr.Bound(Left.Cloned(b), Left.Token, Right, kind, b.Options.Binding);
     b.Convert(ref Right, Left.Datatype);
     return(new AssignOpExpr(Left, Left.Token, Right)
     {
         Symbol = Left.Symbol, Datatype = Left.Datatype
     });
 }
Пример #5
0
 internal override Node Bind(Binder b)
 {
     b.Bind(ref Left, BindAffinity.Assign);
     b.Bind(ref Right);
     Left.RequireGetSetAccess();
     Right.RequireGetAccess();
     Right = BinaryExpr.Bound(Left.Cloned(b), Token, Right, BinaryOperatorSymbol.OperatorKind(Kind), false, b.Options.Binding);
     b.Convert(ref Right, Left.Datatype);
     Symbol   = Left.Symbol;
     Datatype = Left.Datatype;
     return(null);
 }
Пример #6
0
        internal override Node Bind(Binder b)
        {
            b.OpenScope();
            b.Bind(ref Expr);
            Expr.RequireGetAccess();
            var s = b.FindOuter <SwitchStmt>() ?? throw Error(ErrorCode.Internal);

            Cond = BinaryExpr.Bound(Expr, Expr.Token, IdExpr.Bound(s.SwitchValue), BinaryOperatorKind.ExactEqual, b.Options.Binding);
            b.Convert(ref Cond, Compilation.Get(NativeType.Boolean));
            if (When != null)
            {
                b.Bind(ref When);
                When.RequireGetAccess();
                b.Convert(ref When, Compilation.Get(NativeType.Boolean));
            }
            if (Stmt != null)
            {
                b.Bind(ref Stmt);
            }
            b.CloseScope();
            return(null);
        }
Пример #7
0
        internal override Node Bind(Binder b)
        {
            b.OpenScope();

            if (AssignExpr != null)
            {
                b.Bind(ref AssignExpr);
                IterInit = AssignExpr;
            }
            else
            {
                b.Bind(ref ForDecl);
                IterDecl   = ForDecl;
                AssignExpr = ForDecl.Initializer as AssignExpr;
            }

            Expr Iter;

            Iter = AssignExpr.Left;
            Iter.RequireGetAccess();

            b.Bind(ref Final);
            Final.RequireGetAccess();

            if (Step != null)
            {
                b.Bind(ref Step);
                Step.RequireGetAccess();
            }
            else
            {
                Step = LiteralExpr.Bound(Constant.Create(1));
            }

            switch (Dir.Type)
            {
            case TokenType.UPTO:
                WhileExpr = BinaryExpr.Bound(Iter, Dir, Final, BinaryOperatorKind.LessThanOrEqual, b.Options.Binding);
                IncrExpr  = AssignOpExpr.Bound(Iter, Step, BinaryOperatorKind.Addition, b);
                break;

            case TokenType.DOWNTO:
                WhileExpr = BinaryExpr.Bound(Iter, Dir, Final, BinaryOperatorKind.GreaterThanOrEqual, b.Options.Binding);
                IncrExpr  = AssignOpExpr.Bound(Iter, Step, BinaryOperatorKind.Subtraction, b);
                break;

            case TokenType.TO:
                var step_pos        = BinaryExpr.Bound(Step, Dir, LiteralExpr.Bound(Constant.Create(0)), BinaryOperatorKind.GreaterThanOrEqual, b.Options.Binding);
                var whileExprUpTo   = BinaryExpr.Bound(Iter, Dir, Final, BinaryOperatorKind.LessThanOrEqual, b.Options.Binding);
                var whileExprDownTo = BinaryExpr.Bound(Iter, Dir, Final, BinaryOperatorKind.GreaterThanOrEqual, b.Options.Binding);
                WhileExpr = IifExpr.Bound(step_pos, whileExprUpTo, whileExprDownTo, b.Options.Binding);
                IncrExpr  = AssignOpExpr.Bound(Iter, Step, BinaryOperatorKind.Addition, b);
                break;

            default:
                throw Error(ErrorCode.Internal);
            }
            b.Convert(ref WhileExpr, Compilation.Get(NativeType.Boolean));

            b.Bind(ref Stmt);

            b.CloseScope();
            return(null);
        }