Add [CCode (type_check_function = "BLAH_IS_FOO")] for classes.
authorJared Moore <jaredm@svn.gnome.org>
Wed, 23 Jul 2008 09:28:04 +0000 (09:28 +0000)
committerJared William Moore <jaredm@src.gnome.org>
Wed, 23 Jul 2008 09:28:04 +0000 (09:28 +0000)
2008-07-23  Jared Moore  <jaredm@svn.gnome.org>

* vala/valainterfacewriter.vala:
* vala/valaclass.vala:
* gobject/valaccodeinterfacebinding.vala:
* gobject/valaccodeclassbinding.vala:
* gobject/valaccodegenerator.vala:

Add [CCode (type_check_function = "BLAH_IS_FOO")] for classes.

* vapigen/valagidlparser.vala:

Add type_check_function metadata.

* vapi/packages/gnome-vfs-2.0/gnome-vfs-2.0.metadata:

Set type_check_function for GnomeVFSDrive, GnomeVFSVolume,
GnomeVFSVolumeMonitor, fixes bug 543693.

* vapi/gnome-vfs-2.0.vapi: regenerated

svn path=/trunk/; revision=1726

ChangeLog
gobject/valaccodeclassbinding.vala
gobject/valaccodegenerator.vala
gobject/valaccodeinterfacebinding.vala
vala/valaclass.vala
vala/valainterfacewriter.vala
vapi/gnome-vfs-2.0.vapi
vapi/packages/gnome-vfs-2.0/gnome-vfs-2.0.metadata
vapigen/valagidlparser.vala

index 5ff6950..647069a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,24 @@
+2008-07-23  Jared Moore  <jaredm@svn.gnome.org>
+
+       * vala/valainterfacewriter.vala:
+       * vala/valaclass.vala:
+       * gobject/valaccodeinterfacebinding.vala:
+       * gobject/valaccodeclassbinding.vala:
+       * gobject/valaccodegenerator.vala: 
+
+       Add [CCode (type_check_function = "BLAH_IS_FOO")] for classes.
+
+       * vapigen/valagidlparser.vala:
+
+       Add type_check_function metadata.
+
+       * vapi/packages/gnome-vfs-2.0/gnome-vfs-2.0.metadata:
+
+       Set type_check_function for GnomeVFSDrive, GnomeVFSVolume,
+       GnomeVFSVolumeMonitor, fixes bug 543693.
+
+       * vapi/gnome-vfs-2.0.vapi: regenerated
+
 2008-07-22  Jürg Billeter  <j@bitron.ch>
 
        * vapi/glib-2.0.vapi:
index 472fb75..89d1dab 100644 (file)
@@ -89,10 +89,10 @@ public class Vala.CCodeClassBinding : CCodeObjectTypeSymbolBinding {
                        decl_frag.append (new CCodeMacroReplacement ("%s_CLASS(klass)".printf (cl.get_upper_case_cname (null)), macro));
 
                        macro = "(G_TYPE_CHECK_INSTANCE_TYPE ((obj), %s))".printf (cl.get_type_id ());
-                       decl_frag.append (new CCodeMacroReplacement ("%s(obj)".printf (cl.get_upper_case_cname ("IS_")), macro));
+                       decl_frag.append (new CCodeMacroReplacement ("%s(obj)".printf (codegen.get_type_check_function (cl)), macro));
 
                        macro = "(G_TYPE_CHECK_CLASS_TYPE ((klass), %s))".printf (cl.get_type_id ());
-                       decl_frag.append (new CCodeMacroReplacement ("%s_CLASS(klass)".printf (cl.get_upper_case_cname ("IS_")), macro));
+                       decl_frag.append (new CCodeMacroReplacement ("%s_CLASS(klass)".printf (codegen.get_type_check_function (cl)), macro));
 
                        macro = "(G_TYPE_INSTANCE_GET_CLASS ((obj), %s, %sClass))".printf (cl.get_type_id (), cl.get_cname ());
                        decl_frag.append (new CCodeMacroReplacement ("%s_GET_CLASS(obj)".printf (cl.get_upper_case_cname (null)), macro));
index 4cc8fa4..08b7ea4 100644 (file)
@@ -3506,8 +3506,17 @@ public class Vala.CCodeGenerator : CodeGenerator {
                expr.ccodenode = new CCodeBinaryExpression (op, cleft, cright);
        }
 
-       static CCodeFunctionCall create_type_check (CCodeNode ccodenode, TypeSymbol type) {
-               var ccheck = new CCodeFunctionCall (new CCodeIdentifier (type.get_upper_case_cname ("IS_")));
+       public string get_type_check_function (TypeSymbol type) {
+               var cl = type as Class;
+               if (cl != null && cl.type_check_function != null) {
+                       return cl.type_check_function;
+               } else {
+                       return type.get_upper_case_cname ("IS_");
+               }
+       }
+
+       CCodeFunctionCall create_type_check (CCodeNode ccodenode, TypeSymbol type) {
+               var ccheck = new CCodeFunctionCall (new CCodeIdentifier (get_type_check_function (type)));
                ccheck.add_argument ((CCodeExpression) ccodenode);
                return ccheck;
        }
@@ -4014,7 +4023,7 @@ public class Vala.CCodeGenerator : CodeGenerator {
                var ccheck = new CCodeFunctionCall ();
                
                if ((t is Class && ((Class) t).is_subtype_of (gobject_type)) || t is Interface) {
-                       var ctype_check = new CCodeFunctionCall (new CCodeIdentifier (t.get_upper_case_cname ("IS_")));
+                       var ctype_check = new CCodeFunctionCall (new CCodeIdentifier (get_type_check_function (t)));
                        ctype_check.add_argument (new CCodeIdentifier (var_name));
                        
                        CCodeExpression cexpr = ctype_check;
index 448967e..89f3359 100644 (file)
@@ -62,7 +62,7 @@ public class Vala.CCodeInterfaceBinding : CCodeObjectTypeSymbolBinding {
                        decl_frag.append (new CCodeMacroReplacement ("%s(obj)".printf (iface.get_upper_case_cname (null)), macro));
 
                        macro = "(G_TYPE_CHECK_INSTANCE_TYPE ((obj), %s))".printf (iface.get_type_id ());
-                       decl_frag.append (new CCodeMacroReplacement ("%s(obj)".printf (iface.get_upper_case_cname ("IS_")), macro));
+                       decl_frag.append (new CCodeMacroReplacement ("%s(obj)".printf (codegen.get_type_check_function (iface)), macro));
 
                        macro = "(G_TYPE_INSTANCE_GET_INTERFACE ((obj), %s, %s))".printf (iface.get_type_id (), iface.get_type_cname ());
                        decl_frag.append (new CCodeMacroReplacement ("%s_GET_INTERFACE(obj)".printf (iface.get_upper_case_cname (null)), macro));
index c7df296..7e5e23a 100644 (file)
@@ -77,6 +77,13 @@ public class Vala.Class : ObjectTypeSymbol {
        }
 
        /**
+        * The name of the function to use to check whether a value is an instance of
+        * this class. If this is null then the default type check function should be 
+        * used instead.
+        */
+       public string? type_check_function { get; set; }
+
+       /**
         * Specifies whether this class has private fields.
         */
        public bool has_private_fields { get; private set; }
@@ -570,6 +577,9 @@ public class Vala.Class : ObjectTypeSymbol {
                if (a.has_argument ("type_signature")) {
                        type_signature = a.get_string ("type_signature");
                }
+               if (a.has_argument ("type_check_function")) {
+                       type_check_function = a.get_string ("type_check_function");
+               }
        }
        
        /**
index 004c821..8851189 100644 (file)
@@ -137,6 +137,10 @@ public class Vala.InterfaceWriter : CodeVisitor {
                        write_string ("cname = \"%s\", ".printf (cl.get_cname ()));
                }
 
+               if (cl.type_check_function != null) {
+                       write_string ("type_check_function = \"%s\", ".printf (cl.type_check_function ));
+               }
+
                bool first = true;
                string cheaders;
                foreach (string cheader in cl.get_cheader_filenames ()) {
index 2289ce7..b5efa78 100644 (file)
@@ -734,7 +734,7 @@ namespace GnomeVFS {
        }
        [Compact]
        [CCode (cheader_filename = "libgnomevfs/gnome-vfs.h")]
-       public class Address : GLib.Boxed {
+       public class Address {
                public weak GnomeVFS.Address dup ();
                public bool equal (GnomeVFS.Address b);
                public int get_family_type ();
@@ -747,7 +747,7 @@ namespace GnomeVFS {
        }
        [Compact]
        [CCode (ref_function = "gnome_vfs_file_info_ref", unref_function = "gnome_vfs_file_info_unref", cheader_filename = "libgnomevfs/gnome-vfs.h")]
-       public class FileInfo : GLib.Boxed {
+       public class FileInfo {
                public weak string name;
                public GnomeVFS.FileInfoFields valid_fields;
                public GnomeVFS.FileType type;
@@ -784,11 +784,11 @@ namespace GnomeVFS {
        }
        [Compact]
        [CCode (cheader_filename = "libgnomevfs/gnome-vfs.h")]
-       public class GnomeVfsFindDirectoryResult : GLib.Boxed {
+       public class GnomeVfsFindDirectoryResult {
        }
        [Compact]
        [CCode (cheader_filename = "libgnomevfs/gnome-vfs.h")]
-       public class GnomeVfsGetFileInfoResult : GLib.Boxed {
+       public class GnomeVfsGetFileInfoResult {
        }
        [CCode (cheader_filename = "libgnomevfs/gnome-vfs.h")]
        public class ACE : GLib.Object {
@@ -832,7 +832,7 @@ namespace GnomeVFS {
                public void set (GnomeVFS.ACE ace);
                public void unset (GnomeVFS.ACE ace);
        }
-       [CCode (cheader_filename = "libgnomevfs/gnome-vfs.h")]
+       [CCode (type_check_function = "GNOME_IS_VFS_DRIVE", cheader_filename = "libgnomevfs/gnome-vfs.h")]
        public class Drive : GLib.Object {
                public int compare (GnomeVFS.Drive b);
                public void eject (GnomeVFS.VolumeOpCallback callback);
@@ -863,7 +863,7 @@ namespace GnomeVFS {
                public static weak GnomeVFS.MIMEMonitor get ();
                public virtual signal void data_changed ();
        }
-       [CCode (cheader_filename = "libgnomevfs/gnome-vfs.h")]
+       [CCode (type_check_function = "GNOME_IS_VFS_VOLUME", cheader_filename = "libgnomevfs/gnome-vfs.h")]
        public class Volume : GLib.Object {
                public int compare (GnomeVFS.Volume b);
                public void eject (GnomeVFS.VolumeOpCallback callback);
@@ -885,7 +885,7 @@ namespace GnomeVFS {
                public void unmount (GnomeVFS.VolumeOpCallback callback);
                public void unref ();
        }
-       [CCode (cheader_filename = "libgnomevfs/gnome-vfs.h")]
+       [CCode (type_check_function = "GNOME_IS_VFS_VOLUME_MONITOR", cheader_filename = "libgnomevfs/gnome-vfs.h")]
        public class VolumeMonitor : GLib.Object {
                public weak GLib.List get_connected_drives ();
                public weak GnomeVFS.Drive get_drive_by_id (ulong id);
index 0858cb9..b00c72c 100644 (file)
@@ -1,5 +1,8 @@
 GnomeVFS cheader_filename="libgnomevfs/gnome-vfs.h"
 gnome_vfs_address_new_from_sockaddr hidden="1"
+GnomeVFSDrive type_check_function="GNOME_IS_VFS_DRIVE"
 GnomeVFSFileInfo.device hidden="1"
 GnomeVFSMimeApplication.priv hidden="1"
 GnomeVFSMimeApplication.requires_terminal hidden="1"
+GnomeVFSVolume type_check_function="GNOME_IS_VFS_VOLUME"
+GnomeVFSVolumeMonitor type_check_function="GNOME_IS_VFS_VOLUME_MONITOR"
index a6529c3..dd8eb2a 100644 (file)
@@ -843,6 +843,8 @@ public class Vala.GIdlParser : CodeVisitor {
                                                if (eval (nv[1]) == "1") {
                                                        return;
                                                }
+                                       } else if (nv[0] == "type_check_function") {
+                                               cl.type_check_function = eval (nv[1]);
                                        } else if (nv[0] == "abstract") {
                                                if (eval (nv[1]) == "1") {
                                                        cl.is_abstract = true;