aboutsummaryrefslogtreecommitdiff
path: root/src/ast.h
blob: 3cc7206e2cd0bade84882608c304252ebc5ad93c (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
#ifndef AST_H
#define AST_H

#include "bu/list.h"
#include "bu/stack.h"
#include "bu/string.h"
#include "bu/formatter.h"

#include "astnode.h"

/**
 * Abstract Symbol Tree.  This is the thing that the parser builds for us.  In
 * the end, this is also what we "run" when we run build files.
 */
class Ast
{
public:
	typedef Bu::List<AstNode *> NodeList;
	Ast();
	virtual ~Ast();

	void addNode( struct YYLTYPE &loc, AstNode::Type eType );
	void addNode( struct YYLTYPE &loc, AstNode::Type eType, int iVal );
	void addNode( struct YYLTYPE &loc, AstNode::Type eType, float fVal );
	void addNode( struct YYLTYPE &loc, AstNode::Type eType, bool bVal );
	void addNode( struct YYLTYPE &loc, AstNode::Type eType,
			const Bu::String &sVal );
	void addNode( struct YYLTYPE &loc, AstNode::Type eType, const char *sVal );

	void addNode( AstNode::Type eType );
	void addNode( AstNode::Type eType, int iVal );
	void addNode( AstNode::Type eType, float fVal );
	void addNode( AstNode::Type eType, bool bVal );
	void addNode( AstNode::Type eType, const Bu::String &sVal );
	void addNode( AstNode::Type eType, const char *sVal );
	void addNode( AstNode *pNode );

	void openBranch();

	void closeNode();

	NodeList::const_iterator getNodeBegin() const;

private:
	NodeList lNode;
	typedef Bu::Stack<class AstBranch *> BranchStack;
	BranchStack sBranch;
};

Bu::Formatter &operator<<( Bu::Formatter &f, const Ast &a );

#endif