]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codewriter: Write enum cname when it differs from the default cname
authorLuca Bruno <lucabru@src.gnome.org>
Mon, 4 Apr 2011 19:53:45 +0000 (21:53 +0200)
committerJürg Billeter <j@bitron.ch>
Sun, 29 May 2011 08:12:09 +0000 (10:12 +0200)
Based on patch by Evan Nemerson.

Fixes bug 615493.

vala/valacodewriter.vala
vala/valaenum.vala

index dbbd516f45f669930592aa8d282319fd7eb82fb6..3eafe22e9e12bde042a25e558b672e6ee0e3de00 100644 (file)
@@ -591,6 +591,10 @@ public class Vala.CodeWriter : CodeVisitor {
                        write_string ("has_type_id = false, ");
                }
 
+               if (en.get_cname () != en.get_default_cname ()) {
+                       write_string ("cname = \"%s\", ".printf (en.get_cname ()));
+               }
+
                write_string ("cheader_filename = \"%s\")]".printf (get_cheaders(en)));
 
                if (en.is_flags) {
index f5fca292f68d6e3c4f07afd71f3baa56524a1eea..fed3286fe4dea24c069e7121b851daf593daac99 100644 (file)
@@ -160,12 +160,21 @@ public class Vala.Enum : TypeSymbol {
                                cname = attr.get_string ("cname");
                        }
                        if (cname == null) {
-                               cname = "%s%s".printf (parent_symbol.get_cprefix (), name);
+                               cname = get_default_cname ();
                        }
                }
                return cname;
        }
 
+       /**
+        * Returns the default name of this enum 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);
+       }
+
        public void set_cname (string cname) {
                this.cname = cname;
        }