Skip to content

Commit c7a2e39

Browse files
force copy constructor working
1 parent a889ac1 commit c7a2e39

File tree

4 files changed

+80
-14
lines changed

4 files changed

+80
-14
lines changed

astgen/src/astgen.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@ int main(int argc_, const char** argv_) {
208208
#define CPPMM_PROPERTIES(x) __attribute__((annotate("cppmm|properties|" #x)))
209209
#define CPPMM_MANUAL __attribute__((annotate("cppmm|manual")))
210210
#define CPPMM_IMPL __attribute__((annotate("cppmm|impl")))
211+
#define CPPMM_COPY_CTOR __attribute__((annotate("cppmm|copy_constructor")))
212+
#define CPPMM_MOVE_CTOR __attribute__((annotate("cppmm|move_constructor")))
211213
212214
#define CPPMM_THROWS(EX, VAR) __attribute__((annotate("cppmm|throws|" #EX "|" #VAR)))
213215
#define CPPMM_NOEXCEPT __attribute__((annotate("cppmm|noexcept")))

astgen/src/process_binding.cpp

+67-8
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,16 @@ bool has_noexcept_attr(const std::vector<std::string>& attrs) {
455455
attrs.end();
456456
}
457457

458+
bool has_copy_ctor_attr(const std::vector<std::string>& attrs) {
459+
return std::find(attrs.begin(), attrs.end(), "cppmm|copy_constructor") !=
460+
attrs.end();
461+
}
462+
463+
bool has_move_ctor_attr(const std::vector<std::string>& attrs) {
464+
return std::find(attrs.begin(), attrs.end(), "cppmm|move_constructor") !=
465+
attrs.end();
466+
}
467+
458468
bool has_manual_attr(const std::vector<std::string>& attrs) {
459469
return std::find(attrs.begin(), attrs.end(), "cppmm|manual") != attrs.end();
460470
}
@@ -1055,17 +1065,63 @@ bool is_public_move_ctor(const Decl* cmd) {
10551065
}
10561066
}
10571067

1068+
bool has_forbidden_copy_ctor(const CXXRecordDecl* crd) {
1069+
for (const Decl* d: crd->decls()) {
1070+
if (is_inaccessible_copy_ctor(d)) {
1071+
return true;
1072+
}
1073+
}
1074+
1075+
1076+
for (const auto base : crd->bases()) {
1077+
if (const CXXRecordDecl* base_crd =
1078+
base.getType()->getAsCXXRecordDecl()) {
1079+
if (has_forbidden_copy_ctor(base_crd)) {
1080+
return true;
1081+
}
1082+
}
1083+
}
1084+
1085+
return false;
1086+
}
1087+
1088+
bool has_forbidden_move_ctor(const CXXRecordDecl* crd) {
1089+
for (const Decl* d: crd->decls()) {
1090+
if (is_inaccessible_move_ctor(d)) {
1091+
return true;
1092+
}
1093+
}
1094+
1095+
1096+
for (const auto base : crd->bases()) {
1097+
if (const CXXRecordDecl* base_crd =
1098+
base.getType()->getAsCXXRecordDecl()) {
1099+
if (has_forbidden_move_ctor(base_crd)) {
1100+
return true;
1101+
}
1102+
}
1103+
}
1104+
1105+
return false;
1106+
}
1107+
10581108
void has_public_copy_move_ctor(const CXXRecordDecl* crd,
10591109
bool& has_public_copy_ctor,
10601110
bool& has_public_move_ctor) {
1061-
for (const Decl* d : crd->decls()) {
1062-
// has_public_copy_ctor |= is_public_copy_ctor(d);
1063-
// has_public_move_ctor |= is_public_move_ctor(d);
1064-
has_public_copy_ctor |= is_inaccessible_copy_ctor(d);
1065-
has_public_move_ctor |= is_inaccessible_move_ctor(d);
1066-
}
1067-
has_public_copy_ctor = !has_public_copy_ctor;
1068-
has_public_move_ctor = !has_public_move_ctor;
1111+
// for (const Decl* d : crd->decls()) {
1112+
// // has_public_copy_ctor |= is_public_copy_ctor(d);
1113+
// // has_public_move_ctor |= is_public_move_ctor(d);
1114+
// has_public_copy_ctor |= is_inaccessible_copy_ctor(d);
1115+
// has_public_move_ctor |= is_inaccessible_move_ctor(d);
1116+
// }
1117+
// has_public_copy_ctor = !has_public_copy_ctor;
1118+
// has_public_move_ctor = !has_public_move_ctor;
1119+
1120+
// has_public_copy_ctor = crd->hasTrivialCopyConstructor() || crd->hasNonTrivialCopyConstructor();
1121+
has_public_move_ctor = (crd->hasTrivialMoveConstructor() || crd->hasNonTrivialMoveConstructor()) && !has_forbidden_move_ctor(crd);
1122+
1123+
has_public_copy_ctor = !has_forbidden_copy_ctor(crd);
1124+
// has_public_move_ctor = !has_forbidden_move_ctor(crd);
10691125
}
10701126

10711127
std::vector<std::string> get_properties(const std::vector<std::string>& attrs) {
@@ -1226,6 +1282,9 @@ void process_concrete_record(const CXXRecordDecl* crd, std::string filename,
12261282
mptr->is_noexcept |= has_noexcept_attr(mptr->attrs);
12271283
function_map[mptr->_function_id] = mptr;
12281284

1285+
mptr->is_copy_constructor = has_copy_ctor_attr(mptr->attrs);
1286+
mptr->is_move_constructor = has_move_ctor_attr(mptr->attrs);
1287+
12291288
NodeId id = NODES.size();
12301289
NODE_MAP[method->qualified_name] = id;
12311290
NODES.emplace_back(std::move(method));

test/copymoveaccess/bind/cma.cpp

+8-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,14 @@ namespace cppmm_bind {
55

66
namespace foo {
77

8-
class PublicDerived { using BoundType = ::foo::PublicDerived; };
9-
class PrivateDerived { using BoundType = ::foo::PrivateDerived; };
10-
class DeletedDerived { using BoundType = ::foo::DeletedDerived; };
8+
struct PublicDerived {
9+
using BoundType = ::foo::PublicDerived;
10+
11+
PublicDerived(const ::foo::PublicDerived&) CPPMM_MANUAL CPPMM_COPY_CTOR;
12+
};
13+
14+
// class PrivateDerived { using BoundType = ::foo::PrivateDerived; };
15+
// class DeletedDerived { using BoundType = ::foo::DeletedDerived; };
1116

1217
}
1318

test/copymoveaccess/include/cma.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ namespace foo {
44

55
class PublicBase {
66
public:
7-
PublicBase(){}
8-
PublicBase(const PublicBase&){};
9-
PublicBase(PublicBase&&){};
7+
// PublicBase(){}
8+
// PublicBase(const PublicBase&){};
9+
// PublicBase(PublicBase&&){};
1010
};
1111

1212
class PrivateBase {

0 commit comments

Comments
 (0)