]> git.saurik.com Git - cycript.git/blame_incremental - Replace.cpp
Instance's toPointer() should return as CFTypeRef.
[cycript.git] / Replace.cpp
... / ...
CommitLineData
1/* Cycript - The Truly Universal Scripting Language
2 * Copyright (C) 2009-2016 Jay Freeman (saurik)
3*/
4
5/* GNU Affero General Public License, Version 3 {{{ */
6/*
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
16
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19**/
20/* }}} */
21
22#include <iomanip>
23#include <map>
24
25#include "Replace.hpp"
26#include "Syntax.hpp"
27
28CYFunctionExpression *CYNonLocalize(CYContext &context, CYFunctionExpression *function) {
29 function->nonlocal_ = context.nextlocal_;
30 return function;
31}
32
33CYFunctionExpression *CYSuperize(CYContext &context, CYFunctionExpression *function) {
34 function->super_ = context.super_;
35 return function;
36}
37
38CYStatement *CYDefineProperty(CYExpression *object, CYExpression *name, bool configurable, bool enumerable, CYProperty *descriptor) {
39 return $E($C3($M($V("Object"), $S("defineProperty")), object, name, $ CYObject(CYList<CYProperty>()
40 ->* (configurable ? $ CYPropertyValue($S("configurable"), $ CYTrue()) : NULL)
41 ->* (enumerable ? $ CYPropertyValue($S("enumerable"), $ CYTrue()) : NULL)
42 ->* descriptor)));
43}
44
45static void CYImplicitReturn(CYStatement *&code) {
46 if (CYStatement *&last = CYGetLast(code))
47 last = last->Return();
48}
49
50CYExpression *CYAdd::Replace(CYContext &context) {
51 CYInfix::Replace(context);
52
53 CYString *lhs(dynamic_cast<CYString *>(lhs_));
54 CYString *rhs(dynamic_cast<CYString *>(rhs_));
55
56 if (lhs != NULL || rhs != NULL) {
57 if (lhs == NULL) {
58 lhs = lhs_->String(context);
59 if (lhs == NULL)
60 return this;
61 } else if (rhs == NULL) {
62 rhs = rhs_->String(context);
63 if (rhs == NULL)
64 return this;
65 }
66
67 return lhs->Concat(context, rhs);
68 }
69
70 if (CYNumber *lhn = lhs_->Number(context))
71 if (CYNumber *rhn = rhs_->Number(context))
72 return $D(lhn->Value() + rhn->Value());
73
74 return this;
75}
76
77CYExpression *CYAddressOf::Replace(CYContext &context) {
78 return $C0($M(rhs_, $S("$cya")));
79}
80
81CYTarget *CYApply::AddArgument(CYContext &context, CYExpression *value) {
82 CYArgument **argument(&arguments_);
83 while (*argument != NULL)
84 argument = &(*argument)->next_;
85 *argument = $ CYArgument(value);
86 return this;
87}
88
89CYArgument *CYArgument::Replace(CYContext &context) { $T(NULL)
90 context.Replace(value_);
91 next_ = next_->Replace(context);
92
93 if (value_ == NULL) {
94 if (next_ == NULL)
95 return NULL;
96 else
97 value_ = $U;
98 }
99
100 return this;
101}
102
103CYTarget *CYArray::Replace(CYContext &context) {
104 CYForEach (element, elements_)
105 element->Replace(context);
106 return this;
107}
108
109CYTarget *CYArrayComprehension::Replace(CYContext &context) {
110 CYIdentifier *cyv(context.Unique());
111
112 return $C0($F(NULL, $P1($B(cyv), comprehensions_->Parameters(context)), $$
113 ->* $E($ CYAssign($V(cyv), $ CYArray()))
114 ->* comprehensions_->Replace(context, $E($C1($M($V(cyv), $S("push")), expression_)))
115 ->* $ CYReturn($V(cyv))
116 ));
117}
118
119CYExpression *CYAssignment::Replace(CYContext &context) {
120 // XXX: this is a horrible hack but I'm a month over schedule :(
121 if (CYSubscriptMember *subscript = dynamic_cast<CYSubscriptMember *>(lhs_))
122 return $C2($M(subscript->object_, $S("$cys")), subscript->property_, rhs_);
123 context.Replace(lhs_);
124 context.Replace(rhs_);
125 return this;
126}
127
128CYTarget *CYAttemptMember::Replace(CYContext &context) {
129 CYIdentifier *value(context.Unique());
130
131 return $C1($F(NULL, $P1($B(value)), $$
132 ->* $ CYReturn($ CYCondition($V(value), $M($V(value), property_), $V(value)))
133 ), object_);
134}
135
136CYStatement *CYBlock::Return() {
137 CYImplicitReturn(code_);
138 return this;
139}
140
141CYStatement *CYBlock::Replace(CYContext &context) {
142 CYScope scope(true, context);
143 context.ReplaceAll(code_);
144 scope.Close(context);
145
146 if (code_ == NULL)
147 return $ CYEmpty();
148 return this;
149}
150
151CYStatement *CYBreak::Replace(CYContext &context) {
152 return this;
153}
154
155CYTarget *CYCall::Replace(CYContext &context) {
156 // XXX: this also is a horrible hack but I'm still a month over schedule :(
157 if (CYAttemptMember *member = dynamic_cast<CYAttemptMember *>(function_)) {
158 CYIdentifier *value(context.Unique());
159
160 return $C1($F(NULL, $P1($B(value)), $$
161 ->* $ CYReturn($ CYCondition($V(value), $C($M($V(value), member->property_), arguments_), $V(value)))
162 ), member->object_);
163 }
164
165 context.Replace(function_);
166 arguments_->Replace(context);
167 return this;
168}
169
170namespace cy {
171namespace Syntax {
172
173void Catch::Replace(CYContext &context) { $T()
174 CYScope scope(true, context);
175
176 name_ = name_->Replace(context, CYIdentifierCatch);
177
178 context.ReplaceAll(code_);
179 scope.Close(context);
180}
181
182} }
183
184CYTarget *CYClassExpression::Replace(CYContext &context) {
185 CYBuilder builder;
186
187 CYIdentifier *super(context.Unique());
188
189 CYIdentifier *old(context.super_);
190 context.super_ = super;
191
192 CYIdentifier *constructor(context.Unique());
193 CYForEach (member, tail_->static_)
194 member->Replace(context, builder, $V(constructor), true);
195
196 CYIdentifier *prototype(context.Unique());
197 CYForEach (member, tail_->instance_)
198 member->Replace(context, builder, $V(prototype), true);
199
200 if (tail_->constructor_ == NULL)
201 tail_->constructor_ = $ CYFunctionExpression(NULL, NULL, NULL);
202 tail_->constructor_->name_ = name_;
203 tail_->constructor_ = CYSuperize(context, tail_->constructor_);
204
205 context.super_ = old;
206
207 return $C1($ CYFunctionExpression(NULL, $P($B(super)), $$
208 ->* $ CYVar($B1($B(constructor, tail_->constructor_)))
209 ->* $ CYVar($B1($B(prototype, $ CYFunctionExpression(NULL, NULL, NULL))))
210 ->* $E($ CYAssign($M($V(prototype), $S("prototype")), $M($V(super), $S("prototype"))))
211 ->* $E($ CYAssign($V(prototype), $N($V(prototype))))
212 ->* CYDefineProperty($V(prototype), $S("constructor"), false, false, $ CYPropertyValue($S("value"), $V(constructor)))
213 ->* $ CYVar(builder.bindings_)
214 ->* builder.statements_
215 ->* CYDefineProperty($V(constructor), $S("prototype"), false, false, $ CYPropertyValue($S("value"), $V(prototype)))
216 ->* $ CYReturn($V(constructor))
217 ), tail_->extends_ ?: $V($I("Object")));
218}
219
220CYStatement *CYClassStatement::Replace(CYContext &context) {
221 return $ CYVar($B1($B(name_, $ CYClassExpression(name_, tail_))));
222}
223
224void CYClause::Replace(CYContext &context) { $T()
225 context.Replace(value_);
226 context.ReplaceAll(code_);
227 next_->Replace(context);
228}
229
230CYExpression *CYCompound::Replace(CYContext &context) {
231 context.Replace(expression_);
232 context.Replace(next_);
233
234 if (CYCompound *compound = dynamic_cast<CYCompound *>(expression_)) {
235 expression_ = compound->expression_;
236 compound->expression_ = compound->next_;
237 compound->next_ = next_;
238 next_ = compound;
239 }
240
241 return this;
242}
243
244CYFunctionParameter *CYCompound::Parameter() const {
245 CYFunctionParameter *next(next_->Parameter());
246 if (next == NULL)
247 return NULL;
248
249 CYFunctionParameter *parameter(expression_->Parameter());
250 if (parameter == NULL)
251 return NULL;
252
253 parameter->SetNext(next);
254 return parameter;
255}
256
257CYFunctionParameter *CYComprehension::Parameters(CYContext &context) const { $T(NULL)
258 CYFunctionParameter *next(next_->Parameters(context));
259 if (CYFunctionParameter *parameter = Parameter(context)) {
260 parameter->SetNext(next);
261 return parameter;
262 } else
263 return next;
264}
265
266CYStatement *CYComprehension::Replace(CYContext &context, CYStatement *statement) const {
267 return next_ == NULL ? statement : next_->Replace(context, statement);
268}
269
270CYExpression *CYComputed::PropertyName(CYContext &context) {
271 return expression_;
272}
273
274CYExpression *CYCondition::Replace(CYContext &context) {
275 context.Replace(test_);
276 context.Replace(true_);
277 context.Replace(false_);
278 return this;
279}
280
281void CYContext::NonLocal(CYStatement *&statements) {
282 CYContext &context(*this);
283
284 if (nextlocal_ != NULL && nextlocal_->identifier_ != NULL) {
285 CYIdentifier *cye($I("$cye")->Replace(context, CYIdentifierGlobal));
286 CYIdentifier *unique(nextlocal_->identifier_->Replace(context, CYIdentifierGlobal));
287
288 CYStatement *declare(
289 $ CYVar($B1($B(unique, $ CYObject()))));
290
291 cy::Syntax::Catch *rescue(
292 $ cy::Syntax::Catch(cye, $$
293 ->* $ CYIf($ CYIdentical($M($V(cye), $S("$cyk")), $V(unique)), $$
294 ->* $ CYReturn($M($V(cye), $S("$cyv"))))
295 ->* $ cy::Syntax::Throw($V(cye))));
296
297 context.Replace(declare);
298 rescue->Replace(context);
299
300 statements = $$
301 ->* declare
302 ->* $ cy::Syntax::Try(statements, rescue, NULL);
303 }
304}
305
306CYIdentifier *CYContext::Unique() {
307 return $ CYIdentifier($pool.strcat("$cy", $pool.itoa(unique_++), NULL));
308}
309
310CYStatement *CYContinue::Replace(CYContext &context) {
311 return this;
312}
313
314CYStatement *CYDebugger::Replace(CYContext &context) {
315 return this;
316}
317
318CYTarget *CYBinding::Target(CYContext &context) {
319 return $V(identifier_);
320}
321
322CYAssignment *CYBinding::Replace(CYContext &context, CYIdentifierKind kind) {
323 identifier_ = identifier_->Replace(context, kind);
324
325 if (initializer_ == NULL)
326 return NULL;
327
328 CYAssignment *value($ CYAssign(Target(context), initializer_));
329 initializer_ = NULL;
330 return value;
331}
332
333CYExpression *CYBindings::Replace(CYContext &context, CYIdentifierKind kind) { $T(NULL)
334 CYAssignment *assignment(binding_->Replace(context, kind));
335 CYExpression *compound(next_->Replace(context, kind));
336
337 if (assignment != NULL)
338 if (compound == NULL)
339 compound = assignment;
340 else
341 compound = $ CYCompound(assignment, compound);
342 return compound;
343}
344
345CYFunctionParameter *CYBindings::Parameter(CYContext &context) { $T(NULL)
346 return $ CYFunctionParameter($ CYBinding(binding_->identifier_), next_->Parameter(context));
347}
348
349CYArgument *CYBindings::Argument(CYContext &context) { $T(NULL)
350 return $ CYArgument(binding_->initializer_, next_->Argument(context));
351}
352
353CYTarget *CYDirectMember::Replace(CYContext &context) {
354 context.Replace(object_);
355 context.Replace(property_);
356 return this;
357}
358
359CYStatement *CYDoWhile::Replace(CYContext &context) {
360 context.Replace(test_);
361 context.ReplaceAll(code_);
362 return this;
363}
364
365void CYElementSpread::Replace(CYContext &context) {
366 context.Replace(value_);
367}
368
369void CYElementValue::Replace(CYContext &context) {
370 context.Replace(value_);
371}
372
373CYForInitializer *CYEmpty::Replace(CYContext &context) {
374 return NULL;
375}
376
377CYTarget *CYEncodedType::Replace(CYContext &context) {
378 return typed_->Replace(context);
379}
380
381CYTarget *CYEval::Replace(CYContext &context) {
382 context.scope_->Damage();
383 if (arguments_ != NULL)
384 arguments_->value_ = $C1($M($V("Cycript"), $S("compile")), arguments_->value_);
385 return $C($V("eval"), arguments_);
386}
387
388CYStatement *CYExpress::Return() {
389 return $ CYReturn(expression_);
390}
391
392CYForInitializer *CYExpress::Replace(CYContext &context) {
393 context.Replace(expression_);
394 return this;
395}
396
397CYTarget *CYExpression::AddArgument(CYContext &context, CYExpression *value) {
398 return $C1(this, value);
399}
400
401CYFunctionParameter *CYExpression::Parameter() const {
402 return NULL;
403}
404
405CYTarget *CYExtend::Replace(CYContext &context) {
406 return object_.Replace(context, lhs_);
407}
408
409CYStatement *CYExternalDefinition::Replace(CYContext &context) {
410 return $E($ CYAssign($V(name_), $ CYExternalExpression(abi_, type_, name_)));
411}
412
413CYTarget *CYExternalExpression::Replace(CYContext &context) {
414 CYExpression *expression(name_->Number(context));
415 if (expression == NULL)
416 expression = $C2($V("dlsym"), $V("RTLD_DEFAULT"), name_->PropertyName(context));
417 return $C1(type_->Replace(context), expression);
418}
419
420CYNumber *CYFalse::Number(CYContext &context) {
421 return $D(0);
422}
423
424CYString *CYFalse::String(CYContext &context) {
425 return $S("false");
426}
427
428CYExpression *CYFatArrow::Replace(CYContext &context) {
429 CYFunctionExpression *function($ CYFunctionExpression(NULL, parameters_, code_));
430 function->this_.SetNext(context.this_);
431 return function;
432}
433
434void CYFinally::Replace(CYContext &context) { $T()
435 CYScope scope(true, context);
436 context.ReplaceAll(code_);
437 scope.Close(context);
438}
439
440CYStatement *CYFor::Replace(CYContext &context) {
441 CYScope outer(true, context);
442 context.Replace(initializer_);
443
444 context.Replace(test_);
445
446 {
447 CYScope inner(true, context);
448 context.ReplaceAll(code_);
449 inner.Close(context);
450 }
451
452 context.Replace(increment_);
453
454 outer.Close(context);
455 return this;
456}
457
458CYStatement *CYForLexical::Initialize(CYContext &context, CYExpression *value) {
459 if (value == NULL) {
460 if (binding_->initializer_ == NULL)
461 return NULL;
462 value = binding_->initializer_;
463 }
464
465 return $ CYLexical(constant_, $B1($ CYBinding(binding_->identifier_, value)));
466}
467
468CYTarget *CYForLexical::Replace(CYContext &context) {
469 _assert(binding_->Replace(context, CYIdentifierLexical) == NULL);
470 return binding_->Target(context);
471}
472
473CYStatement *CYForIn::Replace(CYContext &context) {
474 CYScope scope(true, context);
475 context.Replace(initializer_);
476 context.Replace(iterable_);
477 context.ReplaceAll(code_);
478 scope.Close(context);
479 return this;
480}
481
482CYStatement *CYForInitialized::Replace(CYContext &context) {
483 CYAssignment *assignment(binding_->Replace(context, CYIdentifierVariable));
484 return $ CYBlock($$
485 ->* (assignment == NULL ? NULL : $ CYExpress(assignment))
486 ->* $ CYForIn(binding_->Target(context), iterable_, code_));
487}
488
489CYFunctionParameter *CYForInComprehension::Parameter(CYContext &context) const {
490 return $ CYFunctionParameter(binding_);
491}
492
493CYStatement *CYForInComprehension::Replace(CYContext &context, CYStatement *statement) const {
494 return $ CYForIn(binding_->Target(context), iterable_, CYComprehension::Replace(context, statement));
495}
496
497CYStatement *CYForOf::Replace(CYContext &context) {
498 CYIdentifier *item(context.Unique()), *list(context.Unique());
499
500 return $ CYBlock($$
501 ->* initializer_->Initialize(context, NULL)
502 ->* $ CYLexical(false, $B2($B(list, iterable_), $B(item)))
503 ->* $ CYForIn($V(item), $V(list), $ CYBlock($$
504 ->* initializer_->Initialize(context, $M($V(list), $V(item)))
505 ->* code_
506 )));
507}
508
509CYFunctionParameter *CYForOfComprehension::Parameter(CYContext &context) const {
510 return $ CYFunctionParameter(binding_);
511}
512
513CYStatement *CYForOfComprehension::Replace(CYContext &context, CYStatement *statement) const {
514 CYIdentifier *cys(context.Unique());
515
516 return $ CYBlock($$
517 ->* $ CYLexical(false, $B1($B(cys, iterable_)))
518 ->* $ CYForIn(binding_->Target(context), $V(cys), $ CYBlock($$
519 ->* $E($ CYAssign(binding_->Target(context), $M($V(cys), binding_->Target(context))))
520 ->* CYComprehension::Replace(context, statement)
521 )));
522}
523
524CYStatement *CYForVariable::Initialize(CYContext &context, CYExpression *value) {
525 if (value == NULL) {
526 if (binding_->initializer_ == NULL)
527 return NULL;
528 value = binding_->initializer_;
529 }
530
531 return $ CYVar($B1($ CYBinding(binding_->identifier_, value)));
532}
533
534CYTarget *CYForVariable::Replace(CYContext &context) {
535 _assert(binding_->Replace(context, CYIdentifierVariable) == NULL);
536 return binding_->Target(context);
537}
538
539// XXX: this is evil evil black magic. don't ask, don't tell... don't believe!
540#define MappingSet "0etnirsoalfucdphmgyvbxTwSNECAFjDLkMOIBPqzRH$_WXUVGYKQJZ"
541//#define MappingSet "0abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$_"
542
543void CYFunction::Replace(CYContext &context) {
544 CYThisScope *_this(context.this_);
545 context.this_ = &this_;
546 context.this_ = CYGetLast(context.this_);
547
548 CYIdentifier *super(context.super_);
549 context.super_ = super_;
550
551 CYNonLocal *nonlocal(context.nonlocal_);
552 CYNonLocal *nextlocal(context.nextlocal_);
553
554 bool localize;
555 if (nonlocal_ != NULL) {
556 localize = false;
557 context.nonlocal_ = nonlocal_;
558 } else {
559 localize = true;
560 nonlocal_ = $ CYNonLocal();
561 context.nextlocal_ = nonlocal_;
562 }
563
564 CYScope scope(!localize, context);
565
566 $I("arguments")->Replace(context, CYIdentifierMagic);
567
568 parameters_->Replace(context, code_);
569
570 context.ReplaceAll(code_);
571
572 if (implicit_)
573 CYImplicitReturn(code_);
574
575 if (CYIdentifier *identifier = this_.identifier_) {
576 context.scope_->Declare(context, identifier, CYIdentifierVariable);
577 code_ = $$
578 ->* $E($ CYAssign($V(identifier), $ CYThis()))
579 ->* code_;
580 }
581
582 if (localize)
583 context.NonLocal(code_);
584
585 context.nextlocal_ = nextlocal;
586 context.nonlocal_ = nonlocal;
587
588 context.super_ = super;
589 context.this_ = _this;
590
591 scope.Close(context, code_);
592}
593
594CYTarget *CYFunctionExpression::Replace(CYContext &context) {
595 CYScope scope(false, context);
596 if (name_ != NULL)
597 name_ = name_->Replace(context, CYIdentifierOther);
598
599 CYFunction::Replace(context);
600 scope.Close(context);
601 return this;
602}
603
604void CYFunctionParameter::Replace(CYContext &context, CYStatement *&statements) { $T()
605 CYAssignment *assignment(binding_->Replace(context, CYIdentifierArgument));
606
607 next_->Replace(context, statements);
608
609 if (assignment != NULL)
610 statements = $$
611 ->* $ CYIf($ CYIdentical($ CYTypeOf(binding_->Target(context)), $S("undefined")), $$
612 ->* $E(assignment))
613 ->* statements;
614}
615
616CYStatement *CYFunctionStatement::Replace(CYContext &context) {
617 name_ = name_->Replace(context, CYIdentifierOther);
618 CYFunction::Replace(context);
619 return this;
620}
621
622CYIdentifier *CYIdentifier::Replace(CYContext &context, CYIdentifierKind kind) {
623 if (next_ == this)
624 return this;
625 if (next_ != NULL)
626 return next_->Replace(context, kind);
627 next_ = context.scope_->Declare(context, this, kind)->identifier_;
628 return next_;
629}
630
631CYStatement *CYIf::Return() {
632 CYImplicitReturn(true_);
633 CYImplicitReturn(false_);
634 return this;
635}
636
637CYStatement *CYIf::Replace(CYContext &context) {
638 context.Replace(test_);
639 context.ReplaceAll(true_);
640 context.ReplaceAll(false_);
641 return this;
642}
643
644CYFunctionParameter *CYIfComprehension::Parameter(CYContext &context) const {
645 return NULL;
646}
647
648CYStatement *CYIfComprehension::Replace(CYContext &context, CYStatement *statement) const {
649 return $ CYIf(test_, CYComprehension::Replace(context, statement));
650}
651
652CYStatement *CYImport::Replace(CYContext &context) {
653 return $ CYVar($B1($B($I(module_->part_->Word()), $C1($V("require"), module_->Replace(context, "/")))));
654}
655
656CYStatement *CYImportDeclaration::Replace(CYContext &context) {
657 CYIdentifier *module(context.Unique());
658
659 CYList<CYStatement> statements;
660 CYForEach (specifier, specifiers_)
661 statements->*specifier->Replace(context, module);
662
663 return $ CYBlock($$
664 ->* $ CYLexical(false, $B1($B(module, $C1($V("require"), module_))))
665 ->* statements);
666}
667
668CYStatement *CYImportSpecifier::Replace(CYContext &context, CYIdentifier *module) {
669 binding_ = binding_->Replace(context, CYIdentifierLexical);
670
671 CYExpression *import($V(module));
672 if (name_ != NULL)
673 import = $M(import, $S(name_));
674 return $E($ CYAssign($V(binding_), import));
675}
676
677CYTarget *CYIndirect::Replace(CYContext &context) {
678 return $M(rhs_, $S("$cyi"));
679}
680
681CYTarget *CYIndirectMember::Replace(CYContext &context) {
682 return $M($ CYIndirect(object_), property_);
683}
684
685CYExpression *CYInfix::Replace(CYContext &context) {
686 context.Replace(lhs_);
687 context.Replace(rhs_);
688 return this;
689}
690
691CYStatement *CYLabel::Replace(CYContext &context) {
692 context.Replace(statement_);
693 return this;
694}
695
696CYTarget *CYLambda::Replace(CYContext &context) {
697 return $N2($V("Functor"), $ CYFunctionExpression(NULL, parameters_->Parameters(context), code_), parameters_->TypeSignature(context, typed_->Replace(context)));
698}
699
700CYForInitializer *CYLexical::Replace(CYContext &context) {
701 if (CYExpression *expression = bindings_->Replace(context, CYIdentifierLexical))
702 return $E(expression);
703 return $ CYEmpty();
704}
705
706CYFunctionExpression *CYMethod::Constructor() {
707 return NULL;
708}
709
710void CYMethod::Replace(CYContext &context) {
711 CYFunction::Replace(context);
712}
713
714CYString *CYModule::Replace(CYContext &context, const char *separator) const {
715 if (next_ == NULL)
716 return $ CYString(part_);
717 return $ CYString($pool.strcat(next_->Replace(context, separator)->Value(), separator, part_->Word(), NULL));
718}
719
720CYExpression *CYMultiply::Replace(CYContext &context) {
721 CYInfix::Replace(context);
722
723 if (CYNumber *lhn = lhs_->Number(context))
724 if (CYNumber *rhn = rhs_->Number(context))
725 return $D(lhn->Value() * rhn->Value());
726
727 return this;
728}
729
730namespace cy {
731namespace Syntax {
732
733CYTarget *New::AddArgument(CYContext &context, CYExpression *value) {
734 CYSetLast(arguments_) = $ CYArgument(value);
735 return this;
736}
737
738CYTarget *New::Replace(CYContext &context) {
739 context.Replace(constructor_);
740 arguments_->Replace(context);
741 return this;
742}
743
744} }
745
746CYNumber *CYNull::Number(CYContext &context) {
747 return $D(0);
748}
749
750CYString *CYNull::String(CYContext &context) {
751 return $S("null");
752}
753
754CYNumber *CYNumber::Number(CYContext &context) {
755 return this;
756}
757
758CYString *CYNumber::String(CYContext &context) {
759 // XXX: there is a precise algorithm for this
760 return $S($pool.sprintf(24, "%.17g", Value()));
761}
762
763CYExpression *CYNumber::PropertyName(CYContext &context) {
764 return String(context);
765}
766
767CYTarget *CYObject::Replace(CYContext &context, CYTarget *seed) {
768 CYBuilder builder;
769 if (properties_ != NULL)
770 properties_ = properties_->ReplaceAll(context, builder, $ CYThis(), seed != this);
771
772 if (builder) {
773 return $C1($M($ CYFunctionExpression(NULL, builder.bindings_->Parameter(context),
774 builder.statements_
775 ->* $ CYReturn($ CYThis())
776 ), $S("call")), seed, builder.bindings_->Argument(context));
777 }
778
779 CYForEach (property, properties_)
780 property->Replace(context);
781 return seed;
782}
783
784CYTarget *CYObject::Replace(CYContext &context) {
785 return Replace(context, this);
786}
787
788CYTarget *CYParenthetical::Replace(CYContext &context) {
789 // XXX: return expression_;
790 context.Replace(expression_);
791 return this;
792}
793
794CYExpression *CYPostfix::Replace(CYContext &context) {
795 context.Replace(lhs_);
796 return this;
797}
798
799CYExpression *CYPrefix::Replace(CYContext &context) {
800 context.Replace(rhs_);
801 return this;
802}
803
804CYProperty *CYProperty::ReplaceAll(CYContext &context, CYBuilder &builder, CYExpression *self, bool update) {
805 update |= Update();
806 if (update)
807 Replace(context, builder, self, false);
808 if (next_ != NULL)
809 next_ = next_->ReplaceAll(context, builder, self, update);
810 return update ? next_ : this;
811}
812
813void CYProperty::Replace(CYContext &context, CYBuilder &builder, CYExpression *self, bool protect) {
814 CYExpression *name(name_->PropertyName(context));
815 if (name_->Computed()) {
816 CYIdentifier *unique(context.Unique());
817 builder.bindings_
818 ->* $B1($B(unique, name));
819 name = $V(unique);
820 }
821
822 Replace(context, builder, self, name, protect);
823}
824
825bool CYProperty::Update() const {
826 return name_->Computed();
827}
828
829void CYPropertyGetter::Replace(CYContext &context, CYBuilder &builder, CYExpression *self, CYExpression *name, bool protect) {
830 CYIdentifier *unique(context.Unique());
831 builder.bindings_
832 ->* $B1($B(unique, CYSuperize(context, $ CYFunctionExpression(NULL, parameters_, code_))));
833 builder.statements_
834 ->* CYDefineProperty(self, name, true, !protect, $ CYPropertyValue($S("get"), $V(unique)));
835}
836
837CYFunctionExpression *CYPropertyMethod::Constructor() {
838 return name_->Constructor() ? $ CYFunctionExpression(NULL, parameters_, code_) : NULL;
839}
840
841void CYPropertyMethod::Replace(CYContext &context, CYBuilder &builder, CYExpression *self, CYExpression *name, bool protect) {
842 CYIdentifier *unique(context.Unique());
843 builder.bindings_
844 ->* $B1($B(unique, CYSuperize(context, $ CYFunctionExpression(NULL, parameters_, code_))));
845 builder.statements_
846 ->* (!protect ? $E($ CYAssign($M(self, name), $V(unique))) :
847 CYDefineProperty(self, name, true, !protect, $ CYPropertyValue($S("value"), $V(unique), $ CYPropertyValue($S("writable"), $ CYTrue()))));
848}
849
850bool CYPropertyMethod::Update() const {
851 return true;
852}
853
854void CYPropertySetter::Replace(CYContext &context, CYBuilder &builder, CYExpression *self, CYExpression *name, bool protect) {
855 CYIdentifier *unique(context.Unique());
856 builder.bindings_
857 ->* $B1($B(unique, CYSuperize(context, $ CYFunctionExpression(NULL, parameters_, code_))));
858 builder.statements_
859 ->* CYDefineProperty(self, name, true, !protect, $ CYPropertyValue($S("set"), $V(unique)));
860}
861
862void CYPropertyValue::Replace(CYContext &context, CYBuilder &builder, CYExpression *self, CYExpression *name, bool protect) {
863 _assert(!protect);
864 CYIdentifier *unique(context.Unique());
865 builder.bindings_
866 ->* $B1($B(unique, value_));
867 builder.statements_
868 ->* $E($ CYAssign($M(self, name), $V(unique)));
869}
870
871void CYPropertyValue::Replace(CYContext &context) {
872 context.Replace(value_);
873}
874
875void CYScript::Replace(CYContext &context) {
876 CYScope scope(false, context);
877 context.scope_->Damage();
878
879 context.nextlocal_ = $ CYNonLocal();
880 context.ReplaceAll(code_);
881 context.NonLocal(code_);
882
883 scope.Close(context, code_);
884
885 unsigned offset(0);
886
887 for (std::vector<CYIdentifier *>::const_iterator i(context.replace_.begin()); i != context.replace_.end(); ++i) {
888 const char *name;
889 if (context.options_.verbose_)
890 name = $pool.strcat("$", $pool.itoa(offset++), NULL);
891 else {
892 char id[8];
893 id[7] = '\0';
894
895 id:
896 unsigned position(7), local(offset++ + 1);
897
898 do {
899 unsigned index(local % (sizeof(MappingSet) - 1));
900 local /= sizeof(MappingSet) - 1;
901 id[--position] = MappingSet[index];
902 } while (local != 0);
903
904 if (scope.Lookup(context, id + position) != NULL)
905 goto id;
906 // XXX: at some point, this could become a keyword
907
908 name = $pool.strmemdup(id + position, 7 - position);
909 }
910
911 CYIdentifier *identifier(*i);
912 _assert(identifier->next_ == identifier);
913 identifier->next_ = $I(name);
914 }
915}
916
917CYTarget *CYResolveMember::Replace(CYContext &context) {
918 return $M($M(object_, $S("$cyr")), property_);
919}
920
921CYStatement *CYReturn::Replace(CYContext &context) {
922 if (context.nonlocal_ != NULL) {
923 CYProperty *value(value_ == NULL ? NULL : $ CYPropertyValue($S("$cyv"), value_));
924 return $ cy::Syntax::Throw($ CYObject(
925 $ CYPropertyValue($S("$cyk"), $V(context.nonlocal_->Target(context)), value)
926 ));
927 }
928
929 context.Replace(value_);
930 return this;
931}
932
933CYTarget *CYRubyBlock::Replace(CYContext &context) {
934 return lhs_->AddArgument(context, proc_->Replace(context));
935}
936
937CYTarget *CYRubyBlock::AddArgument(CYContext &context, CYExpression *value) {
938 return Replace(context)->AddArgument(context, value);
939}
940
941CYTarget *CYRubyProc::Replace(CYContext &context) {
942 CYFunctionExpression *function($ CYFunctionExpression(NULL, parameters_, code_));
943 function = CYNonLocalize(context, function);
944 function->implicit_ = true;
945 return function;
946}
947
948CYScope::CYScope(bool transparent, CYContext &context) :
949 transparent_(transparent),
950 parent_(context.scope_),
951 damaged_(false),
952 shadow_(NULL),
953 internal_(NULL)
954{
955 _assert(!transparent_ || parent_ != NULL);
956 context.scope_ = this;
957}
958
959void CYScope::Damage() {
960 damaged_ = true;
961 if (parent_ != NULL)
962 parent_->Damage();
963}
964
965CYIdentifierFlags *CYScope::Lookup(CYContext &context, const char *word) {
966 CYForEach (i, internal_)
967 if (strcmp(i->identifier_->Word(), word) == 0)
968 return i;
969 return NULL;
970}
971
972CYIdentifierFlags *CYScope::Lookup(CYContext &context, CYIdentifier *identifier) {
973 return Lookup(context, identifier->Word());
974}
975
976CYIdentifierFlags *CYScope::Declare(CYContext &context, CYIdentifier *identifier, CYIdentifierKind kind) {
977 _assert(identifier->next_ == NULL || identifier->next_ == identifier);
978
979 CYIdentifierFlags *existing(Lookup(context, identifier));
980 if (existing == NULL)
981 internal_ = $ CYIdentifierFlags(identifier, kind, internal_);
982 ++internal_->count_;
983 if (existing == NULL)
984 return internal_;
985
986 if (kind == CYIdentifierGlobal);
987 else if (existing->kind_ == CYIdentifierGlobal || existing->kind_ == CYIdentifierMagic)
988 existing->kind_ = kind;
989 else if (existing->kind_ == CYIdentifierLexical || kind == CYIdentifierLexical)
990 _assert(false);
991 else if (transparent_ && existing->kind_ == CYIdentifierArgument && kind == CYIdentifierVariable)
992 _assert(false);
993 // XXX: throw new SyntaxError() instead of these asserts
994
995 return existing;
996}
997
998void CYScope::Merge(CYContext &context, const CYIdentifierFlags *flags) {
999 _assert(flags->identifier_->next_ == flags->identifier_);
1000 CYIdentifierFlags *existing(Declare(context, flags->identifier_, flags->kind_));
1001 flags->identifier_->next_ = existing->identifier_;
1002
1003 existing->count_ += flags->count_;
1004 if (existing->offset_ < flags->offset_)
1005 existing->offset_ = flags->offset_;
1006}
1007
1008void CYScope::Close(CYContext &context, CYStatement *&statements) {
1009 Close(context);
1010
1011 CYList<CYBindings> bindings;
1012
1013 CYForEach (i, internal_)
1014 if (i->kind_ == CYIdentifierVariable)
1015 bindings
1016 ->* $ CYBindings($ CYBinding(i->identifier_));
1017
1018 if (bindings) {
1019 CYVar *var($ CYVar(bindings));
1020 var->SetNext(statements);
1021 statements = var;
1022 }
1023}
1024
1025void CYScope::Close(CYContext &context) {
1026 context.scope_ = parent_;
1027
1028 CYForEach (i, internal_) {
1029 _assert(i->identifier_->next_ == i->identifier_);
1030 switch (i->kind_) {
1031 case CYIdentifierLexical: {
1032 if (!damaged_) {
1033 CYIdentifier *replace(context.Unique());
1034 replace->next_ = replace;
1035 i->identifier_->next_ = replace;
1036 i->identifier_ = replace;
1037 }
1038
1039 if (!transparent_)
1040 i->kind_ = CYIdentifierVariable;
1041 else
1042 parent_->Declare(context, i->identifier_, CYIdentifierVariable);
1043 } break;
1044
1045 case CYIdentifierVariable: {
1046 if (transparent_) {
1047 parent_->Declare(context, i->identifier_, i->kind_);
1048 i->kind_ = CYIdentifierGlobal;
1049 }
1050 } break;
1051 default:; } }
1052
1053 if (damaged_)
1054 return;
1055
1056 typedef std::multimap<unsigned, CYIdentifier *> CYIdentifierOffsetMap;
1057 CYIdentifierOffsetMap offsets;
1058
1059 CYForEach (i, internal_) {
1060 _assert(i->identifier_->next_ == i->identifier_);
1061 switch (i->kind_) {
1062 case CYIdentifierArgument:
1063 case CYIdentifierVariable:
1064 offsets.insert(CYIdentifierOffsetMap::value_type(i->offset_, i->identifier_));
1065 break;
1066 default:; } }
1067
1068 unsigned offset(0);
1069
1070 for (CYIdentifierOffsetMap::const_iterator i(offsets.begin()); i != offsets.end(); ++i) {
1071 if (offset < i->first)
1072 offset = i->first;
1073 CYIdentifier *identifier(i->second);
1074
1075 if (offset >= context.replace_.size())
1076 context.replace_.resize(offset + 1, NULL);
1077 CYIdentifier *&replace(context.replace_[offset++]);
1078
1079 if (replace == NULL)
1080 replace = identifier;
1081 else {
1082 _assert(replace->next_ == replace);
1083 identifier->next_ = replace;
1084 }
1085 }
1086
1087 if (parent_ == NULL)
1088 return;
1089
1090 CYForEach (i, internal_) {
1091 switch (i->kind_) {
1092 case CYIdentifierGlobal: {
1093 if (i->offset_ < offset)
1094 i->offset_ = offset;
1095 parent_->Merge(context, i);
1096 } break;
1097 default:; } }
1098}
1099
1100CYTarget *CYSubscriptMember::Replace(CYContext &context) {
1101 return $C1($M(object_, $S("$cyg")), property_);
1102}
1103
1104CYElementValue *CYSpan::Replace(CYContext &context) { $T(NULL)
1105 return $ CYElementValue(expression_, $ CYElementValue(string_, next_->Replace(context)));
1106}
1107
1108CYStatement *CYStatement::Return() {
1109 return this;
1110}
1111
1112CYString *CYString::Concat(CYContext &context, CYString *rhs) const {
1113 size_t size(size_ + rhs->size_);
1114 char *value($ char[size + 1]);
1115 memcpy(value, value_, size_);
1116 memcpy(value + size_, rhs->value_, rhs->size_);
1117 value[size] = '\0';
1118 return $S(value, size);
1119}
1120
1121CYIdentifier *CYString::Identifier() const {
1122 if (const char *word = Word())
1123 return $ CYIdentifier(word);
1124 return NULL;
1125}
1126
1127CYNumber *CYString::Number(CYContext &context) {
1128 // XXX: there is a precise algorithm for this
1129 return NULL;
1130}
1131
1132CYExpression *CYString::PropertyName(CYContext &context) {
1133 return this;
1134}
1135
1136CYString *CYString::String(CYContext &context) {
1137 return this;
1138}
1139
1140CYStatement *CYStructDefinition::Replace(CYContext &context) {
1141 CYTarget *target(tail_->Replace(context));
1142 if (name_ != NULL)
1143 target = $C1($M(target, $S("withName")), $S(name_->Word()));
1144 return $ CYLexical(false, $B1($B($I($pool.strcat(name_->Word(), "$cy", NULL)), target)));
1145}
1146
1147CYTarget *CYStructTail::Replace(CYContext &context) {
1148 CYList<CYElementValue> types;
1149 CYList<CYElementValue> names;
1150
1151 CYForEach (field, fields_) {
1152 types->*$ CYElementValue(field->type_->Replace(context));
1153
1154 CYExpression *name;
1155 if (field->name_ == NULL)
1156 name = NULL;
1157 else
1158 name = field->name_->PropertyName(context);
1159 names->*$ CYElementValue(name);
1160 }
1161
1162 return $N2($V("Type"), $ CYArray(types), $ CYArray(names));
1163}
1164
1165CYTarget *CYSuperAccess::Replace(CYContext &context) {
1166 return $C1($M($M($M($V(context.super_), $S("prototype")), property_), $S("bind")), $ CYThis());
1167}
1168
1169CYTarget *CYSuperCall::Replace(CYContext &context) {
1170 return $C($C1($M($V(context.super_), $S("bind")), $ CYThis()), arguments_);
1171}
1172
1173CYTarget *CYSymbol::Replace(CYContext &context) {
1174 return $C1($M($V("Symbol"), $S("for")), $S(name_));
1175}
1176
1177CYStatement *CYSwitch::Replace(CYContext &context) {
1178 context.Replace(value_);
1179 clauses_->Replace(context);
1180 return this;
1181}
1182
1183CYStatement *CYTarget::Initialize(CYContext &context, CYExpression *value) {
1184 if (value == NULL)
1185 return NULL;
1186 return $E($ CYAssign(this, value));
1187}
1188
1189CYTarget *CYTemplate::Replace(CYContext &context) {
1190 return $C2($M($M($M($V("String"), $S("prototype")), $S("concat")), $S("apply")), $S(""), $ CYArray($ CYElementValue(string_, spans_->Replace(context))));
1191}
1192
1193CYString *CYTemplate::String(CYContext &context) {
1194 // XXX: implement this over local concat
1195 if (spans_ != NULL)
1196 return NULL;
1197 return string_;
1198}
1199
1200CYTarget *CYThis::Replace(CYContext &context) {
1201 if (context.this_ != NULL)
1202 return $V(context.this_->Identifier(context));
1203 return this;
1204}
1205
1206namespace cy {
1207namespace Syntax {
1208
1209CYStatement *Throw::Replace(CYContext &context) {
1210 context.Replace(value_);
1211 return this;
1212}
1213
1214} }
1215
1216CYTarget *CYTrivial::Replace(CYContext &context) {
1217 return this;
1218}
1219
1220CYNumber *CYTrue::Number(CYContext &context) {
1221 return $D(1);
1222}
1223
1224CYString *CYTrue::String(CYContext &context) {
1225 return $S("true");
1226}
1227
1228namespace cy {
1229namespace Syntax {
1230
1231CYStatement *Try::Replace(CYContext &context) {
1232 CYScope scope(true, context);
1233 context.ReplaceAll(code_);
1234 scope.Close(context);
1235
1236 catch_->Replace(context);
1237 finally_->Replace(context);
1238 return this;
1239}
1240
1241} }
1242
1243CYTarget *CYTypeArrayOf::Replace_(CYContext &context, CYTarget *type) {
1244 return next_->Replace(context, $ CYCall($ CYDirectMember(type, $ CYString("arrayOf")), $ CYArgument(size_)));
1245}
1246
1247CYTarget *CYTypeBlockWith::Replace_(CYContext &context, CYTarget *type) {
1248 return next_->Replace(context, $ CYCall($ CYDirectMember(type, $ CYString("blockWith")), parameters_->Argument(context)));
1249}
1250
1251CYTarget *CYTypeCharacter::Replace(CYContext &context) {
1252 switch (signing_) {
1253 case CYTypeNeutral: return $V("char");
1254 case CYTypeSigned: return $V("schar");
1255 case CYTypeUnsigned: return $V("uchar");
1256 default: _assert(false);
1257 }
1258}
1259
1260CYTarget *CYTypeConstant::Replace_(CYContext &context, CYTarget *type) {
1261 return next_->Replace(context, $ CYCall($ CYDirectMember(type, $ CYString("constant"))));
1262}
1263
1264CYStatement *CYTypeDefinition::Replace(CYContext &context) {
1265 return $ CYLexical(false, $B1($B(name_, $ CYTypeExpression(type_))));
1266}
1267
1268CYTarget *CYTypeEnum::Replace(CYContext &context) {
1269 CYList<CYProperty> properties;
1270 CYForEach (constant, constants_)
1271 properties->*$ CYPropertyValue($S(constant->name_->Word()), constant->value_);
1272 CYObject *constants($ CYObject(properties));
1273
1274 if (specifier_ == NULL)
1275 return $N1($V("Type"), constants);
1276 else
1277 return $C1($M(specifier_->Replace(context), $S("enumFor")), constants);
1278}
1279
1280CYTarget *CYTypeError::Replace(CYContext &context) {
1281 _assert(false);
1282 return NULL;
1283}
1284
1285CYTarget *CYTypeExpression::Replace(CYContext &context) {
1286 return typed_->Replace(context);
1287}
1288
1289CYTarget *CYTypeFloating::Replace(CYContext &context) {
1290 switch (length_) {
1291 case 0: return $V("float");
1292 case 1: return $V("double");
1293 case 2: return $V("longdouble");
1294 default: _assert(false);
1295 }
1296}
1297
1298CYTarget *CYTypeInt128::Replace(CYContext &context) {
1299 return $V(signing_ == CYTypeUnsigned ? "uint128" : "int128");
1300}
1301
1302CYTarget *CYTypeIntegral::Replace(CYContext &context) {
1303 bool u(signing_ == CYTypeUnsigned);
1304 switch (length_) {
1305 case 0: return $V(u ? "ushort" : "short");
1306 case 1: return $V(u ? "uint" : "int");
1307 case 2: return $V(u ? "ulong" : "long");
1308 case 3: return $V(u ? "ulonglong" : "longlong");
1309 default: _assert(false);
1310 }
1311}
1312
1313CYTarget *CYTypeModifier::Replace(CYContext &context, CYTarget *type) { $T(type)
1314 return Replace_(context, type);
1315}
1316
1317CYTarget *CYTypeFunctionWith::Replace_(CYContext &context, CYTarget *type) {
1318 CYList<CYArgument> arguments(parameters_->Argument(context));
1319 if (variadic_)
1320 arguments->*$C_($ CYNull());
1321 return next_->Replace(context, $ CYCall($ CYDirectMember(type, $ CYString("functionWith")), arguments));
1322}
1323
1324CYTarget *CYTypePointerTo::Replace_(CYContext &context, CYTarget *type) {
1325 return next_->Replace(context, $ CYCall($ CYDirectMember(type, $ CYString("pointerTo"))));
1326}
1327
1328CYTarget *CYTypeReference::Replace(CYContext &context) {
1329 const char *prefix;
1330 switch (kind_) {
1331 case CYTypeReferenceStruct: prefix = "$cys"; break;
1332 case CYTypeReferenceEnum: prefix = "$cye"; break;
1333 default: _assert(false);
1334 }
1335
1336 return $V($pool.strcat(prefix, name_->Word(), NULL));
1337}
1338
1339CYTarget *CYTypeStruct::Replace(CYContext &context) {
1340 CYTarget *target(tail_->Replace(context));
1341 if (name_ != NULL)
1342 target = $C1($M(target, $S("withName")), $S(name_->Word()));
1343 return target;
1344}
1345
1346CYTarget *CYTypeVariable::Replace(CYContext &context) {
1347 return $V(name_);
1348}
1349
1350CYTarget *CYTypeVoid::Replace(CYContext &context) {
1351 return $N1($V("Type"), $ CYString("v"));
1352}
1353
1354CYTarget *CYTypeVolatile::Replace_(CYContext &context, CYTarget *type) {
1355 return next_->Replace(context, $ CYCall($ CYDirectMember(type, $ CYString("volatile"))));
1356}
1357
1358CYTarget *CYType::Replace(CYContext &context) {
1359 return modifier_->Replace(context, specifier_->Replace(context));
1360}
1361
1362CYTypeFunctionWith *CYType::Function() {
1363 CYTypeModifier *&modifier(CYGetLast(modifier_));
1364 if (modifier == NULL)
1365 return NULL;
1366
1367 CYTypeFunctionWith *function(modifier->Function());
1368 if (function == NULL)
1369 return NULL;
1370
1371 modifier = NULL;
1372 return function;
1373}
1374
1375CYArgument *CYTypedParameter::Argument(CYContext &context) { $T(NULL)
1376 return $ CYArgument(type_->Replace(context), next_->Argument(context));
1377}
1378
1379CYFunctionParameter *CYTypedParameter::Parameters(CYContext &context) { $T(NULL)
1380 return $ CYFunctionParameter($ CYBinding(name_ ?: context.Unique()), next_->Parameters(context));
1381}
1382
1383CYExpression *CYTypedParameter::TypeSignature(CYContext &context, CYExpression *prefix) { $T(prefix)
1384 return next_->TypeSignature(context, $ CYAdd(prefix, type_->Replace(context)));
1385}
1386
1387CYForInitializer *CYVar::Replace(CYContext &context) {
1388 if (CYExpression *expression = bindings_->Replace(context, CYIdentifierVariable))
1389 return $E(expression);
1390 return $ CYEmpty();
1391}
1392
1393CYTarget *CYVariable::Replace(CYContext &context) {
1394 name_ = name_->Replace(context, CYIdentifierGlobal);
1395 return this;
1396}
1397
1398CYFunctionParameter *CYVariable::Parameter() const {
1399 return $ CYFunctionParameter($ CYBinding(name_));
1400}
1401
1402CYStatement *CYWhile::Replace(CYContext &context) {
1403 context.Replace(test_);
1404 context.ReplaceAll(code_);
1405 return this;
1406}
1407
1408CYStatement *CYWith::Replace(CYContext &context) {
1409 context.Replace(scope_);
1410 CYScope scope(true, context);
1411 scope.Damage();
1412 context.ReplaceAll(code_);
1413 scope.Close(context);
1414 return this;
1415}
1416
1417CYExpression *CYWord::PropertyName(CYContext &context) {
1418 return $S(this);
1419}