Skip to content

Commit a889ac1

Browse files
wip fixing figouring out move ctors
1 parent 57f27fd commit a889ac1

File tree

8 files changed

+107
-14
lines changed

8 files changed

+107
-14
lines changed

CMakeLists.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ project(cppmm)
44
include(GNUInstallDirs)
55

66
set(CPPMM_MAJOR_VERSION 0)
7-
set(CPPMM_MINOR_VERSION 9)
7+
set(CPPMM_MINOR_VERSION 10)
88
set(CPPMM_PATCH_VERSION 0)
99
set(CPPMM_VERSION "${CPPMM_MAJOR_VERSION}.${CPPMM_MINOR_VERSION}.${CPPMM_PATCH_VERSION}")
1010

@@ -59,3 +59,4 @@ add_subdirectory(test/property)
5959
add_subdirectory(test/opaquebytes)
6060
add_subdirectory(test/deriveattr)
6161
add_subdirectory(test/mimpl)
62+
add_subdirectory(test/copymoveaccess)

astgen/src/process_binding.cpp

+24-2
Original file line numberDiff line numberDiff line change
@@ -1024,6 +1024,24 @@ bool is_public_copy_ctor(const Decl* cmd) {
10241024
}
10251025
}
10261026

1027+
bool is_inaccessible_copy_ctor(const Decl* cmd) {
1028+
if (const CXXConstructorDecl* cd = dyn_cast<CXXConstructorDecl>(cmd)) {
1029+
return cd->isCopyConstructor() && (cd->getAccess() != AS_public ||
1030+
cd->isDeleted());
1031+
} else {
1032+
return false;
1033+
}
1034+
}
1035+
1036+
bool is_inaccessible_move_ctor(const Decl* cmd) {
1037+
if (const CXXConstructorDecl* cd = dyn_cast<CXXConstructorDecl>(cmd)) {
1038+
return cd->isMoveConstructor() && (cd->getAccess() != AS_public ||
1039+
cd->isDeleted());
1040+
} else {
1041+
return false;
1042+
}
1043+
}
1044+
10271045
bool is_public_move_ctor(const Decl* cmd) {
10281046
if (const CXXConstructorDecl* cd = dyn_cast<CXXConstructorDecl>(cmd)) {
10291047
SPDLOG_DEBUG("ctor {}", cd->getQualifiedNameAsString());
@@ -1041,9 +1059,13 @@ void has_public_copy_move_ctor(const CXXRecordDecl* crd,
10411059
bool& has_public_copy_ctor,
10421060
bool& has_public_move_ctor) {
10431061
for (const Decl* d : crd->decls()) {
1044-
has_public_copy_ctor |= is_public_copy_ctor(d);
1045-
has_public_move_ctor |= is_public_move_ctor(d);
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);
10461066
}
1067+
has_public_copy_ctor = !has_public_copy_ctor;
1068+
has_public_move_ctor = !has_public_move_ctor;
10471069
}
10481070

10491071
std::vector<std::string> get_properties(const std::vector<std::string>& attrs) {

asttoc/src/cppmm_ast_add_c.cpp

+12-8
Original file line numberDiff line numberDiff line change
@@ -1866,8 +1866,8 @@ void to_c_copy__trivial(TranslationUnit& c_tu,
18661866
Param("rhs", rhs, 1)};
18671867
auto c_function = NodeFunction::n(
18681868
function_name, PLACEHOLDER_ID, attrs, "",
1869-
NodeBuiltinType::n("void", 0, "void", false), std::move(params), "", "", "",
1870-
std::vector<NodeTypePtr>{}, std::vector<Exception>{}, false);
1869+
NodeBuiltinType::n("void", 0, "void", false), std::move(params), "", "",
1870+
"", std::vector<NodeTypePtr>{}, std::vector<Exception>{}, false);
18711871

18721872
c_function->body = c_function_body;
18731873
c_function->private_ = true;
@@ -2167,7 +2167,10 @@ void to_c_copy__constructor(TranslationUnit& c_tu, const NodeRecord& cpp_record,
21672167
//------------------------------------------------------------------------------
21682168
void to_c_move(TranslationUnit& c_tu, const NodeRecord& cpp_record,
21692169
const NodeRecord& c_record) {
2170-
auto rhs = NodeRecordType::n("", 0, cpp_record.name, cpp_record.id, false);
2170+
auto rhs_inner =
2171+
NodeRecordType::n("", 0, cpp_record.name, cpp_record.id, false);
2172+
auto rhs =
2173+
NodePointerType::n(PointerKind::Pointer, std::move(rhs_inner), false);
21712174

21722175
auto c_return =
21732176
NodeRecordType::n("", 0, c_record.nice_name, c_record.id, false);
@@ -2176,12 +2179,13 @@ void to_c_move(TranslationUnit& c_tu, const NodeRecord& cpp_record,
21762179
NodeBlockExpr::n(std::vector<NodeExprPtr>{NodePlacementNewExpr::n(
21772180
NodeVarRefExpr::n("lhs"),
21782181

2179-
NodeFunctionCallExpr::n(cpp_record.name,
2180-
std::vector<NodeExprPtr>{NodeMoveExpr::n(
2181-
NodeVarRefExpr::n("rhs"))},
2182-
std::vector<NodeTypePtr>{}
2182+
NodeFunctionCallExpr::n(
2183+
cpp_record.name,
2184+
std::vector<NodeExprPtr>{
2185+
NodeMoveExpr::n(NodeDerefExpr::n(NodeVarRefExpr::n("rhs")))},
2186+
std::vector<NodeTypePtr>{}
21832187

2184-
))});
2188+
))});
21852189

21862190
auto lhs =
21872191
NodePointerType::n(PointerKind::Pointer, std::move(c_return), false);

include/cppmm_config.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#pragma once
22

33
#define CPPMM_MAJOR_VERSION 0
4-
#define CPPMM_MINOR_VERSION 9
4+
#define CPPMM_MINOR_VERSION 10
55
#define CPPMM_PATCH_VERSION 0
66

77
namespace cppmm {
88

99
inline const char* version() {
10-
return "0.9.0";
10+
return "0.10.0";
1111
}
1212

1313
}

package.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name = 'cppmm'
2-
version = '0.9.0'
2+
version = '0.10.0'
33

44
def commands():
55
env.PATH.append('{root}/bin')

test/copymoveaccess/CMakeLists.txt

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
set(testname copymoveaccess)
2+
3+
add_test(NAME ${testname}
4+
COMMAND
5+
python
6+
${CMAKE_SOURCE_DIR}/test/runtest.py
7+
$<TARGET_FILE:astgen>
8+
$<TARGET_FILE:asttoc>
9+
${CMAKE_CURRENT_SOURCE_DIR}/bind
10+
${CMAKE_BINARY_DIR}/test/${testname}/output
11+
${testname}
12+
${CMAKE_CURRENT_SOURCE_DIR}/ref
13+
-I${CMAKE_CURRENT_SOURCE_DIR}/include
14+
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
15+
)
16+
17+

test/copymoveaccess/bind/cma.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include <cma.hpp>
2+
#include <cppmm_bind.hpp>
3+
4+
namespace cppmm_bind {
5+
6+
namespace foo {
7+
8+
class PublicDerived { using BoundType = ::foo::PublicDerived; };
9+
class PrivateDerived { using BoundType = ::foo::PrivateDerived; };
10+
class DeletedDerived { using BoundType = ::foo::DeletedDerived; };
11+
12+
}
13+
14+
}
15+

test/copymoveaccess/include/cma.hpp

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#pragma once
2+
3+
namespace foo {
4+
5+
class PublicBase {
6+
public:
7+
PublicBase(){}
8+
PublicBase(const PublicBase&){};
9+
PublicBase(PublicBase&&){};
10+
};
11+
12+
class PrivateBase {
13+
public:
14+
PrivateBase(){}
15+
16+
private:
17+
PrivateBase(const PrivateBase&){};
18+
PrivateBase(PrivateBase&&){};
19+
};
20+
21+
class DeletedBase {
22+
public:
23+
DeletedBase(){}
24+
25+
private:
26+
DeletedBase(const DeletedBase&)=delete;
27+
DeletedBase(DeletedBase&&)=delete;
28+
};
29+
30+
class PublicDerived: public PublicBase {};
31+
class PrivateDerived: public PrivateBase {};
32+
class DeletedDerived: public DeletedBase {};
33+
34+
}

0 commit comments

Comments
 (0)