parser,checker: support `[generated] module xyz` (turns off notices). Use it for `infix.v`.
parent
9b7a50b1a2
commit
79de408ef0
|
@ -668,6 +668,7 @@ pub:
|
|||
mod Module // the module of the source file (from `module xyz` at the top)
|
||||
global_scope &Scope
|
||||
is_test bool // true for _test.v files
|
||||
is_generated bool // true for `[generated] module xyz` files; turn off notices
|
||||
pub mut:
|
||||
path string // absolute path of the source file - '/projects/v/file.v'
|
||||
path_base string // file name - 'file.v' (useful for tracing)
|
||||
|
|
|
@ -5,7 +5,6 @@ module checker
|
|||
|
||||
import v.ast
|
||||
import v.token
|
||||
import os
|
||||
|
||||
// TODO: promote(), check_types(), symmetric_check() and check() overlap - should be rearranged
|
||||
pub fn (mut c Checker) check_types(got ast.Type, expected ast.Type) bool {
|
||||
|
@ -260,10 +259,6 @@ pub fn (mut c Checker) check_matching_function_symbols(got_type_sym &ast.TypeSym
|
|||
return true
|
||||
}
|
||||
|
||||
// TODO: remove this exception, by using a more general mechanism for opting out
|
||||
// generated code, from warnings/notices, that are targeted at humans:
|
||||
const infix_v_exception = os.join_path('vlib', 'v', 'eval', 'infix.v')
|
||||
|
||||
fn (mut c Checker) check_shift(mut node ast.InfixExpr, left_type ast.Type, right_type ast.Type) ast.Type {
|
||||
if !left_type.is_int() {
|
||||
left_sym := c.table.get_type_symbol(left_type)
|
||||
|
@ -323,7 +318,7 @@ fn (mut c Checker) check_shift(mut node ast.InfixExpr, left_type ast.Type, right
|
|||
left_sym_final := c.table.get_final_type_symbol(left_type)
|
||||
left_type_final := ast.Type(left_sym_final.idx)
|
||||
if node.op == .left_shift && left_type_final.is_signed() && !(c.inside_unsafe
|
||||
&& c.file.path.ends_with(checker.infix_v_exception)) {
|
||||
&& c.is_generated) {
|
||||
c.note('shifting a value from a signed type `$left_sym_final.name` can change the sign',
|
||||
node.left.position())
|
||||
}
|
||||
|
|
|
@ -73,6 +73,7 @@ pub mut:
|
|||
scope_returns bool
|
||||
mod string // current module name
|
||||
is_builtin_mod bool // true inside the 'builtin', 'os' or 'strconv' modules; TODO: remove the need for special casing this
|
||||
is_generated bool // true for `[generated] module xyz` .v files
|
||||
inside_unsafe bool // true inside `unsafe {}` blocks
|
||||
inside_const bool // true inside `const ( ... )` blocks
|
||||
inside_anon_fn bool // true inside `fn() { ... }()`
|
||||
|
@ -248,6 +249,7 @@ pub fn (mut c Checker) change_current_file(file &ast.File) {
|
|||
c.file = unsafe { file }
|
||||
c.vmod_file_content = ''
|
||||
c.mod = file.mod.name
|
||||
c.is_generated = file.is_generated
|
||||
}
|
||||
|
||||
pub fn (mut c Checker) check_files(ast_files []&ast.File) {
|
||||
|
@ -4707,6 +4709,9 @@ pub fn (mut c Checker) note(message string, pos token.Position) {
|
|||
c.should_abort = true
|
||||
return
|
||||
}
|
||||
if c.is_generated {
|
||||
return
|
||||
}
|
||||
mut details := ''
|
||||
if c.error_details.len > 0 {
|
||||
details = c.error_details.join('\n')
|
||||
|
|
|
@ -5,7 +5,8 @@ import strings
|
|||
import os
|
||||
|
||||
const (
|
||||
header = 'module eval
|
||||
header = '[generated]
|
||||
module eval
|
||||
import v.token
|
||||
import v.ast
|
||||
fn(e Eval)infix_expr(left Object,right Object,op token.Kind,expecting ast.Type)Object{match op{'
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
[generated]
|
||||
module eval
|
||||
|
||||
import v.token
|
||||
|
|
|
@ -51,6 +51,7 @@ mut:
|
|||
mod string // current module name
|
||||
is_manualfree bool // true when `[manualfree] module abc`, makes *all* fns in the current .v file, opt out of autofree
|
||||
has_globals bool // `[has_globals] module abc` - allow globals declarations, even without -enable-globals, in that single .v file __only__
|
||||
is_generated bool // `[generated] module abc` - turn off compiler notices for that single .v file __only__.
|
||||
attrs []ast.Attr // attributes before next decl stmt
|
||||
expr_mod string // for constructing full type names in parse_type()
|
||||
scope &ast.Scope
|
||||
|
@ -310,6 +311,7 @@ pub fn (mut p Parser) parse() &ast.File {
|
|||
path: p.file_name
|
||||
path_base: p.file_base
|
||||
is_test: p.inside_test_file
|
||||
is_generated: p.is_generated
|
||||
nr_lines: p.scanner.line_nr
|
||||
nr_bytes: p.scanner.text.len
|
||||
mod: module_decl
|
||||
|
@ -1760,6 +1762,9 @@ pub fn (mut p Parser) note_with_pos(s string, pos token.Position) {
|
|||
if p.pref.skip_warnings {
|
||||
return
|
||||
}
|
||||
if p.is_generated {
|
||||
return
|
||||
}
|
||||
if p.pref.output_mode == .stdout && !p.pref.check_only {
|
||||
ferror := util.formatted_error('notice:', s, p.file_name, pos)
|
||||
eprintln(ferror)
|
||||
|
@ -2844,6 +2849,9 @@ fn (mut p Parser) module_decl() ast.Module {
|
|||
'manualfree' {
|
||||
p.is_manualfree = true
|
||||
}
|
||||
'generated' {
|
||||
p.is_generated = true
|
||||
}
|
||||
'has_globals' {
|
||||
if p.inside_vlib_file {
|
||||
p.has_globals = true
|
||||
|
|
Loading…
Reference in New Issue