001: /*
002: * $Id: Jumps.java,v 1.5 2002/09/16 08:05:06 jkl Exp $
003: *
004: * Copyright (c) 2002 Njet Communications Ltd. All Rights Reserved.
005: *
006: * Use is subject to license terms, as defined in
007: * Anvil Sofware License, Version 1.1. See LICENSE
008: * file, or http://njet.org/license-1.1.txt
009: */
010: package anvil.script.statements;
011:
012: import java.io.PrintStream;
013:
014: /**
015: * class Jumps
016: *
017: * @author: Jani Lehtimäki
018: */
019: public class Jumps {
020:
021: public static final int BLOCKED = 1;
022: public static final int EXIT = 2;
023: public static final int RETURN = 4;
024: public static final int THROW = 8;
025:
026: public static final int BREAK = 1;
027: public static final int CONTINUE = 1;
028:
029: private byte _flags = 0;
030: private long _break = 0;
031: private long _continue = 0;
032:
033: public Jumps() {
034: }
035:
036: public Jumps(Jumps jumps) {
037: merge(jumps);
038: }
039:
040: public boolean isBlocked() {
041: return (_flags & BLOCKED) != 0;
042: }
043:
044: public Jumps setBlocked(boolean blocked) {
045: if (blocked) {
046: _flags |= BLOCKED;
047: } else {
048: _flags &= ~BLOCKED;
049: }
050: return this ;
051: }
052:
053: public boolean hasExit() {
054: return (_flags & EXIT) != 0;
055: }
056:
057: public Jumps setExit() {
058: _flags |= EXIT;
059: return this ;
060: }
061:
062: public boolean hasReturn() {
063: return (_flags & RETURN) != 0;
064: }
065:
066: public Jumps setReturn() {
067: _flags |= RETURN;
068: return this ;
069: }
070:
071: public Jumps setReturn(boolean hasReturn) {
072: if (hasReturn) {
073: _flags |= RETURN;
074: } else {
075: _flags &= ~RETURN;
076: }
077: return this ;
078: }
079:
080: public boolean hasThrow() {
081: return (_flags & THROW) != 0;
082: }
083:
084: public Jumps setThrow() {
085: _flags |= THROW;
086: return this ;
087: }
088:
089: public Jumps setThrow(boolean hasThrow) {
090: if (hasThrow) {
091: _flags |= THROW;
092: } else {
093: _flags &= ~THROW;
094: }
095: return this ;
096: }
097:
098: public boolean hasBreak() {
099: return (_break & BREAK) != 0;
100: }
101:
102: public Jumps setBreak() {
103: _break |= BREAK;
104: return this ;
105: }
106:
107: public Jumps setBreak(int depth) {
108: if (depth > 63) {
109: throw new RuntimeException(
110: "Statement nesting depth overflow");
111: }
112: _break |= (BREAK << depth);
113: return this ;
114: }
115:
116: public boolean hasContinue() {
117: return (_continue & CONTINUE) != 0;
118: }
119:
120: public Jumps setContinue() {
121: _continue |= CONTINUE;
122: return this ;
123: }
124:
125: public Jumps setContinue(int depth) {
126: if (depth > 63) {
127: throw new RuntimeException(
128: "Statement nesting depth overflow");
129: }
130: _continue |= (CONTINUE << depth);
131: return this ;
132: }
133:
134: public Jumps merge(Jumps jumps) {
135: _flags |= jumps._flags;
136: _break |= jumps._break;
137: _continue |= jumps._continue;
138: return this ;
139: }
140:
141: public Jumps shift() {
142: _break >>= 1;
143: _continue >>= 1;
144: return this ;
145: }
146:
147: public void print(String source) {
148: System.out.print("** " + source + ": ");
149:
150: long b = _break;
151: int c = 0;
152: while (b != 0) {
153: if ((b & 1) != 0) {
154: System.out.print("b" + c + " ");
155: }
156: b = b >> 1;
157: c++;
158: }
159:
160: b = _continue;
161: c = 0;
162: while (b != 0) {
163: if ((b & 1) != 0) {
164: System.out.print("c" + c + " ");
165: }
166: b = b >> 1;
167: c++;
168: }
169:
170: if ((_flags & EXIT) != 0) {
171: System.out.print("exit ");
172: }
173: if ((_flags & RETURN) != 0) {
174: System.out.print("return ");
175: }
176:
177: if ((_flags & THROW) != 0) {
178: System.out.print("throw ");
179: }
180:
181: if ((_flags & BLOCKED) != 0) {
182: System.out.print("blocked");
183: }
184:
185: System.out.println();
186:
187: }
188:
189: }
|