diff options
Diffstat (limited to '')
| -rw-r--r-- | src/builder.cpp | 255 |
1 files changed, 234 insertions, 21 deletions
diff --git a/src/builder.cpp b/src/builder.cpp index 70be725..4d377a8 100644 --- a/src/builder.cpp +++ b/src/builder.cpp | |||
| @@ -3,8 +3,8 @@ | |||
| 3 | #include "performfactory.h" | 3 | #include "performfactory.h" |
| 4 | #include "targetfactory.h" | 4 | #include "targetfactory.h" |
| 5 | #include "action.h" | 5 | #include "action.h" |
| 6 | 6 | #include "build.h" | |
| 7 | subExceptionDef( BuildException ); | 7 | #include "rule.h" |
| 8 | 8 | ||
| 9 | Builder::Builder() : | 9 | Builder::Builder() : |
| 10 | fFunction( FunctionFactory::getInstance() ), | 10 | fFunction( FunctionFactory::getInstance() ), |
| @@ -20,13 +20,15 @@ Builder::~Builder() | |||
| 20 | void yyparse( Builder &bld ); | 20 | void yyparse( Builder &bld ); |
| 21 | extern int yydebug; | 21 | extern int yydebug; |
| 22 | 22 | ||
| 23 | void Builder::load( const std::string &sFile ) | 23 | Build *Builder::load( const std::string &sFile ) |
| 24 | { | 24 | { |
| 25 | file = sFile; | 25 | file = sFile; |
| 26 | scanBegin(); | 26 | scanBegin(); |
| 27 | //yydebug = 1; | 27 | //yydebug = 1; |
| 28 | yyparse( *this ); | 28 | yyparse( *this ); |
| 29 | scanEnd(); | 29 | scanEnd(); |
| 30 | |||
| 31 | return genBuild(); | ||
| 30 | } | 32 | } |
| 31 | 33 | ||
| 32 | void Builder::error( YYLTYPE *locp, const char *msg ) | 34 | void Builder::error( YYLTYPE *locp, const char *msg ) |
| @@ -52,6 +54,47 @@ bool Builder::isTarget( const char *sType ) | |||
| 52 | { | 54 | { |
| 53 | return fTarget.hasPlugin( sType ); | 55 | return fTarget.hasPlugin( sType ); |
| 54 | } | 56 | } |
| 57 | |||
| 58 | void Builder::newTarget() | ||
| 59 | { | ||
| 60 | lTargetTmp.push_back( TargetTmp(lTmp, TargetInfo()) ); | ||
| 61 | } | ||
| 62 | |||
| 63 | void Builder::setTargetRule( const char *sRule ) | ||
| 64 | { | ||
| 65 | lTargetTmp.back().second.sRule = sRule; | ||
| 66 | } | ||
| 67 | |||
| 68 | void Builder::setTargetPrefix( const char *sPrefix ) | ||
| 69 | { | ||
| 70 | lTargetTmp.back().second.sPrefix = sPrefix; | ||
| 71 | } | ||
| 72 | |||
| 73 | void Builder::setTargetType( const char *sType ) | ||
| 74 | { | ||
| 75 | lTargetTmp.back().second.sType = sType; | ||
| 76 | } | ||
| 77 | |||
| 78 | void Builder::addTargetInput() | ||
| 79 | { | ||
| 80 | lTargetTmp.back().second.lInput.insert( | ||
| 81 | lTargetTmp.back().second.lInput.end(), | ||
| 82 | lTmp.begin(), lTmp.end() | ||
| 83 | ); | ||
| 84 | } | ||
| 85 | |||
| 86 | void Builder::addTargetRequires() | ||
| 87 | { | ||
| 88 | lTargetTmp.back().second.lRequires.insert( | ||
| 89 | lTargetTmp.back().second.lRequires.end(), | ||
| 90 | lTmp.begin(), lTmp.end() | ||
| 91 | ); | ||
| 92 | } | ||
| 93 | |||
| 94 | void Builder::addTargetSet( const char *sVar, const char *sVal, int nHow ) | ||
| 95 | { | ||
| 96 | lTargetTmp.back().second.lVar.push_back( SetVar( sVar, sVal, nHow ) ); | ||
| 97 | } | ||
| 55 | 98 | ||
| 56 | // | 99 | // |
| 57 | // Function functions | 100 | // Function functions |
| @@ -71,6 +114,9 @@ void Builder::addFunctionParam( const char *sParam ) | |||
| 71 | pTmpFunc->addParam( sParam ); | 114 | pTmpFunc->addParam( sParam ); |
| 72 | } | 115 | } |
| 73 | 116 | ||
| 117 | // | ||
| 118 | // List functions | ||
| 119 | // | ||
| 74 | void Builder::newList() | 120 | void Builder::newList() |
| 75 | { | 121 | { |
| 76 | lTmp.clear(); | 122 | lTmp.clear(); |
| @@ -86,11 +132,16 @@ void Builder::addListFunc() | |||
| 86 | lTmp.push_back( BuildListItem("", pTmpFunc ) ); | 132 | lTmp.push_back( BuildListItem("", pTmpFunc ) ); |
| 87 | } | 133 | } |
| 88 | 134 | ||
| 89 | StringList Builder::buildToStringList( Builder::BuildList &lSrc, StringList &lIn ) | 135 | void Builder::filterList() |
| 136 | { | ||
| 137 | printf("Filters aren't done yet.\n"); | ||
| 138 | } | ||
| 139 | |||
| 140 | StringList Builder::buildToStringList( const BuildList &lSrc, const StringList &lIn ) | ||
| 90 | { | 141 | { |
| 91 | StringList lOut; | 142 | StringList lOut; |
| 92 | 143 | ||
| 93 | for( BuildList::iterator i = lSrc.begin(); i != lSrc.end(); i++ ) | 144 | for( BuildList::const_iterator i = lSrc.begin(); i != lSrc.end(); i++ ) |
| 94 | { | 145 | { |
| 95 | if( (*i).second ) | 146 | if( (*i).second ) |
| 96 | { | 147 | { |
| @@ -106,6 +157,46 @@ StringList Builder::buildToStringList( Builder::BuildList &lSrc, StringList &lIn | |||
| 106 | } | 157 | } |
| 107 | 158 | ||
| 108 | // | 159 | // |
| 160 | // Rule functions | ||
| 161 | // | ||
| 162 | void Builder::addRule( const char *sName ) | ||
| 163 | { | ||
| 164 | lRuleTmp.push_back( RuleInfo() ); | ||
| 165 | lRuleTmp.back().sName = sName; | ||
| 166 | } | ||
| 167 | |||
| 168 | void Builder::addRuleMatches() | ||
| 169 | { | ||
| 170 | lRuleTmp.back().pMatches = pTmpFunc; | ||
| 171 | } | ||
| 172 | |||
| 173 | void Builder::addRuleProduces() | ||
| 174 | { | ||
| 175 | lRuleTmp.back().lProduces.insert( | ||
| 176 | lRuleTmp.back().lProduces.end(), | ||
| 177 | lTmp.begin(), lTmp.end() | ||
| 178 | ); | ||
| 179 | } | ||
| 180 | |||
| 181 | void Builder::addRuleRequires() | ||
| 182 | { | ||
| 183 | lRuleTmp.back().lRequires.insert( | ||
| 184 | lRuleTmp.back().lRequires.end(), | ||
| 185 | lTmp.begin(), lTmp.end() | ||
| 186 | ); | ||
| 187 | } | ||
| 188 | |||
| 189 | void Builder::addRuleInputFilter() | ||
| 190 | { | ||
| 191 | lRuleTmp.back().lFilter.push_back( pTmpFunc ); | ||
| 192 | } | ||
| 193 | |||
| 194 | void Builder::addRulePerform() | ||
| 195 | { | ||
| 196 | lRuleTmp.back().lPerform.push_back( pTmpPerform ); | ||
| 197 | } | ||
| 198 | |||
| 199 | // | ||
| 109 | // Perform functions | 200 | // Perform functions |
| 110 | // | 201 | // |
| 111 | bool Builder::isPerform( const char *sPerf ) | 202 | bool Builder::isPerform( const char *sPerf ) |
| @@ -115,10 +206,12 @@ bool Builder::isPerform( const char *sPerf ) | |||
| 115 | 206 | ||
| 116 | void Builder::newPerform( const char *sName ) | 207 | void Builder::newPerform( const char *sName ) |
| 117 | { | 208 | { |
| 209 | pTmpPerform = fPerform.instantiate( sName ); | ||
| 118 | } | 210 | } |
| 119 | 211 | ||
| 120 | void Builder::addPerformParam( const char *sParam ) | 212 | void Builder::addPerformParam( const char *sParam ) |
| 121 | { | 213 | { |
| 214 | pTmpPerform->addParam( sParam ); | ||
| 122 | } | 215 | } |
| 123 | 216 | ||
| 124 | // | 217 | // |
| @@ -140,6 +233,14 @@ void Builder::addCommand( int nType ) | |||
| 140 | } | 233 | } |
| 141 | 234 | ||
| 142 | // | 235 | // |
| 236 | // Global variable functions | ||
| 237 | // | ||
| 238 | void Builder::addGlobalSet( const char *sVar, const char *sValue, int nHow ) | ||
| 239 | { | ||
| 240 | lGlobalVars.push_back( SetVar( sVar, sValue, nHow ) ); | ||
| 241 | } | ||
| 242 | |||
| 243 | // | ||
| 143 | // Debug | 244 | // Debug |
| 144 | // | 245 | // |
| 145 | void Builder::debugDump() | 246 | void Builder::debugDump() |
| @@ -159,25 +260,137 @@ void Builder::debugDump() | |||
| 159 | for( ActionTmpCmdList::iterator j = (*i).second.begin(); | 260 | for( ActionTmpCmdList::iterator j = (*i).second.begin(); |
| 160 | j != (*i).second.end(); j++ ) | 261 | j != (*i).second.end(); j++ ) |
| 161 | { | 262 | { |
| 162 | printf(" %d [", (*j).first ); | 263 | printf(" %d ", (*j).first ); |
| 163 | for( BuildList::iterator k = (*j).second.begin(); | 264 | printBuildList( (*j).second ); |
| 164 | k != (*j).second.end(); k++ ) | 265 | printf("\n"); |
| 266 | } | ||
| 267 | } | ||
| 268 | |||
| 269 | printf("\nTargets:\n"); | ||
| 270 | for( TargetTmpList::iterator i = lTargetTmp.begin(); | ||
| 271 | i != lTargetTmp.end(); i++ ) | ||
| 272 | { | ||
| 273 | printf(" "); | ||
| 274 | printBuildList( (*i).first ); | ||
| 275 | printf(":\n"); | ||
| 276 | |||
| 277 | printf(" Rule: %s\n", (*i).second.sRule.c_str() ); | ||
| 278 | printf(" Prefix: %s\n", (*i).second.sPrefix.c_str() ); | ||
| 279 | printf(" Type: %s\n", (*i).second.sType.c_str() ); | ||
| 280 | printf(" Input: "); | ||
| 281 | printBuildList( (*i).second.lInput ); | ||
| 282 | printf("\n Requires: "); | ||
| 283 | printBuildList( (*i).second.lRequires ); | ||
| 284 | printf("\n Vars:\n"); | ||
| 285 | |||
| 286 | for( SetVarList::iterator j = (*i).second.lVar.begin(); | ||
| 287 | j != (*i).second.lVar.end(); j++ ) | ||
| 288 | { | ||
| 289 | char *op; | ||
| 290 | switch( (*j).third ) | ||
| 165 | { | 291 | { |
| 166 | if( k != (*j).second.begin() ) | 292 | case setSet: op = "="; break; |
| 167 | { | 293 | case setAdd: op = "+="; break; |
| 168 | printf(", "); | ||
| 169 | } | ||
| 170 | if( (*k).second ) | ||
| 171 | { | ||
| 172 | printf("func()"); | ||
| 173 | } | ||
| 174 | else | ||
| 175 | { | ||
| 176 | printf("\"%s\"", (*k).first.c_str() ); | ||
| 177 | } | ||
| 178 | } | 294 | } |
| 179 | printf("]\n"); | 295 | printf(" %s %s %s\n", (*j).first.c_str(), op, (*j).second.c_str() ); |
| 296 | } | ||
| 297 | } | ||
| 298 | |||
| 299 | printf("\nGlobals:\n"); | ||
| 300 | for( SetVarList::iterator j = lGlobalVars.begin(); | ||
| 301 | j != lGlobalVars.end(); j++ ) | ||
| 302 | { | ||
| 303 | char *op; | ||
| 304 | switch( (*j).third ) | ||
| 305 | { | ||
| 306 | case setSet: op = "="; break; | ||
| 307 | case setAdd: op = "+="; break; | ||
| 180 | } | 308 | } |
| 309 | printf(" %s %s %s\n", (*j).first.c_str(), op, (*j).second.c_str() ); | ||
| 310 | } | ||
| 311 | |||
| 312 | printf("\nRules:\n"); | ||
| 313 | for( RuleTmpList::iterator i = lRuleTmp.begin(); | ||
| 314 | i != lRuleTmp.end(); i++ ) | ||
| 315 | { | ||
| 316 | printf(" %s:\n", (*i).sName.c_str() ); | ||
| 317 | printf(" Matches: func()\n"); | ||
| 318 | printf(" Produces: "); | ||
| 319 | printBuildList( (*i).lProduces ); | ||
| 320 | printf("\n Requires: "); | ||
| 321 | printBuildList( (*i).lRequires ); | ||
| 322 | printf("\n Filters: %d\n", (*i).lFilter.size() ); | ||
| 323 | printf(" Performs: %d\n", (*i).lPerform.size() ); | ||
| 181 | } | 324 | } |
| 182 | } | 325 | } |
| 183 | 326 | ||
| 327 | void Builder::printBuildList( const BuildList &lst ) | ||
| 328 | { | ||
| 329 | printf("["); | ||
| 330 | for( BuildList::const_iterator k = lst.begin(); | ||
| 331 | k != lst.end(); k++ ) | ||
| 332 | { | ||
| 333 | if( k != lst.begin() ) | ||
| 334 | { | ||
| 335 | printf(", "); | ||
| 336 | } | ||
| 337 | if( (*k).second ) | ||
| 338 | { | ||
| 339 | printf("func()"); | ||
| 340 | } | ||
| 341 | else | ||
| 342 | { | ||
| 343 | printf("\"%s\"", (*k).first.c_str() ); | ||
| 344 | } | ||
| 345 | } | ||
| 346 | printf("]"); | ||
| 347 | } | ||
| 348 | |||
| 349 | // | ||
| 350 | // Actually make a build object | ||
| 351 | // | ||
| 352 | Build *Builder::genBuild() | ||
| 353 | { | ||
| 354 | Build *bld = new Build; | ||
| 355 | |||
| 356 | for( TargetTmpList::iterator i = lTargetTmp.begin(); | ||
| 357 | i != lTargetTmp.end(); i++ ) | ||
| 358 | { | ||
| 359 | StringList lTargetNames = buildToStringList( | ||
| 360 | (*i).first, StringList() | ||
| 361 | ); | ||
| 362 | for( StringList::iterator j = lTargetNames.begin(); | ||
| 363 | j != lTargetNames.end(); j++ ) | ||
| 364 | { | ||
| 365 | if( (*i).second.sType != "" ) | ||
| 366 | { | ||
| 367 | Target *pTarget = fTarget.instantiate( | ||
| 368 | (*i).second.sType.c_str() | ||
| 369 | ); | ||
| 370 | pTarget->setName( *j ); | ||
| 371 | pTarget->setRule( (*i).second.sRule ); | ||
| 372 | |||
| 373 | StringList lInputs = buildToStringList( | ||
| 374 | (*i).second.lInput, StringList() | ||
| 375 | ); | ||
| 376 | pTarget->getInput().insert( | ||
| 377 | pTarget->getInput().end(), | ||
| 378 | lInputs.begin(), lInputs.end() | ||
| 379 | ); | ||
| 380 | |||
| 381 | bld->addTarget( pTarget ); | ||
| 382 | } | ||
| 383 | StringList lReqs = buildToStringList( | ||
| 384 | (*i).second.lRequires, StringList() | ||
| 385 | ); | ||
| 386 | for( StringList::iterator k = lReqs.begin(); | ||
| 387 | k != lReqs.end(); k++ ) | ||
| 388 | { | ||
| 389 | bld->addRequires( (*j), (*k) ); | ||
| 390 | } | ||
| 391 | } | ||
| 392 | } | ||
| 393 | |||
| 394 | return bld; | ||
| 395 | } | ||
| 396 | |||
