/* }}} */
/* 13.2 Arrow Function Definitions {{{ */
ArrowFunction
- : LexSetRegExp ArrowParameters "=>" LexNoBrace ConciseBody { $$ = CYNew CYFunctionExpression(NULL, $2, $5); }
+ : LexSetRegExp ArrowParameters "=>" LexNoBrace ConciseBody { $$ = CYNew CYFatArrow($2, $5); }
;
ArrowParameters
Output(out, flags);
}
+void CYFatArrow::Output(CYOutput &out, CYFlags flags) const {
+ out << '(' << parameters_ << ')' << ' ' << "=>" << ' ' << code_;
+}
+
void CYFinally::Output(CYOutput &out) const {
out << ' ' << "finally" << ' ' << code_;
}
};
struct CYNonLocal;
+struct CYThisScope;
struct CYContext {
CYOptions &options_;
CYScope *scope_;
+ CYThisScope *this_;
+
CYIdentifierUsageVector rename_;
CYNonLocal *nonlocal_;
CYContext(CYOptions &options) :
options_(options),
scope_(NULL),
+ this_(NULL),
nonlocal_(NULL),
nextlocal_(NULL),
unique_(0)
}
};
+struct CYThisScope :
+ CYNext<CYThisScope>
+{
+ CYIdentifier *identifier_;
+
+ CYThisScope() :
+ identifier_(NULL)
+ {
+ }
+
+ CYIdentifier *Identifier(CYContext &context) {
+ if (next_ != NULL)
+ return next_->Identifier(context);
+ if (identifier_ == NULL)
+ identifier_ = context.Unique();
+ return identifier_;
+ }
+};
+
struct CYBlock :
CYStatement,
CYThing
CYIdentifier *name_;
CYFunctionParameter *parameters_;
CYBlock code_;
+
CYNonLocal *nonlocal_;
+ CYThisScope this_;
CYFunction(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *statements) :
name_(name),
virtual void Output(CYOutput &out, CYFlags flags) const;
};
+// XXX: this should derive from CYAnonymousFunction
+struct CYFatArrow :
+ CYFunction,
+ CYExpression
+{
+ CYFatArrow(CYFunctionParameter *parameters, CYStatement *statements) :
+ CYFunction(NULL, parameters, statements)
+ {
+ }
+
+ CYPrecedence(0)
+ CYRightHand(false)
+
+ virtual CYExpression *Replace(CYContext &context);
+ virtual void Output(CYOutput &out, CYFlags flags) const;
+};
+
// XXX: this should derive from CYAnonymousFunctionExpression
struct CYRubyProc :
CYFunctionExpression
return $S("false");
}
+CYExpression *CYFatArrow::Replace(CYContext &context) {
+ CYFunctionExpression *function($ CYFunctionExpression(NULL, parameters_, code_));
+ function->this_.SetNext(context.this_);
+ return function;
+}
+
void CYFinally::Replace(CYContext &context) { $T()
code_.Replace(context);
}
if (outer)
Inject(context);
+ CYThisScope *_this(context.this_);
+ context.this_ = CYGetLast(&this_);
+
CYNonLocal *nonlocal(context.nonlocal_);
CYNonLocal *nextlocal(context.nextlocal_);
parameters_->Replace(context, code_);
code_.Replace(context);
+ if (CYIdentifier *identifier = this_.identifier_)
+ code_.statements_ = $$->*
+ $ CYVar($L1($ CYDeclaration(identifier, $ CYThis())))->*
+ code_.statements_;
+
if (localize)
context.NonLocal(code_.statements_);
context.nextlocal_ = nextlocal;
context.nonlocal_ = nonlocal;
+ context.this_ = _this;
+
scope.Close();
}
}
CYExpression *CYThis::Replace(CYContext &context) {
+ if (context.this_ != NULL)
+ return $V(context.this_->Identifier(context));
return this;
}