aboutsummaryrefslogtreecommitdiff
path: root/src/ast.h
blob: c62406be03dac33ce9a5685902856c54b79d28b9 (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/fstring.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::FString &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::FString &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