Sync the `global_decl` grammar rule
This Cl updates the parser implementation of the `global_decl` rule. The `type_alias` rule is renamed to `type_alias_decl` and the `struct` parsing is moved out of the synchronization to `;` code as a `struct` no longer has a trailling `;`. Bug: tint:1633 Change-Id: I44b25035cbe0ea0963ec73400986205e1623060e Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/98065 Reviewed-by: Antonio Maiorano <amaiorano@google.com> Auto-Submit: Dan Sinclair <dsinclair@chromium.org> Kokoro: Kokoro <noreply+kokoro@google.com> Commit-Queue: Antonio Maiorano <amaiorano@google.com>
This commit is contained in:
parent
c2a052eaa4
commit
b8893b4c2f
|
@ -440,7 +440,7 @@ Maybe<bool> ParserImpl::enable_directive() {
|
|||
// : SEMICOLON
|
||||
// | global_variable_decl SEMICOLON
|
||||
// | global_constant_decl SEMICOLON
|
||||
// | type_alias SEMICOLON
|
||||
// | type_alias_decl SEMICOLON
|
||||
// | struct_decl
|
||||
// | function_decl
|
||||
// | static_assert_statement SEMICOLON
|
||||
|
@ -450,7 +450,6 @@ Maybe<bool> ParserImpl::global_decl() {
|
|||
}
|
||||
|
||||
bool errored = false;
|
||||
|
||||
auto attrs = attribute_list();
|
||||
if (attrs.errored) {
|
||||
errored = true;
|
||||
|
@ -490,7 +489,7 @@ Maybe<bool> ParserImpl::global_decl() {
|
|||
return true;
|
||||
}
|
||||
|
||||
auto ta = type_alias();
|
||||
auto ta = type_alias_decl();
|
||||
if (ta.errored) {
|
||||
return Failure::kErrored;
|
||||
}
|
||||
|
@ -503,15 +502,6 @@ Maybe<bool> ParserImpl::global_decl() {
|
|||
return true;
|
||||
}
|
||||
|
||||
auto str = struct_decl();
|
||||
if (str.errored) {
|
||||
return Failure::kErrored;
|
||||
}
|
||||
if (str.matched) {
|
||||
builder_.AST().AddTypeDecl(str.value);
|
||||
return true;
|
||||
}
|
||||
|
||||
auto assertion = static_assert_stmt();
|
||||
if (assertion.errored) {
|
||||
return Failure::kErrored;
|
||||
|
@ -534,6 +524,15 @@ Maybe<bool> ParserImpl::global_decl() {
|
|||
return expect_attributes_consumed(attrs.value);
|
||||
}
|
||||
|
||||
auto str = struct_decl();
|
||||
if (str.errored) {
|
||||
errored = true;
|
||||
}
|
||||
if (str.matched) {
|
||||
builder_.AST().AddTypeDecl(str.value);
|
||||
return true;
|
||||
}
|
||||
|
||||
auto func = function_decl(attrs.value);
|
||||
if (func.errored) {
|
||||
errored = true;
|
||||
|
@ -1021,9 +1020,9 @@ Maybe<ParserImpl::VariableQualifier> ParserImpl::variable_qualifier() {
|
|||
return vq;
|
||||
}
|
||||
|
||||
// type_alias
|
||||
// type_alias_decl
|
||||
// : TYPE IDENT EQUAL type_decl
|
||||
Maybe<const ast::Alias*> ParserImpl::type_alias() {
|
||||
Maybe<const ast::Alias*> ParserImpl::type_alias_decl() {
|
||||
if (!peek_is(Token::Type::kType)) {
|
||||
return Failure::kNoMatch;
|
||||
}
|
||||
|
|
|
@ -420,9 +420,9 @@ class ParserImpl {
|
|||
/// Parses a `variable_qualifier` grammar element
|
||||
/// @returns the variable qualifier information
|
||||
Maybe<VariableQualifier> variable_qualifier();
|
||||
/// Parses a `type_alias` grammar element
|
||||
/// Parses a `type_alias_decl` grammar element
|
||||
/// @returns the type alias or nullptr on error
|
||||
Maybe<const ast::Alias*> type_alias();
|
||||
Maybe<const ast::Alias*> type_alias_decl();
|
||||
/// Parses a `type_decl` grammar element
|
||||
/// @returns the parsed Type or nullptr if none matched.
|
||||
Maybe<const ast::Type*> type_decl();
|
||||
|
|
|
@ -20,7 +20,7 @@ namespace {
|
|||
TEST_F(ParserImplTest, TypeDecl_ParsesType) {
|
||||
auto p = parser("type a = i32");
|
||||
|
||||
auto t = p->type_alias();
|
||||
auto t = p->type_alias_decl();
|
||||
EXPECT_FALSE(p->has_error());
|
||||
EXPECT_FALSE(t.errored);
|
||||
EXPECT_TRUE(t.matched);
|
||||
|
@ -35,7 +35,7 @@ TEST_F(ParserImplTest, TypeDecl_ParsesType) {
|
|||
TEST_F(ParserImplTest, TypeDecl_Parses_Ident) {
|
||||
auto p = parser("type a = B");
|
||||
|
||||
auto t = p->type_alias();
|
||||
auto t = p->type_alias_decl();
|
||||
EXPECT_FALSE(p->has_error());
|
||||
EXPECT_FALSE(t.errored);
|
||||
EXPECT_TRUE(t.matched);
|
||||
|
@ -54,7 +54,7 @@ TEST_F(ParserImplTest, TypeDecl_Unicode_Parses_Ident) {
|
|||
|
||||
auto p = parser("type " + ident + " = i32");
|
||||
|
||||
auto t = p->type_alias();
|
||||
auto t = p->type_alias_decl();
|
||||
EXPECT_FALSE(p->has_error());
|
||||
EXPECT_FALSE(t.errored);
|
||||
EXPECT_TRUE(t.matched);
|
||||
|
@ -68,7 +68,7 @@ TEST_F(ParserImplTest, TypeDecl_Unicode_Parses_Ident) {
|
|||
|
||||
TEST_F(ParserImplTest, TypeDecl_MissingIdent) {
|
||||
auto p = parser("type = i32");
|
||||
auto t = p->type_alias();
|
||||
auto t = p->type_alias_decl();
|
||||
EXPECT_TRUE(t.errored);
|
||||
EXPECT_FALSE(t.matched);
|
||||
EXPECT_TRUE(p->has_error());
|
||||
|
@ -78,7 +78,7 @@ TEST_F(ParserImplTest, TypeDecl_MissingIdent) {
|
|||
|
||||
TEST_F(ParserImplTest, TypeDecl_InvalidIdent) {
|
||||
auto p = parser("type 123 = i32");
|
||||
auto t = p->type_alias();
|
||||
auto t = p->type_alias_decl();
|
||||
EXPECT_TRUE(t.errored);
|
||||
EXPECT_FALSE(t.matched);
|
||||
EXPECT_TRUE(p->has_error());
|
||||
|
@ -88,7 +88,7 @@ TEST_F(ParserImplTest, TypeDecl_InvalidIdent) {
|
|||
|
||||
TEST_F(ParserImplTest, TypeDecl_MissingEqual) {
|
||||
auto p = parser("type a i32");
|
||||
auto t = p->type_alias();
|
||||
auto t = p->type_alias_decl();
|
||||
EXPECT_TRUE(t.errored);
|
||||
EXPECT_FALSE(t.matched);
|
||||
EXPECT_TRUE(p->has_error());
|
||||
|
|
Loading…
Reference in New Issue