aboutsummaryrefslogtreecommitdiffstats
path: root/src/resp.hpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2010-12-04 22:17:01 +0000
committerDavid Robillard <d@drobilla.net>2010-12-04 22:17:01 +0000
commit6b063941f02808b5e510f8a9c102b3d361de78f3 (patch)
treea8c54efb023830dea046afd7902070c4647d374e /src/resp.hpp
parentd68d9bcf0f2ac65f5f9a3ab92216a11dafa8f2ea (diff)
downloadresp-6b063941f02808b5e510f8a9c102b3d361de78f3.tar.gz
resp-6b063941f02808b5e510f8a9c102b3d361de78f3.tar.bz2
resp-6b063941f02808b5e510f8a9c102b3d361de78f3.zip
Eliminate tuple/list mutation.
Fix AST::str(). git-svn-id: http://svn.drobilla.net/resp/resp@293 ad02d1e2-f140-0410-9f75-f8b11f17cedd
Diffstat (limited to 'src/resp.hpp')
-rw-r--r--src/resp.hpp50
1 files changed, 4 insertions, 46 deletions
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<typename T>
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;