From 169512e499eeb7efc0cd7809fe578113820c96bf Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Sat, 17 Apr 2021 05:52:11 +0000 Subject: [PATCH] ProgramBuilder: Add a WrapInStatement() overload for literals Lets you pass AST literals to WrapInStatement() / WrapInFunction() Change-Id: I69d8918a61f0ea25193b64df38ed6cd606c7f044 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48047 Commit-Queue: Ben Clayton Reviewed-by: James Price --- src/program_builder.cc | 8 ++++++-- src/program_builder.h | 6 ++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/program_builder.cc b/src/program_builder.cc index ccd27c3e27..0f2c695365 100644 --- a/src/program_builder.cc +++ b/src/program_builder.cc @@ -131,8 +131,8 @@ ast::ConstructorExpression* ProgramBuilder::ConstructValueFilledWith( ProgramBuilder::TypesBuilder::TypesBuilder(ProgramBuilder* pb) : builder(pb) {} -ast::VariableDeclStatement* ProgramBuilder::WrapInStatement(ast::Variable* v) { - return create(v); +ast::Statement* ProgramBuilder::WrapInStatement(ast::Literal* lit) { + return WrapInStatement(create(lit)); } ast::Statement* ProgramBuilder::WrapInStatement(ast::Expression* expr) { @@ -140,6 +140,10 @@ ast::Statement* ProgramBuilder::WrapInStatement(ast::Expression* expr) { return Decl(Var(symbols_.New(), nullptr, ast::StorageClass::kFunction, expr)); } +ast::VariableDeclStatement* ProgramBuilder::WrapInStatement(ast::Variable* v) { + return create(v); +} + ast::Statement* ProgramBuilder::WrapInStatement(ast::Statement* stmt) { return stmt; } diff --git a/src/program_builder.h b/src/program_builder.h index 7e2857892b..5125419af7 100644 --- a/src/program_builder.h +++ b/src/program_builder.h @@ -1405,6 +1405,12 @@ class ProgramBuilder { /// expression has no resolved type. type::Type* TypeOf(ast::Expression* expr) const; + /// Wraps the ast::Literal in a statement. This is used by tests that + /// construct a partial AST and require the Resolver to reach these + /// nodes. + /// @param lit the ast::Literal to be wrapped by an ast::Statement + /// @return the ast::Statement that wraps the ast::Statement + ast::Statement* WrapInStatement(ast::Literal* lit); /// Wraps the ast::Expression in a statement. This is used by tests that /// construct a partial AST and require the Resolver to reach these /// nodes.