From 720a57a8df6f5f151bb263ef4e81e7834c5a9d96 Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Mon, 4 Jun 2012 18:37:16 -0700 Subject: [PATCH] Merge CYStatement::Collapse into CYStatement::Replace. --- Parser.hpp | 3 --- Replace.cpp | 27 ++++++++------------------- 2 files changed, 8 insertions(+), 22 deletions(-) diff --git a/Parser.hpp b/Parser.hpp index 2743166..19addb8 100644 --- a/Parser.hpp +++ b/Parser.hpp @@ -154,7 +154,6 @@ struct CYStatement : void Single(CYOutput &out, CYFlags flags) const; void Multiple(CYOutput &out, CYFlags flags = CYNoFlags) const; - virtual CYStatement *Collapse(CYContext &context); virtual CYStatement *Replace(CYContext &context) = 0; private: @@ -1545,7 +1544,6 @@ struct CYExpress : throw; } - virtual CYStatement *Collapse(CYContext &context); virtual CYStatement *Replace(CYContext &context); virtual void Output(CYOutput &out, CYFlags flags) const; }; @@ -1595,7 +1593,6 @@ struct CYReturn : struct CYEmpty : CYStatement { - virtual CYStatement *Collapse(CYContext &context); virtual CYStatement *Replace(CYContext &context); virtual void Output(CYOutput &out, CYFlags flags) const; }; diff --git a/Replace.cpp b/Replace.cpp index 52671c3..fb83630 100644 --- a/Replace.cpp +++ b/Replace.cpp @@ -237,31 +237,24 @@ void CYElement::Replace(CYContext &context) { $T() next_->Replace(context); } -CYStatement *CYEmpty::Collapse(CYContext &context) { - return next_; -} - CYStatement *CYEmpty::Replace(CYContext &context) { return NULL; } -CYStatement *CYExpress::Collapse(CYContext &context) { - if (CYExpress *express = dynamic_cast(next_)) { - CYCompound *next(dynamic_cast(express->expression_)); - if (next == NULL) - next = $ CYCompound(express->expression_); - next->AddPrev(expression_); - expression_ = next; +CYStatement *CYExpress::Replace(CYContext &context) { + while (CYExpress *express = dynamic_cast(next_)) { + CYCompound *compound(dynamic_cast(express->expression_)); + if (compound == NULL) + compound = $ CYCompound(express->expression_); + compound->AddPrev(expression_); + expression_ = compound; SetNext(express->next_); } - return this; -} - -CYStatement *CYExpress::Replace(CYContext &context) { context.Replace(expression_); if (expression_ == NULL) return $ CYEmpty(); + return this; } @@ -736,10 +729,6 @@ void CYScope::Scope(CYContext &context, CYStatement *&statements) { } } -CYStatement *CYStatement::Collapse(CYContext &context) { - return this; -} - CYString *CYString::Concat(CYContext &context, CYString *rhs) const { size_t size(size_ + rhs->size_); char *value($ char[size + 1]); -- 2.47.2