virtual void Output(CYOutput &out, CYFlags flags) const;
};
+struct CYProperty :
+ CYNext<CYProperty>,
+ CYThing
+{
+ CYPropertyName *name_;
+ CYExpression *value_;
+
+ CYProperty(CYPropertyName *name, CYExpression *value, CYProperty *next = NULL) :
+ CYNext<CYProperty>(next),
+ name_(name),
+ value_(value)
+ {
+ }
+
+ void Replace(CYContext &context);
+ virtual void Output(CYOutput &out) const;
+};
+
struct CYDeclaration :
CYForInInitialiser
{
CYIdentifier *identifier_;
CYExpression *initialiser_;
- CYDeclaration(CYIdentifier *identifier, CYExpression *initialiser) :
+ CYDeclaration(CYIdentifier *identifier, CYExpression *initialiser = NULL) :
identifier_(identifier),
initialiser_(initialiser)
{
virtual void For(CYOutput &out) const;
void Replace(CYContext &context);
+ CYProperty *Property(CYContext &context);
virtual void Output(CYOutput &out) const;
virtual void Output(CYOutput &out, CYFlags flags) const;
virtual void Output(CYOutput &out, CYFlags flags) const;
};
-struct CYProperty :
- CYNext<CYProperty>,
- CYThing
-{
- CYPropertyName *name_;
- CYExpression *value_;
-
- CYProperty(CYPropertyName *name, CYExpression *value, CYProperty *next = NULL) :
- CYNext<CYProperty>(next),
- name_(name),
- value_(value)
- {
- }
-
- void Replace(CYContext &context);
- virtual void Output(CYOutput &out) const;
-};
-
struct CYObject :
CYLiteral
{
context.Replace(initialiser_);
}
+CYProperty *CYDeclarations::Property(CYContext &context) { $T(NULL)
+ return $ CYProperty(declaration_->identifier_, declaration_->initialiser_ ?: $U, next_->Property(context));
+}
+
void CYDeclarations::Replace(CYContext &context) { $T()
declaration_->Replace(context);
next_->Replace(context);
CYStatement *CYForEachIn::Replace(CYContext &context) {
CYVariable *cys($V("$cys")), *cyt($V("$cyt"));
- return $ CYWith($ CYObject($ CYProperty($S("$cys"), $D(0), $ CYProperty($S("$cyt"), $D(0)))), $ CYBlock($$->*
- $E($ CYAssign(cys, set_))->*
+ return $ CYLet($L2($L($I("$cys"), set_), $L($I("$cyt"))), $$->*
$ CYForIn(cyt, cys, $ CYBlock($$->*
$E($ CYAssign(initialiser_->ForEachIn(context), $M(cys, cyt)))->*
code_
))
- ));
+ );
}
CYFunctionParameter *CYForEachInComprehension::Parameter(CYContext &context) const {
return NULL;
}
+CYStatement *CYLet::Replace(CYContext &context) {
+ return $ CYWith($ CYObject(declarations_->Property(context)), &code_);
+}
+
void CYMember::Replace_(CYContext &context) {
context.Replace(object_);
context.Replace(property_);
($ CYFunctionParameter(args))
#define $S(args...) \
($ CYString(args))
+#define $U \
+ $V("undefined")
#define $V(name) \
($ CYVariable($I(name)))
#define $N5(func, args...) \
$N(func, $C5_(args))
+#define $L(args...) \
+ $ CYDeclaration(args)
+#define $L1(arg0) \
+ $ CYDeclarations(arg0)
+#define $L2(arg0, args...) \
+ $ CYDeclarations(arg0, $L1(args))
+#define $L3(arg0, args...) \
+ $ CYDeclarations(arg0, $L2(args))
+#define $L4(arg0, args...) \
+ $ CYDeclarations(arg0, $L3(args))
+#define $L5(arg0, args...) \
+ $ CYDeclarations(arg0, $L4(args))
+
#endif/*REPLACE_HPP*/