aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/backend/rust-compile-fnparam.h2
-rw-r--r--gcc/rust/backend/rust-compile-var-decl.h2
-rw-r--r--gcc/rust/hir/rust-ast-lower-expr.h9
-rw-r--r--gcc/rust/hir/rust-ast-lower-extern.h10
-rw-r--r--gcc/rust/hir/rust-ast-lower-item.h11
-rw-r--r--gcc/rust/hir/rust-ast-lower-pattern.h4
-rw-r--r--gcc/rust/hir/rust-ast-lower-type.h8
-rw-r--r--gcc/rust/hir/tree/rust-hir-expr.h10
-rw-r--r--gcc/rust/hir/tree/rust-hir-full-test.cc14
-rw-r--r--gcc/rust/hir/tree/rust-hir-item.h36
-rw-r--r--gcc/rust/hir/tree/rust-hir-pattern.h33
-rw-r--r--gcc/rust/hir/tree/rust-hir-type.h37
-rw-r--r--gcc/rust/typecheck/rust-hir-dot-operator.h4
-rw-r--r--gcc/rust/typecheck/rust-hir-type-check-expr.h8
-rw-r--r--gcc/rust/typecheck/rust-hir-type-check-implitem.h8
-rw-r--r--gcc/rust/typecheck/rust-hir-type-check-type.h8
-rw-r--r--gcc/rust/typecheck/rust-hir-type-check.cc7
-rw-r--r--gcc/rust/typecheck/rust-tyty.h29
-rw-r--r--gcc/rust/util/rust-common.h34
19 files changed, 163 insertions, 111 deletions
diff --git a/gcc/rust/backend/rust-compile-fnparam.h b/gcc/rust/backend/rust-compile-fnparam.h
index e3f9558..9ef72ef 100644
--- a/gcc/rust/backend/rust-compile-fnparam.h
+++ b/gcc/rust/backend/rust-compile-fnparam.h
@@ -40,7 +40,7 @@ public:
void visit (HIR::IdentifierPattern &pattern) override
{
- if (!pattern.is_mut)
+ if (!pattern.is_mut ())
decl_type = ctx->get_backend ()->immutable_type (decl_type);
translated
diff --git a/gcc/rust/backend/rust-compile-var-decl.h b/gcc/rust/backend/rust-compile-var-decl.h
index ee4e65b..bd15a0c 100644
--- a/gcc/rust/backend/rust-compile-var-decl.h
+++ b/gcc/rust/backend/rust-compile-var-decl.h
@@ -54,7 +54,7 @@ public:
void visit (HIR::IdentifierPattern &pattern) override
{
- if (!pattern.is_mut)
+ if (!pattern.is_mut ())
translated_type = ctx->get_backend ()->immutable_type (translated_type);
translated
diff --git a/gcc/rust/hir/rust-ast-lower-expr.h b/gcc/rust/hir/rust-ast-lower-expr.h
index 1d0b6cc..586ec0a 100644
--- a/gcc/rust/hir/rust-ast-lower-expr.h
+++ b/gcc/rust/hir/rust-ast-lower-expr.h
@@ -649,11 +649,10 @@ public:
mappings->get_next_hir_id (crate_num),
UNKNOWN_LOCAL_DEFID);
- translated
- = new HIR::BorrowExpr (mapping,
- std::unique_ptr<HIR::Expr> (borrow_lvalue),
- expr.get_is_mut (), expr.get_is_double_borrow (),
- expr.get_outer_attrs (), expr.get_locus ());
+ translated = new HIR::BorrowExpr (
+ mapping, std::unique_ptr<HIR::Expr> (borrow_lvalue),
+ expr.get_is_mut () ? Mutability::Mut : Mutability::Imm,
+ expr.get_is_double_borrow (), expr.get_outer_attrs (), expr.get_locus ());
}
void visit (AST::DereferenceExpr &expr) override
diff --git a/gcc/rust/hir/rust-ast-lower-extern.h b/gcc/rust/hir/rust-ast-lower-extern.h
index 4ea0019..80852cf 100644
--- a/gcc/rust/hir/rust-ast-lower-extern.h
+++ b/gcc/rust/hir/rust-ast-lower-extern.h
@@ -48,12 +48,10 @@ public:
mappings->get_next_hir_id (crate_num),
mappings->get_next_localdef_id (crate_num));
- HIR::ExternalStaticItem *static_item
- = new HIR::ExternalStaticItem (mapping, item.get_identifier (),
- std::unique_ptr<HIR::Type> (static_type),
- item.is_mut (), std::move (vis),
- item.get_outer_attrs (),
- item.get_locus ());
+ HIR::ExternalStaticItem *static_item = new HIR::ExternalStaticItem (
+ mapping, item.get_identifier (), std::unique_ptr<HIR::Type> (static_type),
+ item.is_mut () ? Mutability::Mut : Mutability::Imm, std::move (vis),
+ item.get_outer_attrs (), item.get_locus ());
translated = static_item;
diff --git a/gcc/rust/hir/rust-ast-lower-item.h b/gcc/rust/hir/rust-ast-lower-item.h
index d5c56c0..5b4ebc5 100644
--- a/gcc/rust/hir/rust-ast-lower-item.h
+++ b/gcc/rust/hir/rust-ast-lower-item.h
@@ -339,11 +339,12 @@ public:
mappings->get_next_hir_id (crate_num),
mappings->get_next_localdef_id (crate_num));
- translated
- = new HIR::StaticItem (mapping, var.get_identifier (), var.is_mutable (),
- std::unique_ptr<HIR::Type> (type),
- std::unique_ptr<HIR::Expr> (expr), vis,
- var.get_outer_attrs (), var.get_locus ());
+ translated = new HIR::StaticItem (mapping, var.get_identifier (),
+ var.is_mutable () ? Mutability::Mut
+ : Mutability::Imm,
+ std::unique_ptr<HIR::Type> (type),
+ std::unique_ptr<HIR::Expr> (expr), vis,
+ var.get_outer_attrs (), var.get_locus ());
mappings->insert_defid_mapping (mapping.get_defid (), translated);
mappings->insert_hir_item (mapping.get_crate_num (), mapping.get_hirid (),
diff --git a/gcc/rust/hir/rust-ast-lower-pattern.h b/gcc/rust/hir/rust-ast-lower-pattern.h
index 340fba8..c68044a 100644
--- a/gcc/rust/hir/rust-ast-lower-pattern.h
+++ b/gcc/rust/hir/rust-ast-lower-pattern.h
@@ -45,7 +45,9 @@ public:
translated
= new HIR::IdentifierPattern (pattern.get_ident (), pattern.get_locus (),
pattern.get_is_ref (),
- pattern.get_is_mut (), std::move (to_bind));
+ pattern.get_is_mut () ? Mutability::Mut
+ : Mutability::Imm,
+ std::move (to_bind));
}
private:
diff --git a/gcc/rust/hir/rust-ast-lower-type.h b/gcc/rust/hir/rust-ast-lower-type.h
index 611c844..f5d7641 100644
--- a/gcc/rust/hir/rust-ast-lower-type.h
+++ b/gcc/rust/hir/rust-ast-lower-type.h
@@ -247,7 +247,9 @@ public:
mappings->get_next_hir_id (crate_num),
mappings->get_next_localdef_id (crate_num));
- translated = new HIR::ReferenceType (mapping, type.get_has_mut (),
+ translated = new HIR::ReferenceType (mapping,
+ type.get_has_mut () ? Mutability::Mut
+ : Mutability::Imm,
std::unique_ptr<HIR::Type> (base_type),
type.get_locus (), lifetime);
@@ -268,7 +270,9 @@ public:
translated
= new HIR::RawPointerType (mapping,
type.get_pointer_type ()
- == AST::RawPointerType::PointerType::MUT,
+ == AST::RawPointerType::PointerType::MUT
+ ? Mutability::Mut
+ : Mutability::Imm,
std::unique_ptr<HIR::Type> (base_type),
type.get_locus ());
diff --git a/gcc/rust/hir/tree/rust-hir-expr.h b/gcc/rust/hir/tree/rust-hir-expr.h
index 66de17d..a1865c3 100644
--- a/gcc/rust/hir/tree/rust-hir-expr.h
+++ b/gcc/rust/hir/tree/rust-hir-expr.h
@@ -19,6 +19,7 @@
#ifndef RUST_HIR_EXPR_H
#define RUST_HIR_EXPR_H
+#include "rust-common.h"
#include "rust-ast-full-decls.h"
#include "rust-hir.h"
#include "rust-hir-path.h"
@@ -171,23 +172,24 @@ public:
* overloaded. */
class BorrowExpr : public OperatorExpr
{
- bool is_mut;
+ Mutability mut;
bool double_borrow;
public:
std::string as_string () const override;
BorrowExpr (Analysis::NodeMapping mappings,
- std::unique_ptr<Expr> borrow_lvalue, bool is_mut_borrow,
+ std::unique_ptr<Expr> borrow_lvalue, Mutability mut,
bool is_double_borrow, AST::AttrVec outer_attribs, Location locus)
: OperatorExpr (std::move (mappings), std::move (borrow_lvalue),
std::move (outer_attribs), locus),
- is_mut (is_mut_borrow), double_borrow (is_double_borrow)
+ mut (mut), double_borrow (is_double_borrow)
{}
void accept_vis (HIRVisitor &vis) override;
- bool get_is_mut () const { return is_mut; }
+ Mutability get_mut () const { return mut; }
+ bool is_mut () const { return mut == Mutability::Mut; }
bool get_is_double_borrow () const { return double_borrow; }
protected:
diff --git a/gcc/rust/hir/tree/rust-hir-full-test.cc b/gcc/rust/hir/tree/rust-hir-full-test.cc
index b0e418c..5a4ff76 100644
--- a/gcc/rust/hir/tree/rust-hir-full-test.cc
+++ b/gcc/rust/hir/tree/rust-hir-full-test.cc
@@ -221,7 +221,7 @@ StaticItem::as_string () const
str += indent_spaces (stay) + "static";
- if (has_mut)
+ if (is_mut ())
{
str += " mut";
}
@@ -1200,7 +1200,7 @@ BorrowExpr::as_string () const
str += "&";
}
- if (is_mut)
+ if (is_mut ())
{
str += "mut ";
}
@@ -2463,7 +2463,7 @@ StructPatternFieldIdent::as_string () const
str += "ref ";
}
- if (has_mut)
+ if (is_mut ())
{
str += "mut ";
}
@@ -2570,7 +2570,7 @@ ReferencePattern::as_string () const
str += "&";
}
- if (is_mut)
+ if (is_mut ())
{
str += "mut ";
}
@@ -2590,7 +2590,7 @@ IdentifierPattern::as_string () const
str += "ref ";
}
- if (is_mut)
+ if (is_mut ())
{
str += "mut ";
}
@@ -2776,7 +2776,7 @@ ReferenceType::as_string () const
str += lifetime.as_string () + " ";
}
- if (has_mut)
+ if (is_mut ())
{
str += "mut ";
}
@@ -3249,7 +3249,7 @@ ExternalStaticItem::as_string () const
str += "static ";
- if (has_mut)
+ if (is_mut ())
{
str += "mut ";
}
diff --git a/gcc/rust/hir/tree/rust-hir-item.h b/gcc/rust/hir/tree/rust-hir-item.h
index 54e32f7..4091355 100644
--- a/gcc/rust/hir/tree/rust-hir-item.h
+++ b/gcc/rust/hir/tree/rust-hir-item.h
@@ -404,6 +404,14 @@ public:
Analysis::NodeMapping get_mappings () { return mappings; }
+ Mutability get_mut () const
+ {
+ return (self_kind == ImplicitSelfKind::MUT
+ || self_kind == ImplicitSelfKind::MUT_REF)
+ ? Mutability::Mut
+ : Mutability::Imm;
+ }
+
bool is_mut () const
{
return self_kind == ImplicitSelfKind::MUT
@@ -2033,7 +2041,7 @@ protected:
* duration? */
class StaticItem : public VisItem
{
- bool has_mut;
+ Mutability mut;
Identifier name;
std::unique_ptr<Type> type;
std::unique_ptr<Expr> expr;
@@ -2042,17 +2050,17 @@ class StaticItem : public VisItem
public:
std::string as_string () const override;
- StaticItem (Analysis::NodeMapping mappings, Identifier name, bool is_mut,
+ StaticItem (Analysis::NodeMapping mappings, Identifier name, Mutability mut,
std::unique_ptr<Type> type, std::unique_ptr<Expr> expr,
Visibility vis, AST::AttrVec outer_attrs, Location locus)
: VisItem (std::move (mappings), std::move (vis), std::move (outer_attrs)),
- has_mut (is_mut), name (std::move (name)), type (std::move (type)),
+ mut (mut), name (std::move (name)), type (std::move (type)),
expr (std::move (expr)), locus (locus)
{}
// Copy constructor with clone
StaticItem (StaticItem const &other)
- : VisItem (other), has_mut (other.has_mut), name (other.name),
+ : VisItem (other), mut (other.mut), name (other.name),
type (other.type->clone_type ()), expr (other.expr->clone_expr ()),
locus (other.locus)
{}
@@ -2062,7 +2070,7 @@ public:
{
VisItem::operator= (other);
name = other.name;
- has_mut = other.has_mut;
+ mut = other.mut;
type = other.type->clone_type ();
expr = other.expr->clone_expr ();
locus = other.locus;
@@ -2080,7 +2088,9 @@ public:
Identifier get_identifier () const { return name; }
- bool is_mutable () const { return has_mut; }
+ Mutability get_mut () const { return mut; }
+
+ bool is_mut () const { return mut == Mutability::Mut; }
Expr *get_expr () { return expr.get (); }
@@ -2726,21 +2736,21 @@ protected:
// A static item used in an extern block
class ExternalStaticItem : public ExternalItem
{
- bool has_mut;
+ Mutability mut;
std::unique_ptr<Type> item_type;
public:
ExternalStaticItem (Analysis::NodeMapping mappings, Identifier item_name,
- std::unique_ptr<Type> item_type, bool is_mut,
+ std::unique_ptr<Type> item_type, Mutability mut,
Visibility vis, AST::AttrVec outer_attrs, Location locus)
: ExternalItem (std::move (mappings), std::move (item_name),
std::move (vis), std::move (outer_attrs), locus),
- has_mut (is_mut), item_type (std::move (item_type))
+ mut (mut), item_type (std::move (item_type))
{}
// Copy constructor
ExternalStaticItem (ExternalStaticItem const &other)
- : ExternalItem (other), has_mut (other.has_mut),
+ : ExternalItem (other), mut (other.mut),
item_type (other.item_type->clone_type ())
{}
@@ -2749,7 +2759,7 @@ public:
{
ExternalItem::operator= (other);
item_type = other.item_type->clone_type ();
- has_mut = other.has_mut;
+ mut = other.mut;
return *this;
}
@@ -2762,6 +2772,10 @@ public:
void accept_vis (HIRVisitor &vis) override;
+ bool is_mut () const { return mut == Mutability::Mut; }
+
+ Mutability get_mut () { return mut; }
+
std::unique_ptr<Type> &get_item_type () { return item_type; }
protected:
diff --git a/gcc/rust/hir/tree/rust-hir-pattern.h b/gcc/rust/hir/tree/rust-hir-pattern.h
index ac7155d..14a2a7d 100644
--- a/gcc/rust/hir/tree/rust-hir-pattern.h
+++ b/gcc/rust/hir/tree/rust-hir-pattern.h
@@ -19,6 +19,7 @@
#ifndef RUST_HIR_PATTERN_H
#define RUST_HIR_PATTERN_H
+#include "rust-common.h"
#include "rust-hir.h"
namespace Rust {
@@ -70,7 +71,7 @@ class IdentifierPattern : public Pattern
public:
Identifier variable_ident;
bool is_ref;
- bool is_mut;
+ Mutability mut;
// bool has_pattern;
std::unique_ptr<Pattern> to_bind;
@@ -84,16 +85,16 @@ public:
// Constructor
IdentifierPattern (Identifier ident, Location locus, bool is_ref = false,
- bool is_mut = false,
+ Mutability mut = Mutability::Imm,
std::unique_ptr<Pattern> to_bind = nullptr)
- : variable_ident (std::move (ident)), is_ref (is_ref), is_mut (is_mut),
+ : variable_ident (std::move (ident)), is_ref (is_ref), mut (mut),
to_bind (std::move (to_bind)), locus (locus)
{}
// Copy constructor with clone
IdentifierPattern (IdentifierPattern const &other)
: variable_ident (other.variable_ident), is_ref (other.is_ref),
- is_mut (other.is_mut), locus (other.locus)
+ mut (other.mut), locus (other.locus)
{
// fix to get prevent null pointer dereference
if (other.to_bind != nullptr)
@@ -105,7 +106,7 @@ public:
{
variable_ident = other.variable_ident;
is_ref = other.is_ref;
- is_mut = other.is_mut;
+ mut = other.mut;
locus = other.locus;
// fix to get prevent null pointer dereference
@@ -121,6 +122,8 @@ public:
Location get_locus () const { return locus; }
+ bool is_mut () const { return mut == Mutability::Mut; }
+
void accept_vis (HIRVisitor &vis) override;
protected:
@@ -327,22 +330,22 @@ protected:
class ReferencePattern : public Pattern
{
bool has_two_amps;
- bool is_mut;
+ Mutability mut;
std::unique_ptr<Pattern> pattern;
Location locus;
public:
std::string as_string () const override;
- ReferencePattern (std::unique_ptr<Pattern> pattern, bool is_mut_reference,
+ ReferencePattern (std::unique_ptr<Pattern> pattern, Mutability reference_mut,
bool ref_has_two_amps, Location locus)
- : has_two_amps (ref_has_two_amps), is_mut (is_mut_reference),
+ : has_two_amps (ref_has_two_amps), mut (reference_mut),
pattern (std::move (pattern)), locus (locus)
{}
// Copy constructor requires clone
ReferencePattern (ReferencePattern const &other)
- : has_two_amps (other.has_two_amps), is_mut (other.is_mut),
+ : has_two_amps (other.has_two_amps), mut (other.mut),
pattern (other.pattern->clone_pattern ()), locus (other.locus)
{}
@@ -350,7 +353,7 @@ public:
ReferencePattern &operator= (ReferencePattern const &other)
{
pattern = other.pattern->clone_pattern ();
- is_mut = other.is_mut;
+ mut = other.mut;
has_two_amps = other.has_two_amps;
locus = other.locus;
@@ -361,6 +364,8 @@ public:
ReferencePattern (ReferencePattern &&other) = default;
ReferencePattern &operator= (ReferencePattern &&other) = default;
+ bool is_mut () const { return mut == Mutability::Mut; }
+
void accept_vis (HIRVisitor &vis) override;
protected:
@@ -527,18 +532,20 @@ protected:
class StructPatternFieldIdent : public StructPatternField
{
bool has_ref;
- bool has_mut;
+ Mutability mut;
Identifier ident;
public:
- StructPatternFieldIdent (Identifier ident, bool is_ref, bool is_mut,
+ StructPatternFieldIdent (Identifier ident, bool is_ref, Mutability mut,
AST::AttrVec outer_attrs, Location locus)
: StructPatternField (std::move (outer_attrs), locus), has_ref (is_ref),
- has_mut (is_mut), ident (std::move (ident))
+ mut (mut), ident (std::move (ident))
{}
std::string as_string () const override;
+ bool is_mut () const { return mut == Mutability::Mut; }
+
void accept_vis (HIRVisitor &vis) override;
protected:
diff --git a/gcc/rust/hir/tree/rust-hir-type.h b/gcc/rust/hir/tree/rust-hir-type.h
index 0428a7a..5eb1d23 100644
--- a/gcc/rust/hir/tree/rust-hir-type.h
+++ b/gcc/rust/hir/tree/rust-hir-type.h
@@ -19,6 +19,7 @@
#ifndef RUST_HIR_TYPE_H
#define RUST_HIR_TYPE_H
+#include "rust-common.h"
#include "rust-hir.h"
#include "rust-hir-path.h"
@@ -448,21 +449,20 @@ public:
class RawPointerType : public TypeNoBounds
{
private:
- bool is_mutable;
+ Mutability mut;
std::unique_ptr<Type> type;
Location locus;
public:
// Constructor requires pointer for polymorphism reasons
- RawPointerType (Analysis::NodeMapping mappings, bool is_mutable,
+ RawPointerType (Analysis::NodeMapping mappings, Mutability mut,
std::unique_ptr<Type> type, Location locus)
- : TypeNoBounds (mappings), is_mutable (is_mutable), type (std::move (type)),
- locus (locus)
+ : TypeNoBounds (mappings), mut (mut), type (std::move (type)), locus (locus)
{}
// Copy constructor calls custom polymorphic clone function
RawPointerType (RawPointerType const &other)
- : TypeNoBounds (other.mappings), is_mutable (other.is_mutable),
+ : TypeNoBounds (other.mappings), mut (other.mut),
type (other.type->clone_type ()), locus (other.locus)
{}
@@ -470,7 +470,7 @@ public:
RawPointerType &operator= (RawPointerType const &other)
{
mappings = other.mappings;
- is_mutable = other.is_mutable;
+ mut = other.mut;
type = other.type->clone_type ();
locus = other.locus;
return *this;
@@ -488,9 +488,11 @@ public:
std::unique_ptr<Type> &get_type () { return type; }
- bool is_mut () const { return is_mutable; }
+ Mutability get_mut () const { return mut; }
+
+ bool is_mut () const { return mut == Mutability::Mut; }
- bool is_const () const { return !is_mutable; }
+ bool is_const () const { return mut == Mutability::Imm; }
std::unique_ptr<Type> &get_base_type () { return type; }
@@ -516,30 +518,29 @@ class ReferenceType : public TypeNoBounds
// bool has_lifetime; // TODO: handle in lifetime or something?
Lifetime lifetime;
- bool has_mut;
+ Mutability mut;
std::unique_ptr<Type> type;
Location locus;
public:
// Returns whether the reference is mutable or immutable.
- bool is_mut () const { return has_mut; }
+ bool is_mut () const { return mut == Mutability::Mut; }
// Returns whether the reference has a lifetime.
bool has_lifetime () const { return !lifetime.is_error (); }
// Constructor
- ReferenceType (Analysis::NodeMapping mappings, bool is_mut,
+ ReferenceType (Analysis::NodeMapping mappings, Mutability mut,
std::unique_ptr<Type> type_no_bounds, Location locus,
Lifetime lifetime)
- : TypeNoBounds (mappings), lifetime (std::move (lifetime)),
- has_mut (is_mut), type (std::move (type_no_bounds)), locus (locus)
+ : TypeNoBounds (mappings), lifetime (std::move (lifetime)), mut (mut),
+ type (std::move (type_no_bounds)), locus (locus)
{}
// Copy constructor with custom clone method
ReferenceType (ReferenceType const &other)
- : TypeNoBounds (other.mappings), lifetime (other.lifetime),
- has_mut (other.has_mut), type (other.type->clone_type ()),
- locus (other.locus)
+ : TypeNoBounds (other.mappings), lifetime (other.lifetime), mut (other.mut),
+ type (other.type->clone_type ()), locus (other.locus)
{}
// Operator overload assignment operator to custom clone the unique pointer
@@ -547,7 +548,7 @@ public:
{
mappings = other.mappings;
lifetime = other.lifetime;
- has_mut = other.has_mut;
+ mut = other.mut;
type = other.type->clone_type ();
locus = other.locus;
@@ -566,7 +567,7 @@ public:
Lifetime &get_lifetime () { return lifetime; }
- bool get_has_mut () const { return has_mut; }
+ Mutability get_mut () const { return mut; }
std::unique_ptr<Type> &get_base_type () { return type; }
diff --git a/gcc/rust/typecheck/rust-hir-dot-operator.h b/gcc/rust/typecheck/rust-hir-dot-operator.h
index 222622f..279e67f 100644
--- a/gcc/rust/typecheck/rust-hir-dot-operator.h
+++ b/gcc/rust/typecheck/rust-hir-dot-operator.h
@@ -51,7 +51,7 @@ public:
// 2. try ref
TyTy::ReferenceType *r1
= new TyTy::ReferenceType (r->get_ref (), TyTy::TyVar (r->get_ref ()),
- TyTy::TypeMutability::IMMUT);
+ Mutability::Imm);
c = Try (candidates, r1);
if (c != nullptr)
{
@@ -63,7 +63,7 @@ public:
// 3. try mut ref
TyTy::ReferenceType *r2
= new TyTy::ReferenceType (r->get_ref (), TyTy::TyVar (r->get_ref ()),
- TyTy::TypeMutability::MUT);
+ Mutability::Mut);
c = Try (candidates, r2);
if (c != nullptr)
{
diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.h b/gcc/rust/typecheck/rust-hir-type-check-expr.h
index aa23e64..b386763 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-expr.h
+++ b/gcc/rust/typecheck/rust-hir-type-check-expr.h
@@ -604,7 +604,7 @@ public:
infered = new TyTy::ReferenceType (expr.get_mappings ().get_hirid (),
TyTy::TyVar (base->get_ref ()),
- TyTy::TypeMutability::IMMUT);
+ Mutability::Imm);
}
break;
@@ -651,7 +651,7 @@ public:
infered = new TyTy::ReferenceType (expr.get_mappings ().get_hirid (),
TyTy::TyVar (array->get_ref ()),
- TyTy::TypeMutability::IMMUT);
+ Mutability::Imm);
}
break;
@@ -1094,9 +1094,7 @@ public:
infered = new TyTy::ReferenceType (expr.get_mappings ().get_hirid (),
TyTy::TyVar (resolved_base->get_ref ()),
- expr.get_is_mut ()
- ? TyTy::TypeMutability::MUT
- : TyTy::TypeMutability::IMMUT);
+ expr.get_mut ());
}
void visit (HIR::DereferenceExpr &expr) override
diff --git a/gcc/rust/typecheck/rust-hir-type-check-implitem.h b/gcc/rust/typecheck/rust-hir-type-check-implitem.h
index 26e504d..1260c2e 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-implitem.h
+++ b/gcc/rust/typecheck/rust-hir-type-check-implitem.h
@@ -101,7 +101,7 @@ public:
auto param_tyty = TypeCheckType::Resolve (param.get_type ().get ());
HIR::IdentifierPattern *param_pattern = new HIR::IdentifierPattern (
- param.get_param_name (), Location (), false, false,
+ param.get_param_name (), Location (), false, Mutability::Imm,
std::unique_ptr<HIR::Pattern> (nullptr));
params.push_back (
@@ -219,7 +219,7 @@ public:
HIR::SelfParam &self_param = function.get_self_param ();
HIR::IdentifierPattern *self_pattern = new HIR::IdentifierPattern (
"self", self_param.get_locus (), self_param.is_ref (),
- self_param.is_mut (), std::unique_ptr<HIR::Pattern> (nullptr));
+ self_param.get_mut (), std::unique_ptr<HIR::Pattern> (nullptr));
// might have a specified type
TyTy::BaseType *self_type = nullptr;
@@ -240,13 +240,13 @@ public:
case HIR::SelfParam::IMM_REF:
self_type = new TyTy::ReferenceType (
self_param.get_mappings ().get_hirid (),
- TyTy::TyVar (self->get_ref ()), TyTy::TypeMutability::IMMUT);
+ TyTy::TyVar (self->get_ref ()), Mutability::Imm);
break;
case HIR::SelfParam::MUT_REF:
self_type = new TyTy::ReferenceType (
self_param.get_mappings ().get_hirid (),
- TyTy::TyVar (self->get_ref ()), TyTy::TypeMutability::MUT);
+ TyTy::TyVar (self->get_ref ()), Mutability::Mut);
break;
default:
diff --git a/gcc/rust/typecheck/rust-hir-type-check-type.h b/gcc/rust/typecheck/rust-hir-type-check-type.h
index f8c6e06..3fdbe30 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-type.h
+++ b/gcc/rust/typecheck/rust-hir-type-check-type.h
@@ -129,9 +129,7 @@ public:
= TypeCheckType::Resolve (type.get_base_type ().get ());
translated = new TyTy::ReferenceType (type.get_mappings ().get_hirid (),
TyTy::TyVar (base->get_ref ()),
- type.get_has_mut ()
- ? TyTy::TypeMutability::MUT
- : TyTy::TypeMutability::IMMUT);
+ type.get_mut ());
}
void visit (HIR::RawPointerType &type) override
@@ -140,9 +138,7 @@ public:
= TypeCheckType::Resolve (type.get_base_type ().get ());
translated
= new TyTy::PointerType (type.get_mappings ().get_hirid (),
- TyTy::TyVar (base->get_ref ()),
- type.is_mut () ? TyTy::TypeMutability::MUT
- : TyTy::TypeMutability::IMMUT);
+ TyTy::TyVar (base->get_ref ()), type.get_mut ());
}
void visit (HIR::InferredType &type) override
diff --git a/gcc/rust/typecheck/rust-hir-type-check.cc b/gcc/rust/typecheck/rust-hir-type-check.cc
index ae5b2a0..1c72d81 100644
--- a/gcc/rust/typecheck/rust-hir-type-check.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check.cc
@@ -526,7 +526,8 @@ TraitItemReference::get_type_from_fn (/*const*/ HIR::TraitItemFunc &fn) const
HIR::IdentifierPattern *self_pattern
= new HIR::IdentifierPattern ("self", self_param.get_locus (),
self_param.is_ref (),
- self_param.is_mut (),
+ self_param.is_mut () ? Mutability::Mut
+ : Mutability::Imm,
std::unique_ptr<HIR::Pattern> (nullptr));
// might have a specified type
TyTy::BaseType *self_type = nullptr;
@@ -547,13 +548,13 @@ TraitItemReference::get_type_from_fn (/*const*/ HIR::TraitItemFunc &fn) const
case HIR::SelfParam::IMM_REF:
self_type = new TyTy::ReferenceType (
self_param.get_mappings ().get_hirid (),
- TyTy::TyVar (self->get_ref ()), TyTy::TypeMutability::IMMUT);
+ TyTy::TyVar (self->get_ref ()), Mutability::Imm);
break;
case HIR::SelfParam::MUT_REF:
self_type = new TyTy::ReferenceType (
self_param.get_mappings ().get_hirid (),
- TyTy::TyVar (self->get_ref ()), TyTy::TypeMutability::MUT);
+ TyTy::TyVar (self->get_ref ()), Mutability::Mut);
break;
default:
diff --git a/gcc/rust/typecheck/rust-tyty.h b/gcc/rust/typecheck/rust-tyty.h
index 22b93fa..2d3c1dc 100644
--- a/gcc/rust/typecheck/rust-tyty.h
+++ b/gcc/rust/typecheck/rust-tyty.h
@@ -24,6 +24,7 @@
#include "rust-hir-full.h"
#include "rust-diagnostics.h"
#include "rust-abi.h"
+#include "rust-common.h"
namespace Rust {
@@ -35,12 +36,6 @@ class AssociatedImplTrait;
namespace TyTy {
-enum TypeMutability
-{
- IMMUT,
- MUT
-};
-
// https://rustc-dev-guide.rust-lang.org/type-inference.html#inference-variables
// https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/enum.TyKind.html#variants
enum TypeKind
@@ -1558,12 +1553,12 @@ public:
class ReferenceType : public BaseType
{
public:
- ReferenceType (HirId ref, TyVar base, TypeMutability mut,
+ ReferenceType (HirId ref, TyVar base, Mutability mut,
std::set<HirId> refs = std::set<HirId> ())
: BaseType (ref, ref, TypeKind::REF, refs), base (base), mut (mut)
{}
- ReferenceType (HirId ref, HirId ty_ref, TyVar base, TypeMutability mut,
+ ReferenceType (HirId ref, HirId ty_ref, TyVar base, Mutability mut,
std::set<HirId> refs = std::set<HirId> ())
: BaseType (ref, ty_ref, TypeKind::REF, refs), base (base), mut (mut)
{}
@@ -1593,24 +1588,24 @@ public:
ReferenceType *handle_substitions (SubstitutionArgumentMappings mappings);
- TypeMutability mutability () const { return mut; }
+ Mutability mutability () const { return mut; }
- bool is_mutable () const { return mut == TypeMutability::MUT; }
+ bool is_mutable () const { return mut == Mutability::Mut; }
private:
TyVar base;
- TypeMutability mut;
+ Mutability mut;
};
class PointerType : public BaseType
{
public:
- PointerType (HirId ref, TyVar base, TypeMutability mut,
+ PointerType (HirId ref, TyVar base, Mutability mut,
std::set<HirId> refs = std::set<HirId> ())
: BaseType (ref, ref, TypeKind::POINTER, refs), base (base), mut (mut)
{}
- PointerType (HirId ref, HirId ty_ref, TyVar base, TypeMutability mut,
+ PointerType (HirId ref, HirId ty_ref, TyVar base, Mutability mut,
std::set<HirId> refs = std::set<HirId> ())
: BaseType (ref, ty_ref, TypeKind::POINTER, refs), base (base), mut (mut)
{}
@@ -1640,15 +1635,15 @@ public:
PointerType *handle_substitions (SubstitutionArgumentMappings mappings);
- TypeMutability mutability () const { return mut; }
+ Mutability mutability () const { return mut; }
- bool is_mutable () const { return mut == TypeMutability::MUT; }
+ bool is_mutable () const { return mut == Mutability::Mut; }
- bool is_const () const { return mut == TypeMutability::IMMUT; }
+ bool is_const () const { return mut == Mutability::Imm; }
private:
TyVar base;
- TypeMutability mut;
+ Mutability mut;
};
class StrType : public BaseType
diff --git a/gcc/rust/util/rust-common.h b/gcc/rust/util/rust-common.h
new file mode 100644
index 0000000..6c8f454
--- /dev/null
+++ b/gcc/rust/util/rust-common.h
@@ -0,0 +1,34 @@
+// Copyright (C) 2021 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/>.
+
+// Common definitions useful throughout the Rust frontend.
+
+#ifndef RUST_COMMON
+#define RUST_COMMON
+
+namespace Rust {
+
+enum Mutability
+{
+ Imm,
+ Mut
+};
+
+} // namespace Rust
+
+#endif // RUST_COMMON