]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Only use const for immutable structs
authorJürg Billeter <j@bitron.ch>
Sun, 27 Sep 2009 14:49:31 +0000 (16:49 +0200)
committerJürg Billeter <j@bitron.ch>
Sun, 27 Sep 2009 14:49:31 +0000 (16:49 +0200)
codegen/valaccodemethodmodule.vala
vala/valaclass.vala
vala/valacodewriter.vala
vala/valastruct.vala
vapigen/valagidlparser.vala

index bed3273b77e95ae6c33f8fc5e3d920cf8e697bca..aa2c1fe4b30224a416b1dcdffc244546c8b3b75d 100644 (file)
@@ -743,7 +743,7 @@ internal class Vala.CCodeMethodModule : CCodeStructModule {
                        if (param.parameter_type.data_type is Struct) {
                                var st = (Struct) param.parameter_type.data_type;
                                if (!st.is_simple_type () && param.direction == ParameterDirection.IN) {
-                                       if (st.use_const && !param.parameter_type.value_owned) {
+                                       if (st.is_immutable && !param.parameter_type.value_owned) {
                                                ctypename = "const " + ctypename;
                                        }
 
index bf4105e5d38c9d7ae3934c68875b9db88e3b4a9f..c04ce0a7bf8b3b8c445e1f6fe6f8d9e0295d0f80 100644 (file)
@@ -110,7 +110,7 @@ public class Vala.Class : ObjectTypeSymbol {
        public bool free_function_address_of { get; private set; }
 
        private string cname;
-       private string const_cname;
+       public string const_cname { get; set; }
        private string lower_case_cprefix;
        private string lower_case_csuffix;
        private string type_id;
@@ -601,7 +601,7 @@ public class Vala.Class : ObjectTypeSymbol {
        public void set_cname (string cname) {
                this.cname = cname;
        }
-       
+
        private string get_lower_case_csuffix () {
                if (lower_case_csuffix == null) {
                        lower_case_csuffix = camel_case_to_lower_case (name);
index cf6a68281ad725c1a466578e787dda06c0e0ae56..21a40da5d0443fa08af7d7171c33e93d7fe1c7c9 100644 (file)
@@ -190,6 +190,9 @@ public class Vala.CodeWriter : CodeVisitor {
                if (cl.get_cname () != cl.get_default_cname ()) {
                        write_string ("cname = \"%s\", ".printf (cl.get_cname ()));
                }
+               if (cl.const_cname != null) {
+                       write_string ("const_cname = \"%s\", ".printf (cl.const_cname));
+               }
 
                if (cl.type_check_function != null) {
                        write_string ("type_check_function = \"%s\", ".printf (cl.type_check_function ));
@@ -304,6 +307,12 @@ public class Vala.CodeWriter : CodeVisitor {
                        return;
                }
                
+               if (st.is_immutable) {
+                       write_indent ();
+                       write_string ("[Immutable]");
+                       write_newline ();
+               }
+
                write_indent ();
 
                write_string ("[CCode (");
@@ -316,10 +325,6 @@ public class Vala.CodeWriter : CodeVisitor {
                        write_string ("type_id = \"%s\", ".printf (st.get_type_id ()));
                }
 
-                if (!st.use_const) {
-                        write_string ("use_const = false, ");
-                }
-
                 if (!st.has_copy_function) {
                         write_string ("has_copy_function = false, ");
                 }
index 95e8bf00c23bd8c3234f7f9ddd14eff3c5611fb7..0d0d2ed94740e86270521890f9958e3696278118 100644 (file)
@@ -85,7 +85,7 @@ public class Vala.Struct : TypeSymbol {
         * Specifies if 'const' should be emitted for input parameters
         * of this type.
         */
-       public bool use_const { get; set; default = true; }
+       public bool is_immutable { get; set; }
 
        /**
         * Specifies whether this struct has a registered GType.
@@ -450,9 +450,6 @@ public class Vala.Struct : TypeSymbol {
                if (a.has_argument ("has_destroy_function")) {
                        has_destroy_function = a.get_bool ("has_destroy_function");
                }
-               if (a.has_argument ("use_const")) {
-                       use_const = a.get_bool ("use_const");
-               }
        }
 
        private void process_boolean_type_attribute (Attribute a) {
@@ -495,6 +492,8 @@ public class Vala.Struct : TypeSymbol {
                                process_integer_type_attribute (a);
                        } else if (a.name == "FloatingType") {
                                process_floating_type_attribute (a);
+                       } else if (a.name == "Immutable") {
+                               is_immutable = true;
                        }
                }
        }
index 6cb068f23fdd8e7ca88bf6a2f3efc25f2cbd84dc..f133bf69e7c2ddbad0b8fb4a5716955cb98af310 100644 (file)
@@ -430,9 +430,9 @@ public class Vala.GIdlParser : CodeVisitor {
                                                        if (eval (nv[1]) == "1") {
                                                                st.set_simple_type (true);
                                                        }
-                                               } else if (nv[0] == "use_const") {
-                                                       if (eval (nv[1]) == "0") {
-                                                               st.use_const = false;
+                                               } else if (nv[0] == "immutable") {
+                                                       if (eval (nv[1]) == "1") {
+                                                               st.is_immutable = true;
                                                        }
                                                } else if (nv[0] == "has_type_id") {
                                                        if (eval (nv[1]) == "0") {
@@ -504,6 +504,8 @@ public class Vala.GIdlParser : CodeVisitor {
                                                        if (eval (nv[1]) == "1") {
                                                                cl.is_immutable = true;
                                                        }
+                                               } else if (nv[0] == "const_cname") {
+                                                       cl.const_cname = eval (nv[1]);
                                                } else if (nv[0] == "is_fundamental") {
                                                        if (eval (nv[1]) == "1") {
                                                                cl.is_compact = false;
@@ -735,9 +737,9 @@ public class Vala.GIdlParser : CodeVisitor {
                                                var nv = attr.split ("=", 2);
                                                if (nv[0] == "cheader_filename") {
                                                        st.add_cheader_filename (eval (nv[1]));
-                                               } else if (nv[0] == "use_const") {
-                                                       if (eval (nv[1]) == "0") {
-                                                               st.use_const = false;
+                                               } else if (nv[0] == "immutable") {
+                                                       if (eval (nv[1]) == "1") {
+                                                               st.is_immutable = true;
                                                        }
                                                } else if (nv[0] == "has_copy_function") {
                                                        if (eval (nv[1]) == "0") {
@@ -790,6 +792,8 @@ public class Vala.GIdlParser : CodeVisitor {
                                                        if (eval (nv[1]) == "1") {
                                                                cl.is_immutable = true;
                                                        }
+                                               } else if (nv[0] == "const_cname") {
+                                                       cl.const_cname = eval (nv[1]);
                                                }
                                        }
                                }