Commit 1bc1d768 authored by John Parent's avatar John Parent
Browse files

capture all relevant stl pygccxml data

Normalize user provided stl container instantiations
write out public API of stl containers to binding code to support opaque
type
parent 98f2a516
......@@ -14,6 +14,9 @@ stl:
stl_bind: True
"Int2Double" :
type: ["int", "double"]
"VectoVec" :
type: [std::vector<std::string>,std::vector<int>]
stl_bind: True
files:
stl_container.h:
classes:
......
......@@ -858,22 +858,32 @@ class BindingsGenerator:
"""
# We know that any type we are looking for is within the STD namespace
# so we can avoid a recursive search and limit ourselves to the STD namespace
std = pygccxml_data.namespace(name="std")
# further avoid RT increase by leveraging decl_type looking for class_t
stl_data = []
for container in self.stl_binders:
if container.stl_bind:
try:
stl_data.append(
std.decl(
lambda dec: dec.partial_decl_string
== container.get_partial_decl(),
decl_type=dec.class_declaration.class_t,
try:
std = pygccxml_data.namespace(name="std")
except:
return []
finally:
# further avoid RT increase by leveraging decl_type looking for class_t
stl_data = []
for container in self.stl_binders:
if container.stl_bind:
try:
stl_data.append(
std.decl(
lambda declaration: dec.templates.normalize(
self.derive_stl_defaults(
declaration.partial_decl_string
)
)
== dec.templates.normalize(
container.get_partial_decl()
),
decl_type=dec.class_declaration.class_t,
)
)
)
except pygccxml.declarations.runtime_errors.declaration_not_found_t:
continue
return stl_data
except pygccxml.declarations.runtime_errors.declaration_not_found_t:
continue
return stl_data
def generate_stl_class_bindings(self, container, pygccxml_data):
"""
......@@ -2423,6 +2433,20 @@ class BindingsGenerator:
self.write_data_to_file(module_cpp_file, module_cpp_text, ".cpp")
return module_cpp_file
def recursive_replace_basic_string(self, template_str):
if self.is_templated(template_str):
call, insts = dec.templates.split(template_str)
if "basic_string" in call:
return self.replace_basic_string(call)
for inst in range(len(insts)):
insts[inst] = self.recursive_replace_basic_string(insts[inst])
return dec.templates.join(call, insts)
else:
return self.replace_basic_string(template_str)
def replace_basic_string(self, template_str):
return template_str.replace("basic_string", "string")
def format_member_insts(
self, module_info, member_insts, class_inst, class_name
):
......@@ -2705,6 +2729,12 @@ class BindingsGenerator:
struct_body += template_str.format(container.cpp_name, num)
return self.opts.stl_struct.format(body=struct_body)
def derive_stl_defaults(self, stl_partial_decl):
stl_partial_decl = self.recursive_replace_basic_string(
stl_partial_decl
)
return stl_partial_decl
def clean_flags(self, rsp_path):
rsp_includes = []
rsp_indx_files = []
......
......@@ -250,21 +250,21 @@ class stl_binder(object):
return (
other.inst_type == self.inst_type
and other.type == self.type
and other.name == self.name
and other.cpp_name == self.cpp_name
)
def __hash__(self):
return hash(
(self.cpp_name, self.stl_bind, self.mod_loc, self.buffer_protocol)
(self.cpp_name, self.type, "-".join(sorted(self.inst_type)))
)
def __create_cpp_name(self, type_, inst):
inst_str = ""
if type(self.inst_type) is list:
inst_str = ", ".join(inst)
inst_str = ",".join(inst)
else:
inst_str = inst
return "std::" + type_ + "< " + inst_str + " >"
return "std::" + type_ + "<" + inst_str + ">"
def get_partial_decl(self):
return "::" + self.cpp_name
......
Supports Markdown
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