Package anvil.script.expression

Source Code of anvil.script.expression.PrefixDecrementNode

/*
* $Id: PrefixDecrementNode.java,v 1.7 2002/09/16 08:05:05 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.ErrorListener;
import anvil.Location;
import anvil.core.Any;
import anvil.codec.Code;
import anvil.codec.ConstantPool;
import anvil.script.compiler.ByteCompiler;
import anvil.script.Context;
import java.io.IOException;

/**
* class PrefixDecrementNode
*
* @author: Jani Lehtim�ki
*/
public class PrefixDecrementNode extends UnaryParent
{

  protected Location _location;


  public PrefixDecrementNode(Location location, Node child)
  {
    super(child);
    _location = location;
  }


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


  public boolean isConstant()
  {
    return false;
  }


  public void check(ErrorListener listener)
  {
    super.check(listener);
    if (!_child.isUpdatable()) {
      listener.error(_location, "Right side of '--' is not an updatable expression");
    }
  }


  public void compile(ByteCompiler context, int operation)
  {
    Code code = context.getCode();
    ConstantPool pool = code.getPool();
    final Node child = _child;
    switch(child.typeOf()) {
    case Node.EXPR_VARIABLE:
      {
        child.compile(context, new Node() {
          public void compile(ByteCompiler context, int operation)
          {
            Code code = context.getCode();
            child.compile(context, GET);
            code.invokevirtual(code.getPool().addMethodRef(context.TYPE_ANY, "decrease", "()Lanvil/core/Any;"));
          }     
        });
      }
      break;
     
    case Node.EXPR_ATTRIBUTE:
      {
        AttributeNode attr = (AttributeNode)child;
        attr.getChild().compile(context, GET);
        code.astring(attr.getAttribute());
        code.aload_first();
        code.invokestatic(pool.addMethodRef(context.TYPE_CONTEXT, "predec",
          "(Lanvil/core/Any;Ljava/lang/String;Lanvil/script/Context;)Lanvil/core/Any;"));
      }
      break;
   
    case Node.EXPR_REFERENCE:
      {
        ReferenceNode ref = (ReferenceNode)child;
        ref.getLeft().compile(context, GET);
        ref.getRight().compile(context, GET);
        code.aload_first();
        code.invokestatic(pool.addMethodRef(context.TYPE_CONTEXT, "predec",
          "(Lanvil/core/Any;Lanvil/core/Any;Lanvil/script/Context;)Lanvil/core/Any;"));
      }
      break;

    default:
      child.compile(context, operation);
    }   
    if (operation == GET_BOOLEAN) {
      context.any2boolean();
   
  }
}
TOP

Related Classes of anvil.script.expression.PrefixDecrementNode

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.