Package anvil.script.expression

Source Code of anvil.script.expression.DynamicInvokeNode

/*
* $Id: DynamicInvokeNode.java,v 1.8 2002/09/16 08:05:04 jkl Exp $
*
* Copyright (c) 2002 Njet Communications Ltd. All Rights Reserved.
*
* Use is subject to license terms, as defined in
* Anvil Sofware License, Version 1.1. See LICENSE
* file, or http://njet.org/license-1.1.txt
*/
package anvil.script.expression;

import anvil.core.Any;
import anvil.ErrorListener;
import anvil.codec.Code;
import anvil.script.compiler.ByteCompiler;
import anvil.script.Context;
import java.io.IOException;

/**
* class DynamicInvokeNode
*
* @author: Jani Lehtim�ki
*/
public class DynamicInvokeNode extends MultiParent
{


  public DynamicInvokeNode(Node self, Node method, Parent parameters)
  {
    super(2 + parameters.childs());
    setChild(0, self);
    setChild(1, method);
    int n = parameters.childs();
    for(int i=0; i<n; i++) {
      setChild(2+i, parameters.getChild(i));
    }
  }


  public int typeOf()
  {
    return Node.EXPR_INVOKE;
  }


  public boolean isConstant()
  {
    return false;
  }

 
  private static final String[] SIGNATURES = {
    "(Lanvil/script/Context;Ljava/lang/String;)Lanvil/core/Any;",
    "(Lanvil/script/Context;Ljava/lang/String;Lanvil/core/Any;)Lanvil/core/Any;",
    "(Lanvil/script/Context;Ljava/lang/String;Lanvil/core/Any;Lanvil/core/Any;)Lanvil/core/Any;",
    "(Lanvil/script/Context;Ljava/lang/String;Lanvil/core/Any;Lanvil/core/Any;Lanvil/core/Any;)Lanvil/core/Any;",
    "(Lanvil/script/Context;Ljava/lang/String;Lanvil/core/Any;Lanvil/core/Any;Lanvil/core/Any;Lanvil/core/Any;)Lanvil/core/Any;"
  }

  public void compile(ByteCompiler context, int operation)
  {
    Code code = context.getCode();
    getChild(0).compile(context, GET);
    code.aload_first();
   
    getChild(1).compile(context, GET);
    code.invokevirtual(code.getPool().addMethodRef(context.TYPE_OBJECT,
      "toString", "()Ljava/lang/String;"));
     
    int n = childs() - 2;
    if (!hasSplices() && n <= 4) {
      for(int i=0; i<n; i++) {
        getChild(2 + i).compile(context, GET);
      }
      code.invokevirtual(code.getPool().addMethodRef(context.TYPE_ANY, "invoke", SIGNATURES[n]));
     
    } else {
      context.compileArgumentList(getChilds(2));
      code.invokevirtual(code.getPool().addMethodRef(context.TYPE_ANY,
        "invoke", "(Lanvil/script/Context;Ljava/lang/String;[Lanvil/core/Any;)Lanvil/core/Any;"));
    }
     
    if (operation == GET_BOOLEAN) {
      context.any2boolean();
    }
  }

}
TOP

Related Classes of anvil.script.expression.DynamicInvokeNode

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.