1 16 19 20 package org.apache.xalan.xsltc.compiler; 21 22 import java.util.Iterator ; 23 import java.util.Vector ; 24 25 import org.apache.bcel.generic.BranchHandle; 26 import org.apache.bcel.generic.InstructionHandle; 27 import org.apache.bcel.generic.InstructionList; 28 29 33 public final class FlowList { 34 private Vector _elements; 35 36 public FlowList() { 37 _elements = null; 38 } 39 40 public FlowList(InstructionHandle bh) { 41 _elements = new Vector (); 42 _elements.addElement(bh); 43 } 44 45 public FlowList(FlowList list) { 46 _elements = list._elements; 47 } 48 49 public FlowList add(InstructionHandle bh) { 50 if (_elements == null) { 51 _elements = new Vector (); 52 } 53 _elements.addElement(bh); 54 return this; 55 } 56 57 public FlowList append(FlowList right) { 58 if (_elements == null) { 59 _elements = right._elements; 60 } 61 else { 62 final Vector temp = right._elements; 63 if (temp != null) { 64 final int n = temp.size(); 65 for (int i = 0; i < n; i++) { 66 _elements.addElement(temp.elementAt(i)); 67 } 68 } 69 } 70 return this; 71 } 72 73 76 public void backPatch(InstructionHandle target) { 77 if (_elements != null) { 78 final int n = _elements.size(); 79 for (int i = 0; i < n; i++) { 80 BranchHandle bh = (BranchHandle)_elements.elementAt(i); 81 bh.setTarget(target); 82 } 83 _elements.clear(); } 85 } 86 87 91 public FlowList copyAndRedirect(InstructionList oldList, 92 InstructionList newList) 93 { 94 final FlowList result = new FlowList(); 95 if (_elements == null) { 96 return result; 97 } 98 99 final int n = _elements.size(); 100 final Iterator oldIter = oldList.iterator(); 101 final Iterator newIter = newList.iterator(); 102 103 while (oldIter.hasNext()) { 104 final InstructionHandle oldIh = (InstructionHandle) oldIter.next(); 105 final InstructionHandle newIh = (InstructionHandle) newIter.next(); 106 107 for (int i = 0; i < n; i++) { 108 if (_elements.elementAt(i) == oldIh) { 109 result.add(newIh); 110 } 111 } 112 } 113 return result; 114 } 115 } 116 | Popular Tags |