From 7f8ef878bbdc768e45b2e10406e0ff0a379a07f7 Mon Sep 17 00:00:00 2001 From: Glyphack Date: Sun, 27 Aug 2023 18:57:27 +0200 Subject: [PATCH] cargo clippy --- parser/src/lexer/lexer.rs | 6 +- parser/src/parser/ast.rs | 4 +- parser/src/parser/diagnostics.rs | 2 +- parser/src/parser/operator.rs | 2 +- parser/src/parser/parser.rs | 167 +++++++++++++------------- parser/src/parser/statement.rs | 6 +- parser/src/parser/string.rs | 14 +-- parser/src/token.rs | 2 +- typechecker/src/ast_visitor.rs | 120 +++++++++--------- typechecker/src/ast_visitor_immut.rs | 120 +++++++++--------- typechecker/src/build.rs | 2 +- typechecker/src/nodes.rs | 108 ++++++++--------- typechecker/src/semanal_utils.rs | 2 +- typechecker/src/semantic_analyzer.rs | 128 ++++++++++---------- typechecker/src/settings.rs | 2 +- typechecker/src/symbol_table.rs | 4 +- typechecker/src/type_check/checker.rs | 122 +++++++++---------- 17 files changed, 402 insertions(+), 409 deletions(-) diff --git a/parser/src/lexer/lexer.rs b/parser/src/lexer/lexer.rs index cac18573..e175b53a 100644 --- a/parser/src/lexer/lexer.rs +++ b/parser/src/lexer/lexer.rs @@ -112,7 +112,7 @@ impl Lexer { } } 3 => { - if curr == str_finisher.chars().nth(0).unwrap() + if curr == str_finisher.chars().next().unwrap() && self.peek() == Some(str_finisher.chars().nth(1).unwrap()) && self.double_peek() == Some(str_finisher.chars().nth(2).unwrap()) { @@ -140,7 +140,7 @@ impl Lexer { } } 3 => { - if peeked_char == str_finisher.chars().nth(0).unwrap() + if peeked_char == str_finisher.chars().next().unwrap() && self.double_peek() == Some(str_finisher.chars().nth(1).unwrap()) && self.triple_peek() == Some(str_finisher.chars().nth(2).unwrap()) { @@ -160,7 +160,7 @@ impl Lexer { return Ok(indent_kind); } } - if self.fstring_stack.len() > 0 { + if !self.fstring_stack.is_empty() { if let Some(kind) = self.next_fstring_token() { return Ok(kind); } diff --git a/parser/src/parser/ast.rs b/parser/src/parser/ast.rs index 7f6a636b..04e4fa74 100644 --- a/parser/src/parser/ast.rs +++ b/parser/src/parser/ast.rs @@ -26,8 +26,8 @@ trait GetNode { impl From for SourceSpan { fn from(val: Node) -> Self { Self::new( - SourceOffset::from(val.start as usize), - SourceOffset::from(val.len() as usize), + SourceOffset::from(val.start), + SourceOffset::from(val.len()), ) } } diff --git a/parser/src/parser/diagnostics.rs b/parser/src/parser/diagnostics.rs index 6af094ff..25c53bc5 100644 --- a/parser/src/parser/diagnostics.rs +++ b/parser/src/parser/diagnostics.rs @@ -1,4 +1,4 @@ -use crate::{parser::ast::Node, token::Kind}; +use crate::{parser::ast::Node}; use miette::{self, Diagnostic}; use thiserror::{self, Error}; diff --git a/parser/src/parser/operator.rs b/parser/src/parser/operator.rs index c5790d46..216f60f7 100644 --- a/parser/src/parser/operator.rs +++ b/parser/src/parser/operator.rs @@ -1,4 +1,4 @@ -use crate::parser::ast::{BinaryOperator, BooleanOperator, UnaryOperator}; +use crate::parser::ast::{BooleanOperator, UnaryOperator}; use crate::token::Kind; pub fn is_bool_op(kind: &Kind) -> bool { diff --git a/parser/src/parser/parser.rs b/parser/src/parser/parser.rs index 534e2550..d6f8c257 100644 --- a/parser/src/parser/parser.rs +++ b/parser/src/parser/parser.rs @@ -1,4 +1,4 @@ -use std::ops::Index; + use std::{panic, vec}; use crate::lexer::lexer::Lexer; @@ -48,7 +48,7 @@ impl Parser { let node = self.start_node(); let mut body = vec![]; while self.cur_kind() != Kind::Eof { - let stmt = if is_at_compound_statement(&self.cur_token()) { + let stmt = if is_at_compound_statement(self.cur_token()) { self.parse_compount_statement() } else { self.parse_simple_statement() @@ -675,7 +675,8 @@ impl Parser { } fn parse_closed_pattern(&mut self) -> Result { - let matching_pattern = match self.cur_kind() { + + match self.cur_kind() { Kind::LeftParen => self.parse_sequence_pattern(), Kind::LeftBrace => self.parse_sequence_pattern(), Kind::LeftBracket => self.parse_mapping_pattern(), @@ -689,13 +690,11 @@ impl Parser { } else { self.parse_value_pattern(value, node) } + } else if matches!(self.peek_kind(), Ok(Kind::LeftParen)) { + let value = self.parse_attr()?; + self.parse_class_pattern(value) } else { - if matches!(self.peek_kind(), Ok(Kind::LeftParen)) { - let value = self.parse_attr()?; - self.parse_class_pattern(value) - } else { - self.parse_capture_or_wildcard_pattern() - } + self.parse_capture_or_wildcard_pattern() } }, Kind::Integer @@ -720,13 +719,12 @@ impl Parser { let node = self.start_node(); let msg = format!("unexpected token {:?}", self.cur_token().value); self.bump_any(); - return Err(diagnostics::InvalidSyntax( + Err(diagnostics::InvalidSyntax( msg, self.finish_node(node), ).into()) }, - }; - matching_pattern + } } // https://docs.python.org/3/reference/compound_stmts.html#literal-patterns @@ -789,7 +787,7 @@ impl Parser { attr: attr_val, }))); } - return expr; + expr } // TODO: This has precedence over sequence pattern but I'm not sure @@ -948,7 +946,8 @@ impl Parser { fn parse_assignment_or_expression_statement(&mut self) -> Result { let node = self.start_node(); let lhs = self.parse_expression()?; - let stmt = if self.cur_kind() == Kind::Assign { + + if self.cur_kind() == Kind::Assign { self.parse_assignment_statement(node, lhs) } else if matches!( self.cur_kind(), @@ -970,8 +969,7 @@ impl Parser { self.parse_ann_assign_statement(node, lhs) } else { Ok(Statement::ExpressionStatement(lhs)) - }; - stmt + } } // https://docs.python.org/3/reference/compound_stmts.html#grammar-token-python-grammar-suite @@ -993,14 +991,14 @@ impl Parser { // https://docs.python.org/3/reference/compound_stmts.html#grammar-token-python-grammar-statement fn parse_statement(&mut self) -> Result> { - let stmt = if is_at_compound_statement(&self.cur_token()) { + + if is_at_compound_statement(self.cur_token()) { let comp_stmt = self.parse_compount_statement()?; Ok(vec![comp_stmt]) } else { - let stmt_list = self.parse_statement_list(); - stmt_list - }; - stmt + + self.parse_statement_list() + } } // https://docs.python.org/3/reference/simple_stmts.html#grammar-token-python-grammar-stmt-list @@ -1048,11 +1046,11 @@ impl Parser { break rhs; } }; - return Ok(Statement::AssignStatement(Assign { + Ok(Statement::AssignStatement(Assign { node: self.finish_node(start), targets, value, - })); + })) } fn parse_aug_assignment_statement( @@ -1063,12 +1061,12 @@ impl Parser { let op = self.parse_aug_assign_op()?; let value = self.parse_assignment_value()?; - return Ok(Statement::AugAssignStatement(AugAssign { + Ok(Statement::AugAssignStatement(AugAssign { node: self.finish_node(start), target: lhs, op, value, - })); + })) } fn parse_ann_assign_statement(&mut self, start: Node, lhs: Expression) -> Result { @@ -1079,21 +1077,21 @@ impl Parser { } else { None }; - return Ok(Statement::AnnAssignStatement(AnnAssign { + Ok(Statement::AnnAssignStatement(AnnAssign { node: self.finish_node(start), target: lhs, annotation, value, // TODO: implement simple simple: true, - })); + })) } // The value is either expression list or yield expression // https://docs.python.org/3/reference/simple_stmts.html#assignment-statements fn parse_assignment_value(&mut self) -> Result { if self.cur_kind() == Kind::Yield { - return Ok(self.parse_yield_expression()?); + return self.parse_yield_expression(); } self.parse_expression_list() } @@ -1135,19 +1133,19 @@ impl Parser { None }; - return Ok(Statement::Assert(Assert { + Ok(Statement::Assert(Assert { node: self.finish_node(node), test, msg, - })); + })) } fn parse_pass_statement(&mut self) -> Result { let node = self.start_node(); self.bump(Kind::Pass); - return Ok(Statement::Pass(Pass { + Ok(Statement::Pass(Pass { node: self.finish_node(node), - })); + })) } fn parse_return_statement(&mut self) -> Result { @@ -1158,10 +1156,10 @@ impl Parser { } else { Some(self.parse_expression_list()?) }; - return Ok(Statement::Return(Return { + Ok(Statement::Return(Return { node: self.finish_node(node), value, - })); + })) } // https://docs.python.org/3/reference/simple_stmts.html#the-raise-statement @@ -1178,29 +1176,29 @@ impl Parser { } else { None }; - return Ok(Statement::Raise(Raise { + Ok(Statement::Raise(Raise { node: self.finish_node(node), exc, cause, - })); + })) } // https://docs.python.org/3/reference/simple_stmts.html#the-break-statement fn parse_break_statement(&mut self) -> Result { let node = self.start_node(); self.bump(Kind::Break); - return Ok(Statement::Break(Break { + Ok(Statement::Break(Break { node: self.finish_node(node), - })); + })) } // https://docs.python.org/3/reference/simple_stmts.html#the-continue-statement fn parse_continue_statement(&mut self) -> Result { let node = self.start_node(); self.bump(Kind::Continue); - return Ok(Statement::Continue(Continue { + Ok(Statement::Continue(Continue { node: self.finish_node(node), - })); + })) } // https://docs.python.org/3/reference/simple_stmts.html#the-global-statement @@ -1216,10 +1214,10 @@ impl Parser { break; } } - return Ok(Statement::Global(Global { + Ok(Statement::Global(Global { node: self.finish_node(node), names, - })); + })) } // https://docs.python.org/3/reference/simple_stmts.html#the-nonlocal-statement @@ -1235,10 +1233,10 @@ impl Parser { break; } } - return Ok(Statement::Nonlocal(Nonlocal { + Ok(Statement::Nonlocal(Nonlocal { node: self.finish_node(node), names, - })); + })) } // https://docs.python.org/3/reference/simple_stmts.html#the-import-statement @@ -1256,10 +1254,10 @@ impl Parser { break; } } - return Ok(Statement::Import(Import { + Ok(Statement::Import(Import { node: self.finish_node(node), names: aliases, - })); + })) } // https://docs.python.org/3/reference/simple_stmts.html#the-from-import-statement @@ -1279,12 +1277,12 @@ impl Parser { break; } } - return Ok(Statement::ImportFrom(ImportFrom { + Ok(Statement::ImportFrom(ImportFrom { node: self.finish_node(import_node), module, names: aliases, level: 0, - })); + })) } fn parse_alias(&mut self, name: String, node: Node) -> Alias { @@ -1295,22 +1293,22 @@ impl Parser { } else { None }; - return Alias { + Alias { node: self.finish_node(node), name, asname, - }; + } } fn parse_module_name(&mut self) -> String { - let mut module = String::from(self.cur_token().value.to_string()); + let mut module = self.cur_token().value.to_string(); self.bump(Kind::Identifier); while self.eat(Kind::Dot) { module.push('.'); module.push_str(self.cur_token().value.to_string().as_str()); self.bump(Kind::Identifier); } - return module; + module } // https://docs.python.org/3/library/ast.html#ast.Expr @@ -1331,10 +1329,10 @@ impl Parser { return Ok(expr); } - return Ok(Expression::Tuple(Box::new(Tuple { + Ok(Expression::Tuple(Box::new(Tuple { node: self.finish_node(node), elements: exprs, - }))); + }))) } // https://docs.python.org/3/reference/expressions.html#conditional-expressions @@ -1446,7 +1444,7 @@ impl Parser { // https://docs.python.org/3/reference/expressions.html#displays-for-lists-sets-and-dictionaries fn parse_comp_for(&mut self) -> Result> { // if current token is async - let is_async = if self.eat(Kind::Async) { true } else { false }; + let is_async = self.eat(Kind::Async); let mut generators = vec![]; loop { @@ -1662,7 +1660,7 @@ impl Parser { fn parse_starred_item(&mut self) -> Result { let mut node = self.start_node(); if self.eat(Kind::Mul) { - let starred_value_kind = self.cur_kind().clone(); + let starred_value_kind = self.cur_kind(); let expr = self.parse_or_expr()?; node = self.finish_node(node); if !is_iterable(&expr) { @@ -1776,7 +1774,7 @@ impl Parser { right: Box::new(lhs), }))); } - return Ok(xor_expr); + Ok(xor_expr) } // https://docs.python.org/3/reference/expressions.html#binary-bitwise-operations @@ -1792,7 +1790,7 @@ impl Parser { right: Box::new(lhs), }))); } - return Ok(and_expr); + Ok(and_expr) } // https://docs.python.org/3/reference/expressions.html#binary-bitwise-operations @@ -1809,7 +1807,7 @@ impl Parser { right: Box::new(lhs), }))); } - return Ok(shift_expr); + Ok(shift_expr) } // https://docs.python.org/3/reference/expressions.html#shifting-operations @@ -1831,7 +1829,7 @@ impl Parser { right: Box::new(lhs), }))); } - return Ok(arith_expr); + Ok(arith_expr) } // https://docs.python.org/3/reference/expressions.html#binary-arithmetic-operations @@ -1848,7 +1846,7 @@ impl Parser { right: Box::new(rhs), }))); } - return Ok(lhs); + Ok(lhs) } // https://docs.python.org/3/reference/expressions.html#unary-arithmetic-and-bitwise-operations @@ -1890,7 +1888,7 @@ impl Parser { }))); } - return base; + base } // https://docs.python.org/3/reference/expressions.html#primaries @@ -1982,7 +1980,7 @@ impl Parser { Ok(atom_or_primary) }; - return primary; + primary } // https://docs.python.org/3/reference/expressions.html#grammar-token-python-grammar-argument_list @@ -2044,7 +2042,7 @@ impl Parser { break; } } - return Ok((positional_args, keyword_args)); + Ok((positional_args, keyword_args)) } fn parse_atribute_ref(&mut self, node: Node, value: Expression) -> Result { @@ -2058,7 +2056,7 @@ impl Parser { attr: attr_val, }))); } - return expr; + expr } fn parse_subscript(&mut self, node: Node, value: Expression) -> Result { @@ -2071,14 +2069,14 @@ impl Parser { slice: Box::new(slice), }))); } - return expr; + expr } // https://docs.python.org/3/reference/expressions.html#atoms fn parse_atom(&mut self) -> Result { let node = self.start_node(); if self.at(Kind::Yield) { - return self.parse_yield_expression(); + self.parse_yield_expression() } else if self.at(Kind::LeftBrace) { self.nested_expression_list += 1; let list_expr = self.parse_list(); @@ -2150,10 +2148,10 @@ impl Parser { let node = self.start_node(); let value = self.cur_token().value.to_string(); self.expect(Kind::Identifier)?; - return Ok(Expression::Name(Box::new(Name { + Ok(Expression::Name(Box::new(Name { node: self.finish_node(node), id: value, - }))); + }))) } // https://docs.python.org/3/reference/expressions.html#yield-expressions @@ -2178,10 +2176,10 @@ impl Parser { Ok(expr) => Some(Box::new(expr)), _ => None, }; - return Ok(Expression::Yield(Box::new(Yield { + Ok(Expression::Yield(Box::new(Yield { node: self.finish_node(yield_node), value, - }))); + }))) } // https://docs.python.org/3/reference/expressions.html#expression-lists @@ -2267,12 +2265,10 @@ impl Parser { let slice_lower = if lower.is_some() { Some(Box::new(lower.unwrap())) + } else if self.eat(Kind::Colon) { + None } else { - if self.eat(Kind::Colon) { - None - } else { - Some(Box::new(self.parse_expression_2()?)) - } + Some(Box::new(self.parse_expression_2()?)) }; let upper = if self.eat(Kind::Colon) { if self.at(Kind::RightBrace) { @@ -2333,7 +2329,7 @@ impl Parser { let bytes_val = extract_string_inside( value .to_string() - .strip_prefix("b") + .strip_prefix('b') .expect("bytes literal must start with b") .to_string(), ) @@ -2579,7 +2575,7 @@ impl Parser { } fn is_def_parameter(&mut self) -> bool { - return self.cur_kind() == Kind::Identifier; + self.cur_kind() == Kind::Identifier // && matches!(self.peek_kind(), Ok(Kind::Assign)) // || matches!(self.peek_kind(), Ok(Kind::Colon)) } @@ -2862,7 +2858,8 @@ mod tests { #[test] fn test_named_expression() { - for test_case in &["(a := b)"] { + { + let test_case = &"(a := b)"; let mut parser = Parser::new(test_case.to_string()); let program = parser.parse(); @@ -3000,7 +2997,8 @@ mod tests { #[test] fn test_starred() { - for test_case in &["(*a)"] { + { + let test_case = &"(*a)"; let mut parser = Parser::new(test_case.to_string()); let program = parser.parse(); @@ -3015,7 +3013,8 @@ mod tests { #[test] fn test_await_expression() { - for test_case in &["await a"] { + { + let test_case = &"await a"; let mut parser = Parser::new(test_case.to_string()); let program = parser.parse(); @@ -3139,10 +3138,8 @@ mod tests { #[test] fn test_conditional_expression() { - for test_case in &[ - // "a if b else c", - "a if b else c if d else e", - ] { + { + let test_case = &"a if b else c if d else e"; let mut parser = Parser::new(test_case.to_string()); let program = parser.parse(); diff --git a/parser/src/parser/statement.rs b/parser/src/parser/statement.rs index d30f3d51..88b1da50 100644 --- a/parser/src/parser/statement.rs +++ b/parser/src/parser/statement.rs @@ -18,10 +18,8 @@ pub fn is_at_compound_statement(token: &Token) -> bool { return true; } - if Kind::Identifier == token.kind { - if token.value.to_string() == "match" { - return true; - } + if Kind::Identifier == token.kind && token.value.to_string() == "match" { + return true; } false diff --git a/parser/src/parser/string.rs b/parser/src/parser/string.rs index cac50656..ae256561 100644 --- a/parser/src/parser/string.rs +++ b/parser/src/parser/string.rs @@ -10,22 +10,22 @@ pub fn extract_string_inside(val: String) -> String { val.strip_suffix("\"\"\"") .expect("String must be enclosed with \"\"\"") .to_string() - } else if let Some(val) = val.strip_prefix("\"") { - val.strip_suffix("\"") + } else if let Some(val) = val.strip_prefix('\"') { + val.strip_suffix('\"') .expect("String must be enclosed with \"") .to_string() } else if let Some(val) = val.strip_prefix("'''") { val.strip_suffix("'''") .expect("String must be enclosed with '''") .to_string() - } else if let Some(val) = val.strip_prefix("'") { - val.strip_suffix("'") + } else if let Some(val) = val.strip_prefix('\'') { + val.strip_suffix('\'') .expect("String must be enclosed with '") .to_string() } else { panic!( "String must be enclosed in \"\"\", \"', ''' or ' but got {} ", - val.starts_with("\'") + val.starts_with('\'') ); } } @@ -63,14 +63,14 @@ pub fn concat_string_exprs(lhs: Expression, rhs: Expression) -> Result { + (ConstantValue::Bytes(_lhs), _) => { return Err(diagnostics::InvalidSyntax( "Cannot concat bytes and string".to_string(), node, ) .into()) } - (_, ConstantValue::Bytes(rhs)) => { + (_, ConstantValue::Bytes(_rhs)) => { return Err(diagnostics::InvalidSyntax( "Cannot concat string and bytes".to_string(), node, diff --git a/parser/src/token.rs b/parser/src/token.rs index 9efbd109..b9b06980 100644 --- a/parser/src/token.rs +++ b/parser/src/token.rs @@ -281,7 +281,7 @@ impl TokenValue { TokenValue::None => "None".to_string(), TokenValue::Number(n) => n.to_string(), TokenValue::Str(s) => s.to_string(), - TokenValue::Indent(i) => panic!("not a string"), + TokenValue::Indent(_i) => panic!("not a string"), } } } diff --git a/typechecker/src/ast_visitor.rs b/typechecker/src/ast_visitor.rs index 7888b3c3..5ac901a0 100644 --- a/typechecker/src/ast_visitor.rs +++ b/typechecker/src/ast_visitor.rs @@ -135,43 +135,43 @@ pub trait TraversalVisitor { Expression::FormattedValue(f) => self.visit_formatted_value(f), } } - fn visit_import(&mut self, i: &Import) { + fn visit_import(&mut self, _i: &Import) { todo!(); } - fn visit_import_from(&mut self, i: &ImportFrom) { + fn visit_import_from(&mut self, _i: &ImportFrom) { todo!(); } fn visit_if(&mut self, i: &parser::ast::If) { for stmt in &i.body { - self.visit_stmt(&stmt); + self.visit_stmt(stmt); } for stmt in &i.orelse { - self.visit_stmt(&stmt); + self.visit_stmt(stmt); } } fn visit_while(&mut self, w: &parser::ast::While) { for stmt in &w.body { - self.visit_stmt(&stmt) + self.visit_stmt(stmt) } } fn visit_for(&mut self, f: &parser::ast::For) { for stmt in &f.body { - self.visit_stmt(&stmt); + self.visit_stmt(stmt); } } fn visit_with(&mut self, w: &parser::ast::With) { for stmt in &w.body { - self.visit_stmt(&stmt); + self.visit_stmt(stmt); } for with_items in &w.items { - self.visit_expr(&*&with_items.context_expr); + self.visit_expr(&with_items.context_expr); match &with_items.optional_vars { - Some(items) => self.visit_expr(&items), + Some(items) => self.visit_expr(items), None => (), } } @@ -179,189 +179,189 @@ pub trait TraversalVisitor { fn visit_try(&mut self, t: &parser::ast::Try) { for stmt in &t.body { - self.visit_stmt(&stmt); + self.visit_stmt(stmt); } for stmt in &t.orelse { - self.visit_stmt(&stmt); + self.visit_stmt(stmt); } for stmt in &t.finalbody { - self.visit_stmt(&stmt); + self.visit_stmt(stmt); } // TODO: need to visit exception handler name and type but let's keep it simple for now for handler in &t.handlers { for stmt in &handler.body { - self.visit_stmt(&stmt); + self.visit_stmt(stmt); } } } fn visit_try_star(&mut self, t: &parser::ast::TryStar) { for stmt in &t.body { - self.visit_stmt(&stmt); + self.visit_stmt(stmt); } for stmt in &t.orelse { - self.visit_stmt(&stmt); + self.visit_stmt(stmt); } for stmt in &t.finalbody { - self.visit_stmt(&stmt); + self.visit_stmt(stmt); } // TODO: need to visit exception handler name and type but let's keep it simple for now for handler in &t.handlers { for stmt in &handler.body { - self.visit_stmt(&stmt); + self.visit_stmt(stmt); } } } fn visit_function_def(&mut self, f: &parser::ast::FunctionDef) { for stmt in &f.body { - self.visit_stmt(&stmt); + self.visit_stmt(stmt); } } fn visit_class_def(&mut self, c: &parser::ast::ClassDef) { for stmt in &c.body { - self.visit_stmt(&stmt); + self.visit_stmt(stmt); } } fn visit_match(&mut self, m: &parser::ast::Match) { for case in &m.cases { for stmt in &case.body { - self.visit_stmt(&stmt); + self.visit_stmt(stmt); } } } - fn visit_constant(&mut self, c: &Constant) { + fn visit_constant(&mut self, _c: &Constant) { todo!() } - fn visit_list(&mut self, l: &List) { + fn visit_list(&mut self, _l: &List) { todo!() } - fn visit_tuple(&mut self, t: &Tuple) { + fn visit_tuple(&mut self, _t: &Tuple) { todo!() } - fn visit_dict(&mut self, d: &Dict) { + fn visit_dict(&mut self, _d: &Dict) { todo!() } - fn visit_set(&mut self, s: &Set) { + fn visit_set(&mut self, _s: &Set) { todo!() } - fn visit_name(&mut self, n: &Name) {} - fn visit_bool_op(&mut self, b: &BoolOperation) { + fn visit_name(&mut self, _n: &Name) {} + fn visit_bool_op(&mut self, _b: &BoolOperation) { todo!() } - fn visit_unary_op(&mut self, u: &UnaryOperation) { + fn visit_unary_op(&mut self, _u: &UnaryOperation) { todo!() } - fn visit_bin_op(&mut self, b: &BinOp) { + fn visit_bin_op(&mut self, _b: &BinOp) { todo!() } - fn visit_named_expr(&mut self, n: &NamedExpression) { + fn visit_named_expr(&mut self, _n: &NamedExpression) { todo!() } - fn visit_yield(&mut self, y: &Yield) { + fn visit_yield(&mut self, _y: &Yield) { todo!() } - fn visit_yield_from(&mut self, y: &YieldFrom) { + fn visit_yield_from(&mut self, _y: &YieldFrom) { todo!() } - fn visit_starred(&mut self, s: &Starred) { + fn visit_starred(&mut self, _s: &Starred) { todo!() } - fn visit_generator(&mut self, g: &Generator) { + fn visit_generator(&mut self, _g: &Generator) { todo!() } - fn visit_list_comp(&mut self, l: &ListComp) { + fn visit_list_comp(&mut self, _l: &ListComp) { todo!() } - fn visit_set_comp(&mut self, s: &SetComp) { + fn visit_set_comp(&mut self, _s: &SetComp) { todo!() } - fn visit_dict_comp(&mut self, d: &DictComp) { + fn visit_dict_comp(&mut self, _d: &DictComp) { todo!() } - fn visit_attribute(&mut self, a: &Attribute) { + fn visit_attribute(&mut self, _a: &Attribute) { todo!() } - fn visit_subscript(&mut self, s: &Subscript) { + fn visit_subscript(&mut self, _s: &Subscript) { todo!() } - fn visit_slice(&mut self, s: &Slice) { + fn visit_slice(&mut self, _s: &Slice) { todo!() } - fn visit_call(&mut self, c: &Call) { + fn visit_call(&mut self, _c: &Call) { todo!() } - fn visit_await(&mut self, a: &Await) { + fn visit_await(&mut self, _a: &Await) { todo!() } - fn visit_compare(&mut self, c: &Compare) { + fn visit_compare(&mut self, _c: &Compare) { todo!() } - fn visit_lambda(&mut self, l: &Lambda) { + fn visit_lambda(&mut self, _l: &Lambda) { todo!() } - fn visit_if_exp(&mut self, i: &IfExp) { + fn visit_if_exp(&mut self, _i: &IfExp) { todo!() } - fn visit_joined_str(&mut self, j: &JoinedStr) { + fn visit_joined_str(&mut self, _j: &JoinedStr) { todo!() } - fn visit_formatted_value(&mut self, f: &FormattedValue) { + fn visit_formatted_value(&mut self, _f: &FormattedValue) { todo!() } - fn visit_alias(&mut self, a: &Alias) { + fn visit_alias(&mut self, _a: &Alias) { todo!() } - fn visit_assign(&mut self, a: &Assign) { + fn visit_assign(&mut self, _a: &Assign) { todo!() } - fn visit_ann_assign(&mut self, a: &AnnAssign) { + fn visit_ann_assign(&mut self, _a: &AnnAssign) { todo!() } - fn visit_aug_assign(&mut self, a: &AugAssign) { + fn visit_aug_assign(&mut self, _a: &AugAssign) { todo!() } - fn visit_assert(&mut self, a: &Assert) { + fn visit_assert(&mut self, _a: &Assert) { todo!() } - fn visit_pass(&mut self, p: &Pass) { + fn visit_pass(&mut self, _p: &Pass) { todo!() } - fn visit_delete(&mut self, d: &Delete) { + fn visit_delete(&mut self, _d: &Delete) { todo!() } - fn visit_return(&mut self, r: &Return) { + fn visit_return(&mut self, _r: &Return) { todo!() } - fn visit_raise(&mut self, r: &Raise) { + fn visit_raise(&mut self, _r: &Raise) { todo!() } - fn visit_break(&mut self, b: &Break) { + fn visit_break(&mut self, _b: &Break) { todo!() } - fn visit_continue(&mut self, c: &Continue) { + fn visit_continue(&mut self, _c: &Continue) { todo!() } - fn visit_global(&mut self, g: &Global) { + fn visit_global(&mut self, _g: &Global) { todo!() } - fn visit_nonlocal(&mut self, n: &Nonlocal) { + fn visit_nonlocal(&mut self, _n: &Nonlocal) { todo!() } } diff --git a/typechecker/src/ast_visitor_immut.rs b/typechecker/src/ast_visitor_immut.rs index 1e480538..fa5321cd 100644 --- a/typechecker/src/ast_visitor_immut.rs +++ b/typechecker/src/ast_visitor_immut.rs @@ -63,43 +63,43 @@ pub trait TraversalVisitorImmut { Expression::FormattedValue(f) => self.visit_formatted_value(f), } } - fn visit_import(&self, i: &Import) { + fn visit_import(&self, _i: &Import) { todo!(); } - fn visit_import_from(&self, i: &ImportFrom) { + fn visit_import_from(&self, _i: &ImportFrom) { todo!(); } fn visit_if(&self, i: &parser::ast::If) { for stmt in &i.body { - self.visit_stmt(&stmt); + self.visit_stmt(stmt); } for stmt in &i.orelse { - self.visit_stmt(&stmt); + self.visit_stmt(stmt); } } fn visit_while(&self, w: &parser::ast::While) { for stmt in &w.body { - self.visit_stmt(&stmt) + self.visit_stmt(stmt) } } fn visit_for(&self, f: &parser::ast::For) { for stmt in &f.body { - self.visit_stmt(&stmt); + self.visit_stmt(stmt); } } fn visit_with(&self, w: &parser::ast::With) { for stmt in &w.body { - self.visit_stmt(&stmt); + self.visit_stmt(stmt); } for with_items in &w.items { - self.visit_expr(&*&with_items.context_expr); + self.visit_expr(&with_items.context_expr); match &with_items.optional_vars { - Some(items) => self.visit_expr(&items), + Some(items) => self.visit_expr(items), None => (), } } @@ -107,189 +107,189 @@ pub trait TraversalVisitorImmut { fn visit_try(&self, t: &parser::ast::Try) { for stmt in &t.body { - self.visit_stmt(&stmt); + self.visit_stmt(stmt); } for stmt in &t.orelse { - self.visit_stmt(&stmt); + self.visit_stmt(stmt); } for stmt in &t.finalbody { - self.visit_stmt(&stmt); + self.visit_stmt(stmt); } // TODO: need to visit exception handler name and type but let's keep it simple for now for handler in &t.handlers { for stmt in &handler.body { - self.visit_stmt(&stmt); + self.visit_stmt(stmt); } } } fn visit_try_star(&self, t: &parser::ast::TryStar) { for stmt in &t.body { - self.visit_stmt(&stmt); + self.visit_stmt(stmt); } for stmt in &t.orelse { - self.visit_stmt(&stmt); + self.visit_stmt(stmt); } for stmt in &t.finalbody { - self.visit_stmt(&stmt); + self.visit_stmt(stmt); } // TODO: need to visit exception handler name and type but let's keep it simple for now for handler in &t.handlers { for stmt in &handler.body { - self.visit_stmt(&stmt); + self.visit_stmt(stmt); } } } fn visit_function_def(&self, f: &parser::ast::FunctionDef) { for stmt in &f.body { - self.visit_stmt(&stmt); + self.visit_stmt(stmt); } } fn visit_class_def(&self, c: &parser::ast::ClassDef) { for stmt in &c.body { - self.visit_stmt(&stmt); + self.visit_stmt(stmt); } } fn visit_match(&self, m: &parser::ast::Match) { for case in &m.cases { for stmt in &case.body { - self.visit_stmt(&stmt); + self.visit_stmt(stmt); } } } - fn visit_constant(&self, c: &Constant) { + fn visit_constant(&self, _c: &Constant) { todo!() } - fn visit_list(&self, l: &List) { + fn visit_list(&self, _l: &List) { todo!() } - fn visit_tuple(&self, t: &Tuple) { + fn visit_tuple(&self, _t: &Tuple) { todo!() } - fn visit_dict(&self, d: &Dict) { + fn visit_dict(&self, _d: &Dict) { todo!() } - fn visit_set(&self, s: &Set) { + fn visit_set(&self, _s: &Set) { todo!() } - fn visit_name(&self, n: &Name) {} - fn visit_bool_op(&self, b: &BoolOperation) { + fn visit_name(&self, _n: &Name) {} + fn visit_bool_op(&self, _b: &BoolOperation) { todo!() } - fn visit_unary_op(&self, u: &UnaryOperation) { + fn visit_unary_op(&self, _u: &UnaryOperation) { todo!() } - fn visit_bin_op(&self, b: &BinOp) { + fn visit_bin_op(&self, _b: &BinOp) { todo!() } - fn visit_named_expr(&self, n: &NamedExpression) { + fn visit_named_expr(&self, _n: &NamedExpression) { todo!() } - fn visit_yield(&self, y: &Yield) { + fn visit_yield(&self, _y: &Yield) { todo!() } - fn visit_yield_from(&self, y: &YieldFrom) { + fn visit_yield_from(&self, _y: &YieldFrom) { todo!() } - fn visit_starred(&self, s: &Starred) { + fn visit_starred(&self, _s: &Starred) { todo!() } - fn visit_generator(&self, g: &Generator) { + fn visit_generator(&self, _g: &Generator) { todo!() } - fn visit_list_comp(&self, l: &ListComp) { + fn visit_list_comp(&self, _l: &ListComp) { todo!() } - fn visit_set_comp(&self, s: &SetComp) { + fn visit_set_comp(&self, _s: &SetComp) { todo!() } - fn visit_dict_comp(&self, d: &DictComp) { + fn visit_dict_comp(&self, _d: &DictComp) { todo!() } - fn visit_attribute(&self, a: &Attribute) { + fn visit_attribute(&self, _a: &Attribute) { todo!() } - fn visit_subscript(&self, s: &Subscript) { + fn visit_subscript(&self, _s: &Subscript) { todo!() } - fn visit_slice(&self, s: &Slice) { + fn visit_slice(&self, _s: &Slice) { todo!() } - fn visit_call(&self, c: &Call) { + fn visit_call(&self, _c: &Call) { todo!() } - fn visit_await(&self, a: &Await) { + fn visit_await(&self, _a: &Await) { todo!() } - fn visit_compare(&self, c: &Compare) { + fn visit_compare(&self, _c: &Compare) { todo!() } - fn visit_lambda(&self, l: &Lambda) { + fn visit_lambda(&self, _l: &Lambda) { todo!() } - fn visit_if_exp(&self, i: &IfExp) { + fn visit_if_exp(&self, _i: &IfExp) { todo!() } - fn visit_joined_str(&self, j: &JoinedStr) { + fn visit_joined_str(&self, _j: &JoinedStr) { todo!() } - fn visit_formatted_value(&self, f: &FormattedValue) { + fn visit_formatted_value(&self, _f: &FormattedValue) { todo!() } - fn visit_alias(&self, a: &Alias) { + fn visit_alias(&self, _a: &Alias) { todo!() } - fn visit_assign(&self, a: &Assign) { + fn visit_assign(&self, _a: &Assign) { todo!() } - fn visit_ann_assign(&self, a: &AnnAssign) { + fn visit_ann_assign(&self, _a: &AnnAssign) { todo!() } - fn visit_aug_assign(&self, a: &AugAssign) { + fn visit_aug_assign(&self, _a: &AugAssign) { todo!() } - fn visit_assert(&self, a: &Assert) { + fn visit_assert(&self, _a: &Assert) { todo!() } - fn visit_pass(&self, p: &Pass) { + fn visit_pass(&self, _p: &Pass) { todo!() } - fn visit_delete(&self, d: &Delete) { + fn visit_delete(&self, _d: &Delete) { todo!() } - fn visit_return(&self, r: &Return) { + fn visit_return(&self, _r: &Return) { todo!() } - fn visit_raise(&self, r: &Raise) { + fn visit_raise(&self, _r: &Raise) { todo!() } - fn visit_break(&self, b: &Break) { + fn visit_break(&self, _b: &Break) { todo!() } - fn visit_continue(&self, c: &Continue) { + fn visit_continue(&self, _c: &Continue) { todo!() } - fn visit_global(&self, g: &Global) { + fn visit_global(&self, _g: &Global) { todo!() } - fn visit_nonlocal(&self, n: &Nonlocal) { + fn visit_nonlocal(&self, _n: &Nonlocal) { todo!() } } diff --git a/typechecker/src/build.rs b/typechecker/src/build.rs index 185a4011..b01f74a2 100644 --- a/typechecker/src/build.rs +++ b/typechecker/src/build.rs @@ -117,7 +117,7 @@ fn snapshot_type_check(source: &str) -> String { ); manager.type_check(); - format!("{}", manager.errors.join("\n")) + manager.errors.join("\n").to_string() } #[cfg(test)] diff --git a/typechecker/src/nodes.rs b/typechecker/src/nodes.rs index 505d9aa4..e9ed5fa5 100755 --- a/typechecker/src/nodes.rs +++ b/typechecker/src/nodes.rs @@ -120,33 +120,33 @@ impl<'a> TraversalVisitor for EnderpyFile { fn visit_if(&mut self, i: &parser::ast::If) { for stmt in &i.body { - self.visit_stmt(&stmt); + self.visit_stmt(stmt); } for stmt in &i.orelse { - self.visit_stmt(&stmt); + self.visit_stmt(stmt); } } fn visit_while(&mut self, w: &parser::ast::While) { for stmt in &w.body { - self.visit_stmt(&stmt) + self.visit_stmt(stmt) } } fn visit_for(&mut self, f: &parser::ast::For) { for stmt in &f.body { - self.visit_stmt(&stmt); + self.visit_stmt(stmt); } } fn visit_with(&mut self, w: &parser::ast::With) { for stmt in &w.body { - self.visit_stmt(&stmt); + self.visit_stmt(stmt); } for with_items in &w.items { - self.visit_expr(&*&with_items.context_expr); + self.visit_expr(&with_items.context_expr); match &with_items.optional_vars { - Some(items) => self.visit_expr(&items), + Some(items) => self.visit_expr(items), None => (), } } @@ -154,36 +154,36 @@ impl<'a> TraversalVisitor for EnderpyFile { fn visit_try(&mut self, t: &parser::ast::Try) { for stmt in &t.body { - self.visit_stmt(&stmt); + self.visit_stmt(stmt); } for stmt in &t.orelse { - self.visit_stmt(&stmt); + self.visit_stmt(stmt); } for stmt in &t.finalbody { - self.visit_stmt(&stmt); + self.visit_stmt(stmt); } // TODO: need to visit exception handler name and type but let's keep it simple for now for handler in &t.handlers { for stmt in &handler.body { - self.visit_stmt(&stmt); + self.visit_stmt(stmt); } } } fn visit_try_star(&mut self, t: &parser::ast::TryStar) { for stmt in &t.body { - self.visit_stmt(&stmt); + self.visit_stmt(stmt); } for stmt in &t.orelse { - self.visit_stmt(&stmt); + self.visit_stmt(stmt); } for stmt in &t.finalbody { - self.visit_stmt(&stmt); + self.visit_stmt(stmt); } // TODO: need to visit exception handler name and type but let's keep it simple for now for handler in &t.handlers { for stmt in &handler.body { - self.visit_stmt(&stmt); + self.visit_stmt(stmt); } } } @@ -201,66 +201,66 @@ impl<'a> TraversalVisitor for EnderpyFile { fn visit_match(&mut self, m: &parser::ast::Match) { for case in &m.cases { for stmt in &case.body { - self.visit_stmt(&stmt); + self.visit_stmt(stmt); } } } - fn visit_constant(&mut self, c: &parser::ast::Constant) {} + fn visit_constant(&mut self, _c: &parser::ast::Constant) {} - fn visit_list(&mut self, l: &parser::ast::List) {} + fn visit_list(&mut self, _l: &parser::ast::List) {} - fn visit_tuple(&mut self, t: &parser::ast::Tuple) {} + fn visit_tuple(&mut self, _t: &parser::ast::Tuple) {} - fn visit_dict(&mut self, d: &parser::ast::Dict) {} + fn visit_dict(&mut self, _d: &parser::ast::Dict) {} - fn visit_set(&mut self, s: &parser::ast::Set) {} + fn visit_set(&mut self, _s: &parser::ast::Set) {} - fn visit_name(&mut self, n: &parser::ast::Name) {} + fn visit_name(&mut self, _n: &parser::ast::Name) {} - fn visit_bool_op(&mut self, b: &parser::ast::BoolOperation) {} + fn visit_bool_op(&mut self, _b: &parser::ast::BoolOperation) {} - fn visit_unary_op(&mut self, u: &parser::ast::UnaryOperation) {} + fn visit_unary_op(&mut self, _u: &parser::ast::UnaryOperation) {} - fn visit_bin_op(&mut self, b: &parser::ast::BinOp) {} + fn visit_bin_op(&mut self, _b: &parser::ast::BinOp) {} - fn visit_named_expr(&mut self, n: &parser::ast::NamedExpression) {} + fn visit_named_expr(&mut self, _n: &parser::ast::NamedExpression) {} - fn visit_yield(&mut self, y: &parser::ast::Yield) {} + fn visit_yield(&mut self, _y: &parser::ast::Yield) {} - fn visit_yield_from(&mut self, y: &parser::ast::YieldFrom) {} + fn visit_yield_from(&mut self, _y: &parser::ast::YieldFrom) {} - fn visit_starred(&mut self, s: &parser::ast::Starred) {} + fn visit_starred(&mut self, _s: &parser::ast::Starred) {} - fn visit_generator(&mut self, g: &parser::ast::Generator) {} + fn visit_generator(&mut self, _g: &parser::ast::Generator) {} - fn visit_list_comp(&mut self, l: &parser::ast::ListComp) {} + fn visit_list_comp(&mut self, _l: &parser::ast::ListComp) {} - fn visit_set_comp(&mut self, s: &parser::ast::SetComp) {} + fn visit_set_comp(&mut self, _s: &parser::ast::SetComp) {} - fn visit_dict_comp(&mut self, d: &parser::ast::DictComp) {} + fn visit_dict_comp(&mut self, _d: &parser::ast::DictComp) {} - fn visit_attribute(&mut self, a: &parser::ast::Attribute) {} + fn visit_attribute(&mut self, _a: &parser::ast::Attribute) {} - fn visit_subscript(&mut self, s: &parser::ast::Subscript) {} + fn visit_subscript(&mut self, _s: &parser::ast::Subscript) {} - fn visit_slice(&mut self, s: &parser::ast::Slice) {} + fn visit_slice(&mut self, _s: &parser::ast::Slice) {} - fn visit_call(&mut self, c: &parser::ast::Call) {} + fn visit_call(&mut self, _c: &parser::ast::Call) {} - fn visit_await(&mut self, a: &parser::ast::Await) {} + fn visit_await(&mut self, _a: &parser::ast::Await) {} - fn visit_compare(&mut self, c: &parser::ast::Compare) {} + fn visit_compare(&mut self, _c: &parser::ast::Compare) {} - fn visit_lambda(&mut self, l: &parser::ast::Lambda) {} + fn visit_lambda(&mut self, _l: &parser::ast::Lambda) {} - fn visit_if_exp(&mut self, i: &parser::ast::IfExp) {} + fn visit_if_exp(&mut self, _i: &parser::ast::IfExp) {} - fn visit_joined_str(&mut self, j: &parser::ast::JoinedStr) {} + fn visit_joined_str(&mut self, _j: &parser::ast::JoinedStr) {} - fn visit_formatted_value(&mut self, f: &parser::ast::FormattedValue) {} + fn visit_formatted_value(&mut self, _f: &parser::ast::FormattedValue) {} - fn visit_alias(&mut self, a: &parser::ast::Alias) {} + fn visit_alias(&mut self, _a: &parser::ast::Alias) {} fn visit_assign(&mut self, a: &parser::ast::Assign) { let stmt = a.clone(); @@ -272,23 +272,23 @@ impl<'a> TraversalVisitor for EnderpyFile { self.defs.push(Statement::AnnAssignStatement(stmt)); } - fn visit_aug_assign(&mut self, a: &parser::ast::AugAssign) {} + fn visit_aug_assign(&mut self, _a: &parser::ast::AugAssign) {} - fn visit_assert(&mut self, a: &parser::ast::Assert) {} + fn visit_assert(&mut self, _a: &parser::ast::Assert) {} - fn visit_pass(&mut self, p: &parser::ast::Pass) {} + fn visit_pass(&mut self, _p: &parser::ast::Pass) {} - fn visit_delete(&mut self, d: &parser::ast::Delete) {} + fn visit_delete(&mut self, _d: &parser::ast::Delete) {} - fn visit_return(&mut self, r: &parser::ast::Return) {} + fn visit_return(&mut self, _r: &parser::ast::Return) {} - fn visit_raise(&mut self, r: &parser::ast::Raise) {} + fn visit_raise(&mut self, _r: &parser::ast::Raise) {} - fn visit_break(&mut self, b: &parser::ast::Break) {} + fn visit_break(&mut self, _b: &parser::ast::Break) {} - fn visit_continue(&mut self, c: &parser::ast::Continue) {} + fn visit_continue(&mut self, _c: &parser::ast::Continue) {} - fn visit_global(&mut self, g: &parser::ast::Global) {} + fn visit_global(&mut self, _g: &parser::ast::Global) {} - fn visit_nonlocal(&mut self, n: &parser::ast::Nonlocal) {} + fn visit_nonlocal(&mut self, _n: &parser::ast::Nonlocal) {} } diff --git a/typechecker/src/semanal_utils.rs b/typechecker/src/semanal_utils.rs index 1e16fa70..8b137891 100644 --- a/typechecker/src/semanal_utils.rs +++ b/typechecker/src/semanal_utils.rs @@ -1 +1 @@ -use parser::ast::Expression; + diff --git a/typechecker/src/semantic_analyzer.rs b/typechecker/src/semantic_analyzer.rs index dab4189f..f868d5ba 100644 --- a/typechecker/src/semantic_analyzer.rs +++ b/typechecker/src/semantic_analyzer.rs @@ -1,4 +1,4 @@ -use std::collections::HashMap; + use parser::ast::Expression; @@ -24,12 +24,12 @@ pub struct SemanticAnalyzer { impl SemanticAnalyzer { pub fn new(file: Box) -> Self { let globals = SymbolTable::new(crate::symbol_table::SymbolTableType::Module, 0); - return SemanticAnalyzer { + SemanticAnalyzer { globals, file, errors: vec![], scope: SymbolScope::Global, - }; + } } fn create_symbol(&mut self, name: String, decl: Declaration) { @@ -42,7 +42,7 @@ impl SemanticAnalyzer { fn report_unresolved_reference(&mut self) { self.errors - .push(String::from(format!("cannot resolve reference {}", ""))) + .push(format!("cannot resolve reference {}", "")) } fn current_scope(&self) -> &SymbolTableType { @@ -50,7 +50,7 @@ impl SemanticAnalyzer { } fn is_inside_class(&self) -> bool { - return matches!(self.current_scope(), SymbolTableType::Class); + matches!(self.current_scope(), SymbolTableType::Class) } fn create_variable_declaration_symbol( @@ -255,43 +255,43 @@ impl TraversalVisitor for SemanticAnalyzer { } } - fn visit_import(&mut self, i: &parser::ast::Import) { + fn visit_import(&mut self, _i: &parser::ast::Import) { todo!(); } - fn visit_import_from(&mut self, i: &parser::ast::ImportFrom) { + fn visit_import_from(&mut self, _i: &parser::ast::ImportFrom) { todo!(); } fn visit_if(&mut self, i: &parser::ast::If) { for stmt in &i.body { - self.visit_stmt(&stmt); + self.visit_stmt(stmt); } for stmt in &i.orelse { - self.visit_stmt(&stmt); + self.visit_stmt(stmt); } } fn visit_while(&mut self, w: &parser::ast::While) { for stmt in &w.body { - self.visit_stmt(&stmt) + self.visit_stmt(stmt) } } fn visit_for(&mut self, f: &parser::ast::For) { for stmt in &f.body { - self.visit_stmt(&stmt); + self.visit_stmt(stmt); } } fn visit_with(&mut self, w: &parser::ast::With) { for stmt in &w.body { - self.visit_stmt(&stmt); + self.visit_stmt(stmt); } for with_items in &w.items { - self.visit_expr(&*&with_items.context_expr); + self.visit_expr(&with_items.context_expr); match &with_items.optional_vars { - Some(items) => self.visit_expr(&items), + Some(items) => self.visit_expr(items), None => (), } } @@ -299,36 +299,36 @@ impl TraversalVisitor for SemanticAnalyzer { fn visit_try(&mut self, t: &parser::ast::Try) { for stmt in &t.body { - self.visit_stmt(&stmt); + self.visit_stmt(stmt); } for stmt in &t.orelse { - self.visit_stmt(&stmt); + self.visit_stmt(stmt); } for stmt in &t.finalbody { - self.visit_stmt(&stmt); + self.visit_stmt(stmt); } // TODO: need to visit exception handler name and type but let's keep it simple for now for handler in &t.handlers { for stmt in &handler.body { - self.visit_stmt(&stmt); + self.visit_stmt(stmt); } } } fn visit_try_star(&mut self, t: &parser::ast::TryStar) { for stmt in &t.body { - self.visit_stmt(&stmt); + self.visit_stmt(stmt); } for stmt in &t.orelse { - self.visit_stmt(&stmt); + self.visit_stmt(stmt); } for stmt in &t.finalbody { - self.visit_stmt(&stmt); + self.visit_stmt(stmt); } // TODO: need to visit exception handler name and type but let's keep it simple for now for handler in &t.handlers { for stmt in &handler.body { - self.visit_stmt(&stmt); + self.visit_stmt(stmt); } } } @@ -349,7 +349,7 @@ impl TraversalVisitor for SemanticAnalyzer { let mut yeild_statements = vec![]; let mut raise_statements = vec![]; for stmt in &f.body { - self.visit_stmt(&stmt); + self.visit_stmt(stmt); match &stmt { parser::ast::Statement::Raise(r) => raise_statements.push(r.clone()), parser::ast::Statement::Return(r) => return_statements.push(r.clone()), @@ -391,7 +391,7 @@ impl TraversalVisitor for SemanticAnalyzer { } _ => (), } - self.visit_stmt(&stmt); + self.visit_stmt(stmt); } self.globals.exit_scope(); @@ -405,116 +405,115 @@ impl TraversalVisitor for SemanticAnalyzer { fn visit_match(&mut self, m: &parser::ast::Match) { for case in &m.cases { for stmt in &case.body { - self.visit_stmt(&stmt); + self.visit_stmt(stmt); } } } - fn visit_constant(&mut self, c: &parser::ast::Constant) {} + fn visit_constant(&mut self, _c: &parser::ast::Constant) {} - fn visit_list(&mut self, l: &parser::ast::List) { + fn visit_list(&mut self, _l: &parser::ast::List) { todo!() } - fn visit_tuple(&mut self, t: &parser::ast::Tuple) { - return; + fn visit_tuple(&mut self, _t: &parser::ast::Tuple) { } - fn visit_dict(&mut self, d: &parser::ast::Dict) { + fn visit_dict(&mut self, _d: &parser::ast::Dict) { todo!() } - fn visit_set(&mut self, s: &parser::ast::Set) { + fn visit_set(&mut self, _s: &parser::ast::Set) { todo!() } - fn visit_name(&mut self, n: &parser::ast::Name) { + fn visit_name(&mut self, _n: &parser::ast::Name) { todo!() } - fn visit_bool_op(&mut self, b: &parser::ast::BoolOperation) { + fn visit_bool_op(&mut self, _b: &parser::ast::BoolOperation) { todo!() } - fn visit_unary_op(&mut self, u: &parser::ast::UnaryOperation) { + fn visit_unary_op(&mut self, _u: &parser::ast::UnaryOperation) { todo!() } - fn visit_bin_op(&mut self, b: &parser::ast::BinOp) {} + fn visit_bin_op(&mut self, _b: &parser::ast::BinOp) {} - fn visit_named_expr(&mut self, n: &parser::ast::NamedExpression) { + fn visit_named_expr(&mut self, _n: &parser::ast::NamedExpression) { todo!() } - fn visit_yield(&mut self, y: &parser::ast::Yield) { + fn visit_yield(&mut self, _y: &parser::ast::Yield) { todo!() } - fn visit_yield_from(&mut self, y: &parser::ast::YieldFrom) { + fn visit_yield_from(&mut self, _y: &parser::ast::YieldFrom) { todo!() } - fn visit_starred(&mut self, s: &parser::ast::Starred) { + fn visit_starred(&mut self, _s: &parser::ast::Starred) { todo!() } - fn visit_generator(&mut self, g: &parser::ast::Generator) { + fn visit_generator(&mut self, _g: &parser::ast::Generator) { todo!() } - fn visit_list_comp(&mut self, l: &parser::ast::ListComp) { + fn visit_list_comp(&mut self, _l: &parser::ast::ListComp) { todo!() } - fn visit_set_comp(&mut self, s: &parser::ast::SetComp) { + fn visit_set_comp(&mut self, _s: &parser::ast::SetComp) { todo!() } - fn visit_dict_comp(&mut self, d: &parser::ast::DictComp) { + fn visit_dict_comp(&mut self, _d: &parser::ast::DictComp) { todo!() } - fn visit_attribute(&mut self, a: &parser::ast::Attribute) { + fn visit_attribute(&mut self, _a: &parser::ast::Attribute) { todo!() } - fn visit_subscript(&mut self, s: &parser::ast::Subscript) { + fn visit_subscript(&mut self, _s: &parser::ast::Subscript) { todo!() } - fn visit_slice(&mut self, s: &parser::ast::Slice) { + fn visit_slice(&mut self, _s: &parser::ast::Slice) { todo!() } - fn visit_call(&mut self, c: &parser::ast::Call) { + fn visit_call(&mut self, _c: &parser::ast::Call) { todo!() } - fn visit_await(&mut self, a: &parser::ast::Await) { + fn visit_await(&mut self, _a: &parser::ast::Await) { todo!() } - fn visit_compare(&mut self, c: &parser::ast::Compare) { + fn visit_compare(&mut self, _c: &parser::ast::Compare) { todo!() } - fn visit_lambda(&mut self, l: &parser::ast::Lambda) { + fn visit_lambda(&mut self, _l: &parser::ast::Lambda) { todo!() } - fn visit_if_exp(&mut self, i: &parser::ast::IfExp) { + fn visit_if_exp(&mut self, _i: &parser::ast::IfExp) { todo!() } - fn visit_joined_str(&mut self, j: &parser::ast::JoinedStr) { + fn visit_joined_str(&mut self, _j: &parser::ast::JoinedStr) { todo!() } - fn visit_formatted_value(&mut self, f: &parser::ast::FormattedValue) { + fn visit_formatted_value(&mut self, _f: &parser::ast::FormattedValue) { todo!() } - fn visit_alias(&mut self, a: &parser::ast::Alias) { + fn visit_alias(&mut self, _a: &parser::ast::Alias) { todo!() } @@ -553,7 +552,7 @@ impl TraversalVisitor for SemanticAnalyzer { ); if let Some(val) = &a.value { - self.visit_expr(&val); + self.visit_expr(val); } } @@ -562,37 +561,36 @@ impl TraversalVisitor for SemanticAnalyzer { self.visit_expr(&a.value); } - fn visit_assert(&mut self, a: &parser::ast::Assert) { + fn visit_assert(&mut self, _a: &parser::ast::Assert) { todo!() } - fn visit_pass(&mut self, p: &parser::ast::Pass) { - return; + fn visit_pass(&mut self, _p: &parser::ast::Pass) { } - fn visit_delete(&mut self, d: &parser::ast::Delete) { + fn visit_delete(&mut self, _d: &parser::ast::Delete) { todo!() } - fn visit_return(&mut self, r: &parser::ast::Return) {} + fn visit_return(&mut self, _r: &parser::ast::Return) {} - fn visit_raise(&mut self, r: &parser::ast::Raise) { + fn visit_raise(&mut self, _r: &parser::ast::Raise) { todo!() } - fn visit_break(&mut self, b: &parser::ast::Break) { + fn visit_break(&mut self, _b: &parser::ast::Break) { todo!() } - fn visit_continue(&mut self, c: &parser::ast::Continue) { + fn visit_continue(&mut self, _c: &parser::ast::Continue) { todo!() } - fn visit_global(&mut self, g: &parser::ast::Global) { + fn visit_global(&mut self, _g: &parser::ast::Global) { todo!() } - fn visit_nonlocal(&mut self, n: &parser::ast::Nonlocal) { + fn visit_nonlocal(&mut self, _n: &parser::ast::Nonlocal) { todo!() } } diff --git a/typechecker/src/settings.rs b/typechecker/src/settings.rs index 07818c80..2d9441a0 100644 --- a/typechecker/src/settings.rs +++ b/typechecker/src/settings.rs @@ -17,7 +17,7 @@ pub struct Settings { impl Settings { pub fn new() -> Result { - let run_mode = env::var("RUN_MODE").unwrap_or_else(|_| "development".into()); + let _run_mode = env::var("RUN_MODE").unwrap_or_else(|_| "development".into()); let s = Config::builder() // Start off by merging in the "default" configuration file .add_source(File::with_name("examples/hierarchical-env/config/default")) diff --git a/typechecker/src/symbol_table.rs b/typechecker/src/symbol_table.rs index 12b31b95..595b517d 100644 --- a/typechecker/src/symbol_table.rs +++ b/typechecker/src/symbol_table.rs @@ -112,7 +112,7 @@ pub enum SymbolScope { } impl SymbolTable { - pub fn new(symbol_table_type: SymbolTableType, start_line_number: u8) -> Self { + pub fn new(symbol_table_type: SymbolTableType, _start_line_number: u8) -> Self { let global_scope = SymbolTableScope { symbol_table_type, symbols: HashMap::new(), @@ -126,7 +126,7 @@ impl SymbolTable { fn current_scope(&self) -> &SymbolTableScope { if let Some(scope) = self.scopes.last() { - return &scope; + scope } else { panic!("no scopes") } diff --git a/typechecker/src/type_check/checker.rs b/typechecker/src/type_check/checker.rs index 38c6b27a..5e91d2ed 100644 --- a/typechecker/src/type_check/checker.rs +++ b/typechecker/src/type_check/checker.rs @@ -7,7 +7,7 @@ use crate::{ }; use super::{ - type_inference::{self, type_check_bin_op, type_equal}, + type_inference::{self, type_check_bin_op}, types::Type, }; @@ -29,7 +29,7 @@ impl<'a> TypeChecker<'a> { pub fn type_check(&mut self) { for stmt in &self.module.file.body { - self.visit_stmt(&stmt); + self.visit_stmt(stmt); } } @@ -131,44 +131,44 @@ impl<'a> TraversalVisitor for TypeChecker<'a> { } } - fn visit_import(&mut self, i: &Import) { + fn visit_import(&mut self, _i: &Import) { todo!(); } - fn visit_import_from(&mut self, i: &ImportFrom) { + fn visit_import_from(&mut self, _i: &ImportFrom) { todo!(); } fn visit_if(&mut self, i: &parser::ast::If) { // self.visit_stmt(i.test); for stmt in &i.body { - self.visit_stmt(&stmt); + self.visit_stmt(stmt); } for stmt in &i.orelse { - self.visit_stmt(&stmt); + self.visit_stmt(stmt); } } fn visit_while(&mut self, w: &parser::ast::While) { for stmt in &w.body { - self.visit_stmt(&stmt) + self.visit_stmt(stmt) } } fn visit_for(&mut self, f: &parser::ast::For) { for stmt in &f.body { - self.visit_stmt(&stmt); + self.visit_stmt(stmt); } } fn visit_with(&mut self, w: &parser::ast::With) { for stmt in &w.body { - self.visit_stmt(&stmt); + self.visit_stmt(stmt); } for with_items in &w.items { - self.visit_expr(&*&with_items.context_expr); + self.visit_expr(&with_items.context_expr); match &with_items.optional_vars { - Some(items) => self.visit_expr(&items), + Some(items) => self.visit_expr(items), None => (), } } @@ -176,85 +176,85 @@ impl<'a> TraversalVisitor for TypeChecker<'a> { fn visit_try(&mut self, t: &parser::ast::Try) { for stmt in &t.body { - self.visit_stmt(&stmt); + self.visit_stmt(stmt); } for stmt in &t.orelse { - self.visit_stmt(&stmt); + self.visit_stmt(stmt); } for stmt in &t.finalbody { - self.visit_stmt(&stmt); + self.visit_stmt(stmt); } // TODO: need to visit exception handler name and type but let's keep it simple for now for handler in &t.handlers { for stmt in &handler.body { - self.visit_stmt(&stmt); + self.visit_stmt(stmt); } } } fn visit_try_star(&mut self, t: &parser::ast::TryStar) { for stmt in &t.body { - self.visit_stmt(&stmt); + self.visit_stmt(stmt); } for stmt in &t.orelse { - self.visit_stmt(&stmt); + self.visit_stmt(stmt); } for stmt in &t.finalbody { - self.visit_stmt(&stmt); + self.visit_stmt(stmt); } // TODO: need to visit exception handler name and type but let's keep it simple for now for handler in &t.handlers { for stmt in &handler.body { - self.visit_stmt(&stmt); + self.visit_stmt(stmt); } } } fn visit_function_def(&mut self, f: &parser::ast::FunctionDef) { for stmt in &f.body { - self.visit_stmt(&stmt); + self.visit_stmt(stmt); } } fn visit_class_def(&mut self, c: &parser::ast::ClassDef) { for stmt in &c.body { - self.visit_stmt(&stmt); + self.visit_stmt(stmt); } } fn visit_match(&mut self, m: &parser::ast::Match) { for case in &m.cases { for stmt in &case.body { - self.visit_stmt(&stmt); + self.visit_stmt(stmt); } } } - fn visit_constant(&mut self, c: &Constant) {} + fn visit_constant(&mut self, _c: &Constant) {} - fn visit_list(&mut self, l: &List) { + fn visit_list(&mut self, _l: &List) { todo!() } - fn visit_tuple(&mut self, t: &Tuple) { + fn visit_tuple(&mut self, _t: &Tuple) { todo!() } - fn visit_dict(&mut self, d: &Dict) { + fn visit_dict(&mut self, _d: &Dict) { todo!() } - fn visit_set(&mut self, s: &Set) { + fn visit_set(&mut self, _s: &Set) { todo!() } - fn visit_name(&mut self, n: &Name) {} + fn visit_name(&mut self, _n: &Name) {} - fn visit_bool_op(&mut self, b: &BoolOperation) { + fn visit_bool_op(&mut self, _b: &BoolOperation) { todo!() } - fn visit_unary_op(&mut self, u: &UnaryOperation) { + fn visit_unary_op(&mut self, _u: &UnaryOperation) { todo!() } @@ -272,123 +272,123 @@ impl<'a> TraversalVisitor for TypeChecker<'a> { } } - fn visit_named_expr(&mut self, n: &NamedExpression) { + fn visit_named_expr(&mut self, _n: &NamedExpression) { todo!() } - fn visit_yield(&mut self, y: &Yield) { + fn visit_yield(&mut self, _y: &Yield) { todo!() } - fn visit_yield_from(&mut self, y: &YieldFrom) { + fn visit_yield_from(&mut self, _y: &YieldFrom) { todo!() } - fn visit_starred(&mut self, s: &Starred) { + fn visit_starred(&mut self, _s: &Starred) { todo!() } - fn visit_generator(&mut self, g: &Generator) { + fn visit_generator(&mut self, _g: &Generator) { todo!() } - fn visit_list_comp(&mut self, l: &ListComp) { + fn visit_list_comp(&mut self, _l: &ListComp) { todo!() } - fn visit_set_comp(&mut self, s: &SetComp) { + fn visit_set_comp(&mut self, _s: &SetComp) { todo!() } - fn visit_dict_comp(&mut self, d: &DictComp) { + fn visit_dict_comp(&mut self, _d: &DictComp) { todo!() } - fn visit_attribute(&mut self, a: &Attribute) { + fn visit_attribute(&mut self, _a: &Attribute) { todo!() } - fn visit_subscript(&mut self, s: &Subscript) { + fn visit_subscript(&mut self, _s: &Subscript) { todo!() } - fn visit_slice(&mut self, s: &Slice) { + fn visit_slice(&mut self, _s: &Slice) { todo!() } - fn visit_call(&mut self, c: &Call) { + fn visit_call(&mut self, _c: &Call) { todo!() } - fn visit_await(&mut self, a: &Await) { + fn visit_await(&mut self, _a: &Await) { todo!() } - fn visit_compare(&mut self, c: &Compare) { + fn visit_compare(&mut self, _c: &Compare) { todo!() } - fn visit_lambda(&mut self, l: &Lambda) { + fn visit_lambda(&mut self, _l: &Lambda) { todo!() } - fn visit_if_exp(&mut self, i: &IfExp) { + fn visit_if_exp(&mut self, _i: &IfExp) { todo!() } - fn visit_joined_str(&mut self, j: &JoinedStr) { + fn visit_joined_str(&mut self, _j: &JoinedStr) { todo!() } - fn visit_formatted_value(&mut self, f: &FormattedValue) { + fn visit_formatted_value(&mut self, _f: &FormattedValue) { todo!() } - fn visit_alias(&mut self, a: &Alias) { + fn visit_alias(&mut self, _a: &Alias) { todo!() } - fn visit_assign(&mut self, a: &Assign) {} + fn visit_assign(&mut self, _a: &Assign) {} - fn visit_ann_assign(&mut self, a: &AnnAssign) {} + fn visit_ann_assign(&mut self, _a: &AnnAssign) {} - fn visit_aug_assign(&mut self, a: &AugAssign) { + fn visit_aug_assign(&mut self, _a: &AugAssign) { todo!() } - fn visit_assert(&mut self, a: &Assert) { + fn visit_assert(&mut self, _a: &Assert) { todo!() } - fn visit_pass(&mut self, p: &Pass) { + fn visit_pass(&mut self, _p: &Pass) { todo!() } - fn visit_delete(&mut self, d: &Delete) { + fn visit_delete(&mut self, _d: &Delete) { todo!() } - fn visit_return(&mut self, r: &Return) { + fn visit_return(&mut self, _r: &Return) { todo!() } - fn visit_raise(&mut self, r: &Raise) { + fn visit_raise(&mut self, _r: &Raise) { todo!() } - fn visit_break(&mut self, b: &Break) { + fn visit_break(&mut self, _b: &Break) { todo!() } - fn visit_continue(&mut self, c: &Continue) { + fn visit_continue(&mut self, _c: &Continue) { todo!() } - fn visit_global(&mut self, g: &Global) { + fn visit_global(&mut self, _g: &Global) { todo!() } - fn visit_nonlocal(&mut self, n: &Nonlocal) { + fn visit_nonlocal(&mut self, _n: &Nonlocal) { todo!() } }