deimos-lang/dmc-lib/src/ir/ir_call.rs

42 lines
1.0 KiB
Rust

use crate::ir::ir_expression::IrExpression;
use crate::ir::ir_variable::IrVariable;
use std::collections::HashSet;
use std::fmt::{Display, Formatter};
use std::rc::Rc;
pub struct IrCall {
function_name: Rc<str>,
arguments: Vec<IrExpression>,
}
impl IrCall {
pub fn new(function_name: Rc<str>, arguments: Vec<IrExpression>) -> Self {
Self {
function_name,
arguments,
}
}
pub fn uses(&self) -> HashSet<Rc<IrVariable>> {
let mut set = HashSet::new();
for argument in &self.arguments {
set.extend(argument.uses());
}
set
}
}
impl Display for IrCall {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{}(", self.function_name)?;
for (i, argument) in self.arguments.iter().enumerate() {
write!(f, "{}", argument)?;
if i < self.arguments.len() - 1 {
write!(f, ", ")?;
}
}
write!(f, ")")?;
Ok(())
}
}