simplify unref expression for non-null types don't mark fields as non-null
authorJürg Billeter <j@bitron.ch>
Wed, 18 Apr 2007 08:49:10 +0000 (08:49 +0000)
committerJürg Billeter <juergbi@src.gnome.org>
Wed, 18 Apr 2007 08:49:10 +0000 (08:49 +0000)
2007-04-18  Jürg Billeter  <j@bitron.ch>

* vala/valacodegenerator.vala: simplify unref expression for non-null
  types
* vala/valaclass.vala: don't mark fields as non-null due to
  initialization issue

svn path=/trunk/; revision=285

vala/ChangeLog
vala/vala/valaclass.vala
vala/vala/valacodegenerator.vala

index daddfcd..1ad4d1d 100644 (file)
@@ -1,3 +1,10 @@
+2007-04-18  Jürg Billeter  <j@bitron.ch>
+
+       * vala/valacodegenerator.vala: simplify unref expression for non-null
+         types
+       * vala/valaclass.vala: don't mark fields as non-null due to
+         initialization issue
+
 2007-04-12  Jürg Billeter  <j@bitron.ch>
 
        * vala/valatypereference.vala: add is_null property
index 4cbc1b9..a5b846f 100644 (file)
@@ -148,6 +148,8 @@ public class Vala.Class : DataType {
         * @param f a field
         */
        public void add_field (Field! f) {
+               // non_null fields not yet supported due to initialization issues
+               f.type_reference.non_null = false;
                fields.append (f);
                if (f.access == MemberAccessibility.PRIVATE && f.instance) {
                        _has_private_fields = true;
@@ -192,7 +194,10 @@ public class Vala.Class : DataType {
                if (prop.set_accessor != null && prop.set_accessor.body == null &&
                    source_reference != null && !source_reference.file.pkg) {
                        /* automatic property accessor body generation */
-                       var f = new Field ("_%s".printf (prop.name), prop.type_reference, null, prop.source_reference);
+                       var field_type = prop.type_reference.copy ();
+                       // non_null fields not yet supported due to initialization issues
+                       field_type.non_null = false;
+                       var f = new Field ("_%s".printf (prop.name), field_type, null, prop.source_reference);
                        f.access = MemberAccessibility.PRIVATE;
                        add_field (f);
                }
index 35d3487..92550bc 100644 (file)
@@ -2260,6 +2260,10 @@ public class Vala.CodeGenerator : CodeVisitor {
                 * if foo is of static type non-null
                 */
 
+               if (type.is_null) {
+                       return new CCodeConstant ("NULL");
+               }
+
                var cisnull = new CCodeBinaryExpression (CCodeBinaryOperator.EQUALITY, cvar, new CCodeConstant ("NULL"));
                if (type.data_type == null) {
                        if (current_class == null) {
@@ -2311,7 +2315,12 @@ public class Vala.CodeGenerator : CodeVisitor {
                ccomma.append_expression (new CCodeConstant ("NULL"));
                
                var cassign = new CCodeAssignment (cvar, ccomma);
-               
+
+               // g_free (NULL) is allowed
+               if (type.non_null || (type.data_type != null && !type.data_type.is_reference_counting () && type.data_type.get_free_function () == "g_free")) {
+                       return new CCodeParenthesizedExpression (cassign);
+               }
+
                return new CCodeConditionalExpression (cisnull, new CCodeConstant ("NULL"), new CCodeParenthesizedExpression (cassign));
        }