]> gcc.gnu.org Git - gcc.git/commitdiff
Mark clone with const
authorPhilip Herron <philip.herron@embecosm.com>
Wed, 4 Aug 2021 13:04:32 +0000 (14:04 +0100)
committerPhilip Herron <philip.herron@embecosm.com>
Thu, 5 Aug 2021 17:19:51 +0000 (18:19 +0100)
TyTy::Clone should be const to enforce compiler checks that we do not
change the object.

gcc/rust/typecheck/rust-tyty.cc
gcc/rust/typecheck/rust-tyty.h

index 6bac7647ec6e6151589e2c26466de01f0df7f490..a1315fb339499424d369cb12822cee8769d6d755 100644 (file)
@@ -127,7 +127,7 @@ InferType::cast (BaseType *other)
 }
 
 BaseType *
-InferType::clone ()
+InferType::clone () const
 {
   return new InferType (get_ref (), get_ty_ref (), get_infer_kind (),
                        get_combined_refs ());
@@ -201,7 +201,7 @@ ErrorType::cast (BaseType *other)
 }
 
 BaseType *
-ErrorType::clone ()
+ErrorType::clone () const
 {
   return new ErrorType (get_ref (), get_ty_ref (), get_combined_refs ());
 }
@@ -531,7 +531,7 @@ ADTType::is_equal (const BaseType &other) const
 }
 
 BaseType *
-ADTType::clone ()
+ADTType::clone () const
 {
   std::vector<StructFieldType *> cloned_fields;
   for (auto &f : fields)
@@ -687,7 +687,7 @@ TupleType::is_equal (const BaseType &other) const
 }
 
 BaseType *
-TupleType::clone ()
+TupleType::clone () const
 {
   return new TupleType (get_ref (), get_ty_ref (), fields,
                        get_combined_refs ());
@@ -808,7 +808,7 @@ FnType::is_equal (const BaseType &other) const
 }
 
 BaseType *
-FnType::clone ()
+FnType::clone () const
 {
   std::vector<std::pair<HIR::Pattern *, BaseType *> > cloned_params;
   for (auto &p : params)
@@ -1011,7 +1011,7 @@ FnPtr::is_equal (const BaseType &other) const
 }
 
 BaseType *
-FnPtr::clone ()
+FnPtr::clone () const
 {
   std::vector<TyVar> cloned_params;
   for (auto &p : params)
@@ -1097,7 +1097,7 @@ ArrayType::get_element_type () const
 }
 
 BaseType *
-ArrayType::clone ()
+ArrayType::clone () const
 {
   return new ArrayType (get_ref (), get_ty_ref (), get_capacity (),
                        element_type, get_combined_refs ());
@@ -1150,7 +1150,7 @@ BoolType::can_eq (const BaseType *other, bool emit_errors) const
 }
 
 BaseType *
-BoolType::clone ()
+BoolType::clone () const
 {
   return new BoolType (get_ref (), get_ty_ref (), get_combined_refs ());
 }
@@ -1216,7 +1216,7 @@ IntType::can_eq (const BaseType *other, bool emit_errors) const
 }
 
 BaseType *
-IntType::clone ()
+IntType::clone () const
 {
   return new IntType (get_ref (), get_ty_ref (), get_int_kind (),
                      get_combined_refs ());
@@ -1293,7 +1293,7 @@ UintType::can_eq (const BaseType *other, bool emit_errors) const
 }
 
 BaseType *
-UintType::clone ()
+UintType::clone () const
 {
   return new UintType (get_ref (), get_ty_ref (), get_uint_kind (),
                       get_combined_refs ());
@@ -1364,7 +1364,7 @@ FloatType::can_eq (const BaseType *other, bool emit_errors) const
 }
 
 BaseType *
-FloatType::clone ()
+FloatType::clone () const
 {
   return new FloatType (get_ref (), get_ty_ref (), get_float_kind (),
                        get_combined_refs ());
@@ -1427,7 +1427,7 @@ USizeType::can_eq (const BaseType *other, bool emit_errors) const
 }
 
 BaseType *
-USizeType::clone ()
+USizeType::clone () const
 {
   return new USizeType (get_ref (), get_ty_ref (), get_combined_refs ());
 }
@@ -1479,7 +1479,7 @@ ISizeType::can_eq (const BaseType *other, bool emit_errors) const
 }
 
 BaseType *
-ISizeType::clone ()
+ISizeType::clone () const
 {
   return new ISizeType (get_ref (), get_ty_ref (), get_combined_refs ());
 }
@@ -1531,7 +1531,7 @@ CharType::can_eq (const BaseType *other, bool emit_errors) const
 }
 
 BaseType *
-CharType::clone ()
+CharType::clone () const
 {
   return new CharType (get_ref (), get_ty_ref (), get_combined_refs ());
 }
@@ -1600,7 +1600,7 @@ ReferenceType::get_base () const
 }
 
 BaseType *
-ReferenceType::clone ()
+ReferenceType::clone () const
 {
   return new ReferenceType (get_ref (), get_ty_ref (), base, is_mutable (),
                            get_combined_refs ());
@@ -1686,7 +1686,7 @@ PointerType::get_base () const
 }
 
 BaseType *
-PointerType::clone ()
+PointerType::clone () const
 {
   return new PointerType (get_ref (), get_ty_ref (), base, is_mutable (),
                          get_combined_refs ());
@@ -1765,10 +1765,10 @@ ParamType::can_eq (const BaseType *other, bool emit_errors) const
 }
 
 BaseType *
-ParamType::clone ()
+ParamType::clone () const
 {
-  return new ParamType (get_symbol (), get_ref (), get_ty_ref (),
-                       get_generic_param (), get_combined_refs ());
+  return new ParamType (get_symbol (), get_ref (), get_ty_ref (), param,
+                       get_combined_refs ());
 }
 
 std::string
@@ -1833,7 +1833,7 @@ ParamType::handle_substitions (SubstitutionArgumentMappings mappings)
 }
 
 BaseType *
-StrType::clone ()
+StrType::clone () const
 {
   return new StrType (get_ref (), get_ty_ref (), get_combined_refs ());
 }
@@ -1937,7 +1937,7 @@ NeverType::can_eq (const BaseType *other, bool emit_errors) const
 }
 
 BaseType *
-NeverType::clone ()
+NeverType::clone () const
 {
   return new NeverType (get_ref (), get_ty_ref (), get_combined_refs ());
 }
@@ -1989,7 +1989,7 @@ PlaceholderType::can_eq (const BaseType *other, bool emit_errors) const
 }
 
 BaseType *
-PlaceholderType::clone ()
+PlaceholderType::clone () const
 {
   return new PlaceholderType (get_ref (), get_ty_ref (), get_combined_refs ());
 }
index 46110e4a9a757f2b7cd5ea9d2912dee883de084c..6abae53eb5fe58e7b45c6c13c04bb66e9e45a557 100644 (file)
@@ -194,10 +194,10 @@ public:
 
   /* Returns a pointer to a clone of this. The caller is responsible for
    * releasing the memory of the returned ty. */
-  virtual BaseType *clone () = 0;
+  virtual BaseType *clone () const = 0;
 
   // get_combined_refs returns the chain of node refs involved in unification
-  std::set<HirId> get_combined_refs () { return combined; }
+  std::set<HirId> get_combined_refs () const { return combined; }
 
   void append_reference (HirId id) { combined.insert (id); }
 
@@ -300,7 +300,7 @@ public:
   BaseType *coerce (BaseType *other) override;
   BaseType *cast (BaseType *other) override;
 
-  BaseType *clone () final override;
+  BaseType *clone () const final override;
 
   InferTypeKind get_infer_kind () const { return infer_kind; }
 
@@ -337,7 +337,7 @@ public:
   BaseType *coerce (BaseType *other) override;
   BaseType *cast (BaseType *other) override;
 
-  BaseType *clone () final override;
+  BaseType *clone () const final override;
 
   std::string get_name () const override final { return as_string (); }
 };
@@ -368,7 +368,7 @@ public:
   BaseType *coerce (BaseType *other) override;
   BaseType *cast (BaseType *other) override;
 
-  BaseType *clone () final override;
+  BaseType *clone () const final override;
 
   std::string get_symbol () const;
 
@@ -462,7 +462,7 @@ public:
 
   BaseType *get_field (size_t index) const;
 
-  BaseType *clone () final override;
+  BaseType *clone () const final override;
 
   bool is_concrete () const override final
   {
@@ -527,7 +527,7 @@ public:
       }
   }
 
-  SubstitutionParamMapping clone ()
+  SubstitutionParamMapping clone () const
   {
     return SubstitutionParamMapping (generic, static_cast<ParamType *> (
                                                param->clone ()));
@@ -728,7 +728,7 @@ public:
     return substitutions;
   }
 
-  std::vector<SubstitutionParamMapping> clone_substs ()
+  std::vector<SubstitutionParamMapping> clone_substs () const
   {
     std::vector<SubstitutionParamMapping> clone;
 
@@ -885,9 +885,9 @@ public:
       identifier (identifier), fields (fields), adt_kind (adt_kind)
   {}
 
-  ADTKind get_adt_kind () { return adt_kind; }
-  bool is_tuple_struct () { return adt_kind == TUPLE_STRUCT; }
-  bool is_union () { return adt_kind == UNION; }
+  ADTKind get_adt_kind () const { return adt_kind; }
+  bool is_tuple_struct () const { return adt_kind == TUPLE_STRUCT; }
+  bool is_union () const { return adt_kind == UNION; }
 
   bool is_unit () const override { return this->fields.empty (); }
 
@@ -942,7 +942,7 @@ public:
     return nullptr;
   }
 
-  BaseType *clone () final override;
+  BaseType *clone () const final override;
 
   std::vector<StructFieldType *> &get_fields () { return fields; }
   const std::vector<StructFieldType *> &get_fields () const { return fields; }
@@ -1076,7 +1076,7 @@ public:
 
   BaseType *get_return_type () const { return type; }
 
-  BaseType *clone () final override;
+  BaseType *clone () const final override;
 
   bool needs_generic_substitutions () const override final
   {
@@ -1136,7 +1136,7 @@ public:
 
   bool is_equal (const BaseType &other) const override;
 
-  BaseType *clone () final override;
+  BaseType *clone () const final override;
 
   void iterate_params (std::function<bool (BaseType *)> cb) const
   {
@@ -1186,7 +1186,7 @@ public:
 
   BaseType *get_element_type () const;
 
-  BaseType *clone () final override;
+  BaseType *clone () const final override;
 
   bool is_concrete () const final override
   {
@@ -1221,7 +1221,7 @@ public:
   BaseType *coerce (BaseType *other) override;
   BaseType *cast (BaseType *other) override;
 
-  BaseType *clone () final override;
+  BaseType *clone () const final override;
 };
 
 class IntType : public BaseType
@@ -1259,7 +1259,7 @@ public:
 
   IntKind get_int_kind () const { return int_kind; }
 
-  BaseType *clone () final override;
+  BaseType *clone () const final override;
 
   bool is_equal (const BaseType &other) const override;
 
@@ -1302,7 +1302,7 @@ public:
 
   UintKind get_uint_kind () const { return uint_kind; }
 
-  BaseType *clone () final override;
+  BaseType *clone () const final override;
 
   bool is_equal (const BaseType &other) const override;
 
@@ -1343,7 +1343,7 @@ public:
 
   FloatKind get_float_kind () const { return float_kind; }
 
-  BaseType *clone () final override;
+  BaseType *clone () const final override;
 
   bool is_equal (const BaseType &other) const override;
 
@@ -1374,7 +1374,7 @@ public:
   BaseType *coerce (BaseType *other) override;
   BaseType *cast (BaseType *other) override;
 
-  BaseType *clone () final override;
+  BaseType *clone () const final override;
 };
 
 class ISizeType : public BaseType
@@ -1400,7 +1400,7 @@ public:
   BaseType *coerce (BaseType *other) override;
   BaseType *cast (BaseType *other) override;
 
-  BaseType *clone () final override;
+  BaseType *clone () const final override;
 };
 
 class CharType : public BaseType
@@ -1426,7 +1426,7 @@ public:
   BaseType *coerce (BaseType *other) override;
   BaseType *cast (BaseType *other) override;
 
-  BaseType *clone () final override;
+  BaseType *clone () const final override;
 };
 
 class ReferenceType : public BaseType
@@ -1458,7 +1458,7 @@ public:
 
   bool is_equal (const BaseType &other) const override;
 
-  BaseType *clone () final override;
+  BaseType *clone () const final override;
 
   bool contains_type_parameters () const override final
   {
@@ -1504,7 +1504,7 @@ public:
 
   bool is_equal (const BaseType &other) const override;
 
-  BaseType *clone () final override;
+  BaseType *clone () const final override;
 
   bool contains_type_parameters () const override final
   {
@@ -1547,7 +1547,7 @@ public:
 
   bool is_equal (const BaseType &other) const override;
 
-  BaseType *clone () final override;
+  BaseType *clone () const final override;
 };
 
 // https://doc.rust-lang.org/std/primitive.never.html
@@ -1581,7 +1581,7 @@ public:
   BaseType *coerce (BaseType *other) override;
   BaseType *cast (BaseType *other) override;
 
-  BaseType *clone () final override;
+  BaseType *clone () const final override;
 
   std::string get_name () const override final { return as_string (); }
 
@@ -1612,7 +1612,7 @@ public:
   BaseType *coerce (BaseType *other) override;
   BaseType *cast (BaseType *other) override;
 
-  BaseType *clone () final override;
+  BaseType *clone () const final override;
 
   std::string get_name () const override final { return as_string (); }
 
This page took 0.078631 seconds and 5 git commands to generate.