1 30 package org.objectweb.asm.tree; 31 32 import java.util.ArrayList ; 33 import java.util.List ; 34 import java.util.Map ; 35 36 import org.objectweb.asm.MethodVisitor; 37 import org.objectweb.asm.Opcodes; 38 39 52 public class FrameNode extends AbstractInsnNode { 53 54 60 public int type; 61 62 68 public List local; 69 70 76 public List stack; 77 78 private FrameNode() { 79 super(-1); 80 } 81 82 101 public FrameNode( 102 final int type, 103 final int nLocal, 104 final Object [] local, 105 final int nStack, 106 final Object [] stack) 107 { 108 super(-1); 109 this.type = type; 110 switch (type) { 111 case Opcodes.F_NEW: 112 case Opcodes.F_FULL: 113 this.local = asList(nLocal, local); 114 this.stack = asList(nStack, stack); 115 break; 116 case Opcodes.F_APPEND: 117 this.local = asList(nLocal, local); 118 break; 119 case Opcodes.F_CHOP: 120 this.local = asList(nLocal, new Object [nLocal]); 121 break; 122 case Opcodes.F_SAME: 123 break; 124 case Opcodes.F_SAME1: 125 this.stack = asList(1, stack); 126 break; 127 } 128 } 129 130 public int getType() { 131 return FRAME; 132 } 133 134 139 public void accept(final MethodVisitor mv) { 140 switch (type) { 141 case Opcodes.F_NEW: 142 case Opcodes.F_FULL: 143 mv.visitFrame(type, 144 local.size(), 145 asArray(local), 146 stack.size(), 147 asArray(stack)); 148 break; 149 case Opcodes.F_APPEND: 150 mv.visitFrame(type, local.size(), asArray(local), 0, null); 151 break; 152 case Opcodes.F_CHOP: 153 mv.visitFrame(type, local.size(), null, 0, null); 154 break; 155 case Opcodes.F_SAME: 156 mv.visitFrame(type, 0, null, 0, null); 157 break; 158 case Opcodes.F_SAME1: 159 mv.visitFrame(type, 0, null, 1, asArray(stack)); 160 break; 161 } 162 } 163 164 public AbstractInsnNode clone(final Map labels) { 165 FrameNode clone = new FrameNode(); 166 clone.type = type; 167 if (local != null) { 168 clone.local = new ArrayList (); 169 for (int i = 0; i < local.size(); ++i) { 170 Object l = local.get(i); 171 if (l instanceof LabelNode) { 172 l = labels.get(l); 173 } 174 clone.local.add(l); 175 } 176 } 177 if (stack != null) { 178 clone.stack = new ArrayList (); 179 for (int i = 0; i < stack.size(); ++i) { 180 Object s = stack.get(i); 181 if (s instanceof LabelNode) { 182 s = labels.get(s); 183 } 184 clone.stack.add(s); 185 } 186 } 187 return clone; 188 } 189 190 192 private static List asList(final int n, final Object [] o) { 193 List l = new ArrayList (n); 194 for (int i = 0; i < n; ++i) { 195 l.add(o[i]); 196 } 197 return l; 198 } 199 200 private static Object [] asArray(final List l) { 201 Object [] objs = new Object [l.size()]; 202 for (int i = 0; i < objs.length; ++i) { 203 Object o = l.get(i); 204 if (o instanceof LabelNode) { 205 o = ((LabelNode) o).getLabel(); 206 } 207 objs[i] = o; 208 } 209 return objs; 210 } 211 } 212 | Popular Tags |