Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
        internal static IifExpr Bound(Expr cond, Expr t, Expr f, BindOptions opt)
        {
            cond.RequireGetAccess();
            t.RequireGetAccess();
            f.RequireGetAccess();
            Binder.Convert(ref cond, Compilation.Get(NativeType.Boolean), Binder.Conversion(cond, Compilation.Get(NativeType.Boolean), opt));
            var r = new IifExpr(cond, t, f, cond.Token);

            r.Datatype = Binder.ConvertResult(ref r.True, ref r.False, opt);
            return(r);
        }
Exemplo n.º 3
0
 internal override Node Bind(Binder b)
 {
     b.OpenScope();
     b.Bind(ref Stmt);
     Stmt = TryStmt.Bound(b,
                          StmtBlock.Bound(
                              ExprStmt.Bound(MethodCallExpr.Bound(null, Compilation.Get(WellKnownMembers.XSharp_Internal_CompilerServices_EnterBeginSequence), null, ArgList.Empty)),
                              Stmt),
                          ExprStmt.Bound(MethodCallExpr.Bound(null, Compilation.Get(WellKnownMembers.XSharp_Internal_CompilerServices_ExitBeginSequence), null, ArgList.Empty))
                          );
     b.CloseScope();
     if (Recover != null)
     {
         b.OpenScope();
         var rv = b.AddLocal(Name.Value, b.ObjectType);
         b.Bind(ref Recover);
         ExVar = b.AddLocal(Compilation.Get(WellKnownTypes.System_Exception));
         Expr rvxw   = MethodCallExpr.Bound(b, TypeCast.Bound(b, IdExpr.Bound(ExVar), Compilation.Get(WellKnownTypes.XSharp_Internal_WrappedException)), "get_Value", ArgList.Empty);
         Expr rvxe   = TypeCast.Bound(b, IdExpr.Bound(ExVar), Compilation.Get(WellKnownTypes.XSharp_Error));
         Expr rvx    = MethodCallExpr.Bound(null, Compilation.Get(WellKnownMembers.XSharp_Error_WrapRawException), null, ArgList.Bound(TypeCast.Bound(b, IdExpr.Bound(ExVar), Compilation.Get(WellKnownTypes.System_Exception))));
         var  rvInit =
             IifExpr.Bound(IsExpr.Bound(IdExpr.Bound(ExVar), IdExpr.Bound(Compilation.Get(WellKnownTypes.XSharp_Internal_WrappedException))), TypeConversion.Bound(b, rvxw, Compilation.Get(NativeType.Usual)),
                           IifExpr.Bound(IsExpr.Bound(IdExpr.Bound(ExVar), IdExpr.Bound(Compilation.Get(WellKnownTypes.XSharp_Error))), TypeConversion.Bound(b, rvxe, Compilation.Get(NativeType.Usual)),
                                         rvx,
                                         b.Options.Binding),
                           b.Options.Binding);
         var rvdecl = DeclStmt.Bound(VarDecl.Bound(rv, rvInit, b.Options.Binding));
         Recover = StmtBlock.Bound(rvdecl, Recover);
         b.CloseScope();
     }
     if (Finally != null)
     {
         bool ar = SaveAllowReturn(b);
         b.OpenScope();
         b.Bind(ref Finally);
         b.CloseScope();
         RestoreAllowReturn(b, ar);
     }
     return(TryStmt.Bound(b, Stmt, CatchBlock.Bound(ExVar, Recover), Finally));
 }
Exemplo n.º 4
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);
        }