From 13ecd1542cc38d7a4699006ad9d7471fa224be0b Mon Sep 17 00:00:00 2001 From: chiba Date: Wed, 2 Mar 2005 03:42:10 +0000 Subject: fixed a bug of CtBehavior.insertAt (and a few other minor fixes) git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@162 30ef5769-5b8d-40dd-aea6-55b5d6557bb3 --- src/main/javassist/CtBehavior.java | 7 +++---- src/main/javassist/compiler/Javac.java | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) (limited to 'src/main') diff --git a/src/main/javassist/CtBehavior.java b/src/main/javassist/CtBehavior.java index 92759e6f..7bde7ae6 100644 --- a/src/main/javassist/CtBehavior.java +++ b/src/main/javassist/CtBehavior.java @@ -799,10 +799,12 @@ public abstract class CtBehavior extends CtMember { jv.recordLocalVariables(ca, index); jv.recordParams(getParameterTypes(), Modifier.isStatic(getModifiers())); + jv.setMaxLocals(ca.getMaxLocals()); jv.compileStmnt(src); Bytecode b = jv.getBytecode(); - int stack = b.getMaxStack(); int locals = b.getMaxLocals(); + int stack = b.getMaxStack(); + ca.setMaxLocals(locals); /* We assume that there is no values in the operand stack * at the position where the bytecode is inserted. @@ -810,9 +812,6 @@ public abstract class CtBehavior extends CtMember { if (stack > ca.getMaxStack()) ca.setMaxStack(stack); - if (locals > ca.getMaxLocals()) - ca.setMaxLocals(locals); - iterator.insert(index, b.get()); iterator.insert(b.getExceptionTable(), index); return lineNum; diff --git a/src/main/javassist/compiler/Javac.java b/src/main/javassist/compiler/Javac.java index abeb8290..88ed0ab5 100644 --- a/src/main/javassist/compiler/Javac.java +++ b/src/main/javassist/compiler/Javac.java @@ -201,6 +201,10 @@ public class Javac { Parser p = new Parser(new Lex(src)); SymbolTable stb = new SymbolTable(stable); Stmnt s = p.parseStatement(stb); + if (p.hasMore()) + throw new CompileError( + "the method/constructor body must be surrounded by {}"); + boolean callSuper = false; if (method instanceof CtConstructor) callSuper = !((CtConstructor)method).isClassInitializer(); @@ -311,6 +315,7 @@ public class Javac { *

This must be called before calling compileStmnt() and * compileExpr(). The correct value of * isStatic must be recorded before compilation. + * maxLocals is updated to include $0,... */ public int recordParams(CtClass[] params, boolean isStatic) throws CompileError @@ -328,6 +333,7 @@ public class Javac { *

This must be called before calling compileStmnt() and * compileExpr(). The correct value of * isStatic must be recorded before compilation. + * maxLocals is updated to include $0,... * * @paaram use0 true if $0 is used. * @param varNo the register number of $0 (use0 is true) @@ -346,6 +352,19 @@ public class Javac { use0, varNo, target, stable); } + /** + * Sets maxLocals to max. + * 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 max, + * max + 1, ... are assigned. + * + *

This method is indirectly called by recordParams. + */ + 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. -- cgit v1.2.3