Skip to content

Commit a5bd7b1

Browse files
committed
Delete abstract_structs_
1 parent cd937fa commit a5bd7b1

5 files changed

Lines changed: 13 additions & 7 deletions

File tree

‎cpp2rust/converter/converter.cpp‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ std::unordered_map<std::string, std::string> Converter::inner_structs_;
3030
std::unordered_set<std::string> Converter::decl_ids_;
3131
std::unordered_set<std::string> Converter::globals_;
3232
std::vector<std::string> Converter::global_inits_;
33-
std::unordered_set<std::string> Converter::abstract_structs_;
3433
Converter::RecordIndex Converter::record_decls_;
3534
std::map<std::string, Converter::DeferredBlock> Converter::virtual_methods_;
3635

@@ -318,7 +317,7 @@ bool Converter::VisitPointerType(clang::PointerType *type) {
318317
auto pointee_type = type->getPointeeType();
319318
StrCat(pointee_type.isConstQualified() ? "*const" : "*mut");
320319
if (pointee_type->isRecordType() &&
321-
abstract_structs_.contains(GetID(pointee_type->getAsRecordDecl()))) {
320+
IsAbstractUserClass(pointee_type->getAsRecordDecl())) {
322321
StrCat(keyword::kDyn);
323322
}
324323
return Convert(pointee_type);
@@ -4629,7 +4628,6 @@ pub fn main() {{
46294628
}
46304629

46314630
void Converter::ConvertAbstractClass(clang::CXXRecordDecl *decl) {
4632-
ENSURE(abstract_structs_.insert(GetID(decl)).second);
46334631
auto trait_name = GetRecordName(decl);
46344632
auto access_specifier_as_string = AccessSpecifierAsString(decl->getAccess());
46354633
auto signature = std::format("{} {} trait {}", access_specifier_as_string,

‎cpp2rust/converter/converter.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -952,7 +952,6 @@ class Converter : public clang::RecursiveASTVisitor<Converter> {
952952
};
953953

954954
static std::unordered_set<std::string> decl_ids_;
955-
static std::unordered_set<std::string> abstract_structs_;
956955

957956
class RecordIndex {
958957
public:

‎cpp2rust/converter/converter_lib.cpp‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,13 @@ bool IsUserDefinedDecl(const clang::Decl *decl) {
301301
!src_mgr.isInSystemMacro(src_loc);
302302
}
303303

304+
bool IsAbstractUserClass(const clang::RecordDecl *decl) {
305+
auto cxx = llvm::dyn_cast<clang::CXXRecordDecl>(decl);
306+
auto definition = cxx ? cxx->getDefinition() : nullptr;
307+
return definition && IsUserDefinedDecl(definition) &&
308+
definition->isAbstract();
309+
}
310+
304311
bool RefersToUserDefinedDecl(const clang::Expr *expr) {
305312
expr = expr->IgnoreParenImpCasts();
306313
const clang::Decl *decl = nullptr;

‎cpp2rust/converter/converter_lib.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ bool IsCodeUnitStringLiteral(const clang::StringLiteral *expr);
6666

6767
bool IsUserDefinedDecl(const clang::Decl *decl);
6868

69+
bool IsAbstractUserClass(const clang::RecordDecl *decl);
70+
6971
bool RefersToUserDefinedDecl(const clang::Expr *expr);
7072

7173
bool IsUnsignedArithOp(const clang::BinaryOperator *expr);

‎cpp2rust/converter/models/converter_refcount.cpp‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ bool ConverterRefCount::VisitPointerType(clang::PointerType *type) {
341341
PushConversionKind push2(*this, ConversionKind::FullRefCount,
342342
pointee_is_array);
343343
if (pointee_type->isRecordType() &&
344-
abstract_structs_.contains(GetID(pointee_type->getAsRecordDecl()))) {
344+
IsAbstractUserClass(pointee_type->getAsRecordDecl())) {
345345
StrCat("PtrDyn<dyn");
346346
} else {
347347
StrCat("Ptr<");
@@ -1507,7 +1507,7 @@ bool ConverterRefCount::VisitImplicitCastExpr(clang::ImplicitCastExpr *expr) {
15071507
auto ptype = clang::dyn_cast<clang::PointerType>(expr->getType());
15081508
auto pointee_type = ptype->getPointeeType()->getAsCXXRecordDecl();
15091509

1510-
if (pointee_type && abstract_structs_.contains(GetID(pointee_type))) {
1510+
if (pointee_type && IsAbstractUserClass(pointee_type)) {
15111511
PushConversionKind push(*this, ConversionKind::Unboxed);
15121512
StrCat(std::format("{}.to_dyn::<{}>(|w| w)",
15131513
ToString(sub_expr->IgnoreCasts()),
@@ -3222,7 +3222,7 @@ void ConverterRefCount::ConvertArrow(clang::Expr *expr) {
32223222
auto pointee_type = expr->getType()->getPointeeType();
32233223
// Virtual methods, which take &mut self, are called through PtrDyn.
32243224
if (auto *record = pointee_type->getAsRecordDecl();
3225-
isLValue() && record && abstract_structs_.contains(GetID(record))) {
3225+
isLValue() && record && IsAbstractUserClass(record)) {
32263226
StrCat(std::format("(*{}.upgrade().deref_mut())", ToString(expr)));
32273227
SetValueFreshness(pointee_type);
32283228
return;

0 commit comments

Comments
 (0)