X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fibex%2Ftool%2FCompiler.java;h=f79f4618832e49448a5f5a87db4d6fc57b209ca9;hb=ff10657e04640ccd49cda319b0457cdb91359599;hp=7c771a679a175ada68e50d0757f4340d7b224e10;hpb=c17753cd9e62cd1a71df3d88af908de0425ac33d;p=org.ibex.tool.git diff --git a/src/org/ibex/tool/Compiler.java b/src/org/ibex/tool/Compiler.java index 7c771a6..f79f461 100644 --- a/src/org/ibex/tool/Compiler.java +++ b/src/org/ibex/tool/Compiler.java @@ -1,3 +1,7 @@ +// Copyright 2000-2005 the Contributors, as shown in the revision logs. +// Licensed under the Apache Public Source License 2.0 ("the License"). +// You may not use this file except in compliance with the License. + package org.ibex.tool; import java.io.*; @@ -247,33 +251,7 @@ public class Compiler { private final FileFilter filterDirs = new FileFilter() { public boolean accept(File path) { return path.isDirectory(); } }; - private byte[] bytes(File bfile) { - byte[] bytes = new byte[2 * 1024]; - int pos = 0, in = 0; - try { - InputStream bin = new FileInputStream(bfile); - while ((in = bin.read(bytes, pos, bytes.length - pos)) != -1) { - pos += in; - if (pos == bytes.length) { - byte[] newbytes= new byte[pos * 2]; - System.arraycopy(bytes, 0, newbytes, 0, pos); - bytes = newbytes; - } - } - bin.close(); - } catch (IOException e) { - System.out.println("Error reading class file"); // FIXME - e.printStackTrace(); return null; - } - if (pos != bytes.length) { - byte[] newbytes= new byte[pos * 2]; - System.arraycopy(bytes, 0, newbytes, 0, pos); - bytes = newbytes; - } - - return bytes; - } private void filterSources(List s, File dir, char[][] pack, String srcdir) { List bclasses = new ArrayList(); File bdir = new File(builddir, str(pack, File.separatorChar)); @@ -388,7 +366,7 @@ public class Compiler { // Compiler Parameters //////////////////////////////////////////////////// // FEATURE: may be able to use this to block access to APIs generated for stack objects - final AccessRestriction access = new AccessRestriction(null, null, null, null); + final AccessRestriction access = null; /** Used by compiler to resolve classes. */ final INameEnvironment env = new INameEnvironment() { @@ -402,17 +380,14 @@ public class Compiler { if (veryverbose) System.out.println(" found in classloader: "+ c); IBinaryType b = (IBinaryType)loaded.get(c); if (b == null) loaded.put(c, b = new ClassFileReader( - read(c.getResourceAsStream(classname)), - (str(p, '/') + '/' + classname).toCharArray())); + bytes(c), (str(p, '/') + '/' + classname).toCharArray())); return new NameEnvironmentAnswer(b, access); } catch (ClassNotFoundException e) { + } catch (LinkageError e) { } catch (ClassFormatException e) { e.printStackTrace(); throw new Error("ClassFormatException reading system class: " + str(p, '.')+new String(n)); - } catch (IOException e) { - e.printStackTrace(); - throw new Error("IOException reading system class: "+str(p, '.')+new String(n)); } // cut out searches for java.* packages in sources list @@ -440,8 +415,8 @@ public class Compiler { } } } catch (ClassFormatException e) { - System.out.println("Unexpected ClassFormatException"); // FIXME - e.printStackTrace(); return null; + e.printStackTrace(); + throw new Error("unexpected ClassFormatException resolving compiled class: "+e); } if (veryverbose) System.out.println(" not found"); return null; @@ -652,23 +627,37 @@ public class Compiler { return sb.toString().toCharArray(); } - private static byte[] read(InputStream in) throws IOException { - byte[] bytes = new byte[16]; - int off = 0, ret; - while ((ret = in.read(bytes, off, bytes.length - off)) != -1) { - off += ret; - if (off == bytes.length) { - byte[] nb = new byte[bytes.length * 2]; - System.arraycopy(bytes, 0, nb, 0, bytes.length); - bytes = nb; + private static byte[] bytes(Class c) { + return bytes(c.getResourceAsStream('/' + c.getName().replace('.', '/') + ".class")); + } + private static byte[] bytes(File bfile) { + try { return bytes(new FileInputStream(bfile)); } + catch (FileNotFoundException e) { throw new Error("FileNotFoundException reading bytes: "+e); } + } + private static byte[] bytes(InputStream bin) { + byte[] bytes = new byte[2 * 1024]; + int pos = 0, in = 0; + try { + while ((in = bin.read(bytes, pos, bytes.length - pos)) != -1) { + pos += in; + if (pos == bytes.length) { + byte[] newbytes= new byte[pos * 2]; + System.arraycopy(bytes, 0, newbytes, 0, pos); + bytes = newbytes; + } } + bin.close(); + } catch (IOException e) { + e.printStackTrace(); + throw new Error("IOException reading class file: "+e); } - if (off != bytes.length) { - byte[] nb = new byte[off]; - System.arraycopy(bytes, 0, nb, 0, off); - bytes = nb; + + if (pos != bytes.length) { + byte[] newbytes= new byte[pos * 2]; + System.arraycopy(bytes, 0, newbytes, 0, pos); + bytes = newbytes; } + return bytes; } - }