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: 79720 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp363670vqo; Wed, 5 Apr 2023 07:48:48 -0700 (PDT) X-Google-Smtp-Source: AKy350bKUkj4rbu+NhjVaoalanOtm9IdSu+uBTCOvqGygcbuZAl/fLyxthkCBuu4eDmX5qbHPZHE X-Received: by 2002:a17:907:d603:b0:931:af6a:ad08 with SMTP id wd3-20020a170907d60300b00931af6aad08mr3513515ejc.57.1680706128218; Wed, 05 Apr 2023 07:48:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680706128; cv=none; d=google.com; s=arc-20160816; b=EOPlXENCoP0IPk9pL3198jezQeKngDKW3vjqB2KDrmgLOcJunRxZLOy1RumHWSHubV x0d9pVMU1WOWhNNvfMGJtxHeDAEu/Wwj2Y/Q158NNvJlOHjgrArJWD48DNMSTOPJM3oB So5EAC4ldeSQXpAbX/TaSG5lRNMTgeJ2NS/oJjedTJmRRIUm+nwEIyY2ckVZpSvYH7fK hwUwUERYBS0zqMM8l6MTIwUZUQ0enD2lKrcADqyjf297kEC+siv2Bn4nasL2RDEAlQqQ 1F3BTApqoIpZ7YsioVsao+CxfDxg7Tu0lsxveSXx02AyldvCxuD/N0c7qskr7DJrITYT yOeQ== 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=Wo1xvsr0lThgNUep0EPVvbCx0o8feDezVrKYU1Cu0UY=; b=g+zB1aCrdwv6eNkIAKy5i8xOYvqnAA/xKxdZXgpQtUqLR8pzP0Ve9lgQUZVyYilbmr yCMwiNU/I4oZb9cV+b4DRDSXhepmTYq6Gu/JXY+LxpLfSs+ephTcS37YBSKD+V5PWjSX 6ANonVsEaiuM+umzzEzsYqmA449Rj2eQTCBec457yInmIUtMfMBclSMIpvquYh6xR+oD wuVwkPwediSguvHbOBzDhlbvHGLt//ZjgZnPvIRkBNxFRy8TOcB9Fa7BLd69Lt4Fxh4J FDUX/5ULs24B7fRvFxSfu4ULuUzGc2qqoM0gH0FnRB6UEyFkM35MtEyAIBEgDHN7DOgV TENw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=Wna9hKCr; 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id hs3-20020a1709073e8300b009269fbb187csi14089124ejc.304.2023.04.05.07.48.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:48:48 -0700 (PDT) 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=Wna9hKCr; 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 3010E386DE9A for ; Wed, 5 Apr 2023 14:17:42 +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-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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762348108805094757?= X-GMAIL-MSGID: =?utf-8?q?1762348108805094757?= 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;