From 1a8107c0156e1615fbdbe009f30d8e66cb280c03 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Mon, 27 Dec 2010 20:59:09 +0000 Subject: Less code. git-svn-id: http://svn.drobilla.net/resp/resp@361 ad02d1e2-f140-0410-9f75-f8b11f17cedd --- src/resp.hpp | 56 ++++++++++++++++++-------------------------------------- 1 file changed, 18 insertions(+), 38 deletions(-) (limited to 'src') diff --git a/src/resp.hpp b/src/resp.hpp index 56c24a6..f6e65ea 100644 --- a/src/resp.hpp +++ b/src/resp.hpp @@ -155,35 +155,19 @@ 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); } - bool operator==(const AST& o) const; - bool operator!=(const AST& o) const; + inline bool operator==(const AST& o) const; + inline bool operator!=(const AST& rhs) const { return !(operator==(rhs)); } string str() const { ostringstream ss; ss << this; return ss.str(); } - const ATuple* as_tuple() const { - assert(tag() == T_TUPLE); - return (ATuple*)this; - } - - const ATuple* to_tuple() const { - if (tag() == T_TUPLE) - return (const ATuple*)this; - return NULL; - } - template - T* as_a(Tag t) const { - assert(tag() == t); - return (T*)this; - } + T* as_a(Tag t) const { assert(tag() == t); return (T*)this; } template - T* to_a(Tag t) const { - if (tag() == t) - return (T*)this; - return NULL; - } + T* to_a(Tag t) const { return (tag() == t) ? (T*)this : NULL; } + const ATuple* as_tuple() const { return as_a(T_TUPLE); } + const ATuple* to_tuple() const { return to_a(T_TUPLE); } const ASymbol* as_symbol() const { return as_a(T_SYMBOL); } const ASymbol* to_symbol() const { return to_a(T_SYMBOL); } @@ -220,18 +204,6 @@ struct ATuple : public AST { ATuple(const AST* fst, const ATuple* rst, Cursor c=Cursor()) : AST(T_TUPLE, c), _fst(fst), _rst(rst) {} - ATuple(Cursor c, AST* ast, va_list args) - : AST(T_TUPLE, c), _fst(ast), _rst(0) { - if (!ast) return; - - ATuple* tail = this; - for (AST* a = va_arg(args, AST*); a; a = va_arg(args, AST*)) { - ATuple* tup = new ATuple(a, NULL); - tail->last(tup); - tail = tup; - } - } - const AST* head() const { return _fst; } const AST* last() const { return _rst; } bool empty() const { return _fst == 0 && _rst ==0; } @@ -308,11 +280,21 @@ private: }; inline ATuple* tup(Cursor c, AST* ast, ...) { + ATuple* const head = new ATuple(ast, 0, c); + if (!ast) + return head; + + ATuple* tail = head; va_list args; va_start(args, ast); - ATuple* ret = new ATuple(c, ast, args); + for (AST* a = va_arg(args, AST*); a; a = va_arg(args, AST*)) { + ATuple* const tup = new ATuple(a, NULL); + tail->last(tup); + tail = tup; + } va_end(args); - return ret; + + return head; } static bool @@ -434,8 +416,6 @@ AST::operator==(const AST& rhs) const return false; } -inline bool AST::operator!=(const AST& rhs) const { return !(operator==(rhs)); } - /*************************************************************************** * Lexical Environmment * -- cgit v1.2.1