Struct semantic_analyzer::types::block_state::BlockState
source · pub struct BlockState {
pub values: HashMap<ValueName, Value>,
pub inner_values_name: HashSet<InnerValueName>,
pub labels: HashSet<LabelName>,
pub last_register_number: u64,
pub manual_return: bool,
pub parent: Option<Rc<RefCell<BlockState>>>,
pub children: Vec<Rc<RefCell<BlockState>>>,
pub context: SemanticStack,
}Expand description
Block state
values- contains unique values map for current state but not unique for parent states. The map contains key-value:value_name(unique only for current state); andValueitself - value parameters.inner_values_name- is entity that represent inner value name - it can be different fromValuename because it should be unique for all parent states. For example, of 3 values with namex, inner value name will be: [x,x.0,x.1]. It mean, inner value name can containvalue counteras end of the name.labels- labels set, for conditional operation. Unique for current and all paren states.last_register_number- represent register counter for current and all parent states forCodegen. Register represented asu64and should be linearly incremented.manual_return- flag indicated, that return was invoked from other state, for example: if-flow, loop-flowparent- represent parent states.
Fields§
§values: HashMap<ValueName, Value>State values
inner_values_name: HashSet<InnerValueName>Used to keep all names in the block state (and parent) as unique
labels: HashSet<LabelName>State labels for conditional operations
last_register_number: u64Last register for unique register representation
manual_return: boolManual return from other states
parent: Option<Rc<RefCell<BlockState>>>Parent state
children: Vec<Rc<RefCell<BlockState>>>children states
context: SemanticStackSemantic stack context for Block state
Implementations§
source§impl BlockState
impl BlockState
sourcepub fn new(parent: Option<Rc<RefCell<Self>>>) -> Self
pub fn new(parent: Option<Rc<RefCell<Self>>>) -> Self
Init block state with optional parent state
sourcepub fn inc_register(&mut self)
pub fn inc_register(&mut self)
Increment register
sourcepub fn set_child(&mut self, child: Rc<RefCell<BlockState>>)
pub fn set_child(&mut self, child: Rc<RefCell<BlockState>>)
Get child Block state
sourcepub fn set_inner_value_name(&mut self, name: &InnerValueName)
pub fn set_inner_value_name(&mut self, name: &InnerValueName)
Set value inner name to current state and parent states
sourcepub fn is_inner_value_name_exist(&self, name: &InnerValueName) -> bool
pub fn is_inner_value_name_exist(&self, name: &InnerValueName) -> bool
Check is inner_value_name exist in current and parent states
sourcepub fn get_value_name(&self, name: &ValueName) -> Option<Value>
pub fn get_value_name(&self, name: &ValueName) -> Option<Value>
Get Value by value name from current state.
If not found on current state - recursively find in parent states.
sourcepub fn is_label_name_exist(&self, name: &LabelName) -> bool
pub fn is_label_name_exist(&self, name: &LabelName) -> bool
Check is label name exist in current and parent states
sourcepub fn set_label_name(&mut self, name: &LabelName)
pub fn set_label_name(&mut self, name: &LabelName)
Set label name to current and all parent states
sourcepub fn set_attr_counter(val: &str) -> String
pub fn set_attr_counter(val: &str) -> String
Set attribute counter - increment, if counter exist.
sourcepub fn get_and_set_next_label(&mut self, label: &LabelName) -> LabelName
pub fn get_and_set_next_label(&mut self, label: &LabelName) -> LabelName
Get and set next label for condition operations
- If label doesn’t exist in State - just insert to State and self return
- if label exists, get label counter
sourcepub fn get_next_inner_name(&self, val: &InnerValueName) -> InnerValueName
pub fn get_next_inner_name(&self, val: &InnerValueName) -> InnerValueName
Get next inner_value_name by name counter for current and
parent states. The inner_value_name should always be unique.
sourcepub fn set_return(&mut self)
pub fn set_return(&mut self)
Set return status flag for current and parent states