Support custom cname for structs in InterfaceWriter
authorJuerg Billeter <j@bitron.ch>
Sat, 3 May 2008 12:04:49 +0000 (12:04 +0000)
committerJürg Billeter <juergbi@src.gnome.org>
Sat, 3 May 2008 12:04:49 +0000 (12:04 +0000)
2008-05-03  Juerg Billeter  <j@bitron.ch>

* vala/valainterfacewriter.vala:
* vala/valastruct.vala:

Support custom cname for structs in InterfaceWriter

svn path=/trunk/; revision=1338

ChangeLog
vala/valainterfacewriter.vala
vala/valastruct.vala

index 54d9e14..8ef609d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2008-05-03  Jürg Billeter  <j@bitron.ch>
+
+       * vala/valainterfacewriter.vala:
+       * vala/valastruct.vala:
+
+       Support custom cname for structs in InterfaceWriter
+
 2008-05-02  Jürg Billeter  <j@bitron.ch>
 
        * vala/valastruct.vala: inherit integer_type and floating_type,
index ebc79fe..2f1cf1f 100644 (file)
@@ -188,6 +188,12 @@ public class Vala.InterfaceWriter : CodeVisitor {
                
                write_indent ();
 
+               write_string ("[CCode (");
+
+               if (st.get_cname () != st.get_default_cname ()) {
+                       write_string ("cname = \"%s\", ".printf (st.get_cname ()));
+               }
+
                var first = true;
                string cheaders;
                foreach (string cheader in st.get_cheader_filenames ()) {
@@ -198,7 +204,7 @@ public class Vala.InterfaceWriter : CodeVisitor {
                                cheaders = "%s,%s".printf (cheaders, cheader);
                        }
                }
-               write_string ("[CCode (cheader_filename = \"%s\")]".printf (cheaders));
+               write_string ("cheader_filename = \"%s\")]".printf (cheaders));
                write_newline ();
 
                if (st.is_simple_type ()) {
index 49b9a62..8b13fb9 100644 (file)
@@ -186,11 +186,20 @@ public class Vala.Struct : Typesymbol {
                }
                
                if (cname == null) {
-                       cname = "%s%s".printf (parent_symbol.get_cprefix (), name);
+                       cname = get_default_cname ();
                }
                return cname;
        }
-       
+
+       /**
+        * Returns the default name of this struct as it is used in C code.
+        *
+        * @return the name to be used in C code by default
+        */
+       public string get_default_cname () {
+               return "%s%s".printf (parent_symbol.get_cprefix (), name);
+       }
+
        private void set_cname (string cname) {
                this.cname = cname;
        }