Add basic support for static properties
authorJürg Billeter <j@bitron.ch>
Sat, 27 Sep 2008 08:51:57 +0000 (08:51 +0000)
committerJürg Billeter <juergbi@src.gnome.org>
Sat, 27 Sep 2008 08:51:57 +0000 (08:51 +0000)
2008-09-27  Jürg Billeter  <j@bitron.ch>

* vala/valaparser.vala:
* vala/valasemanticanalyzer.vala:
* gobject/valaccodegenerator.vala:
* gobject/valaccodememberaccessbinding.vala:

Add basic support for static properties

svn path=/trunk/; revision=1793

ChangeLog
gobject/valaccodegenerator.vala
gobject/valaccodememberaccessbinding.vala
vala/valaparser.vala
vala/valasemanticanalyzer.vala

index 3f98eab..789d7f7 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2008-09-27  Jürg Billeter  <j@bitron.ch>
+
+       * vala/valaparser.vala:
+       * vala/valasemanticanalyzer.vala:
+       * gobject/valaccodegenerator.vala:
+       * gobject/valaccodememberaccessbinding.vala:
+
+       Add basic support for static properties
+
 2008-09-27  Jared Moore  <jaredm@gmx.com>
 
        * vala/valaenum.vala:
index b37ea4f..7f13ae3 100644 (file)
@@ -769,7 +769,8 @@ public class Vala.CCodeGenerator : CodeGenerator {
                next_temp_var_id = old_next_temp_var_id;
 
                var cl = prop.parent_symbol as Class;
-               if (cl != null && cl.is_subtype_of (gobject_type)) {
+               if (cl != null && cl.is_subtype_of (gobject_type)
+                   && prop.binding == MemberBinding.INSTANCE) {
                        // GObject property
                        // FIXME: omit real struct types for now since they
                        // cannot be expressed as gobject property yet
@@ -899,16 +900,18 @@ public class Vala.CCodeGenerator : CodeGenerator {
                        }
 
                        ObjectType base_type = null;
-                       if (is_virtual) {
-                               if (prop.base_property != null) {
-                                       base_type = new ObjectType ((ObjectTypeSymbol) prop.base_property.parent_symbol);
-                               } else if (prop.base_interface_property != null) {
-                                       base_type = new ObjectType ((ObjectTypeSymbol) prop.base_interface_property.parent_symbol);
+                       if (prop.binding == MemberBinding.INSTANCE) {
+                               if (is_virtual) {
+                                       if (prop.base_property != null) {
+                                               base_type = new ObjectType ((ObjectTypeSymbol) prop.base_property.parent_symbol);
+                                       } else if (prop.base_interface_property != null) {
+                                               base_type = new ObjectType ((ObjectTypeSymbol) prop.base_interface_property.parent_symbol);
+                                       }
+                                       function.modifiers |= CCodeModifiers.STATIC;
+                                       function.add_parameter (new CCodeFormalParameter ("base", base_type.get_cname ()));
+                               } else {
+                                       function.add_parameter (cselfparam);
                                }
-                               function.modifiers |= CCodeModifiers.STATIC;
-                               function.add_parameter (new CCodeFormalParameter ("base", base_type.get_cname ()));
-                       } else {
-                               function.add_parameter (cselfparam);
                        }
                        if (returns_real_struct) {
                                // return non simple structs as out parameter
@@ -945,7 +948,7 @@ public class Vala.CCodeGenerator : CodeGenerator {
                                function.block.prepend_statement (cdecl);
                        }
 
-                       if (!is_virtual) {
+                       if (prop.binding == MemberBinding.INSTANCE && !is_virtual) {
                                if (returns_real_struct) {
                                        function.block.prepend_statement (create_property_type_check_statement (prop, false, t, true, "self"));
                                } else {
@@ -3983,8 +3986,10 @@ public class Vala.CCodeGenerator : CodeGenerator {
                
                var ccall = new CCodeFunctionCall (new CCodeIdentifier (set_func));
 
-               /* target instance is first argument */
-               ccall.add_argument ((CCodeExpression) ma.inner.ccodenode);
+               if (prop.binding == MemberBinding.INSTANCE) {
+                       /* target instance is first argument */
+                       ccall.add_argument ((CCodeExpression) ma.inner.ccodenode);
+               }
 
                if (prop.no_accessor_method) {
                        /* property name is second argument of g_object_set */
index cf6cc2c..8f24ef1 100644 (file)
@@ -182,7 +182,9 @@ public class Vala.CCodeMemberAccessBinding : CCodeExpressionBinding {
                                }
                                var ccall = new CCodeFunctionCall (new CCodeIdentifier (getter_cname));
 
-                               ccall.add_argument (pub_inst);
+                               if (prop.binding == MemberBinding.INSTANCE) {
+                                       ccall.add_argument (pub_inst);
+                               }
 
                                // Property acesses to real struct types are handeled different to other properties.
                                // They are returned as out parameter.
index 74fcb25..4ac73dd 100644 (file)
@@ -2176,6 +2176,11 @@ public class Vala.Parser : CodeVisitor {
                var prop = new Property (id, type, null, null, get_src_com (begin));
                prop.access = access;
                set_attributes (prop, attrs);
+               if (ModifierFlags.STATIC in flags) {
+                       prop.binding = MemberBinding.STATIC;
+               } else if (ModifierFlags.CLASS in flags) {
+                       prop.binding = MemberBinding.CLASS;
+               }
                if (ModifierFlags.ABSTRACT in flags) {
                        prop.is_abstract = true;
                }
index e87facf..020815c 100644 (file)
@@ -643,12 +643,6 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
        public override void visit_property (Property prop) {
                current_symbol = prop;
 
-               if (prop.binding != MemberBinding.INSTANCE) {
-                       Report.error (prop.source_reference, "static properties are not yet supported");
-                       prop.error = true;
-                       return;
-               }
-
                prop.accept_children (this);
 
                // check whether property type is at least as accessible as the property