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 CYFunctionExpression
*CYNonLocalize(CYContext
&context
, CYFunctionExpression
*function
) {
28 function
->nonlocal_
= context
.nextlocal_
;
32 CYExpression
*CYAdd::Replace(CYContext
&context
) {
33 CYInfix::Replace(context
);
35 CYExpression
*lhp(lhs_
->Primitive(context
));
36 CYExpression
*rhp(rhs_
->Primitive(context
));
38 CYString
*lhs(dynamic_cast<CYString
*>(lhp
));
39 CYString
*rhs(dynamic_cast<CYString
*>(rhp
));
41 if (lhs
!= NULL
|| rhs
!= NULL
) {
43 lhs
= lhp
->String(context
);
46 } else if (rhs
== NULL
) {
47 rhs
= rhp
->String(context
);
52 return lhs
->Concat(context
, rhs
);
55 if (CYNumber
*lhn
= lhp
->Number(context
))
56 if (CYNumber
*rhn
= rhp
->Number(context
))
57 return $
D(lhn
->Value() + rhn
->Value());
62 CYExpression
*CYAddressOf::Replace(CYContext
&context
) {
63 return $
C0($
M(rhs_
, $
S("$cya")));
66 CYArgument
*CYArgument::Replace(CYContext
&context
) { $
T(NULL
)
67 context
.Replace(value_
);
68 next_
= next_
->Replace(context
);
80 CYExpression
*CYArray::Replace(CYContext
&context
) {
81 elements_
->Replace(context
);
85 CYExpression
*CYArrayComprehension::Replace(CYContext
&context
) {
86 CYVariable
*cyv($
V("$cyv"));
88 return $
C0($
F(NULL
, $
P1("$cyv", comprehensions_
->Parameters(context
)), $$
->*
89 $
E($
CYAssign(cyv
, $
CYArray()))->*
90 comprehensions_
->Replace(context
, $
E($
C1($
M(cyv
, $
S("push")), expression_
)))->*
95 CYExpression
*CYAssignment::Replace(CYContext
&context
) {
96 context
.Replace(lhs_
);
97 context
.Replace(rhs_
);
101 CYStatement
*CYBlock::Replace(CYContext
&context
) {
102 context
.ReplaceAll(statements_
);
103 if (statements_
== NULL
)
108 CYStatement
*CYBreak::Replace(CYContext
&context
) {
112 CYExpression
*CYCall::AddArgument(CYContext
&context
, CYExpression
*value
) {
113 CYArgument
**argument(&arguments_
);
114 while (*argument
!= NULL
)
115 argument
= &(*argument
)->next_
;
116 *argument
= $
CYArgument(value
);
120 CYExpression
*CYCall::Replace(CYContext
&context
) {
121 context
.Replace(function_
);
122 arguments_
->Replace(context
);
129 void Catch::Replace(CYContext
&context
) { $
T()
130 CYScope
scope(true, context
, code_
.statements_
);
132 context
.Replace(name_
);
133 context
.scope_
->Declare(context
, name_
, CYIdentifierCatch
);
135 code_
.Replace(context
);
141 void CYClause::Replace(CYContext
&context
) { $
T()
142 context
.Replace(case_
);
143 context
.ReplaceAll(statements_
);
144 next_
->Replace(context
);
147 CYStatement
*CYComment::Replace(CYContext
&context
) {
151 CYExpression
*CYCompound::Replace(CYContext
&context
) {
152 context
.ReplaceAll(expressions_
);
153 if (expressions_
== NULL
)
158 CYFunctionParameter
*CYComprehension::Parameters(CYContext
&context
) const { $
T(NULL
)
159 CYFunctionParameter
*next(next_
->Parameters(context
));
160 if (CYFunctionParameter
*parameter
= Parameter(context
)) {
161 parameter
->SetNext(next
);
167 CYStatement
*CYComprehension::Replace(CYContext
&context
, CYStatement
*statement
) const {
168 return next_
== NULL
? statement
: next_
->Replace(context
, statement
);
171 CYExpression
*CYCondition::Replace(CYContext
&context
) {
172 context
.Replace(test_
);
173 context
.Replace(true_
);
174 context
.Replace(false_
);
178 void CYContext::NonLocal(CYStatement
*&statements
) {
179 CYContext
&context(*this);
181 if (nextlocal_
!= NULL
&& nextlocal_
->identifier_
!= NULL
) {
182 CYIdentifier
*cye($
I("$cye")->Replace(context
));
183 CYIdentifier
*unique(nextlocal_
->identifier_
->Replace(context
));
185 CYStatement
*declare(
186 $
CYVar($
L1($
L(unique
, $
CYObject()))));
188 cy::Syntax::Catch
*rescue(
189 $
cy::Syntax::Catch(cye
, $$
->*
190 $
CYIf($
CYIdentical($
M($
V(cye
), $
S("$cyk")), $
V(unique
)), $$
->*
191 $
CYReturn($
M($
V(cye
), $
S("$cyv"))))->*
192 $
cy::Syntax::Throw($
V(cye
))));
194 context
.Replace(declare
);
195 rescue
->Replace(context
);
199 $
cy::Syntax::Try(statements
, rescue
, NULL
);
203 CYIdentifier
*CYContext::Unique() {
204 return $
CYIdentifier(apr_psprintf($pool
, "$cy%u", unique_
++));
207 CYStatement
*CYContinue::Replace(CYContext
&context
) {
211 CYAssignment
*CYDeclaration::Assignment(CYContext
&context
) {
212 if (initialiser_
== NULL
)
215 CYAssignment
*value($
CYAssign(Variable(context
), initialiser_
));
220 CYVariable
*CYDeclaration::Variable(CYContext
&context
) {
221 return $
V(identifier_
);
224 CYStatement
*CYDeclaration::ForEachIn(CYContext
&context
, CYExpression
*value
) {
225 return $
CYVar($
L1($
L(identifier_
, value
)));
228 CYExpression
*CYDeclaration::Replace(CYContext
&context
) {
229 context
.Replace(identifier_
);
230 context
.scope_
->Declare(context
, identifier_
, CYIdentifierVariable
);
231 return Variable(context
);
234 void CYDeclarations::Replace(CYContext
&context
) { $
T()
235 declaration_
->Replace(context
);
236 next_
->Replace(context
);
239 CYProperty
*CYDeclarations::Property(CYContext
&context
) { $
T(NULL
)
240 return $
CYProperty(declaration_
->identifier_
, declaration_
->initialiser_
, next_
->Property(context
));
243 CYFunctionParameter
*CYDeclarations::Parameter(CYContext
&context
) { $
T(NULL
)
244 return $
CYFunctionParameter(declaration_
->identifier_
, next_
->Parameter(context
));
247 CYArgument
*CYDeclarations::Argument(CYContext
&context
) { $
T(NULL
)
248 return $
CYArgument(declaration_
->initialiser_
, next_
->Argument(context
));
251 CYCompound
*CYDeclarations::Compound(CYContext
&context
) { $
T(NULL
)
252 CYCompound
*compound(next_
->Compound(context
) ?: $
CYCompound());
253 if (CYAssignment
*assignment
= declaration_
->Assignment(context
))
254 compound
->AddPrev(assignment
);
258 CYExpression
*CYDirectMember::Replace(CYContext
&context
) {
259 context
.Replace(object_
);
260 context
.Replace(property_
);
264 CYStatement
*CYDoWhile::Replace(CYContext
&context
) {
265 context
.Replace(test_
);
266 context
.Replace(code_
);
270 void CYElement::Replace(CYContext
&context
) { $
T()
271 context
.Replace(value_
);
272 next_
->Replace(context
);
275 CYStatement
*CYEmpty::Replace(CYContext
&context
) {
279 CYStatement
*CYExpress::Replace(CYContext
&context
) {
280 while (CYExpress
*express
= dynamic_cast<CYExpress
*>(next_
)) {
281 CYCompound
*compound(dynamic_cast<CYCompound
*>(express
->expression_
));
282 if (compound
== NULL
)
283 compound
= $
CYCompound(express
->expression_
);
284 compound
->AddPrev(expression_
);
285 expression_
= compound
;
286 SetNext(express
->next_
);
289 context
.Replace(expression_
);
290 if (expression_
== NULL
)
296 CYExpression
*CYExpression::AddArgument(CYContext
&context
, CYExpression
*value
) {
297 return $
C1(this, value
);
300 CYExpression
*CYExpression::ClassName(CYContext
&context
, bool object
) {
304 CYStatement
*CYExpression::ForEachIn(CYContext
&context
, CYExpression
*value
) {
305 return $
E($
CYAssign(this, value
));
308 CYAssignment
*CYExpression::Assignment(CYContext
&context
) {
312 CYNumber
*CYFalse::Number(CYContext
&context
) {
316 CYString
*CYFalse::String(CYContext
&context
) {
320 void CYFinally::Replace(CYContext
&context
) { $
T()
321 code_
.Replace(context
);
324 CYStatement
*CYFor::Replace(CYContext
&context
) {
325 context
.Replace(initialiser_
);
326 context
.Replace(test_
);
327 context
.Replace(increment_
);
328 context
.Replace(code_
);
332 CYCompound
*CYForDeclarations::Replace(CYContext
&context
) {
333 declarations_
->Replace(context
);
334 return declarations_
->Compound(context
);
337 // XXX: this still feels highly suboptimal
338 CYStatement
*CYForIn::Replace(CYContext
&context
) {
339 if (CYAssignment
*assignment
= initialiser_
->Assignment(context
))
340 return $
CYBlock($$
->*
345 context
.Replace(initialiser_
);
346 context
.Replace(set_
);
347 context
.Replace(code_
);
351 CYFunctionParameter
*CYForInComprehension::Parameter(CYContext
&context
) const {
352 return $
CYFunctionParameter(name_
);
355 CYStatement
*CYForInComprehension::Replace(CYContext
&context
, CYStatement
*statement
) const {
356 return $
CYForIn($
V(name_
), set_
, CYComprehension::Replace(context
, statement
));
359 CYStatement
*CYForEachIn::Replace(CYContext
&context
) {
360 CYIdentifier
*cys($
I("$cys")), *cyt($
I("$cyt"));
362 return $
CYLet($
L2($
L(cys
, set_
), $
L(cyt
)), $$
->*
363 $
CYForIn($
V(cyt
), $
V(cys
), $
CYBlock($$
->*
364 initialiser_
->ForEachIn(context
, $
M($
V(cys
), $
V(cyt
)))->*
370 CYFunctionParameter
*CYForEachInComprehension::Parameter(CYContext
&context
) const {
371 return $
CYFunctionParameter(name_
);
374 CYStatement
*CYForEachInComprehension::Replace(CYContext
&context
, CYStatement
*statement
) const {
375 CYIdentifier
*cys($
I("cys"));
377 return $
E($
C0($
F(NULL
, $
P1("$cys"), $$
->*
378 $
E($
CYAssign($
V(cys
), set_
))->*
379 $
CYForIn($
V(name_
), $
V(cys
), $
CYBlock($$
->*
380 $
E($
CYAssign($
V(name_
), $
M($
V(cys
), $
V(name_
))))->*
381 CYComprehension::Replace(context
, statement
)
386 void CYFunction::Inject(CYContext
&context
) {
387 context
.Replace(name_
);
388 context
.scope_
->Declare(context
, name_
, CYIdentifierOther
);
391 void CYFunction::Replace_(CYContext
&context
, bool outer
) {
395 CYNonLocal
*nonlocal(context
.nonlocal_
);
396 CYNonLocal
*nextlocal(context
.nextlocal_
);
399 if (nonlocal_
!= NULL
) {
401 context
.nonlocal_
= nonlocal_
;
404 nonlocal_
= $
CYNonLocal();
405 context
.nextlocal_
= nonlocal_
;
408 CYScope
scope(!localize
, context
, code_
.statements_
);
410 if (!outer
&& name_
!= NULL
)
413 if (parameters_
!= NULL
)
414 parameters_
= parameters_
->Replace(context
, code_
);
416 code_
.Replace(context
);
419 context
.NonLocal(code_
.statements_
);
421 context
.nextlocal_
= nextlocal
;
422 context
.nonlocal_
= nonlocal
;
427 CYExpression
*CYFunctionExpression::Replace(CYContext
&context
) {
428 Replace_(context
, false);
432 CYFunctionParameter
*CYFunctionParameter::Replace(CYContext
&context
, CYBlock
&code
) {
433 context
.Replace(name_
);
434 context
.scope_
->Declare(context
, name_
, CYIdentifierArgument
);
436 next_
= next_
->Replace(context
, code
);
440 CYStatement
*CYFunctionStatement::Replace(CYContext
&context
) {
441 Replace_(context
, true);
445 CYIdentifier
*CYIdentifier::Replace(CYContext
&context
) {
446 if (replace_
!= NULL
&& replace_
!= this)
447 return replace_
->Replace(context
);
448 replace_
= context
.scope_
->Lookup(context
, this);
452 CYStatement
*CYIf::Replace(CYContext
&context
) {
453 context
.Replace(test_
);
454 context
.Replace(true_
);
455 context
.Replace(false_
);
459 CYFunctionParameter
*CYIfComprehension::Parameter(CYContext
&context
) const {
463 CYStatement
*CYIfComprehension::Replace(CYContext
&context
, CYStatement
*statement
) const {
464 return $
CYIf(test_
, CYComprehension::Replace(context
, statement
));
467 CYExpression
*CYIndirect::Replace(CYContext
&context
) {
468 return $
M(rhs_
, $
S("$cyi"));
471 CYExpression
*CYIndirectMember::Replace(CYContext
&context
) {
472 return $
M($
CYIndirect(object_
), property_
);
475 CYExpression
*CYInfix::Replace(CYContext
&context
) {
476 context
.Replace(lhs_
);
477 context
.Replace(rhs_
);
481 CYStatement
*CYLabel::Replace(CYContext
&context
) {
482 context
.Replace(statement_
);
486 CYStatement
*CYLet::Replace(CYContext
&context
) {
487 return $
E($
CYCall(CYNonLocalize(context
, $
CYFunctionExpression(NULL
, declarations_
->Parameter(context
), code_
)), declarations_
->Argument(context
)));
493 CYExpression
*New::AddArgument(CYContext
&context
, CYExpression
*value
) {
494 CYSetLast(arguments_
, $
CYArgument(value
));
498 CYExpression
*New::Replace(CYContext
&context
) {
499 context
.Replace(constructor_
);
500 arguments_
->Replace(context
);
506 CYNumber
*CYNull::Number(CYContext
&context
) {
510 CYString
*CYNull::String(CYContext
&context
) {
514 CYNumber
*CYNumber::Number(CYContext
&context
) {
518 CYString
*CYNumber::String(CYContext
&context
) {
519 // XXX: there is a precise algorithm for this
520 return $
S(apr_psprintf($pool
, "%.17g", Value()));
523 CYExpression
*CYObject::Replace(CYContext
&context
) {
524 properties_
->Replace(context
);
528 CYFunctionParameter
*CYOptionalFunctionParameter::Replace(CYContext
&context
, CYBlock
&code
) {
529 CYFunctionParameter
*parameter($
CYFunctionParameter(name_
, next_
));
530 parameter
= parameter
->Replace(context
, code
);
531 context
.Replace(initializer_
);
533 CYVariable
*name($
V(name_
));
534 code
.AddPrev($
CYIf($
CYIdentical($
CYTypeOf(name
), $
S("undefined")), $$
->*
535 $
E($
CYAssign(name
, initializer_
))
541 CYExpression
*CYPostfix::Replace(CYContext
&context
) {
542 context
.Replace(lhs_
);
546 CYExpression
*CYPrefix::Replace(CYContext
&context
) {
547 context
.Replace(rhs_
);
551 // XXX: this is evil evil black magic. don't ask, don't tell... don't believe!
552 #define MappingSet "0etnirsoalfucdphmgyvbxTwSNECAFjDLkMOIBPqzRH$_WXUVGYKQJZ"
553 //#define MappingSet "0abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$_"
556 struct IdentifierUsageLess
:
557 std::binary_function
<CYIdentifier
*, CYIdentifier
*, bool>
559 _finline
bool operator ()(CYIdentifier
*lhs
, CYIdentifier
*rhs
) const {
560 if (lhs
->usage_
!= rhs
->usage_
)
561 return lhs
->usage_
> rhs
->usage_
;
566 typedef std::set
<CYIdentifier
*, IdentifierUsageLess
> IdentifierUsages
;
569 void CYProgram::Replace(CYContext
&context
) {
570 CYScope
scope(true, context
, statements_
);
572 context
.nextlocal_
= $
CYNonLocal();
573 context
.ReplaceAll(statements_
);
574 context
.NonLocal(statements_
);
580 CYCStringSet external
;
581 for (CYIdentifierValueSet::const_iterator
i(scope
.identifiers_
.begin()); i
!= scope
.identifiers_
.end(); ++i
)
582 external
.insert((*i
)->Word());
584 IdentifierUsages usages
;
586 if (offset
< context
.rename_
.size())
587 CYForEach (i
, context
.rename_
[offset
].identifier_
)
590 // XXX: totalling the probable occurrences and sorting by them would improve the result
591 for (CYIdentifierUsageVector::const_iterator
i(context
.rename_
.begin()); i
!= context
.rename_
.end(); ++i
, ++offset
) {
592 //std::cout << *i << ":" << (*i)->offset_ << std::endl;
596 if (context
.options_
.verbose_
)
597 name
= apr_psprintf($pool
, "$%"APR_SIZE_T_FMT
"", offset
);
603 unsigned position(7), local(offset
+ 1);
606 unsigned index(local
% (sizeof(MappingSet
) - 1));
607 local
/= sizeof(MappingSet
) - 1;
608 id
[--position
] = MappingSet
[index
];
609 } while (local
!= 0);
611 if (external
.find(id
+ position
) != external
.end()) {
616 name
= apr_pstrmemdup($pool
, id
+ position
, 7 - position
);
617 // XXX: at some point, this could become a keyword
620 CYForEach (identifier
, i
->identifier_
)
621 identifier
->Set(name
);
625 void CYProperty::Replace(CYContext
&context
) { $
T()
626 context
.Replace(value_
);
627 next_
->Replace(context
);
632 CYStatement
*CYReturn::Replace(CYContext
&context
) {
633 if (context
.nonlocal_
!= NULL
) {
634 CYProperty
*value(value_
== NULL
? NULL
: $
CYProperty($
S("$cyv"), value_
));
635 return $
cy::Syntax::Throw($
CYObject(
636 $
CYProperty($
S("$cyk"), $
V(context
.nonlocal_
->Target(context
)), value
)
640 context
.Replace(value_
);
644 CYExpression
*CYRubyBlock::Replace(CYContext
&context
) {
645 // XXX: this needs to do something much more epic to handle return
646 return call_
->AddArgument(context
, proc_
->Replace(context
));
649 CYExpression
*CYRubyProc::Replace(CYContext
&context
) {
650 return CYNonLocalize(context
, $
CYFunctionExpression(NULL
, parameters_
, code_
));
653 CYScope::CYScope(bool transparent
, CYContext
&context
, CYStatement
*&statements
) :
654 transparent_(transparent
),
656 statements_(statements
),
657 parent_(context
.scope_
)
659 context_
.scope_
= this;
662 CYScope::~CYScope() {
665 void CYScope::Close() {
666 context_
.scope_
= parent_
;
667 Scope(context_
, statements_
);
670 void CYScope::Declare(CYContext
&context
, CYIdentifier
*identifier
, CYIdentifierFlags flags
) {
671 if (!transparent_
|| flags
== CYIdentifierArgument
|| flags
== CYIdentifierCatch
)
672 internal_
.insert(CYIdentifierAddressFlagsMap::value_type(identifier
, flags
));
673 else if (parent_
!= NULL
)
674 parent_
->Declare(context
, identifier
, flags
);
677 CYIdentifier
*CYScope::Lookup(CYContext
&context
, CYIdentifier
*identifier
) {
678 std::pair
<CYIdentifierValueSet::iterator
, bool> insert(identifiers_
.insert(identifier
));
679 return *insert
.first
;
682 void CYScope::Merge(CYContext
&context
, CYIdentifier
*identifier
) {
683 std::pair
<CYIdentifierValueSet::iterator
, bool> insert(identifiers_
.insert(identifier
));
684 if (!insert
.second
) {
685 if ((*insert
.first
)->offset_
< identifier
->offset_
)
686 (*insert
.first
)->offset_
= identifier
->offset_
;
687 identifier
->replace_
= *insert
.first
;
688 (*insert
.first
)->usage_
+= identifier
->usage_
+ 1;
693 struct IdentifierOffset
{
695 CYIdentifierFlags flags_
;
697 CYIdentifier
*identifier_
;
699 IdentifierOffset(CYIdentifier
*identifier
, CYIdentifierFlags flags
) :
700 offset_(identifier
->offset_
),
702 usage_(identifier
->usage_
),
703 identifier_(identifier
)
708 struct IdentifierOffsetLess
:
709 std::binary_function
<const IdentifierOffset
&, const IdentifierOffset
&, bool>
711 _finline
bool operator ()(const IdentifierOffset
&lhs
, const IdentifierOffset
&rhs
) const {
712 if (lhs
.offset_
!= rhs
.offset_
)
713 return lhs
.offset_
< rhs
.offset_
;
714 if (lhs
.flags_
!= rhs
.flags_
)
715 return lhs
.flags_
< rhs
.flags_
;
716 /*if (lhs.usage_ != rhs.usage_)
717 return lhs.usage_ < rhs.usage_;*/
718 return lhs
.identifier_
< rhs
.identifier_
;
722 typedef std::set
<IdentifierOffset
, IdentifierOffsetLess
> IdentifierOffsets
;
725 void CYScope::Scope(CYContext
&context
, CYStatement
*&statements
) {
729 CYDeclarations
*last(NULL
), *curr(NULL
);
731 IdentifierOffsets offsets
;
733 for (CYIdentifierAddressFlagsMap::const_iterator
i(internal_
.begin()); i
!= internal_
.end(); ++i
)
734 if (i
->second
!= CYIdentifierMagic
)
735 offsets
.insert(IdentifierOffset(i
->first
, i
->second
));
739 for (IdentifierOffsets::const_iterator
i(offsets
.begin()); i
!= offsets
.end(); ++i
) {
740 if (i
->flags_
== CYIdentifierVariable
) {
741 CYDeclarations
*next($
CYDeclarations($
CYDeclaration(i
->identifier_
)));
749 if (offset
< i
->offset_
)
751 if (context
.rename_
.size() <= offset
)
752 context
.rename_
.resize(offset
+ 1);
754 CYIdentifierUsage
&rename(context
.rename_
[offset
++]);
755 i
->identifier_
->SetNext(rename
.identifier_
);
756 rename
.identifier_
= i
->identifier_
;
757 rename
.usage_
+= i
->identifier_
->usage_
+ 1;
761 CYVar
*var($
CYVar(last
));
762 var
->SetNext(statements
);
766 for (CYIdentifierValueSet::const_iterator
i(identifiers_
.begin()); i
!= identifiers_
.end(); ++i
)
767 if (internal_
.find(*i
) == internal_
.end()) {
768 //std::cout << *i << '=' << offset << std::endl;
769 if ((*i
)->offset_
< offset
)
770 (*i
)->offset_
= offset
;
771 parent_
->Merge(context
, *i
);
775 CYString
*CYString::Concat(CYContext
&context
, CYString
*rhs
) const {
776 size_t size(size_
+ rhs
->size_
);
777 char *value($
char[size
+ 1]);
778 memcpy(value
, value_
, size_
);
779 memcpy(value
+ size_
, rhs
->value_
, rhs
->size_
);
781 return $
S(value
, size
);
784 CYNumber
*CYString::Number(CYContext
&context
) {
785 // XXX: there is a precise algorithm for this
789 CYString
*CYString::String(CYContext
&context
) {
793 CYStatement
*CYSwitch::Replace(CYContext
&context
) {
794 context
.Replace(value_
);
795 clauses_
->Replace(context
);
799 CYExpression
*CYThis::Replace(CYContext
&context
) {
806 CYStatement
*Throw::Replace(CYContext
&context
) {
807 context
.Replace(value_
);
813 CYExpression
*CYTrivial::Replace(CYContext
&context
) {
817 CYNumber
*CYTrue::Number(CYContext
&context
) {
821 CYString
*CYTrue::String(CYContext
&context
) {
828 CYStatement
*Try::Replace(CYContext
&context
) {
829 code_
.Replace(context
);
830 catch_
->Replace(context
);
831 finally_
->Replace(context
);
837 CYStatement
*CYVar::Replace(CYContext
&context
) {
838 declarations_
->Replace(context
);
839 return $
E(declarations_
->Compound(context
));
842 CYExpression
*CYVariable::Replace(CYContext
&context
) {
843 context
.Replace(name_
);
847 CYStatement
*CYWhile::Replace(CYContext
&context
) {
848 context
.Replace(test_
);
849 context
.Replace(code_
);
853 CYStatement
*CYWith::Replace(CYContext
&context
) {
854 context
.Replace(scope_
);
855 context
.Replace(code_
);
859 CYExpression
*CYWord::ClassName(CYContext
&context
, bool object
) {
860 CYString
*name($
S(this));
862 return $
C1($
V("objc_getClass"), name
);