wgsl-reader: treat function formal params as const
They should only be singly-assigned. This is required because consts can hold pointers, but var's cannot. And we need to support pointer arguments. Bug: tint:275 Change-Id: I00a58734725bd08d40df71c736854a93c364a33c Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/30923 Reviewed-by: dan sinclair <dsinclair@chromium.org> Commit-Queue: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
parent
9ab6e8b9eb
commit
f81c1081ea
|
@ -1991,8 +1991,14 @@ ast::VariableList ParserImpl::param_list() {
|
|||
return {};
|
||||
|
||||
for (;;) {
|
||||
ret.push_back(std::make_unique<ast::Variable>(
|
||||
source, name, ast::StorageClass::kNone, type));
|
||||
auto var = std::make_unique<ast::Variable>(source, name,
|
||||
ast::StorageClass::kNone, type);
|
||||
// Formal parameters are treated like a const declaration where the
|
||||
// initializer value is provided by the call's argument. The key point is
|
||||
// that it's not updatable after intially set. This is unlike C or GLSL
|
||||
// which treat formal parameters like local variables that can be updated.
|
||||
var->set_is_const(true);
|
||||
ret.push_back(std::move(var));
|
||||
|
||||
t = peek();
|
||||
if (!t.IsComma())
|
||||
|
|
|
@ -38,6 +38,7 @@ TEST_F(ParserImplTest, ParamList_Single) {
|
|||
|
||||
EXPECT_EQ(e[0]->name(), "a");
|
||||
EXPECT_EQ(e[0]->type(), i32);
|
||||
EXPECT_TRUE(e[0]->is_const());
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, ParamList_Multiple) {
|
||||
|
@ -52,12 +53,15 @@ TEST_F(ParserImplTest, ParamList_Multiple) {
|
|||
|
||||
EXPECT_EQ(e[0]->name(), "a");
|
||||
EXPECT_EQ(e[0]->type(), i32);
|
||||
EXPECT_TRUE(e[0]->is_const());
|
||||
|
||||
EXPECT_EQ(e[1]->name(), "b");
|
||||
EXPECT_EQ(e[1]->type(), f32);
|
||||
EXPECT_TRUE(e[1]->is_const());
|
||||
|
||||
EXPECT_EQ(e[2]->name(), "c");
|
||||
EXPECT_EQ(e[2]->type(), vec2);
|
||||
EXPECT_TRUE(e[1]->is_const());
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, ParamList_Empty) {
|
||||
|
|
Loading…
Reference in New Issue