forked from onlyliuxin/coding2017
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c0e03cd
commit 4f3cecb
Showing
5 changed files
with
245 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
.../812350401/src/main/java/com/github/miniyk2012/coding2017/coderising/jvm/field/Field.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.github.miniyk2012.coding2017.coderising.jvm.field; | ||
|
||
import assignments.jvm.constant.ConstantPool; | ||
import assignments.jvm.constant.UTF8Info; | ||
import assignments.jvm.loader.ByteCodeIterator; | ||
|
||
|
||
public class Field { | ||
private int accessFlag; | ||
private int nameIndex; | ||
private int descriptorIndex; | ||
|
||
|
||
|
||
private ConstantPool pool; | ||
|
||
public Field(int accessFlag, int nameIndex, int descriptorIndex, ConstantPool pool) { | ||
|
||
this.accessFlag = accessFlag; | ||
this.nameIndex = nameIndex; | ||
this.descriptorIndex = descriptorIndex; | ||
this.pool = pool; | ||
} | ||
|
||
public String toString() { | ||
String name = ((UTF8Info)pool.getConstantInfo(this.nameIndex)).getValue(); | ||
|
||
String desc = ((UTF8Info)pool.getConstantInfo(this.descriptorIndex)).getValue(); | ||
return name +":"+ desc; | ||
} | ||
|
||
|
||
public static Field parse(ConstantPool pool, ByteCodeIterator iter){ | ||
|
||
int accessFlag = iter.nextU2ToInt(); | ||
int nameIndex = iter.nextU2ToInt(); | ||
int descIndex = iter.nextU2ToInt(); | ||
int attribCount = iter.nextU2ToInt(); | ||
//System.out.println("field attribute count:"+ attribCount); | ||
|
||
Field f = new Field(accessFlag, nameIndex, descIndex,pool); | ||
|
||
if(attribCount > 0){ | ||
throw new RuntimeException("Field Attribute has not been implemented"); | ||
} | ||
|
||
return f; | ||
} | ||
|
||
} |
96 changes: 96 additions & 0 deletions
96
...12350401/src/main/java/com/github/miniyk2012/coding2017/coderising/jvm/method/Method.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package com.github.miniyk2012.coding2017.coderising.jvm.method; | ||
|
||
import assignments.jvm.clz.ClassFile; | ||
import assignments.jvm.attr.AttributeInfo; | ||
import assignments.jvm.attr.CodeAttr; | ||
import assignments.jvm.constant.ConstantPool; | ||
import assignments.jvm.constant.UTF8Info; | ||
import assignments.jvm.loader.ByteCodeIterator; | ||
|
||
|
||
|
||
public class Method { | ||
|
||
private int accessFlag; | ||
private int nameIndex; | ||
private int descriptorIndex; | ||
|
||
private CodeAttr codeAttr; | ||
|
||
private ClassFile clzFile; | ||
|
||
|
||
public ClassFile getClzFile() { | ||
return clzFile; | ||
} | ||
|
||
public int getNameIndex() { | ||
return nameIndex; | ||
} | ||
public int getDescriptorIndex() { | ||
return descriptorIndex; | ||
} | ||
|
||
public CodeAttr getCodeAttr() { | ||
return codeAttr; | ||
} | ||
|
||
public void setCodeAttr(CodeAttr code) { | ||
this.codeAttr = code; | ||
} | ||
|
||
public Method(ClassFile clzFile,int accessFlag, int nameIndex, int descriptorIndex) { | ||
this.clzFile = clzFile; | ||
this.accessFlag = accessFlag; | ||
this.nameIndex = nameIndex; | ||
this.descriptorIndex = descriptorIndex; | ||
} | ||
|
||
|
||
|
||
|
||
|
||
public String toString() { | ||
|
||
ConstantPool pool = this.clzFile.getConstantPool(); | ||
StringBuilder buffer = new StringBuilder(); | ||
|
||
String name = ((UTF8Info)pool.getConstantInfo(this.nameIndex)).getValue(); | ||
|
||
String desc = ((UTF8Info)pool.getConstantInfo(this.descriptorIndex)).getValue(); | ||
|
||
buffer.append(name).append(":").append(desc).append("\n"); | ||
|
||
buffer.append(this.codeAttr.toString(pool)); | ||
|
||
return buffer.toString(); | ||
} | ||
|
||
public static Method parse(ClassFile clzFile, ByteCodeIterator iter){ | ||
int accessFlag = iter.nextU2ToInt(); | ||
int nameIndex = iter.nextU2ToInt(); | ||
int descIndex = iter.nextU2ToInt(); | ||
int attribCount = iter.nextU2ToInt(); | ||
|
||
|
||
Method m = new Method(clzFile, accessFlag, nameIndex, descIndex); | ||
|
||
for( int j=1; j<= attribCount; j++){ | ||
|
||
int attrNameIndex = iter.nextU2ToInt(); | ||
String attrName = clzFile.getConstantPool().getUTF8String(attrNameIndex); | ||
iter.back(2); | ||
|
||
if(AttributeInfo.CODE.equalsIgnoreCase(attrName)){ | ||
CodeAttr codeAttr = CodeAttr.parse(clzFile, iter); | ||
m.setCodeAttr(codeAttr); | ||
} else{ | ||
throw new RuntimeException("only CODE attribute is implemented , please implement the "+ attrName); | ||
} | ||
|
||
} | ||
|
||
return m ; | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters