aboutsummaryrefslogtreecommitdiff
path: root/src/buildparser.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/buildparser.cpp')
-rw-r--r--src/buildparser.cpp127
1 files changed, 127 insertions, 0 deletions
diff --git a/src/buildparser.cpp b/src/buildparser.cpp
new file mode 100644
index 0000000..e391523
--- /dev/null
+++ b/src/buildparser.cpp
@@ -0,0 +1,127 @@
1#include "buildparser.h"
2#include "ast.h"
3#include "build.yy.h"
4
5#include "bu/sio.h"
6using Bu::sio;
7
8BuildParser::BuildParser( Ast &rAst ) :
9 xAst( rAst )
10{
11 lIncludePaths.append("./");
12}
13
14BuildParser::~BuildParser()
15{
16}
17
18int build_parse( yyscan_t yyscanner, BuildParser &bld );
19
20void BuildParser::load( const Bu::FString &sFile )
21{
22 yyscan_t scanner;
23
24 sFilename.push( sFile );
25 FILE *fIn = fopen( sFile.getStr(), "rt" );
26 build_lex_init( &scanner );
27 // build_set_debug( true, scanner );
28 build_set_in( fIn, scanner );
29
30 build_parse( scanner, *this );
31
32 build_lex_destroy( scanner );
33 fclose( fIn );
34
35 // Bu::sio << xAst;
36}
37
38bool BuildParser::isKeyword( const Bu::FString &sStr )
39{
40 if( sStr == "important" )
41 return true;
42 if( sStr == "normal" )
43 return true;
44 if( sStr == "hidden" )
45 return true;
46 if( sStr == "autogenerated" )
47 return true;
48 return false;
49}
50
51bool BuildParser::isCond( const Bu::FString &sStr )
52{
53 if( sStr == "filetime" )
54 return true;
55 if( sStr == "always" )
56 return true;
57 if( sStr == "never" )
58 return true;
59 return false;
60}
61
62void BuildParser::include( const Bu::FString &sStr, void *scanner, YYLTYPE *loc )
63{
64 for( StrList::iterator pi = lIncludePaths.begin(); pi; pi++ )
65 {
66 FILE *fIn = fopen( (*pi + sStr).getStr(), "rt" );
67 if( fIn == NULL )
68 {
69 continue;
70 }
71 sFilename.push( sStr );
72 sLocation.push( *loc );
73 loc->first_line = loc->last_line = 1;
74 loc->first_column = loc->last_column = 0;
75 build_push_buffer_state(
76 build__create_buffer( fIn, YY_READ_BUF_SIZE, scanner ),
77 scanner
78 );
79 Bu::FString::const_iterator i = sStr.find('/');
80 if( i )
81 {
82 for(;;)
83 {
84 Bu::FString::const_iterator j = i.find('/');
85 if( !j )
86 break;
87 i = j+1;
88 }
89 sio << "Hey, found it from here: " << sStr.getSubStr( sStr.begin(), i ) << sio.nl;
90 xAst.addNode( AstNode::typePushPrefix, sStr.getSubStr( sStr.begin(), i ) );
91 }
92 else
93 {
94 xAst.addNode( AstNode::typePushPrefix, "" );
95 }
96 return;
97 }
98 Bu::FString msg("Could not open include file: ");
99 msg += sStr;
100 error(
101 loc->first_line, loc->last_line,
102 loc->first_column, loc->last_column,
103 msg
104 );
105}
106
107void BuildParser::endInclude( YYLTYPE *loc )
108{
109 sFilename.pop();
110 memcpy( loc, &sLocation.peek(), sizeof(YYLTYPE) );
111 sLocation.pop();
112 xAst.addNode( AstNode::typePopPrefix );
113}
114
115void BuildParser::error( int iLine1, int iLine2, int iCol1, int iCol2,
116 const Bu::FString &sMsg )
117{
118 throw Bu::ExceptionBase("%s: %d-%d:%d-%d: %s",
119 sFilename.peek().getStr(), iLine1, iLine2, iCol1, iCol2, sMsg.getStr()
120 );
121}
122
123void BuildParser::addIncludePath( const Bu::FString &sPath )
124{
125 lIncludePaths.append( sPath + "/" );
126}
127