1 /* Cycript - Optimizing JavaScript Compiler/Runtime
2 * Copyright (C) 2009-2012 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($
L("$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($
CYDeclaration(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 CYStatement
*CYDebugger::Replace(CYContext
&context
) {
215 CYAssignment
*CYDeclaration::Assignment(CYContext
&context
) {
216 if (initialiser_
== NULL
)
219 CYAssignment
*value($
CYAssign(Variable(context
), initialiser_
));
224 CYVariable
*CYDeclaration::Variable(CYContext
&context
) {
225 return $
V(identifier_
);
228 CYStatement
*CYDeclaration::ForEachIn(CYContext
&context
, CYExpression
*value
) {
229 return $
CYVar($
L1($
CYDeclaration(identifier_
, value
)));
232 CYExpression
*CYDeclaration::Replace(CYContext
&context
) {
233 context
.Replace(identifier_
);
234 context
.scope_
->Declare(context
, identifier_
, CYIdentifierVariable
);
235 return Variable(context
);
238 void CYDeclarations::Replace(CYContext
&context
) { $
T()
239 declaration_
->Replace(context
);
240 next_
->Replace(context
);
243 CYProperty
*CYDeclarations::Property(CYContext
&context
) { $
T(NULL
)
244 return $
CYProperty(declaration_
->identifier_
, declaration_
->initialiser_
, next_
->Property(context
));
247 CYFunctionParameter
*CYDeclarations::Parameter(CYContext
&context
) { $
T(NULL
)
248 return $
CYFunctionParameter($
CYDeclaration(declaration_
->identifier_
), next_
->Parameter(context
));
251 CYArgument
*CYDeclarations::Argument(CYContext
&context
) { $
T(NULL
)
252 return $
CYArgument(declaration_
->initialiser_
, next_
->Argument(context
));
255 CYCompound
*CYDeclarations::Compound(CYContext
&context
) { $
T(NULL
)
256 CYCompound
*compound(next_
->Compound(context
) ?: $
CYCompound());
257 if (CYAssignment
*assignment
= declaration_
->Assignment(context
))
258 compound
->AddPrev(assignment
);
262 CYExpression
*CYDirectMember::Replace(CYContext
&context
) {
263 context
.Replace(object_
);
264 context
.Replace(property_
);
268 CYStatement
*CYDoWhile::Replace(CYContext
&context
) {
269 context
.Replace(test_
);
270 context
.Replace(code_
);
274 void CYElement::Replace(CYContext
&context
) { $
T()
275 context
.Replace(value_
);
276 next_
->Replace(context
);
279 CYStatement
*CYEmpty::Replace(CYContext
&context
) {
283 CYStatement
*CYExpress::Replace(CYContext
&context
) {
284 while (CYExpress
*express
= dynamic_cast<CYExpress
*>(next_
)) {
285 CYCompound
*compound(dynamic_cast<CYCompound
*>(express
->expression_
));
286 if (compound
== NULL
)
287 compound
= $
CYCompound(express
->expression_
);
288 compound
->AddPrev(expression_
);
289 expression_
= compound
;
290 SetNext(express
->next_
);
293 context
.Replace(expression_
);
294 if (expression_
== NULL
)
300 CYExpression
*CYExpression::AddArgument(CYContext
&context
, CYExpression
*value
) {
301 return $
C1(this, value
);
304 CYExpression
*CYExpression::ClassName(CYContext
&context
, bool object
) {
308 CYStatement
*CYExpression::ForEachIn(CYContext
&context
, CYExpression
*value
) {
309 return $
E($
CYAssign(this, value
));
312 CYAssignment
*CYExpression::Assignment(CYContext
&context
) {
316 CYNumber
*CYFalse::Number(CYContext
&context
) {
320 CYString
*CYFalse::String(CYContext
&context
) {
324 void CYFinally::Replace(CYContext
&context
) { $
T()
325 code_
.Replace(context
);
328 CYStatement
*CYFor::Replace(CYContext
&context
) {
329 context
.Replace(initialiser_
);
330 context
.Replace(test_
);
331 context
.Replace(increment_
);
332 context
.Replace(code_
);
336 CYCompound
*CYForDeclarations::Replace(CYContext
&context
) {
337 declarations_
->Replace(context
);
338 return declarations_
->Compound(context
);
341 // XXX: this still feels highly suboptimal
342 CYStatement
*CYForIn::Replace(CYContext
&context
) {
343 if (CYAssignment
*assignment
= initialiser_
->Assignment(context
))
344 return $
CYBlock($$
->*
349 context
.Replace(initialiser_
);
350 context
.Replace(set_
);
351 context
.Replace(code_
);
355 CYFunctionParameter
*CYForInComprehension::Parameter(CYContext
&context
) const {
356 return $
CYFunctionParameter($
CYDeclaration(name_
));
359 CYStatement
*CYForInComprehension::Replace(CYContext
&context
, CYStatement
*statement
) const {
360 return $
CYForIn($
V(name_
), set_
, CYComprehension::Replace(context
, statement
));
363 CYStatement
*CYForOf::Replace(CYContext
&context
) {
364 if (CYAssignment
*assignment
= initialiser_
->Assignment(context
))
365 return $
CYBlock($$
->*
370 CYIdentifier
*cys($
I("$cys")), *cyt($
I("$cyt"));
372 return $
CYLetStatement($
L2($
CYDeclaration(cys
, set_
), $
CYDeclaration(cyt
)), $$
->*
373 $
CYForIn($
V(cyt
), $
V(cys
), $
CYBlock($$
->*
374 initialiser_
->ForEachIn(context
, $
M($
V(cys
), $
V(cyt
)))->*
380 CYFunctionParameter
*CYForOfComprehension::Parameter(CYContext
&context
) const {
381 return $
CYFunctionParameter($
CYDeclaration(name_
));
384 CYStatement
*CYForOfComprehension::Replace(CYContext
&context
, CYStatement
*statement
) const {
385 CYIdentifier
*cys($
I("cys"));
387 return $
E($
C0($
F(NULL
, $
P1($
L("$cys")), $$
->*
388 $
E($
CYAssign($
V(cys
), set_
))->*
389 $
CYForIn($
V(name_
), $
V(cys
), $
CYBlock($$
->*
390 $
E($
CYAssign($
V(name_
), $
M($
V(cys
), $
V(name_
))))->*
391 CYComprehension::Replace(context
, statement
)
396 void CYFunction::Inject(CYContext
&context
) {
397 context
.Replace(name_
);
398 context
.scope_
->Declare(context
, name_
, CYIdentifierOther
);
401 void CYFunction::Replace_(CYContext
&context
, bool outer
) {
405 CYNonLocal
*nonlocal(context
.nonlocal_
);
406 CYNonLocal
*nextlocal(context
.nextlocal_
);
409 if (nonlocal_
!= NULL
) {
411 context
.nonlocal_
= nonlocal_
;
414 nonlocal_
= $
CYNonLocal();
415 context
.nextlocal_
= nonlocal_
;
418 CYScope
scope(!localize
, context
, code_
.statements_
);
420 if (!outer
&& name_
!= NULL
)
423 parameters_
->Replace(context
, code_
);
424 code_
.Replace(context
);
427 context
.NonLocal(code_
.statements_
);
429 context
.nextlocal_
= nextlocal
;
430 context
.nonlocal_
= nonlocal
;
435 CYExpression
*CYFunctionExpression::Replace(CYContext
&context
) {
436 Replace_(context
, false);
440 void CYFunctionParameter::Replace(CYContext
&context
, CYBlock
&code
) { $
T()
441 CYAssignment
*assignment(initialiser_
->Assignment(context
));
442 context
.Replace(initialiser_
);
444 next_
->Replace(context
, code
);
446 if (assignment
!= NULL
)
447 // XXX: this cast is quite incorrect
448 code
.AddPrev($
CYIf($
CYIdentical($
CYTypeOf(dynamic_cast<CYExpression
*>(initialiser_
)), $
S("undefined")), $$
->*
453 CYStatement
*CYFunctionStatement::Replace(CYContext
&context
) {
454 Replace_(context
, true);
458 CYIdentifier
*CYIdentifier::Replace(CYContext
&context
) {
459 if (replace_
!= NULL
&& replace_
!= this)
460 return replace_
->Replace(context
);
461 replace_
= context
.scope_
->Lookup(context
, this);
465 CYStatement
*CYIf::Replace(CYContext
&context
) {
466 context
.Replace(test_
);
467 context
.Replace(true_
);
468 context
.Replace(false_
);
472 CYFunctionParameter
*CYIfComprehension::Parameter(CYContext
&context
) const {
476 CYStatement
*CYIfComprehension::Replace(CYContext
&context
, CYStatement
*statement
) const {
477 return $
CYIf(test_
, CYComprehension::Replace(context
, statement
));
480 CYExpression
*CYIndirect::Replace(CYContext
&context
) {
481 return $
M(rhs_
, $
S("$cyi"));
484 CYExpression
*CYIndirectMember::Replace(CYContext
&context
) {
485 return $
M($
CYIndirect(object_
), property_
);
488 CYExpression
*CYInfix::Replace(CYContext
&context
) {
489 context
.Replace(lhs_
);
490 context
.Replace(rhs_
);
494 CYStatement
*CYLabel::Replace(CYContext
&context
) {
495 context
.Replace(statement_
);
499 CYStatement
*CYLetStatement::Replace(CYContext
&context
) {
500 return $
E($
CYCall(CYNonLocalize(context
, $
CYFunctionExpression(NULL
, declarations_
->Parameter(context
), code_
)), declarations_
->Argument(context
)));
506 CYExpression
*New::AddArgument(CYContext
&context
, CYExpression
*value
) {
507 CYSetLast(arguments_
, $
CYArgument(value
));
511 CYExpression
*New::Replace(CYContext
&context
) {
512 context
.Replace(constructor_
);
513 arguments_
->Replace(context
);
519 CYNumber
*CYNull::Number(CYContext
&context
) {
523 CYString
*CYNull::String(CYContext
&context
) {
527 CYNumber
*CYNumber::Number(CYContext
&context
) {
531 CYString
*CYNumber::String(CYContext
&context
) {
532 // XXX: there is a precise algorithm for this
533 return $
S(apr_psprintf($pool
, "%.17g", Value()));
536 CYExpression
*CYObject::Replace(CYContext
&context
) {
537 properties_
->Replace(context
);
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
);