summaryrefslogtreecommitdiff
path: root/src/ops/express.h
blob: 79148f648846f87adaba0a4ecf04db4c211ce79f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
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 <ops/operator.h>
#include <mt/split.h>
#include <mt/uniheap.h>

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