16147
|
1 |
/*
|
16151
|
2 |
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
|
16147
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation. Oracle designates this
|
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
|
9 |
* by Oracle in the LICENSE file that accompanied this code.
|
|
10 |
*
|
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
15 |
* accompanied this code).
|
|
16 |
*
|
|
17 |
* You should have received a copy of the GNU General Public License version
|
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
20 |
*
|
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
22 |
* or visit www.oracle.com if you need additional information or have any
|
|
23 |
* questions.
|
|
24 |
*/
|
|
25 |
|
|
26 |
package jdk.nashorn.internal.ir;
|
|
27 |
|
|
28 |
import jdk.nashorn.internal.ir.visitor.NodeVisitor;
|
|
29 |
import jdk.nashorn.internal.runtime.Source;
|
|
30 |
|
|
31 |
/**
|
|
32 |
* IR representation for {@code with} statements.
|
|
33 |
*/
|
|
34 |
public class WithNode extends Node {
|
|
35 |
/** This expression. */
|
|
36 |
private Node expression;
|
|
37 |
|
|
38 |
/** Statements. */
|
|
39 |
private Block body;
|
|
40 |
|
|
41 |
/**
|
|
42 |
* Constructor
|
|
43 |
*
|
|
44 |
* @param source the source
|
|
45 |
* @param token token
|
|
46 |
* @param finish finish
|
|
47 |
* @param expression expression in parenthesis
|
|
48 |
* @param body with node body
|
|
49 |
*/
|
|
50 |
public WithNode(final Source source, final long token, final int finish, final Node expression, final Block body) {
|
|
51 |
super(source, token, finish);
|
|
52 |
|
|
53 |
this.expression = expression;
|
|
54 |
this.body = body;
|
|
55 |
}
|
|
56 |
|
|
57 |
private WithNode(final WithNode withNode, final CopyState cs) {
|
|
58 |
super(withNode);
|
|
59 |
|
|
60 |
expression = cs.existingOrCopy(withNode.expression);
|
|
61 |
body = (Block)cs.existingOrCopy(withNode.body);
|
|
62 |
}
|
|
63 |
|
|
64 |
@Override
|
|
65 |
protected Node copy(final CopyState cs) {
|
|
66 |
return new WithNode(this, cs);
|
|
67 |
}
|
|
68 |
|
|
69 |
/**
|
|
70 |
* Assist in IR navigation.
|
|
71 |
*
|
|
72 |
* @param visitor IR navigating visitor.
|
|
73 |
*/
|
|
74 |
@Override
|
|
75 |
public Node accept(final NodeVisitor visitor) {
|
|
76 |
if (visitor.enter(this) != null) {
|
|
77 |
expression = expression.accept(visitor);
|
|
78 |
body = (Block)body.accept(visitor);
|
|
79 |
return visitor.leave(this);
|
|
80 |
}
|
|
81 |
|
|
82 |
return this;
|
|
83 |
}
|
|
84 |
|
|
85 |
@Override
|
|
86 |
public void toString(final StringBuilder sb) {
|
|
87 |
sb.append("with (");
|
|
88 |
expression.toString(sb);
|
|
89 |
sb.append(')');
|
|
90 |
}
|
|
91 |
|
|
92 |
/**
|
|
93 |
* Get the body of this WithNode
|
|
94 |
* @return the body
|
|
95 |
*/
|
|
96 |
public Block getBody() {
|
|
97 |
return body;
|
|
98 |
}
|
|
99 |
|
|
100 |
/**
|
|
101 |
* Reset the body of this with node
|
|
102 |
* @param body new body
|
|
103 |
*/
|
|
104 |
public void setBody(final Block body) {
|
|
105 |
this.body = body;
|
|
106 |
}
|
|
107 |
|
|
108 |
/**
|
|
109 |
* Get the expression of this WithNode
|
|
110 |
* @return the expression
|
|
111 |
*/
|
|
112 |
public Node getExpression() {
|
|
113 |
return expression;
|
|
114 |
}
|
|
115 |
|
|
116 |
/**
|
|
117 |
* Reset the expression of this with node
|
|
118 |
* @param expression new expression
|
|
119 |
*/
|
|
120 |
public void setExpression(final Node expression) {
|
|
121 |
this.expression = expression;
|
|
122 |
}
|
|
123 |
}
|
|
124 |
|