mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
ci: run v vet on cgen and ast
This commit is contained in:
parent
da99868a28
commit
dbcb23ddc8
3
.github/workflows/ci.yml
vendored
3
.github/workflows/ci.yml
vendored
@ -45,6 +45,9 @@ jobs:
|
||||
- name: v vet
|
||||
run: |
|
||||
v vet vlib/v/parser
|
||||
v vet vlib/v/ast
|
||||
v vet vlib/v/ast
|
||||
v vet vlib/v/gen/cgen.v
|
||||
# - name: Test v binaries
|
||||
# run: ./v -silent build-vbinaries
|
||||
|
||||
|
@ -6,8 +6,8 @@ module ast
|
||||
import v.table
|
||||
|
||||
pub struct Scope {
|
||||
//mut:
|
||||
pub mut:
|
||||
// mut:
|
||||
objects map[string]ScopeObject
|
||||
parent &Scope
|
||||
children []&Scope
|
||||
@ -16,7 +16,7 @@ pub mut:
|
||||
}
|
||||
|
||||
pub fn new_scope(parent &Scope, start_pos int) &Scope {
|
||||
return &ast.Scope{
|
||||
return &Scope{
|
||||
parent: parent
|
||||
start_pos: start_pos
|
||||
}
|
||||
@ -24,7 +24,7 @@ pub fn new_scope(parent &Scope, start_pos int) &Scope {
|
||||
|
||||
pub fn (s &Scope) find_with_scope(name string) ?(ScopeObject, &Scope) {
|
||||
mut sc := s
|
||||
for {
|
||||
for {
|
||||
if name in sc.objects {
|
||||
return sc.objects[name], sc
|
||||
}
|
||||
@ -37,7 +37,8 @@ pub fn (s &Scope) find_with_scope(name string) ?(ScopeObject, &Scope) {
|
||||
}
|
||||
|
||||
pub fn (s &Scope) find(name string) ?ScopeObject {
|
||||
for sc := s; ; sc = sc.parent {
|
||||
for sc := s; true; sc = sc.parent
|
||||
{
|
||||
if name in sc.objects {
|
||||
return sc.objects[name]
|
||||
}
|
||||
@ -51,18 +52,15 @@ pub fn (s &Scope) find(name string) ?ScopeObject {
|
||||
pub fn (s &Scope) is_known(name string) bool {
|
||||
if _ := s.find(name) {
|
||||
return true
|
||||
} else {
|
||||
}
|
||||
//
|
||||
else{}
|
||||
return false
|
||||
}
|
||||
|
||||
pub fn (s &Scope) find_var(name string) ?&Var {
|
||||
if obj := s.find(name) {
|
||||
match obj {
|
||||
Var {
|
||||
return it
|
||||
}
|
||||
Var { return obj }
|
||||
else {}
|
||||
}
|
||||
}
|
||||
@ -72,9 +70,7 @@ pub fn (s &Scope) find_var(name string) ?&Var {
|
||||
pub fn (s &Scope) find_const(name string) ?&ConstField {
|
||||
if obj := s.find(name) {
|
||||
match obj {
|
||||
ConstField {
|
||||
return it
|
||||
}
|
||||
ConstField { return obj }
|
||||
else {}
|
||||
}
|
||||
}
|
||||
@ -162,12 +158,8 @@ pub fn (sc &Scope) show(depth, max_depth int) string {
|
||||
out += '$indent# $sc.start_pos - $sc.end_pos\n'
|
||||
for _, obj in sc.objects {
|
||||
match obj {
|
||||
ConstField {
|
||||
out += '$indent * const: $it.name - $it.typ\n'
|
||||
}
|
||||
Var {
|
||||
out += '$indent * var: $it.name - $it.typ\n'
|
||||
}
|
||||
ConstField { out += '$indent * const: $obj.name - $obj.typ\n' }
|
||||
Var { out += '$indent * var: $obj.name - $obj.typ\n' }
|
||||
else {}
|
||||
}
|
||||
}
|
||||
|
@ -4,4 +4,10 @@ struct User {
|
||||
// last comment2
|
||||
}
|
||||
|
||||
|
||||
fn main() {
|
||||
if true {
|
||||
}
|
||||
// else
|
||||
// else {
|
||||
// }
|
||||
}
|
||||
|
@ -83,7 +83,7 @@ mut:
|
||||
attrs []string // attributes before next decl stmt
|
||||
is_builtin_mod bool
|
||||
hotcode_fn_names []string
|
||||
//cur_fn ast.FnDecl
|
||||
// cur_fn ast.FnDecl
|
||||
cur_generic_type table.Type // `int`, `string`, etc in `foo<T>()`
|
||||
sql_i int
|
||||
sql_stmt_name string
|
||||
@ -93,7 +93,7 @@ mut:
|
||||
strs_to_free string
|
||||
inside_call bool
|
||||
has_main bool
|
||||
inside_const bool
|
||||
inside_const bool
|
||||
}
|
||||
|
||||
const (
|
||||
@ -1315,7 +1315,7 @@ fn (mut g Gen) gen_cross_tmp_variable(left []ast.Expr, val ast.Expr) {
|
||||
mut has_var := false
|
||||
for lx in left {
|
||||
if val_.str() == lx.str() {
|
||||
g.write('_var_${lx.position().pos}')
|
||||
g.write('_var_$lx.position().pos')
|
||||
has_var = true
|
||||
break
|
||||
}
|
||||
@ -1341,7 +1341,7 @@ fn (mut g Gen) gen_cross_tmp_variable(left []ast.Expr, val ast.Expr) {
|
||||
mut has_var := false
|
||||
for lx in left {
|
||||
if val_.str() == lx.str() {
|
||||
g.write('_var_${lx.position().pos}')
|
||||
g.write('_var_$lx.position().pos')
|
||||
has_var = true
|
||||
break
|
||||
}
|
||||
@ -2538,7 +2538,6 @@ fn (mut g Gen) const_decl(node ast.ConstDecl) {
|
||||
defer {
|
||||
g.inside_const = false
|
||||
}
|
||||
|
||||
for field in node.fields {
|
||||
name := c_name(field.name)
|
||||
// TODO hack. Cut the generated value and paste it into definitions.
|
||||
|
@ -13,17 +13,35 @@ interface Animal {
|
||||
greet() int
|
||||
}
|
||||
|
||||
fn (d Dog) say(s string) { println('Dog $d.name: "$s"') }
|
||||
fn (c Cat) say(s string) { println('Cat $c.name: "$s"') }
|
||||
|
||||
fn (d Dog) greet() int { d.say('Hello!') return d.age }
|
||||
fn (c Cat) greet() int { c.say('Hello!') return c.age }
|
||||
|
||||
fn use(a Animal) {
|
||||
if a is Dog { println('dog') }
|
||||
else if a is Cat { println('cat') }
|
||||
else { println('its a bug!') }
|
||||
fn (d Dog) say(s string) {
|
||||
println('Dog $d.name: "$s"')
|
||||
}
|
||||
|
||||
use(Dog{ 'Doggo', 5 })
|
||||
use(Cat{ 'Nyancat', 6 })
|
||||
fn (c Cat) say(s string) {
|
||||
println('Cat $c.name: "$s"')
|
||||
}
|
||||
|
||||
fn (d Dog) greet() int {
|
||||
d.say('Hello!')
|
||||
return d.age
|
||||
}
|
||||
|
||||
fn (c Cat) greet() int {
|
||||
c.say('Hello!')
|
||||
return c.age
|
||||
}
|
||||
|
||||
fn use(a Animal) {
|
||||
if a is Dog {
|
||||
println('dog')
|
||||
} else if a is Cat {
|
||||
println('cat')
|
||||
} else {
|
||||
println('its a bug!')
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
use(Dog{'Doggo', 5})
|
||||
use(Cat{'Nyancat', 6})
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ fn (mut p Parser) if_expr() ast.IfExpr {
|
||||
// if p.tok.kind == .comment {
|
||||
// p.error('place comments inside {}')
|
||||
// }
|
||||
// comment = p.check_comment()
|
||||
comment = p.check_comment()
|
||||
p.check(.key_else)
|
||||
if p.tok.kind == .key_if {
|
||||
p.next()
|
||||
@ -74,7 +74,7 @@ fn (mut p Parser) if_expr() ast.IfExpr {
|
||||
cond: cond
|
||||
stmts: stmts
|
||||
pos: start_pos.extend(end_pos)
|
||||
comment: ast.Comment{}
|
||||
comment: comment
|
||||
}
|
||||
if p.tok.kind != .key_else {
|
||||
break
|
||||
|
Loading…
Reference in New Issue
Block a user