1 package polyglot.main; 2 3 import java.util.Arrays ; 4 import java.util.Collection ; 5 import java.util.Collections ; 6 import java.util.HashMap ; 7 import java.util.HashSet ; 8 import java.util.Iterator ; 9 import java.util.Map ; 10 import java.util.Stack ; 11 12 13 public class Report { 14 16 public final static Collection topics = new HashSet (); 17 18 20 public final static Stack should_report = new Stack (); 21 22 26 protected final static Map reportTopics = new HashMap (); 28 29 36 static boolean noReporting = true; 37 38 39 public final static String cfg = "cfg"; 40 public final static String context = "context"; 41 public final static String dataflow = "dataflow"; 42 public final static String errors = "errors"; 43 public final static String frontend = "frontend"; 44 public final static String imports = "imports"; 45 public final static String loader = "loader"; 46 public final static String resolver = "resolver"; 47 public final static String serialize = "serialize"; 48 public final static String time = "time"; 49 public final static String types = "types"; 50 public final static String visit = "visit"; 51 public final static String verbose = "verbose"; 52 53 public final static String debug = "debug"; 55 56 static { 57 topics.add(cfg); 58 topics.add(context); 59 topics.add(dataflow); 60 topics.add(errors); 61 topics.add(frontend); 62 topics.add(imports); 63 topics.add(loader); 64 topics.add(resolver); 65 topics.add(serialize); 66 topics.add(time); 67 topics.add(types); 68 topics.add(visit); 69 topics.add(verbose); 70 topics.add(debug); 71 72 should_report.push(verbose); 73 } 74 75 80 public static boolean should_report(String topic, int level) { 81 if (noReporting) 82 return false; 83 return should_report(Collections.singletonList(topic), level); 84 } 85 86 91 public static boolean should_report(String [] topics, int level) { 92 if (noReporting) 93 return false; 94 return should_report(Arrays.asList(topics), level); 95 } 96 97 102 public static boolean should_report(Collection topics, int level) { 103 if (noReporting) 104 return false; 105 for (Iterator i = should_report.iterator(); i.hasNext();) { 106 String topic = (String ) i.next(); 107 if (level(topic) >= level) return true; 108 } 109 if (topics != null) { 110 for (Iterator i = topics.iterator(); i.hasNext();) { 111 String topic = (String ) i.next(); 112 if (level(topic) >= level) return true; 113 } 114 } 115 return false; 116 } 117 118 public static void addTopic(String topic, int level) { 119 Integer i = (Integer )reportTopics.get(topic); 120 if (i == null || i.intValue() < level) { 121 reportTopics.put(topic, new Integer (level)); 122 } 123 noReporting = false; 124 } 125 126 protected static int level(String name) { 127 Object i = reportTopics.get(name); 128 if (i == null) return 0; 129 else return ((Integer )i).intValue(); 130 } 131 132 139 public static void report(int level, String message) { 140 for (int j = 1; j < level; j++) System.err.print(" "); 141 System.err.println(message); 142 } 143 } 144 | Popular Tags |