forked from mozilla/rhino
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJump.java
More file actions
132 lines (111 loc) · 3.43 KB
/
Copy pathJump.java
File metadata and controls
132 lines (111 loc) · 3.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.javascript.ast;
import org.mozilla.javascript.Node;
import org.mozilla.javascript.Token;
/**
* Used for code generation. During codegen, the AST is transformed
* into an Intermediate Representation (IR) in which loops, ifs, switches
* and other control-flow statements are rewritten as labeled jumps.
* If the parser is set to IDE-mode, the resulting AST will not contain
* any instances of this class.
*/
public class Jump extends AstNode {
public Node target;
private Node target2;
private Jump jumpNode;
public Jump() {
type = Token.ERROR;
}
public Jump(int nodeType) {
type = nodeType;
}
public Jump(int type, int lineno) {
this(type);
setLineno(lineno);
}
public Jump(int type, Node child) {
this(type);
addChildToBack(child);
}
public Jump(int type, Node child, int lineno) {
this(type, child);
setLineno(lineno);
}
public Jump getJumpStatement()
{
if (type != Token.BREAK && type != Token.CONTINUE) codeBug();
return jumpNode;
}
public void setJumpStatement(Jump jumpStatement)
{
if (type != Token.BREAK && type != Token.CONTINUE) codeBug();
if (jumpStatement == null) codeBug();
if (this.jumpNode != null) codeBug(); //only once
this.jumpNode = jumpStatement;
}
public Node getDefault()
{
if (type != Token.SWITCH) codeBug();
return target2;
}
public void setDefault(Node defaultTarget)
{
if (type != Token.SWITCH) codeBug();
if (defaultTarget.getType() != Token.TARGET) codeBug();
if (target2 != null) codeBug(); //only once
target2 = defaultTarget;
}
public Node getFinally()
{
if (type != Token.TRY) codeBug();
return target2;
}
public void setFinally(Node finallyTarget)
{
if (type != Token.TRY) codeBug();
if (finallyTarget.getType() != Token.TARGET) codeBug();
if (target2 != null) codeBug(); //only once
target2 = finallyTarget;
}
public Jump getLoop()
{
if (type != Token.LABEL) codeBug();
return jumpNode;
}
public void setLoop(Jump loop)
{
if (type != Token.LABEL) codeBug();
if (loop == null) codeBug();
if (jumpNode != null) codeBug(); //only once
jumpNode = loop;
}
public Node getContinue()
{
if (type != Token.LOOP) codeBug();
return target2;
}
public void setContinue(Node continueTarget)
{
if (type != Token.LOOP) codeBug();
if (continueTarget.getType() != Token.TARGET) codeBug();
if (target2 != null) codeBug(); //only once
target2 = continueTarget;
}
/**
* Jumps are only used directly during code generation, and do
* not support this interface.
* @throws UnsupportedOperationException
*/
@Override
public void visit(NodeVisitor visitor) {
throw new UnsupportedOperationException(this.toString());
}
@Override
public String toSource(int depth) {
throw new UnsupportedOperationException(this.toString());
}
}