Skip to content

Commit 63b22ae

Browse files
committed
Merge branch 'master' into standard-ifdefs
2 parents 1c6f376 + 240cd0f commit 63b22ae

76 files changed

Lines changed: 1534 additions & 692 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎cpp2rust/converter/converter.cpp‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3573,6 +3573,14 @@ bool Converter::VisitInitListExpr(clang::InitListExpr *expr) {
35733573

35743574
StrCat(GetUnsafeTypeAsString(qual_type));
35753575
PushBrace brace(*this);
3576+
if (record->isUnion()) {
3577+
auto *field = expr->getInitializedFieldInUnion();
3578+
assert(field && expr->getNumInits() == 1);
3579+
StrCat(GetNamedDeclAsString(field), token::kColon);
3580+
ConvertFieldInit(field, expr->getInit(0));
3581+
SetFreshType(qual_type);
3582+
return false;
3583+
}
35763584
int i = 0;
35773585
for (const auto *field : record->fields()) {
35783586
StrCat(GetNamedDeclAsString(field), token::kColon);

‎cpp2rust/converter/converter_lib.cpp‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,14 @@ bool IsUnionArrayMember(const clang::Expr *base) {
214214
return false;
215215
}
216216

217+
clang::Expr *SubscriptedArray(clang::Expr *base) {
218+
while (auto *sub = clang::dyn_cast<clang::ArraySubscriptExpr>(
219+
base->IgnoreImplicit())) {
220+
base = sub->getBase();
221+
}
222+
return base;
223+
}
224+
217225
// TODO: this will be gone when the AST matcher lands
218226
std::tuple<clang::MemberExpr *, clang::RecordDecl *, std::string>
219227
ReplaceNonUniformLibcField(clang::MemberExpr *expr) {

‎cpp2rust/converter/converter_lib.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ bool IsInMainFile(const clang::Decl *decl);
5757

5858
bool IsUnionArrayMember(const clang::Expr *base);
5959

60+
clang::Expr *SubscriptedArray(clang::Expr *base);
61+
6062
std::tuple<clang::MemberExpr *, clang::RecordDecl *, std::string>
6163
ReplaceNonUniformLibcField(clang::MemberExpr *expr);
6264

0 commit comments

Comments
 (0)