Skip to content

Commit

Permalink
checker: improve -line-info
Browse files Browse the repository at this point in the history
  • Loading branch information
medvednikov committed Aug 14, 2023
1 parent 58d4bd6 commit 8306766
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 9 deletions.
33 changes: 33 additions & 0 deletions vlib/gg/draw.c.v
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
34 changes: 28 additions & 6 deletions vlib/v/checker/checker.v
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import v.util
import v.util.version
import v.errors
import v.pkgconfig
import strings

const (
int_min = int(0x80000000)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions vlib/v/checker/line_info.v
Original file line number Diff line number Diff line change
Expand Up @@ -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}'")
Expand All @@ -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 {
Expand All @@ -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]])
}
1 change: 0 additions & 1 deletion vlib/v/checker/struct.v
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions vlib/v/parser/parser.v
Original file line number Diff line number Diff line change
Expand Up @@ -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

This comment has been minimized.

Copy link
@spytheman

spytheman Aug 14, 2023

Member

wtf?

p.file_name = path
p.file_base = os.base(path)
p.file_name_dir = os.dir(path)
Expand Down

2 comments on commit 8306766

@Larpon
Copy link
Contributor

@Larpon Larpon commented on 8306766 Aug 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commit message is misleading, there's updates to gg as well 😄

@spytheman
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not mind the other changes much (they seem useful), but the one in parser broke the CI 🤷🏻‍♂️ for not much benefit.

Please sign in to comment.