From 486fe3d9babeeaa39615629f4130696460cfced6 Mon Sep 17 00:00:00 2001 From: Evgeny Ukhanov Date: Mon, 28 Feb 2022 22:13:45 +0100 Subject: [PATCH] Fix clippy --- Makefile | 8 +++---- src/codegen/mod.rs | 3 +++ src/compiler/mod.rs | 6 ++--- src/llvm/macros.rs | 54 ++++++++++++++++++++++----------------------- src/parser/ast.rs | 1 + 5 files changed, 38 insertions(+), 34 deletions(-) diff --git a/Makefile b/Makefile index 9d7e5c0..7c5876a 100644 --- a/Makefile +++ b/Makefile @@ -1,12 +1,12 @@ clippy: - @cargo clippy + @cargo clippy -- -D warnings check: @cargo check release: @cargo build --release - + fmt: @cargo +nightly fmt @@ -29,7 +29,7 @@ cover: tst: @cargo test test_codegen_variable_let_and_print -- --nocapture - + x: release @target/release/i-lang tst.i - @ls -la build \ No newline at end of file + @ls -la build diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 1e120a8..8372c5e 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -37,6 +37,7 @@ pub enum CodegenError { } /// Codegen structure +#[allow(dead_code)] #[derive(Debug, Clone)] pub struct Codegen<'a> { ctx: Context, @@ -48,6 +49,7 @@ pub struct Codegen<'a> { ast: &'a Main<'a>, } +#[allow(dead_code)] #[derive(Debug, Clone)] pub struct FunctionDeclaration { name: String, @@ -587,6 +589,7 @@ impl<'a> Codegen<'a> { pub fn fn_main(ast: &'a Main) -> Result { #[cfg(feature = "fn_main")] println!("\t#[call] fn_main"); + let mut codegen = Self::new(ast); let module = codegen.fn_module()?; let global_let = codegen.fn_global_let()?; diff --git a/src/compiler/mod.rs b/src/compiler/mod.rs index 617bc12..021c4a5 100644 --- a/src/compiler/mod.rs +++ b/src/compiler/mod.rs @@ -79,7 +79,7 @@ pub fn ar_builder(app_name: String, build_dir: &str) -> Result<(), String> { let a_file_name = format!("{}/lib{}.a", build_dir, app_name); Command::new("ar") - .args(&["crs", &a_file_name, &obj_file_name]) + .args(["crs", &a_file_name, &obj_file_name]) .spawn() .map_err(|_| "Failed to run `ar` command".to_string())? .wait() @@ -95,7 +95,7 @@ pub fn ld_builder(app_name: String, build_dir: &str) -> Result<(), String> { let obj_file = Path::new(&obj_file_name); Command::new("ld") - .args(&[ + .args([ "-o", &app_file_name, "-dynamic-linker", @@ -121,7 +121,7 @@ pub fn gcc_builder(app_name: String, build_dir: &str) -> Result<(), String> { let obj_file = Path::new(&obj_file_name); Command::new("gcc") - .args(&["-o", &app_file_name, &a_file_name]) + .args(["-o", &app_file_name, &a_file_name]) .spawn() .map_err(|_| "Failed to run `gcc` command".to_string())? .wait() diff --git a/src/llvm/macros.rs b/src/llvm/macros.rs index 15c11bb..d051422 100644 --- a/src/llvm/macros.rs +++ b/src/llvm/macros.rs @@ -12,7 +12,7 @@ #[macro_export] macro_rules! alloca { ($ty:ident $res:expr) => { - crate::llvm::instructions::memory_access_addressing_operations::Alloca { + $crate::llvm::instructions::memory_access_addressing_operations::Alloca { result: $res.to_string(), alloc_ty: $ty, elements: None, @@ -22,7 +22,7 @@ macro_rules! alloca { } }; ($ty:ident $res:expr, $align:expr) => { - crate::llvm::instructions::memory_access_addressing_operations::Alloca { + $crate::llvm::instructions::memory_access_addressing_operations::Alloca { result: $res.to_string(), alloc_ty: $ty, elements: None, @@ -50,13 +50,13 @@ macro_rules! alloca { macro_rules! arg { ($($ty:ident $val:expr)? $(,$ty1:ident $val1:expr)*) => {{ let mut v = vec![]; - $( v.push(crate::llvm::functions::ArgumentList { + $( v.push($crate::llvm::functions::ArgumentList { parameter_type: Some($ty), attributes: None, name: Some(format!("%{}", $val)), variable_argument: false, });)? - $( v.push(crate::llvm::functions::ArgumentList { + $( v.push($crate::llvm::functions::ArgumentList { parameter_type: Some($ty1), attributes: None, name: Some(format!("%{}", $val1)), @@ -66,19 +66,19 @@ macro_rules! arg { }}; ($($ty:ident $val:expr)? $(,$ty1:ident $val1:expr)*, ...) => {{ let mut v = vec![]; - $( v.push(crate::llvm::functions::ArgumentList { + $( v.push($crate::llvm::functions::ArgumentList { parameter_type: Some($ty), attributes: None, name: Some(format!("%{}", $val)), variable_argument: false, });)? - $( v.push(crate::llvm::functions::ArgumentList { + $( v.push($crate::llvm::functions::ArgumentList { parameter_type: Some($ty1), attributes: None, name: Some(format!("%{}", $val1)), variable_argument: false, });)* - v.push(crate::llvm::functions::ArgumentList { + v.push($crate::llvm::functions::ArgumentList { parameter_type: None, attributes: None, name: None, @@ -88,13 +88,13 @@ macro_rules! arg { }}; ($($ty:ident)? $(,$ty1:ident)*) => {{ let mut v = vec![]; - $( v.push(crate::llvm::functions::ArgumentList { + $( v.push($crate::llvm::functions::ArgumentList { parameter_type: Some($ty), attributes: None, name: None, variable_argument: false, });)? - $( v.push(crate::llvm::functions::ArgumentList { + $( v.push($crate::llvm::functions::ArgumentList { parameter_type: Some($ty1), attributes: None, name: None, @@ -104,19 +104,19 @@ macro_rules! arg { }}; ($($ty:ident)? $(,$ty1:ident)*, ...) => {{ let mut v = vec![]; - $( v.push(crate::llvm::functions::ArgumentList { + $( v.push($crate::llvm::functions::ArgumentList { parameter_type: Some($ty), attributes: None, name: None, variable_argument: false, });)? - $( v.push(crate::llvm::functions::ArgumentList { + $( v.push($crate::llvm::functions::ArgumentList { parameter_type: Some($ty1), attributes: None, name: None, variable_argument: false, });)* - v.push(crate::llvm::functions::ArgumentList { + v.push($crate::llvm::functions::ArgumentList { parameter_type: None, attributes: None, name: None, @@ -146,15 +146,15 @@ macro_rules! def { $fnval.$attr = Some($val); }}; ($ty:ident $name:ident) => {{ - crate::llvm::functions::Function { - definition_type: crate::llvm::functions::FunctionDefinitionType::Define, + $crate::llvm::functions::Function { + definition_type: $crate::llvm::functions::FunctionDefinitionType::Define, linkage: None, preemption_specifier: None, visibility: None, dll_storage_class: None, cconv: None, ret_attrs: None, - result_type: crate::llvm::types::Type::$ty, + result_type: $crate::llvm::types::Type::$ty, function_name: $name.to_string(), argument_list: vec![], unnamed_addr: None, @@ -194,7 +194,7 @@ macro_rules! decl { }}; ($ty:ident $name:ident) => {{ let mut f_decl = def!($ty $name); - let d = crate::llvm::functions::FunctionDefinitionType::Declare; + let d = $crate::llvm::functions::FunctionDefinitionType::Declare; def!(f_decl.definition_type d); f_decl }}; @@ -209,7 +209,7 @@ macro_rules! decl { #[macro_export] macro_rules! source_file { ($name:expr) => { - crate::llvm::source_filename::SourceFileName($name.to_string()); + $crate::llvm::source_filename::SourceFileName($name.to_string()) }; } @@ -222,7 +222,7 @@ macro_rules! source_file { #[macro_export] macro_rules! target_triple { ($name:ident) => { - crate::llvm::target_triple::TargetTriple(crate::llvm::target_triple::$name.to_string()); + $crate::llvm::target_triple::TargetTriple($crate::llvm::target_triple::$name.to_string()) }; } @@ -249,7 +249,7 @@ macro_rules! global { $var.$attr = Some($val); }}; ($kind:ident $ty:ident $name:expr) => { - crate::llvm::global_variables::GlobalVariable { + $crate::llvm::global_variables::GlobalVariable { name: $name.to_string(), linkage: None, preemption_specifier: None, @@ -258,7 +258,7 @@ macro_rules! global { thread_local: None, unnamed_addr: None, addrspace: None, - global_variable_kind: crate::llvm::global_variables::GlobalVariableKind::$kind, + global_variable_kind: $crate::llvm::global_variables::GlobalVariableKind::$kind, value_type: $ty, initializer_constant: None, section: None, @@ -286,7 +286,7 @@ macro_rules! store { $var.$attr = Some($val); }}; ($ty:ident $val:expr, $ptrval:expr) => {{ - crate::llvm::instructions::memory_access_addressing_operations::Store { + $crate::llvm::instructions::memory_access_addressing_operations::Store { volatile: None, ty: $ty, value: $val.to_string(), @@ -312,7 +312,7 @@ macro_rules! load { $var.$attr = Some($val); }}; ($ty:ident $res:expr, $ptrval:expr) => {{ - crate::llvm::instructions::memory_access_addressing_operations::Load { + $crate::llvm::instructions::memory_access_addressing_operations::Load { result: $res.to_string(), volatile: None, ty: $ty, @@ -336,10 +336,10 @@ macro_rules! load { #[macro_export] macro_rules! ret { ($ty:ident @ $val:expr) => {{ - crate::llvm::instructions::terminator::Ret(Some(($ty, $val.to_string()))) + $crate::llvm::instructions::terminator::Ret(Some(($ty, $val.to_string()))) }}; () => {{ - crate::llvm::instructions::terminator::Ret(None) + $crate::llvm::instructions::terminator::Ret(None) }}; } @@ -436,12 +436,12 @@ macro_rules! call { )? #[allow(unused_mut)] - let mut args: Vec< crate::llvm::instructions::terminator::FunctionArg> = vec![]; + let mut args: Vec< $crate::llvm::instructions::terminator::FunctionArg> = vec![]; $( - args.push(crate::llvm::instructions::terminator::FunctionArg($argty1, $argval1)); + args.push($crate::llvm::instructions::terminator::FunctionArg($argty1, $argval1)); )? $( - args.push(crate::llvm::instructions::terminator::FunctionArg($argty2, $argval2)); + args.push($crate::llvm::instructions::terminator::FunctionArg($argty2, $argval2)); )* Call { diff --git a/src/parser/ast.rs b/src/parser/ast.rs index 411edf3..4255106 100644 --- a/src/parser/ast.rs +++ b/src/parser/ast.rs @@ -1,3 +1,4 @@ +#![allow(clippy::derive_partial_eq_without_eq)] //! Full AST representation //! //! Based on *EBNF* grammar