aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>2023-06-28 13:53:37 +0200
committerArthur Cohen <arthur.cohen@embecosm.com>2024-01-16 18:49:29 +0100
commite6c44bae4e3ab962aed6354830d0fdc74dd2c49b (patch)
tree15696aa5028849f586e1c4592b70841a1bba3c0d
parenteebe4063c1a839a71fd21cb477c9d9a6cc906195 (diff)
downloadgcc-e6c44bae4e3ab962aed6354830d0fdc74dd2c49b.zip
gcc-e6c44bae4e3ab962aed6354830d0fdc74dd2c49b.tar.gz
gcc-e6c44bae4e3ab962aed6354830d0fdc74dd2c49b.tar.bz2
gccrs: parser: Propagate type hint value
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>
-rw-r--r--gcc/rust/ast/rust-pattern.h7
-rw-r--r--gcc/rust/parse/rust-parse-impl.h13
2 files changed, 12 insertions, 8 deletions
diff --git a/gcc/rust/ast/rust-pattern.h b/gcc/rust/ast/rust-pattern.h
index 90111df..c5a2ea7 100644
--- a/gcc/rust/ast/rust-pattern.h
+++ b/gcc/rust/ast/rust-pattern.h
@@ -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; }
diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h
index 6bce55c..f3b795d 100644
--- a/gcc/rust/parse/rust-parse-impl.h
+++ b/gcc/rust/parse/rust-parse-impl.h
@@ -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: