?? bytecodeparser.java
字號:
package AST;
import java.util.HashSet;import java.util.LinkedHashSet;import java.io.FileNotFoundException;import java.io.File;import java.util.*;import beaver.*;import java.util.ArrayList;import java.util.zip.*;import java.io.*;public class BytecodeParser extends java.lang.Object implements BytecodeReader {
// Declared in BytecodeReader.jrag at line 13 public CompilationUnit read(InputStream is, String fullName, Program p) throws FileNotFoundException, IOException { return new BytecodeParser(is, fullName).parse(null, null, p); } // Declared in BytecodeReader.jrag at line 17 public static final boolean VERBOSE = false; // Declared in BytecodeReader.jrag at line 19 private DataInputStream is; // Declared in BytecodeReader.jrag at line 20 public CONSTANT_Class_Info classInfo; // Declared in BytecodeReader.jrag at line 21 public CONSTANT_Class_Info outerClassInfo; // Declared in BytecodeReader.jrag at line 22 public String name; // Declared in BytecodeReader.jrag at line 24 public BytecodeParser(byte[] buffer, int size, String name) { //this.is = new DataInputStream(new DummyInputStream(buffer, size)); this.is = new DataInputStream(new ByteArrayInputStream(buffer, 0, size)); this.name = name; } // Declared in BytecodeReader.jrag at line 29 public BytecodeParser(InputStream in, String name) { //this.is = new DataInputStream(new DummyInputStream(buffer, size)); this.is = new DataInputStream(new DummyInputStream(in)); this.name = name; } // Declared in BytecodeReader.jrag at line 35 public BytecodeParser() { this(""); } // Declared in BytecodeReader.jrag at line 38 public BytecodeParser(String name) { if (!name.endsWith(".class")) { //name = name.replaceAll("\\.", "/") + ".class"; name = name.replace('.', '/') + ".class"; } this.name = name; } // Declared in BytecodeReader.jrag at line 46 private static class DummyInputStream extends InputStream { byte[] bytes; int pos; int size; public DummyInputStream(byte[] buffer, int size) { bytes = buffer; this.size = size; } public DummyInputStream(InputStream is) { bytes = new byte[1024]; int index = 0; size = 1024; try { int status; do { status = is.read(bytes, index, size - index); if(status != -1) { index += status; if(index == size) { byte[] newBytes = new byte[size*2]; System.arraycopy(bytes, 0, newBytes, 0, size); bytes = newBytes; size *= 2; } } } while (status != -1); } catch (IOException e) { System.err.println("Something went wrong trying to read " + is); //System.exit(1); } size = index; pos = 0; } public int available() { return size - pos; } public void close() { } public void mark(int readlimit) { } public boolean markSupported() { return false; } public int read(byte[] b) { int actualLength = Math.min(b.length, size-pos); System.arraycopy(bytes, pos, b, 0, actualLength); pos += actualLength; return actualLength; } public int read(byte[] b, int offset, int length) { int actualLength = Math.min(length, size-pos); System.arraycopy(bytes, pos, b, offset, actualLength); pos += actualLength; return actualLength; } public void reset() { } public long skip(long n) { if(size == pos) return -1; long skipSize = Math.min(n, size-pos); pos += skipSize; return skipSize; } public int read() throws IOException { if(pos < size) { int i = bytes[pos++]; if(i < 0) i = 256 + i; return i; } return -1; } } // Declared in BytecodeReader.jrag at line 130 public int next() { try { return is.read(); } catch (IOException e) { System.exit(1); } return -1; } // Declared in BytecodeReader.jrag at line 139 public int u1() { try { return is.readUnsignedByte(); } catch (IOException e) { System.exit(1); } return -1; } // Declared in BytecodeReader.jrag at line 148 public int u2() { try { return is.readUnsignedShort(); } catch (IOException e) { System.exit(1); } return -1; } // Declared in BytecodeReader.jrag at line 157 public int u4() { try { return is.readInt(); } catch (IOException e) { System.exit(1); } return -1; } // Declared in BytecodeReader.jrag at line 166 public int readInt() { try { return is.readInt(); } catch (IOException e) { System.exit(1); } return -1; } // Declared in BytecodeReader.jrag at line 175 public float readFloat() { try { return is.readFloat(); } catch (IOException e) { System.exit(1); } return -1; } // Declared in BytecodeReader.jrag at line 184 public long readLong() { try { return is.readLong(); } catch (IOException e) { System.exit(1); } return -1; } // Declared in BytecodeReader.jrag at line 193 public double readDouble() { try { return is.readDouble(); } catch (IOException e) { System.exit(1); } return -1; } // Declared in BytecodeReader.jrag at line 202 public String readUTF() { try { return is.readUTF(); } catch (IOException e) { System.exit(1); } return ""; } // Declared in BytecodeReader.jrag at line 211 public void skip(int length) { try { is.skip(length); } catch (IOException e) { System.exit(1); } } // Declared in BytecodeReader.jrag at line 219 public void error(String s) { throw new RuntimeException(s); } // Declared in BytecodeReader.jrag at line 223 public void print(String s) { //System.out.print(s); } // Declared in BytecodeReader.jrag at line 227 public void println(String s) { print(s + "\n"); } // Declared in BytecodeReader.jrag at line 231 public void println() { print("\n"); } // Declared in BytecodeReader.jrag at line 235 public CompilationUnit parse(TypeDecl outerTypeDecl, CONSTANT_Class_Info outerClassInfo, Program classPath) throws FileNotFoundException, IOException { //InputStream file = ClassLoader.getSystemResourceAsStream(name); if(is == null) { FileInputStream file = new FileInputStream("/home/torbjorn/sandbox/jdk/" + name); //System.err.println("/home/torbjorn/sandbox/jdk/" + name); if(file == null) { throw new FileNotFoundException(name); } // // Does not work without DummyInputStream. Why? //is = new DataInputStream(new DummyInputStream(new BufferedInputStream(file))); is = new DataInputStream(new BufferedInputStream(file)); } if(BytecodeParser.VERBOSE) println("Parsing byte codes in " + name); this.outerClassInfo = outerClassInfo; parseMagic(); parseMinor(); parseMajor(); parseConstantPool(); CompilationUnit cu = new CompilationUnit(); TypeDecl typeDecl = parseTypeDecl(); cu.setPackageDecl(classInfo.packageDecl()); cu.addTypeDecl(typeDecl); parseFields(typeDecl); parseMethods(typeDecl); new Attributes(this, typeDecl, outerTypeDecl, classPath); is.close(); is = null; return cu; } // Declared in BytecodeReader.jrag at line 272 public void parseMagic() { if (next() != 0xca || next() != 0xfe || next() != 0xba || next() != 0xbe)
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -