From: Raffaele Sandrini Date: Sat, 23 Feb 2008 15:15:46 +0000 (+0000) Subject: allow any error type to be cast implicitly to GLib.Error declare X-Git-Tag: VALA_0_1_7~56 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=87fdb81e52e648c8190d9ab9cd00a0bd57f5933f;p=platform%2Fupstream%2Fvala.git allow any error type to be cast implicitly to GLib.Error declare 2008-02-23 Raffaele Sandrini * 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 --- diff --git a/ChangeLog b/ChangeLog index 2a53d64..9b5ba8b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2008-02-23 Raffaele Sandrini + + * 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 * vala/valasemanticanalyzer.vala: visit child nodes of object diff --git a/vala/valaclass.vala b/vala/valaclass.vala index 8a186ac..5f49032 100644 --- a/vala/valaclass.vala +++ b/vala/valaclass.vala @@ -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; } } } diff --git a/vala/valaerrortype.vala b/vala/valaerrortype.vala index 8fefb2d..3244e1b 100644 --- a/vala/valaerrortype.vala +++ b/vala/valaerrortype.vala @@ -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); + } } diff --git a/vala/valasymbolresolver.vala b/vala/valasymbolresolver.vala index d778d50..c758ff1 100644 --- a/vala/valasymbolresolver.vala +++ b/vala/valasymbolresolver.vala @@ -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; } diff --git a/vapi/glib-2.0.vapi b/vapi/glib-2.0.vapi index e03d9e2..9776bab 100644 --- a/vapi/glib-2.0.vapi +++ b/vapi/glib-2.0.vapi @@ -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, ...);