From patchwork Tue Nov 3 01:02:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 10313 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 7287ABDB1E for ; Tue, 3 Nov 2020 01:03:46 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id CBA6062B9B; Tue, 3 Nov 2020 02:03:45 +0100 (CET) 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="Qph9K8/n"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id AAEFD62B92 for ; Tue, 3 Nov 2020 02:03:43 +0100 (CET) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 4634651D for ; Tue, 3 Nov 2020 02:03:43 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1604365423; bh=TDOaxCLPkl0LOejtjmUQ1g66C5louBpLBS/9Dv5thes=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Qph9K8/nZKDdTu3K1vfsfEli2Y1wz3GgFx6bw889qlyS8Li7uL27ncZVHl5yQ+jPW hQZRA3NvUqNrzxwbQKUx6XXCwWBrH4bqR+TnQSmfH+TF0SNrfpXqEHr9Cf+YRI4nrr qVuS0FXnb8YPc5r8okzahsQkWtORWBeHiB5HZpUk= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Tue, 3 Nov 2020 03:02:48 +0200 Message-Id: <20201103010251.14689-2-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201103010251.14689-1-laurent.pinchart@ideasonboard.com> References: <20201103010251.14689-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 1/4] 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')