From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1643) id 039AA38983BC; Mon, 5 Dec 2022 09:52:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 039AA38983BC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1670233977; bh=qqUpWTPHigURFJPiXSvT/IYMoLLk9IXBjTr3XmyduXk=; h=From:To:Subject:Date:From; b=bdYMfe/fJNE2W6fHLsAjMqlPBJKFpMT6F6W5YYQl/Sqjv8pCn2tiTbQ80HMm5J9Nt 2eTwLQVfqHMhzR0YcKRz2gCxahvuncmn6EmueTOsdnLnkvOEQ9Y66XeKmaUigxB1Qs NxfVeO2IDV8OYuy1253IRDrLuUGW6S9J3ae8XFgo= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Thomas Schwinge To: gcc-cvs@gcc.gnu.org Subject: [gcc/devel/rust/master] Get rid of make builtin macro X-Act-Checkin: gcc X-Git-Author: Philip Herron X-Git-Refname: refs/heads/devel/rust/master X-Git-Oldrev: 22329b03a6e0a3381d907745205012cf290b3c2a X-Git-Newrev: d07cae9e4b4402a19c5a1371c09d899002362d5d Message-Id: <20221205095257.039AA38983BC@sourceware.org> Date: Mon, 5 Dec 2022 09:52:57 +0000 (GMT) List-Id: https://gcc.gnu.org/g:d07cae9e4b4402a19c5a1371c09d899002362d5d commit d07cae9e4b4402a19c5a1371c09d899002362d5d Author: Philip Herron Date: Fri Oct 21 13:01:43 2022 +0100 Get rid of make builtin macro This macro is a mess and a helper method is much better for this case. Diff: --- gcc/rust/resolve/rust-name-resolver.cc | 87 ++++++++++++++++------------------ gcc/rust/resolve/rust-name-resolver.h | 7 +-- 2 files changed, 46 insertions(+), 48 deletions(-) diff --git a/gcc/rust/resolve/rust-name-resolver.cc b/gcc/rust/resolve/rust-name-resolver.cc index ba8c1a821e3..ed7cc769cfb 100644 --- a/gcc/rust/resolve/rust-name-resolver.cc +++ b/gcc/rust/resolve/rust-name-resolver.cc @@ -19,40 +19,17 @@ #include "rust-name-resolver.h" #include "rust-ast-full.h" -#define MKBUILTIN_TYPE(_X, _R, _TY) \ - do \ - { \ - AST::PathIdentSegment seg (_X, Linemap::predeclared_location ()); \ - auto typePath = ::std::unique_ptr ( \ - new AST::TypePathSegment (::std::move (seg), false, \ - Linemap::predeclared_location ())); \ - ::std::vector< ::std::unique_ptr > segs; \ - segs.push_back (::std::move (typePath)); \ - auto builtin_type \ - = new AST::TypePath (::std::move (segs), \ - Linemap::predeclared_location (), false); \ - _R.push_back (builtin_type); \ - tyctx->insert_builtin (_TY->get_ref (), builtin_type->get_node_id (), \ - _TY); \ - mappings->insert_node_to_hir (builtin_type->get_node_id (), \ - _TY->get_ref ()); \ - mappings->insert_canonical_path ( \ - builtin_type->get_node_id (), \ - CanonicalPath::new_seg (builtin_type->get_node_id (), _X)); \ - } \ - while (0) - namespace Rust { namespace Resolver { Rib::Rib (CrateNum crateNum, NodeId node_id) - : crate_num (crateNum), node_id (node_id), - mappings (Analysis::Mappings::get ()) + : crate_num (crateNum), node_id (node_id) {} void Rib::insert_name ( const CanonicalPath &path, NodeId id, Location locus, bool shadow, + std::function dup_cb) { auto it = path_mappings.find (path); @@ -69,8 +46,8 @@ Rib::insert_name ( } path_mappings[path] = id; - reverse_path_mappings.insert (std::pair (id, path)); - decls_within_rib.insert (std::pair (id, locus)); + reverse_path_mappings.insert ({id, path}); + decls_within_rib.insert ({id, locus}); references[id] = {}; } @@ -387,24 +364,24 @@ Resolver::generate_builtins () auto str = new TyTy::StrType (mappings->get_next_hir_id ()); auto never = new TyTy::NeverType (mappings->get_next_hir_id ()); - MKBUILTIN_TYPE ("u8", builtins, u8); - MKBUILTIN_TYPE ("u16", builtins, u16); - MKBUILTIN_TYPE ("u32", builtins, u32); - MKBUILTIN_TYPE ("u64", builtins, u64); - MKBUILTIN_TYPE ("u128", builtins, u128); - MKBUILTIN_TYPE ("i8", builtins, i8); - MKBUILTIN_TYPE ("i16", builtins, i16); - MKBUILTIN_TYPE ("i32", builtins, i32); - MKBUILTIN_TYPE ("i64", builtins, i64); - MKBUILTIN_TYPE ("i128", builtins, i128); - MKBUILTIN_TYPE ("bool", builtins, rbool); - MKBUILTIN_TYPE ("f32", builtins, f32); - MKBUILTIN_TYPE ("f64", builtins, f64); - MKBUILTIN_TYPE ("usize", builtins, usize); - MKBUILTIN_TYPE ("isize", builtins, isize); - MKBUILTIN_TYPE ("char", builtins, char_tyty); - MKBUILTIN_TYPE ("str", builtins, str); - MKBUILTIN_TYPE ("!", builtins, never); + setup_builtin ("u8", u8); + setup_builtin ("u16", u16); + setup_builtin ("u32", u32); + setup_builtin ("u64", u64); + setup_builtin ("u128", u128); + setup_builtin ("i8", i8); + setup_builtin ("i16", i16); + setup_builtin ("i32", i32); + setup_builtin ("i64", i64); + setup_builtin ("i128", i128); + setup_builtin ("bool", rbool); + setup_builtin ("f32", f32); + setup_builtin ("f64", f64); + setup_builtin ("usize", usize); + setup_builtin ("isize", isize); + setup_builtin ("char", char_tyty); + setup_builtin ("str", str); + setup_builtin ("!", never); // unit type () TyTy::TupleType *unit_tyty @@ -418,6 +395,26 @@ Resolver::generate_builtins () set_unit_type_node_id (unit_type->get_node_id ()); } +void +Resolver::setup_builtin (const std::string &name, TyTy::BaseType *tyty) +{ + AST::PathIdentSegment seg (name, Linemap::predeclared_location ()); + auto typePath = ::std::unique_ptr ( + new AST::TypePathSegment (::std::move (seg), false, + Linemap::predeclared_location ())); + ::std::vector< ::std::unique_ptr > segs; + segs.push_back (::std::move (typePath)); + auto builtin_type + = new AST::TypePath (::std::move (segs), Linemap::predeclared_location (), + false); + builtins.push_back (builtin_type); + tyctx->insert_builtin (tyty->get_ref (), builtin_type->get_node_id (), tyty); + mappings->insert_node_to_hir (builtin_type->get_node_id (), tyty->get_ref ()); + mappings->insert_canonical_path ( + builtin_type->get_node_id (), + CanonicalPath::new_seg (builtin_type->get_node_id (), name)); +} + void Resolver::insert_resolved_name (NodeId refId, NodeId defId) { diff --git a/gcc/rust/resolve/rust-name-resolver.h b/gcc/rust/resolve/rust-name-resolver.h index 3716bb05383..6c2e5fdcadc 100644 --- a/gcc/rust/resolve/rust-name-resolver.h +++ b/gcc/rust/resolve/rust-name-resolver.h @@ -30,8 +30,9 @@ namespace Resolver { class Rib { public: - // Rust uses local_def_ids assigned by def_collector on the AST - // lets use NodeId instead + // FIXME + // Rust uses local_def_ids assigned by def_collector on the AST. Consider + // moving to a local-def-id Rib (CrateNum crateNum, NodeId node_id); // this takes the relative paths of items within a compilation unit for lookup @@ -59,7 +60,6 @@ private: std::map reverse_path_mappings; std::map decls_within_rib; std::map> references; - Analysis::Mappings *mappings; }; class Scope @@ -172,6 +172,7 @@ private: Resolver (); void generate_builtins (); + void setup_builtin (const std::string &name, TyTy::BaseType *tyty); Analysis::Mappings *mappings; TypeCheckContext *tyctx;