aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2009-12-28 20:55:18 +0000
committerMike Buland <eichlan@xagasoft.com>2009-12-28 20:55:18 +0000
commitc5fcf682195b0b191d19a598844f734ebf5b2583 (patch)
tree9fb24ddc20aaee06ee4990e84725b33a3e213207
parente27c94b51a2e315ed5f529ba0c8c0d1bf354143c (diff)
downloadbuild-c5fcf682195b0b191d19a598844f734ebf5b2583.tar.gz
build-c5fcf682195b0b191d19a598844f734ebf5b2583.tar.bz2
build-c5fcf682195b0b191d19a598844f734ebf5b2583.tar.xz
build-c5fcf682195b0b191d19a598844f734ebf5b2583.zip
Location data is being tracked (for the most part, filenames...not as much),
but it isn't being used in errors yet, I should add some new exceptions for now.
-rw-r--r--src/ast.cpp54
-rw-r--r--src/ast.h8
-rw-r--r--src/astbranch.cpp4
-rw-r--r--src/astbranch.h2
-rw-r--r--src/astleaf.cpp24
-rw-r--r--src/astleaf.h12
-rw-r--r--src/astnode.cpp5
-rw-r--r--src/astnode.h4
-rw-r--r--src/build.y148
-rw-r--r--src/location.cpp35
-rw-r--r--src/location.h23
11 files changed, 213 insertions, 106 deletions
diff --git a/src/ast.cpp b/src/ast.cpp
index 03ed4b6..6b213ea 100644
--- a/src/ast.cpp
+++ b/src/ast.cpp
@@ -3,6 +3,8 @@
3#include "astleaf.h" 3#include "astleaf.h"
4#include "astbranch.h" 4#include "astbranch.h"
5 5
6#include "build.tab.h"
7
6Ast::Ast() 8Ast::Ast()
7{ 9{
8} 10}
@@ -11,13 +13,13 @@ Ast::~Ast()
11{ 13{
12} 14}
13 15
14void Ast::addNode( AstNode::Type eType ) 16void Ast::addNode( YYLTYPE &loc, AstNode::Type eType )
15{ 17{
16 switch( eType&AstNode::typeClassMask ) 18 switch( eType&AstNode::typeClassMask )
17 { 19 {
18 case AstNode::typeBranch: 20 case AstNode::typeBranch:
19 { 21 {
20 AstBranch *pNode = new AstBranch( eType ); 22 AstBranch *pNode = new AstBranch( loc, eType );
21 addNode( pNode ); 23 addNode( pNode );
22 sBranch.push( pNode ); 24 sBranch.push( pNode );
23 } 25 }
@@ -25,7 +27,7 @@ void Ast::addNode( AstNode::Type eType )
25 27
26 case AstNode::typeLeaf: 28 case AstNode::typeLeaf:
27 { 29 {
28 AstLeaf *pNode = new AstLeaf( eType ); 30 AstLeaf *pNode = new AstLeaf( loc, eType );
29 addNode( pNode ); 31 addNode( pNode );
30 } 32 }
31 break; 33 break;
@@ -36,29 +38,65 @@ void Ast::addNode( AstNode::Type eType )
36 } 38 }
37} 39}
38 40
41void Ast::addNode( YYLTYPE &loc, AstNode::Type eType, int iVal )
42{
43 addNode( new AstLeaf( loc, eType, iVal ) );
44}
45
46void Ast::addNode( YYLTYPE &loc, AstNode::Type eType, float fVal )
47{
48 addNode( new AstLeaf( loc, eType, fVal ) );
49}
50
51void Ast::addNode( YYLTYPE &loc, AstNode::Type eType, bool bVal )
52{
53 addNode( new AstLeaf( loc, eType, bVal ) );
54}
55
56void Ast::addNode( YYLTYPE &loc, AstNode::Type eType, const Bu::FString &sVal )
57{
58 addNode( new AstLeaf( loc, eType, sVal ) );
59}
60
61void Ast::addNode( YYLTYPE &loc, AstNode::Type eType, const char *sVal )
62{
63 addNode( new AstLeaf( loc, eType, sVal ) );
64}
65
66void Ast::addNode( AstNode::Type eType )
67{
68 YYLTYPE none = {-1, -1, -1, -1};
69 addNode( none, eType );
70}
71
39void Ast::addNode( AstNode::Type eType, int iVal ) 72void Ast::addNode( AstNode::Type eType, int iVal )
40{ 73{
41 addNode( new AstLeaf( eType, iVal ) ); 74 YYLTYPE none = {-1, -1, -1, -1};
75 addNode( none, eType, iVal );
42} 76}
43 77
44void Ast::addNode( AstNode::Type eType, float fVal ) 78void Ast::addNode( AstNode::Type eType, float fVal )
45{ 79{
46 addNode( new AstLeaf( eType, fVal ) ); 80 YYLTYPE none = {-1, -1, -1, -1};
81 addNode( none, eType, fVal );
47} 82}
48 83
49void Ast::addNode( AstNode::Type eType, bool bVal ) 84void Ast::addNode( AstNode::Type eType, bool bVal )
50{ 85{
51 addNode( new AstLeaf( eType, bVal ) ); 86 YYLTYPE none = {-1, -1, -1, -1};
87 addNode( none, eType, bVal );
52} 88}
53 89
54void Ast::addNode( AstNode::Type eType, const Bu::FString &sVal ) 90void Ast::addNode( AstNode::Type eType, const Bu::FString &sVal )
55{ 91{
56 addNode( new AstLeaf( eType, sVal ) ); 92 YYLTYPE none = {-1, -1, -1, -1};
93 addNode( none, eType, sVal );
57} 94}
58 95
59void Ast::addNode( AstNode::Type eType, const char *sVal ) 96void Ast::addNode( AstNode::Type eType, const char *sVal )
60{ 97{
61 addNode( new AstLeaf( eType, sVal ) ); 98 YYLTYPE none = {-1, -1, -1, -1};
99 addNode( none, eType, sVal );
62} 100}
63 101
64void Ast::addNode( AstNode *pNode ) 102void Ast::addNode( AstNode *pNode )
diff --git a/src/ast.h b/src/ast.h
index a4f9361..c62406b 100644
--- a/src/ast.h
+++ b/src/ast.h
@@ -19,6 +19,14 @@ public:
19 Ast(); 19 Ast();
20 virtual ~Ast(); 20 virtual ~Ast();
21 21
22 void addNode( struct YYLTYPE &loc, AstNode::Type eType );
23 void addNode( struct YYLTYPE &loc, AstNode::Type eType, int iVal );
24 void addNode( struct YYLTYPE &loc, AstNode::Type eType, float fVal );
25 void addNode( struct YYLTYPE &loc, AstNode::Type eType, bool bVal );
26 void addNode( struct YYLTYPE &loc, AstNode::Type eType,
27 const Bu::FString &sVal );
28 void addNode( struct YYLTYPE &loc, AstNode::Type eType, const char *sVal );
29
22 void addNode( AstNode::Type eType ); 30 void addNode( AstNode::Type eType );
23 void addNode( AstNode::Type eType, int iVal ); 31 void addNode( AstNode::Type eType, int iVal );
24 void addNode( AstNode::Type eType, float fVal ); 32 void addNode( AstNode::Type eType, float fVal );
diff --git a/src/astbranch.cpp b/src/astbranch.cpp
index a6aa21c..d247b30 100644
--- a/src/astbranch.cpp
+++ b/src/astbranch.cpp
@@ -1,7 +1,7 @@
1#include "astbranch.h" 1#include "astbranch.h"
2 2
3AstBranch::AstBranch( Type eType ) : 3AstBranch::AstBranch( const Location &loc, Type eType ) :
4 AstNode( eType ) 4 AstNode( loc, eType )
5{ 5{
6} 6}
7 7
diff --git a/src/astbranch.h b/src/astbranch.h
index 5ff8606..b582b9f 100644
--- a/src/astbranch.h
+++ b/src/astbranch.h
@@ -10,7 +10,7 @@ class AstBranch : public AstNode
10public: 10public:
11 typedef Bu::List<AstNode *> NodeList; 11 typedef Bu::List<AstNode *> NodeList;
12 typedef Bu::List<NodeList> BranchList; 12 typedef Bu::List<NodeList> BranchList;
13 AstBranch( Type eType ); 13 AstBranch( const Location &loc, Type eType );
14 virtual ~AstBranch(); 14 virtual ~AstBranch();
15 15
16 void addBranch(); 16 void addBranch();
diff --git a/src/astleaf.cpp b/src/astleaf.cpp
index 62773ce..5182a58 100644
--- a/src/astleaf.cpp
+++ b/src/astleaf.cpp
@@ -1,41 +1,41 @@
1#include "astleaf.h" 1#include "astleaf.h"
2 2
3AstLeaf::AstLeaf( Type eType ) : 3AstLeaf::AstLeaf( const Location &loc, Type eType ) :
4 AstNode( eType ), 4 AstNode( loc, eType ),
5 sVal( NULL ) 5 sVal( NULL )
6{ 6{
7} 7}
8 8
9AstLeaf::AstLeaf( Type eType, int iNew ) : 9AstLeaf::AstLeaf( const Location &loc, Type eType, int iNew ) :
10 AstNode( eType ), 10 AstNode( loc, eType ),
11 sVal( NULL ) 11 sVal( NULL )
12{ 12{
13 setIntValue( iNew ); 13 setIntValue( iNew );
14} 14}
15 15
16AstLeaf::AstLeaf( Type eType, float fNew ) : 16AstLeaf::AstLeaf( const Location &loc, Type eType, float fNew ) :
17 AstNode( eType ), 17 AstNode( loc, eType ),
18 sVal( NULL ) 18 sVal( NULL )
19{ 19{
20 setFloatValue( fNew ); 20 setFloatValue( fNew );
21} 21}
22 22
23AstLeaf::AstLeaf( Type eType, bool bNew ) : 23AstLeaf::AstLeaf( const Location &loc, Type eType, bool bNew ) :
24 AstNode( eType ), 24 AstNode( loc, eType ),
25 sVal( NULL ) 25 sVal( NULL )
26{ 26{
27 setBoolValue( bNew ); 27 setBoolValue( bNew );
28} 28}
29 29
30AstLeaf::AstLeaf( Type eType, const Bu::FString &sNew ) : 30AstLeaf::AstLeaf( const Location &loc, Type eType, const Bu::FString &sNew ) :
31 AstNode( eType ), 31 AstNode( loc, eType ),
32 sVal( NULL ) 32 sVal( NULL )
33{ 33{
34 setStrValue( sNew ); 34 setStrValue( sNew );
35} 35}
36 36
37AstLeaf::AstLeaf( Type eType, const char *sNew ) : 37AstLeaf::AstLeaf( const Location &loc, Type eType, const char *sNew ) :
38 AstNode( eType ), 38 AstNode( loc, eType ),
39 sVal( NULL ) 39 sVal( NULL )
40{ 40{
41 setStrValue( sNew ); 41 setStrValue( sNew );
diff --git a/src/astleaf.h b/src/astleaf.h
index 0c8911b..cdcb2ae 100644
--- a/src/astleaf.h
+++ b/src/astleaf.h
@@ -8,12 +8,12 @@
8class AstLeaf : public AstNode 8class AstLeaf : public AstNode
9{ 9{
10public: 10public:
11 AstLeaf( Type eType ); 11 AstLeaf( const Location &loc, Type eType );
12 AstLeaf( Type eType, int iNew ); 12 AstLeaf( const Location &loc, Type eType, int iNew );
13 AstLeaf( Type eType, float fNew ); 13 AstLeaf( const Location &loc, Type eType, float fNew );
14 AstLeaf( Type eType, bool bNew ); 14 AstLeaf( const Location &loc, Type eType, bool bNew );
15 AstLeaf( Type eType, const Bu::FString &sNew ); 15 AstLeaf( const Location &loc, Type eType, const Bu::FString &sNew );
16 AstLeaf( Type eType, const char *sNew ); 16 AstLeaf( const Location &loc, Type eType, const char *sNew );
17 virtual ~AstLeaf(); 17 virtual ~AstLeaf();
18 18
19 void setIntValue( int iNew ); 19 void setIntValue( int iNew );
diff --git a/src/astnode.cpp b/src/astnode.cpp
index 5adb3ee..87b9383 100644
--- a/src/astnode.cpp
+++ b/src/astnode.cpp
@@ -2,8 +2,9 @@
2#include "astleaf.h" 2#include "astleaf.h"
3#include "astbranch.h" 3#include "astbranch.h"
4 4
5AstNode::AstNode( Type eType ) : 5AstNode::AstNode( const Location &loc, Type eType ) :
6 eType( eType ) 6 eType( eType ),
7 loc( loc )
7{ 8{
8} 9}
9 10
diff --git a/src/astnode.h b/src/astnode.h
index 6ade25b..843dba8 100644
--- a/src/astnode.h
+++ b/src/astnode.h
@@ -2,6 +2,7 @@
2#define AST_NODE_H 2#define AST_NODE_H
3 3
4#include "bu/formatter.h" 4#include "bu/formatter.h"
5#include "location.h"
5 6
6class AstNode 7class AstNode
7{ 8{
@@ -91,7 +92,7 @@ public:
91 typeDataMask = 0x0F0000 92 typeDataMask = 0x0F0000
92 }; 93 };
93public: 94public:
94 AstNode( Type eType ); 95 AstNode( const Location &loc, Type eType );
95 virtual ~AstNode(); 96 virtual ~AstNode();
96 97
97 Type getType() const { return eType; } 98 Type getType() const { return eType; }
@@ -100,6 +101,7 @@ public:
100 101
101private: 102private:
102 Type eType; 103 Type eType;
104 Location loc;
103}; 105};
104 106
105Bu::Formatter &operator<<( Bu::Formatter &f, const AstNode &n ); 107Bu::Formatter &operator<<( Bu::Formatter &f, const AstNode &n );
diff --git a/src/build.y b/src/build.y
index 3e9c8fd..8cfc526 100644
--- a/src/build.y
+++ b/src/build.y
@@ -147,19 +147,19 @@ include: TOK_INCLUDE STRING ';' { bld.include( $2, yyscanner, &yylloc ); }
147 * data related 147 * data related
148 */ 148 */
149 149
150string: STRING { bld.xAst.addNode( AstNode::typeString, $1 ); } 150string: STRING { bld.xAst.addNode( @1, AstNode::typeString, $1 ); }
151 ; 151 ;
152 152
153int: INT { bld.xAst.addNode( AstNode::typeInt, $1 ); } 153int: INT { bld.xAst.addNode( @1, AstNode::typeInt, $1 ); }
154 ; 154 ;
155 155
156float: FLOAT { bld.xAst.addNode( AstNode::typeFloat, $1 ); } 156float: FLOAT { bld.xAst.addNode( @1, AstNode::typeFloat, $1 ); }
157 ; 157 ;
158 158
159bool: BOOL { bld.xAst.addNode( AstNode::typeBool, (bool)$1 ); } 159bool: BOOL { bld.xAst.addNode( @1, AstNode::typeBool, (bool)$1 ); }
160 ; 160 ;
161 161
162null: TOK_NULL { bld.xAst.addNode( AstNode::typeNull ); } 162null: TOK_NULL { bld.xAst.addNode( @1, AstNode::typeNull ); }
163 163
164literal: string 164literal: string
165 | int 165 | int
@@ -168,7 +168,7 @@ literal: string
168 | null 168 | null
169 ; 169 ;
170 170
171variable: UNDEF /*VARIABLE*/ { bld.xAst.addNode( AstNode::typeVariable, $1 ); } 171variable: UNDEF { bld.xAst.addNode( @1, AstNode::typeVariable, $1 ); }
172 172
173list_core: 173list_core:
174 | { bld.xAst.openBranch(); } expr 174 | { bld.xAst.openBranch(); } expr
@@ -176,7 +176,7 @@ list_core:
176 ; 176 ;
177 177
178list: '[' { 178list: '[' {
179 bld.xAst.addNode( AstNode::typeList ); 179 bld.xAst.addNode( @1, AstNode::typeList );
180 } list_core ']' { 180 } list_core ']' {
181 bld.xAst.closeNode(); 181 bld.xAst.closeNode();
182 } 182 }
@@ -199,9 +199,9 @@ value: value_core value_mods
199 * misc global things 199 * misc global things
200 */ 200 */
201 201
202notify: TOK_ERROR STRING ';' { bld.xAst.addNode( AstNode::typeError, $2 ); } 202notify: TOK_ERROR STRING ';' { bld.xAst.addNode( @$,AstNode::typeError, $2 ); }
203 | TOK_WARNING STRING ';' { bld.xAst.addNode( AstNode::typeWarning, $2 ); } 203 | TOK_WARNING STRING ';' { bld.xAst.addNode( @$, AstNode::typeWarning, $2 ); }
204 | TOK_NOTICE STRING ';' { bld.xAst.addNode( AstNode::typeNotice, $2 ); } 204 | TOK_NOTICE STRING ';' { bld.xAst.addNode( @$, AstNode::typeNotice, $2 ); }
205 ; 205 ;
206/* 206/*
207set_rhs: '=' { bld.xAst.addNode( AstNode::typeOpEq ); } value 207set_rhs: '=' { bld.xAst.addNode( AstNode::typeOpEq ); } value
@@ -218,7 +218,7 @@ set: TOK_SET {
218 ;*/ 218 ;*/
219 219
220unset: TOK_UNSET { 220unset: TOK_UNSET {
221 bld.xAst.addNode( AstNode::typeUnset ); 221 bld.xAst.addNode( @1, AstNode::typeUnset );
222 bld.xAst.openBranch(); 222 bld.xAst.openBranch();
223 } variable ';' { 223 } variable ';' {
224 bld.xAst.closeNode(); 224 bld.xAst.closeNode();
@@ -230,7 +230,7 @@ export_rhs: '=' value
230 ; 230 ;
231 231
232export: TOK_EXPORT { 232export: TOK_EXPORT {
233 bld.xAst.addNode( AstNode::typeExport ); 233 bld.xAst.addNode( @1, AstNode::typeExport );
234 bld.xAst.openBranch(); 234 bld.xAst.openBranch();
235 } variable export_rhs ';' { 235 } variable export_rhs ';' {
236 bld.xAst.closeNode(); 236 bld.xAst.closeNode();
@@ -246,37 +246,37 @@ func_param_list: { bld.xAst.openBranch(); } value
246 ; 246 ;
247 247
248function: UNDEF '(' { 248function: UNDEF '(' {
249 bld.xAst.addNode( AstNode::typeFunction ); 249 bld.xAst.addNode( @$, AstNode::typeFunction );
250 bld.xAst.openBranch(); 250 bld.xAst.openBranch();
251 bld.xAst.addNode( AstNode::typeString, $1 ); 251 bld.xAst.addNode( @$, AstNode::typeString, $1 );
252 } func_params ')' { 252 } func_params ')' {
253 bld.xAst.closeNode(); 253 bld.xAst.closeNode();
254 } 254 }
255 ; 255 ;
256 256
257function_no_input: UNDEF '(' { 257function_no_input: UNDEF '(' {
258 bld.xAst.addNode( AstNode::typeNull ); 258 bld.xAst.addNode( @$, AstNode::typeNull );
259 bld.xAst.addNode( AstNode::typeFunction ); 259 bld.xAst.addNode( @$, AstNode::typeFunction );
260 bld.xAst.openBranch(); 260 bld.xAst.openBranch();
261 bld.xAst.addNode( AstNode::typeString, $1 ); 261 bld.xAst.addNode( @$, AstNode::typeString, $1 );
262 } func_params ')' { 262 } func_params ')' {
263 bld.xAst.closeNode(); 263 bld.xAst.closeNode();
264 } 264 }
265 ; 265 ;
266 266
267requires: TOK_REQUIRES { 267requires: TOK_REQUIRES {
268 bld.xAst.addNode( AstNode::typeRequires ); 268 bld.xAst.addNode( @$, AstNode::typeRequires );
269 bld.xAst.openBranch(); 269 bld.xAst.openBranch();
270 } value ';' { 270 } value ';' {
271 bld.xAst.closeNode(); 271 bld.xAst.closeNode();
272 } 272 }
273 ; 273 ;
274 274
275type: TOK_STRING { bld.xAst.addNode( AstNode::typeTypeString ); } 275type: TOK_STRING { bld.xAst.addNode( @1, AstNode::typeTypeString ); }
276 | TOK_INT { bld.xAst.addNode( AstNode::typeTypeInt ); } 276 | TOK_INT { bld.xAst.addNode( @1, AstNode::typeTypeInt ); }
277 | TOK_FLOAT { bld.xAst.addNode( AstNode::typeTypeFloat ); } 277 | TOK_FLOAT { bld.xAst.addNode( @1, AstNode::typeTypeFloat ); }
278 | TOK_BOOL { bld.xAst.addNode( AstNode::typeTypeBool ); } 278 | TOK_BOOL { bld.xAst.addNode( @1, AstNode::typeTypeBool ); }
279 | TOK_VERSION { bld.xAst.addNode( AstNode::typeTypeVersion ); } 279 | TOK_VERSION { bld.xAst.addNode( @1, AstNode::typeTypeVersion ); }
280 ; 280 ;
281 281
282/* 282/*
@@ -286,67 +286,67 @@ type: TOK_STRING { bld.xAst.addNode( AstNode::typeTypeString ); }
286expr: value 286expr: value
287 | '(' expr ')' 287 | '(' expr ')'
288 | UNDEF '=' { 288 | UNDEF '=' {
289 bld.xAst.addNode( AstNode::typeVariableRef, $1 ); 289 bld.xAst.addNode( @$, AstNode::typeVariableRef, $1 );
290 } expr { 290 } expr {
291 bld.xAst.addNode( AstNode::typeOpEq ); 291 bld.xAst.addNode( @3, AstNode::typeOpEq );
292 } 292 }
293 | UNDEF OP_ADDSETP { 293 | UNDEF OP_ADDSETP {
294 bld.xAst.addNode( AstNode::typeVariableRef, $1 ); 294 bld.xAst.addNode( @$, AstNode::typeVariableRef, $1 );
295 } expr { 295 } expr {
296 bld.xAst.addNode( AstNode::typeOpPlusEq ); 296 bld.xAst.addNode( @3, AstNode::typeOpPlusEq );
297 } 297 }
298 | expr OP_CMPEQUAL expr 298 | expr OP_CMPEQUAL expr
299 { 299 {
300 bld.xAst.addNode( AstNode::typeCmpEq ); 300 bld.xAst.addNode( @$, AstNode::typeCmpEq );
301 } 301 }
302 | expr '<' expr 302 | expr '<' expr
303 { 303 {
304 bld.xAst.addNode( AstNode::typeCmpLt ); 304 bld.xAst.addNode( @$, AstNode::typeCmpLt );
305 } 305 }
306 | expr '>' expr 306 | expr '>' expr
307 { 307 {
308 bld.xAst.addNode( AstNode::typeCmpGt ); 308 bld.xAst.addNode( @$, AstNode::typeCmpGt );
309 } 309 }
310 | expr OP_INEQUAL expr 310 | expr OP_INEQUAL expr
311 { 311 {
312 bld.xAst.addNode( AstNode::typeCmpNe ); 312 bld.xAst.addNode( @$, AstNode::typeCmpNe );
313 } 313 }
314 | expr OP_LTEQUAL expr 314 | expr OP_LTEQUAL expr
315 { 315 {
316 bld.xAst.addNode( AstNode::typeCmpLtEq ); 316 bld.xAst.addNode( @$, AstNode::typeCmpLtEq );
317 } 317 }
318 | expr OP_GTEQUAL expr 318 | expr OP_GTEQUAL expr
319 { 319 {
320 bld.xAst.addNode( AstNode::typeCmpGtEq ); 320 bld.xAst.addNode( @$, AstNode::typeCmpGtEq );
321 } 321 }
322 | expr '+' expr 322 | expr '+' expr
323 { 323 {
324 bld.xAst.addNode( AstNode::typeOpPlus ); 324 bld.xAst.addNode( @$, AstNode::typeOpPlus );
325 } 325 }
326 | expr '-' expr 326 | expr '-' expr
327 { 327 {
328 bld.xAst.addNode( AstNode::typeOpMinus ); 328 bld.xAst.addNode( @$, AstNode::typeOpMinus );
329 } 329 }
330 | expr '*' expr 330 | expr '*' expr
331 { 331 {
332 bld.xAst.addNode( AstNode::typeOpMultiply ); 332 bld.xAst.addNode( @$, AstNode::typeOpMultiply );
333 } 333 }
334 | expr '/' expr 334 | expr '/' expr
335 { 335 {
336 bld.xAst.addNode( AstNode::typeOpDivide ); 336 bld.xAst.addNode( @$, AstNode::typeOpDivide );
337 } 337 }
338 | '-' expr %prec IINEG 338 | '-' expr %prec IINEG
339 { 339 {
340 bld.xAst.addNode( AstNode::typeOpNegate ); 340 bld.xAst.addNode( @$, AstNode::typeOpNegate );
341 } 341 }
342 | '!' expr %prec IINOT 342 | '!' expr %prec IINOT
343 { 343 {
344 bld.xAst.addNode( AstNode::typeOpNot ); 344 bld.xAst.addNode( @$, AstNode::typeOpNot );
345 } 345 }
346 ; 346 ;
347 347
348line_expr: { 348line_expr: {
349 bld.xAst.addNode( AstNode::typeExpr ); 349 bld.xAst.addNode( @$, AstNode::typeExpr );
350 bld.xAst.openBranch(); 350 bld.xAst.openBranch();
351 } expr ';' 351 } expr ';'
352 { 352 {
@@ -355,9 +355,9 @@ line_expr: {
355 ; 355 ;
356 356
357if_core: TOK_IF { 357if_core: TOK_IF {
358 bld.xAst.addNode( AstNode::typeIf ); 358 bld.xAst.addNode( @$, AstNode::typeIf );
359 bld.xAst.openBranch(); 359 bld.xAst.openBranch();
360// bld.xAst.addNode( AstNode::typeExpr ); 360// bld.xAst.addNode( @$, AstNode::typeExpr );
361// bld.xAst.openBranch(); 361// bld.xAst.openBranch();
362 } expr TOK_THEN { 362 } expr TOK_THEN {
363// bld.xAst.closeNode(); 363// bld.xAst.closeNode();
@@ -406,7 +406,7 @@ function_else:
406 */ 406 */
407 407
408for_base: TOK_FOR { 408for_base: TOK_FOR {
409 bld.xAst.addNode( AstNode::typeFor ); 409 bld.xAst.addNode( @$, AstNode::typeFor );
410 bld.xAst.openBranch(); 410 bld.xAst.openBranch();
411 } variable TOK_IN { 411 } variable TOK_IN {
412 bld.xAst.openBranch(); 412 bld.xAst.openBranch();
@@ -432,9 +432,9 @@ function_for: for_base '{' function_exprs '}' { bld.xAst.closeNode(); }
432 */ 432 */
433 433
434function_def: TOK_FUNCTION UNDEF { 434function_def: TOK_FUNCTION UNDEF {
435 bld.xAst.addNode( AstNode::typeFunctionDef ); 435 bld.xAst.addNode( @1, AstNode::typeFunctionDef );
436 bld.xAst.openBranch(); 436 bld.xAst.openBranch();
437 bld.xAst.addNode( AstNode::typeString, $2 ); 437 bld.xAst.addNode( @2, AstNode::typeString, $2 );
438 bld.xAst.openBranch(); 438 bld.xAst.openBranch();
439 } '(' param_defs ')' { 439 } '(' param_defs ')' {
440 bld.xAst.openBranch(); 440 bld.xAst.openBranch();
@@ -465,7 +465,7 @@ function_exprs:
465 ; 465 ;
466 466
467return: TOK_RETURN { 467return: TOK_RETURN {
468 bld.xAst.addNode( AstNode::typeReturn ); 468 bld.xAst.addNode( @$, AstNode::typeReturn );
469 bld.xAst.openBranch(); 469 bld.xAst.openBranch();
470 } expr { 470 } expr {
471 bld.xAst.closeNode(); 471 bld.xAst.closeNode();
@@ -477,9 +477,9 @@ return: TOK_RETURN {
477 */ 477 */
478 478
479action_def: TOK_ACTION STRING { 479action_def: TOK_ACTION STRING {
480 bld.xAst.addNode( AstNode::typeActionDef ); 480 bld.xAst.addNode( @$, AstNode::typeActionDef );
481 bld.xAst.openBranch(); 481 bld.xAst.openBranch();
482 bld.xAst.addNode( AstNode::typeString, $2 ); 482 bld.xAst.addNode( @1, AstNode::typeString, $2 );
483 bld.xAst.openBranch(); 483 bld.xAst.openBranch();
484 } '{' function_exprs '}' { 484 } '{' function_exprs '}' {
485 bld.xAst.closeNode(); 485 bld.xAst.closeNode();
@@ -491,7 +491,7 @@ action_def: TOK_ACTION STRING {
491 */ 491 */
492 492
493profile: TOK_PROFILE { 493profile: TOK_PROFILE {
494 bld.xAst.addNode( AstNode::typeProfile ); 494 bld.xAst.addNode( @$, AstNode::typeProfile );
495 bld.xAst.openBranch(); 495 bld.xAst.openBranch();
496 } string { 496 } string {
497 bld.xAst.openBranch(); 497 bld.xAst.openBranch();
@@ -518,7 +518,7 @@ profile_exprs:
518 */ 518 */
519 519
520target: TOK_TARGET { 520target: TOK_TARGET {
521 bld.xAst.addNode( AstNode::typeTarget ); 521 bld.xAst.addNode( @$, AstNode::typeTarget );
522 bld.xAst.openBranch(); 522 bld.xAst.openBranch();
523 } expr { 523 } expr {
524 bld.xAst.openBranch(); 524 bld.xAst.openBranch();
@@ -544,7 +544,7 @@ target_exprs:
544 ; 544 ;
545 545
546target_input: TOK_INPUT { 546target_input: TOK_INPUT {
547 bld.xAst.addNode( AstNode::typeInput ); 547 bld.xAst.addNode( @$, AstNode::typeInput );
548 bld.xAst.openBranch(); 548 bld.xAst.openBranch();
549 } expr ';' { 549 } expr ';' {
550 bld.xAst.closeNode(); 550 bld.xAst.closeNode();
@@ -552,7 +552,7 @@ target_input: TOK_INPUT {
552 ; 552 ;
553 553
554target_rule: TOK_RULE { 554target_rule: TOK_RULE {
555 bld.xAst.addNode( AstNode::typeRule ); 555 bld.xAst.addNode( @$, AstNode::typeRule );
556 bld.xAst.openBranch(); 556 bld.xAst.openBranch();
557 } string ';' { 557 } string ';' {
558 bld.xAst.closeNode(); 558 bld.xAst.closeNode();
@@ -560,13 +560,13 @@ target_rule: TOK_RULE {
560 ; 560 ;
561 561
562condition: TOK_CONDITION CONDITION ';' { 562condition: TOK_CONDITION CONDITION ';' {
563 bld.xAst.addNode( AstNode::typeCondition, $2 ); 563 bld.xAst.addNode( @$, AstNode::typeCondition, $2 );
564 } 564 }
565 | TOK_CONDITION TOK_ALWAYS ';'{ 565 | TOK_CONDITION TOK_ALWAYS ';'{
566 bld.xAst.addNode( AstNode::typeCondition, "always" ); 566 bld.xAst.addNode( @$, AstNode::typeCondition, "always" );
567 } 567 }
568 | TOK_CONDITION TOK_NEVER ';'{ 568 | TOK_CONDITION TOK_NEVER ';'{
569 bld.xAst.addNode( AstNode::typeCondition, "never" ); 569 bld.xAst.addNode( @$, AstNode::typeCondition, "never" );
570 } 570 }
571 ; 571 ;
572 572
@@ -575,7 +575,7 @@ condition: TOK_CONDITION CONDITION ';' {
575 */ 575 */
576 576
577rule: TOK_RULE { 577rule: TOK_RULE {
578 bld.xAst.addNode( AstNode::typeRuleDef ); 578 bld.xAst.addNode( @$, AstNode::typeRuleDef );
579 bld.xAst.openBranch(); 579 bld.xAst.openBranch();
580 } string { 580 } string {
581 bld.xAst.openBranch(); 581 bld.xAst.openBranch();
@@ -602,18 +602,18 @@ rule_input_func: function
602 /* In this case, when the input is just a string, 602 /* In this case, when the input is just a string,
603 lets actually turn it into a call to the matches function. 603 lets actually turn it into a call to the matches function.
604 */ 604 */
605 bld.xAst.addNode( AstNode::typeFunction ); 605 bld.xAst.addNode( @1, AstNode::typeFunction );
606 bld.xAst.openBranch(); 606 bld.xAst.openBranch();
607 bld.xAst.addNode( AstNode::typeString, "matches" ); 607 bld.xAst.addNode( @1, AstNode::typeString, "matches" );
608 bld.xAst.openBranch(); 608 bld.xAst.openBranch();
609 bld.xAst.addNode( AstNode::typeString, $1 ); 609 bld.xAst.addNode( @1, AstNode::typeString, $1 );
610 bld.xAst.closeNode(); 610 bld.xAst.closeNode();
611 } 611 }
612/* | string */ 612/* | string */
613 ; 613 ;
614 614
615rule_input: TOK_INPUT { 615rule_input: TOK_INPUT {
616 bld.xAst.addNode( AstNode::typeInput ); 616 bld.xAst.addNode( @$, AstNode::typeInput );
617 bld.xAst.openBranch(); 617 bld.xAst.openBranch();
618 } rule_input_func ';' { 618 } rule_input_func ';' {
619 bld.xAst.closeNode(); 619 bld.xAst.closeNode();
@@ -621,7 +621,7 @@ rule_input: TOK_INPUT {
621 ; 621 ;
622 622
623output: TOK_OUTPUT { 623output: TOK_OUTPUT {
624 bld.xAst.addNode( AstNode::typeOutput ); 624 bld.xAst.addNode( @$, AstNode::typeOutput );
625 bld.xAst.openBranch(); 625 bld.xAst.openBranch();
626 } value ';' { 626 } value ';' {
627 bld.xAst.closeNode(); 627 bld.xAst.closeNode();
@@ -632,7 +632,7 @@ output: TOK_OUTPUT {
632 * config 632 * config
633 */ 633 */
634config: TOK_CONFIG { 634config: TOK_CONFIG {
635 bld.xAst.addNode( AstNode::typeConfig ); 635 bld.xAst.addNode( @$, AstNode::typeConfig );
636 bld.xAst.openBranch(); 636 bld.xAst.openBranch();
637 } string { 637 } string {
638 bld.xAst.openBranch(); 638 bld.xAst.openBranch();
@@ -640,7 +640,7 @@ config: TOK_CONFIG {
640 bld.xAst.closeNode(); 640 bld.xAst.closeNode();
641 } 641 }
642 | TOK_AUTO TOK_CONFIG { 642 | TOK_AUTO TOK_CONFIG {
643 bld.xAst.addNode( AstNode::typeAutoConfig ); 643 bld.xAst.addNode( @$, AstNode::typeAutoConfig );
644 bld.xAst.openBranch(); 644 bld.xAst.openBranch();
645 } string { 645 } string {
646 bld.xAst.openBranch(); 646 bld.xAst.openBranch();
@@ -648,7 +648,7 @@ config: TOK_CONFIG {
648 bld.xAst.closeNode(); 648 bld.xAst.closeNode();
649 } 649 }
650 | TOK_GLOBAL TOK_CONFIG { 650 | TOK_GLOBAL TOK_CONFIG {
651 bld.xAst.addNode( AstNode::typeGlobalConfig ); 651 bld.xAst.addNode( @$, AstNode::typeGlobalConfig );
652 bld.xAst.openBranch(); 652 bld.xAst.openBranch();
653 } string { 653 } string {
654 bld.xAst.openBranch(); 654 bld.xAst.openBranch();
@@ -667,12 +667,12 @@ config_exprs:
667 ; 667 ;
668 668
669display: TOK_DISPLAY STRING ';' { 669display: TOK_DISPLAY STRING ';' {
670 bld.xAst.addNode( AstNode::typeDisplay, $2 ); 670 bld.xAst.addNode( @$, AstNode::typeDisplay, $2 );
671 } 671 }
672 ; 672 ;
673 673
674config_type: TOK_TYPE { 674config_type: TOK_TYPE {
675 bld.xAst.addNode( AstNode::typeType ); 675 bld.xAst.addNode( @$, AstNode::typeType );
676 bld.xAst.openBranch(); 676 bld.xAst.openBranch();
677 } type ';' { 677 } type ';' {
678 bld.xAst.closeNode(); 678 bld.xAst.closeNode();
@@ -680,7 +680,7 @@ config_type: TOK_TYPE {
680 ; 680 ;
681 681
682default: TOK_DEFAULT { 682default: TOK_DEFAULT {
683 bld.xAst.addNode( AstNode::typeDefault ); 683 bld.xAst.addNode( @$, AstNode::typeDefault );
684 bld.xAst.openBranch(); 684 bld.xAst.openBranch();
685 } literal ';' { 685 } literal ';' {
686 bld.xAst.closeNode(); 686 bld.xAst.closeNode();
@@ -691,7 +691,7 @@ value_key_val: value ';'
691 | '{' function_exprs '}' /* inline function */ 691 | '{' function_exprs '}' /* inline function */
692 692
693value_key: TOK_VALUE { 693value_key: TOK_VALUE {
694 bld.xAst.addNode( AstNode::typeValue ); 694 bld.xAst.addNode( @$, AstNode::typeValue );
695 bld.xAst.openBranch(); 695 bld.xAst.openBranch();
696 } value_key_val { 696 } value_key_val {
697 bld.xAst.closeNode(); 697 bld.xAst.closeNode();
@@ -699,7 +699,7 @@ value_key: TOK_VALUE {
699 ; 699 ;
700 700
701allow: TOK_ALLOW { 701allow: TOK_ALLOW {
702 bld.xAst.addNode( AstNode::typeAllow ); 702 bld.xAst.addNode( @$, AstNode::typeAllow );
703 bld.xAst.openBranch(); 703 bld.xAst.openBranch();
704 } value ';' { 704 } value ';' {
705 bld.xAst.closeNode(); 705 bld.xAst.closeNode();
@@ -707,9 +707,9 @@ allow: TOK_ALLOW {
707 ; 707 ;
708 708
709cache: TOK_CACHE TOK_ALWAYS ';' 709cache: TOK_CACHE TOK_ALWAYS ';'
710 { bld.xAst.addNode( AstNode::typeCache, true ); } 710 { bld.xAst.addNode( @$, AstNode::typeCache, true ); }
711 | TOK_CACHE TOK_NEVER ';' 711 | TOK_CACHE TOK_NEVER ';'
712 { bld.xAst.addNode( AstNode::typeCache, false ); } 712 { bld.xAst.addNode( @$, AstNode::typeCache, false ); }
713 ; 713 ;
714 714
715/* 715/*
@@ -717,9 +717,9 @@ cache: TOK_CACHE TOK_ALWAYS ';'
717 */ 717 */
718process_target: PROFILE 718process_target: PROFILE
719 { 719 {
720 bld.xAst.addNode( AstNode::typeProcessTarget ); 720 bld.xAst.addNode( @$, AstNode::typeProcessTarget );
721 bld.xAst.openBranch(); 721 bld.xAst.openBranch();
722 bld.xAst.addNode( AstNode::typeString, $1 ); 722 bld.xAst.addNode( @$, AstNode::typeString, $1 );
723 bld.xAst.openBranch(); 723 bld.xAst.openBranch();
724 } value ';' { 724 } value ';' {
725 bld.xAst.closeNode(); 725 bld.xAst.closeNode();
@@ -728,7 +728,7 @@ process_target: PROFILE
728 728
729tag: TOK_TAG 729tag: TOK_TAG
730 { 730 {
731 bld.xAst.addNode( AstNode::typeTag ); 731 bld.xAst.addNode( @$, AstNode::typeTag );
732 bld.xAst.openBranch(); 732 bld.xAst.openBranch();
733 } value ';' { 733 } value ';' {
734 bld.xAst.closeNode(); 734 bld.xAst.closeNode();
diff --git a/src/location.cpp b/src/location.cpp
new file mode 100644
index 0000000..03b8b43
--- /dev/null
+++ b/src/location.cpp
@@ -0,0 +1,35 @@
1#include "location.h"
2#include "build.tab.h"
3
4Location::Location() :
5 sFile("none"),
6 iStartRow( -1 ),
7 iStartCol( -1 ),
8 iEndRow( -1 ),
9 iEndCol( -1 )
10{
11}
12
13Location::Location( struct YYLTYPE &loc ) :
14 sFile("???"),
15 iStartRow( loc.first_line ),
16 iStartCol( loc.first_column ),
17 iEndRow( loc.last_line ),
18 iEndCol( loc.last_column )
19{
20}
21
22Location::Location( const Bu::FString &sFile, int iStartRow, int iStartCol,
23 int iEndRow, int iEndCol ) :
24 sFile( sFile ),
25 iStartRow( iStartRow ),
26 iStartCol( iStartCol ),
27 iEndRow( iEndRow ),
28 iEndCol( iEndCol )
29{
30}
31
32Location::~Location()
33{
34}
35
diff --git a/src/location.h b/src/location.h
new file mode 100644
index 0000000..76699e3
--- /dev/null
+++ b/src/location.h
@@ -0,0 +1,23 @@
1#ifndef LOCATION_H
2#define LOCATION_H
3
4#include <bu/fstring.h>
5
6class Location
7{
8public:
9 Location();
10 Location( struct YYLTYPE &loc );
11 Location( const Bu::FString &sFile, int iStartRow, int iStartCol,
12 int iEndRow, int iEndCol );
13 virtual ~Location();
14
15private:
16 const Bu::FString sFile;
17 int iStartRow;
18 int iStartCol;
19 int iEndRow;
20 int iEndCol;
21};
22
23#endif