From patchwork Thu Aug 1 14:56:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1967738 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org 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=XxC7Z9qN; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WZXRT6YvKz1ybX for ; Fri, 2 Aug 2024 01:08:53 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 26D8C385E839 for ; Thu, 1 Aug 2024 15:08:52 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-lf1-x129.google.com (mail-lf1-x129.google.com [IPv6:2a00:1450:4864:20::129]) by sourceware.org (Postfix) with ESMTPS id 60146385C6C6 for ; Thu, 1 Aug 2024 14:58:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 60146385C6C6 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 60146385C6C6 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::129 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722524336; cv=none; b=mTVESGqePQwSjEU6mgyeUWtFMa6tzLqAVmxWlzvD2iXizPm/xhfpiaJDmfNvFj79JJMbAPXbg8MQk+CLHUCDmHc45z/4LY/rN4bow1HwR3b0I2S2F/0FuHvnm1sqX8aH/Bh44ZnipFyOe3ujHgEnrYrwT7lotLIAll3TU105ORk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722524336; c=relaxed/simple; bh=K7gptbryDz1trNwjDX/6HbDDRxdotNxXEXj64CLvnjM=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=JJFvwhgr1gdzd3U61VP1+RE/lS5h6aGKgROlgmNZ7/dBR7Z9fqJlquyPBMnBJaDL0Dj1LJVmeYTUoUzSpblVkB6v3yeG6EGe7zOUyrIgJC1ogh+HLwH73A+C3qDHtNrEIwp5lBw/zFmF74dovJCj7Ktyz5eZlA0nd/3Is6TEX6I= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lf1-x129.google.com with SMTP id 2adb3069b0e04-52f025bc147so9932984e87.3 for ; Thu, 01 Aug 2024 07:58:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1722524322; x=1723129122; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=KJOiRRLF7wKoicjZt5vY+xhv3TZIawj5eCEzT35ebYQ=; b=XxC7Z9qNC4HIjBIpJ3Z8CHm6mWYBes0suQz1F1+0gqj1B9FH1jt0K1/2shbj6xOtL6 gKOpf8SYCZ3Ph9IAx1k8CDFvW81wbtPcqw02jtYpWGaMIPjNmLBAlgM/G2Pegf+caZwP RgHlSrH5fOAKf5bbSekdTAa7kT8yCsaxj7keOxPFA7Vq0amBKSvas1vKX9/HQgS+ANHQ VGBdZpK9mbtV/3ewRFY4exYD8YFO4X55BdgL2tw8+L2J9h3NXSjmI1gLQpsimclp7d9z 1OWxCVvT6/MjPAVBBBB7wn3Ta/IELDMNHM4AwBdhwG5QF6AzcYcRpqkX+0ACupFI8tHD 5wvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722524322; x=1723129122; h=content-transfer-encoding:mime-version: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=KJOiRRLF7wKoicjZt5vY+xhv3TZIawj5eCEzT35ebYQ=; b=ZXRuTLqqncOfQ4uJutCF2q37IfCuKeiAWAzD1BJbpvfrjFiXdZXpwd3aDMovuGX6ss p6rsoX850TcdbYNR3g0Fkfp4nR4zdVzAd2WsFfAJMnzRE7mkOWyHpooGGvVaUmsslnNT vpjepMKW4J7HB/1AEPDcO6QjzjFIlK66Gaf/JYNE9H0IZm2O54jY8lkQCDZCiFYGq8ed ovemAwnkM6ydIH5WnwI0DDuZLiR66nA0IA6+AvObJ3eKQbqBnZ2/ybG+Uh0bThWI5dF0 TPnZ4qOcpsLyfRqgKG29Bm5P6eWTzSDYZlYlt0f5BTu9JNYbJPxoQomJ+6l/3NmW+PQv EWTQ== X-Gm-Message-State: AOJu0YyAFpsiKcMxONtm8/7/op8diIUWI07v3F/j2s5eRgmxRCK9xqfY lA4DjYROGczIt9fbgxJgfTs6If31jcxdpHAMLt7ubq9Xafpm/yDFvbSn8UFDJ8nc3rZuAgtot7s cvokM X-Google-Smtp-Source: AGHT+IHcFL0Ep8jGoG3QYoVnFxUPqUeKJKP7fj9VW6j/3NrIXAAXjcd2U6CSFsbQcNrEcSZEyuzVyg== X-Received: by 2002:a05:6512:3996:b0:52c:c9ce:be8d with SMTP id 2adb3069b0e04-530bb39bf1dmr70845e87.57.1722524322489; Thu, 01 Aug 2024 07:58:42 -0700 (PDT) Received: from platypus.lan ([2a04:cec2:9:dc84:3622:6733:ff49:ee91]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5ac63590592sm10252456a12.25.2024.08.01.07.58.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Aug 2024 07:58:41 -0700 (PDT) From: Arthur Cohen To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Arthur Cohen Subject: [PATCH 015/125] gccrs: format_args: Parse format string properly Date: Thu, 1 Aug 2024 16:56:11 +0200 Message-ID: <20240801145809.366388-17-arthur.cohen@embecosm.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240801145809.366388-2-arthur.cohen@embecosm.com> References: <20240801145809.366388-2-arthur.cohen@embecosm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-13.8 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org gcc/rust/ChangeLog: * expand/rust-macro-builtins.cc (MacroBuiltin::format_args_handler): Construct string to parser properly. --- gcc/rust/expand/rust-macro-builtins.cc | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/gcc/rust/expand/rust-macro-builtins.cc b/gcc/rust/expand/rust-macro-builtins.cc index 0e57406f10f..19ea9109453 100644 --- a/gcc/rust/expand/rust-macro-builtins.cc +++ b/gcc/rust/expand/rust-macro-builtins.cc @@ -947,7 +947,24 @@ tl::optional MacroBuiltin::format_args_handler (location_t invoc_locus, AST::MacroInvocData &invoc) { - Fmt::Pieces::collect ("heyo this {is} what I {} want to {3}, {parse}"); + auto fmt_expr + = parse_single_string_literal (BuiltinMacro::FormatArgs, + invoc.get_delim_tok_tree (), invoc_locus, + invoc.get_expander ()); + + if (!fmt_expr) + return AST::Fragment::create_error (); + + // if it is not a literal, it's an eager macro invocation - return it + if (!fmt_expr->is_literal ()) + { + auto token_tree = invoc.get_delim_tok_tree (); + return AST::Fragment ({AST::SingleASTNode (std::move (fmt_expr))}, + token_tree.to_token_stream ()); + } + + auto format_string = fmt_expr->as_string (); + auto pieces = Fmt::Pieces::collect (format_string); return AST::Fragment::create_empty (); }