Changeset 3901
 Timestamp:
 Sep 10, 2008, 9:01:07 PM (12 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

toimperative/trunk/opents/samples/trefal.hh
r3773 r3901 67 67 GExpr (TExpr& _e); 68 68 69 GExpr (Term & t) { 70 size = 1; 71 terms = new Term[size]; 72 *terms = t; 73 } 74 69 75 void init_str (const char* str, size_t len) { 70 76 size = len; … … 78 84 } 79 85 86 GExpr & operator+ (const Term& t) { 87 int old_size = size; 88 Term* old_terms = terms; 89 90 size += 1; 91 terms = new Term[size]; 92 93 for (int i = 0; i < old_size; i++) 94 *(terms++) = *(old_terms++); 95 *terms = t; 96 97 delete old_terms; 98 return this; 99 } 100 101 GExpr & operator+ (const GExpr& x) { 102 int old_size = size; 103 Term* old_terms = terms; 104 105 size += x.size; 106 terms = new Term[size]; 107 108 for (int i = 0; i < old_size; i++) 109 *(terms++) = *(old_terms++); 110 Term* new_terms = x.terms; 111 for (int i = 0; i < x.size; i++) 112 *(terms++) = *(new_terms++); 113 114 delete old_terms; 115 return this; 116 } 117 118 GExpr & operator() () { 119 Term t; 120 t.init_const(global_exprs.add_global_expr(this)); 121 return new GExpr(t); 122 } 123 80 124 void clear() { 81 125 delete[] terms; … … 83 127 }; 84 128 85 extern GExpr global_exprs[]; 86 extern int free_idx; 129 extern GlobalExprs global_exprs; 130 131 class GlobalExprs { 132 int size; 133 int free_idx; 134 135 public: 136 GExpr exprs[]; 137 138 GlobalExprs () : size (8), free_idx(0), exprs(new GExpr[8]) {} 139 140 ~GlobalExprs () { 141 delete exprs; 142 } 143 144 int add_global_expr (const GExpr & expr) { 145 if (free_idx == size) { 146 GExpr* old_exprs = exprs; 147 exprs = new GExpr[2*size]; 148 memcpy(exprs, old_exprs, size*sizeof(GExpr)); 149 delete old_exprs; 150 size *= 2; 151 } 152 exprs[free_idx] = expr; 153 return free_idx++; 154 } 155 }; 87 156 88 157 class Expr : private ts::TExtData … … 161 230 162 231 void init_const (int idx) { 163 terms = global_exprs [idx].terms;164 extDataSize() = global_exprs [idx].size * sizeof(Term);232 terms = global_exprs.exprs[idx].terms; 233 extDataSize() = global_exprs.exprs[idx].size * sizeof(Term); 165 234 is_const = true; 166 235 } … … 221 290 case Term::INT: os << t.data; break; 222 291 case Term::EXPR: os << GExpr(t.e); break; 223 case Term::CONST: os << global_exprs [t.data]; break;292 case Term::CONST: os << global_exprs.exprs[t.data]; break; 224 293 } 225 294 return os; … … 253 322 t.init_int(i); 254 323 } else if (c == '(') { 255 int idx = free_idx++;256 is >> g lobal_exprs[idx];257 t.init_const( idx);324 GExpr ge; 325 is >> ge; 326 t.init_const(global_exprs.add_global_expr(ge)); 258 327 } else { 259 328 throw 0; //FIXME … … 290 359 if (_t2.type == Term::EXPR) 291 360 return _t1.e == _t2.e; 292 return GExpr(_t1.e) == global_exprs [_t2.data];361 return GExpr(_t1.e) == global_exprs.exprs[_t2.data]; 293 362 } 294 363 if (_t2.type == Term::EXPR) 295 return global_exprs [_t1.data] == _t2.e;296 return global_exprs[_t1.data] == global_exprs[_t2.data];364 return global_exprs.exprs[_t1.data] == _t2.e; 365 return _t1.data == _t2.data  global_exprs.exprs[_t1.data] == global_exprs.exprs[_t2.data]; 297 366 } 298 367
Note: See TracChangeset
for help on using the changeset viewer.