Node[] nodes1,
MethodStatement callback,
Node[] nodes2,
boolean castToBoolean)
{
ClassRoom clazz = context.getClassRoom();
Code code = method.getCode();
ConstantPool pool = code.getPool();
int sig_equals = pool.addMethodRef("java/lang/String", "equals", "(Ljava/lang/Object;)Z");
int sig_toBoolean = pool.addMethodRef("anvil/core/Any", "toBoolean", "()Z");
context.pushCode(code);
int l_context = code.addLocal();
int l_attr = code.addLocal();
int l_value = 0;
if (hasValue) {
l_value = code.addLocal();
}
if (methods != null) {
int n = methods.length;
if (n>3) {
code.aload(l_attr);
code.invokevirtual(pool.addMethodRef("java/lang/String", "hashCode", "()I"));
Source notfound = code.getSource();
Switch select = code.select();
for(int i=0; i<n; i++) {
select.addCase(methods[i].getName().substring(prefixLength).hashCode());
}
select.end();
Iterator iter = select.getCases();
while(iter.hasNext()) {
Switch.Case kase = (Switch.Case)iter.next();
kase.bind();
for(int i=0; i<n; i++) {
MethodStatement target = methods[i];
String name = target.getName().substring(prefixLength);
if (name.hashCode() == kase.getKey()) {
code.aload(l_attr);
code.astring(name);
code.invokevirtual(sig_equals);
Source isfalse = code.if_eq();
code.self();
context.compileArgumentList(target, nodes1, l_context);
code.invokevirtual(target.getTypeRef(pool));
if (castToBoolean) {
code.invokevirtual(sig_toBoolean);
code.ireturn();
} else {
code.areturn();
}
isfalse.bind();
}
}
code.go_to(notfound);
}
select.bindDefault();
notfound.bind();
} else {
for(int i=0; i<n; i++) {
MethodStatement target = methods[i];
code.aload(l_attr);
code.astring(target.getName().substring(prefixLength));
code.invokevirtual(sig_equals);
Source isfalse = code.if_eq();
code.self();
context.compileArgumentList(target, nodes1, l_context);
code.invokevirtual(target.getTypeRef(pool));
if (castToBoolean) {
code.invokevirtual(sig_toBoolean);
code.ireturn();
} else {
code.areturn();
}
isfalse.bind();
}
}
}
if (callback != null) {
code.self();
context.compileArgumentList(callback, nodes2, l_context);
code.invokevirtual(callback.getTypeRef(pool));
if (castToBoolean) {
code.invokevirtual(sig_toBoolean);
code.ireturn();
} else {
code.areturn();
}
} else {
code.self();
code.aload(l_context);
code.aload(l_attr);
if (hasValue) {
code.aload(l_value);
}
code.invokespecial(pool.addMethodRef(clazz.getSuperClassIndex(),
method.getName(), method.getDescriptor()));
if (castToBoolean) {
code.ireturn();
} else {
code.areturn();