From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by sourceware.org (Postfix) with ESMTPS id 5E4A4382CD77 for ; Tue, 21 Feb 2023 12:04:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5E4A4382CD77 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-x42a.google.com with SMTP id c12so4165245wrw.1 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=fNLp70Be8K/ffLKf8HrAe6Mh8zF4DDK6eDmCCYpHANJFyEiZGLlHlEKQGrb/Syykqo 2G8wXxnki/sYAkDIozFLHvhVcgWj6yCDgFHOyuIWZnokuzIFApqb6trfRIqnNmryJiyk v9eYLa7+jn5F59JriEK6n6UgK/5akBhSP3D/LMsk76Kias2oasnwzLubbD1Wgk06QrQS h51XhV1C4Kx4ac/vP0xnJi1/4suK2PUFREssiKqE+ZA0z4yj0Dzo3goYVjICt92373/D l7T7cM7DqfX5FJ1L9w2jEvKjuj7WmRPTMWr7rgjwD725i9hUupidcXl0UrgTYroxDgro 9gdg== X-Gm-Message-State: AO0yUKWo/2LdgRkZKpwRYm9eylZEBNv1ZhygJh88cjQNuw1hO+u03+5X YPRH3NuWtVc1KvdjEKGukXuo X-Google-Smtp-Source: AK7set8hOaMj7gqwozJ8G3gnqRf/VFxu2ijtovwY/FjgcUAPBC+bFB+Nir0cvEtmVyTx+GvxYHgAEA== 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> Reply-To: arthur.cohen@embecosm.com MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-14.7 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=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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", -- 2.39.1