Skip to content

Commit b5d18b9

Browse files
committed
Restructure
1 parent b60bb87 commit b5d18b9

59 files changed

Lines changed: 388 additions & 1143 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Makefile.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ LIB_OBJ = $(addprefix $(BUILD_DIR)/, $(LIB_SRC:.cpp=.o))
5656
$(LIB_SBGRAPH): create-folders $(LIB_OBJ)
5757
$(AR) rcs $(LIB_SBGRAPH) $(LIB_OBJ)
5858

59+
DEPS = $(addprefix $(BUILD_DIR)/, $(LIB_SRC:.cpp=.d))
60+
61+
-include $(DEPS)
62+
5963
#///////////////////////////////////////////////////////////////////////////////
6064
# Library Installation ---------------------------------------------------------
6165
#///////////////////////////////////////////////////////////////////////////////

ast/expr.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,8 +418,9 @@ std::ostream &operator<<(std::ostream &out, const BinOp &bop)
418418

419419
Call::Call() : name_(), args_() {}
420420
Call::Call(Name name, ExprList args) : name_(name), args_(args) {}
421-
Call::Call(Name name, Expr args) : name_(name), args_()
422-
{ args_ref().push_back(args); }
421+
Call::Call(Name name, Expr args) : name_(name), args_() {
422+
args_ref().push_back(args);
423+
}
423424

424425
member_imp(Call, Name, name);
425426
member_imp(Call, ExprList, args);
@@ -445,6 +446,20 @@ std::ostream &operator<<(std::ostream &out, const Call &c)
445446
return out;
446447
}
447448

449+
ParenExpr::ParenExpr() : e_() {}
450+
ParenExpr::ParenExpr(Expr e) : e_(e) {}
451+
452+
member_imp(ParenExpr, Expr, e);
453+
454+
bool ParenExpr::operator==(const ParenExpr &pe) const { return e_ == pe.e_; }
455+
456+
std::ostream &operator<<(std::ostream &out, const ParenExpr &pe)
457+
{
458+
out << "(" << pe.e() << ")";
459+
460+
return out;
461+
}
462+
448463
std::ostream &operator<<(std::ostream &out, const ExprList &el)
449464
{
450465
for (Expr e : el)

ast/expr.hpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,9 @@ struct LinearMap;
5050
struct PWLMap;
5151
struct SBG;
5252
struct DSBG;
53+
struct ParenExpr;
5354

54-
typedef std::string VariableName;
55-
56-
typedef boost::variant<Natural, VariableName,
55+
typedef boost::variant<Natural, Name,
5756
boost::recursive_wrapper<Rational>,
5857
boost::recursive_wrapper<UnaryOp>,
5958
boost::recursive_wrapper<BinOp>,
@@ -66,7 +65,8 @@ typedef boost::variant<Natural, VariableName,
6665
boost::recursive_wrapper<LinearMap>,
6766
boost::recursive_wrapper<PWLMap>,
6867
boost::recursive_wrapper<SBG>,
69-
boost::recursive_wrapper<DSBG>> Expr;
68+
boost::recursive_wrapper<DSBG>,
69+
boost::recursive_wrapper<ParenExpr>> Expr;
7070
typedef std::vector<Expr> ExprList;
7171
std::ostream &operator<<(std::ostream &out, const ExprList &el);
7272

@@ -259,6 +259,16 @@ struct Call {
259259
};
260260
std::ostream &operator<<(std::ostream &out, const Call &c);
261261

262+
struct ParenExpr {
263+
member_class(Expr, e);
264+
265+
ParenExpr();
266+
ParenExpr(Expr e);
267+
268+
bool operator==(const ParenExpr &pe) const;
269+
};
270+
std::ostream &operator<<(std::ostream &out, const ParenExpr &pe);
271+
262272
} // namespace AST
263273

264274
} // namespace SBG

ast/statement.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ namespace SBG {
2424
namespace AST {
2525

2626
Assign::Assign() : l_(), r_() {}
27-
Assign::Assign(VariableName l, Expr r) : l_(l), r_(r) {}
27+
Assign::Assign(Name l, Expr r) : l_(l), r_(r) {}
2828

29-
member_imp(Assign, VariableName, l);
29+
member_imp(Assign, Name, l);
3030
member_imp(Assign, Expr, r);
3131

3232
std::ostream &operator<<(std::ostream &out, const Assign &asgn)

ast/statement.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ namespace SBG {
3333
namespace AST {
3434

3535
struct Assign {
36-
member_class(VariableName, l);
36+
member_class(Name, l);
3737
member_class(Expr, r);
3838

3939
Assign();
40-
Assign(VariableName l, Expr r);
40+
Assign(Name l, Expr r);
4141
};
4242
std::ostream &operator<<(std::ostream &out, const Assign &asgn);
4343

eval/defs.cpp

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ template std::ostream &operator<<(std::ostream &out, const ExprBaseType &v);
8686

8787
std::ostream &operator<<(std::ostream &out, const ExprEval &e)
8888
{
89-
out << std::get<0>(e) << "\n --> ";
90-
ExprBaseType ebt = std::get<1>(e);
91-
out << ebt << "\n";
89+
out << std::get<0>(e) << "\n --> " << std::get<1>(e) << "\n";
90+
//ExprBaseType ebt = std::get<1>(e);
91+
//out << ebt << "\n";
9292

9393
return out;
9494
}
@@ -101,19 +101,35 @@ std::ostream &operator<<(std::ostream &out, const ExprEvalList &ee)
101101
return out;
102102
}
103103

104-
ProgramIO::ProgramIO(AST::StatementList stms, ExprEvalList exprs)
104+
std::ostream &operator<<(std::ostream &out, const StmEval &s)
105+
{
106+
out << std::get<0>(s) << " = " << std::get<1>(s) << ";";
107+
108+
return out;
109+
}
110+
111+
std::ostream &operator<<(std::ostream &out, const StmEvalList &ss)
112+
{
113+
for (StmEval s : ss)
114+
out << s << "\n";
115+
116+
return out;
117+
}
118+
119+
ProgramIO::ProgramIO(StmEvalList stms, ExprEvalList exprs)
105120
: nmbr_dims_(1), stms_(stms), exprs_(exprs) {}
106-
ProgramIO::ProgramIO(unsigned int nmbr_dims, AST::StatementList stms, ExprEvalList exprs)
121+
ProgramIO::ProgramIO(unsigned int nmbr_dims, StmEvalList stms
122+
, ExprEvalList exprs)
107123
: nmbr_dims_(nmbr_dims), stms_(stms), exprs_(exprs) {}
108124

109125
member_imp(ProgramIO, unsigned int, nmbr_dims);
110-
member_imp(ProgramIO, AST::StatementList, stms);
126+
member_imp(ProgramIO, StmEvalList, stms);
127+
member_imp(ProgramIO, ExprEvalList, exprs);
111128

112129
std::ostream &operator<<(std::ostream &out, const ProgramIO &p)
113130
{
114-
if (!p.stms().empty())
115-
out << p.stms() << "\n";
116-
out << p.exprs_;
131+
out << p.stms() << "\n";
132+
out << p.exprs();
117133

118134
return out;
119135
}

eval/defs.hpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ typedef std::optional<ExprBaseType> MaybeEBT;
6565

6666
// Environments ----------------------------------------------------------------
6767

68-
typedef AST::VariableName VKey;
68+
typedef AST::Name VKey;
6969
typedef ExprBaseType VValue;
7070
typedef std::optional<VValue> MaybeVValue;
7171
typedef std::map<VKey, VValue> VarEnvType;
@@ -114,6 +114,10 @@ typedef enum { empty, min, max, comp, inv, im, preim, dom, comb
114114
template<typename T, typename... Ts>
115115
std::ostream &operator<<(std::ostream &out, const std::variant<T, Ts...> &v);
116116

117+
typedef std::tuple<AST::Name, ExprBaseType> StmEval;
118+
std::ostream &operator<<(std::ostream &out, const StmEval &e);
119+
typedef std::vector<StmEval> StmEvalList;
120+
std::ostream &operator<<(std::ostream &out, const StmEvalList &e);
117121
typedef std::tuple<AST::Expr, ExprBaseType> ExprEval;
118122
std::ostream &operator<<(std::ostream &out, const ExprEval &e);
119123
typedef std::vector<ExprEval> ExprEvalList;
@@ -127,11 +131,11 @@ std::ostream &operator<<(std::ostream &out, const ExprEvalList &ee);
127131
*/
128132
struct ProgramIO {
129133
member_class(unsigned int, nmbr_dims);
130-
member_class(AST::StatementList, stms);
131-
ExprEvalList exprs_;
134+
member_class(StmEvalList, stms);
135+
member_class(ExprEvalList, exprs);
132136

133-
ProgramIO(AST::StatementList stms, ExprEvalList exprs);
134-
ProgramIO(unsigned int nmbr_dims, AST::StatementList stms, ExprEvalList exprs);
137+
ProgramIO(StmEvalList stms, ExprEvalList exprs);
138+
ProgramIO(unsigned int nmbr_dims, StmEvalList stms, ExprEvalList exprs);
135139
};
136140
std::ostream &operator<<(std::ostream &out, const ProgramIO &p);
137141

eval/visitors/eval_expr.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ ExprBaseType EvalExpression::operator()(AST::Rational v) const
459459
return boost::apply_visitor(EvalRat(env_), AST::Expr(v));
460460
}
461461

462-
ExprBaseType EvalExpression::operator()(AST::VariableName v) const
462+
ExprBaseType EvalExpression::operator()(AST::Name v) const
463463
{
464464
MaybeEBT v_opt = env_[v];
465465
if (v_opt)
@@ -866,6 +866,11 @@ ExprBaseType EvalExpression::operator()(AST::DSBG v) const
866866
return LIB::DSBG(fact_, V, Vmap, mapB, mapD, Emap, subE);
867867
}
868868

869+
ExprBaseType EvalExpression::operator()(AST::ParenExpr v) const
870+
{
871+
return boost::apply_visitor(*this, v.e());
872+
}
873+
869874
} // namespace Eval
870875

871876
} // namespace SBG

eval/visitors/eval_expr.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ struct EvalExpression : public boost::static_visitor<ExprBaseType> {
4040

4141
ExprBaseType operator()(AST::Natural v) const;
4242
ExprBaseType operator()(AST::Rational v) const;
43-
ExprBaseType operator()(AST::VariableName v) const;
43+
ExprBaseType operator()(AST::Name v) const;
4444
ExprBaseType operator()(AST::UnaryOp v) const;
4545
ExprBaseType operator()(AST::BinOp v) const;
4646
ExprBaseType operator()(AST::Call v) const;
@@ -53,6 +53,7 @@ struct EvalExpression : public boost::static_visitor<ExprBaseType> {
5353
ExprBaseType operator()(AST::PWLMap v) const;
5454
ExprBaseType operator()(AST::SBG v) const;
5555
ExprBaseType operator()(AST::DSBG v) const;
56+
ExprBaseType operator()(AST::ParenExpr v) const;
5657

5758
private:
5859
unsigned int nmbr_dims_;

eval/visitors/eval_int.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ namespace Eval {
2626
EvalInt::EvalInt() : env_() {}
2727
EvalInt::EvalInt(VarEnv &env) : env_(env) {}
2828

29-
LIB::INT EvalInt::operator()(AST::Natural v) const { return v; }
29+
LIB::INT EvalInt::operator()(AST::Natural v) const { return (LIB::INT) v; }
3030

3131
LIB::INT EvalInt::operator()(AST::Rational v) const
3232
{
@@ -37,7 +37,7 @@ LIB::INT EvalInt::operator()(AST::Rational v) const
3737
return 0;
3838
}
3939

40-
LIB::INT EvalInt::operator()(AST::VariableName v) const
40+
LIB::INT EvalInt::operator()(AST::Name v) const
4141
{
4242
MaybeEBT v_opt = env_[v];
4343
if (v_opt) {
@@ -154,6 +154,11 @@ LIB::INT EvalInt::operator()(AST::DSBG v) const
154154
return 0;
155155
}
156156

157+
LIB::INT EvalInt::operator()(AST::ParenExpr v) const
158+
{
159+
return boost::apply_visitor(*this, v.e());
160+
}
161+
157162
} // namespace Eval
158163

159164
} // namespace SBG

0 commit comments

Comments
 (0)