pub enum Expression {
Show 39 variants
Invalid,
Uncompiled(SyntaxNode),
StringLiteral(String),
NumberLiteral(f64, Unit),
BoolLiteral(bool),
CallbackReference(NamedReference, Option<NodeOrToken>),
PropertyReference(NamedReference),
FunctionReference(NamedReference, Option<NodeOrToken>),
BuiltinFunctionReference(BuiltinFunction, Option<SourceLocation>),
MemberFunction {
base: Box<Expression>,
base_node: Option<NodeOrToken>,
member: Box<Expression>,
},
BuiltinMacroReference(BuiltinMacroFunction, Option<NodeOrToken>),
ElementReference(Weak<RefCell<Element>>),
RepeaterIndexReference {
element: Weak<RefCell<Element>>,
},
RepeaterModelReference {
element: Weak<RefCell<Element>>,
},
FunctionParameterReference {
index: usize,
ty: Type,
},
StoreLocalVariable {
name: String,
value: Box<Expression>,
},
ReadLocalVariable {
name: String,
ty: Type,
},
StructFieldAccess {
base: Box<Expression>,
name: String,
},
ArrayIndex {
array: Box<Expression>,
index: Box<Expression>,
},
Cast {
from: Box<Expression>,
to: Type,
},
CodeBlock(Vec<Expression>),
FunctionCall {
function: Box<Expression>,
arguments: Vec<Expression>,
source_location: Option<SourceLocation>,
},
SelfAssignment {
lhs: Box<Expression>,
rhs: Box<Expression>,
op: char,
node: Option<NodeOrToken>,
},
BinaryExpression {
lhs: Box<Expression>,
rhs: Box<Expression>,
op: char,
},
UnaryOp {
sub: Box<Expression>,
op: char,
},
ImageReference {
resource_ref: ImageReference,
source_location: Option<SourceLocation>,
},
Condition {
condition: Box<Expression>,
true_expr: Box<Expression>,
false_expr: Box<Expression>,
},
Array {
element_ty: Type,
values: Vec<Expression>,
},
Struct {
ty: Type,
values: HashMap<String, Expression>,
},
PathData(Path),
EasingCurve(EasingCurve),
LinearGradient {
angle: Box<Expression>,
stops: Vec<(Expression, Expression)>,
},
RadialGradient {
stops: Vec<(Expression, Expression)>,
},
EnumerationValue(EnumerationValue),
ReturnStatement(Option<Box<Expression>>),
LayoutCacheAccess {
layout_cache_prop: NamedReference,
index: usize,
repeater_index: Option<Box<Expression>>,
},
ComputeLayoutInfo(Layout, Orientation),
SolveLayout(Layout, Orientation),
MinMax {
ty: Type,
op: MinMaxOp,
lhs: Box<Expression>,
rhs: Box<Expression>,
},
}
Expand description
The Expression is hold by properties, so it should not hold any strong references to node from the object_tree
Variants§
Invalid
Something went wrong (and an error will be reported)
Uncompiled(SyntaxNode)
We haven’t done the lookup yet
StringLiteral(String)
A string literal. The .0 is the content of the string, without the quotes
NumberLiteral(f64, Unit)
Number
BoolLiteral(bool)
CallbackReference(NamedReference, Option<NodeOrToken>)
Reference to the callback <name>
in the <element>
Note: if we are to separate expression and statement, we probably do not need to have callback reference within expressions
PropertyReference(NamedReference)
Reference to the property
FunctionReference(NamedReference, Option<NodeOrToken>)
Reference to a function
BuiltinFunctionReference(BuiltinFunction, Option<SourceLocation>)
Reference to a function built into the run-time, implemented natively
MemberFunction
A MemberFunction expression exists only for a short time, for example for item.focus()
to be translated to
a regular FunctionCall expression where the base becomes the first argument.
BuiltinMacroReference(BuiltinMacroFunction, Option<NodeOrToken>)
Reference to a macro understood by the compiler. These should be transformed to other expression before reaching generation
ElementReference(Weak<RefCell<Element>>)
A reference to a specific element. This isn’t possible to create in .slint syntax itself, but intermediate passes may generate this type of expression.
RepeaterIndexReference
Reference to the index variable of a repeater
Example: idx
in for xxx[idx] in ...
. The element is the reference to the
element that is repeated
RepeaterModelReference
Reference to the model variable of a repeater
Example: xxx
in for xxx[idx] in ...
. The element is the reference to the
element that is repeated
FunctionParameterReference
Reference the parameter at the given index of the current function.
StoreLocalVariable
Should be directly within a CodeBlock expression, and store the value of the expression in a local variable
ReadLocalVariable
a reference to the local variable with the given name. The type system should ensure that a variable has been stored with this name and this type before in one of the statement of an enclosing codeblock
StructFieldAccess
Access to a field of the given name within a struct.
ArrayIndex
Access to a index within an array.
Cast
Cast an expression to the given type
CodeBlock(Vec<Expression>)
a code block with different expression
FunctionCall
A function call
SelfAssignment
A SelfAssignment or an Assignment. When op is ‘=’ this is a simple assignment.
BinaryExpression
UnaryOp
ImageReference
Condition
Array
Struct
PathData(Path)
EasingCurve(EasingCurve)
LinearGradient
Fields
angle: Box<Expression>
stops: Vec<(Expression, Expression)>
First expression in the tuple is a color, second expression is the stop position
RadialGradient
Fields
stops: Vec<(Expression, Expression)>
First expression in the tuple is a color, second expression is the stop position
EnumerationValue(EnumerationValue)
ReturnStatement(Option<Box<Expression>>)
LayoutCacheAccess
Fields
layout_cache_prop: NamedReference
repeater_index: Option<Box<Expression>>
When set, this is the index within a repeater, and the index is then the location of another offset.
So this looks like layout_cache_prop[layout_cache_prop[index] + repeater_index]
ComputeLayoutInfo(Layout, Orientation)
Compute the LayoutInfo for the given layout. The orientation is the orientation of the cache, not the orientation of the layout
SolveLayout(Layout, Orientation)
MinMax
Implementations§
source§impl Expression
impl Expression
sourcepub fn visit(&self, visitor: impl FnMut(&Self))
pub fn visit(&self, visitor: impl FnMut(&Self))
Call the visitor for each sub-expression. (note: this function does not recurse)
pub fn visit_mut(&mut self, visitor: impl FnMut(&mut Self))
sourcepub fn visit_recursive(&self, visitor: &mut dyn FnMut(&Self))
pub fn visit_recursive(&self, visitor: &mut dyn FnMut(&Self))
Visit itself and each sub expression recursively
sourcepub fn visit_recursive_mut(&mut self, visitor: &mut dyn FnMut(&mut Self))
pub fn visit_recursive_mut(&mut self, visitor: &mut dyn FnMut(&mut Self))
Visit itself and each sub expression recursively
pub fn is_constant(&self) -> bool
sourcepub fn maybe_convert_to(
self,
target_type: Type,
node: &impl Spanned,
diag: &mut BuildDiagnostics
) -> Expression
pub fn maybe_convert_to( self, target_type: Type, node: &impl Spanned, diag: &mut BuildDiagnostics ) -> Expression
Create a conversion node if needed, or throw an error if the type is not matching
sourcepub fn default_value_for_type(ty: &Type) -> Expression
pub fn default_value_for_type(ty: &Type) -> Expression
Return the default value for the given type
source§impl Expression
impl Expression
pub fn from_binding_expression_node( node: SyntaxNode, ctx: &mut LookupCtx<'_> ) -> Self
Trait Implementations§
source§impl Clone for Expression
impl Clone for Expression
source§fn clone(&self) -> Expression
fn clone(&self) -> Expression
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more