From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.3 required=3.0 tests=DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DB3C2C352A4 for ; Sun, 9 Feb 2020 15:35:28 +0000 (UTC) Received: from isis.lip6.fr (isis.lip6.fr [132.227.60.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7BC7B2080C for ; Sun, 9 Feb 2020 15:35:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="MCqqoPAm" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7BC7B2080C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=cocci-bounces@systeme.lip6.fr Received: from systeme.lip6.fr (systeme.lip6.fr [132.227.104.7]) by isis.lip6.fr (8.15.2/8.15.2) with ESMTP id 019FZAO4015563; Sun, 9 Feb 2020 16:35:10 +0100 (CET) Received: from systeme.lip6.fr (systeme.lip6.fr [127.0.0.1]) by systeme.lip6.fr (Postfix) with ESMTP id CF961772F; Sun, 9 Feb 2020 16:35:10 +0100 (CET) Received: from isis.lip6.fr (isis.lip6.fr [132.227.60.2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by systeme.lip6.fr (Postfix) with ESMTPS id E18907718 for ; Sun, 9 Feb 2020 16:35:09 +0100 (CET) Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20:0:0:0:441]) by isis.lip6.fr (8.15.2/8.15.2) with ESMTPS id 019FZ8eP010112 (version=TLSv1.2 cipher=AES128-GCM-SHA256 bits=128 verify=OK) for ; Sun, 9 Feb 2020 16:35:09 +0100 (CET) Received: by mail-pf1-x441.google.com with SMTP id 185so2396477pfv.3 for ; Sun, 09 Feb 2020 07:35:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=64oHOSEzoPdfu0x0Rb4lVn2rSoJYTu0rEMNFQd1UT2E=; b=MCqqoPAm8QXgUqQXMwNonlmrA4gtNlxFc4vD+sSCIdMAFEAht7/dhVAoRDLFfrshD+ mfX1lcc2JcKAq6vk6U66q1ExAwgrYnEyBlt91XLL6QZIgQMQ9xeHyXC8qdkROA/n+Xlf 0aelVfn+mz3GkJZnpRp4QkpdMvOggpkbQ1ZfzLxs2ctVgG0tCeFKMfOev42TJULP5nbv BBYzzkOrJdtmHkPP3+QlgDKGh0I00ZrcM7BSsh6ErbW04npd+Ve6ezbLYVbRmKpBtq1J 5pZMZ/RLr+Krrc2lvsfhHjrvWaj9eqezj7G8rkeeM3hbjzdYNFqnV09+EdZKNnO383u1 6kBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=64oHOSEzoPdfu0x0Rb4lVn2rSoJYTu0rEMNFQd1UT2E=; b=k4b7eXrqnwJ224WhTxLfuoAko37AZM4e4L6wxIOvdFePbzKc7ZbYcFpFBZTCEQmtjc temSu007JrlnC+NOtiCZGW5zPfK2wqAxXHvxzar2bSwMdrhtEwhRMnZoU9W9Qj1BTjxu vB1fX3maET8wbtjEOn5Z2T0bf+KBnNGudvu/o1MFRbOwU5qjNPhBLexBz+YKB/Ah+yaQ IJcH3Vr7daryYnjEX8ePlD9r+PasPk2haaSklJLca0gclG7eSdxr1K0I3vQ+loejkQUo GdWYWC3uUJVWrpVZhr6beJlEQmQPvki8/y4rnHwxKIxzwVBnFDOjRTKpfO8osIuS3Zvt y4Ow== X-Gm-Message-State: APjAAAVzXWkBDPQLdhC/29cYsgDM4aECPH3EsJ7x+zUFuQSGi3QrosbY 0Sg56paP8dGOZMe8FJOxNbZ7RAT4 X-Google-Smtp-Source: APXvYqw4ETarQ5jCEv/zTRYrNnyNY2cVLNZeSDEvuVuOB/LZB5lTgo7IyEk1d7nsHI1P7/A6n6NKaw== X-Received: by 2002:aa7:9f90:: with SMTP id z16mr9026785pfr.161.1581262507334; Sun, 09 Feb 2020 07:35:07 -0800 (PST) Received: from localhost.localdomain ([2405:204:22ac:7250:d1c8:6411:2f12:731d]) by smtp.gmail.com with ESMTPSA id c11sm9451702pfo.170.2020.02.09.07.35.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Feb 2020 07:35:07 -0800 (PST) From: Jaskaran Singh To: cocci@systeme.lip6.fr Date: Sun, 9 Feb 2020 21:04:50 +0530 Message-Id: <20200209153452.11837-2-jaskaransingh7654321@gmail.com> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200209153452.11837-1-jaskaransingh7654321@gmail.com> References: <20200209153452.11837-1-jaskaransingh7654321@gmail.com> MIME-Version: 1.0 X-Greylist: Sender IP whitelisted, Sender e-mail whitelisted, not delayed by milter-greylist-4.4.3 (isis.lip6.fr [132.227.60.2]); Sun, 09 Feb 2020 16:35:10 +0100 (CET) X-Greylist: Sender DNS name whitelisted, not delayed by milter-greylist-4.4.3 (isis.lip6.fr [IPv6:2001:660:3302:283c:0:0:0:2]); Sun, 09 Feb 2020 16:35:09 +0100 (CET) X-Scanned-By: MIMEDefang 2.78 on 132.227.60.2 X-Scanned-By: MIMEDefang 2.78 Cc: linux-kernel-mentees@lists.linuxfoundation.org Subject: [Cocci] [PATCH v4 1/3] parsing_c: Align C AST and Cocci AST for pointer X-BeenThere: cocci@systeme.lip6.fr X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: cocci-bounces@systeme.lip6.fr Errors-To: cocci-bounces@systeme.lip6.fr For a pointer, the C parser constructed an AST dissimilar from that of the Cocci AST. This caused failures in matching with certain pointer types. For example, for the following case: char *1 const *2 id; The C AST constructed would be: const Pointer1 -> Pointer2 -> char The Cocci AST constructed would be: Pointer2 -> const Pointer1 -> char Change the pointer rule in the C parser so that an AST similar to the Cocci AST is constructed. Make necessary changes in the C pretty printer so that the pointer type is printed correctly. Signed-off-by: Jaskaran Singh --- parsing_c/parser_c.mly | 4 ++-- parsing_c/pretty_print_c.ml | 14 ++++++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/parsing_c/parser_c.mly b/parsing_c/parser_c.mly index 8d7b761e..4c74f15a 100644 --- a/parsing_c/parser_c.mly +++ b/parsing_c/parser_c.mly @@ -1333,14 +1333,14 @@ pointer: | tmul { (Ast_c.noattr,fun x -> mk_ty (Pointer x) [$1]) } | tmul pointer { let (attr,ptr) = $2 in - (attr,fun x -> mk_ty (Pointer (ptr x)) [$1]) } + (attr,fun x -> ptr (mk_ty (Pointer x) [$1])) } | tmul type_qualif_list { let (attr,tq) = $2 in (attr,fun x -> (tq.qualifD, mk_tybis (Pointer x) [$1]))} | tmul type_qualif_list pointer { let (attr1,tq) = $2 in let (attr2,ptr) = $3 in - (attr1@attr2,fun x -> (tq.qualifD, mk_tybis (Pointer (ptr x)) [$1])) } + (attr1@attr2,fun x -> ptr (tq.qualifD, mk_tybis (Pointer x) [$1])) } tmul: TMul { $1 } diff --git a/parsing_c/pretty_print_c.ml b/parsing_c/pretty_print_c.ml index a2e35588..3aaa97ca 100644 --- a/parsing_c/pretty_print_c.ml +++ b/parsing_c/pretty_print_c.ml @@ -804,11 +804,14 @@ and pp_string_format (e,ii) = (FunctionType (return=void, params=int i) *) (*WRONG I THINK, use left & right function *) (* bug: pp_type_with_ident_rest None t; print_ident ident *) + pp_type_left t; pr_elem i; - iiqu +> List.iter pr_elem; (* le const est forcement apres le '*' *) + iiqu +> + List.iter (* le const est forcement apres le '*' *) + (function x -> (pr_space(); pr_elem x)); if iiqu <> [] || get_comments_after i <> [] then pr_space(); - pp_type_with_ident_rest ident t attrs Ast_c.noattr; + print_ident ident (* ugly special case ... todo? maybe sufficient in practice *) | (ParenType ttop, [i1;i2]) -> @@ -885,11 +888,14 @@ and pp_string_format (e,ii) = match ty, iity with (NoType,_) -> failwith "pp_type_left: unexpected NoType" | (Pointer t, [i]) -> + pp_type_left t; pr_elem i; - iiqu +> List.iter pr_elem; (* le const est forcement apres le '*' *) + iiqu +> + List.iter (* le const est forcement apres le '*' *) + (function x -> (pr_space(); pr_elem x)); if iiqu <> [] || get_comments_after i <> [] then pr_space(); - pp_type_left t + () | (Array (eopt, t), [i1;i2]) -> pp_type_left t | (FunctionType (returnt, paramst), [i1;i2]) -> pp_type_left returnt -- 2.21.1 _______________________________________________ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci