OLD | NEW |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 /* | 5 /* |
6 * type check the whole tree of an expression. | 6 * type check the whole tree of an expression. |
7 * calculates expression types. | 7 * calculates expression types. |
8 * evaluates compile time constants. | 8 * evaluates compile time constants. |
9 * marks variables that escape the local frame. | 9 * marks variables that escape the local frame. |
10 * rewrites n->op to be more specific in some cases. | 10 * rewrites n->op to be more specific in some cases. |
(...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
531 break; | 531 break; |
532 default: | 532 default: |
533 checklvalue(n->left, "take the address of"); | 533 checklvalue(n->left, "take the address of"); |
534 } | 534 } |
535 defaultlit(&n->left, T); | 535 defaultlit(&n->left, T); |
536 l = n->left; | 536 l = n->left; |
537 if((t = l->type) == T) | 537 if((t = l->type) == T) |
538 goto error; | 538 goto error; |
539 // top&Eindir means this is &x in *&x. (or the arg to built-in
print) | 539 // top&Eindir means this is &x in *&x. (or the arg to built-in
print) |
540 // n->etype means code generator flagged it as non-escaping. | 540 // n->etype means code generator flagged it as non-escaping. |
541 » » if(!(top & Eindir) && !n->etype && !debug['s']) | 541 » » if(debug['s'] && !(top & Eindir) && !n->etype) |
542 addrescapes(n->left); | 542 addrescapes(n->left); |
543 n->type = ptrto(t); | 543 n->type = ptrto(t); |
544 goto ret; | 544 goto ret; |
545 | 545 |
546 case OCOMPLIT: | 546 case OCOMPLIT: |
547 ok |= Erv; | 547 ok |= Erv; |
548 typecheckcomplit(&n); | 548 typecheckcomplit(&n); |
549 if(n->type == T) | 549 if(n->type == T) |
550 goto error; | 550 goto error; |
551 goto ret; | 551 goto ret; |
(...skipping 1048 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1600 return 1; | 1600 return 1; |
1601 } | 1601 } |
1602 | 1602 |
1603 if(f2 != T) { | 1603 if(f2 != T) { |
1604 tt = n->left->type; | 1604 tt = n->left->type; |
1605 dowidth(tt); | 1605 dowidth(tt); |
1606 rcvr = getthisx(f2->type)->type->type; | 1606 rcvr = getthisx(f2->type)->type->type; |
1607 if(!eqtype(rcvr, tt)) { | 1607 if(!eqtype(rcvr, tt)) { |
1608 if(rcvr->etype == tptr && eqtype(rcvr->type, tt)) { | 1608 if(rcvr->etype == tptr && eqtype(rcvr->type, tt)) { |
1609 checklvalue(n->left, "call pointer method on"); | 1609 checklvalue(n->left, "call pointer method on"); |
1610 » » » » if(!debug['s']) | 1610 » » » » if(debug['s']) |
1611 addrescapes(n->left); | 1611 addrescapes(n->left); |
1612 n->left = nod(OADDR, n->left, N); | 1612 n->left = nod(OADDR, n->left, N); |
1613 n->left->implicit = 1; | 1613 n->left->implicit = 1; |
1614 typecheck(&n->left, Etype|Erv); | 1614 typecheck(&n->left, Etype|Erv); |
1615 } else if(tt->etype == tptr && eqtype(tt->type, rcvr)) { | 1615 } else if(tt->etype == tptr && eqtype(tt->type, rcvr)) { |
1616 n->left = nod(OIND, n->left, N); | 1616 n->left = nod(OIND, n->left, N); |
1617 n->left->implicit = 1; | 1617 n->left->implicit = 1; |
1618 typecheck(&n->left, Etype|Erv); | 1618 typecheck(&n->left, Etype|Erv); |
1619 } else { | 1619 } else { |
1620 // method is attached to wrong type? | 1620 // method is attached to wrong type? |
(...skipping 1127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2748 ret: | 2748 ret: |
2749 if(typecheckdefstack->n != n) | 2749 if(typecheckdefstack->n != n) |
2750 fatal("typecheckdefstack mismatch"); | 2750 fatal("typecheckdefstack mismatch"); |
2751 l = typecheckdefstack; | 2751 l = typecheckdefstack; |
2752 typecheckdefstack = l->next; | 2752 typecheckdefstack = l->next; |
2753 | 2753 |
2754 lineno = lno; | 2754 lineno = lno; |
2755 n->walkdef = 1; | 2755 n->walkdef = 1; |
2756 return n; | 2756 return n; |
2757 } | 2757 } |
OLD | NEW |