Unverified Commit 37b4ae2e authored by Julian Kranz's avatar Julian Kranz
Browse files

cppgdsl: rreil id comparison

parent f88fb817
......@@ -22,13 +22,14 @@ private:
public:
arch_id(std::string name);
size_t get_subclass_counter();
size_t get_subclass_counter() const;
const std::string& get_name() {
return name;
}
bool operator== (id &other) const;
bool operator<(id const& other) const;
void accept(id_visitor &v);
};
......
......@@ -25,7 +25,7 @@ public:
virtual ~id() {
}
virtual size_t get_subclass_counter() = 0;
virtual size_t get_subclass_counter() const = 0;
std::string to_string();
friend std::ostream &operator<< (std::ostream &out, id &_this);
......
......@@ -29,12 +29,13 @@ private:
public:
shared_id(shared_id_type _id);
size_t get_subclass_counter();
size_t get_subclass_counter() const;
shared_id_type get_inner() {
return inner;
}
bool operator== (id &other) const;
bool operator<(id const& other) const;
std::string to_string();
void accept(id_visitor &v);
......
......@@ -22,10 +22,11 @@ private:
public:
_virtual(int_t t);
size_t get_subclass_counter();
size_t get_subclass_counter() const;
int_t get_t();
bool operator== (id &other) const;
bool operator<(id const& other) const;
void accept(id_visitor &v);
};
......
......@@ -22,20 +22,28 @@ arch_id::arch_id(string name) {
this->name = name;
}
size_t gdsl::rreil::arch_id::get_subclass_counter() {
size_t gdsl::rreil::arch_id::get_subclass_counter() const {
return subclass_counter;
}
bool gdsl::rreil::arch_id::operator ==(id &other) const {
bool gdsl::rreil::arch_id::operator==(id &other) const {
bool equals = false;
id_visitor iv;
iv._((std::function<void(arch_id*)>)[&](arch_id *aid) {
equals = this->name == aid->name;
});
iv._((std::function<void(arch_id *)>)[&](arch_id * aid) { equals = this->name == aid->name; });
other.accept(iv);
return equals;
}
bool gdsl::rreil::arch_id::operator<(const id &other) const {
size_t scc_me = subclass_counter;
size_t scc_other = other.get_subclass_counter();
if(scc_me == scc_other) {
arch_id const &other_casted = dynamic_cast<arch_id const &>(other);
return name.compare(other_casted.name) < 0;
} else
return scc_me < scc_other;
}
void gdsl::rreil::arch_id::accept(id_visitor &v) {
v.visit(this);
}
......@@ -27,20 +27,28 @@ gdsl::rreil::shared_id::shared_id(shared_id_type _id) {
this->inner = _id;
}
size_t gdsl::rreil::shared_id::get_subclass_counter() {
size_t gdsl::rreil::shared_id::get_subclass_counter() const {
return subclass_counter;
}
bool gdsl::rreil::shared_id::operator ==(id &other) const {
bool gdsl::rreil::shared_id::operator==(id &other) const {
bool equals = false;
id_visitor iv;
iv._((std::function<void(shared_id*)>)[&](shared_id *aid) {
equals = this->inner == aid->inner;
});
iv._((std::function<void(shared_id *)>)[&](shared_id * aid) { equals = this->inner == aid->inner; });
other.accept(iv);
return equals;
}
bool gdsl::rreil::shared_id::operator<(const id &other) const {
size_t scc_me = subclass_counter;
size_t scc_other = other.get_subclass_counter();
if(scc_me == scc_other) {
shared_id const &other_casted = dynamic_cast<shared_id const&>(other);
return inner < other_casted.inner;
} else
return scc_me < scc_other;
}
void gdsl::rreil::shared_id::accept(id_visitor &v) {
v.visit(this);
}
......@@ -20,7 +20,7 @@ _virtual::_virtual(int_t t) {
this->t = t;
}
size_t gdsl::rreil::_virtual::get_subclass_counter() {
size_t gdsl::rreil::_virtual::get_subclass_counter() const {
return subclass_counter;
}
......@@ -28,16 +28,24 @@ int_t _virtual::get_t() {
return this->t;
}
bool gdsl::rreil::_virtual::operator ==(id &other) const {
bool gdsl::rreil::_virtual::operator==(id &other) const {
bool equals = false;
id_visitor iv;
iv._((std::function<void(_virtual*)>)[&](_virtual *aid) {
equals = this->t == aid->t;
});
iv._((std::function<void(_virtual *)>)[&](_virtual * aid) { equals = this->t == aid->t; });
other.accept(iv);
return equals;
}
bool gdsl::rreil::_virtual::operator<(const id &other) const {
size_t scc_me = subclass_counter;
size_t scc_other = other.get_subclass_counter();
if(scc_me == scc_other) {
_virtual const &other_casted = dynamic_cast<_virtual const &>(other);
return t < other_casted.t;
} else
return scc_me < scc_other;
}
void gdsl::rreil::_virtual::accept(id_visitor &v) {
v.visit(this);
}
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