]> git.saurik.com Git - cycript.git/commitdiff
Merge CYStatement::Collapse into CYStatement::Replace.
authorJay Freeman (saurik) <saurik@saurik.com>
Tue, 5 Jun 2012 01:37:16 +0000 (18:37 -0700)
committerJay Freeman (saurik) <saurik@saurik.com>
Tue, 5 Jun 2012 01:42:15 +0000 (18:42 -0700)
Parser.hpp
Replace.cpp

index 27431662558439a707ad06d9de07d152fc38542a..19addb8dc7b0226292e588c6b038b938adc74ee8 100644 (file)
@@ -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;
 };
index 52671c334aae0b69c154f5519211146ced7e1a45..fb8363002c82b4f86a012b84a26f6d534b37c8f8 100644 (file)
@@ -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<CYExpress *>(next_)) {
-        CYCompound *next(dynamic_cast<CYCompound *>(express->expression_));
-        if (next == NULL)
-            next = $ CYCompound(express->expression_);
-        next->AddPrev(expression_);
-        expression_ = next;
+CYStatement *CYExpress::Replace(CYContext &context) {
+    while (CYExpress *express = dynamic_cast<CYExpress *>(next_)) {
+        CYCompound *compound(dynamic_cast<CYCompound *>(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]);