mirror of
https://github.com/vlang/v.git
synced 2025-09-10 07:47:20 -04:00
checker: improve -line-info
This commit is contained in:
parent
58d4bd67b2
commit
83067667c7
@ -219,6 +219,39 @@ pub fn (ctx &Context) draw_rect_filled(x f32, y f32, w f32, h f32, c gx.Color) {
|
|||||||
sgl.end()
|
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.
|
// 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.
|
// `x`,`y` is the top-left corner of the rectangle.
|
||||||
// `w` is the width, `h` is the height.
|
// `w` is the width, `h` is the height.
|
||||||
|
@ -12,6 +12,7 @@ import v.util
|
|||||||
import v.util.version
|
import v.util.version
|
||||||
import v.errors
|
import v.errors
|
||||||
import v.pkgconfig
|
import v.pkgconfig
|
||||||
|
import strings
|
||||||
|
|
||||||
const (
|
const (
|
||||||
int_min = int(0x80000000)
|
int_min = int(0x80000000)
|
||||||
@ -117,6 +118,7 @@ mut:
|
|||||||
inside_if_guard bool // true inside the guard condition of `if x := opt() {}`
|
inside_if_guard bool // true inside the guard condition of `if x := opt() {}`
|
||||||
inside_assign bool
|
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
|
is_index_assign bool
|
||||||
comptime_call_pos int // needed for correctly checking use before decl for templates
|
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
|
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
|
return ast.string_type
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct ACFieldMethod {
|
||||||
|
name string
|
||||||
|
typ string
|
||||||
|
}
|
||||||
|
|
||||||
fn (mut c Checker) ident(mut node ast.Ident) ast.Type {
|
fn (mut c Checker) ident(mut node ast.Ident) ast.Type {
|
||||||
if c.doing_line_info > 0 {
|
if c.doing_line_info > 0 {
|
||||||
|
mut sb := strings.new_builder(10)
|
||||||
// Mini LS hack (v -line-info "a.v:16")
|
// Mini LS hack (v -line-info "a.v:16")
|
||||||
// println('line_nr=${node.pos.line_nr} doing line nr=${c.doing_line_info}')
|
// println('line_nr=${node.pos.line_nr} doing line nr=${c.doing_line_info}')
|
||||||
if node.pos.line_nr == c.doing_line_info {
|
// println('Start line_nr=${node.pos.line_nr} line2=${c.doing_line_info} file="${c.file.path}", pppp="${c.doing_line_path}"')
|
||||||
println('===')
|
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)
|
sym := c.table.sym(node.obj.typ)
|
||||||
println('VAR ${node.name}:${sym.name}')
|
sb.writeln('VAR ${node.name}:${sym.name}')
|
||||||
struct_info := sym.info as ast.Struct
|
mut struct_info := sym.info as ast.Struct
|
||||||
|
mut fields := []ACFieldMethod{cap: struct_info.fields.len}
|
||||||
for field in struct_info.fields {
|
for field in struct_info.fields {
|
||||||
field_sym := c.table.sym(field.typ)
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
module checker
|
module checker
|
||||||
|
|
||||||
import v.ast
|
import v.ast
|
||||||
import os
|
// import os
|
||||||
|
|
||||||
fn (mut c Checker) do_line_info(line string, all_ast_files []&ast.File) {
|
fn (mut c Checker) do_line_info(line string, all_ast_files []&ast.File) {
|
||||||
// println("do_line_info '${line}'")
|
// 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_path := ''
|
||||||
mut found_file_idx := -1
|
mut found_file_idx := -1
|
||||||
for i, file in all_ast_files {
|
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)
|
// println(base)
|
||||||
if base == file_name {
|
if base == file_name {
|
||||||
if found {
|
if found {
|
||||||
@ -46,5 +47,6 @@ fn (mut c Checker) do_line_info(line string, all_ast_files []&ast.File) {
|
|||||||
|
|
||||||
// println('found ${found_path}')
|
// println('found ${found_path}')
|
||||||
c.doing_line_info = line_nr
|
c.doing_line_info = line_nr
|
||||||
|
c.doing_line_path = file_name
|
||||||
c.check_files([all_ast_files[found_file_idx]])
|
c.check_files([all_ast_files[found_file_idx]])
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,6 @@ fn (mut c Checker) struct_decl(mut node ast.StructDecl) {
|
|||||||
util.timing_measure_cumulative(@METHOD)
|
util.timing_measure_cumulative(@METHOD)
|
||||||
}
|
}
|
||||||
mut struct_sym, struct_typ_idx := c.table.find_sym_and_type_idx(node.name)
|
mut struct_sym, struct_typ_idx := c.table.find_sym_and_type_idx(node.name)
|
||||||
// struct_sym.jj0
|
|
||||||
mut has_generic_types := false
|
mut has_generic_types := false
|
||||||
if mut struct_sym.info is ast.Struct {
|
if mut struct_sym.info is ast.Struct {
|
||||||
if node.language == .v && !c.is_builtin_mod && !struct_sym.info.is_anon {
|
if node.language == .v && !c.is_builtin_mod && !struct_sym.info.is_anon {
|
||||||
|
@ -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) {
|
pub fn (mut p Parser) set_path(path string) {
|
||||||
|
p.xx
|
||||||
p.file_name = path
|
p.file_name = path
|
||||||
p.file_base = os.base(path)
|
p.file_base = os.base(path)
|
||||||
p.file_name_dir = os.dir(path)
|
p.file_name_dir = os.dir(path)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user