summaryrefslogtreecommitdiffstats
path: root/microbe/btreenode.h
blob: ea39050d3db01ca75222c09831f2f0ba26755c6d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/***************************************************************************
 *   Copyright (C) 2004-2005 by Daniel Clarke                              *
 *   daniel.jc@gmail.com                                                   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.             *
 ***************************************************************************/

#ifndef BTREENODE_H
#define BTREENODE_H

#include "btreebase.h"
#include "expression.h"

#include <tqstring.h>
#include <tqptrlist.h>

/**
A node points to the two child nodes (left and right), and contains the binary
operation used to combine them.

@author Daniel Clarke
@author David Saxton
*/
class BTreeNode
{
	public:
		BTreeNode();
		BTreeNode(BTreeNode *p, BTreeNode *l, BTreeNode *r);
		~BTreeNode();

		/**
		 * Used for debugging purposes; prints the tree structure to stdout.
		 */
// 		void printTree();
		/**
		 * Recursively delete all children of a node.
		 */
		void deleteChildren();
		/**
		 * @return the parent node.
		 */
		BTreeNode *parent() const { return m_parent; }
		/**
		 * @return the left child node.
		 */
		BTreeNode *left() const { return m_left; }
		/**
		 * @return the right child node.
		 */
		BTreeNode *right() const { return m_right; }
		void setParent(BTreeNode *parent) { m_parent = parent; }
		/**
		 * Set the child node on the left to the one give, and reparents it to
		 * this node. 
		 */
		void setLeft(BTreeNode *left) { m_left = left; m_left->setParent( this ); }
		/**
		 * Set the child node on the right to the one give, and reparents it to
		 * this node. 
		 */
		void setRight(BTreeNode *right) { m_right = right; m_right->setParent( this ); }
		/**
		 * @return true if have a left or a right child node.
		 */
		bool hasChildren() const { return m_left || m_right; }
	
		ExprType type() const {return m_type;}
		void setType(ExprType type) { m_type = type; }
		TQString value() const {return m_value;}
		void setValue( const TQString & value ) { m_value = value; }
	
		Expression::Operation childOp() const {return m_childOp;}
		void setChildOp(Expression::Operation op){ m_childOp = op;}
	
		void setReg( const TQString & r ){ m_reg = r; }
		TQString reg() const {return m_reg;}
	
		bool needsEvaluating() const { return hasChildren(); }
		
	protected:
		BTreeNode *m_parent;
		BTreeNode *m_left;
		BTreeNode *m_right;
	
		/** This is used to remember what working register contains the value of the node during assembly.*/
		TQString m_reg;
	
		ExprType m_type;
		TQString m_value;
	
		Expression::Operation m_childOp;
};

#endif