aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/hir
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/rust/hir')
-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
10 files changed, 100 insertions, 72 deletions
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; }