Commit 4ef80761 authored by John Parent's avatar John Parent
Browse files

Naive unique_ptr abstract fix

parent 935f5d8a
Pipeline #231699 failed with stages
in 11 minutes and 11 seconds
......@@ -8,6 +8,7 @@ files:
classes:
UniqueHolder:
Base2:
AbBase:
functions:
take_your_ptr:
shared_base.hpp:
......
......@@ -10,6 +10,11 @@ UniqueHolder::UniqueHolder(std::unique_ptr<int> b)
this->b = std::move(b);
}
UniqueHolder::UniqueHolder(std::unique_ptr<AbBase> b)
{
this->b= std::make_unique<int>(0);
};
void UniqueHolder::take(std::unique_ptr<int> new_b)
{
this->b = std::move(new_b);
......
......@@ -10,6 +10,13 @@ public:
Base2() {}
};
class AbBase
{
public:
virtual ~AbBase() = default;
virtual void base1() = 0;
};
typedef std::unique_ptr<int> u_int_ptr;
using ub2 = std::unique_ptr<Base2>;
class UniqueHolder
......@@ -17,6 +24,7 @@ class UniqueHolder
public:
UniqueHolder();
UniqueHolder(std::unique_ptr<int> b);
UniqueHolder(std::unique_ptr<AbBase> b);
std::unique_ptr<Base2> give();
void take(std::unique_ptr<int> new_b);
u_int_ptr give_back_int(u_int_ptr a) {return a;}
......
......@@ -1124,13 +1124,28 @@ class BindingsGenerator:
if dec.templates.is_instantiation(base_decl_string):
dec_type = dec.templates.split(base_decl_string)
if "unique_ptr" in dec_type[0] and self.opts.cxx14_flag:
# so if a type is going to be the dependency of another type and
# is either in our TU or added by another mdx
# we know it's in our yaml or that other yaml so maybe we can walk though that way??
# need to look at cross loading data
# for now tho
# does pygccxml skip templates in the start with thing?
type_ = dec_type[1][0]
dec = self.name_data.decls(
name=type_, decl_type=dec.class_t, recursive=True
)[0]
if dec.is_abstract:
pass
# instead of the copy constructor new thing, rather we used move semantics or just a reference
# to construct the unique ptr
lambda_return += (
self.opts.make_unique_fmt.format(type=type_, var=name)
+ ","
)
elif "unique_ptr" in dec_type[0] and not self.opts.cxx14_flag:
type_ = dec_type[1][0]
# dcl = self.name_data.decls(name=type_,decl_type=dec.class_t, recursive=True)
lambda_return += (
self.opts.compose_unique.format(type=type_, var=name)
+ ","
......@@ -1925,100 +1940,107 @@ class BindingsGenerator:
instance_data.constructors(self.public_filter),
key=lambda c: self.get_sort_key(c),
):
if self.uses_shared_stl(constructorObj):
constructor_str += self.constructor_shared_stl_lambda(
constructorObj
)
if self.check_unique_ptr(constructorObj):
constructor_str += self.constructor_unique_lambda(
constructorObj
)
else:
arg_string = ""
arg_name_string = ","
keep_alive_str = self.generate_keep_alive_string(
constructorObj, keep_alive_dict
)
for arg in constructorObj.arguments:
if (
self.is_eigen_matrix(arg.decl_type)
and self.eigen_is_not_ref(arg.decl_type)
and self.opts.eigen_ref
):
if self.ensure_deps(constructorObj):
if self.uses_shared_stl(constructorObj):
constructor_str += self.constructor_shared_stl_lambda(
constructorObj
)
if self.check_unique_ptr(constructorObj):
constructor_str += self.constructor_unique_lambda(
constructorObj
)
else:
arg_string = ""
arg_name_string = ","
keep_alive_str = self.generate_keep_alive_string(
constructorObj, keep_alive_dict
)
for arg in constructorObj.arguments:
if (
self.is_eigen_matrix(arg.decl_type)
and self.eigen_is_not_ref(arg.decl_type)
and self.opts.eigen_ref
):
type_checks = set(
(
dec.cpptypes.reference_t,
dec.cpptypes.const_t,
type_checks = set(
(
dec.cpptypes.reference_t,
dec.cpptypes.const_t,
)
)
traits = self.get_desired_type_traits(
arg.decl_type, type_checks
)
)
traits = self.get_desired_type_traits(
arg.decl_type, type_checks
)
arg_string += (
self.add_eigen_ref_holder(
arg.decl_type.decl_string,
dec.cpptypes.const_t in traits,
dec.cpptypes.reference_t in traits,
arg_string += (
self.add_eigen_ref_holder(
arg.decl_type.decl_string,
dec.cpptypes.const_t in traits,
dec.cpptypes.reference_t in traits,
)
+ ","
)
else:
arg_string += (
arg.decl_type.decl_string + ","
)
+ ","
)
else:
arg_string += arg.decl_type.decl_string + ","
default_val = ""
if arg.default_value:
fmt_string = self.opts.arg_val_cast_fmt
# startswith is used to prevent a (<type>){val, val, val} casting string
# which is a non-standard explicit type conversion syntax error.
if (
" " in arg.decl_type.decl_string
and not arg.default_value.startswith("{")
):
fmt_string = self.opts.nullptr_arg_val_fmt
default_val = fmt_string.format(
type=arg.decl_type.decl_string.replace(
"const &", ""
).strip(),
val=arg.default_value,
default_val = ""
if arg.default_value:
fmt_string = self.opts.arg_val_cast_fmt
# startswith is used to prevent a (<type>){val, val, val} casting string
# which is a non-standard explicit type conversion syntax error.
if (
" " in arg.decl_type.decl_string
and not arg.default_value.startswith(
"{"
)
):
fmt_string = (
self.opts.nullptr_arg_val_fmt
)
default_val = fmt_string.format(
type=arg.decl_type.decl_string.replace(
"const &", ""
).strip(),
val=arg.default_value,
)
arg_name_string += self.opts.member_func_arg_fmt.format(
arg.name, default_val
)
arg_name_string += ","
arg_string = arg_string.rstrip(",")
arg_name_string = arg_name_string.rstrip(",")
# If we're using a trampoline, we need to be careful of
# the copy constructor (CC).
if tramp_methods and dec.is_copy_constructor(
constructorObj
):
cname = instance_data.decl_string
cc_keys = {
"arg_type": arg_string,
"cname": cname,
"doc": "",
"indent": self.indent,
"tramp_arg_type": arg_string.replace(
cname, tramp_name
),
"trampname": tramp_name,
}
constructor_str += self.opts.copy_constructor_tramp_fmt.format(
**cc_keys
)
arg_name_string += self.opts.member_func_arg_fmt.format(
arg.name, default_val
)
arg_name_string += ","
arg_string = arg_string.rstrip(",")
arg_name_string = arg_name_string.rstrip(",")
# If we're using a trampoline, we need to be careful of
# the copy constructor (CC).
if tramp_methods and dec.is_copy_constructor(
constructorObj
):
cname = instance_data.decl_string
cc_keys = {
"arg_type": arg_string,
"cname": cname,
"doc": "",
"indent": self.indent,
"tramp_arg_type": arg_string.replace(
cname, tramp_name
),
"trampname": tramp_name,
}
constructor_str += self.opts.copy_constructor_tramp_fmt.format(
**cc_keys
)
else:
constructor_str += self.opts.constructor_fmt.format(
arg_string,
arg_name_string,
", " if False else "",
keep_alive_str,
)
else:
constructor_str += self.opts.constructor_fmt.format(
arg_string,
arg_name_string,
", " if False else "",
keep_alive_str,
)
constructor_str += self.indent
constructor_str += self.indent
# If virtual functions are present and the class is abstract,
# we actually have to utilize the default constructor for the trampoline
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment