1 2 package polyglot.util.typedump; 3 4 import polyglot.util.*; 5 import polyglot.types.Type; 6 import polyglot.types.TypeSystem; 7 import polyglot.frontend.ExtensionInfo; 8 9 public class Main { 10 public static void main(String args[]) { 11 String extension = "jl"; 12 String className; 13 if (args.length == 3 && args[0].equals("-ext")) 14 extension = args[1]; 15 if ((extension == null && args.length != 1) || 16 (extension != null && args.length != 3)) { 17 System.err.println("Usage: " + 18 "polyglot.util.typedump.Main "+ 19 "[-ext <extension>] <classname>"); 20 System.exit(1); 21 } 22 23 if (extension == null) 24 className = args[0]; 25 else 26 className = args[2]; 27 28 ExtensionInfo extInfo = null; 29 30 String extClassName = 31 "polyglot.ext." + extension + ".ExtensionInfo"; 32 Class extClass = null; 33 34 try { 35 extClass = Class.forName(extClassName); 36 } 37 catch (ClassNotFoundException e) { 38 System.err.println( "Extension " + extension + 39 " not found: could not find class " + 40 extClassName + "."); 41 System.exit( 1); 42 } 43 44 try { 45 extInfo = (ExtensionInfo) extClass.newInstance(); 46 } 47 catch (Exception e) { 48 System.err.println( "Extension " + extension + 49 " could not be loaded: "+ 50 "could not instantiate " + extClassName + "."); 51 System.exit( 1); 52 } 53 54 try { 55 TypeSystem ts = extInfo.typeSystem(); 56 TypeDumper t = TypeDumper.load(className, ts); 57 58 CodeWriter cw = new CodeWriter(System.out, 72); 59 60 t.dump(cw); 61 cw.newline(0); 62 63 try { 64 cw.flush(); 65 } catch (java.io.IOException exn) { 66 System.err.println(exn.getMessage()); 67 } 68 } catch (java.io.IOException exn) { 69 System.err.println("IO errors."); 70 System.err.println(exn.getMessage()); 71 } catch (ClassNotFoundException exn) { 72 System.err.println("Could not load .class: "+className); 73 System.err.println(exn.getMessage()); 74 } catch (NoSuchFieldException exn) { 75 System.err.println("Could not reflect jlc fields"); 76 System.err.println(exn.getMessage()); 77 } catch (SecurityException exn) { 78 System.err.println("Security policy error."); 79 System.err.println(exn.getMessage()); 80 } 81 } 82 } 83 | Popular Tags |