Skip to content

Commit

Permalink
Generate name for inner anonymous records
Browse files Browse the repository at this point in the history
  • Loading branch information
kornilova203 committed Jan 29, 2019
1 parent 3a6a280 commit 0f6fb19
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions bindgen/TypeTranslator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,18 +193,19 @@ TypeTranslator::addUnionDefinition(clang::RecordDecl *record,
std::string name) {
std::vector<std::shared_ptr<Field>> fields;

int anonIdField = 0;
for (const clang::FieldDecl *field : record->fields()) {
std::string fname = field->getNameAsString();
std::shared_ptr<Type> ftype = translate(field->getType());

std::string fname = field->getNameAsString();
if (fname.empty()) fname = "anonymous_" + std::to_string(anonIdField++);
fields.push_back(std::make_shared<Field>(fname, ftype));
}

uint64_t sizeInBits = ctx->getTypeSize(record->getTypeForDecl());
assert(sizeInBits % 8 == 0);

return ir.addUnion(name, std::move(fields), sizeInBits / 8,
getLocation(record));
return ir.addUnion(std::move(name), std::move(fields), sizeInBits / 8, getLocation(record));
}

std::shared_ptr<TypeDef>
Expand All @@ -222,15 +223,17 @@ TypeTranslator::addStructDefinition(clang::RecordDecl *record,
ctx->getASTRecordLayout(record);

bool isBitFieldStruct = false;
int anonIdField = 0;
for (const clang::FieldDecl *field : record->fields()) {
if (field->isBitField()) {
isBitFieldStruct = true;
}
std::shared_ptr<Type> ftype = translate(field->getType());
uint64_t recordOffsetInBits =
recordLayout.getFieldOffset(field->getFieldIndex());
fields.push_back(std::make_shared<Field>(field->getNameAsString(),
ftype, recordOffsetInBits));
std::string fname = field->getNameAsString();
if (fname.empty()) fname = "anonymous_" + std::to_string(anonIdField++);
fields.push_back(std::make_shared<Field>(fname, ftype, recordOffsetInBits));
}

uint64_t sizeInBits = ctx->getTypeSize(record->getTypeForDecl());
Expand Down

0 comments on commit 0f6fb19

Please sign in to comment.