001/* ASTPtBitwiseNode represent bitwise operator(&, |, ^) nodes in the parse tree
002
003 Copyright (c) 1998-2014 The Regents of the University of California.
004 All rights reserved.
005 Permission is hereby granted, without written agreement and without
006 license or royalty fees, to use, copy, modify, and distribute this
007 software and its documentation for any purpose, provided that the above
008 copyright notice and the following two paragraphs appear in all copies
009 of this software.
010
011 IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
012 FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
013 ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
014 THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
015 SUCH DAMAGE.
016
017 THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
018 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
019 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
020 PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
021 CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
022 ENHANCEMENTS, OR MODIFICATIONS.
023
024 PT_COPYRIGHT_VERSION_2
025 COPYRIGHTENDKEY
026
027
028 Created : May 1998
029
030 */
031package ptolemy.data.expr;
032
033import java.util.Map;
034
035import ptolemy.kernel.util.IllegalActionException;
036
037//////////////////////////////////////////////////////////////////////////
038//// ASTPtBitwiseNode
039
040/**
041 The parse tree created from the expression string consists of a
042 hierarchy of node objects. This class represents bitwise operator(&, |, ^)
043 nodes in the parse tree.
044
045 @author Neil Smyth, Steve Neuendorffer
046 @version $Id$
047 @since Ptolemy II 0.2
048 @Pt.ProposedRating Yellow (nsmyth)
049 @Pt.AcceptedRating Red (cxh)
050 @see ptolemy.data.expr.ASTPtRootNode
051 @see ptolemy.data.expr.PtParser
052 @see ptolemy.data.Token
053 */
054public class ASTPtBitwiseNode extends ASTPtRootNode {
055    public ASTPtBitwiseNode(int id) {
056        super(id);
057    }
058
059    public ASTPtBitwiseNode(PtParser p, int id) {
060        super(p, id);
061    }
062
063    /** Return the token that represents the operation of this node.
064     *  @return the token that represents the operation of this node.
065     */
066    public Token getOperator() {
067        return _lexicalToken;
068    }
069
070    /** Return true if this operation represents a boolean AND operation.
071     * @return true if this operation represents a boolean AND operation.
072     */
073    public boolean isBitwiseAnd() {
074        return _lexicalToken.kind == PtParserConstants.AND;
075    }
076
077    /** Return true if this operation represents a boolean OR operation.
078     * @return true if this operation represents a boolean OR operation.
079     */
080    public boolean isBitwiseOr() {
081        return _lexicalToken.kind == PtParserConstants.OR;
082    }
083
084    /** Return true if this operation represents a boolean XOR operation.
085     *  @return true if this operation represents a boolean XOR operation.
086     */
087    public boolean isBitwiseXor() {
088        return _lexicalToken.kind == PtParserConstants.XOR;
089    }
090
091    /** Return true if this node is (hierarchically) congruent to the
092     *  given node, under the given renaming of bound identifiers.
093     *  Derived classes should extend this method to add additional
094     *  necessary congruency checks.
095     *  @param node The node to compare to.
096     *  @param renaming A map from String to String that gives a
097     *  renaming from identifiers in this node to identifiers in the
098     *  given node.
099     */
100    @Override
101    public boolean isCongruent(ASTPtRootNode node, Map renaming) {
102        if (!super.isCongruent(node, renaming)) {
103            return false;
104        }
105
106        if (_lexicalToken.kind != ((ASTPtBitwiseNode) node)._lexicalToken.kind) {
107            return false;
108        }
109
110        return true;
111    }
112
113    /** Traverse this node with the given visitor.
114     */
115    @Override
116    public void visit(ParseTreeVisitor visitor) throws IllegalActionException {
117        visitor.visitBitwiseNode(this);
118    }
119
120    protected Token _lexicalToken = null;
121}