From 6b063941f02808b5e510f8a9c102b3d361de78f3 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 4 Dec 2010 22:17:01 +0000 Subject: Eliminate tuple/list mutation. Fix AST::str(). git-svn-id: http://svn.drobilla.net/resp/resp@293 ad02d1e2-f140-0410-9f75-f8b11f17cedd --- src/resp.hpp | 50 ++++---------------------------------------------- 1 file changed, 4 insertions(+), 46 deletions(-) (limited to 'src/resp.hpp') diff --git a/src/resp.hpp b/src/resp.hpp index 12d2ca0..0112a9e 100644 --- a/src/resp.hpp +++ b/src/resp.hpp @@ -204,6 +204,9 @@ struct ASymbol; struct AType; struct ALexeme; +class AST; +extern ostream& operator<<(ostream& out, const AST* ast); + /// Base class for all AST nodes struct AST : public Object { AST(Tag t, Cursor c=Cursor()) : loc(c) { this->tag(t); } @@ -263,8 +266,6 @@ struct AST : public Object { Cursor loc; }; -extern ostream& operator<<(ostream& out, const AST* ast); - template static T* tup(Cursor c, AST* ast, ...) { @@ -359,42 +360,12 @@ struct ATuple : public AST { void last(AST* ast) { _vec[_len - 1] = ast; } - struct iterator { - iterator(ATuple* n) : node(n) { - assert(!n || n->tup_len() == 0 || n->tup_len() == 2); - if (!n || n->tup_len() == 0) - node = NULL; - } - inline void increment() { - if (node->last()) - node = node->last()->as_tuple(); - else - node = NULL; - } - inline iterator& operator++() { - assert(node); - increment(); - return *this; - } - inline iterator operator++(int) { - assert(node); - const iterator ret(node); - increment(); - return ret; - } - inline bool operator==(const iterator& i) const { return node == i.node; } - inline bool operator!=(const iterator& i) const { return node != i.node; } - AST*& operator*() { return node->head(); } - ATuple* node; - }; - struct const_iterator { const_iterator(const ATuple* n) : node(n) { assert(!n || n->tup_len() == 0 || n->tup_len() == 2); if (!n || n->tup_len() == 0) node = NULL; } - const_iterator(const iterator& i) : node(i.node) {} inline void increment() { if (node->last()) node = node->last()->as_tuple(); @@ -423,9 +394,7 @@ struct ATuple : public AST { }; const_iterator begin() const { assert(_len == 0 || _len == 2); return const_iterator(this); } - iterator begin() { assert(_len == 0 || _len == 2); return iterator(this); } const_iterator end() const { return const_iterator(NULL); } - iterator end() { return iterator(NULL); } const_iterator iter_at(unsigned index) const { const_iterator i = begin(); @@ -435,20 +404,9 @@ struct ATuple : public AST { return i; } - iterator iter_at(unsigned index) { - iterator i = begin(); - for (unsigned idx = 0; idx != index; ++i, ++idx) { - assert(i != end()); - } - return i; - } - - AST*& list_ref(unsigned index) { return *iter_at(index); } const AST* list_ref(unsigned index) const { return *iter_at(index); } - const ATuple* prot() const { return list_ref(1)->as_tuple(); } - ATuple* prot() { return list_ref(1)->as_tuple(); } - void set_prot(ATuple* prot) { *iter_at(1) = prot; } + const ATuple* prot() const { return list_ref(1)->as_tuple(); } private: friend class GC; -- cgit v1.2.1