Enum Expression

Source
pub enum Expression {
Show 36 variants Invalid, Uncompiled(SyntaxNode), StringLiteral(String), NumberLiteral(f64, Unit), BoolLiteral(bool), CallbackReference(NamedReference), PropertyReference(NamedReference), 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, }, 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)>, }, EnumerationValue(EnumerationValue), ReturnStatement(Option<Box<Expression>>), LayoutCacheAccess { layout_cache_prop: NamedReference, index: usize, repeater_index: Option<Box<Expression>>, }, ComputeLayoutInfo(Layout, Orientation), SolveLayout(Layout, Orientation),
}
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)

Reference to the callback in the

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 callback in the

§

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.

Fields

§base_node: Option<NodeOrToken>
§member: Box<Expression>
§

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 .60 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

Fields

§

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

Fields

§

FunctionParameterReference

Reference the parameter at the given index of the current function.

Fields

§index: usize
§ty: Type
§

StoreLocalVariable

Should be directly within a CodeBlock expression, and store the value of the expression in a local variable

Fields

§name: String
§

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

Fields

§name: String
§ty: Type
§

StructFieldAccess

Access to a field of the given name within a struct.

Fields

§base: Box<Expression>

This expression should have Type::Struct type

§name: String
§

ArrayIndex

Access to a index within an array.

Fields

§array: Box<Expression>

This expression should have Type::Array type

§

Cast

Cast an expression to the given type

Fields

§to: Type
§

CodeBlock(Vec<Expression>)

a code block with different expression

§

FunctionCall

A function call

Fields

§function: Box<Expression>
§arguments: Vec<Expression>
§source_location: Option<SourceLocation>
§

SelfAssignment

A SelfAssignment or an Assignment. When op is ‘=’ this is a signal assignment.

Fields

§op: char

‘+’, ‘-’, ‘/’, ‘*’, or ‘=’

§

BinaryExpression

Fields

§op: char

‘+’, ‘-’, ‘/’, ‘*’, ‘=’, ‘!’, ‘<’, ‘>’, ‘≤’, ‘≥’, ‘&’, ‘|’

§

UnaryOp

Fields

§op: char

‘+’, ‘-’, ‘!’

§

ImageReference

Fields

§resource_ref: ImageReference
§source_location: Option<SourceLocation>
§

Condition

Fields

§condition: Box<Expression>
§true_expr: Box<Expression>
§false_expr: Box<Expression>
§

Array

Fields

§element_ty: Type
§values: Vec<Expression>
§

Struct

Fields

§ty: Type
§

PathData(Path)

§

EasingCurve(EasingCurve)

§

LinearGradient

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
§index: usize
§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)

Implementations§

Source§

impl Expression

Source

pub fn ty(&self) -> Type

Return the type of this property

Source

pub fn visit(&self, visitor: impl FnMut(&Self))

Call the visitor for each sub-expression. (note: this function does not recurse)

Source

pub fn visit_mut(&mut self, visitor: impl FnMut(&mut Self))

Source

pub fn visit_recursive(&self, visitor: &mut dyn FnMut(&Self))

Visit itself and each sub expression recursively

Source

pub fn visit_recursive_mut(&mut self, visitor: &mut dyn FnMut(&mut Self))

Visit itself and each sub expression recursively

Source

pub fn is_constant(&self) -> bool

Source

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

Source

pub fn default_value_for_type(ty: &Type) -> Expression

Return the default value for the given type

Source

pub fn try_set_rw(&mut self) -> bool

Try to mark this expression to a lvalue that can be assigned to.

Return true if the expression is a “lvalue” that can be used as the left hand side of a = or += or similar

Source§

impl Expression

Source

pub fn from_binding_expression_node( node: SyntaxNode, ctx: &mut LookupCtx<'_>, ) -> Self

Trait Implementations§

Source§

impl Clone for Expression

Source§

fn clone(&self) -> Expression

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Expression

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Expression

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl From<Expression> for BindingExpression

Source§

fn from(expression: Expression) -> Self

Converts to this type from the input type.
Source§

impl From<Expression> for LookupResult

Source§

fn from(expression: Expression) -> Self

Converts to this type from the input type.
Source§

impl LookupObject for Expression

Source§

fn for_each_entry<R>( &self, ctx: &LookupCtx<'_>, f: &mut impl FnMut(&str, LookupResult) -> Option<R>, ) -> Option<R>

Will call the function for each entry (useful for completion) If the function return Some, it will immediately be returned and not called further
Source§

fn lookup(&self, ctx: &LookupCtx<'_>, name: &str) -> Option<LookupResult>

Perform a lookup of a given identifier. One does not have to re-implement unless we can make it faster

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> ErasedDestructor for T
where T: 'static,