📄 javac.java
字号:
if (index < numOfLocalVars) gen.recordVariable(va.descriptor(i), va.variableName(i), index, stable); } return true; } /** * Makes variables $0 (this), $1, $2, ..., and $args represent method * parameters. $args represents an array of all the parameters. * It also makes $$ available as a parameter list of method call. * * <p>This must be called before calling <code>compileStmnt()</code> and * <code>compileExpr()</code>. The correct value of * <code>isStatic</code> must be recorded before compilation. * <code>maxLocals</code> is updated to include $0,... */ public int recordParams(CtClass[] params, boolean isStatic) throws CompileError { return gen.recordParams(params, isStatic, "$", "$args", "$$", stable); } /** * Makes variables $0, $1, $2, ..., and $args represent method * parameters. $args represents an array of all the parameters. * It also makes $$ available as a parameter list of method call. * $0 can represent a local variable other than THIS (variable 0). * $class is also made available. * * <p>This must be called before calling <code>compileStmnt()</code> and * <code>compileExpr()</code>. The correct value of * <code>isStatic</code> must be recorded before compilation. * <code>maxLocals</code> is updated to include $0,... * * @paaram use0 true if $0 is used. * @param varNo the register number of $0 (use0 is true) * or $1 (otherwise). * @param target the type of $0 (it can be null if use0 is false). * It is used as the name of the type represented * by $class. * @param isStatic true if the method in which the compiled bytecode * is embedded is static. */ public int recordParams(String target, CtClass[] params, boolean use0, int varNo, boolean isStatic) throws CompileError { return gen.recordParams(params, isStatic, "$", "$args", "$$", use0, varNo, target, stable); } /** * Sets <code>maxLocals</code> to <code>max</code>. * This method tells the compiler the local variables that have been * allocated for the rest of the code. When the compiler needs * new local variables, the local variables at the index <code>max</code>, * <code>max + 1</code>, ... are assigned. * * <p>This method is indirectly called by <code>recordParams</code>. */ public void setMaxLocals(int max) { gen.setMaxLocals(max); } /** * Prepares to use cast $r, $w, $_, and $type. * $type is made to represent the specified return type. * It also enables to write a return statement with a return value * for void method. * * <p>If the return type is void, ($r) does nothing. * The type of $_ is java.lang.Object. * * @param type the return type. * @param useResultVar true if $_ is used. * @return -1 or the variable index assigned to $_. * @see #recordType(CtClass) */ public int recordReturnType(CtClass type, boolean useResultVar) throws CompileError { gen.recordType(type); return gen.recordReturnType(type, "$r", (useResultVar ? resultVarName : null), stable); } /** * Prepares to use $type. Note that recordReturnType() overwrites * the value of $type. * * @param t the type represented by $type. */ public void recordType(CtClass t) { gen.recordType(t); } /** * Makes the given variable available. * * @param type variable type * @param name variable name */ public int recordVariable(CtClass type, String name) throws CompileError { return gen.recordVariable(type, name, stable); } /** * Prepares to use $proceed(). * If the return type of $proceed() is void, null is pushed on the * stack. * * @param target an expression specifying the target object. * if null, "this" is the target. * @param method the method name. */ public void recordProceed(String target, String method) throws CompileError { Parser p = new Parser(new Lex(target)); final ASTree texpr = p.parseExpression(stable); final String m = method; ProceedHandler h = new ProceedHandler() { public void doit(JvstCodeGen gen, Bytecode b, ASTList args) throws CompileError { ASTree expr = new Member(m); if (texpr != null) expr = Expr.make('.', texpr, expr); expr = CallExpr.makeCall(expr, args); gen.compileExpr(expr); gen.addNullIfVoid(); } public void setReturnType(JvstTypeChecker check, ASTList args) throws CompileError { ASTree expr = new Member(m); if (texpr != null) expr = Expr.make('.', texpr, expr); expr = CallExpr.makeCall(expr, args); expr.accept(check); check.addNullIfVoid(); } }; gen.setProceedHandler(h, proceedName); } /** * Prepares to use $proceed() representing a static method. * If the return type of $proceed() is void, null is pushed on the * stack. * * @param targetClass the fully-qualified dot-separated name * of the class declaring the method. * @param method the method name. */ public void recordStaticProceed(String targetClass, String method) throws CompileError { final String c = targetClass; final String m = method; ProceedHandler h = new ProceedHandler() { public void doit(JvstCodeGen gen, Bytecode b, ASTList args) throws CompileError { Expr expr = Expr.make(TokenId.MEMBER, new Symbol(c), new Member(m)); expr = CallExpr.makeCall(expr, args); gen.compileExpr(expr); gen.addNullIfVoid(); } public void setReturnType(JvstTypeChecker check, ASTList args) throws CompileError { Expr expr = Expr.make(TokenId.MEMBER, new Symbol(c), new Member(m)); expr = CallExpr.makeCall(expr, args); expr.accept(check); check.addNullIfVoid(); } }; gen.setProceedHandler(h, proceedName); } /** * Prepares to use $proceed() representing a private/super's method. * If the return type of $proceed() is void, null is pushed on the * stack. This method is for methods invoked by INVOKESPECIAL. * * @param target an expression specifying the target object. * if null, "this" is the target. * @param classname the class name declaring the method. * @param methodname the method name. * @param descriptor the method descriptor. */ public void recordSpecialProceed(String target, String classname, String methodname, String descriptor) throws CompileError { Parser p = new Parser(new Lex(target)); final ASTree texpr = p.parseExpression(stable); final String cname = classname; final String method = methodname; final String desc = descriptor; ProceedHandler h = new ProceedHandler() { public void doit(JvstCodeGen gen, Bytecode b, ASTList args) throws CompileError { gen.compileInvokeSpecial(texpr, cname, method, desc, args); } public void setReturnType(JvstTypeChecker c, ASTList args) throws CompileError { c.compileInvokeSpecial(texpr, cname, method, desc, args); } }; gen.setProceedHandler(h, proceedName); } /** * Prepares to use $proceed(). */ public void recordProceed(ProceedHandler h) { gen.setProceedHandler(h, proceedName); } /** * Compiles a statement (or a block). * <code>recordParams()</code> must be called before invoking * this method. * * <p>Local variables that are not declared * in the compiled source text might not be accessible within that * source text. Fields and method parameters ($0, $1, ..) are available. */ public void compileStmnt(String src) throws CompileError { Parser p = new Parser(new Lex(src)); SymbolTable stb = new SymbolTable(stable); while (p.hasMore()) { Stmnt s = p.parseStatement(stb); if (s != null) s.accept(gen); } } /** * Compiles an exression. <code>recordParams()</code> must be * called before invoking this method. * * <p>Local variables are not accessible * within the compiled source text. Fields and method parameters * ($0, $1, ..) are available if <code>recordParams()</code> * have been invoked. */ public void compileExpr(String src) throws CompileError { ASTree e = parseExpr(src, stable); compileExpr(e); } /** * Parsers an expression. */ public static ASTree parseExpr(String src, SymbolTable st) throws CompileError { Parser p = new Parser(new Lex(src)); return p.parseExpression(st); } /** * Compiles an exression. <code>recordParams()</code> must be * called before invoking this method. * * <p>Local variables are not accessible * within the compiled source text. Fields and method parameters * ($0, $1, ..) are available if <code>recordParams()</code> * have been invoked. */ public void compileExpr(ASTree e) throws CompileError { if (e != null) gen.compileExpr(e); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -