allow any error type to be cast implicitly to GLib.Error declare
authorRaffaele Sandrini <raffaele@sandrini.ch>
Sat, 23 Feb 2008 15:15:46 +0000 (15:15 +0000)
committerRaffaele Sandrini <rasa@src.gnome.org>
Sat, 23 Feb 2008 15:15:46 +0000 (15:15 +0000)
2008-02-23  Raffaele Sandrini  <raffaele@sandrini.ch>

* vala/valaclass.vala, vala/valaerrortype.vala,
  vala/valasymbolresolver.vala: allow any error type to be cast
  implicitly to GLib.Error
* vapi/glib-2.0.vapi: declare GLib.Error as ErrorBase, random fixes

svn path=/trunk/; revision=1035

ChangeLog
vala/valaclass.vala
vala/valaerrortype.vala
vala/valasymbolresolver.vala
vapi/glib-2.0.vapi

index 2a53d64..9b5ba8b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2008-02-23  Raffaele Sandrini  <raffaele@sandrini.ch>
+
+       * vala/valaclass.vala, vala/valaerrortype.vala,
+         vala/valasymbolresolver.vala: allow any error type to be cast
+         implicitly to GLib.Error
+       * vapi/glib-2.0.vapi: declare GLib.Error as ErrorBase, random fixes
+
 2008-02-23  Jürg Billeter  <j@bitron.ch>
 
        * vala/valasemanticanalyzer.vala: visit child nodes of object
index 8a186ac..5f49032 100644 (file)
@@ -97,7 +97,12 @@ public class Vala.Class : Typesymbol {
         * Specifies the instance destructor.
         */
        public Destructor destructor { get; set; }
-       
+
+       /**
+        * Specifies whether this class denotes an error base.
+        */
+       public bool is_error_base { get; set ; }
+
        /**
         * Creates a new class.
         *
@@ -487,6 +492,8 @@ public class Vala.Class : Typesymbol {
                foreach (Attribute a in attributes) {
                        if (a.name == "CCode") {
                                process_ccode_attribute (a);
+                       } else if (a.name == "ErrorBase") {
+                               is_error_base = true;
                        }
                }
        }
index 8fefb2d..3244e1b 100644 (file)
@@ -35,4 +35,33 @@ public class Vala.ErrorType : ReferenceType {
                this.error_domain = error_domain;
                this.data_type = error_domain;
        }
+
+       public override bool compatible (DataType! target_type, bool enable_non_null = true) {
+               var et = target_type as ErrorType;
+
+               /* error types are only compatible to error types */
+               if (et == null) {
+                       return false;
+               }
+
+               /* every error type is compatible to the base error type */
+               if (et.error_domain == null) {
+                       return true;
+               }
+
+               /* otherwhise the error_domain has to be equal */
+               return et.error_domain == error_domain;
+       }
+
+       public override string to_string () {
+               if (error_domain == null) {
+                       return "GLib.error";
+               } else {
+                       return error_domain.get_full_name ();
+               }
+       }
+
+       public override DataType copy () {
+               return new ErrorType (error_domain);
+       }
 }
index d778d50..c758ff1 100644 (file)
@@ -313,6 +313,11 @@ public class Vala.SymbolResolver : CodeVisitor {
                        }
                }
 
+               /* check whether this type resolved to a ErrorBase class */
+               if (type.data_type is Class && ((Class)type.data_type).is_error_base) {
+                       type = new ErrorType (null);
+               }
+
                return type;
        }
 
index e03d9e2..9776bab 100644 (file)
@@ -586,6 +586,8 @@ public class string {
        
        [CCode (cname = "atoi")]
        public int to_int ();
+       [CCode (cname = "atol")]
+       public long to_long ();
        [CCode (cname = "strtod")]
        public double to_double (out string endptr = null);
        [CCode (cname = "strtoul")]
@@ -1096,6 +1098,7 @@ namespace GLib {
                public static bool remove_by_data (pointer data);
        }
 
+       [SimpleType]
        [CCode (default_value = "0")]
        public struct Pid {
        }
@@ -1188,14 +1191,14 @@ namespace GLib {
        public class Thread {
                public static void init (ThreadFunctions vtable = null);
                public static bool supported ();
-               public static weak Thread create (ThreadFunc func, pointer data, bool joinable) throws ThreadError;
-               public static weak Thread create_full (ThreadFunc func, pointer data, ulong stack_size, bool joinable, bool bound, ThreadPriority priority) throws ThreadError;
+               public static weak Thread create (ThreadFunc func, bool joinable) throws ThreadError;
+               public static weak Thread create_full (ThreadFunc func, ulong stack_size, bool joinable, bool bound, ThreadPriority priority) throws ThreadError;
                public static weak Thread self ();
                public pointer join ();
                public void set_priority (ThreadPriority priority);
                public static void yield ();
                public static void exit (pointer retval);
-               public static void @foreach (Func thread_func, pointer user_data);
+               public static void @foreach (Func thread_func);
                
                [CCode (cname = "g_usleep")]
                public static void usleep (ulong microseconds);
@@ -1367,6 +1370,7 @@ namespace GLib {
 
        /* Error Reporting */
 
+       [ErrorBase]
        [CCode (copy_function = "g_error_copy", free_function = "g_error_free")]
        public class Error {
                public Error (Quark domain, int code, string! format, ...);