]>
git.saurik.com Git - cycript.git/blob - Replace.cpp
7 CYExpression
*CYAddressOf::Replace(CYContext
&context
) {
8 CYPrefix::Replace(context
);
9 return $
C0($
M(rhs_
, $
S("$cya")));
12 void CYArgument::Replace(CYContext
&context
) { $
T()
13 context
.Replace(value_
);
14 next_
->Replace(context
);
17 CYExpression
*CYArray::Replace(CYContext
&context
) {
18 elements_
->Replace(context
);
22 CYExpression
*CYArrayComprehension::Replace(CYContext
&context
) {
23 CYVariable
*cyv($
V("$cyv"));
25 return $
C0($
F(NULL
, $
P1("$cyv", comprehensions_
->Parameters(context
)), $$
->*
26 $
E($
CYAssign(cyv
, $
CYArray()))->*
27 comprehensions_
->Replace(context
, $
E($
C1($
M(cyv
, $
S("push")), expression_
)))->*
32 CYExpression
*CYAssignment::Replace(CYContext
&context
) {
33 context
.Replace(lhs_
);
34 context
.Replace(rhs_
);
38 CYStatement
*CYBlock::Replace(CYContext
&context
) {
39 statements_
= statements_
->ReplaceAll(context
);
43 CYStatement
*CYBreak::Replace(CYContext
&context
) {
47 CYExpression
*CYCall::Replace(CYContext
&context
) {
48 context
.Replace(function_
);
49 arguments_
->Replace(context
);
53 void CYCatch::Replace(CYContext
&context
) { $
T()
54 code_
.Replace(context
);
57 void CYClause::Replace(CYContext
&context
) { $
T()
58 context
.Replace(case_
);
59 statements_
= statements_
->ReplaceAll(context
);
60 next_
->Replace(context
);
63 CYExpression
*CYCompound::Replace(CYContext
&context
) {
64 expressions_
= expressions_
->ReplaceAll(context
);
68 CYFunctionParameter
*CYComprehension::Parameters(CYContext
&context
) const { $
T(NULL
)
69 CYFunctionParameter
*next(next_
->Parameters(context
));
70 if (CYFunctionParameter
*parameter
= Parameter(context
)) {
71 parameter
->SetNext(next
);
77 CYStatement
*CYComprehension::Replace(CYContext
&context
, CYStatement
*statement
) const {
78 return next_
== NULL
? statement
: next_
->Replace(context
, statement
);
81 CYExpression
*CYCondition::Replace(CYContext
&context
) {
82 context
.Replace(test_
);
83 context
.Replace(true_
);
84 context
.Replace(false_
);
88 CYStatement
*CYContinue::Replace(CYContext
&context
) {
92 CYExpression
*CYDeclaration::ForEachIn(CYContext
&context
) {
93 return $
CYVariable(identifier_
);
96 void CYDeclaration::Replace(CYContext
&context
) {
97 context
.Replace(initialiser_
);
100 void CYDeclarations::Replace(CYContext
&context
) { $
T()
101 declaration_
->Replace(context
);
102 next_
->Replace(context
);
105 CYExpression
*CYDirectMember::Replace(CYContext
&context
) {
110 CYStatement
*CYDoWhile::Replace(CYContext
&context
) {
111 context
.Replace(test_
);
112 context
.Replace(code_
);
116 void CYElement::Replace(CYContext
&context
) { $
T()
117 context
.Replace(value_
);
118 next_
->Replace(context
);
121 CYStatement
*CYEmpty::Replace(CYContext
&context
) {
125 CYStatement
*CYExpress::Replace(CYContext
&context
) {
126 context
.Replace(expression_
);
130 CYExpression
*CYExpression::ClassName(CYContext
&context
, bool object
) {
134 CYExpression
*CYExpression::ForEachIn(CYContext
&context
) {
138 CYExpression
*CYExpression::ReplaceAll(CYContext
&context
) { $
T(NULL
)
139 CYExpression
*replace(this);
140 context
.Replace(replace
);
142 if (CYExpression
*next
= next_
->ReplaceAll(context
))
143 replace
->SetNext(next
);
145 replace
->SetNext(next_
);
150 void CYFinally::Replace(CYContext
&context
) { $
T()
151 code_
.Replace(context
);
154 CYStatement
*CYFor::Replace(CYContext
&context
) {
156 context
.Replace(test_
);
157 context
.Replace(increment_
);
158 context
.Replace(code_
);
162 CYStatement
*CYForIn::Replace(CYContext
&context
) {
164 context
.Replace(set_
);
165 context
.Replace(code_
);
169 CYFunctionParameter
*CYForInComprehension::Parameter(CYContext
&context
) const {
170 return $
CYFunctionParameter(name_
);
173 CYStatement
*CYForInComprehension::Replace(CYContext
&context
, CYStatement
*statement
) const {
174 return $
CYForIn($
CYVariable(name_
), set_
, CYComprehension::Replace(context
, statement
));
177 CYStatement
*CYForEachIn::Replace(CYContext
&context
) {
178 CYVariable
*cys($
V("$cys")), *cyt($
V("$cyt"));
180 return $
CYWith($
CYObject($
CYProperty($
S("$cys"), $
D(0), $
CYProperty($
S("$cyt"), $
D(0)))), $
CYBlock($$
->*
181 $
E($
CYAssign(cys
, set_
))->*
182 $
CYForIn(cyt
, cys
, $
CYBlock($$
->*
183 $
E($
CYAssign(initialiser_
->ForEachIn(context
), $
M(cys
, cyt
)))->*
189 CYFunctionParameter
*CYForEachInComprehension::Parameter(CYContext
&context
) const {
190 return $
CYFunctionParameter(name_
);
193 CYStatement
*CYForEachInComprehension::Replace(CYContext
&context
, CYStatement
*statement
) const {
194 CYVariable
*cys($
V("$cys")), *name($
CYVariable(name_
));
196 return $
E($
C0($
F(NULL
, $
P1("$cys"), $$
->*
197 $
E($
CYAssign(cys
, set_
))->*
198 $
CYForIn(name
, cys
, $
CYBlock($$
->*
199 $
E($
CYAssign(name
, $
M(cys
, name
)))->*
200 CYComprehension::Replace(context
, statement
)
205 void CYFunction::Replace_(CYContext
&context
) {
206 code_
.Replace(context
);
209 CYExpression
*CYFunctionExpression::Replace(CYContext
&context
) {
214 CYStatement
*CYFunctionStatement::Replace(CYContext
&context
) {
219 CYStatement
*CYIf::Replace(CYContext
&context
) {
220 context
.Replace(test_
);
221 context
.Replace(true_
);
222 context
.Replace(false_
);
226 CYFunctionParameter
*CYIfComprehension::Parameter(CYContext
&context
) const {
230 CYStatement
*CYIfComprehension::Replace(CYContext
&context
, CYStatement
*statement
) const {
231 return $
CYIf(test_
, CYComprehension::Replace(context
, statement
));
234 CYExpression
*CYIndirect::Replace(CYContext
&context
) {
235 CYPrefix::Replace(context
);
236 return $
M(rhs_
, $
S("$cyi"));
239 CYExpression
*CYIndirectMember::Replace(CYContext
&context
) {
241 return $
M($
CYIndirect(object_
), property_
);
244 CYExpression
*CYInfix::Replace(CYContext
&context
) {
245 context
.Replace(lhs_
);
246 context
.Replace(rhs_
);
250 CYStatement
*CYLabel::Replace(CYContext
&context
) {
251 context
.Replace(statement_
);
255 void CYMember::Replace_(CYContext
&context
) {
256 context
.Replace(object_
);
257 context
.Replace(property_
);
260 CYExpression
*CYNew::Replace(CYContext
&context
) {
261 context
.Replace(constructor_
);
262 arguments_
->Replace(context
);
266 CYExpression
*CYObject::Replace(CYContext
&context
) {
267 properties_
->Replace(context
);
271 CYExpression
*CYPostfix::Replace(CYContext
&context
) {
272 context
.Replace(lhs_
);
276 CYExpression
*CYPrefix::Replace(CYContext
&context
) {
277 context
.Replace(rhs_
);
281 void CYProgram::Replace(CYContext
&context
) {
282 statements_
= statements_
->ReplaceAll(context
);
285 void CYProperty::Replace(CYContext
&context
) { $
T()
286 context
.Replace(value_
);
287 next_
->Replace(context
);
290 CYStatement
*CYReturn::Replace(CYContext
&context
) {
291 context
.Replace(value_
);
295 CYStatement
*CYStatement::ReplaceAll(CYContext
&context
) { $
T(NULL
)
296 CYStatement
*replace(this);
297 context
.Replace(replace
);
299 if (CYStatement
*next
= next_
->ReplaceAll(context
))
300 replace
->SetNext(next
);
302 replace
->SetNext(next_
);
307 CYStatement
*CYSwitch::Replace(CYContext
&context
) {
308 context
.Replace(value_
);
309 clauses_
->Replace(context
);
313 CYExpression
*CYThis::Replace(CYContext
&context
) {
317 CYStatement
*CYThrow::Replace(CYContext
&context
) {
318 context
.Replace(value_
);
322 CYExpression
*CYTrivial::Replace(CYContext
&context
) {
326 CYStatement
*CYTry::Replace(CYContext
&context
) {
327 code_
.Replace(context
);
328 catch_
->Replace(context
);
329 finally_
->Replace(context
);
333 CYStatement
*CYVar::Replace(CYContext
&context
) {
334 declarations_
->Replace(context
);
338 CYExpression
*CYVariable::Replace(CYContext
&context
) {
342 CYStatement
*CYWhile::Replace(CYContext
&context
) {
343 context
.Replace(test_
);
344 context
.Replace(code_
);
348 CYStatement
*CYWith::Replace(CYContext
&context
) {
349 context
.Replace(scope_
);
350 context
.Replace(code_
);
354 CYExpression
*CYWord::ClassName(CYContext
&context
, bool object
) {
355 CYString
*name($
S(this));
357 return $
C1($
V("objc_getClass"), name
);