aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/ast/rust-pattern.cc
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/rust/ast/rust-pattern.cc')
-rw-r--r--gcc/rust/ast/rust-pattern.cc32
1 files changed, 27 insertions, 5 deletions
diff --git a/gcc/rust/ast/rust-pattern.cc b/gcc/rust/ast/rust-pattern.cc
index 9091637..c62a4c3 100644
--- a/gcc/rust/ast/rust-pattern.cc
+++ b/gcc/rust/ast/rust-pattern.cc
@@ -22,7 +22,6 @@ along with GCC; see the file COPYING3. If not see
#include "rust-diagnostics.h"
#include "rust-ast-visitor.h"
#include "rust-macro.h"
-#include "rust-session-manager.h"
#include "rust-lex.h"
#include "rust-parse.h"
#include "rust-operators.h"
@@ -30,6 +29,22 @@ along with GCC; see the file COPYING3. If not see
namespace Rust {
namespace AST {
+RangeKind
+tokenid_to_rangekind (TokenId id)
+{
+ switch (id)
+ {
+ case DOT_DOT_EQ:
+ return RangeKind::INCLUDED;
+ case ELLIPSIS:
+ return RangeKind::ELLIPSIS;
+ case DOT_DOT:
+ return RangeKind::EXCLUDED;
+ default:
+ rust_unreachable ();
+ }
+}
+
std::string
LiteralPattern::as_string () const
{
@@ -73,10 +88,17 @@ std::string
RangePattern::as_string () const
{
// TODO: maybe rewrite to work with non-linearisable bounds
- if (has_ellipsis_syntax)
- return lower->as_string () + "..." + upper->as_string ();
- else
- return lower->as_string () + "..=" + upper->as_string ();
+ switch (range_kind)
+ {
+ case RangeKind::EXCLUDED:
+ return lower->as_string () + ".." + upper->as_string ();
+ case RangeKind::INCLUDED:
+ return lower->as_string () + "..=" + upper->as_string ();
+ case RangeKind::ELLIPSIS:
+ return lower->as_string () + "..." + upper->as_string ();
+ default:
+ rust_unreachable ();
+ }
}
std::string