diff options
author | Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com> | 2023-10-23 17:06:43 +0200 |
---|---|---|
committer | P-E-P <32375388+P-E-P@users.noreply.github.com> | 2023-10-23 16:35:23 +0000 |
commit | 4f0da0ec6e113402a6063fc0f8cc94b8692b450a (patch) | |
tree | 17448dc8e1c50f585e8267ede881c52c0d696d29 /gcc | |
parent | af3071fc346d0e6cfd7c36a5b203589d5e1b2f85 (diff) | |
download | gcc-4f0da0ec6e113402a6063fc0f8cc94b8692b450a.zip gcc-4f0da0ec6e113402a6063fc0f8cc94b8692b450a.tar.gz gcc-4f0da0ec6e113402a6063fc0f8cc94b8692b450a.tar.bz2 |
Parse const with no value expression
Const with no value expression may exist either in trait or in disabled
blocks. This means we should be able to parse those correctly.
gcc/rust/ChangeLog:
* ast/rust-item.h: Add a new constructor for const with no value
expression.
* parse/rust-parse-impl.h (Parser::parse_const_item): Allow const with
no expression value.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/ast/rust-item.h | 7 | ||||
-rw-r--r-- | gcc/rust/parse/rust-parse-impl.h | 10 |
2 files changed, 17 insertions, 0 deletions
diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h index e842f98..99cb908 100644 --- a/gcc/rust/ast/rust-item.h +++ b/gcc/rust/ast/rust-item.h @@ -2604,6 +2604,13 @@ public: const_expr (std::move (const_expr)), locus (locus) {} + ConstantItem (std::string ident, Visibility vis, std::unique_ptr<Type> type, + std::vector<Attribute> outer_attrs, location_t locus) + : VisItem (std::move (vis), std::move (outer_attrs)), + identifier (std::move (ident)), type (std::move (type)), + const_expr (nullptr), locus (locus) + {} + ConstantItem (ConstantItem const &other) : VisItem (other), identifier (other.identifier), locus (other.locus) { diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index ad7b3bf..7b5fb83 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -4783,6 +4783,16 @@ Parser<ManagedTokenSource>::parse_const_item (AST::Visibility vis, // parse constant type (required) std::unique_ptr<AST::Type> type = parse_type (); + // A const with no given expression value + if (lexer.peek_token ()->get_id () == SEMICOLON) + { + lexer.skip_token (); + return std::unique_ptr<AST::ConstantItem> ( + new AST::ConstantItem (std::move (ident), std::move (vis), + std::move (type), std::move (outer_attrs), + locus)); + } + if (!skip_token (EQUAL)) { skip_after_semicolon (); |