C++: don't re-export private symbol in the public API

Use the cbindgen_private namespace dirrectly from the generated code
This commit is contained in:
Olivier Goffart 2021-06-28 11:45:01 +02:00
parent 16ba23ae47
commit ae114cf79d
7 changed files with 39 additions and 91 deletions

View file

@ -40,24 +40,17 @@ using ComponentRef = vtable::VRef<private_api::ComponentVTable>;
using ItemRef = vtable::VRef<private_api::ItemVTable>; using ItemRef = vtable::VRef<private_api::ItemVTable>;
using ItemVisitorRefMut = vtable::VRefMut<cbindgen_private::ItemVisitorVTable>; using ItemVisitorRefMut = vtable::VRefMut<cbindgen_private::ItemVisitorVTable>;
using cbindgen_private::ItemWeak; using cbindgen_private::ItemWeak;
}
using cbindgen_private::ComponentRc; using cbindgen_private::ComponentRc;
using cbindgen_private::EasingCurve;
using cbindgen_private::EventResult;
using cbindgen_private::FillRule;
using cbindgen_private::ImageFit;
using cbindgen_private::KeyboardModifiers;
using cbindgen_private::KeyEvent;
using cbindgen_private::PropertyAnimation;
using cbindgen_private::Slice;
using cbindgen_private::TextHorizontalAlignment;
using cbindgen_private::TextOverflow;
using cbindgen_private::TextVerticalAlignment;
using cbindgen_private::TextWrap;
using cbindgen_private::TraversalOrder; using cbindgen_private::TraversalOrder;
}
// FIXME: this should not be public API
using cbindgen_private::Slice;
namespace private_api { namespace private_api {
using ItemTreeNode = cbindgen_private::ItemTreeNode<uint8_t>; using ItemTreeNode = cbindgen_private::ItemTreeNode<uint8_t>;
using cbindgen_private::KeyboardModifiers;
using cbindgen_private::KeyEvent;
class ComponentWindow class ComponentWindow
{ {
@ -115,36 +108,7 @@ public:
private: private:
cbindgen_private::ComponentWindowOpaque inner; cbindgen_private::ComponentWindowOpaque inner;
}; };
}
using cbindgen_private::BorderRectangle;
using cbindgen_private::BoxShadow;
using cbindgen_private::Clip;
using cbindgen_private::ClippedImage;
using cbindgen_private::Flickable;
using cbindgen_private::FocusScope;
using cbindgen_private::ImageItem;
using cbindgen_private::Opacity;
using cbindgen_private::Path;
using cbindgen_private::Rectangle;
using cbindgen_private::Rotate;
using cbindgen_private::Text;
using cbindgen_private::TextInput;
using cbindgen_private::TouchArea;
using cbindgen_private::Window;
using cbindgen_private::NativeButton;
using cbindgen_private::NativeCheckBox;
using cbindgen_private::NativeComboBox;
using cbindgen_private::NativeGroupBox;
using cbindgen_private::NativeLineEdit;
using cbindgen_private::NativeScrollView;
using cbindgen_private::NativeSlider;
using cbindgen_private::NativeSpinBox;
using cbindgen_private::NativeStandardListViewItem;
using cbindgen_private::NativeStyleMetrics;
namespace private_api {
constexpr inline ItemTreeNode make_item_node(std::uintptr_t offset, constexpr inline ItemTreeNode make_item_node(std::uintptr_t offset,
const cbindgen_private::ItemVTable *vtable, const cbindgen_private::ItemVTable *vtable,
uint32_t child_count, uint32_t child_index, uint32_t child_count, uint32_t child_index,
@ -177,16 +141,6 @@ inline ItemWeak parent_item(cbindgen_private::ComponentWeak component,
} }
} }
}
using cbindgen_private::FocusEvent;
using cbindgen_private::InputEventResult;
using cbindgen_private::KeyEvent;
using cbindgen_private::KeyEventResult;
using cbindgen_private::MouseEvent;
using cbindgen_private::sixtyfps_visit_item_tree;
namespace private_api {
inline void dealloc(const ComponentVTable *, uint8_t *ptr, vtable::Layout layout) inline void dealloc(const ComponentVTable *, uint8_t *ptr, vtable::Layout layout)
{ {
#ifdef __cpp_sized_deallocation #ifdef __cpp_sized_deallocation
@ -645,16 +599,16 @@ public:
} // namespace private_api } // namespace private_api
#if !defined(DOXYGEN) #if !defined(DOXYGEN)
Flickable::Flickable() cbindgen_private::Flickable::Flickable()
{ {
sixtyfps_flickable_data_init(&data); sixtyfps_flickable_data_init(&data);
} }
Flickable::~Flickable() cbindgen_private::Flickable::~Flickable()
{ {
sixtyfps_flickable_data_free(&data); sixtyfps_flickable_data_free(&data);
} }
NativeStyleMetrics::NativeStyleMetrics() cbindgen_private::NativeStyleMetrics::NativeStyleMetrics()
{ {
sixtyfps_init_native_style_metrics(this); sixtyfps_init_native_style_metrics(this);
} }

View file

@ -31,7 +31,7 @@ inline void send_mouse_click(const Component *component, float x, float y)
template<typename Component> template<typename Component>
inline void send_keyboard_string_sequence(const Component *component, inline void send_keyboard_string_sequence(const Component *component,
const sixtyfps::SharedString &str, const sixtyfps::SharedString &str,
KeyboardModifiers modifiers = {}) cbindgen_private::KeyboardModifiers modifiers = {})
{ {
cbindgen_private::send_keyboard_string_sequence(&str, modifiers, &component->window); cbindgen_private::send_keyboard_string_sequence(&str, modifiers, &component->window);
} }

View file

@ -111,7 +111,7 @@ export TouchArea := _ {
} }
export struct KeyboardModifiers := { export struct KeyboardModifiers := {
//-name:sixtyfps::KeyboardModifiers //-name:sixtyfps::private_api::KeyboardModifiers
alt: bool, alt: bool,
control: bool, control: bool,
shift: bool, shift: bool,
@ -119,7 +119,7 @@ export struct KeyboardModifiers := {
} }
export struct KeyEvent := { export struct KeyEvent := {
//-name:sixtyfps::KeyEvent //-name:sixtyfps::private_api::KeyEvent
text: string, text: string,
modifiers: KeyboardModifiers, modifiers: KeyboardModifiers,
} }

View file

@ -246,7 +246,7 @@ impl CppType for Type {
Type::Bool => Some("bool".to_owned()), Type::Bool => Some("bool".to_owned()),
Type::Struct { name: Some(name), node: Some(_), .. } => Some(name.clone()), Type::Struct { name: Some(name), node: Some(_), .. } => Some(name.clone()),
Type::Struct { name: Some(name), node: None, .. } => { Type::Struct { name: Some(name), node: None, .. } => {
Some(format!("sixtyfps::{}", name)) Some(format!("sixtyfps::cbindgen_private::{}", name))
} }
Type::Struct { fields, .. } => { Type::Struct { fields, .. } => {
let elem = fields.values().map(|v| v.cpp_type()).collect::<Option<Vec<_>>>()?; let elem = fields.values().map(|v| v.cpp_type()).collect::<Option<Vec<_>>>()?;
@ -257,7 +257,9 @@ impl CppType for Type {
Type::Array(i) => Some(format!("std::shared_ptr<sixtyfps::Model<{}>>", i.cpp_type()?)), Type::Array(i) => Some(format!("std::shared_ptr<sixtyfps::Model<{}>>", i.cpp_type()?)),
Type::Image => Some("sixtyfps::Image".to_owned()), Type::Image => Some("sixtyfps::Image".to_owned()),
Type::Builtin(elem) => elem.native_class.cpp_type.clone(), Type::Builtin(elem) => elem.native_class.cpp_type.clone(),
Type::Enumeration(enumeration) => Some(format!("sixtyfps::{}", enumeration.name)), Type::Enumeration(enumeration) => {
Some(format!("sixtyfps::cbindgen_private::{}", enumeration.name))
}
Type::Brush => Some("sixtyfps::Brush".to_owned()), Type::Brush => Some("sixtyfps::Brush".to_owned()),
Type::LayoutCache => Some("sixtyfps::SharedVector<float>".into()), Type::LayoutCache => Some("sixtyfps::SharedVector<float>".into()),
_ => None, _ => None,
@ -313,7 +315,11 @@ fn new_struct_with_bindings(
} }
fn property_animation_code(component: &Rc<Component>, animation: &ElementRc) -> String { fn property_animation_code(component: &Rc<Component>, animation: &ElementRc) -> String {
new_struct_with_bindings("sixtyfps::PropertyAnimation", &animation.borrow().bindings, component) new_struct_with_bindings(
"sixtyfps::cbindgen_private::PropertyAnimation",
&animation.borrow().bindings,
component,
)
} }
fn property_set_value_code( fn property_set_value_code(
@ -425,7 +431,7 @@ fn handle_property_binding(
}); });
format!( format!(
"{}.set_animated_binding_for_transition({}, "{}.set_animated_binding_for_transition({},
[this](uint64_t *start_time) -> sixtyfps::PropertyAnimation {{ [this](uint64_t *start_time) -> sixtyfps::cbindgen_private::PropertyAnimation {{
[[maybe_unused]] auto self = this; [[maybe_unused]] auto self = this;
auto state = {}; auto state = {};
*start_time = state.change_time; *start_time = state.change_time;
@ -450,7 +456,7 @@ fn handle_item(elem: &ElementRc, main_struct: &mut Struct) {
main_struct.members.push(( main_struct.members.push((
Access::Private, Access::Private,
Declaration::Var(Var { Declaration::Var(Var {
ty: format!("sixtyfps::{}", item.base_type.as_native().class_name), ty: format!("sixtyfps::cbindgen_private::{}", item.base_type.as_native().class_name),
name: item.id.clone(), name: item.id.clone(),
init: Some("{}".to_owned()), init: Some("{}".to_owned()),
}), }),
@ -1027,7 +1033,7 @@ fn generate_component(
} else { } else {
if item.is_flickable_viewport { if item.is_flickable_viewport {
tree_array.push(format!( tree_array.push(format!(
"sixtyfps::private_api::make_item_node(offsetof({}, {}) + offsetof(sixtyfps::Flickable, viewport), SIXTYFPS_GET_ITEM_VTABLE(RectangleVTable), {}, {}, {})", "sixtyfps::private_api::make_item_node(offsetof({}, {}) + offsetof(sixtyfps::cbindgen_private::Flickable, viewport), SIXTYFPS_GET_ITEM_VTABLE(RectangleVTable), {}, {}, {})",
&component_id, &component_id,
crate::object_tree::find_parent_element(item_rc).unwrap().borrow().id, crate::object_tree::find_parent_element(item_rc).unwrap().borrow().id,
item.children.len(), item.children.len(),
@ -1124,15 +1130,15 @@ fn generate_component(
Access::Private, Access::Private,
Declaration::Function(Function { Declaration::Function(Function {
name: "visit_children".into(), name: "visit_children".into(),
signature: "(sixtyfps::private_api::ComponentRef component, intptr_t index, sixtyfps::TraversalOrder order, sixtyfps::private_api::ItemVisitorRefMut visitor) -> int64_t".into(), signature: "(sixtyfps::private_api::ComponentRef component, intptr_t index, sixtyfps::private_api::TraversalOrder order, sixtyfps::private_api::ItemVisitorRefMut visitor) -> int64_t".into(),
is_static: true, is_static: true,
statements: Some(vec![ statements: Some(vec![
"static const auto dyn_visit = [] (const uint8_t *base, [[maybe_unused]] sixtyfps::TraversalOrder order, [[maybe_unused]] sixtyfps::private_api::ItemVisitorRefMut visitor, uintptr_t dyn_index) -> int64_t {".to_owned(), "static const auto dyn_visit = [] (const uint8_t *base, [[maybe_unused]] sixtyfps::private_api::TraversalOrder order, [[maybe_unused]] sixtyfps::private_api::ItemVisitorRefMut visitor, uintptr_t dyn_index) -> int64_t {".to_owned(),
format!(" [[maybe_unused]] auto self = reinterpret_cast<const {}*>(base);", component_id), format!(" [[maybe_unused]] auto self = reinterpret_cast<const {}*>(base);", component_id),
format!(" switch(dyn_index) {{ {} }};", children_visitor_cases.join("")), format!(" switch(dyn_index) {{ {} }};", children_visitor_cases.join("")),
" std::abort();\n};".to_owned(), " std::abort();\n};".to_owned(),
format!("auto self_rc = reinterpret_cast<const {}*>(component.instance)->self_weak.lock()->into_dyn();", component_id), format!("auto self_rc = reinterpret_cast<const {}*>(component.instance)->self_weak.lock()->into_dyn();", component_id),
"return sixtyfps::sixtyfps_visit_item_tree(&self_rc, item_tree() , index, order, visitor, dyn_visit);".to_owned(), "return sixtyfps::cbindgen_private::sixtyfps_visit_item_tree(&self_rc, item_tree() , index, order, visitor, dyn_visit);".to_owned(),
]), ]),
..Default::default() ..Default::default()
}), }),
@ -1243,7 +1249,9 @@ fn generate_component(
for glob in component.used_global.borrow().iter() { for glob in component.used_global.borrow().iter() {
let ty = match &glob.root_element.borrow().base_type { let ty = match &glob.root_element.borrow().base_type {
Type::Void => self::component_id(glob), Type::Void => self::component_id(glob),
Type::Builtin(b) => format!("sixtyfps::{}", b.native_class.class_name), Type::Builtin(b) => {
format!("sixtyfps::cbindgen_private::{}", b.native_class.class_name)
}
_ => unreachable!(), _ => unreachable!(),
}; };
component_struct.members.push(( component_struct.members.push((
@ -1575,7 +1583,7 @@ fn compile_expression(
let item = item.upgrade().unwrap(); let item = item.upgrade().unwrap();
let item = item.borrow(); let item = item.borrow();
let native_item = item.base_type.as_native(); let native_item = item.base_type.as_native();
format!("{vt}->layouting_info({{{vt}, const_cast<sixtyfps::{ty}*>(&self->{id})}}, {o}, &window)", format!("{vt}->layouting_info({{{vt}, const_cast<sixtyfps::cbindgen_private::{ty}*>(&self->{id})}}, {o}, &window)",
vt = native_item.cpp_vtable_getter, vt = native_item.cpp_vtable_getter,
ty = native_item.class_name, ty = native_item.class_name,
id = item.id, id = item.id,
@ -1682,9 +1690,9 @@ fn compile_expression(
} }
} }
Expression::PathElements { elements } => compile_path(elements, component), Expression::PathElements { elements } => compile_path(elements, component),
Expression::EasingCurve(EasingCurve::Linear) => "sixtyfps::EasingCurve()".into(), Expression::EasingCurve(EasingCurve::Linear) => "sixtyfps::cbindgen_private::EasingCurve()".into(),
Expression::EasingCurve(EasingCurve::CubicBezier(a, b, c, d)) => format!( Expression::EasingCurve(EasingCurve::CubicBezier(a, b, c, d)) => format!(
"sixtyfps::EasingCurve(sixtyfps::EasingCurve::Tag::CubicBezier, {}, {}, {}, {})", "sixtyfps::cbindgen_private::EasingCurve(sixtyfps::cbindgen_private::EasingCurve::Tag::CubicBezier, {}, {}, {}, {})",
a, b, c, d a, b, c, d
), ),
Expression::LinearGradient{angle, stops} => { Expression::LinearGradient{angle, stops} => {
@ -1700,7 +1708,7 @@ fn compile_expression(
) )
} }
Expression::EnumerationValue(value) => { Expression::EnumerationValue(value) => {
format!("sixtyfps::{}::{}", value.enumeration.name, value.to_string()) format!("sixtyfps::cbindgen_private::{}::{}", value.enumeration.name, value.to_string())
} }
Expression::ReturnStatement(Some(expr)) => format!( Expression::ReturnStatement(Some(expr)) => format!(
"throw sixtyfps::private_api::ReturnWrapper<{}>({})", "throw sixtyfps::private_api::ReturnWrapper<{}>({})",
@ -1740,7 +1748,7 @@ fn compile_expression(
const auto padding = {};\ const auto padding = {};\
{}\ {}\
const sixtyfps::Slice<sixtyfps::BoxLayoutCellData> slice{{ &*std::begin(cells), std::size(cells)}}; \ const sixtyfps::Slice<sixtyfps::BoxLayoutCellData> slice{{ &*std::begin(cells), std::size(cells)}}; \
return sixtyfps::{};\ return sixtyfps::cbindgen_private::{};\
}}()", }}()",
padding, cells, call padding, cells, call
) )
@ -2020,7 +2028,7 @@ fn get_layout_info(
format!("{}.get()", access_named_reference(layout_info_prop, component, "self")) format!("{}.get()", access_named_reference(layout_info_prop, component, "self"))
} else { } else {
format!( format!(
"{vt}->layouting_info({{{vt}, const_cast<sixtyfps::{ty}*>(&self->{id})}}, {o}, &self->window)", "{vt}->layouting_info({{{vt}, const_cast<sixtyfps::cbindgen_private::{ty}*>(&self->{id})}}, {o}, &self->window)",
vt = elem.borrow().base_type.as_native().cpp_vtable_getter, vt = elem.borrow().base_type.as_native().cpp_vtable_getter,
ty = elem.borrow().base_type.as_native().class_name, ty = elem.borrow().base_type.as_native().class_name,
id = elem.borrow().id, id = elem.borrow().id,

View file

@ -16,9 +16,7 @@ When adding an item or a property, it needs to be kept in sync with different pl
- It needs to be changed in this module - It needs to be changed in this module
- In the compiler: builtins.60 - In the compiler: builtins.60
- In the interpreter (new item only): dynamic_component.rs - In the interpreter (new item only): dynamic_component.rs
- For the C++ code (new item only): - For the C++ code (new item only): the cbindgen.rs to export the new item
- the cbindgen.rs to export the new item
- the `using` declaration in sixtyfps.h for the item and its vtable
- Don't forget to update the documentation - Don't forget to update the documentation
*/ */

View file

@ -11,13 +11,7 @@ LICENSE END */
This module contains the builtin image related items. This module contains the builtin image related items.
When adding an item or a property, it needs to be kept in sync with different place. When adding an item or a property, it needs to be kept in sync with different place.
(This is less than ideal and maybe we can have some automation later) Lookup the [`crate::items`] module documentation.
- It needs to be changed in this module
- In the compiler: builtins.60
- In the interpreter: dynamic_component.rs
- For the C++ code (new item only): the cbindgen.rs to export the new item, and the `using` declaration in sixtyfps.h
- Don't forget to update the documentation
*/ */
use super::{Item, ItemConsts, ItemRc}; use super::{Item, ItemConsts, ItemRc};
use crate::graphics::Rect; use crate::graphics::Rect;

View file

@ -11,13 +11,7 @@ LICENSE END */
This module contains the builtin text related items. This module contains the builtin text related items.
When adding an item or a property, it needs to be kept in sync with different place. When adding an item or a property, it needs to be kept in sync with different place.
(This is less than ideal and maybe we can have some automation later) Lookup the [`crate::items`] module documentation.
- It needs to be changed in this module
- In the compiler: builtins.60
- In the interpreter: dynamic_component.rs
- For the C++ code (new item only): the cbindgen.rs to export the new item, and the `using` declaration in sixtyfps.h
- Don't forget to update the documentation
*/ */
use super::{Item, ItemConsts, ItemRc, VoidArg}; use super::{Item, ItemConsts, ItemRc, VoidArg};