Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
He1pa committed Aug 15, 2022
1 parent bfec27a commit f75c767
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 24 deletions.
7 changes: 2 additions & 5 deletions kclvm/ast/src/walker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -991,7 +991,7 @@ pub fn walk_module<'ctx, V: Walker<'ctx>>(walker: &mut V, module: &'ctx ast::Mod
walk_list!(walker, walk_stmt, module.body)
}
/// Each method of the `MutSelfWalker` trait returns void type and does not need to modify the AST.
/// We can use it to traverse the AST and do some check at the same time, For example, in the process
/// We can use it to traverse the AST and do some check at the same time, For example, in the process
/// of lint checking, we can use it to check each AST node and generate diagnostcs.
pub trait MutSelfWalker {
fn walk_expr_stmt(&mut self, expr_stmt: &ast::ExprStmt) {
Expand Down Expand Up @@ -1113,10 +1113,7 @@ pub trait MutSelfWalker {
self.walk_expr(&dict_comp.entry.value.node);
walk_list!(self, walk_comp_clause, dict_comp.generators);
}
fn walk_config_if_entry_expr(
&mut self,
config_if_entry_expr: &ast::ConfigIfEntryExpr,
) {
fn walk_config_if_entry_expr(&mut self, config_if_entry_expr: &ast::ConfigIfEntryExpr) {
self.walk_expr(&config_if_entry_expr.if_cond.node);
for config_entry in &config_if_entry_expr.items {
walk_if!(self, walk_expr, config_entry.node.key);
Expand Down
5 changes: 3 additions & 2 deletions kclvm/sema/src/resolver/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,8 @@ impl Linter<CombinedLintPass> {
}
}
pub fn walk_scope(&mut self, scope: &Scope) {
self.pass.check_scope(&mut self.handler, &mut self.ctx, scope);
self.pass
.check_scope(&mut self.handler, &mut self.ctx, scope);
}
}

Expand All @@ -397,7 +398,7 @@ impl Resolver<'_> {
self.linter.walk_scope(scope);
for children in &scope.children {
self.lint_check_scope(&children.borrow().clone())
}
}
}

pub fn merge_lint_diagnostics(&mut self) {
Expand Down
9 changes: 5 additions & 4 deletions kclvm/sema/src/resolver/lint_def.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use crate::{declare_lint_pass, resolver::scope::ScopeObjectKind};

use super::{lint::{Lint, LintArray, LintContext, LintPass}, scope::Scope};
use super::{
lint::{Lint, LintArray, LintContext, LintPass},
scope::Scope,
};
use indexmap::IndexSet;
use kclvm_ast::ast;
use kclvm_error::{Handler, Level, Message, Position, Style, WarningKind};
Expand Down Expand Up @@ -146,7 +149,7 @@ pub static REIMPORT: &Lint = &Lint {
declare_lint_pass!(ReImport => [REIMPORT]);

impl LintPass for ReImport {
fn check_module(&mut self,handler: &mut Handler,ctx: &mut LintContext,module: &ast::Module) {
fn check_module(&mut self, handler: &mut Handler, ctx: &mut LintContext, module: &ast::Module) {
let mut import_names = IndexSet::<String>::new();
for stmt in &module.body {
if let ast::Stmt::Import(import_stmt) = &stmt.node {
Expand All @@ -170,10 +173,8 @@ impl LintPass for ReImport {
} else {
import_names.insert(import_stmt.path.clone());
}

}
}

}
// fn check_import_stmt(
// &mut self,
Expand Down
7 changes: 6 additions & 1 deletion kclvm/sema/src/resolver/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,12 @@ fn test_lint() {
note: Some("Consider removing this statement".to_string()),
}],
);
for (d1, d2) in resolver.linter.handler.diagnostics.iter().zip(handler.diagnostics.iter())
for (d1, d2) in resolver
.linter
.handler
.diagnostics
.iter()
.zip(handler.diagnostics.iter())
{
assert_eq!(d1, d2);
}
Expand Down
29 changes: 17 additions & 12 deletions kclvm/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fn main() {
(@arg sort_key: -k --sort "Sort result keys")
(@arg ARGUMENT: ... -D --argument "Specify the top-level argument")
)
(@subcommand lint =>
(@subcommand lint =>
(@arg INPUT: ... "Sets the input file to use")
(@arg OUTPUT: -o --output +takes_value "Sets the LLVM IR/BC output file path")
(@arg SETTING: ... -Y --setting +takes_value "Sets the input file to use")
Expand All @@ -46,7 +46,7 @@ fn main() {
match (files, setting) {
(None, None) => {
println!("{}", matches.usage());
},
}
(_, _) => {
let mut files: Vec<&str> = match matches.values_of("INPUT") {
Some(files) => files.into_iter().collect::<Vec<&str>>(),
Expand All @@ -66,15 +66,14 @@ fn main() {
// Resolve AST program, generate libs, link libs and execute.
// TODO: The argument "plugin_agent" need to be read from python3.
execute(program, 0, &ExecProgramArgs::default()).unwrap();
},
}
}

} else if let Some(matches) = matches.subcommand_matches("lint") {
let (files, setting) = (matches.values_of("INPUT"), matches.values_of("SETTING"));
match (files, setting) {
(None, None) => {
println!("{}", matches.usage());
},
}
(_, _) => {
let mut files: Vec<&str> = match matches.values_of("INPUT") {
Some(files) => files.into_iter().collect::<Vec<&str>>(),
Expand All @@ -84,9 +83,14 @@ fn main() {
let settings = build_settings(&matches);
// Convert settings into execute arguments.
let args: ExecProgramArgs = settings.into();
files = if !files.is_empty() {files} else {args.get_files()};
files = if !files.is_empty() {
files
} else {
args.get_files()
};
// Parse AST program.
let mut program = load_program(&files, Some(args.get_load_program_options())).unwrap();
let mut program =
load_program(&files, Some(args.get_load_program_options())).unwrap();
// Resolve AST program, generate libs, link libs and execute.
// TODO: The argument "plugin_agent" need to be read from python3.
let scope = resolve_program(&mut program);
Expand All @@ -97,10 +101,8 @@ fn main() {
for diag in &scope.diagnostics {
if diag.level == Level::Error {
err_handler.diagnostics.insert(diag.clone());

} else if diag.level == Level::Warning {
warning_handler.diagnostics.insert(diag.clone());

} else {
continue;
}
Expand All @@ -109,9 +111,12 @@ fn main() {
if matches.occurrences_of("EMIT_WARNING") > 0 {
warning_handler.emit();
}
println!("total {:?} error, {:?} warning", err_handler.diagnostics.len(), warning_handler.diagnostics.len());

},
println!(
"total {:?} error, {:?} warning",
err_handler.diagnostics.len(),
warning_handler.diagnostics.len()
);
}
}
} else {
println!("{}", matches.usage());
Expand Down

0 comments on commit f75c767

Please sign in to comment.