From cde20a5add55cd85f55405acf6d60c2eafc2b575 Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Mon, 12 Jul 2010 01:32:02 +0000 Subject: [PATCH] Merge CYStatement::ReplaceAll with the new CYCompound::Replace version of CYExpression::ReplaceAll and use as CYContext::ReplaceAll. --- Parser.hpp | 11 +++++++++-- Replace.cpp | 17 ++++------------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/Parser.hpp b/Parser.hpp index 54ad617..5d86018 100644 --- a/Parser.hpp +++ b/Parser.hpp @@ -143,9 +143,7 @@ struct CYStatement : 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: @@ -369,6 +367,15 @@ struct CYContext { virtual ~CYContext() { } + template + void ReplaceAll(Type_ *&values) { + Type_ **last(&values); + for (Type_ *next(values); next != NULL; next = next->next_) { + Replace(*last); + last = &(*last)->next_; + } + } + template void Replace(Type_ *&value) { for (;;) if (value == NULL) diff --git a/Replace.cpp b/Replace.cpp index 3538944..b804ce3 100644 --- a/Replace.cpp +++ b/Replace.cpp @@ -86,7 +86,7 @@ CYExpression *CYAssignment::Replace(CYContext &context) { } CYStatement *CYBlock::Replace(CYContext &context) { - statements_ = statements_->ReplaceAll(context); + context.ReplaceAll(statements_); if (statements_ == NULL) return $ CYEmpty(); return this; @@ -127,7 +127,7 @@ void Catch::Replace(CYContext &context) { $T() void CYClause::Replace(CYContext &context) { $T() context.Replace(case_); - statements_ = statements_->ReplaceAll(context); + context.ReplaceAll(statements_); next_->Replace(context); } @@ -136,9 +136,7 @@ CYStatement *CYComment::Replace(CYContext &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; } @@ -545,7 +543,7 @@ void CYProgram::Replace(CYContext &context) { CYScope scope(CYScopeProgram, context, statements_); context.nextlocal_ = $ CYNonLocal(); - statements_ = statements_->ReplaceAll(context); + context.ReplaceAll(statements_); context.NonLocal(statements_); scope.Close(); @@ -748,13 +746,6 @@ CYStatement *CYStatement::Collapse(CYContext &context) { 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]); -- 2.45.2