diff options
| author | Mike Buland <eichlan@xagasoft.com> | 2009-12-21 18:04:02 +0000 |
|---|---|---|
| committer | Mike Buland <eichlan@xagasoft.com> | 2009-12-21 18:04:02 +0000 |
| commit | fb28f6800864176be2ffca29e8e664b641f33170 (patch) | |
| tree | ba9180ac442939edc4eacbe1fdae93c5a7f87cee /src/buildparser.cpp | |
| parent | 51e21a316be6e052251b3dfc7d671061ebd67cee (diff) | |
| download | build-fb28f6800864176be2ffca29e8e664b641f33170.tar.gz build-fb28f6800864176be2ffca29e8e664b641f33170.tar.bz2 build-fb28f6800864176be2ffca29e8e664b641f33170.tar.xz build-fb28f6800864176be2ffca29e8e664b641f33170.zip | |
m3 is copied into trunk, we should be good to go, now.
Diffstat (limited to '')
| -rw-r--r-- | src/buildparser.cpp | 127 |
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" | ||
| 6 | using Bu::sio; | ||
| 7 | |||
| 8 | BuildParser::BuildParser( Ast &rAst ) : | ||
| 9 | xAst( rAst ) | ||
| 10 | { | ||
| 11 | lIncludePaths.append("./"); | ||
| 12 | } | ||
| 13 | |||
| 14 | BuildParser::~BuildParser() | ||
| 15 | { | ||
| 16 | } | ||
| 17 | |||
| 18 | int build_parse( yyscan_t yyscanner, BuildParser &bld ); | ||
| 19 | |||
| 20 | void 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 | |||
| 38 | bool 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 | |||
| 51 | bool 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 | |||
| 62 | void 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 | |||
| 107 | void 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 | |||
| 115 | void 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 | |||
| 123 | void BuildParser::addIncludePath( const Bu::FString &sPath ) | ||
| 124 | { | ||
| 125 | lIncludePaths.append( sPath + "/" ); | ||
| 126 | } | ||
| 127 | |||
