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

source

pub fn new<N>(nodes: N) -> Self
where N: IntoIterator<Item = Node>,

Creates a new instance of CodeBody populated with the provided nodes.

§Panics

Assumes that the number of nodes is smaller than 2^16 and panics otherwise.

source

pub fn with_source_locations<L>(self, locations: L) -> Self
where 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.

source

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.

source

pub fn clear_locations(&mut self)

Removes source location information from this code body.

source

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.

source

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.

source

pub fn nodes(&self) -> &[Node]

Returns the Node sequence.

source

pub fn source_locations(&self) -> &[SourceLocation]

Returns the [SourceLocations] bound to the nodes of this body structure.

source

pub fn has_locations(&self) -> bool

Returns true if this code body contain source location information.

source

pub fn into_parts(self) -> (Vec<Node>, Vec<SourceLocation>)

Returns the internal parts of this code body.

Trait Implementations§

source§

impl Clone for CodeBody

source§

fn clone(&self) -> CodeBody

Returns a copy 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 CodeBody

source§

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

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

impl Default for CodeBody

source§

fn default() -> CodeBody

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

impl FromIterator<(Node, SourceLocation)> for CodeBody

source§

fn from_iter<T: IntoIterator<Item = (Node, SourceLocation)>>(nodes: T) -> Self

Creates a value from an iterator. Read more
source§

impl FromIterator<Node> for CodeBody

source§

fn from_iter<T: IntoIterator<Item = Node>>(nodes: T) -> Self

Creates a value from an iterator. Read more
source§

impl<'a> IntoIterator for &'a CodeBody

§

type Item = (&'a Node, &'a SourceLocation)

The type of the elements being iterated over.
§

type IntoIter = Zip<Iter<'a, Node>, Iter<'a, SourceLocation>>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl PartialEq for CodeBody

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for CodeBody

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> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

§

type Output = T

Should always be Self
source§

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

§

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

§

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

§

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<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more