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

« back to all changes in this revision

Viewing changes to vala/valalocalvariable.c

  • 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:
3
3
 
4
4
/* valalocalvariable.vala
5
5
 *
6
 
 * Copyright (C) 2006-2009  Jürg Billeter
 
6
 * Copyright (C) 2006-2010  Jürg Billeter
7
7
 *
8
8
 * This library is free software; you can redistribute it and/or
9
9
 * modify it under the terms of the GNU Lesser General Public
124
124
typedef struct _ValaSourceReference ValaSourceReference;
125
125
typedef struct _ValaSourceReferenceClass ValaSourceReferenceClass;
126
126
 
 
127
#define VALA_TYPE_FIELD_PROTOTYPE (vala_field_prototype_get_type ())
 
128
#define VALA_FIELD_PROTOTYPE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), VALA_TYPE_FIELD_PROTOTYPE, ValaFieldPrototype))
 
129
#define VALA_FIELD_PROTOTYPE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), VALA_TYPE_FIELD_PROTOTYPE, ValaFieldPrototypeClass))
 
130
#define VALA_IS_FIELD_PROTOTYPE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), VALA_TYPE_FIELD_PROTOTYPE))
 
131
#define VALA_IS_FIELD_PROTOTYPE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), VALA_TYPE_FIELD_PROTOTYPE))
 
132
#define VALA_FIELD_PROTOTYPE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), VALA_TYPE_FIELD_PROTOTYPE, ValaFieldPrototypeClass))
 
133
 
 
134
typedef struct _ValaFieldPrototype ValaFieldPrototype;
 
135
typedef struct _ValaFieldPrototypeClass ValaFieldPrototypeClass;
 
136
#define _g_free0(var) (var = (g_free (var), NULL))
 
137
 
127
138
#define VALA_TYPE_MEMBER_ACCESS (vala_member_access_get_type ())
128
139
#define VALA_MEMBER_ACCESS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), VALA_TYPE_MEMBER_ACCESS, ValaMemberAccess))
129
140
#define VALA_MEMBER_ACCESS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), VALA_TYPE_MEMBER_ACCESS, ValaMemberAccessClass))
193
204
 
194
205
typedef struct _ValaDelegate ValaDelegate;
195
206
typedef struct _ValaDelegateClass ValaDelegateClass;
196
 
#define _g_free0(var) (var = (g_free (var), NULL))
197
207
 
198
208
#define VALA_TYPE_POINTER_TYPE (vala_pointer_type_get_type ())
199
209
#define VALA_POINTER_TYPE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), VALA_TYPE_POINTER_TYPE, ValaPointerType))
285
295
void vala_code_node_unref (gpointer instance);
286
296
GParamSpec* vala_param_spec_code_node (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags);
287
297
void vala_value_set_code_node (GValue* value, gpointer v_object);
 
298
void vala_value_take_code_node (GValue* value, gpointer v_object);
288
299
gpointer vala_value_get_code_node (const GValue* value);
289
300
GType vala_code_node_get_type (void);
290
301
gpointer vala_code_visitor_ref (gpointer instance);
291
302
void vala_code_visitor_unref (gpointer instance);
292
303
GParamSpec* vala_param_spec_code_visitor (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags);
293
304
void vala_value_set_code_visitor (GValue* value, gpointer v_object);
 
305
void vala_value_take_code_visitor (GValue* value, gpointer v_object);
294
306
gpointer vala_value_get_code_visitor (const GValue* value);
295
307
GType vala_code_visitor_get_type (void);
296
308
GType vala_semantic_analyzer_get_type (void);
307
319
void vala_source_reference_unref (gpointer instance);
308
320
GParamSpec* vala_param_spec_source_reference (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags);
309
321
void vala_value_set_source_reference (GValue* value, gpointer v_object);
 
322
void vala_value_take_source_reference (GValue* value, gpointer v_object);
310
323
gpointer vala_value_get_source_reference (const GValue* value);
311
324
GType vala_source_reference_get_type (void);
312
325
ValaSymbol* vala_symbol_construct (GType object_type, const char* name, ValaSourceReference* source_reference);
332
345
void vala_report_error (ValaSourceReference* source, const char* message);
333
346
ValaSourceReference* vala_code_node_get_source_reference (ValaCodeNode* self);
334
347
ValaDataType* vala_expression_get_value_type (ValaExpression* self);
 
348
GType vala_field_prototype_get_type (void);
 
349
ValaSymbol* vala_expression_get_symbol_reference (ValaExpression* self);
 
350
char* vala_symbol_get_full_name (ValaSymbol* self);
335
351
ValaDataType* vala_data_type_copy (ValaDataType* self);
336
352
void vala_data_type_set_value_owned (ValaDataType* self, gboolean value);
337
353
void vala_data_type_set_floating_reference (ValaDataType* self, gboolean value);
338
354
GType vala_member_access_get_type (void);
339
355
GType vala_lambda_expression_get_type (void);
340
 
ValaSymbol* vala_expression_get_symbol_reference (ValaExpression* self);
341
356
GType vala_member_get_type (void);
342
357
GType vala_method_get_type (void);
343
358
GType vala_delegate_type_get_type (void);
345
360
GType vala_delegate_get_type (void);
346
361
ValaDelegate* vala_delegate_type_get_delegate_symbol (ValaDelegateType* self);
347
362
gboolean vala_delegate_matches_method (ValaDelegate* self, ValaMethod* m);
348
 
char* vala_symbol_get_full_name (ValaSymbol* self);
349
363
void vala_expression_set_value_type (ValaExpression* self, ValaDataType* value);
350
364
gboolean vala_data_type_compatible (ValaDataType* self, ValaDataType* target_type);
351
365
char* vala_code_node_to_string (ValaCodeNode* self);
357
371
void vala_scope_unref (gpointer instance);
358
372
GParamSpec* vala_param_spec_scope (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags);
359
373
void vala_value_set_scope (GValue* value, gpointer v_object);
 
374
void vala_value_take_scope (GValue* value, gpointer v_object);
360
375
gpointer vala_value_get_scope (const GValue* value);
361
376
GType vala_scope_get_type (void);
362
377
ValaScope* vala_symbol_get_scope (ValaSymbol* self);
445
460
 
446
461
static gboolean vala_local_variable_real_check (ValaCodeNode* base, ValaSemanticAnalyzer* analyzer) {
447
462
        ValaLocalVariable * self;
448
 
        gboolean result;
449
 
        ValaSymbol* _tmp10_;
 
463
        gboolean result = FALSE;
 
464
        gboolean _tmp3_ = FALSE;
 
465
        ValaSymbol* _tmp13_;
450
466
        ValaBlock* block;
451
467
        self = (ValaLocalVariable*) base;
452
468
        g_return_val_if_fail (analyzer != NULL, FALSE);
463
479
                vala_code_node_check ((ValaCodeNode*) vala_local_variable_get_initializer (self), analyzer);
464
480
        }
465
481
        if (vala_local_variable_get_variable_type (self) == NULL) {
466
 
                ValaDataType* _tmp0_;
 
482
                ValaDataType* _tmp2_;
467
483
                if (vala_local_variable_get_initializer (self) == NULL) {
468
484
                        vala_code_node_set_error ((ValaCodeNode*) self, TRUE);
469
485
                        vala_report_error (vala_code_node_get_source_reference ((ValaCodeNode*) self), "var declaration not allowed without initializer");
476
492
                        result = FALSE;
477
493
                        return result;
478
494
                }
479
 
                vala_local_variable_set_variable_type (self, _tmp0_ = vala_data_type_copy (vala_expression_get_value_type (vala_local_variable_get_initializer (self))));
480
 
                _vala_code_node_unref0 (_tmp0_);
 
495
                if (VALA_IS_FIELD_PROTOTYPE (vala_expression_get_value_type (vala_local_variable_get_initializer (self)))) {
 
496
                        char* _tmp1_;
 
497
                        char* _tmp0_;
 
498
                        vala_code_node_set_error ((ValaCodeNode*) self, TRUE);
 
499
                        vala_report_error (vala_code_node_get_source_reference ((ValaCodeNode*) vala_local_variable_get_initializer (self)), _tmp1_ = g_strdup_printf ("Access to instance member `%s' denied", _tmp0_ = vala_symbol_get_full_name (vala_expression_get_symbol_reference (vala_local_variable_get_initializer (self)))));
 
500
                        _g_free0 (_tmp1_);
 
501
                        _g_free0 (_tmp0_);
 
502
                        result = FALSE;
 
503
                        return result;
 
504
                }
 
505
                vala_local_variable_set_variable_type (self, _tmp2_ = vala_data_type_copy (vala_expression_get_value_type (vala_local_variable_get_initializer (self))));
 
506
                _vala_code_node_unref0 (_tmp2_);
481
507
                vala_data_type_set_value_owned (vala_local_variable_get_variable_type (self), TRUE);
482
508
                vala_data_type_set_floating_reference (vala_local_variable_get_variable_type (self), FALSE);
483
509
                vala_expression_set_target_type (vala_local_variable_get_initializer (self), vala_local_variable_get_variable_type (self));
484
510
        }
485
511
        if (vala_local_variable_get_initializer (self) != NULL) {
 
512
                _tmp3_ = !vala_code_node_get_error ((ValaCodeNode*) vala_local_variable_get_initializer (self));
 
513
        } else {
 
514
                _tmp3_ = FALSE;
 
515
        }
 
516
        if (_tmp3_) {
486
517
                if (vala_expression_get_value_type (vala_local_variable_get_initializer (self)) == NULL) {
487
 
                        gboolean _tmp1_ = FALSE;
488
 
                        gboolean _tmp2_ = FALSE;
 
518
                        gboolean _tmp4_ = FALSE;
 
519
                        gboolean _tmp5_ = FALSE;
489
520
                        if (!VALA_IS_MEMBER_ACCESS (vala_local_variable_get_initializer (self))) {
490
 
                                _tmp1_ = !VALA_IS_LAMBDA_EXPRESSION (vala_local_variable_get_initializer (self));
 
521
                                _tmp4_ = !VALA_IS_LAMBDA_EXPRESSION (vala_local_variable_get_initializer (self));
491
522
                        } else {
492
 
                                _tmp1_ = FALSE;
 
523
                                _tmp4_ = FALSE;
493
524
                        }
494
 
                        if (_tmp1_) {
 
525
                        if (_tmp4_) {
495
526
                                vala_code_node_set_error ((ValaCodeNode*) self, TRUE);
496
527
                                vala_report_error (vala_code_node_get_source_reference ((ValaCodeNode*) self), "expression type not allowed as initializer");
497
528
                                result = FALSE;
498
529
                                return result;
499
530
                        }
500
531
                        if (VALA_IS_METHOD (vala_expression_get_symbol_reference (vala_local_variable_get_initializer (self)))) {
501
 
                                _tmp2_ = VALA_IS_DELEGATE_TYPE (vala_local_variable_get_variable_type (self));
 
532
                                _tmp5_ = VALA_IS_DELEGATE_TYPE (vala_local_variable_get_variable_type (self));
502
533
                        } else {
503
 
                                _tmp2_ = FALSE;
 
534
                                _tmp5_ = FALSE;
504
535
                        }
505
 
                        if (_tmp2_) {
 
536
                        if (_tmp5_) {
506
537
                                ValaMethod* m;
507
538
                                ValaDelegateType* dt;
508
539
                                ValaDelegate* cb;
510
541
                                dt = _vala_code_node_ref0 (VALA_DELEGATE_TYPE (vala_local_variable_get_variable_type (self)));
511
542
                                cb = _vala_code_node_ref0 (vala_delegate_type_get_delegate_symbol (dt));
512
543
                                if (!vala_delegate_matches_method (cb, m)) {
513
 
                                        char* _tmp5_;
514
 
                                        char* _tmp4_;
515
 
                                        char* _tmp3_;
 
544
                                        char* _tmp8_;
 
545
                                        char* _tmp7_;
 
546
                                        char* _tmp6_;
516
547
                                        vala_code_node_set_error ((ValaCodeNode*) self, TRUE);
517
 
                                        vala_report_error (vala_code_node_get_source_reference ((ValaCodeNode*) self), _tmp5_ = g_strdup_printf ("declaration of method `%s' doesn't match declaration of callback `%s'", _tmp3_ = vala_symbol_get_full_name ((ValaSymbol*) m), _tmp4_ = vala_symbol_get_full_name ((ValaSymbol*) cb)));
518
 
                                        _g_free0 (_tmp5_);
519
 
                                        _g_free0 (_tmp4_);
520
 
                                        _g_free0 (_tmp3_);
 
548
                                        vala_report_error (vala_code_node_get_source_reference ((ValaCodeNode*) self), _tmp8_ = g_strdup_printf ("declaration of method `%s' doesn't match declaration of callback `%s'", _tmp6_ = vala_symbol_get_full_name ((ValaSymbol*) m), _tmp7_ = vala_symbol_get_full_name ((ValaSymbol*) cb)));
 
549
                                        _g_free0 (_tmp8_);
 
550
                                        _g_free0 (_tmp7_);
 
551
                                        _g_free0 (_tmp6_);
521
552
                                        result = FALSE;
522
553
                                        _vala_code_node_unref0 (m);
523
554
                                        _vala_code_node_unref0 (dt);
536
567
                        }
537
568
                }
538
569
                if (!vala_data_type_compatible (vala_expression_get_value_type (vala_local_variable_get_initializer (self)), vala_local_variable_get_variable_type (self))) {
539
 
                        char* _tmp8_;
540
 
                        char* _tmp7_;
541
 
                        char* _tmp6_;
 
570
                        char* _tmp11_;
 
571
                        char* _tmp10_;
 
572
                        char* _tmp9_;
542
573
                        vala_code_node_set_error ((ValaCodeNode*) self, TRUE);
543
 
                        vala_report_error (vala_code_node_get_source_reference ((ValaCodeNode*) self), _tmp8_ = g_strdup_printf ("Assignment: Cannot convert from `%s' to `%s'", _tmp6_ = vala_code_node_to_string ((ValaCodeNode*) vala_expression_get_value_type (vala_local_variable_get_initializer (self))), _tmp7_ = vala_code_node_to_string ((ValaCodeNode*) vala_local_variable_get_variable_type (self))));
544
 
                        _g_free0 (_tmp8_);
545
 
                        _g_free0 (_tmp7_);
546
 
                        _g_free0 (_tmp6_);
 
574
                        vala_report_error (vala_code_node_get_source_reference ((ValaCodeNode*) self), _tmp11_ = g_strdup_printf ("Assignment: Cannot convert from `%s' to `%s'", _tmp9_ = vala_code_node_to_string ((ValaCodeNode*) vala_expression_get_value_type (vala_local_variable_get_initializer (self))), _tmp10_ = vala_code_node_to_string ((ValaCodeNode*) vala_local_variable_get_variable_type (self))));
 
575
                        _g_free0 (_tmp11_);
 
576
                        _g_free0 (_tmp10_);
 
577
                        _g_free0 (_tmp9_);
547
578
                        result = FALSE;
548
579
                        return result;
549
580
                }
550
581
                if (vala_data_type_is_disposable (vala_expression_get_value_type (vala_local_variable_get_initializer (self)))) {
551
 
                        gboolean _tmp9_ = FALSE;
 
582
                        gboolean _tmp12_ = FALSE;
552
583
                        if (!VALA_IS_POINTER_TYPE (vala_local_variable_get_variable_type (self))) {
553
 
                                _tmp9_ = !vala_data_type_get_value_owned (vala_local_variable_get_variable_type (self));
 
584
                                _tmp12_ = !vala_data_type_get_value_owned (vala_local_variable_get_variable_type (self));
554
585
                        } else {
555
 
                                _tmp9_ = FALSE;
 
586
                                _tmp12_ = FALSE;
556
587
                        }
557
 
                        if (_tmp9_) {
 
588
                        if (_tmp12_) {
558
589
                                vala_code_node_set_error ((ValaCodeNode*) self, TRUE);
559
590
                                vala_report_error (vala_code_node_get_source_reference ((ValaCodeNode*) self), "Invalid assignment from owned expression to unowned variable");
560
591
                                result = FALSE;
563
594
                }
564
595
        }
565
596
        vala_scope_add (vala_symbol_get_scope (vala_semantic_analyzer_get_current_symbol (analyzer)), vala_symbol_get_name ((ValaSymbol*) self), (ValaSymbol*) self);
566
 
        block = _vala_code_node_ref0 ((_tmp10_ = vala_semantic_analyzer_get_current_symbol (analyzer), VALA_IS_BLOCK (_tmp10_) ? ((ValaBlock*) _tmp10_) : NULL));
 
597
        block = _vala_code_node_ref0 ((_tmp13_ = vala_semantic_analyzer_get_current_symbol (analyzer), VALA_IS_BLOCK (_tmp13_) ? ((ValaBlock*) _tmp13_) : NULL));
567
598
        if (block != NULL) {
568
599
                vala_block_add_local_variable (block, self);
569
600
        }
693
724
 
694
725
 
695
726
GType vala_local_variable_get_type (void) {
696
 
        static GType vala_local_variable_type_id = 0;
697
 
        if (vala_local_variable_type_id == 0) {
 
727
        static volatile gsize vala_local_variable_type_id__volatile = 0;
 
728
        if (g_once_init_enter (&vala_local_variable_type_id__volatile)) {
698
729
                static const GTypeInfo g_define_type_info = { sizeof (ValaLocalVariableClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) vala_local_variable_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ValaLocalVariable), 0, (GInstanceInitFunc) vala_local_variable_instance_init, NULL };
 
730
                GType vala_local_variable_type_id;
699
731
                vala_local_variable_type_id = g_type_register_static (VALA_TYPE_SYMBOL, "ValaLocalVariable", &g_define_type_info, 0);
 
732
                g_once_init_leave (&vala_local_variable_type_id__volatile, vala_local_variable_type_id);
700
733
        }
701
 
        return vala_local_variable_type_id;
 
734
        return vala_local_variable_type_id__volatile;
702
735
}
703
736
 
704
737