📄 javacclassgenerator.java
字号:
//
// public void visitIfElse(IfStatement ifElse) {
// onLineNumber(ifElse);
//
// ifElse.getBooleanExpression().visit(this);
//
// Label l0 = new Label();
// cv.visitJumpInsn(IFEQ, l0);
// ifElse.getIfBlock().visit(this);
//
// Label l1 = new Label();
// cv.visitJumpInsn(GOTO, l1);
// cv.visitLabel(l0);
//
// ifElse.getElseBlock().visit(this);
// cv.visitLabel(l1);
// }
//
// public void visitTernaryExpression(TernaryExpression expression) {
// onLineNumber(expression);
//
// expression.getBooleanExpression().visit(this);
//
// Label l0 = new Label();
// cv.visitJumpInsn(IFEQ, l0);
// expression.getTrueExpression().visit(this);
//
// Label l1 = new Label();
// cv.visitJumpInsn(GOTO, l1);
// cv.visitLabel(l0);
//
// expression.getFalseExpression().visit(this);
// cv.visitLabel(l1);
// }
//
// public void visitAssertStatement(AssertStatement statement) {
// onLineNumber(statement);
//
// //System.out.println("Assert: " + statement.getLineNumber() + " for: "
// // + statement.getText());
//
// BooleanExpression booleanExpression = statement.getBooleanExpression();
// booleanExpression.visit(this);
//
// Label l0 = new Label();
// cv.visitJumpInsn(IFEQ, l0);
//
// // do nothing
//
// Label l1 = new Label();
// cv.visitJumpInsn(GOTO, l1);
// cv.visitLabel(l0);
//
// // push expression string onto stack
// String expressionText = booleanExpression.getText();
// List list = new ArrayList();
// addVariableNames(booleanExpression, list);
// if (list.isEmpty()) {
// cv.visitLdcInsn(expressionText);
// }
// else {
// boolean first = true;
//
// // lets create a new expression
// cv.visitTypeInsn(NEW, "java/lang/StringBuffer");
// cv.visitInsn(DUP);
// cv.visitLdcInsn(expressionText + ". Values: ");
//
// cv.visitMethodInsn(INVOKESPECIAL, "java/lang/StringBuffer", "<init>", "(Ljava/lang/String;)V");
//
// int tempIndex = defineVariable(createVariableName("assert"), "java.lang.Object", false).getIndex();
//
// cv.visitVarInsn(ASTORE, tempIndex);
//
// for (Iterator iter = list.iterator(); iter.hasNext();) {
// String name = (String) iter.next();
// String text = name + " = ";
// if (first) {
// first = false;
// }
// else {
// text = ", " + text;
// }
//
// cv.visitVarInsn(ALOAD, tempIndex);
// cv.visitLdcInsn(text);
// cv.visitMethodInsn(
// INVOKEVIRTUAL,
// "java/lang/StringBuffer",
// "append",
// "(Ljava/lang/String;)Ljava/lang/StringBuffer;");
// cv.visitInsn(POP);
//
// cv.visitVarInsn(ALOAD, tempIndex);
// new VariableExpression(name).visit(this);
// cv.visitMethodInsn(
// INVOKEVIRTUAL,
// "java/lang/StringBuffer",
// "append",
// "(Ljava/lang/Object;)Ljava/lang/StringBuffer;");
// cv.visitInsn(POP);
//
// }
// cv.visitVarInsn(ALOAD, tempIndex);
// }
//
// // now the optional exception expression
// statement.getMessageExpression().visit(this);
//
// assertFailedMethod.call(cv);
// cv.visitLabel(l1);
// }
//
// public void visitTryCatchFinally(TryCatchStatement statement) {
// onLineNumber(statement);
//
// CatchStatement catchStatement = statement.getCatchStatement(0);
//
// Statement tryStatement = statement.getTryStatement();
//
// if (tryStatement.isEmpty() || catchStatement == null) {
// final Label l0 = new Label();
// cv.visitLabel(l0);
//
// tryStatement.visit(this);
//
// int index1 = defineVariable(this.createVariableName("exception"), "java.lang.Object").getIndex();
// int index2 = defineVariable(this.createVariableName("exception"), "java.lang.Object").getIndex();
//
// final Label l1 = new Label();
// cv.visitJumpInsn(JSR, l1);
// final Label l2 = new Label();
// cv.visitLabel(l2);
// final Label l3 = new Label();
// cv.visitJumpInsn(GOTO, l3);
// final Label l4 = new Label();
// cv.visitLabel(l4);
// cv.visitVarInsn(ASTORE, index1);
// cv.visitJumpInsn(JSR, l1);
// final Label l5 = new Label();
// cv.visitLabel(l5);
// cv.visitVarInsn(ALOAD, index1);
// cv.visitInsn(ATHROW);
// cv.visitLabel(l1);
// cv.visitVarInsn(ASTORE, index2);
//
// statement.getFinallyStatement().visit(this);
//
// cv.visitVarInsn(RET, index2);
// cv.visitLabel(l3);
//
// exceptionBlocks.add(new Runnable() {
// public void run() {
// cv.visitTryCatchBlock(l0, l2, l4, null);
// cv.visitTryCatchBlock(l4, l5, l4, null);
// }
// });
//
// }
// else {
// String exceptionVar = catchStatement.getVariable();
// String exceptionType =
// checkValidType(catchStatement.getExceptionType(), catchStatement, "in catch statement");
//
// int exceptionIndex = defineVariable(exceptionVar, exceptionType, false).getIndex();
// int index2 = defineVariable(this.createVariableName("exception"), "java.lang.Object").getIndex();
// int index3 = defineVariable(this.createVariableName("exception"), "java.lang.Object").getIndex();
//
// final Label l0 = new Label();
// cv.visitLabel(l0);
//
// tryStatement.visit(this);
//
// final Label l1 = new Label();
// cv.visitLabel(l1);
// Label l2 = new Label();
// cv.visitJumpInsn(JSR, l2);
// final Label l3 = new Label();
// cv.visitLabel(l3);
// Label l4 = new Label();
// cv.visitJumpInsn(GOTO, l4);
// final Label l5 = new Label();
// cv.visitLabel(l5);
//
// cv.visitVarInsn(ASTORE, exceptionIndex);
//
// if (catchStatement != null) {
// catchStatement.visit(this);
// }
//
// cv.visitJumpInsn(JSR, l2);
// final Label l6 = new Label();
// cv.visitLabel(l6);
// cv.visitJumpInsn(GOTO, l4);
//
// final Label l7 = new Label();
// cv.visitLabel(l7);
// cv.visitVarInsn(ASTORE, index2);
// cv.visitJumpInsn(JSR, l2);
//
// final Label l8 = new Label();
// cv.visitLabel(l8);
// cv.visitVarInsn(ALOAD, index2);
// cv.visitInsn(ATHROW);
// cv.visitLabel(l2);
// cv.visitVarInsn(ASTORE, index3);
//
// statement.getFinallyStatement().visit(this);
//
// cv.visitVarInsn(RET, index3);
// cv.visitLabel(l4);
//
// // rest of code goes here...
//
// //final String exceptionTypeInternalName = (catchStatement !=
// // null) ?
// // getTypeDescription(exceptionType) : null;
// final String exceptionTypeInternalName =
// (catchStatement != null) ? BytecodeHelper.getClassInternalName(exceptionType) : null;
//
// exceptionBlocks.add(new Runnable() {
// public void run() {
// cv.visitTryCatchBlock(l0, l1, l5, exceptionTypeInternalName);
// cv.visitTryCatchBlock(l0, l3, l7, null);
// cv.visitTryCatchBlock(l5, l6, l7, null);
// cv.visitTryCatchBlock(l7, l8, l7, null);
// }
// });
// }
// }
//
// public void visitSwitch(SwitchStatement statement) {
// onLineNumber(statement);
//
// statement.getExpression().visit(this);
//
// pushBlockScope();
//
// int switchVariableIndex = defineVariable(createVariableName("switch"), "java.lang.Object").getIndex();
// cv.visitVarInsn(ASTORE, switchVariableIndex);
//
// List caseStatements = statement.getCaseStatements();
// int caseCount = caseStatements.size();
// Label[] labels = new Label[caseCount + 1];
// for (int i = 0; i < caseCount; i++) {
// labels[i] = new Label();
// }
//
// int i = 0;
// for (Iterator iter = caseStatements.iterator(); iter.hasNext(); i++) {
// CaseStatement caseStatement = (CaseStatement) iter.next();
// visitCaseStatement(caseStatement, switchVariableIndex, labels[i], labels[i + 1]);
// }
//
// statement.getDefaultStatement().visit(this);
//
// cv.visitLabel(scope.getBreakLabel());
//
// popScope();
// }
//
// public void visitCaseStatement(CaseStatement statement) {
// }
//
// public void visitCaseStatement(
// CaseStatement statement,
// int switchVariableIndex,
// Label thisLabel,
// Label nextLabel) {
//
// onLineNumber(statement);
//
// cv.visitVarInsn(ALOAD, switchVariableIndex);
// statement.getExpression().visit(this);
//
// isCaseMethod.call(cv);
//
// Label l0 = new Label();
// cv.visitJumpInsn(IFEQ, l0);
//
// cv.visitLabel(thisLabel);
//
// statement.getCode().visit(this);
//
// // now if we don't finish with a break we need to jump past
// // the next comparison
// if (nextLabel != null) {
// cv.visitJumpInsn(GOTO, nextLabel);
// }
//
// cv.visitLabel(l0);
// }
//
// public void visitBreakStatement(BreakStatement statement) {
// onLineNumber(statement);
//
// cv.visitJumpInsn(GOTO, scope.getBreakLabel());
// }
//
// public void visitContinueStatement(ContinueStatement statement) {
// onLineNumber(statement);
//
// cv.visitJumpInsn(GOTO, scope.getContinueLabel());
// }
//
// public void visitSynchronizedStatement(SynchronizedStatement statement) {
// onLineNumber(statement);
//
// statement.getExpression().visit(this);
//
// int index = defineVariable(createVariableName("synchronized"), "java.lang.Integer").getIndex();
//
// cv.visitVarInsn(ASTORE, index);
// cv.visitInsn(MONITORENTER);
// final Label l0 = new Label();
// cv.visitLabel(l0);
//
// statement.getCode().visit(this);
//
// cv.visitVarInsn(ALOAD, index);
// cv.visitInsn(MONITOREXIT);
// final Label l1 = new Label();
// cv.visitJumpInsn(GOTO, l1);
// final Label l2 = new Label();
// cv.visitLabel(l2);
// cv.visitVarInsn(ALOAD, index);
// cv.visitInsn(MONITOREXIT);
// cv.visitInsn(ATHROW);
// cv.visitLabel(l1);
//
// exceptionBlocks.add(new Runnable() {
// public void run() {
// cv.visitTryCatchBlock(l0, l2, l2, null);
// }
// });
// }
//
// public void visitThrowStatement(ThrowStatement statement) {
// statement.getExpression().visit(this);
//
// // we should infer the type of the exception from the expression
// cv.visitTypeInsn(CHECKCAST, "java/lang/Throwable");
//
// cv.visitInsn(ATHROW);
// }
//
// public void visitReturnStatement(ReturnStatement statement) {
// onLineNumber(statement);
//
// Expression expression = statement.getExpression();
// evaluateExpression(expression);
//
// //return is based on class type
// //TODO: make work with arrays
// // we may need to cast
// String returnType = methodNode.getReturnType();
// helper.unbox(returnType);
// if (returnType.equals("double")) {
// cv.visitInsn(DRETURN);
// }
// else if (returnType.equals("float")) {
// cv.visitInsn(FRETURN);
// }
// else if (returnType.equals("long")) {
// cv.visitInsn(LRETURN);
// }
// else if (returnType.equals("boolean")) {
// cv.visitInsn(IRETURN);
// }
// else if (
// returnType.equals("char")
// || returnType.equals("byte")
// || returnType.equals("int")
// || returnType.equals("short")) { //byte,short,boolean,int are
// // all IRETURN
// cv.visitInsn(IRETURN);
// }
// else {
// doConvertAndCast(returnType, expression);
// cv.visitInsn(ARETURN);
//
// /*
// if (c == Boolean.class) {
// Label l0 = new Label();
// cv.visitJumpInsn(IFEQ, l0);
// cv.visitFieldInsn(GETSTATIC, "java/lang/Boolean", "TRUE", "Ljava/lang/Boolean;");
// cv.visitInsn(ARETURN);
// cv.visitLabel(l0);
// cv.visitFieldInsn(GETSTATIC, "java/lang/Boolean", "FALSE", "Ljava/lang/Boolean;");
// cv.visitInsn(ARETURN);
// }
// else {
// if (isValidTypeForCast(returnType) && !returnType.equals(c.getName())) {
// doConvertAndCast(returnType, expression);
// }
// cv.visitInsn(ARETURN);
// }
// */
// }
//
// outputReturn = true;
// }
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -