Commit 7719ddc8 authored by Julian Kranz's avatar Julian Kranz
Browse files

Merge pull request #18 from newgre/master

A few small improvements in the statement class hierarchy
parents 4782d09c 4883b357
......@@ -22,24 +22,25 @@ private:
variable *lhs;
expr *rhs;
void put(std::ostream &out);
void put(std::ostream &out) const override;
public:
assign(int_t size, variable *lhs, expr *rhs);
~assign();
~assign() override;
int_t get_size() {
int_t get_size() const {
return size;
}
variable *get_lhs() {
variable *get_lhs() const {
return lhs;
}
expr *get_rhs() {
expr *get_rhs() const {
return rhs;
}
void accept(statement_visitor &v);
void accept(statement_visitor &v) override;
};
}}
} // namespace rreil
} //namespace gdsl
......@@ -22,20 +22,21 @@ private:
address *target;
branch_hint hint;
void put(std::ostream &out);
void put(std::ostream &out) const override;
public:
branch(address *target, branch_hint hint);
~branch();
~branch() override;
address *get_target() {
address *get_target() const {
return target;
}
branch_hint get_hint() {
branch_hint get_hint() const {
return hint;
}
void accept(statement_visitor &v);
void accept(statement_visitor &v) override;
};
}}
} // namespace rreil
} // namespace gdsl
......@@ -23,24 +23,25 @@ private:
address *target_true;
address *target_false;
void put(std::ostream &out);
void put(std::ostream &out) const override;
public:
cbranch(sexpr *cond, address *target_true, address *target_false);
~cbranch();
sexpr *get_cond() {
sexpr *get_cond() const {
return cond;
}
address *get_target_false() {
address *get_target_false() const {
return target_false;
}
address *get_target_true() {
address *get_target_true() const {
return target_true;
}
void accept(statement_visitor &v);
void accept(statement_visitor &v) override;
};
}}
} // namespace rreil
} // namespace gdsl
......@@ -26,29 +26,29 @@ private:
variable_limited *lhs;
std::vector<variable_limited*> rhs;
void put(std::ostream &out);
void put(std::ostream &out) const override;
public:
floating(flop op, variable *flags, variable_limited *lhs, std::vector<variable_limited*> rhs);
~floating();
~floating() override;
flop get_op() {
flop get_op() const {
return op;
}
variable *get_flags() {
variable *get_flags() const {
return flags;
}
variable_limited *get_lhs() {
variable_limited *get_lhs() const {
return lhs;
}
std::vector<variable_limited*> const &get_rhs() {
const std::vector<variable_limited*> &get_rhs() const {
return rhs;
}
void accept(statement_visitor &v);
void accept(statement_visitor &v) override;
};
}
}
} // namespace rreil
} // namespace gdsl
......@@ -22,24 +22,25 @@ private:
std::vector<statement*> *then_branch;
std::vector<statement*> *else_branch;
void put(std::ostream &out);
void put(std::ostream &out) const override;
public:
ite(sexpr *cond, std::vector<statement*> *then_branch, std::vector<statement*> *else_branch);
~ite();
sexpr *get_cond() {
sexpr *get_cond() const {
return cond;
}
std::vector<statement*> *get_then_branch() {
const std::vector<statement*> *get_then_branch() const {
return then_branch;
}
std::vector<statement*> *get_else_branch() {
const std::vector<statement*> *get_else_branch() const {
return else_branch;
}
void accept(statement_visitor &v);
void accept(statement_visitor &v) override;
};
}}
} // namespace rreil
} // namespace gdsl
......@@ -23,24 +23,25 @@ private:
variable *lhs;
address *_address;
void put(std::ostream &out);
void put(std::ostream &out) const override;
public:
load(int_t size, variable *lhs, address *_address);
~load();
int_t get_size() {
int_t get_size() const {
return size;
}
variable *get_lhs() {
variable *get_lhs() const {
return lhs;
}
address *get_address() {
address *get_address() const {
return _address;
}
void accept(statement_visitor &v);
void accept(statement_visitor &v) override;
};
}}
} // namespace rreil
} // namespace gdsl
......@@ -25,25 +25,25 @@ private:
std::vector<variable_limited*> lhs;
std::vector<variable_limited*> rhs;
void put(std::ostream &out);
void put(std::ostream &out) const override;
public:
prim(std::string op, std::vector<variable_limited*> lhs, std::vector<variable_limited*> rhs);
~prim();
~prim() override;
std::string get_op() {
std::string get_op() const {
return op;
}
std::vector<variable_limited*> const &get_lhs() {
const std::vector<variable_limited*> &get_lhs() const {
return lhs;
}
std::vector<variable_limited*> const &get_rhs() {
const std::vector<variable_limited*> &get_rhs() const {
return rhs;
}
void accept(statement_visitor &v);
void accept(statement_visitor &v) override;
};
}
}
} //namespace rreil
} //namespace gdsl
......@@ -18,21 +18,21 @@ typedef std::vector<rreil::statement*> statements_t;
class statement {
private:
virtual void put(std::ostream &out) = 0;
virtual void put(std::ostream &out) const = 0;
public:
virtual ~statement() {
}
virtual std::string to_string();
friend std::ostream& operator<< (std::ostream &out, statement &_this);
std::string to_string() const;
friend std::ostream& operator<<(std::ostream &out, const statement &_this);
virtual void accept(statement_visitor &v) = 0;
};
std::ostream& operator<<(std::ostream &out, statement &_this);
std::ostream& operator<<(std::ostream &out, const statement &_this);
}
}
} // namespace rreil
} // namespace gdsl
#include "assign.h"
#include "branch.h"
......
......@@ -23,24 +23,25 @@ private:
address *_address;
linear *rhs;
void put(std::ostream &out);
void put(std::ostream &out) const override;
public:
store(int_t size, address *_address, linear *rhs);
~store();
~store() override;
int_t get_size() {
int_t get_size() const {
return size;
}
address *get_address() {
address *get_address() const {
return _address;
}
linear *get_rhs() {
linear *get_rhs() const {
return rhs;
}
void accept(statement_visitor &v);
void accept(statement_visitor &v) override;
};
}}
} //namespace rreil
} //namespace gdsl
......@@ -20,17 +20,17 @@ class _throw : public statement {
private:
exception *inner;
void put(std::ostream &out);
void put(std::ostream &out) const override;
public:
_throw(exception *inner);
~_throw();
explicit _throw(exception *inner);
~_throw() override;
exception *get_inner() {
exception *get_inner() const {
return inner;
}
void accept(statement_visitor &v);
void accept(statement_visitor &v) override;
};
}
}
} // namespace rreil
} // namespace gdsl
......@@ -22,20 +22,21 @@ private:
sexpr *cond;
std::vector<statement*> *body;
void put(std::ostream &out);
void put(std::ostream &out) const override;
public:
_while(sexpr *cond, std::vector<statement*> *body);
~_while();
~_while() override;
sexpr *get_cond() {
sexpr *get_cond() const {
return cond;
}
std::vector<statement*> *get_body() {
const std::vector<statement*> *get_body() const{
return body;
}
void accept(statement_visitor &v);
};
}}
} // namespace rreil
} // namespace gdsl
......@@ -23,6 +23,6 @@ void gdsl::rreil::assign::accept(statement_visitor &v) {
v.visit(this);
}
void gdsl::rreil::assign::put(std::ostream &out) {
void gdsl::rreil::assign::put(std::ostream &out) const {
out << *lhs << " =:" << size << " " << *rhs;
}
......@@ -21,6 +21,6 @@ void gdsl::rreil::branch::accept(statement_visitor &v) {
v.visit(this);
}
void gdsl::rreil::branch::put(std::ostream &out) {
void gdsl::rreil::branch::put(std::ostream &out) const {
out << branch_hint_to_string(hint) << " => " << *target;
}
......@@ -24,6 +24,6 @@ void gdsl::rreil::cbranch::accept(statement_visitor &v) {
v.visit(this);
}
void gdsl::rreil::cbranch::put(std::ostream &out) {
void gdsl::rreil::cbranch::put(std::ostream &out) const {
out << *cond << " ? goto " << *target_true << " : goto " << *target_false;
}
......@@ -28,7 +28,7 @@ void gdsl::rreil::floating::accept(statement_visitor &v) {
v.visit(this);
}
void gdsl::rreil::floating::put(std::ostream &out) {
void gdsl::rreil::floating::put(std::ostream &out) const {
out << *lhs << " = (" << flop_to_string(op) << ")(";
for (size_t i = 0; i < rhs.size(); ++i) {
if(i)
......
......@@ -8,8 +8,6 @@
#include <cppgdsl/rreil/statement/ite.h>
#include <iostream>
using namespace std;
gdsl::rreil::ite::ite(sexpr *cond, std::vector<statement*> *then_branch, std::vector<statement*> *else_branch) {
this->cond = cond;
this->then_branch = then_branch;
......@@ -30,7 +28,7 @@ void gdsl::rreil::ite::accept(statement_visitor &v) {
v.visit(this);
}
void gdsl::rreil::ite::put(std::ostream &out) {
void gdsl::rreil::ite::put(std::ostream &out) const {
out << "if(" << *cond << ") {\n";
for(auto stmt : *then_branch)
out << *stmt << "\n";
......
......@@ -23,6 +23,6 @@ void gdsl::rreil::load::accept(statement_visitor &v) {
v.visit(this);
}
void gdsl::rreil::load::put(std::ostream &out) {
void gdsl::rreil::load::put(std::ostream &out) const {
out << *lhs << " =:" << size << " *" << *_address;
}
......@@ -8,8 +8,6 @@
#include <cppgdsl/rreil/statement/prim.h>
#include <iostream>
using namespace std;
gdsl::rreil::prim::prim(std::string op, std::vector<variable_limited*> lhs, std::vector<variable_limited*> rhs) {
this->op = op;
this->lhs = lhs;
......@@ -27,7 +25,7 @@ void gdsl::rreil::prim::accept(statement_visitor &v) {
v.visit(this);
}
void gdsl::rreil::prim::put(std::ostream &out) {
void gdsl::rreil::prim::put(std::ostream &out) const {
out << "(";
for (size_t i = 0; i < lhs.size(); ++i) {
if(i)
......
......@@ -7,13 +7,14 @@
#include <cppgdsl/rreil/statement/statement.h>
#include <sstream>
std::string gdsl::rreil::statement::to_string() {
std::string gdsl::rreil::statement::to_string() const {
std::stringstream o;
o << *this;
return o.str();
}
std::ostream& gdsl::rreil::operator <<(std::ostream &out, statement &_this) {
std::ostream &gdsl::rreil::operator<<(std::ostream &out,
const statement &_this) {
_this.put(out);
return out;
}
......@@ -24,6 +24,6 @@ void gdsl::rreil::store::accept(statement_visitor &v) {
v.visit(this);
}
void gdsl::rreil::store::put(std::ostream &out) {
void gdsl::rreil::store::put(std::ostream &out) const {
out << "*" << *_address << " =:" << size << " " << *rhs;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment