From patchwork Wed Apr 5 14:03:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 79691 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp355380vqo; Wed, 5 Apr 2023 07:35:53 -0700 (PDT) X-Google-Smtp-Source: AKy350YzBAksrk6db2qbBEb6+piXMq9YKR2dRxz+G0tUn68+y6KgDMM+IpexUy/YH1/51sHdEXhe X-Received: by 2002:a17:906:e1b:b0:87b:d3f3:dcf3 with SMTP id l27-20020a1709060e1b00b0087bd3f3dcf3mr2916302eji.35.1680705353595; Wed, 05 Apr 2023 07:35:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680705353; cv=none; d=google.com; s=arc-20160816; b=r5kkK1SepS+qCOHPx9WAPgf3Fn99l6sZ8k20i8weeW+kaSCiXonyFmgdk5syFWlNrj 3hJ+RBrMERu6srGR+HfZyab8IuNRQlJe08KzHeD6xWNXtMrlNtrEzj7d+kDLbCpc27wG wEf7QEYaeqifADI2/JIx7FNLFs5AVAkyAvBwWZVjI1EdG1VTaEDyIJ32UJe64GUgP0om h/CE8sfPKPBAevzGwR2uS54gq6d3yt77r9IAAx+9KlWa00GQyQ7HNmHbLCutQSJRQdf8 ZcIPte/Wb2XzMe1NCw4LN2cXr9QY/8pQuZvzaoPqduGXdJ40DLrrQb4H2rzQxemaO/4c tTpQ== 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=8b32RuoybSkyTRQ0LtyuiJsCvJja3So0VmvYcWED2Vc=; b=E25tstX8s1IT0rU62VKRm3vgabOF9aTyt7WKJr5aB1RnI7DiAEkt4m2d/At2uG4SEV 2DAhd7JU/XNm4ZXU8QhNt23qRyNIzEAwxYOMqsxGv6xcrNflsUj+SC2/ZpnmxgG1TMAK vjAACWkRnlIAnoPFN7LGrVq1tocafsCMxl9PNvoDT0Bzz7Oz5f+naOpDqPRpCJNZTosi qXLaKbjGdRKAxucv0hiGlMHjYsG//eyBS91SLV+9uQohAjZWBy4MPUyCaj0dYunpAb1a 2BaOnSOiNcyzlpF3lUK+5d56qfwptZ/23y2MyF72IP5WA6l3/oiD7cD9sVWh+fHuhdlr dAJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=DLUuNkn7; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id q17-20020a170906145100b0094779d354efsi526253ejc.941.2023.04.05.07.35.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:35:53 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=DLUuNkn7; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 997E438DCF2B for ; Wed, 5 Apr 2023 14:13:41 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by sourceware.org (Postfix) with ESMTPS id 617973857006 for ; Wed, 5 Apr 2023 14:06:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 617973857006 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-wm1-x32c.google.com with SMTP id i5-20020a05600c354500b003edd24054e0so23810660wmq.4 for ; Wed, 05 Apr 2023 07:06:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703570; 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=8b32RuoybSkyTRQ0LtyuiJsCvJja3So0VmvYcWED2Vc=; b=DLUuNkn7v03y0w2TAT6sIXa4PnmIhp/XmtvJYzO1ajYjjmwJLDOYXHh1zMLDNR8n75 Cpqv8UBvl42xvBP8Qlh/mrTzUGeQuKqAT+V/HRcVs3bYjXR96ha1J/U9BPQezG8fVSyP TnBqb56Os5AKpGEpL4BO/sqvz+Fqwnx/xZfyg7XSQjKZ5eFdgay3cyojJAdp/TAOoL2d G1wmtNErz67zNiA02tf0yI0vXO1S+89gakZmwpRkvYxqZK7vUS+RaKMOtdJL5YAQxaA1 /hyp3J2qwAjQOkS2XdG394PxRI280bv8dwjkIjJ3j1bLf+8IB2VVKfyRbMpTBb6as3DS WSzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703570; 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=8b32RuoybSkyTRQ0LtyuiJsCvJja3So0VmvYcWED2Vc=; b=LuqOkje+vwi+8F6wPuSnWk6fZk3Dmx7t7+OSrysnomBJ/RWzzu7f8iL0k+rTQPsOgL jaAhIj/ORCGNJEjZX2TUzo7RCN9bbzIZjm0y7p+4iFK6eJVT78XMVnO2OB0hYaKBoAsm 3PxqDzB9/9vMwD9yzC38iR2Pg2vzMcXKzY8k5OaQCP7dsuJWB/s96A5NEvoiYqv34353 RwsaVIZt/tFMS8f0h1oBLxAsrvE0iLgbvAeTubCGouI8RuE8gqWdluwzvjebikEPegil TXq2GmLkazhUdWP5CEJoofHJe/Kyln7r/9jA1K0aNdeB31LPXEhEYqzVliJY6OgX5OQh C+GQ== X-Gm-Message-State: AAQBX9foMP2nUWtnqo+VUb3Gk67HG3fUD9ZAbDmLSoMWFDC5+pkXgK7t Kh67WrQJajuIhObxoZfueQv1zUh5x3PX/SSwEA== X-Received: by 2002:a1c:f218:0:b0:3ef:6eeb:c25a with SMTP id s24-20020a1cf218000000b003ef6eebc25amr4700855wmc.6.1680703570741; Wed, 05 Apr 2023 07:06:10 -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.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:06:10 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Arthur Cohen Subject: [committed 61/88] gccrs: expander: Add documentation for `expand_eager_invocations` Date: Wed, 5 Apr 2023 16:03:45 +0200 Message-Id: <20230405140411.3016563-62-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?1762347296801380915?= X-GMAIL-MSGID: =?utf-8?q?1762347296801380915?= From: Arthur Cohen gcc/rust/ChangeLog: * expand/rust-macro-expand.cc (MacroExpander::expand_eager_invocations): Add documentation explaining the algorithm. --- gcc/rust/expand/rust-macro-expand.cc | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/gcc/rust/expand/rust-macro-expand.cc b/gcc/rust/expand/rust-macro-expand.cc index 0ff849dc85d..4b494490424 100644 --- a/gcc/rust/expand/rust-macro-expand.cc +++ b/gcc/rust/expand/rust-macro-expand.cc @@ -197,17 +197,25 @@ MacroExpander::expand_eager_invocations (AST::MacroInvocation &invoc) auto start = kv.first.first; auto end = kv.first.second; - // TODO: Add doc + // We're now going to re-add the tokens to the invocation's token tree. + // 1. Basically, what we want to do is insert all tokens up until the + // beginning of the macro invocation (start). + // 2. Then, we'll insert all of the tokens resulting from the macro + // expansion: These are in `new_tokens`. + // 3. Finally, we'll do that again from + // the end of macro and go back to 1. + for (size_t i = current_idx; i < start; i++) new_stream.emplace_back (stream[i]->clone_token ()); - // TODO: Add doc for (auto &tok : new_tokens) new_stream.emplace_back (tok->clone_token ()); current_idx = end; } - // TODO: Add doc + + // Once all of that is done, we copy the last remaining tokens from the + // original stream for (size_t i = current_idx; i < stream.size (); i++) new_stream.emplace_back (stream[i]->clone_token ());