1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

cgen: string_add()

This commit is contained in:
Alexander Medvednikov 2020-03-07 00:34:14 +01:00
parent 3c7b0d6d05
commit 180b9b971a
6 changed files with 40 additions and 26 deletions

View File

@ -278,8 +278,9 @@ pub:
op token.Kind
pos token.Position
left Expr
left_type table.Type
right Expr
mut:
left_type table.Type
right_type table.Type
}

View File

@ -120,9 +120,10 @@ pub fn (c mut Checker) check_struct_init(struct_init ast.StructInit) table.Type
return struct_init.typ
}
pub fn (c mut Checker) infix_expr(infix_expr ast.InfixExpr) table.Type {
pub fn (c mut Checker) infix_expr(infix_expr mut ast.InfixExpr) table.Type {
// println('checker: infix expr(op $infix_expr.op.str())')
left_type := c.expr(infix_expr.left)
infix_expr.left_type = left_type
c.expected_type = left_type
right_type := c.expr(infix_expr.right)
if !c.table.check(right_type, left_type) {
@ -569,7 +570,7 @@ pub fn (c mut Checker) expr(node ast.Expr) table.Type {
return c.index_expr(mut it)
}
ast.InfixExpr {
return c.infix_expr(it)
return c.infix_expr(mut it)
}
ast.IntegerLiteral {
return table.int_type

View File

@ -476,15 +476,23 @@ fn (g mut Gen) expr(node ast.Expr) {
g.index_expr(it)
}
ast.InfixExpr {
// if it.left_type == table.string_type_idx {
// g.write('/*$it.left_type str*/')
// }
if it.op == .plus && it.left_type == table.string_type_idx {
g.write('string_add(')
g.expr(it.left)
g.write(', ')
g.expr(it.right)
}
else {
// if it.op == .dot {
// println('!! dot')
// }
g.expr(it.left)
g.write(' $it.op.str() ')
g.expr(it.right)
// if typ.name != typ2.name {
// verror('bad types $typ.name $typ2.name')
// }
}
}
ast.IntegerLiteral {
g.write(it.val.str())

View File

@ -88,6 +88,8 @@ i < 10; i++) {
bool b2 = array_get(bools, 0) || true;
bool b3 = get_bool() || true;
int f = array_int_first(nums);
string d = tos3("d");
println(string_add(s + d));
}
void User_inc_age(User u, int n) {

View File

@ -78,6 +78,8 @@ fn foo(a int) {
b2 := bools[0] || true
b3 := get_bool() || true
f := nums.first()
d := 'd'
println(s + d)
//cloned = nums.clone()
//cloned1 := cloned[0]
//println(cloned1 == 1)

View File

@ -18,9 +18,9 @@ multi_return_int_string mr_test();
int testa();
string testb(int a);
int testc(int a);
int Foo_testa(Foo f);
int Foo_testb(Foo f);
int Bar_testa(Bar b);
int Foo_testa(Foo* f);
int Foo_testb(Foo* f);
int Bar_testa(Bar* b);
int main() {
Bar b = (Bar){
@ -71,16 +71,16 @@ int testc(int a) {
return a;
}
int Foo_testa(Foo f) {
int Foo_testa(Foo* f) {
int a = Foo_testb(f);
a = 1;
return 4;
}
int Foo_testb(Foo f) {
int Foo_testb(Foo* f) {
return 4;
}
int Bar_testa(Bar b) {
int Bar_testa(Bar* b) {
return 4;
}