aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/ast/rust-path.cc
diff options
context:
space:
mode:
authorArthur Cohen <arthur.cohen@embecosm.com>2024-06-24 18:25:15 +0200
committerCohenArthur <arthur.cohen@embecosm.com>2024-08-19 12:39:49 +0000
commitd44051dea3036534b672684d22c7adf4f0684f9f (patch)
tree2520c760209dbb22478ab89e7d07fdfa391feeb6 /gcc/rust/ast/rust-path.cc
parent530b6121cf5db17eb2da34aa60e911c23e66918d (diff)
downloadgcc-d44051dea3036534b672684d22c7adf4f0684f9f.zip
gcc-d44051dea3036534b672684d22c7adf4f0684f9f.tar.gz
gcc-d44051dea3036534b672684d22c7adf4f0684f9f.tar.bz2
ast: Introduce class hierarchy for lang item paths
Create a base Path class which is derived into two children classes for regular paths and lang item paths. This allows it to hold either the segments of a fully formed path, or the node ID of a lang-item path. This is required in order to create these special paths which do not have segments, and do not necessarily have a canonical form - they only depend on where the item was defined. gcc/rust/ChangeLog: * ast/rust-ast-full-decls.h (class PathPattern): Rename PathPattern to... (class Path): ...Path * ast/rust-ast-collector.cc (TokenCollector::visit): Add required methods for LangItemPath and RegularPath. * ast/rust-ast-collector.h: Likewise. * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Likewise. * ast/rust-ast-visitor.h: Likewise. * ast/rust-path.cc (PathPattern::as_string): Likewise. (RegularPath::as_string): Likewise. (LangItemPath::as_string): Likewise. (PathPattern::convert_to_simple_path): Likewise. (RegularPath::convert_to_simple_path): Likewise. (RegularPath::accept_vis): Likewise. (LangItemPath::accept_vis): Likewise. (PathInExpression::as_string): Likewise. (QualifiedPathInExpression::as_string): Likewise. * ast/rust-path.h (class PathPattern): Likewise. (class Path): Likewise. (class RegularPath): Likewise. (class LangItemPath): Likewise. (class PathInExpression): Likewise. (class QualifiedPathInExpression): Likewise. * ast/rust-pattern.h (class PathPattern): Likewise. (class Path): Likewise. * expand/rust-derive.h: Likewise. * hir/rust-ast-lower-base.cc (ASTLoweringBase::visit): Likewise. * hir/rust-ast-lower-base.h: Likewise. * resolve/rust-ast-resolve-base.cc (ResolverBase::visit): Likewise. * resolve/rust-ast-resolve-base.h: Likewise.
Diffstat (limited to 'gcc/rust/ast/rust-path.cc')
-rw-r--r--gcc/rust/ast/rust-path.cc28
1 files changed, 24 insertions, 4 deletions
diff --git a/gcc/rust/ast/rust-path.cc b/gcc/rust/ast/rust-path.cc
index 9131962..58bfbb4 100644
--- a/gcc/rust/ast/rust-path.cc
+++ b/gcc/rust/ast/rust-path.cc
@@ -17,6 +17,7 @@ You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>. */
+#include "rust-path.h"
#include "rust-system.h"
#include "rust-ast-full.h"
#include "rust-diagnostics.h"
@@ -135,7 +136,7 @@ PathExprSegment::as_string () const
}
std::string
-PathPattern::as_string () const
+RegularPath::as_string () const
{
std::string str;
@@ -148,8 +149,15 @@ PathPattern::as_string () const
return str;
}
+std::string
+LangItemPath::as_string () const
+{
+ // FIXME: Handle #[lang] paths
+ rust_unreachable ();
+}
+
SimplePath
-PathPattern::convert_to_simple_path (bool with_opening_scope_resolution) const
+RegularPath::convert_to_simple_path (bool with_opening_scope_resolution) const
{
if (!has_segments ())
return SimplePath::create_empty ();
@@ -184,6 +192,18 @@ PathPattern::convert_to_simple_path (bool with_opening_scope_resolution) const
}
void
+RegularPath::accept_vis (ASTVisitor &vis)
+{
+ vis.visit (*this);
+}
+
+void
+LangItemPath::accept_vis (ASTVisitor &vis)
+{
+ vis.visit (*this);
+}
+
+void
PathInExpression::accept_vis (ASTVisitor &vis)
{
vis.visit (*this);
@@ -197,7 +217,7 @@ PathInExpression::as_string () const
if (has_opening_scope_resolution)
str = "::";
- return str + PathPattern::as_string ();
+ return str + path->as_string ();
}
std::string
@@ -297,7 +317,7 @@ TypePathFunction::as_string () const
std::string
QualifiedPathInExpression::as_string () const
{
- return path_type.as_string () + "::" + PathPattern::as_string ();
+ return path_type.as_string () + "::" + path->as_string ();
}
std::string