aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2010-12-27 20:59:09 +0000
committerDavid Robillard <d@drobilla.net>2010-12-27 20:59:09 +0000
commit1a8107c0156e1615fbdbe009f30d8e66cb280c03 (patch)
tree2113fe470bf24b2dedbb1480d462e24e1b657fc5 /src
parent248a2c44e8f8e599d64640cff584a2ef5265b9d9 (diff)
downloadresp-1a8107c0156e1615fbdbe009f30d8e66cb280c03.tar.gz
resp-1a8107c0156e1615fbdbe009f30d8e66cb280c03.tar.bz2
resp-1a8107c0156e1615fbdbe009f30d8e66cb280c03.zip
Less code.
git-svn-id: http://svn.drobilla.net/resp/resp@361 ad02d1e2-f140-0410-9f75-f8b11f17cedd
Diffstat (limited to 'src')
-rw-r--r--src/resp.hpp56
1 files changed, 18 insertions, 38 deletions
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<typename T>
- 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<typename T>
- 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<const ATuple>(T_TUPLE); }
+ const ATuple* to_tuple() const { return to_a<const ATuple>(T_TUPLE); }
const ASymbol* as_symbol() const { return as_a<const ASymbol>(T_SYMBOL); }
const ASymbol* to_symbol() const { return to_a<const ASymbol>(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 *