wsgl parser: Add expect_builtin()
Mirrors expect_pipeline_stage() Bug: tint:282 Change-Id: I413c87b3684c1f5cfec0c4acd7d3a5160d4b24a9 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/31735 Commit-Queue: Ben Clayton <bclayton@google.com> Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
parent
32ba9b6722
commit
b8791a5129
|
@ -452,16 +452,11 @@ std::unique_ptr<ast::VariableDecoration> ParserImpl::variable_decoration() {
|
||||||
if (!expect("builtin decoration", Token::Type::kParenLeft))
|
if (!expect("builtin decoration", Token::Type::kParenLeft))
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
std::string ident;
|
ast::Builtin builtin;
|
||||||
if (!expect_ident("builtin", &ident, &source))
|
std::tie(builtin, source) = expect_builtin();
|
||||||
|
if (builtin == ast::Builtin::kNone)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
ast::Builtin builtin = ident_to_builtin(ident);
|
|
||||||
if (builtin == ast::Builtin::kNone) {
|
|
||||||
add_error(source, "invalid value for builtin decoration");
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!expect("builtin decoration", Token::Type::kParenRight))
|
if (!expect("builtin decoration", Token::Type::kParenRight))
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
|
@ -1796,6 +1791,20 @@ std::pair<ast::PipelineStage, Source> ParserImpl::expect_pipeline_stage() {
|
||||||
return {ast::PipelineStage::kNone, t.source()};
|
return {ast::PipelineStage::kNone, t.source()};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::pair<ast::Builtin, Source> ParserImpl::expect_builtin() {
|
||||||
|
Source source;
|
||||||
|
std::string ident;
|
||||||
|
|
||||||
|
if (!expect_ident("builtin", &ident, &source))
|
||||||
|
return {ast::Builtin::kNone, source};
|
||||||
|
|
||||||
|
ast::Builtin builtin = ident_to_builtin(ident);
|
||||||
|
if (builtin == ast::Builtin::kNone)
|
||||||
|
add_error(source, "invalid value for builtin decoration");
|
||||||
|
|
||||||
|
return {builtin, source};
|
||||||
|
}
|
||||||
|
|
||||||
// body_stmt
|
// body_stmt
|
||||||
// : BRACKET_LEFT statements BRACKET_RIGHT
|
// : BRACKET_LEFT statements BRACKET_RIGHT
|
||||||
std::unique_ptr<ast::BlockStatement> ParserImpl::body_stmt() {
|
std::unique_ptr<ast::BlockStatement> ParserImpl::body_stmt() {
|
||||||
|
|
|
@ -262,6 +262,11 @@ class ParserImpl {
|
||||||
/// @returns the pipeline stage or PipelineStage::kNone if none matched, along
|
/// @returns the pipeline stage or PipelineStage::kNone if none matched, along
|
||||||
/// with the source location for the stage.
|
/// with the source location for the stage.
|
||||||
std::pair<ast::PipelineStage, Source> expect_pipeline_stage();
|
std::pair<ast::PipelineStage, Source> expect_pipeline_stage();
|
||||||
|
/// Parses a builtin identifier, erroring if the next token does not match a
|
||||||
|
/// valid builtin name.
|
||||||
|
/// @returns the builtin or Builtin::kNone if none matched, along with the
|
||||||
|
/// source location for the stage.
|
||||||
|
std::pair<ast::Builtin, Source> expect_builtin();
|
||||||
/// Parses a `body_stmt` grammar element
|
/// Parses a `body_stmt` grammar element
|
||||||
/// @returns the parsed statements
|
/// @returns the parsed statements
|
||||||
std::unique_ptr<ast::BlockStatement> body_stmt();
|
std::unique_ptr<ast::BlockStatement> body_stmt();
|
||||||
|
|
Loading…
Reference in New Issue