1 /* 2 * reserved comment block 3 * DO NOT REMOVE OR ALTER! 4 */ 5 /* 6 * Licensed to the Apache Software Foundation (ASF) under one or more 7 * contributor license agreements. See the NOTICE file distributed with 8 * this work for additional information regarding copyright ownership. 9 * The ASF licenses this file to You under the Apache License, Version 2.0 10 * (the "License"); you may not use this file except in compliance with 11 * the License. You may obtain a copy of the License at 12 * 13 * http://www.apache.org/licenses/LICENSE-2.0 14 * 15 * Unless required by applicable law or agreed to in writing, software 16 * distributed under the License is distributed on an "AS IS" BASIS, 17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 * See the License for the specific language governing permissions and 19 * limitations under the License. 20 */ 21 22 package com.sun.org.apache.bcel.internal.generic; 23 24 25 /** 26 * Equality of instructions isn't clearly to be defined. You might 27 * wish, for example, to compare whether instructions have the same 28 * meaning. E.g., whether two INVOKEVIRTUALs describe the same 29 * call.<br>The DEFAULT comparator however, considers two instructions 30 * to be equal if they have same opcode and point to the same indexes 31 * (if any) in the constant pool or the same local variable index. Branch 32 * instructions must have the same target. 33 * 34 * @see Instruction 35 * @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> 36 */ 37 public interface InstructionComparator { 38 public static final InstructionComparator DEFAULT = 39 new InstructionComparator() { 40 public boolean equals(Instruction i1, Instruction i2) { 41 if(i1.opcode == i2.opcode) { 42 if(i1 instanceof Select) { 43 InstructionHandle[] t1 = ((Select)i1).getTargets(); 44 InstructionHandle[] t2 = ((Select)i2).getTargets(); 45 46 if(t1.length == t2.length) { 47 for(int i = 0; i < t1.length; i++) { 48 if(t1[i] != t2[i]) { 49 return false; 50 } 51 } 52 53 return true; 54 } 55 } else if(i1 instanceof BranchInstruction) { 56 return ((BranchInstruction)i1).target == 57 ((BranchInstruction)i2).target; 58 } else if(i1 instanceof ConstantPushInstruction) { 59 return ((ConstantPushInstruction)i1).getValue(). 60 equals(((ConstantPushInstruction)i2).getValue()); 61 } else if(i1 instanceof IndexedInstruction) { 62 return ((IndexedInstruction)i1).getIndex() == 63 ((IndexedInstruction)i2).getIndex(); 64 } else if(i1 instanceof NEWARRAY) { 65 return ((NEWARRAY)i1).getTypecode() == ((NEWARRAY)i2).getTypecode(); 66 } else { 67 return true; 68 } 69 } 70 71 return false; 72 } 73 }; 74 75 public boolean equals(Instruction i1, Instruction i2); 76 }