Skip to content

Commit 855f35d

Browse files
committed
Restructure of ast/parser [not working]
1 parent bb7120f commit 855f35d

10 files changed

Lines changed: 300 additions & 1106 deletions

File tree

ast/expr.cpp

Lines changed: 147 additions & 374 deletions
Large diffs are not rendered by default.

ast/expr.hpp

Lines changed: 51 additions & 159 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,10 @@ struct UnaryOp;
4242
struct BinOp;
4343
struct Call;
4444
struct Interval;
45-
struct InterUnaryOp;
46-
struct InterBinOp;
4745
struct MultiDimInter;
48-
struct MDInterUnaryOp;
49-
struct MDInterBinOp;
5046
struct Set;
51-
struct SetUnaryOp;
52-
struct SetBinOp;
5347
struct LinearExp;
54-
struct LExpBinOp;
5548
struct MDLExp;
56-
struct MDLExpBinOp;
5749
struct LinearMap;
5850
struct PWLMap;
5951
struct SBG;
@@ -67,18 +59,10 @@ typedef boost::variant<Natural, VariableName,
6759
boost::recursive_wrapper<BinOp>,
6860
boost::recursive_wrapper<Call>,
6961
boost::recursive_wrapper<Interval>,
70-
boost::recursive_wrapper<InterUnaryOp>,
71-
boost::recursive_wrapper<InterBinOp>,
7262
boost::recursive_wrapper<MultiDimInter>,
73-
boost::recursive_wrapper<MDInterUnaryOp>,
74-
boost::recursive_wrapper<MDInterBinOp>,
7563
boost::recursive_wrapper<Set>,
76-
boost::recursive_wrapper<SetUnaryOp>,
77-
boost::recursive_wrapper<SetBinOp>,
7864
boost::recursive_wrapper<LinearExp>,
79-
boost::recursive_wrapper<LExpBinOp>,
8065
boost::recursive_wrapper<MDLExp>,
81-
boost::recursive_wrapper<MDLExpBinOp>,
8266
boost::recursive_wrapper<LinearMap>,
8367
boost::recursive_wrapper<PWLMap>,
8468
boost::recursive_wrapper<SBG>,
@@ -89,6 +73,10 @@ std::ostream &operator<<(std::ostream &out, const ExprList &el);
8973
template <typename T>
9074
inline bool is(Expr e) { return e.type() == typeid(T); }
9175

76+
////////////////////////////////////////////////////////////////////////////////
77+
// Arithmetic expressions ------------------------------------------------------
78+
////////////////////////////////////////////////////////////////////////////////
79+
9280
struct Rational {
9381
member_class(Expr, num);
9482
member_class(Expr, den);
@@ -100,54 +88,9 @@ struct Rational {
10088
};
10189
std::ostream &operator<<(std::ostream &out, const Rational &op);
10290

103-
enum class UnOp { neg };
104-
std::ostream &operator<<(std::ostream &out, const UnOp &op);
105-
106-
struct UnaryOp {
107-
member_class(UnOp, op);
108-
member_class(Expr, expr);
109-
110-
UnaryOp();
111-
UnaryOp(UnOp op, Expr expr);
112-
113-
bool operator==(const UnaryOp &uop) const;
114-
};
115-
std::ostream &operator<<(std::ostream &out, const UnaryOp &uop);
116-
117-
enum class Op { add, sub, mult, div, expo };
118-
std::ostream &operator<<(std::ostream &out, const Op &op);
119-
120-
struct BinOp {
121-
member_class(Expr, left);
122-
member_class(Op, op);
123-
member_class(Expr, right);
124-
125-
BinOp();
126-
BinOp(Expr left, Op op, Expr right);
127-
128-
bool operator==(const BinOp &bop) const;
129-
};
130-
std::ostream &operator<<(std::ostream &out, const BinOp &bop);
131-
132-
struct Call {
133-
member_class(Name, name);
134-
member_class(ExprList, args);
135-
136-
Call();
137-
Call(Name name, Expr args);
138-
Call(Name name, ExprList args);
139-
140-
bool operator==(const Call &c) const;
141-
};
142-
std::ostream &operator<<(std::ostream &out, const Call &c);
143-
91+
////////////////////////////////////////////////////////////////////////////////
14492
// SBG structures --------------------------------------------------------------
145-
146-
enum class ContainerUOp { card, comp };
147-
std::ostream &operator<<(std::ostream &out, const ContainerUOp &op);
148-
149-
enum class ContainerOp { eq, less, cap, diff, cup };
150-
std::ostream &operator<<(std::ostream &out, const ContainerOp &op);
93+
////////////////////////////////////////////////////////////////////////////////
15194

15295
// Intervals -------------------------------------------------------------------
15396

@@ -163,29 +106,6 @@ struct Interval {
163106
};
164107
std::ostream &operator<<(std::ostream &out, const Interval &i);
165108

166-
struct InterUnaryOp {
167-
member_class(ContainerUOp, op);
168-
member_class(Expr, e);
169-
170-
InterUnaryOp();
171-
InterUnaryOp(ContainerUOp op, Expr e);
172-
173-
bool operator==(const InterUnaryOp &iuop) const;
174-
};
175-
std::ostream &operator<<(std::ostream &out, const InterUnaryOp &i);
176-
177-
struct InterBinOp {
178-
member_class(Expr, left);
179-
member_class(ContainerOp, op);
180-
member_class(Expr, right);
181-
182-
InterBinOp();
183-
InterBinOp(Expr left, ContainerOp op, Expr right);
184-
185-
bool operator==(const InterBinOp &ibop) const;
186-
};
187-
std::ostream &operator<<(std::ostream &out, const InterBinOp &i);
188-
189109
// Multi-dimensional intervals -------------------------------------------------
190110

191111
struct MultiDimInter {
@@ -198,29 +118,6 @@ struct MultiDimInter {
198118
};
199119
std::ostream &operator<<(std::ostream &out, const MultiDimInter &mdi);
200120

201-
struct MDInterUnaryOp {
202-
member_class(ContainerUOp, op);
203-
member_class(Expr, e);
204-
205-
MDInterUnaryOp();
206-
MDInterUnaryOp(ContainerUOp op, Expr e);
207-
208-
bool operator==(const MDInterUnaryOp &mdiuop) const;
209-
};
210-
std::ostream &operator<<(std::ostream &out, const MDInterUnaryOp &mdi);
211-
212-
struct MDInterBinOp {
213-
member_class(Expr, left);
214-
member_class(ContainerOp, op);
215-
member_class(Expr, right);
216-
217-
MDInterBinOp();
218-
MDInterBinOp(Expr left, ContainerOp op, Expr right);
219-
220-
bool operator==(const MDInterBinOp &bop) const;
221-
};
222-
std::ostream &operator<<(std::ostream &out, const MDInterBinOp &mdi);
223-
224121
// Sets ------------------------------------------------------------------------
225122

226123
struct Set {
@@ -233,29 +130,6 @@ struct Set {
233130
};
234131
std::ostream &operator<<(std::ostream &out, const Set &s);
235132

236-
struct SetUnaryOp {
237-
member_class(ContainerUOp, op);
238-
member_class(Expr, e);
239-
240-
SetUnaryOp();
241-
SetUnaryOp(ContainerUOp op, Expr e);
242-
243-
bool operator==(const SetUnaryOp &uop) const;
244-
};
245-
std::ostream &operator<<(std::ostream &out, const SetUnaryOp &s);
246-
247-
struct SetBinOp {
248-
member_class(Expr, left);
249-
member_class(ContainerOp, op);
250-
member_class(Expr, right);
251-
252-
SetBinOp();
253-
SetBinOp(Expr left, ContainerOp op, Expr right);
254-
255-
bool operator==(const SetBinOp &bop) const;
256-
};
257-
std::ostream &operator<<(std::ostream &out, const SetBinOp &s);
258-
259133
// Linear expression -----------------------------------------------------------
260134

261135
struct LinearExp {
@@ -269,21 +143,6 @@ struct LinearExp {
269143
};
270144
std::ostream &operator<<(std::ostream &out, const LinearExp &le);
271145

272-
enum class ExpOp { eq, add, sub };
273-
std::ostream &operator<<(std::ostream &out, const ExpOp &op);
274-
275-
struct LExpBinOp {
276-
member_class(Expr, left);
277-
member_class(ExpOp, op);
278-
member_class(Expr, right);
279-
280-
LExpBinOp();
281-
LExpBinOp(Expr left, ExpOp op, Expr right);
282-
283-
bool operator==(const LExpBinOp &bop) const;
284-
};
285-
std::ostream &operator<<(std::ostream &out, const LExpBinOp &lbop);
286-
287146
// Multi-dimensional linear expression -----------------------------------------
288147

289148
struct MDLExp {
@@ -296,18 +155,6 @@ struct MDLExp {
296155
};
297156
std::ostream &operator<<(std::ostream &out, const MDLExp &le);
298157

299-
struct MDLExpBinOp {
300-
member_class(Expr, left);
301-
member_class(ExpOp, op);
302-
member_class(Expr, right);
303-
304-
MDLExpBinOp();
305-
MDLExpBinOp(Expr left, ExpOp op, Expr right);
306-
307-
bool operator==(const MDLExpBinOp &bop) const;
308-
};
309-
std::ostream &operator<<(std::ostream &out, const MDLExpBinOp &lbop);
310-
311158
// SBG map ---------------------------------------------------------------------
312159

313160
struct LinearMap {
@@ -367,6 +214,51 @@ struct DSBG {
367214
};
368215
std::ostream &operator<<(std::ostream &out, const DSBG &g);
369216

217+
////////////////////////////////////////////////////////////////////////////////
218+
// Composite expressions -------------------------------------------------------
219+
////////////////////////////////////////////////////////////////////////////////
220+
221+
enum class UnOp { neg, card, comp };
222+
std::ostream &operator<<(std::ostream &out, const UnOp &op);
223+
224+
struct UnaryOp {
225+
member_class(UnOp, op);
226+
member_class(Expr, expr);
227+
228+
UnaryOp();
229+
UnaryOp(UnOp op, Expr expr);
230+
231+
bool operator==(const UnaryOp &uop) const;
232+
};
233+
std::ostream &operator<<(std::ostream &out, const UnaryOp &uop);
234+
235+
enum class Op { add, sub, mult, expo, eq, less, cap, cup, diff };
236+
std::ostream &operator<<(std::ostream &out, const Op &op);
237+
238+
struct BinOp {
239+
member_class(Expr, left);
240+
member_class(Op, op);
241+
member_class(Expr, right);
242+
243+
BinOp();
244+
BinOp(Expr left, Op op, Expr right);
245+
246+
bool operator==(const BinOp &bop) const;
247+
};
248+
std::ostream &operator<<(std::ostream &out, const BinOp &bop);
249+
250+
struct Call {
251+
member_class(Name, name);
252+
member_class(ExprList, args);
253+
254+
Call();
255+
Call(Name name, Expr args);
256+
Call(Name name, ExprList args);
257+
258+
bool operator==(const Call &c) const;
259+
};
260+
std::ostream &operator<<(std::ostream &out, const Call &c);
261+
370262
} // namespace AST
371263

372264
} // namespace SBG

eval/Makefile.include

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ all: $(EVAL)
1212
EVAL_SRC := \
1313
$(EVAL_DIR)/main.cpp \
1414
$(VISIT_DIR)/program_visitor.cpp \
15-
$(VISIT_DIR)/check_opt_conds.cpp \
1615
$(VISIT_DIR)/stm_visitor.cpp \
1716
$(VISIT_DIR)/eval_expr.cpp \
1817
$(VISIT_DIR)/eval_dsbg.cpp \

0 commit comments

Comments
 (0)