Struct miden_objects::assembly::ModuleAst
source · 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
impl ModuleAst
sourcepub fn new(
local_procs: Vec<ProcedureAst>,
reexported_procs: Vec<ProcReExport>,
docs: Option<String>
) -> Result<ModuleAst, ParsingError>
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.
sourcepub fn with_import_info(self, import_info: ModuleImports) -> ModuleAst
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.
sourcepub fn parse(source: &str) -> Result<ModuleAst, ParsingError>
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.
sourcepub fn procs(&self) -> &[ProcedureAst]
pub fn procs(&self) -> &[ProcedureAst]
Returns a list of procedures in this module.
sourcepub fn reexported_procs(&self) -> &[ProcReExport]
pub fn reexported_procs(&self) -> &[ProcReExport]
Returns a list of re-exported procedures in this module.
sourcepub fn import_info(&self) -> &ModuleImports
pub fn import_info(&self) -> &ModuleImports
Returns a reference to the import information for this module
sourcepub fn clear_locations(&mut self)
pub fn clear_locations(&mut self)
Clears the source locations from this module.
sourcepub fn write_into<R>(&self, target: &mut R, options: AstSerdeOptions)where
R: ByteWriter,
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.
sourcepub fn read_from<R>(
source: &mut R,
options: AstSerdeOptions
) -> Result<ModuleAst, DeserializationError>where
R: ByteReader,
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.
sourcepub fn to_bytes(&self, options: AstSerdeOptions) -> Vec<u8> ⓘ
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.
sourcepub fn from_bytes(bytes: &[u8]) -> Result<ModuleAst, DeserializationError>
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.
sourcepub fn load_source_locations<R>(
&mut self,
source: &mut R
) -> Result<(), DeserializationError>where
R: ByteReader,
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.
sourcepub fn write_source_locations<W>(&self, target: &mut W)where
W: ByteWriter,
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.
sourcepub fn clear_imports(&mut self)
pub fn clear_imports(&mut self)
Clear import info from the module