]> git.saurik.com Git - cycript.git/blob - Replace.cpp
f0b09344e300eda52d0f6d5fce834f771ce6799a
[cycript.git] / Replace.cpp
1 /* Cycript - Inlining/Optimizing JavaScript Compiler
2 * Copyright (C) 2009 Jay Freeman (saurik)
3 */
4
5 /* Modified BSD License {{{ */
6 /*
7 * Redistribution and use in source and binary
8 * forms, with or without modification, are permitted
9 * provided that the following conditions are met:
10 *
11 * 1. Redistributions of source code must retain the
12 * above copyright notice, this list of conditions
13 * and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the
15 * above copyright notice, this list of conditions
16 * and the following disclaimer in the documentation
17 * and/or other materials provided with the
18 * distribution.
19 * 3. The name of the author may not be used to endorse
20 * or promote products derived from this software
21 * without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS''
24 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
25 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
26 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
28 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
30 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
31 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
34 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
35 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
36 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 */
38 /* }}} */
39
40 #include "Parser.hpp"
41 #include "Replace.hpp"
42
43 #include <iomanip>
44
45 CYExpression *CYAdd::Replace(CYContext &context) {
46 CYInfix::Replace(context);
47
48 CYExpression *lhp(lhs_->Primitive(context));
49 CYExpression *rhp(rhs_->Primitive(context));
50
51 CYString *lhs(dynamic_cast<CYString *>(lhp));
52 CYString *rhs(dynamic_cast<CYString *>(rhp));
53
54 if (lhs != NULL || rhs != NULL) {
55 if (lhs == NULL) {
56 lhs = lhp->String(context);
57 if (lhs == NULL)
58 return this;
59 } else if (rhs == NULL) {
60 rhs = rhp->String(context);
61 if (rhs == NULL)
62 return this;
63 }
64
65 return lhs->Concat(context, rhs);
66 }
67
68 if (CYNumber *lhn = lhp->Number(context))
69 if (CYNumber *rhn = rhp->Number(context))
70 return $D(lhn->Value() + rhn->Value());
71
72 return this;
73 }
74
75 CYExpression *CYAddressOf::Replace(CYContext &context) {
76 CYPrefix::Replace(context);
77 return $C0($M(rhs_, $S("$cya")));
78 }
79
80 void CYArgument::Replace(CYContext &context) { $T()
81 context.Replace(value_);
82 next_->Replace(context);
83 }
84
85 CYExpression *CYArray::Replace(CYContext &context) {
86 elements_->Replace(context);
87 return this;
88 }
89
90 CYExpression *CYArrayComprehension::Replace(CYContext &context) {
91 CYVariable *cyv($V("$cyv"));
92
93 return $C0($F(NULL, $P1("$cyv", comprehensions_->Parameters(context)), $$->*
94 $E($ CYAssign(cyv, $ CYArray()))->*
95 comprehensions_->Replace(context, $E($C1($M(cyv, $S("push")), expression_)))->*
96 $ CYReturn(cyv)
97 ));
98 }
99
100 CYExpression *CYAssignment::Replace(CYContext &context) {
101 context.Replace(lhs_);
102 context.Replace(rhs_);
103 return this;
104 }
105
106 CYStatement *CYBlock::Replace(CYContext &context) {
107 statements_ = statements_->ReplaceAll(context);
108 if (statements_ == NULL)
109 return $ CYEmpty();
110 return this;
111 }
112
113 CYStatement *CYBreak::Replace(CYContext &context) {
114 return this;
115 }
116
117 CYExpression *CYCall::Replace(CYContext &context) {
118 context.Replace(function_);
119 arguments_->Replace(context);
120 return this;
121 }
122
123 namespace cy {
124 namespace Syntax {
125
126 void Catch::Replace(CYContext &context) { $T()
127 code_.Replace(context);
128 }
129
130 } }
131
132 void CYClause::Replace(CYContext &context) { $T()
133 context.Replace(case_);
134 statements_ = statements_->ReplaceAll(context);
135 next_->Replace(context);
136 }
137
138 CYStatement *CYComment::Replace(CYContext &context) {
139 return this;
140 }
141
142 CYExpression *CYCompound::Replace(CYContext &context) {
143 expressions_ = expressions_->ReplaceAll(context);
144 return expressions_ == NULL ? NULL : this;
145 }
146
147 CYFunctionParameter *CYComprehension::Parameters(CYContext &context) const { $T(NULL)
148 CYFunctionParameter *next(next_->Parameters(context));
149 if (CYFunctionParameter *parameter = Parameter(context)) {
150 parameter->SetNext(next);
151 return parameter;
152 } else
153 return next;
154 }
155
156 CYStatement *CYComprehension::Replace(CYContext &context, CYStatement *statement) const {
157 return next_ == NULL ? statement : next_->Replace(context, statement);
158 }
159
160 CYExpression *CYCondition::Replace(CYContext &context) {
161 context.Replace(test_);
162 context.Replace(true_);
163 context.Replace(false_);
164 return this;
165 }
166
167 CYStatement *CYContinue::Replace(CYContext &context) {
168 return this;
169 }
170
171 CYAssignment *CYDeclaration::Assignment(CYContext &context) {
172 CYExpression *variable(Replace(context));
173 return initialiser_ == NULL ? NULL : $ CYAssign(variable, initialiser_);
174 }
175
176 CYExpression *CYDeclaration::ForEachIn(CYContext &context) {
177 return $ CYVariable(identifier_);
178 }
179
180 CYExpression *CYDeclaration::Replace(CYContext &context) {
181 context.Replace(identifier_);
182 context.scope_->Declare(context, identifier_, CYIdentifierVariable);
183 return $ CYVariable(identifier_);
184 }
185
186 CYProperty *CYDeclarations::Property(CYContext &context) { $T(NULL)
187 return $ CYProperty(declaration_->identifier_, declaration_->initialiser_ ?: $U, next_->Property(context));
188 }
189
190 CYCompound *CYDeclarations::Replace(CYContext &context) {
191 CYCompound *compound;
192 if (next_ == NULL) compound:
193 compound = $ CYCompound();
194 else {
195 compound = next_->Replace(context);
196 if (compound == NULL)
197 goto compound;
198 }
199
200 if (CYAssignment *assignment = declaration_->Assignment(context))
201 compound->AddPrev(assignment);
202 return compound;
203 }
204
205 CYExpression *CYDirectMember::Replace(CYContext &context) {
206 Replace_(context);
207 return this;
208 }
209
210 CYStatement *CYDoWhile::Replace(CYContext &context) {
211 context.Replace(test_);
212 context.Replace(code_);
213 return this;
214 }
215
216 void CYElement::Replace(CYContext &context) { $T()
217 context.Replace(value_);
218 next_->Replace(context);
219 }
220
221 CYStatement *CYEmpty::Collapse(CYContext &context) {
222 return next_;
223 }
224
225 CYStatement *CYEmpty::Replace(CYContext &context) {
226 return this;
227 }
228
229 CYStatement *CYExpress::Collapse(CYContext &context) {
230 if (CYExpress *express = dynamic_cast<CYExpress *>(next_)) {
231 CYCompound *next(dynamic_cast<CYCompound *>(express->expression_));
232 if (next == NULL)
233 next = $ CYCompound(express->expression_);
234 next->AddPrev(expression_);
235 expression_ = next;
236 SetNext(express->next_);
237 }
238
239 return this;
240 }
241
242 CYStatement *CYExpress::Replace(CYContext &context) {
243 context.Replace(expression_);
244 if (expression_ == NULL)
245 return $ CYEmpty();
246 return this;
247 }
248
249 CYExpression *CYExpression::ClassName(CYContext &context, bool object) {
250 return this;
251 }
252
253 CYExpression *CYExpression::ForEachIn(CYContext &context) {
254 return this;
255 }
256
257 CYExpression *CYExpression::ReplaceAll(CYContext &context) { $T(NULL)
258 CYExpression *replace(this);
259 context.Replace(replace);
260
261 if (CYExpression *next = next_->ReplaceAll(context))
262 replace->SetNext(next);
263 else
264 replace->SetNext(next_);
265
266 return replace;
267 }
268
269 CYNumber *CYFalse::Number(CYContext &context) {
270 return $D(0);
271 }
272
273 CYString *CYFalse::String(CYContext &context) {
274 return $S("false");
275 }
276
277 void CYFinally::Replace(CYContext &context) { $T()
278 code_.Replace(context);
279 }
280
281 CYStatement *CYFor::Replace(CYContext &context) {
282 context.Replace(initialiser_);
283 context.Replace(test_);
284 context.Replace(increment_);
285 context.Replace(code_);
286 return this;
287 }
288
289 CYStatement *CYForIn::Replace(CYContext &context) {
290 // XXX: this actually might need a prefix statement
291 context.Replace(initialiser_);
292 context.Replace(set_);
293 context.Replace(code_);
294 return this;
295 }
296
297 CYFunctionParameter *CYForInComprehension::Parameter(CYContext &context) const {
298 return $ CYFunctionParameter(name_);
299 }
300
301 CYStatement *CYForInComprehension::Replace(CYContext &context, CYStatement *statement) const {
302 return $ CYForIn($ CYVariable(name_), set_, CYComprehension::Replace(context, statement));
303 }
304
305 CYStatement *CYForEachIn::Replace(CYContext &context) {
306 CYVariable *cys($V("$cys")), *cyt($V("$cyt"));
307
308 return $ CYLet($L2($L($I("$cys"), set_), $L($I("$cyt"))), $$->*
309 $ CYForIn(cyt, cys, $ CYBlock($$->*
310 $E($ CYAssign(initialiser_->ForEachIn(context), $M(cys, cyt)))->*
311 code_
312 ))
313 );
314 }
315
316 CYFunctionParameter *CYForEachInComprehension::Parameter(CYContext &context) const {
317 return $ CYFunctionParameter(name_);
318 }
319
320 CYStatement *CYForEachInComprehension::Replace(CYContext &context, CYStatement *statement) const {
321 CYVariable *cys($V("$cys")), *name($ CYVariable(name_));
322
323 return $E($C0($F(NULL, $P1("$cys"), $$->*
324 $E($ CYAssign(cys, set_))->*
325 $ CYForIn(name, cys, $ CYBlock($$->*
326 $E($ CYAssign(name, $M(cys, name)))->*
327 CYComprehension::Replace(context, statement)
328 ))
329 )));
330 }
331
332 void CYFunction::Inject(CYContext &context) {
333 context.Replace(name_);
334 context.scope_->Declare(context, name_, CYIdentifierOther);
335 }
336
337 void CYFunction::Replace_(CYContext &context, bool outer) {
338 if (outer)
339 Inject(context);
340
341 CYScope scope;
342 scope.parent_ = context.scope_;
343 context.scope_ = &scope;
344
345 if (!outer && name_ != NULL)
346 Inject(context);
347
348 parameters_ = parameters_->Replace(context, code_);
349 code_.Replace(context);
350
351 context.scope_ = scope.parent_;
352 scope.Scope(context, code_.statements_);
353 }
354
355 CYExpression *CYFunctionExpression::Replace(CYContext &context) {
356 Replace_(context, false);
357 return this;
358 }
359
360 CYFunctionParameter *CYFunctionParameter::Replace(CYContext &context, CYBlock &code) {
361 name_ = name_->Replace(context);
362 context.scope_->Declare(context, name_, CYIdentifierArgument);
363 if (next_ != NULL)
364 next_ = next_->Replace(context, code);
365 return this;
366 }
367
368 CYStatement *CYFunctionStatement::Replace(CYContext &context) {
369 Replace_(context, true);
370 return this;
371 }
372
373 CYIdentifier *CYIdentifier::Replace(CYContext &context) {
374 if (replace_ != NULL && replace_ != this)
375 return replace_->Replace(context);
376 replace_ = context.scope_->Lookup(context, this);
377 return replace_;
378 }
379
380 CYStatement *CYIf::Replace(CYContext &context) {
381 context.Replace(test_);
382 context.Replace(true_);
383 context.Replace(false_);
384 return this;
385 }
386
387 CYFunctionParameter *CYIfComprehension::Parameter(CYContext &context) const {
388 return NULL;
389 }
390
391 CYStatement *CYIfComprehension::Replace(CYContext &context, CYStatement *statement) const {
392 return $ CYIf(test_, CYComprehension::Replace(context, statement));
393 }
394
395 CYExpression *CYIndirect::Replace(CYContext &context) {
396 CYPrefix::Replace(context);
397 return $M(rhs_, $S("$cyi"));
398 }
399
400 CYExpression *CYIndirectMember::Replace(CYContext &context) {
401 Replace_(context);
402 return $M($ CYIndirect(object_), property_);
403 }
404
405 CYExpression *CYInfix::Replace(CYContext &context) {
406 context.Replace(lhs_);
407 context.Replace(rhs_);
408 return this;
409 }
410
411 CYStatement *CYLabel::Replace(CYContext &context) {
412 context.Replace(statement_);
413 return this;
414 }
415
416 CYStatement *CYLet::Replace(CYContext &context) {
417 return $ CYWith($ CYObject(declarations_->Property(context)), &code_);
418 }
419
420 void CYMember::Replace_(CYContext &context) {
421 context.Replace(object_);
422 context.Replace(property_);
423 }
424
425 CYExpression *CYNew::Replace(CYContext &context) {
426 context.Replace(constructor_);
427 arguments_->Replace(context);
428 return this;
429 }
430
431 CYNumber *CYNull::Number(CYContext &context) {
432 return $D(0);
433 }
434
435 CYString *CYNull::String(CYContext &context) {
436 return $S("null");
437 }
438
439 CYNumber *CYNumber::Number(CYContext &context) {
440 return this;
441 }
442
443 CYString *CYNumber::String(CYContext &context) {
444 // XXX: there is a precise algorithm for this
445 return $S(apr_psprintf(context.pool_, "%.17g", Value()));
446 }
447
448 CYExpression *CYObject::Replace(CYContext &context) {
449 properties_->Replace(context);
450 return this;
451 }
452
453 CYFunctionParameter *CYOptionalFunctionParameter::Replace(CYContext &context, CYBlock &code) {
454 CYFunctionParameter *parameter($ CYFunctionParameter(name_, next_));
455 parameter = parameter->Replace(context, code);
456
457 CYVariable *name($ CYVariable(name_));
458 code.AddPrev($ CYIf($ CYIdentical($ CYTypeOf(name), $S("undefined")), $$->*
459 $E($ CYAssign(name, initializer_))
460 ));
461
462 return parameter;
463 }
464
465 CYExpression *CYPostfix::Replace(CYContext &context) {
466 context.Replace(lhs_);
467 return this;
468 }
469
470 CYExpression *CYPrefix::Replace(CYContext &context) {
471 context.Replace(rhs_);
472 return this;
473 }
474
475 // XXX: this is evil evil black magic. don't ask, don't tell... don't believe!
476 #define MappingSet "0etnirsoalfucdphmgyvbxTwSNECAFjDLkMOIBPqzRH$_WXUVGYKQJZ"
477 //#define MappingSet "0abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$_"
478
479 namespace {
480 struct IdentifierUsageLess :
481 std::binary_function<CYIdentifier *, CYIdentifier *, bool>
482 {
483 _finline bool operator ()(CYIdentifier *lhs, CYIdentifier *rhs) const {
484 if (lhs->usage_ != rhs->usage_)
485 return lhs->usage_ > rhs->usage_;
486 return lhs < rhs;
487 }
488 };
489
490 typedef std::set<CYIdentifier *, IdentifierUsageLess> IdentifierUsages;
491 }
492
493 void CYProgram::Replace(CYContext &context) {
494 CYScope scope;
495 scope.parent_ = context.scope_;
496 context.scope_ = &scope;
497 statements_ = statements_->ReplaceAll(context);
498 context.scope_ = scope.parent_;
499 scope.Scope(context, statements_);
500
501 size_t offset(0);
502
503 CYCStringSet external;
504 for (CYIdentifierValueSet::const_iterator i(scope.identifiers_.begin()); i != scope.identifiers_.end(); ++i)
505 external.insert((*i)->Word());
506
507 IdentifierUsages usages;
508
509 if (offset < context.rename_.size())
510 for (CYIdentifier *i(context.rename_[offset].identifier_); i != NULL; i = i->next_)
511 usages.insert(i);
512
513 // XXX: totalling the probable occurrences and sorting by them would improve the result
514 for (CYIdentifierUsageVector::const_iterator i(context.rename_.begin()); i != context.rename_.end(); ++i, ++offset) {
515 //std::cout << *i << ":" << (*i)->offset_ << std::endl;
516
517 const char *name;
518
519 if (context.options_.verbose_)
520 name = apr_psprintf(context.pool_, "$%"APR_SIZE_T_FMT"", offset);
521 else {
522 char id[8];
523 id[7] = '\0';
524
525 id:
526 unsigned position(7), local(offset + 1);
527
528 do {
529 unsigned index(local % (sizeof(MappingSet) - 1));
530 local /= sizeof(MappingSet) - 1;
531 id[--position] = MappingSet[index];
532 } while (local != 0);
533
534 if (external.find(id + position) != external.end()) {
535 ++offset;
536 goto id;
537 }
538
539 name = apr_pstrmemdup(context.pool_, id + position, 7 - position);
540 // XXX: at some point, this could become a keyword
541 }
542
543 for (CYIdentifier *identifier(i->identifier_); identifier != NULL; identifier = identifier->next_)
544 identifier->Set(name);
545 }
546 }
547
548 void CYProperty::Replace(CYContext &context) { $T()
549 context.Replace(value_);
550 next_->Replace(context);
551 }
552
553 CYStatement *CYReturn::Replace(CYContext &context) {
554 context.Replace(value_);
555 return this;
556 }
557
558 void CYScope::Declare(CYContext &context, CYIdentifier *identifier, CYIdentifierFlags flags) {
559 internal_.insert(CYIdentifierAddressFlagsMap::value_type(identifier, flags));
560 }
561
562 CYIdentifier *CYScope::Lookup(CYContext &context, CYIdentifier *identifier) {
563 std::pair<CYIdentifierValueSet::iterator, bool> insert(identifiers_.insert(identifier));
564 return *insert.first;
565 }
566
567 void CYScope::Merge(CYContext &context, CYIdentifier *identifier) {
568 std::pair<CYIdentifierValueSet::iterator, bool> insert(identifiers_.insert(identifier));
569 if (!insert.second) {
570 if ((*insert.first)->offset_ < identifier->offset_)
571 (*insert.first)->offset_ = identifier->offset_;
572 identifier->replace_ = *insert.first;
573 (*insert.first)->usage_ += identifier->usage_ + 1;
574 }
575 }
576
577 namespace {
578 struct IdentifierOffset {
579 size_t offset_;
580 CYIdentifierFlags flags_;
581 size_t usage_;
582 CYIdentifier *identifier_;
583
584 IdentifierOffset(CYIdentifier *identifier, CYIdentifierFlags flags) :
585 offset_(identifier->offset_),
586 flags_(flags),
587 usage_(identifier->usage_),
588 identifier_(identifier)
589 {
590 }
591 };
592
593 struct IdentifierOffsetLess :
594 std::binary_function<const IdentifierOffset &, const IdentifierOffset &, bool>
595 {
596 _finline bool operator ()(const IdentifierOffset &lhs, const IdentifierOffset &rhs) const {
597 if (lhs.offset_ != rhs.offset_)
598 return lhs.offset_ < rhs.offset_;
599 if (lhs.flags_ != rhs.flags_)
600 return lhs.flags_ < rhs.flags_;
601 /*if (lhs.usage_ != rhs.usage_)
602 return lhs.usage_ < rhs.usage_;*/
603 return lhs.identifier_ < rhs.identifier_;
604 }
605 };
606
607 typedef std::set<IdentifierOffset, IdentifierOffsetLess> IdentifierOffsets;
608 }
609
610 void CYScope::Scope(CYContext &context, CYStatement *&statements) {
611 if (parent_ == NULL)
612 return;
613
614 CYDeclarations *last(NULL), *curr(NULL);
615
616 IdentifierOffsets offsets;
617
618 for (CYIdentifierAddressFlagsMap::const_iterator i(internal_.begin()); i != internal_.end(); ++i)
619 if (i->second != CYIdentifierMagic)
620 offsets.insert(IdentifierOffset(i->first, i->second));
621
622 size_t offset(0);
623
624 for (IdentifierOffsets::const_iterator i(offsets.begin()); i != offsets.end(); ++i) {
625 if (i->flags_ == CYIdentifierVariable) {
626 CYDeclarations *next($ CYDeclarations($ CYDeclaration(i->identifier_)));
627 if (last == NULL)
628 last = next;
629 if (curr != NULL)
630 curr->SetNext(next);
631 curr = next;
632 }
633
634 if (offset < i->offset_)
635 offset = i->offset_;
636 if (context.rename_.size() <= offset)
637 context.rename_.resize(offset + 1);
638
639 CYIdentifierUsage &rename(context.rename_[offset++]);
640 i->identifier_->SetNext(rename.identifier_);
641 rename.identifier_ = i->identifier_;
642 rename.usage_ += i->identifier_->usage_ + 1;
643 }
644
645 if (last != NULL) {
646 CYVar *var($ CYVar(last));
647 var->SetNext(statements);
648 statements = var;
649 }
650
651 for (CYIdentifierValueSet::const_iterator i(identifiers_.begin()); i != identifiers_.end(); ++i)
652 if (internal_.find(*i) == internal_.end()) {
653 //std::cout << *i << '=' << offset << std::endl;
654 if ((*i)->offset_ < offset)
655 (*i)->offset_ = offset;
656 parent_->Merge(context, *i);
657 }
658 }
659
660 CYStatement *CYStatement::Collapse(CYContext &context) {
661 return this;
662 }
663
664 CYStatement *CYStatement::ReplaceAll(CYContext &context) { $T(NULL)
665 CYStatement *replace(this);
666 context.Replace(replace);
667 replace->SetNext(next_->ReplaceAll(context));
668 return replace->Collapse(context);
669 }
670
671 CYString *CYString::Concat(CYContext &context, CYString *rhs) const {
672 size_t size(size_ + rhs->size_);
673 char *value(new(context.pool_) char[size + 1]);
674 memcpy(value, value_, size_);
675 memcpy(value + size_, rhs->value_, rhs->size_);
676 value[size] = '\0';
677 return $S(value, size);
678 }
679
680 CYNumber *CYString::Number(CYContext &context) {
681 // XXX: there is a precise algorithm for this
682 return NULL;
683 }
684
685 CYString *CYString::String(CYContext &context) {
686 return this;
687 }
688
689 CYStatement *CYSwitch::Replace(CYContext &context) {
690 context.Replace(value_);
691 clauses_->Replace(context);
692 return this;
693 }
694
695 CYExpression *CYThis::Replace(CYContext &context) {
696 return this;
697 }
698
699 namespace cy {
700 namespace Syntax {
701
702 CYStatement *Throw::Replace(CYContext &context) {
703 context.Replace(value_);
704 return this;
705 }
706
707 } }
708
709 CYExpression *CYTrivial::Replace(CYContext &context) {
710 return this;
711 }
712
713 CYNumber *CYTrue::Number(CYContext &context) {
714 return $D(1);
715 }
716
717 CYString *CYTrue::String(CYContext &context) {
718 return $S("true");
719 }
720
721 namespace cy {
722 namespace Syntax {
723
724 CYStatement *Try::Replace(CYContext &context) {
725 code_.Replace(context);
726 catch_->Replace(context);
727 finally_->Replace(context);
728 return this;
729 }
730
731 } }
732
733 CYStatement *CYVar::Replace(CYContext &context) {
734 return $E(declarations_->Replace(context));
735 }
736
737 CYExpression *CYVariable::Replace(CYContext &context) {
738 name_ = name_->Replace(context);
739 return this;
740 }
741
742 CYStatement *CYWhile::Replace(CYContext &context) {
743 context.Replace(test_);
744 context.Replace(code_);
745 return this;
746 }
747
748 CYStatement *CYWith::Replace(CYContext &context) {
749 context.Replace(scope_);
750 context.Replace(code_);
751 return this;
752 }
753
754 CYExpression *CYWord::ClassName(CYContext &context, bool object) {
755 CYString *name($S(this));
756 if (object)
757 return $C1($V("objc_getClass"), name);
758 else
759 return name;
760 }