~ubuntu-branches/ubuntu/maverick/vala/maverick

« back to all changes in this revision

Viewing changes to vala/valaforeachstatement.vala

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2010-04-02 10:10:55 UTC
  • mfrom: (1.4.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20100402101055-qbx3okzv0tnp3wpp
Tags: 0.8.0-0ubuntu1
* New upstream release:
  - Infer type arguments when calling generic methods.
  - Support `in' operator for arrays.
  - Add experimental support for regular expression literals.
  - Add experimental support for chained relational expressions.
  - Add va_list support.
  - Add clutter-gtk-0.10 bindings (Gordon Allott).
  - Add gdl-1.0 bindings (Nicolas Joseph).
  - Add gstreamer-app-0.10 bindings (Sebastian Dröge).
  - Add gstreamer-cdda-0.10 bindings (Sebastian Dröge).
  - Add gudev-1.0 bindings (Jim Nelson).
  - Add libgda-report-4.0 bindings (Shawn Ferris).
  - Add libgvc (graphviz) bindings (Martin Olsson).
  - Add purple bindings (Adrien Bustany).
  - Many bug fixes and binding updates.
* debian/patches/99_ltmain_as-needed.patch: refreshed

Show diffs side-by-side

added added

removed removed

Lines of Context:
167
167
                var collection_type = collection.value_type.copy ();
168
168
                collection.target_type = collection_type.copy ();
169
169
                
170
 
                if (collection_type.is_array ()) {
 
170
                if (analyzer.context.profile != Profile.DOVA && collection_type.is_array ()) {
171
171
                        var array_type = (ArrayType) collection_type;
172
172
 
173
173
                        // can't use inline-allocated array for temporary variable
174
174
                        array_type.inline_allocated = false;
175
175
 
176
176
                        return check_without_iterator (analyzer, collection_type, array_type.element_type);
177
 
                } else if (collection_type.compatible (analyzer.glist_type) || collection_type.compatible (analyzer.gslist_type)) {
 
177
                } else if (analyzer.context.profile == Profile.GOBJECT && (collection_type.compatible (analyzer.glist_type) || collection_type.compatible (analyzer.gslist_type))) {
178
178
                        if (collection_type.get_type_arguments ().size != 1) {
179
179
                                error = true;
180
180
                                Report.error (collection.source_reference, "missing type argument for collection");
182
182
                        }
183
183
 
184
184
                        return check_without_iterator (analyzer, collection_type, collection_type.get_type_arguments ().get (0));
185
 
                } else if (collection_type.compatible (analyzer.gvaluearray_type)) {
 
185
                } else if (analyzer.context.profile == Profile.GOBJECT && collection_type.compatible (analyzer.gvaluearray_type)) {
186
186
                        return check_without_iterator (analyzer, collection_type, analyzer.gvalue_type);
187
187
                } else {
188
188
                        return check_with_iterator (analyzer, collection_type);
209
209
                        error = true;
210
210
                        return false;
211
211
                }
212
 
                var next_method = iterator_type.get_member ("next") as Method;
213
 
                if (next_method == null) {
214
 
                        Report.error (collection.source_reference, "`%s' does not have a `next' method".printf (iterator_type.to_string ()));
215
 
                        error = true;
216
 
                        return false;
217
 
                }
218
 
                if (next_method.get_parameters ().size != 0) {
219
 
                        Report.error (collection.source_reference, "`%s' must not have any parameters".printf (next_method.get_full_name ()));
220
 
                        error = true;
221
 
                        return false;
222
 
                }
223
 
                if (!next_method.return_type.compatible (analyzer.bool_type)) {
224
 
                        Report.error (collection.source_reference, "`%s' must return a boolean value".printf (next_method.get_full_name ()));
225
 
                        error = true;
226
 
                        return false;
227
 
                }
228
 
                var get_method = iterator_type.get_member ("get") as Method;
229
 
                if (get_method == null) {
230
 
                        Report.error (collection.source_reference, "`%s' does not have a `get' method".printf (iterator_type.to_string ()));
231
 
                        error = true;
232
 
                        return false;
233
 
                }
234
 
                if (get_method.get_parameters ().size != 0) {
235
 
                        Report.error (collection.source_reference, "`%s' must not have any parameters".printf (get_method.get_full_name ()));
236
 
                        error = true;
237
 
                        return false;
238
 
                }
239
 
                var element_type = get_method.return_type.get_actual_type (iterator_type, null, this);
240
 
                if (element_type is VoidType) {
241
 
                        Report.error (collection.source_reference, "`%s' must return an element".printf (get_method.get_full_name ()));
242
 
                        error = true;
243
 
                        return false;
244
 
                }
245
 
 
246
 
                // analyze element type
247
 
                if (type_reference == null) {
248
 
                        // var type
249
 
                        type_reference = element_type.copy ();
250
 
                } else if (!element_type.compatible (type_reference)) {
251
 
                        error = true;
252
 
                        Report.error (source_reference, "Foreach: Cannot convert from `%s' to `%s'".printf (element_type.to_string (), type_reference.to_string ()));
253
 
                        return false;
254
 
                } else if (element_type.is_disposable () && element_type.value_owned && !type_reference.value_owned) {
255
 
                        error = true;
256
 
                        Report.error (source_reference, "Foreach: Invalid assignment from owned expression to unowned variable");
257
 
                        return false;
258
 
                }
259
212
 
260
213
                var iterator_call = new MethodCall (new MemberAccess (collection, "iterator"));
261
214
                add_statement (new DeclarationStatement (new LocalVariable (iterator_type, "_%s_it".printf (variable_name), iterator_call, source_reference), source_reference));
262
215
 
263
 
                var next_call = new MethodCall (new MemberAccess (new MemberAccess.simple ("_%s_it".printf (variable_name), source_reference), "next", source_reference), source_reference);
264
 
                var loop = new WhileStatement (next_call, body, source_reference);
265
 
                add_statement (loop);
266
 
 
267
 
                var get_call = new MethodCall (new MemberAccess (new MemberAccess.simple ("_%s_it".printf (variable_name), source_reference), "get", source_reference), source_reference);
268
 
                body.insert_statement (0, new DeclarationStatement (new LocalVariable (type_reference, variable_name, get_call, source_reference), source_reference));
 
216
                var next_value_method = iterator_type.get_member ("next_value") as Method;
 
217
                var next_method = iterator_type.get_member ("next") as Method;
 
218
                if (next_value_method != null) {
 
219
                        if (next_value_method.get_parameters ().size != 0) {
 
220
                                Report.error (collection.source_reference, "`%s' must not have any parameters".printf (next_value_method.get_full_name ()));
 
221
                                error = true;
 
222
                                return false;
 
223
                        }
 
224
                        var element_type = next_value_method.return_type.get_actual_type (iterator_type, null, this);
 
225
                        if (!element_type.nullable) {
 
226
                                Report.error (collection.source_reference, "return type of `%s' must be nullable".printf (next_value_method.get_full_name ()));
 
227
                                error = true;
 
228
                                return false;
 
229
                        }
 
230
 
 
231
                        if (!analyze_element_type (element_type)) {
 
232
                                return false;
 
233
                        }
 
234
 
 
235
                        add_statement (new DeclarationStatement (new LocalVariable (type_reference, variable_name, null, source_reference), source_reference));
 
236
 
 
237
                        var next_value_call = new MethodCall (new MemberAccess (new MemberAccess.simple ("_%s_it".printf (variable_name), source_reference), "next_value", source_reference), source_reference);
 
238
                        var assignment = new Assignment (new MemberAccess (null, variable_name, source_reference), next_value_call, AssignmentOperator.SIMPLE, source_reference);
 
239
                        var conditional = new BinaryExpression (BinaryOperator.INEQUALITY, assignment, new NullLiteral (source_reference), source_reference);
 
240
                        var loop = new WhileStatement (conditional, body, source_reference);
 
241
                        add_statement (loop);
 
242
                } else if (next_method != null) {
 
243
                        if (next_method.get_parameters ().size != 0) {
 
244
                                Report.error (collection.source_reference, "`%s' must not have any parameters".printf (next_method.get_full_name ()));
 
245
                                error = true;
 
246
                                return false;
 
247
                        }
 
248
                        if (!next_method.return_type.compatible (analyzer.bool_type)) {
 
249
                                Report.error (collection.source_reference, "`%s' must return a boolean value".printf (next_method.get_full_name ()));
 
250
                                error = true;
 
251
                                return false;
 
252
                        }
 
253
                        var get_method = iterator_type.get_member ("get") as Method;
 
254
                        if (get_method == null) {
 
255
                                Report.error (collection.source_reference, "`%s' does not have a `get' method".printf (iterator_type.to_string ()));
 
256
                                error = true;
 
257
                                return false;
 
258
                        }
 
259
                        if (get_method.get_parameters ().size != 0) {
 
260
                                Report.error (collection.source_reference, "`%s' must not have any parameters".printf (get_method.get_full_name ()));
 
261
                                error = true;
 
262
                                return false;
 
263
                        }
 
264
                        var element_type = get_method.return_type.get_actual_type (iterator_type, null, this);
 
265
                        if (element_type is VoidType) {
 
266
                                Report.error (collection.source_reference, "`%s' must return an element".printf (get_method.get_full_name ()));
 
267
                                error = true;
 
268
                                return false;
 
269
                        }
 
270
 
 
271
                        if (!analyze_element_type (element_type)) {
 
272
                                return false;
 
273
                        }
 
274
 
 
275
                        var next_call = new MethodCall (new MemberAccess (new MemberAccess.simple ("_%s_it".printf (variable_name), source_reference), "next", source_reference), source_reference);
 
276
                        var loop = new WhileStatement (next_call, body, source_reference);
 
277
                        add_statement (loop);
 
278
 
 
279
                        var get_call = new MethodCall (new MemberAccess (new MemberAccess.simple ("_%s_it".printf (variable_name), source_reference), "get", source_reference), source_reference);
 
280
                        body.insert_statement (0, new DeclarationStatement (new LocalVariable (type_reference, variable_name, get_call, source_reference), source_reference));
 
281
                } else {
 
282
                        Report.error (collection.source_reference, "`%s' does not have a `next_value' or `next' method".printf (iterator_type.to_string ()));
 
283
                        error = true;
 
284
                        return false;
 
285
                }
269
286
 
270
287
                checked = false;
271
288
                return base.check (analyzer);
272
289
        }
273
290
 
 
291
        bool analyze_element_type (DataType element_type) {
 
292
                // analyze element type
 
293
                if (type_reference == null) {
 
294
                        // var type
 
295
                        type_reference = element_type.copy ();
 
296
                } else if (!element_type.compatible (type_reference)) {
 
297
                        error = true;
 
298
                        Report.error (source_reference, "Foreach: Cannot convert from `%s' to `%s'".printf (element_type.to_string (), type_reference.to_string ()));
 
299
                        return false;
 
300
                } else if (element_type.is_disposable () && element_type.value_owned && !type_reference.value_owned) {
 
301
                        error = true;
 
302
                        Report.error (source_reference, "Foreach: Invalid assignment from owned expression to unowned variable");
 
303
                        return false;
 
304
                }
 
305
 
 
306
                return true;
 
307
        }
 
308
 
274
309
        bool check_without_iterator (SemanticAnalyzer analyzer, DataType collection_type, DataType element_type) {
275
310
                // analyze element type
276
311
                if (type_reference == null) {