diff options
author | chiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3> | 2004-01-11 17:41:50 +0000 |
---|---|---|
committer | chiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3> | 2004-01-11 17:41:50 +0000 |
commit | 100b440ac93f02f249a1e9492fcac5372ebe397a (patch) | |
tree | 24462bf01c1891a41787876e0a44f4bddc21f04b /src/main/javassist/compiler/Javac.java | |
parent | bd4705d214608f17b3c33339fb2399347b2f8c82 (diff) | |
download | javassist-100b440ac93f02f249a1e9492fcac5372ebe397a.tar.gz javassist-100b440ac93f02f249a1e9492fcac5372ebe397a.zip |
local variables were made available in the source text passed
to insertBefore() etc.
git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@68 30ef5769-5b8d-40dd-aea6-55b5d6557bb3
Diffstat (limited to 'src/main/javassist/compiler/Javac.java')
-rw-r--r-- | src/main/javassist/compiler/Javac.java | 72 |
1 files changed, 67 insertions, 5 deletions
diff --git a/src/main/javassist/compiler/Javac.java b/src/main/javassist/compiler/Javac.java index 4f83bda8..5e20e7e8 100644 --- a/src/main/javassist/compiler/Javac.java +++ b/src/main/javassist/compiler/Javac.java @@ -25,6 +25,8 @@ import javassist.CtConstructor; import javassist.CannotCompileException; import javassist.Modifier; import javassist.bytecode.Bytecode; +import javassist.bytecode.CodeAttribute; +import javassist.bytecode.LocalVariableAttribute; import javassist.bytecode.Opcode; import javassist.NotFoundException; @@ -242,6 +244,66 @@ public class Javac { } /** + * Records local variables available at the specified program counter. + * If the LocalVariableAttribute is not available, this method does not + * record any local variable. It only returns false. + * + * @param pc program counter (>= 0) + * @return false if the CodeAttribute does not include a + * LocalVariableAttribute. + */ + public boolean recordLocalVariables(CodeAttribute ca, int pc) + throws CompileError + { + LocalVariableAttribute va + = (LocalVariableAttribute) + ca.getAttribute(LocalVariableAttribute.tag); + if (va == null) + return false; + + int n = va.tableLength(); + for (int i = 0; i < n; ++i) { + int start = va.startPc(i); + int len = va.codeLength(i); + if (start <= pc && pc < start + len) + gen.recordVariable(va.descriptor(i), va.variableName(i), + va.index(i), stable); + } + + return true; + } + + /** + * Records parameter names if the LocalVariableAttribute is available. + * It returns false unless the LocalVariableAttribute is available. + * + * @param numOfLocalVars the number of local variables used + * for storing the parameters. + * @return false if the CodeAttribute does not include a + * LocalVariableAttribute. + */ + public boolean recordParamNames(CodeAttribute ca, int numOfLocalVars) + throws CompileError + { + LocalVariableAttribute va + = (LocalVariableAttribute) + ca.getAttribute(LocalVariableAttribute.tag); + if (va == null) + return false; + + int n = va.tableLength(); + for (int i = 0; i < n; ++i) { + int index = va.index(i); + 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. @@ -250,10 +312,10 @@ public class Javac { * <code>compileExpr()</code>. The correct value of * <code>isStatic</code> must be recorded before compilation. */ - public void recordParams(CtClass[] params, boolean isStatic) + public int recordParams(CtClass[] params, boolean isStatic) throws CompileError { - gen.recordParams(params, isStatic, "$", "$args", "$$", stable); + return gen.recordParams(params, isStatic, "$", "$args", "$$", stable); } /** @@ -273,12 +335,12 @@ public class Javac { * @param isStatic true if the method in which the compiled bytecode * is embedded is static. */ - public void recordParams(String target, CtClass[] params, + public int recordParams(String target, CtClass[] params, boolean use0, int varNo, boolean isStatic) throws CompileError { - gen.recordParams(params, isStatic, "$", "$args", "$$", - use0, varNo, target, stable); + return gen.recordParams(params, isStatic, "$", "$args", "$$", + use0, varNo, target, stable); } /** |