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 statements_
= statements_
->ReplaceAll(context
);
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 statements_
= statements_
->ReplaceAll(context
);
131 next_
->Replace(context
);
134 CYStatement
*CYComment::Replace(CYContext
&context
) {
138 CYExpression
*CYCompound::Replace(CYContext
&context
) {
139 expressions_
= expressions_
->ReplaceAll(context
);
140 return expressions_
== NULL
? NULL
: this;
143 CYFunctionParameter
*CYComprehension::Parameters(CYContext
&context
) const { $
T(NULL
)
144 CYFunctionParameter
*next(next_
->Parameters(context
));
145 if (CYFunctionParameter
*parameter
= Parameter(context
)) {
146 parameter
->SetNext(next
);
152 CYStatement
*CYComprehension::Replace(CYContext
&context
, CYStatement
*statement
) const {
153 return next_
== NULL
? statement
: next_
->Replace(context
, statement
);
156 CYExpression
*CYCondition::Replace(CYContext
&context
) {
157 context
.Replace(test_
);
158 context
.Replace(true_
);
159 context
.Replace(false_
);
163 void CYContext::NonLocal(CYStatement
*&statements
) {
164 CYContext
&context(*this);
166 if (nextlocal_
!= NULL
&& nextlocal_
->identifier_
!= NULL
) {
167 CYIdentifier
*cye($
I("$cye")->Replace(context
));
168 CYIdentifier
*unique(nextlocal_
->identifier_
->Replace(context
));
170 CYStatement
*declare(
171 $
CYVar($
L1($
L(unique
, $
CYObject()))));
173 cy::Syntax::Catch
*rescue(
174 $
cy::Syntax::Catch(cye
, $$
->*
175 $
CYIf($
CYIdentical($
M($
V(cye
), $
S("$cyk")), $
V(unique
)), $$
->*
176 $
CYReturn($
M($
V(cye
), $
S("$cyv"))))->*
177 $
cy::Syntax::Throw($
V(cye
))));
179 context
.Replace(declare
);
180 rescue
->Replace(context
);
184 $
cy::Syntax::Try(statements
, rescue
, NULL
);
188 CYIdentifier
*CYContext::Unique() {
189 return $
CYIdentifier(apr_psprintf($pool
, "$cy%u", unique_
++));
192 CYStatement
*CYContinue::Replace(CYContext
&context
) {
196 CYAssignment
*CYDeclaration::Assignment(CYContext
&context
) {
197 CYExpression
*variable(Replace(context
));
198 return initialiser_
== NULL
? NULL
: $
CYAssign(variable
, initialiser_
);
201 CYExpression
*CYDeclaration::ForEachIn(CYContext
&context
) {
202 return $
V(identifier_
);
205 CYExpression
*CYDeclaration::Replace(CYContext
&context
) {
206 context
.Replace(identifier_
);
207 context
.scope_
->Declare(context
, identifier_
, CYIdentifierVariable
);
208 return $
V(identifier_
);
211 CYProperty
*CYDeclarations::Property(CYContext
&context
) { $
T(NULL
)
212 return $
CYProperty(declaration_
->identifier_
, declaration_
->initialiser_
?: $U
, next_
->Property(context
));
215 CYCompound
*CYDeclarations::Replace(CYContext
&context
) {
216 CYCompound
*compound
;
217 if (next_
== NULL
) compound
:
218 compound
= $
CYCompound();
220 compound
= next_
->Replace(context
);
221 if (compound
== NULL
)
225 if (CYAssignment
*assignment
= declaration_
->Assignment(context
))
226 compound
->AddPrev(assignment
);
230 CYExpression
*CYDirectMember::Replace(CYContext
&context
) {
235 CYStatement
*CYDoWhile::Replace(CYContext
&context
) {
236 context
.Replace(test_
);
237 context
.Replace(code_
);
241 void CYElement::Replace(CYContext
&context
) { $
T()
242 context
.Replace(value_
);
243 next_
->Replace(context
);
246 CYStatement
*CYEmpty::Collapse(CYContext
&context
) {
250 CYStatement
*CYEmpty::Replace(CYContext
&context
) {
254 CYStatement
*CYExpress::Collapse(CYContext
&context
) {
255 if (CYExpress
*express
= dynamic_cast<CYExpress
*>(next_
)) {
256 CYCompound
*next(dynamic_cast<CYCompound
*>(express
->expression_
));
258 next
= $
CYCompound(express
->expression_
);
259 next
->AddPrev(expression_
);
261 SetNext(express
->next_
);
267 CYStatement
*CYExpress::Replace(CYContext
&context
) {
268 context
.Replace(expression_
);
269 if (expression_
== NULL
)
274 CYExpression
*CYExpression::AddArgument(CYContext
&context
, CYExpression
*value
) {
275 return $
C1(this, value
);
278 CYExpression
*CYExpression::ClassName(CYContext
&context
, bool object
) {
282 CYExpression
*CYExpression::ForEachIn(CYContext
&context
) {
286 CYExpression
*CYExpression::ReplaceAll(CYContext
&context
) { $
T(NULL
)
287 CYExpression
*replace(this);
288 context
.Replace(replace
);
290 if (CYExpression
*next
= next_
->ReplaceAll(context
))
291 replace
->SetNext(next
);
293 replace
->SetNext(next_
);
298 CYNumber
*CYFalse::Number(CYContext
&context
) {
302 CYString
*CYFalse::String(CYContext
&context
) {
306 void CYFinally::Replace(CYContext
&context
) { $
T()
307 code_
.Replace(context
);
310 CYStatement
*CYFor::Replace(CYContext
&context
) {
311 context
.Replace(initialiser_
);
312 context
.Replace(test_
);
313 context
.Replace(increment_
);
314 context
.Replace(code_
);
318 CYStatement
*CYForIn::Replace(CYContext
&context
) {
319 // XXX: this actually might need a prefix statement
320 context
.Replace(initialiser_
);
321 context
.Replace(set_
);
322 context
.Replace(code_
);
326 CYFunctionParameter
*CYForInComprehension::Parameter(CYContext
&context
) const {
327 return $
CYFunctionParameter(name_
);
330 CYStatement
*CYForInComprehension::Replace(CYContext
&context
, CYStatement
*statement
) const {
331 return $
CYForIn($
V(name_
), set_
, CYComprehension::Replace(context
, statement
));
334 CYStatement
*CYForEachIn::Replace(CYContext
&context
) {
335 CYIdentifier
*cys($
I("$cys")), *cyt($
I("$cyt"));
337 return $
CYLet($
L2($
L(cys
, set_
), $
L(cyt
)), $$
->*
338 $
CYForIn($
V(cyt
), $
V(cys
), $
CYBlock($$
->*
339 $
E($
CYAssign(initialiser_
->ForEachIn(context
), $
M($
V(cys
), $
V(cyt
))))->*
345 CYFunctionParameter
*CYForEachInComprehension::Parameter(CYContext
&context
) const {
346 return $
CYFunctionParameter(name_
);
349 CYStatement
*CYForEachInComprehension::Replace(CYContext
&context
, CYStatement
*statement
) const {
350 CYIdentifier
*cys($
I("cys"));
352 return $
E($
C0($
F(NULL
, $
P1("$cys"), $$
->*
353 $
E($
CYAssign($
V(cys
), set_
))->*
354 $
CYForIn($
V(name_
), $
V(cys
), $
CYBlock($$
->*
355 $
E($
CYAssign($
V(name_
), $
M($
V(cys
), $
V(name_
))))->*
356 CYComprehension::Replace(context
, statement
)
361 void CYFunction::Inject(CYContext
&context
) {
362 context
.Replace(name_
);
363 context
.scope_
->Declare(context
, name_
, CYIdentifierOther
);
366 void CYFunction::Replace_(CYContext
&context
, bool outer
) {
370 CYScope
scope(CYScopeFunction
, context
, code_
.statements_
);
372 CYNonLocal
*nonlocal(context
.nonlocal_
);
373 CYNonLocal
*nextlocal(context
.nextlocal_
);
376 if (nonlocal_
!= NULL
) {
378 context
.nonlocal_
= nonlocal_
;
381 nonlocal_
= $
CYNonLocal();
382 context
.nextlocal_
= nonlocal_
;
385 if (!outer
&& name_
!= NULL
)
388 if (parameters_
!= NULL
)
389 parameters_
= parameters_
->Replace(context
, code_
);
391 code_
.Replace(context
);
394 context
.NonLocal(code_
.statements_
);
396 context
.nextlocal_
= nextlocal
;
397 context
.nonlocal_
= nonlocal
;
402 CYExpression
*CYFunctionExpression::Replace(CYContext
&context
) {
403 Replace_(context
, false);
407 CYFunctionParameter
*CYFunctionParameter::Replace(CYContext
&context
, CYBlock
&code
) {
408 context
.Replace(name_
);
409 context
.scope_
->Declare(context
, name_
, CYIdentifierArgument
);
411 next_
= next_
->Replace(context
, code
);
415 CYStatement
*CYFunctionStatement::Replace(CYContext
&context
) {
416 Replace_(context
, true);
420 CYIdentifier
*CYIdentifier::Replace(CYContext
&context
) {
421 if (replace_
!= NULL
&& replace_
!= this)
422 return replace_
->Replace(context
);
423 replace_
= context
.scope_
->Lookup(context
, this);
427 CYStatement
*CYIf::Replace(CYContext
&context
) {
428 context
.Replace(test_
);
429 context
.Replace(true_
);
430 context
.Replace(false_
);
434 CYFunctionParameter
*CYIfComprehension::Parameter(CYContext
&context
) const {
438 CYStatement
*CYIfComprehension::Replace(CYContext
&context
, CYStatement
*statement
) const {
439 return $
CYIf(test_
, CYComprehension::Replace(context
, statement
));
442 CYExpression
*CYIndirect::Replace(CYContext
&context
) {
443 CYPrefix::Replace(context
);
444 return $
M(rhs_
, $
S("$cyi"));
447 CYExpression
*CYIndirectMember::Replace(CYContext
&context
) {
449 return $
M($
CYIndirect(object_
), property_
);
452 CYExpression
*CYInfix::Replace(CYContext
&context
) {
453 context
.Replace(lhs_
);
454 context
.Replace(rhs_
);
458 CYStatement
*CYLabel::Replace(CYContext
&context
) {
459 context
.Replace(statement_
);
463 CYStatement
*CYLet::Replace(CYContext
&context
) {
464 return $
CYWith($
CYObject(declarations_
->Property(context
)), &code_
);
467 void CYMember::Replace_(CYContext
&context
) {
468 context
.Replace(object_
);
469 context
.Replace(property_
);
475 CYExpression
*New::AddArgument(CYContext
&context
, CYExpression
*value
) {
476 CYArgument
**argument(&arguments_
);
477 while (*argument
!= NULL
)
478 argument
= &(*argument
)->next_
;
479 *argument
= $
CYArgument(value
);
483 CYExpression
*New::Replace(CYContext
&context
) {
484 context
.Replace(constructor_
);
485 arguments_
->Replace(context
);
491 CYNumber
*CYNull::Number(CYContext
&context
) {
495 CYString
*CYNull::String(CYContext
&context
) {
499 CYNumber
*CYNumber::Number(CYContext
&context
) {
503 CYString
*CYNumber::String(CYContext
&context
) {
504 // XXX: there is a precise algorithm for this
505 return $
S(apr_psprintf($pool
, "%.17g", Value()));
508 CYExpression
*CYObject::Replace(CYContext
&context
) {
509 properties_
->Replace(context
);
513 CYFunctionParameter
*CYOptionalFunctionParameter::Replace(CYContext
&context
, CYBlock
&code
) {
514 CYFunctionParameter
*parameter($
CYFunctionParameter(name_
, next_
));
515 parameter
= parameter
->Replace(context
, code
);
516 context
.Replace(initializer_
);
518 CYVariable
*name($
V(name_
));
519 code
.AddPrev($
CYIf($
CYIdentical($
CYTypeOf(name
), $
S("undefined")), $$
->*
520 $
E($
CYAssign(name
, initializer_
))
526 CYExpression
*CYPostfix::Replace(CYContext
&context
) {
527 context
.Replace(lhs_
);
531 CYExpression
*CYPrefix::Replace(CYContext
&context
) {
532 context
.Replace(rhs_
);
536 // XXX: this is evil evil black magic. don't ask, don't tell... don't believe!
537 #define MappingSet "0etnirsoalfucdphmgyvbxTwSNECAFjDLkMOIBPqzRH$_WXUVGYKQJZ"
538 //#define MappingSet "0abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$_"
541 struct IdentifierUsageLess
:
542 std::binary_function
<CYIdentifier
*, CYIdentifier
*, bool>
544 _finline
bool operator ()(CYIdentifier
*lhs
, CYIdentifier
*rhs
) const {
545 if (lhs
->usage_
!= rhs
->usage_
)
546 return lhs
->usage_
> rhs
->usage_
;
551 typedef std::set
<CYIdentifier
*, IdentifierUsageLess
> IdentifierUsages
;
554 void CYProgram::Replace(CYContext
&context
) {
555 CYScope
scope(CYScopeProgram
, context
, statements_
);
557 context
.nextlocal_
= $
CYNonLocal();
558 statements_
= statements_
->ReplaceAll(context
);
559 context
.NonLocal(statements_
);
565 CYCStringSet external
;
566 for (CYIdentifierValueSet::const_iterator
i(scope
.identifiers_
.begin()); i
!= scope
.identifiers_
.end(); ++i
)
567 external
.insert((*i
)->Word());
569 IdentifierUsages usages
;
571 if (offset
< context
.rename_
.size())
572 for (CYIdentifier
*i(context
.rename_
[offset
].identifier_
); i
!= NULL
; i
= i
->next_
)
575 // XXX: totalling the probable occurrences and sorting by them would improve the result
576 for (CYIdentifierUsageVector::const_iterator
i(context
.rename_
.begin()); i
!= context
.rename_
.end(); ++i
, ++offset
) {
577 //std::cout << *i << ":" << (*i)->offset_ << std::endl;
581 if (context
.options_
.verbose_
)
582 name
= apr_psprintf($pool
, "$%"APR_SIZE_T_FMT
"", offset
);
588 unsigned position(7), local(offset
+ 1);
591 unsigned index(local
% (sizeof(MappingSet
) - 1));
592 local
/= sizeof(MappingSet
) - 1;
593 id
[--position
] = MappingSet
[index
];
594 } while (local
!= 0);
596 if (external
.find(id
+ position
) != external
.end()) {
601 name
= apr_pstrmemdup($pool
, id
+ position
, 7 - position
);
602 // XXX: at some point, this could become a keyword
605 for (CYIdentifier
*identifier(i
->identifier_
); identifier
!= NULL
; identifier
= identifier
->next_
)
606 identifier
->Set(name
);
610 void CYProperty::Replace(CYContext
&context
) { $
T()
611 context
.Replace(value_
);
612 next_
->Replace(context
);
615 CYStatement
*CYReturn::Replace(CYContext
&context
) {
616 if (context
.nonlocal_
!= NULL
) {
617 CYProperty
*value(value_
== NULL
? NULL
: $
CYProperty($
S("$cyv"), value_
));
618 return $
cy::Syntax::Throw($
CYObject(
619 $
CYProperty($
S("$cyk"), $
V(context
.nonlocal_
->Target(context
)), value
)
623 context
.Replace(value_
);
627 CYExpression
*CYRubyBlock::Replace(CYContext
&context
) {
628 // XXX: this needs to do something much more epic to handle return
629 return call_
->AddArgument(context
, proc_
->Replace(context
));
632 CYExpression
*CYRubyProc::Replace(CYContext
&context
) {
633 CYFunctionExpression
*function($
CYFunctionExpression(NULL
, parameters_
, code_
));
634 function
->nonlocal_
= context
.nextlocal_
;
638 CYScope::CYScope(CYScopeType type
, CYContext
&context
, CYStatement
*&statements
) :
641 statements_(statements
),
642 parent_(context
.scope_
)
644 context_
.scope_
= this;
647 void CYScope::Close() {
648 context_
.scope_
= parent_
;
649 Scope(context_
, statements_
);
652 void CYScope::Declare(CYContext
&context
, CYIdentifier
*identifier
, CYIdentifierFlags flags
) {
653 if (type_
== CYScopeCatch
&& flags
!= CYIdentifierCatch
)
654 parent_
->Declare(context
, identifier
, flags
);
656 internal_
.insert(CYIdentifierAddressFlagsMap::value_type(identifier
, flags
));
659 CYIdentifier
*CYScope::Lookup(CYContext
&context
, CYIdentifier
*identifier
) {
660 std::pair
<CYIdentifierValueSet::iterator
, bool> insert(identifiers_
.insert(identifier
));
661 return *insert
.first
;
664 void CYScope::Merge(CYContext
&context
, CYIdentifier
*identifier
) {
665 std::pair
<CYIdentifierValueSet::iterator
, bool> insert(identifiers_
.insert(identifier
));
666 if (!insert
.second
) {
667 if ((*insert
.first
)->offset_
< identifier
->offset_
)
668 (*insert
.first
)->offset_
= identifier
->offset_
;
669 identifier
->replace_
= *insert
.first
;
670 (*insert
.first
)->usage_
+= identifier
->usage_
+ 1;
675 struct IdentifierOffset
{
677 CYIdentifierFlags flags_
;
679 CYIdentifier
*identifier_
;
681 IdentifierOffset(CYIdentifier
*identifier
, CYIdentifierFlags flags
) :
682 offset_(identifier
->offset_
),
684 usage_(identifier
->usage_
),
685 identifier_(identifier
)
690 struct IdentifierOffsetLess
:
691 std::binary_function
<const IdentifierOffset
&, const IdentifierOffset
&, bool>
693 _finline
bool operator ()(const IdentifierOffset
&lhs
, const IdentifierOffset
&rhs
) const {
694 if (lhs
.offset_
!= rhs
.offset_
)
695 return lhs
.offset_
< rhs
.offset_
;
696 if (lhs
.flags_
!= rhs
.flags_
)
697 return lhs
.flags_
< rhs
.flags_
;
698 /*if (lhs.usage_ != rhs.usage_)
699 return lhs.usage_ < rhs.usage_;*/
700 return lhs
.identifier_
< rhs
.identifier_
;
704 typedef std::set
<IdentifierOffset
, IdentifierOffsetLess
> IdentifierOffsets
;
707 void CYScope::Scope(CYContext
&context
, CYStatement
*&statements
) {
711 CYDeclarations
*last(NULL
), *curr(NULL
);
713 IdentifierOffsets offsets
;
715 for (CYIdentifierAddressFlagsMap::const_iterator
i(internal_
.begin()); i
!= internal_
.end(); ++i
)
716 if (i
->second
!= CYIdentifierMagic
)
717 offsets
.insert(IdentifierOffset(i
->first
, i
->second
));
721 for (IdentifierOffsets::const_iterator
i(offsets
.begin()); i
!= offsets
.end(); ++i
) {
722 if (i
->flags_
== CYIdentifierVariable
) {
723 CYDeclarations
*next($
CYDeclarations($
CYDeclaration(i
->identifier_
)));
731 if (offset
< i
->offset_
)
733 if (context
.rename_
.size() <= offset
)
734 context
.rename_
.resize(offset
+ 1);
736 CYIdentifierUsage
&rename(context
.rename_
[offset
++]);
737 i
->identifier_
->SetNext(rename
.identifier_
);
738 rename
.identifier_
= i
->identifier_
;
739 rename
.usage_
+= i
->identifier_
->usage_
+ 1;
743 CYVar
*var($
CYVar(last
));
744 var
->SetNext(statements
);
748 for (CYIdentifierValueSet::const_iterator
i(identifiers_
.begin()); i
!= identifiers_
.end(); ++i
)
749 if (internal_
.find(*i
) == internal_
.end()) {
750 //std::cout << *i << '=' << offset << std::endl;
751 if ((*i
)->offset_
< offset
)
752 (*i
)->offset_
= offset
;
753 parent_
->Merge(context
, *i
);
757 CYStatement
*CYStatement::Collapse(CYContext
&context
) {
761 CYStatement
*CYStatement::ReplaceAll(CYContext
&context
) { $
T(NULL
)
762 CYStatement
*replace(this);
763 context
.Replace(replace
);
764 replace
->SetNext(next_
->ReplaceAll(context
));
765 return replace
->Collapse(context
);
768 CYString
*CYString::Concat(CYContext
&context
, CYString
*rhs
) const {
769 size_t size(size_
+ rhs
->size_
);
770 char *value($
char[size
+ 1]);
771 memcpy(value
, value_
, size_
);
772 memcpy(value
+ size_
, rhs
->value_
, rhs
->size_
);
774 return $
S(value
, size
);
777 CYNumber
*CYString::Number(CYContext
&context
) {
778 // XXX: there is a precise algorithm for this
782 CYString
*CYString::String(CYContext
&context
) {
786 CYStatement
*CYSwitch::Replace(CYContext
&context
) {
787 context
.Replace(value_
);
788 clauses_
->Replace(context
);
792 CYExpression
*CYThis::Replace(CYContext
&context
) {
799 CYStatement
*Throw::Replace(CYContext
&context
) {
800 context
.Replace(value_
);
806 CYExpression
*CYTrivial::Replace(CYContext
&context
) {
810 CYNumber
*CYTrue::Number(CYContext
&context
) {
814 CYString
*CYTrue::String(CYContext
&context
) {
821 CYStatement
*Try::Replace(CYContext
&context
) {
822 code_
.Replace(context
);
823 catch_
->Replace(context
);
824 finally_
->Replace(context
);
830 CYStatement
*CYVar::Replace(CYContext
&context
) {
831 return $
E(declarations_
->Replace(context
));
834 CYExpression
*CYVariable::Replace(CYContext
&context
) {
835 context
.Replace(name_
);
839 CYStatement
*CYWhile::Replace(CYContext
&context
) {
840 context
.Replace(test_
);
841 context
.Replace(code_
);
845 CYStatement
*CYWith::Replace(CYContext
&context
) {
846 context
.Replace(scope_
);
847 context
.Replace(code_
);
851 CYExpression
*CYWord::ClassName(CYContext
&context
, bool object
) {
852 CYString
*name($
S(this));
854 return $
C1($
V("objc_getClass"), name
);