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.
Sourcepub fn has_body(&self) -> bool
pub fn has_body(&self) -> bool
DECY-190: Check if this function has a body (is a definition, not just a declaration). Returns true for definitions, false for forward declarations/prototypes.
Sourcepub fn cuda_qualifier(&self) -> Option<HirCudaQualifier>
pub fn cuda_qualifier(&self) -> Option<HirCudaQualifier>
Get the CUDA qualifier (DECY-199).
Sourcepub fn set_cuda_qualifier(&mut self, qualifier: Option<HirCudaQualifier>)
pub fn set_cuda_qualifier(&mut self, qualifier: Option<HirCudaQualifier>)
Set the CUDA qualifier (DECY-221: preserve through transformations).
Trait Implementations§
Source§impl Clone for HirFunction
impl Clone for HirFunction
Source§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 UnsafeUnpin 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