Debian Codegraph @

rhino/src/org/mozilla/javascript/ast/Jump.java

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