checker: improve -line-info

This commit is contained in:
Alexander Medvednikov 2023-08-14 09:37:41 +03:00
parent 58d4bd67b2
commit 83067667c7
5 changed files with 66 additions and 9 deletions

View File

@ -219,6 +219,39 @@ pub fn (ctx &Context) draw_rect_filled(x f32, y f32, w f32, h f32, c gx.Color) {
sgl.end()
}
enum PaintStyle {
fill
stroke
}
[params]
pub struct DrawRectParams {
x f32
y f32
w f32
h f32
color gx.Color = gx.black
style PaintStyle = .fill
is_rounded bool
radius f32
}
pub fn (ctx &Context) draw_rect(p DrawRectParams) {
if p.is_rounded {
if p.style == .fill {
ctx.draw_rounded_rect_filled(p.x, p.y, p.w, p.h, p.radius, p.color)
} else {
ctx.draw_rounded_rect_empty(p.x, p.y, p.w, p.h, p.radius, p.color)
}
} else {
if p.style == .fill {
ctx.draw_rect_filled(p.x, p.y, p.w, p.h, p.color)
} else {
ctx.draw_rect_empty(p.x, p.y, p.w, p.h, p.color)
}
}
}
// draw_rounded_rect_empty draws the outline of a rounded rectangle with a thickness of 1 px.
// `x`,`y` is the top-left corner of the rectangle.
// `w` is the width, `h` is the height.

View File

@ -12,6 +12,7 @@ import v.util
import v.util.version
import v.errors
import v.pkgconfig
import strings
const (
int_min = int(0x80000000)
@ -116,7 +117,8 @@ mut:
inside_decl_rhs bool
inside_if_guard bool // true inside the guard condition of `if x := opt() {}`
inside_assign bool
doing_line_info int // a quick single file run when called with v -line-info (contains line nr to inspect)
doing_line_info int // a quick single file run when called with v -line-info (contains line nr to inspect)
doing_line_path string // same, but stores the path being parsed
is_index_assign bool
comptime_call_pos int // needed for correctly checking use before decl for templates
goto_labels map[string]ast.GotoLabel // to check for unused goto labels
@ -3279,18 +3281,38 @@ fn (mut c Checker) at_expr(mut node ast.AtExpr) ast.Type {
return ast.string_type
}
struct ACFieldMethod {
name string
typ string
}
fn (mut c Checker) ident(mut node ast.Ident) ast.Type {
if c.doing_line_info > 0 {
mut sb := strings.new_builder(10)
// Mini LS hack (v -line-info "a.v:16")
// println('line_nr=${node.pos.line_nr} doing line nr=${c.doing_line_info}')
if node.pos.line_nr == c.doing_line_info {
println('===')
// println('Start line_nr=${node.pos.line_nr} line2=${c.doing_line_info} file="${c.file.path}", pppp="${c.doing_line_path}"')
if node.pos.line_nr == c.doing_line_info && c.file.path == c.doing_line_path {
sb.writeln('===')
sym := c.table.sym(node.obj.typ)
println('VAR ${node.name}:${sym.name}')
struct_info := sym.info as ast.Struct
sb.writeln('VAR ${node.name}:${sym.name}')
mut struct_info := sym.info as ast.Struct
mut fields := []ACFieldMethod{cap: struct_info.fields.len}
for field in struct_info.fields {
field_sym := c.table.sym(field.typ)
println('${field.name}:${field_sym.name}')
fields << ACFieldMethod{field.name, field_sym.name}
}
for method in sym.methods {
method_ret_type := c.table.sym(method.return_type)
fields << ACFieldMethod{method.name + '()', method_ret_type.name}
}
fields.sort(a.name < b.name)
for field in fields {
sb.writeln('${field.name}:${field.typ}')
}
res := sb.str().trim_space()
if res != '' {
println(res)
}
}
}

View File

@ -3,7 +3,7 @@
module checker
import v.ast
import os
// import os
fn (mut c Checker) do_line_info(line string, all_ast_files []&ast.File) {
// println("do_line_info '${line}'")
@ -26,7 +26,8 @@ fn (mut c Checker) do_line_info(line string, all_ast_files []&ast.File) {
mut found_path := ''
mut found_file_idx := -1
for i, file in all_ast_files {
base := os.base(file.path)
// base := os.base(file.path)
base := file.path // os.base(file.path)
// println(base)
if base == file_name {
if found {
@ -46,5 +47,6 @@ fn (mut c Checker) do_line_info(line string, all_ast_files []&ast.File) {
// println('found ${found_path}')
c.doing_line_info = line_nr
c.doing_line_path = file_name
c.check_files([all_ast_files[found_file_idx]])
}

View File

@ -11,7 +11,6 @@ fn (mut c Checker) struct_decl(mut node ast.StructDecl) {
util.timing_measure_cumulative(@METHOD)
}
mut struct_sym, struct_typ_idx := c.table.find_sym_and_type_idx(node.name)
// struct_sym.jj0
mut has_generic_types := false
if mut struct_sym.info is ast.Struct {
if node.language == .v && !c.is_builtin_mod && !struct_sym.info.is_anon {

View File

@ -192,6 +192,7 @@ const normalised_working_folder = (os.real_path(os.getwd()) + os.path_separator)
'/')
pub fn (mut p Parser) set_path(path string) {
p.xx
p.file_name = path
p.file_base = os.base(path)
p.file_name_dir = os.dir(path)