don't let named creation methods conflict with normal methods
authorJuerg Billeter <j@bitron.ch>
Sat, 1 Dec 2007 10:35:36 +0000 (10:35 +0000)
committerJürg Billeter <juergbi@src.gnome.org>
Sat, 1 Dec 2007 10:35:36 +0000 (10:35 +0000)
2007-12-01  Juerg Billeter  <j@bitron.ch>

* vala/parser.y, vala/valaclass.vala, vala/valacreationmethod.vala,
  vala/valainterfacewriter.vala, vala/valamemberaccess.vala,
  vala/valasemanticanalyzer.vala, vala/valastruct.vala: don't let named
  creation methods conflict with normal methods

* gobject/valaccodegenerator.vala: fix revealed typo

* vapi/cairo.vapi: Matrix is a value-type, declare it as struct

* vapi/packages/gtk+-2.0/gtk+-2.0-custom.vala,
  vapi/packages/gtk+-2.0/gtk+-2.0.metadata: remove default creation
  method from Gtk.Widget

* vapi/gtk+-2.0.vapi: regenerated

svn path=/trunk/; revision=743

13 files changed:
ChangeLog
gobject/valaccodegenerator.vala
vala/parser.y
vala/valaclass.vala
vala/valacreationmethod.vala
vala/valainterfacewriter.vala
vala/valamemberaccess.vala
vala/valasemanticanalyzer.vala
vala/valastruct.vala
vapi/cairo.vapi
vapi/gtk+-2.0.vapi
vapi/packages/gtk+-2.0/gtk+-2.0-custom.vala
vapi/packages/gtk+-2.0/gtk+-2.0.metadata

index 3876ea7..9d25b2f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+2007-12-01  Jürg Billeter  <j@bitron.ch>
+
+       * vala/parser.y, vala/valaclass.vala, vala/valacreationmethod.vala,
+         vala/valainterfacewriter.vala, vala/valamemberaccess.vala,
+         vala/valasemanticanalyzer.vala, vala/valastruct.vala: don't let named
+         creation methods conflict with normal methods
+
+       * gobject/valaccodegenerator.vala: fix revealed typo
+
+       * vapi/cairo.vapi: Matrix is a value-type, declare it as struct
+
+       * vapi/packages/gtk+-2.0/gtk+-2.0-custom.vala,
+         vapi/packages/gtk+-2.0/gtk+-2.0.metadata: remove default creation
+         method from Gtk.Widget
+
+       * vapi/gtk+-2.0.vapi: regenerated
+
 2007-11-30  Jürg Billeter  <j@bitron.ch>
 
        * gobject/valaccodegenerator.vala,
index 33c5785..18df28b 100644 (file)
@@ -1558,7 +1558,7 @@ public class Vala.CCodeGenerator : CodeGenerator {
                                        element_expr = get_ref_expression (ma);
 
                                        var clendecl = new CCodeDeclaration ("int");
-                                       clendecl.add_declarator (CCodeVariableDeclarator.with_initializer (get_array_length_cname (collection_backup.name, 1), array_len));
+                                       clendecl.add_declarator (new CCodeVariableDeclarator.with_initializer (get_array_length_cname (collection_backup.name, 1), array_len));
                                        cblock.add_statement (clendecl);
 
                                        var cfrag = new CCodeFragment ();
index f389dcc..c45fef3 100644 (file)
@@ -859,6 +859,7 @@ object_creation_expression
        : NEW member_name open_parens opt_argument_list CLOSE_PARENS opt_object_initializer
          {
                ValaSourceReference *src = src(@2);
+               vala_member_access_set_creation_member (VALA_MEMBER_ACCESS ($2), TRUE);
                ValaObjectCreationExpression *expr = vala_code_context_create_object_creation_expression (context, VALA_MEMBER_ACCESS ($2), src);
                g_object_unref ($2);
                g_object_unref (src);
index b319449..9349809 100644 (file)
@@ -192,8 +192,13 @@ public class Vala.Class : DataType {
                        m.this_parameter.type_reference.data_type = this;
                        m.scope.add (m.this_parameter.name, m.this_parameter);
                }
-               if (m is CreationMethod && m.name == null) {
-                       default_construction_method = m;
+               if (m is CreationMethod) {
+                       if (m.name == null) {
+                               default_construction_method = m;
+                               m.name = ".new";
+                       } else {
+                               m.name = ".new." + m.name;
+                       }
                }
 
                methods.add (m);
index 818ad69..effafcf 100644 (file)
@@ -68,10 +68,10 @@ public class Vala.CreationMethod : Method {
        public override string! get_default_cname () {
                var parent = parent_symbol;
                assert (parent is DataType);
-               if (name == null) {
+               if (name.len () == ".new".len ()) {
                        return "%snew".printf (((DataType) parent).get_lower_case_cprefix ());
                } else {
-                       return "%snew_%s".printf (((DataType) parent).get_lower_case_cprefix (), name);
+                       return "%snew_%s".printf (((DataType) parent).get_lower_case_cprefix (), name.offset (".new.".len ()));
                }
        }
 }
index 594bd14..2ea1e5d 100644 (file)
@@ -518,11 +518,7 @@ public class Vala.InterfaceWriter : CodeVisitor {
                        write_string (" ");
                        var datatype = (DataType) m.parent_symbol;
                        write_identifier (datatype.name);
-               
-                       if (m.name != null) {
-                               write_string (".");
-                               write_identifier (m.name);
-                       }
+                       write_identifier (m.name.offset (".new".len ()));
                } else if (!m.instance) {
                        write_string (" static");
                } else if (m.is_abstract) {
index 56e5284..f1adead 100644 (file)
@@ -53,6 +53,11 @@ public class Vala.MemberAccess : Expression {
         */
        public bool prototype_access { get; set; }
 
+       /**
+        * Specifies whether the member is used for object creation.
+        */
+       public bool creation_member { get; set; }
+
        private Expression _inner;
        private Gee.List<TypeReference> type_argument_list = new ArrayList<TypeReference> ();
        
index 87d3318..767a6ab 100644 (file)
@@ -1359,7 +1359,13 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
 
                        if (expr.inner is MemberAccess || expr.inner is BaseAccess) {
                                base_symbol = expr.inner.symbol_reference;
-                               if (base_symbol is Namespace || base_symbol is DataType) {
+
+                               if (expr.creation_member && base_symbol is DataType) {
+                                       // check for named creation method
+                                       expr.symbol_reference = base_symbol.scope.lookup (".new." + expr.member_name);
+                               }
+
+                               if (expr.symbol_reference == null && (base_symbol is Namespace || base_symbol is DataType)) {
                                        expr.symbol_reference = base_symbol.scope.lookup (expr.member_name);
                                        if (expr.inner is BaseAccess) {
                                                // inner expression is base access
index 5f65d21..127e701 100644 (file)
@@ -118,8 +118,13 @@ public class Vala.Struct : DataType {
                        m.this_parameter.type_reference.data_type = this;
                        m.scope.add (m.this_parameter.name, m.this_parameter);
                }
-               if (m is CreationMethod && m.name == null) {
-                       default_construction_method = m;
+               if (m is CreationMethod) {
+                       if (m.name == null) {
+                               default_construction_method = m;
+                               m.name = ".new";
+                       } else {
+                               m.name = ".new." + m.name;
+                       }
                }
 
                methods.add (m);
index cf60d31..cacdbd6 100644 (file)
@@ -44,7 +44,7 @@ namespace Cairo {
                public weak Pattern get_source ();
 
                public void set_matrix (Matrix matrix);
-               public void get_matrix (Matrix matrix);
+               public void get_matrix (out Matrix matrix);
 
                public void set_antialias (Antialias antialias);
                public Antialias get_antialias ();
@@ -137,8 +137,8 @@ namespace Cairo {
                
                public void select_font_face (string! family, FontSlant slant, FontWeight weight);
                public void set_font_size (double size);
-               public void set_font_matrix (Matrix! matrix);
-               public void get_font_matrix (Matrix matrix);
+               public void set_font_matrix (Matrix matrix);
+               public void get_font_matrix (out Matrix matrix);
                public void set_font_options (ref FontOptions! options);
                public void get_font_options (ref FontOptions options);
                
@@ -253,7 +253,7 @@ namespace Cairo {
                public Filter get_filter ();
                
                public void set_matrix (Matrix matrix);
-               public void get_matrix (Matrix matrix);
+               public void get_matrix (out Matrix matrix);
                
                public PatternType get_type ();
        }
@@ -326,8 +326,8 @@ namespace Cairo {
                public void glyph_extents (Glyph[] glyphs, int num_glyphs, ref TextExtents extents);
                public weak FontFace get_font_face ();
                public void get_font_options (ref FontOptions options);
-               public void get_font_matrix (Matrix font_matrix);
-               public void get_ctm (Matrix ctm);
+               public void get_font_matrix (out Matrix font_matrix);
+               public void get_ctm (out Matrix ctm);
                public FontType get_type ();
        }
        
@@ -520,13 +520,19 @@ namespace Cairo {
                public int get_depth ();
        }
        
-       [CCode (free_function = "g_free", cname = "cairo_matrix_t")]
-       public class Matrix {
-               public void init (double xx, double yx, double xy, double yy, double x0, double y0);
-               public void init_identity ();
-               public void init_translate (double tx, double ty);
-               public void init_scale (double sx, double sy);
-               public void init_rotate (double radians);
+       [CCode (cname = "cairo_matrix_t")]
+       public struct Matrix {
+               [CCode (cname = "cairo_matrix_init")]
+               public Matrix (double xx, double yx, double xy, double yy, double x0, double y0);
+               [CCode (cname = "cairo_matrix_init_identity")]
+               public Matrix.identity ();
+               [CCode (cname = "cairo_matrix_init_translate")]
+               public Matrix.translate (double tx, double ty);
+               [CCode (cname = "cairo_matrix_init_scale")]
+               public Matrix.scale (double sx, double sy);
+               [CCode (cname = "cairo_matrix_init_rotate")]
+               public Matrix.rotate (double radians);
+
                public void translate (double tx, double ty);
                public void scale (double sx, double sy);
                public void rotate (double radians);
index ea863d0..7e0d815 100644 (file)
@@ -934,13 +934,13 @@ namespace Gtk {
                public Gtk.Requisition requisition;
                public Gtk.Allocation allocation;
                public weak Gdk.Window window;
+               public Widget (GLib.Type type, ...);
                [CCode (cname = "GTK_WIDGET_FLAGS")]
                public Gtk.WidgetFlags get_flags ();
                [CCode (cname = "GTK_WIDGET_SET_FLAGS")]
                public void set_flags (Gtk.WidgetFlags flags);
                [CCode (cname = "GTK_WIDGET_UNSET_FLAGS")]
                public void unset_flags (Gtk.WidgetFlags flags);
-               public Widget ();
                public bool activate ();
                public void add_accelerator (string accel_signal, Gtk.AccelGroup accel_group, uint accel_key, Gdk.ModifierType accel_mods, Gtk.AccelFlags accel_flags);
                public void add_events (int events);
@@ -1009,7 +1009,6 @@ namespace Gtk {
                public void modify_font (Pango.FontDescription font_desc);
                public void modify_style (Gtk.RcStyle style);
                public void modify_text (Gtk.StateType state, out Gdk.Color color);
-               public Widget (GLib.Type type, ...);
                public void path (uint path_length, string path, string path_reversed);
                public static void pop_colormap ();
                public static void pop_composite_child ();
index 3b1f9df..c0fce51 100644 (file)
@@ -33,6 +33,9 @@ namespace Gtk {
 
        public class Widget {
                [Import]
+               public Widget (GLib.Type type, ...);
+
+               [Import]
                [CCode (cname = "GTK_WIDGET_FLAGS")]
                public WidgetFlags get_flags ();
 
index 59550fb..74c0477 100644 (file)
@@ -160,6 +160,7 @@ GtkWidget::unmap has_emitter="1"
 GtkWidget::unrealize has_emitter="1"
 gtk_window_has_toplevel_focus hidden="1" experimental="1"
 gtk_window_is_active hidden="1" experimental="1"
+gtk_widget_new hidden="1"
 GtkWindow::activate_default name="default_activated" experimental="1"
 GtkWindow::activate_focus name="focus_activated" experimental="1"
 GtkWindow::set_focus has_emitter="1"