aboutsummaryrefslogtreecommitdiff
path: root/src/rule.cpp
blob: c5ed1c2a3c221cc47b0d1cbf88c81c75c9a06d78 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include "rule.h"
#include "build.h"
#include "function.h"
#include "perform.h"

Rule::Rule() :
	pAggregate( NULL )
{
}

Rule::~Rule()
{
}

StringList Rule::execute( Build &bld, StringList &lInput, PerformList &lPerf )
{
	StringList lOutput;

	RuleList rl = bld.findChainRules( this );

	for( RuleList::iterator i = rl.begin(); i != rl.end(); i++ )
	{
		StringList tmp = (*i)->execute( bld, lInput, lPerf );
		lOutput.insert( lOutput.end(), tmp.begin(), tmp.end() );
	}

	StringList lMine;
	for( FunctionList::iterator i = lMatches.begin(); i != lMatches.end(); i++ )
	{
		(*i)->execute( &bld, lInput, lMine );
	}

	StringList lTmp;
	for( FunctionList::iterator i = lFilter.begin(); i != lFilter.end(); i++ )
	{
		(*i)->execute( &bld, lMine, lTmp );
		lMine.swap( lTmp );
		lTmp.clear();
	}

	bool bHasProduces = true;
	if( lProduces.empty() )
	{
		bHasProduces = false;
		lProduces.push_back( sTarget );
	}

	StringList lNewOut;
	if( pAggregate )
	{
		VarMap mTmp;
		std::string target = lProduces.front();//, lProduces.front(), NULL ).c_str();
		mTmp["target"] = target;
		lNewOut.push_back( target );

		for( StringList::iterator i = lMine.begin(); i != lMine.end(); i++ )
		{
			bld.addRequires( target, (*i) );
		}
		for( StringList::iterator i = lReqStrs.begin();
			 i != lReqStrs.end(); i++ )
		{
			bld.addRequires( target, (*i) );
		}

		StringList lTmp;
		pAggregate->execute( &bld, lMine, lTmp );
		mTmp["match"] = lTmp.front();

		for( PerformList::iterator k = lPerform.begin();
			 k != lPerform.end(); k++ )
		{
			Perform *p = (*k)->duplicate( bld, target, &mTmp );
			p->setTarget( target );
			p->setRule( sName );
			//p->setReqFuncs( &lReqFuncs );
			lPerf.push_back( p );
		}
	}
	else
	{
		for( StringList::iterator i = lMine.begin(); i != lMine.end(); i++ )
		{
			for( StringList::iterator j = lProduces.begin();
				 j != lProduces.end(); j++ )
			{
				VarMap mTmp;
				std::string target = bld.replVars( (*j), (*i), NULL );
				mTmp["target"] = target;
				lNewOut.push_back( target );
				mTmp["match"] = (*i);
				bld.addRequires( target, (*i) );
				for( StringList::iterator k = lReqStrs.begin();
					 k != lReqStrs.end(); k++ )
				{
					bld.addRequires( target, (*k) );
				}
				for( PerformList::iterator k = lPerform.begin();
					 k != lPerform.end(); k++ )
				{
					Perform *p = (*k)->duplicate( bld, (*i), &mTmp );
					p->setTarget( target );
					p->setRule( sName );
					for( FunctionList::iterator f = lReqFuncs.begin();
						 f != lReqFuncs.end(); f++ )
					{
						p->getReqFuncs().push_back(
							(*f)->duplicate( bld, (*i), &mTmp )
							);
					}
					lPerf.push_back( p );
				}
			}
		}
	}

	lInput.insert( lInput.end(), lNewOut.begin(), lNewOut.end() );
	lOutput.insert( lOutput.end(), lNewOut.begin(), lNewOut.end() );

	if( bHasProduces == false )
	{
		lProduces.clear();
	}

	return lOutput;
}