diff options
Diffstat (limited to 'src/libutil')
-rw-r--r-- | src/libutil/Makefile.am | 7 | ||||
-rw-r--r-- | src/libutil/aterm.cc | 89 | ||||
-rw-r--r-- | src/libutil/aterm.hh | 42 | ||||
-rw-r--r-- | src/libutil/test-aterm.cc | 66 |
4 files changed, 0 insertions, 204 deletions
diff --git a/src/libutil/Makefile.am b/src/libutil/Makefile.am index bd19bfa83a15..a7ff1b6e0358 100644 --- a/src/libutil/Makefile.am +++ b/src/libutil/Makefile.am @@ -4,10 +4,3 @@ libutil_a_SOURCES = util.cc util.hh hash.cc hash.hh \ archive.cc archive.hh md5.c md5.h aterm.cc aterm.hh AM_CXXFLAGS = -Wall -I.. ${aterm_include} - -check_PROGRAMS = test-aterm - -test_aterm_SOURCES = test-aterm.cc -test_aterm_LDADD = ./libutil.a ../boost/format/libformat.a \ - ${aterm_lib} - diff --git a/src/libutil/aterm.cc b/src/libutil/aterm.cc index fb734b3a0847..77bf8dab4c12 100644 --- a/src/libutil/aterm.cc +++ b/src/libutil/aterm.cc @@ -16,95 +16,6 @@ ostream & operator << (ostream & stream, ATerm e) } -ATMatcher & atMatch(ATMatcher & pos, ATerm t) -{ - pos.t = t; - pos.pos = ATMatcher::funPos; - return pos; -} - - -static inline bool failed(const ATMatcher & pos) -{ - return pos.pos == ATMatcher::failPos; -} - - -static inline ATMatcher & fail(ATMatcher & pos) -{ - pos.pos = ATMatcher::failPos; - return pos; -} - - -ATMatcher & operator >> (ATMatcher & pos, ATerm & out) -{ - out = 0; - if (failed(pos)) return pos; - if (pos.pos == ATMatcher::funPos || - ATgetType(pos.t) != AT_APPL || - pos.pos >= (int) ATgetArity(ATgetAFun(pos.t))) - return fail(pos); - out = ATgetArgument(pos.t, pos.pos); - pos.pos++; - return pos; -} - - -ATMatcher & operator >> (ATMatcher & pos, string & out) -{ - out = ""; - if (pos.pos == ATMatcher::funPos) { - if (ATgetType(pos.t) != AT_APPL) return fail(pos); - out = ATgetName(ATgetAFun(pos.t)); - pos.pos = 0; - } else { - ATerm t; - pos = pos >> t; - if (failed(pos)) return pos; - if (ATgetType(t) != AT_APPL || - ATgetArity(ATgetAFun(t)) != 0) - return fail(pos); - out = ATgetName(ATgetAFun(t)); - } - return pos; -} - - -ATMatcher & operator >> (ATMatcher & pos, const string & s) -{ - string s2; - pos = pos >> s2; - if (failed(pos)) return pos; - if (s != s2) return fail(pos); - return pos; -} - - -ATMatcher & operator >> (ATMatcher & pos, int & n) -{ - n = 0; - ATerm t; - pos = pos >> t; - if (failed(pos)) return pos; - if (ATgetType(t) != AT_INT) return fail(pos); - n = ATgetInt((ATermInt) t); - return pos; -} - - -ATMatcher & operator >> (ATMatcher & pos, ATermList & out) -{ - out = 0; - ATerm t; - pos = pos >> t; - if (failed(pos)) return pos; - if (ATgetType(t) != AT_LIST) return fail(pos); - out = (ATermList) t; - return pos; -} - - Error badTerm(const format & f, ATerm t) { char * s = ATwriteToString(t); diff --git a/src/libutil/aterm.hh b/src/libutil/aterm.hh index 577b784be202..883d20c63ad1 100644 --- a/src/libutil/aterm.hh +++ b/src/libutil/aterm.hh @@ -36,48 +36,6 @@ public: }; -/* Type-safe matching. */ - -struct ATMatcher -{ - ATerm t; - int pos; - const static int failPos = -2; - const static int funPos = -1; - - ATMatcher() : t(0), pos(failPos) - { - } - - operator bool() const - { - return pos != failPos; - } -}; - -/* Initiate matching of a term. */ -ATMatcher & atMatch(ATMatcher & pos, ATerm t); - -/* Get the next argument of an application. */ -ATMatcher & operator >> (ATMatcher & pos, ATerm & out); - -/* Get the name of the function symbol of an application, or the next - argument of an application as a string. */ -ATMatcher & operator >> (ATMatcher & pos, string & out); - -/* Like the previous, but check that the string is equal to the given - string. */ -ATMatcher & operator >> (ATMatcher & pos, const string & s); - -/* Get the next argument of an application, and verify that it is a - integer. */ -ATMatcher & operator >> (ATMatcher & pos, int & n); - -/* Get the next argument of an application, and verify that it is a - list. */ -ATMatcher & operator >> (ATMatcher & pos, ATermList & out); - - /* Throw an exception with an error message containing the given aterm. */ Error badTerm(const format & f, ATerm t); diff --git a/src/libutil/test-aterm.cc b/src/libutil/test-aterm.cc deleted file mode 100644 index 325639ca4f30..000000000000 --- a/src/libutil/test-aterm.cc +++ /dev/null @@ -1,66 +0,0 @@ -#include "aterm.hh" -#include <iostream> - - -void runTests() -{ - verbosity = lvlDebug; - - ATMatcher pos; - - ATerm t = ATmake("Call(Foo, Bar, \"xyz\")"); - - debug(format("term: %1%") % t); - - string fun, arg3; - ATerm lhs, rhs; - - if (!(atMatch(pos, t) >> "Call" >> lhs >> rhs >> arg3)) - throw Error("should succeed"); - if (arg3 != "xyz") throw Error("bad 1"); - - if (!(atMatch(pos, t) >> fun >> lhs >> rhs >> arg3)) - throw Error("should succeed"); - if (fun != "Call") throw Error("bad 2"); - if (arg3 != "xyz") throw Error("bad 3"); - - if (!(atMatch(pos, t) >> fun >> lhs >> rhs >> "xyz")) - throw Error("should succeed"); - - if (atMatch(pos, t) >> fun >> lhs >> rhs >> "abc") - throw Error("should fail"); - - if (atMatch(pos, t) >> "Call" >> lhs >> rhs >> "abc") - throw Error("should fail"); - - t = ATmake("X([A, B, C], \"abc\")"); - - ATerm t1, t2, t3; - if (atMatch(pos, t) >> "X" >> t1 >> t2 >> t3) - throw Error("should fail"); - if (!(atMatch(pos, t) >> "X" >> t1 >> t2)) - throw Error("should succeed"); - ATermList ts; - if (!(atMatch(pos, t) >> "X" >> ts >> t2)) - throw Error("should succeed"); - if (ATgetLength(ts) != 3) - throw Error("bad"); - if (atMatch(pos, t) >> "X" >> t1 >> ts) - throw Error("should fail"); -} - - -int main(int argc, char * * argv) -{ - ATerm bottomOfStack; - ATinit(argc, argv, &bottomOfStack); - - try { - runTests(); - } catch (Error & e) { - printMsg(lvlError, format("error: %1%") % e.msg()); - return 1; - } - - return 0; -} |