]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Add support for [Immutable] class attribute, allow duplication of
authorJuerg Billeter <j@bitron.ch>
Sun, 25 May 2008 14:02:57 +0000 (14:02 +0000)
committerJürg Billeter <juergbi@src.gnome.org>
Sun, 25 May 2008 14:02:57 +0000 (14:02 +0000)
2008-05-25  Juerg Billeter  <j@bitron.ch>

* vala/valaclass.vala:
* gobject/valaccodegenerator.vala:
* vapi/glib-2.0.vapi:

Add support for [Immutable] class attribute, allow duplication of
immutable instances

svn path=/trunk/; revision=1430

ChangeLog
gobject/valaccodegenerator.vala
vala/valaclass.vala
vapi/glib-2.0.vapi

index b83005312bb746d76231a7b63e3d4caa613bdf99..fa324b76cff1baeff84aaf3eaa82ef333c68b0b2 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2008-05-25  Jürg Billeter  <j@bitron.ch>
+
+       * vala/valaclass.vala:
+       * gobject/valaccodegenerator.vala:
+       * vapi/glib-2.0.vapi:
+
+       Add support for [Immutable] class attribute, allow duplication of
+       immutable instances
+
 2008-05-25  Jürg Billeter  <j@bitron.ch>
 
        * vala/valaparser.vala: fix warning with pointer casts
index 920350b351937f5f49660d66f734ccf4cca760cb..64047f2f73b8810b85def22a4210b910a845846a 100644 (file)
@@ -1254,11 +1254,13 @@ public class Vala.CCodeGenerator : CodeGenerator {
        }
 
        private CCodeExpression? get_dup_func_expression (DataType type, SourceReference? source_reference) {
+               var cl = type.data_type as Class;
                if (type.data_type != null) {
                        string dup_function;
                        if (type.data_type.is_reference_counting ()) {
                                dup_function = type.data_type.get_ref_function ();
-                       } else if (type.data_type == string_type.data_type) {
+                       } else if (cl != null && cl.is_immutable) {
+                               // allow duplicates of immutable instances as for example strings
                                dup_function = type.data_type.get_dup_function ();
                        } else if (type is ValueType) {
                                dup_function = "";
index 3f0276064d461b28f5773825ab5af4a59d8df8d9..bd67bf623d0ca2a04f2f8198cad560c9838ddb1d 100644 (file)
@@ -61,6 +61,21 @@ public class Vala.Class : Typesymbol {
                }
        }
 
+       /**
+        * Instances of immutable classes are immutable after construction.
+        */
+       public bool is_immutable {
+               get {
+                       if (base_class != null) {
+                               return base_class.is_immutable;
+                       }
+                       return _is_immutable;
+               }
+               set {
+                       _is_immutable = value;
+               }
+       }
+
        /**
         * Specifies whether this class has private fields.
         */
@@ -80,6 +95,7 @@ public class Vala.Class : Typesymbol {
        private string set_value_function;
        private string? type_signature;
        private bool _is_compact;
+       private bool _is_immutable;
 
        private Gee.List<TypeParameter> type_parameters = new ArrayList<TypeParameter> ();
 
@@ -562,6 +578,8 @@ public class Vala.Class : Typesymbol {
                                is_error_base = true;
                        } else if (a.name == "Compact") {
                                is_compact = true;
+                       } else if (a.name == "Immutable") {
+                               is_immutable = true;
                        }
                }
        }
index c6a47202652f5c57336c7e9a0066256db3033cd2..85cb01e572c27fd6fc3c1d6c43b42c021437b5e0 100644 (file)
@@ -545,6 +545,7 @@ public enum UnicodeBreakType {
 }
 
 [Compact]
+[Immutable]
 [CCode (cname = "char", const_cname = "const char", copy_function = "g_strdup", free_function = "g_free", cheader_filename = "stdlib.h,string.h,glib.h", type_id = "G_TYPE_STRING", marshaller_type_name = "STRING", get_value_function = "g_value_get_string", set_value_function = "g_value_set_string", type_signature = "s")]
 public class string {
        [CCode (cname = "strstr")]