Struct AstMetadata

pub struct AstMetadata { /* private fields */ }
Expand description

AST metadata produced by the parser.

Implementations§

§

impl AstMetadata

pub fn new() -> Self

Creates the AST metadata.

pub fn set_node_type(&mut self, node_id: AstNodeId, data_type: AstType)

Sets the data type of a node. This either adds or updates the data type for the node.

pub fn try_get_node_type(&self, node_id: AstNodeId) -> Option<&AstType>

If a data type has been set for this node, returns Some(&AstType), or otherwise returns None.

pub fn get_node_type(&self, node_id: AstNodeId) -> &AstType

Gets a node’s data type.

Pre: Expects the data type to previously have been set; emits an ICE otherwise.

pub fn add_source_location( &mut self, node_id: AstNodeId, source_loc: SourceLocation, )

Adds the source location metadata for the given node.

pub fn get_source_location(&self, node_id: AstNodeId) -> SourceLocation

Gets the source location metadata for the given node.

Pre: Expects the source location to previously have been set; emits an ICE otherwise.

pub fn copy_source_location_from_child( &mut self, child_node_id: AstNodeId, parent_node_id: AstNodeId, )

Copies a source location from a child expression to a parent expression.

pub fn add_operator_sloc( &mut self, node_id: AstNodeId, source_loc: SourceLocation, )

Adds the source location metadata of the operator for the given binary/ternary expression node.

pub fn get_operator_sloc(&self, node_id: AstNodeId) -> SourceLocation

Gets the source location metadata of the operator for the given binary/ternary expression node.

Pre: Expects the source location to previously have been set; emits an ICE otherwise.

pub fn propagate_const_flag_from_child( &mut self, child_node_id: AstNodeId, parent_node_id: AstNodeId, )

Propagates the constant expression flag from a child sub-expression to a parent expression.

pub fn propagate_const_flag_from_children( &mut self, child_node_ids: &[AstNodeId], parent_node_id: AstNodeId, )

If all child sub-expressions have the constant expression flag set, then propagates the flag to the parent.

pub fn set_expr_flag(&mut self, node_id: AstNodeId, flag: AstExpressionFlag)

Sets a metadata flag for the given expression.

pub fn clear_expr_flag(&mut self, node_id: AstNodeId, flag: AstExpressionFlag)

Clears a metadata flag for the given expression.

pub fn is_expr_flag_set( &self, node_id: AstNodeId, flag: AstExpressionFlag, ) -> bool

Is the metadata flag set for the given expression?

pub fn add_switch_case( &mut self, switch_node_id: AstNodeId, constant_expr_node_id: AstNodeId, constant_value: AstConstantInteger, ) -> Option<AstNodeId>

Adds metadata about a switch case statement.

Returns None if a case did not already exist with this constant_value.

If a case already exists with this constant_value, Some is returned with the ID of the previous case statement node whose expression evaluated to this value.

pub fn add_switch_default_label( &mut self, switch_node_id: AstNodeId, location: SourceLocation, ) -> Option<SourceLocation>

Adds a default label to the given switch statement.

Returns None if a default label did not already exist.

If a default label already exists, returns Some with the source location of the previous default statement.

pub fn get_switch_cases( &self, switch_node_id: AstNodeId, ) -> Vec<(AstConstantInteger, AstNodeId)>

Gets the case statement values and node ids for the given switch statement, or an empty vector if the given switch node id is not found.

The cases are sorted by the case value in ascending order.

pub fn switch_has_default(&self, switch_node_id: AstNodeId) -> bool

Does the given switch statement have a default label?

Trait Implementations§

§

impl Debug for AstMetadata

§

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

Formats the value using the given formatter. Read more
§

impl Default for AstMetadata

§

fn default() -> Self

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

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