Skip to content

Commit

Permalink
Tests work locally
Browse files Browse the repository at this point in the history
  • Loading branch information
virtuald committed Oct 1, 2023
1 parent 06c0c4b commit a14baba
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 22 deletions.
51 changes: 32 additions & 19 deletions robotpy_build/autowrap/cxxparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def _is_prop_readonly(dt: DecoratedType) -> bool:
t: typing.Union[DecoratedType, FunctionType] = dt
while True:
if isinstance(t, Array):
return True
return False
elif isinstance(t, (FunctionType, MoveReference, Reference)):
return False
elif isinstance(t, Type):
Expand Down Expand Up @@ -204,14 +204,15 @@ def _fmt_base_name(typename: PQName) -> typing.Tuple[str, str, typing.List[str]]

if last_segment.specialization:
most_parts = all_parts[:-1]
all_parts.append(last_segment.format())
most_parts.append(last_segment.name)
tparam_list = [arg.format() for arg in last_segment.specialization.args]
else:
all_parts.append(last_segment.name)
most_parts = all_parts
tparam_list = []

return ("::".join(all_parts), "::".join(most_parts), tparam_list)
return ("::".join(most_parts), "::".join(all_parts), tparam_list)

# returns all names, with specialization for everything except the last
# returns all names + specialization
Expand Down Expand Up @@ -352,6 +353,8 @@ def on_namespace_start(self, state: AWNamespaceBlockState) -> None:
if not names:
# anonymous namespace items are referenced using the parent
ns = parent_ns
elif not parent_ns:
ns = "::".join(names)
else:
ns = f"{parent_ns}::{'::'.join(names)}"

Expand Down Expand Up @@ -495,17 +498,18 @@ def on_enum(self, state: AWState, enum: EnumDecl) -> None:

py_name = ""
full_cpp_name = ""
value_scope = f"{enum_scope}::{ename}"

if ename:
full_cpp_name = value_scope
full_cpp_name = f"{enum_scope}::{ename}"
py_name = self._make_py_name(ename, enum_data)

value_prefix = enum_data.value_prefix
if not value_prefix:
value_prefix = ename

strip_prefixes = [f"{value_prefix}_", value_prefix]
else:
full_cpp_name = enum_scope

for v in enum.values:
name = v.name
Expand All @@ -515,7 +519,7 @@ def on_enum(self, state: AWState, enum: EnumDecl) -> None:

values.append(
EnumeratorContext(
full_cpp_name=f"{value_scope}{name}",
full_cpp_name=f"{full_cpp_name}::{name}",
py_name=self._make_py_name(name, v_data, strip_prefixes),
doc=self._process_doc(v.doxygen, v_data, append_prefix=" "),
)
Expand All @@ -525,6 +529,7 @@ def on_enum(self, state: AWState, enum: EnumDecl) -> None:
EnumContext(
scope_var=scope_var,
var_name=var_name,
cpp_name=ename,
full_cpp_name=full_cpp_name,
py_name=py_name,
values=values,
Expand Down Expand Up @@ -679,14 +684,12 @@ def on_class_start(self, state: AWClassBlockState) -> typing.Optional[bool]:
user_typealias: typing.List[str] = []
self._extract_typealias(class_data.typealias, user_typealias, typealias_names)

full_cpp_name_identifier = cls_qualname.translate(_qualname_trans)

ctx = ClassContext(
parent=parent_ctx,
namespace=cls_namespace,
cpp_name=cls_name,
full_cpp_name=cls_qualname,
full_cpp_name_identifier=full_cpp_name_identifier,
full_cpp_name_identifier=cls_cpp_identifier,
py_name=py_name,
scope_var=scope_var,
var_name=var_name,
Expand Down Expand Up @@ -787,12 +790,9 @@ def _process_class_bases(
if ignored_bases.pop(cpp_name_w_templates, None):
continue

if cls_name == "ClassWithIgnoredBase":
breakpoint()

# Sometimes, we can't guess all the information about the base, so the
# user needs to specify it explicitly.
user_bqual = class_data.base_qualnames.get(cpp_name_w_templates)
user_bqual = class_data.base_qualnames.get(cpp_name)
if user_bqual:
cpp_name_w_templates = user_bqual
# TODO: sometimes need to add this to pybase_params, but
Expand Down Expand Up @@ -898,12 +898,15 @@ def _on_class_field(
if isinstance(f.type, Array):
is_array = True
array_size = _fmt_array_size(f.type)
cpp_type = f.type.array_of.format()
else:
cpp_type = f.type.format()

props.append(
PropContext(
py_name=py_name,
cpp_name=prop_name,
cpp_type=f.type.format(),
cpp_type=cpp_type,
readonly=prop_readonly,
doc=doc,
array_size=array_size,
Expand Down Expand Up @@ -996,6 +999,7 @@ def _on_class_method(
)

# Update class-specific method attributes
fctx.is_constructor = is_constructor
if operator:
fctx.operator = operator
self.hctx.need_operators_h = True
Expand Down Expand Up @@ -1153,7 +1157,7 @@ def on_class_end(self, state: AWClassBlockState) -> None:

trampoline_cfg = f"rpygen::PyTrampolineCfg_{cdata.cls_cpp_identifier}<{cdata.template_argument_list}>"
tname = f"rpygen::PyTrampoline_{cdata.cls_cpp_identifier}<typename {ctx.full_cpp_name}{tmpl}, typename {trampoline_cfg}>"
tvar = f"{ctx.var_name}_Trampoline"
tvar = f"{ctx.cpp_name}_Trampoline"

ctx.trampoline = TrampolineData(
full_cpp_name=tname,
Expand Down Expand Up @@ -1220,7 +1224,7 @@ def _on_fn_or_method(
pctx = self._on_fn_param(
p,
p_name,
bool(fn_disable_none),
fn_disable_none,
po,
param_remap,
)
Expand Down Expand Up @@ -1317,7 +1321,7 @@ def _on_fn_param(
self,
p: Parameter,
p_name: str,
fn_disable_none: bool,
fn_disable_none: typing.Optional[bool],
param_override: ParamData,
param_remap: typing.Dict[str, str],
):
Expand All @@ -1327,7 +1331,14 @@ def _on_fn_param(
)
self._add_type_caster(ptype)

cpp_type_no_const = ptype.format()
# TODO: get rid of this, use const by default?
if isinstance(ptype, Type) and ptype.const:
ptype.const = False
cpp_type_no_const = ptype.format()
ptype.const = True
else:
cpp_type_no_const = ptype.format()

cpp_type = cpp_type_no_const

if p_pointer:
Expand Down Expand Up @@ -1406,10 +1417,11 @@ def _on_fn_param(
asz = _fmt_array_size(ptype)

if asz is not None:
cpp_type = f"std::array<{cpp_type}, {asz}>"
cpp_type = f"std::array<{ptype.array_of.format()}, {asz}>"
call_name = f"{call_name}.data()"
if not default:
default = "{}"
self._add_user_type_caster("std::array")
else:
# it's a vector
pass
Expand Down Expand Up @@ -1855,6 +1867,7 @@ def parse_header(
inline_code=user_cfg.inline_code,
trampoline_signature=trampoline_signature,
using_signature=_using_signature,
# TODO: this isn't right?
rel_fname=str(header_path.relative_to(header_root)),
)

Expand Down Expand Up @@ -1933,7 +1946,7 @@ def main():
hctx = parse_header(
"hname",
args.header,
pathlib.Path("."),
args.header.parent,
gendata,
parser_options,
casters,
Expand Down
4 changes: 2 additions & 2 deletions robotpy_build/autowrap/generator_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@ def _process_missing(
overloads_count = len(overloads) + len(deferred_signatures)
if overloads_count > 1:
# process each deferred signature
for fn, v in deferred_signatures:
signature = self._get_function_signature(fn)
for dfn, v in deferred_signatures:
signature = self._get_function_signature(dfn)
overloads[signature] = v

has_data = all(overloads.values())
Expand Down
3 changes: 3 additions & 0 deletions robotpy_build/autowrap/j2_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ class EnumContext:
#: Name of variable in initializer
var_name: str

#: C++ name without namespace
cpp_name: str

#: C++ name, including namespace/classname
full_cpp_name: str

Expand Down
5 changes: 4 additions & 1 deletion robotpy_build/autowrap/pybind11.cpp.j2
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
{%- elif cls_qualname -%}
{{ cls_qualname }}::
{%- else -%}
{{ fn.namespace }}
{{ fn.namespace }}::
{%- endif -%}
{% if tmpl %}template {% endif %}{{ fn.cpp_name }}{{ tmpl }}
{%- else -%}
Expand Down Expand Up @@ -232,6 +232,9 @@
{% for ccls in cls.child_classes if not ccls.template %}
using {{ ccls.cpp_name }} [[maybe_unused]] = typename {{ ccls.full_cpp_name }};
{% endfor %}
{% for enum in cls.enums if enum.cpp_name %}
using {{ enum.cpp_name }} [[maybe_unused]] = typename {{ enum.full_cpp_name }};
{% endfor %}
{% for typealias in cls.auto_typealias %}
{{ typealias }};
{% endfor %}
Expand Down

0 comments on commit a14baba

Please sign in to comment.