aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/ast
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-12-16 10:47:11 +0000
committerGitHub <noreply@github.com>2021-12-16 10:47:11 +0000
commit83a984b1a12694d8e06eb139089429b61e236fdd (patch)
tree715954488f9c719a3db3d98d29e8828df325c750 /gcc/rust/ast
parent768f926074a27a7b1a2179613eeeb8291648b8a7 (diff)
parenta688913ac153a85aa803faad9d243e66fd12889d (diff)
downloadgcc-83a984b1a12694d8e06eb139089429b61e236fdd.zip
gcc-83a984b1a12694d8e06eb139089429b61e236fdd.tar.gz
gcc-83a984b1a12694d8e06eb139089429b61e236fdd.tar.bz2
Merge #835
835: Add name-resolution and HIR lowering pass for MatchExpr r=philberty a=philberty This adds the name-resolution and HIR lowering pass for the match-expr the type checking pass patch needs some work to be split up but these are two nice isolated commits which are easier to read. Co-authored-by: Philip Herron <philip.herron@embecosm.com>
Diffstat (limited to 'gcc/rust/ast')
-rw-r--r--gcc/rust/ast/rust-expr.h9
-rw-r--r--gcc/rust/ast/rust-pattern.h61
2 files changed, 61 insertions, 9 deletions
diff --git a/gcc/rust/ast/rust-expr.h b/gcc/rust/ast/rust-expr.h
index 7f6714a..48dcc10 100644
--- a/gcc/rust/ast/rust-expr.h
+++ b/gcc/rust/ast/rust-expr.h
@@ -4337,23 +4337,26 @@ struct MatchCase
private:
MatchArm arm;
std::unique_ptr<Expr> expr;
+ NodeId node_id;
/* TODO: does whether trailing comma exists need to be stored? currently
* assuming it is only syntactical and has no effect on meaning. */
public:
MatchCase (MatchArm arm, std::unique_ptr<Expr> expr)
- : arm (std::move (arm)), expr (std::move (expr))
+ : arm (std::move (arm)), expr (std::move (expr)),
+ node_id (Analysis::Mappings::get ()->get_next_node_id ())
{}
MatchCase (const MatchCase &other)
- : arm (other.arm), expr (other.expr->clone_expr ())
+ : arm (other.arm), expr (other.expr->clone_expr ()), node_id (other.node_id)
{}
MatchCase &operator= (const MatchCase &other)
{
arm = other.arm;
expr = other.expr->clone_expr ();
+ node_id = other.node_id;
return *this;
}
@@ -4378,6 +4381,8 @@ public:
rust_assert (!arm.is_error ());
return arm;
}
+
+ NodeId get_node_id () const { return node_id; }
};
#if 0
diff --git a/gcc/rust/ast/rust-pattern.h b/gcc/rust/ast/rust-pattern.h
index b2c3686..d46bf0e 100644
--- a/gcc/rust/ast/rust-pattern.h
+++ b/gcc/rust/ast/rust-pattern.h
@@ -456,7 +456,17 @@ class StructPatternField
std::vector<Attribute> outer_attrs;
Location locus;
+protected:
+ NodeId node_id;
+
public:
+ enum ItemType
+ {
+ TUPLE_PAT,
+ IDENT_PAT,
+ IDENT
+ };
+
virtual ~StructPatternField () {}
// Unique pointer custom clone function
@@ -474,14 +484,18 @@ public:
virtual void mark_for_strip () = 0;
virtual bool is_marked_for_strip () const = 0;
+ virtual ItemType get_item_type () const = 0;
+
+ NodeId get_node_id () const { return node_id; }
// TODO: seems kinda dodgy. Think of better way.
std::vector<Attribute> &get_outer_attrs () { return outer_attrs; }
const std::vector<Attribute> &get_outer_attrs () const { return outer_attrs; }
protected:
- StructPatternField (std::vector<Attribute> outer_attribs, Location locus)
- : outer_attrs (std::move (outer_attribs)), locus (locus)
+ StructPatternField (std::vector<Attribute> outer_attribs, Location locus,
+ NodeId node_id)
+ : outer_attrs (std::move (outer_attribs)), locus (locus), node_id (node_id)
{}
// Clone function implementation as pure virtual method
@@ -499,8 +513,9 @@ public:
std::unique_ptr<Pattern> tuple_pattern,
std::vector<Attribute> outer_attribs,
Location locus)
- : StructPatternField (std::move (outer_attribs), locus), index (index),
- tuple_pattern (std::move (tuple_pattern))
+ : StructPatternField (std::move (outer_attribs), locus,
+ Analysis::Mappings::get ()->get_next_node_id ()),
+ index (index), tuple_pattern (std::move (tuple_pattern))
{}
// Copy constructor requires clone
@@ -508,6 +523,7 @@ public:
: StructPatternField (other), index (other.index)
{
// guard to prevent null dereference (only required if error state)
+ node_id = other.get_node_id ();
if (other.tuple_pattern != nullptr)
tuple_pattern = other.tuple_pattern->clone_pattern ();
}
@@ -519,6 +535,7 @@ public:
StructPatternField::operator= (other);
index = other.index;
// outer_attrs = other.outer_attrs;
+ node_id = other.get_node_id ();
// guard to prevent null dereference (only required if error state)
if (other.tuple_pattern != nullptr)
@@ -552,6 +569,8 @@ public:
return tuple_pattern;
}
+ ItemType get_item_type () const override final { return ItemType::TUPLE_PAT; }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
@@ -572,7 +591,8 @@ public:
std::unique_ptr<Pattern> ident_pattern,
std::vector<Attribute> outer_attrs,
Location locus)
- : StructPatternField (std::move (outer_attrs), locus),
+ : StructPatternField (std::move (outer_attrs), locus,
+ Analysis::Mappings::get ()->get_next_node_id ()),
ident (std::move (ident)), ident_pattern (std::move (ident_pattern))
{}
@@ -581,6 +601,7 @@ public:
: StructPatternField (other), ident (other.ident)
{
// guard to prevent null dereference (only required if error state)
+ node_id = other.get_node_id ();
if (other.ident_pattern != nullptr)
ident_pattern = other.ident_pattern->clone_pattern ();
}
@@ -592,6 +613,7 @@ public:
StructPatternField::operator= (other);
ident = other.ident;
// outer_attrs = other.outer_attrs;
+ node_id = other.get_node_id ();
// guard to prevent null dereference (only required if error state)
if (other.ident_pattern != nullptr)
@@ -618,6 +640,8 @@ public:
return ident_pattern == nullptr;
}
+ const Identifier &get_identifier () const { return ident; }
+
// TODO: is this better? Or is a "vis_pattern" better?
std::unique_ptr<Pattern> &get_ident_pattern ()
{
@@ -625,6 +649,8 @@ public:
return ident_pattern;
}
+ ItemType get_item_type () const override final { return ItemType::IDENT_PAT; }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
@@ -644,8 +670,9 @@ class StructPatternFieldIdent : public StructPatternField
public:
StructPatternFieldIdent (Identifier ident, bool is_ref, bool is_mut,
std::vector<Attribute> outer_attrs, Location locus)
- : StructPatternField (std::move (outer_attrs), locus), has_ref (is_ref),
- has_mut (is_mut), ident (std::move (ident))
+ : StructPatternField (std::move (outer_attrs), locus,
+ Analysis::Mappings::get ()->get_next_node_id ()),
+ has_ref (is_ref), has_mut (is_mut), ident (std::move (ident))
{}
std::string as_string () const override;
@@ -656,6 +683,14 @@ public:
void mark_for_strip () override { ident = {}; }
bool is_marked_for_strip () const override { return ident.empty (); }
+ const Identifier &get_identifier () const { return ident; }
+
+ ItemType get_item_type () const override final { return ItemType::IDENT; }
+
+ bool is_ref () const { return has_ref; }
+
+ bool is_mut () const { return has_mut; }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
@@ -827,6 +862,12 @@ protected:
class TupleStructItems
{
public:
+ enum ItemType
+ {
+ RANGE,
+ NO_RANGE
+ };
+
virtual ~TupleStructItems () {}
// TODO: should this store location data?
@@ -841,6 +882,8 @@ public:
virtual void accept_vis (ASTVisitor &vis) = 0;
+ virtual ItemType get_item_type () const = 0;
+
protected:
// pure virtual clone implementation
virtual TupleStructItems *clone_tuple_struct_items_impl () const = 0;
@@ -890,6 +933,8 @@ public:
return patterns;
}
+ ItemType get_item_type () const override final { return ItemType::NO_RANGE; }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
@@ -966,6 +1011,8 @@ public:
return upper_patterns;
}
+ ItemType get_item_type () const override final { return ItemType::RANGE; }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */