Skip to content
Snippets Groups Projects
Commit d03f0a85 authored by rahix's avatar rahix
Browse files

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: default avatarRahix <rahix@rahix.de>
parent 12992926
Branches
No related tags found
No related merge requests found
0.4 0.5
...@@ -34,7 +34,6 @@ Otherwise, documentation comments are passed through verbatim. ...@@ -34,7 +34,6 @@ Otherwise, documentation comments are passed through verbatim.
""" """
import enum import enum
import itertools
import sys import sys
from clang.cindex import CursorKind, TypeKind from clang.cindex import CursorKind, TypeKind
...@@ -75,18 +74,22 @@ def comment_extract(tu): ...@@ -75,18 +74,22 @@ def comment_extract(tu):
current_comment = token current_comment = token
continue 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 # cursors that are 1) never documented themselves, and 2) allowed
# between comment and the actual cursor being documented # between comment and the actual cursor being documented
if (token.cursor.kind == CursorKind.INVALID_FILE or if (token_cursor.kind == CursorKind.INVALID_FILE or
token.cursor.kind == CursorKind.TYPE_REF or token_cursor.kind == CursorKind.TYPE_REF or
token.cursor.kind == CursorKind.PREPROCESSING_DIRECTIVE or token_cursor.kind == CursorKind.PREPROCESSING_DIRECTIVE or
token.cursor.kind == CursorKind.MACRO_INSTANTIATION): token_cursor.kind == CursorKind.MACRO_INSTANTIATION):
continue continue
if cursor is not None and token.cursor == cursor: if cursor is not None and token_cursor == cursor:
continue continue
cursor = token.cursor cursor = token_cursor
# Note: current_comment may be None # Note: current_comment may be None
if current_comment != None and docstr.is_doc(current_comment.spelling): if current_comment != None and docstr.is_doc(current_comment.spelling):
...@@ -125,16 +128,18 @@ def _get_macro_args(cursor): ...@@ -125,16 +128,18 @@ def _get_macro_args(cursor):
if cursor.kind != CursorKind.MACRO_DEFINITION: if cursor.kind != CursorKind.MACRO_DEFINITION:
return None return None
tokens = cursor.get_tokens()
# Use the first two tokens to make sure this starts with 'IDENTIFIER(' # Use the first two tokens to make sure this starts with 'IDENTIFIER('
x = [token for token in itertools.islice(cursor.get_tokens(), 2)] one = next(tokens)
if (len(x) != 2 or x[0].spelling != cursor.spelling or two = next(tokens, None)
x[1].spelling != '(' or x[0].extent.end != x[1].extent.start): if two is None or one.extent.end != two.extent.start or two.spelling != '(':
return None return None
# Naïve parsing of macro arguments # Naïve parsing of macro arguments
# FIXME: This doesn't handle GCC named vararg extension FOO(vararg...) # FIXME: This doesn't handle GCC named vararg extension FOO(vararg...)
args = [] args = []
for token in itertools.islice(cursor.get_tokens(), 2, None): for token in tokens:
if token.spelling == ')': if token.spelling == ')':
return args return args
elif token.spelling == ',': elif token.spelling == ',':
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment