diff options
author | SimplyTheOther <simplytheother@gmail.com> | 2020-12-18 21:33:09 +0800 |
---|---|---|
committer | SimplyTheOther <simplytheother@gmail.com> | 2020-12-18 21:33:09 +0800 |
commit | aa283484a3dffedc404653af18f9413775cbc3df (patch) | |
tree | 118a5b918c48fba3261731bba0a6b4149209f7d8 /gcc/rust/ast/rust-path.h | |
parent | f764eeb8abf1ec50794ddb1f31bc57d025e29a3c (diff) | |
parent | bc14d9a0cd3c67093a9c11ad368c0d28325b21c6 (diff) | |
download | gcc-aa283484a3dffedc404653af18f9413775cbc3df.zip gcc-aa283484a3dffedc404653af18f9413775cbc3df.tar.gz gcc-aa283484a3dffedc404653af18f9413775cbc3df.tar.bz2 |
Merge branch 'master' of https://github.com/redbrain/gccrs
Diffstat (limited to 'gcc/rust/ast/rust-path.h')
-rw-r--r-- | gcc/rust/ast/rust-path.h | 40 |
1 files changed, 38 insertions, 2 deletions
diff --git a/gcc/rust/ast/rust-path.h b/gcc/rust/ast/rust-path.h index 392fc18..bd3b0f0 100644 --- a/gcc/rust/ast/rust-path.h +++ b/gcc/rust/ast/rust-path.h @@ -240,6 +240,8 @@ public: rust_assert (has_generic_args ()); return generic_args; } + + PathIdentSegment &get_ident_segment () { return segment_name; } }; // AST node representing a pattern that involves a "path" - abstract base class @@ -276,6 +278,15 @@ public: // TODO: this seems kinda dodgy std::vector<PathExprSegment> &get_segments () { return segments; } const std::vector<PathExprSegment> &get_segments () const { return segments; } + + void iterate_path_segments (std::function<bool (PathExprSegment &)> cb) + { + for (auto it = segments.begin (); it != segments.end (); it++) + { + if (!cb (*it)) + return; + } + } }; /* AST node representing a path-in-expression pattern (path that allows generic @@ -285,6 +296,8 @@ class PathInExpression : public PathPattern, public PathExpr bool has_opening_scope_resolution; Location locus; + NodeId _node_id; + public: std::string as_string () const override; @@ -296,7 +309,8 @@ public: = std::vector<Attribute> ()) : PathPattern (std::move (path_segments)), PathExpr (std::move (outer_attrs)), - has_opening_scope_resolution (has_opening_scope_resolution), locus (locus) + has_opening_scope_resolution (has_opening_scope_resolution), + locus (locus), _node_id (Analysis::Mappings::get ()->get_next_node_id ()) {} // Creates an error state path in expression. @@ -328,6 +342,9 @@ public: // Invalid if path is empty (error state), so base stripping on that. void mark_for_strip () override { remove_all_segments (); } bool is_marked_for_strip () const override { return is_error (); } + bool opening_scope_resolution () { return has_opening_scope_resolution; } + + NodeId get_node_id () const override { return _node_id; } protected: /* Use covariance to implement clone function as returning this object rather @@ -404,6 +421,13 @@ public: // not pure virtual as class not abstract virtual void accept_vis (ASTVisitor &vis); + + bool get_separating_scope_resolution () const + { + return has_separating_scope_resolution; + } + + PathIdentSegment get_ident_segment () { return ident_segment; }; }; // Segment used in type path with generic args @@ -635,7 +659,8 @@ public: // Constructor TypePath (std::vector<std::unique_ptr<TypePathSegment> > segments, Location locus, bool has_opening_scope_resolution = false) - : has_opening_scope_resolution (has_opening_scope_resolution), + : TypeNoBounds (), + has_opening_scope_resolution (has_opening_scope_resolution), segments (std::move (segments)), locus (locus) {} @@ -689,6 +714,17 @@ public: { return segments; } + + size_t get_num_segments () const { return segments.size (); } + + void iterate_segments (std::function<bool (TypePathSegment *)> cb) + { + for (auto it = segments.begin (); it != segments.end (); it++) + { + if (!cb ((*it).get ())) + return; + } + } }; struct QualifiedPathType |