📄 jasmparser.java
字号:
}
private int getLookupSource(String arg, int line) {
try {
String[] args = arg.split(":");
if (args.length != 2) {
parseException.addError(JAsmParseException.BAD_LOOKUP_ARGUMENT,
arg, line);
return 1;
}
if (args[0].trim().equals("default")) {
return -1;
}
int b = Integer.parseInt(args[0].trim());
return b;
} catch (ArrayIndexOutOfBoundsException exc1) {
parseException.addError(JAsmParseException.MISSING_ARGUMENTS, arg,
line);
return 1;
} catch (NumberFormatException exc1) {
parseException.addError(JAsmParseException.BAD_LOOKUP_ARGUMENT,
arg, line);
return 1;
}
}
private int getLookupTarget(String arg, int line, int codeLength) {
try {
String[] args = arg.split(":");
if (args.length != 2) {
parseException.addError(JAsmParseException.BAD_LOOKUP_ARGUMENT,
arg, line);
return 1;
}
int b = Integer.parseInt(args[1].trim());
if (b < 1 || b > codeLength) {
parseException.addError(JAsmParseException.JUMP_OUT_OF_DOMAIN,
arg, line);
return 1;
}
return b;
} catch (ArrayIndexOutOfBoundsException exc1) {
parseException.addError(JAsmParseException.MISSING_ARGUMENTS, arg,
line);
return 1;
} catch (NumberFormatException exc1) {
parseException.addError(JAsmParseException.BAD_LOOKUP_ARGUMENT,
arg, line);
return 1;
}
}
private int countLines(String[] codeLines) {
int count = 0;
for (int i = 0; i < codeLines.length; i++) {
if (!beginsWithWhitespace(codeLines[i])) {
count++;
}
}
return count;
}
private boolean beginsWithWhitespace(String line) {
if (!line.equals("")) {
if (line.charAt(0) == ' ' || line.charAt(0) == '\t')
return true;
}
return false;
}
private int getTableArg(String arg, int line, int codeLength) {
try {
int i = Integer.parseInt(arg);
if (i < 1 || i > codeLength) {
parseException.addError(JAsmParseException.JUMP_OUT_OF_DOMAIN,
arg, line);
return 1;
}
return i;
} catch (ArrayIndexOutOfBoundsException exc1) {
parseException.addError(JAsmParseException.MISSING_ARGUMENTS, arg,
line);
return 1;
} catch (NumberFormatException exc1) {
parseException.addError(JAsmParseException.INT_REQUIRED, arg, line);
return 1;
}
}
private int getJumpArg(String[] instrElems, int line, int codeLength) {
try {
int b = Integer.parseInt(instrElems[1]);
if (b < 1 || b > codeLength) {
parseException.addError(JAsmParseException.JUMP_OUT_OF_DOMAIN,
instrElems[0], line);
return 1;
}
return b;
} catch (ArrayIndexOutOfBoundsException exc1) {
parseException.addError(JAsmParseException.MISSING_ARGUMENTS,
instrElems[0], line);
return 1;
} catch (NumberFormatException exc1) {
parseException.addError(JAsmParseException.INT_REQUIRED,
instrElems[0], line);
return 1;
}
}
private short getSingleShortArg(String[] instrElems, int line) {
try {
short b = Short.parseShort(instrElems[1]);
return b;
} catch (ArrayIndexOutOfBoundsException exc1) {
parseException.addError(JAsmParseException.MISSING_ARGUMENTS,
instrElems[0], line);
return 0;
} catch (NumberFormatException exc1) {
parseException.addError(JAsmParseException.SHORT_REQUIRED,
instrElems[0], line);
return 0;
}
}
private int getSingleIntArg(String[] instrElems, int line) {
try {
int b = Integer.parseInt(instrElems[1]);
return b;
} catch (ArrayIndexOutOfBoundsException exc1) {
parseException.addError(JAsmParseException.MISSING_ARGUMENTS,
instrElems[0], line);
return 0;
} catch (NumberFormatException exc1) {
parseException.addError(JAsmParseException.INT_REQUIRED,
instrElems[0], line);
return 0;
}
}
private byte getSingleByteArg(String[] instrElems, int line) {
try {
byte b = Byte.parseByte(instrElems[1]);
return b;
} catch (ArrayIndexOutOfBoundsException exc1) {
parseException.addError(JAsmParseException.MISSING_ARGUMENTS,
instrElems[0], line);
return 0;
} catch (NumberFormatException exc1) {
parseException.addError(JAsmParseException.BYTE_REQUIRED,
instrElems[0], line);
return 0;
}
}
private int getConstRefldc2_w(String[] instrElems, ConstantPoolGen cpg,
int line) {
if (instrElems.length < 2) {
parseException.addError(JAsmParseException.MISSING_ARGUMENTS,
instrElems[0], line);
return 0;
}
try {
long larg = Long.parseLong(instrElems[1]);
return cpg.addLong(larg);
} catch (NumberFormatException nfei) {
}
try {
double darg = Double.parseDouble(instrElems[1]);
return cpg.addDouble(darg);
} catch (NumberFormatException nfed) {
}
parseException.addError(JAsmParseException.ARG_TYPE_ERROR_LDC2_W,
instrElems[0], line);
return 0;
}
private byte getArrayRef(String[] instrElems, int line) {
if (instrElems.length < 2) {
parseException.addError(JAsmParseException.MISSING_ARGUMENTS,
instrElems[0], line);
return 0;
}
byte arg;
try {
arg = Byte.parseByte(instrElems[1]);
} catch (NumberFormatException nfe) {
arg = OpcodesUtil.getArrayType(instrElems[1]);
if (arg == 0) {
parseException.addError(JAsmParseException.ARG_TYPE_ERROR,
instrElems[0], line);
}
}
return arg;
}
private int getConstRef4ldc(String[] instrElems, ConstantPoolGen cpg,
int line) {
if (instrElems.length < 2) {
parseException.addError(JAsmParseException.MISSING_ARGUMENTS,
instrElems[0], line);
return 0;
}
try {
int iarg = Integer.parseInt(instrElems[1]);
return cpg.addInteger(iarg);
} catch (NumberFormatException nfei) {
}
try {
float farg = Float.parseFloat(instrElems[1]);
return cpg.addFloat(farg);
} catch (NumberFormatException nfed) {
}
if (instrElems[1].startsWith("\"")) {
StringBuffer sb = new StringBuffer(instrElems[1]);
for (int i = 2; i < instrElems.length; i++) {
sb.append(" ").append(instrElems[i]);
}
String sarg = sb.toString();
if (sarg.startsWith("\"") && sarg.endsWith("\"")) {
sarg = sarg.substring(1, sarg.length() - 1);
return cpg.addString(sarg);
} else {
parseException.addError(JAsmParseException.ARG_TYPE_ERROR,
instrElems[0], line);
return 0;
}
}
parseException.addError(JAsmParseException.ARG_TYPE_ERROR,
instrElems[0], line);
return 0;
}
private int getClassConstRef(String[] instrElems, ConstantPoolGen cpg,
int line) {
if (instrElems.length < 2) {
parseException.addError(JAsmParseException.MISSING_ARGUMENTS,
instrElems[0], line);
return 0;
}
int arg;
try {
arg = Integer.parseInt(instrElems[1]);
} catch (NumberFormatException nfe) {
String classN = instrElems[1];
arg = cpg.addClass(classN);
}
return arg;
}
private int getFieldConstRef(String[] instrElems, ConstantPoolGen cpg,
int line) {
if (instrElems.length < 3) {
parseException.addError(JAsmParseException.MISSING_ARGUMENTS,
instrElems[0], line);
return 0;
}
int arg;
try {
arg = Integer.parseInt(instrElems[1]);
} catch (NumberFormatException nfe) {
String classN = getClassFromFieldName(instrElems[1]);
String fieldN = getFieldFromFieldName(instrElems[1]);
String descr = instrElems[2];
arg = cpg.addFieldref(classN, fieldN, descr);
}
return arg;
}
private int getMethodConstRef(String[] instrElems, ConstantPoolGen cpg,
int line) {
if (instrElems.length < 2) {
parseException.addError(JAsmParseException.MISSING_ARGUMENTS,
instrElems[0], line);
return 0;
}
int arg;
try {
arg = Integer.parseInt(instrElems[1]);
} catch (NumberFormatException nfe) {
String classN = getClassFromFullMethod(instrElems[1]);
String methodN = getMethodFromFullMethod(instrElems[1]);
String descr = getDescrFromFullMethod(instrElems[1]);
arg = cpg.addMethodref(classN, methodN, descr);
}
return arg;
}
public String getClassFromFullMethod(String fullMethod) {
String classAndMeth = fullMethod.substring(0, fullMethod.indexOf('('));
String className = getClassFromFieldName(classAndMeth);
return className;
}
public String getMethodFromFullMethod(String fullMethod) {
String classAndMeth = fullMethod.substring(0, fullMethod.indexOf('('));
String methName = getFieldFromFieldName(classAndMeth);
return methName;
}
public String getDescrFromFullMethod(String fullMethod) {
String description = fullMethod.substring(fullMethod.indexOf('('),
fullMethod.length());
return description;
}
public String getClassFromFieldName(String fieldName) {
String className = fieldName.substring(0, fieldName.lastIndexOf('/'));
return className.replace('/', '.');
}
public String getFieldFromFieldName(String fieldName) {
String field = fieldName.substring(fieldName.lastIndexOf('/') + 1,
fieldName.length());
return field;
}
class BranchPair {
int source, target;
BranchPair(int s, int t) {
source = s;
target = t;
}
}
class TempSwitchData {
int type; // 1 - table, 2 - lookup
int initialLab;
ArrayList<BranchPair> branchPairs = new ArrayList<BranchPair>();
private InstructionHandle ih;
public TempSwitchData(int type, int label) {
this.type = type;
initialLab = label;
}
public void setHandle(InstructionHandle ih) {
this.ih = ih;
}
public void incInitialLab() {
initialLab++;
}
public int getInitialLab() {
return initialLab;
}
public ArrayList<BranchPair> getBranchPairs() {
return branchPairs;
}
public TempSwitchData() {
}
public TempSwitchData(int type) {
this.type = type;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -