001: /***** BEGIN LICENSE BLOCK *****
002: * Version: CPL 1.0/GPL 2.0/LGPL 2.1
003: *
004: * The contents of this file are subject to the Common Public
005: * License Version 1.0 (the "License"); you may not use this file
006: * except in compliance with the License. You may obtain a copy of
007: * the License at http://www.eclipse.org/legal/cpl-v10.html
008: *
009: * Software distributed under the License is distributed on an "AS
010: * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
011: * implied. See the License for the specific language governing
012: * rights and limitations under the License.
013: *
014: * Copyright (C) 2001-2002 Jan Arne Petersen <jpetersen@uni-bonn.de>
015: * Copyright (C) 2001-2002 Benoit Cerrina <b.cerrina@wanadoo.fr>
016: * Copyright (C) 2002-2004 Anders Bengtsson <ndrsbngtssn@yahoo.se>
017: * Copyright (C) 2004 Thomas E Enebo <enebo@acm.org>
018: *
019: * Alternatively, the contents of this file may be used under the terms of
020: * either of the GNU General Public License Version 2 or later (the "GPL"),
021: * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
022: * in which case the provisions of the GPL or the LGPL are applicable instead
023: * of those above. If you wish to allow use of your version of this file only
024: * under the terms of either the GPL or the LGPL, and not to allow others to
025: * use your version of this file under the terms of the CPL, indicate your
026: * decision by deleting the provisions above and replace them with the notice
027: * and other provisions required by the GPL or the LGPL. If you do not delete
028: * the provisions above, a recipient may use your version of this file under
029: * the terms of any one of the CPL, the GPL or the LGPL.
030: ***** END LICENSE BLOCK *****/package org.jruby.ast;
031:
032: import java.util.List;
033:
034: import org.jruby.ast.visitor.NodeVisitor;
035: import org.jruby.evaluator.Instruction;
036: import org.jruby.lexer.yacc.ISourcePosition;
037:
038: /** Represents a while stetement. This could be the both versions:
039: *
040: * while <condition>
041: * <body>
042: * end
043: *
044: * and
045: *
046: * <body> 'while' <condition>
047: *
048: * @author jpetersen
049: */
050: public class WhileNode extends Node {
051: static final long serialVersionUID = -5355364190446060873L;
052:
053: private final Node conditionNode;
054: private final Node bodyNode;
055: private final boolean evaluateAtStart;
056:
057: public WhileNode(ISourcePosition position, Node conditionNode,
058: Node bodyNode) {
059: this (position, conditionNode, bodyNode, true);
060: }
061:
062: public WhileNode(ISourcePosition position, Node conditionNode,
063: Node bodyNode, boolean evalAtStart) {
064: super (position, NodeTypes.WHILENODE);
065: this .conditionNode = conditionNode;
066: this .bodyNode = bodyNode;
067: this .evaluateAtStart = evalAtStart;
068: }
069:
070: /**
071: * Accept for the visitor pattern.
072: * @param iVisitor the visitor
073: **/
074: public Instruction accept(NodeVisitor iVisitor) {
075: return iVisitor.visitWhileNode(this );
076: }
077:
078: /**
079: * Gets the bodyNode.
080: * @return Returns a Node
081: */
082: public Node getBodyNode() {
083: return bodyNode;
084: }
085:
086: /**
087: * Gets the conditionNode.
088: * @return Returns a Node
089: */
090: public Node getConditionNode() {
091: return conditionNode;
092: }
093:
094: /**
095: * Determine whether this is while or do while
096: * @return true if you are a while, false if do while
097: */
098: public boolean evaluateAtStart() {
099: return evaluateAtStart;
100: }
101:
102: public List childNodes() {
103: return Node.createList(conditionNode, bodyNode);
104: }
105:
106: }
|