From patchwork Wed Apr 5 14:03:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1765485 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=embecosm.com header.i=@embecosm.com header.a=rsa-sha256 header.s=google header.b=Wna9hKCr; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Ps6HH2XQzz1yZT for ; Thu, 6 Apr 2023 00:20:43 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7E34F395B41A for ; Wed, 5 Apr 2023 14:17:13 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by sourceware.org (Postfix) with ESMTPS id 2D40F3856DD4 for ; Wed, 5 Apr 2023 14:06:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2D40F3856DD4 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-x42d.google.com with SMTP id j24so36393424wrd.0 for ; Wed, 05 Apr 2023 07:06:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703569; 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=Wo1xvsr0lThgNUep0EPVvbCx0o8feDezVrKYU1Cu0UY=; b=Wna9hKCreUiVK3h3+9Zka5cRD6KjNFv3N/DRZjeK8cN9BoS8MGLzytLxlu5l8panJg 9kzMEhLuFKAiNO5eln1251m8kYknC3JHv4U2yYEQLBF9i7f8rOlxm+nBPxU4htaifIwV AuOnK/8ahgchasHXGXf2vh/7iexJYYT4zYuQqlVTNzp/HAzv5do9aEqH+7B3m161hOJ+ Klsk3GFkp1+0jVPHUq+2QXNeqgLlg5SNIJvmIPWXakuAJeao0ZrhzTcEW2VudU+KKItW Dg/0gmRgi1NtK8o/wLr4of5uwFSedXkcvD6Q04V3SzhTlrCM69D2RDeuwLEGHeipF5MZ QC6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703569; 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=Wo1xvsr0lThgNUep0EPVvbCx0o8feDezVrKYU1Cu0UY=; b=fa6JWKndjxwwNuQYkQ+Cuop6gzxB/4HuPjZc98KwrO2kqWGizgz0TMaqtCgHUcMGYT fQUscecJ5HU0MM+uu8wYa4+M22zeqwtZy4iQ0nBprUKFCtsgh8IycTBnUdW0FFBgBbs+ k8PKvGy89PCiTcmt1XdhmC+w0EMx/jswYmQwN/pWP8ibNQu0cnWViwePVjlgKhOOnHCV iIuC64l+n8Rb/qqAV659KbcymLKhJW6AjZkaVxa2XYpZTyEcHrRwy1Yk3+knF+09GV44 zh+/nsHvBVnRXl4f5pMg2MaVa/33jS94luJ8pwa/+XF/UmOVqVMh/VQu22sCkEJRy922 652w== X-Gm-Message-State: AAQBX9eFfwNvuSESr845m5mNn+1Xvqe0mTdRU1dxEBTUpfoHFH7ytJLQ Euf4KumVKq61MerzQ+gJ7+NAv13RcGDMvQbfXA== X-Google-Smtp-Source: AKy350YBriUy/wzZNZfb5bBqbM/6DKj8d9XRXfQpocN/kOitXYNeq7hiasTJdBZwm3+ihqv8n2jh9w== X-Received: by 2002:a5d:510c:0:b0:2cf:eb86:bd90 with SMTP id s12-20020a5d510c000000b002cfeb86bd90mr4039432wrt.63.1680703569457; Wed, 05 Apr 2023 07:06:09 -0700 (PDT) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id ay8-20020a05600c1e0800b003edddae1068sm2330150wmb.9.2023.04.05.07.06.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:06:09 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Arthur Cohen Subject: [committed 59/88] gccrs: expansion: Add `get_token_slice` to `MacroInvocLexer` class Date: Wed, 5 Apr 2023 16:03:43 +0200 Message-Id: <20230405140411.3016563-60-arthur.cohen@embecosm.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230405140411.3016563-1-arthur.cohen@embecosm.com> References: <20230405140411.3016563-1-arthur.cohen@embecosm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-14.6 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 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+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" From: Arthur Cohen gcc/rust/ChangeLog: * expand/rust-macro-invoc-lexer.cc (MacroInvocLexer::get_token_slice): Add API to retrieve token slices when lexing macro expansions. * expand/rust-macro-invoc-lexer.h: Declare `get_token_slice`. --- gcc/rust/expand/rust-macro-invoc-lexer.cc | 14 ++++++++++++++ gcc/rust/expand/rust-macro-invoc-lexer.h | 3 +++ 2 files changed, 17 insertions(+) diff --git a/gcc/rust/expand/rust-macro-invoc-lexer.cc b/gcc/rust/expand/rust-macro-invoc-lexer.cc index 8a43d29e0d1..321f0f97a76 100644 --- a/gcc/rust/expand/rust-macro-invoc-lexer.cc +++ b/gcc/rust/expand/rust-macro-invoc-lexer.cc @@ -26,4 +26,18 @@ MacroInvocLexer::split_current_token (TokenId new_left __attribute__ ((unused)), // FIXME gcc_unreachable (); } + +std::vector> +MacroInvocLexer::get_token_slice (size_t start_idx, size_t end_idx) const +{ + std::vector> slice; + + rust_assert (end_idx < token_stream.size ()); + + for (size_t i = start_idx; i < end_idx; i++) + slice.emplace_back (token_stream[i]->clone_token ()); + + return slice; +} + } // namespace Rust diff --git a/gcc/rust/expand/rust-macro-invoc-lexer.h b/gcc/rust/expand/rust-macro-invoc-lexer.h index a0d30164850..0923c18c84d 100644 --- a/gcc/rust/expand/rust-macro-invoc-lexer.h +++ b/gcc/rust/expand/rust-macro-invoc-lexer.h @@ -55,6 +55,9 @@ public: size_t get_offs () const { return offs; } + std::vector> + get_token_slice (size_t start_idx, size_t end_idx) const; + private: size_t offs; std::vector> token_stream;