01: /*
02: * $Id: StaticInvokeNode.java,v 1.19 2002/09/16 08:05:05 jkl Exp $
03: *
04: * Copyright (c) 2002 Njet Communications Ltd. All Rights Reserved.
05: *
06: * Use is subject to license terms, as defined in
07: * Anvil Sofware License, Version 1.1. See LICENSE
08: * file, or http://njet.org/license-1.1.txt
09: */
10: package anvil.script.expression;
11:
12: import anvil.core.Any;
13: import anvil.core.AnyClass;
14: import anvil.core.Register;
15: import anvil.ErrorListener;
16: import anvil.script.ClassType;
17: import anvil.codec.Code;
18: import anvil.codec.ConstantPool;
19: import anvil.script.compiler.ByteCompiler;
20: import anvil.script.Context;
21: import anvil.script.Type;
22: import anvil.script.MethodType;
23: import java.io.IOException;
24:
25: /**
26: * class StaticInvokeNode
27: *
28: * @author: Jani Lehtimäki
29: */
30: public class StaticInvokeNode extends MultiParent {
31:
32: private ClassType _target;
33: private ClassType _context;
34: private MethodType _method;
35:
36: public StaticInvokeNode(ClassType target, ClassType context,
37: MethodType method, Parent parameters) {
38: super (parameters);
39: _target = target;
40: _context = context;
41: _method = method;
42: }
43:
44: public int typeOf() {
45: return Node.EXPR_INVOKE;
46: }
47:
48: public boolean isConstant() {
49: return false;
50: }
51:
52: private static final String[] SIGNATURES = {
53: "(Lanvil/script/Context;I)Lanvil/core/Any;",
54: "(Lanvil/script/Context;ILanvil/core/Any;)Lanvil/core/Any;",
55: "(Lanvil/script/Context;ILanvil/core/Any;Lanvil/core/Any;)Lanvil/core/Any;",
56: "(Lanvil/script/Context;ILanvil/core/Any;Lanvil/core/Any;Lanvil/core/Any;)Lanvil/core/Any;",
57: "(Lanvil/script/Context;ILanvil/core/Any;Lanvil/core/Any;Lanvil/core/Any;Lanvil/core/Any;)Lanvil/core/Any;" };
58:
59: public void compile(ByteCompiler context, int operation) {
60: Code code = context.getCode();
61: ConstantPool pool = code.getPool();
62: context.accessInstance(_context, _target);
63: code.aload_first();
64: context.symbol(_method.getName());
65: int n = childs();
66: if (!hasSplices() && n <= 4) {
67: for (int i = 0; i < n; i++) {
68: getChild(i).compile(context, GET);
69: }
70: code.invokevirtual(pool.addMethodRef("anvil/core/AnyClass",
71: "_invoke", SIGNATURES[n]));
72: } else {
73: context.compileArgumentList(getChilds(0));
74: code
75: .invokevirtual(pool
76: .addMethodRef("anvil/core/AnyClass",
77: "_invoke",
78: "(Lanvil/script/Context;I[Lanvil/core/Any;)Lanvil/core/Any;"));
79: }
80: if (operation == GET_BOOLEAN) {
81: context.any2boolean();
82: }
83: }
84:
85: }
|