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); }
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); }