[vala/wip/abi: 2/4] ccode: Allow adding of comments to a CCodeStruct



commit 521dd11c5c594270219e2e12d6a1524e6d2f8810
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Wed Jan 17 12:55:59 2018 +0100

    ccode: Allow adding of comments to a CCodeStruct
    
    https://bugzilla.gnome.org/show_bug.cgi?id=789069

 ccode/valaccodestruct.vala |   24 +++++++++++++++++++-----
 1 files changed, 19 insertions(+), 5 deletions(-)
---
diff --git a/ccode/valaccodestruct.vala b/ccode/valaccodestruct.vala
index fce7fcb..44473aa 100644
--- a/ccode/valaccodestruct.vala
+++ b/ccode/valaccodestruct.vala
@@ -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 ();


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]