public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] Remove bad has-minus flag which should be contained within AST::Literal
@ 2022-06-08 12:33 Thomas Schwinge
  0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2022-06-08 12:33 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:03ec66cf1162f139ba873e5d8237a1dfad989937

commit 03ec66cf1162f139ba873e5d8237a1dfad989937
Author: Philip Herron <philip.herron@embecosm.com>
Date:   Wed Apr 20 17:52:59 2022 +0100

    Remove bad has-minus flag which should be contained within AST::Literal

Diff:
---
 gcc/rust/ast/rust-ast-full-test.cc |  7 +------
 gcc/rust/ast/rust-pattern.h        | 24 +++++++++---------------
 gcc/rust/parse/rust-parse-impl.h   |  2 +-
 3 files changed, 11 insertions(+), 22 deletions(-)

diff --git a/gcc/rust/ast/rust-ast-full-test.cc b/gcc/rust/ast/rust-ast-full-test.cc
index e6bad4bcbad..5c6a7545d76 100644
--- a/gcc/rust/ast/rust-ast-full-test.cc
+++ b/gcc/rust/ast/rust-ast-full-test.cc
@@ -2819,12 +2819,7 @@ StructPattern::as_string () const
 std::string
 LiteralPattern::as_string () const
 {
-  std::string str;
-
-  if (has_minus)
-    str += "-";
-
-  return str + lit.as_string ();
+  return lit.as_string ();
 }
 
 std::string
diff --git a/gcc/rust/ast/rust-pattern.h b/gcc/rust/ast/rust-pattern.h
index 5d937d73925..62456e89f82 100644
--- a/gcc/rust/ast/rust-pattern.h
+++ b/gcc/rust/ast/rust-pattern.h
@@ -27,14 +27,6 @@ namespace AST {
 class LiteralPattern : public Pattern
 {
   Literal lit;
-  /* make literal have a type given by enum, etc. rustc uses an extended form of
-   * its literal token implementation */
-  // TODO: literal representation - use LiteralExpr? or another thing?
-
-  // Minus prefixed to literal (if integer or floating-point)
-  bool has_minus;
-  // Actually, this might be a good place to use a template.
-
   Location locus;
   NodeId node_id;
 
@@ -42,16 +34,14 @@ public:
   std::string as_string () const override;
 
   // Constructor for a literal pattern
-  LiteralPattern (Literal lit, Location locus, bool has_minus = false)
-    : lit (std::move (lit)), has_minus (has_minus), locus (locus),
+  LiteralPattern (Literal lit, Location locus)
+    : lit (std::move (lit)), locus (locus),
       node_id (Analysis::Mappings::get ()->get_next_node_id ())
   {}
 
-  LiteralPattern (std::string val, Literal::LitType type, Location locus,
-		  bool has_minus = false)
+  LiteralPattern (std::string val, Literal::LitType type, Location locus)
     : lit (Literal (std::move (val), type, PrimitiveCoreType::CORETYPE_STR)),
-      has_minus (has_minus), locus (locus),
-      node_id (Analysis::Mappings::get ()->get_next_node_id ())
+      locus (locus), node_id (Analysis::Mappings::get ()->get_next_node_id ())
   {}
 
   Location get_locus () const override final { return locus; }
@@ -62,6 +52,10 @@ public:
 
   NodeId get_pattern_node_id () const override final { return node_id; }
 
+  Literal &get_literal () { return lit; }
+
+  const Literal &get_literal () const { return lit; }
+
 protected:
   /* Use covariance to implement clone function as returning this object rather
    * than base */
@@ -1110,7 +1104,7 @@ public:
   TupleStructPattern (TupleStructPattern &&other) = default;
   TupleStructPattern &operator= (TupleStructPattern &&other) = default;
 
-  Location get_locus () const { return path.get_locus (); }
+  Location get_locus () const override { return path.get_locus (); }
 
   void accept_vis (ASTVisitor &vis) override;
 
diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h
index c95afd64e8b..0198bfa3e55 100644
--- a/gcc/rust/parse/rust-parse-impl.h
+++ b/gcc/rust/parse/rust-parse-impl.h
@@ -10400,7 +10400,7 @@ Parser<ManagedTokenSource>::parse_literal_or_range_pattern ()
       // literal pattern
       return std::unique_ptr<AST::LiteralPattern> (
 	new AST::LiteralPattern (range_lower->get_str (), type,
-				 range_lower->get_locus (), has_minus));
+				 range_lower->get_locus ()));
     }
 }


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-06-08 12:33 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-08 12:33 [gcc/devel/rust/master] Remove bad has-minus flag which should be contained within AST::Literal 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).