View Javadoc

1   /*
2    * Copyright 2005 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at 
7    * 
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software 
11   * distributed under the License is distributed on an "AS IS" BASIS, 
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
13   * See the License for the specific language governing permissions and 
14   * limitations under the License.
15   */
16  
17  
18  package org.apache.jdo.impl.enhancer.classfile;
19  
20  import java.io.PrintStream;
21  import java.util.Stack;
22  
23  /***
24   * InsnTarget is a pseudo-instruction which represents a branch target
25   * in an instruction stream.
26   */
27  public class InsnTarget extends Insn {
28  
29      private boolean branchTarget = false;
30  
31      public int nStackArgs() {
32          return 0;
33      }
34  
35      public int nStackResults() {
36          return 0;
37      }
38  
39      public String argTypes() {
40          return "";
41      }
42  
43      public String resultTypes() {
44          return "";
45      }
46  
47      public boolean branches() {
48          return false;
49      }
50  
51      public void setBranchTarget() {
52          branchTarget = true;
53      }
54  
55      /* not valid unless method instructions processed specially */
56      public boolean isBranchTarget() {
57          return branchTarget;
58      }
59  
60      /***
61       * Constructor
62       */
63      public InsnTarget() {
64          super(opc_target, NO_OFFSET);
65      }
66  
67      /***
68       * Compares this instance with another for structural equality.
69       */
70      //@olsen: added method
71      public boolean isEqual(Stack msg, Object obj) {
72          if (!(obj instanceof InsnTarget)) {
73              msg.push("obj/obj.getClass() = "
74                       + (obj == null ? null : obj.getClass()));
75              msg.push("this.getClass() = "
76                       + this.getClass());
77              return false;
78          }
79          InsnTarget other = (InsnTarget)obj;
80  
81          if (!super.isEqual(msg, other)) {
82              return false;
83          }
84  
85          if (this.branchTarget != other.branchTarget) {
86              msg.push(String.valueOf("branchTarget = "
87                                      + other.branchTarget));
88              msg.push(String.valueOf("branchTarget = "
89                                      + this.branchTarget));
90              return false;
91          }
92          return true;
93      }
94  
95      /* package local methods *//package-summary/html">class="comment"> package local methods *//package-summary.html">/* package local methods *//package-summary.html">class="comment"> package local methods */
96  
97      void print (PrintStream out, int indent) {
98          ClassPrint.spaces(out, indent);
99          out.println(offset() + ":");
100     }
101 
102     int store(byte buf[], int index) {
103         return index;
104     }
105 
106     int size() {
107         return 0;
108     }
109 
110     InsnTarget(int offset) {
111         super(opc_target, offset);
112     }
113 }