File indexing completed on 2025-02-16 05:15:09
0001 /*************************************************************************** 0002 * Copyright (C) 2004-2005 by Daniel Clarke * 0003 * daniel.jc@gmail.com * 0004 * * 0005 * This program is free software; you can redistribute it and/or modify * 0006 * it under the terms of the GNU General Public License as published by * 0007 * the Free Software Foundation; either version 2 of the License, or * 0008 * (at your option) any later version. * 0009 * * 0010 * This program is distributed in the hope that it will be useful, * 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0013 * GNU General Public License for more details. * 0014 * * 0015 * You should have received a copy of the GNU General Public License * 0016 * along with this program; if not, write to the * 0017 * Free Software Foundation, Inc., * 0018 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 0019 ***************************************************************************/ 0020 0021 #ifndef BTREENODE_H 0022 #define BTREENODE_H 0023 0024 #include "btreebase.h" 0025 #include "expression.h" 0026 0027 #include <QString> 0028 #include <QList> 0029 0030 /** 0031 A node points to the two child nodes (left and right), and contains the binary 0032 operation used to combine them. 0033 0034 @author Daniel Clarke 0035 @author David Saxton 0036 */ 0037 class BTreeNode 0038 { 0039 public: 0040 BTreeNode(); 0041 BTreeNode(BTreeNode *p, BTreeNode *l, BTreeNode *r); 0042 ~BTreeNode(); 0043 0044 /** 0045 * Used for debugging purposes; prints the tree structure to stdout. 0046 */ 0047 // void printTree(); 0048 /** 0049 * Recursively delete all children of a node. 0050 */ 0051 void deleteChildren(); 0052 /** 0053 * @return the parent node. 0054 */ 0055 BTreeNode *parent() const { return m_parent; } 0056 /** 0057 * @return the left child node. 0058 */ 0059 BTreeNode *left() const { return m_left; } 0060 /** 0061 * @return the right child node. 0062 */ 0063 BTreeNode *right() const { return m_right; } 0064 void setParent(BTreeNode *parent) { m_parent = parent; } 0065 /** 0066 * Set the child node on the left to the one give, and reparents it to 0067 * this node. 0068 */ 0069 void setLeft(BTreeNode *left) { m_left = left; m_left->setParent( this ); } 0070 /** 0071 * Set the child node on the right to the one give, and reparents it to 0072 * this node. 0073 */ 0074 void setRight(BTreeNode *right) { m_right = right; m_right->setParent( this ); } 0075 /** 0076 * @return true if have a left or a right child node. 0077 */ 0078 bool hasChildren() const { return m_left || m_right; } 0079 0080 ExprType type() const {return m_type;} 0081 void setType(ExprType type) { m_type = type; } 0082 QString value() const {return m_value;} 0083 void setValue( const QString & value ) { m_value = value; } 0084 0085 Expression::Operation childOp() const {return m_childOp;} 0086 void setChildOp(Expression::Operation op){ m_childOp = op;} 0087 0088 void setReg( const QString & r ){ m_reg = r; } 0089 QString reg() const {return m_reg;} 0090 0091 bool needsEvaluating() const { return hasChildren(); } 0092 0093 protected: 0094 BTreeNode *m_parent; 0095 BTreeNode *m_left; 0096 BTreeNode *m_right; 0097 0098 /** This is used to remember what working register contains the value of the node during assembly.*/ 0099 QString m_reg; 0100 0101 ExprType m_type; 0102 QString m_value; 0103 0104 Expression::Operation m_childOp; 0105 }; 0106 0107 #endif