]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: ast: builder: Remove ASTTypeBuilder
authorArthur Cohen <arthur.cohen@embecosm.com>
Tue, 20 May 2025 13:08:06 +0000 (15:08 +0200)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 5 Aug 2025 14:36:52 +0000 (16:36 +0200)
gcc/rust/ChangeLog:

* Make-lang.in: Remove object file for ASTTypeBuilder.
* ast/rust-ast-builder.h: Remove function.
* ast/rust-ast-builder.cc (Builder::new_type): Likewise.
(Builder::new_const_param): Use reconstruct_type() instead.
(Builder::new_generic_args): Likewise.
* expand/rust-derive-default.cc (DeriveDefault::visit_struct): Likewise.
(DeriveDefault::visit_tuple): Likewise.
* expand/rust-derive-eq.cc (DeriveEq::visit_tuple): Likewise.
(DeriveEq::visit_struct): Likewise.
(DeriveEq::visit_enum): Likewise.
(DeriveEq::visit_union): Likewise.
* ast/rust-ast-builder-type.cc: Removed.
* ast/rust-ast-builder-type.h: Removed.

gcc/rust/Make-lang.in
gcc/rust/ast/rust-ast-builder-type.cc [deleted file]
gcc/rust/ast/rust-ast-builder-type.h [deleted file]
gcc/rust/ast/rust-ast-builder.cc
gcc/rust/ast/rust-ast-builder.h
gcc/rust/expand/rust-derive-default.cc
gcc/rust/expand/rust-derive-eq.cc

index 2a2e79d29f5fe519ac6a0edb2ee80091350da32c..c7846892d8955806e0b6489454a2a3b62b2185fd 100644 (file)
@@ -93,7 +93,6 @@ GRS_OBJS = \
     rust/rust-cfg-strip.o \
     rust/rust-expand-visitor.o \
     rust/rust-ast-builder.o \
-    rust/rust-ast-builder-type.o \
     rust/rust-derive.o \
     rust/rust-derive-cmp-common.o \
     rust/rust-derive-clone.o \
diff --git a/gcc/rust/ast/rust-ast-builder-type.cc b/gcc/rust/ast/rust-ast-builder-type.cc
deleted file mode 100644 (file)
index 7f8571a..0000000
+++ /dev/null
@@ -1,166 +0,0 @@
-// Copyright (C) 2020-2024 Free Software Foundation, Inc.
-
-// This file is part of GCC.
-
-// GCC is free software; you can redistribute it and/or modify it under
-// the terms of the GNU General Public License as published by the Free
-// Software Foundation; either version 3, or (at your option) any later
-// version.
-
-// GCC is distributed in the hope that it will be useful, but WITHOUT ANY
-// WARRANTY; without even the implied warranty of MERCHANTABILITY or
-// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-// for more details.
-
-// You should have received a copy of the GNU General Public License
-// along with GCC; see the file COPYING3.  If not see
-// <http://www.gnu.org/licenses/>.
-
-#include "rust-ast-builder-type.h"
-#include "rust-ast-builder.h"
-#include "rust-ast-full.h"
-#include "rust-common.h"
-
-namespace Rust {
-namespace AST {
-
-ASTTypeBuilder::ASTTypeBuilder () : translated (nullptr) {}
-
-Type *
-ASTTypeBuilder::build (Type &type)
-{
-  ASTTypeBuilder builder;
-  type.accept_vis (builder);
-  rust_assert (builder.translated != nullptr);
-  return builder.translated;
-}
-
-void
-ASTTypeBuilder::visit (BareFunctionType &fntype)
-{
-  /* TODO */
-}
-
-void
-ASTTypeBuilder::visit (TupleType &tuple)
-{
-  std::vector<std::unique_ptr<Type> > elems;
-  for (auto &elem : tuple.get_elems ())
-    {
-      Type *t = ASTTypeBuilder::build (*elem.get ());
-      std::unique_ptr<Type> ty (t);
-      elems.push_back (std::move (ty));
-    }
-  translated = new TupleType (std::move (elems), tuple.get_locus ());
-}
-
-void
-ASTTypeBuilder::visit (TypePath &path)
-{
-  std::vector<std::unique_ptr<TypePathSegment> > segments;
-  for (auto &seg : path.get_segments ())
-    {
-      switch (seg->get_type ())
-       {
-       case TypePathSegment::REG:
-         {
-           const TypePathSegment &segment
-             = (const TypePathSegment &) (*seg.get ());
-           TypePathSegment *s
-             = new TypePathSegment (segment.get_ident_segment (),
-                                    segment.get_separating_scope_resolution (),
-                                    segment.get_locus ());
-           std::unique_ptr<TypePathSegment> sg (s);
-           segments.push_back (std::move (sg));
-         }
-         break;
-
-       case TypePathSegment::GENERIC:
-         {
-           TypePathSegmentGeneric &generic
-             = (TypePathSegmentGeneric &) (*seg.get ());
-
-           GenericArgs args
-             = Builder::new_generic_args (generic.get_generic_args ());
-           TypePathSegmentGeneric *s
-             = new TypePathSegmentGeneric (generic.get_ident_segment (), false,
-                                           std::move (args),
-                                           generic.get_locus ());
-           std::unique_ptr<TypePathSegment> sg (s);
-           segments.push_back (std::move (sg));
-         }
-         break;
-
-       case TypePathSegment::FUNCTION:
-         {
-           rust_unreachable ();
-           // TODO
-           // const TypePathSegmentFunction &fn
-           //   = (const TypePathSegmentFunction &) (*seg.get ());
-         }
-         break;
-       }
-    }
-
-  translated = new TypePath (std::move (segments), path.get_locus (),
-                            path.has_opening_scope_resolution_op ());
-}
-
-void
-ASTTypeBuilder::visit (QualifiedPathInType &path)
-{
-  /* TODO */
-}
-
-void
-ASTTypeBuilder::visit (ArrayType &type)
-{
-  /* TODO */
-}
-
-void
-ASTTypeBuilder::visit (ReferenceType &type)
-{
-  /* TODO */
-}
-
-void
-ASTTypeBuilder::visit (RawPointerType &type)
-{
-  /* TODO */
-}
-
-void
-ASTTypeBuilder::visit (SliceType &type)
-{
-  Type *t = ASTTypeBuilder::build (type.get_elem_type ());
-  std::unique_ptr<Type> ty (t);
-  translated = new SliceType (std::move (ty), type.get_locus ());
-}
-
-void
-ASTTypeBuilder::visit (InferredType &type)
-{
-  translated = new InferredType (type.get_locus ());
-}
-
-void
-ASTTypeBuilder::visit (NeverType &type)
-{
-  translated = new NeverType (type.get_locus ());
-}
-
-void
-ASTTypeBuilder::visit (TraitObjectTypeOneBound &type)
-{
-  /* TODO */
-}
-
-void
-ASTTypeBuilder::visit (TraitObjectType &type)
-{
-  /* TODO */
-}
-
-} // namespace AST
-} // namespace Rust
diff --git a/gcc/rust/ast/rust-ast-builder-type.h b/gcc/rust/ast/rust-ast-builder-type.h
deleted file mode 100644 (file)
index b67ae3b..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-// Copyright (C) 2020-2024 Free Software Foundation, Inc.
-
-// This file is part of GCC.
-
-// GCC is free software; you can redistribute it and/or modify it under
-// the terms of the GNU General Public License as published by the Free
-// Software Foundation; either version 3, or (at your option) any later
-// version.
-
-// GCC is distributed in the hope that it will be useful, but WITHOUT ANY
-// WARRANTY; without even the implied warranty of MERCHANTABILITY or
-// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-// for more details.
-
-// You should have received a copy of the GNU General Public License
-// along with GCC; see the file COPYING3.  If not see
-// <http://www.gnu.org/licenses/>.
-
-#ifndef RUST_AST_BUILDER_TYPE
-#define RUST_AST_BUILDER_TYPE
-
-#include "rust-ast-visitor.h"
-
-namespace Rust {
-namespace AST {
-
-class ASTTypeBuilder : public DefaultASTVisitor
-{
-protected:
-  using DefaultASTVisitor::visit;
-
-public:
-  static Type *build (Type &type);
-
-  void visit (BareFunctionType &fntype) override;
-  void visit (TupleType &tuple) override;
-  void visit (TypePath &path) override;
-  void visit (QualifiedPathInType &path) override;
-  void visit (ArrayType &type) override;
-  void visit (ReferenceType &type) override;
-  void visit (RawPointerType &type) override;
-  void visit (SliceType &type) override;
-  void visit (InferredType &type) override;
-  void visit (NeverType &type) override;
-  void visit (TraitObjectTypeOneBound &type) override;
-  void visit (TraitObjectType &type) override;
-
-private:
-  ASTTypeBuilder ();
-
-  Type *translated;
-};
-
-} // namespace AST
-} // namespace Rust
-
-#endif // RUST_AST_BUILDER_TYPE
index 914b321279f5ddeff8d067133623f92628ad97f6..914477120d2b4e068f64980fd44966247dc1e161 100644 (file)
@@ -18,7 +18,6 @@
 
 #include "rust-ast-builder.h"
 #include "optional.h"
-#include "rust-ast-builder-type.h"
 #include "rust-ast.h"
 #include "rust-common.h"
 #include "rust-expr.h"
@@ -552,13 +551,6 @@ Builder::discriminant_value (std::string binding_name, std::string instance)
              call (std::move (intrinsic), identifier (instance)));
 }
 
-std::unique_ptr<Type>
-Builder::new_type (Type &type)
-{
-  Type *t = ASTTypeBuilder::build (type);
-  return std::unique_ptr<Type> (t);
-}
-
 std::unique_ptr<GenericParam>
 Builder::new_lifetime_param (LifetimeParam &param)
 {
@@ -596,7 +588,7 @@ Builder::new_type_param (
   std::unique_ptr<Type> type = nullptr;
 
   if (param.has_type ())
-    type = new_type (param.get_type ());
+    type = param.get_type ().reconstruct ();
 
   for (auto &&extra_bound : extra_bounds)
     type_param_bounds.emplace_back (std::move (extra_bound));
@@ -726,7 +718,7 @@ Builder::new_generic_args (GenericArgs &args)
   for (auto &binding : args.get_binding_args ())
     {
       Type &t = *binding.get_type_ptr ().get ();
-      std::unique_ptr<Type> ty = new_type (t);
+      std::unique_ptr<Type> ty = t.reconstruct ();
       GenericArgsBinding b (binding.get_identifier (), std::move (ty),
                            binding.get_locus ());
       binding_args.push_back (std::move (b));
@@ -734,20 +726,25 @@ Builder::new_generic_args (GenericArgs &args)
 
   for (auto &arg : args.get_generic_args ())
     {
+      tl::optional<GenericArg> new_arg = tl::nullopt;
+
       switch (arg.get_kind ())
        {
        case GenericArg::Kind::Type:
-         {
-           std::unique_ptr<Type> ty = new_type (arg.get_type ());
-           GenericArg arg = GenericArg::create_type (std::move (ty));
-         }
+         new_arg = GenericArg::create_type (arg.get_type ().reconstruct ());
          break;
-
-       default:
-         // FIXME
-         rust_unreachable ();
+       case GenericArg::Kind::Either:
+         new_arg
+           = GenericArg::create_ambiguous (arg.get_path (), arg.get_locus ());
+         break;
+       case GenericArg::Kind::Const:
+         new_arg
+           = GenericArg::create_const (arg.get_expression ().clone_expr ());
+         // FIXME: Use `reconstruct()` here, not `clone_expr()`
          break;
        }
+
+      generic_args.emplace_back (*new_arg);
     }
 
   return GenericArgs (std::move (lifetime_args), std::move (generic_args),
index fa3c95ce4fdf9a68498c3a6f14955a66b21fde46..843bab896c74d8e73a770255f17520566beb5ca1 100644 (file)
@@ -315,8 +315,6 @@ public:
   std::unique_ptr<Stmt> discriminant_value (std::string binding_name,
                                            std::string instance = "self");
 
-  static std::unique_ptr<Type> new_type (Type &type);
-
   static std::unique_ptr<GenericParam>
   new_lifetime_param (LifetimeParam &param);
 
index 1b497b5923b02d8e488c7bb0d3cf2533ec61f3d2..26ee5461095a4aeebfc36712caadc7568f5e34b0 100644 (file)
@@ -98,7 +98,7 @@ DeriveDefault::visit_struct (StructStruct &item)
   for (auto &field : item.get_fields ())
     {
       auto name = field.get_field_name ().as_string ();
-      auto type = Builder::new_type (field.get_field_type ());
+      auto type = field.get_field_type ().reconstruct ();
       auto expr = default_call (std::move (type));
 
       cloned_fields.emplace_back (
@@ -120,7 +120,7 @@ DeriveDefault::visit_tuple (TupleStruct &tuple_item)
 
   for (auto &field : tuple_item.get_fields ())
     {
-      auto type = Builder::new_type (field.get_field_type ());
+      auto type = field.get_field_type ().reconstruct ();
 
       defaulted_fields.emplace_back (default_call (std::move (type)));
     }
index 97651270bc55782b479438b1f26aea2a54c8fa55..7da137fb5c27e6e7367fcd160a6640f2650efdf1 100644 (file)
@@ -142,10 +142,7 @@ DeriveEq::visit_tuple (TupleStruct &item)
   auto types = std::vector<std::unique_ptr<Type>> ();
 
   for (auto &field : item.get_fields ())
-    {
-      auto type = Builder::new_type (field.get_field_type ());
-      types.emplace_back (std::move (type));
-    }
+    types.emplace_back (field.get_field_type ().reconstruct ());
 
   expanded = eq_impls (assert_receiver_is_total_eq_fn (std::move (types)),
                       item.get_identifier ().as_string (),
@@ -158,10 +155,7 @@ DeriveEq::visit_struct (StructStruct &item)
   auto types = std::vector<std::unique_ptr<Type>> ();
 
   for (auto &field : item.get_fields ())
-    {
-      auto type = Builder::new_type (field.get_field_type ());
-      types.emplace_back (std::move (type));
-    }
+    types.emplace_back (field.get_field_type ().reconstruct ());
 
   expanded = eq_impls (assert_receiver_is_total_eq_fn (std::move (types)),
                       item.get_identifier ().as_string (),
@@ -186,10 +180,7 @@ DeriveEq::visit_enum (Enum &item)
            auto &tuple = static_cast<EnumItemTuple &> (*variant);
 
            for (auto &field : tuple.get_tuple_fields ())
-             {
-               auto type = Builder::new_type (field.get_field_type ());
-               types.emplace_back (std::move (type));
-             }
+             types.emplace_back (field.get_field_type ().reconstruct ());
            break;
          }
        case EnumItem::Kind::Struct:
@@ -197,10 +188,7 @@ DeriveEq::visit_enum (Enum &item)
            auto &tuple = static_cast<EnumItemStruct &> (*variant);
 
            for (auto &field : tuple.get_struct_fields ())
-             {
-               auto type = Builder::new_type (field.get_field_type ());
-               types.emplace_back (std::move (type));
-             }
+             types.emplace_back (field.get_field_type ().reconstruct ());
 
            break;
          }
@@ -218,10 +206,7 @@ DeriveEq::visit_union (Union &item)
   auto types = std::vector<std::unique_ptr<Type>> ();
 
   for (auto &field : item.get_variants ())
-    {
-      auto type = Builder::new_type (field.get_field_type ());
-      types.emplace_back (std::move (type));
-    }
+    types.emplace_back (field.get_field_type ().reconstruct ());
 
   expanded = eq_impls (assert_receiver_is_total_eq_fn (std::move (types)),
                       item.get_identifier ().as_string (),