01: /* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com
02:
03: This file is part of the db4o open source object database.
04:
05: db4o is free software; you can redistribute it and/or modify it under
06: the terms of version 2 of the GNU General Public License as published
07: by the Free Software Foundation and as clarified by db4objects' GPL
08: interpretation policy, available at
09: http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
10: Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
11: Suite 350, San Mateo, CA 94403, USA.
12:
13: db4o is distributed in the hope that it will be useful, but WITHOUT ANY
14: WARRANTY; without even the implied warranty of MERCHANTABILITY or
15: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16: for more details.
17:
18: You should have received a copy of the GNU General Public License along
19: with this program; if not, write to the Free Software Foundation, Inc.,
20: 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21: package EDU.purdue.cs.bloat.tree;
22:
23: import EDU.purdue.cs.bloat.cfg.*;
24:
25: /**
26: * SwitchStmt represents a switch statement.
27: */
28: public class SwitchStmt extends JumpStmt {
29: Expr index;
30:
31: Block defaultTarget;
32:
33: Block[] targets;
34:
35: int[] values;
36:
37: /**
38: * Constructor.
39: *
40: * @param index
41: * The expression on which the switch is made.
42: * @param defaultTarget
43: * The code to be executed if index is not contained in values.
44: * @param targets
45: * The code to be executed for each value in values.
46: * @param values
47: * The interesting values that index can have. That is, the
48: * values of index in which a non-default target is executed.
49: */
50: public SwitchStmt(final Expr index, final Block defaultTarget,
51: final Block[] targets, final int[] values) {
52: this .index = index;
53: this .defaultTarget = defaultTarget;
54: this .targets = targets;
55: this .values = values;
56:
57: index.setParent(this );
58: }
59:
60: public Expr index() {
61: return index;
62: }
63:
64: public void setDefaultTarget(final Block block) {
65: this .defaultTarget = block;
66: }
67:
68: public Block defaultTarget() {
69: return defaultTarget;
70: }
71:
72: public Block[] targets() {
73: return targets;
74: }
75:
76: public int[] values() {
77: return values;
78: }
79:
80: public void visitForceChildren(final TreeVisitor visitor) {
81: index.visit(visitor);
82: }
83:
84: public void visit(final TreeVisitor visitor) {
85: visitor.visitSwitchStmt(this );
86: }
87:
88: public Object clone() {
89: final Block[] t = new Block[targets.length];
90: System.arraycopy(targets, 0, t, 0, targets.length);
91:
92: final int[] v = new int[values.length];
93: System.arraycopy(values, 0, v, 0, values.length);
94:
95: return copyInto(new SwitchStmt((Expr) index.clone(),
96: defaultTarget, t, v));
97: }
98: }
|