public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Thomas Schwinge <tschwinge@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc/devel/rust/master] parser: Parse external type item
Date: Tue, 28 Feb 2023 22:36:44 +0000 (GMT)	[thread overview]
Message-ID: <20230228223644.4DEE93858C50@sourceware.org> (raw)

https://gcc.gnu.org/g:689c421dd7a92bba7e31342a034fb25b85407b37

commit 689c421dd7a92bba7e31342a034fb25b85407b37
Author: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Date:   Mon Feb 27 10:10:51 2023 +0100

    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 <pierre-emmanuel.patry@embecosm.com>

Diff:
---
 gcc/rust/parse/rust-parse-impl.h | 31 +++++++++++++++++++++++++++++++
 gcc/rust/parse/rust-parse.h      |  2 ++
 2 files changed, 33 insertions(+)

diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h
index 7807d750ba2..7988d12309d 100644
--- a/gcc/rust/parse/rust-parse-impl.h
+++ b/gcc/rust/parse/rust-parse-impl.h
@@ -3990,6 +3990,34 @@ Parser<ManagedTokenSource>::parse_lifetime ()
     }
 }
 
+template <typename ManagedTokenSource>
+std::unique_ptr<AST::ExternalTypeItem>
+Parser<ManagedTokenSource>::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<AST::ExternalTypeItem> (
+    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 <typename ManagedTokenSource>
 std::unique_ptr<AST::TypeAlias>
@@ -6011,6 +6039,9 @@ Parser<ManagedTokenSource>::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 (
diff --git a/gcc/rust/parse/rust-parse.h b/gcc/rust/parse/rust-parse.h
index 54a87c946f9..42168e961e3 100644
--- a/gcc/rust/parse/rust-parse.h
+++ b/gcc/rust/parse/rust-parse.h
@@ -273,6 +273,8 @@ private:
   template <typename EndTokenPred>
   std::vector<AST::Lifetime> parse_lifetime_bounds (EndTokenPred is_end_token);
   AST::Lifetime parse_lifetime ();
+  std::unique_ptr<AST::ExternalTypeItem>
+  parse_external_type_item (AST::Visibility vis, AST::AttrVec outer_attrs);
   std::unique_ptr<AST::TypeAlias> parse_type_alias (AST::Visibility vis,
 						    AST::AttrVec outer_attrs);
   std::unique_ptr<AST::Struct> parse_struct (AST::Visibility vis,

                 reply	other threads:[~2023-02-28 22:36 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230228223644.4DEE93858C50@sourceware.org \
    --to=tschwinge@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).