Package anvil.script.statements

Source Code of anvil.script.statements.YieldStatement

/*
* $Id: YieldStatement.java,v 1.4 2002/09/16 08:05:06 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.statements;

import anvil.Location;
import anvil.core.Any;
import anvil.codec.Code;
import anvil.codec.ConstantPool;
import anvil.parser.Tag;
import anvil.ErrorListener;
import anvil.script.compiler.ByteCompiler;
import anvil.script.Context;
import anvil.script.expression.Expression;
import anvil.script.parser.TemplateParser;
import anvil.script.Grammar;
import java.io.IOException;

/**
* class YieldStatement
*
* @author: Jani Lehtim�ki
*/
public class YieldStatement extends Statement
{
  private Expression _expression = null;
  private int _state;


  public YieldStatement(Statement parent, Location location, Expression expression)
  {
    super(parent, location);
    _expression = expression;
    _state = getFunctionStatement().addYieldState();
  }


  public int typeOf()
  {
    return Statement.ST_YIELD;
  }


  public String name()
  {
    return "yield";
  }


  public void parse(TemplateParser parser, Tag tag)
  {
  }

 
  public void check(ErrorListener context)
  {
    if (!allowYield()) {
      context.error(getLocation(), "Yield statement is not allowed inside synchronized or finally statement, or try statement having finally clause.");
    }
    _expression.check(context);
  }
 

  public Jumps eliminate(ErrorListener context)
  {
    return new Jumps();
    //return new Jumps().setReturn().setBlocked(true);
  }
 

  public void compile(ByteCompiler context)
  {
    FunctionStatement function = getFunctionStatement();
    Code code = context.getCode();
    ConstantPool pool = code.getPool();
    if (_expression.needLineNumbers()) {
      context.location(_expression.getLocation());
    }
    code.aload(function.getFrameIndex());
    code.iconst(_state);
    code.invokevirtual(pool.addMethodRef("anvil/script/Generator", "setState", "(I)V"));
    _expression.compile(context, Expression.GET);
    code.areturn();
    function.bindYieldState(_state);
    /*Code code = context.getCode();
    int rv = 0;   
    if (_expression != null) {
      rv = code.addLocal();
      _expression.compile(context, Expression.GET);
      code.astore(rv);
    }
    boolean blocked = false;
    Statement stmt = this;
    while(!blocked && stmt!=null) {
      blocked = stmt.callFinalizer();
      if (stmt.typeOf() == ST_FUNCTION) {
        break;
      }
      stmt = stmt.getParentStatement();
    }
    if (!blocked) {
      if (_expression != null) {
        code.aload(rv);
        code.areturn();
      } else {
        code.self();
        code.areturn();
      }
    }*/
  }  
 
  public boolean isBlocked()
  {
    return true;
  }
 
}

  
TOP

Related Classes of anvil.script.statements.YieldStatement

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.