Extract constant arguments from function calls.

This commit is contained in:
Stephen Chung
2021-03-28 19:04:25 +08:00
parent 8e8c367034
commit 7bdc2e3d20
6 changed files with 190 additions and 85 deletions

View File

@@ -1400,6 +1400,8 @@ pub struct FnCallExpr {
pub capture: bool,
/// List of function call arguments.
pub args: StaticVec<Expr>,
/// List of function call arguments that are constants.
pub constant_args: StaticVec<(Dynamic, Position)>,
/// Namespace of the function, if any. Boxed because it occurs rarely.
pub namespace: Option<NamespaceRef>,
/// Function name.
@@ -1408,6 +1410,19 @@ pub struct FnCallExpr {
pub name: Cow<'static, str>,
}
impl FnCallExpr {
/// Are there no arguments to this function call?
#[inline(always)]
pub fn is_args_empty(&self) -> bool {
self.args.is_empty() && self.constant_args.is_empty()
}
/// Get the number of arguments to this function call.
#[inline(always)]
pub fn num_args(&self) -> usize {
self.args.len() + self.constant_args.len()
}
}
/// A type that wraps a [`FLOAT`] and implements [`Hash`].
#[cfg(not(feature = "no_float"))]
#[derive(Clone, Copy, PartialEq, PartialOrd)]