1 30 package com.tc.asm.tree.analysis; 31 32 import java.util.ArrayList ; 33 import java.util.List ; 34 35 import com.tc.asm.Label; 36 import com.tc.asm.tree.JumpInsnNode; 37 38 43 class Subroutine { 44 45 Label start; 46 47 boolean[] access; 48 49 List callers; 50 51 private Subroutine() { 52 } 53 54 public Subroutine( 55 final Label start, 56 final int maxLocals, 57 final JumpInsnNode caller) 58 { 59 this.start = start; 60 this.access = new boolean[maxLocals]; 61 this.callers = new ArrayList (); 62 callers.add(caller); 63 } 64 65 public Subroutine copy() { 66 Subroutine result = new Subroutine(); 67 result.start = start; 68 result.access = new boolean[access.length]; 69 System.arraycopy(access, 0, result.access, 0, access.length); 70 result.callers = new ArrayList (callers); 71 return result; 72 } 73 74 public boolean merge(final Subroutine subroutine, boolean checkOverlap) 75 throws AnalyzerException 76 { 77 if (checkOverlap && subroutine.start != start) { 78 throw new AnalyzerException("Overlapping sub routines"); 79 } 80 boolean changes = false; 81 for (int i = 0; i < access.length; ++i) { 82 if (subroutine.access[i] && !access[i]) { 83 access[i] = true; 84 changes = true; 85 } 86 } 87 for (int i = 0; i < subroutine.callers.size(); ++i) { 88 Object caller = subroutine.callers.get(i); 89 if (!callers.contains(caller)) { 90 callers.add(caller); 91 changes = true; 92 } 93 } 94 return changes; 95 } 96 } | Popular Tags |