ThrowStatement.java :  » Web-Framework » anvil » anvil » script » statements » Java Open Source

Java Open Source » Web Framework » anvil 
anvil » anvil » script » statements » ThrowStatement.java
/*
 * $Id: ThrowStatement.java,v 1.8 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.ScriptException;
import java.io.IOException;

/**
 * class ThrowStatement
 *
 * @author: Jani Lehtimki
 */
public class ThrowStatement extends Statement
{
 
  private Expression _expression = null;


  public ThrowStatement(Statement parent, Location location, Expression expression) {
    super(parent, location);
    _expression = expression;
  }


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


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


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

  
  public void check(ErrorListener context)
  {
    if (_expression != null) {
      _expression.check(context);
    }
  }
  

  public Jumps eliminate(ErrorListener context)
  {
    Jumps jumps = new Jumps().setThrow().setBlocked(true);
    return jumps;
  }
  

  public void compile(ByteCompiler context)
  {
    Code code = context.getCode();
    ConstantPool pool = code.getPool();
    code.aload_first();
    FunctionStatement function = getFunctionStatement();
    if (function.isGenerator()) {
      code.aload(function.getFrameIndex());
      code.invokevirtual(pool.addMethodRef("anvil/script/Generator", "setClosedState", "()V"));
    }
    _expression.compile(context, Expression.GET);
    code.invokevirtual(pool.addMethodRef(context.TYPE_CONTEXT,
      "exception", "(Lanvil/core/Any;)Lanvil/script/ScriptException;"));
    code.athrow();
  }  
  
    
  public boolean isBlocked()
  {
    return true;
  }  
  
}

  
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.