aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/hir/tree/rust-hir-path.h
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/rust/hir/tree/rust-hir-path.h')
-rw-r--r--gcc/rust/hir/tree/rust-hir-path.h95
1 files changed, 86 insertions, 9 deletions
diff --git a/gcc/rust/hir/tree/rust-hir-path.h b/gcc/rust/hir/tree/rust-hir-path.h
index bbb9c2d..3ce2662 100644
--- a/gcc/rust/hir/tree/rust-hir-path.h
+++ b/gcc/rust/hir/tree/rust-hir-path.h
@@ -19,6 +19,7 @@
#ifndef RUST_HIR_PATH_H
#define RUST_HIR_PATH_H
+#include "rust-hir-map.h"
#include "rust-hir-simple-path.h"
#include "rust-hir-type-no-bounds.h"
#include "rust-hir-pattern-abstract.h"
@@ -230,15 +231,34 @@ public:
// HIR node representing a pattern that involves a "path" - abstract base class
class PathPattern : public Pattern
{
+public:
+ enum class Kind
+ {
+ Segmented,
+ LangItem
+ };
+
+private:
std::vector<PathExprSegment> segments;
+ tl::optional<LangItem::Kind> lang_item;
+ Kind kind;
protected:
PathPattern (std::vector<PathExprSegment> segments)
- : segments (std::move (segments))
+ : segments (std::move (segments)), lang_item (tl::nullopt),
+ kind (Kind::Segmented)
+ {}
+
+ PathPattern (LangItem::Kind lang_item)
+ : segments ({}), lang_item (lang_item), kind (Kind::LangItem)
{}
// Returns whether path has segments.
- bool has_segments () const { return !segments.empty (); }
+ bool has_segments () const
+ {
+ rust_assert (kind == Kind::Segmented);
+ return !segments.empty ();
+ }
/* Converts path segments to their equivalent SimplePath segments if possible,
* and creates a SimplePath from them. */
@@ -248,26 +268,61 @@ protected:
public:
/* Returns whether the path is a single segment (excluding qualified path
* initial as segment). */
- bool is_single_segment () const { return segments.size () == 1; }
+ bool is_single_segment () const
+ {
+ rust_assert (kind == Kind::Segmented);
+ return segments.size () == 1;
+ }
std::string as_string () const override;
void iterate_path_segments (std::function<bool (PathExprSegment &)> cb);
- size_t get_num_segments () const { return segments.size (); }
+ size_t get_num_segments () const
+ {
+ rust_assert (kind == Kind::Segmented);
+ return segments.size ();
+ }
+
+ std::vector<PathExprSegment> &get_segments ()
+ {
+ rust_assert (kind == Kind::Segmented);
+ return segments;
+ }
+
+ const std::vector<PathExprSegment> &get_segments () const
+ {
+ rust_assert (kind == Kind::Segmented);
+ return segments;
+ }
- std::vector<PathExprSegment> &get_segments () { return segments; }
+ PathExprSegment &get_root_seg ()
+ {
+ rust_assert (kind == Kind::Segmented);
+ return segments.at (0);
+ }
- const std::vector<PathExprSegment> &get_segments () const { return segments; }
+ const PathExprSegment &get_final_segment () const
+ {
+ rust_assert (kind == Kind::Segmented);
+ return segments.back ();
+ }
- PathExprSegment &get_root_seg () { return segments.at (0); }
+ LangItem::Kind get_lang_item () const
+ {
+ rust_assert (kind == Kind::LangItem);
- const PathExprSegment &get_final_segment () const { return segments.back (); }
+ return *lang_item;
+ }
PatternType get_pattern_type () const override final
{
return PatternType::PATH;
}
+
+ bool is_lang_item () const { return kind == Kind::LangItem; }
+
+ Kind get_path_kind () const { return kind; }
};
/* HIR node representing a path-in-expression pattern (path that allows generic
@@ -288,6 +343,13 @@ public:
std::vector<AST::Attribute> outer_attrs
= std::vector<AST::Attribute> ());
+ // lang-item Constructor
+ PathInExpression (Analysis::NodeMapping mappings, LangItem::Kind kind,
+ location_t locus = UNDEF_LOCATION,
+ bool has_opening_scope_resolution = false,
+ std::vector<AST::Attribute> outer_attrs
+ = std::vector<AST::Attribute> ());
+
// Creates an error state path in expression.
static PathInExpression create_error ()
{
@@ -671,13 +733,20 @@ public:
Analysis::NodeMapping get_mappings () const { return mappings; }
+ bool has_type () { return type != nullptr; }
+ bool has_trait () { return trait != nullptr; }
+
Type &get_type ()
{
rust_assert (type);
return *type;
}
- TypePath &get_trait () { return *trait; }
+ TypePath &get_trait ()
+ {
+ rust_assert (trait);
+ return *trait;
+ }
bool trait_has_generic_args () const;
@@ -701,6 +770,14 @@ public:
std::vector<AST::Attribute> outer_attrs
= std::vector<AST::Attribute> ());
+ // lang-item constructor
+ QualifiedPathInExpression (Analysis::NodeMapping mappings,
+ QualifiedPathType qual_path_type,
+ LangItem::Kind lang_item,
+ location_t locus = UNDEF_LOCATION,
+ std::vector<AST::Attribute> outer_attrs
+ = std::vector<AST::Attribute> ());
+
location_t get_locus () const override final { return locus; }
void accept_vis (HIRFullVisitor &vis) override;