[PATCH 1/2] apibuild.py: Handle enum comments properly

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

 



After f4cb85c6aff7c1d90 we only have two options for placing enum
values descriptions. It's either:

    typedef enum {
        /* Some long description. Therefore it's placed before
         * the value. */
        VIR_ENUM_A_VAL = 1,
    } virEnumA;

or:

    typedef enum {
        VIR_ENUM_B_VAL = 1, /* Some short description */
    } virEnumB;

However, our apibuild.py script is not able to deal with the
former one. It messes up comments. To fix this couple of things
needs to be done:

a) DO NOT reset self.comment in parseEnumBlock(). This is a
result from our tokenizer. Upon calling token() if it finds a
comment block it stores it in self.comment and returns the next
token (which is not comment). Therefore, if we reset self.comment
we might lose the first comment in the enum block.

b) we need a variable to track if the current enum block uses
value descriptions before or after values. That is if it's type
virEnumA or virEnumB. Depending on that, it we're dealing with
virEnumA type and the current token is a comma ',' we can add the
value into the list as we already have everything needed:
comment, name and value.

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 docs/apibuild.py | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/docs/apibuild.py b/docs/apibuild.py
index 47f340c7d..3a8f5d449 100755
--- a/docs/apibuild.py
+++ b/docs/apibuild.py
@@ -1365,9 +1365,9 @@ class CParser:
     def parseEnumBlock(self, token):
         self.enums = []
         name = None
-        self.comment = None
         comment = ""
         value = "-1"
+        commentsBeforeVal = self.comment is not None
         while token is not None:
             if token[0] == "sep" and token[1] == "{":
                 token = self.token()
@@ -1408,6 +1408,10 @@ class CParser:
                         self.warning("Failed to compute value of enum %s" % (name))
                         value=""
                 if token[0] == "sep" and token[1] == ",":
+                    if commentsBeforeVal and self.comment is not None:
+                        self.cleanupComment()
+                        self.enums.append((name, value, self.comment))
+                        name = comment = self.comment = None
                     token = self.token()
             else:
                 token = self.token()
@@ -1652,6 +1656,8 @@ class CParser:
             self.enums = []
             token = self.token()
             if token is not None and token[0] == "sep" and token[1] == "{":
+                # drop comments before the enum block
+                self.comment = None
                 token = self.token()
                 token = self.parseEnumBlock(token)
             else:
-- 
2.13.0

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]
  Powered by Linux