]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: parser: Propagate type hint value
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Wed, 28 Jun 2023 11:53:37 +0000 (13:53 +0200)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 16 Jan 2024 17:49:29 +0000 (18:49 +0100)
Type hint value was not propagated correctly to LiteralPattern in ast.
This was defaulted to CORETYPE_STR instead, which introduced several
bugs with systems that did require any ast collection.

gcc/rust/ChangeLog:

* ast/rust-pattern.h: Change constructor to accept new parameter
instead of defaulting on string type.
* parse/rust-parse-impl.h (Parser::parse_literal_or_range_pattern):
Propagate type hint.
(Parser::parse_pattern_no_alt): Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
gcc/rust/ast/rust-pattern.h
gcc/rust/parse/rust-parse-impl.h

index 90111df10c749890800f5f6a85f2ab627d8c1bcd..c5a2ea7eb70d992778d00af68582e20c003a2c44 100644 (file)
@@ -39,9 +39,10 @@ public:
       node_id (Analysis::Mappings::get ()->get_next_node_id ())
   {}
 
-  LiteralPattern (std::string val, Literal::LitType type, Location locus)
-    : lit (Literal (std::move (val), type, PrimitiveCoreType::CORETYPE_STR)),
-      locus (locus), node_id (Analysis::Mappings::get ()->get_next_node_id ())
+  LiteralPattern (std::string val, Literal::LitType type, Location locus,
+                 PrimitiveCoreType type_hint)
+    : lit (Literal (std::move (val), type, type_hint)), locus (locus),
+      node_id (Analysis::Mappings::get ()->get_next_node_id ())
   {}
 
   Location get_locus () const override final { return locus; }
index 6bce55c43a9696bc700df38627aa2e3b106a60c9..f3b795dd178a0f608383f47391d62a0e76022277 100644 (file)
@@ -10397,7 +10397,8 @@ 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 ()));
+                                range_lower->get_locus (),
+                                range_lower->get_type_hint ()));
     }
 }
 
@@ -10559,11 +10560,13 @@ Parser<ManagedTokenSource>::parse_pattern_no_alt ()
     case TRUE_LITERAL:
       lexer.skip_token ();
       return std::unique_ptr<AST::LiteralPattern> (
-       new AST::LiteralPattern ("true", AST::Literal::BOOL, t->get_locus ()));
+       new AST::LiteralPattern ("true", AST::Literal::BOOL, t->get_locus (),
+                                t->get_type_hint ()));
     case FALSE_LITERAL:
       lexer.skip_token ();
       return std::unique_ptr<AST::LiteralPattern> (
-       new AST::LiteralPattern ("false", AST::Literal::BOOL, t->get_locus ()));
+       new AST::LiteralPattern ("false", AST::Literal::BOOL, t->get_locus (),
+                                t->get_type_hint ()));
     case CHAR_LITERAL:
     case BYTE_CHAR_LITERAL:
     case INT_LITERAL:
@@ -10573,12 +10576,12 @@ Parser<ManagedTokenSource>::parse_pattern_no_alt ()
       lexer.skip_token ();
       return std::unique_ptr<AST::LiteralPattern> (
        new AST::LiteralPattern (t->get_str (), AST::Literal::STRING,
-                                t->get_locus ()));
+                                t->get_locus (), t->get_type_hint ()));
     case BYTE_STRING_LITERAL:
       lexer.skip_token ();
       return std::unique_ptr<AST::LiteralPattern> (
        new AST::LiteralPattern (t->get_str (), AST::Literal::BYTE_STRING,
-                                t->get_locus ()));
+                                t->get_locus (), t->get_type_hint ()));
     // raw string and raw byte string literals too if they are readded to
     // lexer
     case MINUS: