From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7905) id 3EC753857809; Tue, 16 Jan 2024 18:10:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3EC753857809 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1705428645; bh=rEHg4JURYzmOtUBn0HcoAspL7BIpFxbOGlw3xV/FoYU=; h=From:To:Subject:Date:From; b=ZayJ/jsnyiRqKizZNrK6g1NoRS293xAmqQUiBPYu7yHW8mykupxk56dJ1t/5zWX07 STZhR4EdRngLR7Gkx3qeg969ypDkQNSnNPFxlNwuf5221lQ154WRT7fDCxDd+W7Ka8 LShfnBOMwiHtgssSMTs5kpAZED4u95oA4LfTIwxY= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Arthur Cohen To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-7981] gccrs: Add proc macro ast representation X-Act-Checkin: gcc X-Git-Author: Pierre-Emmanuel Patry X-Git-Refname: refs/heads/trunk X-Git-Oldrev: 47886454483eefc4dc2f0e82dd3e19173a7bf357 X-Git-Newrev: 7c265ce70b5104b6c6ea2ec0efe3b0f47ea0bbb8 Message-Id: <20240116181045.3EC753857809@sourceware.org> Date: Tue, 16 Jan 2024 18:10:45 +0000 (GMT) List-Id: https://gcc.gnu.org/g:7c265ce70b5104b6c6ea2ec0efe3b0f47ea0bbb8 commit r14-7981-g7c265ce70b5104b6c6ea2ec0efe3b0f47ea0bbb8 Author: Pierre-Emmanuel Patry Date: Mon Jul 31 18:26:40 2023 +0200 gccrs: Add proc macro ast representation When resolving proc macros it is convenient to store every macro directly in the extern crate. These class in the ast module provide a better abstraction over the raw ProcMacro::{CustomDerive, Bang, Attribute} structures provided by the proc_macro library. gcc/rust/ChangeLog: * ast/rust-ast.h (class BangProcMacro): Add new proc macro abstraction. (class AttributeProcMacro): Likewise. (class CustomDeriveProcMacro): Likewise. Signed-off-by: Pierre-Emmanuel Patry Diff: --- gcc/rust/ast/rust-ast.h | 65 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h index 136da86525d..b78c4291e7a 100644 --- a/gcc/rust/ast/rust-ast.h +++ b/gcc/rust/ast/rust-ast.h @@ -1950,6 +1950,71 @@ public: } }; +class BangProcMacro +{ +private: + std::string name; + NodeId node_id; + ProcMacro::BangMacro macro; + +public: + BangProcMacro (ProcMacro::Bang macro) + : name (macro.name), + node_id (Analysis::Mappings::get ()->get_next_node_id ()), + macro (macro.macro) + {} + + const std::string &get_name () const { return name; } + + NodeId get_node_id () const { return node_id; } + + ProcMacro::BangMacro get_handle () const { return macro; } +}; + +class AttributeProcMacro +{ +private: + std::string name; + NodeId node_id; + ProcMacro::AttributeMacro macro; + +public: + AttributeProcMacro (ProcMacro::Attribute macro) + : name (macro.name), + node_id (Analysis::Mappings::get ()->get_next_node_id ()), + macro (macro.macro) + {} + + const std::string &get_name () const { return name; } + + NodeId get_node_id () const { return node_id; } + + ProcMacro::AttributeMacro get_handle () const { return macro; } +}; + +class CustomDeriveProcMacro +{ +private: + std::string trait_name; + std::vector attributes; + NodeId node_id; + ProcMacro::CustomDeriveMacro macro; + +public: + CustomDeriveProcMacro (ProcMacro::CustomDerive macro) + : trait_name (macro.trait_name), + attributes (macro.attributes, macro.attributes + macro.attr_size), + node_id (Analysis::Mappings::get ()->get_next_node_id ()), + macro (macro.macro) + {} + + const std::string &get_trait_name () const { return trait_name; } + + NodeId get_node_id () const { return node_id; } + + ProcMacro::CustomDeriveMacro get_handle () const { return macro; } +}; + // A crate AST object - holds all the data for a single compilation unit struct Crate {