Struct miden_assembly::ast::CodeBody
source · pub struct CodeBody { /* private fields */ }Expand description
A contiguous sequence of Nodes with optional SourceLocation specified for each node.
When present, the number of locations is equal to the number of nodes + 1. This is because the
last location tracks the end token of a body which does not have its own node.
Implementations§
source§impl CodeBody
impl CodeBody
sourcepub fn new<N>(nodes: N) -> Selfwhere
N: IntoIterator<Item = Node>,
pub fn new<N>(nodes: N) -> Selfwhere
N: IntoIterator<Item = Node>,
sourcepub fn with_source_locations<L>(self, locations: L) -> Selfwhere
L: IntoIterator<Item = SourceLocation>,
pub fn with_source_locations<L>(self, locations: L) -> Selfwhere
L: IntoIterator<Item = SourceLocation>,
Binds SourceLocations to their respective Node.
It is expected that locations have the length one greater than the length of self.nodes.
sourcepub fn add_final_location(&mut self, location: SourceLocation)
pub fn add_final_location(&mut self, location: SourceLocation)
Adds the provided location to the end of location list.
It is expected that prior to calling this method the number of nodes and locations
contained in this code body is the same. Thus, after calling this method there will be one
more location than node. This is because locations should map 1:1 to their nodes, except
for the block termination that is always the last location.
§Panics
Panics if the final location has been added previously.
sourcepub fn clear_locations(&mut self)
pub fn clear_locations(&mut self)
Removes source location information from this code body.
sourcepub fn load_source_locations<R: ByteReader>(
&mut self,
source: &mut R
) -> Result<(), DeserializationError>
pub fn load_source_locations<R: ByteReader>( &mut self, source: &mut R ) -> Result<(), DeserializationError>
Loads the SourceLocation from the source.
The source is expected to provide a locations count equal to the block nodes count + 1,
having the last element reserved for its end node. This way, the locations count is not
expected to be read, as opposed to common vector serialization strategies.
This implementation intentionally diverges from Deserializable so locations can be optionally stored.
sourcepub fn write_source_locations<W: ByteWriter>(&self, target: &mut W)
pub fn write_source_locations<W: ByteWriter>(&self, target: &mut W)
Writes the SourceLocation into target.
The locations will be written directly, without storing the locations count. This is the counterpart of CodeBody::load_source_locations.
This implementation intentionally diverges from Serializable so locations can be optionally stored.
sourcepub fn source_locations(&self) -> &[SourceLocation]
pub fn source_locations(&self) -> &[SourceLocation]
Returns the [SourceLocations] bound to the nodes of this body structure.
sourcepub fn has_locations(&self) -> bool
pub fn has_locations(&self) -> bool
Returns true if this code body contain source location information.
sourcepub fn into_parts(self) -> (Vec<Node>, Vec<SourceLocation>)
pub fn into_parts(self) -> (Vec<Node>, Vec<SourceLocation>)
Returns the internal parts of this code body.