From patchwork Tue Feb 21 12:02:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 60062 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1846530wrn; Tue, 21 Feb 2023 04:59:29 -0800 (PST) X-Google-Smtp-Source: AK7set/UYzEt7hNEzGfuL1L7oghoc4pRRabLFlE9A1xIBOGP8sC4UFqfibaYKjp4Z9ZpNolEcWBL X-Received: by 2002:a17:907:7628:b0:8b1:7daf:6285 with SMTP id jy8-20020a170907762800b008b17daf6285mr14180006ejc.35.1676984369575; Tue, 21 Feb 2023 04:59:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676984369; cv=none; d=google.com; s=arc-20160816; b=OMlvhKB2Qub4ZsW81fAoYC+2AemOHNRR6vS8y5l35PZGlo2OuPks/HlDpJlBNW8aEI npI3x2XEwKmuDiOz3hRsc+0B3CTjrTj8KqXV3mMZKAvuS3PI3Ac/618z22Ykw1sGHO2M EM/XmYE77JJgaF8ofAofSXBDvxSNvsvQ8GadiO2CUnGU0421LWHfd8gNQnLAQlOZ2IGX g+4GFikvFjCRBdgXk0+Ze0cgBrnfUn559dBWXP5dXkaK/RzOoZCpz491rcY5IOoqbHOv IQWhrd9ZgQplZI0rrTlmTw9HspgL3zvWC7y5n0yXjziVNVUNFP4NjCYWO9poMtDOIDHp dnpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature:dmarc-filter :delivered-to; bh=NCRIyJ3oqIvHXngAtHm1nMT8c70CGNL0Rd3wv/jq6L0=; b=XrIXNs5bgVaFOZzH6ArxtlKpMmNZ/o6m/ern2KVfsjGLKbov8hTfIb7xp6xet8Nh9f 4Snw9e5HuI7FjxDJF6FKpcosKa7JHIAuvJiRohhn+d+zBe5Raz7MJuEFPv/9Akkl7lLy HzwWcWNm+0Z6iKD9u7bYLW/pb4HjkexdrUh//yIC9TL81Ou7qFcKLzIMEXFsa6iEEIR0 0JYQXAJ7hLg1V66awNeiZgh4b/GEJMumDZ8CrpB8IUO4IPI9tMo1G3THKBJXsDlXXypz wiejzLCLFaG6ha2Xuhmv9p+hGqhGWZu+rX2iWoJp2rBOlTbQzEF02ctA5y+r3fTNFd2i kpXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=hBc5Q22q; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id cm3-20020a170907938300b008cf2b9f412csi6425075ejc.67.2023.02.21.04.59.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:59:29 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=hBc5Q22q; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2BC763886C53 for ; Tue, 21 Feb 2023 12:20:53 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by sourceware.org (Postfix) with ESMTPS id 9BBAC3844765 for ; Tue, 21 Feb 2023 12:04:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9BBAC3844765 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embecosm.com Received: by mail-wr1-x42c.google.com with SMTP id t15so4269890wrz.7 for ; Tue, 21 Feb 2023 04:04:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=NCRIyJ3oqIvHXngAtHm1nMT8c70CGNL0Rd3wv/jq6L0=; b=hBc5Q22qorEz/qCHyMec+yUsViKI43PHNLsvpdtaRi3f7iXSHd3FU/CQGG+UkIEDTs Bf9loDXCSqz3k4UxKxd/2w/BBO3vVKdIpH2TB5vaEZTXm7vi+O0WZSZrlh/UCzI4Odg1 ZkkSYKUJ9KnpyvrHo4cURtMGW3NaXxqRNf8OkhcaP+rW+APF7m+xxD/3vKlEgwMQiN+G sUm3+PY5Mw05j8SwOJVgIuYbykjt27asis08X77iBApIYpZ7d6/yDR9XJ+81NjcTJ3yg jjwClo4YuJIcK6XA4SgdLrBihBCJcUG6uvTrv3FP5Nxrhd3GbF78m3Of1649P9N4i5xN 7flA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=NCRIyJ3oqIvHXngAtHm1nMT8c70CGNL0Rd3wv/jq6L0=; b=ogh6ORfhNj+dZzb2ke8vht2tbmoIu3EzUfcJR/bSek02myyITsiTeQTGKi2Y8dKbDw LHO5ZDRdI43Acsrt2cuHlmZuigd7YjPmOj0CynHqHh8NnImm9dU5ueusNGgDTb6xgVUO l93TKf6NiI2cEYHHml056ZjOLlB/7rralmGrPbQI2GIQ21wL5OHD9We7JJnj0mkuPrAC S7FXEhSZDYuUjXy3MFDWO7SYa5QrLqzlISxZqQznqGzvk25Nnr5SnBzixadpk6mswbb8 bXBJxAbeKK3+kstJTgmXIeOCtpraa1DHYvZvoCzJjo82niOQe4WivqMddMTzlhaZFZ22 s+Rg== X-Gm-Message-State: AO0yUKW0L+UH2DH/+pNEV2ITSiDkAn05Fo2jS+LswgHd/ODFpNXfy1jH C41jFG6BQXs3dc9DlvlQpIG1i9IGgb8xq8krKg== X-Received: by 2002:a5d:522e:0:b0:2c3:db9e:4b06 with SMTP id i14-20020a5d522e000000b002c3db9e4b06mr4944863wra.45.1676981075971; Tue, 21 Feb 2023 04:04:35 -0800 (PST) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id c15-20020adffb4f000000b002c55b0e6ef1sm5013811wrs.4.2023.02.21.04.04.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:04:35 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Dave Subject: [committed 091/103] gccrs: Remove default location. Add visibility location to create_* functions Date: Tue, 21 Feb 2023 13:02:21 +0100 Message-Id: <20230221120230.596966-92-arthur.cohen@embecosm.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230221120230.596966-1-arthur.cohen@embecosm.com> References: <20230221120230.596966-1-arthur.cohen@embecosm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-14.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: arthur.cohen@embecosm.com Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758445562080392789?= X-GMAIL-MSGID: =?utf-8?q?1758445562080392789?= From: Dave gcc/rust/ChangeLog: * ast/rust-item.h: Remoe default location for Visibility class. * parse/rust-parse-impl.h (Parser::parse_visibility): Pass proper location when instantiating visibilities. --- gcc/rust/ast/rust-item.h | 33 ++++++++++++++++++-------------- gcc/rust/parse/rust-parse-impl.h | 11 ++++++----- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h index 96201d668de..7ea7b86562f 100644 --- a/gcc/rust/ast/rust-item.h +++ b/gcc/rust/ast/rust-item.h @@ -633,8 +633,7 @@ private: public: // Creates a Visibility - TODO make constructor protected or private? - Visibility (VisType vis_type, SimplePath in_path, - Location locus = Location ()) + Visibility (VisType vis_type, SimplePath in_path, Location locus) : vis_type (vis_type), in_path (std::move (in_path)), locus (locus) {} @@ -654,10 +653,11 @@ public: Location get_locus () const { return locus; } + // empty? // Creates an error visibility. static Visibility create_error () { - return Visibility (PUB_IN_PATH, SimplePath::create_empty ()); + return Visibility (PUB_IN_PATH, SimplePath::create_empty (), Location ()); } // Unique pointer custom clone function @@ -669,45 +669,50 @@ public: * is one idea but may be too resource-intensive. */ // Creates a public visibility with no further features/arguments. - static Visibility create_public () + // empty? + static Visibility create_public (Location pub_vis_location) { - return Visibility (PUB, SimplePath::create_empty ()); + return Visibility (PUB, SimplePath::create_empty (), pub_vis_location); } // Creates a public visibility with crate-relative paths - static Visibility create_crate (Location crate_tok_location) + static Visibility create_crate (Location crate_tok_location, + Location crate_vis_location) { return Visibility (PUB_CRATE, SimplePath::from_str ("crate", crate_tok_location), - crate_tok_location); + crate_vis_location); } // Creates a public visibility with self-relative paths - static Visibility create_self (Location self_tok_location) + static Visibility create_self (Location self_tok_location, + Location self_vis_location) { return Visibility (PUB_SELF, SimplePath::from_str ("self", self_tok_location), - self_tok_location); + self_vis_location); } // Creates a public visibility with parent module-relative paths - static Visibility create_super (Location super_tok_location) + static Visibility create_super (Location super_tok_location, + Location super_vis_location) { return Visibility (PUB_SUPER, SimplePath::from_str ("super", super_tok_location), - super_tok_location); + super_vis_location); } // Creates a private visibility static Visibility create_private () { - return Visibility (PRIV, SimplePath::create_empty ()); + return Visibility (PRIV, SimplePath::create_empty (), Location ()); } // Creates a public visibility with a given path or whatever. - static Visibility create_in_path (SimplePath in_path) + static Visibility create_in_path (SimplePath in_path, + Location in_path_vis_location) { - return Visibility (PUB_IN_PATH, std::move (in_path), in_path.get_locus ()); + return Visibility (PUB_IN_PATH, std::move (in_path), in_path_vis_location); } std::string as_string () const; diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index a4a912f8c1d..ee0282bdab3 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -2137,12 +2137,13 @@ Parser::parse_visibility () return AST::Visibility::create_private (); } + auto vis_loc = lexer.peek_token ()->get_locus (); lexer.skip_token (); // create simple pub visibility if no parentheses if (lexer.peek_token ()->get_id () != LEFT_PAREN) { - return AST::Visibility::create_public (); + return AST::Visibility::create_public (vis_loc); // or whatever } @@ -2158,19 +2159,19 @@ Parser::parse_visibility () skip_token (RIGHT_PAREN); - return AST::Visibility::create_crate (path_loc); + return AST::Visibility::create_crate (path_loc, vis_loc); case SELF: lexer.skip_token (); skip_token (RIGHT_PAREN); - return AST::Visibility::create_self (path_loc); + return AST::Visibility::create_self (path_loc, vis_loc); case SUPER: lexer.skip_token (); skip_token (RIGHT_PAREN); - return AST::Visibility::create_super (path_loc); + return AST::Visibility::create_super (path_loc, vis_loc); case IN: { lexer.skip_token (); @@ -2188,7 +2189,7 @@ Parser::parse_visibility () skip_token (RIGHT_PAREN); - return AST::Visibility::create_in_path (std::move (path)); + return AST::Visibility::create_in_path (std::move (path), vis_loc); } default: add_error (Error (t->get_locus (), "unexpected token %qs in visibility",