From patchwork Tue Oct 20 01:40:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 10107 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 16A74BDB1F for ; Tue, 20 Oct 2020 01:40:59 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A5718613BF; Tue, 20 Oct 2020 03:40:57 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="Z4inkzAW"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9B61E60CE6 for ; Tue, 20 Oct 2020 03:40:56 +0200 (CEST) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 35A39309 for ; Tue, 20 Oct 2020 03:40:56 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1603158056; bh=Ac66USv+unUkNJVSXkjyKOsX4yhDCvlIGajTFo/mnzk=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Z4inkzAWPAsumfns/Ylpd5bfFeotAi16bAYr/6gDUMj/b6lzdTVbOfZ7ieVeVq8O8 MOoH28nUuGXOOs7d1DhoMWw5leJxvpKRFiAz/HgHNSbmLsK8fFmDMn/du67ahpTy0b 9RqCI+iL7YxTUM1P8FTg+c2e4WUKLfHxwRHadSho= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Tue, 20 Oct 2020 04:40:01 +0300 Message-Id: <20201020014005.12783-2-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201020014005.12783-1-laurent.pinchart@ideasonboard.com> References: <20201020014005.12783-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 1/5] utils: checkstyle.py: Add d-pointer formatter X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add a formatter to ensure consistent naming of 'd' and 'o' variables related to the d-pointer design pattern, as implemented by the Extensible class. The formatter also ensures that the pointer is always const. const-correctness issues related to the data pointed to will be caught by the compiler, and thus don't need to be checked here. Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund --- utils/checkstyle.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/utils/checkstyle.py b/utils/checkstyle.py index d5dc26c0f666..7225cac47a4e 100755 --- a/utils/checkstyle.py +++ b/utils/checkstyle.py @@ -481,6 +481,38 @@ class DoxygenFormatter(Formatter): return '\n'.join(lines) +class DPointerFormatter(Formatter): + # Ensure consistent naming of variables related to the d-pointer design + # pattern. + patterns = ('*.cpp', '*.h') + + # The clang formatter runs first, we can thus rely on appropriate coding + # style. + declare_regex = re.compile(r'^(\t*)(const )?([a-zA-Z0-9_]+) \*( ?const )?([a-zA-Z0-9_]+) = (LIBCAMERA_[DO]_PTR)\(([a-zA-Z0-9_]+)\);$') + + @classmethod + def format(cls, filename, data): + lines = [] + + for line in data.split('\n'): + match = cls.declare_regex.match(line) + if match: + indent = match.group(1) or '' + const = match.group(2) or '' + macro = match.group(6) + klass = match.group(7) + if macro == 'LIBCAMERA_D_PTR': + var = 'Private *const d' + else: + var = f'{klass} *const o' + + line = f'{indent}{const}{var} = {macro}({klass});' + + lines.append(line) + + return '\n'.join(lines) + + class IncludeOrderFormatter(Formatter): patterns = ('*.cpp', '*.h')