comparison dmd/ArrayInitializer.d @ 130:60bb0fe4563e

dmdfe 2.037 first main iteration
author Eldar Insafutdinov <e.insafutdinov@gmail.com>
date Thu, 09 Sep 2010 22:51:44 +0100
parents e6e542f37b94
children 0c8cc2a10f99
comparison
equal deleted inserted replaced
129:010eb8f0e18d 130:60bb0fe4563e
96 } 96 }
97 97
98 length = 0; 98 length = 0;
99 foreach (size_t i, Expression idx; index) 99 foreach (size_t i, Expression idx; index)
100 { 100 {
101 Initializer val;
102
103 if (idx) 101 if (idx)
104 { 102 {
105 idx = idx.semantic(sc); 103 idx = idx.semantic(sc);
106 idx = idx.optimize(WANTvalue | WANTinterpret); 104 idx = idx.optimize(WANTvalue | WANTinterpret);
107 index[i] = idx; 105 index[i] = idx;
108 length = cast(uint)idx.toInteger(); 106 length = cast(uint)idx.toInteger();
109 } 107 }
110 108
111 val = value[i]; 109 Initializer val = value[i];
112 val = val.semantic(sc, t.nextOf()); 110 val = val.semantic(sc, t.nextOf());
113 value[i] = val; 111 value[i] = val;
114 length++; 112 length++;
115 if (length == 0) 113 if (length == 0)
116 error(loc, "array dimension overflow"); 114 error(loc, "array dimension overflow");
122 error(loc, "array dimension %u exceeds max of %ju", dim, amax / t.nextOf().size()); 120 error(loc, "array dimension %u exceeds max of %ju", dim, amax / t.nextOf().size());
123 121
124 return this; 122 return this;
125 } 123 }
126 124
125 int isAssociativeArray()
126 {
127 for (size_t i = 0; i < value.dim; i++)
128 {
129 if (index[i])
130 return 1;
131 }
132 return 0;
133 }
134
127 override Type inferType(Scope sc) 135 override Type inferType(Scope sc)
128 { 136 {
129 //printf("ArrayInitializer.inferType() %s\n", toChars()); 137 //printf("ArrayInitializer.inferType() %s\n", toChars());
138 assert(0);
139 return null;
140 static if (false) {
130 type = Type.terror; 141 type = Type.terror;
131 for (size_t i = 0; i < value.dim; i++) 142 for (size_t i = 0; i < value.dim; i++)
132 { 143 {
133 if (index[i]) 144 if (index[i])
134 goto Laa; 145 goto Laa;
138 { 149 {
139 if (iz) 150 if (iz)
140 { 151 {
141 Type t = iz.inferType(sc); 152 Type t = iz.inferType(sc);
142 if (i == 0) 153 if (i == 0)
143 { 154 { /* BUG: This gets the type from the first element.
155 * Fix to use all the elements to figure out the type.
156 */
144 t = new TypeSArray(t, new IntegerExp(value.dim)); 157 t = new TypeSArray(t, new IntegerExp(value.dim));
145 t = t.semantic(loc, sc); 158 t = t.semantic(loc, sc);
146 type = t; 159 type = t;
147 } 160 }
148 } 161 }
149 } 162 }
150 return type; 163 return type;
151 164
152 Laa: 165 Laa:
153 /* It's possibly an associative array initializer 166 /* It's possibly an associative array initializer.
154 */ 167 * BUG: inferring type from first member.
168 */
155 Initializer iz = value[0]; 169 Initializer iz = value[0];
156 Expression indexinit = index[0]; 170 Expression indexinit = index[0];
157 if (iz && indexinit) 171 if (iz && indexinit)
158 { 172 {
159 Type t = iz.inferType(sc); 173 Type t = iz.inferType(sc);
163 type = t.semantic(loc, sc); 177 type = t.semantic(loc, sc);
164 } 178 }
165 else 179 else
166 error(loc, "cannot infer type from this array initializer"); 180 error(loc, "cannot infer type from this array initializer");
167 return type; 181 return type;
182 }
168 } 183 }
169 184
170 /******************************** 185 /********************************
171 * If possible, convert array initializer to array literal. 186 * If possible, convert array initializer to array literal.
172 * Otherwise return null. 187 * Otherwise return null.
254 269
255 Lno: 270 Lno:
256 return null; 271 return null;
257 } 272 }
258 273
259 Initializer toAssocArrayInitializer() 274 Expression toAssocArrayLiteral()
260 { 275 {
261 assert(false); 276 assert(false);
262 } 277 }
263 278
264 override void toCBuffer(OutBuffer buf, HdrGenState* hgs) 279 override void toCBuffer(OutBuffer buf, HdrGenState* hgs)