From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by sourceware.org (Postfix) with ESMTPS id F41D53858010 for ; Tue, 30 Jan 2024 12:10:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F41D53858010 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embecosm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org F41D53858010 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::32b ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616661; cv=none; b=LIOexUU9tPSu5GaWR9XgKqUsogfHWJFv45cmv97bUiuu0kS+HOsWpX4QbijwwtocwOD6jV/DHxQPYQK2YUKbX1cXqjJfEQTKW/6HrXzM79bQXIWC+jpQcinql+hjAikb7SE6uMla3u1q2ux7ZxJdUcyfm7B/n/yyL7G+UetTbRc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616661; c=relaxed/simple; bh=aSyWwnez/G5kPGp+NXGFQJGK0g60e21nwGoU2b1H2pc=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=JVVqCmgaEWPiOxiAQHBY2B573fQUaHIA5kulWWVBlTuymB+WM7/q7WdJTwOpLvX8yPxNsyBcBEtfd0Z8pbb7vCPMuGbHiWFTlGutPFlPVUVAYang9gEmGb2lApqqNl6eaxaYBebqybixfDKsvrSXiDpI0KvtOoFP+S50qVaLY2o= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-40e800461baso52289685e9.3 for ; Tue, 30 Jan 2024 04:10:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616655; x=1707221455; darn=gcc.gnu.org; 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=3BtTVOTTc+QSfGDQq3+cLC2DSjVbspRvC3zL2WUZErw=; b=Po8B1KXAWjDTtqlxHv0bSl7fNMuveNtyA159kXjfhHpMiKrWOVSbeqzqGRrKIkAC9x UwsvGIZH9tzO5fo9tu0KfmBLL6S7t/GmgHSHTRcYz6M4iuEPm7qQKmadc4XK7Y4cuOX/ GeBzmUU3ZSLXwms9gwDMlBO42cDjwE/dvDaSkJ2IIUwXxDEbxDxVZ6ALJeerhmuXnxkX OZlS58h8EhpcnqTM4y6R27mJ+t/4PMW0/JEs7D665i41Bytep8HJZBBYoBzhtuvUHDVe /cqmtAip8GIZTi9cwP+m3mDizFJLzuaiPlglMAfiukhaZfVl5kJugr8NhVfvXF7DMiKl 3Vdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616655; x=1707221455; 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=3BtTVOTTc+QSfGDQq3+cLC2DSjVbspRvC3zL2WUZErw=; b=Um9RIILmZd9y4xrJBwuj6if4IEeb5/jEkNuGOq4laRM+nRkvaLZf5ETqm+CV6r7eP3 r+QWwNOwbSM5pfiOWankXBquu+Kr8goy4DOBxD6hpOzvECfE7yGGVBTD13kN11e54Pf6 O6p5jJiEYw+dx3APmiNP4mq1zb2WZqtU/CADyHhmP93PB2ZOOdPn3KcUBtImg7fpMsCu wuuV3kOaXHJ9IcstO1WLEEbV3E4fDy43HHM1Z3N9pj1mnHy58YcoGPcOiCAiOZoK/phw /Oxf5fi1QXFewC+Xr7M72910XONl+GmdADfudJOz3K6QUsOQcXQeRQQzWNia0cLXfd5N WTvw== X-Gm-Message-State: AOJu0YwzDm+a+bH9b5zZ8E7WYpQTPl4GTNJ0/9Mx96pV+j6bZJuHlSfp uO59BZxShNspwa5zNIR6+YKv4ziNgzefZD3zjq4ievJ7i9ihOCAWJB8bn2KCN/11RdmiVC+DhYN QHQ== X-Google-Smtp-Source: AGHT+IFcBcbBNbhUGgJxmZYOUbLIYk6BYOGO7tbTPGDAkMdusWrkcjBpVJqVMPgIt8RDiGjh8CKLHA== X-Received: by 2002:a05:600c:4e91:b0:40e:490f:3f31 with SMTP id f17-20020a05600c4e9100b0040e490f3f31mr7055767wmq.35.1706616655754; Tue, 30 Jan 2024 04:10:55 -0800 (PST) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id f9-20020a056000036900b00339307d9d31sm10569894wrf.112.2024.01.30.04.10.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:10:55 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Arthur Cohen Subject: [COMMITTED 008/101] gccrs: forever-stack: Fix basic get logic Date: Tue, 30 Jan 2024 13:06:24 +0100 Message-ID: <20240130121026.807464-11-arthur.cohen@embecosm.com> X-Mailer: git-send-email 2.42.1 In-Reply-To: <20240130121026.807464-2-arthur.cohen@embecosm.com> References: <20240130121026.807464-2-arthur.cohen@embecosm.com> Reply-To: arthur.cohen@embecosm.com MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-14.1 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,T_SCC_BODY_TEXT_LINE 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: Arthur Cohen gcc/rust/ChangeLog: * resolve/rust-forever-stack.h: Improve resolve_path API. * resolve/rust-forever-stack.hxx: Likewise and fix implementation. --- gcc/rust/resolve/rust-forever-stack.h | 19 +++++++------ gcc/rust/resolve/rust-forever-stack.hxx | 38 ++++++++++++------------- 2 files changed, 29 insertions(+), 28 deletions(-) diff --git a/gcc/rust/resolve/rust-forever-stack.h b/gcc/rust/resolve/rust-forever-stack.h index 7ee08491987..349d0971f61 100644 --- a/gcc/rust/resolve/rust-forever-stack.h +++ b/gcc/rust/resolve/rust-forever-stack.h @@ -473,7 +473,7 @@ public: * @return a valid option with the NodeId if the path is present in the * current map, an empty one otherwise. */ - tl::optional resolve_path (const AST::SimplePath &path); + template tl::optional resolve_path (const P &path); std::string as_debug_string (); @@ -550,18 +550,19 @@ private: /* Helper types and functions for `resolve_path` */ - using SegIterator = std::vector::const_iterator; + template + using SegIterator = typename std::vector::const_iterator; Node &find_closest_module (Node &starting_point); - tl::optional - find_starting_point (const std::vector &segments, - Node &starting_point); + template + tl::optional> + find_starting_point (const std::vector &segments, Node &starting_point); - tl::optional - resolve_segments (Node &starting_point, - const std::vector &segments, - SegIterator iterator); + template + tl::optional resolve_segments (Node &starting_point, + const std::vector &segments, + SegIterator iterator); }; } // namespace Resolver2_0 diff --git a/gcc/rust/resolve/rust-forever-stack.hxx b/gcc/rust/resolve/rust-forever-stack.hxx index 5acdf06c770..806745eb908 100644 --- a/gcc/rust/resolve/rust-forever-stack.hxx +++ b/gcc/rust/resolve/rust-forever-stack.hxx @@ -208,15 +208,8 @@ ForeverStack::update_cursor (Node &new_cursor) } template -tl::optional -ForeverStack::get (const Identifier &name) -{ - return tl::nullopt; -} - -template <> inline tl::optional -ForeverStack::get (const Identifier &name) +ForeverStack::get (const Identifier &name) { tl::optional resolved_node = tl::nullopt; @@ -226,9 +219,9 @@ ForeverStack::get (const Identifier &name) return candidate.map_or ( [&resolved_node] (NodeId found) { - // macro resolving does not need to care about various ribs - they are - // available from all contexts if defined in the current scope, or an - // outermore one. so if we do have a candidate, we can return it + // for most namespaces, we do not need to care about various ribs - they + // are available from all contexts if defined in the current scope, or + // an outermore one. so if we do have a candidate, we can return it // directly and stop iterating resolved_node = found; @@ -278,9 +271,9 @@ ForeverStack::find_closest_module (Node &starting_point) /* If a the given condition is met, emit an error about misused leading path * segments */ +template static inline bool -check_leading_kw_at_start (const AST::SimplePathSegment &segment, - bool condition) +check_leading_kw_at_start (const S &segment, bool condition) { if (condition) rust_error_at ( @@ -297,9 +290,10 @@ check_leading_kw_at_start (const AST::SimplePathSegment &segment, // `super` segment, we go back to the cursor's parent until we reach the // correct one or the root. template -tl::optional::const_iterator> -ForeverStack::find_starting_point ( - const std::vector &segments, Node &starting_point) +template +tl::optional::const_iterator> +ForeverStack::find_starting_point (const std::vector &segments, + Node &starting_point) { auto iterator = segments.begin (); @@ -357,10 +351,11 @@ ForeverStack::find_starting_point ( } template +template tl::optional::Node &> ForeverStack::resolve_segments ( - Node &starting_point, const std::vector &segments, - std::vector::const_iterator iterator) + Node &starting_point, const std::vector &segments, + typename std::vector::const_iterator iterator) { auto *current_node = &starting_point; for (; !is_last (iterator, segments); iterator++) @@ -407,9 +402,14 @@ ForeverStack::resolve_segments ( } template +template tl::optional -ForeverStack::resolve_path (const AST::SimplePath &path) +ForeverStack::resolve_path (const P &path) { + // if there's only one segment, we just use `get` + if (path.get_segments ().size () == 1) + return get (path.get_final_segment ().as_string ()); + auto starting_point = cursor (); auto &segments = path.get_segments (); -- 2.42.1