Skip to content

Commit eec1a00

Browse files
committed
Add hoisted_records
1 parent 5265595 commit eec1a00

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

‎cpp2rust/converter/converter.cpp‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,10 @@ bool Converter::VisitTranslationUnitDecl(clang::TranslationUnitDecl *decl) {
363363
if (IsUserDefinedDecl(child) &&
364364
(IsInMainFile(child) || !decl_ids_.contains(GetID(child)))) {
365365
Convert(child);
366+
if (!hoisted_records_.empty()) {
367+
StrCat(hoisted_records_);
368+
hoisted_records_.clear();
369+
}
366370
}
367371
}
368372
return false;
@@ -1257,6 +1261,12 @@ bool Converter::VisitCompoundStmt(clang::CompoundStmt *stmt) {
12571261

12581262
bool Converter::VisitDeclStmt(clang::DeclStmt *stmt) {
12591263
for (auto *decl : stmt->decls()) {
1264+
if (clang::isa<clang::TagDecl>(decl)) {
1265+
Buffer buf(*this);
1266+
Convert(decl);
1267+
hoisted_records_ += std::move(buf).str();
1268+
continue;
1269+
}
12601270
Convert(decl);
12611271
StrCat(token::kSemiColon);
12621272
}

‎cpp2rust/converter/converter.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,8 @@ class Converter : public clang::RecursiveASTVisitor<Converter> {
880880
// translation units.
881881
static std::map<std::string, MethodsOnPtr> methods_on_ptr_;
882882

883+
std::string hoisted_records_;
884+
883885
enum class ExprKind : uint8_t {
884886
Callee,
885887
LValue,

0 commit comments

Comments
 (0)