[hawkmoth] [PATCH v2 1/2] parser: fix documentation of non prototyped functions

  • From: Bruno Santos <brunomanuelsantos@xxxxxxxxxxxxxxxxxx>
  • To: hawkmoth mailing list <hawkmoth@xxxxxxxxxxxxx>, Jani Nikula <jani@xxxxxxxxxx>
  • Date: Sun, 9 Jun 2019 16:13:56 +0100

If the arguments list of a function is empty, Clang can not rule whether
a function is variadic or not. Previously the test was called
nonetheless only to trigger an exception in Clang. This patch prevents
that situation and will instead behave as if the function had been
declared with a single 'void' parameter.
---
 hawkmoth/parser.py | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/hawkmoth/parser.py b/hawkmoth/parser.py
index 60002bc..a070ad1 100644
--- a/hawkmoth/parser.py
+++ b/hawkmoth/parser.py
@@ -37,7 +37,7 @@
 import itertools
 import sys
 
-from clang.cindex import CursorKind
+from clang.cindex import CursorKind, TypeKind
 from clang.cindex import Index, TranslationUnit
 from clang.cindex import SourceLocation, SourceRange
 from clang.cindex import TokenKind, TokenGroup
@@ -216,13 +216,16 @@ def _recursive_parse(comments, cursor, nest, compat):
         # FIXME: children may contain extra stuff if the return type is a
         # typedef, for example
         args = []
-        for c in cursor.get_children():
-            if c.kind == CursorKind.PARM_DECL:
-                args.append('{ttype} {arg}'.format(ttype=c.type.spelling,
-                                                   arg=c.spelling))
 
-        if cursor.type.is_function_variadic():
-            args.append('...')
+        # Only fully prototyped functions will have argument lists to process.
+        if cursor.type.kind == TypeKind.FUNCTIONPROTO:
+            for c in cursor.get_children():
+                if c.kind == CursorKind.PARM_DECL:
+                    args.append('{ttype} {arg}'.format(ttype=c.type.spelling,
+                                                    arg=c.spelling))
+
+            if cursor.type.is_function_variadic():
+                args.append('...')
 
         fmt = docstr.Type.FUNC
         ttype = cursor.result_type.spelling
-- 
2.21.0


Other related posts: