LEFT | RIGHT |
(no file at all) | |
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 * static initialization | 6 * static initialization |
7 */ | 7 */ |
8 | 8 |
9 #include <u.h> | 9 #include <u.h> |
10 #include <libc.h> | 10 #include <libc.h> |
(...skipping 1049 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1060 | 1060 |
1061 var = nod(OIND, var, N); | 1061 var = nod(OIND, var, N); |
1062 typecheck(&var, Erv | Easgn); | 1062 typecheck(&var, Erv | Easgn); |
1063 anylit(ctxt, n->left, var, init); | 1063 anylit(ctxt, n->left, var, init); |
1064 break; | 1064 break; |
1065 | 1065 |
1066 case OSTRUCTLIT: | 1066 case OSTRUCTLIT: |
1067 if(t->etype != TSTRUCT) | 1067 if(t->etype != TSTRUCT) |
1068 fatal("anylit: not struct"); | 1068 fatal("anylit: not struct"); |
1069 | 1069 |
1070 » » if(simplename(var)) { | 1070 » » if(simplename(var) && count(n->list) > 4) { |
1071 | 1071 |
1072 if(ctxt == 0) { | 1072 if(ctxt == 0) { |
1073 // lay out static data | 1073 // lay out static data |
1074 vstat = staticname(t, ctxt); | 1074 vstat = staticname(t, ctxt); |
1075 structlit(ctxt, 1, n, vstat, init); | 1075 structlit(ctxt, 1, n, vstat, init); |
1076 | 1076 |
1077 // copy static to var | 1077 // copy static to var |
1078 a = nod(OAS, var, vstat); | 1078 a = nod(OAS, var, vstat); |
1079 typecheck(&a, Etop); | 1079 typecheck(&a, Etop); |
1080 walkexpr(&a, init); | 1080 walkexpr(&a, init); |
1081 *init = list(*init, a); | 1081 *init = list(*init, a); |
1082 | 1082 |
1083 // add expressions to automatic | 1083 // add expressions to automatic |
1084 structlit(ctxt, 2, n, var, init); | 1084 structlit(ctxt, 2, n, var, init); |
1085 break; | 1085 break; |
1086 } | 1086 } |
1087 structlit(ctxt, 1, n, var, init); | 1087 structlit(ctxt, 1, n, var, init); |
1088 structlit(ctxt, 2, n, var, init); | 1088 structlit(ctxt, 2, n, var, init); |
1089 break; | 1089 break; |
1090 } | 1090 } |
1091 | 1091 |
1092 // initialize of not completely specified | 1092 // initialize of not completely specified |
1093 » » if(count(n->list) < structcount(t)) { | 1093 » » if(simplename(var) || count(n->list) < structcount(t)) { |
1094 a = nod(OAS, var, N); | 1094 a = nod(OAS, var, N); |
1095 typecheck(&a, Etop); | 1095 typecheck(&a, Etop); |
1096 walkexpr(&a, init); | 1096 walkexpr(&a, init); |
1097 *init = list(*init, a); | 1097 *init = list(*init, a); |
1098 } | 1098 } |
1099 structlit(ctxt, 3, n, var, init); | 1099 structlit(ctxt, 3, n, var, init); |
1100 break; | 1100 break; |
1101 | 1101 |
1102 case OARRAYLIT: | 1102 case OARRAYLIT: |
1103 if(t->etype != TARRAY) | 1103 if(t->etype != TARRAY) |
1104 fatal("anylit: not array"); | 1104 fatal("anylit: not array"); |
1105 if(t->bound < 0) { | 1105 if(t->bound < 0) { |
1106 slicelit(ctxt, n, var, init); | 1106 slicelit(ctxt, n, var, init); |
1107 break; | 1107 break; |
1108 } | 1108 } |
1109 | 1109 |
1110 » » if(simplename(var)) { | 1110 » » if(simplename(var) && count(n->list) > 4) { |
1111 | 1111 |
1112 if(ctxt == 0) { | 1112 if(ctxt == 0) { |
1113 // lay out static data | 1113 // lay out static data |
1114 vstat = staticname(t, ctxt); | 1114 vstat = staticname(t, ctxt); |
1115 arraylit(1, 1, n, vstat, init); | 1115 arraylit(1, 1, n, vstat, init); |
1116 | 1116 |
1117 // copy static to automatic | 1117 // copy static to automatic |
1118 a = nod(OAS, var, vstat); | 1118 a = nod(OAS, var, vstat); |
1119 typecheck(&a, Etop); | 1119 typecheck(&a, Etop); |
1120 walkexpr(&a, init); | 1120 walkexpr(&a, init); |
1121 *init = list(*init, a); | 1121 *init = list(*init, a); |
1122 | 1122 |
1123 // add expressions to automatic | 1123 // add expressions to automatic |
1124 arraylit(ctxt, 2, n, var, init); | 1124 arraylit(ctxt, 2, n, var, init); |
1125 break; | 1125 break; |
1126 } | 1126 } |
1127 arraylit(ctxt, 1, n, var, init); | 1127 arraylit(ctxt, 1, n, var, init); |
1128 arraylit(ctxt, 2, n, var, init); | 1128 arraylit(ctxt, 2, n, var, init); |
1129 break; | 1129 break; |
1130 } | 1130 } |
1131 | 1131 |
1132 // initialize of not completely specified | 1132 // initialize of not completely specified |
1133 » » if(count(n->list) < t->bound) { | 1133 » » if(simplename(var) || count(n->list) < t->bound) { |
1134 a = nod(OAS, var, N); | 1134 a = nod(OAS, var, N); |
1135 typecheck(&a, Etop); | 1135 typecheck(&a, Etop); |
1136 walkexpr(&a, init); | 1136 walkexpr(&a, init); |
1137 *init = list(*init, a); | 1137 *init = list(*init, a); |
1138 } | 1138 } |
1139 arraylit(ctxt, 3, n, var, init); | 1139 arraylit(ctxt, 3, n, var, init); |
1140 break; | 1140 break; |
1141 | 1141 |
1142 case OMAPLIT: | 1142 case OMAPLIT: |
1143 if(t->etype != TMAP) | 1143 if(t->etype != TMAP) |
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1496 if(p->cap == 0) | 1496 if(p->cap == 0) |
1497 p->cap = 4; | 1497 p->cap = 4; |
1498 else | 1498 else |
1499 p->cap *= 2; | 1499 p->cap *= 2; |
1500 p->e = realloc(p->e, p->cap*sizeof p->e[0]); | 1500 p->e = realloc(p->e, p->cap*sizeof p->e[0]); |
1501 if(p->e == nil) | 1501 if(p->e == nil) |
1502 fatal("out of memory"); | 1502 fatal("out of memory"); |
1503 } | 1503 } |
1504 return &p->e[p->len++]; | 1504 return &p->e[p->len++]; |
1505 } | 1505 } |
LEFT | RIGHT |