1 /* Cycript - Optimizing JavaScript Compiler/Runtime
2 * Copyright (C) 2009-2010 Jay Freeman (saurik)
5 /* GNU Lesser General Public License, Version 3 {{{ */
7 * Cycript is free software: you can redistribute it and/or modify it under
8 * the terms of the GNU Lesser General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
12 * Cycript is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15 * License for more details.
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with Cycript. If not, see <http://www.gnu.org/licenses/>.
23 #include "Replace.hpp"
27 CYExpression
*CYAdd::Replace(CYContext
&context
) {
28 CYInfix::Replace(context
);
30 CYExpression
*lhp(lhs_
->Primitive(context
));
31 CYExpression
*rhp(rhs_
->Primitive(context
));
33 CYString
*lhs(dynamic_cast<CYString
*>(lhp
));
34 CYString
*rhs(dynamic_cast<CYString
*>(rhp
));
36 if (lhs
!= NULL
|| rhs
!= NULL
) {
38 lhs
= lhp
->String(context
);
41 } else if (rhs
== NULL
) {
42 rhs
= rhp
->String(context
);
47 return lhs
->Concat(context
, rhs
);
50 if (CYNumber
*lhn
= lhp
->Number(context
))
51 if (CYNumber
*rhn
= rhp
->Number(context
))
52 return $
D(lhn
->Value() + rhn
->Value());
57 CYExpression
*CYAddressOf::Replace(CYContext
&context
) {
58 CYPrefix::Replace(context
);
59 return $
C0($
M(rhs_
, $
S("$cya")));
62 void CYArgument::Replace(CYContext
&context
) { $
T()
63 context
.Replace(value_
);
64 next_
->Replace(context
);
67 CYExpression
*CYArray::Replace(CYContext
&context
) {
68 elements_
->Replace(context
);
72 CYExpression
*CYArrayComprehension::Replace(CYContext
&context
) {
73 CYVariable
*cyv($
V("$cyv"));
75 return $
C0($
F(NULL
, $
P1("$cyv", comprehensions_
->Parameters(context
)), $$
->*
76 $
E($
CYAssign(cyv
, $
CYArray()))->*
77 comprehensions_
->Replace(context
, $
E($
C1($
M(cyv
, $
S("push")), expression_
)))->*
82 CYExpression
*CYAssignment::Replace(CYContext
&context
) {
83 context
.Replace(lhs_
);
84 context
.Replace(rhs_
);
88 CYStatement
*CYBlock::Replace(CYContext
&context
) {
89 context
.ReplaceAll(statements_
);
90 if (statements_
== NULL
)
95 CYStatement
*CYBreak::Replace(CYContext
&context
) {
99 CYExpression
*CYCall::AddArgument(CYContext
&context
, CYExpression
*value
) {
100 CYArgument
**argument(&arguments_
);
101 while (*argument
!= NULL
)
102 argument
= &(*argument
)->next_
;
103 *argument
= $
CYArgument(value
);
107 CYExpression
*CYCall::Replace(CYContext
&context
) {
108 context
.Replace(function_
);
109 arguments_
->Replace(context
);
116 void Catch::Replace(CYContext
&context
) { $
T()
117 CYScope
scope(CYScopeCatch
, context
, code_
.statements_
);
119 context
.Replace(name_
);
120 context
.scope_
->Declare(context
, name_
, CYIdentifierCatch
);
122 code_
.Replace(context
);
128 void CYClause::Replace(CYContext
&context
) { $
T()
129 context
.Replace(case_
);
130 context
.ReplaceAll(statements_
);
131 next_
->Replace(context
);
134 CYStatement
*CYComment::Replace(CYContext
&context
) {
138 CYExpression
*CYCompound::Replace(CYContext
&context
) {
139 context
.ReplaceAll(expressions_
);
140 if (expressions_
== NULL
)
145 CYFunctionParameter
*CYComprehension::Parameters(CYContext
&context
) const { $
T(NULL
)
146 CYFunctionParameter
*next(next_
->Parameters(context
));
147 if (CYFunctionParameter
*parameter
= Parameter(context
)) {
148 parameter
->SetNext(next
);
154 CYStatement
*CYComprehension::Replace(CYContext
&context
, CYStatement
*statement
) const {
155 return next_
== NULL
? statement
: next_
->Replace(context
, statement
);
158 CYExpression
*CYCondition::Replace(CYContext
&context
) {
159 context
.Replace(test_
);
160 context
.Replace(true_
);
161 context
.Replace(false_
);
165 void CYContext::NonLocal(CYStatement
*&statements
) {
166 CYContext
&context(*this);
168 if (nextlocal_
!= NULL
&& nextlocal_
->identifier_
!= NULL
) {
169 CYIdentifier
*cye($
I("$cye")->Replace(context
));
170 CYIdentifier
*unique(nextlocal_
->identifier_
->Replace(context
));
172 CYStatement
*declare(
173 $
CYVar($
L1($
L(unique
, $
CYObject()))));
175 cy::Syntax::Catch
*rescue(
176 $
cy::Syntax::Catch(cye
, $$
->*
177 $
CYIf($
CYIdentical($
M($
V(cye
), $
S("$cyk")), $
V(unique
)), $$
->*
178 $
CYReturn($
M($
V(cye
), $
S("$cyv"))))->*
179 $
cy::Syntax::Throw($
V(cye
))));
181 context
.Replace(declare
);
182 rescue
->Replace(context
);
186 $
cy::Syntax::Try(statements
, rescue
, NULL
);
190 CYIdentifier
*CYContext::Unique() {
191 return $
CYIdentifier(apr_psprintf($pool
, "$cy%u", unique_
++));
194 CYStatement
*CYContinue::Replace(CYContext
&context
) {
198 CYAssignment
*CYDeclaration::Assignment(CYContext
&context
) {
199 if (initialiser_
== NULL
)
201 return $
CYAssign(Variable(context
), initialiser_
);
204 CYVariable
*CYDeclaration::Variable(CYContext
&context
) {
205 return $
V(identifier_
);
208 CYStatement
*CYDeclaration::ForEachIn(CYContext
&context
, CYExpression
*value
) {
209 return $
CYVar($
L1($
L(identifier_
, value
)));
212 CYExpression
*CYDeclaration::Replace(CYContext
&context
) {
213 context
.Replace(identifier_
);
214 context
.scope_
->Declare(context
, identifier_
, CYIdentifierVariable
);
215 return Variable(context
);
218 void CYDeclarations::Replace(CYContext
&context
) { $
T()
219 declaration_
->Replace(context
);
220 next_
->Replace(context
);
223 CYProperty
*CYDeclarations::Property(CYContext
&context
) { $
T(NULL
)
224 return $
CYProperty(declaration_
->identifier_
, declaration_
->initialiser_
?: $U
, next_
->Property(context
));
227 CYFunctionParameter
*CYDeclarations::Parameter(CYContext
&context
) { $
T(NULL
)
228 return $
CYFunctionParameter(declaration_
->identifier_
, next_
->Parameter(context
));
231 CYArgument
*CYDeclarations::Argument(CYContext
&context
) { $
T(NULL
)
232 return $
CYArgument(declaration_
->initialiser_
?: $U
, next_
->Argument(context
));
235 CYCompound
*CYDeclarations::Compound(CYContext
&context
) { $
T(NULL
)
236 CYCompound
*compound(next_
->Compound(context
) ?: $
CYCompound());
237 if (CYAssignment
*assignment
= declaration_
->Assignment(context
))
238 compound
->AddPrev(assignment
);
242 CYExpression
*CYDirectMember::Replace(CYContext
&context
) {
247 CYStatement
*CYDoWhile::Replace(CYContext
&context
) {
248 context
.Replace(test_
);
249 context
.Replace(code_
);
253 void CYElement::Replace(CYContext
&context
) { $
T()
254 context
.Replace(value_
);
255 next_
->Replace(context
);
258 CYStatement
*CYEmpty::Replace(CYContext
&context
) {
262 CYStatement
*CYExpress::Replace(CYContext
&context
) {
263 while (CYExpress
*express
= dynamic_cast<CYExpress
*>(next_
)) {
264 CYCompound
*compound(dynamic_cast<CYCompound
*>(express
->expression_
));
265 if (compound
== NULL
)
266 compound
= $
CYCompound(express
->expression_
);
267 compound
->AddPrev(expression_
);
268 expression_
= compound
;
269 SetNext(express
->next_
);
272 context
.Replace(expression_
);
273 if (expression_
== NULL
)
279 CYExpression
*CYExpression::AddArgument(CYContext
&context
, CYExpression
*value
) {
280 return $
C1(this, value
);
283 CYExpression
*CYExpression::ClassName(CYContext
&context
, bool object
) {
287 CYStatement
*CYExpression::ForEachIn(CYContext
&context
, CYExpression
*value
) {
288 return $
E($
CYAssign(this, value
));
291 CYAssignment
*CYExpression::Assignment(CYContext
&context
) {
295 CYNumber
*CYFalse::Number(CYContext
&context
) {
299 CYString
*CYFalse::String(CYContext
&context
) {
303 void CYFinally::Replace(CYContext
&context
) { $
T()
304 code_
.Replace(context
);
307 CYStatement
*CYFor::Replace(CYContext
&context
) {
308 context
.Replace(initialiser_
);
309 context
.Replace(test_
);
310 context
.Replace(increment_
);
311 context
.Replace(code_
);
315 CYCompound
*CYForDeclarations::Replace(CYContext
&context
) {
316 declarations_
->Replace(context
);
317 return declarations_
->Compound(context
);
320 // XXX: this still feels highly suboptimal
321 CYStatement
*CYForIn::Replace(CYContext
&context
) {
322 CYForInInitialiser
*initialiser(initialiser_
);
324 context
.Replace(initialiser_
);
325 context
.Replace(set_
);
326 context
.Replace(code_
);
328 if (CYAssignment
*assignment
= initialiser
->Assignment(context
))
329 return $
CYBlock($$
->*
337 CYFunctionParameter
*CYForInComprehension::Parameter(CYContext
&context
) const {
338 return $
CYFunctionParameter(name_
);
341 CYStatement
*CYForInComprehension::Replace(CYContext
&context
, CYStatement
*statement
) const {
342 return $
CYForIn($
V(name_
), set_
, CYComprehension::Replace(context
, statement
));
345 CYStatement
*CYForEachIn::Replace(CYContext
&context
) {
346 CYIdentifier
*cys($
I("$cys")), *cyt($
I("$cyt"));
348 return $
CYLet($
L2($
L(cys
, set_
), $
L(cyt
)), $$
->*
349 $
CYForIn($
V(cyt
), $
V(cys
), $
CYBlock($$
->*
350 initialiser_
->ForEachIn(context
, $
M($
V(cys
), $
V(cyt
)))->*
356 CYFunctionParameter
*CYForEachInComprehension::Parameter(CYContext
&context
) const {
357 return $
CYFunctionParameter(name_
);
360 CYStatement
*CYForEachInComprehension::Replace(CYContext
&context
, CYStatement
*statement
) const {
361 CYIdentifier
*cys($
I("cys"));
363 return $
E($
C0($
F(NULL
, $
P1("$cys"), $$
->*
364 $
E($
CYAssign($
V(cys
), set_
))->*
365 $
CYForIn($
V(name_
), $
V(cys
), $
CYBlock($$
->*
366 $
E($
CYAssign($
V(name_
), $
M($
V(cys
), $
V(name_
))))->*
367 CYComprehension::Replace(context
, statement
)
372 void CYFunction::Inject(CYContext
&context
) {
373 context
.Replace(name_
);
374 context
.scope_
->Declare(context
, name_
, CYIdentifierOther
);
377 void CYFunction::Replace_(CYContext
&context
, bool outer
) {
381 CYScope
scope(CYScopeFunction
, context
, code_
.statements_
);
383 CYNonLocal
*nonlocal(context
.nonlocal_
);
384 CYNonLocal
*nextlocal(context
.nextlocal_
);
387 if (nonlocal_
!= NULL
) {
389 context
.nonlocal_
= nonlocal_
;
392 nonlocal_
= $
CYNonLocal();
393 context
.nextlocal_
= nonlocal_
;
396 if (!outer
&& name_
!= NULL
)
399 if (parameters_
!= NULL
)
400 parameters_
= parameters_
->Replace(context
, code_
);
402 code_
.Replace(context
);
405 context
.NonLocal(code_
.statements_
);
407 context
.nextlocal_
= nextlocal
;
408 context
.nonlocal_
= nonlocal
;
413 CYExpression
*CYFunctionExpression::Replace(CYContext
&context
) {
414 Replace_(context
, false);
418 CYFunctionParameter
*CYFunctionParameter::Replace(CYContext
&context
, CYBlock
&code
) {
419 context
.Replace(name_
);
420 context
.scope_
->Declare(context
, name_
, CYIdentifierArgument
);
422 next_
= next_
->Replace(context
, code
);
426 CYStatement
*CYFunctionStatement::Replace(CYContext
&context
) {
427 Replace_(context
, true);
431 CYIdentifier
*CYIdentifier::Replace(CYContext
&context
) {
432 if (replace_
!= NULL
&& replace_
!= this)
433 return replace_
->Replace(context
);
434 replace_
= context
.scope_
->Lookup(context
, this);
438 CYStatement
*CYIf::Replace(CYContext
&context
) {
439 context
.Replace(test_
);
440 context
.Replace(true_
);
441 context
.Replace(false_
);
445 CYFunctionParameter
*CYIfComprehension::Parameter(CYContext
&context
) const {
449 CYStatement
*CYIfComprehension::Replace(CYContext
&context
, CYStatement
*statement
) const {
450 return $
CYIf(test_
, CYComprehension::Replace(context
, statement
));
453 CYExpression
*CYIndirect::Replace(CYContext
&context
) {
454 CYPrefix::Replace(context
);
455 return $
M(rhs_
, $
S("$cyi"));
458 CYExpression
*CYIndirectMember::Replace(CYContext
&context
) {
460 return $
M($
CYIndirect(object_
), property_
);
463 CYExpression
*CYInfix::Replace(CYContext
&context
) {
464 context
.Replace(lhs_
);
465 context
.Replace(rhs_
);
469 CYStatement
*CYLabel::Replace(CYContext
&context
) {
470 context
.Replace(statement_
);
474 CYStatement
*CYLet::Replace(CYContext
&context
) {
475 declarations_
->Replace(context
);
476 return $
CYWith($
CYObject(declarations_
->Property(context
)), code_
);
479 void CYMember::Replace_(CYContext
&context
) {
480 context
.Replace(object_
);
481 context
.Replace(property_
);
487 CYExpression
*New::AddArgument(CYContext
&context
, CYExpression
*value
) {
488 CYSetLast(arguments_
, $
CYArgument(value
));
492 CYExpression
*New::Replace(CYContext
&context
) {
493 context
.Replace(constructor_
);
494 arguments_
->Replace(context
);
500 CYNumber
*CYNull::Number(CYContext
&context
) {
504 CYString
*CYNull::String(CYContext
&context
) {
508 CYNumber
*CYNumber::Number(CYContext
&context
) {
512 CYString
*CYNumber::String(CYContext
&context
) {
513 // XXX: there is a precise algorithm for this
514 return $
S(apr_psprintf($pool
, "%.17g", Value()));
517 CYExpression
*CYObject::Replace(CYContext
&context
) {
518 properties_
->Replace(context
);
522 CYFunctionParameter
*CYOptionalFunctionParameter::Replace(CYContext
&context
, CYBlock
&code
) {
523 CYFunctionParameter
*parameter($
CYFunctionParameter(name_
, next_
));
524 parameter
= parameter
->Replace(context
, code
);
525 context
.Replace(initializer_
);
527 CYVariable
*name($
V(name_
));
528 code
.AddPrev($
CYIf($
CYIdentical($
CYTypeOf(name
), $
S("undefined")), $$
->*
529 $
E($
CYAssign(name
, initializer_
))
535 CYExpression
*CYPostfix::Replace(CYContext
&context
) {
536 context
.Replace(lhs_
);
540 CYExpression
*CYPrefix::Replace(CYContext
&context
) {
541 context
.Replace(rhs_
);
545 // XXX: this is evil evil black magic. don't ask, don't tell... don't believe!
546 #define MappingSet "0etnirsoalfucdphmgyvbxTwSNECAFjDLkMOIBPqzRH$_WXUVGYKQJZ"
547 //#define MappingSet "0abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$_"
550 struct IdentifierUsageLess
:
551 std::binary_function
<CYIdentifier
*, CYIdentifier
*, bool>
553 _finline
bool operator ()(CYIdentifier
*lhs
, CYIdentifier
*rhs
) const {
554 if (lhs
->usage_
!= rhs
->usage_
)
555 return lhs
->usage_
> rhs
->usage_
;
560 typedef std::set
<CYIdentifier
*, IdentifierUsageLess
> IdentifierUsages
;
563 void CYProgram::Replace(CYContext
&context
) {
564 CYScope
scope(CYScopeProgram
, context
, statements_
);
566 context
.nextlocal_
= $
CYNonLocal();
567 context
.ReplaceAll(statements_
);
568 context
.NonLocal(statements_
);
574 CYCStringSet external
;
575 for (CYIdentifierValueSet::const_iterator
i(scope
.identifiers_
.begin()); i
!= scope
.identifiers_
.end(); ++i
)
576 external
.insert((*i
)->Word());
578 IdentifierUsages usages
;
580 if (offset
< context
.rename_
.size())
581 CYForEach (i
, context
.rename_
[offset
].identifier_
)
584 // XXX: totalling the probable occurrences and sorting by them would improve the result
585 for (CYIdentifierUsageVector::const_iterator
i(context
.rename_
.begin()); i
!= context
.rename_
.end(); ++i
, ++offset
) {
586 //std::cout << *i << ":" << (*i)->offset_ << std::endl;
590 if (context
.options_
.verbose_
)
591 name
= apr_psprintf($pool
, "$%"APR_SIZE_T_FMT
"", offset
);
597 unsigned position(7), local(offset
+ 1);
600 unsigned index(local
% (sizeof(MappingSet
) - 1));
601 local
/= sizeof(MappingSet
) - 1;
602 id
[--position
] = MappingSet
[index
];
603 } while (local
!= 0);
605 if (external
.find(id
+ position
) != external
.end()) {
610 name
= apr_pstrmemdup($pool
, id
+ position
, 7 - position
);
611 // XXX: at some point, this could become a keyword
614 CYForEach (identifier
, i
->identifier_
)
615 identifier
->Set(name
);
619 void CYProperty::Replace(CYContext
&context
) { $
T()
620 context
.Replace(value_
);
621 next_
->Replace(context
);
624 CYStatement
*CYReturn::Replace(CYContext
&context
) {
625 if (context
.nonlocal_
!= NULL
) {
626 CYProperty
*value(value_
== NULL
? NULL
: $
CYProperty($
S("$cyv"), value_
));
627 return $
cy::Syntax::Throw($
CYObject(
628 $
CYProperty($
S("$cyk"), $
V(context
.nonlocal_
->Target(context
)), value
)
632 context
.Replace(value_
);
636 CYExpression
*CYRubyBlock::Replace(CYContext
&context
) {
637 // XXX: this needs to do something much more epic to handle return
638 return call_
->AddArgument(context
, proc_
->Replace(context
));
641 CYExpression
*CYRubyProc::Replace(CYContext
&context
) {
642 CYFunctionExpression
*function($
CYFunctionExpression(NULL
, parameters_
, code_
));
643 function
->nonlocal_
= context
.nextlocal_
;
647 CYScope::CYScope(CYScopeType type
, CYContext
&context
, CYStatement
*&statements
) :
650 statements_(statements
),
651 parent_(context
.scope_
)
653 context_
.scope_
= this;
656 CYScope::~CYScope() {
659 void CYScope::Close() {
660 context_
.scope_
= parent_
;
661 Scope(context_
, statements_
);
664 void CYScope::Declare(CYContext
&context
, CYIdentifier
*identifier
, CYIdentifierFlags flags
) {
665 if (type_
== CYScopeCatch
&& flags
!= CYIdentifierCatch
)
666 parent_
->Declare(context
, identifier
, flags
);
668 internal_
.insert(CYIdentifierAddressFlagsMap::value_type(identifier
, flags
));
671 CYIdentifier
*CYScope::Lookup(CYContext
&context
, CYIdentifier
*identifier
) {
672 std::pair
<CYIdentifierValueSet::iterator
, bool> insert(identifiers_
.insert(identifier
));
673 return *insert
.first
;
676 void CYScope::Merge(CYContext
&context
, CYIdentifier
*identifier
) {
677 std::pair
<CYIdentifierValueSet::iterator
, bool> insert(identifiers_
.insert(identifier
));
678 if (!insert
.second
) {
679 if ((*insert
.first
)->offset_
< identifier
->offset_
)
680 (*insert
.first
)->offset_
= identifier
->offset_
;
681 identifier
->replace_
= *insert
.first
;
682 (*insert
.first
)->usage_
+= identifier
->usage_
+ 1;
687 struct IdentifierOffset
{
689 CYIdentifierFlags flags_
;
691 CYIdentifier
*identifier_
;
693 IdentifierOffset(CYIdentifier
*identifier
, CYIdentifierFlags flags
) :
694 offset_(identifier
->offset_
),
696 usage_(identifier
->usage_
),
697 identifier_(identifier
)
702 struct IdentifierOffsetLess
:
703 std::binary_function
<const IdentifierOffset
&, const IdentifierOffset
&, bool>
705 _finline
bool operator ()(const IdentifierOffset
&lhs
, const IdentifierOffset
&rhs
) const {
706 if (lhs
.offset_
!= rhs
.offset_
)
707 return lhs
.offset_
< rhs
.offset_
;
708 if (lhs
.flags_
!= rhs
.flags_
)
709 return lhs
.flags_
< rhs
.flags_
;
710 /*if (lhs.usage_ != rhs.usage_)
711 return lhs.usage_ < rhs.usage_;*/
712 return lhs
.identifier_
< rhs
.identifier_
;
716 typedef std::set
<IdentifierOffset
, IdentifierOffsetLess
> IdentifierOffsets
;
719 void CYScope::Scope(CYContext
&context
, CYStatement
*&statements
) {
723 CYDeclarations
*last(NULL
), *curr(NULL
);
725 IdentifierOffsets offsets
;
727 for (CYIdentifierAddressFlagsMap::const_iterator
i(internal_
.begin()); i
!= internal_
.end(); ++i
)
728 if (i
->second
!= CYIdentifierMagic
)
729 offsets
.insert(IdentifierOffset(i
->first
, i
->second
));
733 for (IdentifierOffsets::const_iterator
i(offsets
.begin()); i
!= offsets
.end(); ++i
) {
734 if (i
->flags_
== CYIdentifierVariable
) {
735 CYDeclarations
*next($
CYDeclarations($
CYDeclaration(i
->identifier_
)));
743 if (offset
< i
->offset_
)
745 if (context
.rename_
.size() <= offset
)
746 context
.rename_
.resize(offset
+ 1);
748 CYIdentifierUsage
&rename(context
.rename_
[offset
++]);
749 i
->identifier_
->SetNext(rename
.identifier_
);
750 rename
.identifier_
= i
->identifier_
;
751 rename
.usage_
+= i
->identifier_
->usage_
+ 1;
755 CYVar
*var($
CYVar(last
));
756 var
->SetNext(statements
);
760 for (CYIdentifierValueSet::const_iterator
i(identifiers_
.begin()); i
!= identifiers_
.end(); ++i
)
761 if (internal_
.find(*i
) == internal_
.end()) {
762 //std::cout << *i << '=' << offset << std::endl;
763 if ((*i
)->offset_
< offset
)
764 (*i
)->offset_
= offset
;
765 parent_
->Merge(context
, *i
);
769 CYString
*CYString::Concat(CYContext
&context
, CYString
*rhs
) const {
770 size_t size(size_
+ rhs
->size_
);
771 char *value($
char[size
+ 1]);
772 memcpy(value
, value_
, size_
);
773 memcpy(value
+ size_
, rhs
->value_
, rhs
->size_
);
775 return $
S(value
, size
);
778 CYNumber
*CYString::Number(CYContext
&context
) {
779 // XXX: there is a precise algorithm for this
783 CYString
*CYString::String(CYContext
&context
) {
787 CYStatement
*CYSwitch::Replace(CYContext
&context
) {
788 context
.Replace(value_
);
789 clauses_
->Replace(context
);
793 CYExpression
*CYThis::Replace(CYContext
&context
) {
800 CYStatement
*Throw::Replace(CYContext
&context
) {
801 context
.Replace(value_
);
807 CYExpression
*CYTrivial::Replace(CYContext
&context
) {
811 CYNumber
*CYTrue::Number(CYContext
&context
) {
815 CYString
*CYTrue::String(CYContext
&context
) {
822 CYStatement
*Try::Replace(CYContext
&context
) {
823 code_
.Replace(context
);
824 catch_
->Replace(context
);
825 finally_
->Replace(context
);
831 CYStatement
*CYVar::Replace(CYContext
&context
) {
832 declarations_
->Replace(context
);
833 return $
E(declarations_
->Compound(context
));
836 CYExpression
*CYVariable::Replace(CYContext
&context
) {
837 context
.Replace(name_
);
841 CYStatement
*CYWhile::Replace(CYContext
&context
) {
842 context
.Replace(test_
);
843 context
.Replace(code_
);
847 CYStatement
*CYWith::Replace(CYContext
&context
) {
848 context
.Replace(scope_
);
849 context
.Replace(code_
);
853 CYExpression
*CYWord::ClassName(CYContext
&context
, bool object
) {
854 CYString
*name($
S(this));
856 return $
C1($
V("objc_getClass"), name
);