public static TryStatement TryCatchFinally(SourceSpan span, SourceLocation header, Statement body, CatchBlock[] handlers, Statement @finally) { return new TryStatement( span, header, body, CollectionUtils.ToReadOnlyCollection(handlers), @finally ); }
public static ScopeStatement Scope(SourceSpan span, Expression scope, Statement body) { Contract.RequiresNotNull(scope, "scope"); Contract.RequiresNotNull(body, "body"); Contract.Requires(TypeUtils.CanAssign(typeof(IAttributesCollection), scope.Type), "scope", "Scope must be IAttributesCollection"); return new ScopeStatement(span, scope, body); }
internal SwitchCase(SourceLocation header, bool @default, int value, Statement body) : base(AstNodeType.SwitchCase) { _header = header; _default = @default; _value = value; _body = body; }
public static CatchBlock Catch(SourceSpan span, SourceLocation header, Type type, Variable target, Statement body) { Contract.RequiresNotNull(type, "type"); Contract.Requires(target == null || TypeUtils.CanAssign(target.Type, type), "target"); Contract.RequiresNotNull(body, "body"); return new CatchBlock(span, header, type, target, body); }
/// <summary> /// Called by <see cref="DoStatementBuilder"/>. /// </summary> internal DoStatement(SourceSpan span, SourceLocation header, Expression /*!*/ test, Statement /*!*/ body) : base(AstNodeType.DoStatement, span) { _header = header; _test = test; _body = body; }
internal DoStatementBuilder(SourceSpan statementSpan, SourceLocation location, Statement body) { Contract.RequiresNotNull(body, "body"); _body = body; _doLocation = location; _statementSpan = statementSpan; }
/// <summary> /// Null test means infinite loop. /// </summary> internal LoopStatement(SourceSpan span, SourceLocation header, Expression test, Expression increment, Statement /*!*/ body, Statement @else) : base(AstNodeType.LoopStatement, span) { _test = test; _increment = increment; _body = body; _else = @else; _header = header; }
public static IfStatementTest IfCondition(SourceSpan span, SourceLocation header, Expression test, Statement body) { Contract.RequiresNotNull(test, "test"); Contract.RequiresNotNull(body, "body"); Contract.Requires(test.Type == typeof(bool), "test", "Test must be boolean"); return new IfStatementTest(span, header, test, body); }
/// <summary> /// Called by <see cref="TryStatementBuilder"/>. /// Creates a try/catch/finally/else block. /// /// The body is protected by the try block. /// The handlers consist of a set of language-dependent tests which call into the LanguageContext. /// The elseSuite runs if no exception is thrown. /// The finallySuite runs regardless of how control exits the body. /// </summary> internal TryStatement(SourceSpan span, SourceLocation header, Statement body, ReadOnlyCollection<CatchBlock> handlers, Statement @finally) : base(AstNodeType.TryStatement, span) { _body = body; _handlers = handlers; _finally = @finally; _header = header; }
public static VariableReference[] Bind(Expression test, Statement target) { Assert.NotNull(test, target); RuleBinder rb = new RuleBinder(); rb.WalkNode(test); rb.WalkNode(target); return rb.GetReferences(); }
public Targets(Nullable<Label> breakLabel, Nullable<Label> continueLabel, TargetBlockType blockType, Slot finallyReturns, Statement statement) { this.breakLabel = breakLabel; this.continueLabel = continueLabel; this._blockType = blockType; this.finallyReturns = finallyReturns; this.leaveLabel = null; this.statement = statement; }
internal IfStatementTest(SourceSpan span, SourceLocation header, Expression /*!*/ test, Statement /*!*/ body) : base(AstNodeType.IfStatementTest) { _test = test; _body = body; _header = header; _start = span.Start; _end = span.End; }
public override void Optimize() { Pass0 p0 = new Pass0(references); p0.WalkNode(Root); foreach (var v in references.Keys) { foreach (var t in references[v].Keys) { var c = references[v][t]; if (t != typeof(object) && c > 1 && t.IsValueType) { var n = SymbolTable.StringToId(t.Name + "___" + SymbolTable.IdToString(v.Name)); var tv = v.Block.CreateVariable(n, Variable.VariableKind.Local, t); v.SetTypedVariable(t, tv); var vv = v; if (vv.Kind == Variable.VariableKind.Local && vv.AssumedValue is BoundExpression) { var assbe = vv.AssumedValue as BoundExpression; if (assbe.Variable.Kind == Variable.VariableKind.Parameter) { vv = assbe.Variable; } } var inittv = Ast.Write(tv, Ast.SimpleCallHelper(typeof(IronScheme.Runtime.Helpers).GetMethod("UnsafeConvert").MakeGenericMethod(tv.Type), Ast.Read(vv))); var bs = v.Block.Body as BlockStatement; if (bs != null) { Statement[] newbody = new Statement[bs.Statements.Count + 1]; newbody[0] = inittv; bs.Statements.CopyTo(newbody, 1); v.Block.Body = Ast.Block(newbody); } else { v.Block.Body = Ast.Block(inittv, v.Block.Body); } } } v.Block.Bind(); } Pass1 p1 = new Pass1(references); p1.WalkNode(Root); foreach (var v in references.Keys) { v.Block.Bind(); } }
private bool _yield; // The catch block contains a yield #endregion Fields #region Constructors internal CatchBlock(SourceSpan span, SourceLocation header, Type /*!*/ test, Variable target, Statement /*!*/ body) : base(AstNodeType.CatchBlock) { _test = test; _var = target; _body = body; _start = span.Start; _header = header; _end = span.End; }
public static IfStatement IfThenElse(SourceSpan span, Expression test, Statement body, Statement @else) { return If( span, new IfStatementTest[] { Ast.IfCondition(SourceSpan.None, SourceLocation.None, test, body) }, @else ); }
internal override Tree.Statement Gen(InfixGenerator lg) { if (_statements != null) { Tree.Statement[] statements = new Tree.Statement[_statements.Length]; for (int i = 0; i < statements.Length; i++) { statements[i] = _statements[i].Gen(lg); } return Tree.Ast.Block( statements ); } else { return Tree.Ast.Empty(); } }
public static SwitchCase DefaultCase(SourceLocation header, Statement body) { Contract.RequiresNotNull(body, "body"); return(new SwitchCase(header, true, 0, body)); }
internal BreakStatement(SourceSpan span, Statement statement) : base(AstNodeType.BreakStatement, span) { _statement = statement; }
public static BreakStatement Break(SourceSpan span, Statement statement) { return new BreakStatement(span, statement); }
public SwitchStatementBuilder Case(int value, Statement body) { return Case(SourceLocation.None, value, body); }
internal LabeledStatement(SourceSpan span, Statement statement) : base(AstNodeType.LabeledStatement, span) { _statement = statement; }
public static LabeledStatement Labeled(Statement statement) { return Labeled(SourceSpan.None, statement); }
static Expression RewriteReturn(Statement statement) { if (statement is BlockStatement) { BlockStatement bs = (BlockStatement)statement; List<Statement> newbody = new List<Statement>(bs.Statements); Statement last = newbody[newbody.Count - 1]; newbody.RemoveAt(newbody.Count - 1); Statement fb = FlattenStatement(Ast.Block(newbody)); Expression eb = Ast.Void(fb); if (fb is ExpressionStatement) { eb = ((ExpressionStatement)fb).Expression; } return Ast.Comma(eb, Unwrap(RewriteReturn(last))); } if (statement is ReturnStatement) { Expression e = ((ReturnStatement)statement).Expression; if (e is MethodCallExpression) { ((MethodCallExpression)e).TailCall = false; } if (e.Type != typeof(object)) { return e; } else { return Unwrap(e); } } if (statement is IfStatement) { IfStatement ifs = (IfStatement)statement; Debug.Assert(ifs.Tests.Count == 1); var a = Unwrap(RewriteReturn(ifs.Tests[0].Body)); var b = Unwrap(RewriteReturn(ifs.ElseStatement)); if (a.Type != b.Type) { a = Ast.ConvertHelper(a, typeof(object)); b = Ast.ConvertHelper(b, typeof(object)); } return Ast.Condition(ifs.Tests[0].Test, a, b); } if (statement is LabeledStatement) { var ls = statement as LabeledStatement; return Ast.Void(ls); } throw new ArgumentException("Unexpected"); }
public static SwitchCase SwitchCase(int value, Statement body) { return(SwitchCase(SourceLocation.None, value, body)); }
public static SwitchCase SwitchCase(SourceLocation header, int value, Statement body) { Contract.RequiresNotNull(body, "body"); return(new SwitchCase(header, false, value, body)); }
public static SwitchCase DefaultCase(Statement body) { return(DefaultCase(SourceLocation.None, body)); }
public SwitchStatementBuilder Default(Statement body) { return Default(SourceLocation.None, body); }
public SwitchStatementBuilder Default(SourceLocation header, Statement body) { Contract.Requires(_default == false, "body", "Already has default clause"); _cases.Add(Ast.DefaultCase(header, body)); _default = true; return this; }
internal IfStatement(SourceSpan span, ReadOnlyCollection<IfStatementTest> /*!*/ tests, Statement @else) : base(AstNodeType.IfStatement, span) { _tests = tests; _else = @else; }
public static IfStatement Unless(SourceSpan span, Expression test, Statement body) { return IfThenElse(span, test, Ast.Empty(), body); }
static bool IsNotIfOrReturn(Statement s) { if (s is BlockStatement) { BlockStatement bs = (BlockStatement)s; return IsNotIfOrReturn(bs.Statements[bs.Statements.Count - 1]); } else if (s is IfStatement) { var ifs = s as IfStatement; return IsNotIfOrReturn(ifs.Tests[0].Body) || (ifs.ElseStatement != null && IsNotIfOrReturn(ifs.ElseStatement)); } else { if (!(s is ReturnStatement) && !(s is ContinueStatement)) { return true; } } return false; }
public static DoStatementBuilder Do(Statement body) { return new DoStatementBuilder(SourceSpan.None, SourceLocation.None, body); }
static Statement FlattenStatement(Statement s) { if (s is BlockStatement) { BlockStatement bs = (BlockStatement)s; return FlattenStatements(bs.Statements); } return s; }
public static DoStatementBuilder Do(SourceSpan statementSpan, SourceLocation location, Statement body) { return new DoStatementBuilder(statementSpan, location, body); }
public static LabeledStatement Labeled(SourceSpan span, Statement statement) { return new LabeledStatement(span, statement); }
public static BreakStatement Break(Statement statement) { return Break(SourceSpan.None, statement); }
public LabeledStatement Mark(Statement statement) { Contract.RequiresNotNull(statement, "statement"); _statement = statement; return this; }
public SwitchStatementBuilder Case(SourceLocation header, int value, Statement body) { _cases.Add(Ast.SwitchCase(header, value, body)); return this; }