Skip to content

Commit 535b724

Browse files
authored
Merge pull request #126 from kornilova-l/fix-StructOrUnion-equals
Fix StructOrUnion operator==
2 parents 65450fd + 2b088d1 commit 535b724

File tree

2 files changed

+11
-27
lines changed

2 files changed

+11
-27
lines changed

bindgen/ir/Struct.cpp

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,6 @@ StructOrUnion::StructOrUnion(std::string name,
2121

2222
std::string StructOrUnion::getName() const { return name; }
2323

24-
bool StructOrUnion::equals(const StructOrUnion &other) const {
25-
if (this == &other) {
26-
return true;
27-
}
28-
if (isInstanceOf<const Struct>(&other)) {
29-
auto *s = dynamic_cast<const Struct *>(&other);
30-
if (name != s->name) {
31-
return false;
32-
}
33-
if (fields.size() != s->fields.size()) {
34-
return false;
35-
}
36-
for (size_t i = 0; i < fields.size(); i++) {
37-
if (*fields[i] != *s->fields[i]) {
38-
return false;
39-
}
40-
}
41-
return true;
42-
}
43-
return false;
44-
}
45-
4624
std::shared_ptr<Location> StructOrUnion::getLocation() const {
4725
return location;
4826
}
@@ -142,17 +120,21 @@ bool Struct::usesType(const std::shared_ptr<Type> &type,
142120
bool stopOnTypeDefs) const {
143121
for (const auto &field : fields) {
144122
if (*field->getType() == *type ||
145-
field->getType().get()->usesType(type, stopOnTypeDefs)) {
123+
field->getType()->usesType(type, stopOnTypeDefs)) {
146124
return true;
147125
}
148126
}
149127
return false;
150128
}
151129

152130
bool Struct::operator==(const Type &other) const {
131+
if (this == &other) {
132+
return true;
133+
}
153134
auto *s = dynamic_cast<const Struct *>(&other);
154135
if (s) {
155-
return this->equals(*s);
136+
/* structs have unique names */
137+
return name == s->name;
156138
}
157139
return false;
158140
}
@@ -290,9 +272,13 @@ std::string Union::generateHelperClass() const {
290272
std::string Union::getTypeAlias() const { return "union_" + name; }
291273

292274
bool Union::operator==(const Type &other) const {
275+
if (this == &other) {
276+
return true;
277+
}
293278
auto *u = dynamic_cast<const Union *>(&other);
294279
if (u) {
295-
return this->equals(*u);
280+
/* unions have unique names */
281+
return name == u->name;
296282
}
297283
return false;
298284
}

bindgen/ir/Struct.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ class StructOrUnion {
3535

3636
std::string getName() const;
3737

38-
bool equals(const StructOrUnion &other) const;
39-
4038
std::shared_ptr<Location> getLocation() const;
4139

4240
virtual std::string getTypeAlias() const = 0;

0 commit comments

Comments
 (0)