📄 block.java
字号:
function.cl.popDepth(); function.println("}"); Block old = pop(); if (! old.canExit) old.isDead = true; return old; } Block startSwitch(Expr test) throws ESException { ESId id = ESId.intern("_switchtemp"); function.print("_switchtemp = "); function.addExpr(test); function.println(";"); Block block = create(); block.switchTop = function.getSwitch(); block.isLoop = true; block.hasDefault = false; function.println("switch (_switchcode) {"); return block; } void doCase(int i) throws ESException { isDead = false; evalExpr(); function.println("case " + i + ":"); } void doDefault() throws ESException { isDead = false; hasDefault = true; evalExpr(); function.println("default:"); } Block fillSwitch(ArrayList exprs) throws ESException { evalExpr(); if (! hasDefault && ! isDead) { function.println("default:"); function.println(" break;"); } else if (! isDead) function.println("break;"); function.println("}"); int mark = function.mark(); for (int i = 0; i < exprs.size(); i++) { if (i != 0) function.print("else "); Expr test = (Expr) exprs.get(i); function.print("if (_switchtemp.equals("); function.addExpr(test); function.println(")) _switchcode = " + i + ";"); } if (exprs.size() > 0) function.print("else "); function.println("_switchcode = -1;"); function.moveChunk(switchTop, mark); Block old = pop(); if (isDead && ! canExit && hasDefault) old.isDead = true; return old; } void doBreak(ESId id) throws ESException { Block block = this; for (; block != null; block = block.parent) { if (block.id == id) { block.canExit = true; break; } } if (block == null) throw error("break needs enclosing loop"); function.setVars(); evalExpr(); function.println("break " + id + ";"); isDead = true; } void doBreak() throws ESException { Block block = this; for (; block != null; block = block.parent) { if (block.isLoop) { block.canExit = true; break; } } if (block == null) throw error("break needs enclosing loop"); function.setVars(); evalExpr(); function.println("break;"); isDead = true; } void doContinue(ESId id) throws ESException { Block block = this; for (; block != null; block = block.parent) { if (block.id == id && block.isLoop) break; /* else block.canExit = true; */ } if (block == null) throw error("continue needs enclosing loop"); function.setVars(); evalExpr(); function.println("continue " + id + ";"); isDead = true; } void doContinue() throws ESException { if (findBlock(null) == null) throw error("continue needs enclosing loop"); function.setVars(); evalExpr(); function.println("continue;"); isDead = true; } private Block findBlock(ESId id) { for (Block block = this; block != null; block = block.parent) { if (id != null && block.id == id) return block; else if (id == null && block.isLoop) return block; } return null; } Block startWith(Expr expr) throws ESException { function.setArguments(); function.setUseAllVariables(); evalExpr(); withDepth++; function.println("try {"); function.print("_env.pushScope("); function.addExpr(expr); function.println(");"); setTop(); return this; } Block endWith() throws ESException { evalExpr(); withDepth--; function.println("} finally {"); function.println("_env.popScope();"); function.println("}"); return this; } int getWithDepth() { return withDepth; } Block startTry() throws ESException { function.setVars(); evalExpr(); function.println("try {"); return this; } Block endTry() throws ESException { function.setVars(); evalExpr(); function.println("}"); return this; } void doTry() throws ESException { evalExpr(); int i = 0; for (; i < function.data.size(); i++) { Object o = function.data.get(i); if (o != top) { } else if (o instanceof CharBuffer) { CharBuffer cb = (CharBuffer) o; cb.insert(topMark, " try {\n"); break; } else { function.data.add(i + 1, new CharBuffer(" try {\n")); break; } } if (i < function.data.size()) { } else if (function.tail != null && top == function.tail) function.tail.insert(topMark, " try {\n"); else function.data.add(0, new CharBuffer(" try {\n")); function.println("}"); } Block startCatch(String exn, Expr var) throws ESException { evalExpr(); String temp = "_e" + function.getTemp(); function.println("catch (" + exn + " " + temp + ") {"); if (var != null) { Expr expr = new SpecialExpr(this, SpecialExpr.EXCEPTION, temp); var.assign(expr).exprStatement(function); } isDead = false; setTop(); return this; } Block endCatch() throws ESException { evalExpr(); function.println("}"); return this; } Block startFinally() throws ESException { evalExpr(); Block block = create(); function.println("finally {"); function.pushStatementLoop(); block.setTop(); return block; } Block endFinally() throws ESException { evalExpr(); function.println("}"); function.popStatementLoop(); return pop(); } Block startSynchronized(Expr expr) throws ESException { evalExpr(); function.print("synchronized ("); function.addExpr(expr); function.println(".toJavaObject()) {"); return create(); } Block endSynchronized() throws ESException { evalExpr(); function.println("}"); Block old = pop(); old.isDead = isDead; return old; } void doThrow(Expr expr) throws ESException { function.print("throw (Exception)"); function.addExpr(expr); function.println(".toJavaObject();"); isDead = true; } void doReturn(Expr value) throws ESException { evalExpr(); function.print("return "); value.setUsed(); if (function.getReturnType() != null) function.addExpr(new TopExpr(this, value, function.getReturnType())); else function.addExpr(value); function.println(";"); isDead = true; /* can't break for (Block block = this; block != null; block = block.parent) block.canExit = true; */ } void doReturn() throws ESException { evalExpr(); if (function.getReturnType() != null) function.print("return 0;"); else function.print("return ESBase.esUndefined;"); isDead = true; /* for (Block block = this; block != null; block = block.parent) block.canExit = true; */ } void finish() throws ESException { if (isDead) return; if (lastExpr != null) { function.print("return "); function.addExpr(lastExpr); function.println(";"); lastExpr = null; } else if (hasStatementValue) function.println("return _val0;"); else function.println("return ESBase.esUndefined;"); } String newIterator(ESId id, Expr expr) throws ESException { evalExpr(); String iter = "iter" + function.getIter(); function.print(iter + " = "); function.addExpr(expr); function.println(".keys();"); return iter; } void evalExpr() throws ESException { if (lastExpr == null) return; function.print(function.getStatementVar() + " = "); function.addExpr(lastExpr); function.println(";"); lastExpr = null; } private static Block allocate() { Block block = new Block(); return block; } ESException error(String message) { return parser.lexer.error(message); } void free() { } static { specialNames = new HashMap(); specialNames.put(ESId.intern("Object"), "Object"); specialNames.put(ESId.intern("Date"), "Date"); specialNames.put(ESId.intern("String"), "String"); specialNames.put(ESId.intern("Number"), "Number"); specialNames.put(ESId.intern("Array"), "Array"); specialNames.put(ESId.intern("Boolean"), "Boolean"); specialNames.put(ESId.intern("Math"), "Math"); };}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -