aboutsummaryrefslogtreecommitdiff
path: root/src/rule.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/rule.cpp168
1 files changed, 84 insertions, 84 deletions
diff --git a/src/rule.cpp b/src/rule.cpp
index 81e775e..15b2388 100644
--- a/src/rule.cpp
+++ b/src/rule.cpp
@@ -12,8 +12,8 @@
12using namespace Bu; 12using namespace Bu;
13 13
14Rule::Rule( const Bu::String &sName ) : 14Rule::Rule( const Bu::String &sName ) :
15 sName( sName ), 15 sName( sName ),
16 pInput( NULL ) 16 pInput( NULL )
17{ 17{
18} 18}
19 19
@@ -23,146 +23,146 @@ Rule::~Rule()
23 23
24const Bu::String &Rule::getName() const 24const Bu::String &Rule::getName() const
25{ 25{
26 return sName; 26 return sName;
27} 27}
28 28
29void Rule::setInput( const AstBranch *pNewInput ) 29void Rule::setInput( const AstBranch *pNewInput )
30{ 30{
31 pInput = pNewInput; 31 pInput = pNewInput;
32} 32}
33 33
34const AstBranch *Rule::getInput() const 34const AstBranch *Rule::getInput() const
35{ 35{
36 return pInput; 36 return pInput;
37} 37}
38 38
39bool Rule::hasOutputs() const 39bool Rule::hasOutputs() const
40{ 40{
41 return !lOutput.isEmpty(); 41 return !lOutput.isEmpty();
42} 42}
43 43
44void Rule::addOutput( const AstBranch *pNewOutput ) 44void Rule::addOutput( const AstBranch *pNewOutput )
45{ 45{
46 lOutput.append( pNewOutput ); 46 lOutput.append( pNewOutput );
47} 47}
48 48
49void Rule::addProfile( const AstBranch *pProfRoot ) 49void Rule::addProfile( const AstBranch *pProfRoot )
50{ 50{
51 Profile *pProf = new Profile( pProfRoot ); 51 Profile *pProf = new Profile( pProfRoot );
52 hProfiles.insert( pProf->getName(), pProf ); 52 hProfiles.insert( pProf->getName(), pProf );
53 /* 53 /*
54 hProfiles.insert( 54 hProfiles.insert(
55 dynamic_cast<const AstLeaf *>( 55 dynamic_cast<const AstLeaf *>(
56 (*pProfile->getBranchBegin()).first() 56 (*pProfile->getBranchBegin()).first()
57 )->getStrValue(), 57 )->getStrValue(),
58 pProfile 58 pProfile
59 ); 59 );
60 */ 60 */
61} 61}
62 62
63void Rule::prepTarget( class Target *pTarget ) 63void Rule::prepTarget( class Target *pTarget )
64{ 64{
65 pTarget->setDisplay( getDisplay() ); 65 pTarget->setDisplay( getDisplay() );
66 for( ProfileHash::iterator i = hProfiles.begin(); i; i++ ) 66 for( ProfileHash::iterator i = hProfiles.begin(); i; i++ )
67 { 67 {
68 pTarget->addProfile( *i ); 68 pTarget->addProfile( *i );
69 } 69 }
70 for( AstBranchList::iterator i = lRequires.begin(); i; i++ ) 70 for( AstBranchList::iterator i = lRequires.begin(); i; i++ )
71 { 71 {
72 pTarget->addRequires( *i ); 72 pTarget->addRequires( *i );
73 } 73 }
74} 74}
75 75
76Target *Rule::createTarget( class Runner &r, const Bu::String &sInput, 76Target *Rule::createTarget( class Runner &r, const Bu::String &sInput,
77 Target *pParent ) 77 Target *pParent )
78{ 78{
79 r.getContext().pushScope( pParent->getVars() ); 79 r.getContext().pushScope( pParent->getVars() );
80 r.getContext().addVariable("INPUT", sInput ); 80 r.getContext().addVariable("INPUT", sInput );
81 Target *pTrg = new Target( false ); 81 Target *pTrg = new Target( false );
82 for( AstBranchList::iterator i = lOutput.begin(); i; i++ ) 82 for( AstBranchList::iterator i = lOutput.begin(); i; i++ )
83 { 83 {
84 Variable vOut = r.execExpr( 84 Variable vOut = r.execExpr(
85 (*(*i)->getBranchBegin()).begin(), 85 (*(*i)->getBranchBegin()).begin(),
86 Variable( sInput ) 86 Variable( sInput )
87 ); 87 );
88 if( vOut.getType() == Variable::typeString ) 88 if( vOut.getType() == Variable::typeString )
89 { 89 {
90 pTrg->addOutput( vOut.getString() ); 90 pTrg->addOutput( vOut.getString() );
91 } 91 }
92 else if( vOut.getType() == Variable::typeList ) 92 else if( vOut.getType() == Variable::typeList )
93 { 93 {
94 for( VarList::iterator j = vOut.begin(); j; j++ ) 94 for( VarList::iterator j = vOut.begin(); j; j++ )
95 { 95 {
96 pTrg->addOutput( (*j).getString() ); 96 pTrg->addOutput( (*j).getString() );
97 } 97 }
98 } 98 }
99 } 99 }
100 r.getContext().addVariable("OUTPUT", pTrg->getOutputList() ); 100 r.getContext().addVariable("OUTPUT", pTrg->getOutputList() );
101 pTrg->addInput( sInput ); 101 pTrg->addInput( sInput );
102 pTrg->setDisplay( getDisplay() ); 102 pTrg->setDisplay( getDisplay() );
103 for( ProfileHash::iterator i = hProfiles.begin(); i; i++ ) 103 for( ProfileHash::iterator i = hProfiles.begin(); i; i++ )
104 { 104 {
105 pTrg->addProfile( *i ); 105 pTrg->addProfile( *i );
106 } 106 }
107 for( AstBranchList::iterator i = lRequires.begin(); i; i++ ) 107 for( AstBranchList::iterator i = lRequires.begin(); i; i++ )
108 { 108 {
109 pTrg->addRequires( *i ); 109 pTrg->addRequires( *i );
110 } 110 }
111 pTrg->setVars( r.getContext().getScope() ); 111 pTrg->setVars( r.getContext().getScope() );
112 r.getContext().popScope(); 112 r.getContext().popScope();
113 113
114 return pTrg; 114 return pTrg;
115} 115}
116 116
117bool Rule::ruleMatches( Runner &r, const Bu::String &sInput ) 117bool Rule::ruleMatches( Runner &r, const Bu::String &sInput )
118{ 118{
119 r.getContext().pushScope(); 119 r.getContext().pushScope();
120 r.getContext().addVariable("INPUT", sInput ); 120 r.getContext().addVariable("INPUT", sInput );
121 Variable vInput( sInput ); 121 Variable vInput( sInput );
122 Variable vOut = r.execExpr( 122 Variable vOut = r.execExpr(
123 (*pInput->getBranchBegin()).begin(), 123 (*pInput->getBranchBegin()).begin(),
124 vInput 124 vInput
125 ); 125 );
126 r.getContext().popScope(); 126 r.getContext().popScope();
127 if( vOut.getType() == Variable::typeBool ) 127 if( vOut.getType() == Variable::typeBool )
128 return vOut.getBool(); 128 return vOut.getBool();
129 else if( vOut.getType() == Variable::typeList ) 129 else if( vOut.getType() == Variable::typeList )
130 return vOut.begin(); 130 return vOut.begin();
131 return false; 131 return false;
132} 132}
133 133
134void Rule::addTag( const Bu::String &sTag ) 134void Rule::addTag( const Bu::String &sTag )
135{ 135{
136 lsTags.append( sTag ); 136 lsTags.append( sTag );
137} 137}
138 138
139const StrList &Rule::getTagList() const 139const StrList &Rule::getTagList() const
140{ 140{
141 return lsTags; 141 return lsTags;
142} 142}
143 143
144void Rule::setDisplay( const Bu::String &sStr ) 144void Rule::setDisplay( const Bu::String &sStr )
145{ 145{
146 sDisplay = sStr; 146 sDisplay = sStr;
147} 147}
148 148
149const Bu::String &Rule::getDisplay() const 149const Bu::String &Rule::getDisplay() const
150{ 150{
151 return (sDisplay.isSet())?(sDisplay):(sName); 151 return (sDisplay.isSet())?(sDisplay):(sName);
152} 152}
153 153
154void Rule::addRequires( const AstBranch *pBr ) 154void Rule::addRequires( const AstBranch *pBr )
155{ 155{
156 lRequires.append( pBr ); 156 lRequires.append( pBr );
157} 157}
158 158
159Bu::Formatter &operator<<( Bu::Formatter &f, const Rule &/*t*/ ) 159Bu::Formatter &operator<<( Bu::Formatter &f, const Rule &/*t*/ )
160{ 160{
161 return f << "rule"; 161 return f << "rule";
162} 162}
163 163
164template<> Bu::Formatter &Bu::operator<< <Rule>( Bu::Formatter &f, const Rule *t ) 164template<> Bu::Formatter &Bu::operator<< <Rule>( Bu::Formatter &f, const Rule *t )
165{ 165{
166 return f << (*t); 166 return f << (*t);
167} 167}
168 168