From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by sourceware.org (Postfix) with ESMTPS id 1EF8C3857001 for ; Wed, 5 Apr 2023 14:06:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1EF8C3857001 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-x32f.google.com with SMTP id o32so20950123wms.1 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=bB5PhxYXmglBNgOlT6Xqf8GMb7vTCSRiiTiRZZ7p9GRKuuAHQzGhM9jMUd5rnsSN4H wgS9LyCNkJBCNFTgejyA6L/LoN6mHlLSWhKBnRoYpRiki1bB+iFBOUejDGo7Yg2E2AGs 6nPu9Vwe+0gR7QzTESqs1hfvopj1fQbs9AE9Fs1R3yIpoQctivbIPAf/49LQY7WThaLX JNwCoHxvxn+KXuiII0E8boLapjKRt6CXfDLSYqFZEPP8WCFKaDZqCUgeAYw/lZ6b8yaW aSgZpmZPjk/7ZszDwAZSWjFgeZZDuwuGc3ZFYzwwhYg/+C6z74BvLoHrPorzf5NFocTQ AFwA== X-Gm-Message-State: AAQBX9eLhW38un3TFoYDfDitjOAmqForfLpNyP555pxNdKQW/wexRlYD 1MFtcr90SynWIFvwFiUCkl7dboCk3yEOglDkHA== X-Google-Smtp-Source: AKy350YVao/y9CQcYdWpTdavFHU64A612oU6IHA5o/MI0NrVhZQEZqPNRQzkqb0/W8oHWO1OGXvahg== 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> Reply-To: arthur.cohen@embecosm.com MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 List-Id: 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 ()); -- 2.40.0