Context aware address space parsing.
This Cl remoevs the address space names from the keyword list and makes their parsing context dependant. The mechanism in the parser is the same, we just change to looking for an `ident` in `expect_address_space`. `storage_buffer` is kept for now, this keeps the functionality the same. Bug: tint:1621 Change-Id: I928a5472d8ac194b2bef2da56a224e9f4abb65a8 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/96905 Commit-Queue: Ben Clayton <bclayton@google.com> Kokoro: Kokoro <noreply+kokoro@google.com> Auto-Submit: Dan Sinclair <dsinclair@chromium.org> Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
parent
87254ff58e
commit
a089376daf
|
@ -1127,9 +1127,6 @@ Token Lexer::check_keyword(const Source& source, std::string_view str) {
|
|||
if (str == "for") {
|
||||
return {Token::Type::kFor, source, "for"};
|
||||
}
|
||||
if (str == "function") {
|
||||
return {Token::Type::kFunction, source, "function"};
|
||||
}
|
||||
if (str == "i32") {
|
||||
return {Token::Type::kI32, source, "i32"};
|
||||
}
|
||||
|
@ -1175,9 +1172,6 @@ Token Lexer::check_keyword(const Source& source, std::string_view str) {
|
|||
if (str == "override") {
|
||||
return {Token::Type::kOverride, source, "override"};
|
||||
}
|
||||
if (str == "private") {
|
||||
return {Token::Type::kPrivate, source, "private"};
|
||||
}
|
||||
if (str == "ptr") {
|
||||
return {Token::Type::kPtr, source, "ptr"};
|
||||
}
|
||||
|
@ -1190,9 +1184,6 @@ Token Lexer::check_keyword(const Source& source, std::string_view str) {
|
|||
if (str == "sampler_comparison") {
|
||||
return {Token::Type::kComparisonSampler, source, "sampler_comparison"};
|
||||
}
|
||||
if (str == "storage_buffer" || str == "storage") {
|
||||
return {Token::Type::kStorage, source, "storage"};
|
||||
}
|
||||
if (str == "struct") {
|
||||
return {Token::Type::kStruct, source, "struct"};
|
||||
}
|
||||
|
@ -1259,9 +1250,6 @@ Token Lexer::check_keyword(const Source& source, std::string_view str) {
|
|||
if (str == "u32") {
|
||||
return {Token::Type::kU32, source, "u32"};
|
||||
}
|
||||
if (str == "uniform") {
|
||||
return {Token::Type::kUniform, source, "uniform"};
|
||||
}
|
||||
if (str == "var") {
|
||||
return {Token::Type::kVar, source, "var"};
|
||||
}
|
||||
|
@ -1277,9 +1265,6 @@ Token Lexer::check_keyword(const Source& source, std::string_view str) {
|
|||
if (str == "while") {
|
||||
return {Token::Type::kWhile, source, "while"};
|
||||
}
|
||||
if (str == "workgroup") {
|
||||
return {Token::Type::kWorkgroup, source, "workgroup"};
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
|
|
|
@ -941,7 +941,6 @@ INSTANTIATE_TEST_SUITE_P(
|
|||
TokenData{"false", Token::Type::kFalse},
|
||||
TokenData{"fn", Token::Type::kFn},
|
||||
TokenData{"for", Token::Type::kFor},
|
||||
TokenData{"function", Token::Type::kFunction},
|
||||
TokenData{"i32", Token::Type::kI32},
|
||||
TokenData{"if", Token::Type::kIf},
|
||||
TokenData{"import", Token::Type::kImport},
|
||||
|
@ -957,13 +956,10 @@ INSTANTIATE_TEST_SUITE_P(
|
|||
TokenData{"mat4x3", Token::Type::kMat4x3},
|
||||
TokenData{"mat4x4", Token::Type::kMat4x4},
|
||||
TokenData{"override", Token::Type::kOverride},
|
||||
TokenData{"private", Token::Type::kPrivate},
|
||||
TokenData{"ptr", Token::Type::kPtr},
|
||||
TokenData{"return", Token::Type::kReturn},
|
||||
TokenData{"sampler", Token::Type::kSampler},
|
||||
TokenData{"sampler_comparison", Token::Type::kComparisonSampler},
|
||||
TokenData{"storage", Token::Type::kStorage},
|
||||
TokenData{"storage_buffer", Token::Type::kStorage},
|
||||
TokenData{"struct", Token::Type::kStruct},
|
||||
TokenData{"switch", Token::Type::kSwitch},
|
||||
TokenData{"texture_1d", Token::Type::kTextureSampled1d},
|
||||
|
@ -986,13 +982,11 @@ INSTANTIATE_TEST_SUITE_P(
|
|||
TokenData{"true", Token::Type::kTrue},
|
||||
TokenData{"type", Token::Type::kType},
|
||||
TokenData{"u32", Token::Type::kU32},
|
||||
TokenData{"uniform", Token::Type::kUniform},
|
||||
TokenData{"var", Token::Type::kVar},
|
||||
TokenData{"vec2", Token::Type::kVec2},
|
||||
TokenData{"vec3", Token::Type::kVec3},
|
||||
TokenData{"vec4", Token::Type::kVec4},
|
||||
TokenData{"while", Token::Type::kWhile},
|
||||
TokenData{"workgroup", Token::Type::kWorkgroup}));
|
||||
TokenData{"while", Token::Type::kWhile}));
|
||||
|
||||
} // namespace
|
||||
} // namespace tint::reader::wgsl
|
||||
|
|
|
@ -1271,34 +1271,31 @@ Expect<const ast::Type*> ParserImpl::expect_type_decl_matrix(Token t) {
|
|||
return builder_.ty.mat(make_source_range_from(t.source()), subtype, columns, rows);
|
||||
}
|
||||
|
||||
// storage_class
|
||||
// : INPUT
|
||||
// | OUTPUT
|
||||
// | UNIFORM
|
||||
// | WORKGROUP
|
||||
// | STORAGE
|
||||
// | PRIVATE
|
||||
// | FUNCTION
|
||||
Expect<ast::StorageClass> ParserImpl::expect_storage_class(std::string_view use) {
|
||||
auto source = peek().source();
|
||||
auto ident = expect_ident("storage class");
|
||||
if (ident.errored) {
|
||||
return Failure::kErrored;
|
||||
}
|
||||
|
||||
if (match(Token::Type::kUniform)) {
|
||||
auto name = ident.value;
|
||||
if (name == "uniform") {
|
||||
return {ast::StorageClass::kUniform, source};
|
||||
}
|
||||
|
||||
if (match(Token::Type::kWorkgroup)) {
|
||||
if (name == "workgroup") {
|
||||
return {ast::StorageClass::kWorkgroup, source};
|
||||
}
|
||||
|
||||
if (match(Token::Type::kStorage)) {
|
||||
if (name == "storage" || name == "storage_buffer") {
|
||||
return {ast::StorageClass::kStorage, source};
|
||||
}
|
||||
|
||||
if (match(Token::Type::kPrivate)) {
|
||||
if (name == "private") {
|
||||
return {ast::StorageClass::kPrivate, source};
|
||||
}
|
||||
|
||||
if (match(Token::Type::kFunction)) {
|
||||
if (name == "function") {
|
||||
return {ast::StorageClass::kFunction, source};
|
||||
}
|
||||
|
||||
|
|
|
@ -56,10 +56,6 @@ TEST_F(ParserImplTest, StorageClass_NoMatch) {
|
|||
EXPECT_EQ(sc.errored, true);
|
||||
EXPECT_TRUE(p->has_error());
|
||||
EXPECT_EQ(p->error(), "1:1: invalid storage class for test");
|
||||
|
||||
auto t = p->next();
|
||||
EXPECT_TRUE(t.IsIdentifier());
|
||||
EXPECT_EQ(t.to_str(), "not");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
|
|
@ -272,7 +272,7 @@ TEST_F(ParserImplTest, TypeDecl_Ptr_MissingStorageClass) {
|
|||
EXPECT_FALSE(t.matched);
|
||||
ASSERT_EQ(t.value, nullptr);
|
||||
ASSERT_TRUE(p->has_error());
|
||||
ASSERT_EQ(p->error(), "1:5: invalid storage class for ptr declaration");
|
||||
ASSERT_EQ(p->error(), "1:5: expected identifier for storage class");
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, TypeDecl_Ptr_MissingType) {
|
||||
|
@ -302,7 +302,7 @@ TEST_F(ParserImplTest, TypeDecl_Ptr_MissingParams) {
|
|||
EXPECT_FALSE(t.matched);
|
||||
ASSERT_EQ(t.value, nullptr);
|
||||
ASSERT_TRUE(p->has_error());
|
||||
ASSERT_EQ(p->error(), "1:5: invalid storage class for ptr declaration");
|
||||
ASSERT_EQ(p->error(), "1:5: expected identifier for storage class");
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, TypeDecl_Ptr_BadStorageClass) {
|
||||
|
|
|
@ -73,7 +73,7 @@ TEST_F(ParserImplTest, VariableQualifier_Empty) {
|
|||
EXPECT_TRUE(p->has_error());
|
||||
EXPECT_TRUE(sc.errored);
|
||||
EXPECT_FALSE(sc.matched);
|
||||
EXPECT_EQ(p->error(), "1:2: invalid storage class for variable declaration");
|
||||
EXPECT_EQ(p->error(), "1:2: expected identifier for storage class");
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, VariableQualifier_MissingLessThan) {
|
||||
|
@ -84,7 +84,7 @@ TEST_F(ParserImplTest, VariableQualifier_MissingLessThan) {
|
|||
EXPECT_FALSE(sc.matched);
|
||||
|
||||
auto t = p->next();
|
||||
ASSERT_TRUE(t.Is(Token::Type::kPrivate));
|
||||
ASSERT_TRUE(t.Is(Token::Type::kIdentifier));
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, VariableQualifier_MissingLessThan_AfterSC) {
|
||||
|
@ -95,7 +95,7 @@ TEST_F(ParserImplTest, VariableQualifier_MissingLessThan_AfterSC) {
|
|||
EXPECT_FALSE(sc.matched);
|
||||
|
||||
auto t = p->next();
|
||||
ASSERT_TRUE(t.Is(Token::Type::kPrivate));
|
||||
ASSERT_TRUE(t.Is(Token::Type::kIdentifier));
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, VariableQualifier_MissingGreaterThan) {
|
||||
|
|
|
@ -167,8 +167,6 @@ std::string_view Token::TypeToName(Type type) {
|
|||
return "fn";
|
||||
case Token::Type::kFor:
|
||||
return "for";
|
||||
case Token::Type::kFunction:
|
||||
return "function";
|
||||
case Token::Type::kI32:
|
||||
return "i32";
|
||||
case Token::Type::kIf:
|
||||
|
@ -199,8 +197,6 @@ std::string_view Token::TypeToName(Type type) {
|
|||
return "mat4x4";
|
||||
case Token::Type::kOverride:
|
||||
return "override";
|
||||
case Token::Type::kPrivate:
|
||||
return "private";
|
||||
case Token::Type::kPtr:
|
||||
return "ptr";
|
||||
case Token::Type::kReturn:
|
||||
|
@ -209,8 +205,6 @@ std::string_view Token::TypeToName(Type type) {
|
|||
return "sampler";
|
||||
case Token::Type::kComparisonSampler:
|
||||
return "sampler_comparison";
|
||||
case Token::Type::kStorage:
|
||||
return "storage";
|
||||
case Token::Type::kStruct:
|
||||
return "struct";
|
||||
case Token::Type::kSwitch:
|
||||
|
@ -255,8 +249,6 @@ std::string_view Token::TypeToName(Type type) {
|
|||
return "type";
|
||||
case Token::Type::kU32:
|
||||
return "u32";
|
||||
case Token::Type::kUniform:
|
||||
return "uniform";
|
||||
case Token::Type::kVar:
|
||||
return "var";
|
||||
case Token::Type::kVec2:
|
||||
|
@ -267,8 +259,6 @@ std::string_view Token::TypeToName(Type type) {
|
|||
return "vec4";
|
||||
case Token::Type::kWhile:
|
||||
return "while";
|
||||
case Token::Type::kWorkgroup:
|
||||
return "workgroup";
|
||||
}
|
||||
|
||||
return "<unknown>";
|
||||
|
|
|
@ -177,8 +177,6 @@ class Token {
|
|||
kFn,
|
||||
// A 'for'
|
||||
kFor,
|
||||
/// A 'function'
|
||||
kFunction,
|
||||
/// A 'i32'
|
||||
kI32,
|
||||
/// A 'if'
|
||||
|
@ -209,8 +207,6 @@ class Token {
|
|||
kMat4x4,
|
||||
/// A 'override'
|
||||
kOverride,
|
||||
/// A 'private'
|
||||
kPrivate,
|
||||
/// A 'ptr'
|
||||
kPtr,
|
||||
/// A 'return'
|
||||
|
@ -219,8 +215,6 @@ class Token {
|
|||
kSampler,
|
||||
/// A 'sampler_comparison'
|
||||
kComparisonSampler,
|
||||
/// A 'storage'
|
||||
kStorage,
|
||||
/// A 'struct'
|
||||
kStruct,
|
||||
/// A 'switch'
|
||||
|
@ -265,8 +259,6 @@ class Token {
|
|||
kType,
|
||||
/// A 'u32'
|
||||
kU32,
|
||||
/// A 'uniform'
|
||||
kUniform,
|
||||
/// A 'var'
|
||||
kVar,
|
||||
/// A 'vec2'
|
||||
|
@ -277,8 +269,6 @@ class Token {
|
|||
kVec4,
|
||||
/// A 'while'
|
||||
kWhile,
|
||||
/// A 'workgroup'
|
||||
kWorkgroup,
|
||||
};
|
||||
|
||||
/// Converts a token type to a name
|
||||
|
|
Loading…
Reference in New Issue