From: Pierre-Emmanuel Patry <[email protected]>
Continue the effort to keep both opening scope resolution flag and
segments together.
gcc/rust/ChangeLog:
* hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Remove opening
scope resolution flag.
* hir/rust-ast-lower.cc (ASTLowerPathInExpression::visit): Likewise.
* hir/rust-hir-dump.cc (Dump::visit): Change function call name.
* hir/tree/rust-hir-path.cc (PathInExpression::PathInExpression):
Remove opening scope resolution flag initialization. Move it to
PathPattern.
* hir/tree/rust-hir-path.h (class PathPattern): Make PathPattern
inherit from RawPath.
(class PathInExpression): Remove opening scope resolution flag.
* hir/tree/rust-hir.cc (PathInExpression::to_string): Adapt function
name.
Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
---
This change was merged into the gccrs repository and is posted here for
upstream visibility and potential drive-by review, as requested by GCC
release managers.
Each commit email contains a link to its details on github from where you can
find the Pull-Request and associated discussions.
Commit on github:
https://github.com/Rust-GCC/gccrs/commit/08097f2bb2584ec3b47a7ac8557dfc53b147096f
The commit has NOT been mentioned in any issue.
The commit has been mentioned in the following pull-request(s):
- https://github.com/Rust-GCC/gccrs/pull/5044
gcc/rust/hir/rust-ast-lower-expr.cc | 2 +-
gcc/rust/hir/rust-ast-lower.cc | 2 +-
gcc/rust/hir/rust-hir-dump.cc | 2 +-
gcc/rust/hir/tree/rust-hir-path.cc | 11 ++++-------
gcc/rust/hir/tree/rust-hir-path.h | 18 +++++++-----------
gcc/rust/hir/tree/rust-hir.cc | 2 +-
6 files changed, 15 insertions(+), 22 deletions(-)
diff --git a/gcc/rust/hir/rust-ast-lower-expr.cc
b/gcc/rust/hir/rust-ast-lower-expr.cc
index cebc2bff9..58dfe6d3b 100644
--- a/gcc/rust/hir/rust-ast-lower-expr.cc
+++ b/gcc/rust/hir/rust-ast-lower-expr.cc
@@ -804,7 +804,7 @@ ASTLoweringExpr::visit (AST::RangeFromToInclExpr &expr)
HIR::Expr *func
= new HIR::PathInExpression (path_mapping,
LangItem::Kind::RANGE_INCLUSIVE_NEW,
- expr.get_locus (), false);
+ expr.get_locus ());
HIR::Expr *range_from = ASTLoweringExpr::translate (expr.get_from_expr ());
HIR::Expr *range_to = ASTLoweringExpr::translate (expr.get_to_expr ());
diff --git a/gcc/rust/hir/rust-ast-lower.cc b/gcc/rust/hir/rust-ast-lower.cc
index 152ff81ea..9f1d95424 100644
--- a/gcc/rust/hir/rust-ast-lower.cc
+++ b/gcc/rust/hir/rust-ast-lower.cc
@@ -472,7 +472,7 @@ ASTLowerPathInExpression::visit (AST::PathInExpression
&expr)
if (expr.is_lang_item ())
{
translated = new HIR::PathInExpression (mapping, expr.get_lang_item (),
- expr.get_locus (), false);
+ expr.get_locus ());
return;
}
diff --git a/gcc/rust/hir/rust-hir-dump.cc b/gcc/rust/hir/rust-hir-dump.cc
index e1c2cfa8e..a1893b163 100644
--- a/gcc/rust/hir/rust-hir-dump.cc
+++ b/gcc/rust/hir/rust-hir-dump.cc
@@ -734,7 +734,7 @@ Dump::visit (PathInExpression &e)
do_pathexpr (e);
put_field ("has_opening_scope_resolution",
- std::to_string (e.opening_scope_resolution ()));
+ std::to_string (e.has_opening_scope_resolution ()));
end ("PathInExpression");
}
diff --git a/gcc/rust/hir/tree/rust-hir-path.cc
b/gcc/rust/hir/tree/rust-hir-path.cc
index 1c1117f93..cfdec9a08 100644
--- a/gcc/rust/hir/tree/rust-hir-path.cc
+++ b/gcc/rust/hir/tree/rust-hir-path.cc
@@ -149,18 +149,15 @@ PathInExpression::PathInExpression (Analysis::NodeMapping
mappings,
location_t locus,
bool has_opening_scope_resolution,
std::vector<AST::Attribute> outer_attrs)
- : PathPattern (std::move (path_segments)),
- PathExpr (std::move (mappings), std::move (outer_attrs)),
- has_opening_scope_resolution (has_opening_scope_resolution), locus (locus)
+ : PathPattern (std::move (path_segments), has_opening_scope_resolution),
+ PathExpr (std::move (mappings), std::move (outer_attrs)), locus (locus)
{}
PathInExpression::PathInExpression (Analysis::NodeMapping mappings,
LangItem::Kind lang_item, location_t locus,
- bool has_opening_scope_resolution,
std::vector<AST::Attribute> outer_attrs)
: PathPattern (lang_item),
- PathExpr (std::move (mappings), std::move (outer_attrs)),
- has_opening_scope_resolution (has_opening_scope_resolution), locus (locus)
+ PathExpr (std::move (mappings), std::move (outer_attrs)), locus (locus)
{}
bool
@@ -368,7 +365,7 @@ QualifiedPathInExpression::QualifiedPathInExpression (
Analysis::NodeMapping mappings, QualifiedPathType qual_path_type,
std::vector<PathExprSegment> path_segments, location_t locus,
std::vector<AST::Attribute> outer_attrs)
- : PathPattern (std::move (path_segments)),
+ : PathPattern (std::move (path_segments), false),
PathExpr (std::move (mappings), std::move (outer_attrs)),
path_type (std::move (qual_path_type)), locus (locus)
{}
diff --git a/gcc/rust/hir/tree/rust-hir-path.h
b/gcc/rust/hir/tree/rust-hir-path.h
index b9de6b90b..ea1dab27d 100644
--- a/gcc/rust/hir/tree/rust-hir-path.h
+++ b/gcc/rust/hir/tree/rust-hir-path.h
@@ -246,7 +246,7 @@ public:
};
// HIR node representing a pattern that involves a "path" - abstract base class
-class PathPattern : public Pattern
+class PathPattern : public Pattern, public RawPath<PathExprSegment>
{
public:
enum class Kind
@@ -256,18 +256,18 @@ public:
};
private:
- std::vector<PathExprSegment> segments;
tl::optional<LangItem::Kind> lang_item;
Kind kind;
protected:
- PathPattern (std::vector<PathExprSegment> segments)
- : segments (std::move (segments)), lang_item (tl::nullopt),
- kind (Kind::Segmented)
+ PathPattern (std::vector<PathExprSegment> segments,
+ bool has_opening_scope_resolution)
+ : RawPath (std::move (segments), has_opening_scope_resolution),
+ lang_item (tl::nullopt), kind (Kind::Segmented)
{}
PathPattern (LangItem::Kind lang_item)
- : segments ({}), lang_item (lang_item), kind (Kind::LangItem)
+ : RawPath ({}, false), lang_item (lang_item), kind (Kind::LangItem)
{}
bool is_refutable (const TyTy::BaseType &scrutinee) const override;
bool is_refutable () const override
@@ -352,7 +352,6 @@ public:
* arguments) */
class PathInExpression : public PathPattern, public PathExpr
{
- bool has_opening_scope_resolution;
location_t locus;
public:
@@ -369,7 +368,6 @@ public:
// 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> ());
@@ -392,7 +390,7 @@ public:
* so the method in the parent class should be protected, not public. Have
* to pass in opening scope resolution as parent class has no access to it.
*/
- return convert_to_simple_path (has_opening_scope_resolution);
+ return convert_to_simple_path (has_opening_scope_resolution ());
}
location_t get_locus () const override final { return locus; }
@@ -401,8 +399,6 @@ public:
void accept_vis (HIRExpressionVisitor &vis) override;
void accept_vis (HIRPatternVisitor &vis) override;
- bool opening_scope_resolution () { return has_opening_scope_resolution; }
-
bool is_self () const;
const Analysis::NodeMapping &get_mappings () const override final
diff --git a/gcc/rust/hir/tree/rust-hir.cc b/gcc/rust/hir/tree/rust-hir.cc
index 00db9fc64..34a1a645f 100644
--- a/gcc/rust/hir/tree/rust-hir.cc
+++ b/gcc/rust/hir/tree/rust-hir.cc
@@ -1179,7 +1179,7 @@ PathInExpression::to_string () const
{
std::string str;
- if (has_opening_scope_resolution)
+ if (has_opening_scope_resolution ())
{
str = "::";
}
--
2.56.0