aboutsummaryrefslogtreecommitdiff
path: root/src/ast.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/ast.cpp106
1 files changed, 53 insertions, 53 deletions
diff --git a/src/ast.cpp b/src/ast.cpp
index 005372b..6c03607 100644
--- a/src/ast.cpp
+++ b/src/ast.cpp
@@ -15,122 +15,122 @@ Ast::~Ast()
15 15
16void Ast::addNode( YYLTYPE &loc, AstNode::Type eType ) 16void Ast::addNode( YYLTYPE &loc, AstNode::Type eType )
17{ 17{
18 switch( eType&AstNode::typeClassMask ) 18 switch( eType&AstNode::typeClassMask )
19 { 19 {
20 case AstNode::typeBranch: 20 case AstNode::typeBranch:
21 { 21 {
22 AstBranch *pNode = new AstBranch( loc, eType ); 22 AstBranch *pNode = new AstBranch( loc, eType );
23 addNode( pNode ); 23 addNode( pNode );
24 sBranch.push( pNode ); 24 sBranch.push( pNode );
25 } 25 }
26 break; 26 break;
27 27
28 case AstNode::typeLeaf: 28 case AstNode::typeLeaf:
29 { 29 {
30 AstLeaf *pNode = new AstLeaf( loc, eType ); 30 AstLeaf *pNode = new AstLeaf( loc, eType );
31 addNode( pNode ); 31 addNode( pNode );
32 } 32 }
33 break; 33 break;
34 34
35 default: 35 default:
36 throw Bu::ExceptionBase("You got it wrong."); 36 throw Bu::ExceptionBase("You got it wrong.");
37 break; 37 break;
38 } 38 }
39} 39}
40 40
41void Ast::addNode( YYLTYPE &loc, AstNode::Type eType, int iVal ) 41void Ast::addNode( YYLTYPE &loc, AstNode::Type eType, int iVal )
42{ 42{
43 addNode( new AstLeaf( loc, eType, iVal ) ); 43 addNode( new AstLeaf( loc, eType, iVal ) );
44} 44}
45 45
46void Ast::addNode( YYLTYPE &loc, AstNode::Type eType, float fVal ) 46void Ast::addNode( YYLTYPE &loc, AstNode::Type eType, float fVal )
47{ 47{
48 addNode( new AstLeaf( loc, eType, fVal ) ); 48 addNode( new AstLeaf( loc, eType, fVal ) );
49} 49}
50 50
51void Ast::addNode( YYLTYPE &loc, AstNode::Type eType, bool bVal ) 51void Ast::addNode( YYLTYPE &loc, AstNode::Type eType, bool bVal )
52{ 52{
53 addNode( new AstLeaf( loc, eType, bVal ) ); 53 addNode( new AstLeaf( loc, eType, bVal ) );
54} 54}
55 55
56void Ast::addNode( YYLTYPE &loc, AstNode::Type eType, const Bu::String &sVal ) 56void Ast::addNode( YYLTYPE &loc, AstNode::Type eType, const Bu::String &sVal )
57{ 57{
58 addNode( new AstLeaf( loc, eType, sVal ) ); 58 addNode( new AstLeaf( loc, eType, sVal ) );
59} 59}
60 60
61void Ast::addNode( YYLTYPE &loc, AstNode::Type eType, const char *sVal ) 61void Ast::addNode( YYLTYPE &loc, AstNode::Type eType, const char *sVal )
62{ 62{
63 addNode( new AstLeaf( loc, eType, sVal ) ); 63 addNode( new AstLeaf( loc, eType, sVal ) );
64} 64}
65 65
66void Ast::addNode( AstNode::Type eType ) 66void Ast::addNode( AstNode::Type eType )
67{ 67{
68 YYLTYPE none = {-1, -1, -1, -1}; 68 YYLTYPE none = {-1, -1, -1, -1};
69 addNode( none, eType ); 69 addNode( none, eType );
70} 70}
71 71
72void Ast::addNode( AstNode::Type eType, int iVal ) 72void Ast::addNode( AstNode::Type eType, int iVal )
73{ 73{
74 YYLTYPE none = {-1, -1, -1, -1}; 74 YYLTYPE none = {-1, -1, -1, -1};
75 addNode( none, eType, iVal ); 75 addNode( none, eType, iVal );
76} 76}
77 77
78void Ast::addNode( AstNode::Type eType, float fVal ) 78void Ast::addNode( AstNode::Type eType, float fVal )
79{ 79{
80 YYLTYPE none = {-1, -1, -1, -1}; 80 YYLTYPE none = {-1, -1, -1, -1};
81 addNode( none, eType, fVal ); 81 addNode( none, eType, fVal );
82} 82}
83 83
84void Ast::addNode( AstNode::Type eType, bool bVal ) 84void Ast::addNode( AstNode::Type eType, bool bVal )
85{ 85{
86 YYLTYPE none = {-1, -1, -1, -1}; 86 YYLTYPE none = {-1, -1, -1, -1};
87 addNode( none, eType, bVal ); 87 addNode( none, eType, bVal );
88} 88}
89 89
90void Ast::addNode( AstNode::Type eType, const Bu::String &sVal ) 90void Ast::addNode( AstNode::Type eType, const Bu::String &sVal )
91{ 91{
92 YYLTYPE none = {-1, -1, -1, -1}; 92 YYLTYPE none = {-1, -1, -1, -1};
93 addNode( none, eType, sVal ); 93 addNode( none, eType, sVal );
94} 94}
95 95
96void Ast::addNode( AstNode::Type eType, const char *sVal ) 96void Ast::addNode( AstNode::Type eType, const char *sVal )
97{ 97{
98 YYLTYPE none = {-1, -1, -1, -1}; 98 YYLTYPE none = {-1, -1, -1, -1};
99 addNode( none, eType, sVal ); 99 addNode( none, eType, sVal );
100} 100}
101 101
102void Ast::addNode( AstNode *pNode ) 102void Ast::addNode( AstNode *pNode )
103{ 103{
104 if( sBranch.isEmpty() ) 104 if( sBranch.isEmpty() )
105 lNode.append( pNode ); 105 lNode.append( pNode );
106 else 106 else
107 sBranch.peek()->addNode( pNode ); 107 sBranch.peek()->addNode( pNode );
108} 108}
109 109
110void Ast::openBranch() 110void Ast::openBranch()
111{ 111{
112 sBranch.peek()->addBranch(); 112 sBranch.peek()->addBranch();
113} 113}
114 114
115void Ast::closeNode() 115void Ast::closeNode()
116{ 116{
117 sBranch.pop(); 117 sBranch.pop();
118} 118}
119 119
120Ast::NodeList::const_iterator Ast::getNodeBegin() const 120Ast::NodeList::const_iterator Ast::getNodeBegin() const
121{ 121{
122 return lNode.begin(); 122 return lNode.begin();
123} 123}
124 124
125Bu::Formatter &operator<<( Bu::Formatter &f, const Ast &a ) 125Bu::Formatter &operator<<( Bu::Formatter &f, const Ast &a )
126{ 126{
127 f << "Abstract Syntax Tree:"; 127 f << "Abstract Syntax Tree:";
128 f.incIndent(); 128 f.incIndent();
129 f << f.nl; 129 f << f.nl;
130 for( Ast::NodeList::const_iterator i = a.getNodeBegin(); i; i++ ) 130 for( Ast::NodeList::const_iterator i = a.getNodeBegin(); i; i++ )
131 f << **i << f.nl; 131 f << **i << f.nl;
132 f << f.nl; 132 f << f.nl;
133 f.decIndent(); 133 f.decIndent();
134 return f; 134 return f;
135} 135}
136 136