Package anvil.script.expression

Source Code of anvil.script.expression.ComprehensionNode

/*
* $Id: ComprehensionNode.java,v 1.2 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.ErrorListener;
import anvil.core.Any;
import anvil.core.Array;
import anvil.codec.Code;
import anvil.codec.ConstantPool;
import anvil.script.statements.Statement;
import anvil.script.compiler.ByteCompiler;
import anvil.script.Context;
import java.io.IOException;

/**
* class ComprehensionNode
*
* @author: Jani Lehtim�ki
*/
public abstract class ComprehensionNode extends Node
{
  protected Statement _stmt;
  protected VariableNode _var;

  public ComprehensionNode()
  {
    super();
  }


  public void init(Statement stmt, VariableNode var)
  {
    _stmt = stmt;
    _var = var;
  }


  public abstract int getClassReference(ConstantPool pool);

  public abstract int typeOf();

 
  public Node optimize()
  {
    return this;
  }

 
  public void check(ErrorListener context)
  {
    super.check(context);
    _var.check(context);
    _stmt.check(context);
  }
 

  public void compile(ByteCompiler context, int operation)
  {
    Code code = context.getCode();
    _var.compile(context, new Node() {
      public void compile(ByteCompiler context, int operation)
      {
        Code code_ = context.getCode();
        ConstantPool pool = code_.getPool();
        int clazz = getClassReference(pool);
        code_.anew(clazz);
        code_.dup();
        code_.invokespecial(pool.addMethodRef(clazz, "<init>", "()V"));
      }     
    });
    code.pop();
    _stmt.compile(context);
    _var.compile(context, GET);
    if (operation == GET_BOOLEAN) {
      context.any2boolean();
    }
  }

}
TOP

Related Classes of anvil.script.expression.ComprehensionNode

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.