Browse Source

made javassist.expr.MethodCall#replace correctly work

with super's method calls.


git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@53 30ef5769-5b8d-40dd-aea6-55b5d6557bb3
tags/rel_3_17_1_ga
chiba 21 years ago
parent
commit
2799b5c40f

+ 33
- 0
src/main/javassist/compiler/Javac.java View File

gen.setProceedHandler(h, proceedName); 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);
}
};

gen.setProceedHandler(h, proceedName);
}

/** /**
* Prepares to use $proceed(). * Prepares to use $proceed().
*/ */

+ 19
- 3
src/main/javassist/compiler/JvstCodeGen.java View File

} }


/* /*
public int atMethodArgsLength(ASTList args) {
public int getMethodArgsLength(ASTList args) {
if (!isParamListName(args)) if (!isParamListName(args))
return super.atMethodArgsLength(args);
return super.getMethodArgsLength(args);


return paramTypeList.length; return paramTypeList.length;
} }
*/ */


public int atMethodArgsLength(ASTList args) {
public int getMethodArgsLength(ASTList args) {
String pname = paramListName; String pname = paramListName;
int n = 0; int n = 0;
while (args != null) { while (args != null) {
} }
*/ */


/* called by Javac#recordSpecialProceed().
*/
void compileInvokeSpecial(ASTree target, String classname,
String methodname, String descriptor,
ASTList args)
throws CompileError
{
target.accept(this);
int nargs = getMethodArgsLength(args);
atMethodArgs(args, new int[nargs], new int[nargs],
new String[nargs]);
bytecode.addInvokespecial(classname, methodname, descriptor);
setReturnType(descriptor, false, false);
addNullIfVoid();
}

/* /*
* Makes it valid to write "return <expr>;" for a void method. * Makes it valid to write "return <expr>;" for a void method.
*/ */

+ 3
- 4
src/main/javassist/compiler/MemberCodeGen.java View File

int aload0pos) int aload0pos)
throws CompileError throws CompileError
{ {
int nargs = atMethodArgsLength(args);
int nargs = getMethodArgsLength(args);
int[] types = new int[nargs]; int[] types = new int[nargs];
int[] dims = new int[nargs]; int[] dims = new int[nargs];
String[] cnames = new String[nargs]; String[] cnames = new String[nargs];
setReturnType(desc, isStatic, popTarget); setReturnType(desc, isStatic, popTarget);
} }


public int atMethodArgsLength(ASTList args) {
public int getMethodArgsLength(ASTList args) {
return ASTList.length(args); return ASTList.length(args);
} }


} }
} }


private void setReturnType(String desc, boolean isStatic,
boolean popTarget)
void setReturnType(String desc, boolean isStatic, boolean popTarget)
throws CompileError throws CompileError
{ {
int i = desc.indexOf(')'); int i = desc.indexOf(')');

+ 1
- 1
src/main/javassist/expr/Cast.java View File

public void doit(JvstCodeGen gen, Bytecode bytecode, ASTList args) public void doit(JvstCodeGen gen, Bytecode bytecode, ASTList args)
throws CompileError throws CompileError
{ {
if (gen.atMethodArgsLength(args) != 1)
if (gen.getMethodArgsLength(args) != 1)
throw new CompileError(Javac.proceedName throw new CompileError(Javac.proceedName
+ "() cannot take more than one parameter " + "() cannot take more than one parameter "
+ "for cast"); + "for cast");

+ 1
- 1
src/main/javassist/expr/FieldAccess.java View File

public void doit(JvstCodeGen gen, Bytecode bytecode, ASTList args) public void doit(JvstCodeGen gen, Bytecode bytecode, ASTList args)
throws CompileError throws CompileError
{ {
if (gen.atMethodArgsLength(args) != 1)
if (gen.getMethodArgsLength(args) != 1)
throw new CompileError(Javac.proceedName throw new CompileError(Javac.proceedName
+ "() cannot take more than one parameter " + "() cannot take more than one parameter "
+ "for field writing"); + "for field writing");

+ 1
- 1
src/main/javassist/expr/Instanceof.java View File

public void doit(JvstCodeGen gen, Bytecode bytecode, ASTList args) public void doit(JvstCodeGen gen, Bytecode bytecode, ASTList args)
throws CompileError throws CompileError
{ {
if (gen.atMethodArgsLength(args) != 1)
if (gen.getMethodArgsLength(args) != 1)
throw new CompileError(Javac.proceedName throw new CompileError(Javac.proceedName
+ "() cannot take more than one parameter " + "() cannot take more than one parameter "
+ "for instanceof"); + "for instanceof");

+ 3
- 0
src/main/javassist/expr/MethodCall.java View File

int retVar = jc.recordReturnType(retType, true); int retVar = jc.recordReturnType(retType, true);
if (c == INVOKESTATIC) if (c == INVOKESTATIC)
jc.recordStaticProceed(classname, methodname); jc.recordStaticProceed(classname, methodname);
else if (c == INVOKESPECIAL)
jc.recordSpecialProceed(Javac.param0Name, classname,
methodname, signature);
else else
jc.recordProceed(Javac.param0Name, methodname); jc.recordProceed(Javac.param0Name, methodname);



Loading…
Cancel
Save