From f8c5dc596ca58bb02d60f35984a78e6f962820c9 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sun, 28 Apr 2024 23:30:31 +0200 Subject: rebel-lang: typing: change function names for expr types Be explicit about that these functions handle types of AST expressions, rather than an explicit type specification. --- crates/rebel-lang/src/typing.rs | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/crates/rebel-lang/src/typing.rs b/crates/rebel-lang/src/typing.rs index 6d8ee8b..eaf30bc 100644 --- a/crates/rebel-lang/src/typing.rs +++ b/crates/rebel-lang/src/typing.rs @@ -96,23 +96,23 @@ impl Type { use ast::Expr::*; Ok(match expr { - Binary { left, op, right } => Self::binary_op_type(ctx, left, *op, right)?, - Unary { op, expr } => Self::unary_op_type(ctx, *op, expr)?, - Apply { expr, params } => Self::apply_type(ctx, expr, params)?, + Binary { left, op, right } => Self::binary_op_expr_type(ctx, left, *op, right)?, + Unary { op, expr } => Self::unary_op_expr_type(ctx, *op, expr)?, + Apply { expr, params } => Self::apply_expr_type(ctx, expr, params)?, Method { expr, method, params, - } => Self::method_type(ctx, expr, method, params)?, - Index { expr, index } => Self::index_type(ctx, expr, index)?, - Field { expr, field } => Self::field_type(ctx, expr, field)?, + } => Self::method_expr_type(ctx, expr, method, params)?, + Index { expr, index } => Self::index_expr_type(ctx, expr, index)?, + Field { expr, field } => Self::field_expr_type(ctx, expr, field)?, Paren(subexpr) => Self::ast_expr_type(ctx, subexpr)?, - Path(path) => Self::path_type(ctx, path)?, - Literal(lit) => Self::literal_type(ctx, lit)?, + Path(path) => Self::path_expr_type(ctx, path)?, + Literal(lit) => Self::literal_expr_type(ctx, lit)?, }) } - fn binary_op_type( + fn binary_op_expr_type( ctx: &Context, left: &ast::Expr<'_>, op: ast::OpBinary, @@ -161,7 +161,7 @@ impl Type { }) } - fn unary_op_type(ctx: &Context, op: ast::OpUnary, expr: &ast::Expr<'_>) -> Result { + fn unary_op_expr_type(ctx: &Context, op: ast::OpUnary, expr: &ast::Expr<'_>) -> Result { use ast::OpUnary::*; use Type::*; @@ -174,7 +174,7 @@ impl Type { }) } - fn index_type(ctx: &Context, expr: &ast::Expr<'_>, index: &ast::Expr<'_>) -> Result { + fn index_expr_type(ctx: &Context, expr: &ast::Expr<'_>, index: &ast::Expr<'_>) -> Result { use Type::*; let expr_type = Self::ast_expr_type(ctx, expr)?; @@ -189,7 +189,7 @@ impl Type { Ok(*elem_type) } - fn apply_type(ctx: &Context, expr: &ast::Expr<'_>, params: &[ast::Expr]) -> Result { + fn apply_expr_type(ctx: &Context, expr: &ast::Expr<'_>, params: &[ast::Expr]) -> Result { use Type::*; let expr_type = Self::ast_expr_type(ctx, expr)?; @@ -212,7 +212,7 @@ impl Type { Ok(func.ret) } - fn method_type( + fn method_expr_type( ctx: &Context, expr: &ast::Expr<'_>, method: &ast::Ident<'_>, @@ -241,7 +241,11 @@ impl Type { Ok(method.typ.ret.clone()) } - fn field_type(ctx: &Context, expr: &ast::Expr<'_>, field: &ast::Ident<'_>) -> Result { + fn field_expr_type( + ctx: &Context, + expr: &ast::Expr<'_>, + field: &ast::Ident<'_>, + ) -> Result { use Type::*; let expr_type = Self::ast_expr_type(ctx, expr)?; @@ -257,7 +261,7 @@ impl Type { }) } - fn path_type(ctx: &Context, path: &ast::Path<'_>) -> Result { + fn path_expr_type(ctx: &Context, path: &ast::Path<'_>) -> Result { use Type::*; if path.components == [ast::Ident { name: "_" }] { @@ -286,7 +290,7 @@ impl Type { } } - fn literal_type(ctx: &Context, lit: &ast::Literal<'_>) -> Result { + fn literal_expr_type(ctx: &Context, lit: &ast::Literal<'_>) -> Result { use ast::Literal; use Type::*; -- cgit v1.2.3