equal
deleted
inserted
replaced
30 |
30 |
31 /** |
31 /** |
32 * IR representation for {@code with} statements. |
32 * IR representation for {@code with} statements. |
33 */ |
33 */ |
34 @Immutable |
34 @Immutable |
35 public final class WithNode extends LexicalContextNode { |
35 public final class WithNode extends LexicalContextStatement { |
36 /** This expression. */ |
36 /** This expression. */ |
37 private final Node expression; |
37 private final Expression expression; |
38 |
38 |
39 /** Statements. */ |
39 /** Statements. */ |
40 private final Block body; |
40 private final Block body; |
41 |
41 |
42 /** |
42 /** |
50 super(lineNumber, token, finish); |
50 super(lineNumber, token, finish); |
51 this.expression = null; |
51 this.expression = null; |
52 this.body = null; |
52 this.body = null; |
53 } |
53 } |
54 |
54 |
55 private WithNode(final WithNode node, final Node expression, final Block body) { |
55 private WithNode(final WithNode node, final Expression expression, final Block body) { |
56 super(node); |
56 super(node); |
57 this.expression = expression; |
57 this.expression = expression; |
58 this.body = body; |
58 this.body = body; |
59 } |
59 } |
60 |
60 |
65 */ |
65 */ |
66 @Override |
66 @Override |
67 public Node accept(final LexicalContext lc, final NodeVisitor<? extends LexicalContext> visitor) { |
67 public Node accept(final LexicalContext lc, final NodeVisitor<? extends LexicalContext> visitor) { |
68 if (visitor.enterWithNode(this)) { |
68 if (visitor.enterWithNode(this)) { |
69 return visitor.leaveWithNode( |
69 return visitor.leaveWithNode( |
70 setExpression(lc, expression.accept(visitor)). |
70 setExpression(lc, (Expression)expression.accept(visitor)). |
71 setBody(lc, (Block)body.accept(visitor))); |
71 setBody(lc, (Block)body.accept(visitor))); |
72 } |
72 } |
73 return this; |
73 return this; |
74 } |
74 } |
75 |
75 |
108 |
108 |
109 /** |
109 /** |
110 * Get the expression of this WithNode |
110 * Get the expression of this WithNode |
111 * @return the expression |
111 * @return the expression |
112 */ |
112 */ |
113 public Node getExpression() { |
113 public Expression getExpression() { |
114 return expression; |
114 return expression; |
115 } |
115 } |
116 |
116 |
117 /** |
117 /** |
118 * Reset the expression of this with node |
118 * Reset the expression of this with node |
119 * @param lc lexical context |
119 * @param lc lexical context |
120 * @param expression new expression |
120 * @param expression new expression |
121 * @return new or same withnode |
121 * @return new or same withnode |
122 */ |
122 */ |
123 public WithNode setExpression(final LexicalContext lc, final Node expression) { |
123 public WithNode setExpression(final LexicalContext lc, final Expression expression) { |
124 if (this.expression == expression) { |
124 if (this.expression == expression) { |
125 return this; |
125 return this; |
126 } |
126 } |
127 return Node.replaceInLexicalContext(lc, this, new WithNode(this, expression, body)); |
127 return Node.replaceInLexicalContext(lc, this, new WithNode(this, expression, body)); |
128 } |
128 } |