]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Add support for constant members inside enums
authorSebastian Dröge <sebastian.droege@collabora.co.uk>
Thu, 8 Apr 2010 08:14:26 +0000 (10:14 +0200)
committerJürg Billeter <j@bitron.ch>
Wed, 21 Apr 2010 11:47:18 +0000 (13:47 +0200)
vala/valacodewriter.vala
vala/valaenum.vala
vala/valaparser.vala

index 04b3d5f1d74e884817394f9f4f11038af4f3f393..8d5f1b385ab2ef0650efc6fe4626466a36e1f7e2 100644 (file)
@@ -526,7 +526,7 @@ public class Vala.CodeWriter : CodeVisitor {
                }
 
                if (!first) {
-                       if (en.get_methods ().size > 0) {
+                       if (en.get_methods ().size > 0 || en.get_constants ().size > 0) {
                                write_string (";");
                        }
                        write_newline ();
@@ -536,6 +536,9 @@ public class Vala.CodeWriter : CodeVisitor {
                foreach (Method m in en.get_methods ()) {
                        m.accept (this);
                }
+               foreach (Constant c in en.get_constants ()) {
+                       c.accept (this);
+               }
                current_scope = current_scope.parent_scope;
 
                write_end_block ();
index f5c21489bca20d236a3e98a4d4f2ff9344cb6434..407e88f6f95cec7ab4d9eb240d6f5672dbc72998 100644 (file)
@@ -38,6 +38,7 @@ public class Vala.Enum : TypeSymbol {
 
        private List<EnumValue> values = new ArrayList<EnumValue> ();
        private List<Method> methods = new ArrayList<Method> ();
+       private List<Constant> constants = new ArrayList<Constant> ();
        private string cname;
        private string cprefix;
        private string lower_case_cprefix;
@@ -90,6 +91,16 @@ public class Vala.Enum : TypeSymbol {
                scope.add (m.name, m);
        }
 
+       /**
+        * Adds the specified constant as a member to this enum.
+        *
+        * @param c a constant
+        */
+       public void add_constant (Constant c) {
+               constants.add (c);
+               scope.add (c.name, c);
+       }
+
        /**
         * Returns a copy of the list of enum values.
         *
@@ -108,6 +119,15 @@ public class Vala.Enum : TypeSymbol {
                return methods;
        }
 
+       /**
+        * Returns a copy of the list of constants.
+        *
+        * @return list of constants
+        */
+       public List<Constant> get_constants () {
+               return constants;
+       }
+
        public override void accept (CodeVisitor visitor) {
                visitor.visit_enum (this);
        }
@@ -120,6 +140,10 @@ public class Vala.Enum : TypeSymbol {
                foreach (Method m in methods) {
                        m.accept (visitor);
                }
+
+               foreach (Constant c in constants) {
+                       c.accept (visitor);
+               }
        }
 
        public override string get_cname (bool const_type = false) {
@@ -312,6 +336,10 @@ public class Vala.Enum : TypeSymbol {
                        m.check (analyzer);
                }
 
+               foreach (Constant c in constants) {
+                       c.check (analyzer);
+               }
+
                analyzer.current_source_file = old_source_file;
                analyzer.current_symbol = old_symbol;
 
index 15ae81b96983bd15dc847a9924ef266abfb9886c..23d4b0fb4775102513376fac6e521449400b4d6f 100644 (file)
@@ -2943,6 +2943,8 @@ public class Vala.Parser : CodeVisitor {
                                var member_sym = parse_declaration ();
                                if (member_sym is Method) {
                                        en.add_method ((Method) member_sym);
+                               } else if (member_sym is Constant) {
+                                       en.add_constant ((Constant) member_sym);
                                } else {
                                        Report.error (member_sym.source_reference, "unexpected declaration in enum");
                                }