]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
ccode: Allow adding of comments to a CCodeStruct
authorRico Tzschichholz <ricotz@ubuntu.com>
Wed, 17 Jan 2018 11:55:59 +0000 (12:55 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Thu, 12 Jul 2018 07:26:20 +0000 (09:26 +0200)
See https://gitlab.gnome.org/GNOME/vala/issues/598

ccode/valaccodestruct.vala

index 50af6a2bf0e479b9355dd4a06b0ad646445766e8..93bfe044ea046a5159fc4313c1837b4a108a9631 100644 (file)
@@ -31,21 +31,31 @@ public class Vala.CCodeStruct : CCodeNode {
         */
        public string name { get; set; }
 
-       public bool is_empty { get { return declarations.size == 0; } }
+       public bool is_empty { get { return nodes.size == 0; } }
 
-       private List<CCodeDeclaration> declarations = new ArrayList<CCodeDeclaration> ();
+       private List<CCodeNode> nodes = new ArrayList<CCodeNode> ();
 
        public CCodeStruct (string name) {
                this.name = name;
        }
 
+       /**
+        * Adds the specified comment inside this struct.
+        *
+        * @param comment a string comment
+        */
+       public void add_comment (string comment) {
+               var c = new CCodeComment (comment);
+               nodes.add (c);
+       }
+
        /**
         * Adds the specified declaration as member to this struct.
         *
         * @param decl a variable declaration
         */
        public void add_declaration (CCodeDeclaration decl) {
-               declarations.add (decl);
+               nodes.add (decl);
        }
 
        /**
@@ -65,8 +75,12 @@ public class Vala.CCodeStruct : CCodeNode {
                writer.write_string ("struct ");
                writer.write_string (name);
                writer.write_begin_block ();
-               foreach (CCodeDeclaration decl in declarations) {
-                       decl.write_declaration (writer);
+               foreach (CCodeNode node in nodes) {
+                       if (node is CCodeDeclaration) {
+                               ((CCodeDeclaration) node).write_declaration (writer);
+                       } else {
+                               node.write (writer);
+                       }
                }
 
                writer.write_end_block ();