]> git.saurik.com Git - cycript.git/blobdiff - Parser.hpp
Move CYNext, CYSetLast, and CYForEach to List.hpp.
[cycript.git] / Parser.hpp
index 54ad617abbfcae0fb63e4703958bf8f66af36ed7..d8539399fb9c13a016ce5cb7c63284a7390741f5 100644 (file)
 #include <cstdlib>
 
 #include "location.hh"
+
+#include "List.hpp"
 #include "Pooling.hpp"
 #include "Options.hpp"
 
 class CYContext;
 
-template <typename Type_>
-struct CYNext {
-    Type_ *next_;
-
-    CYNext() :
-        next_(NULL)
-    {
-    }
-
-    CYNext(Type_ *next) :
-        next_(next)
-    {
-    }
-
-    void SetNext(Type_ *next) {
-        next_ = next;
-    }
-};
-
 struct CYThing {
     virtual ~CYThing() {
     }
@@ -143,9 +126,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 +350,15 @@ struct CYContext {
     virtual ~CYContext() {
     }
 
+    template <typename Type_>
+    void ReplaceAll(Type_ *&values) {
+        Type_ **last(&values);
+        CYForEach (next, values) {
+            Replace(*last);
+            last = &(*last)->next_;
+        }
+    }
+
     template <typename Type_>
     void Replace(Type_ *&value) {
         for (;;) if (value == NULL)
@@ -416,10 +406,7 @@ struct CYBlock :
     }
 
     void AddPrev(CYStatement *statement) {
-        CYStatement *last(statement);
-        while (last->next_ != NULL)
-            last = last->next_;
-        last->SetNext(statements_);
+        CYSetLast(statement, statements_);
         statements_ = statement;
     }
 
@@ -604,10 +591,7 @@ struct CYCompound :
     }
 
     void AddPrev(CYExpression *expression) {
-        CYExpression *last(expression);
-        while (last->next_ != NULL)
-            last = last->next_;
-        last->SetNext(expressions_);
+        CYSetLast(expression, expressions_);
         expressions_ = expression;
     }