1 2 package java_cup; 3 import java_cup.runtime.Symbol; 4 import java.lang.reflect.Field ; 5 import java.lang.reflect.Modifier ; 6 public class ErrorManager{ 7 private static ErrorManager errorManager; 8 private int errors = 0; 9 private int warnings = 0; 10 private int fatals = 0; 11 public int getFatalCount() { return fatals; } 12 public int getErrorCount() { return errors; } 13 public int getWarningCount() { return warnings; } 14 static { 15 errorManager = new ErrorManager(); 16 } 17 public static ErrorManager getManager() { return errorManager; } 18 private ErrorManager(){ 19 } 20 21 27 public void emit_fatal(String message){ 28 System.err.println("Fatal : "+message); 29 fatals++; 30 } 31 public void emit_fatal(String message, Symbol sym){ 32 System.err.println("Fatal: "+message+" @ "+sym); 34 fatals++; 35 } 36 public void emit_warning(String message){ 37 System.err.println("Warning : " + message); 38 warnings++; 39 } 40 public void emit_warning(String message, Symbol sym){ 41 System.err.println("Fatal: "+message+" @ "+sym); 43 warnings++; 44 } 45 public void emit_error(String message){ 46 System.err.println("Error : " + message); 47 errors++; 48 } 49 public void emit_error(String message, Symbol sym){ 50 System.err.println("Error: "+message+" @ "+sym); 52 errors++; 53 } 54 private static String convSymbol(Symbol symbol){ 55 String result = (symbol.value == null)? "" : " (\""+symbol.value.toString()+"\")"; 56 Field [] fields = sym.class.getFields(); 57 for (int i = 0; i < fields.length ; i++){ 58 if (!Modifier.isPublic(fields[i].getModifiers())) continue; 59 try { 60 if (fields[i].getInt(null) == symbol.sym) return fields[i].getName()+result; 61 }catch (Exception ex) { 62 } 63 } 64 return symbol.toString()+result; 65 } 66 67 } 68 | Popular Tags |