virtual CYStatement *Replace(CYContext &context) = 0;
+ virtual CYStatement *Return();
+
private:
virtual void Output(CYOutput &out, CYFlags flags) const = 0;
};
virtual CYStatement *Replace(CYContext &context);
virtual void Output(CYOutput &out, CYFlags flags) const;
+
+ virtual CYStatement *Return();
};
struct CYForInitialiser {
virtual CYStatement *Replace(CYContext &context);
virtual void Output(CYOutput &out, CYFlags flags) const;
+
+ virtual CYStatement *Return();
};
struct CYDoWhile :
CYStatement *code_;
CYNonLocal *nonlocal_;
+ bool implicit_;
CYThisScope this_;
CYFunction(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *code) :
name_(name),
parameters_(parameters),
code_(code),
- nonlocal_(NULL)
+ nonlocal_(NULL),
+ implicit_(false)
{
}
virtual CYStatement *Replace(CYContext &context);
virtual void Output(CYOutput &out, CYFlags flags) const;
+
+ virtual CYStatement *Return();
};
struct CYContinue :
return function;
}
+static void CYImplicitReturn(CYStatement *&code) {
+ if (CYStatement *&last = CYGetLast(code))
+ last = last->Return();
+}
+
CYExpression *CYAdd::Replace(CYContext &context) {
CYInfix::Replace(context);
return this;
}
+CYStatement *CYBlock::Return() {
+ CYImplicitReturn(code_);
+ return this;
+}
+
CYStatement *CYBlock::Replace(CYContext &context) {
context.ReplaceAll(code_);
if (code_ == NULL)
return typed_->Replace(context);
}
+CYStatement *CYExpress::Return() {
+ return $ CYReturn(expression_);
+}
+
CYStatement *CYExpress::Replace(CYContext &context) {
context.Replace(expression_);
return this;
Inject(context);
CYThisScope *_this(context.this_);
- context.this_ = CYGetLast(&this_);
+ context.this_ = &this_;
+ context.this_ = CYGetLast(context.this_);
CYNonLocal *nonlocal(context.nonlocal_);
CYNonLocal *nextlocal(context.nextlocal_);
parameters_->Replace(context, code_);
context.ReplaceAll(code_);
+ if (implicit_)
+ CYImplicitReturn(code_);
+
if (CYIdentifier *identifier = this_.identifier_)
code_ = $$->*
$ CYVar($L1($ CYDeclaration(identifier, $ CYThis())))->*
return replace_;
}
+CYStatement *CYIf::Return() {
+ CYImplicitReturn(true_);
+ CYImplicitReturn(false_);
+ return this;
+}
+
CYStatement *CYIf::Replace(CYContext &context) {
context.Replace(test_);
context.ReplaceAll(true_);
}
CYExpression *CYRubyBlock::Replace(CYContext &context) {
- // XXX: this needs to do something much more epic to handle return
return call_->AddArgument(context, proc_->Replace(context));
}
CYExpression *CYRubyProc::Replace(CYContext &context) {
- return CYNonLocalize(context, $ CYFunctionExpression(NULL, parameters_, code_));
+ CYFunctionExpression *function($ CYFunctionExpression(NULL, parameters_, code_));
+ function = CYNonLocalize(context, function);
+ function->implicit_ = true;
+ return function;
}
CYScope::CYScope(bool transparent, CYContext &context) :
}
}
+CYStatement *CYStatement::Return() {
+ return this;
+}
+
CYString *CYString::Concat(CYContext &context, CYString *rhs) const {
size_t size(size_ + rhs->size_);
char *value($ char[size + 1]);