ci: run v vet on cgen and ast

pull/5612/head
Alexander Medvednikov 2020-07-01 19:07:19 +02:00
parent da99868a28
commit dbcb23ddc8
6 changed files with 56 additions and 38 deletions

View File

@ -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

View File

@ -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
}
@ -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 {}
}
}

View File

@ -4,4 +4,10 @@ struct User {
// last comment2
}
fn main() {
if true {
}
// else
// else {
// }
}

View File

@ -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.

View File

@ -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"')
}
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})
}

View File

@ -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