aboutsummaryrefslogtreecommitdiff
path: root/src/buildparser.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/buildparser.cpp')
-rw-r--r--src/buildparser.cpp613
1 files changed, 0 insertions, 613 deletions
diff --git a/src/buildparser.cpp b/src/buildparser.cpp
deleted file mode 100644
index 8f40097..0000000
--- a/src/buildparser.cpp
+++ /dev/null
@@ -1,613 +0,0 @@
1#include "buildparser.h"
2#include "functionfactory.h"
3#include "performfactory.h"
4#include "targetfactory.h"
5#include "action.h"
6#include "build.h"
7#include "rule.h"
8#include "stringprocbuild.h"
9
10BuildParser::BuildParser() :
11 fFunction( FunctionFactory::getInstance() ),
12 fPerform( PerformFactory::getInstance() ),
13 fTarget( TargetFactory::getInstance() )
14{
15}
16
17BuildParser::~BuildParser()
18{
19}
20
21void yyparse( BuildParser &bld );
22extern int yydebug;
23
24Build *BuildParser::load( const std::string &sFile )
25{
26 file = sFile;
27 scanBegin();
28 //yydebug = 1;
29 yyparse( *this );
30 scanEnd();
31
32 return genBuild();
33}
34
35//
36// Target functions
37//
38bool BuildParser::isTarget( const char *sType )
39{
40 return fTarget.hasPlugin( sType );
41}
42
43void BuildParser::newTarget()
44{
45 lTargetTmp.push_back( TargetTmp(lTmp, TargetInfo()) );
46}
47
48void BuildParser::setTargetRule( const char *sRule )
49{
50 lTargetTmp.back().second.sRule = sRule;
51}
52
53void BuildParser::setTargetPrefix( const char *sPrefix )
54{
55 lTargetTmp.back().second.sPrefix = sPrefix;
56}
57
58void BuildParser::setTargetType( const char *sType )
59{
60 lTargetTmp.back().second.sType = sType;
61}
62
63void BuildParser::addTargetInput()
64{
65 lTargetTmp.back().second.lInput.first.insert(
66 lTargetTmp.back().second.lInput.first.end(),
67 lTmp.first.begin(), lTmp.first.end()
68 );
69 lTargetTmp.back().second.lInput.second = lTmp.second;
70}
71
72void BuildParser::addTargetRequires()
73{
74 lTargetTmp.back().second.lRequires.first.insert(
75 lTargetTmp.back().second.lRequires.first.end(),
76 lTmp.first.begin(), lTmp.first.end()
77 );
78 lTargetTmp.back().second.lRequires.second = lTmp.second;
79}
80
81void BuildParser::addTargetSet( const char *sVar, const char *sVal, int nHow )
82{
83 lTargetTmp.back().second.lVar.push_back( SetVar( sVar, sVal, nHow ) );
84}
85
86void BuildParser::addTargetGroup( const char *sGroup )
87{
88 lTargetTmp.back().second.lGroups.push_back( sGroup );
89}
90
91//
92// Function functions
93//
94bool BuildParser::isFunction( const char *sFunc )
95{
96 return fFunction.hasPlugin( sFunc );
97}
98
99void BuildParser::newFunctionCall( const char *sName )
100{
101 pTmpFunc = fFunction.instantiate( sName );
102}
103
104void BuildParser::addFunctionParam( const char *sParam )
105{
106 pTmpFunc->addParam( sParam );
107}
108
109//
110// List functions
111//
112void BuildParser::newList()
113{
114 lTmp.first.clear();
115 lTmp.second = NULL;
116}
117
118void BuildParser::addListString( const char *str )
119{
120 lTmp.first.push_back( BuildListItem(str, NULL) );
121}
122
123void BuildParser::addListFunc()
124{
125 lTmp.first.push_back( BuildListItem("", pTmpFunc ) );
126}
127
128void BuildParser::filterList()
129{
130 lTmp.second = pTmpFunc;
131 //StringList lTmp2;
132 //StringList lIn = buildToStringList( lTmp, StringList() );
133 //pTmpFunc->execute( NULL, lIn, lTmp2 );
134 //lTmp.clear();
135 //for( StringList::iterator i = lTmp2.begin(); i != lTmp2.end(); i++ )
136 //{
137 // lTmp.push_back( BuildListItem( *i, NULL ) );
138 //}
139}
140
141void BuildParser::buildListFilter( BuildList &lSrc )
142{
143 if( lSrc.second == NULL )
144 return;
145
146 StringList lTmp2;
147 StringList lIn = buildToStringList( lSrc, StringList() );
148 pTmpFunc->execute( NULL, lIn, lTmp2 );
149 lSrc.first.clear();
150 delete lSrc.second;
151 for( StringList::iterator i = lTmp2.begin(); i != lTmp2.end(); i++ )
152 {
153 lSrc.first.push_back( BuildListItem( *i, NULL ) );
154 }
155}
156
157StringList BuildParser::buildToStringList( const BuildList &lSrc, const StringList &lIn, Build *pPass )
158{
159 StringList lOut;
160
161 for( BuildListCore::const_iterator i = lSrc.first.begin();
162 i != lSrc.first.end(); i++ )
163 {
164 if( (*i).second )
165 {
166 (*i).second->execute( pPass, lIn, lOut );
167 }
168 else
169 {
170 lOut.push_back( (*i).first );
171 }
172 }
173
174 if( lSrc.second )
175 {
176 StringList lTmp;
177 lSrc.second->execute( pPass, lOut, lTmp );
178 lOut.swap( lTmp );
179 }
180
181 return lOut;
182}
183
184StringList BuildParser::buildToStringListDup( const BuildList &lSrc, const StringList &lIn, Build &bld, const std::string &sCont, VarMap *mExtra, Build *pPass )
185{
186 StringList lOut;
187
188 for( BuildListCore::const_iterator i = lSrc.first.begin();
189 i != lSrc.first.end(); i++ )
190 {
191 if( (*i).second )
192 {
193 StringList l;
194 l.push_back( sCont );
195 Function *pTmp = (*i).second->duplicate( bld, &l, mExtra );
196 pTmp->execute( pPass, lIn, lOut );
197 delete pTmp;
198 }
199 else
200 {
201 StringList l;
202 l.push_back( sCont );
203 lOut.push_back( bld.replVars( (*i).first, &l, mExtra ) );
204 }
205 }
206
207 if( lSrc.second )
208 {
209 StringList lTmp;
210 lSrc.second->execute( pPass, lOut, lTmp );
211 lOut.swap( lTmp );
212 }
213
214 return lOut;
215}
216
217//
218// Rule functions
219//
220void BuildParser::addRule( const char *sName )
221{
222 lRuleTmp.push_back( RuleInfo() );
223 lRuleTmp.back().sName = sName;
224 lRuleTmp.back().pAggregate = NULL;
225}
226
227void BuildParser::addRuleMatches()
228{
229 lRuleTmp.back().pMatches = pTmpFunc;
230}
231
232void BuildParser::addRuleProduces()
233{
234 lRuleTmp.back().lProduces.first.insert(
235 lRuleTmp.back().lProduces.first.end(),
236 lTmp.first.begin(), lTmp.first.end()
237 );
238}
239
240void BuildParser::addRuleRequires()
241{
242 lRuleTmp.back().lRequires.first.insert(
243 lRuleTmp.back().lRequires.first.end(),
244 lTmp.first.begin(), lTmp.first.end()
245 );
246}
247
248void BuildParser::addRuleInputFilter()
249{
250 lRuleTmp.back().lFilter.push_back( pTmpFunc );
251}
252
253void BuildParser::addRulePerform()
254{
255 lRuleTmp.back().lPerform.push_back( pTmpPerform );
256}
257
258void BuildParser::setRuleAggregate()
259{
260 lRuleTmp.back().pAggregate = pTmpFunc;
261}
262
263//
264// Perform functions
265//
266bool BuildParser::isPerform( const char *sPerf )
267{
268 return fPerform.hasPlugin( sPerf );
269}
270
271void BuildParser::newPerform( const char *sName )
272{
273 pTmpPerform = fPerform.instantiate( sName );
274}
275
276void BuildParser::addPerformParam( const char *sParam )
277{
278 pTmpPerform->addParam( sParam );
279}
280
281//
282// Functions for dealing with actions
283//
284void BuildParser::addAction()
285{
286 lActions.push_back( ActionTmp("", ActionTmpCmdList() ) );
287}
288
289void BuildParser::addAction( const char *sName )
290{
291 lActions.push_back( ActionTmp(sName, ActionTmpCmdList()) );
292}
293
294void BuildParser::addCommand( int nType )
295{
296 lActions.back().second.push_back( ActionTmpCmd( nType, lTmp ) );
297}
298
299void BuildParser::addGrpCommand( const char *sGroup, int nType )
300{
301 lActions.back().second.push_back( ActionTmpCmd( nType, sGroup ) );
302}
303
304//
305// Global variable functions
306//
307void BuildParser::addGlobalSet( const char *sVar, const char *sValue, int nHow )
308{
309 lGlobalVars.push_back( SetVar( sVar, sValue, nHow ) );
310}
311
312//
313// Debug
314//
315void BuildParser::debugDump()
316{
317 printf("Actions:\n");
318 for( ActionTmpList::iterator i = lActions.begin();
319 i != lActions.end(); i++ )
320 {
321 if( (*i).first == "" )
322 {
323 printf(" default:\n");
324 }
325 else
326 {
327 printf(" \"%s\":\n", (*i).first.c_str() );
328 }
329 for( ActionTmpCmdList::iterator j = (*i).second.begin();
330 j != (*i).second.end(); j++ )
331 {
332 printf(" %d ", (*j).nAct );
333 if( (*j).bGroup )
334 {
335 printf("!%s", (*j).sGroup.c_str() );
336 }
337 else
338 {
339 printBuildList( (*j).lCmds );
340 }
341 printf("\n");
342 }
343 }
344
345 printf("\nTargets:\n");
346 for( TargetTmpList::iterator i = lTargetTmp.begin();
347 i != lTargetTmp.end(); i++ )
348 {
349 printf(" ");
350 printBuildList( (*i).first );
351 printf(":\n");
352
353 printf(" Rule: %s\n", (*i).second.sRule.c_str() );
354 printf(" Prefix: %s\n", (*i).second.sPrefix.c_str() );
355 printf(" Type: %s\n", (*i).second.sType.c_str() );
356 printf(" Input: ");
357 printBuildList( (*i).second.lInput );
358 printf("\n Requires: ");
359 printBuildList( (*i).second.lRequires );
360 printf("\n Vars:\n");
361
362 for( SetVarList::iterator j = (*i).second.lVar.begin();
363 j != (*i).second.lVar.end(); j++ )
364 {
365 const char *op;
366 switch( (*j).third )
367 {
368 case setSet: op = "="; break;
369 case setAdd: op = "+="; break;
370 }
371 printf(" %s %s %s\n", (*j).first.c_str(), op, (*j).second.c_str() );
372 }
373 }
374
375 printf("\nGlobals:\n");
376 for( SetVarList::iterator j = lGlobalVars.begin();
377 j != lGlobalVars.end(); j++ )
378 {
379 const char *op;
380 switch( (*j).third )
381 {
382 case setSet: op = "="; break;
383 case setAdd: op = "+="; break;
384 }
385 printf(" %s %s %s\n", (*j).first.c_str(), op, (*j).second.c_str() );
386 }
387
388 printf("\nRules:\n");
389 for( RuleTmpList::iterator i = lRuleTmp.begin();
390 i != lRuleTmp.end(); i++ )
391 {
392 printf(" %s:\n", (*i).sName.c_str() );
393 printf(" Matches: func()\n");
394 printf(" Produces: ");
395 printBuildList( (*i).lProduces );
396 printf("\n Requires: ");
397 printBuildList( (*i).lRequires );
398 printf("\n Filters: %d\n", (*i).lFilter.size() );
399 printf(" Performs: %d\n", (*i).lPerform.size() );
400 }
401}
402
403void BuildParser::printBuildList( const BuildList &lst )
404{
405 printf("[");
406 for( BuildListCore::const_iterator k = lst.first.begin();
407 k != lst.first.end(); k++ )
408 {
409 if( k != lst.first.begin() )
410 {
411 printf(", ");
412 }
413 if( (*k).second )
414 {
415 printf("func()");
416 }
417 else
418 {
419 printf("\"%s\"", (*k).first.c_str() );
420 }
421 }
422 printf("]");
423}
424
425//
426// Actually make a build object
427//
428Build *BuildParser::genBuild()
429{
430 Build *bld = new Build;
431 bld->setStringProc( new StringProcBuild( bld ) );
432
433 for( SetVarList::iterator i = lGlobalVars.begin();
434 i != lGlobalVars.end(); i++ )
435 {
436 switch( (*i).third )
437 {
438 case setSet:
439 bld->set( "", (*i).first, (*i).second );
440 break;
441
442 case setAdd:
443 bld->setAdd( "", (*i).first, (*i).second );
444 break;
445 }
446 }
447
448 for( TargetTmpList::iterator i = lTargetTmp.begin();
449 i != lTargetTmp.end(); i++ )
450 {
451 StringList lTargetNames = buildToStringList(
452 (*i).first, StringList(), bld
453 );
454 for( StringList::iterator j = lTargetNames.begin();
455 j != lTargetNames.end(); j++ )
456 {
457 if( (*i).second.sType != "" )
458 {
459 Target *pTarget = fTarget.instantiate(
460 (*i).second.sType.c_str()
461 );
462 pTarget->setName( *j );
463 pTarget->setRule( (*i).second.sRule );
464
465 VarMap mExtra;
466 mExtra["target"] = (*j);
467
468 StringList lInputs = buildToStringListDup(
469 (*i).second.lInput, StringList(),
470 *bld, *j, &mExtra /*, bld <-- should this be here? */
471 );
472 pTarget->getInput().insert(
473 pTarget->getInput().end(),
474 lInputs.begin(), lInputs.end()
475 );
476
477 bld->addTarget( pTarget );
478
479 for( StringList::iterator c = (*i).second.lGroups.begin();
480 c != (*i).second.lGroups.end(); c++ )
481 {
482 bld->addToGroup( *c, pTarget );
483 }
484 }
485 StringList lReqs = buildToStringList(
486 (*i).second.lRequires, StringList()
487 );
488 for( StringList::iterator k = lReqs.begin();
489 k != lReqs.end(); k++ )
490 {
491 bld->addRequires( (*j), (*k) );
492 }
493 for( SetVarList::iterator k = (*i).second.lVar.begin();
494 k != (*i).second.lVar.end(); k++ )
495 {
496 switch( (*k).third )
497 {
498 case setSet:
499 bld->set( *j, (*k).first, (*k).second );
500 break;
501
502 case setAdd:
503 bld->setAdd( *j, (*k).first, (*k).second );
504 break;
505 }
506 }
507 }
508 }
509
510 for( RuleTmpList::iterator i = lRuleTmp.begin(); i != lRuleTmp.end(); i++ )
511 {
512 Rule *pRule = new Rule;
513 pRule->setName( (*i).sName );
514 pRule->getMatchesList().push_back( (*i).pMatches );
515
516 for( FunctionList::iterator j = (*i).lFilter.begin();
517 j != (*i).lFilter.end(); j++ )
518 {
519 pRule->getFilterList().push_back( *j );
520 }
521
522 for( PerformList::iterator j = (*i).lPerform.begin();
523 j != (*i).lPerform.end(); j++ )
524 {
525 pRule->getPerformList().push_back( *j );
526 }
527
528 for( BuildListCore::iterator j = (*i).lProduces.first.begin();
529 j != (*i).lProduces.first.end(); j++ )
530 {
531 if( (*j).second )
532 {
533 throw BuildException(
534 "You cannot have functions in produces lists (rule %s).",
535 (*i).sName.c_str() );
536 }
537 pRule->getProducesList().push_back( (*j).first );
538 }
539
540 if( (*i).pAggregate )
541 {
542 pRule->setAggregate( (*i).pAggregate );
543 }
544
545 for( BuildListCore::iterator j = (*i).lRequires.first.begin();
546 j != (*i).lRequires.first.end(); j++ )
547 {
548 if( (*j).second )
549 {
550 pRule->getReqFuncList().push_back( (*j).second );
551 }
552 else
553 {
554 pRule->getReqStrList().push_back( (*j).first );
555 }
556 }
557
558 bld->addRule( pRule );
559 }
560
561 for( ActionTmpList::iterator i = lActions.begin();
562 i != lActions.end(); i++ )
563 {
564 Action *pAct = new Action;
565 pAct->setName( (*i).first );
566
567 for( ActionTmpCmdList::iterator j = (*i).second.begin();
568 j != (*i).second.end(); j++ )
569 {
570 if( (*j).bGroup )
571 {
572 pAct->addCommand(
573 (Action::eAction)((*j).nAct), (*j).sGroup, true
574 );
575 }
576 else
577 {
578 StringList lWhat = buildToStringList(
579 (*j).lCmds, StringList(), bld
580 );
581
582 for( StringList::iterator k = lWhat.begin();
583 k != lWhat.end(); k++ )
584 {
585 pAct->addCommand( (Action::eAction)((*j).nAct), *k, false );
586 }
587 }
588 }
589
590 bld->addAction( pAct );
591 }
592
593 // Now create an auto check-action for each group where there isn't already
594 // an action.
595 for( TargetTmpList::iterator i = lTargetTmp.begin();
596 i != lTargetTmp.end(); i++ )
597 {
598 for( StringList::iterator j = (*i).second.lGroups.begin();
599 j != (*i).second.lGroups.end(); j++ )
600 {
601 if( !bld->hasAction( (*j) ) )
602 {
603 Action *pAct = new Action;
604 pAct->setName( *j );
605 pAct->addCommand( Action::actCheck, *j, true );
606 bld->addAction( pAct );
607 }
608 }
609 }
610
611 return bld;
612}
613