]> git.saurik.com Git - cycript.git/blobdiff - Parser.hpp
More consistent Trampoline error handling.
[cycript.git] / Parser.hpp
index ebcbb7f8f577b48ca154d52427d1f18fd0e4598d..aad1d478db2ec111ddf7ab8121897a40a8eb519a 100644 (file)
@@ -19,8 +19,8 @@
 **/
 /* }}} */
 
-#ifndef CYPARSER_HPP
-#define CYPARSER_HPP
+#ifndef CYCRIPT_PARSER_HPP
+#define CYCRIPT_PARSER_HPP
 
 #include <iostream>
 
 #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;
-    }
-};
-
-#define CYForEach(value, list) \
-    for (__typeof__(*list) *value(list); value != NULL; value = value->next_)
-
 struct CYThing {
     virtual ~CYThing() {
     }
@@ -374,7 +354,7 @@ struct CYContext {
     void ReplaceAll(Type_ *&values) {
         Type_ **last(&values);
         CYForEach (next, values) {
-            Replace(*last);
+            Replace(*last = next);
             last = &(*last)->next_;
         }
     }
@@ -426,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;
     }
 
@@ -614,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;
     }
 
@@ -1867,4 +1841,4 @@ CYAssignment_("&=", BitwiseAnd)
 CYAssignment_("^=", BitwiseXOr)
 CYAssignment_("|=", BitwiseOr)
 
-#endif/*CYPARSER_HPP*/
+#endif/*CYCRIPT_PARSER_HPP*/