diff options
author | Philip Herron <philip.herron@embecosm.com> | 2021-01-05 17:49:01 +0000 |
---|---|---|
committer | Philip Herron <herron.philip@googlemail.com> | 2021-01-06 10:13:39 +0000 |
commit | 1a97dbc6b54cd77ba7c3f00cb8dd2e870017a83c (patch) | |
tree | 8fc0819dcb268ce0a36e63d4947563aca056529b /gcc/rust/ast | |
parent | 4d590e5d210492444c4a2b69282970d683cf7c8d (diff) | |
download | gcc-1a97dbc6b54cd77ba7c3f00cb8dd2e870017a83c.zip gcc-1a97dbc6b54cd77ba7c3f00cb8dd2e870017a83c.tar.gz gcc-1a97dbc6b54cd77ba7c3f00cb8dd2e870017a83c.tar.bz2 |
Examine the Suffix hint on integers to apply apropriate TyTy type.
This change propagates the PrimitiveCoreType to AST and HIR so
the suffix can be examined.
Diffstat (limited to 'gcc/rust/ast')
-rw-r--r-- | gcc/rust/ast/rust-ast-full-test.cc | 21 | ||||
-rw-r--r-- | gcc/rust/ast/rust-ast.h | 16 | ||||
-rw-r--r-- | gcc/rust/ast/rust-expr.h | 4 | ||||
-rw-r--r-- | gcc/rust/ast/rust-pattern.h | 4 |
4 files changed, 29 insertions, 16 deletions
diff --git a/gcc/rust/ast/rust-ast-full-test.cc b/gcc/rust/ast/rust-ast-full-test.cc index 030b0b3..5c1289e 100644 --- a/gcc/rust/ast/rust-ast-full-test.cc +++ b/gcc/rust/ast/rust-ast-full-test.cc @@ -4940,28 +4940,30 @@ MacroParser::parse_literal () { case CHAR_LITERAL: skip_token (); - return Literal (tok->as_string (), Literal::CHAR); + return Literal (tok->as_string (), Literal::CHAR, tok->get_type_hint ()); case STRING_LITERAL: skip_token (); - return Literal (tok->as_string (), Literal::STRING); + return Literal (tok->as_string (), Literal::STRING, + tok->get_type_hint ()); case BYTE_CHAR_LITERAL: skip_token (); - return Literal (tok->as_string (), Literal::BYTE); + return Literal (tok->as_string (), Literal::BYTE, tok->get_type_hint ()); case BYTE_STRING_LITERAL: skip_token (); - return Literal (tok->as_string (), Literal::BYTE_STRING); + return Literal (tok->as_string (), Literal::BYTE_STRING, + tok->get_type_hint ()); case INT_LITERAL: skip_token (); - return Literal (tok->as_string (), Literal::INT); + return Literal (tok->as_string (), Literal::INT, tok->get_type_hint ()); case FLOAT_LITERAL: skip_token (); - return Literal (tok->as_string (), Literal::FLOAT); + return Literal (tok->as_string (), Literal::FLOAT, tok->get_type_hint ()); case TRUE_LITERAL: skip_token (); - return Literal ("true", Literal::BOOL); + return Literal ("true", Literal::BOOL, tok->get_type_hint ()); case FALSE_LITERAL: skip_token (); - return Literal ("false", Literal::BOOL); + return Literal ("false", Literal::BOOL, tok->get_type_hint ()); default: rust_error_at (tok->get_locus (), "expected literal - found '%s'", get_token_description (tok->get_id ())); @@ -5284,7 +5286,8 @@ Token::to_token_stream () const Attribute MetaNameValueStr::to_attribute () const { - LiteralExpr lit_expr (str, Literal::LitType::STRING, Location ()); + LiteralExpr lit_expr (str, Literal::LitType::STRING, + PrimitiveCoreType::CORETYPE_UNKNOWN, Location ()); return Attribute (SimplePath::from_str (ident), std::unique_ptr<AttrInputLiteral> ( new AttrInputLiteral (std::move (lit_expr)))); diff --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h index b26c770..941b2fe 100644 --- a/gcc/rust/ast/rust-ast.h +++ b/gcc/rust/ast/rust-ast.h @@ -212,6 +212,8 @@ public: Location get_locus () const { return locus; } + PrimitiveCoreType get_type_hint () const { return type_hint; } + protected: // No virtual for now as not polymorphic but can be in future /*virtual*/ Token *clone_token_impl () const { return new Token (*this); } @@ -250,17 +252,25 @@ private: * (or generics) */ std::string value_as_string; LitType type; + PrimitiveCoreType type_hint; public: std::string as_string () const { return value_as_string; } LitType get_lit_type () const { return type; } - Literal (std::string value_as_string, LitType type) - : value_as_string (std::move (value_as_string)), type (type) + PrimitiveCoreType get_type_hint () const { return type_hint; } + + Literal (std::string value_as_string, LitType type, + PrimitiveCoreType type_hint) + : value_as_string (std::move (value_as_string)), type (type), + type_hint (type_hint) {} - static Literal create_error () { return Literal ("", CHAR); } + static Literal create_error () + { + return Literal ("", CHAR, PrimitiveCoreType::CORETYPE_UNKNOWN); + } // Returns whether literal is in an invalid state. bool is_error () const { return value_as_string == ""; } diff --git a/gcc/rust/ast/rust-expr.h b/gcc/rust/ast/rust-expr.h index 584e210..8baf7b7 100644 --- a/gcc/rust/ast/rust-expr.h +++ b/gcc/rust/ast/rust-expr.h @@ -50,10 +50,10 @@ public: Literal::LitType get_lit_type () const { return literal.get_lit_type (); } LiteralExpr (std::string value_as_string, Literal::LitType type, - Location locus, + PrimitiveCoreType type_hint, Location locus, std::vector<Attribute> outer_attrs = std::vector<Attribute> ()) : ExprWithoutBlock (std::move (outer_attrs)), - literal (std::move (value_as_string), type), locus (locus) + literal (std::move (value_as_string), type, type_hint), locus (locus) {} LiteralExpr (Literal literal, Location locus, diff --git a/gcc/rust/ast/rust-pattern.h b/gcc/rust/ast/rust-pattern.h index 79beebb..e89fc62 100644 --- a/gcc/rust/ast/rust-pattern.h +++ b/gcc/rust/ast/rust-pattern.h @@ -47,8 +47,8 @@ public: LiteralPattern (std::string val, Literal::LitType type, Location locus, bool has_minus = false) - : lit (Literal (std::move (val), type)), has_minus (has_minus), - locus (locus) + : lit (Literal (std::move (val), type, PrimitiveCoreType::CORETYPE_STR)), + has_minus (has_minus), locus (locus) {} Location get_locus () const { return locus; } |