Package anvil.script.expression

Source Code of anvil.script.expression.PostfixDecrementNode

/*
* $Id: PostfixDecrementNode.java,v 1.8 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 PostfixDecrementNode
*
* @author: Jani Lehtim�ki
*/
public class PostfixDecrementNode extends UnaryParent
{
  protected Location _location;

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


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


  public boolean isConstant()
  {
    return false;
  }


  public void check(ErrorListener listener)
  {
    super.check(listener);
    if (!_child.isUpdatable()) {
      listener.error(_location, "Left 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:
      {
        final int tmp = code.addLocal();
        child.compile(context, GET);
        code.astore(tmp);
        child.compile(context, new Node() {
          public void compile(ByteCompiler context, int operation)
          {
            Code code_ = context.getCode();
            code_.aload(tmp);
            code_.invokevirtual(code_.getPool().addMethodRef(context.TYPE_ANY, "decrease", "()Lanvil/core/Any;"));
          }     
        });
        code.pop();
        code.aload(tmp);
        code.endLocal(tmp);
      }
      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, "postdec",
          "(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, "postdec",
          "(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.PostfixDecrementNode

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.