Struct AstMetadata
pub struct AstMetadata { /* private fields */ }Expand description
AST metadata produced by the parser.
Implementations§
§impl AstMetadata
impl AstMetadata
pub fn new() -> Self
pub fn new() -> Self
Creates the AST metadata.
pub fn set_node_type(&mut self, node_id: AstNodeId, data_type: AstType)
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>
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
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,
)
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
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,
)
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,
)
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
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,
)
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,
)
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)
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)
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
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>
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>
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)>
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
pub fn switch_has_default(&self, switch_node_id: AstNodeId) -> bool
Does the given switch statement have a default label?