From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by sourceware.org (Postfix) with ESMTPS id AFCC63857720 for ; Tue, 30 Jan 2024 12:12:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AFCC63857720 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 AFCC63857720 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::436 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616775; cv=none; b=r8a4aOO129igf+wjiFk548LoHjAHC+6yUZOC9KySklCixhCpLMZVSrB6CGwzPeizYP3sNETYTHLxauwzqnuaY6V+HdBSmEJ5qm9OdS43xnfJrCO9Y7CvPJ8LQomz8qTkvfbz3qmVW7NLRz6vrQUlPOknDw2UaOCQ//hiswYtycg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616775; c=relaxed/simple; bh=BbZT06Wyh0LNElHxaJSdP6W81PvlRZzmCuL4xsbB71Q=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=dvJpuLQEtD+PQhD9xwWJlzUQKuTI8ylHldDhKp66cwtO3ogLeq80a2QVD/7QPMnCGEAkGgxN3AzMhfxrqqi4umoh99qgUH+holULcaGXZn+V1eExLn75vSKqsO5Jq9oBMNij+8hFQhqg7BU0mRQxCaHkpqd2aMhsHuG831gTXes= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-337d05b8942so3297990f8f.3 for ; Tue, 30 Jan 2024 04:12:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616718; x=1707221518; 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=gqP0D+eKaqDsX+09aT8DebNlqQZnKLBDu1l86xZVAvQ=; b=bBtCoTJaBjAOT4iK4/iTlkwIAik2AXhy58zMKmlscGed6ss0sqAkaQe0TTYVK9tcvZ XdxcvuUu9Nbo+H5ZFogAJn+OtpWKitJYK/LegJzeEgLU2LnAZjZ8PoyvcssBVgjPZc5C xUG6N5XIClhPe5/bGaJk4jUQxzNdHLhUeMY0vI8T6xOSi1V80FdqpcIP4TK/5EbWaJl0 u/KblB5KrH1i2RFN03BYea/1GFWD0fgi3XFr1kQ39NJpax6/YovYqzVDpegaxfG+jHD3 GnMRg1KaCsz0Iyt+hju9DeX1tnaMJbGCkljXaRHa88CdFRDTJBrpfyLa7jk1FmtabEPv PDAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616718; x=1707221518; 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=gqP0D+eKaqDsX+09aT8DebNlqQZnKLBDu1l86xZVAvQ=; b=D+3nb0sdepI6DUza0h6JE9Rj4K0kJSQMvF/GlkDAU+YB/bwOb1BPNAfC5OAk7Q8Ne3 bszrhqDiOX3vq3zY995PvKhv3FDlZcsDQb5sH+lj/CUETN2GNOMMTvEQ88W9ci+qhtWh 4qn2O1opNuCd2ygSWCeEgVDnIZexRtoYdKteU00SENBETsqCTh4t9L4srDI9F3N0A+ir KELtQ2QMVHr57u138R81T4w5nLZ7yCgOvMDdem8JllocFdhxPmB60K+1m7BZFQRSD/cA mZX9xUNfmkNb4wICj1Ykyq6VXic2wj3BwKHAfKkZYrj6B0LlD1sxuh+wY3ewGaPQrR5i UDXA== X-Gm-Message-State: AOJu0YzqYJX6VFyj5FIFmEAsyR3ynVAiq44T9YZ14OYx9wvMMiWcGaQB AVWGWz6nDaYt6Cl04iDqOWuhdimS/LWiBtfxREAIxkCM7Oa0EiLSVMP/URmTBpyOQ4N3e3jNRJY 4OA== X-Google-Smtp-Source: AGHT+IGfESPyER3aPvsj0AGBXUJZiIGE0A+op6ySd4kWnr2RNXtPGDsPXfr7A28VFmniv3oMWQYn8g== X-Received: by 2002:adf:dd92:0:b0:33a:f3a5:37d1 with SMTP id x18-20020adfdd92000000b0033af3a537d1mr2976810wrl.29.1706616718157; Tue, 30 Jan 2024 04:11:58 -0800 (PST) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id f9-20020a056000036900b00339307d9d31sm10569894wrf.112.2024.01.30.04.11.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:57 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Jakub Dupak Subject: [COMMITTED 096/101] gccrs: AST: Fix for lifetime parsing Date: Tue, 30 Jan 2024 13:07:52 +0100 Message-ID: <20240130121026.807464-99-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.2 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: Jakub Dupak gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_where_clause): fix parsing (Parser::parse_where_clause_item): fix parsing (Parser::parse_type_bound_where_clause_item): fix parsing (Parser::parse_trait_bound): fix parsing * parse/rust-parse.h: fix parsing Signed-off-by: Jakub Dupak --- gcc/rust/parse/rust-parse-impl.h | 37 ++++++++++++++++++++------------ gcc/rust/parse/rust-parse.h | 6 ++++-- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index c14c75ce70d..7ea7276dc94 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -3756,6 +3756,10 @@ Parser::parse_where_clause () * so won't be here */ std::vector> where_clause_items; + std::vector for_lifetimes; + if (lexer.peek_token ()->get_id () == FOR) + for_lifetimes = parse_for_lifetimes (); + /* HACK: where clauses end with a right curly or semicolon or equals in all * uses currently */ const_TokenPtr t = lexer.peek_token (); @@ -3763,7 +3767,7 @@ Parser::parse_where_clause () && t->get_id () != EQUAL) { std::unique_ptr where_clause_item - = parse_where_clause_item (); + = parse_where_clause_item (for_lifetimes); if (where_clause_item == nullptr) { @@ -3791,7 +3795,8 @@ Parser::parse_where_clause () * commas. */ template std::unique_ptr -Parser::parse_where_clause_item () +Parser::parse_where_clause_item ( + const std::vector &outer_for_lifetimes) { // shitty cheat way of determining lifetime or type bound - test for // lifetime @@ -3800,7 +3805,7 @@ Parser::parse_where_clause_item () if (t->get_id () == LIFETIME) return parse_lifetime_where_clause_item (); else - return parse_type_bound_where_clause_item (); + return parse_type_bound_where_clause_item (outer_for_lifetimes); } // Parses a lifetime where clause item. @@ -3834,12 +3839,10 @@ Parser::parse_lifetime_where_clause_item () // Parses a type bound where clause item. template std::unique_ptr -Parser::parse_type_bound_where_clause_item () +Parser::parse_type_bound_where_clause_item ( + const std::vector &outer_for_lifetimes) { - // parse for lifetimes, if it exists - std::vector for_lifetimes; - if (lexer.peek_token ()->get_id () == FOR) - for_lifetimes = parse_for_lifetimes (); + std::vector for_lifetimes = outer_for_lifetimes; std::unique_ptr type = parse_type (); if (type == nullptr) @@ -3853,6 +3856,13 @@ Parser::parse_type_bound_where_clause_item () return nullptr; } + if (lexer.peek_token ()->get_id () == FOR) + { + auto for_lifetimes_inner = parse_for_lifetimes (); + for_lifetimes.insert (for_lifetimes.end (), for_lifetimes_inner.begin (), + for_lifetimes_inner.end ()); + } + // parse type param bounds if they exist std::vector> type_param_bounds = parse_type_param_bounds (); @@ -4029,6 +4039,11 @@ Parser::parse_trait_bound () location_t locus = lexer.peek_token ()->get_locus (); + /* parse optional `for lifetimes`. */ + std::vector for_lifetimes; + if (lexer.peek_token ()->get_id () == FOR) + for_lifetimes = parse_for_lifetimes (); + // handle trait bound being in parentheses if (lexer.peek_token ()->get_id () == LEFT_PAREN) { @@ -4043,12 +4058,6 @@ Parser::parse_trait_bound () lexer.skip_token (); } - /* parse for lifetimes, if it exists (although empty for lifetimes is ok to - * handle this) */ - std::vector for_lifetimes; - if (lexer.peek_token ()->get_id () == FOR) - for_lifetimes = parse_for_lifetimes (); - // handle TypePath AST::TypePath type_path = parse_type_path (); diff --git a/gcc/rust/parse/rust-parse.h b/gcc/rust/parse/rust-parse.h index 3fc86206de7..02f90217fc2 100644 --- a/gcc/rust/parse/rust-parse.h +++ b/gcc/rust/parse/rust-parse.h @@ -288,11 +288,13 @@ private: std::unique_ptr parse_function_param (); std::unique_ptr parse_function_return_type (); AST::WhereClause parse_where_clause (); - std::unique_ptr parse_where_clause_item (); + std::unique_ptr parse_where_clause_item ( + const std::vector &global_for_lifetimes); std::unique_ptr parse_lifetime_where_clause_item (); std::unique_ptr - parse_type_bound_where_clause_item (); + parse_type_bound_where_clause_item ( + const std::vector &global_for_lifetimes); std::vector parse_for_lifetimes (); template std::vector> -- 2.42.1