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

An abstract syntax tree of a Miden module.

A module AST consists of a list of procedure ASTs, a list of re-exported procedures, a list of imports, and module documentation. Local procedures could be internal or exported.

Implementations§

source§

impl ModuleAst

source

pub fn new( local_procs: Vec<ProcedureAst>, reexported_procs: Vec<ProcReExport>, docs: Option<String> ) -> Result<ModuleAst, ParsingError>

Returns a new ModuleAst.

A module consists of internal and exported procedures but does not contain a body.

source

pub fn with_import_info(self, import_info: ModuleImports) -> ModuleAst

Adds the provided import information to the module.

§Panics

Panics if import information has already been added.

source

pub fn parse(source: &str) -> Result<ModuleAst, ParsingError>

Parses the provided source into a ModuleAst.

A module consists of internal and exported procedures but does not contain a body.

source

pub fn procs(&self) -> &[ProcedureAst]

Returns a list of procedures in this module.

source

pub fn reexported_procs(&self) -> &[ProcReExport]

Returns a list of re-exported procedures in this module.

source

pub fn docs(&self) -> Option<&String>

Returns doc comments for this module.

source

pub fn import_info(&self) -> &ModuleImports

Returns a reference to the import information for this module

source

pub fn clear_locations(&mut self)

Clears the source locations from this module.

source

pub fn write_into<R>(&self, target: &mut R, options: AstSerdeOptions)
where R: ByteWriter,

Returns byte representation of this ModuleAst.

The serde options are NOT serialized - the caller must keep track of the serialization options used.

source

pub fn read_from<R>( source: &mut R, options: AstSerdeOptions ) -> Result<ModuleAst, DeserializationError>
where R: ByteReader,

Returns a ModuleAst struct deserialized from the provided source.

The serde options must correspond to the options used for serialization.

source

pub fn to_bytes(&self, options: AstSerdeOptions) -> Vec<u8>

Returns byte representation of this ModuleAst.

The serde options are serialized as header information for the purposes of deserialization.

source

pub fn from_bytes(bytes: &[u8]) -> Result<ModuleAst, DeserializationError>

Returns a ModuleAst struct deserialized from the provided bytes.

This function assumes that the byte array contains a serialized AstSerdeOptions struct as a header.

source

pub fn load_source_locations<R>( &mut self, source: &mut R ) -> Result<(), DeserializationError>
where R: ByteReader,

Loads the [SourceLocation] of the procedures via ProcedureAst::load_source_locations.

The local procedures are expected to have deterministic order from parse. This way, the serialization can be simplified into a contiguous sequence of locations.

source

pub fn write_source_locations<W>(&self, target: &mut W)
where W: ByteWriter,

Writes the [SourceLocation] of the procedures via ProcedureAst::write_source_locations.

The local procedures are expected to have deterministic order from parse. This way, the serialization can be simplified into a contiguous sequence of locations.

source

pub fn clear_imports(&mut self)

Clear import info from the module

Trait Implementations§

source§

impl Clone for ModuleAst

source§

fn clone(&self) -> ModuleAst

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 ModuleAst

source§

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

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

impl Display for ModuleAst

source§

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

Writes this ModuleAst as formatted MASM code into the formatter.

The formatted code puts each instruction on a separate line and preserves correct indentation for instruction blocks.

§Panics

Panics if import info is not associated with this module.

source§

impl PartialEq for ModuleAst

source§

fn eq(&self, other: &ModuleAst) -> 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 ModuleAst

source§

impl StructuralPartialEq for ModuleAst

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> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. 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<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