ci: run v vet on cgen and ast
parent
da99868a28
commit
dbcb23ddc8
|
@ -45,6 +45,9 @@ jobs:
|
||||||
- name: v vet
|
- name: v vet
|
||||||
run: |
|
run: |
|
||||||
v vet vlib/v/parser
|
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
|
# - name: Test v binaries
|
||||||
# run: ./v -silent build-vbinaries
|
# run: ./v -silent build-vbinaries
|
||||||
|
|
||||||
|
|
|
@ -6,8 +6,8 @@ module ast
|
||||||
import v.table
|
import v.table
|
||||||
|
|
||||||
pub struct Scope {
|
pub struct Scope {
|
||||||
//mut:
|
|
||||||
pub mut:
|
pub mut:
|
||||||
|
// mut:
|
||||||
objects map[string]ScopeObject
|
objects map[string]ScopeObject
|
||||||
parent &Scope
|
parent &Scope
|
||||||
children []&Scope
|
children []&Scope
|
||||||
|
@ -16,7 +16,7 @@ pub mut:
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_scope(parent &Scope, start_pos int) &Scope {
|
pub fn new_scope(parent &Scope, start_pos int) &Scope {
|
||||||
return &ast.Scope{
|
return &Scope{
|
||||||
parent: parent
|
parent: parent
|
||||||
start_pos: start_pos
|
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 {
|
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 {
|
if name in sc.objects {
|
||||||
return sc.objects[name]
|
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 {
|
pub fn (s &Scope) is_known(name string) bool {
|
||||||
if _ := s.find(name) {
|
if _ := s.find(name) {
|
||||||
return true
|
return true
|
||||||
|
} else {
|
||||||
}
|
}
|
||||||
//
|
|
||||||
else{}
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (s &Scope) find_var(name string) ?&Var {
|
pub fn (s &Scope) find_var(name string) ?&Var {
|
||||||
if obj := s.find(name) {
|
if obj := s.find(name) {
|
||||||
match obj {
|
match obj {
|
||||||
Var {
|
Var { return obj }
|
||||||
return it
|
|
||||||
}
|
|
||||||
else {}
|
else {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -72,9 +70,7 @@ pub fn (s &Scope) find_var(name string) ?&Var {
|
||||||
pub fn (s &Scope) find_const(name string) ?&ConstField {
|
pub fn (s &Scope) find_const(name string) ?&ConstField {
|
||||||
if obj := s.find(name) {
|
if obj := s.find(name) {
|
||||||
match obj {
|
match obj {
|
||||||
ConstField {
|
ConstField { return obj }
|
||||||
return it
|
|
||||||
}
|
|
||||||
else {}
|
else {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -162,12 +158,8 @@ pub fn (sc &Scope) show(depth, max_depth int) string {
|
||||||
out += '$indent# $sc.start_pos - $sc.end_pos\n'
|
out += '$indent# $sc.start_pos - $sc.end_pos\n'
|
||||||
for _, obj in sc.objects {
|
for _, obj in sc.objects {
|
||||||
match obj {
|
match obj {
|
||||||
ConstField {
|
ConstField { out += '$indent * const: $obj.name - $obj.typ\n' }
|
||||||
out += '$indent * const: $it.name - $it.typ\n'
|
Var { out += '$indent * var: $obj.name - $obj.typ\n' }
|
||||||
}
|
|
||||||
Var {
|
|
||||||
out += '$indent * var: $it.name - $it.typ\n'
|
|
||||||
}
|
|
||||||
else {}
|
else {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,4 +4,10 @@ struct User {
|
||||||
// last comment2
|
// last comment2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
if true {
|
||||||
|
}
|
||||||
|
// else
|
||||||
|
// else {
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
|
@ -1315,7 +1315,7 @@ fn (mut g Gen) gen_cross_tmp_variable(left []ast.Expr, val ast.Expr) {
|
||||||
mut has_var := false
|
mut has_var := false
|
||||||
for lx in left {
|
for lx in left {
|
||||||
if val_.str() == lx.str() {
|
if val_.str() == lx.str() {
|
||||||
g.write('_var_${lx.position().pos}')
|
g.write('_var_$lx.position().pos')
|
||||||
has_var = true
|
has_var = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -1341,7 +1341,7 @@ fn (mut g Gen) gen_cross_tmp_variable(left []ast.Expr, val ast.Expr) {
|
||||||
mut has_var := false
|
mut has_var := false
|
||||||
for lx in left {
|
for lx in left {
|
||||||
if val_.str() == lx.str() {
|
if val_.str() == lx.str() {
|
||||||
g.write('_var_${lx.position().pos}')
|
g.write('_var_$lx.position().pos')
|
||||||
has_var = true
|
has_var = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -2538,7 +2538,6 @@ fn (mut g Gen) const_decl(node ast.ConstDecl) {
|
||||||
defer {
|
defer {
|
||||||
g.inside_const = false
|
g.inside_const = false
|
||||||
}
|
}
|
||||||
|
|
||||||
for field in node.fields {
|
for field in node.fields {
|
||||||
name := c_name(field.name)
|
name := c_name(field.name)
|
||||||
// TODO hack. Cut the generated value and paste it into definitions.
|
// TODO hack. Cut the generated value and paste it into definitions.
|
||||||
|
|
|
@ -13,17 +13,35 @@ interface Animal {
|
||||||
greet() int
|
greet() int
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (d Dog) say(s string) { println('Dog $d.name: "$s"') }
|
fn (d Dog) say(s string) {
|
||||||
fn (c Cat) say(s string) { println('Cat $c.name: "$s"') }
|
println('Dog $d.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 (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(Dog{'Doggo', 5})
|
||||||
use(Cat{'Nyancat', 6})
|
use(Cat{'Nyancat', 6})
|
||||||
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ fn (mut p Parser) if_expr() ast.IfExpr {
|
||||||
// if p.tok.kind == .comment {
|
// if p.tok.kind == .comment {
|
||||||
// p.error('place comments inside {}')
|
// p.error('place comments inside {}')
|
||||||
// }
|
// }
|
||||||
// comment = p.check_comment()
|
comment = p.check_comment()
|
||||||
p.check(.key_else)
|
p.check(.key_else)
|
||||||
if p.tok.kind == .key_if {
|
if p.tok.kind == .key_if {
|
||||||
p.next()
|
p.next()
|
||||||
|
@ -74,7 +74,7 @@ fn (mut p Parser) if_expr() ast.IfExpr {
|
||||||
cond: cond
|
cond: cond
|
||||||
stmts: stmts
|
stmts: stmts
|
||||||
pos: start_pos.extend(end_pos)
|
pos: start_pos.extend(end_pos)
|
||||||
comment: ast.Comment{}
|
comment: comment
|
||||||
}
|
}
|
||||||
if p.tok.kind != .key_else {
|
if p.tok.kind != .key_else {
|
||||||
break
|
break
|
||||||
|
|
Loading…
Reference in New Issue