From patchwork Wed Sep 7 07:12:57 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Heiser X-Patchwork-Id: 9318315 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 12C28601C0 for ; Wed, 7 Sep 2016 07:13:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 00A83290B2 for ; Wed, 7 Sep 2016 07:13:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E978E290B4; Wed, 7 Sep 2016 07:13:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 18188290B2 for ; Wed, 7 Sep 2016 07:13:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754144AbcIGHNq (ORCPT ); Wed, 7 Sep 2016 03:13:46 -0400 Received: from smtp2.goneo.de ([85.220.129.33]:41608 "EHLO smtp2.goneo.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753663AbcIGHNo (ORCPT ); Wed, 7 Sep 2016 03:13:44 -0400 Received: from localhost (localhost [127.0.0.1]) by smtp2.goneo.de (Postfix) with ESMTP id 636C02430E7; Wed, 7 Sep 2016 09:13:41 +0200 (CEST) X-Virus-Scanned: by goneo Received: from smtp2.goneo.de ([127.0.0.1]) by localhost (smtp2.goneo.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id DiJJ6t480UGx; Wed, 7 Sep 2016 09:13:07 +0200 (CEST) Received: from ubu1604.fritz.box (dyndsl-095-033-002-234.ewe-ip-backbone.de [95.33.2.234]) by smtp2.goneo.de (Postfix) with ESMTPSA id DEF9F242CF6; Wed, 7 Sep 2016 09:13:06 +0200 (CEST) From: Markus Heiser To: Jonathan Corbet , Mauro Carvalho Chehab , Jani Nikula Cc: Markus Heiser , Linux Media Mailing List , linux-doc@vger.kernel.org, Markus Heiser Subject: [PATCH v2 2/3] doc-rst:c-domain: function-like macros arguments Date: Wed, 7 Sep 2016 09:12:57 +0200 Message-Id: <1473232378-11869-3-git-send-email-markus.heiser@darmarit.de> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1473232378-11869-1-git-send-email-markus.heiser@darmarit.de> References: <1473232378-11869-1-git-send-email-markus.heiser@darmarit.de> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Markus Heiser Handle signatures of function-like macros well. Don't try to deduce arguments types of function-like macros. Signed-off-by: Markus Heiser --- Documentation/sphinx/cdomain.py | 55 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/Documentation/sphinx/cdomain.py b/Documentation/sphinx/cdomain.py index 5f0c7ed..df0419c 100644 --- a/Documentation/sphinx/cdomain.py +++ b/Documentation/sphinx/cdomain.py @@ -1,4 +1,5 @@ # -*- coding: utf-8; mode: python -*- +# pylint: disable=W0141,C0113,C0103,C0325 u""" cdomain ~~~~~~~ @@ -25,11 +26,18 @@ u""" * :c:func:`VIDIOC_LOG_STATUS` or * :any:`VIDIOC_LOG_STATUS` (``:any:`` needs sphinx 1.3) + + * Handle signatures of function-like macros well. Don't try to deduce + arguments types of function-like macros. + """ +from docutils import nodes from docutils.parsers.rst import directives import sphinx +from sphinx import addnodes +from sphinx.domains.c import c_funcptr_sig_re, c_sig_re from sphinx.domains.c import CObject as Base_CObject from sphinx.domains.c import CDomain as Base_CDomain @@ -57,9 +65,54 @@ class CObject(Base_CObject): "name" : directives.unchanged } + def handle_func_like_macro(self, sig, signode): + u"""Handles signatures of function-like macros. + + If the objtype is 'function' and the the signature ``sig`` is a + function-like macro, the name of the macro is returned. Otherwise + ``False`` is returned. """ + + if not self.objtype == 'function': + return False + + m = c_funcptr_sig_re.match(sig) + if m is None: + m = c_sig_re.match(sig) + if m is None: + raise ValueError('no match') + + rettype, fullname, arglist, _const = m.groups() + arglist = arglist.strip() + if rettype or not arglist: + return False + + arglist = arglist.replace('`', '').replace('\\ ', '') # remove markup + arglist = [a.strip() for a in arglist.split(",")] + + # has the first argument a type? + if len(arglist[0].split(" ")) > 1: + return False + + # This is a function-like macro, it's arguments are typeless! + signode += addnodes.desc_name(fullname, fullname) + paramlist = addnodes.desc_parameterlist() + signode += paramlist + + for argname in arglist: + param = addnodes.desc_parameter('', '', noemph=True) + # separate by non-breaking space in the output + param += nodes.emphasis(argname, argname) + paramlist += param + + return fullname + def handle_signature(self, sig, signode): """Transform a C signature into RST nodes.""" - fullname = super(CObject, self).handle_signature(sig, signode) + + fullname = self.handle_func_like_macro(sig, signode) + if not fullname: + fullname = super(CObject, self).handle_signature(sig, signode) + if "name" in self.options: if self.objtype == 'function': fullname = self.options["name"]