28 #include "globals.hpp"
29 #include "timezone/interval.hpp"
30 #include "cow_ptr.hpp"
74 extern const char* et_to_string[];
77 E(Etype et,
const loc_t& l) : etype(et), loc(l) {
80 virtual E* clone()
const {
return new E(*
this); }
81 virtual bool operator==(
const E& o)
const {
return etype == o.etype; }
87 E(
const E& e) : etype(e.etype), loc(e.loc) { }
93 virtual Et* clone()
const {
return new Et(*
this); }
96 Et(
const Et& e) :
E(t, e.loc) { }
107 SElt(
const string& s,
const loc_t& l) :
E(t, l), data(s) { }
109 virtual SElt* clone()
const {
return new SElt(*
this); }
110 virtual bool operator==(
const SElt& s)
const {
111 return data == s.data;
114 SElt(
const SElt& e) :
E(t, e.loc), data(e.data) { }
122 Symbol(
const string& s,
const loc_t& l,
bool ref_p=
false) :
123 E(etsymbol, l), data(s), ref(ref_p) { }
128 virtual Symbol* clone()
const {
return new Symbol(*
this); }
129 virtual bool operator==(
const Symbol& s)
const {
return data == s.data; }
132 Symbol(
const Symbol& e) :
E(etsymbol, e.loc), data(e.data), ref(e.ref) { }
137 ElNode(
E* e_p) : e(e_p), next(
nullptr) { }
146 El() :
E(etexprlist, yy::missing_loc()), n(0), begin(
nullptr), end(
nullptr) { }
147 El(
E* e) :
E(etexprlist, e->loc) {
148 begin = end =
new ElNode(e);
179 eln->next = here->next;
199 node->next =
nullptr;
205 virtual El* clone()
const {
return new El(*
this); }
206 virtual bool operator==(
const El& el)
const {
214 for (
unsigned i=0; i<n; ++i) {
215 if (!(*iter->e == *iters->e)) {
231 for (
unsigned i=0; i<n; ++i) {
239 El(
const El& el) :
E(etexprlist, el.loc) {
242 begin =
new ElNode(el.begin->e->clone());
243 ElNode* iterclone = begin;
246 iterclone->next =
new ElNode(iter->next->e->clone());
247 iterclone = iterclone->next;
262 E(t, yy::span_loc(e_p->loc, el_p->loc)), e(e_p), el(el_p) { }
263 EEl(
E* e_p) :
E(t, e_p->loc), e(e_p), el(
nullptr) { }
264 virtual EEl* clone()
const {
return new EEl(*
this); }
265 virtual bool operator==(
const EEl<t>& eel)
const {
266 return *e == *eel.e ? *el == *eel.el :
false;
271 ~
EEl() {
delete e;
delete el; }
274 EEl(
const EEl& ee) :
E(t, ee.loc), e(ee.e->clone()), el(ee.el->clone()) { }
280 Binop(
unsigned op_p,
E* l,
E* r,
loc_t loc_p,
E* a=
nullptr) :
281 E(etbinop, loc_p), op(op_p), left(l), right(r), attrib(a ? a :
new Null(yy::missing_loc())) { }
282 virtual Binop* clone()
const {
return new Binop(*
this); }
283 virtual bool operator==(
const Binop& b)
const {
287 *attrib == *b.attrib : false : false :
false;
294 ~
Binop() {
delete left;
delete right;
delete attrib; }
300 left(b.left->clone()),
301 right(b.right->clone()),
302 attrib(b.attrib->clone()) { }
306 Unop(
unsigned op_p,
E* e_p,
loc_t l) :
E(etunop, l), op(op_p), e(e_p) { }
307 virtual Unop* clone()
const {
return new Unop(*
this); }
308 virtual bool operator==(
const Unop& u)
const {
309 return op == u.op ? (*e == *u.e) :
false;
314 ~
Unop() {
delete e; }
317 Unop(
const Unop& u) :
E(etunop, u.loc), op(u.op), e(u.e->clone()) { }
323 E1(
E* e_p,
loc_t l) :
E(t, l), e(e_p) { }
324 virtual E* clone()
const {
return new E1(*
this); }
325 virtual bool operator==(
const E1<t>& ee)
const {
330 ~
E1() {
if (e)
delete e; }
333 E1(
const E1& e) :
E(t, e.loc), e(e.e->clone()) { }
342 E2(
E* e1_p,
E* e2_p,
loc_t l) :
E(t, l), e1(e1_p), e2(e2_p) { }
343 virtual E2* clone()
const {
return new E2(*
this); }
344 virtual bool operator==(
const E2<t>& e)
const {
345 return *e1 == *e.e1 ? (*e2 == *e.e2) :
false;
350 ~
E2() {
delete e1;
delete e2; }
353 E2(
const E2& e) :
E(t, e.loc), e1(e.e1->clone()), e2(e.e2->clone()) { }
363 E3(
E* e1_p,
E* e2_p,
E* e3_p,
loc_t l) :
E(t, l), e1(e1_p), e2(e2_p), e3(e3_p) { }
364 virtual E3* clone()
const {
return new E3(*
this); }
365 virtual bool operator==(
const E3<t>& e)
const {
366 return *e1 == *e.e1 ?
368 (*e3 == *e.e3) :
false) :
false;
374 ~
E3() {
delete e1;
delete e2;
delete e3; }
377 E3(
const E3& e) :
E(t, e.loc), e1(e.e1->clone()), e2(e.e2->clone()), e3(e.e3->clone()) { }
385 E(etfor, l), forloop(forloop_p) { }
389 virtual For* clone()
const {
return new For(*
this); }
390 virtual bool operator==(
const For& f)
const {
return *forloop == *f.forloop; }
393 ~
For() {
delete forloop; }
396 For(
const For& f) :
E(etfor, f.loc), forloop(f.forloop->clone()) { }
399 template<Etype t,
typename T>
402 typedef T value_type;
408 vector<arr::Vector<arr::zstring>>())) { }
409 virtual EData* clone()
const {
return new EData(*
this); }
410 virtual bool operator==(
const EData& ed)
const {
411 return *data == *ed.data;
416 EData(
const EData& e) :
E(t, e.loc), data(e.data) { }
428 virtual GenArg* clone()
const {
return new GenArg(*
this); }
429 virtual bool operator==(
const GenArg& te)
const {
430 return *symb == *te.symb ? (*e == *te.e) :
false;
435 ~
GenArg() {
delete symb;
delete e; }
439 E(t, te.loc), symb(te.symb->clone()), e(te.e->clone()) { }
450 Function(
E* b,
loc_t l) :
E(etfunction, l), formlist(
nullptr), body(b) { }
454 virtual bool operator==(
const Function& f)
const {
455 return *formlist == *f.formlist ? *body == *f.body :
false;
461 void processFormlist(map<string, int>& argMap,
int& ellipsisPos) {
464 ElNode* eln = formlist->begin;
465 for (
unsigned n=0; n<formlist->n; ++n) {
466 if (eln->e->etype == ettaggedexpr) {
468 auto res = argMap.emplace(te->symb->data,
static_cast<int>(n));
470 throw range_error(
"repeated formal argument '" + te->symb->data +
"'");
473 else if (eln->e->etype == etsymbol) {
474 auto symb =
static_cast<Symbol*
>(eln->e);
475 auto res = argMap.emplace(symb->data,
static_cast<int>(n));
477 throw range_error(
"repeated formal argument '" + symb->data +
"'");
481 if (ellipsisPos != -1) {
482 throw std::range_error(
"repeated formal argument '...'");
485 ellipsisPos =
static_cast<int>(n);
493 ~
Function() {
if (formlist)
delete formlist;
delete body; }
497 E(etfunction, f.loc),
498 formlist(f.formlist ? f.formlist->clone() :
nullptr),
499 body(f.body->clone()) { }
504 string to_string(
const E& e);
506 string to_string_cs(
const El& el);
508 void getBoundVars(
E* e, set<string>& ss);
510 bool isEqual(
const E*,
const E*);