From 8760313ce5dd5f895b781bb9a57f9b3662f21fd0 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Thu, 16 Apr 2020 15:35:19 +0200 Subject: [PATCH] fmt builder.v --- vlib/v/builder/builder.v | 65 +++++++++++++++++++--------------------- vlib/v/parser/parser.v | 2 +- 2 files changed, 32 insertions(+), 35 deletions(-) diff --git a/vlib/v/builder/builder.v b/vlib/v/builder/builder.v index 5c23e57a70..aff52d8184 100644 --- a/vlib/v/builder/builder.v +++ b/vlib/v/builder/builder.v @@ -1,21 +1,19 @@ module builder -import ( - os - time - v.ast - v.table - v.pref - v.util - v.vmod - v.checker - v.parser - v.scanner - v.gen - v.gen.js - v.gen.x64 - v.depgraph -) +import os +import time +import v.ast +import v.table +import v.pref +import v.util +import v.vmod +import v.checker +import v.parser +import v.scanner +import v.gen +import v.gen.js +import v.gen.x64 +import v.depgraph pub struct Builder { pub: @@ -29,14 +27,14 @@ mut: parsed_files []ast.File global_scope &ast.Scope out_name_c string - out_name_js string + out_name_js string } pub fn new_builder(pref &pref.Preferences) Builder { rdir := os.real_path(pref.path) compiled_dir := if os.is_dir(rdir) { rdir } else { os.dir(rdir) } table := table.new_table() - return builder.Builder{ + return Builder{ pref: pref table: table checker: checker.new_checker(table, pref) @@ -49,10 +47,10 @@ pub fn new_builder(pref &pref.Preferences) Builder { // parse all deps from already parsed files pub fn (b mut Builder) parse_imports() { - mut done_imports := []string + var done_imports := []string // NB: b.parsed_files is appended in the loop, // so we can not use the shorter `for in` form. - for i := 0; i v.ast -> v.table cycles anymore return } @@ -100,7 +97,7 @@ pub fn (b mut Builder) resolve_deps() { eprintln(deps_resolved.display()) eprintln('------------------------------------------') } - mut mods := []string + var mods := []string for node in deps_resolved.nodes { mods << node.name } @@ -109,12 +106,12 @@ pub fn (b mut Builder) resolve_deps() { eprintln(mods.str()) eprintln('-------------------------------') } - mut reordered_parsed_files := []ast.File + var reordered_parsed_files := []ast.File for m in mods { for pf in b.parsed_files { if m == pf.mod.name { reordered_parsed_files << pf - //eprintln('pf.mod.name: $pf.mod.name | pf.path: $pf.path') + // eprintln('pf.mod.name: $pf.mod.name | pf.path: $pf.path') } } } @@ -123,11 +120,11 @@ pub fn (b mut Builder) resolve_deps() { // graph of all imported modules pub fn (b &Builder) import_graph() &depgraph.DepGraph { - mut builtins := util.builtin_module_parts + var builtins := util.builtin_module_parts builtins << 'builtin' - mut graph := depgraph.new_dep_graph() + var graph := depgraph.new_dep_graph() for p in b.parsed_files { - mut deps := []string + var deps := []string if p.mod.name !in builtins { deps << 'builtin' } @@ -140,7 +137,7 @@ pub fn (b &Builder) import_graph() &depgraph.DepGraph { } pub fn (b Builder) v_files_from_dir(dir string) []string { - mut res := []string + var res := []string if !os.exists(dir) { if dir == 'compiler' && os.is_dir('vlib') { println('looks like you are trying to build V with an old command') @@ -150,7 +147,7 @@ pub fn (b Builder) v_files_from_dir(dir string) []string { } else if !os.is_dir(dir) { verror("$dir isn't a directory!") } - mut files := os.ls(dir) or { + var files := os.ls(dir) or { panic(err) } if b.pref.is_verbose { @@ -171,7 +168,7 @@ pub fn (b Builder) v_files_from_dir(dir string) []string { continue } if b.pref.compile_defines_all.len > 0 && file.contains('_d_') { - mut allowed := false + var allowed := false for cdefine in b.pref.compile_defines { file_postfix := '_d_${cdefine}.v' if file.ends_with(file_postfix) { @@ -245,11 +242,11 @@ fn module_path(mod string) string { return mod.replace('.', os.path_separator) } -pub fn (b Builder) find_module_path(mod string, fpath string) ?string { +pub fn (b Builder) find_module_path(mod, fpath string) ?string { // support @VROOT/v.mod relative paths: - vmod_file_location := vmod.mod_file_cacher.get( fpath ) + vmod_file_location := vmod.mod_file_cacher.get(fpath) mod_path := module_path(mod) - mut module_lookup_paths := []string + var module_lookup_paths := []string if vmod_file_location.vmod_file.len != 0 && !(vmod_file_location.vmod_folder in b.module_search_paths) { module_lookup_paths << vmod_file_location.vmod_folder } diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index eff2c72b6e..01bf6b1de1 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -618,6 +618,7 @@ fn (p mut Parser) struct_init(short_syntax bool) ast.StructInit { pub fn (p mut Parser) name_expr() ast.Expr { var node := ast.Expr{} if p.inside_is { + p.inside_is = false return ast.Type{ typ: p.parse_type() } @@ -1054,7 +1055,6 @@ fn (p mut Parser) infix_expr(left ast.Expr) ast.Expr { p.inside_is = true } right = p.expr(precedence) - p.inside_is = false var expr := ast.Expr{} expr = ast.InfixExpr{ left: left