diff options
Diffstat (limited to 'src/ops/express.h')
| -rw-r--r-- | src/ops/express.h | 79 |
1 files changed, 79 insertions, 0 deletions
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 @@ | |||
| 1 | /************************************************************************* | ||
| 2 | * | ||
| 3 | * HTCd - Copyright (C) 1998-2006 Henrik Rydberg | ||
| 4 | * | ||
| 5 | * This program is free software; you can redistribute it and/or modify | ||
| 6 | * it under the terms of the GNU General Public License as published by | ||
| 7 | * the Free Software Foundation; either version 2 of the License, or | ||
| 8 | * (at your option) any later version. | ||
| 9 | * | ||
| 10 | * This program is distributed in the hope that it will be useful, | ||
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 13 | * GNU General Public License for more details. | ||
| 14 | * | ||
| 15 | * You should have received a copy of the GNU General Public License | ||
| 16 | * along with this program; if not, write to the Free Software | ||
| 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 18 | */ | ||
| 19 | |||
| 20 | #ifndef EXPRESSH | ||
| 21 | #define EXPRESSH | ||
| 22 | |||
| 23 | #include <ops/operator.h> | ||
| 24 | #include <mt/split.h> | ||
| 25 | #include <mt/uniheap.h> | ||
| 26 | |||
| 27 | const int OP_LOCAL=1; | ||
| 28 | const int OP_GLOBAL=2; | ||
| 29 | const int OP_NINIT=4; | ||
| 30 | const int OP_ALL=OP_LOCAL|OP_GLOBAL|OP_NINIT; | ||
| 31 | |||
| 32 | class expr_t { | ||
| 33 | public: | ||
| 34 | sref expr; | ||
| 35 | const op_t* op; | ||
| 36 | int status; | ||
| 37 | mstring result; | ||
| 38 | expr_t *left,*right; | ||
| 39 | |||
| 40 | expr_t(): | ||
| 41 | expr(),op(0),status(OP_ALL),result(),left(0),right(0) {} | ||
| 42 | expr_t(const expr_t& x): | ||
| 43 | expr(),op(0),status(OP_ALL),result(),left(0),right(0) { copy(x); } | ||
| 44 | expr_t(const sref& s): | ||
| 45 | expr(s),op(0),status(OP_ALL),result(),left(0),right(0) {} | ||
| 46 | expr_t(const sref& s,const op_t* o): | ||
| 47 | expr(s),op(o),status(OP_ALL),result(),left(0),right(0) {} | ||
| 48 | expr_t(const sref& s,const op_t* o,expr_t* p): | ||
| 49 | expr(s),op(o),status(OP_ALL),result(),left(p),right(0) {} | ||
| 50 | ~expr_t() { delete left; delete right; } | ||
| 51 | |||
| 52 | void clear(); | ||
| 53 | expr_t& operator=(const expr_t& x) { clear(); copy(x); return *this; } | ||
| 54 | expr_t& operator=(const sref& in) { clear(); expr=in; return *this; } | ||
| 55 | |||
| 56 | void trav(mstream& out,int n); | ||
| 57 | void expand(op_env& env) throw(merror_t); | ||
| 58 | void eval(mstream& out,op_env& env,int opt) throw(merror_t); | ||
| 59 | |||
| 60 | static void* operator new(size_t n); | ||
| 61 | static void operator delete(void* p); | ||
| 62 | protected: | ||
| 63 | void copy(const expr_t& x); | ||
| 64 | static uniheap<36> tree; | ||
| 65 | }; | ||
| 66 | |||
| 67 | //////////////////////////////////////////////////////////// | ||
| 68 | |||
| 69 | struct op_env { | ||
| 70 | opmap* ops; | ||
| 71 | |||
| 72 | op_env() : ops(0) {} | ||
| 73 | op_env(opmap& map) : ops(&map) {} | ||
| 74 | |||
| 75 | virtual int split(sref& first,sref& rest) throw(merror_t) { return 0; } | ||
| 76 | virtual void term(mstream& out,expr_t* x) throw(merror_t) { x->status=0; } | ||
| 77 | }; | ||
| 78 | |||
| 79 | #endif | ||
