1 19 20 25 26 27 package soot.jimple.toolkits.scalar; 28 29 import soot.*; 30 import soot.jimple.*; 31 import soot.util.*; 32 import java.util.*; 33 34 38 public class LocalCreation { 39 40 public static final String DEFAULT_PREFIX = "soot"; 41 private String prefix; 42 private int counter; 43 private Set locals; 44 private Chain localChain; 45 46 52 public LocalCreation(Chain locals) { 53 this(locals, DEFAULT_PREFIX); 54 } 55 56 63 public LocalCreation(Chain locals, String prefix) { 64 this.locals = new HashSet(locals.size()); 65 localChain = locals; 66 Iterator it = locals.iterator(); 67 while (it.hasNext()) { 68 Local l = (Local)it.next(); 69 this.locals.add(l.getName()); 70 } 71 this.prefix = prefix; 72 counter = 0; } 74 75 85 public Local newLocal(Type type) { 86 return newLocal(prefix, type); 87 } 88 89 99 public Local newLocal(String prefix, Type type) { 100 int suffix = 0; 101 if (prefix == this.prefix || 102 prefix.equals(this.prefix)) { 103 suffix = counter; 104 } 105 106 while (locals.contains(prefix + suffix)) suffix++; 107 108 if (prefix == this.prefix || 109 prefix.equals(this.prefix)) { 110 counter = suffix + 1; 111 } 112 String newName = prefix + suffix; 113 Local newLocal = Jimple.v().newLocal(newName, type); 114 localChain.addLast(newLocal); 115 locals.add(newName); 116 return newLocal; 117 } 118 } 119 | Popular Tags |