diff options
Diffstat (limited to 'gcc/rust/hir')
-rw-r--r-- | gcc/rust/hir/rust-hir-dump.cc | 3 | ||||
-rw-r--r-- | gcc/rust/hir/rust-hir-dump.h | 1 | ||||
-rw-r--r-- | gcc/rust/hir/tree/rust-hir-full-decls.h | 1 | ||||
-rw-r--r-- | gcc/rust/hir/tree/rust-hir-pattern.h | 67 | ||||
-rw-r--r-- | gcc/rust/hir/tree/rust-hir-visitor.h | 3 | ||||
-rw-r--r-- | gcc/rust/hir/tree/rust-hir.h | 1 |
6 files changed, 76 insertions, 0 deletions
diff --git a/gcc/rust/hir/rust-hir-dump.cc b/gcc/rust/hir/rust-hir-dump.cc index 4c271a8..273333b 100644 --- a/gcc/rust/hir/rust-hir-dump.cc +++ b/gcc/rust/hir/rust-hir-dump.cc @@ -580,6 +580,9 @@ Dump::visit (TuplePattern &) void Dump::visit (SlicePattern &) {} +void +Dump::visit (AltPattern &) +{} void Dump::visit (EmptyStmt &) diff --git a/gcc/rust/hir/rust-hir-dump.h b/gcc/rust/hir/rust-hir-dump.h index 2bcd5dd..e853069 100644 --- a/gcc/rust/hir/rust-hir-dump.h +++ b/gcc/rust/hir/rust-hir-dump.h @@ -164,6 +164,7 @@ private: virtual void visit (TuplePatternItemsRanged &) override; virtual void visit (TuplePattern &) override; virtual void visit (SlicePattern &) override; + virtual void visit (AltPattern &) override; virtual void visit (EmptyStmt &) override; virtual void visit (LetStmt &) override; diff --git a/gcc/rust/hir/tree/rust-hir-full-decls.h b/gcc/rust/hir/tree/rust-hir-full-decls.h index 69a3cad..23ffa44 100644 --- a/gcc/rust/hir/tree/rust-hir-full-decls.h +++ b/gcc/rust/hir/tree/rust-hir-full-decls.h @@ -207,6 +207,7 @@ class TuplePatternItemsMultiple; class TuplePatternItemsRanged; class TuplePattern; class SlicePattern; +class AltPattern; // rust-type.h class TraitBound; diff --git a/gcc/rust/hir/tree/rust-hir-pattern.h b/gcc/rust/hir/tree/rust-hir-pattern.h index 934a39a..5826c8b 100644 --- a/gcc/rust/hir/tree/rust-hir-pattern.h +++ b/gcc/rust/hir/tree/rust-hir-pattern.h @@ -1300,6 +1300,73 @@ protected: } }; +// HIR node for alternative patterns +class AltPattern : public Pattern +{ + std::vector<std::unique_ptr<Pattern>> alts; + Location locus; + Analysis::NodeMapping mappings; + +public: +public: + std::string as_string () const override; + + AltPattern (Analysis::NodeMapping mappings, + std::vector<std::unique_ptr<Pattern>> alts, Location locus) + : alts (std::move (alts)), locus (locus), mappings (mappings) + {} + + // Copy constructor with vector clone + AltPattern (AltPattern const &other) + : locus (other.locus), mappings (other.mappings) + { + alts.reserve (other.alts.size ()); + for (const auto &e : other.alts) + alts.push_back (e->clone_pattern ()); + } + + // Overloaded assignment operator to vector clone + AltPattern &operator= (AltPattern const &other) + { + locus = other.locus; + mappings = other.mappings; + + alts.clear (); + alts.reserve (other.alts.size ()); + for (const auto &e : other.alts) + alts.push_back (e->clone_pattern ()); + + return *this; + } + + // move constructors + AltPattern (AltPattern &&other) = default; + AltPattern &operator= (AltPattern &&other) = default; + + Location get_locus () const override { return locus; } + + void accept_vis (HIRFullVisitor &vis) override; + void accept_vis (HIRPatternVisitor &vis) override; + + Analysis::NodeMapping get_pattern_mappings () const override final + { + return mappings; + } + + PatternType get_pattern_type () const override final + { + return PatternType::ALT; + } + +protected: + /* Use covariance to implement clone function as returning this object rather + * than base */ + AltPattern *clone_pattern_impl () const override + { + return new AltPattern (*this); + } +}; + // Moved definition to rust-path.h class PathPattern; diff --git a/gcc/rust/hir/tree/rust-hir-visitor.h b/gcc/rust/hir/tree/rust-hir-visitor.h index d1e99f0..a9ca6e9 100644 --- a/gcc/rust/hir/tree/rust-hir-visitor.h +++ b/gcc/rust/hir/tree/rust-hir-visitor.h @@ -139,6 +139,7 @@ public: virtual void visit (TuplePatternItemsRanged &tuple_items) = 0; virtual void visit (TuplePattern &pattern) = 0; virtual void visit (SlicePattern &pattern) = 0; + virtual void visit (AltPattern &pattern) = 0; virtual void visit (EmptyStmt &stmt) = 0; virtual void visit (LetStmt &stmt) = 0; virtual void visit (ExprStmtWithoutBlock &stmt) = 0; @@ -290,6 +291,7 @@ public: virtual void visit (TuplePatternItemsRanged &) override {} virtual void visit (TuplePattern &) override {} virtual void visit (SlicePattern &) override {} + virtual void visit (AltPattern &) override {} virtual void visit (EmptyStmt &) override {} virtual void visit (LetStmt &) override {} @@ -475,6 +477,7 @@ public: virtual void visit (RangePattern &) = 0; virtual void visit (ReferencePattern &) = 0; virtual void visit (SlicePattern &) = 0; + virtual void visit (AltPattern &) = 0; virtual void visit (StructPattern &) = 0; virtual void visit (TuplePattern &) = 0; virtual void visit (TupleStructPattern &) = 0; diff --git a/gcc/rust/hir/tree/rust-hir.h b/gcc/rust/hir/tree/rust-hir.h index d353d01..31f1494 100644 --- a/gcc/rust/hir/tree/rust-hir.h +++ b/gcc/rust/hir/tree/rust-hir.h @@ -384,6 +384,7 @@ public: TUPLE, GROUPED, SLICE, + ALT }; BaseKind get_hir_kind () override final { return PATTERN; } |