aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/parse/rust-parse-impl.h
diff options
context:
space:
mode:
authorMark Wielaard <mark@klomp.org>2021-09-06 00:48:09 +0200
committerPhilip Herron <philip.herron@embecosm.com>2021-09-06 10:31:35 +0100
commit2bbe1af01db19b67cf668384b096e0e6a01765e6 (patch)
tree55446764ab88b4d4a09f30e57364012baf42cd24 /gcc/rust/parse/rust-parse-impl.h
parent50623899998de5a8ffe47227a351c2b3dd29aa0a (diff)
downloadgcc-2bbe1af01db19b67cf668384b096e0e6a01765e6.zip
gcc-2bbe1af01db19b67cf668384b096e0e6a01765e6.tar.gz
gcc-2bbe1af01db19b67cf668384b096e0e6a01765e6.tar.bz2
Parse optional visibility for enum item
Syntactically enum items can have a visibility. The visibility has to be removed (through a cfg attribute or macro) before they get lowered. The semantic checking will be done when we implement lowering enum items. Make the AST EnumItem class a VisItem. This simplifies things a little for cloning items, handling outer attributes and will help when adding EnumItem (sub)classes to AST visitors (so they can be handled as Items). Also add a get_identifier method to Enum and EnumItem.
Diffstat (limited to 'gcc/rust/parse/rust-parse-impl.h')
-rw-r--r--gcc/rust/parse/rust-parse-impl.h12
1 files changed, 8 insertions, 4 deletions
diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h
index 1c0644d..8cce933 100644
--- a/gcc/rust/parse/rust-parse-impl.h
+++ b/gcc/rust/parse/rust-parse-impl.h
@@ -4431,6 +4431,9 @@ Parser<ManagedTokenSource>::parse_enum_item ()
// parse outer attributes if they exist
AST::AttrVec outer_attrs = parse_outer_attributes ();
+ // parse visibility, which may or may not exist
+ AST::Visibility vis = parse_visibility ();
+
// parse name for enum item, which is required
const_TokenPtr item_name_tok = lexer.peek_token ();
if (item_name_tok->get_id () != IDENTIFIER)
@@ -4463,7 +4466,7 @@ Parser<ManagedTokenSource>::parse_enum_item ()
}
return std::unique_ptr<AST::EnumItemTuple> (new AST::EnumItemTuple (
- std::move (item_name), std::move (tuple_fields),
+ std::move (item_name), std::move (vis), std::move (tuple_fields),
std::move (outer_attrs), item_name_tok->get_locus ()));
}
case LEFT_CURLY: {
@@ -4480,7 +4483,7 @@ Parser<ManagedTokenSource>::parse_enum_item ()
}
return std::unique_ptr<AST::EnumItemStruct> (new AST::EnumItemStruct (
- std::move (item_name), std::move (struct_fields),
+ std::move (item_name), std::move (vis), std::move (struct_fields),
std::move (outer_attrs), item_name_tok->get_locus ()));
}
case EQUAL: {
@@ -4490,7 +4493,7 @@ Parser<ManagedTokenSource>::parse_enum_item ()
std::unique_ptr<AST::Expr> discriminant_expr = parse_expr ();
return std::unique_ptr<AST::EnumItemDiscriminant> (
- new AST::EnumItemDiscriminant (std::move (item_name),
+ new AST::EnumItemDiscriminant (std::move (item_name), std::move (vis),
std::move (discriminant_expr),
std::move (outer_attrs),
item_name_tok->get_locus ()));
@@ -4498,7 +4501,8 @@ Parser<ManagedTokenSource>::parse_enum_item ()
default:
// regular enum with just an identifier
return std::unique_ptr<AST::EnumItem> (
- new AST::EnumItem (std::move (item_name), std::move (outer_attrs),
+ new AST::EnumItem (std::move (item_name), std::move (vis),
+ std::move (outer_attrs),
item_name_tok->get_locus ()));
}
}