]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
distinguish between ref_function/unref_function and
authorJürg Billeter <j@bitron.ch>
Thu, 29 Jun 2006 21:22:17 +0000 (21:22 +0000)
committerJürg Billeter <juergbi@src.gnome.org>
Thu, 29 Jun 2006 21:22:17 +0000 (21:22 +0000)
2006-06-29  Jürg Billeter  <j@bitron.ch>

* vala/valacodegenerator.vala, vala/valaclass.vala,
  vala/valadatatype.vala, vala/valastruct.vala: distinguish between
  ref_function/unref_function and dup_function/free_function
* vala/valadatatype.vala: add interface documentation
* vapi/glib-2.0.vala: use dup_function attribute, keep ref_function for
  compatibility

svn path=/trunk/; revision=57

vala/ChangeLog
vala/vala/valaclass.vala
vala/vala/valacodegenerator.vala
vala/vala/valadatatype.vala
vala/vala/valastruct.vala
vala/vapi/glib-2.0.vala

index e549005346855d745abeb5a5fa1e731fd9f9671d..951cf3c57e4c964988817ccd0d9fd0a74c89a84f 100644 (file)
@@ -1,3 +1,12 @@
+2006-06-29  Jürg Billeter  <j@bitron.ch>
+
+       * vala/valacodegenerator.vala, vala/valaclass.vala,
+         vala/valadatatype.vala, vala/valastruct.vala: distinguish between
+         ref_function/unref_function and dup_function/free_function
+       * vala/valadatatype.vala: add interface documentation
+       * vapi/glib-2.0.vala: use dup_function attribute, keep ref_function for
+         compatibility
+
 2006-06-29  Jürg Billeter  <j@bitron.ch>
 
        * vala/valacodenode.vala, vala/valaexpression.vala: add interface
index e9267d96d582873883cced137da958417057e4e2..f02f0e0ac9ce9752f3aff1a1e11f7251091321ac 100644 (file)
@@ -221,7 +221,7 @@ namespace Vala {
                        return "g_object_ref";
                }
                
-               public override string get_free_function () {
+               public override string get_unref_function () {
                        return "g_object_unref";
                }
        }
index bd3eb34b53694e386f445e45112a9d474652770d..05acccaa8d9686fdcfa029a829f842fb6d34051e 100644 (file)
@@ -1039,17 +1039,23 @@ namespace Vala {
 
                        var cisnull = new CCodeBinaryExpression (operator = CCodeBinaryOperator.EQUALITY, left = cvar, right = new CCodeConstant (name = "NULL"));
 
-                       var free_func = type.type.get_free_function ();
+                       string unref_function;
+                       if (type.type.is_reference_counting ()) {
+                               unref_function = type.type.get_unref_function ();
+                       } else {
+                               unref_function = type.type.get_free_function ();
+                       }
+               
                        if (type.array && type.type.name == "string") {
-                               free_func = "g_strfreev";
+                               unref_function = "g_strfreev";
                        }
-                       var ccall = new CCodeFunctionCall (call = new CCodeIdentifier (name = free_func));
+                       var ccall = new CCodeFunctionCall (call = new CCodeIdentifier (name = unref_function));
                        ccall.add_argument (cvar);
                        
                        /* set freed references to NULL to prevent further use */
                        var ccomma = new CCodeCommaExpression ();
                        
-                       if (free_func == "g_list_free") {
+                       if (unref_function == "g_list_free") {
                                bool is_ref = false;
                                bool is_class = false;
                                var type_args = type.get_type_arguments ();
@@ -1069,7 +1075,7 @@ namespace Vala {
                                        cunrefcall.add_argument (new CCodeConstant (name = "NULL"));
                                        ccomma.inner.append (cunrefcall);
                                }
-                       } else if (free_func == "g_string_free") {
+                       } else if (unref_function == "g_string_free") {
                                ccall.add_argument (new CCodeConstant (name = "TRUE"));
                        }
                        
@@ -1630,8 +1636,15 @@ namespace Vala {
                        var ctemp = new CCodeIdentifier (name = decl.name);
                        
                        var cisnull = new CCodeBinaryExpression (operator = CCodeBinaryOperator.EQUALITY, left = ctemp, right = new CCodeConstant (name = "NULL"));
+                       
+                       string ref_function;
+                       if (expr.static_type.type.is_reference_counting ()) {
+                               ref_function = expr.static_type.type.get_ref_function ();
+                       } else {
+                               ref_function = expr.static_type.type.get_dup_function ();
+                       }
                
-                       var ccall = new CCodeFunctionCall (call = new CCodeIdentifier (name = expr.static_type.type.get_ref_function ()));
+                       var ccall = new CCodeFunctionCall (call = new CCodeIdentifier (name = ref_function));
                        ccall.add_argument (ctemp);
                        
                        var ccomma = new CCodeCommaExpression ();
index 9c5b1a482f5d9b03873e1f1e3fbe35178b7b8395..47b822e145d7dfbca60f2ae206bc7d8d8c47bcd9 100644 (file)
 using GLib;
 
 namespace Vala {
+       /**
+        * Represents a runtime data type. This data type may be defined in Vala
+        * source code or imported from an external library with a Vala API
+        * file.
+        */
        public abstract class DataType : CodeNode {
+               /**
+                * The symbol name of this data type.
+                */
                public string! name { get; set construct; }
-               public weak Namespace @namespace;
+               
+               /**
+                * Specifies the accessibility of the class. Public
+                * accessibility doesn't limit access. Default accessibility
+                * limits access to this program or library. Protected and
+                * private accessibility is not supported for types.
+                */
                public MemberAccessibility access;
+               
+               /**
+                * The namespace containing this data type.
+                */
+               public weak Namespace @namespace;
 
+               /**
+                * Returns the name of this data type as it is used in C code.
+                *
+                * @return the name to be used in C code
+                */
                public abstract string get_cname ();
-               public abstract bool is_reference_type ();
-               public abstract bool is_reference_counting ();
-               public abstract string get_ref_function ();
-               public abstract string get_free_function ();
-               public abstract string get_type_id ();
                
-               public abstract ref string get_upper_case_cname (string infix);
-               public abstract ref string get_lower_case_cname (string infix);
+               /**
+                * Checks whether this data type has value or reference type
+                * semantics.
+                *
+                * @return true if this data type has reference type semantics
+                */
+               public virtual bool is_reference_type () {
+                       return false;
+               }
                
-               private List<string> cheader_filenames;
+               /**
+                * Returns the C function name that duplicates instances of this
+                * data type. The specified C function must accept one argument
+                * referencing the instance of this data type and return a
+                * reference to the duplicate.
+                *
+                * @return the name of the C function if supported or null
+                *         otherwise
+                */
+               public virtual string get_dup_function () {
+                       return null;
+               }
+               
+               /**
+                * Returns the C function name that frees instances of this
+                * data type. This is only valid for data types with reference
+                * type semantics that do not support reference counting. The
+                * specified C function must accept one argument pointing to the
+                * instance to be freed.
+                *
+                * @return the name of the C function or null if this data type
+                *         is not a reference type or if it supports reference
+                *         counting
+                */
+               public virtual string get_free_function () {
+                       return null;
+               }
+               
+               /**
+                * Checks whether this data type supports reference counting.
+                * This is only valid for reference types.
+                *
+                * @return true if this data type supports reference counting
+                */
+               public virtual bool is_reference_counting () {
+                       return false;
+               }
+               
+               /**
+                * Returns the C function name that increments the reference
+                * count of instances of this data type. This is only valid for
+                * data types supporting reference counting. The specified C
+                * function must accept one argument referencing the instance of
+                * this data type and return the reference.
+                *
+                * @return the name of the C function or null if this data type
+                *         does not support reference counting
+                */
+               public virtual string get_ref_function () {
+                       return null;
+               }
+               
+               /**
+                * Returns the C function name that decrements the reference
+                * count of instances of this data type. This is only valid for
+                * data types supporting reference counting. The specified C
+                * function must accept one argument referencing the instance of
+                * this data type.
+                *
+                * @return the name of the C function or null if this data type
+                *         does not support reference counting
+                */
+               public virtual string get_unref_function () {
+                       return null;
+               }
+               
+               /**
+                * Returns the C symbol representing the runtime type id for
+                * this data type. The specified symbol must express a
+                * registered GType.
+                *
+                * @return the name of the GType name in C code or null if this
+                *         data type is not registered with GType
+                */
+               public virtual string get_type_id () {
+                       return null;
+               }
+               
+               /**
+                * Returns the C name of this data type in upper case. Words are
+                * separated by underscores. The upper case C name of the
+                * namespace is prefix of the result.
+                *
+                * @param infix a string to be placed between namespace and
+                *              data type name or null
+                * @return      the upper case name to be used in C code
+                */
+               public abstract ref string! get_upper_case_cname (string infix);
+               
+               /**
+                * Returns the C name of this data type in lower case. Words are
+                * separated by underscores. The lower case C name of the
+                * namespace is prefix of the result.
+                *
+                * @param infix a string to be placed between namespace and
+                *              data type name or null
+                * @return      the lower case name to be used in C code
+                */
+               public abstract ref string! get_lower_case_cname (string infix);
+               
+               /**
+                * Returns a list of C header filenames users of this data type
+                * must include.
+                *
+                * @return list of C header filenames for this data type
+                */
                public ref List<string> get_cheader_filenames () {
                        if (cheader_filenames == null) {
                                /* default to header filenames of the namespace */
@@ -48,9 +179,17 @@ namespace Vala {
                        }
                        return cheader_filenames.copy ();
                }
-               
+
+               /**
+                * Adds a filename to the list of C header filenames users of
+                * this data type must include.
+                *
+                * @param filename a C header filename
+                */
                public void add_cheader_filename (string! filename) {
                        cheader_filenames.append (filename);
                }
+
+               private List<string> cheader_filenames;
        }
 }
index 4d21ba0bc40810e6cc16cf76fa9749d98b757d64..ef8d40ffd953f47a5c010381eb73b16a925b924b 100644 (file)
@@ -29,11 +29,11 @@ namespace Vala {
                List<Field> fields;
                List<Method> methods;
                
-               public string cname;
-               public string ref_function;
-               public string free_function;
-               public string type_id;
-               public string lower_case_csuffix;
+               string cname;
+               string dup_function;
+               string free_function;
+               string type_id;
+               string lower_case_csuffix;
                bool reference_type;
                
                public static ref Struct new (string! name, SourceReference source) {
@@ -154,12 +154,12 @@ namespace Vala {
                private void process_ref_type_attribute (Attribute! a) {
                        reference_type = true;
                        foreach (NamedArgument arg in a.args) {
-                               if (arg.name == "ref_function") {
+                               if (arg.name == "dup_function") {
                                        /* this will already be checked during semantic analysis */
                                        if (arg.argument is LiteralExpression) {
                                                var lit = ((LiteralExpression) arg.argument).literal;
                                                if (lit is StringLiteral) {
-                                                       set_ref_function (((StringLiteral) lit).eval ());
+                                                       set_dup_function (((StringLiteral) lit).eval ());
                                                }
                                        }
                                } else if (arg.name == "free_function") {
@@ -196,15 +196,15 @@ namespace Vala {
                        return false;
                }
                
-               public override string get_ref_function () {
-                       if (ref_function == null) {
+               public override string get_dup_function () {
+                       if (dup_function == null) {
                                Report.error (source_reference, "The type `%s` doesn't contain a copy function".printf (symbol.get_full_name ()));
                        }
-                       return ref_function;
+                       return dup_function;
                }
                
-               public void set_ref_function (string! name) {
-                       this.ref_function = name;
+               public void set_dup_function (string! name) {
+                       this.dup_function = name;
                }
                
                public override string get_free_function () {
index 6ac45abf868b10604c84fa865f1058942dd4da7e..9bf68abcb9ed95421b2e255bfd14c312f3055c5b 100644 (file)
@@ -112,7 +112,7 @@ public struct unichar {
        public unichar tolower ();
 }
 
-[ReferenceType (ref_function = "g_strdup", free_function = "g_free", type_id = "G_TYPE_STRING")]
+[ReferenceType (dup_function = "g_strdup", free_function = "g_free", type_id = "G_TYPE_STRING", ref_function = "g_strdup")]
 [CCode (cname = "char", cheader_filename = "string.h,glib.h")]
 public struct string {
        [CCode (cname = "g_str_has_suffix")]
@@ -295,7 +295,7 @@ namespace GLib {
                string arg_description;
        }
        
-       [ReferenceType (ref_function = "g_list_copy", free_function = "g_list_free")]
+       [ReferenceType (dup_function = "g_list_copy", free_function = "g_list_free", ref_function = "g_list_copy")]
        public struct List<G> {
                [ReturnsModifiedPointer ()]
                public void append (ref G data);
@@ -343,7 +343,7 @@ namespace GLib {
        [CCode (cname = "strcmp")]
        public static GLib.CompareFunc strcmp;
        
-       [ReferenceType (ref_function = "g_hash_table_ref", free_function = "g_hash_table_unref")]
+       [ReferenceType (dup_function = "g_hash_table_ref", free_function = "g_hash_table_unref", ref_function = "g_hash_table_ref")]
        public struct HashTable<K,V> {
                public static ref HashTable new (HashFunc hash_func, EqualFunc key_equal_func);
                public static ref HashTable new_full (HashFunc hash_func, EqualFunc key_equal_func, DestroyNotify key_destroy_func, DestroyNotify value_destroy_func);