pub struct HirFunction { /* private fields */ }Expand description
Represents a function in HIR.
Implementations§
Source§impl HirFunction
impl HirFunction
Sourcepub fn new(
name: String,
return_type: HirType,
parameters: Vec<HirParameter>,
) -> Self
pub fn new( name: String, return_type: HirType, parameters: Vec<HirParameter>, ) -> Self
Create a new HIR function.
§Examples
use decy_hir::{HirFunction, HirType, HirParameter};
let func = HirFunction::new(
"add".to_string(),
HirType::Int,
vec![
HirParameter::new("a".to_string(), HirType::Int),
HirParameter::new("b".to_string(), HirType::Int),
],
);
assert_eq!(func.name(), "add");
assert_eq!(func.parameters().len(), 2);Sourcepub fn return_type(&self) -> &HirType
pub fn return_type(&self) -> &HirType
Get the return type.
Sourcepub fn parameters(&self) -> &[HirParameter]
pub fn parameters(&self) -> &[HirParameter]
Get the parameters.
Sourcepub fn from_ast_function(ast_func: &Function) -> Self
pub fn from_ast_function(ast_func: &Function) -> Self
Convert from parser AST function to HIR function.
§Examples
use decy_hir::HirFunction;
use decy_parser::parser::{Function, Type, Parameter};
let ast_func = Function::new(
"test".to_string(),
Type::Void,
vec![],
);
let hir_func = HirFunction::from_ast_function(&ast_func);
assert_eq!(hir_func.name(), "test");Sourcepub fn new_with_body(
name: String,
return_type: HirType,
parameters: Vec<HirParameter>,
body: Vec<HirStatement>,
) -> Self
pub fn new_with_body( name: String, return_type: HirType, parameters: Vec<HirParameter>, body: Vec<HirStatement>, ) -> Self
Create a new HIR function with a body.
§Examples
use decy_hir::{HirFunction, HirType, HirStatement, HirExpression};
let func = HirFunction::new_with_body(
"test".to_string(),
HirType::Int,
vec![],
vec![
HirStatement::VariableDeclaration {
name: "x".to_string(),
var_type: HirType::Int,
initializer: Some(HirExpression::IntLiteral(5)),
},
HirStatement::Return(Some(HirExpression::Variable("x".to_string()))),
],
);
assert_eq!(func.name(), "test");
assert_eq!(func.body().len(), 2);Sourcepub fn body(&self) -> &[HirStatement]
pub fn body(&self) -> &[HirStatement]
Get the function body.
Trait Implementations§
Source§impl Clone for HirFunction
impl Clone for HirFunction
Source§fn clone(&self) -> HirFunction
fn clone(&self) -> HirFunction
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for HirFunction
impl Debug for HirFunction
Source§impl PartialEq for HirFunction
impl PartialEq for HirFunction
impl StructuralPartialEq for HirFunction
Auto Trait Implementations§
impl Freeze for HirFunction
impl RefUnwindSafe for HirFunction
impl Send for HirFunction
impl Sync for HirFunction
impl Unpin for HirFunction
impl UnwindSafe for HirFunction
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