public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] Add get_pattern_kind to Pattern
@ 2024-05-07 16:16 Thomas Schwinge
0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2024-05-07 16:16 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:1c467c0a8642d462e045975b0f4c2e667be06ca2
commit 1c467c0a8642d462e045975b0f4c2e667be06ca2
Author: 0xn4utilus <gyanendrabanjare8@gmail.com>
Date: Sun Feb 25 06:20:51 2024 +0530
Add get_pattern_kind to Pattern
gcc/rust/ChangeLog:
* ast/rust-ast.h: Add Kind Enum to
Pattern.
* ast/rust-macro.h: Add get_pattern_kind().
* ast/rust-path.h: Likewise.
* ast/rust-pattern.h: Likewise.
Signed-off-by: 0xn4utilus <gyanendrabanjare8@gmail.com>
Diff:
---
gcc/rust/ast/rust-ast.h | 20 ++++++++++++++++++++
gcc/rust/ast/rust-macro.h | 5 +++++
gcc/rust/ast/rust-path.h | 2 ++
gcc/rust/ast/rust-pattern.h | 33 +++++++++++++++++++++++++++++++++
4 files changed, 60 insertions(+)
diff --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h
index 92faaf297f9d..edf726b1ffec 100644
--- a/gcc/rust/ast/rust-ast.h
+++ b/gcc/rust/ast/rust-ast.h
@@ -1360,12 +1360,32 @@ protected:
class Pattern : public Visitable
{
public:
+ enum class Kind
+ {
+ Literal,
+ Identifier,
+ Wildcard,
+ Rest,
+ Range,
+ Reference,
+ Struct,
+ TupleStruct,
+ Tuple,
+ Grouped,
+ Slice,
+ Alt,
+ Path,
+ MacroInvocation,
+ };
+
// Unique pointer custom clone function
std::unique_ptr<Pattern> clone_pattern () const
{
return std::unique_ptr<Pattern> (clone_pattern_impl ());
}
+ virtual Kind get_pattern_kind () = 0;
+
// possible virtual methods: is_refutable()
virtual ~Pattern () {}
diff --git a/gcc/rust/ast/rust-macro.h b/gcc/rust/ast/rust-macro.h
index bfdebfc42032..5b9ff3f22c88 100644
--- a/gcc/rust/ast/rust-macro.h
+++ b/gcc/rust/ast/rust-macro.h
@@ -610,6 +610,11 @@ public:
std::string as_string () const override;
+ Pattern::Kind get_pattern_kind () override
+ {
+ return Pattern::Kind::MacroInvocation;
+ }
+
/**
* The default constructor you should use. Whenever we parse a macro call, we
* cannot possibly know whether or not this call refers to a builtin macro or
diff --git a/gcc/rust/ast/rust-path.h b/gcc/rust/ast/rust-path.h
index ccac6303bb4b..bd3012b1bed3 100644
--- a/gcc/rust/ast/rust-path.h
+++ b/gcc/rust/ast/rust-path.h
@@ -578,6 +578,8 @@ public:
// TODO: this seems kinda dodgy
std::vector<PathExprSegment> &get_segments () { return segments; }
const std::vector<PathExprSegment> &get_segments () const { return segments; }
+
+ Pattern::Kind get_pattern_kind () override { return Pattern::Kind::Path; }
};
/* AST node representing a path-in-expression pattern (path that allows
diff --git a/gcc/rust/ast/rust-pattern.h b/gcc/rust/ast/rust-pattern.h
index 96f09355fae0..365f3b7f69d2 100644
--- a/gcc/rust/ast/rust-pattern.h
+++ b/gcc/rust/ast/rust-pattern.h
@@ -55,6 +55,8 @@ public:
const Literal &get_literal () const { return lit; }
+ Pattern::Kind get_pattern_kind () override { return Pattern::Kind::Literal; }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
@@ -149,6 +151,11 @@ public:
NodeId get_node_id () const override { return node_id; }
+ Pattern::Kind get_pattern_kind () override
+ {
+ return Pattern::Kind::Identifier;
+ }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
@@ -177,6 +184,8 @@ public:
NodeId get_node_id () const override { return node_id; }
+ Pattern::Kind get_pattern_kind () override { return Pattern::Kind::Wildcard; }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
@@ -204,6 +213,8 @@ public:
NodeId get_node_id () const override final { return node_id; }
+ Pattern::Kind get_pattern_kind () override { return Pattern::Kind::Rest; }
+
protected:
RestPattern *clone_pattern_impl () const override
{
@@ -431,6 +442,8 @@ public:
NodeId get_node_id () const override { return node_id; }
+ Pattern::Kind get_pattern_kind () override { return Pattern::Kind::Range; }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
@@ -499,6 +512,11 @@ public:
NodeId get_node_id () const override { return node_id; }
+ Pattern::Kind get_pattern_kind () override
+ {
+ return Pattern::Kind::Reference;
+ }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
@@ -934,6 +952,8 @@ public:
NodeId get_node_id () const override { return node_id; }
+ Pattern::Kind get_pattern_kind () override { return Pattern::Kind::Struct; }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
@@ -1174,6 +1194,11 @@ public:
NodeId get_node_id () const override { return node_id; }
+ Pattern::Kind get_pattern_kind () override
+ {
+ return Pattern::Kind::TupleStruct;
+ }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
@@ -1411,6 +1436,8 @@ public:
NodeId get_node_id () const override { return node_id; }
+ Pattern::Kind get_pattern_kind () override { return Pattern::Kind::Tuple; }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
@@ -1471,6 +1498,8 @@ public:
NodeId get_node_id () const override { return node_id; }
+ Pattern::Kind get_pattern_kind () override { return Pattern::Kind::Grouped; }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
@@ -1535,6 +1564,8 @@ public:
NodeId get_node_id () const override { return node_id; }
+ Pattern::Kind get_pattern_kind () override { return Pattern::Kind::Slice; }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
@@ -1600,6 +1631,8 @@ public:
NodeId get_node_id () const override { return node_id; }
+ Pattern::Kind get_pattern_kind () override { return Pattern::Kind::Alt; }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2024-05-07 16:16 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-07 16:16 [gcc/devel/rust/master] Add get_pattern_kind to Pattern Thomas Schwinge
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).