void Single(CYOutput &out, CYFlags flags) const;
void Multiple(CYOutput &out, CYFlags flags = CYNoFlags) const;
- CYStatement *ReplaceAll(CYContext &context);
virtual CYStatement *Collapse(CYContext &context);
-
virtual CYStatement *Replace(CYContext &context) = 0;
private:
virtual ~CYContext() {
}
+ template <typename Type_>
+ void ReplaceAll(Type_ *&values) {
+ Type_ **last(&values);
+ for (Type_ *next(values); next != NULL; next = next->next_) {
+ Replace(*last);
+ last = &(*last)->next_;
+ }
+ }
+
template <typename Type_>
void Replace(Type_ *&value) {
for (;;) if (value == NULL)
}
CYStatement *CYBlock::Replace(CYContext &context) {
- statements_ = statements_->ReplaceAll(context);
+ context.ReplaceAll(statements_);
if (statements_ == NULL)
return $ CYEmpty();
return this;
void CYClause::Replace(CYContext &context) { $T()
context.Replace(case_);
- statements_ = statements_->ReplaceAll(context);
+ context.ReplaceAll(statements_);
next_->Replace(context);
}
}
CYExpression *CYCompound::Replace(CYContext &context) {
- CYExpression **last(&expressions_);
- for (CYExpression *next(expressions_); next != NULL; next = next->next_)
- last = &(*last = next->Replace(context))->next_;
+ context.ReplaceAll(expressions_);
return this;
}
CYScope scope(CYScopeProgram, context, statements_);
context.nextlocal_ = $ CYNonLocal();
- statements_ = statements_->ReplaceAll(context);
+ context.ReplaceAll(statements_);
context.NonLocal(statements_);
scope.Close();
return this;
}
-CYStatement *CYStatement::ReplaceAll(CYContext &context) { $T(NULL)
- CYStatement *replace(this);
- context.Replace(replace);
- replace->SetNext(next_->ReplaceAll(context));
- return replace->Collapse(context);
-}
-
CYString *CYString::Concat(CYContext &context, CYString *rhs) const {
size_t size(size_ + rhs->size_);
char *value($ char[size + 1]);