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) 2002 Benoit Cerrina <b.cerrina@wanadoo.fr>
015: * Copyright (C) 2002 Jan Arne Petersen <jpetersen@uni-bonn.de>
016: * Copyright (C) 2002-2004 Anders Bengtsson <ndrsbngtssn@yahoo.se>
017: * Copyright (C) 2004 Thomas E Enebo <enebo@acm.org>
018: * Copyright (C) 2004 Stefan Matthias Aust <sma@3plus4.de>
019: *
020: * Alternatively, the contents of this file may be used under the terms of
021: * either of the GNU General Public License Version 2 or later (the "GPL"),
022: * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
023: * in which case the provisions of the GPL or the LGPL are applicable instead
024: * of those above. If you wish to allow use of your version of this file only
025: * under the terms of either the GPL or the LGPL, and not to allow others to
026: * use your version of this file under the terms of the CPL, indicate your
027: * decision by deleting the provisions above and replace them with the notice
028: * and other provisions required by the GPL or the LGPL. If you do not delete
029: * the provisions above, a recipient may use your version of this file under
030: * the terms of any one of the CPL, the GPL or the LGPL.
031: ***** END LICENSE BLOCK *****/package org.jruby.ast;
032:
033: import java.util.List;
034:
035: import org.jruby.ast.visitor.NodeVisitor;
036: import org.jruby.evaluator.Instruction;
037: import org.jruby.lexer.yacc.ISourcePosition;
038:
039: /**
040: * a Range in a boolean expression.
041: * named after a FlipFlop component in electronic I believe.
042: *
043: * @author jpetersen
044: */
045: public class FlipNode extends Node {
046: static final long serialVersionUID = -4735579451657299802L;
047:
048: private final Node beginNode;
049: private final Node endNode;
050: private final boolean exclusive;
051: // A scoped location of this variable (high 16 bits is how many scopes down and low 16 bits
052: // is what index in the right scope to set the value.
053: private final int location;
054:
055: public FlipNode(ISourcePosition position, Node beginNode,
056: Node endNode, boolean exclusive, int location) {
057: super (position, NodeTypes.FLIPNODE);
058: this .beginNode = beginNode;
059: this .endNode = endNode;
060: this .exclusive = exclusive;
061: this .location = location;
062: }
063:
064: /**
065: * Accept for the visitor pattern.
066: * @param iVisitor the visitor
067: **/
068: public Instruction accept(NodeVisitor iVisitor) {
069: return iVisitor.visitFlipNode(this );
070: }
071:
072: /**
073: * Gets the beginNode.
074: * beginNode will set the FlipFlop the first time it is true
075: * @return Returns a Node
076: */
077: public Node getBeginNode() {
078: return beginNode;
079: }
080:
081: /**
082: * Gets the endNode.
083: * endNode will reset the FlipFlop when it is true while the FlipFlop is set.
084: * @return Returns a Node
085: */
086: public Node getEndNode() {
087: return endNode;
088: }
089:
090: /**
091: * Gets the exclusive.
092: * if the range is a 2 dot range it is false if it is a three dot it is true
093: * @return Returns a boolean
094: */
095: public boolean isExclusive() {
096: return exclusive;
097: }
098:
099: /**
100: * How many scopes should we burrow down to until we need to set the block variable value.
101: *
102: * @return 0 for current scope, 1 for one down, ...
103: */
104: public int getDepth() {
105: return location >> 16;
106: }
107:
108: /**
109: * Gets the index within the scope construct that actually holds the eval'd value
110: * of this local variable
111: *
112: * @return Returns an int offset into storage structure
113: */
114: public int getIndex() {
115: return location & 0xffff;
116: }
117:
118: public List childNodes() {
119: return Node.createList(beginNode, endNode);
120: }
121:
122: }
|