pub struct HirModule {
pub functions: Vec<HirFunction>,
pub imports: Vec<Import>,
pub type_aliases: Vec<TypeAlias>,
pub protocols: Vec<Protocol>,
pub classes: Vec<HirClass>,
pub constants: Vec<HirConstant>,
pub top_level_stmts: Vec<HirStmt>,
}Expand description
High-level Intermediate Representation of a Python module
HirModule represents a complete Python module after semantic analysis and type inference.
It contains all the declarations (functions, classes, imports, etc.) in a form that’s
optimized for transpilation to Rust.
§Examples
Creating a HIR module manually:
use depyler_core::hir::{HirModule, HirFunction, HirParam, Type, FunctionProperties};
use depyler_annotations::TranspilationAnnotations;
use smallvec::smallvec;
let function = HirFunction {
name: "example".to_string(),
params: smallvec![HirParam::new("x".to_string(), Type::Int)],
ret_type: Type::Int,
body: vec![],
properties: FunctionProperties::default(),
annotations: TranspilationAnnotations::default(),
docstring: Some("Example function".to_string()),
};
let module = HirModule {
functions: vec![function],
imports: vec![],
type_aliases: vec![],
protocols: vec![],
classes: vec![],
constants: vec![],
};
assert_eq!(module.functions.len(), 1);
assert_eq!(module.functions[0].name, "example");Fields§
§functions: Vec<HirFunction>§imports: Vec<Import>§type_aliases: Vec<TypeAlias>§protocols: Vec<Protocol>§classes: Vec<HirClass>§constants: Vec<HirConstant>§top_level_stmts: Vec<HirStmt>DEPYLER-1216: Top-level statements for script-style Python files. These are non-declarative statements (expressions, loops, etc.) that appear at module scope and should be wrapped into a synthetic main().
Trait Implementations§
Source§impl<'de> Deserialize<'de> for HirModule
impl<'de> Deserialize<'de> for HirModule
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<HirModule, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<HirModule, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Serialize for HirModule
impl Serialize for HirModule
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Serialize this value into the given Serde serializer. Read more
impl StructuralPartialEq for HirModule
Auto Trait Implementations§
impl Freeze for HirModule
impl RefUnwindSafe for HirModule
impl Send for HirModule
impl Sync for HirModule
impl Unpin for HirModule
impl UnsafeUnpin for HirModule
impl UnwindSafe for HirModule
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more