1 /* Cycript - Inlining/Optimizing JavaScript Compiler
2 * Copyright (C) 2009 Jay Freeman (saurik)
5 /* Modified BSD License {{{ */
7 * Redistribution and use in source and binary
8 * forms, with or without modification, are permitted
9 * provided that the following conditions are met:
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
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.
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.
41 #include "Replace.hpp"
45 CYExpression
*CYAdd::Replace(CYContext
&context
) {
46 CYInfix::Replace(context
);
48 CYExpression
*lhp(lhs_
->Primitive(context
));
49 CYExpression
*rhp(rhs_
->Primitive(context
));
51 CYString
*lhs(dynamic_cast<CYString
*>(lhp
));
52 CYString
*rhs(dynamic_cast<CYString
*>(rhp
));
54 if (lhs
!= NULL
|| rhs
!= NULL
) {
56 lhs
= lhp
->String(context
);
59 } else if (rhs
== NULL
) {
60 rhs
= rhp
->String(context
);
65 return lhs
->Concat(context
, rhs
);
68 if (CYNumber
*lhn
= lhp
->Number(context
))
69 if (CYNumber
*rhn
= rhp
->Number(context
))
70 return $
D(lhn
->Value() + rhn
->Value());
75 CYExpression
*CYAddressOf::Replace(CYContext
&context
) {
76 CYPrefix::Replace(context
);
77 return $
C0($
M(rhs_
, $
S("$cya")));
80 void CYArgument::Replace(CYContext
&context
) { $
T()
81 context
.Replace(value_
);
82 next_
->Replace(context
);
85 CYExpression
*CYArray::Replace(CYContext
&context
) {
86 elements_
->Replace(context
);
90 CYExpression
*CYArrayComprehension::Replace(CYContext
&context
) {
91 CYVariable
*cyv($
V("$cyv"));
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_
)))->*
100 CYExpression
*CYAssignment::Replace(CYContext
&context
) {
101 context
.Replace(lhs_
);
102 context
.Replace(rhs_
);
106 CYStatement
*CYBlock::Replace(CYContext
&context
) {
107 statements_
= statements_
->ReplaceAll(context
);
108 if (statements_
== NULL
)
113 CYStatement
*CYBreak::Replace(CYContext
&context
) {
117 CYExpression
*CYCall::AddArgument(CYContext
&context
, CYExpression
*value
) {
118 CYArgument
**argument(&arguments_
);
119 while (*argument
!= NULL
)
120 argument
= &(*argument
)->next_
;
121 *argument
= $
CYArgument(value
);
125 CYExpression
*CYCall::Replace(CYContext
&context
) {
126 context
.Replace(function_
);
127 arguments_
->Replace(context
);
134 void Catch::Replace(CYContext
&context
) { $
T()
135 code_
.Replace(context
);
140 void CYClause::Replace(CYContext
&context
) { $
T()
141 context
.Replace(case_
);
142 statements_
= statements_
->ReplaceAll(context
);
143 next_
->Replace(context
);
146 CYStatement
*CYComment::Replace(CYContext
&context
) {
150 CYExpression
*CYCompound::Replace(CYContext
&context
) {
151 expressions_
= expressions_
->ReplaceAll(context
);
152 return expressions_
== NULL
? NULL
: this;
155 CYFunctionParameter
*CYComprehension::Parameters(CYContext
&context
) const { $
T(NULL
)
156 CYFunctionParameter
*next(next_
->Parameters(context
));
157 if (CYFunctionParameter
*parameter
= Parameter(context
)) {
158 parameter
->SetNext(next
);
164 CYStatement
*CYComprehension::Replace(CYContext
&context
, CYStatement
*statement
) const {
165 return next_
== NULL
? statement
: next_
->Replace(context
, statement
);
168 CYExpression
*CYCondition::Replace(CYContext
&context
) {
169 context
.Replace(test_
);
170 context
.Replace(true_
);
171 context
.Replace(false_
);
175 void CYContext::NonLocal(CYStatement
*&statements
) {
176 CYContext
&context(*this);
178 if (nonlocal_
->identifier_
!= NULL
) {
179 CYVariable
*cye($
V("$cye"));
180 CYVariable
*unique($
CYVariable(nonlocal_
->identifier_
));
183 $
E($
CYAssign(unique
, $
CYObject()))->*
184 $
cy::Syntax::Try(statements
, $
cy::Syntax::Catch(cye
->name_
, $$
->*
185 $
CYIf($
CYIdentical($
M(cye
, $
S("$cyk")), unique
), $$
->*
186 $
CYReturn($
M(cye
, $
S("$cyv"))))->*
187 $
cy::Syntax::Throw(cye
)
192 CYIdentifier
*CYContext::Unique() {
193 CYContext
&context(*this);
194 return $
CYIdentifier(apr_psprintf(pool_
, "$cy%u", unique_
++));
197 CYStatement
*CYContinue::Replace(CYContext
&context
) {
201 CYAssignment
*CYDeclaration::Assignment(CYContext
&context
) {
202 CYExpression
*variable(Replace(context
));
203 return initialiser_
== NULL
? NULL
: $
CYAssign(variable
, initialiser_
);
206 CYExpression
*CYDeclaration::ForEachIn(CYContext
&context
) {
207 return $
CYVariable(identifier_
);
210 CYExpression
*CYDeclaration::Replace(CYContext
&context
) {
211 context
.Replace(identifier_
);
212 context
.scope_
->Declare(context
, identifier_
, CYIdentifierVariable
);
213 return $
CYVariable(identifier_
);
216 CYProperty
*CYDeclarations::Property(CYContext
&context
) { $
T(NULL
)
217 return $
CYProperty(declaration_
->identifier_
, declaration_
->initialiser_
?: $U
, next_
->Property(context
));
220 CYCompound
*CYDeclarations::Replace(CYContext
&context
) {
221 CYCompound
*compound
;
222 if (next_
== NULL
) compound
:
223 compound
= $
CYCompound();
225 compound
= next_
->Replace(context
);
226 if (compound
== NULL
)
230 if (CYAssignment
*assignment
= declaration_
->Assignment(context
))
231 compound
->AddPrev(assignment
);
235 CYExpression
*CYDirectMember::Replace(CYContext
&context
) {
240 CYStatement
*CYDoWhile::Replace(CYContext
&context
) {
241 context
.Replace(test_
);
242 context
.Replace(code_
);
246 void CYElement::Replace(CYContext
&context
) { $
T()
247 context
.Replace(value_
);
248 next_
->Replace(context
);
251 CYStatement
*CYEmpty::Collapse(CYContext
&context
) {
255 CYStatement
*CYEmpty::Replace(CYContext
&context
) {
259 CYStatement
*CYExpress::Collapse(CYContext
&context
) {
260 if (CYExpress
*express
= dynamic_cast<CYExpress
*>(next_
)) {
261 CYCompound
*next(dynamic_cast<CYCompound
*>(express
->expression_
));
263 next
= $
CYCompound(express
->expression_
);
264 next
->AddPrev(expression_
);
266 SetNext(express
->next_
);
272 CYStatement
*CYExpress::Replace(CYContext
&context
) {
273 context
.Replace(expression_
);
274 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 CYExpression
*CYExpression::ForEachIn(CYContext
&context
) {
291 CYExpression
*CYExpression::ReplaceAll(CYContext
&context
) { $
T(NULL
)
292 CYExpression
*replace(this);
293 context
.Replace(replace
);
295 if (CYExpression
*next
= next_
->ReplaceAll(context
))
296 replace
->SetNext(next
);
298 replace
->SetNext(next_
);
303 CYNumber
*CYFalse::Number(CYContext
&context
) {
307 CYString
*CYFalse::String(CYContext
&context
) {
311 void CYFinally::Replace(CYContext
&context
) { $
T()
312 code_
.Replace(context
);
315 CYStatement
*CYFor::Replace(CYContext
&context
) {
316 context
.Replace(initialiser_
);
317 context
.Replace(test_
);
318 context
.Replace(increment_
);
319 context
.Replace(code_
);
323 CYStatement
*CYForIn::Replace(CYContext
&context
) {
324 // XXX: this actually might need a prefix statement
325 context
.Replace(initialiser_
);
326 context
.Replace(set_
);
327 context
.Replace(code_
);
331 CYFunctionParameter
*CYForInComprehension::Parameter(CYContext
&context
) const {
332 return $
CYFunctionParameter(name_
);
335 CYStatement
*CYForInComprehension::Replace(CYContext
&context
, CYStatement
*statement
) const {
336 return $
CYForIn($
CYVariable(name_
), set_
, CYComprehension::Replace(context
, statement
));
339 CYStatement
*CYForEachIn::Replace(CYContext
&context
) {
340 CYVariable
*cys($
V("$cys")), *cyt($
V("$cyt"));
342 return $
CYLet($
L2($
L($
I("$cys"), set_
), $
L($
I("$cyt"))), $$
->*
343 $
CYForIn(cyt
, cys
, $
CYBlock($$
->*
344 $
E($
CYAssign(initialiser_
->ForEachIn(context
), $
M(cys
, cyt
)))->*
350 CYFunctionParameter
*CYForEachInComprehension::Parameter(CYContext
&context
) const {
351 return $
CYFunctionParameter(name_
);
354 CYStatement
*CYForEachInComprehension::Replace(CYContext
&context
, CYStatement
*statement
) const {
355 CYVariable
*cys($
V("$cys")), *name($
CYVariable(name_
));
357 return $
E($
C0($
F(NULL
, $
P1("$cys"), $$
->*
358 $
E($
CYAssign(cys
, set_
))->*
359 $
CYForIn(name
, cys
, $
CYBlock($$
->*
360 $
E($
CYAssign(name
, $
M(cys
, name
)))->*
361 CYComprehension::Replace(context
, statement
)
366 void CYFunction::Inject(CYContext
&context
) {
367 context
.Replace(name_
);
368 context
.scope_
->Declare(context
, name_
, CYIdentifierOther
);
371 void CYFunction::Replace_(CYContext
&context
, bool outer
) {
376 scope
.parent_
= context
.scope_
;
377 context
.scope_
= &scope
;
380 if (nonlocal_
!= NULL
)
384 nonlocal_
= $
CYNonLocal();
387 CYNonLocal
*nonlocal(context
.nonlocal_
);
388 context
.nonlocal_
= nonlocal_
;
390 if (!outer
&& name_
!= NULL
)
393 if (parameters_
!= NULL
)
394 parameters_
= parameters_
->Replace(context
, code_
);
395 code_
.Replace(context
);
398 context
.NonLocal(code_
.statements_
);
399 context
.nonlocal_
= nonlocal
;
401 context
.scope_
= scope
.parent_
;
402 scope
.Scope(context
, code_
.statements_
);
405 CYExpression
*CYFunctionExpression::Replace(CYContext
&context
) {
406 Replace_(context
, false);
410 CYFunctionParameter
*CYFunctionParameter::Replace(CYContext
&context
, CYBlock
&code
) {
411 name_
= name_
->Replace(context
);
412 context
.scope_
->Declare(context
, name_
, CYIdentifierArgument
);
414 next_
= next_
->Replace(context
, code
);
418 CYStatement
*CYFunctionStatement::Replace(CYContext
&context
) {
419 Replace_(context
, true);
423 CYIdentifier
*CYIdentifier::Replace(CYContext
&context
) {
424 if (replace_
!= NULL
&& replace_
!= this)
425 return replace_
->Replace(context
);
426 replace_
= context
.scope_
->Lookup(context
, this);
430 CYStatement
*CYIf::Replace(CYContext
&context
) {
431 context
.Replace(test_
);
432 context
.Replace(true_
);
433 context
.Replace(false_
);
437 CYFunctionParameter
*CYIfComprehension::Parameter(CYContext
&context
) const {
441 CYStatement
*CYIfComprehension::Replace(CYContext
&context
, CYStatement
*statement
) const {
442 return $
CYIf(test_
, CYComprehension::Replace(context
, statement
));
445 CYExpression
*CYIndirect::Replace(CYContext
&context
) {
446 CYPrefix::Replace(context
);
447 return $
M(rhs_
, $
S("$cyi"));
450 CYExpression
*CYIndirectMember::Replace(CYContext
&context
) {
452 return $
M($
CYIndirect(object_
), property_
);
455 CYExpression
*CYInfix::Replace(CYContext
&context
) {
456 context
.Replace(lhs_
);
457 context
.Replace(rhs_
);
461 CYStatement
*CYLabel::Replace(CYContext
&context
) {
462 context
.Replace(statement_
);
466 CYStatement
*CYLet::Replace(CYContext
&context
) {
467 return $
CYWith($
CYObject(declarations_
->Property(context
)), &code_
);
470 void CYMember::Replace_(CYContext
&context
) {
471 context
.Replace(object_
);
472 context
.Replace(property_
);
475 CYExpression
*CYNew::AddArgument(CYContext
&context
, CYExpression
*value
) {
476 CYArgument
**argument(&arguments_
);
477 while (*argument
!= NULL
)
478 argument
= &(*argument
)->next_
;
479 *argument
= $
CYArgument(value
);
483 CYExpression
*CYNew::Replace(CYContext
&context
) {
484 context
.Replace(constructor_
);
485 arguments_
->Replace(context
);
489 CYNumber
*CYNull::Number(CYContext
&context
) {
493 CYString
*CYNull::String(CYContext
&context
) {
497 CYNumber
*CYNumber::Number(CYContext
&context
) {
501 CYString
*CYNumber::String(CYContext
&context
) {
502 // XXX: there is a precise algorithm for this
503 return $
S(apr_psprintf(context
.pool_
, "%.17g", Value()));
506 CYExpression
*CYObject::Replace(CYContext
&context
) {
507 properties_
->Replace(context
);
511 CYFunctionParameter
*CYOptionalFunctionParameter::Replace(CYContext
&context
, CYBlock
&code
) {
512 CYFunctionParameter
*parameter($
CYFunctionParameter(name_
, next_
));
513 parameter
= parameter
->Replace(context
, code
);
514 initializer_
= initializer_
->Replace(context
);
516 CYVariable
*name($
CYVariable(name_
));
517 code
.AddPrev($
CYIf($
CYIdentical($
CYTypeOf(name
), $
S("undefined")), $$
->*
518 $
E($
CYAssign(name
, initializer_
))
524 CYExpression
*CYPostfix::Replace(CYContext
&context
) {
525 context
.Replace(lhs_
);
529 CYExpression
*CYPrefix::Replace(CYContext
&context
) {
530 context
.Replace(rhs_
);
534 // XXX: this is evil evil black magic. don't ask, don't tell... don't believe!
535 #define MappingSet "0etnirsoalfucdphmgyvbxTwSNECAFjDLkMOIBPqzRH$_WXUVGYKQJZ"
536 //#define MappingSet "0abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$_"
539 struct IdentifierUsageLess
:
540 std::binary_function
<CYIdentifier
*, CYIdentifier
*, bool>
542 _finline
bool operator ()(CYIdentifier
*lhs
, CYIdentifier
*rhs
) const {
543 if (lhs
->usage_
!= rhs
->usage_
)
544 return lhs
->usage_
> rhs
->usage_
;
549 typedef std::set
<CYIdentifier
*, IdentifierUsageLess
> IdentifierUsages
;
552 void CYProgram::Replace(CYContext
&context
) {
554 scope
.parent_
= context
.scope_
;
555 context
.scope_
= &scope
;
557 context
.nonlocal_
= $
CYNonLocal();
558 statements_
= statements_
->ReplaceAll(context
);
559 context
.NonLocal(statements_
);
561 context
.scope_
= scope
.parent_
;
562 scope
.Scope(context
, statements_
);
566 CYCStringSet external
;
567 for (CYIdentifierValueSet::const_iterator
i(scope
.identifiers_
.begin()); i
!= scope
.identifiers_
.end(); ++i
)
568 external
.insert((*i
)->Word());
570 IdentifierUsages usages
;
572 if (offset
< context
.rename_
.size())
573 for (CYIdentifier
*i(context
.rename_
[offset
].identifier_
); i
!= NULL
; i
= i
->next_
)
576 // XXX: totalling the probable occurrences and sorting by them would improve the result
577 for (CYIdentifierUsageVector::const_iterator
i(context
.rename_
.begin()); i
!= context
.rename_
.end(); ++i
, ++offset
) {
578 //std::cout << *i << ":" << (*i)->offset_ << std::endl;
582 if (context
.options_
.verbose_
)
583 name
= apr_psprintf(context
.pool_
, "$%"APR_SIZE_T_FMT
"", offset
);
589 unsigned position(7), local(offset
+ 1);
592 unsigned index(local
% (sizeof(MappingSet
) - 1));
593 local
/= sizeof(MappingSet
) - 1;
594 id
[--position
] = MappingSet
[index
];
595 } while (local
!= 0);
597 if (external
.find(id
+ position
) != external
.end()) {
602 name
= apr_pstrmemdup(context
.pool_
, id
+ position
, 7 - position
);
603 // XXX: at some point, this could become a keyword
606 for (CYIdentifier
*identifier(i
->identifier_
); identifier
!= NULL
; identifier
= identifier
->next_
)
607 identifier
->Set(name
);
611 void CYProperty::Replace(CYContext
&context
) { $
T()
612 context
.Replace(value_
);
613 next_
->Replace(context
);
616 CYStatement
*CYReturn::Replace(CYContext
&context
) {
617 if (context
.nonlocal_
!= NULL
) {
618 CYProperty
*value(value_
== NULL
? NULL
: $
CYProperty($
S("$cyv"), value_
));
619 return $
cy::Syntax::Throw($
CYObject(
620 $
CYProperty($
S("$cyk"), $
CYVariable(context
.nonlocal_
->Target(context
)), value
)
624 context
.Replace(value_
);
628 CYExpression
*CYRubyBlock::Replace(CYContext
&context
) {
629 // XXX: this needs to do something much more epic to handle return
630 return call_
->AddArgument(context
, proc_
->Replace(context
));
633 CYExpression
*CYRubyProc::Replace(CYContext
&context
) {
634 CYFunctionExpression
*function($
CYFunctionExpression(NULL
, parameters_
, code_
));
635 function
->nonlocal_
= context
.nonlocal_
;
639 void CYScope::Declare(CYContext
&context
, CYIdentifier
*identifier
, CYIdentifierFlags flags
) {
640 internal_
.insert(CYIdentifierAddressFlagsMap::value_type(identifier
, flags
));
643 CYIdentifier
*CYScope::Lookup(CYContext
&context
, CYIdentifier
*identifier
) {
644 std::pair
<CYIdentifierValueSet::iterator
, bool> insert(identifiers_
.insert(identifier
));
645 return *insert
.first
;
648 void CYScope::Merge(CYContext
&context
, CYIdentifier
*identifier
) {
649 std::pair
<CYIdentifierValueSet::iterator
, bool> insert(identifiers_
.insert(identifier
));
650 if (!insert
.second
) {
651 if ((*insert
.first
)->offset_
< identifier
->offset_
)
652 (*insert
.first
)->offset_
= identifier
->offset_
;
653 identifier
->replace_
= *insert
.first
;
654 (*insert
.first
)->usage_
+= identifier
->usage_
+ 1;
659 struct IdentifierOffset
{
661 CYIdentifierFlags flags_
;
663 CYIdentifier
*identifier_
;
665 IdentifierOffset(CYIdentifier
*identifier
, CYIdentifierFlags flags
) :
666 offset_(identifier
->offset_
),
668 usage_(identifier
->usage_
),
669 identifier_(identifier
)
674 struct IdentifierOffsetLess
:
675 std::binary_function
<const IdentifierOffset
&, const IdentifierOffset
&, bool>
677 _finline
bool operator ()(const IdentifierOffset
&lhs
, const IdentifierOffset
&rhs
) const {
678 if (lhs
.offset_
!= rhs
.offset_
)
679 return lhs
.offset_
< rhs
.offset_
;
680 if (lhs
.flags_
!= rhs
.flags_
)
681 return lhs
.flags_
< rhs
.flags_
;
682 /*if (lhs.usage_ != rhs.usage_)
683 return lhs.usage_ < rhs.usage_;*/
684 return lhs
.identifier_
< rhs
.identifier_
;
688 typedef std::set
<IdentifierOffset
, IdentifierOffsetLess
> IdentifierOffsets
;
691 void CYScope::Scope(CYContext
&context
, CYStatement
*&statements
) {
695 CYDeclarations
*last(NULL
), *curr(NULL
);
697 IdentifierOffsets offsets
;
699 for (CYIdentifierAddressFlagsMap::const_iterator
i(internal_
.begin()); i
!= internal_
.end(); ++i
)
700 if (i
->second
!= CYIdentifierMagic
)
701 offsets
.insert(IdentifierOffset(i
->first
, i
->second
));
705 for (IdentifierOffsets::const_iterator
i(offsets
.begin()); i
!= offsets
.end(); ++i
) {
706 if (i
->flags_
== CYIdentifierVariable
) {
707 CYDeclarations
*next($
CYDeclarations($
CYDeclaration(i
->identifier_
)));
715 if (offset
< i
->offset_
)
717 if (context
.rename_
.size() <= offset
)
718 context
.rename_
.resize(offset
+ 1);
720 CYIdentifierUsage
&rename(context
.rename_
[offset
++]);
721 i
->identifier_
->SetNext(rename
.identifier_
);
722 rename
.identifier_
= i
->identifier_
;
723 rename
.usage_
+= i
->identifier_
->usage_
+ 1;
727 CYVar
*var($
CYVar(last
));
728 var
->SetNext(statements
);
732 for (CYIdentifierValueSet::const_iterator
i(identifiers_
.begin()); i
!= identifiers_
.end(); ++i
)
733 if (internal_
.find(*i
) == internal_
.end()) {
734 //std::cout << *i << '=' << offset << std::endl;
735 if ((*i
)->offset_
< offset
)
736 (*i
)->offset_
= offset
;
737 parent_
->Merge(context
, *i
);
741 CYStatement
*CYStatement::Collapse(CYContext
&context
) {
745 CYStatement
*CYStatement::ReplaceAll(CYContext
&context
) { $
T(NULL
)
746 CYStatement
*replace(this);
747 context
.Replace(replace
);
748 replace
->SetNext(next_
->ReplaceAll(context
));
749 return replace
->Collapse(context
);
752 CYString
*CYString::Concat(CYContext
&context
, CYString
*rhs
) const {
753 size_t size(size_
+ rhs
->size_
);
754 char *value(new(context
.pool_
) char[size
+ 1]);
755 memcpy(value
, value_
, size_
);
756 memcpy(value
+ size_
, rhs
->value_
, rhs
->size_
);
758 return $
S(value
, size
);
761 CYNumber
*CYString::Number(CYContext
&context
) {
762 // XXX: there is a precise algorithm for this
766 CYString
*CYString::String(CYContext
&context
) {
770 CYStatement
*CYSwitch::Replace(CYContext
&context
) {
771 context
.Replace(value_
);
772 clauses_
->Replace(context
);
776 CYExpression
*CYThis::Replace(CYContext
&context
) {
783 CYStatement
*Throw::Replace(CYContext
&context
) {
784 context
.Replace(value_
);
790 CYExpression
*CYTrivial::Replace(CYContext
&context
) {
794 CYNumber
*CYTrue::Number(CYContext
&context
) {
798 CYString
*CYTrue::String(CYContext
&context
) {
805 CYStatement
*Try::Replace(CYContext
&context
) {
806 code_
.Replace(context
);
807 catch_
->Replace(context
);
808 finally_
->Replace(context
);
814 CYStatement
*CYVar::Replace(CYContext
&context
) {
815 return $
E(declarations_
->Replace(context
));
818 CYExpression
*CYVariable::Replace(CYContext
&context
) {
819 name_
= name_
->Replace(context
);
823 CYStatement
*CYWhile::Replace(CYContext
&context
) {
824 context
.Replace(test_
);
825 context
.Replace(code_
);
829 CYStatement
*CYWith::Replace(CYContext
&context
) {
830 context
.Replace(scope_
);
831 context
.Replace(code_
);
835 CYExpression
*CYWord::ClassName(CYContext
&context
, bool object
) {
836 CYString
*name($
S(this));
838 return $
C1($
V("objc_getClass"), name
);