From 5df79c53745fde5d6c3340a2979b1429cd5892c1 Mon Sep 17 00:00:00 2001 From: Henrik Rydberg Date: Sat, 8 Oct 2011 20:30:28 +0200 Subject: Initial import of htcd system 1.0 Signed-off-by: Henrik Rydberg --- src/ops/express.h | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 src/ops/express.h (limited to 'src/ops/express.h') diff --git a/src/ops/express.h b/src/ops/express.h new file mode 100644 index 0000000..79148f6 --- /dev/null +++ b/src/ops/express.h @@ -0,0 +1,79 @@ +/************************************************************************* + * + * HTCd - Copyright (C) 1998-2006 Henrik Rydberg + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef EXPRESSH +#define EXPRESSH + +#include +#include +#include + +const int OP_LOCAL=1; +const int OP_GLOBAL=2; +const int OP_NINIT=4; +const int OP_ALL=OP_LOCAL|OP_GLOBAL|OP_NINIT; + +class expr_t { +public: + sref expr; + const op_t* op; + int status; + mstring result; + expr_t *left,*right; + + expr_t(): + expr(),op(0),status(OP_ALL),result(),left(0),right(0) {} + expr_t(const expr_t& x): + expr(),op(0),status(OP_ALL),result(),left(0),right(0) { copy(x); } + expr_t(const sref& s): + expr(s),op(0),status(OP_ALL),result(),left(0),right(0) {} + expr_t(const sref& s,const op_t* o): + expr(s),op(o),status(OP_ALL),result(),left(0),right(0) {} + expr_t(const sref& s,const op_t* o,expr_t* p): + expr(s),op(o),status(OP_ALL),result(),left(p),right(0) {} + ~expr_t() { delete left; delete right; } + + void clear(); + expr_t& operator=(const expr_t& x) { clear(); copy(x); return *this; } + expr_t& operator=(const sref& in) { clear(); expr=in; return *this; } + + void trav(mstream& out,int n); + void expand(op_env& env) throw(merror_t); + void eval(mstream& out,op_env& env,int opt) throw(merror_t); + + static void* operator new(size_t n); + static void operator delete(void* p); +protected: + void copy(const expr_t& x); + static uniheap<36> tree; +}; + +//////////////////////////////////////////////////////////// + +struct op_env { + opmap* ops; + + op_env() : ops(0) {} + op_env(opmap& map) : ops(&map) {} + + virtual int split(sref& first,sref& rest) throw(merror_t) { return 0; } + virtual void term(mstream& out,expr_t* x) throw(merror_t) { x->status=0; } +}; + +#endif -- cgit v1.2.3