Skip to content

Commit 58c4617

Browse files
committed
compiler: Rename builtin struct types
1 parent a922eca commit 58c4617

File tree

14 files changed

+117
-128
lines changed

14 files changed

+117
-128
lines changed

internal/common/builtin_structs.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ macro_rules! for_each_builtin_structs {
3939
/// On Windows, the Windows key is mapped to the meta modifier.
4040
#[derive(Copy, Eq)]
4141
struct KeyboardModifiers {
42-
@name = NativePrivateType::KeyboardModifiers,
42+
@name = BuiltinPrivateStruct::KeyboardModifiers,
4343
export {
4444
/// Indicates the Alt key on a keyboard.
4545
alt: bool,
@@ -57,7 +57,7 @@ macro_rules! for_each_builtin_structs {
5757
/// Represents a Pointer event sent by the windowing system.
5858
/// This structure is passed to the `pointer-event` callback of the `TouchArea` element.
5959
struct PointerEvent {
60-
@name = NativePrivateType::PointerEvent,
60+
@name = BuiltinPrivateStruct::PointerEvent,
6161
export {
6262
/// The button that was pressed or released
6363
button: PointerEventButton,
@@ -75,7 +75,7 @@ macro_rules! for_each_builtin_structs {
7575
/// Represents a Pointer scroll (or wheel) event sent by the windowing system.
7676
/// This structure is passed to the `scroll-event` callback of the `TouchArea` element.
7777
struct PointerScrollEvent {
78-
@name = NativePrivateType::PointerScrollEvent,
78+
@name = BuiltinPrivateStruct::PointerScrollEvent,
7979
export {
8080
/// The amount of pixel in the horizontal direction
8181
delta_x: Coord,
@@ -90,7 +90,7 @@ macro_rules! for_each_builtin_structs {
9090

9191
/// This structure is generated and passed to the key press and release callbacks of the `FocusScope` element.
9292
struct KeyEvent {
93-
@name = NativePrivateType::KeyEvent,
93+
@name = BuiltinPrivateStruct::KeyEvent,
9494
export {
9595
/// The unicode representation of the key pressed.
9696
text: SharedString,
@@ -119,7 +119,7 @@ macro_rules! for_each_builtin_structs {
119119

120120
/// This structure is passed to the callbacks of the `DropArea` element
121121
struct DropEvent {
122-
@name = NativePrivateType::DropEvent,
122+
@name = BuiltinPrivateStruct::DropEvent,
123123
export {
124124
/// The mime type of the data being dragged
125125
mime_type: SharedString,
@@ -135,7 +135,7 @@ macro_rules! for_each_builtin_structs {
135135
/// Represents an item in a StandardListView and a StandardTableView.
136136
#[non_exhaustive]
137137
struct StandardListViewItem {
138-
@name = NativePublicType::StandardListViewItem,
138+
@name = BuiltinPublicStruct::StandardListViewItem,
139139
export {
140140
/// The text content of the item
141141
text: SharedString,
@@ -147,7 +147,7 @@ macro_rules! for_each_builtin_structs {
147147
/// This is used to define the column and the column header of a TableView
148148
#[non_exhaustive]
149149
struct TableColumn {
150-
@name = NativePrivateType::TableColumn,
150+
@name = BuiltinPrivateStruct::TableColumn,
151151
export {
152152
/// The title of the column header
153153
title: SharedString,
@@ -167,7 +167,7 @@ macro_rules! for_each_builtin_structs {
167167
/// Value of the state property
168168
/// A state is just the current state, but also has information about the previous state and the moment it changed
169169
struct StateInfo {
170-
@name = NativePrivateType::StateInfo,
170+
@name = BuiltinPrivateStruct::StateInfo,
171171
export {
172172
/// The current state value
173173
current_state: i32,
@@ -182,7 +182,7 @@ macro_rules! for_each_builtin_structs {
182182

183183
/// A structure to hold metrics of a font for a specified pixel size.
184184
struct FontMetrics {
185-
@name = NativePrivateType::FontMetrics,
185+
@name = BuiltinPrivateStruct::FontMetrics,
186186
export {
187187
/// The distance between the baseline and the top of the tallest glyph in the font.
188188
ascent: Coord,
@@ -202,7 +202,7 @@ macro_rules! for_each_builtin_structs {
202202

203203
/// An item in the menu of a menu bar or context menu
204204
struct MenuEntry {
205-
@name = NativePrivateType::MenuEntry,
205+
@name = BuiltinPrivateStruct::MenuEntry,
206206
export {
207207
/// The text of the menu entry
208208
title: SharedString,

internal/compiler/builtins.slint

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -442,15 +442,15 @@ component MoveTo {
442442
in property <float> x;
443443
in property <float> y;
444444

445-
//-native_type:PathMoveTo
445+
//-builtin_struct:PathMoveTo
446446
//-is_non_item_type
447447
}
448448

449449
component LineTo {
450450
in property <float> x;
451451
in property <float> y;
452452

453-
//-native_type:PathLineTo
453+
//-builtin_struct:PathLineTo
454454
//-is_non_item_type
455455
}
456456

@@ -463,7 +463,7 @@ component ArcTo {
463463
in property <bool> large_arc;
464464
in property <bool> sweep;
465465

466-
//-native_type:PathArcTo
466+
//-builtin_struct:PathArcTo
467467
//-is_non_item_type
468468
}
469469

@@ -475,7 +475,7 @@ component CubicTo {
475475
in property <float> x;
476476
in property <float> y;
477477

478-
//-native_type:PathCubicTo
478+
//-builtin_struct:PathCubicTo
479479
//-is_non_item_type
480480
}
481481

@@ -485,12 +485,12 @@ component QuadraticTo {
485485
in property <float> x;
486486
in property <float> y;
487487

488-
//-native_type:PathQuadraticTo
488+
//-builtin_struct:PathQuadraticTo
489489
//-is_non_item_type
490490
}
491491

492492
component Close {
493-
//-native_type:PathClose
493+
//-builtin_struct:PathClose
494494
//-is_non_item_type
495495
}
496496

internal/compiler/expression_tree.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
33

44
use crate::diagnostics::{BuildDiagnostics, SourceLocation, Spanned};
5-
use crate::langtype::{BuiltinElement, EnumerationValue, Function, NativePublicType, Struct, Type};
5+
use crate::langtype::{
6+
BuiltinElement, BuiltinPublicStruct, EnumerationValue, Function, Struct, Type,
7+
};
68
use crate::layout::Orientation;
79
use crate::lookup::LookupCtx;
810
use crate::object_tree::*;
@@ -215,7 +217,7 @@ declare_builtin_function_types!(
215217
(SmolStr::new_static("alpha"), Type::Int32),
216218
])
217219
.collect(),
218-
name: NativePublicType::Color.into(),
220+
name: BuiltinPublicStruct::Color.into(),
219221
rust_attributes: None,
220222
})),
221223
ColorHsvaStruct: (Type::Color) -> Type::Struct(Rc::new(Struct {
@@ -226,7 +228,7 @@ declare_builtin_function_types!(
226228
(SmolStr::new_static("alpha"), Type::Float32),
227229
])
228230
.collect(),
229-
name: NativePublicType::Color.into(),
231+
name: BuiltinPublicStruct::Color.into(),
230232
rust_attributes: None,
231233
})),
232234
ColorBrighter: (Type::Brush, Type::Float32) -> Type::Brush,
@@ -240,7 +242,7 @@ declare_builtin_function_types!(
240242
(SmolStr::new_static("height"), Type::Int32),
241243
])
242244
.collect(),
243-
name: crate::langtype::NativePrivateType::Size.into(),
245+
name: crate::langtype::BuiltinPrivateStruct::Size.into(),
244246
rust_attributes: None,
245247
})),
246248
ArrayLength: (Type::Model) -> Type::Int32,

internal/compiler/generator.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use std::rc::{Rc, Weak};
1515

1616
use crate::CompilerConfiguration;
1717
use crate::expression_tree::{BindingExpression, Expression};
18-
use crate::langtype::{ElementType, NativePrivateType, NativeType, StructName};
18+
use crate::langtype::{BuiltinPrivateStruct, ElementType, StructName};
1919
use crate::namedreference::NamedReference;
2020
use crate::object_tree::{Component, Document, ElementRc};
2121

@@ -423,7 +423,7 @@ pub fn for_each_const_properties(
423423
.iter()
424424
.filter(|(_, x)| {
425425
x.property_type.is_property_type() &&
426-
!matches!( &x.property_type, crate::langtype::Type::Struct(s) if matches!(s.name, StructName::Native(NativeType::Private(NativePrivateType::StateInfo))))
426+
!matches!( &x.property_type, crate::langtype::Type::Struct(s) if matches!(s.name, StructName::BuiltinPrivate(BuiltinPrivateStruct::StateInfo)))
427427
})
428428
.map(|(k, _)| k.clone()),
429429
);

internal/compiler/generator/cpp.rs

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ pub mod cpp_ast {
459459
use crate::CompilerConfiguration;
460460
use crate::expression_tree::{BuiltinFunction, EasingCurve, MinMaxOp};
461461
use crate::langtype::{
462-
Enumeration, EnumerationValue, NativeClass, NativePrivateType, NativePublicType, NativeType,
462+
BuiltinPrivateStruct, BuiltinPublicStruct, Enumeration, EnumerationValue, NativeClass,
463463
StructName, Type,
464464
};
465465
use crate::layout::Orientation;
@@ -495,36 +495,28 @@ impl CppType for StructName {
495495
match self {
496496
StructName::None => return None,
497497
StructName::User { name, .. } => Some(ident(name)),
498-
StructName::Native(native) => native.cpp_type(),
498+
StructName::BuiltinPrivate(builtin_private) => builtin_private.cpp_type(),
499+
StructName::BuiltinPublic(builtin_public) => builtin_public.cpp_type(),
499500
}
500501
}
501502
}
502503

503-
impl CppType for NativeType {
504-
fn cpp_type(&self) -> Option<SmolStr> {
505-
match self {
506-
NativeType::Private(native_private_type) => native_private_type.cpp_type(),
507-
NativeType::Public(native_public_type) => native_public_type.cpp_type(),
508-
}
509-
}
510-
}
511-
512-
impl CppType for NativePrivateType {
504+
impl CppType for BuiltinPrivateStruct {
513505
fn cpp_type(&self) -> Option<SmolStr> {
514506
let name: &'static str = self.into();
515507
match self {
516-
NativePrivateType::PathMoveTo
517-
| NativePrivateType::PathLineTo
518-
| NativePrivateType::PathArcTo
519-
| NativePrivateType::PathCubicTo
520-
| NativePrivateType::PathQuadraticTo
521-
| NativePrivateType::PathClose => Some(format_smolstr!("slint::private_api::{}", name)),
508+
Self::PathMoveTo
509+
| Self::PathLineTo
510+
| Self::PathArcTo
511+
| Self::PathCubicTo
512+
| Self::PathQuadraticTo
513+
| Self::PathClose => Some(format_smolstr!("slint::private_api::{}", name)),
522514
_ => Some(format_smolstr!("slint::cbindgen_private::{}", name)),
523515
}
524516
}
525517
}
526518

527-
impl CppType for NativePublicType {
519+
impl CppType for BuiltinPublicStruct {
528520
fn cpp_type(&self) -> Option<SmolStr> {
529521
let name: &'static str = self.into();
530522
Some(format_smolstr!("slint::{}", name))

internal/compiler/generator/rust.rs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Some convention used in the generated code:
1414

1515
use crate::CompilerConfiguration;
1616
use crate::expression_tree::{BuiltinFunction, EasingCurve, MinMaxOp, OperatorClass};
17-
use crate::langtype::{Enumeration, EnumerationValue, NativeType, Struct, StructName, Type};
17+
use crate::langtype::{Enumeration, EnumerationValue, Struct, StructName, Type};
1818
use crate::layout::Orientation;
1919
use crate::llr::{
2020
self, EvaluationContext as llr_EvaluationContext, EvaluationScope, Expression, ParentScope,
@@ -2593,7 +2593,7 @@ fn compile_expression(expr: &Expression, ctx: &EvaluationContext) -> TokenStream
25932593
if ty.name.is_some() {
25942594
let name_tokens = struct_name_to_tokens(&ty.name).unwrap();
25952595
let keys = ty.fields.keys().map(|k| ident(k));
2596-
if matches!(&ty.name, StructName::Native(NativeType::Private(private_type)) if private_type.is_layout_data()) {
2596+
if matches!(&ty.name, StructName::BuiltinPrivate(private_type) if private_type.is_layout_data()) {
25972597
quote!(#name_tokens{#(#keys: #elem as _,)*})
25982598
} else {
25992599
quote!({ let mut the_struct = #name_tokens::default(); #(the_struct.#keys = #elem as _;)* the_struct})
@@ -3409,18 +3409,16 @@ fn struct_name_to_tokens(name: &StructName) -> Option<proc_macro2::TokenStream>
34093409
match name {
34103410
StructName::None => None,
34113411
StructName::User { name, .. } => Some(proc_macro2::TokenTree::from(ident(name)).into()),
3412-
StructName::Native(native_type) => match native_type {
3413-
crate::langtype::NativeType::Private(native_private_type) => {
3414-
let name: &'static str = native_private_type.into();
3415-
let name = format_ident!("{}", name);
3416-
Some(quote!(sp::#name))
3417-
}
3418-
crate::langtype::NativeType::Public(native_public_type) => {
3419-
let name: &'static str = native_public_type.into();
3420-
let name = format_ident!("{}", name);
3421-
Some(quote!(slint::#name))
3422-
}
3423-
},
3412+
StructName::BuiltinPrivate(builtin_private_struct) => {
3413+
let name: &'static str = builtin_private_struct.into();
3414+
let name = format_ident!("{}", name);
3415+
Some(quote!(sp::#name))
3416+
}
3417+
StructName::BuiltinPublic(builtin_public_struct) => {
3418+
let name: &'static str = builtin_public_struct.into();
3419+
let name = format_ident!("{}", name);
3420+
Some(quote!(slint::#name))
3421+
}
34243422
}
34253423
}
34263424

0 commit comments

Comments
 (0)