diff options
author | Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com> | 2023-06-28 13:53:37 +0200 |
---|---|---|
committer | CohenArthur <arthur.cohen@embecosm.com> | 2023-06-30 14:24:44 +0000 |
commit | 1db82e8886d5704f0f3948f74b9f11c13bc80228 (patch) | |
tree | 7cb0916d5b849d25ec9df55d2a823062fd15e29f | |
parent | abfb39e2c6942efb6a60fc25bd6fe9fee2c15392 (diff) | |
download | gcc-1db82e8886d5704f0f3948f74b9f11c13bc80228.zip gcc-1db82e8886d5704f0f3948f74b9f11c13bc80228.tar.gz gcc-1db82e8886d5704f0f3948f74b9f11c13bc80228.tar.bz2 |
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.h | 7 | ||||
-rw-r--r-- | gcc/rust/parse/rust-parse-impl.h | 13 |
2 files changed, 12 insertions, 8 deletions
diff --git a/gcc/rust/ast/rust-pattern.h b/gcc/rust/ast/rust-pattern.h index 10af61f..f854563 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 c0de23c..ad52824 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: |