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,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham 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 9E800C352A3 for ; Tue, 11 Feb 2020 14:01:58 +0000 (UTC) Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (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 6423C206ED for ; Tue, 11 Feb 2020 14:01:58 +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="Xu63uOfV" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6423C206ED Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linux-kernel-mentees-bounces@lists.linuxfoundation.org Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 205F9204E0; Tue, 11 Feb 2020 14:01:58 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id GyQvd9MA9xOh; Tue, 11 Feb 2020 14:01:57 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by silver.osuosl.org (Postfix) with ESMTP id 6E84B20006; Tue, 11 Feb 2020 14:01:57 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 5A944C1D80; Tue, 11 Feb 2020 14:01:57 +0000 (UTC) Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by lists.linuxfoundation.org (Postfix) with ESMTP id D9B04C07FE for ; Tue, 11 Feb 2020 14:01:55 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id C87928266F for ; Tue, 11 Feb 2020 14:01:55 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id MrGvAF4qKeMa for ; Tue, 11 Feb 2020 14:01:55 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-pl1-f195.google.com (mail-pl1-f195.google.com [209.85.214.195]) by hemlock.osuosl.org (Postfix) with ESMTPS id 28F68823B0 for ; Tue, 11 Feb 2020 14:01:55 +0000 (UTC) Received: by mail-pl1-f195.google.com with SMTP id g6so4322575plt.2 for ; Tue, 11 Feb 2020 06:01:55 -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=ghVu4OJ3L2uII3bIe675FjO/5HT0E/BaTOy1eE/SBDk=; b=Xu63uOfVV77SshD8HZEjZIiRcnHXH+owM0i3VGRhS1P7+BdHi1j12sTjWkUJcqlhA2 85s0Iq2HnOOjnA78WJjT1x2PoNRk7R0TxtENsQ2Urd5PQWdUeoXSJ4iQklZjBnhaZCmK mhOMNPrR1Yzf4FMEi2tDo5/tPie68ZXO2zevBrJIEjFhcBftWcBBtNwJ6b1KxjBnmyAP nbx/vtazk9pPeKbsLa9IE+eusp6iJh4A8q+b0xIIG3EHlWqVxZIVuSpOfcQNcxamLKqe oZiv5PVx+GEGQcOvfSufB4iL9kZEw5spZMuBL20FiBuGeA4mrzIOccnWtawKNFVFSGhI iCEA== 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=ghVu4OJ3L2uII3bIe675FjO/5HT0E/BaTOy1eE/SBDk=; b=XpOP6u7108kLScKoezo68rAi97iuI82pOWb/e+ibD0n267zWV/JcIQ+02qrneU2Smr 4w/2qNkM9WJWdpirrB2TUhnuSMdyCtgnz95t8hlOytSMRng+wjyIVD4Yh+kYbepimUL8 Uh74yh9fyOgVaVjO88BpnXPPXFNi/IwRutVLu1m9rjlElxYLU8nLA949fS8R+BH2shQ1 TB9uaHiMXNWtGfefphr86ODp02hLZiOFSJwK4aBxBiExvUMZca2Ko7GY5sbteoi14XJ2 106/es7EOJeKfRfF0/RWBLseV1bFgi3aJnrCj8UgN5kaHKFL4beP8paKRXPorg/qKqBk Y3gA== X-Gm-Message-State: APjAAAUkcKxnEG7ahzP8s5soRYaTNIzqVh4u1FyfMQSfltQ5Bl9rxHWw dZYOQeZ1PY5EaQbSs/OIfU0= X-Google-Smtp-Source: APXvYqyeyab7EZE7U4MyususChitcHk4tIiqkVP85T9zLSHnexikQ8aDXPwep00BAKgw7ustP1kmoA== X-Received: by 2002:a17:90a:8001:: with SMTP id b1mr3804254pjn.39.1581429714618; Tue, 11 Feb 2020 06:01:54 -0800 (PST) Received: from localhost.localdomain ([2405:204:22ac:7250:d1c8:6411:2f12:731d]) by smtp.gmail.com with ESMTPSA id z26sm4203575pgu.80.2020.02.11.06.01.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Feb 2020 06:01:54 -0800 (PST) From: Jaskaran Singh To: cocci@systeme.lip6.fr Date: Tue, 11 Feb 2020 19:31:35 +0530 Message-Id: <20200211140137.2304-2-jaskaransingh7654321@gmail.com> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200211140137.2304-1-jaskaransingh7654321@gmail.com> References: <20200211140137.2304-1-jaskaransingh7654321@gmail.com> MIME-Version: 1.0 Cc: julia.lawall@inria.fr, Jaskaran Singh , linux-kernel-mentees@lists.linuxfoundation.org Subject: [Linux-kernel-mentees] [PATCH v5 1/3] parsing_c: Align C AST and Cocci AST for pointer X-BeenThere: linux-kernel-mentees@lists.linuxfoundation.org X-Mailman-Version: 2.1.15 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 Errors-To: linux-kernel-mentees-bounces@lists.linuxfoundation.org Sender: "Linux-kernel-mentees" 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 | 15 ++++++++++----- 2 files changed, 12 insertions(+), 7 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..f4821d5c 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,13 @@ 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 + then pr_space() | (Array (eopt, t), [i1;i2]) -> pp_type_left t | (FunctionType (returnt, paramst), [i1;i2]) -> pp_type_left returnt -- 2.21.1 _______________________________________________ Linux-kernel-mentees mailing list Linux-kernel-mentees@lists.linuxfoundation.org https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees