Skip to content

Commit 329f350

Browse files
authored
Merge pull request #121 from kornilova-l/cleanups
Minor cleanups
2 parents 0e5ac3e + 78cbf96 commit 329f350

File tree

2 files changed

+5
-10
lines changed

2 files changed

+5
-10
lines changed

bindgen/TypeTranslator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class TypeTranslator {
1515
* @return the type translated or nullptr if type is function type.
1616
*/
1717
std::shared_ptr<Type> translate(const clang::QualType &tpe,
18-
const std::string * = nullptr);
18+
const std::string *avoid = nullptr);
1919

2020
std::string getTypeFromTypeMap(std::string cType);
2121

bindgen/visitor/TreeVisitor.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,22 +99,20 @@ bool TreeVisitor::VisitRecordDecl(clang::RecordDecl *record) {
9999
}
100100

101101
void TreeVisitor::handleUnion(clang::RecordDecl *record, std::string name) {
102-
uint64_t maxSize = 0;
103-
104102
std::vector<std::shared_ptr<Field>> fields;
105103

106104
for (const clang::FieldDecl *field : record->fields()) {
107-
uint64_t sizeInBits = astContext->getTypeSize(field->getType());
108-
assert(sizeInBits % 8 == 0);
109-
maxSize = std::max(maxSize, sizeInBits / 8);
110105
std::string fname = field->getNameAsString();
111106
std::shared_ptr<Type> ftype =
112107
typeTranslator.translate(field->getType(), &name);
113108

114109
fields.push_back(std::make_shared<Field>(fname, ftype));
115110
}
116111

117-
ir.addUnion(name, std::move(fields), maxSize, getLocation(record));
112+
uint64_t sizeInBits = astContext->getTypeSize(record->getTypeForDecl());
113+
assert(sizeInBits % 8 == 0);
114+
115+
ir.addUnion(name, std::move(fields), sizeInBits / 8, getLocation(record));
118116
}
119117

120118
void TreeVisitor::handleStruct(clang::RecordDecl *record, std::string name) {
@@ -127,7 +125,6 @@ void TreeVisitor::handleStruct(clang::RecordDecl *record, std::string name) {
127125
llvm::errs().flush();
128126
}
129127

130-
int fieldCnt = 0;
131128
std::vector<std::shared_ptr<Field>> fields;
132129

133130
for (const clang::FieldDecl *field : record->fields()) {
@@ -137,8 +134,6 @@ void TreeVisitor::handleStruct(clang::RecordDecl *record, std::string name) {
137134
std::make_shared<Field>(field->getNameAsString(), ftype));
138135

139136
cycleDetection.AddDependency(newName, field->getType());
140-
141-
fieldCnt++;
142137
}
143138

144139
if (cycleDetection.isCyclic(newName)) {

0 commit comments

Comments
 (0)