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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 case ONAME: | 73 case ONAME: |
74 case OTYPE: | 74 case OTYPE: |
75 case OLITERAL: | 75 case OLITERAL: |
76 case OPACK: | 76 case OPACK: |
77 break; | 77 break; |
78 default: | 78 default: |
79 return n; | 79 return n; |
80 } | 80 } |
81 } | 81 } |
82 | 82 |
83 » if(n->typecheck == 2) | 83 » if(n->typecheck == 2) { |
84 » » fatal("typecheck loop"); | 84 » » yyerror("typechecking loop"); |
| 85 » » return n; |
| 86 » } |
85 n->typecheck = 2; | 87 n->typecheck = 2; |
86 | 88 |
87 redo: | 89 redo: |
88 lno = setlineno(n); | 90 lno = setlineno(n); |
89 if(n->sym) { | 91 if(n->sym) { |
90 walkdef(n); | 92 walkdef(n); |
91 if(n->op == ONONAME) | 93 if(n->op == ONONAME) |
92 goto error; | 94 goto error; |
93 } | 95 } |
94 | 96 |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 if(n->op != OLITERAL) { | 350 if(n->op != OLITERAL) { |
349 defaultlit2(&l, &r, 1); | 351 defaultlit2(&l, &r, 1); |
350 n->left = l; | 352 n->left = l; |
351 n->right = r; | 353 n->right = r; |
352 } | 354 } |
353 } | 355 } |
354 if(et == TSTRING) { | 356 if(et == TSTRING) { |
355 if(iscmp[n->op]) { | 357 if(iscmp[n->op]) { |
356 n->etype = n->op; | 358 n->etype = n->op; |
357 n->op = OCMPSTR; | 359 n->op = OCMPSTR; |
358 » » » } else if(n->op == OASOP) | 360 » » » } else if(n->op == OADD) |
359 » » » » n->op = OAPPENDSTR; | |
360 » » » else if(n->op == OADD) | |
361 n->op = OADDSTR; | 361 n->op = OADDSTR; |
362 } | 362 } |
363 if(et == TINTER) { | 363 if(et == TINTER) { |
364 if(l->op == OLITERAL && l->val.ctype == CTNIL) { | 364 if(l->op == OLITERAL && l->val.ctype == CTNIL) { |
365 // swap for back end | 365 // swap for back end |
366 n->left = r; | 366 n->left = r; |
367 n->right = l; | 367 n->right = l; |
368 } else if(r->op == OLITERAL && r->val.ctype == CTNIL) { | 368 } else if(r->op == OLITERAL && r->val.ctype == CTNIL) { |
369 // leave alone for back end | 369 // leave alone for back end |
370 } else { | 370 } else { |
(...skipping 1921 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2292 while(p < ep) { | 2292 while(p < ep) { |
2293 p += chartorune(&r, p); | 2293 p += chartorune(&r, p); |
2294 l = list(l, nod(OKEY, nodintconst(i++), nodintconst(r)))
; | 2294 l = list(l, nod(OKEY, nodintconst(i++), nodintconst(r)))
; |
2295 } | 2295 } |
2296 } | 2296 } |
2297 nn = nod(OCOMPLIT, N, typenod(n->type)); | 2297 nn = nod(OCOMPLIT, N, typenod(n->type)); |
2298 nn->list = l; | 2298 nn->list = l; |
2299 typecheck(&nn, Erv); | 2299 typecheck(&nn, Erv); |
2300 *np = nn; | 2300 *np = nn; |
2301 } | 2301 } |
OLD | NEW |