aboutsummaryrefslogtreecommitdiffstats
path: root/src/resp.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/resp.hpp')
-rw-r--r--src/resp.hpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/resp.hpp b/src/resp.hpp
index a5bf99d..2ae556c 100644
--- a/src/resp.hpp
+++ b/src/resp.hpp
@@ -26,6 +26,7 @@
#include <stdint.h>
#include <string.h>
+#include <cassert>
#include <iostream>
#include <list>
#include <map>
@@ -270,6 +271,8 @@ struct ATuple : public AST {
const AST* list_ref(unsigned index) const { return *iter_at(index); }
+ const ATuple* replace(const AST* from, const AST* to) const;
+
const ATuple* prot() const { return list_ref(1)->as_tuple(); }
private:
@@ -375,6 +378,22 @@ struct List {
ATuple* tail;
};
+inline const ATuple*
+ATuple::replace(const AST* from, const AST* to) const
+{
+ List copy;
+ FOREACHP(const_iterator, i, this) {
+ if (*i == from) {
+ copy.push_back(to);
+ } else {
+ const ATuple* tup = (*i)->to_tuple();
+ copy.push_back(tup ? tup->replace(from, to) : (*i));
+ }
+ }
+ copy.head->loc = loc;
+ return copy;
+}
+
template<typename T>
inline bool
literal_equals(const ALiteral<T>* lhs, const ALiteral<T>* rhs)