Commit graph

604 commits

Author SHA1 Message Date
Simon Hausmann
90a97cd737 Remove unused variable 2021-11-03 18:37:40 +01:00
Olivier Goffart
d438374792 Refactor the build_item_tree
Use a trait instead of two functions
2021-11-03 17:46:48 +01:00
Olivier Goffart
ab88e3553e Fix the item tree building for components whose base is a component
We should only visit element that are native item with the visit_item function
2021-11-03 14:59:27 +01:00
Simon Hausmann
2a8c004a7e Fix repeated elements in C++ sub-components
Delegate the visitation of dynamic children. Fixes test_cpp_models_for.
2021-11-03 12:35:32 +01:00
Simon Hausmann
88293151b1 Remove unused variable in the Rust code generator 2021-11-03 11:49:18 +01:00
Olivier Goffart
db52f8e726 Fix the C++ compilation of the gallery without inlining
Some code like this was generated:
`if (*self->checkbox_31.get_checked()).get()`
the remove_parentheses function removed a parentheses that it shouldn't have removed
2021-11-03 11:48:05 +01:00
Simon Hausmann
8ddd01ad9a Remove unused variable in the C++ code generator 2021-11-03 11:40:24 +01:00
Simon Hausmann
76b4d7ec75 Remove trailing whitespace 2021-11-03 10:53:40 +01:00
Simon Hausmann
a0c644ab25 Fix compilation of root_item() implementation for the ComponentVTable in C++
... when the root item is a sub-component.
2021-11-03 10:47:11 +01:00
Simon Hausmann
da169b0e3c Fix calling focus() in sub-components when inlining is disabled
focus() is implemented by calling set_focus() on the window with the absolute item
index as a parameter. The
generate_item_indices pass generates local item indicies,
which need to made absolute.

Sadly there exists a gap in the item tree between the root element of a sub-component
and its children. Therefore each sub-component gets two members passed to the constructor,
the tree_index and tree_index_of_first_child.
The former is to be used when the local index is zero (indicates the root).
The latter is used as base for any children.
2021-11-03 09:45:35 +01:00
Simon Hausmann
dd9f6787fd Silence clang warning about unused m_root variable
The variable in C++ sub-components is sometimes unused. We could try to lazily emit it, but
that requires more work and this is distracting :-). This silencing should hopefully also work for gcc.
2021-11-02 20:58:32 +01:00
Simon Hausmann
88d050d8ce Revert "Silence warning about unused m_root member in C++ sub-components"
This reverts commit fde3846392 because it
breaks the gcc build ("error: 'maybe_unused' attribute ignored
[-Werror=attributes]"). Will need a different solution that works for
clang (which warns about m_root_ being unused).
2021-11-02 11:56:08 +01:00
Olivier Goffart
4b73cce76e C++: make the member funciton layout_info and root_item const
It might be called with a const pointer
2021-11-02 11:49:30 +01:00
Simon Hausmann
fde3846392 Silence warning about unused m_root member in C++ sub-components
There are a few things we could probably do lazily in the code generator, but
for now this is distracting :-)
2021-11-02 11:29:07 +01:00
Olivier Goffart
e17e035251 Fix warning about unused variable in the C++ generated code 2021-11-02 09:58:26 +01:00
Olivier Goffart
08c1d875d3 C++: The property getter should be const
Because it is sompetimes used with const pointers
2021-11-02 09:51:38 +01:00
Olivier Goffart
54f9ccfa8e Add all repeated components as friend of the root items
They need to be in order to access the globals

Now the test_cpp_models_for compiles, but it crashes at runtime
2021-11-02 09:20:48 +01:00
Simon Hausmann
167fa790fe Fix initialization of self_weak in sub-components in C++
Calling init on sub-components with self_weak as argument only works after self_weak is
initialized, which happens in create(). So a new init() function for root components is called afterwards.
2021-11-01 20:04:46 +01:00
Simon Hausmann
14cb0520a9 Fix drop implementation of Rust generated code
Call free_graphics_resources, not init_items %-)

Amends commit 67579ec560
2021-11-01 18:50:33 +01:00
Olivier Goffart
efa1448565 C++: Pass the right root pointer 2021-11-01 17:04:31 +01:00
Olivier Goffart
789ac719eb Make the parent_item function work with repeater component 2021-11-01 16:11:38 +01:00
Olivier Goffart
199fe1c676 C++: fix warning about unused variable and unordered initialization 2021-11-01 14:09:28 +01:00
Simon Hausmann
096fbab93d Simplify the destructor of generated C++ components
Similar to the parent commit, avoid creating an array of item refs and pass the item tree instead
to a run-time helper function.
2021-11-01 10:19:17 +01:00
Simon Hausmann
67579ec560 Simplify drop implementation of generated components
Avoid creating an intermediate array of items to free the graphics resources.
Instead call run-time function with the item tree as a parameter, which is traversed.

It's practically the same data structure that was previously created, except
that it is shared/global and has little holes for the dynamic tree items, but those are easy to skip.
2021-11-01 08:58:53 +01:00
Simon Hausmann
d57edfbb7c Simplify free_graphics_resources API in the backend
Take an iterator reference instead of a slice, so that we can change the call sites in the future.
2021-10-30 13:03:52 +02:00
Simon Hausmann
db64d30a29 First attempt at fixing the item tree for sub-components
By accident the tree was still depth-first instead of level-order. This implementation works better,
by placing the root element of sub-components as
parents and the children into the children space later.

There's still more work to do to clean it up and make work with more complex scenarios.
2021-10-29 19:05:25 +02:00
Simon Hausmann
f205a2806c Fix accessing aliases on sub-components in C++
When the use-site of a component tries to set a binding on a property that is an alias,
it might be that the alias was optimized away.

To avoid needeless recursion, this patch generates a mutable property getter
for declared properties (which takes care of alias redirection).

This also removes the use of root_item() because it's insufficient: If the property is custom (and/or an alias), then we need to use the getter,
otherwise we need to recurse.

So there are three cases:

```
MyButton {
    text: "Ok";
}
```

If `MyButton` is `MyButton := Rectangle { property<string> text; }` then
we go through the mutable prop reference getter. This also works for aliases.
If it's `MyButton := Text { ... }` or (more complex) `L := Text {} MyButton := L {}` then
we recurse.

Traditionally the recursion is not needed because in public API the "inherited" properties
aren't expose. But since in the language they are exposed, we need to continue.

As a bonus this cleans up the property access code a little by re-using access_member.
2021-10-29 14:10:43 +02:00
Simon Hausmann
efc09dd17b Fix setting bindings at use-site on custom properties of sub-components in C++
* Make sure the fields are public
* Detect when the target property is not in the item itself but a custom property
2021-10-29 11:15:56 +02:00
Simon Hausmann
342d908a10 Fix build of bindings in sub-components in C++ that access the window
To keep the rest of the C++ generator simpler, let's also add an m_window member
2021-10-29 10:56:23 +02:00
Simon Hausmann
8dbf78c95d Fix access to globals from within sub-components in C++
* Forward declare the root component
* Pass it as a parameter to the constructor and save it as m_root pointer and use it to access globals
* Make the sub-components friends of the root component, in order to access the globals
* Delay binding initialization to an explicit init() call in sub-components
2021-10-29 10:32:25 +02:00
Simon Hausmann
ae25dd3d07 Fix calls to BuiltinFunction::ImplicitLayoutInfo for sub-components in C++
Provide a layout_info implementation for sub-components and call it. This
disables the lowering the implicit_layout_info call again,
also to ensure that when this
is installed from the use-site of the sub-component, the self can be used to obtain
the info (by calling the new generated function).
2021-10-28 21:49:07 +02:00
Simon Hausmann
08c49a5ff4 Fix call to free_graphics_resources in C++ when using sub-components
The fields in item_names_and_vt_symbols need to be prefixed with the sub-component field names.
2021-10-28 16:56:49 +02:00
Simon Hausmann
59898429e8 Fix compilation of bindings on sub-components in C++
We need to install them on the root item (which can be subject to indirection).
2021-10-28 16:44:30 +02:00
Simon Hausmann
8efca487dd Fix access rights of fields in sub-components
They need to be public for now,
in order to install bindings from
the use-site.
2021-10-28 16:31:43 +02:00
Simon Hausmann
d64990460f Fix access of sub-component fields in the root component
Make them private
2021-10-28 16:25:56 +02:00
Simon Hausmann
5c5d9b7988 Fix broken constructor calls to sub-components in C++
The constructor needs to be accessible.
2021-10-28 16:05:56 +02:00
Simon Hausmann
529db12ee8 Fix child offset in the item tree when using sub-components
The base is advanced by taking the item index of the element that has the sub-component base type,
not the one of the root element or any children.
2021-10-28 15:52:29 +02:00
Simon Hausmann
cebb415b08 Replace two uses of build_array_helper with a new recurse_elem variant
For the item index generation and the member population for the C++
structs, a level-order variant of `recurse_elem` is sufficient - as also
indicate by the unused item index parameters.
2021-10-28 15:52:29 +02:00
Simon Hausmann
90abcf3066 WIP: Implement item tree generation for sub-components in C++
In the generator for producing the members of built-in items, repeaters
or sub-components, we don't need to traverse into sub-components. The
C++ compiler will take care of instantiating the fields of
sub-components after all.

For the item tree however we do need to recurse, so this change attempts
to do that. Repeaters are explicitly not handled yet though.
2021-10-28 15:52:29 +02:00
Simon Hausmann
467a02310c Fix assert in C++ code generator when using repeated sub-components
Instead of requiring inlining, assume that the generated code will provide an
implementation of layouting_info as well as root_item.

They're not implemented yet though.
2021-10-28 15:52:29 +02:00
Simon Hausmann
125a2ae125 C++ generator: forward the sub-component start indicies
Within sub-components we only know the local item index, and together with the
offset provided in the constructor we'll be able to
compute the correct index for items that's needed sometimes,
for example for focus setting.

The item indices are still wrong though, that'll need fixing in the corresponding pass.
2021-10-28 15:52:29 +02:00
Simon Hausmann
d0216a4291 C++ generator: don't generate m_window and self_weak for sub-components 2021-10-28 15:52:29 +02:00
Simon Hausmann
2a7976abda C++ generator: generate members for sub-components 2021-10-28 15:52:29 +02:00
Simon Hausmann
98f6cab553 Make it easier to distinguish between the component types in the generators
Besides `is_global()` add `is_root_component` to Rc<Component>, so that
we can distinguish between the main component (that should have the full
API, etc.) and supplementary components.

This also avoids the generation of unnecessary members when inlining is
disabled.
2021-10-28 15:52:29 +02:00
Simon Hausmann
5e7175b1e3 C++ generator: Don't generate a class initialize for the m_window member for child components
The constructor initializes it property, so don't generate code that
when read might give the false impression that we allocate a new window.
2021-10-28 15:52:29 +02:00
Simon Hausmann
9028f69f27 C++ generator cleanup: Remove supplementary_components field again
This amends the parent commit, we don't need a separate vec, after
inlining the sub_components should simply be empty.
2021-10-28 15:52:29 +02:00
Simon Hausmann
b5f4a2c27c C++ generator: begin generating code for supplementary components
The generation is still incomplete, but this change passes them to the C++ generator
when not inlining.

Another option would've been a "inline: bool", but that won't suffice in
the future when we may want to use heuristics to selectively inline some
and others not. And always taking used_types.sub_components is wrong
when inlining as those are ... inlined.
2021-10-28 15:52:29 +02:00
Simon Hausmann
4183c7122b C++ generator cleanup: move component vtable generation into a helper function
Despite only being called from one place, this reduces the size
of `generate_component`, in an effort to make it more readable.
2021-10-28 15:52:29 +02:00
Simon Hausmann
007fe36839 C++ Generator: more cleanups
Move all `!component.is_global()` related code generation into one block.
2021-10-28 15:52:29 +02:00
Simon Hausmann
545ec38ed3 C++ generator: minor cleanup
Also de-duplicate the self_weak member emission
2021-10-28 15:52:29 +02:00