Commit d03f0a85 authored by Rahix's avatar Rahix

chore(docs): Update hawkmoth to version 0.5

Changelog:

    - packaging: upgrade development status to beta
    - build: remove FIXME about VERSION
    - test: cover additional macro cases
    - parser: simplify macro arguments extraction
    - Re-use the looked up cursor of a token.
    - test: cover cases of functions with no parameters
    - parser: fix documentation of non prototyped functions
    - doc: add example with preprocessor
Signed-off-by: Rahix's avatarRahix <rahix@rahix.de>
parent 12992926
Pipeline #4574 passed with stages
in 1 minute and 5 seconds
......@@ -34,7 +34,6 @@ Otherwise, documentation comments are passed through verbatim.
"""
import enum
import itertools
import sys
from clang.cindex import CursorKind, TypeKind
......@@ -75,18 +74,22 @@ def comment_extract(tu):
current_comment = token
continue
# Store off the token's cursor for a slight performance improvement
# instead of accessing the `cursor` property multiple times.
token_cursor = token.cursor
# cursors that are 1) never documented themselves, and 2) allowed
# between comment and the actual cursor being documented
if (token.cursor.kind == CursorKind.INVALID_FILE or
token.cursor.kind == CursorKind.TYPE_REF or
token.cursor.kind == CursorKind.PREPROCESSING_DIRECTIVE or
token.cursor.kind == CursorKind.MACRO_INSTANTIATION):
if (token_cursor.kind == CursorKind.INVALID_FILE or
token_cursor.kind == CursorKind.TYPE_REF or
token_cursor.kind == CursorKind.PREPROCESSING_DIRECTIVE or
token_cursor.kind == CursorKind.MACRO_INSTANTIATION):
continue
if cursor is not None and token.cursor == cursor:
if cursor is not None and token_cursor == cursor:
continue
cursor = token.cursor
cursor = token_cursor
# Note: current_comment may be None
if current_comment != None and docstr.is_doc(current_comment.spelling):
......@@ -125,16 +128,18 @@ def _get_macro_args(cursor):
if cursor.kind != CursorKind.MACRO_DEFINITION:
return None
tokens = cursor.get_tokens()
# Use the first two tokens to make sure this starts with 'IDENTIFIER('
x = [token for token in itertools.islice(cursor.get_tokens(), 2)]
if (len(x) != 2 or x[0].spelling != cursor.spelling or
x[1].spelling != '(' or x[0].extent.end != x[1].extent.start):
one = next(tokens)
two = next(tokens, None)
if two is None or one.extent.end != two.extent.start or two.spelling != '(':
return None
# Naïve parsing of macro arguments
# FIXME: This doesn't handle GCC named vararg extension FOO(vararg...)
args = []
for token in itertools.islice(cursor.get_tokens(), 2, None):
for token in tokens:
if token.spelling == ')':
return args
elif token.spelling == ',':
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment