2 Copyright (C) 2003 by Walter Schreppers
3 Copyright (C) 2004 by Cies Breijs
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of version 2 of the GNU General Public
7 License as published by the Free Software Foundation.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 // This file is originally written by Walter Scheppers, but allmost
20 // every aspect of it is slightly changed by Cies Breijs.
35 using namespace std
; // needed because treenode inherites from std::list
37 //BUGS: prevSibling and nextSibling sometimes segfault and are not optimal, in short, don't use em! :)
115 // HOPEFULLY THIS LIST CAN ONCE LOOK LIKE THIS:
116 // nodeProgram, // this frirst block has no corresponding token
119 // nodeReturnFunction,
120 // nodeParameterList,
123 // nodeId, // for assignments
125 // nodeNotSet = -1, // inittial type of all tokens
126 // nodeUnknown = 0, // when no token was found, a tokUnknown is often a variable, function or error
142 // // nodeNumber, --> constantNode
159 // // nodeBraceClose,
161 // nodeAdd, // different from TokenType
162 // nodeSub, // different from TokenType
165 // nodeMinus, // different meaning from TokenType
212 class TreeNode
: public list
<TreeNode
*> /*, public Value <-- maybe oneday */
215 TreeNode(); // used for creation of the first node called 'tree', in the contructor of the parser
216 TreeNode( TreeNode
* ); // give parent
217 TreeNode( Token
, NodeType
= Unknown
, QString
= QString() );
222 void appendChild(TreeNode
*);
223 void appendSibling(TreeNode
*); // works only if it has parent set!
225 TreeNode
* firstChild();
226 TreeNode
* secondChild();
227 TreeNode
* thirdChild();
228 TreeNode
* fourthChild();
229 TreeNode
* fifthChild();
231 TreeNode
* lastChild();
232 TreeNode
* nextSibling();
233 TreeNode
* prevSibling();
235 void setParent(TreeNode
* p
) { parent
= p
; }
236 TreeNode
* getParent() const { return parent
; }
238 void setToken(Token t
) { fTok
= t
; }
239 Token
& getToken() { return fTok
; }
241 void setType(NodeType t
) { fType
= t
; }
242 NodeType
getType() const { return fType
; }
244 void setLook(const QString
& s
) { fTok
.look
= s
; }
245 QString
getLook() const { return fTok
.look
; }
247 void setValue(const Value
& n
) { fTok
.value
= n
; }
248 void setValue(double d
) { fTok
.value
= d
; }
249 void setValue(const QString
& s
) { fTok
.value
= s
; }
250 void setValue(bool b
) { fTok
.value
.setBool(b
); }
251 Value
getValue() const { return fTok
.value
; }
253 uint
getRow() const { return fTok
.start
.row
; }
254 uint
getCol() const { return fTok
.start
.col
; }
256 bool hasChildren() const { return size() != 0; }
257 TreeNode::iterator
lookup(); // gives location in parent list as iterator (used by prevSibling and nextSibling)
259 TreeNode
& operator=(const TreeNode
&);
261 virtual void show(int indent
= 0);
262 void showTree(TreeNode
* node
, int indent
= 0) const;
266 void destroy(TreeNode
*);
276 #endif // _TREENODE_H_