Clippy on reduced_ast.rs
This commit is contained in:
parent
49a50deb04
commit
f8c2e57b37
@ -12,6 +12,9 @@
|
|||||||
//! then ReducedAST shouldn't be duplicating information that can be queried at runtime from the
|
//! then ReducedAST shouldn't be duplicating information that can be queried at runtime from the
|
||||||
//! symbol table. But I think the former might make sense since ultimately the bytecode will be
|
//! symbol table. But I think the former might make sense since ultimately the bytecode will be
|
||||||
//! built from the ReducedAST.
|
//! built from the ReducedAST.
|
||||||
|
|
||||||
|
#![allow(clippy::enum_variant_names)]
|
||||||
|
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
@ -141,6 +144,7 @@ impl<'a> Reducer<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::ptr_arg)]
|
||||||
fn block(&mut self, block: &Block) -> Vec<Stmt> {
|
fn block(&mut self, block: &Block) -> Vec<Stmt> {
|
||||||
block.iter().map(|stmt| self.statement(stmt)).collect()
|
block.iter().map(|stmt| self.statement(stmt)).collect()
|
||||||
}
|
}
|
||||||
@ -189,11 +193,11 @@ impl<'a> Reducer<'a> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
match spec {
|
match spec {
|
||||||
SymbolSpec::RecordConstructor { .. } => Expr::ReductionError(format!("AST reducer doesn't expect a RecordConstructor here")),
|
SymbolSpec::RecordConstructor { .. } => Expr::ReductionError("AST reducer doesn't expect a RecordConstructor here".to_string()),
|
||||||
SymbolSpec::DataConstructor { index, arity, type_name } => Expr::Constructor {
|
SymbolSpec::DataConstructor { index, arity, type_name } => Expr::Constructor {
|
||||||
type_name: type_name.clone(),
|
type_name: type_name.clone(),
|
||||||
name: local_name.clone(),
|
name: local_name.clone(),
|
||||||
tag: index.clone(),
|
tag: *index,
|
||||||
arity: *arity,
|
arity: *arity,
|
||||||
},
|
},
|
||||||
SymbolSpec::Func(_) => Expr::Sym(local_name.clone()),
|
SymbolSpec::Func(_) => Expr::Sym(local_name.clone()),
|
||||||
@ -201,7 +205,8 @@ impl<'a> Reducer<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn reduce_lambda(&mut self, params: &Vec<FormalParam>, body: &Block) -> Expr {
|
#[allow(clippy::ptr_arg)]
|
||||||
|
fn reduce_lambda(&mut self, params: &[FormalParam], body: &Block) -> Expr {
|
||||||
Expr::Func(Func::UserDefined {
|
Expr::Func(Func::UserDefined {
|
||||||
name: None,
|
name: None,
|
||||||
params: params.iter().map(|param| param.name.clone()).collect(),
|
params: params.iter().map(|param| param.name.clone()).collect(),
|
||||||
@ -209,7 +214,7 @@ impl<'a> Reducer<'a> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn reduce_named_struct(&mut self, name: &QualifiedName, fields: &Vec<(Rc<String>, Expression)>) -> Expr {
|
fn reduce_named_struct(&mut self, name: &QualifiedName, fields: &[(Rc<String>, Expression)]) -> Expr {
|
||||||
let symbol = match self.symbol_table.lookup_symbol(&name.id) {
|
let symbol = match self.symbol_table.lookup_symbol(&name.id) {
|
||||||
Some(fqsn) => fqsn,
|
Some(fqsn) => fqsn,
|
||||||
None => return Expr::ReductionError(format!("FQSN lookup for name {:?} failed", name)),
|
None => return Expr::ReductionError(format!("FQSN lookup for name {:?} failed", name)),
|
||||||
@ -236,7 +241,7 @@ impl<'a> Reducer<'a> {
|
|||||||
Expr::Call { f, args }
|
Expr::Call { f, args }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn reduce_call_expression(&mut self, func: &Expression, arguments: &Vec<InvocationArgument>) -> Expr {
|
fn reduce_call_expression(&mut self, func: &Expression, arguments: &[ InvocationArgument ]) -> Expr {
|
||||||
Expr::Call {
|
Expr::Call {
|
||||||
f: Box::new(self.expression(func)),
|
f: Box::new(self.expression(func)),
|
||||||
args: arguments.iter().map(|arg| self.invocation_argument(arg)).collect(),
|
args: arguments.iter().map(|arg| self.invocation_argument(arg)).collect(),
|
||||||
@ -246,23 +251,23 @@ impl<'a> Reducer<'a> {
|
|||||||
fn reduce_if_expression(&mut self, discriminator: Option<&Expression>, body: &IfExpressionBody) -> Expr {
|
fn reduce_if_expression(&mut self, discriminator: Option<&Expression>, body: &IfExpressionBody) -> Expr {
|
||||||
let cond = Box::new(match discriminator {
|
let cond = Box::new(match discriminator {
|
||||||
Some(expr) => self.expression(expr),
|
Some(expr) => self.expression(expr),
|
||||||
None => return Expr::ReductionError(format!("blank cond if-expr not supported")),
|
None => return Expr::ReductionError("blank cond if-expr not supported".to_string()),
|
||||||
});
|
});
|
||||||
|
|
||||||
match body {
|
match body {
|
||||||
IfExpressionBody::SimpleConditional { then_case, else_case } => {
|
IfExpressionBody::SimpleConditional { then_case, else_case } => {
|
||||||
let then_clause = self.block(&then_case);
|
let then_clause = self.block(then_case);
|
||||||
let else_clause = match else_case.as_ref() {
|
let else_clause = match else_case.as_ref() {
|
||||||
None => vec![],
|
None => vec![],
|
||||||
Some(stmts) => self.block(&stmts),
|
Some(stmts) => self.block(stmts),
|
||||||
};
|
};
|
||||||
Expr::Conditional { cond, then_clause, else_clause }
|
Expr::Conditional { cond, then_clause, else_clause }
|
||||||
},
|
},
|
||||||
IfExpressionBody::SimplePatternMatch { pattern, then_case, else_case } => {
|
IfExpressionBody::SimplePatternMatch { pattern, then_case, else_case } => {
|
||||||
let then_clause = self.block(&then_case);
|
let then_clause = self.block(then_case);
|
||||||
let else_clause = match else_case.as_ref() {
|
let else_clause = match else_case.as_ref() {
|
||||||
None => vec![],
|
None => vec![],
|
||||||
Some(stmts) => self.block(&stmts),
|
Some(stmts) => self.block(stmts),
|
||||||
};
|
};
|
||||||
|
|
||||||
let alternatives = vec![
|
let alternatives = vec![
|
||||||
@ -368,7 +373,7 @@ impl<'a> Reducer<'a> {
|
|||||||
* x is SomeBigOldEnum(_, x, Some(t))
|
* x is SomeBigOldEnum(_, x, Some(t))
|
||||||
*/
|
*/
|
||||||
|
|
||||||
fn handle_symbol(symbol: Option<&Symbol>, inner_patterns: &Vec<Pattern>, symbol_table: &SymbolTable) -> Subpattern {
|
fn handle_symbol(symbol: Option<&Symbol>, inner_patterns: &[Pattern], symbol_table: &SymbolTable) -> Subpattern {
|
||||||
use self::Pattern::*;
|
use self::Pattern::*;
|
||||||
let tag = symbol.map(|symbol| match symbol.spec {
|
let tag = symbol.map(|symbol| match symbol.spec {
|
||||||
SymbolSpec::DataConstructor { index, .. } => index,
|
SymbolSpec::DataConstructor { index, .. } => index,
|
||||||
@ -451,7 +456,7 @@ impl Pattern {
|
|||||||
// if symbol is Some, treat this as a symbol pattern. If it's None, treat it
|
// if symbol is Some, treat this as a symbol pattern. If it's None, treat it
|
||||||
// as a variable.
|
// as a variable.
|
||||||
match symbol_table.lookup_symbol(id) {
|
match symbol_table.lookup_symbol(id) {
|
||||||
Some(symbol) => handle_symbol(Some(symbol), &vec![], symbol_table),
|
Some(symbol) => handle_symbol(Some(symbol), &[], symbol_table),
|
||||||
None => {
|
None => {
|
||||||
println!("Components: {:?}", components);
|
println!("Components: {:?}", components);
|
||||||
let name = if components.len() == 1 {
|
let name = if components.len() == 1 {
|
||||||
@ -480,8 +485,8 @@ impl PatternLiteral {
|
|||||||
let comparison = Expr::Lit(match (neg, num) {
|
let comparison = Expr::Lit(match (neg, num) {
|
||||||
(false, ExpressionKind::NatLiteral(n)) => Lit::Nat(*n),
|
(false, ExpressionKind::NatLiteral(n)) => Lit::Nat(*n),
|
||||||
(false, ExpressionKind::FloatLiteral(f)) => Lit::Float(*f),
|
(false, ExpressionKind::FloatLiteral(f)) => Lit::Float(*f),
|
||||||
(true, ExpressionKind::NatLiteral(n)) => Lit::Int(-1*(*n as i64)),
|
(true, ExpressionKind::NatLiteral(n)) => Lit::Int(-(*n as i64)),
|
||||||
(true, ExpressionKind::FloatLiteral(f)) => Lit::Float(-1.0*f),
|
(true, ExpressionKind::FloatLiteral(f)) => Lit::Float(-f),
|
||||||
_ => panic!("This should never happen")
|
_ => panic!("This should never happen")
|
||||||
});
|
});
|
||||||
let guard = Some(Expr::Call {
|
let guard = Some(Expr::Call {
|
||||||
|
Loading…
Reference in New Issue
Block a user