From b01d0f6fbb9892aacefdf0e6b96732fe56f4addc Mon Sep 17 00:00:00 2001 From: pca006132 Date: Thu, 5 Aug 2021 14:55:09 +0800 Subject: [PATCH] formatting --- nac3core/src/typecheck/function_check.rs | 40 +++++-------------- nac3core/src/typecheck/location.rs | 2 +- nac3core/src/typecheck/symbol_resolver.rs | 2 +- nac3core/src/typecheck/type_inferencer/mod.rs | 20 +++++----- 4 files changed, 24 insertions(+), 40 deletions(-) diff --git a/nac3core/src/typecheck/function_check.rs b/nac3core/src/typecheck/function_check.rs index c114f67f..92509ccc 100644 --- a/nac3core/src/typecheck/function_check.rs +++ b/nac3core/src/typecheck/function_check.rs @@ -22,9 +22,7 @@ impl<'a> Inferencer<'a> { } Ok(()) } - _ => { - self.check_expr(pattern, defined_identifiers) - } + _ => self.check_expr(pattern, defined_identifiers), } } @@ -46,7 +44,10 @@ impl<'a> Inferencer<'a> { match &expr.node { ExprKind::Name { id, .. } => { if !defined_identifiers.contains(id) { - return Err(format!("unknown identifier {} (use before def?) at {}", id, expr.location)); + return Err(format!( + "unknown identifier {} (use before def?) at {}", + id, expr.location + )); } } ExprKind::List { elts, .. } @@ -66,9 +67,7 @@ impl<'a> Inferencer<'a> { ExprKind::UnaryOp { operand, .. } => { self.check_expr(operand, defined_identifiers)?; } - ExprKind::Compare { - left, comparators, .. - } => { + ExprKind::Compare { left, comparators, .. } => { for elt in once(left.as_ref()).chain(comparators.iter()) { self.check_expr(elt, defined_identifiers)?; } @@ -83,10 +82,7 @@ impl<'a> Inferencer<'a> { self.check_expr(orelse, defined_identifiers)?; } ExprKind::Slice { lower, upper, step } => { - for elt in [lower.as_ref(), upper.as_ref(), step.as_ref()] - .iter() - .flatten() - { + for elt in [lower.as_ref(), upper.as_ref(), step.as_ref()].iter().flatten() { self.check_expr(elt, defined_identifiers)?; } } @@ -99,13 +95,9 @@ impl<'a> Inferencer<'a> { } self.check_expr(body, &defined_identifiers)?; } - ExprKind::ListComp { - elt, generators, .. - } => { + ExprKind::ListComp { elt, generators, .. } => { // in our type inference stage, we already make sure that there is only 1 generator - let ast::Comprehension { - target, iter, ifs, .. - } = &generators[0]; + let ast::Comprehension { target, iter, ifs, .. } = &generators[0]; self.check_expr(iter, defined_identifiers)?; let mut defined_identifiers = defined_identifiers.to_vec(); self.check_pattern(target, &mut defined_identifiers)?; @@ -113,11 +105,7 @@ impl<'a> Inferencer<'a> { self.check_expr(term, &defined_identifiers)?; } } - ExprKind::Call { - func, - args, - keywords, - } => { + ExprKind::Call { func, args, keywords } => { for expr in once(func.as_ref()) .chain(args.iter()) .chain(keywords.iter().map(|v| v.node.value.as_ref())) @@ -141,13 +129,7 @@ impl<'a> Inferencer<'a> { defined_identifiers: &mut Vec, ) -> Result { match &stmt.node { - StmtKind::For { - target, - iter, - body, - orelse, - .. - } => { + StmtKind::For { target, iter, body, orelse, .. } => { self.check_expr(iter, defined_identifiers)?; for stmt in orelse.iter() { self.check_stmt(stmt, defined_identifiers)?; diff --git a/nac3core/src/typecheck/location.rs b/nac3core/src/typecheck/location.rs index 0165ef0a..424336f2 100644 --- a/nac3core/src/typecheck/location.rs +++ b/nac3core/src/typecheck/location.rs @@ -7,7 +7,7 @@ pub struct FileID(u32); #[derive(Clone, Copy, PartialEq)] pub enum Location { CodeRange(FileID, ast::Location), - Builtin + Builtin, } pub struct FileRegistry { diff --git a/nac3core/src/typecheck/symbol_resolver.rs b/nac3core/src/typecheck/symbol_resolver.rs index 33d56201..fd2ad3f4 100644 --- a/nac3core/src/typecheck/symbol_resolver.rs +++ b/nac3core/src/typecheck/symbol_resolver.rs @@ -1,6 +1,6 @@ use super::location::Location; -use super::top_level::DefinitionId; use super::typedef::Type; +use crate::top_level::DefinitionId; use rustpython_parser::ast::Expr; pub enum SymbolValue<'a> { diff --git a/nac3core/src/typecheck/type_inferencer/mod.rs b/nac3core/src/typecheck/type_inferencer/mod.rs index f474a66f..95ea2027 100644 --- a/nac3core/src/typecheck/type_inferencer/mod.rs +++ b/nac3core/src/typecheck/type_inferencer/mod.rs @@ -1,7 +1,7 @@ -use std::{cell::RefCell, sync::Arc}; use std::collections::HashMap; -use std::convert::{TryInto, From}; +use std::convert::{From, TryInto}; use std::iter::once; +use std::{cell::RefCell, sync::Arc}; use super::magic_methods::*; use super::symbol_resolver::SymbolResolver; @@ -24,10 +24,7 @@ pub struct CodeLocation { impl From for CodeLocation { fn from(loc: Location) -> CodeLocation { - CodeLocation { - row: loc.row(), - col: loc.column() - } + CodeLocation { row: loc.row(), col: loc.column() } } } @@ -190,8 +187,12 @@ impl<'a> Inferencer<'a> { params: Vec, ret: Type, ) -> InferenceResult { - let call = - Arc::new(Call { posargs: params, kwargs: HashMap::new(), ret, fun: RefCell::new(None) }); + let call = Arc::new(Call { + posargs: params, + kwargs: HashMap::new(), + ret, + fun: RefCell::new(None), + }); let call = self.unifier.add_ty(TypeEnum::TCall(vec![call].into())); let fields = once((method, call)).collect(); let record = self.unifier.add_record(fields); @@ -333,7 +334,8 @@ impl<'a> Inferencer<'a> { } let arg0 = self.fold_expr(args.remove(0))?; let ty = if let Some(arg) = args.pop() { - self.function_data.resolver + self.function_data + .resolver .parse_type_name(&arg) .ok_or_else(|| "error parsing type".to_string())? } else {