From: Pierre-Emmanuel Patry Date: Wed, 28 Jun 2023 11:53:37 +0000 (+0200) Subject: gccrs: parser: Propagate type hint value X-Git-Tag: basepoints/gcc-15~2421 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e6c44bae4e3ab962aed6354830d0fdc74dd2c49b;p=thirdparty%2Fgcc.git 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 --- diff --git a/gcc/rust/ast/rust-pattern.h b/gcc/rust/ast/rust-pattern.h index 90111df10c74..c5a2ea7eb70d 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 6bce55c43a96..f3b795dd178a 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -10397,7 +10397,8 @@ Parser::parse_literal_or_range_pattern () // literal pattern return std::unique_ptr ( 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::parse_pattern_no_alt () case TRUE_LITERAL: lexer.skip_token (); return std::unique_ptr ( - 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 ( - 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::parse_pattern_no_alt () lexer.skip_token (); return std::unique_ptr ( 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 ( 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: