Package anvil.script.statements

Source Code of anvil.script.statements.BreakStatement

/*
* $Id: BreakStatement.java,v 1.10 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.codec.Code;
import anvil.parser.Tag;
import anvil.ErrorListener;
import anvil.script.compiler.ByteCompiler;
import anvil.script.Context;
import anvil.script.parser.TemplateParser;
import java.io.IOException;

/**
* class BreakStatement
*
* @author: Jani Lehtim�ki
*/
public class BreakStatement extends Statement
{

  private String _label = null;
  private int _depth = 0;


  public BreakStatement(Statement parent, Location location) {
    super(parent, location);
  }


  public BreakStatement(Statement parent, Location location, String label, int depth) {
    super(parent, location);
    _label = label;
    _depth = depth;
  }

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


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


  public void parse(TemplateParser parser, Tag tag)
  {
    String label = tag.getValue("to");
    if (label != null) {
      _depth = getLabelDepth(label);
      if (_depth == -1) {
        parser.error(getLocation(), "Label '"+label+"' is not declared");
        return;
      }
    }
    _label = label;
  }


  public void check(ErrorListener context)
  {
  }
 

  public Jumps eliminate(ErrorListener context)
  {
    Jumps jumps = new Jumps();
    if (_label != null) {
      jumps.setBreak(_depth).setBlocked(true);
    } else {
      jumps.setBreak().setBlocked(true);
    }
    //jumps.print("break");
    return jumps;
  }
 

  public void compile(ByteCompiler context)
  {
    boolean blocked = false;
    Code code = context.getCode();
    Labeled target = getLabeled(_label, false);
    Statement stmt = this;
    while(!blocked && stmt!=target) {
      blocked = stmt.callFinalizer();
      stmt = stmt.getParentStatement();
    }
    if (!blocked) {
      code.go_to(target.getEndOfScope());
    }
  }
 
   
  public boolean isBlocked()
  {
    return true;
  }
   
 
}

 
TOP

Related Classes of anvil.script.statements.BreakStatement

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.