[hawkmoth] [PATCH 1/2] parser: parse members like variable declarations

  • From: Jani Nikula <jani@xxxxxxxxxx>
  • To: hawkmoth@xxxxxxxxxxxxx
  • Date: Mon, 25 Jan 2021 21:08:32 +0200

Struct members may also be arrays, and this currently fails similarly to
how array variables used to fail. Parse members like variable
declarations to fix the issue.

Update the tests to cover the case.
---
 hawkmoth/parser.py | 13 +++++--------
 test/struct.c      |  4 ++++
 test/struct.rst    |  5 +++++
 3 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/hawkmoth/parser.py b/hawkmoth/parser.py
index 37862d38327c..35213739f2de 100644
--- a/hawkmoth/parser.py
+++ b/hawkmoth/parser.py
@@ -166,8 +166,11 @@ def _recursive_parse(comments, cursor, nest, compat):
         return _result(comment, cursor=cursor, fmt=fmt,
                        nest=nest, name=name, args=args, compat=compat)
 
-    elif cursor.kind == CursorKind.VAR_DECL:
-        fmt = docstr.Type.VAR
+    elif cursor.kind in [CursorKind.VAR_DECL, CursorKind.FIELD_DECL]:
+        if cursor.kind == CursorKind.VAR_DECL:
+            fmt = docstr.Type.VAR
+        else:
+            fmt = docstr.Type.MEMBER
 
         # The dimensions should be applied to the name, not the type.
         dims = ttype.rsplit(' ', 1)[-1]
@@ -222,12 +225,6 @@ def _recursive_parse(comments, cursor, nest, compat):
         return _result(comment, cursor=cursor, fmt=fmt,
                        nest=nest, name=name, compat=compat)
 
-    elif cursor.kind == CursorKind.FIELD_DECL:
-        fmt = docstr.Type.MEMBER
-
-        return _result(comment, cursor=cursor, fmt=fmt,
-                       nest=nest, name=name, ttype=ttype, compat=compat)
-
     elif cursor.kind == CursorKind.FUNCTION_DECL:
         # FIXME: check args against comment
         # FIXME: children may contain extra stuff if the return type is a
diff --git a/test/struct.c b/test/struct.c
index 0b0640dc6dbc..d8353f5b66f5 100644
--- a/test/struct.c
+++ b/test/struct.c
@@ -8,6 +8,10 @@ struct sample_struct {
         * member
         */
        int jesh;
+       /**
+        * array member
+        */
+       int array_member[5];
        /**
         * foo next
         */
diff --git a/test/struct.rst b/test/struct.rst
index 3fc33bce0255..fb2b1abaf980 100644
--- a/test/struct.rst
+++ b/test/struct.rst
@@ -11,6 +11,11 @@
       member
 
 
+   .. c:member:: int array_member[5]
+
+      array member
+
+
    .. c:member:: struct sample_struct * next
 
       foo next
-- 
2.29.2


Other related posts:

  • » [hawkmoth] [PATCH 1/2] parser: parse members like variable declarations - Jani Nikula