From d03f0a8549810416816889213868a84e25f1157b Mon Sep 17 00:00:00 2001 From: Rahix <rahix@rahix.de> Date: Thu, 21 May 2020 16:07:02 +0200 Subject: [PATCH] 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 <rahix@rahix.de> --- Documentation/hawkmoth/VERSION | 2 +- Documentation/hawkmoth/parser.py | 27 ++++++++++++++++----------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/Documentation/hawkmoth/VERSION b/Documentation/hawkmoth/VERSION index bd73f4707..2eb3c4fe4 100644 --- a/Documentation/hawkmoth/VERSION +++ b/Documentation/hawkmoth/VERSION @@ -1 +1 @@ -0.4 +0.5 diff --git a/Documentation/hawkmoth/parser.py b/Documentation/hawkmoth/parser.py index a070ad1cd..d06321731 100644 --- a/Documentation/hawkmoth/parser.py +++ b/Documentation/hawkmoth/parser.py @@ -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 == ',': -- GitLab