checker: fix first() and last(); call_args; method cgen

pull/3893/head
Alexander Medvednikov 2020-03-01 13:07:51 +01:00
parent 9978fb3e2c
commit 7a499b3cd3
6 changed files with 64 additions and 34 deletions

View File

@ -166,6 +166,7 @@ pub:
args []Expr
muts []bool
or_block OrExpr
typ table.Type
}
pub struct Return {

View File

@ -12,7 +12,7 @@ import (
)
const (
max_nr_errors = 50
max_nr_errors = 150
)
pub struct Checker {
@ -45,6 +45,7 @@ pub fn (c mut Checker) check(ast_file ast.File) {
println(t.name + ' - ' + t.kind.str())
}
*/
}
pub fn (c mut Checker) check2(ast_file ast.File) []string {
@ -71,7 +72,6 @@ pub fn (c mut Checker) check_files(ast_files []ast.File) {
for file in ast_files {
c.check(file)
}
c.print_unhandled_nodes()
}
@ -232,8 +232,11 @@ pub fn (c mut Checker) check_method_call_expr(method_call_expr ast.MethodCallExp
return method.return_type
}
if typ_sym.kind == .array && name in ['filter', 'clone'] {
// info := typ_sym.info as table.Array
return typ // info.elem_type
return typ
}
if typ_sym.kind == .array && name in ['first', 'last'] {
info := typ_sym.info as table.Array
return info.elem_type
}
// check parent
if typ_sym.parent_idx != 0 {
@ -436,7 +439,9 @@ fn (c mut Checker) stmt(node ast.Stmt) {
}
else {
node_name := typeof(node)
if !(node_name) in c.unhandled_stmts { c.unhandled_stmts << node_name }
if !(node_name) in c.unhandled_stmts {
c.unhandled_stmts << node_name
}
}
}
}
@ -538,12 +543,12 @@ pub fn (c mut Checker) expr(node ast.Expr) table.Type {
c.expr(it.left)
}
*/
else {
else {}
// TODO: find nil string bug triggered with typeof
// node_name := typeof(node)
// if !(node_name) in c.unhandled_exprs { c.unhandled_exprs << node_name }
}
}
return table.void_type
}

View File

@ -284,15 +284,28 @@ fn (g mut Gen) expr(node ast.Expr) {
}
ast.CallExpr {
g.write('${it.name}(')
g.call_args(it.args)
g.write(')')
/*
for i, expr in it.args {
g.expr(expr)
if i != it.args.len - 1 {
g.write(', ')
}
}
*/
}
ast.MethodCallExpr {
typ := 'TODO'
g.write('${typ}_${it.name}(')
g.expr(it.expr)
if it.args.len > 0 {
g.write(', ')
}
g.call_args(it.args)
g.write(')')
}
ast.MethodCallExpr {}
ast.Ident {
g.write('$it.name')
}
@ -382,6 +395,15 @@ fn (g mut Gen) index_expr(node ast.IndexExpr) {
}
}
fn (g mut Gen) call_args(args []ast.Expr) {
for i, expr in args {
g.expr(expr)
if i != args.len - 1 {
g.write(', ')
}
}
}
fn verror(s string) {
println(s)
exit(1)

View File

@ -66,6 +66,7 @@ i < 10; i++;
bool q = true || false;
bool b2 = bools[0] || true;
bool b3 = get_bool() || true;
int f = TODO_first(nums);
}
int get_int(string a) {

View File

@ -72,6 +72,7 @@ fn foo(a int) {
q := true || false
b2 := bools[0] || true
b3 := get_bool() || true
f := nums.first()
//cloned = nums.clone()
//cloned1 := cloned[0]
//println(cloned1 == 1)

View File

@ -17,7 +17,7 @@ int main() {
a.a = tos3("da");
a.b.a = 111;
string a1 = a.a;
int a2 = ;
int a2 = TODO_testa(b);
int c = testa();
c = 1;
string d = testb(1);
@ -56,7 +56,7 @@ int testc(int a) {
}
int testa() {
int a = ;
int a = TODO_testb(f);
a = 1;
return 4;
}