From 689c421dd7a92bba7e31342a034fb25b85407b37 Mon Sep 17 00:00:00 2001 From: Pierre-Emmanuel Patry Date: Mon, 27 Feb 2023 10:10:51 +0100 Subject: parser: Parse external type item Add the code to parse type item declaration within an extern block. gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_external_type_item): Add function to parser an external type item. (Parser::parse_external_item): Add identification and parsing for external type items. * parse/rust-parse.h: Add parser_external_type_item prototype. Signed-off-by: Pierre-Emmanuel Patry --- gcc/rust/parse/rust-parse-impl.h | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'gcc/rust/parse/rust-parse-impl.h') diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index 7807d75..7988d12 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -3990,6 +3990,34 @@ Parser::parse_lifetime () } } +template +std::unique_ptr +Parser::parse_external_type_item (AST::Visibility vis, + AST::AttrVec outer_attrs) +{ + Location locus = lexer.peek_token ()->get_locus (); + skip_token (TYPE); + + const_TokenPtr alias_name_tok = expect_token (IDENTIFIER); + if (alias_name_tok == nullptr) + { + Error error (lexer.peek_token ()->get_locus (), + "could not parse identifier in external opaque type"); + add_error (std::move (error)); + + skip_after_semicolon (); + return nullptr; + } + + if (!skip_token (SEMICOLON)) + return nullptr; + + return std::unique_ptr ( + new AST::ExternalTypeItem (std::move (alias_name_tok->get_str ()), + std::move (vis), std::move (outer_attrs), + std::move (locus))); +} + // Parses a "type alias" (typedef) item. template std::unique_ptr @@ -6011,6 +6039,9 @@ Parser::parse_external_item () std::move (variadic_attrs), std::move (vis), std::move (outer_attrs), locus)); } + case TYPE: + return parse_external_type_item (std::move (vis), + std::move (outer_attrs)); default: // error add_error ( -- cgit v1.1