summaryrefslogtreecommitdiff
path: root/src/astnode.cpp
blob: 88363c95eefb729ae49f2f110135eb201a1b8dad (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
#include "astnode.h"

#include <bu/formatter.h>

#include "astleaf.h"
#include "astleafliteral.h"
#include "astbranch.h"

AstNode::AstNode( AstNode::Type eType ) :
	eType( eType )
{
}

AstNode::~AstNode()
{
}

Bu::Formatter &operator<<( Bu::Formatter &f, AstNode::Type t )
{
	switch( t )
	{
		case AstNode::tLeaf:			return f << "!tLeaf!";
		case AstNode::tNot:				return f << "tNot";
		case AstNode::tComp:			return f << "tComp";
		case AstNode::tCompGt:			return f << "tCompGt";
		case AstNode::tCompLt:			return f << "tCompLt";
		case AstNode::tCompGtEq:		return f << "tCompGtEq";
		case AstNode::tCompLtEq:		return f << "tCompLtEq";
		case AstNode::tStore:			return f << "tStore";
		case AstNode::tAnd:				return f << "tAnd";
		case AstNode::tOr:				return f << "tOr";
		case AstNode::tPlus:			return f << "tPlus";
		case AstNode::tMinus:			return f << "tMinus";
		case AstNode::tDivide:			return f << "tDivide";
		case AstNode::tMultiply:		return f << "tMultiply";
		case AstNode::tPlusStore:		return f << "tPlusStore";
		case AstNode::tMinusStore:		return f << "tMinusStore";
		case AstNode::tDivideStore:		return f << "tDivideStore";
		case AstNode::tMultiplyStore:	return f << "tMultiplyStore";
		case AstNode::tNegate:			return f << "tNegate";
		case AstNode::tIn:				return f << "tIn";
		case AstNode::tGoto:			return f << "tGoto";
		case AstNode::tSwap:			return f << "tSwap";
		
		case AstNode::tLeafLiteral:		return f << "!tLeafLiteral!";
		case AstNode::tVarName:			return f << "tVarName";
		case AstNode::tLiteral:			return f << "tLiteral";
		case AstNode::tFuncCall:		return f << "tFuncCall";

		case AstNode::tBranch:			return f << "!tBranch!";
		case AstNode::tScope:			return f << "tScope";
		case AstNode::tIf:				return f << "tIf";
		case AstNode::tForEach:			return f << "tForEach";
		case AstNode::tWhile:			return f << "tWhile";

		case AstNode::tTypeMask:		return f << "!tTypeMask!";
	}

	return f << "???";
}

Bu::Formatter &operator<<( Bu::Formatter &f, const AstNode &n )
{
	switch( n.eType & AstNode::tTypeMask )
	{
		case AstNode::tLeaf:
			return f << dynamic_cast<const AstLeaf &>(n);

		case AstNode::tLeafLiteral:
			return f << dynamic_cast<const AstLeafLiteral &>(n);

		case AstNode::tBranch:
			return f << dynamic_cast<const AstBranch &>(n);
	}

	return f << "!!!ERROR!!!";
}