Flatten ast::Decoration class hierarchy

Remove the decoration groupings (Array, Function, Struct,
StructMember, Type, Variable), such that all *Decoration classes now
subclass ast::Decoration directly. This allows for decorations to be
used in multiple places; for example, builtin decorations are now
valid for both variables and struct members.

Checking that decoration lists only contain decorations that are valid
for the node that they are attached to is now done inside the
validator.

Change-Id: Ie8c0e53e5730a7dedea50a1dec8f26f9e7b00e8d
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/44320
Commit-Queue: James Price <jrprice@google.com>
Reviewed-by: Ben Clayton <bclayton@chromium.org>
This commit is contained in:
James Price 2021-03-11 17:39:32 +00:00 committed by Commit Bot service account
parent f1773c6700
commit 95d4077648
114 changed files with 1225 additions and 1411 deletions

View File

@ -230,8 +230,6 @@ source_set("libtint_core_src") {
"src/ast/access_decoration.h", "src/ast/access_decoration.h",
"src/ast/array_accessor_expression.cc", "src/ast/array_accessor_expression.cc",
"src/ast/array_accessor_expression.h", "src/ast/array_accessor_expression.h",
"src/ast/array_decoration.cc",
"src/ast/array_decoration.h",
"src/ast/assignment_statement.cc", "src/ast/assignment_statement.cc",
"src/ast/assignment_statement.h", "src/ast/assignment_statement.h",
"src/ast/binary_expression.cc", "src/ast/binary_expression.cc",
@ -276,8 +274,6 @@ source_set("libtint_core_src") {
"src/ast/float_literal.h", "src/ast/float_literal.h",
"src/ast/function.cc", "src/ast/function.cc",
"src/ast/function.h", "src/ast/function.h",
"src/ast/function_decoration.cc",
"src/ast/function_decoration.h",
"src/ast/group_decoration.cc", "src/ast/group_decoration.cc",
"src/ast/group_decoration.h", "src/ast/group_decoration.h",
"src/ast/identifier_expression.cc", "src/ast/identifier_expression.cc",
@ -320,20 +316,14 @@ source_set("libtint_core_src") {
"src/ast/struct.h", "src/ast/struct.h",
"src/ast/struct_block_decoration.cc", "src/ast/struct_block_decoration.cc",
"src/ast/struct_block_decoration.h", "src/ast/struct_block_decoration.h",
"src/ast/struct_decoration.cc",
"src/ast/struct_decoration.h",
"src/ast/struct_member.cc", "src/ast/struct_member.cc",
"src/ast/struct_member.h", "src/ast/struct_member.h",
"src/ast/struct_member_decoration.cc",
"src/ast/struct_member_decoration.h",
"src/ast/struct_member_offset_decoration.cc", "src/ast/struct_member_offset_decoration.cc",
"src/ast/struct_member_offset_decoration.h", "src/ast/struct_member_offset_decoration.h",
"src/ast/switch_statement.cc", "src/ast/switch_statement.cc",
"src/ast/switch_statement.h", "src/ast/switch_statement.h",
"src/ast/type_constructor_expression.cc", "src/ast/type_constructor_expression.cc",
"src/ast/type_constructor_expression.h", "src/ast/type_constructor_expression.h",
"src/ast/type_decoration.cc",
"src/ast/type_decoration.h",
"src/ast/uint_literal.cc", "src/ast/uint_literal.cc",
"src/ast/uint_literal.h", "src/ast/uint_literal.h",
"src/ast/unary_op.cc", "src/ast/unary_op.cc",
@ -344,8 +334,6 @@ source_set("libtint_core_src") {
"src/ast/variable.h", "src/ast/variable.h",
"src/ast/variable_decl_statement.cc", "src/ast/variable_decl_statement.cc",
"src/ast/variable_decl_statement.h", "src/ast/variable_decl_statement.h",
"src/ast/variable_decoration.cc",
"src/ast/variable_decoration.h",
"src/ast/workgroup_decoration.cc", "src/ast/workgroup_decoration.cc",
"src/ast/workgroup_decoration.h", "src/ast/workgroup_decoration.h",
"src/block_allocator.h", "src/block_allocator.h",
@ -797,7 +785,6 @@ source_set("tint_unittests_core_src") {
"src/ast/case_statement_test.cc", "src/ast/case_statement_test.cc",
"src/ast/constant_id_decoration_test.cc", "src/ast/constant_id_decoration_test.cc",
"src/ast/continue_statement_test.cc", "src/ast/continue_statement_test.cc",
"src/ast/decoration_test.cc",
"src/ast/discard_statement_test.cc", "src/ast/discard_statement_test.cc",
"src/ast/else_statement_test.cc", "src/ast/else_statement_test.cc",
"src/ast/fallthrough_statement_test.cc", "src/ast/fallthrough_statement_test.cc",
@ -883,6 +870,7 @@ source_set("tint_unittests_core_src") {
"src/utils/unique_vector_test.cc", "src/utils/unique_vector_test.cc",
"src/validator/validator_builtins_test.cc", "src/validator/validator_builtins_test.cc",
"src/validator/validator_control_block_test.cc", "src/validator/validator_control_block_test.cc",
"src/validator/validator_decoration_test.cc",
"src/validator/validator_function_test.cc", "src/validator/validator_function_test.cc",
"src/validator/validator_test.cc", "src/validator/validator_test.cc",
"src/validator/validator_test_helper.cc", "src/validator/validator_test_helper.cc",

View File

@ -44,8 +44,6 @@ set(TINT_LIB_SRCS
ast/access_decoration.h ast/access_decoration.h
ast/array_accessor_expression.cc ast/array_accessor_expression.cc
ast/array_accessor_expression.h ast/array_accessor_expression.h
ast/array_decoration.cc
ast/array_decoration.h
ast/assignment_statement.cc ast/assignment_statement.cc
ast/assignment_statement.h ast/assignment_statement.h
ast/binary_expression.cc ast/binary_expression.cc
@ -90,8 +88,6 @@ set(TINT_LIB_SRCS
ast/float_literal.h ast/float_literal.h
ast/function.cc ast/function.cc
ast/function.h ast/function.h
ast/function_decoration.cc
ast/function_decoration.h
ast/group_decoration.cc ast/group_decoration.cc
ast/group_decoration.h ast/group_decoration.h
ast/identifier_expression.cc ast/identifier_expression.cc
@ -134,20 +130,14 @@ set(TINT_LIB_SRCS
ast/struct.h ast/struct.h
ast/struct_block_decoration.cc ast/struct_block_decoration.cc
ast/struct_block_decoration.h ast/struct_block_decoration.h
ast/struct_decoration.cc
ast/struct_decoration.h
ast/struct_member.cc ast/struct_member.cc
ast/struct_member.h ast/struct_member.h
ast/struct_member_decoration.cc
ast/struct_member_decoration.h
ast/struct_member_offset_decoration.cc ast/struct_member_offset_decoration.cc
ast/struct_member_offset_decoration.h ast/struct_member_offset_decoration.h
ast/switch_statement.cc ast/switch_statement.cc
ast/switch_statement.h ast/switch_statement.h
ast/type_constructor_expression.cc ast/type_constructor_expression.cc
ast/type_constructor_expression.h ast/type_constructor_expression.h
ast/type_decoration.cc
ast/type_decoration.h
ast/uint_literal.cc ast/uint_literal.cc
ast/uint_literal.h ast/uint_literal.h
ast/unary_op.cc ast/unary_op.cc
@ -156,8 +146,6 @@ set(TINT_LIB_SRCS
ast/unary_op_expression.h ast/unary_op_expression.h
ast/variable.cc ast/variable.cc
ast/variable.h ast/variable.h
ast/variable_decoration.cc
ast/variable_decoration.h
ast/variable_decl_statement.cc ast/variable_decl_statement.cc
ast/variable_decl_statement.h ast/variable_decl_statement.h
ast/workgroup_decoration.cc ast/workgroup_decoration.cc
@ -426,7 +414,6 @@ if(${TINT_BUILD_TESTS})
ast/case_statement_test.cc ast/case_statement_test.cc
ast/constant_id_decoration_test.cc ast/constant_id_decoration_test.cc
ast/continue_statement_test.cc ast/continue_statement_test.cc
ast/decoration_test.cc
ast/discard_statement_test.cc ast/discard_statement_test.cc
ast/else_statement_test.cc ast/else_statement_test.cc
ast/fallthrough_statement_test.cc ast/fallthrough_statement_test.cc
@ -506,6 +493,7 @@ if(${TINT_BUILD_TESTS})
utils/unique_vector_test.cc utils/unique_vector_test.cc
validator/validator_builtins_test.cc validator/validator_builtins_test.cc
validator/validator_control_block_test.cc validator/validator_control_block_test.cc
validator/validator_decoration_test.cc
validator/validator_function_test.cc validator/validator_function_test.cc
validator/validator_test.cc validator/validator_test.cc
validator/validator_type_test.cc validator/validator_type_test.cc

View File

@ -16,13 +16,13 @@
#define SRC_AST_ACCESS_DECORATION_H_ #define SRC_AST_ACCESS_DECORATION_H_
#include "src/ast/access_control.h" #include "src/ast/access_control.h"
#include "src/ast/type_decoration.h" #include "src/ast/decoration.h"
namespace tint { namespace tint {
namespace ast { namespace ast {
/// An access decoration /// An access decoration
class AccessDecoration : public Castable<AccessDecoration, TypeDecoration> { class AccessDecoration : public Castable<AccessDecoration, Decoration> {
public: public:
/// constructor /// constructor
/// @param source the source of this decoration /// @param source the source of this decoration

View File

@ -1,50 +0,0 @@
// Copyright 2020 The Tint Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef SRC_AST_ARRAY_DECORATION_H_
#define SRC_AST_ARRAY_DECORATION_H_
#include <vector>
#include "src/ast/decoration.h"
namespace tint {
namespace ast {
class StrideDecoration;
/// A decoration attached to an array
class ArrayDecoration : public Castable<ArrayDecoration, Decoration> {
public:
/// The kind of decoration that this type represents
static constexpr const DecorationKind Kind = DecorationKind::kArray;
~ArrayDecoration() override;
/// @return the decoration kind
DecorationKind GetKind() const override;
protected:
/// Constructor
/// @param source the source of this decoration
explicit ArrayDecoration(const Source& source);
};
/// A list of array decorations
using ArrayDecorationList = std::vector<ArrayDecoration*>;
} // namespace ast
} // namespace tint
#endif // SRC_AST_ARRAY_DECORATION_H_

View File

@ -15,14 +15,13 @@
#ifndef SRC_AST_BINDING_DECORATION_H_ #ifndef SRC_AST_BINDING_DECORATION_H_
#define SRC_AST_BINDING_DECORATION_H_ #define SRC_AST_BINDING_DECORATION_H_
#include "src/ast/variable_decoration.h" #include "src/ast/decoration.h"
namespace tint { namespace tint {
namespace ast { namespace ast {
/// A binding decoration /// A binding decoration
class BindingDecoration class BindingDecoration : public Castable<BindingDecoration, Decoration> {
: public Castable<BindingDecoration, VariableDecoration> {
public: public:
/// constructor /// constructor
/// @param value the binding value /// @param value the binding value

View File

@ -16,14 +16,13 @@
#define SRC_AST_BUILTIN_DECORATION_H_ #define SRC_AST_BUILTIN_DECORATION_H_
#include "src/ast/builtin.h" #include "src/ast/builtin.h"
#include "src/ast/variable_decoration.h" #include "src/ast/decoration.h"
namespace tint { namespace tint {
namespace ast { namespace ast {
/// A builtin decoration /// A builtin decoration
class BuiltinDecoration class BuiltinDecoration : public Castable<BuiltinDecoration, Decoration> {
: public Castable<BuiltinDecoration, VariableDecoration> {
public: public:
/// constructor /// constructor
/// @param source the source of this decoration /// @param source the source of this decoration

View File

@ -15,14 +15,13 @@
#ifndef SRC_AST_CONSTANT_ID_DECORATION_H_ #ifndef SRC_AST_CONSTANT_ID_DECORATION_H_
#define SRC_AST_CONSTANT_ID_DECORATION_H_ #define SRC_AST_CONSTANT_ID_DECORATION_H_
#include "src/ast/variable_decoration.h" #include "src/ast/decoration.h"
namespace tint { namespace tint {
namespace ast { namespace ast {
/// A constant id decoration /// A constant id decoration
class ConstantIdDecoration class ConstantIdDecoration : public Castable<ConstantIdDecoration, Decoration> {
: public Castable<ConstantIdDecoration, VariableDecoration> {
public: public:
/// constructor /// constructor
/// @param source the source of this decoration /// @param source the source of this decoration

View File

@ -21,23 +21,5 @@ namespace ast {
Decoration::~Decoration() = default; Decoration::~Decoration() = default;
std::ostream& operator<<(std::ostream& out, DecorationKind data) {
switch (data) {
case DecorationKind::kArray:
return out << "array";
case DecorationKind::kFunction:
return out << "function";
case DecorationKind::kStruct:
return out << "struct";
case DecorationKind::kStructMember:
return out << "struct member";
case DecorationKind::kType:
return out << "type";
case DecorationKind::kVariable:
return out << "variable";
}
return out << "<unknown>";
}
} // namespace ast } // namespace ast
} // namespace tint } // namespace tint

View File

@ -22,26 +22,11 @@
namespace tint { namespace tint {
namespace ast { namespace ast {
/// The decoration kind enumerator
enum class DecorationKind {
kArray,
kFunction,
kStruct,
kStructMember,
kType,
kVariable,
};
std::ostream& operator<<(std::ostream& out, DecorationKind data);
/// The base class for all decorations /// The base class for all decorations
class Decoration : public Castable<Decoration, Node> { class Decoration : public Castable<Decoration, Node> {
public: public:
~Decoration() override; ~Decoration() override;
/// @return the decoration kind
virtual DecorationKind GetKind() const = 0;
protected: protected:
/// Constructor /// Constructor
/// @param source the source of this decoration /// @param source the source of this decoration

View File

@ -1,67 +0,0 @@
// Copyright 2020 The Tint Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "src/ast/access_decoration.h"
#include "src/ast/constant_id_decoration.h"
#include "src/ast/stage_decoration.h"
#include "src/ast/test_helper.h"
#include "src/ast/workgroup_decoration.h"
namespace tint {
namespace ast {
namespace {
using DecorationTest = TestHelper;
TEST_F(DecorationTest, AsCorrectType) {
auto* decoration = create<ConstantIdDecoration>(1);
auto* upcast = static_cast<Decoration*>(decoration);
auto* downcast = As<VariableDecoration>(upcast);
EXPECT_EQ(decoration, downcast);
}
TEST_F(DecorationTest, AsIncorrectType) {
auto* decoration = create<ConstantIdDecoration>(1);
auto* upcast = static_cast<Decoration*>(decoration);
auto* downcast = As<ArrayDecoration>(upcast);
EXPECT_EQ(nullptr, downcast);
}
TEST_F(DecorationTest, Is) {
Decoration* decoration = create<ConstantIdDecoration>(1);
EXPECT_TRUE(decoration->Is<VariableDecoration>());
EXPECT_FALSE(decoration->Is<ArrayDecoration>());
}
TEST_F(DecorationTest, Kinds) {
EXPECT_EQ(ArrayDecoration::Kind, DecorationKind::kArray);
EXPECT_EQ(StrideDecoration::Kind, DecorationKind::kArray);
EXPECT_EQ(FunctionDecoration::Kind, DecorationKind::kFunction);
EXPECT_EQ(StageDecoration::Kind, DecorationKind::kFunction);
EXPECT_EQ(WorkgroupDecoration::Kind, DecorationKind::kFunction);
EXPECT_EQ(StructDecoration::Kind, DecorationKind::kStruct);
EXPECT_EQ(StructMemberDecoration::Kind, DecorationKind::kStructMember);
EXPECT_EQ(StructMemberOffsetDecoration::Kind, DecorationKind::kStructMember);
EXPECT_EQ(TypeDecoration::Kind, DecorationKind::kType);
EXPECT_EQ(AccessDecoration::Kind, DecorationKind::kType);
EXPECT_EQ(VariableDecoration::Kind, DecorationKind::kVariable);
EXPECT_EQ(BindingDecoration::Kind, DecorationKind::kVariable);
EXPECT_EQ(BuiltinDecoration::Kind, DecorationKind::kVariable);
EXPECT_EQ(ConstantIdDecoration::Kind, DecorationKind::kVariable);
EXPECT_EQ(LocationDecoration::Kind, DecorationKind::kVariable);
}
} // namespace
} // namespace ast
} // namespace tint

View File

@ -28,7 +28,7 @@ Function::Function(const Source& source,
VariableList params, VariableList params,
type::Type* return_type, type::Type* return_type,
BlockStatement* body, BlockStatement* body,
FunctionDecorationList decorations) DecorationList decorations)
: Base(source), : Base(source),
symbol_(symbol), symbol_(symbol),
params_(std::move(params)), params_(std::move(params)),

View File

@ -23,7 +23,7 @@
#include "src/ast/binding_decoration.h" #include "src/ast/binding_decoration.h"
#include "src/ast/block_statement.h" #include "src/ast/block_statement.h"
#include "src/ast/builtin_decoration.h" #include "src/ast/builtin_decoration.h"
#include "src/ast/function_decoration.h" #include "src/ast/decoration.h"
#include "src/ast/group_decoration.h" #include "src/ast/group_decoration.h"
#include "src/ast/location_decoration.h" #include "src/ast/location_decoration.h"
#include "src/ast/pipeline_stage.h" #include "src/ast/pipeline_stage.h"
@ -47,7 +47,7 @@ class Function : public Castable<Function, Node> {
VariableList params, VariableList params,
type::Type* return_type, type::Type* return_type,
BlockStatement* body, BlockStatement* body,
FunctionDecorationList decorations); DecorationList decorations);
/// Move constructor /// Move constructor
Function(Function&&); Function(Function&&);
@ -59,7 +59,7 @@ class Function : public Castable<Function, Node> {
const VariableList& params() const { return params_; } const VariableList& params() const { return params_; }
/// @returns the decorations attached to this function /// @returns the decorations attached to this function
const FunctionDecorationList& decorations() const { return decorations_; } const DecorationList& decorations() const { return decorations_; }
/// @returns the workgroup size {x, y, z} for the function. {1, 1, 1} will be /// @returns the workgroup size {x, y, z} for the function. {1, 1, 1} will be
/// return if no workgroup size was set. /// return if no workgroup size was set.
@ -107,7 +107,7 @@ class Function : public Castable<Function, Node> {
VariableList const params_; VariableList const params_;
type::Type* const return_type_; type::Type* const return_type_;
BlockStatement* const body_; BlockStatement* const body_;
FunctionDecorationList const decorations_; DecorationList const decorations_;
}; };
/// A list of functions /// A list of functions

View File

@ -1,33 +0,0 @@
// Copyright 2020 The Tint Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "src/ast/function_decoration.h"
TINT_INSTANTIATE_TYPEINFO(tint::ast::FunctionDecoration);
namespace tint {
namespace ast {
constexpr const DecorationKind FunctionDecoration::Kind;
FunctionDecoration::FunctionDecoration(const Source& source) : Base(source) {}
FunctionDecoration::~FunctionDecoration() = default;
DecorationKind FunctionDecoration::GetKind() const {
return Kind;
}
} // namespace ast
} // namespace tint

View File

@ -29,8 +29,7 @@ TEST_F(FunctionTest, Creation) {
params.push_back(Var("var", ty.i32(), StorageClass::kNone)); params.push_back(Var("var", ty.i32(), StorageClass::kNone));
auto* var = params[0]; auto* var = params[0];
auto* f = Func("func", params, ty.void_(), StatementList{}, auto* f = Func("func", params, ty.void_(), StatementList{}, DecorationList{});
FunctionDecorationList{});
EXPECT_EQ(f->symbol(), Symbols().Get("func")); EXPECT_EQ(f->symbol(), Symbols().Get("func"));
ASSERT_EQ(f->params().size(), 1u); ASSERT_EQ(f->params().size(), 1u);
EXPECT_EQ(f->return_type(), ty.void_()); EXPECT_EQ(f->return_type(), ty.void_());
@ -42,7 +41,7 @@ TEST_F(FunctionTest, Creation_WithSource) {
params.push_back(Var("var", ty.i32(), StorageClass::kNone)); params.push_back(Var("var", ty.i32(), StorageClass::kNone));
auto* f = Func(Source{Source::Location{20, 2}}, "func", params, ty.void_(), auto* f = Func(Source{Source::Location{20, 2}}, "func", params, ty.void_(),
StatementList{}, FunctionDecorationList{}); StatementList{}, DecorationList{});
auto src = f->source(); auto src = f->source();
EXPECT_EQ(src.range.begin.line, 20u); EXPECT_EQ(src.range.begin.line, 20u);
EXPECT_EQ(src.range.begin.column, 2u); EXPECT_EQ(src.range.begin.column, 2u);
@ -53,7 +52,7 @@ TEST_F(FunctionTest, Assert_InvalidName) {
{ {
ProgramBuilder b; ProgramBuilder b;
b.Func("", VariableList{}, b.ty.void_(), StatementList{}, b.Func("", VariableList{}, b.ty.void_(), StatementList{},
FunctionDecorationList{}); DecorationList{});
}, },
"internal compiler error"); "internal compiler error");
} }
@ -62,8 +61,7 @@ TEST_F(FunctionTest, Assert_NullReturnType) {
EXPECT_FATAL_FAILURE( EXPECT_FATAL_FAILURE(
{ {
ProgramBuilder b; ProgramBuilder b;
b.Func("f", VariableList{}, nullptr, StatementList{}, b.Func("f", VariableList{}, nullptr, StatementList{}, DecorationList{});
FunctionDecorationList{});
}, },
"internal compiler error"); "internal compiler error");
} }
@ -76,8 +74,7 @@ TEST_F(FunctionTest, Assert_NullParam) {
params.push_back(b.Var("var", b.ty.i32(), StorageClass::kNone)); params.push_back(b.Var("var", b.ty.i32(), StorageClass::kNone));
params.push_back(nullptr); params.push_back(nullptr);
b.Func("f", params, b.ty.void_(), StatementList{}, b.Func("f", params, b.ty.void_(), StatementList{}, DecorationList{});
FunctionDecorationList{});
}, },
"internal compiler error"); "internal compiler error");
} }
@ -87,7 +84,7 @@ TEST_F(FunctionTest, ToStr) {
StatementList{ StatementList{
create<DiscardStatement>(), create<DiscardStatement>(),
}, },
FunctionDecorationList{}); DecorationList{});
EXPECT_EQ(str(f), R"(Function func -> __void EXPECT_EQ(str(f), R"(Function func -> __void
() ()
@ -102,7 +99,7 @@ TEST_F(FunctionTest, ToStr_WithDecoration) {
StatementList{ StatementList{
create<DiscardStatement>(), create<DiscardStatement>(),
}, },
FunctionDecorationList{create<WorkgroupDecoration>(2, 4, 6)}); DecorationList{create<WorkgroupDecoration>(2, 4, 6)});
EXPECT_EQ(str(f), R"(Function func -> __void EXPECT_EQ(str(f), R"(Function func -> __void
WorkgroupDecoration{2 4 6} WorkgroupDecoration{2 4 6}
@ -121,7 +118,7 @@ TEST_F(FunctionTest, ToStr_WithParams) {
StatementList{ StatementList{
create<DiscardStatement>(), create<DiscardStatement>(),
}, },
FunctionDecorationList{}); DecorationList{});
EXPECT_EQ(str(f), R"(Function func -> __void EXPECT_EQ(str(f), R"(Function func -> __void
( (
@ -139,7 +136,7 @@ TEST_F(FunctionTest, ToStr_WithParams) {
TEST_F(FunctionTest, TypeName) { TEST_F(FunctionTest, TypeName) {
auto* f = Func("func", VariableList{}, ty.void_(), StatementList{}, auto* f = Func("func", VariableList{}, ty.void_(), StatementList{},
FunctionDecorationList{}); DecorationList{});
EXPECT_EQ(f->type_name(), "__func__void"); EXPECT_EQ(f->type_name(), "__func__void");
} }
@ -148,31 +145,29 @@ TEST_F(FunctionTest, TypeName_WithParams) {
params.push_back(Var("var1", ty.i32(), StorageClass::kNone)); params.push_back(Var("var1", ty.i32(), StorageClass::kNone));
params.push_back(Var("var2", ty.f32(), StorageClass::kNone)); params.push_back(Var("var2", ty.f32(), StorageClass::kNone));
auto* f = Func("func", params, ty.void_(), StatementList{}, auto* f = Func("func", params, ty.void_(), StatementList{}, DecorationList{});
FunctionDecorationList{});
EXPECT_EQ(f->type_name(), "__func__void__i32__f32"); EXPECT_EQ(f->type_name(), "__func__void__i32__f32");
} }
TEST_F(FunctionTest, GetLastStatement) { TEST_F(FunctionTest, GetLastStatement) {
VariableList params; VariableList params;
auto* stmt = create<DiscardStatement>(); auto* stmt = create<DiscardStatement>();
auto* f = Func("func", params, ty.void_(), StatementList{stmt}, auto* f =
FunctionDecorationList{}); Func("func", params, ty.void_(), StatementList{stmt}, DecorationList{});
EXPECT_EQ(f->get_last_statement(), stmt); EXPECT_EQ(f->get_last_statement(), stmt);
} }
TEST_F(FunctionTest, GetLastStatement_nullptr) { TEST_F(FunctionTest, GetLastStatement_nullptr) {
VariableList params; VariableList params;
auto* f = Func("func", params, ty.void_(), StatementList{}, auto* f = Func("func", params, ty.void_(), StatementList{}, DecorationList{});
FunctionDecorationList{});
EXPECT_EQ(f->get_last_statement(), nullptr); EXPECT_EQ(f->get_last_statement(), nullptr);
} }
TEST_F(FunctionTest, WorkgroupSize_NoneSet) { TEST_F(FunctionTest, WorkgroupSize_NoneSet) {
auto* f = Func("func", VariableList{}, ty.void_(), StatementList{}, auto* f = Func("func", VariableList{}, ty.void_(), StatementList{},
FunctionDecorationList{}); DecorationList{});
uint32_t x = 0; uint32_t x = 0;
uint32_t y = 0; uint32_t y = 0;
uint32_t z = 0; uint32_t z = 0;
@ -183,9 +178,8 @@ TEST_F(FunctionTest, WorkgroupSize_NoneSet) {
} }
TEST_F(FunctionTest, WorkgroupSize) { TEST_F(FunctionTest, WorkgroupSize) {
auto* f = auto* f = Func("func", VariableList{}, ty.void_(), StatementList{},
Func("func", VariableList{}, ty.void_(), StatementList{}, DecorationList{create<WorkgroupDecoration>(2u, 4u, 6u)});
FunctionDecorationList{create<WorkgroupDecoration>(2u, 4u, 6u)});
uint32_t x = 0; uint32_t x = 0;
uint32_t y = 0; uint32_t y = 0;
@ -200,7 +194,7 @@ using FunctionListTest = TestHelper;
TEST_F(FunctionListTest, FindSymbol) { TEST_F(FunctionListTest, FindSymbol) {
auto* func = Func("main", VariableList{}, ty.f32(), StatementList{}, auto* func = Func("main", VariableList{}, ty.f32(), StatementList{},
ast::FunctionDecorationList{}); ast::DecorationList{});
FunctionList list; FunctionList list;
list.Add(func); list.Add(func);
EXPECT_EQ(func, list.Find(Symbols().Register("main"))); EXPECT_EQ(func, list.Find(Symbols().Register("main")));
@ -213,11 +207,11 @@ TEST_F(FunctionListTest, FindSymbolMissing) {
TEST_F(FunctionListTest, FindSymbolStage) { TEST_F(FunctionListTest, FindSymbolStage) {
auto* fs = Func("main", VariableList{}, ty.f32(), StatementList{}, auto* fs = Func("main", VariableList{}, ty.f32(), StatementList{},
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(PipelineStage::kFragment), create<ast::StageDecoration>(PipelineStage::kFragment),
}); });
auto* vs = Func("main", VariableList{}, ty.f32(), StatementList{}, auto* vs = Func("main", VariableList{}, ty.f32(), StatementList{},
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(PipelineStage::kVertex), create<ast::StageDecoration>(PipelineStage::kVertex),
}); });
FunctionList list; FunctionList list;
@ -231,7 +225,7 @@ TEST_F(FunctionListTest, FindSymbolStage) {
TEST_F(FunctionListTest, FindSymbolStageMissing) { TEST_F(FunctionListTest, FindSymbolStageMissing) {
FunctionList list; FunctionList list;
list.Add(Func("main", VariableList{}, ty.f32(), StatementList{}, list.Add(Func("main", VariableList{}, ty.f32(), StatementList{},
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(PipelineStage::kFragment), create<ast::StageDecoration>(PipelineStage::kFragment),
})); }));
EXPECT_EQ(nullptr, EXPECT_EQ(nullptr,
@ -241,7 +235,7 @@ TEST_F(FunctionListTest, FindSymbolStageMissing) {
TEST_F(FunctionListTest, HasStage) { TEST_F(FunctionListTest, HasStage) {
FunctionList list; FunctionList list;
list.Add(Func("main", VariableList{}, ty.f32(), StatementList{}, list.Add(Func("main", VariableList{}, ty.f32(), StatementList{},
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(PipelineStage::kFragment), create<ast::StageDecoration>(PipelineStage::kFragment),
})); }));
EXPECT_TRUE(list.HasStage(PipelineStage::kFragment)); EXPECT_TRUE(list.HasStage(PipelineStage::kFragment));

View File

@ -15,13 +15,13 @@
#ifndef SRC_AST_GROUP_DECORATION_H_ #ifndef SRC_AST_GROUP_DECORATION_H_
#define SRC_AST_GROUP_DECORATION_H_ #define SRC_AST_GROUP_DECORATION_H_
#include "src/ast/variable_decoration.h" #include "src/ast/decoration.h"
namespace tint { namespace tint {
namespace ast { namespace ast {
/// A group decoration /// A group decoration
class GroupDecoration : public Castable<GroupDecoration, VariableDecoration> { class GroupDecoration : public Castable<GroupDecoration, Decoration> {
public: public:
/// constructor /// constructor
/// @param value the group value /// @param value the group value

View File

@ -151,7 +151,7 @@ ast::Variable* TextureOverloadCase::buildTextureVariable(
ProgramBuilder* b) const { ProgramBuilder* b) const {
auto* datatype = resultVectorComponentType(b); auto* datatype = resultVectorComponentType(b);
VariableDecorationList decos = { DecorationList decos = {
b->create<ast::GroupDecoration>(0), b->create<ast::GroupDecoration>(0),
b->create<ast::BindingDecoration>(0), b->create<ast::BindingDecoration>(0),
}; };
@ -189,7 +189,7 @@ ast::Variable* TextureOverloadCase::buildTextureVariable(
ast::Variable* TextureOverloadCase::buildSamplerVariable( ast::Variable* TextureOverloadCase::buildSamplerVariable(
ProgramBuilder* b) const { ProgramBuilder* b) const {
VariableDecorationList decos = { DecorationList decos = {
b->create<ast::GroupDecoration>(0), b->create<ast::GroupDecoration>(0),
b->create<ast::BindingDecoration>(1), b->create<ast::BindingDecoration>(1),
}; };

View File

@ -15,14 +15,13 @@
#ifndef SRC_AST_LOCATION_DECORATION_H_ #ifndef SRC_AST_LOCATION_DECORATION_H_
#define SRC_AST_LOCATION_DECORATION_H_ #define SRC_AST_LOCATION_DECORATION_H_
#include "src/ast/variable_decoration.h" #include "src/ast/decoration.h"
namespace tint { namespace tint {
namespace ast { namespace ast {
/// A location decoration /// A location decoration
class LocationDecoration class LocationDecoration : public Castable<LocationDecoration, Decoration> {
: public Castable<LocationDecoration, VariableDecoration> {
public: public:
/// constructor /// constructor
/// @param source the source of this decoration /// @param source the source of this decoration

View File

@ -33,7 +33,7 @@ TEST_F(ModuleTest, ToStrEmitsPreambleAndPostamble) {
TEST_F(ModuleTest, LookupFunction) { TEST_F(ModuleTest, LookupFunction) {
auto* func = Func("main", VariableList{}, ty.f32(), StatementList{}, auto* func = Func("main", VariableList{}, ty.f32(), StatementList{},
ast::FunctionDecorationList{}); ast::DecorationList{});
Program program(std::move(*this)); Program program(std::move(*this));
EXPECT_EQ(func, EXPECT_EQ(func,

View File

@ -15,14 +15,14 @@
#ifndef SRC_AST_STAGE_DECORATION_H_ #ifndef SRC_AST_STAGE_DECORATION_H_
#define SRC_AST_STAGE_DECORATION_H_ #define SRC_AST_STAGE_DECORATION_H_
#include "src/ast/function_decoration.h" #include "src/ast/decoration.h"
#include "src/ast/pipeline_stage.h" #include "src/ast/pipeline_stage.h"
namespace tint { namespace tint {
namespace ast { namespace ast {
/// A workgroup decoration /// A workgroup decoration
class StageDecoration : public Castable<StageDecoration, FunctionDecoration> { class StageDecoration : public Castable<StageDecoration, Decoration> {
public: public:
/// constructor /// constructor
/// @param stage the pipeline stage /// @param stage the pipeline stage

View File

@ -15,13 +15,13 @@
#ifndef SRC_AST_STRIDE_DECORATION_H_ #ifndef SRC_AST_STRIDE_DECORATION_H_
#define SRC_AST_STRIDE_DECORATION_H_ #define SRC_AST_STRIDE_DECORATION_H_
#include "src/ast/array_decoration.h" #include "src/ast/decoration.h"
namespace tint { namespace tint {
namespace ast { namespace ast {
/// A stride decoration /// A stride decoration
class StrideDecoration : public Castable<StrideDecoration, ArrayDecoration> { class StrideDecoration : public Castable<StrideDecoration, Decoration> {
public: public:
/// constructor /// constructor
/// @param stride the stride value /// @param stride the stride value

View File

@ -24,7 +24,7 @@ namespace ast {
Struct::Struct(const Source& source, Struct::Struct(const Source& source,
StructMemberList members, StructMemberList members,
StructDecorationList decorations) DecorationList decorations)
: Base(source), : Base(source),
members_(std::move(members)), members_(std::move(members)),
decorations_(std::move(decorations)) { decorations_(std::move(decorations)) {

View File

@ -17,7 +17,7 @@
#include <utility> #include <utility>
#include "src/ast/struct_decoration.h" #include "src/ast/decoration.h"
#include "src/ast/struct_member.h" #include "src/ast/struct_member.h"
namespace tint { namespace tint {
@ -32,14 +32,14 @@ class Struct : public Castable<Struct, Node> {
/// @param decorations The struct decorations /// @param decorations The struct decorations
Struct(const Source& source, Struct(const Source& source,
StructMemberList members, StructMemberList members,
StructDecorationList decorations); DecorationList decorations);
/// Move constructor /// Move constructor
Struct(Struct&&); Struct(Struct&&);
~Struct() override; ~Struct() override;
/// @returns the struct decorations /// @returns the struct decorations
const StructDecorationList& decorations() const { return decorations_; } const DecorationList& decorations() const { return decorations_; }
/// @returns the members /// @returns the members
const StructMemberList& members() const { return members_; } const StructMemberList& members() const { return members_; }
@ -70,7 +70,7 @@ class Struct : public Castable<Struct, Node> {
Struct(const Struct&) = delete; Struct(const Struct&) = delete;
StructMemberList const members_; StructMemberList const members_;
StructDecorationList const decorations_; DecorationList const decorations_;
}; };
} // namespace ast } // namespace ast

View File

@ -17,14 +17,14 @@
#include <vector> #include <vector>
#include "src/ast/struct_decoration.h" #include "src/ast/decoration.h"
namespace tint { namespace tint {
namespace ast { namespace ast {
/// The struct decorations /// The struct decorations
class StructBlockDecoration class StructBlockDecoration
: public Castable<StructBlockDecoration, StructDecoration> { : public Castable<StructBlockDecoration, Decoration> {
public: public:
/// constructor /// constructor
/// @param source the source of this decoration /// @param source the source of this decoration
@ -47,7 +47,7 @@ class StructBlockDecoration
}; };
/// List of struct decorations /// List of struct decorations
using StructDecorationList = std::vector<StructDecoration*>; using DecorationList = std::vector<Decoration*>;
} // namespace ast } // namespace ast
} // namespace tint } // namespace tint

View File

@ -1,33 +0,0 @@
// Copyright 2020 The Tint Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "src/ast/struct_decoration.h"
TINT_INSTANTIATE_TYPEINFO(tint::ast::StructDecoration);
namespace tint {
namespace ast {
constexpr const DecorationKind StructDecoration::Kind;
StructDecoration::StructDecoration(const Source& source) : Base(source) {}
StructDecoration::~StructDecoration() = default;
DecorationKind StructDecoration::GetKind() const {
return Kind;
}
} // namespace ast
} // namespace tint

View File

@ -24,7 +24,7 @@ namespace ast {
StructMember::StructMember(const Source& source, StructMember::StructMember(const Source& source,
const Symbol& sym, const Symbol& sym,
type::Type* type, type::Type* type,
StructMemberDecorationList decorations) DecorationList decorations)
: Base(source), : Base(source),
symbol_(sym), symbol_(sym),
type_(type), type_(type),

View File

@ -18,7 +18,7 @@
#include <utility> #include <utility>
#include <vector> #include <vector>
#include "src/ast/struct_member_decoration.h" #include "src/ast/decoration.h"
namespace tint { namespace tint {
namespace ast { namespace ast {
@ -34,7 +34,7 @@ class StructMember : public Castable<StructMember, Node> {
StructMember(const Source& source, StructMember(const Source& source,
const Symbol& sym, const Symbol& sym,
type::Type* type, type::Type* type,
StructMemberDecorationList decorations); DecorationList decorations);
/// Move constructor /// Move constructor
StructMember(StructMember&&); StructMember(StructMember&&);
@ -46,7 +46,7 @@ class StructMember : public Castable<StructMember, Node> {
type::Type* type() const { return type_; } type::Type* type() const { return type_; }
/// @returns the decorations /// @returns the decorations
const StructMemberDecorationList& decorations() const { return decorations_; } const DecorationList& decorations() const { return decorations_; }
/// @returns true if the struct member has an offset decoration /// @returns true if the struct member has an offset decoration
bool has_offset_decoration() const; bool has_offset_decoration() const;
@ -72,7 +72,7 @@ class StructMember : public Castable<StructMember, Node> {
Symbol const symbol_; Symbol const symbol_;
type::Type* const type_; type::Type* const type_;
StructMemberDecorationList const decorations_; DecorationList const decorations_;
}; };
/// A list of struct members /// A list of struct members

View File

@ -1,49 +0,0 @@
// Copyright 2020 The Tint Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef SRC_AST_STRUCT_MEMBER_DECORATION_H_
#define SRC_AST_STRUCT_MEMBER_DECORATION_H_
#include <vector>
#include "src/ast/decoration.h"
namespace tint {
namespace ast {
/// A decoration attached to a struct member
class StructMemberDecoration
: public Castable<StructMemberDecoration, Decoration> {
public:
/// The kind of decoration that this type represents
static constexpr const DecorationKind Kind = DecorationKind::kStructMember;
~StructMemberDecoration() override;
/// @return the decoration kind
DecorationKind GetKind() const override;
protected:
/// Constructor
/// @param source the source of this decoration
explicit StructMemberDecoration(const Source& source);
};
/// A list of struct member decorations
using StructMemberDecorationList = std::vector<StructMemberDecoration*>;
} // namespace ast
} // namespace tint
#endif // SRC_AST_STRUCT_MEMBER_DECORATION_H_

View File

@ -15,14 +15,14 @@
#ifndef SRC_AST_STRUCT_MEMBER_OFFSET_DECORATION_H_ #ifndef SRC_AST_STRUCT_MEMBER_OFFSET_DECORATION_H_
#define SRC_AST_STRUCT_MEMBER_OFFSET_DECORATION_H_ #define SRC_AST_STRUCT_MEMBER_OFFSET_DECORATION_H_
#include "src/ast/struct_member_decoration.h" #include "src/ast/decoration.h"
namespace tint { namespace tint {
namespace ast { namespace ast {
/// A struct member offset decoration /// A struct member offset decoration
class StructMemberOffsetDecoration class StructMemberOffsetDecoration
: public Castable<StructMemberOffsetDecoration, StructMemberDecoration> { : public Castable<StructMemberOffsetDecoration, Decoration> {
public: public:
/// constructor /// constructor
/// @param source the source of this decoration /// @param source the source of this decoration

View File

@ -23,8 +23,8 @@ namespace {
using StructTest = TestHelper; using StructTest = TestHelper;
TEST_F(StructTest, Creation) { TEST_F(StructTest, Creation) {
auto* s = create<Struct>(StructMemberList{Member("a", ty.i32())}, auto* s =
StructDecorationList{}); create<Struct>(StructMemberList{Member("a", ty.i32())}, DecorationList{});
EXPECT_EQ(s->members().size(), 1u); EXPECT_EQ(s->members().size(), 1u);
EXPECT_TRUE(s->decorations().empty()); EXPECT_TRUE(s->decorations().empty());
EXPECT_EQ(s->source().range.begin.line, 0u); EXPECT_EQ(s->source().range.begin.line, 0u);
@ -34,7 +34,7 @@ TEST_F(StructTest, Creation) {
} }
TEST_F(StructTest, Creation_WithDecorations) { TEST_F(StructTest, Creation_WithDecorations) {
StructDecorationList decos; DecorationList decos;
decos.push_back(create<StructBlockDecoration>()); decos.push_back(create<StructBlockDecoration>());
auto* s = create<Struct>(StructMemberList{Member("a", ty.i32())}, decos); auto* s = create<Struct>(StructMemberList{Member("a", ty.i32())}, decos);
@ -48,7 +48,7 @@ TEST_F(StructTest, Creation_WithDecorations) {
} }
TEST_F(StructTest, CreationWithSourceAndDecorations) { TEST_F(StructTest, CreationWithSourceAndDecorations) {
StructDecorationList decos; DecorationList decos;
decos.push_back(create<StructBlockDecoration>()); decos.push_back(create<StructBlockDecoration>());
auto* s = create<Struct>( auto* s = create<Struct>(
@ -68,7 +68,7 @@ TEST_F(StructTest, Assert_Null_StructMember) {
{ {
ProgramBuilder b; ProgramBuilder b;
b.create<Struct>(StructMemberList{b.Member("a", b.ty.i32()), nullptr}, b.create<Struct>(StructMemberList{b.Member("a", b.ty.i32()), nullptr},
StructDecorationList{}); DecorationList{});
}, },
"internal compiler error"); "internal compiler error");
} }
@ -78,13 +78,13 @@ TEST_F(StructTest, Assert_Null_Decoration) {
{ {
ProgramBuilder b; ProgramBuilder b;
b.create<Struct>(StructMemberList{b.Member("a", b.ty.i32())}, b.create<Struct>(StructMemberList{b.Member("a", b.ty.i32())},
StructDecorationList{nullptr}); DecorationList{nullptr});
}, },
"internal compiler error"); "internal compiler error");
} }
TEST_F(StructTest, ToStr) { TEST_F(StructTest, ToStr) {
StructDecorationList decos; DecorationList decos;
decos.push_back(create<StructBlockDecoration>()); decos.push_back(create<StructBlockDecoration>());
auto* s = create<Struct>(StructMemberList{Member("a", ty.i32())}, decos); auto* s = create<Struct>(StructMemberList{Member("a", ty.i32())}, decos);

View File

@ -1,50 +0,0 @@
// Copyright 2020 The Tint Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef SRC_AST_TYPE_DECORATION_H_
#define SRC_AST_TYPE_DECORATION_H_
#include <vector>
#include "src/ast/decoration.h"
namespace tint {
namespace ast {
class AccessDecoration;
/// A decoration attached to a type
class TypeDecoration : public Castable<TypeDecoration, Decoration> {
public:
/// The kind of decoration that this type represents
static constexpr const DecorationKind Kind = DecorationKind::kType;
~TypeDecoration() override;
/// @return the decoration kind
DecorationKind GetKind() const override;
protected:
/// Constructor
/// @param source the source of this decoration
explicit TypeDecoration(const Source& source);
};
/// A list of type decorations
using TypeDecorationList = std::vector<TypeDecoration*>;
} // namespace ast
} // namespace tint
#endif // SRC_AST_TYPE_DECORATION_H_

View File

@ -29,7 +29,7 @@ Variable::Variable(const Source& source,
type::Type* type, type::Type* type,
bool is_const, bool is_const,
Expression* constructor, Expression* constructor,
VariableDecorationList decorations) DecorationList decorations)
: Base(source), : Base(source),
symbol_(sym), symbol_(sym),
type_(type), type_(type),

View File

@ -18,9 +18,9 @@
#include <utility> #include <utility>
#include <vector> #include <vector>
#include "src/ast/decoration.h"
#include "src/ast/expression.h" #include "src/ast/expression.h"
#include "src/ast/storage_class.h" #include "src/ast/storage_class.h"
#include "src/ast/variable_decoration.h"
namespace tint { namespace tint {
namespace ast { namespace ast {
@ -90,7 +90,7 @@ class Variable : public Castable<Variable, Node> {
type::Type* type, type::Type* type,
bool is_const, bool is_const,
Expression* constructor, Expression* constructor,
VariableDecorationList decorations); DecorationList decorations);
/// Move constructor /// Move constructor
Variable(Variable&&); Variable(Variable&&);
@ -115,7 +115,7 @@ class Variable : public Castable<Variable, Node> {
bool is_const() const { return is_const_; } bool is_const() const { return is_const_; }
/// @returns the decorations attached to this variable /// @returns the decorations attached to this variable
const VariableDecorationList& decorations() const { return decorations_; } const DecorationList& decorations() const { return decorations_; }
/// @returns true if the decorations include a LocationDecoration /// @returns true if the decorations include a LocationDecoration
bool HasLocationDecoration() const; bool HasLocationDecoration() const;
@ -169,7 +169,7 @@ class Variable : public Castable<Variable, Node> {
type::Type* const type_; type::Type* const type_;
bool const is_const_; bool const is_const_;
Expression* const constructor_; Expression* const constructor_;
VariableDecorationList const decorations_; DecorationList const decorations_;
StorageClass const declared_storage_class_; StorageClass const declared_storage_class_;
}; };

View File

@ -1,48 +0,0 @@
// Copyright 2020 The Tint Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef SRC_AST_VARIABLE_DECORATION_H_
#define SRC_AST_VARIABLE_DECORATION_H_
#include <vector>
#include "src/ast/decoration.h"
namespace tint {
namespace ast {
/// A decoration attached to a variable
class VariableDecoration : public Castable<VariableDecoration, Decoration> {
public:
/// The kind of decoration that this type represents
static constexpr const DecorationKind Kind = DecorationKind::kVariable;
~VariableDecoration() override;
/// @return the decoration kind
DecorationKind GetKind() const override;
protected:
/// Constructor
/// @param source the source of this decoration
explicit VariableDecoration(const Source& source);
};
/// A list of variable decorations
using VariableDecorationList = std::vector<VariableDecoration*>;
} // namespace ast
} // namespace tint
#endif // SRC_AST_VARIABLE_DECORATION_H_

View File

@ -37,7 +37,7 @@ TEST_F(VariableTest, Creation) {
TEST_F(VariableTest, CreationWithSource) { TEST_F(VariableTest, CreationWithSource) {
auto* v = Var( auto* v = Var(
Source{Source::Range{Source::Location{27, 4}, Source::Location{27, 5}}}, Source{Source::Range{Source::Location{27, 4}, Source::Location{27, 5}}},
"i", ty.f32(), StorageClass::kPrivate, nullptr, VariableDecorationList{}); "i", ty.f32(), StorageClass::kPrivate, nullptr, DecorationList{});
EXPECT_EQ(v->symbol(), Symbol(1)); EXPECT_EQ(v->symbol(), Symbol(1));
EXPECT_EQ(v->declared_storage_class(), StorageClass::kPrivate); EXPECT_EQ(v->declared_storage_class(), StorageClass::kPrivate);
@ -51,8 +51,7 @@ TEST_F(VariableTest, CreationWithSource) {
TEST_F(VariableTest, CreationEmpty) { TEST_F(VariableTest, CreationEmpty) {
auto* v = Var( auto* v = Var(
Source{Source::Range{Source::Location{27, 4}, Source::Location{27, 7}}}, Source{Source::Range{Source::Location{27, 4}, Source::Location{27, 7}}},
"a_var", ty.i32(), StorageClass::kWorkgroup, nullptr, "a_var", ty.i32(), StorageClass::kWorkgroup, nullptr, DecorationList{});
VariableDecorationList{});
EXPECT_EQ(v->symbol(), Symbol(1)); EXPECT_EQ(v->symbol(), Symbol(1));
EXPECT_EQ(v->declared_storage_class(), StorageClass::kWorkgroup); EXPECT_EQ(v->declared_storage_class(), StorageClass::kWorkgroup);
@ -93,7 +92,7 @@ TEST_F(VariableTest, to_str) {
TEST_F(VariableTest, WithDecorations) { TEST_F(VariableTest, WithDecorations) {
auto* var = Var("my_var", ty.i32(), StorageClass::kFunction, nullptr, auto* var = Var("my_var", ty.i32(), StorageClass::kFunction, nullptr,
VariableDecorationList{ DecorationList{
create<LocationDecoration>(1), create<LocationDecoration>(1),
create<BuiltinDecoration>(Builtin::kPosition), create<BuiltinDecoration>(Builtin::kPosition),
create<ConstantIdDecoration>(1200), create<ConstantIdDecoration>(1200),
@ -110,7 +109,7 @@ TEST_F(VariableTest, WithDecorations) {
TEST_F(VariableTest, ConstantId) { TEST_F(VariableTest, ConstantId) {
auto* var = Var("my_var", ty.i32(), StorageClass::kFunction, nullptr, auto* var = Var("my_var", ty.i32(), StorageClass::kFunction, nullptr,
VariableDecorationList{ DecorationList{
create<ConstantIdDecoration>(1200), create<ConstantIdDecoration>(1200),
}); });
@ -119,7 +118,7 @@ TEST_F(VariableTest, ConstantId) {
TEST_F(VariableTest, Decorated_to_str) { TEST_F(VariableTest, Decorated_to_str) {
auto* var = Var("my_var", ty.f32(), StorageClass::kFunction, Expr("expr"), auto* var = Var("my_var", ty.f32(), StorageClass::kFunction, Expr("expr"),
VariableDecorationList{ DecorationList{
create<BindingDecoration>(2), create<BindingDecoration>(2),
create<GroupDecoration>(1), create<GroupDecoration>(1),
}); });

View File

@ -17,14 +17,13 @@
#include <tuple> #include <tuple>
#include "src/ast/function_decoration.h" #include "src/ast/decoration.h"
namespace tint { namespace tint {
namespace ast { namespace ast {
/// A workgroup decoration /// A workgroup decoration
class WorkgroupDecoration class WorkgroupDecoration : public Castable<WorkgroupDecoration, Decoration> {
: public Castable<WorkgroupDecoration, FunctionDecoration> {
public: public:
/// constructor /// constructor
/// @param source the source of this decoration /// @param source the source of this decoration

View File

@ -37,7 +37,7 @@ class InspectorHelper : public ProgramBuilder {
/// @param name name of the function created /// @param name name of the function created
/// @param decorations the function decorations /// @param decorations the function decorations
void MakeEmptyBodyFunction(std::string name, void MakeEmptyBodyFunction(std::string name,
ast::FunctionDecorationList decorations) { ast::DecorationList decorations) {
Func(name, ast::VariableList(), ty.void_(), Func(name, ast::VariableList(), ty.void_(),
ast::StatementList{create<ast::ReturnStatement>()}, decorations); ast::StatementList{create<ast::ReturnStatement>()}, decorations);
} }
@ -48,7 +48,7 @@ class InspectorHelper : public ProgramBuilder {
/// @param decorations the function decorations /// @param decorations the function decorations
void MakeCallerBodyFunction(std::string caller, void MakeCallerBodyFunction(std::string caller,
std::vector<std::string> callees, std::vector<std::string> callees,
ast::FunctionDecorationList decorations) { ast::DecorationList decorations) {
ast::StatementList body; ast::StatementList body;
body.reserve(callees.size() + 1); body.reserve(callees.size() + 1);
for (auto callee : callees) { for (auto callee : callees) {
@ -70,11 +70,9 @@ class InspectorHelper : public ProgramBuilder {
std::tie(in, out) = inout; std::tie(in, out) = inout;
Global(in, ty.u32(), ast::StorageClass::kInput, nullptr, Global(in, ty.u32(), ast::StorageClass::kInput, nullptr,
ast::VariableDecorationList{ ast::DecorationList{create<ast::LocationDecoration>(location++)});
create<ast::LocationDecoration>(location++)});
Global(out, ty.u32(), ast::StorageClass::kOutput, nullptr, Global(out, ty.u32(), ast::StorageClass::kOutput, nullptr,
ast::VariableDecorationList{ ast::DecorationList{create<ast::LocationDecoration>(location++)});
create<ast::LocationDecoration>(location++)});
} }
} }
@ -86,7 +84,7 @@ class InspectorHelper : public ProgramBuilder {
void MakeInOutVariableBodyFunction( void MakeInOutVariableBodyFunction(
std::string name, std::string name,
std::vector<std::tuple<std::string, std::string>> inout_vars, std::vector<std::tuple<std::string, std::string>> inout_vars,
ast::FunctionDecorationList decorations) { ast::DecorationList decorations) {
ast::StatementList stmts; ast::StatementList stmts;
for (auto inout : inout_vars) { for (auto inout : inout_vars) {
std::string in, out; std::string in, out;
@ -109,7 +107,7 @@ class InspectorHelper : public ProgramBuilder {
std::string caller, std::string caller,
std::string callee, std::string callee,
std::vector<std::tuple<std::string, std::string>> inout_vars, std::vector<std::tuple<std::string, std::string>> inout_vars,
ast::FunctionDecorationList decorations) { ast::DecorationList decorations) {
ast::StatementList stmts; ast::StatementList stmts;
for (auto inout : inout_vars) { for (auto inout : inout_vars) {
std::string in, out; std::string in, out;
@ -136,7 +134,7 @@ class InspectorHelper : public ProgramBuilder {
create<ast::ScalarConstructorExpression>(MakeLiteral(type, val)); create<ast::ScalarConstructorExpression>(MakeLiteral(type, val));
} }
GlobalConst(name, type, constructor, GlobalConst(name, type, constructor,
ast::VariableDecorationList{ ast::DecorationList{
create<ast::ConstantIdDecoration>(id), create<ast::ConstantIdDecoration>(id),
}); });
} }
@ -210,7 +208,7 @@ class InspectorHelper : public ProgramBuilder {
{MemberOffset(offset)})); {MemberOffset(offset)}));
} }
ast::StructDecorationList decos; ast::DecorationList decos;
if (is_block) { if (is_block) {
decos.push_back(create<ast::StructBlockDecoration>()); decos.push_back(create<ast::StructBlockDecoration>());
} }
@ -280,7 +278,7 @@ class InspectorHelper : public ProgramBuilder {
uint32_t group, uint32_t group,
uint32_t binding) { uint32_t binding) {
Global(name, type, storage_class, nullptr, Global(name, type, storage_class, nullptr,
ast::VariableDecorationList{ ast::DecorationList{
create<ast::BindingDecoration>(binding), create<ast::BindingDecoration>(binding),
create<ast::GroupDecoration>(group), create<ast::GroupDecoration>(group),
}); });
@ -343,7 +341,7 @@ class InspectorHelper : public ProgramBuilder {
stmts.emplace_back(create<ast::ReturnStatement>()); stmts.emplace_back(create<ast::ReturnStatement>());
Func(func_name, ast::VariableList(), ty.void_(), stmts, Func(func_name, ast::VariableList(), ty.void_(), stmts,
ast::FunctionDecorationList{}); ast::DecorationList{});
} }
/// Adds a regular sampler variable to the program /// Adds a regular sampler variable to the program
@ -446,7 +444,7 @@ class InspectorHelper : public ProgramBuilder {
const std::string& sampler_name, const std::string& sampler_name,
const std::string& coords_name, const std::string& coords_name,
type::Type* base_type, type::Type* base_type,
ast::FunctionDecorationList decorations) { ast::DecorationList decorations) {
std::string result_name = "sampler_result"; std::string result_name = "sampler_result";
ast::StatementList stmts; ast::StatementList stmts;
@ -478,7 +476,7 @@ class InspectorHelper : public ProgramBuilder {
const std::string& coords_name, const std::string& coords_name,
const std::string& array_index, const std::string& array_index,
type::Type* base_type, type::Type* base_type,
ast::FunctionDecorationList decorations) { ast::DecorationList decorations) {
std::string result_name = "sampler_result"; std::string result_name = "sampler_result";
ast::StatementList stmts; ast::StatementList stmts;
@ -512,7 +510,7 @@ class InspectorHelper : public ProgramBuilder {
const std::string& coords_name, const std::string& coords_name,
const std::string& depth_name, const std::string& depth_name,
type::Type* base_type, type::Type* base_type,
ast::FunctionDecorationList decorations) { ast::DecorationList decorations) {
std::string result_name = "sampler_result"; std::string result_name = "sampler_result";
ast::StatementList stmts; ast::StatementList stmts;
@ -617,7 +615,7 @@ class InspectorHelper : public ProgramBuilder {
const std::string& func_name, const std::string& func_name,
const std::string& st_name, const std::string& st_name,
type::Type* dim_type, type::Type* dim_type,
ast::FunctionDecorationList decorations) { ast::DecorationList decorations) {
ast::StatementList stmts; ast::StatementList stmts;
stmts.emplace_back(create<ast::VariableDeclStatement>( stmts.emplace_back(create<ast::VariableDeclStatement>(
@ -646,7 +644,7 @@ class InspectorHelper : public ProgramBuilder {
if (array_type_memo_.find(count) == array_type_memo_.end()) { if (array_type_memo_.find(count) == array_type_memo_.end()) {
array_type_memo_[count] = array_type_memo_[count] =
create<type::Array>(ty.u32(), count, create<type::Array>(ty.u32(), count,
ast::ArrayDecorationList{ ast::DecorationList{
create<ast::StrideDecoration>(4), create<ast::StrideDecoration>(4),
}); });
} }
@ -763,7 +761,7 @@ TEST_F(InspectorGetEntryPointTest, NoEntryPoints) {
TEST_F(InspectorGetEntryPointTest, OneEntryPoint) { TEST_F(InspectorGetEntryPointTest, OneEntryPoint) {
MakeEmptyBodyFunction( MakeEmptyBodyFunction(
"foo", ast::FunctionDecorationList{ "foo", ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
@ -782,12 +780,12 @@ TEST_F(InspectorGetEntryPointTest, OneEntryPoint) {
TEST_F(InspectorGetEntryPointTest, MultipleEntryPoints) { TEST_F(InspectorGetEntryPointTest, MultipleEntryPoints) {
MakeEmptyBodyFunction( MakeEmptyBodyFunction(
"foo", ast::FunctionDecorationList{ "foo", ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
MakeEmptyBodyFunction( MakeEmptyBodyFunction(
"bar", ast::FunctionDecorationList{ "bar", ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kCompute), create<ast::StageDecoration>(ast::PipelineStage::kCompute),
}); });
@ -812,13 +810,13 @@ TEST_F(InspectorGetEntryPointTest, MixFunctionsAndEntryPoints) {
MakeCallerBodyFunction( MakeCallerBodyFunction(
"foo", {"func"}, "foo", {"func"},
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
MakeCallerBodyFunction( MakeCallerBodyFunction(
"bar", {"func"}, "bar", {"func"},
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment), create<ast::StageDecoration>(ast::PipelineStage::kFragment),
}); });
@ -840,7 +838,7 @@ TEST_F(InspectorGetEntryPointTest, MixFunctionsAndEntryPoints) {
TEST_F(InspectorGetEntryPointTest, DefaultWorkgroupSize) { TEST_F(InspectorGetEntryPointTest, DefaultWorkgroupSize) {
MakeEmptyBodyFunction( MakeEmptyBodyFunction(
"foo", ast::FunctionDecorationList{ "foo", ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
@ -859,7 +857,7 @@ TEST_F(InspectorGetEntryPointTest, DefaultWorkgroupSize) {
TEST_F(InspectorGetEntryPointTest, NonDefaultWorkgroupSize) { TEST_F(InspectorGetEntryPointTest, NonDefaultWorkgroupSize) {
MakeEmptyBodyFunction( MakeEmptyBodyFunction(
"foo", ast::FunctionDecorationList{ "foo", ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kCompute), create<ast::StageDecoration>(ast::PipelineStage::kCompute),
create<ast::WorkgroupDecoration>(8u, 2u, 1u), create<ast::WorkgroupDecoration>(8u, 2u, 1u),
}); });
@ -882,7 +880,7 @@ TEST_F(InspectorGetEntryPointTest, NoInOutVariables) {
MakeCallerBodyFunction( MakeCallerBodyFunction(
"foo", {"func"}, "foo", {"func"},
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
@ -901,7 +899,7 @@ TEST_F(InspectorGetEntryPointTest, EntryPointInOutVariables) {
MakeInOutVariableBodyFunction( MakeInOutVariableBodyFunction(
"foo", {{"in_var", "out_var"}}, "foo", {{"in_var", "out_var"}},
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
@ -932,7 +930,7 @@ TEST_F(InspectorGetEntryPointTest, FunctionInOutVariables) {
MakeCallerBodyFunction( MakeCallerBodyFunction(
"foo", {"func"}, "foo", {"func"},
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
@ -963,7 +961,7 @@ TEST_F(InspectorGetEntryPointTest, RepeatedInOutVariables) {
MakeInOutVariableCallerBodyFunction( MakeInOutVariableCallerBodyFunction(
"foo", "func", {{"in_var", "out_var"}}, "foo", "func", {{"in_var", "out_var"}},
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
@ -992,7 +990,7 @@ TEST_F(InspectorGetEntryPointTest, EntryPointMultipleInOutVariables) {
MakeInOutVariableBodyFunction( MakeInOutVariableBodyFunction(
"foo", {{"in_var", "out_var"}, {"in2_var", "out2_var"}}, "foo", {{"in_var", "out_var"}, {"in2_var", "out2_var"}},
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
@ -1032,7 +1030,7 @@ TEST_F(InspectorGetEntryPointTest, FunctionMultipleInOutVariables) {
MakeCallerBodyFunction( MakeCallerBodyFunction(
"foo", {"func"}, "foo", {"func"},
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
@ -1069,13 +1067,13 @@ TEST_F(InspectorGetEntryPointTest, MultipleEntryPointsInOutVariables) {
MakeInOutVariableBodyFunction( MakeInOutVariableBodyFunction(
"foo", {{"in_var", "out2_var"}}, "foo", {{"in_var", "out2_var"}},
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
MakeInOutVariableBodyFunction( MakeInOutVariableBodyFunction(
"bar", {{"in2_var", "out_var"}}, "bar", {{"in2_var", "out_var"}},
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kCompute), create<ast::StageDecoration>(ast::PipelineStage::kCompute),
}); });
@ -1127,13 +1125,13 @@ TEST_F(InspectorGetEntryPointTest, MultipleEntryPointsSharedInOutVariables) {
MakeInOutVariableCallerBodyFunction( MakeInOutVariableCallerBodyFunction(
"foo", "func", {{"in_var", "out_var"}}, "foo", "func", {{"in_var", "out_var"}},
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
MakeCallerBodyFunction( MakeCallerBodyFunction(
"bar", {"func"}, "bar", {"func"},
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kCompute), create<ast::StageDecoration>(ast::PipelineStage::kCompute),
}); });
@ -1188,16 +1186,16 @@ TEST_F(InspectorGetEntryPointTest, MultipleEntryPointsSharedInOutVariables) {
TEST_F(InspectorGetEntryPointTest, BuiltInsNotStageVariables) { TEST_F(InspectorGetEntryPointTest, BuiltInsNotStageVariables) {
Global("in_var", ty.u32(), ast::StorageClass::kInput, nullptr, Global("in_var", ty.u32(), ast::StorageClass::kInput, nullptr,
ast::VariableDecorationList{ ast::DecorationList{
create<ast::BuiltinDecoration>(ast::Builtin::kPosition)}); create<ast::BuiltinDecoration>(ast::Builtin::kPosition)});
Global("out_var", ty.u32(), ast::StorageClass::kOutput, nullptr, Global("out_var", ty.u32(), ast::StorageClass::kOutput, nullptr,
ast::VariableDecorationList{create<ast::LocationDecoration>(0)}); ast::DecorationList{create<ast::LocationDecoration>(0)});
MakeInOutVariableBodyFunction("func", {{"in_var", "out_var"}}, {}); MakeInOutVariableBodyFunction("func", {{"in_var", "out_var"}}, {});
MakeCallerBodyFunction( MakeCallerBodyFunction(
"foo", {"func"}, "foo", {"func"},
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
@ -1246,7 +1244,7 @@ TEST_F(InspectorGetRemappedNameForEntryPointTest, DISABLED_NoEntryPoints) {
// through // through
TEST_F(InspectorGetRemappedNameForEntryPointTest, DISABLED_OneEntryPoint) { TEST_F(InspectorGetRemappedNameForEntryPointTest, DISABLED_OneEntryPoint) {
MakeEmptyBodyFunction( MakeEmptyBodyFunction(
"foo", ast::FunctionDecorationList{ "foo", ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
@ -1266,7 +1264,7 @@ TEST_F(InspectorGetRemappedNameForEntryPointTest, DISABLED_OneEntryPoint) {
TEST_F(InspectorGetRemappedNameForEntryPointTest, TEST_F(InspectorGetRemappedNameForEntryPointTest,
DISABLED_MultipleEntryPoints) { DISABLED_MultipleEntryPoints) {
MakeEmptyBodyFunction( MakeEmptyBodyFunction(
"foo", ast::FunctionDecorationList{ "foo", ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
@ -1274,7 +1272,7 @@ TEST_F(InspectorGetRemappedNameForEntryPointTest,
// available. // available.
MakeEmptyBodyFunction( MakeEmptyBodyFunction(
"bar", ast::FunctionDecorationList{ "bar", ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kCompute), create<ast::StageDecoration>(ast::PipelineStage::kCompute),
}); });
@ -1391,7 +1389,7 @@ TEST_F(InspectorGetConstantIDsTest, Float) {
TEST_F(InspectorGetResourceBindingsTest, Empty) { TEST_F(InspectorGetResourceBindingsTest, Empty) {
MakeCallerBodyFunction( MakeCallerBodyFunction(
"ep_func", {}, "ep_func", {},
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
@ -1443,7 +1441,7 @@ TEST_F(InspectorGetResourceBindingsTest, Simple) {
MakeCallerBodyFunction( MakeCallerBodyFunction(
"ep_func", {"ub_func", "sb_func", "ro_func", "s_func", "cs_func"}, "ep_func", {"ub_func", "sb_func", "ro_func", "s_func", "cs_func"},
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
@ -1508,7 +1506,7 @@ TEST_F(InspectorGetUniformBufferResourceBindingsTest, NonEntryPointFunc) {
MakeCallerBodyFunction( MakeCallerBodyFunction(
"ep_func", {"ub_func"}, "ep_func", {"ub_func"},
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
@ -1520,7 +1518,7 @@ TEST_F(InspectorGetUniformBufferResourceBindingsTest, NonEntryPointFunc) {
} }
TEST_F(InspectorGetUniformBufferResourceBindingsTest, MissingBlockDeco) { TEST_F(InspectorGetUniformBufferResourceBindingsTest, MissingBlockDeco) {
ast::StructDecorationList decos; ast::DecorationList decos;
auto* str = create<ast::Struct>( auto* str = create<ast::Struct>(
ast::StructMemberList{ ast::StructMemberList{
Member(StructMemberName(0, ty.i32()), ty.i32(), {MemberOffset(0)})}, Member(StructMemberName(0, ty.i32()), ty.i32(), {MemberOffset(0)})},
@ -1533,7 +1531,7 @@ TEST_F(InspectorGetUniformBufferResourceBindingsTest, MissingBlockDeco) {
MakeCallerBodyFunction( MakeCallerBodyFunction(
"ep_func", {"ub_func"}, "ep_func", {"ub_func"},
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
@ -1555,7 +1553,7 @@ TEST_F(InspectorGetUniformBufferResourceBindingsTest, Simple) {
MakeCallerBodyFunction( MakeCallerBodyFunction(
"ep_func", {"ub_func"}, "ep_func", {"ub_func"},
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
@ -1584,7 +1582,7 @@ TEST_F(InspectorGetUniformBufferResourceBindingsTest, MultipleMembers) {
MakeCallerBodyFunction( MakeCallerBodyFunction(
"ep_func", {"ub_func"}, "ep_func", {"ub_func"},
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
@ -1627,7 +1625,7 @@ TEST_F(InspectorGetUniformBufferResourceBindingsTest, MultipleUniformBuffers) {
ast::StatementList{FuncCall("ub_foo_func"), FuncCall("ub_bar_func"), ast::StatementList{FuncCall("ub_foo_func"), FuncCall("ub_bar_func"),
FuncCall("ub_baz_func"), FuncCall("ub_baz_func"),
create<ast::ReturnStatement>()}, create<ast::ReturnStatement>()},
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
@ -1667,7 +1665,7 @@ TEST_F(InspectorGetUniformBufferResourceBindingsTest, ContainingArray) {
MakeCallerBodyFunction( MakeCallerBodyFunction(
"ep_func", {"ub_func"}, "ep_func", {"ub_func"},
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
@ -1695,7 +1693,7 @@ TEST_F(InspectorGetStorageBufferResourceBindingsTest, Simple) {
MakeCallerBodyFunction( MakeCallerBodyFunction(
"ep_func", {"sb_func"}, "ep_func", {"sb_func"},
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
@ -1724,7 +1722,7 @@ TEST_F(InspectorGetStorageBufferResourceBindingsTest, MultipleMembers) {
MakeCallerBodyFunction( MakeCallerBodyFunction(
"ep_func", {"sb_func"}, "ep_func", {"sb_func"},
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
@ -1770,7 +1768,7 @@ TEST_F(InspectorGetStorageBufferResourceBindingsTest, MultipleStorageBuffers) {
FuncCall("sb_baz_func"), FuncCall("sb_baz_func"),
create<ast::ReturnStatement>(), create<ast::ReturnStatement>(),
}, },
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
@ -1810,7 +1808,7 @@ TEST_F(InspectorGetStorageBufferResourceBindingsTest, ContainingArray) {
MakeCallerBodyFunction( MakeCallerBodyFunction(
"ep_func", {"sb_func"}, "ep_func", {"sb_func"},
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
@ -1838,7 +1836,7 @@ TEST_F(InspectorGetStorageBufferResourceBindingsTest, ContainingRuntimeArray) {
MakeCallerBodyFunction( MakeCallerBodyFunction(
"ep_func", {"sb_func"}, "ep_func", {"sb_func"},
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
@ -1866,7 +1864,7 @@ TEST_F(InspectorGetStorageBufferResourceBindingsTest, SkipReadOnly) {
MakeCallerBodyFunction( MakeCallerBodyFunction(
"ep_func", {"sb_func"}, "ep_func", {"sb_func"},
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
@ -1888,7 +1886,7 @@ TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest, Simple) {
MakeCallerBodyFunction( MakeCallerBodyFunction(
"ep_func", {"sb_func"}, "ep_func", {"sb_func"},
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
@ -1935,7 +1933,7 @@ TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest,
FuncCall("sb_baz_func"), FuncCall("sb_baz_func"),
create<ast::ReturnStatement>(), create<ast::ReturnStatement>(),
}, },
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
@ -1975,7 +1973,7 @@ TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest, ContainingArray) {
MakeCallerBodyFunction( MakeCallerBodyFunction(
"ep_func", {"sb_func"}, "ep_func", {"sb_func"},
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
@ -2004,7 +2002,7 @@ TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest,
MakeCallerBodyFunction( MakeCallerBodyFunction(
"ep_func", {"sb_func"}, "ep_func", {"sb_func"},
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
@ -2032,7 +2030,7 @@ TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest, SkipNonReadOnly) {
MakeCallerBodyFunction( MakeCallerBodyFunction(
"ep_func", {"sb_func"}, "ep_func", {"sb_func"},
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
@ -2052,7 +2050,7 @@ TEST_F(InspectorGetSamplerResourceBindingsTest, Simple) {
MakeSamplerReferenceBodyFunction( MakeSamplerReferenceBodyFunction(
"ep", "foo_texture", "foo_sampler", "foo_coords", ty.f32(), "ep", "foo_texture", "foo_sampler", "foo_coords", ty.f32(),
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
@ -2069,7 +2067,7 @@ TEST_F(InspectorGetSamplerResourceBindingsTest, Simple) {
TEST_F(InspectorGetSamplerResourceBindingsTest, NoSampler) { TEST_F(InspectorGetSamplerResourceBindingsTest, NoSampler) {
MakeEmptyBodyFunction( MakeEmptyBodyFunction(
"ep_func", ast::FunctionDecorationList{ "ep_func", ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
@ -2093,7 +2091,7 @@ TEST_F(InspectorGetSamplerResourceBindingsTest, InFunction) {
MakeCallerBodyFunction( MakeCallerBodyFunction(
"ep_func", {"foo_func"}, "ep_func", {"foo_func"},
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
@ -2117,7 +2115,7 @@ TEST_F(InspectorGetSamplerResourceBindingsTest, UnknownEntryPoint) {
MakeSamplerReferenceBodyFunction( MakeSamplerReferenceBodyFunction(
"ep", "foo_texture", "foo_sampler", "foo_coords", ty.f32(), "ep", "foo_texture", "foo_sampler", "foo_coords", ty.f32(),
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
@ -2136,7 +2134,7 @@ TEST_F(InspectorGetSamplerResourceBindingsTest, SkipsComparisonSamplers) {
MakeComparisonSamplerReferenceBodyFunction( MakeComparisonSamplerReferenceBodyFunction(
"ep", "foo_texture", "foo_sampler", "foo_coords", "foo_depth", ty.f32(), "ep", "foo_texture", "foo_sampler", "foo_coords", "foo_depth", ty.f32(),
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
@ -2157,7 +2155,7 @@ TEST_F(InspectorGetComparisonSamplerResourceBindingsTest, Simple) {
MakeComparisonSamplerReferenceBodyFunction( MakeComparisonSamplerReferenceBodyFunction(
"ep", "foo_texture", "foo_sampler", "foo_coords", "foo_depth", ty.f32(), "ep", "foo_texture", "foo_sampler", "foo_coords", "foo_depth", ty.f32(),
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
@ -2175,7 +2173,7 @@ TEST_F(InspectorGetComparisonSamplerResourceBindingsTest, Simple) {
TEST_F(InspectorGetComparisonSamplerResourceBindingsTest, NoSampler) { TEST_F(InspectorGetComparisonSamplerResourceBindingsTest, NoSampler) {
MakeEmptyBodyFunction( MakeEmptyBodyFunction(
"ep_func", ast::FunctionDecorationList{ "ep_func", ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
@ -2200,7 +2198,7 @@ TEST_F(InspectorGetComparisonSamplerResourceBindingsTest, InFunction) {
MakeCallerBodyFunction( MakeCallerBodyFunction(
"ep_func", {"foo_func"}, "ep_func", {"foo_func"},
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
@ -2225,7 +2223,7 @@ TEST_F(InspectorGetComparisonSamplerResourceBindingsTest, UnknownEntryPoint) {
MakeComparisonSamplerReferenceBodyFunction( MakeComparisonSamplerReferenceBodyFunction(
"ep", "foo_texture", "foo_sampler", "foo_coords", "foo_depth", ty.f32(), "ep", "foo_texture", "foo_sampler", "foo_coords", "foo_depth", ty.f32(),
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
@ -2244,7 +2242,7 @@ TEST_F(InspectorGetComparisonSamplerResourceBindingsTest, SkipsSamplers) {
MakeSamplerReferenceBodyFunction( MakeSamplerReferenceBodyFunction(
"ep", "foo_texture", "foo_sampler", "foo_coords", ty.f32(), "ep", "foo_texture", "foo_sampler", "foo_coords", ty.f32(),
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
@ -2258,7 +2256,7 @@ TEST_F(InspectorGetComparisonSamplerResourceBindingsTest, SkipsSamplers) {
TEST_F(InspectorGetSampledTextureResourceBindingsTest, Empty) { TEST_F(InspectorGetSampledTextureResourceBindingsTest, Empty) {
MakeEmptyBodyFunction( MakeEmptyBodyFunction(
"foo", ast::FunctionDecorationList{ "foo", ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
@ -2281,7 +2279,7 @@ TEST_P(InspectorGetSampledTextureResourceBindingsTestWithParam, textureSample) {
MakeSamplerReferenceBodyFunction( MakeSamplerReferenceBodyFunction(
"ep", "foo_texture", "foo_sampler", "foo_coords", "ep", "foo_texture", "foo_sampler", "foo_coords",
GetBaseType(GetParam().sampled_kind), GetBaseType(GetParam().sampled_kind),
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
@ -2340,7 +2338,7 @@ TEST_P(InspectorGetSampledArrayTextureResourceBindingsTestWithParam,
MakeSamplerReferenceBodyFunction( MakeSamplerReferenceBodyFunction(
"ep", "foo_texture", "foo_sampler", "foo_coords", "foo_array_index", "ep", "foo_texture", "foo_sampler", "foo_coords", "foo_array_index",
GetBaseType(GetParam().sampled_kind), GetBaseType(GetParam().sampled_kind),
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
@ -2385,7 +2383,7 @@ TEST_P(InspectorGetMultisampledTextureResourceBindingsTestWithParam,
create<ast::CallStatement>(Call("textureLoad", "foo_texture", create<ast::CallStatement>(Call("textureLoad", "foo_texture",
"foo_coords", "foo_sample_index")), "foo_coords", "foo_sample_index")),
}, },
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
@ -2429,7 +2427,7 @@ INSTANTIATE_TEST_SUITE_P(
TEST_F(InspectorGetMultisampledArrayTextureResourceBindingsTest, Empty) { TEST_F(InspectorGetMultisampledArrayTextureResourceBindingsTest, Empty) {
MakeEmptyBodyFunction( MakeEmptyBodyFunction(
"foo", ast::FunctionDecorationList{ "foo", ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
@ -2454,7 +2452,7 @@ TEST_P(InspectorGetMultisampledArrayTextureResourceBindingsTestWithParam,
MakeSamplerReferenceBodyFunction( MakeSamplerReferenceBodyFunction(
"ep", "foo_texture", "foo_sampler", "foo_coords", "foo_array_index", "ep", "foo_texture", "foo_sampler", "foo_coords", "foo_array_index",
GetBaseType(GetParam().sampled_kind), GetBaseType(GetParam().sampled_kind),
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
@ -2491,7 +2489,7 @@ INSTANTIATE_TEST_SUITE_P(
TEST_F(InspectorGetStorageTextureResourceBindingsTest, Empty) { TEST_F(InspectorGetStorageTextureResourceBindingsTest, Empty) {
MakeEmptyBodyFunction( MakeEmptyBodyFunction(
"ep", ast::FunctionDecorationList{ "ep", ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
@ -2548,7 +2546,7 @@ TEST_P(InspectorGetStorageTextureResourceBindingsTestWithParam, Simple) {
MakeStorageTextureBodyFunction( MakeStorageTextureBodyFunction(
"ep", "st_var", dim_type, "ep", "st_var", dim_type,
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex)}); create<ast::StageDecoration>(ast::PipelineStage::kVertex)});
Inspector& inspector = Build(); Inspector& inspector = Build();
@ -2707,7 +2705,7 @@ TEST_P(InspectorGetDepthTextureResourceBindingsTestWithParam,
create<ast::CallStatement>( create<ast::CallStatement>(
Call("textureDimensions", "dt", "dt_level")), Call("textureDimensions", "dt", "dt_level")),
}, },
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });

View File

@ -414,7 +414,7 @@ class ArrayBuilder : public Builder {
type::Type* Build(BuildState& state) const override { type::Type* Build(BuildState& state) const override {
auto* el = element_builder_->Build(state); auto* el = element_builder_->Build(state);
return state.ty_mgr.Get<type::Array>(el, 0, ast::ArrayDecorationList{}); return state.ty_mgr.Get<type::Array>(el, 0, ast::DecorationList{});
} }
std::string str() const override { std::string str() const override {

View File

@ -408,8 +408,7 @@ class ProgramBuilder {
/// @param n the array size. 0 represents a runtime-array. /// @param n the array size. 0 represents a runtime-array.
/// @return the tint AST type for a array of size `n` of type `T` /// @return the tint AST type for a array of size `n` of type `T`
type::Array* array(type::Type* subtype, uint32_t n) const { type::Array* array(type::Type* subtype, uint32_t n) const {
return builder->create<type::Array>(subtype, n, return builder->create<type::Array>(subtype, n, ast::DecorationList{});
ast::ArrayDecorationList{});
} }
/// @param subtype the array element type /// @param subtype the array element type
@ -419,7 +418,7 @@ class ProgramBuilder {
type::Array* array(type::Type* subtype, uint32_t n, uint32_t stride) const { type::Array* array(type::Type* subtype, uint32_t n, uint32_t stride) const {
return builder->create<type::Array>( return builder->create<type::Array>(
subtype, n, subtype, n,
ast::ArrayDecorationList{ ast::DecorationList{
builder->create<ast::StrideDecoration>(stride), builder->create<ast::StrideDecoration>(stride),
}); });
} }
@ -755,7 +754,7 @@ class ProgramBuilder {
type::Type* type, type::Type* type,
ast::StorageClass storage, ast::StorageClass storage,
ast::Expression* constructor = nullptr, ast::Expression* constructor = nullptr,
ast::VariableDecorationList decorations = {}) { ast::DecorationList decorations = {}) {
return create<ast::Variable>(Symbols().Register(name), storage, type, false, return create<ast::Variable>(Symbols().Register(name), storage, type, false,
constructor, decorations); constructor, decorations);
} }
@ -772,7 +771,7 @@ class ProgramBuilder {
type::Type* type, type::Type* type,
ast::StorageClass storage, ast::StorageClass storage,
ast::Expression* constructor = nullptr, ast::Expression* constructor = nullptr,
ast::VariableDecorationList decorations = {}) { ast::DecorationList decorations = {}) {
return create<ast::Variable>(source, Symbols().Register(name), storage, return create<ast::Variable>(source, Symbols().Register(name), storage,
type, false, constructor, decorations); type, false, constructor, decorations);
} }
@ -787,7 +786,7 @@ class ProgramBuilder {
type::Type* type, type::Type* type,
ast::StorageClass storage, ast::StorageClass storage,
ast::Expression* constructor = nullptr, ast::Expression* constructor = nullptr,
ast::VariableDecorationList decorations = {}) { ast::DecorationList decorations = {}) {
return create<ast::Variable>(symbol, storage, type, false, constructor, return create<ast::Variable>(symbol, storage, type, false, constructor,
decorations); decorations);
} }
@ -804,7 +803,7 @@ class ProgramBuilder {
type::Type* type, type::Type* type,
ast::StorageClass storage, ast::StorageClass storage,
ast::Expression* constructor = nullptr, ast::Expression* constructor = nullptr,
ast::VariableDecorationList decorations = {}) { ast::DecorationList decorations = {}) {
return create<ast::Variable>(source, symbol, storage, type, false, return create<ast::Variable>(source, symbol, storage, type, false,
constructor, decorations); constructor, decorations);
} }
@ -817,7 +816,7 @@ class ProgramBuilder {
ast::Variable* Const(const std::string& name, ast::Variable* Const(const std::string& name,
type::Type* type, type::Type* type,
ast::Expression* constructor = nullptr, ast::Expression* constructor = nullptr,
ast::VariableDecorationList decorations = {}) { ast::DecorationList decorations = {}) {
return create<ast::Variable>(Symbols().Register(name), return create<ast::Variable>(Symbols().Register(name),
ast::StorageClass::kNone, type, true, ast::StorageClass::kNone, type, true,
constructor, decorations); constructor, decorations);
@ -833,7 +832,7 @@ class ProgramBuilder {
const std::string& name, const std::string& name,
type::Type* type, type::Type* type,
ast::Expression* constructor = nullptr, ast::Expression* constructor = nullptr,
ast::VariableDecorationList decorations = {}) { ast::DecorationList decorations = {}) {
return create<ast::Variable>(source, Symbols().Register(name), return create<ast::Variable>(source, Symbols().Register(name),
ast::StorageClass::kNone, type, true, ast::StorageClass::kNone, type, true,
constructor, decorations); constructor, decorations);
@ -848,7 +847,7 @@ class ProgramBuilder {
ast::Variable* Const(Symbol symbol, ast::Variable* Const(Symbol symbol,
type::Type* type, type::Type* type,
ast::Expression* constructor = nullptr, ast::Expression* constructor = nullptr,
ast::VariableDecorationList decorations = {}) { ast::DecorationList decorations = {}) {
return create<ast::Variable>(symbol, ast::StorageClass::kNone, type, true, return create<ast::Variable>(symbol, ast::StorageClass::kNone, type, true,
constructor, decorations); constructor, decorations);
} }
@ -864,7 +863,7 @@ class ProgramBuilder {
Symbol symbol, Symbol symbol,
type::Type* type, type::Type* type,
ast::Expression* constructor = nullptr, ast::Expression* constructor = nullptr,
ast::VariableDecorationList decorations = {}) { ast::DecorationList decorations = {}) {
return create<ast::Variable>(source, symbol, ast::StorageClass::kNone, type, return create<ast::Variable>(source, symbol, ast::StorageClass::kNone, type,
true, constructor, decorations); true, constructor, decorations);
} }
@ -969,7 +968,7 @@ class ProgramBuilder {
ast::VariableList params, ast::VariableList params,
type::Type* type, type::Type* type,
ast::StatementList body, ast::StatementList body,
ast::FunctionDecorationList decorations) { ast::DecorationList decorations) {
auto* func = auto* func =
create<ast::Function>(source, Symbols().Register(name), params, type, create<ast::Function>(source, Symbols().Register(name), params, type,
create<ast::BlockStatement>(body), decorations); create<ast::BlockStatement>(body), decorations);
@ -988,7 +987,7 @@ class ProgramBuilder {
ast::VariableList params, ast::VariableList params,
type::Type* type, type::Type* type,
ast::StatementList body, ast::StatementList body,
ast::FunctionDecorationList decorations) { ast::DecorationList decorations) {
auto* func = auto* func =
create<ast::Function>(Symbols().Register(name), params, type, create<ast::Function>(Symbols().Register(name), params, type,
create<ast::BlockStatement>(body), decorations); create<ast::BlockStatement>(body), decorations);
@ -1005,7 +1004,7 @@ class ProgramBuilder {
const std::string& name, const std::string& name,
type::Type* type) { type::Type* type) {
return create<ast::StructMember>(source, Symbols().Register(name), type, return create<ast::StructMember>(source, Symbols().Register(name), type,
ast::StructMemberDecorationList{}); ast::DecorationList{});
} }
/// Creates a ast::StructMember /// Creates a ast::StructMember
@ -1014,7 +1013,7 @@ class ProgramBuilder {
/// @returns the struct member pointer /// @returns the struct member pointer
ast::StructMember* Member(const std::string& name, type::Type* type) { ast::StructMember* Member(const std::string& name, type::Type* type) {
return create<ast::StructMember>(source_, Symbols().Register(name), type, return create<ast::StructMember>(source_, Symbols().Register(name), type,
ast::StructMemberDecorationList{}); ast::DecorationList{});
} }
/// Creates a ast::StructMember /// Creates a ast::StructMember
@ -1024,7 +1023,7 @@ class ProgramBuilder {
/// @returns the struct member pointer /// @returns the struct member pointer
ast::StructMember* Member(const std::string& name, ast::StructMember* Member(const std::string& name,
type::Type* type, type::Type* type,
ast::StructMemberDecorationList decorations) { ast::DecorationList decorations) {
return create<ast::StructMember>(source_, Symbols().Register(name), type, return create<ast::StructMember>(source_, Symbols().Register(name), type,
decorations); decorations);
} }
@ -1039,7 +1038,7 @@ class ProgramBuilder {
type::Type* type) { type::Type* type) {
return create<ast::StructMember>( return create<ast::StructMember>(
source_, Symbols().Register(name), type, source_, Symbols().Register(name), type,
ast::StructMemberDecorationList{ ast::DecorationList{
create<ast::StructMemberOffsetDecoration>(offset), create<ast::StructMemberOffsetDecoration>(offset),
}); });
} }

View File

@ -887,7 +887,7 @@ bool FunctionEmitter::ParseFunctionDeclaration(FunctionDeclaration* decl) {
if (ast_type != nullptr) { if (ast_type != nullptr) {
auto* ast_param = parser_impl_.MakeVariable( auto* ast_param = parser_impl_.MakeVariable(
param->result_id(), ast::StorageClass::kNone, ast_type, true, param->result_id(), ast::StorageClass::kNone, ast_type, true,
nullptr, ast::VariableDecorationList{}); nullptr, ast::DecorationList{});
// Parameters are treated as const declarations. // Parameters are treated as const declarations.
ast_params.emplace_back(ast_param); ast_params.emplace_back(ast_param);
// The value is accessible by name. // The value is accessible by name.
@ -900,7 +900,7 @@ bool FunctionEmitter::ParseFunctionDeclaration(FunctionDeclaration* decl) {
if (failed()) { if (failed()) {
return false; return false;
} }
ast::FunctionDecorationList decos; ast::DecorationList decos;
if (ep_info_ != nullptr) { if (ep_info_ != nullptr) {
decos.emplace_back(create<ast::StageDecoration>(Source{}, ep_info_->stage)); decos.emplace_back(create<ast::StageDecoration>(Source{}, ep_info_->stage));
} }
@ -1961,7 +1961,7 @@ bool FunctionEmitter::EmitFunctionVariables() {
} }
auto* var = parser_impl_.MakeVariable( auto* var = parser_impl_.MakeVariable(
inst.result_id(), ast::StorageClass::kFunction, var_store_type, false, inst.result_id(), ast::StorageClass::kFunction, var_store_type, false,
constructor, ast::VariableDecorationList{}); constructor, ast::DecorationList{});
auto* var_decl_stmt = create<ast::VariableDeclStatement>(Source{}, var); auto* var_decl_stmt = create<ast::VariableDeclStatement>(Source{}, var);
AddStatement(var_decl_stmt); AddStatement(var_decl_stmt);
// Save this as an already-named value. // Save this as an already-named value.
@ -2287,7 +2287,7 @@ bool FunctionEmitter::EmitIfStart(const BlockInfo& block_info) {
parser_impl_.Bool(), // type parser_impl_.Bool(), // type
false, // is_const false, // is_const
MakeTrue(Source{}), // constructor MakeTrue(Source{}), // constructor
ast::VariableDecorationList{}); // decorations ast::DecorationList{}); // decorations
auto* guard_decl = create<ast::VariableDeclStatement>(Source{}, guard_var); auto* guard_decl = create<ast::VariableDeclStatement>(Source{}, guard_var);
AddStatement(guard_decl); AddStatement(guard_decl);
} }
@ -2796,9 +2796,9 @@ bool FunctionEmitter::EmitStatementsInBasicBlock(const BlockInfo& block_info,
auto* ast_type = auto* ast_type =
RemapStorageClass(parser_impl_.ConvertType(def_inst->type_id()), id); RemapStorageClass(parser_impl_.ConvertType(def_inst->type_id()), id);
AddStatement(create<ast::VariableDeclStatement>( AddStatement(create<ast::VariableDeclStatement>(
Source{}, parser_impl_.MakeVariable(id, ast::StorageClass::kFunction, Source{},
ast_type, false, nullptr, parser_impl_.MakeVariable(id, ast::StorageClass::kFunction, ast_type,
ast::VariableDecorationList{}))); false, nullptr, ast::DecorationList{})));
// Save this as an already-named value. // Save this as an already-named value.
identifier_values_.insert(id); identifier_values_.insert(id);
} }
@ -2815,7 +2815,7 @@ bool FunctionEmitter::EmitStatementsInBasicBlock(const BlockInfo& block_info,
parser_impl_.ConvertType(def_inst->type_id()), // type parser_impl_.ConvertType(def_inst->type_id()), // type
false, // is_const false, // is_const
nullptr, // constructor nullptr, // constructor
ast::VariableDecorationList{}); // decorations ast::DecorationList{}); // decorations
AddStatement(create<ast::VariableDeclStatement>(Source{}, var)); AddStatement(create<ast::VariableDeclStatement>(Source{}, var));
} }
@ -2866,7 +2866,7 @@ bool FunctionEmitter::EmitConstDefinition(
} }
auto* ast_const = parser_impl_.MakeVariable( auto* ast_const = parser_impl_.MakeVariable(
inst.result_id(), ast::StorageClass::kNone, ast_expr.type, true, inst.result_id(), ast::StorageClass::kNone, ast_expr.type, true,
ast_expr.expr, ast::VariableDecorationList{}); ast_expr.expr, ast::DecorationList{});
if (!ast_const) { if (!ast_const) {
return false; return false;
} }
@ -4910,7 +4910,7 @@ bool FunctionEmitter::MakeVectorInsertDynamic(
auto* temp_var = create<ast::Variable>( auto* temp_var = create<ast::Variable>(
Source{}, registered_temp_name, ast::StorageClass::kFunction, ast_type, Source{}, registered_temp_name, ast::StorageClass::kFunction, ast_type,
false, src_vector.expr, ast::VariableDecorationList{}); false, src_vector.expr, ast::DecorationList{});
AddStatement(create<ast::VariableDeclStatement>(Source{}, temp_var)); AddStatement(create<ast::VariableDeclStatement>(Source{}, temp_var));
auto* lhs = create<ast::ArrayAccessorExpression>( auto* lhs = create<ast::ArrayAccessorExpression>(
@ -4956,7 +4956,7 @@ bool FunctionEmitter::MakeCompositeInsert(
auto* temp_var = create<ast::Variable>( auto* temp_var = create<ast::Variable>(
Source{}, registered_temp_name, ast::StorageClass::kFunction, ast_type, Source{}, registered_temp_name, ast::StorageClass::kFunction, ast_type,
false, src_composite.expr, ast::VariableDecorationList{}); false, src_composite.expr, ast::DecorationList{});
AddStatement(create<ast::VariableDeclStatement>(Source{}, temp_var)); AddStatement(create<ast::VariableDeclStatement>(Source{}, temp_var));
TypedExpression seed_expr{ast_type, create<ast::IdentifierExpression>( TypedExpression seed_expr{ast_type, create<ast::IdentifierExpression>(

View File

@ -849,7 +849,7 @@ class FunctionEmitter {
/// Function return type /// Function return type
type::Type* return_type; type::Type* return_type;
/// Function decorations /// Function decorations
ast::FunctionDecorationList decorations; ast::DecorationList decorations;
}; };
/// Parse the function declaration, which comprises the name, parameters, and /// Parse the function declaration, which comprises the name, parameters, and

View File

@ -377,7 +377,7 @@ std::string ParserImpl::ShowType(uint32_t type_id) {
return "SPIR-V type " + std::to_string(type_id); return "SPIR-V type " + std::to_string(type_id);
} }
ast::StructMemberDecoration* ParserImpl::ConvertMemberDecoration( ast::Decoration* ParserImpl::ConvertMemberDecoration(
uint32_t struct_type_id, uint32_t struct_type_id,
uint32_t member_index, uint32_t member_index,
const Decoration& decoration) { const Decoration& decoration) {
@ -729,7 +729,7 @@ type::Type* ParserImpl::ConvertType(
if (ast_elem_ty == nullptr) { if (ast_elem_ty == nullptr) {
return nullptr; return nullptr;
} }
ast::ArrayDecorationList decorations; ast::DecorationList decorations;
if (!ParseArrayDecorations(rtarr_ty, &decorations)) { if (!ParseArrayDecorations(rtarr_ty, &decorations)) {
return nullptr; return nullptr;
} }
@ -770,7 +770,7 @@ type::Type* ParserImpl::ConvertType(
<< num_elem; << num_elem;
return nullptr; return nullptr;
} }
ast::ArrayDecorationList decorations; ast::DecorationList decorations;
if (!ParseArrayDecorations(arr_ty, &decorations)) { if (!ParseArrayDecorations(arr_ty, &decorations)) {
return nullptr; return nullptr;
} }
@ -784,7 +784,7 @@ type::Type* ParserImpl::ConvertType(
bool ParserImpl::ParseArrayDecorations( bool ParserImpl::ParseArrayDecorations(
const spvtools::opt::analysis::Type* spv_type, const spvtools::opt::analysis::Type* spv_type,
ast::ArrayDecorationList* decorations) { ast::DecorationList* decorations) {
bool has_array_stride = false; bool has_array_stride = false;
const auto type_id = type_mgr_->GetId(spv_type); const auto type_id = type_mgr_->GetId(spv_type);
for (auto& decoration : this->GetDecorationsFor(type_id)) { for (auto& decoration : this->GetDecorationsFor(type_id)) {
@ -816,7 +816,7 @@ type::Type* ParserImpl::ConvertType(
const spvtools::opt::analysis::Struct* struct_ty) { const spvtools::opt::analysis::Struct* struct_ty) {
// Compute the struct decoration. // Compute the struct decoration.
auto struct_decorations = this->GetDecorationsFor(type_id); auto struct_decorations = this->GetDecorationsFor(type_id);
ast::StructDecorationList ast_struct_decorations; ast::DecorationList ast_struct_decorations;
if (struct_decorations.size() == 1) { if (struct_decorations.size() == 1) {
const auto decoration = struct_decorations[0][0]; const auto decoration = struct_decorations[0][0];
if (decoration == SpvDecorationBlock) { if (decoration == SpvDecorationBlock) {
@ -849,7 +849,7 @@ type::Type* ParserImpl::ConvertType(
// Already emitted diagnostics. // Already emitted diagnostics.
return nullptr; return nullptr;
} }
ast::StructMemberDecorationList ast_member_decorations; ast::DecorationList ast_member_decorations;
bool is_non_writable = false; bool is_non_writable = false;
for (auto& decoration : GetDecorationsForMember(type_id, member_index)) { for (auto& decoration : GetDecorationsForMember(type_id, member_index)) {
if (decoration.empty()) { if (decoration.empty()) {
@ -1034,7 +1034,7 @@ bool ParserImpl::EmitScalarSpecConstants() {
break; break;
} }
if (ast_type && ast_expr) { if (ast_type && ast_expr) {
ast::VariableDecorationList spec_id_decos; ast::DecorationList spec_id_decos;
for (const auto& deco : GetDecorationsFor(inst.result_id())) { for (const auto& deco : GetDecorationsFor(inst.result_id())) {
if ((deco.size() == 2) && (deco[0] == SpvDecorationSpecId)) { if ((deco.size() == 2) && (deco[0] == SpvDecorationSpecId)) {
auto* cid = create<ast::ConstantIdDecoration>(Source{}, deco[1]); auto* cid = create<ast::ConstantIdDecoration>(Source{}, deco[1]);
@ -1161,7 +1161,7 @@ bool ParserImpl::EmitModuleScopeVariables() {
} }
auto* ast_var = auto* ast_var =
MakeVariable(var.result_id(), ast_storage_class, ast_store_type, false, MakeVariable(var.result_id(), ast_storage_class, ast_store_type, false,
ast_constructor, ast::VariableDecorationList{}); ast_constructor, ast::DecorationList{});
// TODO(dneto): initializers (a.k.a. constructor expression) // TODO(dneto): initializers (a.k.a. constructor expression)
if (ast_var) { if (ast_var) {
builder_.AST().AddGlobalVariable(ast_var); builder_.AST().AddGlobalVariable(ast_var);
@ -1177,7 +1177,7 @@ bool ParserImpl::EmitModuleScopeVariables() {
builtin_position_.per_vertex_var_id, builtin_position_.per_vertex_var_id,
enum_converter_.ToStorageClass(builtin_position_.storage_class), enum_converter_.ToStorageClass(builtin_position_.storage_class),
ConvertType(builtin_position_.position_member_type_id), false, nullptr, ConvertType(builtin_position_.position_member_type_id), false, nullptr,
ast::VariableDecorationList{ ast::DecorationList{
create<ast::BuiltinDecoration>(Source{}, ast::Builtin::kPosition), create<ast::BuiltinDecoration>(Source{}, ast::Builtin::kPosition),
}); });
@ -1211,13 +1211,12 @@ const spvtools::opt::analysis::IntConstant* ParserImpl::GetArraySize(
return size->AsIntConstant(); return size->AsIntConstant();
} }
ast::Variable* ParserImpl::MakeVariable( ast::Variable* ParserImpl::MakeVariable(uint32_t id,
uint32_t id, ast::StorageClass sc,
ast::StorageClass sc, type::Type* type,
type::Type* type, bool is_const,
bool is_const, ast::Expression* constructor,
ast::Expression* constructor, ast::DecorationList decorations) {
ast::VariableDecorationList decorations) {
if (type == nullptr) { if (type == nullptr) {
Fail() << "internal error: can't make ast::Variable for null type"; Fail() << "internal error: can't make ast::Variable for null type";
return nullptr; return nullptr;

View File

@ -177,10 +177,9 @@ class ParserImpl : Reader {
/// @param member_index the index of the member /// @param member_index the index of the member
/// @param decoration an encoded SPIR-V Decoration /// @param decoration an encoded SPIR-V Decoration
/// @returns the corresponding ast::StructuMemberDecoration /// @returns the corresponding ast::StructuMemberDecoration
ast::StructMemberDecoration* ConvertMemberDecoration( ast::Decoration* ConvertMemberDecoration(uint32_t struct_type_id,
uint32_t struct_type_id, uint32_t member_index,
uint32_t member_index, const Decoration& decoration);
const Decoration& decoration);
/// Returns a string for the given type. If the type ID is invalid, /// Returns a string for the given type. If the type ID is invalid,
/// then the resulting string only names the type ID. /// then the resulting string only names the type ID.
@ -298,7 +297,7 @@ class ParserImpl : Reader {
type::Type* type, type::Type* type,
bool is_const, bool is_const,
ast::Expression* constructor, ast::Expression* constructor,
ast::VariableDecorationList decorations); ast::DecorationList decorations);
/// Creates an AST expression node for a SPIR-V constant. /// Creates an AST expression node for a SPIR-V constant.
/// @param id the SPIR-V ID of the constant /// @param id the SPIR-V ID of the constant
@ -537,7 +536,7 @@ class ParserImpl : Reader {
/// @param decorations the populated decoration list /// @param decorations the populated decoration list
/// @returns true on success. /// @returns true on success.
bool ParseArrayDecorations(const spvtools::opt::analysis::Type* spv_type, bool ParseArrayDecorations(const spvtools::opt::analysis::Type* spv_type,
ast::ArrayDecorationList* decorations); ast::DecorationList* decorations);
/// Creates a new `ast::Node` owned by the ProgramBuilder. /// Creates a new `ast::Node` owned by the ProgramBuilder.
/// @param args the arguments to pass to the type constructor /// @param args the arguments to pass to the type constructor

View File

@ -384,10 +384,6 @@ Maybe<ast::Variable*> ParserImpl::global_variable_decl(
if (!decl.matched) if (!decl.matched)
return Failure::kNoMatch; return Failure::kNoMatch;
auto var_decos = cast_decorations<ast::VariableDecoration>(decos);
if (var_decos.errored)
return Failure::kErrored;
ast::Expression* constructor = nullptr; ast::Expression* constructor = nullptr;
if (match(Token::Type::kEqual)) { if (match(Token::Type::kEqual)) {
auto expr = expect_const_expr(); auto expr = expect_const_expr();
@ -403,7 +399,7 @@ Maybe<ast::Variable*> ParserImpl::global_variable_decl(
decl->type, // type decl->type, // type
false, // is_const false, // is_const
constructor, // constructor constructor, // constructor
std::move(var_decos.value)); // decorations std::move(decos)); // decorations
} }
// global_constant_decl // global_constant_decl
@ -426,10 +422,6 @@ Maybe<ast::Variable*> ParserImpl::global_constant_decl(
if (init.errored) if (init.errored)
return Failure::kErrored; return Failure::kErrored;
auto var_decos = cast_decorations<ast::VariableDecoration>(decos);
if (var_decos.errored)
return Failure::kErrored;
return create<ast::Variable>( return create<ast::Variable>(
decl->source, // source decl->source, // source
builder_.Symbols().Register(decl->name), // symbol builder_.Symbols().Register(decl->name), // symbol
@ -437,7 +429,7 @@ Maybe<ast::Variable*> ParserImpl::global_constant_decl(
decl->type, // type decl->type, // type
true, // is_const true, // is_const
init.value, // constructor init.value, // constructor
std::move(var_decos.value)); // decorations std::move(decos)); // decorations
} }
// variable_decl // variable_decl
@ -937,11 +929,7 @@ Maybe<type::Type*> ParserImpl::type_decl(ast::DecorationList& decos) {
return expect_type_decl_pointer(); return expect_type_decl_pointer();
if (match(Token::Type::kArray)) { if (match(Token::Type::kArray)) {
auto array_decos = cast_decorations<ast::ArrayDecoration>(decos); return expect_type_decl_array(std::move(decos));
if (array_decos.errored)
return Failure::kErrored;
return expect_type_decl_array(std::move(array_decos.value));
} }
if (t.IsMat2x2() || t.IsMat2x3() || t.IsMat2x4() || t.IsMat3x2() || if (t.IsMat2x2() || t.IsMat2x3() || t.IsMat2x4() || t.IsMat3x2() ||
@ -1005,7 +993,7 @@ Expect<type::Type*> ParserImpl::expect_type_decl_vector(Token t) {
} }
Expect<type::Type*> ParserImpl::expect_type_decl_array( Expect<type::Type*> ParserImpl::expect_type_decl_array(
ast::ArrayDecorationList decos) { ast::DecorationList decos) {
const char* use = "array declaration"; const char* use = "array declaration";
return expect_lt_gt_block(use, [&]() -> Expect<type::Type*> { return expect_lt_gt_block(use, [&]() -> Expect<type::Type*> {
@ -1109,14 +1097,9 @@ Maybe<type::Struct*> ParserImpl::struct_decl(ast::DecorationList& decos) {
if (body.errored) if (body.errored)
return Failure::kErrored; return Failure::kErrored;
auto struct_decos = cast_decorations<ast::StructDecoration>(decos);
if (struct_decos.errored)
return Failure::kErrored;
return create<type::Struct>( return create<type::Struct>(
builder_.Symbols().Register(name.value), builder_.Symbols().Register(name.value),
create<ast::Struct>(source, std::move(body.value), create<ast::Struct>(source, std::move(body.value), std::move(decos)));
std::move(struct_decos.value)));
} }
// struct_body_decl // struct_body_decl
@ -1161,16 +1144,12 @@ Expect<ast::StructMember*> ParserImpl::expect_struct_member(
if (decl.errored) if (decl.errored)
return Failure::kErrored; return Failure::kErrored;
auto member_decos = cast_decorations<ast::StructMemberDecoration>(decos);
if (member_decos.errored)
return Failure::kErrored;
if (!expect("struct member", Token::Type::kSemicolon)) if (!expect("struct member", Token::Type::kSemicolon))
return Failure::kErrored; return Failure::kErrored;
return create<ast::StructMember>(decl->source, return create<ast::StructMember>(decl->source,
builder_.Symbols().Register(decl->name), builder_.Symbols().Register(decl->name),
decl->type, std::move(member_decos.value)); decl->type, std::move(decos));
} }
// function_decl // function_decl
@ -1194,10 +1173,6 @@ Maybe<ast::Function*> ParserImpl::function_decl(ast::DecorationList& decos) {
bool errored = false; bool errored = false;
auto func_decos = cast_decorations<ast::FunctionDecoration>(decos);
if (func_decos.errored)
errored = true;
auto body = expect_body_stmt(); auto body = expect_body_stmt();
if (body.errored) if (body.errored)
errored = true; errored = true;
@ -1207,7 +1182,7 @@ Maybe<ast::Function*> ParserImpl::function_decl(ast::DecorationList& decos) {
return create<ast::Function>( return create<ast::Function>(
header->source, builder_.Symbols().Register(header->name), header->params, header->source, builder_.Symbols().Register(header->name), header->params,
header->return_type, body.value, func_decos.value); header->return_type, body.value, decos);
} }
// function_type_decl // function_type_decl
@ -1289,9 +1264,6 @@ Expect<ast::VariableList> ParserImpl::expect_param_list() {
// : decoration_list* variable_ident_decl // : decoration_list* variable_ident_decl
Expect<ast::Variable*> ParserImpl::expect_param() { Expect<ast::Variable*> ParserImpl::expect_param() {
auto decos = decoration_list(); auto decos = decoration_list();
auto var_decos = cast_decorations<ast::VariableDecoration>(decos.value);
if (var_decos.errored)
return Failure::kErrored;
auto decl = expect_variable_ident_decl("parameter"); auto decl = expect_variable_ident_decl("parameter");
if (decl.errored) if (decl.errored)
@ -1300,11 +1272,11 @@ Expect<ast::Variable*> ParserImpl::expect_param() {
auto* var = auto* var =
create<ast::Variable>(decl->source, // source create<ast::Variable>(decl->source, // source
builder_.Symbols().Register(decl->name), // symbol builder_.Symbols().Register(decl->name), // symbol
ast::StorageClass::kNone, // storage_class ast::StorageClass::kNone, // storage_class
decl->type, // type decl->type, // type
true, // is_const true, // is_const
nullptr, // constructor nullptr, // constructor
std::move(var_decos.value)); // decorations std::move(decos.value)); // decorations
// Formal parameters are treated like a const declaration where the // Formal parameters are treated like a const declaration where the
// initializer value is provided by the call's argument. The key point is // initializer value is provided by the call's argument. The key point is
// that it's not updatable after initially set. This is unlike C or GLSL // that it's not updatable after initially set. This is unlike C or GLSL
@ -1566,7 +1538,7 @@ Maybe<ast::VariableDeclStatement*> ParserImpl::variable_stmt() {
decl->type, // type decl->type, // type
true, // is_const true, // is_const
constructor.value, // constructor constructor.value, // constructor
ast::VariableDecorationList{}); // decorations ast::DecorationList{}); // decorations
return create<ast::VariableDeclStatement>(decl->source, var); return create<ast::VariableDeclStatement>(decl->source, var);
} }
@ -1591,11 +1563,11 @@ Maybe<ast::VariableDeclStatement*> ParserImpl::variable_stmt() {
auto* var = auto* var =
create<ast::Variable>(decl->source, // source create<ast::Variable>(decl->source, // source
builder_.Symbols().Register(decl->name), // symbol builder_.Symbols().Register(decl->name), // symbol
decl->storage_class, // storage_class decl->storage_class, // storage_class
decl->type, // type decl->type, // type
false, // is_const false, // is_const
constructor, // constructor constructor, // constructor
ast::VariableDecorationList{}); // decorations ast::DecorationList{}); // decorations
return create<ast::VariableDeclStatement>(var->source(), var); return create<ast::VariableDeclStatement>(var->source(), var);
} }
@ -2835,7 +2807,7 @@ Maybe<ast::Decoration*> ParserImpl::decoration() {
if (val.errored) if (val.errored)
return Failure::kErrored; return Failure::kErrored;
return create<ast::AccessDecoration>(val.source, val.value); return create<ast::AccessDecoration>(t.source(), val.value);
}); });
} }
@ -2846,7 +2818,7 @@ Maybe<ast::Decoration*> ParserImpl::decoration() {
if (val.errored) if (val.errored)
return Failure::kErrored; return Failure::kErrored;
return create<ast::LocationDecoration>(val.source, val.value); return create<ast::LocationDecoration>(t.source(), val.value);
}); });
} }
@ -2857,7 +2829,7 @@ Maybe<ast::Decoration*> ParserImpl::decoration() {
if (val.errored) if (val.errored)
return Failure::kErrored; return Failure::kErrored;
return create<ast::BindingDecoration>(val.source, val.value); return create<ast::BindingDecoration>(t.source(), val.value);
}); });
} }
@ -2868,7 +2840,7 @@ Maybe<ast::Decoration*> ParserImpl::decoration() {
if (val.errored) if (val.errored)
return Failure::kErrored; return Failure::kErrored;
return create<ast::GroupDecoration>(val.source, val.value); return create<ast::GroupDecoration>(t.source(), val.value);
}); });
} }
@ -2878,7 +2850,7 @@ Maybe<ast::Decoration*> ParserImpl::decoration() {
if (builtin.errored) if (builtin.errored)
return Failure::kErrored; return Failure::kErrored;
return create<ast::BuiltinDecoration>(builtin.source, builtin.value); return create<ast::BuiltinDecoration>(t.source(), builtin.value);
}); });
} }
@ -2917,7 +2889,7 @@ Maybe<ast::Decoration*> ParserImpl::decoration() {
if (stage.errored) if (stage.errored)
return Failure::kErrored; return Failure::kErrored;
return create<ast::StageDecoration>(stage.source, stage.value); return create<ast::StageDecoration>(t.source(), stage.value);
}); });
} }
@ -2978,29 +2950,6 @@ std::vector<T*> ParserImpl::take_decorations(ast::DecorationList& in) {
return out; return out;
} }
template <typename T>
Expect<std::vector<T*>> ParserImpl::cast_decorations(ast::DecorationList& in) {
auto out = take_decorations<T>(in);
bool ok = true;
for (auto* deco : in) {
std::stringstream msg;
msg << deco->GetKind() << " decoration type cannot be used for " << T::Kind;
add_error(deco->source(), msg.str());
ok = false;
}
// clear in so that expect_decorations_consumed() doesn't error again on the
// decorations we've already errored on.
in.clear();
if (!ok)
return Failure::kErrored;
return out;
}
bool ParserImpl::expect_decorations_consumed(const ast::DecorationList& in) { bool ParserImpl::expect_decorations_consumed(const ast::DecorationList& in) {
if (in.empty()) { if (in.empty()) {
return true; return true;

View File

@ -772,18 +772,13 @@ class ParserImpl {
template <typename T> template <typename T>
std::vector<T*> take_decorations(ast::DecorationList& list); std::vector<T*> take_decorations(ast::DecorationList& list);
/// Downcasts all the decorations in `list` to the type `T`, raising a parser
/// error if any of the decorations aren't of the type `T`.
template <typename T>
Expect<std::vector<T*>> cast_decorations(ast::DecorationList& list);
/// Reports an error if the decoration list `list` is not empty. /// Reports an error if the decoration list `list` is not empty.
/// Used to ensure that all decorations are consumed. /// Used to ensure that all decorations are consumed.
bool expect_decorations_consumed(const ast::DecorationList& list); bool expect_decorations_consumed(const ast::DecorationList& list);
Expect<type::Type*> expect_type_decl_pointer(); Expect<type::Type*> expect_type_decl_pointer();
Expect<type::Type*> expect_type_decl_vector(Token t); Expect<type::Type*> expect_type_decl_vector(Token t);
Expect<type::Type*> expect_type_decl_array(ast::ArrayDecorationList decos); Expect<type::Type*> expect_type_decl_array(ast::DecorationList decos);
Expect<type::Type*> expect_type_decl_matrix(Token t); Expect<type::Type*> expect_type_decl_matrix(Token t);
Expect<type::Type*> expect_type(const std::string& use); Expect<type::Type*> expect_type(const std::string& use);

View File

@ -119,7 +119,7 @@ struct S {
a : i32; a : i32;
blah blah blah; blah blah blah;
b : i32; b : i32;
[[block]] x : i32; [[]] x : i32;
c : i32; c : i32;
} }
)", )",
@ -131,10 +131,9 @@ struct S {
" blah blah blah;\n" " blah blah blah;\n"
" ^^^^\n" " ^^^^\n"
"\n" "\n"
"test.wgsl:7:7 error: struct decoration type cannot be used for " "test.wgsl:7:7 error: empty decoration list\n"
"struct member\n" " [[]] x : i32;\n"
" [[block]] x : i32;\n" " ^^\n");
" ^^^^^\n");
} }
// Check that the forward scan in resynchronize() stop at nested sync points. // Check that the forward scan in resynchronize() stop at nested sync points.

View File

@ -20,7 +20,7 @@ namespace reader {
namespace wgsl { namespace wgsl {
namespace { namespace {
TEST_F(ParserImplTest, FunctionDecorationList_Parses) { TEST_F(ParserImplTest, DecorationList_Parses) {
auto p = parser("[[workgroup_size(2), workgroup_size(3, 4, 5)]]"); auto p = parser("[[workgroup_size(2), workgroup_size(3, 4, 5)]]");
auto decos = p->decoration_list(); auto decos = p->decoration_list();
EXPECT_FALSE(p->has_error()) << p->error(); EXPECT_FALSE(p->has_error()) << p->error();
@ -28,8 +28,8 @@ TEST_F(ParserImplTest, FunctionDecorationList_Parses) {
EXPECT_TRUE(decos.matched); EXPECT_TRUE(decos.matched);
ASSERT_EQ(decos.value.size(), 2u); ASSERT_EQ(decos.value.size(), 2u);
auto* deco_0 = decos.value[0]->As<ast::FunctionDecoration>(); auto* deco_0 = decos.value[0]->As<ast::Decoration>();
auto* deco_1 = decos.value[1]->As<ast::FunctionDecoration>(); auto* deco_1 = decos.value[1]->As<ast::Decoration>();
ASSERT_NE(deco_0, nullptr); ASSERT_NE(deco_0, nullptr);
ASSERT_NE(deco_1, nullptr); ASSERT_NE(deco_1, nullptr);
@ -47,7 +47,7 @@ TEST_F(ParserImplTest, FunctionDecorationList_Parses) {
EXPECT_EQ(z, 5u); EXPECT_EQ(z, 5u);
} }
TEST_F(ParserImplTest, FunctionDecorationList_Empty) { TEST_F(ParserImplTest, DecorationList_Empty) {
auto p = parser("[[]]"); auto p = parser("[[]]");
auto decos = p->decoration_list(); auto decos = p->decoration_list();
EXPECT_TRUE(p->has_error()); EXPECT_TRUE(p->has_error());
@ -56,7 +56,7 @@ TEST_F(ParserImplTest, FunctionDecorationList_Empty) {
EXPECT_EQ(p->error(), "1:3: empty decoration list"); EXPECT_EQ(p->error(), "1:3: empty decoration list");
} }
TEST_F(ParserImplTest, FunctionDecorationList_Invalid) { TEST_F(ParserImplTest, DecorationList_Invalid) {
auto p = parser("[[invalid]]"); auto p = parser("[[invalid]]");
auto decos = p->decoration_list(); auto decos = p->decoration_list();
EXPECT_TRUE(p->has_error()); EXPECT_TRUE(p->has_error());
@ -66,7 +66,7 @@ TEST_F(ParserImplTest, FunctionDecorationList_Invalid) {
EXPECT_EQ(p->error(), "1:3: expected decoration"); EXPECT_EQ(p->error(), "1:3: expected decoration");
} }
TEST_F(ParserImplTest, FunctionDecorationList_ExtraComma) { TEST_F(ParserImplTest, DecorationList_ExtraComma) {
auto p = parser("[[workgroup_size(2), ]]"); auto p = parser("[[workgroup_size(2), ]]");
auto decos = p->decoration_list(); auto decos = p->decoration_list();
EXPECT_TRUE(p->has_error()); EXPECT_TRUE(p->has_error());
@ -75,7 +75,7 @@ TEST_F(ParserImplTest, FunctionDecorationList_ExtraComma) {
EXPECT_EQ(p->error(), "1:22: expected decoration"); EXPECT_EQ(p->error(), "1:22: expected decoration");
} }
TEST_F(ParserImplTest, FunctionDecorationList_MissingComma) { TEST_F(ParserImplTest, DecorationList_MissingComma) {
auto p = parser("[[workgroup_size(2) workgroup_size(2)]]"); auto p = parser("[[workgroup_size(2) workgroup_size(2)]]");
auto decos = p->decoration_list(); auto decos = p->decoration_list();
EXPECT_TRUE(p->has_error()); EXPECT_TRUE(p->has_error());
@ -84,7 +84,7 @@ TEST_F(ParserImplTest, FunctionDecorationList_MissingComma) {
EXPECT_EQ(p->error(), "1:21: expected ',' for decoration list"); EXPECT_EQ(p->error(), "1:21: expected ',' for decoration list");
} }
TEST_F(ParserImplTest, FunctionDecorationList_BadDecoration) { TEST_F(ParserImplTest, DecorationList_BadDecoration) {
auto p = parser("[[workgroup_size()]]"); auto p = parser("[[workgroup_size()]]");
auto decos = p->decoration_list(); auto decos = p->decoration_list();
EXPECT_TRUE(p->has_error()); EXPECT_TRUE(p->has_error());
@ -95,7 +95,7 @@ TEST_F(ParserImplTest, FunctionDecorationList_BadDecoration) {
"1:18: expected signed integer literal for workgroup_size x parameter"); "1:18: expected signed integer literal for workgroup_size x parameter");
} }
TEST_F(ParserImplTest, FunctionDecorationList_MissingRightAttr) { TEST_F(ParserImplTest, DecorationList_MissingRightAttr) {
auto p = parser("[[workgroup_size(2), workgroup_size(3, 4, 5)"); auto p = parser("[[workgroup_size(2), workgroup_size(3, 4, 5)");
auto decos = p->decoration_list(); auto decos = p->decoration_list();
EXPECT_TRUE(p->has_error()); EXPECT_TRUE(p->has_error());

View File

@ -21,14 +21,14 @@ namespace reader {
namespace wgsl { namespace wgsl {
namespace { namespace {
TEST_F(ParserImplTest, FunctionDecoration_Workgroup) { TEST_F(ParserImplTest, Decoration_Workgroup) {
auto p = parser("workgroup_size(4)"); auto p = parser("workgroup_size(4)");
auto deco = p->decoration(); auto deco = p->decoration();
EXPECT_TRUE(deco.matched); EXPECT_TRUE(deco.matched);
EXPECT_FALSE(deco.errored); EXPECT_FALSE(deco.errored);
ASSERT_NE(deco.value, nullptr) << p->error(); ASSERT_NE(deco.value, nullptr) << p->error();
ASSERT_FALSE(p->has_error()); ASSERT_FALSE(p->has_error());
auto* func_deco = deco.value->As<ast::FunctionDecoration>(); auto* func_deco = deco.value->As<ast::Decoration>();
ASSERT_NE(func_deco, nullptr); ASSERT_NE(func_deco, nullptr);
ASSERT_TRUE(func_deco->Is<ast::WorkgroupDecoration>()); ASSERT_TRUE(func_deco->Is<ast::WorkgroupDecoration>());
@ -41,14 +41,14 @@ TEST_F(ParserImplTest, FunctionDecoration_Workgroup) {
EXPECT_EQ(z, 1u); EXPECT_EQ(z, 1u);
} }
TEST_F(ParserImplTest, FunctionDecoration_Workgroup_2Param) { TEST_F(ParserImplTest, Decoration_Workgroup_2Param) {
auto p = parser("workgroup_size(4, 5)"); auto p = parser("workgroup_size(4, 5)");
auto deco = p->decoration(); auto deco = p->decoration();
EXPECT_TRUE(deco.matched); EXPECT_TRUE(deco.matched);
EXPECT_FALSE(deco.errored); EXPECT_FALSE(deco.errored);
ASSERT_NE(deco.value, nullptr) << p->error(); ASSERT_NE(deco.value, nullptr) << p->error();
ASSERT_FALSE(p->has_error()); ASSERT_FALSE(p->has_error());
auto* func_deco = deco.value->As<ast::FunctionDecoration>(); auto* func_deco = deco.value->As<ast::Decoration>();
ASSERT_NE(func_deco, nullptr) << p->error(); ASSERT_NE(func_deco, nullptr) << p->error();
ASSERT_TRUE(func_deco->Is<ast::WorkgroupDecoration>()); ASSERT_TRUE(func_deco->Is<ast::WorkgroupDecoration>());
@ -61,14 +61,14 @@ TEST_F(ParserImplTest, FunctionDecoration_Workgroup_2Param) {
EXPECT_EQ(z, 1u); EXPECT_EQ(z, 1u);
} }
TEST_F(ParserImplTest, FunctionDecoration_Workgroup_3Param) { TEST_F(ParserImplTest, Decoration_Workgroup_3Param) {
auto p = parser("workgroup_size(4, 5, 6)"); auto p = parser("workgroup_size(4, 5, 6)");
auto deco = p->decoration(); auto deco = p->decoration();
EXPECT_TRUE(deco.matched); EXPECT_TRUE(deco.matched);
EXPECT_FALSE(deco.errored); EXPECT_FALSE(deco.errored);
ASSERT_NE(deco.value, nullptr) << p->error(); ASSERT_NE(deco.value, nullptr) << p->error();
ASSERT_FALSE(p->has_error()); ASSERT_FALSE(p->has_error());
auto* func_deco = deco.value->As<ast::FunctionDecoration>(); auto* func_deco = deco.value->As<ast::Decoration>();
ASSERT_NE(func_deco, nullptr); ASSERT_NE(func_deco, nullptr);
ASSERT_TRUE(func_deco->Is<ast::WorkgroupDecoration>()); ASSERT_TRUE(func_deco->Is<ast::WorkgroupDecoration>());
@ -81,7 +81,7 @@ TEST_F(ParserImplTest, FunctionDecoration_Workgroup_3Param) {
EXPECT_EQ(z, 6u); EXPECT_EQ(z, 6u);
} }
TEST_F(ParserImplTest, FunctionDecoration_Workgroup_TooManyValues) { TEST_F(ParserImplTest, Decoration_Workgroup_TooManyValues) {
auto p = parser("workgroup_size(1, 2, 3, 4)"); auto p = parser("workgroup_size(1, 2, 3, 4)");
auto deco = p->decoration(); auto deco = p->decoration();
EXPECT_FALSE(deco.matched); EXPECT_FALSE(deco.matched);
@ -91,7 +91,7 @@ TEST_F(ParserImplTest, FunctionDecoration_Workgroup_TooManyValues) {
EXPECT_EQ(p->error(), "1:23: expected ')' for workgroup_size decoration"); EXPECT_EQ(p->error(), "1:23: expected ')' for workgroup_size decoration");
} }
TEST_F(ParserImplTest, FunctionDecoration_Workgroup_Invalid_X_Value) { TEST_F(ParserImplTest, Decoration_Workgroup_Invalid_X_Value) {
auto p = parser("workgroup_size(-2, 5, 6)"); auto p = parser("workgroup_size(-2, 5, 6)");
auto deco = p->decoration(); auto deco = p->decoration();
EXPECT_FALSE(deco.matched); EXPECT_FALSE(deco.matched);
@ -102,7 +102,7 @@ TEST_F(ParserImplTest, FunctionDecoration_Workgroup_Invalid_X_Value) {
"1:16: workgroup_size x parameter must be greater than 0"); "1:16: workgroup_size x parameter must be greater than 0");
} }
TEST_F(ParserImplTest, FunctionDecoration_Workgroup_Invalid_Y_Value) { TEST_F(ParserImplTest, Decoration_Workgroup_Invalid_Y_Value) {
auto p = parser("workgroup_size(4, 0, 6)"); auto p = parser("workgroup_size(4, 0, 6)");
auto deco = p->decoration(); auto deco = p->decoration();
EXPECT_FALSE(deco.matched); EXPECT_FALSE(deco.matched);
@ -113,7 +113,7 @@ TEST_F(ParserImplTest, FunctionDecoration_Workgroup_Invalid_Y_Value) {
"1:19: workgroup_size y parameter must be greater than 0"); "1:19: workgroup_size y parameter must be greater than 0");
} }
TEST_F(ParserImplTest, FunctionDecoration_Workgroup_Invalid_Z_Value) { TEST_F(ParserImplTest, Decoration_Workgroup_Invalid_Z_Value) {
auto p = parser("workgroup_size(4, 5, -3)"); auto p = parser("workgroup_size(4, 5, -3)");
auto deco = p->decoration(); auto deco = p->decoration();
EXPECT_FALSE(deco.matched); EXPECT_FALSE(deco.matched);
@ -124,7 +124,7 @@ TEST_F(ParserImplTest, FunctionDecoration_Workgroup_Invalid_Z_Value) {
"1:22: workgroup_size z parameter must be greater than 0"); "1:22: workgroup_size z parameter must be greater than 0");
} }
TEST_F(ParserImplTest, FunctionDecoration_Workgroup_MissingLeftParam) { TEST_F(ParserImplTest, Decoration_Workgroup_MissingLeftParam) {
auto p = parser("workgroup_size 4, 5, 6)"); auto p = parser("workgroup_size 4, 5, 6)");
auto deco = p->decoration(); auto deco = p->decoration();
EXPECT_FALSE(deco.matched); EXPECT_FALSE(deco.matched);
@ -134,7 +134,7 @@ TEST_F(ParserImplTest, FunctionDecoration_Workgroup_MissingLeftParam) {
EXPECT_EQ(p->error(), "1:16: expected '(' for workgroup_size decoration"); EXPECT_EQ(p->error(), "1:16: expected '(' for workgroup_size decoration");
} }
TEST_F(ParserImplTest, FunctionDecoration_Workgroup_MissingRightParam) { TEST_F(ParserImplTest, Decoration_Workgroup_MissingRightParam) {
auto p = parser("workgroup_size(4, 5, 6"); auto p = parser("workgroup_size(4, 5, 6");
auto deco = p->decoration(); auto deco = p->decoration();
EXPECT_FALSE(deco.matched); EXPECT_FALSE(deco.matched);
@ -144,7 +144,7 @@ TEST_F(ParserImplTest, FunctionDecoration_Workgroup_MissingRightParam) {
EXPECT_EQ(p->error(), "1:23: expected ')' for workgroup_size decoration"); EXPECT_EQ(p->error(), "1:23: expected ')' for workgroup_size decoration");
} }
TEST_F(ParserImplTest, FunctionDecoration_Workgroup_MissingValues) { TEST_F(ParserImplTest, Decoration_Workgroup_MissingValues) {
auto p = parser("workgroup_size()"); auto p = parser("workgroup_size()");
auto deco = p->decoration(); auto deco = p->decoration();
EXPECT_FALSE(deco.matched); EXPECT_FALSE(deco.matched);
@ -156,7 +156,7 @@ TEST_F(ParserImplTest, FunctionDecoration_Workgroup_MissingValues) {
"1:16: expected signed integer literal for workgroup_size x parameter"); "1:16: expected signed integer literal for workgroup_size x parameter");
} }
TEST_F(ParserImplTest, FunctionDecoration_Workgroup_Missing_X_Value) { TEST_F(ParserImplTest, Decoration_Workgroup_Missing_X_Value) {
auto p = parser("workgroup_size(, 2, 3)"); auto p = parser("workgroup_size(, 2, 3)");
auto deco = p->decoration(); auto deco = p->decoration();
EXPECT_FALSE(deco.matched); EXPECT_FALSE(deco.matched);
@ -168,7 +168,7 @@ TEST_F(ParserImplTest, FunctionDecoration_Workgroup_Missing_X_Value) {
"1:16: expected signed integer literal for workgroup_size x parameter"); "1:16: expected signed integer literal for workgroup_size x parameter");
} }
TEST_F(ParserImplTest, FunctionDecoration_Workgroup_Missing_Y_Comma) { TEST_F(ParserImplTest, Decoration_Workgroup_Missing_Y_Comma) {
auto p = parser("workgroup_size(1 2, 3)"); auto p = parser("workgroup_size(1 2, 3)");
auto deco = p->decoration(); auto deco = p->decoration();
EXPECT_FALSE(deco.matched); EXPECT_FALSE(deco.matched);
@ -178,7 +178,7 @@ TEST_F(ParserImplTest, FunctionDecoration_Workgroup_Missing_Y_Comma) {
EXPECT_EQ(p->error(), "1:18: expected ')' for workgroup_size decoration"); EXPECT_EQ(p->error(), "1:18: expected ')' for workgroup_size decoration");
} }
TEST_F(ParserImplTest, FunctionDecoration_Workgroup_Missing_Y_Value) { TEST_F(ParserImplTest, Decoration_Workgroup_Missing_Y_Value) {
auto p = parser("workgroup_size(1, , 3)"); auto p = parser("workgroup_size(1, , 3)");
auto deco = p->decoration(); auto deco = p->decoration();
EXPECT_FALSE(deco.matched); EXPECT_FALSE(deco.matched);
@ -190,7 +190,7 @@ TEST_F(ParserImplTest, FunctionDecoration_Workgroup_Missing_Y_Value) {
"1:19: expected signed integer literal for workgroup_size y parameter"); "1:19: expected signed integer literal for workgroup_size y parameter");
} }
TEST_F(ParserImplTest, FunctionDecoration_Workgroup_Missing_Z_Comma) { TEST_F(ParserImplTest, Decoration_Workgroup_Missing_Z_Comma) {
auto p = parser("workgroup_size(1, 2 3)"); auto p = parser("workgroup_size(1, 2 3)");
auto deco = p->decoration(); auto deco = p->decoration();
EXPECT_FALSE(deco.matched); EXPECT_FALSE(deco.matched);
@ -200,7 +200,7 @@ TEST_F(ParserImplTest, FunctionDecoration_Workgroup_Missing_Z_Comma) {
EXPECT_EQ(p->error(), "1:21: expected ')' for workgroup_size decoration"); EXPECT_EQ(p->error(), "1:21: expected ')' for workgroup_size decoration");
} }
TEST_F(ParserImplTest, FunctionDecoration_Workgroup_Missing_Z_Value) { TEST_F(ParserImplTest, Decoration_Workgroup_Missing_Z_Value) {
auto p = parser("workgroup_size(1, 2, )"); auto p = parser("workgroup_size(1, 2, )");
auto deco = p->decoration(); auto deco = p->decoration();
EXPECT_FALSE(deco.matched); EXPECT_FALSE(deco.matched);
@ -212,7 +212,7 @@ TEST_F(ParserImplTest, FunctionDecoration_Workgroup_Missing_Z_Value) {
"1:22: expected signed integer literal for workgroup_size z parameter"); "1:22: expected signed integer literal for workgroup_size z parameter");
} }
TEST_F(ParserImplTest, FunctionDecoration_Workgroup_Missing_X_Invalid) { TEST_F(ParserImplTest, Decoration_Workgroup_Missing_X_Invalid) {
auto p = parser("workgroup_size(nan)"); auto p = parser("workgroup_size(nan)");
auto deco = p->decoration(); auto deco = p->decoration();
EXPECT_FALSE(deco.matched); EXPECT_FALSE(deco.matched);
@ -224,7 +224,7 @@ TEST_F(ParserImplTest, FunctionDecoration_Workgroup_Missing_X_Invalid) {
"1:16: expected signed integer literal for workgroup_size x parameter"); "1:16: expected signed integer literal for workgroup_size x parameter");
} }
TEST_F(ParserImplTest, FunctionDecoration_Workgroup_Missing_Y_Invalid) { TEST_F(ParserImplTest, Decoration_Workgroup_Missing_Y_Invalid) {
auto p = parser("workgroup_size(2, nan)"); auto p = parser("workgroup_size(2, nan)");
auto deco = p->decoration(); auto deco = p->decoration();
EXPECT_FALSE(deco.matched); EXPECT_FALSE(deco.matched);
@ -236,7 +236,7 @@ TEST_F(ParserImplTest, FunctionDecoration_Workgroup_Missing_Y_Invalid) {
"1:19: expected signed integer literal for workgroup_size y parameter"); "1:19: expected signed integer literal for workgroup_size y parameter");
} }
TEST_F(ParserImplTest, FunctionDecoration_Workgroup_Missing_Z_Invalid) { TEST_F(ParserImplTest, Decoration_Workgroup_Missing_Z_Invalid) {
auto p = parser("workgroup_size(2, 3, nan)"); auto p = parser("workgroup_size(2, 3, nan)");
auto deco = p->decoration(); auto deco = p->decoration();
EXPECT_FALSE(deco.matched); EXPECT_FALSE(deco.matched);
@ -248,21 +248,21 @@ TEST_F(ParserImplTest, FunctionDecoration_Workgroup_Missing_Z_Invalid) {
"1:22: expected signed integer literal for workgroup_size z parameter"); "1:22: expected signed integer literal for workgroup_size z parameter");
} }
TEST_F(ParserImplTest, FunctionDecoration_Stage) { TEST_F(ParserImplTest, Decoration_Stage) {
auto p = parser("stage(compute)"); auto p = parser("stage(compute)");
auto deco = p->decoration(); auto deco = p->decoration();
EXPECT_TRUE(deco.matched); EXPECT_TRUE(deco.matched);
EXPECT_FALSE(deco.errored); EXPECT_FALSE(deco.errored);
ASSERT_NE(deco.value, nullptr) << p->error(); ASSERT_NE(deco.value, nullptr) << p->error();
ASSERT_FALSE(p->has_error()); ASSERT_FALSE(p->has_error());
auto* func_deco = deco.value->As<ast::FunctionDecoration>(); auto* func_deco = deco.value->As<ast::Decoration>();
ASSERT_NE(func_deco, nullptr); ASSERT_NE(func_deco, nullptr);
ASSERT_TRUE(func_deco->Is<ast::StageDecoration>()); ASSERT_TRUE(func_deco->Is<ast::StageDecoration>());
EXPECT_EQ(func_deco->As<ast::StageDecoration>()->value(), EXPECT_EQ(func_deco->As<ast::StageDecoration>()->value(),
ast::PipelineStage::kCompute); ast::PipelineStage::kCompute);
} }
TEST_F(ParserImplTest, FunctionDecoration_Stage_MissingValue) { TEST_F(ParserImplTest, Decoration_Stage_MissingValue) {
auto p = parser("stage()"); auto p = parser("stage()");
auto deco = p->decoration(); auto deco = p->decoration();
EXPECT_FALSE(deco.matched); EXPECT_FALSE(deco.matched);
@ -272,7 +272,7 @@ TEST_F(ParserImplTest, FunctionDecoration_Stage_MissingValue) {
EXPECT_EQ(p->error(), "1:7: invalid value for stage decoration"); EXPECT_EQ(p->error(), "1:7: invalid value for stage decoration");
} }
TEST_F(ParserImplTest, FunctionDecoration_Stage_MissingInvalid) { TEST_F(ParserImplTest, Decoration_Stage_MissingInvalid) {
auto p = parser("stage(nan)"); auto p = parser("stage(nan)");
auto deco = p->decoration(); auto deco = p->decoration();
EXPECT_FALSE(deco.matched); EXPECT_FALSE(deco.matched);
@ -282,7 +282,7 @@ TEST_F(ParserImplTest, FunctionDecoration_Stage_MissingInvalid) {
EXPECT_EQ(p->error(), "1:7: invalid value for stage decoration"); EXPECT_EQ(p->error(), "1:7: invalid value for stage decoration");
} }
TEST_F(ParserImplTest, FunctionDecoration_Stage_MissingLeftParen) { TEST_F(ParserImplTest, Decoration_Stage_MissingLeftParen) {
auto p = parser("stage compute)"); auto p = parser("stage compute)");
auto deco = p->decoration(); auto deco = p->decoration();
EXPECT_FALSE(deco.matched); EXPECT_FALSE(deco.matched);
@ -292,7 +292,7 @@ TEST_F(ParserImplTest, FunctionDecoration_Stage_MissingLeftParen) {
EXPECT_EQ(p->error(), "1:7: expected '(' for stage decoration"); EXPECT_EQ(p->error(), "1:7: expected '(' for stage decoration");
} }
TEST_F(ParserImplTest, FunctionDecoration_Stage_MissingRightParen) { TEST_F(ParserImplTest, Decoration_Stage_MissingRightParen) {
auto p = parser("stage(compute"); auto p = parser("stage(compute");
auto deco = p->decoration(); auto deco = p->decoration();
EXPECT_FALSE(deco.matched); EXPECT_FALSE(deco.matched);

View File

@ -161,7 +161,7 @@ TEST_F(ParserImplTest, StructDecl_InvalidStructBody) {
EXPECT_EQ(p->error(), "1:16: unknown constructed type 'B'"); EXPECT_EQ(p->error(), "1:16: unknown constructed type 'B'");
} }
TEST_F(ParserImplTest, StructDecl_InvalidStructDecorationDecl) { TEST_F(ParserImplTest, StructDecl_InvalidDecorationDecl) {
auto p = parser("[[block struct S { a : i32; }"); auto p = parser("[[block struct S { a : i32; }");
auto decos = p->decoration_list(); auto decos = p->decoration_list();
EXPECT_TRUE(decos.errored); EXPECT_TRUE(decos.errored);

View File

@ -20,18 +20,18 @@ namespace reader {
namespace wgsl { namespace wgsl {
namespace { namespace {
TEST_F(ParserImplTest, StructDecorationDecl_Parses) { TEST_F(ParserImplTest, DecorationDecl_Parses) {
auto p = parser("[[block]]"); auto p = parser("[[block]]");
auto decos = p->decoration_list(); auto decos = p->decoration_list();
EXPECT_FALSE(p->has_error()); EXPECT_FALSE(p->has_error());
EXPECT_FALSE(decos.errored); EXPECT_FALSE(decos.errored);
EXPECT_TRUE(decos.matched); EXPECT_TRUE(decos.matched);
ASSERT_EQ(decos.value.size(), 1u); ASSERT_EQ(decos.value.size(), 1u);
auto* struct_deco = decos.value[0]->As<ast::StructDecoration>(); auto* struct_deco = decos.value[0]->As<ast::Decoration>();
EXPECT_TRUE(struct_deco->Is<ast::StructBlockDecoration>()); EXPECT_TRUE(struct_deco->Is<ast::StructBlockDecoration>());
} }
TEST_F(ParserImplTest, StructDecorationDecl_MissingAttrRight) { TEST_F(ParserImplTest, DecorationDecl_MissingAttrRight) {
auto p = parser("[[block"); auto p = parser("[[block");
auto decos = p->decoration_list(); auto decos = p->decoration_list();
EXPECT_TRUE(p->has_error()); EXPECT_TRUE(p->has_error());
@ -41,7 +41,7 @@ TEST_F(ParserImplTest, StructDecorationDecl_MissingAttrRight) {
EXPECT_EQ(p->error(), "1:8: expected ']]' for decoration list"); EXPECT_EQ(p->error(), "1:8: expected ']]' for decoration list");
} }
TEST_F(ParserImplTest, StructDecorationDecl_InvalidDecoration) { TEST_F(ParserImplTest, DecorationDecl_InvalidDecoration) {
auto p = parser("[[invalid]]"); auto p = parser("[[invalid]]");
auto decos = p->decoration_list(); auto decos = p->decoration_list();
EXPECT_TRUE(p->has_error()); EXPECT_TRUE(p->has_error());

View File

@ -20,19 +20,18 @@ namespace reader {
namespace wgsl { namespace wgsl {
namespace { namespace {
struct StructDecorationData { struct DecorationData {
const char* input; const char* input;
bool is_block; bool is_block;
}; };
inline std::ostream& operator<<(std::ostream& out, StructDecorationData data) { inline std::ostream& operator<<(std::ostream& out, DecorationData data) {
out << std::string(data.input); out << std::string(data.input);
return out; return out;
} }
class StructDecorationTest class DecorationTest : public ParserImplTestWithParam<DecorationData> {};
: public ParserImplTestWithParam<StructDecorationData> {};
TEST_P(StructDecorationTest, Parses) { TEST_P(DecorationTest, Parses) {
auto params = GetParam(); auto params = GetParam();
auto p = parser(params.input); auto p = parser(params.input);
@ -41,15 +40,15 @@ TEST_P(StructDecorationTest, Parses) {
EXPECT_TRUE(deco.matched); EXPECT_TRUE(deco.matched);
EXPECT_FALSE(deco.errored); EXPECT_FALSE(deco.errored);
ASSERT_NE(deco.value, nullptr); ASSERT_NE(deco.value, nullptr);
auto* struct_deco = deco.value->As<ast::StructDecoration>(); auto* struct_deco = deco.value->As<ast::Decoration>();
ASSERT_NE(struct_deco, nullptr); ASSERT_NE(struct_deco, nullptr);
EXPECT_EQ(struct_deco->Is<ast::StructBlockDecoration>(), params.is_block); EXPECT_EQ(struct_deco->Is<ast::StructBlockDecoration>(), params.is_block);
} }
INSTANTIATE_TEST_SUITE_P(ParserImplTest, INSTANTIATE_TEST_SUITE_P(ParserImplTest,
StructDecorationTest, DecorationTest,
testing::Values(StructDecorationData{"block", true})); testing::Values(DecorationData{"block", true}));
TEST_F(ParserImplTest, StructDecoration_NoMatch) { TEST_F(ParserImplTest, Decoration_NoMatch) {
auto p = parser("not-a-stage"); auto p = parser("not-a-stage");
auto deco = p->decoration(); auto deco = p->decoration();
EXPECT_FALSE(deco.matched); EXPECT_FALSE(deco.matched);

View File

@ -19,7 +19,7 @@ namespace reader {
namespace wgsl { namespace wgsl {
namespace { namespace {
TEST_F(ParserImplTest, StructMemberDecorationDecl_EmptyStr) { TEST_F(ParserImplTest, DecorationDecl_EmptyStr) {
auto p = parser(""); auto p = parser("");
auto decos = p->decoration_list(); auto decos = p->decoration_list();
EXPECT_FALSE(p->has_error()); EXPECT_FALSE(p->has_error());
@ -28,7 +28,7 @@ TEST_F(ParserImplTest, StructMemberDecorationDecl_EmptyStr) {
EXPECT_EQ(decos.value.size(), 0u); EXPECT_EQ(decos.value.size(), 0u);
} }
TEST_F(ParserImplTest, StructMemberDecorationDecl_EmptyBlock) { TEST_F(ParserImplTest, DecorationDecl_EmptyBlock) {
auto p = parser("[[]]"); auto p = parser("[[]]");
auto decos = p->decoration_list(); auto decos = p->decoration_list();
EXPECT_TRUE(p->has_error()); EXPECT_TRUE(p->has_error());
@ -38,19 +38,19 @@ TEST_F(ParserImplTest, StructMemberDecorationDecl_EmptyBlock) {
EXPECT_EQ(p->error(), "1:3: empty decoration list"); EXPECT_EQ(p->error(), "1:3: empty decoration list");
} }
TEST_F(ParserImplTest, StructMemberDecorationDecl_Single) { TEST_F(ParserImplTest, DecorationDecl_Single) {
auto p = parser("[[offset(4)]]"); auto p = parser("[[offset(4)]]");
auto decos = p->decoration_list(); auto decos = p->decoration_list();
EXPECT_FALSE(p->has_error()); EXPECT_FALSE(p->has_error());
EXPECT_FALSE(decos.errored); EXPECT_FALSE(decos.errored);
EXPECT_TRUE(decos.matched); EXPECT_TRUE(decos.matched);
ASSERT_EQ(decos.value.size(), 1u); ASSERT_EQ(decos.value.size(), 1u);
auto* deco = decos.value[0]->As<ast::StructMemberDecoration>(); auto* deco = decos.value[0]->As<ast::Decoration>();
ASSERT_NE(deco, nullptr); ASSERT_NE(deco, nullptr);
EXPECT_TRUE(deco->Is<ast::StructMemberOffsetDecoration>()); EXPECT_TRUE(deco->Is<ast::StructMemberOffsetDecoration>());
} }
TEST_F(ParserImplTest, StructMemberDecorationDecl_InvalidDecoration) { TEST_F(ParserImplTest, DecorationDecl_InvalidDecoration) {
auto p = parser("[[offset(nan)]]"); auto p = parser("[[offset(nan)]]");
auto decos = p->decoration_list(); auto decos = p->decoration_list();
EXPECT_TRUE(p->has_error()) << p->error(); EXPECT_TRUE(p->has_error()) << p->error();
@ -60,7 +60,7 @@ TEST_F(ParserImplTest, StructMemberDecorationDecl_InvalidDecoration) {
"1:10: expected signed integer literal for offset decoration"); "1:10: expected signed integer literal for offset decoration");
} }
TEST_F(ParserImplTest, StructMemberDecorationDecl_MissingClose) { TEST_F(ParserImplTest, DecorationDecl_MissingClose) {
auto p = parser("[[offset(4)"); auto p = parser("[[offset(4)");
auto decos = p->decoration_list(); auto decos = p->decoration_list();
EXPECT_TRUE(p->has_error()) << p->error(); EXPECT_TRUE(p->has_error()) << p->error();

View File

@ -19,7 +19,7 @@ namespace reader {
namespace wgsl { namespace wgsl {
namespace { namespace {
TEST_F(ParserImplTest, StructMemberDecoration_Offset) { TEST_F(ParserImplTest, Decoration_Offset) {
auto p = parser("offset(4)"); auto p = parser("offset(4)");
auto deco = p->decoration(); auto deco = p->decoration();
EXPECT_TRUE(deco.matched); EXPECT_TRUE(deco.matched);
@ -27,7 +27,7 @@ TEST_F(ParserImplTest, StructMemberDecoration_Offset) {
ASSERT_NE(deco.value, nullptr); ASSERT_NE(deco.value, nullptr);
ASSERT_FALSE(p->has_error()); ASSERT_FALSE(p->has_error());
auto* member_deco = deco.value->As<ast::StructMemberDecoration>(); auto* member_deco = deco.value->As<ast::Decoration>();
ASSERT_NE(member_deco, nullptr); ASSERT_NE(member_deco, nullptr);
ASSERT_TRUE(member_deco->Is<ast::StructMemberOffsetDecoration>()); ASSERT_TRUE(member_deco->Is<ast::StructMemberOffsetDecoration>());
@ -35,7 +35,7 @@ TEST_F(ParserImplTest, StructMemberDecoration_Offset) {
EXPECT_EQ(o->offset(), 4u); EXPECT_EQ(o->offset(), 4u);
} }
TEST_F(ParserImplTest, StructMemberDecoration_Offset_MissingLeftParen) { TEST_F(ParserImplTest, Decoration_Offset_MissingLeftParen) {
auto p = parser("offset 4)"); auto p = parser("offset 4)");
auto deco = p->decoration(); auto deco = p->decoration();
EXPECT_FALSE(deco.matched); EXPECT_FALSE(deco.matched);
@ -45,7 +45,7 @@ TEST_F(ParserImplTest, StructMemberDecoration_Offset_MissingLeftParen) {
EXPECT_EQ(p->error(), "1:8: expected '(' for offset decoration"); EXPECT_EQ(p->error(), "1:8: expected '(' for offset decoration");
} }
TEST_F(ParserImplTest, StructMemberDecoration_Offset_MissingRightParen) { TEST_F(ParserImplTest, Decoration_Offset_MissingRightParen) {
auto p = parser("offset(4"); auto p = parser("offset(4");
auto deco = p->decoration(); auto deco = p->decoration();
EXPECT_FALSE(deco.matched); EXPECT_FALSE(deco.matched);
@ -55,7 +55,7 @@ TEST_F(ParserImplTest, StructMemberDecoration_Offset_MissingRightParen) {
EXPECT_EQ(p->error(), "1:9: expected ')' for offset decoration"); EXPECT_EQ(p->error(), "1:9: expected ')' for offset decoration");
} }
TEST_F(ParserImplTest, StructMemberDecoration_Offset_MissingValue) { TEST_F(ParserImplTest, Decoration_Offset_MissingValue) {
auto p = parser("offset()"); auto p = parser("offset()");
auto deco = p->decoration(); auto deco = p->decoration();
EXPECT_FALSE(deco.matched); EXPECT_FALSE(deco.matched);
@ -66,7 +66,7 @@ TEST_F(ParserImplTest, StructMemberDecoration_Offset_MissingValue) {
"1:8: expected signed integer literal for offset decoration"); "1:8: expected signed integer literal for offset decoration");
} }
TEST_F(ParserImplTest, StructMemberDecoration_Offset_MissingInvalid) { TEST_F(ParserImplTest, Decoration_Offset_MissingInvalid) {
auto p = parser("offset(nan)"); auto p = parser("offset(nan)");
auto deco = p->decoration(); auto deco = p->decoration();
EXPECT_FALSE(deco.matched); EXPECT_FALSE(deco.matched);

View File

@ -19,7 +19,7 @@ namespace reader {
namespace wgsl { namespace wgsl {
namespace { namespace {
TEST_F(ParserImplTest, VariableDecorationList_Parses) { TEST_F(ParserImplTest, DecorationList_Parses) {
auto p = parser(R"([[location(4), builtin(position)]])"); auto p = parser(R"([[location(4), builtin(position)]])");
auto decos = p->decoration_list(); auto decos = p->decoration_list();
ASSERT_FALSE(p->has_error()) << p->error(); ASSERT_FALSE(p->has_error()) << p->error();
@ -27,8 +27,8 @@ TEST_F(ParserImplTest, VariableDecorationList_Parses) {
ASSERT_TRUE(decos.matched); ASSERT_TRUE(decos.matched);
ASSERT_EQ(decos.value.size(), 2u); ASSERT_EQ(decos.value.size(), 2u);
auto* deco_0 = decos.value[0]->As<ast::VariableDecoration>(); auto* deco_0 = decos.value[0]->As<ast::Decoration>();
auto* deco_1 = decos.value[1]->As<ast::VariableDecoration>(); auto* deco_1 = decos.value[1]->As<ast::Decoration>();
ASSERT_NE(deco_0, nullptr); ASSERT_NE(deco_0, nullptr);
ASSERT_NE(deco_1, nullptr); ASSERT_NE(deco_1, nullptr);
@ -39,7 +39,7 @@ TEST_F(ParserImplTest, VariableDecorationList_Parses) {
ast::Builtin::kPosition); ast::Builtin::kPosition);
} }
TEST_F(ParserImplTest, VariableDecorationList_Empty) { TEST_F(ParserImplTest, DecorationList_Empty) {
auto p = parser(R"([[]])"); auto p = parser(R"([[]])");
auto decos = p->decoration_list(); auto decos = p->decoration_list();
EXPECT_TRUE(p->has_error()); EXPECT_TRUE(p->has_error());
@ -49,7 +49,7 @@ TEST_F(ParserImplTest, VariableDecorationList_Empty) {
EXPECT_EQ(p->error(), "1:3: empty decoration list"); EXPECT_EQ(p->error(), "1:3: empty decoration list");
} }
TEST_F(ParserImplTest, VariableDecorationList_Invalid) { TEST_F(ParserImplTest, DecorationList_Invalid) {
auto p = parser(R"([[invalid]])"); auto p = parser(R"([[invalid]])");
auto decos = p->decoration_list(); auto decos = p->decoration_list();
EXPECT_TRUE(p->has_error()); EXPECT_TRUE(p->has_error());
@ -59,7 +59,7 @@ TEST_F(ParserImplTest, VariableDecorationList_Invalid) {
EXPECT_EQ(p->error(), "1:3: expected decoration"); EXPECT_EQ(p->error(), "1:3: expected decoration");
} }
TEST_F(ParserImplTest, VariableDecorationList_ExtraComma) { TEST_F(ParserImplTest, DecorationList_ExtraComma) {
auto p = parser(R"([[builtin(position), ]])"); auto p = parser(R"([[builtin(position), ]])");
auto decos = p->decoration_list(); auto decos = p->decoration_list();
EXPECT_TRUE(p->has_error()); EXPECT_TRUE(p->has_error());
@ -69,7 +69,7 @@ TEST_F(ParserImplTest, VariableDecorationList_ExtraComma) {
EXPECT_EQ(p->error(), "1:22: expected decoration"); EXPECT_EQ(p->error(), "1:22: expected decoration");
} }
TEST_F(ParserImplTest, VariableDecorationList_MissingComma) { TEST_F(ParserImplTest, DecorationList_MissingComma) {
auto p = parser(R"([[binding(4) location(5)]])"); auto p = parser(R"([[binding(4) location(5)]])");
auto decos = p->decoration_list(); auto decos = p->decoration_list();
EXPECT_TRUE(p->has_error()); EXPECT_TRUE(p->has_error());
@ -79,7 +79,7 @@ TEST_F(ParserImplTest, VariableDecorationList_MissingComma) {
EXPECT_EQ(p->error(), "1:14: expected ',' for decoration list"); EXPECT_EQ(p->error(), "1:14: expected ',' for decoration list");
} }
TEST_F(ParserImplTest, VariableDecorationList_BadDecoration) { TEST_F(ParserImplTest, DecorationList_BadDecoration) {
auto p = parser(R"([[location(bad)]])"); auto p = parser(R"([[location(bad)]])");
auto decos = p->decoration_list(); auto decos = p->decoration_list();
EXPECT_TRUE(p->has_error()); EXPECT_TRUE(p->has_error());
@ -90,7 +90,7 @@ TEST_F(ParserImplTest, VariableDecorationList_BadDecoration) {
"1:12: expected signed integer literal for location decoration"); "1:12: expected signed integer literal for location decoration");
} }
TEST_F(ParserImplTest, VariableDecorationList_InvalidBuiltin) { TEST_F(ParserImplTest, DecorationList_InvalidBuiltin) {
auto p = parser("[[builtin(invalid)]]"); auto p = parser("[[builtin(invalid)]]");
auto decos = p->decoration_list(); auto decos = p->decoration_list();
EXPECT_TRUE(p->has_error()); EXPECT_TRUE(p->has_error());

View File

@ -19,13 +19,13 @@ namespace reader {
namespace wgsl { namespace wgsl {
namespace { namespace {
TEST_F(ParserImplTest, VariableDecoration_Location) { TEST_F(ParserImplTest, Decoration_Location) {
auto p = parser("location(4)"); auto p = parser("location(4)");
auto deco = p->decoration(); auto deco = p->decoration();
EXPECT_TRUE(deco.matched); EXPECT_TRUE(deco.matched);
EXPECT_FALSE(deco.errored); EXPECT_FALSE(deco.errored);
ASSERT_NE(deco.value, nullptr); ASSERT_NE(deco.value, nullptr);
auto* var_deco = deco.value->As<ast::VariableDecoration>(); auto* var_deco = deco.value->As<ast::Decoration>();
ASSERT_NE(var_deco, nullptr); ASSERT_NE(var_deco, nullptr);
ASSERT_FALSE(p->has_error()); ASSERT_FALSE(p->has_error());
ASSERT_TRUE(var_deco->Is<ast::LocationDecoration>()); ASSERT_TRUE(var_deco->Is<ast::LocationDecoration>());
@ -34,7 +34,7 @@ TEST_F(ParserImplTest, VariableDecoration_Location) {
EXPECT_EQ(loc->value(), 4u); EXPECT_EQ(loc->value(), 4u);
} }
TEST_F(ParserImplTest, VariableDecoration_Location_MissingLeftParen) { TEST_F(ParserImplTest, Decoration_Location_MissingLeftParen) {
auto p = parser("location 4)"); auto p = parser("location 4)");
auto deco = p->decoration(); auto deco = p->decoration();
EXPECT_FALSE(deco.matched); EXPECT_FALSE(deco.matched);
@ -44,7 +44,7 @@ TEST_F(ParserImplTest, VariableDecoration_Location_MissingLeftParen) {
EXPECT_EQ(p->error(), "1:10: expected '(' for location decoration"); EXPECT_EQ(p->error(), "1:10: expected '(' for location decoration");
} }
TEST_F(ParserImplTest, VariableDecoration_Location_MissingRightParen) { TEST_F(ParserImplTest, Decoration_Location_MissingRightParen) {
auto p = parser("location(4"); auto p = parser("location(4");
auto deco = p->decoration(); auto deco = p->decoration();
EXPECT_FALSE(deco.matched); EXPECT_FALSE(deco.matched);
@ -54,7 +54,7 @@ TEST_F(ParserImplTest, VariableDecoration_Location_MissingRightParen) {
EXPECT_EQ(p->error(), "1:11: expected ')' for location decoration"); EXPECT_EQ(p->error(), "1:11: expected ')' for location decoration");
} }
TEST_F(ParserImplTest, VariableDecoration_Location_MissingValue) { TEST_F(ParserImplTest, Decoration_Location_MissingValue) {
auto p = parser("location()"); auto p = parser("location()");
auto deco = p->decoration(); auto deco = p->decoration();
EXPECT_FALSE(deco.matched); EXPECT_FALSE(deco.matched);
@ -65,7 +65,7 @@ TEST_F(ParserImplTest, VariableDecoration_Location_MissingValue) {
"1:10: expected signed integer literal for location decoration"); "1:10: expected signed integer literal for location decoration");
} }
TEST_F(ParserImplTest, VariableDecoration_Location_MissingInvalid) { TEST_F(ParserImplTest, Decoration_Location_MissingInvalid) {
auto p = parser("location(nan)"); auto p = parser("location(nan)");
auto deco = p->decoration(); auto deco = p->decoration();
EXPECT_FALSE(deco.matched); EXPECT_FALSE(deco.matched);
@ -87,7 +87,7 @@ inline std::ostream& operator<<(std::ostream& out, BuiltinData data) {
class BuiltinTest : public ParserImplTestWithParam<BuiltinData> {}; class BuiltinTest : public ParserImplTestWithParam<BuiltinData> {};
TEST_P(BuiltinTest, VariableDecoration_Builtin) { TEST_P(BuiltinTest, Decoration_Builtin) {
auto params = GetParam(); auto params = GetParam();
auto p = parser(std::string("builtin(") + params.input + ")"); auto p = parser(std::string("builtin(") + params.input + ")");
@ -95,7 +95,7 @@ TEST_P(BuiltinTest, VariableDecoration_Builtin) {
EXPECT_TRUE(deco.matched); EXPECT_TRUE(deco.matched);
EXPECT_FALSE(deco.errored); EXPECT_FALSE(deco.errored);
ASSERT_NE(deco.value, nullptr); ASSERT_NE(deco.value, nullptr);
auto* var_deco = deco.value->As<ast::VariableDecoration>(); auto* var_deco = deco.value->As<ast::Decoration>();
ASSERT_FALSE(p->has_error()) << p->error(); ASSERT_FALSE(p->has_error()) << p->error();
ASSERT_NE(var_deco, nullptr); ASSERT_NE(var_deco, nullptr);
ASSERT_TRUE(var_deco->Is<ast::BuiltinDecoration>()); ASSERT_TRUE(var_deco->Is<ast::BuiltinDecoration>());
@ -125,7 +125,7 @@ INSTANTIATE_TEST_SUITE_P(
BuiltinData{"sample_mask_in", ast::Builtin::kSampleMaskIn}, BuiltinData{"sample_mask_in", ast::Builtin::kSampleMaskIn},
BuiltinData{"sample_mask_out", ast::Builtin::kSampleMaskOut})); BuiltinData{"sample_mask_out", ast::Builtin::kSampleMaskOut}));
TEST_F(ParserImplTest, VariableDecoration_Builtin_MissingLeftParen) { TEST_F(ParserImplTest, Decoration_Builtin_MissingLeftParen) {
auto p = parser("builtin position)"); auto p = parser("builtin position)");
auto deco = p->decoration(); auto deco = p->decoration();
EXPECT_FALSE(deco.matched); EXPECT_FALSE(deco.matched);
@ -135,7 +135,7 @@ TEST_F(ParserImplTest, VariableDecoration_Builtin_MissingLeftParen) {
EXPECT_EQ(p->error(), "1:9: expected '(' for builtin decoration"); EXPECT_EQ(p->error(), "1:9: expected '(' for builtin decoration");
} }
TEST_F(ParserImplTest, VariableDecoration_Builtin_MissingRightParen) { TEST_F(ParserImplTest, Decoration_Builtin_MissingRightParen) {
auto p = parser("builtin(position"); auto p = parser("builtin(position");
auto deco = p->decoration(); auto deco = p->decoration();
EXPECT_FALSE(deco.matched); EXPECT_FALSE(deco.matched);
@ -145,7 +145,7 @@ TEST_F(ParserImplTest, VariableDecoration_Builtin_MissingRightParen) {
EXPECT_EQ(p->error(), "1:17: expected ')' for builtin decoration"); EXPECT_EQ(p->error(), "1:17: expected ')' for builtin decoration");
} }
TEST_F(ParserImplTest, VariableDecoration_Builtin_MissingValue) { TEST_F(ParserImplTest, Decoration_Builtin_MissingValue) {
auto p = parser("builtin()"); auto p = parser("builtin()");
auto deco = p->decoration(); auto deco = p->decoration();
EXPECT_FALSE(deco.matched); EXPECT_FALSE(deco.matched);
@ -155,7 +155,7 @@ TEST_F(ParserImplTest, VariableDecoration_Builtin_MissingValue) {
EXPECT_EQ(p->error(), "1:9: expected identifier for builtin"); EXPECT_EQ(p->error(), "1:9: expected identifier for builtin");
} }
TEST_F(ParserImplTest, VariableDecoration_Builtin_InvalidValue) { TEST_F(ParserImplTest, Decoration_Builtin_InvalidValue) {
auto p = parser("builtin(other_thingy)"); auto p = parser("builtin(other_thingy)");
auto deco = p->decoration(); auto deco = p->decoration();
EXPECT_FALSE(deco.matched); EXPECT_FALSE(deco.matched);
@ -165,7 +165,7 @@ TEST_F(ParserImplTest, VariableDecoration_Builtin_InvalidValue) {
EXPECT_EQ(p->error(), "1:9: invalid value for builtin decoration"); EXPECT_EQ(p->error(), "1:9: invalid value for builtin decoration");
} }
TEST_F(ParserImplTest, VariableDecoration_Builtin_MissingInvalid) { TEST_F(ParserImplTest, Decoration_Builtin_MissingInvalid) {
auto p = parser("builtin(3)"); auto p = parser("builtin(3)");
auto deco = p->decoration(); auto deco = p->decoration();
EXPECT_FALSE(deco.matched); EXPECT_FALSE(deco.matched);
@ -175,13 +175,13 @@ TEST_F(ParserImplTest, VariableDecoration_Builtin_MissingInvalid) {
EXPECT_EQ(p->error(), "1:9: expected identifier for builtin"); EXPECT_EQ(p->error(), "1:9: expected identifier for builtin");
} }
TEST_F(ParserImplTest, VariableDecoration_Binding) { TEST_F(ParserImplTest, Decoration_Binding) {
auto p = parser("binding(4)"); auto p = parser("binding(4)");
auto deco = p->decoration(); auto deco = p->decoration();
EXPECT_TRUE(deco.matched); EXPECT_TRUE(deco.matched);
EXPECT_FALSE(deco.errored); EXPECT_FALSE(deco.errored);
ASSERT_NE(deco.value, nullptr); ASSERT_NE(deco.value, nullptr);
auto* var_deco = deco.value->As<ast::VariableDecoration>(); auto* var_deco = deco.value->As<ast::Decoration>();
ASSERT_NE(var_deco, nullptr); ASSERT_NE(var_deco, nullptr);
ASSERT_FALSE(p->has_error()); ASSERT_FALSE(p->has_error());
ASSERT_TRUE(var_deco->Is<ast::BindingDecoration>()); ASSERT_TRUE(var_deco->Is<ast::BindingDecoration>());
@ -190,7 +190,7 @@ TEST_F(ParserImplTest, VariableDecoration_Binding) {
EXPECT_EQ(binding->value(), 4u); EXPECT_EQ(binding->value(), 4u);
} }
TEST_F(ParserImplTest, VariableDecoration_Binding_MissingLeftParen) { TEST_F(ParserImplTest, Decoration_Binding_MissingLeftParen) {
auto p = parser("binding 4)"); auto p = parser("binding 4)");
auto deco = p->decoration(); auto deco = p->decoration();
EXPECT_FALSE(deco.matched); EXPECT_FALSE(deco.matched);
@ -200,7 +200,7 @@ TEST_F(ParserImplTest, VariableDecoration_Binding_MissingLeftParen) {
EXPECT_EQ(p->error(), "1:9: expected '(' for binding decoration"); EXPECT_EQ(p->error(), "1:9: expected '(' for binding decoration");
} }
TEST_F(ParserImplTest, VariableDecoration_Binding_MissingRightParen) { TEST_F(ParserImplTest, Decoration_Binding_MissingRightParen) {
auto p = parser("binding(4"); auto p = parser("binding(4");
auto deco = p->decoration(); auto deco = p->decoration();
EXPECT_FALSE(deco.matched); EXPECT_FALSE(deco.matched);
@ -210,7 +210,7 @@ TEST_F(ParserImplTest, VariableDecoration_Binding_MissingRightParen) {
EXPECT_EQ(p->error(), "1:10: expected ')' for binding decoration"); EXPECT_EQ(p->error(), "1:10: expected ')' for binding decoration");
} }
TEST_F(ParserImplTest, VariableDecoration_Binding_MissingValue) { TEST_F(ParserImplTest, Decoration_Binding_MissingValue) {
auto p = parser("binding()"); auto p = parser("binding()");
auto deco = p->decoration(); auto deco = p->decoration();
EXPECT_FALSE(deco.matched); EXPECT_FALSE(deco.matched);
@ -221,7 +221,7 @@ TEST_F(ParserImplTest, VariableDecoration_Binding_MissingValue) {
"1:9: expected signed integer literal for binding decoration"); "1:9: expected signed integer literal for binding decoration");
} }
TEST_F(ParserImplTest, VariableDecoration_Binding_MissingInvalid) { TEST_F(ParserImplTest, Decoration_Binding_MissingInvalid) {
auto p = parser("binding(nan)"); auto p = parser("binding(nan)");
auto deco = p->decoration(); auto deco = p->decoration();
EXPECT_FALSE(deco.matched); EXPECT_FALSE(deco.matched);
@ -233,13 +233,13 @@ TEST_F(ParserImplTest, VariableDecoration_Binding_MissingInvalid) {
} }
// DEPRECATED // DEPRECATED
TEST_F(ParserImplTest, VariableDecoration_set) { TEST_F(ParserImplTest, Decoration_set) {
auto p = parser("set(4)"); auto p = parser("set(4)");
auto deco = p->decoration(); auto deco = p->decoration();
EXPECT_TRUE(deco.matched); EXPECT_TRUE(deco.matched);
EXPECT_FALSE(deco.errored); EXPECT_FALSE(deco.errored);
ASSERT_NE(deco.value, nullptr); ASSERT_NE(deco.value, nullptr);
auto* var_deco = deco.value->As<ast::VariableDecoration>(); auto* var_deco = deco.value->As<ast::Decoration>();
ASSERT_FALSE(p->has_error()); ASSERT_FALSE(p->has_error());
ASSERT_NE(var_deco, nullptr); ASSERT_NE(var_deco, nullptr);
ASSERT_TRUE(var_deco->Is<ast::GroupDecoration>()); ASSERT_TRUE(var_deco->Is<ast::GroupDecoration>());
@ -248,13 +248,13 @@ TEST_F(ParserImplTest, VariableDecoration_set) {
EXPECT_EQ(group->value(), 4u); EXPECT_EQ(group->value(), 4u);
} }
TEST_F(ParserImplTest, VariableDecoration_group) { TEST_F(ParserImplTest, Decoration_group) {
auto p = parser("group(4)"); auto p = parser("group(4)");
auto deco = p->decoration(); auto deco = p->decoration();
EXPECT_TRUE(deco.matched); EXPECT_TRUE(deco.matched);
EXPECT_FALSE(deco.errored); EXPECT_FALSE(deco.errored);
ASSERT_NE(deco.value, nullptr); ASSERT_NE(deco.value, nullptr);
auto* var_deco = deco.value->As<ast::VariableDecoration>(); auto* var_deco = deco.value->As<ast::Decoration>();
ASSERT_FALSE(p->has_error()); ASSERT_FALSE(p->has_error());
ASSERT_NE(var_deco, nullptr); ASSERT_NE(var_deco, nullptr);
ASSERT_TRUE(var_deco->Is<ast::GroupDecoration>()); ASSERT_TRUE(var_deco->Is<ast::GroupDecoration>());
@ -263,7 +263,7 @@ TEST_F(ParserImplTest, VariableDecoration_group) {
EXPECT_EQ(group->value(), 4u); EXPECT_EQ(group->value(), 4u);
} }
TEST_F(ParserImplTest, VariableDecoration_Group_MissingLeftParen) { TEST_F(ParserImplTest, Decoration_Group_MissingLeftParen) {
auto p = parser("group 2)"); auto p = parser("group 2)");
auto deco = p->decoration(); auto deco = p->decoration();
EXPECT_FALSE(deco.matched); EXPECT_FALSE(deco.matched);
@ -273,7 +273,7 @@ TEST_F(ParserImplTest, VariableDecoration_Group_MissingLeftParen) {
EXPECT_EQ(p->error(), "1:7: expected '(' for group decoration"); EXPECT_EQ(p->error(), "1:7: expected '(' for group decoration");
} }
TEST_F(ParserImplTest, VariableDecoration_Group_MissingRightParen) { TEST_F(ParserImplTest, Decoration_Group_MissingRightParen) {
auto p = parser("group(2"); auto p = parser("group(2");
auto deco = p->decoration(); auto deco = p->decoration();
EXPECT_FALSE(deco.matched); EXPECT_FALSE(deco.matched);
@ -283,7 +283,7 @@ TEST_F(ParserImplTest, VariableDecoration_Group_MissingRightParen) {
EXPECT_EQ(p->error(), "1:8: expected ')' for group decoration"); EXPECT_EQ(p->error(), "1:8: expected ')' for group decoration");
} }
TEST_F(ParserImplTest, VariableDecoration_Group_MissingValue) { TEST_F(ParserImplTest, Decoration_Group_MissingValue) {
auto p = parser("group()"); auto p = parser("group()");
auto deco = p->decoration(); auto deco = p->decoration();
EXPECT_FALSE(deco.matched); EXPECT_FALSE(deco.matched);
@ -294,7 +294,7 @@ TEST_F(ParserImplTest, VariableDecoration_Group_MissingValue) {
"1:7: expected signed integer literal for group decoration"); "1:7: expected signed integer literal for group decoration");
} }
TEST_F(ParserImplTest, VariableDecoration_Group_MissingInvalid) { TEST_F(ParserImplTest, Decoration_Group_MissingInvalid) {
auto p = parser("group(nan)"); auto p = parser("group(nan)");
auto deco = p->decoration(); auto deco = p->decoration();
EXPECT_FALSE(deco.matched); EXPECT_FALSE(deco.matched);

View File

@ -109,12 +109,12 @@ TEST_F(ParserImplTest, VariableIdentDecl_ParsesWithTextureAccessDeco_Write) {
TEST_F(ParserImplTest, VariableIdentDecl_ParsesWithAccessDeco_Read) { TEST_F(ParserImplTest, VariableIdentDecl_ParsesWithAccessDeco_Read) {
auto p = parser("my_var : [[access(read)]] S"); auto p = parser("my_var : [[access(read)]] S");
auto* mem = Member("a", ty.i32(), ast::StructMemberDecorationList{}); auto* mem = Member("a", ty.i32(), ast::DecorationList{});
ast::StructMemberList members; ast::StructMemberList members;
members.push_back(mem); members.push_back(mem);
auto* block_deco = create<ast::StructBlockDecoration>(); auto* block_deco = create<ast::StructBlockDecoration>();
ast::StructDecorationList decos; ast::DecorationList decos;
decos.push_back(block_deco); decos.push_back(block_deco);
auto* str = create<ast::Struct>(members, decos); auto* str = create<ast::Struct>(members, decos);
@ -134,12 +134,12 @@ TEST_F(ParserImplTest, VariableIdentDecl_ParsesWithAccessDeco_Read) {
TEST_F(ParserImplTest, VariableIdentDecl_ParsesWithAccessDeco_ReadWrite) { TEST_F(ParserImplTest, VariableIdentDecl_ParsesWithAccessDeco_ReadWrite) {
auto p = parser("my_var : [[access(read_write)]] S"); auto p = parser("my_var : [[access(read_write)]] S");
auto* mem = Member("a", ty.i32(), ast::StructMemberDecorationList{}); auto* mem = Member("a", ty.i32(), ast::DecorationList{});
ast::StructMemberList members; ast::StructMemberList members;
members.push_back(mem); members.push_back(mem);
auto* block_deco = create<ast::StructBlockDecoration>(); auto* block_deco = create<ast::StructBlockDecoration>();
ast::StructDecorationList decos; ast::DecorationList decos;
decos.push_back(block_deco); decos.push_back(block_deco);
auto* str = create<ast::Struct>(members, decos); auto* str = create<ast::Struct>(members, decos);
@ -159,12 +159,12 @@ TEST_F(ParserImplTest, VariableIdentDecl_ParsesWithAccessDeco_ReadWrite) {
TEST_F(ParserImplTest, VariableIdentDecl_MultipleAccessDecoFail) { TEST_F(ParserImplTest, VariableIdentDecl_MultipleAccessDecoFail) {
auto p = parser("my_var : [[access(read), access(read_write)]] S"); auto p = parser("my_var : [[access(read), access(read_write)]] S");
auto* mem = Member("a", ty.i32(), ast::StructMemberDecorationList{}); auto* mem = Member("a", ty.i32(), ast::DecorationList{});
ast::StructMemberList members; ast::StructMemberList members;
members.push_back(mem); members.push_back(mem);
auto* block_deco = create<ast::StructBlockDecoration>(); auto* block_deco = create<ast::StructBlockDecoration>();
ast::StructDecorationList decos; ast::DecorationList decos;
decos.push_back(block_deco); decos.push_back(block_deco);
auto* str = create<ast::Struct>(members, decos); auto* str = create<ast::Struct>(members, decos);
@ -181,12 +181,12 @@ TEST_F(ParserImplTest, VariableIdentDecl_MultipleAccessDecoFail) {
TEST_F(ParserImplTest, VariableIdentDecl_MultipleAccessDeco_MultiBlock_Fail) { TEST_F(ParserImplTest, VariableIdentDecl_MultipleAccessDeco_MultiBlock_Fail) {
auto p = parser("my_var : [[access(read)]][[access(read_write)]] S"); auto p = parser("my_var : [[access(read)]][[access(read_write)]] S");
auto* mem = Member("a", ty.i32(), ast::StructMemberDecorationList{}); auto* mem = Member("a", ty.i32(), ast::DecorationList{});
ast::StructMemberList members; ast::StructMemberList members;
members.push_back(mem); members.push_back(mem);
auto* block_deco = create<ast::StructBlockDecoration>(); auto* block_deco = create<ast::StructBlockDecoration>();
ast::StructDecorationList decos; ast::DecorationList decos;
decos.push_back(block_deco); decos.push_back(block_deco);
auto* str = create<ast::Struct>(members, decos); auto* str = create<ast::Struct>(members, decos);
@ -219,12 +219,12 @@ TEST_F(ParserImplTest, VariableIdentDecl_AccessDecoIllegalValue) {
TEST_F(ParserImplTest, VariableIdentDecl_NonAccessDecoFail) { TEST_F(ParserImplTest, VariableIdentDecl_NonAccessDecoFail) {
auto p = parser("my_var : [[stride(1)]] S"); auto p = parser("my_var : [[stride(1)]] S");
auto* mem = Member("a", ty.i32(), ast::StructMemberDecorationList{}); auto* mem = Member("a", ty.i32(), ast::DecorationList{});
ast::StructMemberList members; ast::StructMemberList members;
members.push_back(mem); members.push_back(mem);
auto* block_deco = create<ast::StructBlockDecoration>(); auto* block_deco = create<ast::StructBlockDecoration>();
ast::StructDecorationList decos; ast::DecorationList decos;
decos.push_back(block_deco); decos.push_back(block_deco);
auto* str = create<ast::Struct>(members, decos); auto* str = create<ast::Struct>(members, decos);

View File

@ -248,7 +248,7 @@ TEST_F(ResolverTest, Stmt_Switch) {
TEST_F(ResolverTest, Stmt_Call) { TEST_F(ResolverTest, Stmt_Call) {
ast::VariableList params; ast::VariableList params;
Func("my_func", params, ty.f32(), ast::StatementList{}, Func("my_func", params, ty.f32(), ast::StatementList{},
ast::FunctionDecorationList{}); ast::DecorationList{});
auto* expr = Call("my_func"); auto* expr = Call("my_func");
@ -337,7 +337,7 @@ TEST_F(ResolverTest, Stmt_VariableDecl_OuterScopeAfterInnerScope) {
Func("func", params, ty.f32(), Func("func", params, ty.f32(),
ast::StatementList{inner, foo_f32_decl, bar_f32_decl}, ast::StatementList{inner, foo_f32_decl, bar_f32_decl},
ast::FunctionDecorationList{}); ast::DecorationList{});
EXPECT_TRUE(r()->Resolve()); EXPECT_TRUE(r()->Resolve());
ASSERT_NE(TypeOf(foo_i32_init), nullptr); ASSERT_NE(TypeOf(foo_i32_init), nullptr);
@ -372,7 +372,7 @@ TEST_F(ResolverTest, Stmt_VariableDecl_ModuleScopeAfterFunctionScope) {
auto* fn_i32_init = fn_i32->constructor(); auto* fn_i32_init = fn_i32->constructor();
auto* fn_i32_decl = create<ast::VariableDeclStatement>(fn_i32); auto* fn_i32_decl = create<ast::VariableDeclStatement>(fn_i32);
Func("func_i32", params, ty.i32(), ast::StatementList{fn_i32_decl}, Func("func_i32", params, ty.i32(), ast::StatementList{fn_i32_decl},
ast::FunctionDecorationList{}); ast::DecorationList{});
// Declare f32 "foo" at module scope // Declare f32 "foo" at module scope
auto* mod_f32 = Var("foo", ty.f32(), ast::StorageClass::kNone, Expr(2.f)); auto* mod_f32 = Var("foo", ty.f32(), ast::StorageClass::kNone, Expr(2.f));
@ -384,7 +384,7 @@ TEST_F(ResolverTest, Stmt_VariableDecl_ModuleScopeAfterFunctionScope) {
auto* fn_f32_init = fn_f32->constructor(); auto* fn_f32_init = fn_f32->constructor();
auto* fn_f32_decl = create<ast::VariableDeclStatement>(fn_f32); auto* fn_f32_decl = create<ast::VariableDeclStatement>(fn_f32);
Func("func_f32", params, ty.f32(), ast::StatementList{fn_f32_decl}, Func("func_f32", params, ty.f32(), ast::StatementList{fn_f32_decl},
ast::FunctionDecorationList{}); ast::DecorationList{});
EXPECT_TRUE(r()->Resolve()); EXPECT_TRUE(r()->Resolve());
ASSERT_NE(TypeOf(mod_init), nullptr); ASSERT_NE(TypeOf(mod_init), nullptr);
@ -506,7 +506,7 @@ TEST_F(ResolverTest, Expr_Bitcast) {
TEST_F(ResolverTest, Expr_Call) { TEST_F(ResolverTest, Expr_Call) {
ast::VariableList params; ast::VariableList params;
Func("my_func", params, ty.f32(), ast::StatementList{}, Func("my_func", params, ty.f32(), ast::StatementList{},
ast::FunctionDecorationList{}); ast::DecorationList{});
auto* call = Call("my_func"); auto* call = Call("my_func");
WrapInFunction(call); WrapInFunction(call);
@ -519,8 +519,7 @@ TEST_F(ResolverTest, Expr_Call) {
TEST_F(ResolverTest, Expr_Call_InBinaryOp) { TEST_F(ResolverTest, Expr_Call_InBinaryOp) {
ast::VariableList params; ast::VariableList params;
Func("func", params, ty.f32(), ast::StatementList{}, Func("func", params, ty.f32(), ast::StatementList{}, ast::DecorationList{});
ast::FunctionDecorationList{});
auto* expr = Add(Call("func"), Call("func")); auto* expr = Add(Call("func"), Call("func"));
WrapInFunction(expr); WrapInFunction(expr);
@ -534,7 +533,7 @@ TEST_F(ResolverTest, Expr_Call_InBinaryOp) {
TEST_F(ResolverTest, Expr_Call_WithParams) { TEST_F(ResolverTest, Expr_Call_WithParams) {
ast::VariableList params; ast::VariableList params;
Func("my_func", params, ty.f32(), ast::StatementList{}, Func("my_func", params, ty.f32(), ast::StatementList{},
ast::FunctionDecorationList{}); ast::DecorationList{});
auto* param = Expr(2.4f); auto* param = Expr(2.4f);
@ -629,7 +628,7 @@ TEST_F(ResolverTest, Expr_Identifier_FunctionVariable_Const) {
create<ast::VariableDeclStatement>(var), create<ast::VariableDeclStatement>(var),
assign, assign,
}, },
ast::FunctionDecorationList{}); ast::DecorationList{});
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();
@ -654,7 +653,7 @@ TEST_F(ResolverTest, Expr_Identifier_FunctionVariable) {
create<ast::VariableDeclStatement>(var), create<ast::VariableDeclStatement>(var),
assign, assign,
}, },
ast::FunctionDecorationList{}); ast::DecorationList{});
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();
@ -681,7 +680,7 @@ TEST_F(ResolverTest, Expr_Identifier_Function_Ptr) {
ast::StorageClass::kNone)), ast::StorageClass::kNone)),
assign, assign,
}, },
ast::FunctionDecorationList{}); ast::DecorationList{});
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();
@ -697,7 +696,7 @@ TEST_F(ResolverTest, Expr_Identifier_Function_Ptr) {
TEST_F(ResolverTest, Expr_Call_Function) { TEST_F(ResolverTest, Expr_Call_Function) {
Func("my_func", ast::VariableList{}, ty.f32(), ast::StatementList{}, Func("my_func", ast::VariableList{}, ty.f32(), ast::StatementList{},
ast::FunctionDecorationList{}); ast::DecorationList{});
auto* call = Call("my_func"); auto* call = Call("my_func");
WrapInFunction(call); WrapInFunction(call);
@ -730,7 +729,7 @@ TEST_F(ResolverTest, Function_RegisterInputOutputVariables) {
create<ast::AssignmentStatement>(Expr("sb_var"), Expr("sb_var")), create<ast::AssignmentStatement>(Expr("sb_var"), Expr("sb_var")),
create<ast::AssignmentStatement>(Expr("priv_var"), Expr("priv_var")), create<ast::AssignmentStatement>(Expr("priv_var"), Expr("priv_var")),
}, },
ast::FunctionDecorationList{}); ast::DecorationList{});
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();
@ -760,14 +759,14 @@ TEST_F(ResolverTest, Function_RegisterInputOutputVariables_SubFunction) {
create<ast::AssignmentStatement>(Expr("sb_var"), Expr("sb_var")), create<ast::AssignmentStatement>(Expr("sb_var"), Expr("sb_var")),
create<ast::AssignmentStatement>(Expr("priv_var"), Expr("priv_var")), create<ast::AssignmentStatement>(Expr("priv_var"), Expr("priv_var")),
}, },
ast::FunctionDecorationList{}); ast::DecorationList{});
auto* func2 = Func( auto* func2 = Func(
"func", ast::VariableList{}, ty.f32(), "func", ast::VariableList{}, ty.f32(),
ast::StatementList{ ast::StatementList{
create<ast::AssignmentStatement>(Expr("out_var"), Call("my_func")), create<ast::AssignmentStatement>(Expr("out_var"), Call("my_func")),
}, },
ast::FunctionDecorationList{}); ast::DecorationList{});
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();
@ -792,7 +791,7 @@ TEST_F(ResolverTest, Function_NotRegisterFunctionVariable) {
create<ast::VariableDeclStatement>(var), create<ast::VariableDeclStatement>(var),
create<ast::AssignmentStatement>(Expr("var"), Expr(1.f)), create<ast::AssignmentStatement>(Expr("var"), Expr(1.f)),
}, },
ast::FunctionDecorationList{}); ast::DecorationList{});
Global("var", ty.f32(), ast::StorageClass::kFunction); Global("var", ty.f32(), ast::StorageClass::kFunction);
@ -808,7 +807,7 @@ TEST_F(ResolverTest, Expr_MemberAccessor_Struct) {
auto* strct = create<ast::Struct>( auto* strct = create<ast::Struct>(
ast::StructMemberList{Member("first_member", ty.i32()), ast::StructMemberList{Member("first_member", ty.i32()),
Member("second_member", ty.f32())}, Member("second_member", ty.f32())},
ast::StructDecorationList{}); ast::DecorationList{});
auto* st = ty.struct_("S", strct); auto* st = ty.struct_("S", strct);
Global("my_struct", st, ast::StorageClass::kNone); Global("my_struct", st, ast::StorageClass::kNone);
@ -829,7 +828,7 @@ TEST_F(ResolverTest, Expr_MemberAccessor_Struct_Alias) {
auto* strct = create<ast::Struct>( auto* strct = create<ast::Struct>(
ast::StructMemberList{Member("first_member", ty.i32()), ast::StructMemberList{Member("first_member", ty.i32()),
Member("second_member", ty.f32())}, Member("second_member", ty.f32())},
ast::StructDecorationList{}); ast::DecorationList{});
auto* st = ty.struct_("alias", strct); auto* st = ty.struct_("alias", strct);
auto* alias = ty.alias("alias", st); auto* alias = ty.alias("alias", st);
@ -906,12 +905,12 @@ TEST_F(ResolverTest, Expr_Accessor_MultiLevel) {
auto* strctB = auto* strctB =
create<ast::Struct>(ast::StructMemberList{Member("foo", ty.vec4<f32>())}, create<ast::Struct>(ast::StructMemberList{Member("foo", ty.vec4<f32>())},
ast::StructDecorationList{}); ast::DecorationList{});
auto* stB = ty.struct_("B", strctB); auto* stB = ty.struct_("B", strctB);
type::Vector vecB(stB, 3); type::Vector vecB(stB, 3);
auto* strctA = create<ast::Struct>( auto* strctA = create<ast::Struct>(
ast::StructMemberList{Member("mem", &vecB)}, ast::StructDecorationList{}); ast::StructMemberList{Member("mem", &vecB)}, ast::DecorationList{});
auto* stA = ty.struct_("A", strctA); auto* stA = ty.struct_("A", strctA);
Global("c", stA, ast::StorageClass::kNone); Global("c", stA, ast::StorageClass::kNone);
@ -933,7 +932,7 @@ TEST_F(ResolverTest, Expr_MemberAccessor_InBinaryOp) {
auto* strct = create<ast::Struct>( auto* strct = create<ast::Struct>(
ast::StructMemberList{Member("first_member", ty.f32()), ast::StructMemberList{Member("first_member", ty.f32()),
Member("second_member", ty.f32())}, Member("second_member", ty.f32())},
ast::StructDecorationList{}); ast::DecorationList{});
auto* st = ty.struct_("S", strct); auto* st = ty.struct_("S", strct);
Global("my_struct", st, ast::StorageClass::kNone); Global("my_struct", st, ast::StorageClass::kNone);
@ -1214,7 +1213,7 @@ TEST_F(ResolverTest, StorageClass_SetsIfMissing) {
auto* stmt = create<ast::VariableDeclStatement>(var); auto* stmt = create<ast::VariableDeclStatement>(var);
Func("func", ast::VariableList{}, ty.i32(), ast::StatementList{stmt}, Func("func", ast::VariableList{}, ty.i32(), ast::StatementList{stmt},
ast::FunctionDecorationList{}); ast::DecorationList{});
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();
@ -1225,7 +1224,7 @@ TEST_F(ResolverTest, StorageClass_DoesNotSetOnConst) {
auto* var = Const("var", ty.i32()); auto* var = Const("var", ty.i32());
auto* stmt = create<ast::VariableDeclStatement>(var); auto* stmt = create<ast::VariableDeclStatement>(var);
Func("func", ast::VariableList{}, ty.i32(), ast::StatementList{stmt}, Func("func", ast::VariableList{}, ty.i32(), ast::StatementList{stmt},
ast::FunctionDecorationList{}); ast::DecorationList{});
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();
@ -1246,21 +1245,21 @@ TEST_F(ResolverTest, Function_EntryPoints_StageDecoration) {
// ep_2 -> {} // ep_2 -> {}
ast::VariableList params; ast::VariableList params;
auto* func_b = Func("b", params, ty.f32(), ast::StatementList{}, auto* func_b =
ast::FunctionDecorationList{}); Func("b", params, ty.f32(), ast::StatementList{}, ast::DecorationList{});
auto* func_c = auto* func_c =
Func("c", params, ty.f32(), Func("c", params, ty.f32(),
ast::StatementList{ ast::StatementList{
create<ast::AssignmentStatement>(Expr("second"), Call("b")), create<ast::AssignmentStatement>(Expr("second"), Call("b")),
}, },
ast::FunctionDecorationList{}); ast::DecorationList{});
auto* func_a = auto* func_a =
Func("a", params, ty.f32(), Func("a", params, ty.f32(),
ast::StatementList{ ast::StatementList{
create<ast::AssignmentStatement>(Expr("first"), Call("c")), create<ast::AssignmentStatement>(Expr("first"), Call("c")),
}, },
ast::FunctionDecorationList{}); ast::DecorationList{});
auto* ep_1 = auto* ep_1 =
Func("ep_1", params, ty.f32(), Func("ep_1", params, ty.f32(),
@ -1268,7 +1267,7 @@ TEST_F(ResolverTest, Function_EntryPoints_StageDecoration) {
create<ast::AssignmentStatement>(Expr("call_a"), Call("a")), create<ast::AssignmentStatement>(Expr("call_a"), Call("a")),
create<ast::AssignmentStatement>(Expr("call_b"), Call("b")), create<ast::AssignmentStatement>(Expr("call_b"), Call("b")),
}, },
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
@ -1277,7 +1276,7 @@ TEST_F(ResolverTest, Function_EntryPoints_StageDecoration) {
ast::StatementList{ ast::StatementList{
create<ast::AssignmentStatement>(Expr("call_c"), Call("c")), create<ast::AssignmentStatement>(Expr("call_c"), Call("c")),
}, },
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });

View File

@ -95,13 +95,13 @@ TEST_F(ResolverValidationTest, Stmt_Call_undeclared) {
create<ast::CallStatement>(call_expr), create<ast::CallStatement>(call_expr),
create<ast::ReturnStatement>(), create<ast::ReturnStatement>(),
}, },
ast::FunctionDecorationList{}); ast::DecorationList{});
Func("func", params0, ty.f32(), Func("func", params0, ty.f32(),
ast::StatementList{ ast::StatementList{
create<ast::ReturnStatement>(), create<ast::ReturnStatement>(),
}, },
ast::FunctionDecorationList{}); ast::DecorationList{});
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
@ -120,7 +120,7 @@ TEST_F(ResolverValidationTest, Stmt_Call_recursive) {
ast::StatementList{ ast::StatementList{
create<ast::CallStatement>(call_expr), create<ast::CallStatement>(call_expr),
}, },
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
@ -246,7 +246,7 @@ TEST_F(ResolverValidationTest, StorageClass_NonFunctionClassError) {
auto* stmt = create<ast::VariableDeclStatement>(var); auto* stmt = create<ast::VariableDeclStatement>(var);
Func("func", ast::VariableList{}, ty.i32(), ast::StatementList{stmt}, Func("func", ast::VariableList{}, ty.i32(), ast::StatementList{stmt},
ast::FunctionDecorationList{}); ast::DecorationList{});
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());

View File

@ -47,7 +47,7 @@ Transform::Output EmitVertexPointSize::Run(const Program* in) {
f32, // type f32, // type
false, // is_const false, // is_const
nullptr, // constructor nullptr, // constructor
ast::VariableDecorationList{ ast::DecorationList{
out.create<ast::BuiltinDecoration>(Source{}, out.create<ast::BuiltinDecoration>(Source{},
ast::Builtin::kPointSize), ast::Builtin::kPointSize),
}); });

View File

@ -101,7 +101,7 @@ Transform::Output FirstIndexOffset::Run(const Program* in) {
CloneContext ctx(&out, in); CloneContext ctx(&out, in);
ctx.ReplaceAll([&](ast::Variable* var) -> ast::Variable* { ctx.ReplaceAll([&](ast::Variable* var) -> ast::Variable* {
for (ast::VariableDecoration* dec : var->decorations()) { for (ast::Decoration* dec : var->decorations()) {
if (auto* blt_dec = dec->As<ast::BuiltinDecoration>()) { if (auto* blt_dec = dec->As<ast::BuiltinDecoration>()) {
ast::Builtin blt_type = blt_dec->value(); ast::Builtin blt_type = blt_dec->value();
if (blt_type == ast::Builtin::kVertexIndex) { if (blt_type == ast::Builtin::kVertexIndex) {
@ -157,7 +157,7 @@ ast::Variable* FirstIndexOffset::State::AddUniformBuffer() {
ast::StructMemberList members; ast::StructMemberList members;
uint32_t offset = 0; uint32_t offset = 0;
if (has_vertex_index) { if (has_vertex_index) {
ast::StructMemberDecorationList member_dec; ast::DecorationList member_dec;
member_dec.push_back( member_dec.push_back(
dst->create<ast::StructMemberOffsetDecoration>(Source{}, offset)); dst->create<ast::StructMemberOffsetDecoration>(Source{}, offset));
members.push_back(dst->create<ast::StructMember>( members.push_back(dst->create<ast::StructMember>(
@ -168,7 +168,7 @@ ast::Variable* FirstIndexOffset::State::AddUniformBuffer() {
} }
if (has_instance_index) { if (has_instance_index) {
ast::StructMemberDecorationList member_dec; ast::DecorationList member_dec;
member_dec.push_back( member_dec.push_back(
dst->create<ast::StructMemberOffsetDecoration>(Source{}, offset)); dst->create<ast::StructMemberOffsetDecoration>(Source{}, offset));
members.push_back(dst->create<ast::StructMember>( members.push_back(dst->create<ast::StructMember>(
@ -178,7 +178,7 @@ ast::Variable* FirstIndexOffset::State::AddUniformBuffer() {
offset += 4; offset += 4;
} }
ast::StructDecorationList decos; ast::DecorationList decos;
decos.push_back(dst->create<ast::StructBlockDecoration>(Source{})); decos.push_back(dst->create<ast::StructBlockDecoration>(Source{}));
auto* struct_type = dst->create<type::Struct>( auto* struct_type = dst->create<type::Struct>(
@ -192,7 +192,7 @@ ast::Variable* FirstIndexOffset::State::AddUniformBuffer() {
struct_type, // type struct_type, // type
false, // is_const false, // is_const
nullptr, // constructor nullptr, // constructor
ast::VariableDecorationList{ ast::DecorationList{
dst->create<ast::BindingDecoration>(Source{}, binding), dst->create<ast::BindingDecoration>(Source{}, binding),
dst->create<ast::GroupDecoration>(Source{}, group), dst->create<ast::GroupDecoration>(Source{}, group),
}); });
@ -227,7 +227,7 @@ ast::VariableDeclStatement* FirstIndexOffset::State::CreateFirstIndexOffset(
dst->create<type::U32>(), // type dst->create<type::U32>(), // type
true, // is_const true, // is_const
constructor, // constructor constructor, // constructor
ast::VariableDecorationList{}); // decorations ast::DecorationList{}); // decorations
return dst->create<ast::VariableDeclStatement>(Source{}, var); return dst->create<ast::VariableDeclStatement>(Source{}, var);
} }

View File

@ -135,7 +135,7 @@ void VertexPulling::State::FindOrInsertVertexIndexIfUsed() {
GetI32Type(), // type GetI32Type(), // type
false, // is_const false, // is_const
nullptr, // constructor nullptr, // constructor
ast::VariableDecorationList{ ast::DecorationList{
ctx.dst->create<ast::BuiltinDecoration>(Source{}, ctx.dst->create<ast::BuiltinDecoration>(Source{},
ast::Builtin::kVertexIndex), ast::Builtin::kVertexIndex),
}); });
@ -182,7 +182,7 @@ void VertexPulling::State::FindOrInsertInstanceIndexIfUsed() {
GetI32Type(), // type GetI32Type(), // type
false, // is_const false, // is_const
nullptr, // constructor nullptr, // constructor
ast::VariableDecorationList{ ast::DecorationList{
ctx.dst->create<ast::BuiltinDecoration>(Source{}, ctx.dst->create<ast::BuiltinDecoration>(Source{},
ast::Builtin::kInstanceIndex), ast::Builtin::kInstanceIndex),
}); });
@ -210,7 +210,7 @@ void VertexPulling::State::ConvertVertexInputVariablesToPrivate() {
ctx.Clone(v->type()), // type ctx.Clone(v->type()), // type
false, // is_const false, // is_const
nullptr, // constructor nullptr, // constructor
ast::VariableDecorationList{}); // decorations ast::DecorationList{}); // decorations
location_to_var[location] = replacement; location_to_var[location] = replacement;
location_replacements.emplace_back(LocationReplacement{v, replacement}); location_replacements.emplace_back(LocationReplacement{v, replacement});
break; break;
@ -224,13 +224,13 @@ void VertexPulling::State::AddVertexStorageBuffers() {
// The array inside the struct definition // The array inside the struct definition
auto* internal_array_type = ctx.dst->create<type::Array>( auto* internal_array_type = ctx.dst->create<type::Array>(
GetU32Type(), 0, GetU32Type(), 0,
ast::ArrayDecorationList{ ast::DecorationList{
ctx.dst->create<ast::StrideDecoration>(Source{}, 4u), ctx.dst->create<ast::StrideDecoration>(Source{}, 4u),
}); });
// Creating the struct type // Creating the struct type
ast::StructMemberList members; ast::StructMemberList members;
ast::StructMemberDecorationList member_dec; ast::DecorationList member_dec;
member_dec.push_back( member_dec.push_back(
ctx.dst->create<ast::StructMemberOffsetDecoration>(Source{}, 0u)); ctx.dst->create<ast::StructMemberOffsetDecoration>(Source{}, 0u));
@ -238,7 +238,7 @@ void VertexPulling::State::AddVertexStorageBuffers() {
Source{}, ctx.dst->Symbols().Register(kStructBufferName), Source{}, ctx.dst->Symbols().Register(kStructBufferName),
internal_array_type, std::move(member_dec))); internal_array_type, std::move(member_dec)));
ast::StructDecorationList decos; ast::DecorationList decos;
decos.push_back(ctx.dst->create<ast::StructBlockDecoration>(Source{})); decos.push_back(ctx.dst->create<ast::StructBlockDecoration>(Source{}));
auto* struct_type = ctx.dst->create<type::Struct>( auto* struct_type = ctx.dst->create<type::Struct>(
@ -256,7 +256,7 @@ void VertexPulling::State::AddVertexStorageBuffers() {
struct_type, // type struct_type, // type
false, // is_const false, // is_const
nullptr, // constructor nullptr, // constructor
ast::VariableDecorationList{ ast::DecorationList{
ctx.dst->create<ast::BindingDecoration>(Source{}, i), ctx.dst->create<ast::BindingDecoration>(Source{}, i),
ctx.dst->create<ast::GroupDecoration>(Source{}, cfg.pulling_group), ctx.dst->create<ast::GroupDecoration>(Source{}, cfg.pulling_group),
}); });
@ -276,11 +276,11 @@ ast::BlockStatement* VertexPulling::State::CreateVertexPullingPreamble() const {
Source{}, ctx.dst->create<ast::Variable>( Source{}, ctx.dst->create<ast::Variable>(
Source{}, // source Source{}, // source
ctx.dst->Symbols().Register(kPullingPosVarName), // symbol ctx.dst->Symbols().Register(kPullingPosVarName), // symbol
ast::StorageClass::kFunction, // storage_class ast::StorageClass::kFunction, // storage_class
GetI32Type(), // type GetI32Type(), // type
false, // is_const false, // is_const
nullptr, // constructor nullptr, // constructor
ast::VariableDecorationList{})); // decorations ast::DecorationList{})); // decorations
// |kPullingPosVarName| refers to the byte location of the current read. We // |kPullingPosVarName| refers to the byte location of the current read. We
// declare a variable in the shader to avoid having to reuse Expression // declare a variable in the shader to avoid having to reuse Expression

View File

@ -103,16 +103,14 @@ TEST_F(AccessControlTest, MinBufferBindingSizeU32) {
TEST_F(AccessControlTest, MinBufferBindingSizeArray) { TEST_F(AccessControlTest, MinBufferBindingSizeArray) {
U32 u32; U32 u32;
Array array(&u32, 4, Array array(&u32, 4, ast::DecorationList{create<ast::StrideDecoration>(4)});
ast::ArrayDecorationList{create<ast::StrideDecoration>(4)});
AccessControl at{ast::AccessControl::kReadOnly, &array}; AccessControl at{ast::AccessControl::kReadOnly, &array};
EXPECT_EQ(16u, at.MinBufferBindingSize(MemoryLayout::kUniformBuffer)); EXPECT_EQ(16u, at.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
} }
TEST_F(AccessControlTest, MinBufferBindingSizeRuntimeArray) { TEST_F(AccessControlTest, MinBufferBindingSizeRuntimeArray) {
U32 u32; U32 u32;
Array array(&u32, 0, Array array(&u32, 0, ast::DecorationList{create<ast::StrideDecoration>(4)});
ast::ArrayDecorationList{create<ast::StrideDecoration>(4)});
AccessControl at{ast::AccessControl::kReadOnly, &array}; AccessControl at{ast::AccessControl::kReadOnly, &array};
EXPECT_EQ(4u, at.MinBufferBindingSize(MemoryLayout::kUniformBuffer)); EXPECT_EQ(4u, at.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
} }
@ -121,7 +119,7 @@ TEST_F(AccessControlTest, MinBufferBindingSizeStruct) {
auto* str = create<ast::Struct>( auto* str = create<ast::Struct>(
ast::StructMemberList{Member("foo", ty.u32(), {MemberOffset(0)}), ast::StructMemberList{Member("foo", ty.u32(), {MemberOffset(0)}),
Member("bar", ty.u32(), {MemberOffset(4)})}, Member("bar", ty.u32(), {MemberOffset(4)})},
ast::StructDecorationList{}); ast::DecorationList{});
auto* struct_type = ty.struct_("struct_type", str); auto* struct_type = ty.struct_("struct_type", str);
AccessControl at{ast::AccessControl::kReadOnly, struct_type}; AccessControl at{ast::AccessControl::kReadOnly, struct_type};
@ -137,16 +135,14 @@ TEST_F(AccessControlTest, BaseAlignmentU32) {
TEST_F(AccessControlTest, BaseAlignmentArray) { TEST_F(AccessControlTest, BaseAlignmentArray) {
U32 u32; U32 u32;
Array array(&u32, 4, Array array(&u32, 4, ast::DecorationList{create<ast::StrideDecoration>(4)});
ast::ArrayDecorationList{create<ast::StrideDecoration>(4)});
AccessControl at{ast::AccessControl::kReadOnly, &array}; AccessControl at{ast::AccessControl::kReadOnly, &array};
EXPECT_EQ(16u, at.BaseAlignment(MemoryLayout::kUniformBuffer)); EXPECT_EQ(16u, at.BaseAlignment(MemoryLayout::kUniformBuffer));
} }
TEST_F(AccessControlTest, BaseAlignmentRuntimeArray) { TEST_F(AccessControlTest, BaseAlignmentRuntimeArray) {
U32 u32; U32 u32;
Array array(&u32, 0, Array array(&u32, 0, ast::DecorationList{create<ast::StrideDecoration>(4)});
ast::ArrayDecorationList{create<ast::StrideDecoration>(4)});
AccessControl at{ast::AccessControl::kReadOnly, &array}; AccessControl at{ast::AccessControl::kReadOnly, &array};
EXPECT_EQ(16u, at.BaseAlignment(MemoryLayout::kUniformBuffer)); EXPECT_EQ(16u, at.BaseAlignment(MemoryLayout::kUniformBuffer));
} }
@ -155,7 +151,7 @@ TEST_F(AccessControlTest, BaseAlignmentStruct) {
auto* str = create<ast::Struct>( auto* str = create<ast::Struct>(
ast::StructMemberList{Member("foo", ty.u32(), {MemberOffset(0)}), ast::StructMemberList{Member("foo", ty.u32(), {MemberOffset(0)}),
Member("bar", ty.u32(), {MemberOffset(4)})}, Member("bar", ty.u32(), {MemberOffset(4)})},
ast::StructDecorationList{}); ast::DecorationList{});
auto* struct_type = ty.struct_("struct_type", str); auto* struct_type = ty.struct_("struct_type", str);
AccessControl at{ast::AccessControl::kReadOnly, struct_type}; AccessControl at{ast::AccessControl::kReadOnly, struct_type};

View File

@ -144,7 +144,7 @@ TEST_F(AliasTest, MinBufferBindingSizeU32) {
TEST_F(AliasTest, MinBufferBindingSizeArray) { TEST_F(AliasTest, MinBufferBindingSizeArray) {
Array array(ty.u32(), 4, Array array(ty.u32(), 4,
ast::ArrayDecorationList{ ast::DecorationList{
create<ast::StrideDecoration>(4), create<ast::StrideDecoration>(4),
}); });
auto* alias = ty.alias("alias", &array); auto* alias = ty.alias("alias", &array);
@ -153,7 +153,7 @@ TEST_F(AliasTest, MinBufferBindingSizeArray) {
TEST_F(AliasTest, MinBufferBindingSizeRuntimeArray) { TEST_F(AliasTest, MinBufferBindingSizeRuntimeArray) {
Array array(ty.u32(), 0, Array array(ty.u32(), 0,
ast::ArrayDecorationList{ ast::DecorationList{
create<ast::StrideDecoration>(4), create<ast::StrideDecoration>(4),
}); });
auto* alias = ty.alias("alias", &array); auto* alias = ty.alias("alias", &array);
@ -164,7 +164,7 @@ TEST_F(AliasTest, MinBufferBindingSizeStruct) {
auto* str = create<ast::Struct>( auto* str = create<ast::Struct>(
ast::StructMemberList{Member("foo", ty.u32(), {MemberOffset(0)}), ast::StructMemberList{Member("foo", ty.u32(), {MemberOffset(0)}),
Member("bar", ty.u32(), {MemberOffset(4)})}, Member("bar", ty.u32(), {MemberOffset(4)})},
ast::StructDecorationList{}); ast::DecorationList{});
auto* struct_type = ty.struct_("struct_type", str); auto* struct_type = ty.struct_("struct_type", str);
auto* alias = ty.alias("alias", struct_type); auto* alias = ty.alias("alias", struct_type);
@ -179,7 +179,7 @@ TEST_F(AliasTest, BaseAlignmentU32) {
TEST_F(AliasTest, BaseAlignmentArray) { TEST_F(AliasTest, BaseAlignmentArray) {
Array array(ty.u32(), 4, Array array(ty.u32(), 4,
ast::ArrayDecorationList{ ast::DecorationList{
create<ast::StrideDecoration>(4), create<ast::StrideDecoration>(4),
}); });
auto* alias = ty.alias("alias", &array); auto* alias = ty.alias("alias", &array);
@ -188,7 +188,7 @@ TEST_F(AliasTest, BaseAlignmentArray) {
TEST_F(AliasTest, BaseAlignmentRuntimeArray) { TEST_F(AliasTest, BaseAlignmentRuntimeArray) {
Array array(ty.u32(), 0, Array array(ty.u32(), 0,
ast::ArrayDecorationList{ ast::DecorationList{
create<ast::StrideDecoration>(4), create<ast::StrideDecoration>(4),
}); });
auto* alias = ty.alias("alias", &array); auto* alias = ty.alias("alias", &array);
@ -199,7 +199,7 @@ TEST_F(AliasTest, BaseAlignmentStruct) {
auto* str = create<ast::Struct>( auto* str = create<ast::Struct>(
ast::StructMemberList{Member("foo", ty.u32(), {MemberOffset(0)}), ast::StructMemberList{Member("foo", ty.u32(), {MemberOffset(0)}),
Member("bar", ty.u32(), {MemberOffset(4)})}, Member("bar", ty.u32(), {MemberOffset(4)})},
ast::StructDecorationList{}); ast::DecorationList{});
auto* struct_type = ty.struct_("struct_type", str); auto* struct_type = ty.struct_("struct_type", str);
auto* alias = ty.alias("alias", struct_type); auto* alias = ty.alias("alias", struct_type);

View File

@ -23,7 +23,7 @@ TINT_INSTANTIATE_TYPEINFO(tint::type::Array);
namespace tint { namespace tint {
namespace type { namespace type {
Array::Array(Type* subtype, uint32_t size, ast::ArrayDecorationList decorations) Array::Array(Type* subtype, uint32_t size, ast::DecorationList decorations)
: subtype_(subtype), size_(size), decos_(decorations) {} : subtype_(subtype), size_(size), decos_(decorations) {}
Array::Array(Array&&) = default; Array::Array(Array&&) = default;

View File

@ -17,7 +17,7 @@
#include <string> #include <string>
#include "src/ast/array_decoration.h" #include "src/ast/decoration.h"
#include "src/type/type.h" #include "src/type/type.h"
namespace tint { namespace tint {
@ -31,7 +31,7 @@ class Array : public Castable<Array, Type> {
/// @param size the number of elements in the array. `0` represents a /// @param size the number of elements in the array. `0` represents a
/// runtime-sized array. /// runtime-sized array.
/// @param decorations the array decorations /// @param decorations the array decorations
Array(Type* subtype, uint32_t size, ast::ArrayDecorationList decorations); Array(Type* subtype, uint32_t size, ast::DecorationList decorations);
/// Move constructor /// Move constructor
Array(Array&&); Array(Array&&);
~Array() override; ~Array() override;
@ -51,7 +51,7 @@ class Array : public Castable<Array, Type> {
uint64_t BaseAlignment(MemoryLayout mem_layout) const override; uint64_t BaseAlignment(MemoryLayout mem_layout) const override;
/// @returns the array decorations /// @returns the array decorations
const ast::ArrayDecorationList& decorations() const { return decos_; } const ast::DecorationList& decorations() const { return decos_; }
/// @returns the array stride or 0 if none set. /// @returns the array stride or 0 if none set.
uint32_t array_stride() const; uint32_t array_stride() const;
@ -79,7 +79,7 @@ class Array : public Castable<Array, Type> {
private: private:
Type* const subtype_; Type* const subtype_;
uint32_t const size_; uint32_t const size_;
ast::ArrayDecorationList const decos_; ast::DecorationList const decos_;
}; };
} // namespace type } // namespace type

View File

@ -24,7 +24,7 @@ using ArrayTest = TestHelper;
TEST_F(ArrayTest, CreateSizedArray) { TEST_F(ArrayTest, CreateSizedArray) {
U32 u32; U32 u32;
Array arr{&u32, 3, ast::ArrayDecorationList{}}; Array arr{&u32, 3, ast::DecorationList{}};
EXPECT_EQ(arr.type(), &u32); EXPECT_EQ(arr.type(), &u32);
EXPECT_EQ(arr.size(), 3u); EXPECT_EQ(arr.size(), 3u);
EXPECT_TRUE(arr.Is<Array>()); EXPECT_TRUE(arr.Is<Array>());
@ -33,7 +33,7 @@ TEST_F(ArrayTest, CreateSizedArray) {
TEST_F(ArrayTest, CreateRuntimeArray) { TEST_F(ArrayTest, CreateRuntimeArray) {
U32 u32; U32 u32;
Array arr{&u32, 0, ast::ArrayDecorationList{}}; Array arr{&u32, 0, ast::DecorationList{}};
EXPECT_EQ(arr.type(), &u32); EXPECT_EQ(arr.type(), &u32);
EXPECT_EQ(arr.size(), 0u); EXPECT_EQ(arr.size(), 0u);
EXPECT_TRUE(arr.Is<Array>()); EXPECT_TRUE(arr.Is<Array>());
@ -43,7 +43,7 @@ TEST_F(ArrayTest, CreateRuntimeArray) {
TEST_F(ArrayTest, Is) { TEST_F(ArrayTest, Is) {
I32 i32; I32 i32;
Array arr{&i32, 3, ast::ArrayDecorationList{}}; Array arr{&i32, 3, ast::DecorationList{}};
Type* ty = &arr; Type* ty = &arr;
EXPECT_FALSE(ty->Is<AccessControl>()); EXPECT_FALSE(ty->Is<AccessControl>());
EXPECT_FALSE(ty->Is<Alias>()); EXPECT_FALSE(ty->Is<Alias>());
@ -62,71 +62,66 @@ TEST_F(ArrayTest, Is) {
TEST_F(ArrayTest, TypeName) { TEST_F(ArrayTest, TypeName) {
I32 i32; I32 i32;
Array arr{&i32, 0, ast::ArrayDecorationList{}}; Array arr{&i32, 0, ast::DecorationList{}};
EXPECT_EQ(arr.type_name(), "__array__i32"); EXPECT_EQ(arr.type_name(), "__array__i32");
} }
TEST_F(ArrayTest, FriendlyNameRuntimeSized) { TEST_F(ArrayTest, FriendlyNameRuntimeSized) {
Array arr{ty.i32(), 0, ast::ArrayDecorationList{}}; Array arr{ty.i32(), 0, ast::DecorationList{}};
EXPECT_EQ(arr.FriendlyName(Symbols()), "array<i32>"); EXPECT_EQ(arr.FriendlyName(Symbols()), "array<i32>");
} }
TEST_F(ArrayTest, FriendlyNameStaticSized) { TEST_F(ArrayTest, FriendlyNameStaticSized) {
Array arr{ty.i32(), 5, ast::ArrayDecorationList{}}; Array arr{ty.i32(), 5, ast::DecorationList{}};
EXPECT_EQ(arr.FriendlyName(Symbols()), "array<i32, 5>"); EXPECT_EQ(arr.FriendlyName(Symbols()), "array<i32, 5>");
} }
TEST_F(ArrayTest, FriendlyNameWithStride) { TEST_F(ArrayTest, FriendlyNameWithStride) {
Array arr{ty.i32(), 5, Array arr{ty.i32(), 5,
ast::ArrayDecorationList{create<ast::StrideDecoration>(32)}}; ast::DecorationList{create<ast::StrideDecoration>(32)}};
EXPECT_EQ(arr.FriendlyName(Symbols()), "[[stride(32)]] array<i32, 5>"); EXPECT_EQ(arr.FriendlyName(Symbols()), "[[stride(32)]] array<i32, 5>");
} }
TEST_F(ArrayTest, TypeName_RuntimeArray) { TEST_F(ArrayTest, TypeName_RuntimeArray) {
I32 i32; I32 i32;
Array arr{&i32, 3, ast::ArrayDecorationList{}}; Array arr{&i32, 3, ast::DecorationList{}};
EXPECT_EQ(arr.type_name(), "__array__i32_3"); EXPECT_EQ(arr.type_name(), "__array__i32_3");
} }
TEST_F(ArrayTest, TypeName_WithStride) { TEST_F(ArrayTest, TypeName_WithStride) {
I32 i32; I32 i32;
Array arr{&i32, 3, Array arr{&i32, 3, ast::DecorationList{create<ast::StrideDecoration>(16)}};
ast::ArrayDecorationList{create<ast::StrideDecoration>(16)}};
EXPECT_EQ(arr.type_name(), "__array__i32_3_stride_16"); EXPECT_EQ(arr.type_name(), "__array__i32_3_stride_16");
} }
TEST_F(ArrayTest, MinBufferBindingSizeNoStride) { TEST_F(ArrayTest, MinBufferBindingSizeNoStride) {
U32 u32; U32 u32;
Array arr(&u32, 4, ast::ArrayDecorationList{}); Array arr(&u32, 4, ast::DecorationList{});
EXPECT_EQ(0u, arr.MinBufferBindingSize(MemoryLayout::kUniformBuffer)); EXPECT_EQ(0u, arr.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
} }
TEST_F(ArrayTest, MinBufferBindingSizeArray) { TEST_F(ArrayTest, MinBufferBindingSizeArray) {
U32 u32; U32 u32;
Array arr(&u32, 4, Array arr(&u32, 4, ast::DecorationList{create<ast::StrideDecoration>(4)});
ast::ArrayDecorationList{create<ast::StrideDecoration>(4)});
EXPECT_EQ(16u, arr.MinBufferBindingSize(MemoryLayout::kUniformBuffer)); EXPECT_EQ(16u, arr.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
} }
TEST_F(ArrayTest, MinBufferBindingSizeRuntimeArray) { TEST_F(ArrayTest, MinBufferBindingSizeRuntimeArray) {
U32 u32; U32 u32;
Array arr(&u32, 0, Array arr(&u32, 0, ast::DecorationList{create<ast::StrideDecoration>(4)});
ast::ArrayDecorationList{create<ast::StrideDecoration>(4)});
EXPECT_EQ(4u, arr.MinBufferBindingSize(MemoryLayout::kUniformBuffer)); EXPECT_EQ(4u, arr.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
} }
TEST_F(ArrayTest, BaseAlignmentArray) { TEST_F(ArrayTest, BaseAlignmentArray) {
U32 u32; U32 u32;
Array arr(&u32, 4, Array arr(&u32, 4, ast::DecorationList{create<ast::StrideDecoration>(4)});
ast::ArrayDecorationList{create<ast::StrideDecoration>(4)});
EXPECT_EQ(16u, arr.BaseAlignment(MemoryLayout::kUniformBuffer)); EXPECT_EQ(16u, arr.BaseAlignment(MemoryLayout::kUniformBuffer));
EXPECT_EQ(4u, arr.BaseAlignment(MemoryLayout::kStorageBuffer)); EXPECT_EQ(4u, arr.BaseAlignment(MemoryLayout::kStorageBuffer));
} }
TEST_F(ArrayTest, BaseAlignmentRuntimeArray) { TEST_F(ArrayTest, BaseAlignmentRuntimeArray) {
U32 u32; U32 u32;
Array arr(&u32, 0, Array arr(&u32, 0, ast::DecorationList{create<ast::StrideDecoration>(4)});
ast::ArrayDecorationList{create<ast::StrideDecoration>(4)});
EXPECT_EQ(16u, arr.BaseAlignment(MemoryLayout::kUniformBuffer)); EXPECT_EQ(16u, arr.BaseAlignment(MemoryLayout::kUniformBuffer));
EXPECT_EQ(4u, arr.BaseAlignment(MemoryLayout::kStorageBuffer)); EXPECT_EQ(4u, arr.BaseAlignment(MemoryLayout::kStorageBuffer));
} }

View File

@ -53,7 +53,7 @@ uint64_t Matrix::MinBufferBindingSize(MemoryLayout mem_layout) const {
uint64_t Matrix::BaseAlignment(MemoryLayout mem_layout) const { uint64_t Matrix::BaseAlignment(MemoryLayout mem_layout) const {
Vector vec(subtype_, rows_); Vector vec(subtype_, rows_);
Array arr(&vec, columns_, ast::ArrayDecorationList{}); Array arr(&vec, columns_, ast::DecorationList{});
return arr.BaseAlignment(mem_layout); return arr.BaseAlignment(mem_layout);
} }

View File

@ -24,7 +24,7 @@ using StructTypeTest = TestHelper;
TEST_F(StructTypeTest, Creation) { TEST_F(StructTypeTest, Creation) {
auto* impl = auto* impl =
create<ast::Struct>(ast::StructMemberList{}, ast::StructDecorationList{}); create<ast::Struct>(ast::StructMemberList{}, ast::DecorationList{});
auto* ptr = impl; auto* ptr = impl;
auto* s = ty.struct_("S", impl); auto* s = ty.struct_("S", impl);
EXPECT_EQ(s->impl(), ptr); EXPECT_EQ(s->impl(), ptr);
@ -32,7 +32,7 @@ TEST_F(StructTypeTest, Creation) {
TEST_F(StructTypeTest, Is) { TEST_F(StructTypeTest, Is) {
auto* impl = auto* impl =
create<ast::Struct>(ast::StructMemberList{}, ast::StructDecorationList{}); create<ast::Struct>(ast::StructMemberList{}, ast::DecorationList{});
auto* s = ty.struct_("S", impl); auto* s = ty.struct_("S", impl);
type::Type* ty = s; type::Type* ty = s;
EXPECT_FALSE(ty->Is<AccessControl>()); EXPECT_FALSE(ty->Is<AccessControl>());
@ -52,14 +52,14 @@ TEST_F(StructTypeTest, Is) {
TEST_F(StructTypeTest, TypeName) { TEST_F(StructTypeTest, TypeName) {
auto* impl = auto* impl =
create<ast::Struct>(ast::StructMemberList{}, ast::StructDecorationList{}); create<ast::Struct>(ast::StructMemberList{}, ast::DecorationList{});
auto* s = ty.struct_("my_struct", impl); auto* s = ty.struct_("my_struct", impl);
EXPECT_EQ(s->type_name(), "__struct_tint_symbol_1"); EXPECT_EQ(s->type_name(), "__struct_tint_symbol_1");
} }
TEST_F(StructTypeTest, FriendlyName) { TEST_F(StructTypeTest, FriendlyName) {
auto* impl = auto* impl =
create<ast::Struct>(ast::StructMemberList{}, ast::StructDecorationList{}); create<ast::Struct>(ast::StructMemberList{}, ast::DecorationList{});
auto* s = ty.struct_("my_struct", impl); auto* s = ty.struct_("my_struct", impl);
EXPECT_EQ(s->FriendlyName(Symbols()), "my_struct"); EXPECT_EQ(s->FriendlyName(Symbols()), "my_struct");
} }
@ -68,7 +68,7 @@ TEST_F(StructTypeTest, MinBufferBindingSize) {
auto* str = create<ast::Struct>( auto* str = create<ast::Struct>(
ast::StructMemberList{Member("foo", ty.u32(), {MemberOffset(0)}), ast::StructMemberList{Member("foo", ty.u32(), {MemberOffset(0)}),
Member("bar", ty.u32(), {MemberOffset(4)})}, Member("bar", ty.u32(), {MemberOffset(4)})},
ast::StructDecorationList{}); ast::DecorationList{});
auto* s_ty = ty.struct_("s_ty", str); auto* s_ty = ty.struct_("s_ty", str);
EXPECT_EQ(16u, s_ty->MinBufferBindingSize(MemoryLayout::kUniformBuffer)); EXPECT_EQ(16u, s_ty->MinBufferBindingSize(MemoryLayout::kUniformBuffer));
@ -76,14 +76,13 @@ TEST_F(StructTypeTest, MinBufferBindingSize) {
} }
TEST_F(StructTypeTest, MinBufferBindingSizeArray) { TEST_F(StructTypeTest, MinBufferBindingSizeArray) {
Array arr(ty.u32(), 4, Array arr(ty.u32(), 4, ast::DecorationList{create<ast::StrideDecoration>(4)});
ast::ArrayDecorationList{create<ast::StrideDecoration>(4)});
auto* str = create<ast::Struct>( auto* str = create<ast::Struct>(
ast::StructMemberList{Member("foo", ty.u32(), {MemberOffset(0)}), ast::StructMemberList{Member("foo", ty.u32(), {MemberOffset(0)}),
Member("bar", ty.u32(), {MemberOffset(4)}), Member("bar", ty.u32(), {MemberOffset(4)}),
Member("bar", &arr, {MemberOffset(8)})}, Member("bar", &arr, {MemberOffset(8)})},
ast::StructDecorationList{}); ast::DecorationList{});
auto* s_ty = ty.struct_("s_ty", str); auto* s_ty = ty.struct_("s_ty", str);
EXPECT_EQ(32u, s_ty->MinBufferBindingSize(MemoryLayout::kUniformBuffer)); EXPECT_EQ(32u, s_ty->MinBufferBindingSize(MemoryLayout::kUniformBuffer));
@ -91,14 +90,13 @@ TEST_F(StructTypeTest, MinBufferBindingSizeArray) {
} }
TEST_F(StructTypeTest, MinBufferBindingSizeRuntimeArray) { TEST_F(StructTypeTest, MinBufferBindingSizeRuntimeArray) {
Array arr(ty.u32(), 0, Array arr(ty.u32(), 0, ast::DecorationList{create<ast::StrideDecoration>(4)});
ast::ArrayDecorationList{create<ast::StrideDecoration>(4)});
auto* str = create<ast::Struct>( auto* str = create<ast::Struct>(
ast::StructMemberList{Member("foo", ty.u32(), {MemberOffset(0)}), ast::StructMemberList{Member("foo", ty.u32(), {MemberOffset(0)}),
Member("bar", ty.u32(), {MemberOffset(4)}), Member("bar", ty.u32(), {MemberOffset(4)}),
Member("bar", ty.u32(), {MemberOffset(8)})}, Member("bar", ty.u32(), {MemberOffset(8)})},
ast::StructDecorationList{}); ast::DecorationList{});
auto* s_ty = ty.struct_("s_ty", str); auto* s_ty = ty.struct_("s_ty", str);
EXPECT_EQ(12u, s_ty->MinBufferBindingSize(MemoryLayout::kStorageBuffer)); EXPECT_EQ(12u, s_ty->MinBufferBindingSize(MemoryLayout::kStorageBuffer));
@ -107,7 +105,7 @@ TEST_F(StructTypeTest, MinBufferBindingSizeRuntimeArray) {
TEST_F(StructTypeTest, MinBufferBindingSizeVec2) { TEST_F(StructTypeTest, MinBufferBindingSizeVec2) {
auto* str = create<ast::Struct>( auto* str = create<ast::Struct>(
ast::StructMemberList{Member("foo", ty.vec2<u32>(), {MemberOffset(0)})}, ast::StructMemberList{Member("foo", ty.vec2<u32>(), {MemberOffset(0)})},
ast::StructDecorationList{}); ast::DecorationList{});
auto* s_ty = ty.struct_("s_ty", str); auto* s_ty = ty.struct_("s_ty", str);
EXPECT_EQ(16u, s_ty->MinBufferBindingSize(MemoryLayout::kUniformBuffer)); EXPECT_EQ(16u, s_ty->MinBufferBindingSize(MemoryLayout::kUniformBuffer));
@ -117,7 +115,7 @@ TEST_F(StructTypeTest, MinBufferBindingSizeVec2) {
TEST_F(StructTypeTest, MinBufferBindingSizeVec3) { TEST_F(StructTypeTest, MinBufferBindingSizeVec3) {
auto* str = create<ast::Struct>( auto* str = create<ast::Struct>(
ast::StructMemberList{Member("foo", ty.vec3<u32>(), {MemberOffset(0)})}, ast::StructMemberList{Member("foo", ty.vec3<u32>(), {MemberOffset(0)})},
ast::StructDecorationList{}); ast::DecorationList{});
auto* s_ty = ty.struct_("s_ty", str); auto* s_ty = ty.struct_("s_ty", str);
EXPECT_EQ(16u, s_ty->MinBufferBindingSize(MemoryLayout::kUniformBuffer)); EXPECT_EQ(16u, s_ty->MinBufferBindingSize(MemoryLayout::kUniformBuffer));
@ -127,7 +125,7 @@ TEST_F(StructTypeTest, MinBufferBindingSizeVec3) {
TEST_F(StructTypeTest, MinBufferBindingSizeVec4) { TEST_F(StructTypeTest, MinBufferBindingSizeVec4) {
auto* str = create<ast::Struct>( auto* str = create<ast::Struct>(
ast::StructMemberList{Member("foo", ty.vec4<u32>(), {MemberOffset(0)})}, ast::StructMemberList{Member("foo", ty.vec4<u32>(), {MemberOffset(0)})},
ast::StructDecorationList{}); ast::DecorationList{});
auto* s_ty = ty.struct_("s_ty", str); auto* s_ty = ty.struct_("s_ty", str);
EXPECT_EQ(16u, s_ty->MinBufferBindingSize(MemoryLayout::kUniformBuffer)); EXPECT_EQ(16u, s_ty->MinBufferBindingSize(MemoryLayout::kUniformBuffer));
@ -138,7 +136,7 @@ TEST_F(StructTypeTest, BaseAlignment) {
auto* str = create<ast::Struct>( auto* str = create<ast::Struct>(
ast::StructMemberList{Member("foo", ty.u32(), {MemberOffset(0)}), ast::StructMemberList{Member("foo", ty.u32(), {MemberOffset(0)}),
Member("bar", ty.u32(), {MemberOffset(8)})}, Member("bar", ty.u32(), {MemberOffset(8)})},
ast::StructDecorationList{}); ast::DecorationList{});
auto* s_ty = ty.struct_("s_ty", str); auto* s_ty = ty.struct_("s_ty", str);
EXPECT_EQ(16u, s_ty->BaseAlignment(MemoryLayout::kUniformBuffer)); EXPECT_EQ(16u, s_ty->BaseAlignment(MemoryLayout::kUniformBuffer));
@ -146,13 +144,12 @@ TEST_F(StructTypeTest, BaseAlignment) {
} }
TEST_F(StructTypeTest, BaseAlignmentArray) { TEST_F(StructTypeTest, BaseAlignmentArray) {
Array arr(ty.u32(), 4, Array arr(ty.u32(), 4, ast::DecorationList{create<ast::StrideDecoration>(4)});
ast::ArrayDecorationList{create<ast::StrideDecoration>(4)});
auto* str = create<ast::Struct>( auto* str = create<ast::Struct>(
ast::StructMemberList{Member("foo", ty.u32(), {MemberOffset(0)}), ast::StructMemberList{Member("foo", ty.u32(), {MemberOffset(0)}),
Member("bar", ty.u32(), {MemberOffset(4)}), Member("bar", ty.u32(), {MemberOffset(4)}),
Member("bar", &arr, {MemberOffset(8)})}, Member("bar", &arr, {MemberOffset(8)})},
ast::StructDecorationList{}); ast::DecorationList{});
auto* s_ty = ty.struct_("s_ty", str); auto* s_ty = ty.struct_("s_ty", str);
EXPECT_EQ(16u, s_ty->BaseAlignment(MemoryLayout::kUniformBuffer)); EXPECT_EQ(16u, s_ty->BaseAlignment(MemoryLayout::kUniformBuffer));
@ -160,13 +157,12 @@ TEST_F(StructTypeTest, BaseAlignmentArray) {
} }
TEST_F(StructTypeTest, BaseAlignmentRuntimeArray) { TEST_F(StructTypeTest, BaseAlignmentRuntimeArray) {
Array arr(ty.u32(), 0, Array arr(ty.u32(), 0, ast::DecorationList{create<ast::StrideDecoration>(4)});
ast::ArrayDecorationList{create<ast::StrideDecoration>(4)});
auto* str = create<ast::Struct>( auto* str = create<ast::Struct>(
ast::StructMemberList{Member("foo", ty.u32(), {MemberOffset(0)}), ast::StructMemberList{Member("foo", ty.u32(), {MemberOffset(0)}),
Member("bar", ty.u32(), {MemberOffset(4)}), Member("bar", ty.u32(), {MemberOffset(4)}),
Member("bar", ty.u32(), {MemberOffset(8)})}, Member("bar", ty.u32(), {MemberOffset(8)})},
ast::StructDecorationList{}); ast::DecorationList{});
auto* s_ty = ty.struct_("s_ty", str); auto* s_ty = ty.struct_("s_ty", str);
EXPECT_EQ(4u, s_ty->BaseAlignment(MemoryLayout::kStorageBuffer)); EXPECT_EQ(4u, s_ty->BaseAlignment(MemoryLayout::kStorageBuffer));
@ -175,7 +171,7 @@ TEST_F(StructTypeTest, BaseAlignmentRuntimeArray) {
TEST_F(StructTypeTest, BaseAlignmentVec2) { TEST_F(StructTypeTest, BaseAlignmentVec2) {
auto* str = create<ast::Struct>( auto* str = create<ast::Struct>(
ast::StructMemberList{Member("foo", ty.vec2<u32>(), {MemberOffset(0)})}, ast::StructMemberList{Member("foo", ty.vec2<u32>(), {MemberOffset(0)})},
ast::StructDecorationList{}); ast::DecorationList{});
auto* s_ty = ty.struct_("s_ty", str); auto* s_ty = ty.struct_("s_ty", str);
EXPECT_EQ(16u, s_ty->BaseAlignment(MemoryLayout::kUniformBuffer)); EXPECT_EQ(16u, s_ty->BaseAlignment(MemoryLayout::kUniformBuffer));
@ -185,7 +181,7 @@ TEST_F(StructTypeTest, BaseAlignmentVec2) {
TEST_F(StructTypeTest, BaseAlignmentVec3) { TEST_F(StructTypeTest, BaseAlignmentVec3) {
auto* str = create<ast::Struct>( auto* str = create<ast::Struct>(
ast::StructMemberList{Member("foo", ty.vec3<u32>(), {MemberOffset(0)})}, ast::StructMemberList{Member("foo", ty.vec3<u32>(), {MemberOffset(0)})},
ast::StructDecorationList{}); ast::DecorationList{});
auto* s_ty = ty.struct_("s_ty", str); auto* s_ty = ty.struct_("s_ty", str);
EXPECT_EQ(16u, s_ty->BaseAlignment(MemoryLayout::kUniformBuffer)); EXPECT_EQ(16u, s_ty->BaseAlignment(MemoryLayout::kUniformBuffer));
@ -195,7 +191,7 @@ TEST_F(StructTypeTest, BaseAlignmentVec3) {
TEST_F(StructTypeTest, BaseAlignmentVec4) { TEST_F(StructTypeTest, BaseAlignmentVec4) {
auto* str = create<ast::Struct>( auto* str = create<ast::Struct>(
ast::StructMemberList{Member("foo", ty.vec4<u32>(), {MemberOffset(0)})}, ast::StructMemberList{Member("foo", ty.vec4<u32>(), {MemberOffset(0)})},
ast::StructDecorationList{}); ast::DecorationList{});
auto* s_ty = ty.struct_("s_ty", str); auto* s_ty = ty.struct_("s_ty", str);
EXPECT_EQ(16u, s_ty->BaseAlignment(MemoryLayout::kUniformBuffer)); EXPECT_EQ(16u, s_ty->BaseAlignment(MemoryLayout::kUniformBuffer));

View File

@ -0,0 +1,253 @@
// Copyright 2021 The Tint Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "src/ast/access_decoration.h"
#include "src/ast/binding_decoration.h"
#include "src/ast/builtin_decoration.h"
#include "src/ast/constant_id_decoration.h"
#include "src/ast/group_decoration.h"
#include "src/ast/location_decoration.h"
#include "src/ast/stage_decoration.h"
#include "src/ast/struct_block_decoration.h"
#include "src/ast/struct_member_offset_decoration.h"
#include "src/ast/workgroup_decoration.h"
#include "src/validator/validator_test_helper.h"
namespace tint {
namespace {
enum class DecorationKind {
kAccess,
kBinding,
kBuiltin,
kConstantId,
kGroup,
kLocation,
kStage,
kStride,
kStructBlock,
kStructMemberOffset,
kWorkgroup,
};
struct DecorationTestParams {
DecorationKind kind;
bool should_pass;
};
class ValidatorDecorationsTestWithParams
: public ValidatorTestHelper,
public testing::TestWithParam<DecorationTestParams> {};
ast::Decoration* createDecoration(ProgramBuilder& builder,
DecorationKind kind) {
switch (kind) {
case DecorationKind::kAccess:
return builder.create<ast::AccessDecoration>(
ast::AccessControl::kReadOnly);
case DecorationKind::kLocation:
return builder.create<ast::LocationDecoration>(1);
case DecorationKind::kBinding:
return builder.create<ast::BindingDecoration>(1);
case DecorationKind::kGroup:
return builder.create<ast::GroupDecoration>(1u);
case DecorationKind::kBuiltin:
return builder.create<ast::BuiltinDecoration>(ast::Builtin::kPosition);
case DecorationKind::kWorkgroup:
return builder.create<ast::WorkgroupDecoration>(1u, 1u, 1u);
case DecorationKind::kStage:
return builder.create<ast::StageDecoration>(ast::PipelineStage::kCompute);
case DecorationKind::kStructBlock:
return builder.create<ast::StructBlockDecoration>();
case DecorationKind::kStride:
return builder.create<ast::StrideDecoration>(4u);
case DecorationKind::kStructMemberOffset:
return builder.create<ast::StructMemberOffsetDecoration>(4u);
case DecorationKind::kConstantId:
return builder.create<ast::ConstantIdDecoration>(0u);
}
}
using ArrayDecorationTest = ValidatorDecorationsTestWithParams;
TEST_P(ArrayDecorationTest, Decoration_IsValid) {
auto params = GetParam();
ast::StructMemberList members{Member(
"a", create<type::Array>(
ty.f32(), 0,
ast::DecorationList{createDecoration(*this, params.kind)}))};
auto* s = create<ast::Struct>(
members, ast::DecorationList{create<ast::StructBlockDecoration>()});
auto* s_ty = ty.struct_("mystruct", s);
ValidatorImpl& v = Build();
if (params.should_pass) {
EXPECT_TRUE(v.ValidateConstructedType(s_ty));
} else {
EXPECT_FALSE(v.ValidateConstructedType(s_ty));
EXPECT_EQ(v.error(), "decoration is not valid for array types");
}
}
INSTANTIATE_TEST_SUITE_P(
ValidatorTest,
ArrayDecorationTest,
testing::Values(DecorationTestParams{DecorationKind::kAccess, false},
DecorationTestParams{DecorationKind::kBinding, false},
DecorationTestParams{DecorationKind::kBuiltin, false},
DecorationTestParams{DecorationKind::kConstantId, false},
DecorationTestParams{DecorationKind::kGroup, false},
DecorationTestParams{DecorationKind::kLocation, false},
DecorationTestParams{DecorationKind::kStage, false},
DecorationTestParams{DecorationKind::kStride, true},
DecorationTestParams{DecorationKind::kStructBlock, false},
DecorationTestParams{DecorationKind::kStructMemberOffset,
false},
DecorationTestParams{DecorationKind::kWorkgroup, false}));
using FunctionDecorationTest = ValidatorDecorationsTestWithParams;
TEST_P(FunctionDecorationTest, Decoration_IsValid) {
auto params = GetParam();
Func("foo", ast::VariableList{}, ty.void_(), ast::StatementList{},
ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kCompute),
createDecoration(*this, params.kind)});
ValidatorImpl& v = Build();
if (params.should_pass) {
EXPECT_TRUE(v.Validate());
} else {
EXPECT_FALSE(v.Validate());
EXPECT_EQ(v.error(), "decoration is not valid for functions");
}
}
INSTANTIATE_TEST_SUITE_P(
ValidatorTest,
FunctionDecorationTest,
testing::Values(DecorationTestParams{DecorationKind::kAccess, false},
DecorationTestParams{DecorationKind::kBinding, false},
DecorationTestParams{DecorationKind::kBuiltin, false},
DecorationTestParams{DecorationKind::kConstantId, false},
DecorationTestParams{DecorationKind::kGroup, false},
DecorationTestParams{DecorationKind::kLocation, false},
// Skip kStage as we always apply it in this test
DecorationTestParams{DecorationKind::kStride, false},
DecorationTestParams{DecorationKind::kStructBlock, false},
DecorationTestParams{DecorationKind::kStructMemberOffset,
false},
DecorationTestParams{DecorationKind::kWorkgroup, true}));
using StructDecorationTest = ValidatorDecorationsTestWithParams;
TEST_P(StructDecorationTest, Decoration_IsValid) {
auto params = GetParam();
auto* s = create<ast::Struct>(
ast::StructMemberList{},
ast::DecorationList{createDecoration(*this, params.kind)});
auto* s_ty = ty.struct_("mystruct", s);
ValidatorImpl& v = Build();
if (params.should_pass) {
EXPECT_TRUE(v.ValidateConstructedType(s_ty));
} else {
EXPECT_FALSE(v.ValidateConstructedType(s_ty));
EXPECT_EQ(v.error(), "decoration is not valid for struct declarations");
}
}
INSTANTIATE_TEST_SUITE_P(
ValidatorTest,
StructDecorationTest,
testing::Values(DecorationTestParams{DecorationKind::kAccess, false},
DecorationTestParams{DecorationKind::kBinding, false},
DecorationTestParams{DecorationKind::kBuiltin, false},
DecorationTestParams{DecorationKind::kConstantId, false},
DecorationTestParams{DecorationKind::kGroup, false},
DecorationTestParams{DecorationKind::kLocation, false},
DecorationTestParams{DecorationKind::kStage, false},
DecorationTestParams{DecorationKind::kStride, false},
DecorationTestParams{DecorationKind::kStructBlock, true},
DecorationTestParams{DecorationKind::kStructMemberOffset,
false},
DecorationTestParams{DecorationKind::kWorkgroup, false}));
using StructMemberDecorations = ValidatorDecorationsTestWithParams;
TEST_P(StructMemberDecorations, Decoration_IsValid) {
auto params = GetParam();
ast::StructMemberList members{
Member("a", ty.i32(),
ast::DecorationList{createDecoration(*this, params.kind)})};
auto* s = create<ast::Struct>(members, ast::DecorationList{});
auto* s_ty = ty.struct_("mystruct", s);
ValidatorImpl& v = Build();
if (params.should_pass) {
EXPECT_TRUE(v.ValidateConstructedType(s_ty));
} else {
EXPECT_FALSE(v.ValidateConstructedType(s_ty));
EXPECT_EQ(v.error(), "decoration is not valid for structure members");
}
}
INSTANTIATE_TEST_SUITE_P(
ValidatorTest,
StructMemberDecorations,
testing::Values(DecorationTestParams{DecorationKind::kAccess, false},
DecorationTestParams{DecorationKind::kBinding, false},
DecorationTestParams{DecorationKind::kBuiltin, true},
DecorationTestParams{DecorationKind::kConstantId, false},
DecorationTestParams{DecorationKind::kGroup, false},
DecorationTestParams{DecorationKind::kLocation, true},
DecorationTestParams{DecorationKind::kStage, false},
DecorationTestParams{DecorationKind::kStride, false},
DecorationTestParams{DecorationKind::kStructBlock, false},
DecorationTestParams{DecorationKind::kStructMemberOffset,
true},
DecorationTestParams{DecorationKind::kWorkgroup, false}));
using VariableDecorationTest = ValidatorDecorationsTestWithParams;
TEST_P(VariableDecorationTest, Decoration_IsValid) {
auto params = GetParam();
auto* var = Global("a", ty.f32(), ast::StorageClass::kInput, nullptr,
ast::DecorationList{createDecoration(*this, params.kind)});
ValidatorImpl& v = Build();
if (params.should_pass) {
EXPECT_TRUE(v.ValidateGlobalVariable(var));
} else {
EXPECT_FALSE(v.ValidateGlobalVariable(var));
EXPECT_EQ(v.error(), "decoration is not valid for variables");
}
}
INSTANTIATE_TEST_SUITE_P(
ValidatorTest,
VariableDecorationTest,
testing::Values(DecorationTestParams{DecorationKind::kAccess, false},
DecorationTestParams{DecorationKind::kBinding, true},
DecorationTestParams{DecorationKind::kBuiltin, true},
DecorationTestParams{DecorationKind::kConstantId, true},
DecorationTestParams{DecorationKind::kGroup, true},
DecorationTestParams{DecorationKind::kLocation, true},
DecorationTestParams{DecorationKind::kStage, false},
DecorationTestParams{DecorationKind::kStride, false},
DecorationTestParams{DecorationKind::kStructBlock, false},
DecorationTestParams{DecorationKind::kStructMemberOffset,
false},
DecorationTestParams{DecorationKind::kWorkgroup, false}));
} // namespace
} // namespace tint

View File

@ -31,7 +31,7 @@ TEST_F(ValidateFunctionTest, VoidFunctionEndWithoutReturnStatement_Pass) {
ast::StatementList{ ast::StatementList{
create<ast::VariableDeclStatement>(var), create<ast::VariableDeclStatement>(var),
}, },
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
@ -47,7 +47,7 @@ TEST_F(ValidateFunctionTest,
Func(Source{Source::Location{12, 34}}, "func", ast::VariableList{}, Func(Source{Source::Location{12, 34}}, "func", ast::VariableList{},
ty.void_(), ast::StatementList{}, ty.void_(), ast::StatementList{},
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
@ -65,7 +65,7 @@ TEST_F(ValidateFunctionTest, FunctionEndWithoutReturnStatement_Fail) {
ast::StatementList{ ast::StatementList{
create<ast::VariableDeclStatement>(var), create<ast::VariableDeclStatement>(var),
}, },
ast::FunctionDecorationList{}); ast::DecorationList{});
ValidatorImpl& v = Build(); ValidatorImpl& v = Build();
@ -78,7 +78,7 @@ TEST_F(ValidateFunctionTest, FunctionEndWithoutReturnStatementEmptyBody_Fail) {
// fn func -> int {} // fn func -> int {}
Func(Source{Source::Location{12, 34}}, "func", ast::VariableList{}, ty.i32(), Func(Source{Source::Location{12, 34}}, "func", ast::VariableList{}, ty.i32(),
ast::StatementList{}, ast::FunctionDecorationList{}); ast::StatementList{}, ast::DecorationList{});
ValidatorImpl& v = Build(); ValidatorImpl& v = Build();
@ -95,7 +95,7 @@ TEST_F(ValidateFunctionTest, FunctionTypeMustMatchReturnStatementType_Pass) {
ast::StatementList{ ast::StatementList{
create<ast::ReturnStatement>(), create<ast::ReturnStatement>(),
}, },
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
@ -111,7 +111,7 @@ TEST_F(ValidateFunctionTest, FunctionTypeMustMatchReturnStatementType_fail) {
create<ast::ReturnStatement>(Source{Source::Location{12, 34}}, create<ast::ReturnStatement>(Source{Source::Location{12, 34}},
Expr(2)), Expr(2)),
}, },
ast::FunctionDecorationList{}); ast::DecorationList{});
ValidatorImpl& v = Build(); ValidatorImpl& v = Build();
@ -129,7 +129,7 @@ TEST_F(ValidateFunctionTest, FunctionTypeMustMatchReturnStatementTypeF32_fail) {
create<ast::ReturnStatement>(Source{Source::Location{12, 34}}, create<ast::ReturnStatement>(Source{Source::Location{12, 34}},
Expr(2)), Expr(2)),
}, },
ast::FunctionDecorationList{}); ast::DecorationList{});
ValidatorImpl& v = Build(); ValidatorImpl& v = Build();
@ -147,13 +147,13 @@ TEST_F(ValidateFunctionTest, FunctionNamesMustBeUnique_fail) {
ast::StatementList{ ast::StatementList{
create<ast::ReturnStatement>(Expr(2)), create<ast::ReturnStatement>(Expr(2)),
}, },
ast::FunctionDecorationList{}); ast::DecorationList{});
Func(Source{Source::Location{12, 34}}, "func", ast::VariableList{}, ty.i32(), Func(Source{Source::Location{12, 34}}, "func", ast::VariableList{}, ty.i32(),
ast::StatementList{ ast::StatementList{
create<ast::ReturnStatement>(Expr(2)), create<ast::ReturnStatement>(Expr(2)),
}, },
ast::FunctionDecorationList{}); ast::DecorationList{});
ValidatorImpl& v = Build(); ValidatorImpl& v = Build();
@ -170,7 +170,7 @@ TEST_F(ValidateFunctionTest, PipelineStage_MustBeUnique_Fail) {
ast::StatementList{ ast::StatementList{
create<ast::ReturnStatement>(), create<ast::ReturnStatement>(),
}, },
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
create<ast::StageDecoration>(ast::PipelineStage::kFragment), create<ast::StageDecoration>(ast::PipelineStage::kFragment),
}); });
@ -191,7 +191,7 @@ TEST_F(ValidateFunctionTest, OnePipelineStageFunctionMustBePresent_Pass) {
ast::StatementList{ ast::StatementList{
create<ast::ReturnStatement>(), create<ast::ReturnStatement>(),
}, },
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
@ -206,7 +206,7 @@ TEST_F(ValidateFunctionTest, OnePipelineStageFunctionMustBePresent_Fail) {
ast::StatementList{ ast::StatementList{
create<ast::ReturnStatement>(), create<ast::ReturnStatement>(),
}, },
ast::FunctionDecorationList{}); ast::DecorationList{});
ValidatorImpl& v = Build(); ValidatorImpl& v = Build();

View File

@ -17,10 +17,15 @@
#include <utility> #include <utility>
#include "src/ast/call_statement.h" #include "src/ast/call_statement.h"
#include "src/ast/constant_id_decoration.h"
#include "src/ast/fallthrough_statement.h" #include "src/ast/fallthrough_statement.h"
#include "src/ast/sint_literal.h" #include "src/ast/sint_literal.h"
#include "src/ast/stage_decoration.h" #include "src/ast/stage_decoration.h"
#include "src/ast/stride_decoration.h"
#include "src/ast/struct_block_decoration.h"
#include "src/ast/struct_member_offset_decoration.h"
#include "src/ast/uint_literal.h" #include "src/ast/uint_literal.h"
#include "src/ast/workgroup_decoration.h"
#include "src/semantic/call.h" #include "src/semantic/call.h"
#include "src/semantic/function.h" #include "src/semantic/function.h"
#include "src/semantic/variable.h" #include "src/semantic/variable.h"
@ -108,8 +113,34 @@ bool ValidatorImpl::ValidateConstructedType(const type::Type* type) {
program_->Symbols().NameFor(st->symbol()) + "'"); program_->Symbols().NameFor(st->symbol()) + "'");
return false; return false;
} }
for (auto* deco : r->decorations()) {
if (!deco->Is<ast::StrideDecoration>()) {
add_error(deco->source(),
"decoration is not valid for array types");
return false;
}
}
} }
} }
for (auto* deco : member->decorations()) {
if (!(deco->Is<ast::BuiltinDecoration>() ||
deco->Is<ast::LocationDecoration>() ||
deco->Is<ast::StructMemberOffsetDecoration>())) {
add_error(deco->source(),
"decoration is not valid for structure members");
return false;
}
}
}
for (auto* deco : st->impl()->decorations()) {
if (!(deco->Is<ast::StructBlockDecoration>())) {
add_error(deco->source(),
"decoration is not valid for struct declarations");
return false;
}
} }
} }
@ -141,6 +172,18 @@ bool ValidatorImpl::ValidateGlobalVariable(const ast::Variable* var) {
"global constants shouldn't have a storage class"); "global constants shouldn't have a storage class");
return false; return false;
} }
for (auto* deco : var->decorations()) {
if (!(deco->Is<ast::BindingDecoration>() ||
deco->Is<ast::BuiltinDecoration>() ||
deco->Is<ast::ConstantIdDecoration>() ||
deco->Is<ast::GroupDecoration>() ||
deco->Is<ast::LocationDecoration>())) {
add_error(deco->source(), "decoration is not valid for variables");
return false;
}
}
variable_stack_.set_global(var->symbol(), var); variable_stack_.set_global(var->symbol(), var);
return true; return true;
} }
@ -154,6 +197,9 @@ bool ValidatorImpl::ValidateEntryPoint(const ast::FunctionList& funcs) {
for (auto* deco : func->decorations()) { for (auto* deco : func->decorations()) {
if (deco->Is<ast::StageDecoration>()) { if (deco->Is<ast::StageDecoration>()) {
stage_deco_count++; stage_deco_count++;
} else if (!deco->Is<ast::WorkgroupDecoration>()) {
add_error(func->source(), "decoration is not valid for functions");
return false;
} }
} }
if (stage_deco_count > 1) { if (stage_deco_count > 1) {

View File

@ -317,7 +317,7 @@ TEST_F(ValidatorTest, GlobalConstantWithStorageClass_Fail) {
AST().AddGlobalVariable(create<ast::Variable>( AST().AddGlobalVariable(create<ast::Variable>(
Source{Source::Location{12, 34}}, Symbols().Register("global_var"), Source{Source::Location{12, 34}}, Symbols().Register("global_var"),
ast::StorageClass::kInput, ty.f32(), true, nullptr, ast::StorageClass::kInput, ty.f32(), true, nullptr,
ast::VariableDecorationList{})); ast::DecorationList{}));
ValidatorImpl& v = Build(); ValidatorImpl& v = Build();
@ -350,7 +350,7 @@ TEST_F(ValidatorTest, UsingUndefinedVariableGlobalVariableAfter_Fail) {
ast::StatementList{ ast::StatementList{
create<ast::AssignmentStatement>(lhs, rhs), create<ast::AssignmentStatement>(lhs, rhs),
}, },
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex)}); create<ast::StageDecoration>(ast::PipelineStage::kVertex)});
Global("global_var", ty.f32(), ast::StorageClass::kPrivate, Expr(2.1f)); Global("global_var", ty.f32(), ast::StorageClass::kPrivate, Expr(2.1f));
@ -376,7 +376,7 @@ TEST_F(ValidatorTest, UsingUndefinedVariableGlobalVariable_Pass) {
Expr("global_var"), Expr(3.14f)), Expr("global_var"), Expr(3.14f)),
create<ast::ReturnStatement>(), create<ast::ReturnStatement>(),
}, },
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
@ -553,7 +553,7 @@ TEST_F(ValidatorTest, GlobalVariableFunctionVariableNotUnique_Pass) {
ast::StatementList{ ast::StatementList{
create<ast::VariableDeclStatement>(var), create<ast::VariableDeclStatement>(var),
}, },
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex)}); create<ast::StageDecoration>(ast::PipelineStage::kVertex)});
Global("a", ty.f32(), ast::StorageClass::kPrivate, Expr(2.1f)); Global("a", ty.f32(), ast::StorageClass::kPrivate, Expr(2.1f));
@ -579,7 +579,7 @@ TEST_F(ValidatorTest, GlobalVariableFunctionVariableNotUnique_Fail) {
create<ast::VariableDeclStatement>(Source{Source::Location{12, 34}}, create<ast::VariableDeclStatement>(Source{Source::Location{12, 34}},
var), var),
}, },
ast::FunctionDecorationList{}); ast::DecorationList{});
ValidatorImpl& v = Build(); ValidatorImpl& v = Build();
@ -602,7 +602,7 @@ TEST_F(ValidatorTest, RedeclaredIdentifier_Fail) {
create<ast::VariableDeclStatement>(Source{Source::Location{12, 34}}, create<ast::VariableDeclStatement>(Source{Source::Location{12, 34}},
var_a_float), var_a_float),
}, },
ast::FunctionDecorationList{}); ast::DecorationList{});
ValidatorImpl& v = Build(); ValidatorImpl& v = Build();
@ -728,7 +728,7 @@ TEST_F(ValidatorTest, RedeclaredIdentifierDifferentFunctions_Pass) {
var0), var0),
create<ast::ReturnStatement>(), create<ast::ReturnStatement>(),
}, },
ast::FunctionDecorationList{}); ast::DecorationList{});
Func("func1", ast::VariableList{}, ty.void_(), Func("func1", ast::VariableList{}, ty.void_(),
ast::StatementList{ ast::StatementList{
@ -736,7 +736,7 @@ TEST_F(ValidatorTest, RedeclaredIdentifierDifferentFunctions_Pass) {
var1), var1),
create<ast::ReturnStatement>(), create<ast::ReturnStatement>(),
}, },
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
@ -898,7 +898,7 @@ TEST_F(ValidatorTest, IsStorable_ArrayUnsizedOfNonStorable) {
TEST_F(ValidatorTest, IsStorable_Struct_AllMembersStorable) { TEST_F(ValidatorTest, IsStorable_Struct_AllMembersStorable) {
ast::StructMemberList members{Member("a", ty.i32()), Member("b", ty.f32())}; ast::StructMemberList members{Member("a", ty.i32()), Member("b", ty.f32())};
auto* s = create<ast::Struct>(Source{}, members, ast::StructDecorationList{}); auto* s = create<ast::Struct>(Source{}, members, ast::DecorationList{});
auto* s_ty = ty.struct_("mystruct", s); auto* s_ty = ty.struct_("mystruct", s);
ValidatorImpl& v = Build(); ValidatorImpl& v = Build();
@ -909,7 +909,7 @@ TEST_F(ValidatorTest, IsStorable_Struct_AllMembersStorable) {
TEST_F(ValidatorTest, IsStorable_Struct_SomeMembersNonStorable) { TEST_F(ValidatorTest, IsStorable_Struct_SomeMembersNonStorable) {
auto* ptr_ty = ty.pointer<int>(ast::StorageClass::kPrivate); auto* ptr_ty = ty.pointer<int>(ast::StorageClass::kPrivate);
ast::StructMemberList members{Member("a", ty.i32()), Member("b", ptr_ty)}; ast::StructMemberList members{Member("a", ty.i32()), Member("b", ptr_ty)};
auto* s = create<ast::Struct>(Source{}, members, ast::StructDecorationList{}); auto* s = create<ast::Struct>(Source{}, members, ast::DecorationList{});
auto* s_ty = ty.struct_("mystruct", s); auto* s_ty = ty.struct_("mystruct", s);
ValidatorImpl& v = Build(); ValidatorImpl& v = Build();

View File

@ -28,7 +28,7 @@ TEST_F(ValidatorTypeTest, RuntimeArrayIsLast_Pass) {
// rt: array<f32>; // rt: array<f32>;
// }; // };
ast::StructDecorationList decos; ast::DecorationList decos;
decos.push_back(create<ast::StructBlockDecoration>()); decos.push_back(create<ast::StructBlockDecoration>());
auto* st = auto* st =
create<ast::Struct>(ast::StructMemberList{Member("vf", ty.f32()), create<ast::Struct>(ast::StructMemberList{Member("vf", ty.f32()),
@ -50,7 +50,7 @@ TEST_F(ValidatorTypeTest, RuntimeArrayIsLastNoBlock_Fail) {
// rt: array<f32>; // rt: array<f32>;
// }; // };
ast::StructDecorationList decos; ast::DecorationList decos;
auto* st = auto* st =
create<ast::Struct>(ast::StructMemberList{Member("vf", ty.f32()), create<ast::Struct>(ast::StructMemberList{Member("vf", ty.f32()),
Member("rt", ty.array<f32>())}, Member("rt", ty.array<f32>())},
@ -74,7 +74,7 @@ TEST_F(ValidatorTypeTest, RuntimeArrayIsNotLast_Fail) {
// vf: f32; // vf: f32;
// }; // };
ast::StructDecorationList decos; ast::DecorationList decos;
decos.push_back(create<ast::StructBlockDecoration>()); decos.push_back(create<ast::StructBlockDecoration>());
SetSource(Source::Location{12, 34}); SetSource(Source::Location{12, 34});
@ -105,7 +105,7 @@ TEST_F(ValidatorTypeTest, AliasRuntimeArrayIsNotLast_Fail) {
auto* alias = ty.alias("RTArr", ty.array<u32>()); auto* alias = ty.alias("RTArr", ty.array<u32>());
ast::StructDecorationList decos; ast::DecorationList decos;
decos.push_back(create<ast::StructBlockDecoration>()); decos.push_back(create<ast::StructBlockDecoration>());
auto* st = create<ast::Struct>( auto* st = create<ast::Struct>(
ast::StructMemberList{Member("b", alias), Member("a", ty.u32())}, decos); ast::StructMemberList{Member("b", alias), Member("a", ty.u32())}, decos);
@ -131,7 +131,7 @@ TEST_F(ValidatorTypeTest, AliasRuntimeArrayIsLast_Pass) {
auto* alias = ty.alias("RTArr", ty.array<u32>()); auto* alias = ty.alias("RTArr", ty.array<u32>());
ast::StructDecorationList decos; ast::DecorationList decos;
decos.push_back(create<ast::StructBlockDecoration>()); decos.push_back(create<ast::StructBlockDecoration>());
auto* st = create<ast::Struct>( auto* st = create<ast::Struct>(
ast::StructMemberList{Member("a", ty.u32()), Member("b", alias)}, decos); ast::StructMemberList{Member("a", ty.u32()), Member("b", alias)}, decos);
@ -155,7 +155,7 @@ TEST_F(ValidatorTypeTest, RuntimeArrayInFunction_Fail) {
create<ast::VariableDeclStatement>(Source{Source::Location{12, 34}}, create<ast::VariableDeclStatement>(Source{Source::Location{12, 34}},
var), var),
}, },
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
@ -178,13 +178,13 @@ TEST_F(ValidatorTypeTest, RuntimeArrayAsParameter_Fail) {
ast::StatementList{ ast::StatementList{
create<ast::ReturnStatement>(), create<ast::ReturnStatement>(),
}, },
ast::FunctionDecorationList{}); ast::DecorationList{});
Func("main", ast::VariableList{}, ty.void_(), Func("main", ast::VariableList{}, ty.void_(),
ast::StatementList{ ast::StatementList{
create<ast::ReturnStatement>(), create<ast::ReturnStatement>(),
}, },
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });

View File

@ -1520,8 +1520,8 @@ bool GeneratorImpl::EmitEntryPointData(
std::ostream& out, std::ostream& out,
ast::Function* func, ast::Function* func,
std::unordered_set<Symbol>& emitted_globals) { std::unordered_set<Symbol>& emitted_globals) {
std::vector<std::pair<ast::Variable*, ast::VariableDecoration*>> in_variables; std::vector<std::pair<ast::Variable*, ast::Decoration*>> in_variables;
std::vector<std::pair<ast::Variable*, ast::VariableDecoration*>> outvariables; std::vector<std::pair<ast::Variable*, ast::Decoration*>> outvariables;
auto* func_sem = builder_.Sem().Get(func); auto* func_sem = builder_.Sem().Get(func);
auto func_sym = func->symbol(); auto func_sym = func->symbol();
@ -2525,7 +2525,7 @@ bool GeneratorImpl::EmitStructType(std::ostream& out,
const type::Struct* str, const type::Struct* str,
const std::string& name) { const std::string& name) {
// TODO(dsinclair): Block decoration? // TODO(dsinclair): Block decoration?
// if (str->impl()->decoration() != ast::StructDecoration::kNone) { // if (str->impl()->decoration() != ast::Decoration::kNone) {
// } // }
out << "struct " << name << " {" << std::endl; out << "struct " << name << " {" << std::endl;

View File

@ -45,7 +45,7 @@ TEST_F(HlslGeneratorImplTest_Alias, EmitAlias_Struct) {
auto* str = create<ast::Struct>( auto* str = create<ast::Struct>(
ast::StructMemberList{Member("a", ty.f32()), ast::StructMemberList{Member("a", ty.f32()),
Member("b", ty.i32(), {MemberOffset(4)})}, Member("b", ty.i32(), {MemberOffset(4)})},
ast::StructDecorationList{}); ast::DecorationList{});
auto* s = ty.struct_("A", str); auto* s = ty.struct_("A", str);
auto* alias = ty.alias("B", s); auto* alias = ty.alias("B", s);

View File

@ -457,7 +457,7 @@ TEST_F(HlslGeneratorImplTest_Binary, Call_WithLogical) {
// foo(a && b, c || d, (a || c) && (b || d)) // foo(a && b, c || d, (a || c) && (b || d))
Func("foo", ast::VariableList{}, ty.void_(), ast::StatementList{}, Func("foo", ast::VariableList{}, ty.void_(), ast::StatementList{},
ast::FunctionDecorationList{}); ast::DecorationList{});
Global("a", ty.bool_(), ast::StorageClass::kNone); Global("a", ty.bool_(), ast::StorageClass::kNone);
Global("b", ty.bool_(), ast::StorageClass::kNone); Global("b", ty.bool_(), ast::StorageClass::kNone);
Global("c", ty.bool_(), ast::StorageClass::kNone); Global("c", ty.bool_(), ast::StorageClass::kNone);

View File

@ -24,7 +24,7 @@ using HlslGeneratorImplTest_Call = TestHelper;
TEST_F(HlslGeneratorImplTest_Call, EmitExpression_Call_WithoutParams) { TEST_F(HlslGeneratorImplTest_Call, EmitExpression_Call_WithoutParams) {
Func("my_func", ast::VariableList{}, ty.void_(), ast::StatementList{}, Func("my_func", ast::VariableList{}, ty.void_(), ast::StatementList{},
ast::FunctionDecorationList{}); ast::DecorationList{});
auto* call = Call("my_func"); auto* call = Call("my_func");
WrapInFunction(call); WrapInFunction(call);
@ -37,7 +37,7 @@ TEST_F(HlslGeneratorImplTest_Call, EmitExpression_Call_WithoutParams) {
TEST_F(HlslGeneratorImplTest_Call, EmitExpression_Call_WithParams) { TEST_F(HlslGeneratorImplTest_Call, EmitExpression_Call_WithParams) {
Func("my_func", ast::VariableList{}, ty.void_(), ast::StatementList{}, Func("my_func", ast::VariableList{}, ty.void_(), ast::StatementList{},
ast::FunctionDecorationList{}); ast::DecorationList{});
Global("param1", ty.f32(), ast::StorageClass::kNone); Global("param1", ty.f32(), ast::StorageClass::kNone);
Global("param2", ty.f32(), ast::StorageClass::kNone); Global("param2", ty.f32(), ast::StorageClass::kNone);
@ -52,7 +52,7 @@ TEST_F(HlslGeneratorImplTest_Call, EmitExpression_Call_WithParams) {
TEST_F(HlslGeneratorImplTest_Call, EmitStatement_Call) { TEST_F(HlslGeneratorImplTest_Call, EmitStatement_Call) {
Func("my_func", ast::VariableList{}, ty.void_(), ast::StatementList{}, Func("my_func", ast::VariableList{}, ty.void_(), ast::StatementList{},
ast::FunctionDecorationList{}); ast::DecorationList{});
Global("param1", ty.f32(), ast::StorageClass::kNone); Global("param1", ty.f32(), ast::StorageClass::kNone);
Global("param2", ty.f32(), ast::StorageClass::kNone); Global("param2", ty.f32(), ast::StorageClass::kNone);

View File

@ -33,12 +33,12 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
// }; // };
Global("foo", ty.f32(), ast::StorageClass::kInput, nullptr, Global("foo", ty.f32(), ast::StorageClass::kInput, nullptr,
ast::VariableDecorationList{ ast::DecorationList{
create<ast::LocationDecoration>(0), create<ast::LocationDecoration>(0),
}); });
Global("bar", ty.i32(), ast::StorageClass::kInput, nullptr, Global("bar", ty.i32(), ast::StorageClass::kInput, nullptr,
ast::VariableDecorationList{ ast::DecorationList{
create<ast::LocationDecoration>(1), create<ast::LocationDecoration>(1),
}); });
@ -47,7 +47,7 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")), create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
create<ast::AssignmentStatement>(Expr("bar"), Expr("bar")), create<ast::AssignmentStatement>(Expr("bar"), Expr("bar")),
}, },
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
@ -76,12 +76,12 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
// }; // };
Global("foo", ty.f32(), ast::StorageClass::kOutput, nullptr, Global("foo", ty.f32(), ast::StorageClass::kOutput, nullptr,
ast::VariableDecorationList{ ast::DecorationList{
create<ast::LocationDecoration>(0), create<ast::LocationDecoration>(0),
}); });
Global("bar", ty.i32(), ast::StorageClass::kOutput, nullptr, Global("bar", ty.i32(), ast::StorageClass::kOutput, nullptr,
ast::VariableDecorationList{ ast::DecorationList{
create<ast::LocationDecoration>(1), create<ast::LocationDecoration>(1),
}); });
@ -90,7 +90,7 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")), create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
create<ast::AssignmentStatement>(Expr("bar"), Expr("bar")), create<ast::AssignmentStatement>(Expr("bar"), Expr("bar")),
}, },
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
@ -119,12 +119,12 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
// }; // };
Global("foo", ty.f32(), ast::StorageClass::kInput, nullptr, Global("foo", ty.f32(), ast::StorageClass::kInput, nullptr,
ast::VariableDecorationList{ ast::DecorationList{
create<ast::LocationDecoration>(0), create<ast::LocationDecoration>(0),
}); });
Global("bar", ty.i32(), ast::StorageClass::kInput, nullptr, Global("bar", ty.i32(), ast::StorageClass::kInput, nullptr,
ast::VariableDecorationList{ ast::DecorationList{
create<ast::LocationDecoration>(1), create<ast::LocationDecoration>(1),
}); });
@ -133,7 +133,7 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")), create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
create<ast::AssignmentStatement>(Expr("bar"), Expr("bar")), create<ast::AssignmentStatement>(Expr("bar"), Expr("bar")),
}, },
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
@ -162,12 +162,12 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
// }; // };
Global("foo", ty.f32(), ast::StorageClass::kOutput, nullptr, Global("foo", ty.f32(), ast::StorageClass::kOutput, nullptr,
ast::VariableDecorationList{ ast::DecorationList{
create<ast::LocationDecoration>(0), create<ast::LocationDecoration>(0),
}); });
Global("bar", ty.i32(), ast::StorageClass::kOutput, nullptr, Global("bar", ty.i32(), ast::StorageClass::kOutput, nullptr,
ast::VariableDecorationList{ ast::DecorationList{
create<ast::LocationDecoration>(1), create<ast::LocationDecoration>(1),
}); });
@ -176,7 +176,7 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")), create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
create<ast::AssignmentStatement>(Expr("bar"), Expr("bar")), create<ast::AssignmentStatement>(Expr("bar"), Expr("bar")),
}, },
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment), create<ast::StageDecoration>(ast::PipelineStage::kFragment),
}); });
@ -202,12 +202,12 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
// -> Error, not allowed // -> Error, not allowed
Global("foo", ty.f32(), ast::StorageClass::kInput, nullptr, Global("foo", ty.f32(), ast::StorageClass::kInput, nullptr,
ast::VariableDecorationList{ ast::DecorationList{
create<ast::LocationDecoration>(0), create<ast::LocationDecoration>(0),
}); });
Global("bar", ty.i32(), ast::StorageClass::kInput, nullptr, Global("bar", ty.i32(), ast::StorageClass::kInput, nullptr,
ast::VariableDecorationList{ ast::DecorationList{
create<ast::LocationDecoration>(1), create<ast::LocationDecoration>(1),
}); });
@ -216,7 +216,7 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")), create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
create<ast::AssignmentStatement>(Expr("bar"), Expr("bar")), create<ast::AssignmentStatement>(Expr("bar"), Expr("bar")),
}, },
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kCompute), create<ast::StageDecoration>(ast::PipelineStage::kCompute),
}); });
@ -238,12 +238,12 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
// -> Error not allowed // -> Error not allowed
Global("foo", ty.f32(), ast::StorageClass::kOutput, nullptr, Global("foo", ty.f32(), ast::StorageClass::kOutput, nullptr,
ast::VariableDecorationList{ ast::DecorationList{
create<ast::LocationDecoration>(0), create<ast::LocationDecoration>(0),
}); });
Global("bar", ty.i32(), ast::StorageClass::kOutput, nullptr, Global("bar", ty.i32(), ast::StorageClass::kOutput, nullptr,
ast::VariableDecorationList{ ast::DecorationList{
create<ast::LocationDecoration>(1), create<ast::LocationDecoration>(1),
}); });
@ -252,7 +252,7 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")), create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
create<ast::AssignmentStatement>(Expr("bar"), Expr("bar")), create<ast::AssignmentStatement>(Expr("bar"), Expr("bar")),
}, },
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kCompute), create<ast::StageDecoration>(ast::PipelineStage::kCompute),
}); });
@ -280,12 +280,12 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
// }; // };
Global("coord", ty.vec4<f32>(), ast::StorageClass::kInput, nullptr, Global("coord", ty.vec4<f32>(), ast::StorageClass::kInput, nullptr,
ast::VariableDecorationList{ ast::DecorationList{
create<ast::BuiltinDecoration>(ast::Builtin::kFragCoord), create<ast::BuiltinDecoration>(ast::Builtin::kFragCoord),
}); });
Global("depth", ty.f32(), ast::StorageClass::kOutput, nullptr, Global("depth", ty.f32(), ast::StorageClass::kOutput, nullptr,
ast::VariableDecorationList{ ast::DecorationList{
create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth), create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth),
}); });
@ -294,7 +294,7 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
create<ast::AssignmentStatement>(Expr("depth"), create<ast::AssignmentStatement>(Expr("depth"),
MemberAccessor("coord", "x")), MemberAccessor("coord", "x")),
}, },
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment), create<ast::StageDecoration>(ast::PipelineStage::kFragment),
}); });

View File

@ -31,7 +31,7 @@ TEST_F(HlslGeneratorImplTest_Function, Emit_Function) {
ast::StatementList{ ast::StatementList{
create<ast::ReturnStatement>(), create<ast::ReturnStatement>(),
}, },
ast::FunctionDecorationList{}); ast::DecorationList{});
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
@ -50,7 +50,7 @@ TEST_F(HlslGeneratorImplTest_Function, Emit_Function_Name_Collision) {
ast::StatementList{ ast::StatementList{
create<ast::ReturnStatement>(), create<ast::ReturnStatement>(),
}, },
ast::FunctionDecorationList{}); ast::DecorationList{});
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
@ -72,7 +72,7 @@ TEST_F(HlslGeneratorImplTest_Function, Emit_Function_WithParams) {
ast::StatementList{ ast::StatementList{
create<ast::ReturnStatement>(), create<ast::ReturnStatement>(),
}, },
ast::FunctionDecorationList{}); ast::DecorationList{});
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
@ -87,10 +87,10 @@ TEST_F(HlslGeneratorImplTest_Function, Emit_Function_WithParams) {
} }
TEST_F(HlslGeneratorImplTest_Function, TEST_F(HlslGeneratorImplTest_Function,
Emit_FunctionDecoration_EntryPoint_NoReturn_Void) { Emit_Decoration_EntryPoint_NoReturn_Void) {
Func("main", ast::VariableList{}, ty.void_(), Func("main", ast::VariableList{}, ty.void_(),
ast::StatementList{/* no explicit return */}, ast::StatementList{/* no explicit return */},
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment), create<ast::StageDecoration>(ast::PipelineStage::kFragment),
}); });
@ -105,14 +105,14 @@ TEST_F(HlslGeneratorImplTest_Function,
} }
TEST_F(HlslGeneratorImplTest_Function, TEST_F(HlslGeneratorImplTest_Function,
Emit_FunctionDecoration_EntryPoint_NoReturn_InOut) { Emit_Decoration_EntryPoint_NoReturn_InOut) {
Global("foo", ty.f32(), ast::StorageClass::kInput, nullptr, Global("foo", ty.f32(), ast::StorageClass::kInput, nullptr,
ast::VariableDecorationList{ ast::DecorationList{
create<ast::LocationDecoration>(0), create<ast::LocationDecoration>(0),
}); });
Global("bar", ty.f32(), ast::StorageClass::kOutput, nullptr, Global("bar", ty.f32(), ast::StorageClass::kOutput, nullptr,
ast::VariableDecorationList{ ast::DecorationList{
create<ast::LocationDecoration>(1), create<ast::LocationDecoration>(1),
}); });
@ -120,7 +120,7 @@ TEST_F(HlslGeneratorImplTest_Function,
ast::StatementList{ ast::StatementList{
create<ast::AssignmentStatement>(Expr("bar"), Expr("foo")), create<ast::AssignmentStatement>(Expr("bar"), Expr("foo")),
/* no explicit return */}, /* no explicit return */},
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment), create<ast::StageDecoration>(ast::PipelineStage::kFragment),
}); });
@ -145,14 +145,14 @@ main_out main(main_in tint_in) {
} }
TEST_F(HlslGeneratorImplTest_Function, TEST_F(HlslGeneratorImplTest_Function,
Emit_FunctionDecoration_EntryPoint_WithInOutVars) { Emit_Decoration_EntryPoint_WithInOutVars) {
Global("foo", ty.f32(), ast::StorageClass::kInput, nullptr, Global("foo", ty.f32(), ast::StorageClass::kInput, nullptr,
ast::VariableDecorationList{ ast::DecorationList{
create<ast::LocationDecoration>(0), create<ast::LocationDecoration>(0),
}); });
Global("bar", ty.f32(), ast::StorageClass::kOutput, nullptr, Global("bar", ty.f32(), ast::StorageClass::kOutput, nullptr,
ast::VariableDecorationList{ ast::DecorationList{
create<ast::LocationDecoration>(1), create<ast::LocationDecoration>(1),
}); });
@ -161,7 +161,7 @@ TEST_F(HlslGeneratorImplTest_Function,
create<ast::AssignmentStatement>(Expr("bar"), Expr("foo")), create<ast::AssignmentStatement>(Expr("bar"), Expr("foo")),
create<ast::ReturnStatement>(), create<ast::ReturnStatement>(),
}, },
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment), create<ast::StageDecoration>(ast::PipelineStage::kFragment),
}); });
@ -186,14 +186,14 @@ frag_main_out frag_main(frag_main_in tint_in) {
} }
TEST_F(HlslGeneratorImplTest_Function, TEST_F(HlslGeneratorImplTest_Function,
Emit_FunctionDecoration_EntryPoint_WithInOut_Builtins) { Emit_Decoration_EntryPoint_WithInOut_Builtins) {
Global("coord", ty.vec4<f32>(), ast::StorageClass::kInput, nullptr, Global("coord", ty.vec4<f32>(), ast::StorageClass::kInput, nullptr,
ast::VariableDecorationList{ ast::DecorationList{
create<ast::BuiltinDecoration>(ast::Builtin::kFragCoord), create<ast::BuiltinDecoration>(ast::Builtin::kFragCoord),
}); });
Global("depth", ty.f32(), ast::StorageClass::kOutput, nullptr, Global("depth", ty.f32(), ast::StorageClass::kOutput, nullptr,
ast::VariableDecorationList{ ast::DecorationList{
create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth), create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth),
}); });
@ -203,7 +203,7 @@ TEST_F(HlslGeneratorImplTest_Function,
MemberAccessor("coord", "x")), MemberAccessor("coord", "x")),
create<ast::ReturnStatement>(), create<ast::ReturnStatement>(),
}, },
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment), create<ast::StageDecoration>(ast::PipelineStage::kFragment),
}); });
@ -228,9 +228,9 @@ frag_main_out frag_main(frag_main_in tint_in) {
} }
TEST_F(HlslGeneratorImplTest_Function, TEST_F(HlslGeneratorImplTest_Function,
Emit_FunctionDecoration_EntryPoint_With_Uniform) { Emit_Decoration_EntryPoint_With_Uniform) {
Global("coord", ty.vec4<f32>(), ast::StorageClass::kUniform, nullptr, Global("coord", ty.vec4<f32>(), ast::StorageClass::kUniform, nullptr,
ast::VariableDecorationList{ ast::DecorationList{
create<ast::BindingDecoration>(0), create<ast::BindingDecoration>(0),
create<ast::GroupDecoration>(1), create<ast::GroupDecoration>(1),
}); });
@ -243,7 +243,7 @@ TEST_F(HlslGeneratorImplTest_Function,
create<ast::VariableDeclStatement>(var), create<ast::VariableDeclStatement>(var),
create<ast::ReturnStatement>(), create<ast::ReturnStatement>(),
}, },
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment), create<ast::StageDecoration>(ast::PipelineStage::kFragment),
}); });
@ -263,15 +263,15 @@ void frag_main() {
} }
TEST_F(HlslGeneratorImplTest_Function, TEST_F(HlslGeneratorImplTest_Function,
Emit_FunctionDecoration_EntryPoint_With_UniformStruct) { Emit_Decoration_EntryPoint_With_UniformStruct) {
auto* str = create<ast::Struct>( auto* str = create<ast::Struct>(
ast::StructMemberList{Member("coord", ty.vec4<f32>())}, ast::StructMemberList{Member("coord", ty.vec4<f32>())},
ast::StructDecorationList{}); ast::DecorationList{});
auto* s = ty.struct_("Uniforms", str); auto* s = ty.struct_("Uniforms", str);
Global("uniforms", s, ast::StorageClass::kUniform, nullptr, Global("uniforms", s, ast::StorageClass::kUniform, nullptr,
ast::VariableDecorationList{ ast::DecorationList{
create<ast::BindingDecoration>(0), create<ast::BindingDecoration>(0),
create<ast::GroupDecoration>(1), create<ast::GroupDecoration>(1),
}); });
@ -287,7 +287,7 @@ TEST_F(HlslGeneratorImplTest_Function,
create<ast::VariableDeclStatement>(var), create<ast::VariableDeclStatement>(var),
create<ast::ReturnStatement>(), create<ast::ReturnStatement>(),
}, },
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment), create<ast::StageDecoration>(ast::PipelineStage::kFragment),
}); });
@ -309,17 +309,17 @@ void frag_main() {
} }
TEST_F(HlslGeneratorImplTest_Function, TEST_F(HlslGeneratorImplTest_Function,
Emit_FunctionDecoration_EntryPoint_With_RW_StorageBuffer_Read) { Emit_Decoration_EntryPoint_With_RW_StorageBuffer_Read) {
auto* str = create<ast::Struct>( auto* str = create<ast::Struct>(
ast::StructMemberList{Member("a", ty.i32(), {MemberOffset(0)}), ast::StructMemberList{Member("a", ty.i32(), {MemberOffset(0)}),
Member("b", ty.f32(), {MemberOffset(4)})}, Member("b", ty.f32(), {MemberOffset(4)})},
ast::StructDecorationList{}); ast::DecorationList{});
auto* s = ty.struct_("Data", str); auto* s = ty.struct_("Data", str);
type::AccessControl ac(ast::AccessControl::kReadWrite, s); type::AccessControl ac(ast::AccessControl::kReadWrite, s);
Global("coord", &ac, ast::StorageClass::kStorage, nullptr, Global("coord", &ac, ast::StorageClass::kStorage, nullptr,
ast::VariableDecorationList{ ast::DecorationList{
create<ast::BindingDecoration>(0), create<ast::BindingDecoration>(0),
create<ast::GroupDecoration>(1), create<ast::GroupDecoration>(1),
}); });
@ -332,7 +332,7 @@ TEST_F(HlslGeneratorImplTest_Function,
create<ast::VariableDeclStatement>(var), create<ast::VariableDeclStatement>(var),
create<ast::ReturnStatement>(), create<ast::ReturnStatement>(),
}, },
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment), create<ast::StageDecoration>(ast::PipelineStage::kFragment),
}); });
@ -350,17 +350,17 @@ void frag_main() {
} }
TEST_F(HlslGeneratorImplTest_Function, TEST_F(HlslGeneratorImplTest_Function,
Emit_FunctionDecoration_EntryPoint_With_RO_StorageBuffer_Read) { Emit_Decoration_EntryPoint_With_RO_StorageBuffer_Read) {
auto* str = create<ast::Struct>( auto* str = create<ast::Struct>(
ast::StructMemberList{Member("a", ty.i32(), {MemberOffset(0)}), ast::StructMemberList{Member("a", ty.i32(), {MemberOffset(0)}),
Member("b", ty.f32(), {MemberOffset(4)})}, Member("b", ty.f32(), {MemberOffset(4)})},
ast::StructDecorationList{}); ast::DecorationList{});
auto* s = ty.struct_("Data", str); auto* s = ty.struct_("Data", str);
type::AccessControl ac(ast::AccessControl::kReadOnly, s); type::AccessControl ac(ast::AccessControl::kReadOnly, s);
Global("coord", &ac, ast::StorageClass::kStorage, nullptr, Global("coord", &ac, ast::StorageClass::kStorage, nullptr,
ast::VariableDecorationList{ ast::DecorationList{
create<ast::BindingDecoration>(0), create<ast::BindingDecoration>(0),
create<ast::GroupDecoration>(1), create<ast::GroupDecoration>(1),
}); });
@ -373,7 +373,7 @@ TEST_F(HlslGeneratorImplTest_Function,
create<ast::VariableDeclStatement>(var), create<ast::VariableDeclStatement>(var),
create<ast::ReturnStatement>(), create<ast::ReturnStatement>(),
}, },
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment), create<ast::StageDecoration>(ast::PipelineStage::kFragment),
}); });
@ -391,17 +391,17 @@ void frag_main() {
} }
TEST_F(HlslGeneratorImplTest_Function, TEST_F(HlslGeneratorImplTest_Function,
Emit_FunctionDecoration_EntryPoint_With_WO_StorageBuffer_Store) { Emit_Decoration_EntryPoint_With_WO_StorageBuffer_Store) {
auto* str = create<ast::Struct>( auto* str = create<ast::Struct>(
ast::StructMemberList{Member("a", ty.i32(), {MemberOffset(0)}), ast::StructMemberList{Member("a", ty.i32(), {MemberOffset(0)}),
Member("b", ty.f32(), {MemberOffset(4)})}, Member("b", ty.f32(), {MemberOffset(4)})},
ast::StructDecorationList{}); ast::DecorationList{});
auto* s = ty.struct_("Data", str); auto* s = ty.struct_("Data", str);
type::AccessControl ac(ast::AccessControl::kWriteOnly, s); type::AccessControl ac(ast::AccessControl::kWriteOnly, s);
Global("coord", &ac, ast::StorageClass::kStorage, nullptr, Global("coord", &ac, ast::StorageClass::kStorage, nullptr,
ast::VariableDecorationList{ ast::DecorationList{
create<ast::BindingDecoration>(0), create<ast::BindingDecoration>(0),
create<ast::GroupDecoration>(1), create<ast::GroupDecoration>(1),
}); });
@ -412,7 +412,7 @@ TEST_F(HlslGeneratorImplTest_Function,
Expr(2.0f)), Expr(2.0f)),
create<ast::ReturnStatement>(), create<ast::ReturnStatement>(),
}, },
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment), create<ast::StageDecoration>(ast::PipelineStage::kFragment),
}); });
@ -430,17 +430,17 @@ void frag_main() {
} }
TEST_F(HlslGeneratorImplTest_Function, TEST_F(HlslGeneratorImplTest_Function,
Emit_FunctionDecoration_EntryPoint_With_StorageBuffer_Store) { Emit_Decoration_EntryPoint_With_StorageBuffer_Store) {
auto* str = create<ast::Struct>( auto* str = create<ast::Struct>(
ast::StructMemberList{Member("a", ty.i32(), {MemberOffset(0)}), ast::StructMemberList{Member("a", ty.i32(), {MemberOffset(0)}),
Member("b", ty.f32(), {MemberOffset(4)})}, Member("b", ty.f32(), {MemberOffset(4)})},
ast::StructDecorationList{}); ast::DecorationList{});
auto* s = ty.struct_("Data", str); auto* s = ty.struct_("Data", str);
type::AccessControl ac(ast::AccessControl::kReadWrite, s); type::AccessControl ac(ast::AccessControl::kReadWrite, s);
Global("coord", &ac, ast::StorageClass::kStorage, nullptr, Global("coord", &ac, ast::StorageClass::kStorage, nullptr,
ast::VariableDecorationList{ ast::DecorationList{
create<ast::BindingDecoration>(0), create<ast::BindingDecoration>(0),
create<ast::GroupDecoration>(1), create<ast::GroupDecoration>(1),
}); });
@ -451,7 +451,7 @@ TEST_F(HlslGeneratorImplTest_Function,
Expr(2.0f)), Expr(2.0f)),
create<ast::ReturnStatement>(), create<ast::ReturnStatement>(),
}, },
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment), create<ast::StageDecoration>(ast::PipelineStage::kFragment),
}); });
@ -470,19 +470,19 @@ void frag_main() {
TEST_F( TEST_F(
HlslGeneratorImplTest_Function, HlslGeneratorImplTest_Function,
Emit_FunctionDecoration_Called_By_EntryPoints_WithLocationGlobals_And_Params) { // NOLINT Emit_Decoration_Called_By_EntryPoints_WithLocationGlobals_And_Params) { // NOLINT
Global("foo", ty.f32(), ast::StorageClass::kInput, nullptr, Global("foo", ty.f32(), ast::StorageClass::kInput, nullptr,
ast::VariableDecorationList{ ast::DecorationList{
create<ast::LocationDecoration>(0), create<ast::LocationDecoration>(0),
}); });
Global("bar", ty.f32(), ast::StorageClass::kOutput, nullptr, Global("bar", ty.f32(), ast::StorageClass::kOutput, nullptr,
ast::VariableDecorationList{ ast::DecorationList{
create<ast::LocationDecoration>(1), create<ast::LocationDecoration>(1),
}); });
Global("val", ty.f32(), ast::StorageClass::kOutput, nullptr, Global("val", ty.f32(), ast::StorageClass::kOutput, nullptr,
ast::VariableDecorationList{ ast::DecorationList{
create<ast::LocationDecoration>(0), create<ast::LocationDecoration>(0),
}); });
@ -494,7 +494,7 @@ TEST_F(
create<ast::AssignmentStatement>(Expr("val"), Expr("param")), create<ast::AssignmentStatement>(Expr("val"), Expr("param")),
create<ast::ReturnStatement>(Expr("foo")), create<ast::ReturnStatement>(Expr("foo")),
}, },
ast::FunctionDecorationList{}); ast::DecorationList{});
Func( Func(
"ep_1", ast::VariableList{}, ty.void_(), "ep_1", ast::VariableList{}, ty.void_(),
@ -502,7 +502,7 @@ TEST_F(
create<ast::AssignmentStatement>(Expr("bar"), Call("sub_func", 1.0f)), create<ast::AssignmentStatement>(Expr("bar"), Call("sub_func", 1.0f)),
create<ast::ReturnStatement>(), create<ast::ReturnStatement>(),
}, },
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment), create<ast::StageDecoration>(ast::PipelineStage::kFragment),
}); });
@ -534,9 +534,9 @@ ep_1_out ep_1(ep_1_in tint_in) {
} }
TEST_F(HlslGeneratorImplTest_Function, TEST_F(HlslGeneratorImplTest_Function,
Emit_FunctionDecoration_Called_By_EntryPoints_NoUsedGlobals) { Emit_Decoration_Called_By_EntryPoints_NoUsedGlobals) {
Global("depth", ty.f32(), ast::StorageClass::kOutput, nullptr, Global("depth", ty.f32(), ast::StorageClass::kOutput, nullptr,
ast::VariableDecorationList{ ast::DecorationList{
create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth), create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth),
}); });
@ -546,7 +546,7 @@ TEST_F(HlslGeneratorImplTest_Function,
ast::StatementList{ ast::StatementList{
create<ast::ReturnStatement>(Expr("param")), create<ast::ReturnStatement>(Expr("param")),
}, },
ast::FunctionDecorationList{}); ast::DecorationList{});
Func("ep_1", ast::VariableList{}, ty.void_(), Func("ep_1", ast::VariableList{}, ty.void_(),
ast::StatementList{ ast::StatementList{
@ -554,7 +554,7 @@ TEST_F(HlslGeneratorImplTest_Function,
Call("sub_func", 1.0f)), Call("sub_func", 1.0f)),
create<ast::ReturnStatement>(), create<ast::ReturnStatement>(),
}, },
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment), create<ast::StageDecoration>(ast::PipelineStage::kFragment),
}); });
@ -580,14 +580,14 @@ ep_1_out ep_1() {
TEST_F( TEST_F(
HlslGeneratorImplTest_Function, HlslGeneratorImplTest_Function,
Emit_FunctionDecoration_Called_By_EntryPoints_WithBuiltinGlobals_And_Params) { // NOLINT Emit_Decoration_Called_By_EntryPoints_WithBuiltinGlobals_And_Params) { // NOLINT
Global("coord", ty.vec4<f32>(), ast::StorageClass::kInput, nullptr, Global("coord", ty.vec4<f32>(), ast::StorageClass::kInput, nullptr,
ast::VariableDecorationList{ ast::DecorationList{
create<ast::BuiltinDecoration>(ast::Builtin::kFragCoord), create<ast::BuiltinDecoration>(ast::Builtin::kFragCoord),
}); });
Global("depth", ty.f32(), ast::StorageClass::kOutput, nullptr, Global("depth", ty.f32(), ast::StorageClass::kOutput, nullptr,
ast::VariableDecorationList{ ast::DecorationList{
create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth), create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth),
}); });
@ -599,7 +599,7 @@ TEST_F(
MemberAccessor("coord", "x")), MemberAccessor("coord", "x")),
create<ast::ReturnStatement>(Expr("param")), create<ast::ReturnStatement>(Expr("param")),
}, },
ast::FunctionDecorationList{}); ast::DecorationList{});
Func("ep_1", ast::VariableList{}, ty.void_(), Func("ep_1", ast::VariableList{}, ty.void_(),
ast::StatementList{ ast::StatementList{
@ -607,7 +607,7 @@ TEST_F(
Call("sub_func", 1.0f)), Call("sub_func", 1.0f)),
create<ast::ReturnStatement>(), create<ast::ReturnStatement>(),
}, },
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment), create<ast::StageDecoration>(ast::PipelineStage::kFragment),
}); });
@ -637,9 +637,9 @@ ep_1_out ep_1(ep_1_in tint_in) {
} }
TEST_F(HlslGeneratorImplTest_Function, TEST_F(HlslGeneratorImplTest_Function,
Emit_FunctionDecoration_Called_By_EntryPoint_With_Uniform) { Emit_Decoration_Called_By_EntryPoint_With_Uniform) {
Global("coord", ty.vec4<f32>(), ast::StorageClass::kUniform, nullptr, Global("coord", ty.vec4<f32>(), ast::StorageClass::kUniform, nullptr,
ast::VariableDecorationList{ ast::DecorationList{
create<ast::BindingDecoration>(0), create<ast::BindingDecoration>(0),
create<ast::GroupDecoration>(1), create<ast::GroupDecoration>(1),
}); });
@ -650,7 +650,7 @@ TEST_F(HlslGeneratorImplTest_Function,
ast::StatementList{ ast::StatementList{
create<ast::ReturnStatement>(MemberAccessor("coord", "x")), create<ast::ReturnStatement>(MemberAccessor("coord", "x")),
}, },
ast::FunctionDecorationList{}); ast::DecorationList{});
auto* var = auto* var =
Var("v", ty.f32(), ast::StorageClass::kFunction, Call("sub_func", 1.0f)); Var("v", ty.f32(), ast::StorageClass::kFunction, Call("sub_func", 1.0f));
@ -660,7 +660,7 @@ TEST_F(HlslGeneratorImplTest_Function,
create<ast::VariableDeclStatement>(var), create<ast::VariableDeclStatement>(var),
create<ast::ReturnStatement>(), create<ast::ReturnStatement>(),
}, },
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment), create<ast::StageDecoration>(ast::PipelineStage::kFragment),
}); });
@ -684,10 +684,10 @@ void frag_main() {
} }
TEST_F(HlslGeneratorImplTest_Function, TEST_F(HlslGeneratorImplTest_Function,
Emit_FunctionDecoration_Called_By_EntryPoint_With_StorageBuffer) { Emit_Decoration_Called_By_EntryPoint_With_StorageBuffer) {
type::AccessControl ac(ast::AccessControl::kReadWrite, ty.vec4<f32>()); type::AccessControl ac(ast::AccessControl::kReadWrite, ty.vec4<f32>());
Global("coord", &ac, ast::StorageClass::kStorage, nullptr, Global("coord", &ac, ast::StorageClass::kStorage, nullptr,
ast::VariableDecorationList{ ast::DecorationList{
create<ast::BindingDecoration>(0), create<ast::BindingDecoration>(0),
create<ast::GroupDecoration>(1), create<ast::GroupDecoration>(1),
}); });
@ -698,7 +698,7 @@ TEST_F(HlslGeneratorImplTest_Function,
ast::StatementList{ ast::StatementList{
create<ast::ReturnStatement>(MemberAccessor("coord", "x")), create<ast::ReturnStatement>(MemberAccessor("coord", "x")),
}, },
ast::FunctionDecorationList{}); ast::DecorationList{});
auto* var = auto* var =
Var("v", ty.f32(), ast::StorageClass::kFunction, Call("sub_func", 1.0f)); Var("v", ty.f32(), ast::StorageClass::kFunction, Call("sub_func", 1.0f));
@ -708,7 +708,7 @@ TEST_F(HlslGeneratorImplTest_Function,
create<ast::VariableDeclStatement>(var), create<ast::VariableDeclStatement>(var),
create<ast::ReturnStatement>(), create<ast::ReturnStatement>(),
}, },
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment), create<ast::StageDecoration>(ast::PipelineStage::kFragment),
}); });
@ -730,9 +730,9 @@ void frag_main() {
} }
TEST_F(HlslGeneratorImplTest_Function, TEST_F(HlslGeneratorImplTest_Function,
Emit_FunctionDecoration_EntryPoints_WithGlobal_Nested_Return) { Emit_Decoration_EntryPoints_WithGlobal_Nested_Return) {
Global("bar", ty.f32(), ast::StorageClass::kOutput, nullptr, Global("bar", ty.f32(), ast::StorageClass::kOutput, nullptr,
ast::VariableDecorationList{ ast::DecorationList{
create<ast::LocationDecoration>(1), create<ast::LocationDecoration>(1),
}); });
@ -749,7 +749,7 @@ TEST_F(HlslGeneratorImplTest_Function,
list, ast::ElseStatementList{}), list, ast::ElseStatementList{}),
create<ast::ReturnStatement>(), create<ast::ReturnStatement>(),
}, },
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment), create<ast::StageDecoration>(ast::PipelineStage::kFragment),
}); });
@ -773,9 +773,9 @@ ep_1_out ep_1() {
} }
TEST_F(HlslGeneratorImplTest_Function, TEST_F(HlslGeneratorImplTest_Function,
Emit_FunctionDecoration_EntryPoint_WithNameCollision) { Emit_Decoration_EntryPoint_WithNameCollision) {
Func("GeometryShader", ast::VariableList{}, ty.void_(), ast::StatementList{}, Func("GeometryShader", ast::VariableList{}, ty.void_(), ast::StatementList{},
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment), create<ast::StageDecoration>(ast::PipelineStage::kFragment),
}); });
@ -789,13 +789,12 @@ TEST_F(HlslGeneratorImplTest_Function,
)"); )");
} }
TEST_F(HlslGeneratorImplTest_Function, TEST_F(HlslGeneratorImplTest_Function, Emit_Decoration_EntryPoint_Compute) {
Emit_FunctionDecoration_EntryPoint_Compute) {
Func("main", ast::VariableList{}, ty.void_(), Func("main", ast::VariableList{}, ty.void_(),
ast::StatementList{ ast::StatementList{
create<ast::ReturnStatement>(), create<ast::ReturnStatement>(),
}, },
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kCompute), create<ast::StageDecoration>(ast::PipelineStage::kCompute),
}); });
@ -811,12 +810,12 @@ void main() {
} }
TEST_F(HlslGeneratorImplTest_Function, TEST_F(HlslGeneratorImplTest_Function,
Emit_FunctionDecoration_EntryPoint_Compute_WithWorkgroup) { Emit_Decoration_EntryPoint_Compute_WithWorkgroup) {
Func("main", ast::VariableList{}, ty.void_(), Func("main", ast::VariableList{}, ty.void_(),
ast::StatementList{ ast::StatementList{
create<ast::ReturnStatement>(), create<ast::ReturnStatement>(),
}, },
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kCompute), create<ast::StageDecoration>(ast::PipelineStage::kCompute),
create<ast::WorkgroupDecoration>(2u, 4u, 6u), create<ast::WorkgroupDecoration>(2u, 4u, 6u),
}); });
@ -840,7 +839,7 @@ TEST_F(HlslGeneratorImplTest_Function, Emit_Function_WithArrayParams) {
ast::StatementList{ ast::StatementList{
create<ast::ReturnStatement>(), create<ast::ReturnStatement>(),
}, },
ast::FunctionDecorationList{}); ast::DecorationList{});
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
@ -874,7 +873,7 @@ TEST_F(HlslGeneratorImplTest_Function,
auto* str = create<ast::Struct>( auto* str = create<ast::Struct>(
ast::StructMemberList{Member("d", ty.f32(), {MemberOffset(0)})}, ast::StructMemberList{Member("d", ty.f32(), {MemberOffset(0)})},
ast::StructDecorationList{create<ast::StructBlockDecoration>()}); ast::DecorationList{create<ast::StructBlockDecoration>()});
auto* s = ty.struct_("Data", str); auto* s = ty.struct_("Data", str);
AST().AddConstructedType(s); AST().AddConstructedType(s);
@ -882,7 +881,7 @@ TEST_F(HlslGeneratorImplTest_Function,
type::AccessControl ac(ast::AccessControl::kReadWrite, s); type::AccessControl ac(ast::AccessControl::kReadWrite, s);
Global("data", &ac, ast::StorageClass::kStorage, nullptr, Global("data", &ac, ast::StorageClass::kStorage, nullptr,
ast::VariableDecorationList{ ast::DecorationList{
create<ast::BindingDecoration>(0), create<ast::BindingDecoration>(0),
create<ast::GroupDecoration>(0), create<ast::GroupDecoration>(0),
}); });
@ -896,7 +895,7 @@ TEST_F(HlslGeneratorImplTest_Function,
create<ast::VariableDeclStatement>(var), create<ast::VariableDeclStatement>(var),
create<ast::ReturnStatement>(), create<ast::ReturnStatement>(),
}, },
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kCompute), create<ast::StageDecoration>(ast::PipelineStage::kCompute),
}); });
} }
@ -910,7 +909,7 @@ TEST_F(HlslGeneratorImplTest_Function,
create<ast::VariableDeclStatement>(var), create<ast::VariableDeclStatement>(var),
create<ast::ReturnStatement>(), create<ast::ReturnStatement>(),
}, },
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kCompute), create<ast::StageDecoration>(ast::PipelineStage::kCompute),
}); });
} }

View File

@ -387,7 +387,7 @@ TEST_P(HlslGeneratorIntrinsicTextureTest, Call) {
ast::StatementList{ ast::StatementList{
create<ast::CallStatement>(call), create<ast::CallStatement>(call),
}, },
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment), create<ast::StageDecoration>(ast::PipelineStage::kFragment),
}); });

View File

@ -24,7 +24,7 @@ using HlslGeneratorImplTest_MemberAccessor = TestHelper;
TEST_F(HlslGeneratorImplTest_MemberAccessor, EmitExpression_MemberAccessor) { TEST_F(HlslGeneratorImplTest_MemberAccessor, EmitExpression_MemberAccessor) {
auto* strct = create<ast::Struct>( auto* strct = create<ast::Struct>(
ast::StructMemberList{Member("mem", ty.f32(), {MemberOffset(0)})}, ast::StructMemberList{Member("mem", ty.f32(), {MemberOffset(0)})},
ast::StructDecorationList{}); ast::DecorationList{});
auto* s = ty.struct_("Str", strct); auto* s = ty.struct_("Str", strct);
auto* str_var = Global("str", s, ast::StorageClass::kPrivate); auto* str_var = Global("str", s, ast::StorageClass::kPrivate);
@ -54,7 +54,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
auto* str = create<ast::Struct>( auto* str = create<ast::Struct>(
ast::StructMemberList{Member("a", ty.i32(), {MemberOffset(0)}), ast::StructMemberList{Member("a", ty.i32(), {MemberOffset(0)}),
Member("b", ty.f32(), {MemberOffset(4)})}, Member("b", ty.f32(), {MemberOffset(4)})},
ast::StructDecorationList{}); ast::DecorationList{});
auto* s = ty.struct_("Data", str); auto* s = ty.struct_("Data", str);
auto* coord_var = Global("data", s, ast::StorageClass::kStorage); auto* coord_var = Global("data", s, ast::StorageClass::kStorage);
@ -84,7 +84,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
auto* str = create<ast::Struct>( auto* str = create<ast::Struct>(
ast::StructMemberList{Member("a", ty.i32(), {MemberOffset(0)}), ast::StructMemberList{Member("a", ty.i32(), {MemberOffset(0)}),
Member("b", ty.f32(), {MemberOffset(4)})}, Member("b", ty.f32(), {MemberOffset(4)})},
ast::StructDecorationList{}); ast::DecorationList{});
auto* s = ty.struct_("Data", str); auto* s = ty.struct_("Data", str);
auto* coord_var = Global("data", s, ast::StorageClass::kStorage); auto* coord_var = Global("data", s, ast::StorageClass::kStorage);
@ -116,7 +116,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
auto* str = create<ast::Struct>( auto* str = create<ast::Struct>(
ast::StructMemberList{Member("z", ty.i32(), {MemberOffset(0)}), ast::StructMemberList{Member("z", ty.i32(), {MemberOffset(0)}),
Member("a", ty.mat2x3<f32>(), {MemberOffset(4)})}, Member("a", ty.mat2x3<f32>(), {MemberOffset(4)})},
ast::StructDecorationList{}); ast::DecorationList{});
auto* s = ty.struct_("Data", str); auto* s = ty.struct_("Data", str);
auto* b_var = Global("b", ty.mat2x3<f32>(), ast::StorageClass::kPrivate); auto* b_var = Global("b", ty.mat2x3<f32>(), ast::StorageClass::kPrivate);
@ -157,7 +157,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
auto* str = create<ast::Struct>( auto* str = create<ast::Struct>(
ast::StructMemberList{Member("z", ty.i32(), {MemberOffset(0)}), ast::StructMemberList{Member("z", ty.i32(), {MemberOffset(0)}),
Member("a", ty.mat2x3<f32>(), {MemberOffset(4)})}, Member("a", ty.mat2x3<f32>(), {MemberOffset(4)})},
ast::StructDecorationList{}); ast::DecorationList{});
auto* s = ty.struct_("Data", str); auto* s = ty.struct_("Data", str);
auto* coord_var = Global("data", s, ast::StorageClass::kStorage); auto* coord_var = Global("data", s, ast::StorageClass::kStorage);
@ -196,7 +196,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
auto* str = create<ast::Struct>( auto* str = create<ast::Struct>(
ast::StructMemberList{Member("z", ty.i32(), {MemberOffset(0)}), ast::StructMemberList{Member("z", ty.i32(), {MemberOffset(0)}),
Member("a", ty.mat3x2<f32>(), {MemberOffset(4)})}, Member("a", ty.mat3x2<f32>(), {MemberOffset(4)})},
ast::StructDecorationList{}); ast::DecorationList{});
auto* s = ty.struct_("Data", str); auto* s = ty.struct_("Data", str);
auto* coord_var = Global("data", s, ast::StorageClass::kStorage); auto* coord_var = Global("data", s, ast::StorageClass::kStorage);
@ -234,7 +234,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
Member("z", ty.i32(), {MemberOffset(0)}), Member("z", ty.i32(), {MemberOffset(0)}),
Member("a", ty.mat2x3<f32>(), {MemberOffset(4)}), Member("a", ty.mat2x3<f32>(), {MemberOffset(4)}),
}, },
ast::StructDecorationList{}); ast::DecorationList{});
auto* s = ty.struct_("Data", str); auto* s = ty.struct_("Data", str);
auto* coord_var = Global("data", s, ast::StorageClass::kStorage); auto* coord_var = Global("data", s, ast::StorageClass::kStorage);
@ -265,7 +265,7 @@ TEST_F(
auto* str = create<ast::Struct>( auto* str = create<ast::Struct>(
ast::StructMemberList{Member("a", ty.mat3x3<f32>(), {MemberOffset(0)})}, ast::StructMemberList{Member("a", ty.mat3x3<f32>(), {MemberOffset(0)})},
ast::StructDecorationList{}); ast::DecorationList{});
auto* s = ty.struct_("Data", str); auto* s = ty.struct_("Data", str);
auto* coord_var = Global("data", s, ast::StorageClass::kStorage); auto* coord_var = Global("data", s, ast::StorageClass::kStorage);
@ -297,7 +297,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
auto* str = create<ast::Struct>( auto* str = create<ast::Struct>(
ast::StructMemberList{Member("z", ty.i32(), {MemberOffset(0)}), ast::StructMemberList{Member("z", ty.i32(), {MemberOffset(0)}),
Member("a", ty.mat4x3<f32>(), {MemberOffset(16)})}, Member("a", ty.mat4x3<f32>(), {MemberOffset(16)})},
ast::StructDecorationList{}); ast::DecorationList{});
auto* s = ty.struct_("Data", str); auto* s = ty.struct_("Data", str);
auto* coord_var = Global("data", s, ast::StorageClass::kStorage); auto* coord_var = Global("data", s, ast::StorageClass::kStorage);
@ -324,13 +324,13 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
// //
// -> asint(data.Load((2 * 4)); // -> asint(data.Load((2 * 4));
type::Array ary(ty.i32(), 5, type::Array ary(ty.i32(), 5,
ast::ArrayDecorationList{ ast::DecorationList{
create<ast::StrideDecoration>(4), create<ast::StrideDecoration>(4),
}); });
auto* str = create<ast::Struct>( auto* str = create<ast::Struct>(
ast::StructMemberList{Member("a", &ary, {MemberOffset(0)})}, ast::StructMemberList{Member("a", &ary, {MemberOffset(0)})},
ast::StructDecorationList{}); ast::DecorationList{});
auto* s = ty.struct_("Data", str); auto* s = ty.struct_("Data", str);
auto* coord_var = Global("data", s, ast::StorageClass::kStorage); auto* coord_var = Global("data", s, ast::StorageClass::kStorage);
@ -355,13 +355,13 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
// //
// -> asint(data.Load((4 * ((2 + 4) - 3))); // -> asint(data.Load((4 * ((2 + 4) - 3)));
type::Array ary(ty.i32(), 5, type::Array ary(ty.i32(), 5,
ast::ArrayDecorationList{ ast::DecorationList{
create<ast::StrideDecoration>(4), create<ast::StrideDecoration>(4),
}); });
auto* str = create<ast::Struct>( auto* str = create<ast::Struct>(
ast::StructMemberList{Member("a", &ary, {MemberOffset(0)})}, ast::StructMemberList{Member("a", &ary, {MemberOffset(0)})},
ast::StructDecorationList{}); ast::DecorationList{});
auto* s = ty.struct_("Data", str); auto* s = ty.struct_("Data", str);
auto* coord_var = Global("data", s, ast::StorageClass::kStorage); auto* coord_var = Global("data", s, ast::StorageClass::kStorage);
@ -391,7 +391,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
auto* str = create<ast::Struct>( auto* str = create<ast::Struct>(
ast::StructMemberList{Member("a", ty.i32(), {MemberOffset(0)}), ast::StructMemberList{Member("a", ty.i32(), {MemberOffset(0)}),
Member("b", ty.f32(), {MemberOffset(4)})}, Member("b", ty.f32(), {MemberOffset(4)})},
ast::StructDecorationList{}); ast::DecorationList{});
auto* s = ty.struct_("Data", str); auto* s = ty.struct_("Data", str);
auto* coord_var = Global("data", s, ast::StorageClass::kStorage); auto* coord_var = Global("data", s, ast::StorageClass::kStorage);
@ -421,13 +421,13 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
// -> data.Store((2 * 4), asuint(2.3f)); // -> data.Store((2 * 4), asuint(2.3f));
type::Array ary(ty.i32(), 5, type::Array ary(ty.i32(), 5,
ast::ArrayDecorationList{ ast::DecorationList{
create<ast::StrideDecoration>(4), create<ast::StrideDecoration>(4),
}); });
auto* str = create<ast::Struct>( auto* str = create<ast::Struct>(
ast::StructMemberList{Member("a", &ary, {MemberOffset(0)})}, ast::StructMemberList{Member("a", &ary, {MemberOffset(0)})},
ast::StructDecorationList{}); ast::DecorationList{});
auto* s = ty.struct_("Data", str); auto* s = ty.struct_("Data", str);
auto* coord_var = Global("data", s, ast::StorageClass::kStorage); auto* coord_var = Global("data", s, ast::StorageClass::kStorage);
@ -460,7 +460,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
auto* str = create<ast::Struct>( auto* str = create<ast::Struct>(
ast::StructMemberList{Member("a", ty.i32(), {MemberOffset(0)}), ast::StructMemberList{Member("a", ty.i32(), {MemberOffset(0)}),
Member("b", ty.f32(), {MemberOffset(4)})}, Member("b", ty.f32(), {MemberOffset(4)})},
ast::StructDecorationList{}); ast::DecorationList{});
auto* s = ty.struct_("Data", str); auto* s = ty.struct_("Data", str);
auto* coord_var = Global("data", s, ast::StorageClass::kStorage); auto* coord_var = Global("data", s, ast::StorageClass::kStorage);
@ -493,7 +493,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
auto* str = create<ast::Struct>( auto* str = create<ast::Struct>(
ast::StructMemberList{Member("a", ty.vec3<i32>(), {MemberOffset(0)}), ast::StructMemberList{Member("a", ty.vec3<i32>(), {MemberOffset(0)}),
Member("b", ty.vec3<f32>(), {MemberOffset(16)})}, Member("b", ty.vec3<f32>(), {MemberOffset(16)})},
ast::StructDecorationList{}); ast::DecorationList{});
auto* s = ty.struct_("Data", str); auto* s = ty.struct_("Data", str);
auto* coord_var = Global("data", s, ast::StorageClass::kStorage); auto* coord_var = Global("data", s, ast::StorageClass::kStorage);
@ -523,7 +523,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
auto* str = create<ast::Struct>( auto* str = create<ast::Struct>(
ast::StructMemberList{Member("a", ty.vec3<i32>(), {MemberOffset(0)}), ast::StructMemberList{Member("a", ty.vec3<i32>(), {MemberOffset(0)}),
Member("b", ty.vec3<f32>(), {MemberOffset(16)})}, Member("b", ty.vec3<f32>(), {MemberOffset(16)})},
ast::StructDecorationList{}); ast::DecorationList{});
auto* s = ty.struct_("Data", str); auto* s = ty.struct_("Data", str);
auto* coord_var = Global("data", s, ast::StorageClass::kStorage); auto* coord_var = Global("data", s, ast::StorageClass::kStorage);
@ -565,17 +565,17 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
Member("a", ty.vec3<i32>(), {MemberOffset(0)}), Member("a", ty.vec3<i32>(), {MemberOffset(0)}),
Member("b", ty.vec3<f32>(), {MemberOffset(16)}), Member("b", ty.vec3<f32>(), {MemberOffset(16)}),
}, },
ast::StructDecorationList{}); ast::DecorationList{});
auto* data = ty.struct_("Data", data_str); auto* data = ty.struct_("Data", data_str);
type::Array ary(data, 4, type::Array ary(data, 4,
ast::ArrayDecorationList{ ast::DecorationList{
create<ast::StrideDecoration>(32), create<ast::StrideDecoration>(32),
}); });
auto* pre_str = create<ast::Struct>( auto* pre_str = create<ast::Struct>(
ast::StructMemberList{Member("c", &ary, {MemberOffset(0)})}, ast::StructMemberList{Member("c", &ary, {MemberOffset(0)})},
ast::StructDecorationList{}); ast::DecorationList{});
auto* pre_struct = ty.struct_("Pre", pre_str); auto* pre_struct = ty.struct_("Pre", pre_str);
auto* coord_var = Global("data", pre_struct, ast::StorageClass::kStorage); auto* coord_var = Global("data", pre_struct, ast::StorageClass::kStorage);
@ -612,15 +612,15 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
Member("a", ty.vec3<i32>(), {MemberOffset(0)}), Member("a", ty.vec3<i32>(), {MemberOffset(0)}),
Member("b", ty.vec3<f32>(), {MemberOffset(16)}), Member("b", ty.vec3<f32>(), {MemberOffset(16)}),
}, },
ast::StructDecorationList{}); ast::DecorationList{});
auto* data = ty.struct_("Data", data_str); auto* data = ty.struct_("Data", data_str);
type::Array ary(data, 4, type::Array ary(data, 4,
ast::ArrayDecorationList{create<ast::StrideDecoration>(32)}); ast::DecorationList{create<ast::StrideDecoration>(32)});
auto* pre_str = create<ast::Struct>( auto* pre_str = create<ast::Struct>(
ast::StructMemberList{Member("c", &ary, {MemberOffset(0)})}, ast::StructMemberList{Member("c", &ary, {MemberOffset(0)})},
ast::StructDecorationList{}); ast::DecorationList{});
auto* pre_struct = ty.struct_("Pre", pre_str); auto* pre_struct = ty.struct_("Pre", pre_str);
auto* coord_var = Global("data", pre_struct, ast::StorageClass::kStorage); auto* coord_var = Global("data", pre_struct, ast::StorageClass::kStorage);
@ -659,17 +659,17 @@ TEST_F(
Member("a", ty.vec3<i32>(), {MemberOffset(0)}), Member("a", ty.vec3<i32>(), {MemberOffset(0)}),
Member("b", ty.vec3<f32>(), {MemberOffset(16)}), Member("b", ty.vec3<f32>(), {MemberOffset(16)}),
}, },
ast::StructDecorationList{}); ast::DecorationList{});
auto* data = ty.struct_("Data", data_str); auto* data = ty.struct_("Data", data_str);
type::Array ary(data, 4, type::Array ary(data, 4,
ast::ArrayDecorationList{ ast::DecorationList{
create<ast::StrideDecoration>(32), create<ast::StrideDecoration>(32),
}); });
auto* pre_str = create<ast::Struct>( auto* pre_str = create<ast::Struct>(
ast::StructMemberList{Member("c", &ary, {MemberOffset(0)})}, ast::StructMemberList{Member("c", &ary, {MemberOffset(0)})},
ast::StructDecorationList{}); ast::DecorationList{});
auto* pre_struct = ty.struct_("Pre", pre_str); auto* pre_struct = ty.struct_("Pre", pre_str);
auto* coord_var = Global("data", pre_struct, ast::StorageClass::kStorage); auto* coord_var = Global("data", pre_struct, ast::StorageClass::kStorage);
@ -707,17 +707,17 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
Member("a", ty.vec3<i32>(), {MemberOffset(0)}), Member("a", ty.vec3<i32>(), {MemberOffset(0)}),
Member("b", ty.vec3<f32>(), {MemberOffset(16)}), Member("b", ty.vec3<f32>(), {MemberOffset(16)}),
}, },
ast::StructDecorationList{}); ast::DecorationList{});
auto* data = ty.struct_("Data", data_str); auto* data = ty.struct_("Data", data_str);
type::Array ary(data, 4, type::Array ary(data, 4,
ast::ArrayDecorationList{ ast::DecorationList{
create<ast::StrideDecoration>(32), create<ast::StrideDecoration>(32),
}); });
auto* pre_str = create<ast::Struct>( auto* pre_str = create<ast::Struct>(
ast::StructMemberList{Member("c", &ary, {MemberOffset(0)})}, ast::StructMemberList{Member("c", &ary, {MemberOffset(0)})},
ast::StructDecorationList{}); ast::DecorationList{});
auto* pre_struct = ty.struct_("Pre", pre_str); auto* pre_struct = ty.struct_("Pre", pre_str);
auto* coord_var = Global("data", pre_struct, ast::StorageClass::kStorage); auto* coord_var = Global("data", pre_struct, ast::StorageClass::kStorage);
@ -755,17 +755,17 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
Member("a", ty.vec3<i32>(), {MemberOffset(0)}), Member("a", ty.vec3<i32>(), {MemberOffset(0)}),
Member("b", ty.vec3<f32>(), {MemberOffset(16)}), Member("b", ty.vec3<f32>(), {MemberOffset(16)}),
}, },
ast::StructDecorationList{}); ast::DecorationList{});
auto* data = ty.struct_("Data", data_str); auto* data = ty.struct_("Data", data_str);
type::Array ary(data, 4, type::Array ary(data, 4,
ast::ArrayDecorationList{ ast::DecorationList{
create<ast::StrideDecoration>(32), create<ast::StrideDecoration>(32),
}); });
auto* pre_str = create<ast::Struct>( auto* pre_str = create<ast::Struct>(
ast::StructMemberList{Member("c", &ary, {MemberOffset(0)})}, ast::StructMemberList{Member("c", &ary, {MemberOffset(0)})},
ast::StructDecorationList{}); ast::DecorationList{});
auto* pre_struct = ty.struct_("Pre", pre_str); auto* pre_struct = ty.struct_("Pre", pre_str);
auto* coord_var = Global("data", pre_struct, ast::StorageClass::kStorage); auto* coord_var = Global("data", pre_struct, ast::StorageClass::kStorage);
@ -808,17 +808,17 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
Member("a", ty.vec3<i32>(), {MemberOffset(0)}), Member("a", ty.vec3<i32>(), {MemberOffset(0)}),
Member("b", ty.vec3<f32>(), {MemberOffset(16)}), Member("b", ty.vec3<f32>(), {MemberOffset(16)}),
}, },
ast::StructDecorationList{}); ast::DecorationList{});
auto* data = ty.struct_("Data", data_str); auto* data = ty.struct_("Data", data_str);
type::Array ary(data, 4, type::Array ary(data, 4,
ast::ArrayDecorationList{ ast::DecorationList{
create<ast::StrideDecoration>(32), create<ast::StrideDecoration>(32),
}); });
auto* pre_str = create<ast::Struct>( auto* pre_str = create<ast::Struct>(
ast::StructMemberList{Member("c", &ary, {MemberOffset(0)})}, ast::StructMemberList{Member("c", &ary, {MemberOffset(0)})},
ast::StructDecorationList{}); ast::DecorationList{});
auto* pre_struct = ty.struct_("Pre", pre_str); auto* pre_struct = ty.struct_("Pre", pre_str);
auto* coord_var = Global("data", pre_struct, ast::StorageClass::kStorage); auto* coord_var = Global("data", pre_struct, ast::StorageClass::kStorage);

View File

@ -33,7 +33,7 @@ TEST_F(HlslGeneratorImplTest_ModuleConstant, Emit_ModuleConstant) {
TEST_F(HlslGeneratorImplTest_ModuleConstant, Emit_SpecConstant) { TEST_F(HlslGeneratorImplTest_ModuleConstant, Emit_SpecConstant) {
auto* var = Const("pos", ty.f32(), Expr(3.0f), auto* var = Const("pos", ty.f32(), Expr(3.0f),
ast::VariableDecorationList{ ast::DecorationList{
create<ast::ConstantIdDecoration>(23), create<ast::ConstantIdDecoration>(23),
}); });
@ -50,7 +50,7 @@ static const float pos = WGSL_SPEC_CONSTANT_23;
TEST_F(HlslGeneratorImplTest_ModuleConstant, Emit_SpecConstant_NoConstructor) { TEST_F(HlslGeneratorImplTest_ModuleConstant, Emit_SpecConstant_NoConstructor) {
auto* var = Const("pos", ty.f32(), nullptr, auto* var = Const("pos", ty.f32(), nullptr,
ast::VariableDecorationList{ ast::DecorationList{
create<ast::ConstantIdDecoration>(23), create<ast::ConstantIdDecoration>(23),
}); });

View File

@ -32,7 +32,7 @@ TEST_F(HlslSanitizerTest, PromoteArrayInitializerToConstVar) {
ast::StatementList{ ast::StatementList{
create<ast::VariableDeclStatement>(pos), create<ast::VariableDeclStatement>(pos),
}, },
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });

View File

@ -23,7 +23,7 @@ using HlslGeneratorImplTest = TestHelper;
TEST_F(HlslGeneratorImplTest, Generate) { TEST_F(HlslGeneratorImplTest, Generate) {
Func("my_func", ast::VariableList{}, ty.void_(), ast::StatementList{}, Func("my_func", ast::VariableList{}, ty.void_(), ast::StatementList{},
ast::FunctionDecorationList{}); ast::DecorationList{});
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();

View File

@ -170,7 +170,7 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_StructDecl) {
auto* str = create<ast::Struct>( auto* str = create<ast::Struct>(
ast::StructMemberList{Member("a", ty.i32()), ast::StructMemberList{Member("a", ty.i32()),
Member("b", ty.f32(), {MemberOffset(4)})}, Member("b", ty.f32(), {MemberOffset(4)})},
ast::StructDecorationList{}); ast::DecorationList{});
auto* s = ty.struct_("S", str); auto* s = ty.struct_("S", str);
@ -188,7 +188,7 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_Struct) {
auto* str = create<ast::Struct>( auto* str = create<ast::Struct>(
ast::StructMemberList{Member("a", ty.i32()), ast::StructMemberList{Member("a", ty.i32()),
Member("b", ty.f32(), {MemberOffset(4)})}, Member("b", ty.f32(), {MemberOffset(4)})},
ast::StructDecorationList{}); ast::DecorationList{});
auto* s = ty.struct_("S", str); auto* s = ty.struct_("S", str);
@ -203,7 +203,7 @@ TEST_F(HlslGeneratorImplTest_Type, DISABLED_EmitType_Struct_InjectPadding) {
ast::StructMemberList{Member("a", ty.i32(), {MemberOffset(4)}), ast::StructMemberList{Member("a", ty.i32(), {MemberOffset(4)}),
Member("b", ty.f32(), {MemberOffset(32)}), Member("b", ty.f32(), {MemberOffset(32)}),
Member("c", ty.f32(), {MemberOffset(128)})}, Member("c", ty.f32(), {MemberOffset(128)})},
ast::StructDecorationList{}); ast::DecorationList{});
auto* s = ty.struct_("S", str); auto* s = ty.struct_("S", str);
@ -224,7 +224,7 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_Struct_NameCollision) {
auto* str = auto* str =
create<ast::Struct>(ast::StructMemberList{Member("double", ty.i32()), create<ast::Struct>(ast::StructMemberList{Member("double", ty.i32()),
Member("float", ty.f32())}, Member("float", ty.f32())},
ast::StructDecorationList{}); ast::DecorationList{});
auto* s = ty.struct_("S", str); auto* s = ty.struct_("S", str);
@ -240,7 +240,7 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_Struct_NameCollision) {
// TODO(dsinclair): How to translate [[block]] // TODO(dsinclair): How to translate [[block]]
TEST_F(HlslGeneratorImplTest_Type, DISABLED_EmitType_Struct_WithDecoration) { TEST_F(HlslGeneratorImplTest_Type, DISABLED_EmitType_Struct_WithDecoration) {
ast::StructDecorationList decos; ast::DecorationList decos;
decos.push_back(create<ast::StructBlockDecoration>()); decos.push_back(create<ast::StructBlockDecoration>());
auto* str = create<ast::Struct>( auto* str = create<ast::Struct>(

View File

@ -1040,8 +1040,7 @@ bool GeneratorImpl::EmitEntryPointData(ast::Function* func) {
auto* func_sem = program_->Sem().Get(func); auto* func_sem = program_->Sem().Get(func);
std::vector<std::pair<ast::Variable*, uint32_t>> in_locations; std::vector<std::pair<ast::Variable*, uint32_t>> in_locations;
std::vector<std::pair<ast::Variable*, ast::VariableDecoration*>> std::vector<std::pair<ast::Variable*, ast::Decoration*>> out_variables;
out_variables;
for (auto data : func_sem->ReferencedLocationVariables()) { for (auto data : func_sem->ReferencedLocationVariables()) {
auto* var = data.first; auto* var = data.first;
@ -2028,7 +2027,7 @@ bool GeneratorImpl::EmitType(type::Type* type, const std::string& name) {
bool GeneratorImpl::EmitStructType(const type::Struct* str) { bool GeneratorImpl::EmitStructType(const type::Struct* str) {
// TODO(dsinclair): Block decoration? // TODO(dsinclair): Block decoration?
// if (str->impl()->decoration() != ast::StructDecoration::kNone) { // if (str->impl()->decoration() != ast::Decoration::kNone) {
// } // }
out_ << "struct " << program_->Symbols().NameFor(str->symbol()) << " {" out_ << "struct " << program_->Symbols().NameFor(str->symbol()) << " {"
<< std::endl; << std::endl;

View File

@ -35,7 +35,7 @@ TEST_F(MslGeneratorImplTest, EmitConstructedType_Struct) {
auto* str = create<ast::Struct>( auto* str = create<ast::Struct>(
ast::StructMemberList{Member("a", ty.f32()), ast::StructMemberList{Member("a", ty.f32()),
Member("b", ty.i32(), {MemberOffset(4)})}, Member("b", ty.i32(), {MemberOffset(4)})},
ast::StructDecorationList{}); ast::DecorationList{});
auto* s = ty.struct_("a", str); auto* s = ty.struct_("a", str);
@ -53,7 +53,7 @@ TEST_F(MslGeneratorImplTest, EmitConstructedType_AliasStructIdent) {
auto* str = create<ast::Struct>( auto* str = create<ast::Struct>(
ast::StructMemberList{Member("a", ty.f32()), ast::StructMemberList{Member("a", ty.f32()),
Member("b", ty.i32(), {MemberOffset(4)})}, Member("b", ty.i32(), {MemberOffset(4)})},
ast::StructDecorationList{}); ast::DecorationList{});
auto* s = ty.struct_("b", str); auto* s = ty.struct_("b", str);
auto* alias = ty.alias("a", s); auto* alias = ty.alias("a", s);

View File

@ -24,7 +24,7 @@ using MslGeneratorImplTest = TestHelper;
TEST_F(MslGeneratorImplTest, EmitExpression_Call_WithoutParams) { TEST_F(MslGeneratorImplTest, EmitExpression_Call_WithoutParams) {
Func("my_func", ast::VariableList{}, ty.void_(), ast::StatementList{}, Func("my_func", ast::VariableList{}, ty.void_(), ast::StatementList{},
ast::FunctionDecorationList{}); ast::DecorationList{});
auto* call = Call("my_func"); auto* call = Call("my_func");
WrapInFunction(call); WrapInFunction(call);
@ -37,7 +37,7 @@ TEST_F(MslGeneratorImplTest, EmitExpression_Call_WithoutParams) {
TEST_F(MslGeneratorImplTest, EmitExpression_Call_WithParams) { TEST_F(MslGeneratorImplTest, EmitExpression_Call_WithParams) {
Func("my_func", ast::VariableList{}, ty.void_(), ast::StatementList{}, Func("my_func", ast::VariableList{}, ty.void_(), ast::StatementList{},
ast::FunctionDecorationList{}); ast::DecorationList{});
Global("param1", ty.f32(), ast::StorageClass::kNone); Global("param1", ty.f32(), ast::StorageClass::kNone);
Global("param2", ty.f32(), ast::StorageClass::kNone); Global("param2", ty.f32(), ast::StorageClass::kNone);
@ -52,7 +52,7 @@ TEST_F(MslGeneratorImplTest, EmitExpression_Call_WithParams) {
TEST_F(MslGeneratorImplTest, EmitStatement_Call) { TEST_F(MslGeneratorImplTest, EmitStatement_Call) {
Func("my_func", ast::VariableList{}, ty.void_(), ast::StatementList{}, Func("my_func", ast::VariableList{}, ty.void_(), ast::StatementList{},
ast::FunctionDecorationList{}); ast::DecorationList{});
Global("param1", ty.f32(), ast::StorageClass::kNone); Global("param1", ty.f32(), ast::StorageClass::kNone);
Global("param2", ty.f32(), ast::StorageClass::kNone); Global("param2", ty.f32(), ast::StorageClass::kNone);

View File

@ -134,7 +134,7 @@ TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Mat) {
} }
TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Array) { TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Array) {
type::Array ary(ty.vec3<f32>(), 3, ast::ArrayDecorationList{}); type::Array ary(ty.vec3<f32>(), 3, ast::DecorationList{});
ast::ExpressionList ary_values; ast::ExpressionList ary_values;

View File

@ -32,10 +32,10 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Vertex_Input) {
// }; // };
Global("foo", ty.f32(), ast::StorageClass::kInput, nullptr, Global("foo", ty.f32(), ast::StorageClass::kInput, nullptr,
ast::VariableDecorationList{create<ast::LocationDecoration>(0)}); ast::DecorationList{create<ast::LocationDecoration>(0)});
Global("bar", ty.i32(), ast::StorageClass::kInput, nullptr, Global("bar", ty.i32(), ast::StorageClass::kInput, nullptr,
ast::VariableDecorationList{create<ast::LocationDecoration>(1)}); ast::DecorationList{create<ast::LocationDecoration>(1)});
auto body = ast::StatementList{ auto body = ast::StatementList{
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")), create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
@ -43,7 +43,7 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Vertex_Input) {
}; };
Func("vtx_main", ast::VariableList{}, ty.f32(), body, Func("vtx_main", ast::VariableList{}, ty.f32(), body,
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
@ -69,10 +69,10 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Vertex_Output) {
// }; // };
Global("foo", ty.f32(), ast::StorageClass::kOutput, nullptr, Global("foo", ty.f32(), ast::StorageClass::kOutput, nullptr,
ast::VariableDecorationList{create<ast::LocationDecoration>(0)}); ast::DecorationList{create<ast::LocationDecoration>(0)});
Global("bar", ty.i32(), ast::StorageClass::kOutput, nullptr, Global("bar", ty.i32(), ast::StorageClass::kOutput, nullptr,
ast::VariableDecorationList{create<ast::LocationDecoration>(1)}); ast::DecorationList{create<ast::LocationDecoration>(1)});
auto body = ast::StatementList{ auto body = ast::StatementList{
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")), create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
@ -80,7 +80,7 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Vertex_Output) {
}; };
Func("vtx_main", ast::VariableList{}, ty.f32(), body, Func("vtx_main", ast::VariableList{}, ty.f32(), body,
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
@ -106,10 +106,10 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Fragment_Input) {
// }; // };
Global("foo", ty.f32(), ast::StorageClass::kInput, nullptr, Global("foo", ty.f32(), ast::StorageClass::kInput, nullptr,
ast::VariableDecorationList{create<ast::LocationDecoration>(0)}); ast::DecorationList{create<ast::LocationDecoration>(0)});
Global("bar", ty.i32(), ast::StorageClass::kInput, nullptr, Global("bar", ty.i32(), ast::StorageClass::kInput, nullptr,
ast::VariableDecorationList{create<ast::LocationDecoration>(1)}); ast::DecorationList{create<ast::LocationDecoration>(1)});
auto body = ast::StatementList{ auto body = ast::StatementList{
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")), create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
@ -117,7 +117,7 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Fragment_Input) {
}; };
Func("main", ast::VariableList{}, ty.f32(), body, Func("main", ast::VariableList{}, ty.f32(), body,
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment), create<ast::StageDecoration>(ast::PipelineStage::kFragment),
}); });
@ -143,10 +143,10 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Fragment_Output) {
// }; // };
Global("foo", ty.f32(), ast::StorageClass::kOutput, nullptr, Global("foo", ty.f32(), ast::StorageClass::kOutput, nullptr,
ast::VariableDecorationList{create<ast::LocationDecoration>(0)}); ast::DecorationList{create<ast::LocationDecoration>(0)});
Global("bar", ty.i32(), ast::StorageClass::kOutput, nullptr, Global("bar", ty.i32(), ast::StorageClass::kOutput, nullptr,
ast::VariableDecorationList{create<ast::LocationDecoration>(1)}); ast::DecorationList{create<ast::LocationDecoration>(1)});
auto body = ast::StatementList{ auto body = ast::StatementList{
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")), create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
@ -154,7 +154,7 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Fragment_Output) {
}; };
Func("main", ast::VariableList{}, ty.f32(), body, Func("main", ast::VariableList{}, ty.f32(), body,
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment), create<ast::StageDecoration>(ast::PipelineStage::kFragment),
}); });
@ -177,10 +177,10 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Compute_Input) {
// -> Error, not allowed // -> Error, not allowed
Global("foo", ty.f32(), ast::StorageClass::kInput, nullptr, Global("foo", ty.f32(), ast::StorageClass::kInput, nullptr,
ast::VariableDecorationList{create<ast::LocationDecoration>(0)}); ast::DecorationList{create<ast::LocationDecoration>(0)});
Global("bar", ty.i32(), ast::StorageClass::kInput, nullptr, Global("bar", ty.i32(), ast::StorageClass::kInput, nullptr,
ast::VariableDecorationList{create<ast::LocationDecoration>(1)}); ast::DecorationList{create<ast::LocationDecoration>(1)});
auto body = ast::StatementList{ auto body = ast::StatementList{
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")), create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
@ -188,7 +188,7 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Compute_Input) {
}; };
Func("main", ast::VariableList{}, ty.f32(), body, Func("main", ast::VariableList{}, ty.f32(), body,
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kCompute), create<ast::StageDecoration>(ast::PipelineStage::kCompute),
}); });
@ -207,10 +207,10 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Compute_Output) {
// -> Error not allowed // -> Error not allowed
Global("foo", ty.f32(), ast::StorageClass::kOutput, nullptr, Global("foo", ty.f32(), ast::StorageClass::kOutput, nullptr,
ast::VariableDecorationList{create<ast::LocationDecoration>(0)}); ast::DecorationList{create<ast::LocationDecoration>(0)});
Global("bar", ty.i32(), ast::StorageClass::kOutput, nullptr, Global("bar", ty.i32(), ast::StorageClass::kOutput, nullptr,
ast::VariableDecorationList{create<ast::LocationDecoration>(1)}); ast::DecorationList{create<ast::LocationDecoration>(1)});
auto body = ast::StatementList{ auto body = ast::StatementList{
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")), create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
@ -218,7 +218,7 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Compute_Output) {
}; };
Func("main", ast::VariableList{}, ty.f32(), body, Func("main", ast::VariableList{}, ty.f32(), body,
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kCompute), create<ast::StageDecoration>(ast::PipelineStage::kCompute),
}); });
@ -242,18 +242,18 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Builtins) {
// }; // };
Global("coord", ty.vec4<f32>(), ast::StorageClass::kInput, nullptr, Global("coord", ty.vec4<f32>(), ast::StorageClass::kInput, nullptr,
ast::VariableDecorationList{ ast::DecorationList{
create<ast::BuiltinDecoration>(ast::Builtin::kFragCoord)}); create<ast::BuiltinDecoration>(ast::Builtin::kFragCoord)});
Global("depth", ty.f32(), ast::StorageClass::kOutput, nullptr, Global("depth", ty.f32(), ast::StorageClass::kOutput, nullptr,
ast::VariableDecorationList{ ast::DecorationList{
create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth)}); create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth)});
auto body = ast::StatementList{create<ast::AssignmentStatement>( auto body = ast::StatementList{create<ast::AssignmentStatement>(
Expr("depth"), MemberAccessor("coord", "x"))}; Expr("depth"), MemberAccessor("coord", "x"))};
Func("main", ast::VariableList{}, ty.void_(), body, Func("main", ast::VariableList{}, ty.void_(), body,
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment), create<ast::StageDecoration>(ast::PipelineStage::kFragment),
}); });

View File

@ -30,7 +30,7 @@ TEST_F(MslGeneratorImplTest, Emit_Function) {
ast::StatementList{ ast::StatementList{
create<ast::ReturnStatement>(), create<ast::ReturnStatement>(),
}, },
ast::FunctionDecorationList{}); ast::DecorationList{});
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
@ -56,7 +56,7 @@ TEST_F(MslGeneratorImplTest, Emit_Function_WithParams) {
ast::StatementList{ ast::StatementList{
create<ast::ReturnStatement>(), create<ast::ReturnStatement>(),
}, },
ast::FunctionDecorationList{}); ast::DecorationList{});
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
@ -73,10 +73,10 @@ using namespace metal;
)"); )");
} }
TEST_F(MslGeneratorImplTest, Emit_FunctionDecoration_EntryPoint_NoReturn_Void) { TEST_F(MslGeneratorImplTest, Emit_Decoration_EntryPoint_NoReturn_Void) {
Func("main", ast::VariableList{}, ty.void_(), Func("main", ast::VariableList{}, ty.void_(),
ast::StatementList{/* no explicit return */}, ast::StatementList{/* no explicit return */},
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment)}); create<ast::StageDecoration>(ast::PipelineStage::kFragment)});
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
@ -92,19 +92,18 @@ fragment void main() {
)"); )");
} }
TEST_F(MslGeneratorImplTest, TEST_F(MslGeneratorImplTest, Emit_Decoration_EntryPoint_NoReturn_InOut) {
Emit_FunctionDecoration_EntryPoint_NoReturn_InOut) {
Global("foo", ty.f32(), ast::StorageClass::kInput, nullptr, Global("foo", ty.f32(), ast::StorageClass::kInput, nullptr,
ast::VariableDecorationList{create<ast::LocationDecoration>(0)}); ast::DecorationList{create<ast::LocationDecoration>(0)});
Global("bar", ty.f32(), ast::StorageClass::kOutput, nullptr, Global("bar", ty.f32(), ast::StorageClass::kOutput, nullptr,
ast::VariableDecorationList{create<ast::LocationDecoration>(1)}); ast::DecorationList{create<ast::LocationDecoration>(1)});
Func("main", ast::VariableList{}, ty.void_(), Func("main", ast::VariableList{}, ty.void_(),
ast::StatementList{ ast::StatementList{
create<ast::AssignmentStatement>(Expr("bar"), Expr("foo")), create<ast::AssignmentStatement>(Expr("bar"), Expr("foo")),
/* no explicit return */}, /* no explicit return */},
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment)}); create<ast::StageDecoration>(ast::PipelineStage::kFragment)});
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
@ -130,19 +129,19 @@ fragment main_out main(main_in _tint_in [[stage_in]]) {
)"); )");
} }
TEST_F(MslGeneratorImplTest, Emit_FunctionDecoration_EntryPoint_WithInOutVars) { TEST_F(MslGeneratorImplTest, Emit_Decoration_EntryPoint_WithInOutVars) {
Global("foo", ty.f32(), ast::StorageClass::kInput, nullptr, Global("foo", ty.f32(), ast::StorageClass::kInput, nullptr,
ast::VariableDecorationList{create<ast::LocationDecoration>(0)}); ast::DecorationList{create<ast::LocationDecoration>(0)});
Global("bar", ty.f32(), ast::StorageClass::kOutput, nullptr, Global("bar", ty.f32(), ast::StorageClass::kOutput, nullptr,
ast::VariableDecorationList{create<ast::LocationDecoration>(1)}); ast::DecorationList{create<ast::LocationDecoration>(1)});
auto body = ast::StatementList{ auto body = ast::StatementList{
create<ast::AssignmentStatement>(Expr("bar"), Expr("foo")), create<ast::AssignmentStatement>(Expr("bar"), Expr("foo")),
create<ast::ReturnStatement>(), create<ast::ReturnStatement>(),
}; };
Func("frag_main", ast::VariableList{}, ty.void_(), body, Func("frag_main", ast::VariableList{}, ty.void_(), body,
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment)}); create<ast::StageDecoration>(ast::PipelineStage::kFragment)});
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
@ -168,14 +167,13 @@ fragment frag_main_out frag_main(frag_main_in _tint_in [[stage_in]]) {
)"); )");
} }
TEST_F(MslGeneratorImplTest, TEST_F(MslGeneratorImplTest, Emit_Decoration_EntryPoint_WithInOut_Builtins) {
Emit_FunctionDecoration_EntryPoint_WithInOut_Builtins) {
Global("coord", ty.vec4<f32>(), ast::StorageClass::kInput, nullptr, Global("coord", ty.vec4<f32>(), ast::StorageClass::kInput, nullptr,
ast::VariableDecorationList{ ast::DecorationList{
create<ast::BuiltinDecoration>(ast::Builtin::kFragCoord)}); create<ast::BuiltinDecoration>(ast::Builtin::kFragCoord)});
Global("depth", ty.f32(), ast::StorageClass::kOutput, nullptr, Global("depth", ty.f32(), ast::StorageClass::kOutput, nullptr,
ast::VariableDecorationList{ ast::DecorationList{
create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth)}); create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth)});
auto body = ast::StatementList{ auto body = ast::StatementList{
@ -185,7 +183,7 @@ TEST_F(MslGeneratorImplTest,
}; };
Func("frag_main", ast::VariableList{}, ty.void_(), body, Func("frag_main", ast::VariableList{}, ty.void_(), body,
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment), create<ast::StageDecoration>(ast::PipelineStage::kFragment),
}); });
@ -208,10 +206,10 @@ fragment frag_main_out frag_main(float4 coord [[position]]) {
)"); )");
} }
TEST_F(MslGeneratorImplTest, Emit_FunctionDecoration_EntryPoint_With_Uniform) { TEST_F(MslGeneratorImplTest, Emit_Decoration_EntryPoint_With_Uniform) {
Global("coord", ty.vec4<f32>(), ast::StorageClass::kUniform, nullptr, Global("coord", ty.vec4<f32>(), ast::StorageClass::kUniform, nullptr,
ast::VariableDecorationList{create<ast::BindingDecoration>(0), ast::DecorationList{create<ast::BindingDecoration>(0),
create<ast::GroupDecoration>(1)}); create<ast::GroupDecoration>(1)});
auto* var = Var("v", ty.f32(), ast::StorageClass::kFunction, auto* var = Var("v", ty.f32(), ast::StorageClass::kFunction,
MemberAccessor("coord", "x")); MemberAccessor("coord", "x"));
@ -221,7 +219,7 @@ TEST_F(MslGeneratorImplTest, Emit_FunctionDecoration_EntryPoint_With_Uniform) {
create<ast::VariableDeclStatement>(var), create<ast::VariableDeclStatement>(var),
create<ast::ReturnStatement>(), create<ast::ReturnStatement>(),
}, },
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment), create<ast::StageDecoration>(ast::PipelineStage::kFragment),
}); });
@ -239,12 +237,11 @@ fragment void frag_main(constant float4& coord [[buffer(0)]]) {
)"); )");
} }
TEST_F(MslGeneratorImplTest, TEST_F(MslGeneratorImplTest, Emit_Decoration_EntryPoint_With_RW_StorageBuffer) {
Emit_FunctionDecoration_EntryPoint_With_RW_StorageBuffer) {
auto* str = create<ast::Struct>( auto* str = create<ast::Struct>(
ast::StructMemberList{Member("a", ty.i32(), {MemberOffset(0)}), ast::StructMemberList{Member("a", ty.i32(), {MemberOffset(0)}),
Member("b", ty.f32(), {MemberOffset(4)})}, Member("b", ty.f32(), {MemberOffset(4)})},
ast::StructDecorationList{}); ast::DecorationList{});
auto* s = ty.struct_("Data", str); auto* s = ty.struct_("Data", str);
type::AccessControl ac(ast::AccessControl::kReadWrite, s); type::AccessControl ac(ast::AccessControl::kReadWrite, s);
@ -252,8 +249,8 @@ TEST_F(MslGeneratorImplTest,
AST().AddConstructedType(s); AST().AddConstructedType(s);
Global("coord", &ac, ast::StorageClass::kStorage, nullptr, Global("coord", &ac, ast::StorageClass::kStorage, nullptr,
ast::VariableDecorationList{create<ast::BindingDecoration>(0), ast::DecorationList{create<ast::BindingDecoration>(0),
create<ast::GroupDecoration>(1)}); create<ast::GroupDecoration>(1)});
auto* var = Var("v", ty.f32(), ast::StorageClass::kFunction, auto* var = Var("v", ty.f32(), ast::StorageClass::kFunction,
MemberAccessor("coord", "b")); MemberAccessor("coord", "b"));
@ -263,7 +260,7 @@ TEST_F(MslGeneratorImplTest,
create<ast::VariableDeclStatement>(var), create<ast::VariableDeclStatement>(var),
create<ast::ReturnStatement>(), create<ast::ReturnStatement>(),
}, },
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment), create<ast::StageDecoration>(ast::PipelineStage::kFragment),
}); });
@ -286,20 +283,19 @@ fragment void frag_main(device Data& coord [[buffer(0)]]) {
)"); )");
} }
TEST_F(MslGeneratorImplTest, TEST_F(MslGeneratorImplTest, Emit_Decoration_EntryPoint_With_RO_StorageBuffer) {
Emit_FunctionDecoration_EntryPoint_With_RO_StorageBuffer) {
auto* str = create<ast::Struct>( auto* str = create<ast::Struct>(
ast::StructMemberList{Member("a", ty.i32(), {MemberOffset(0)}), ast::StructMemberList{Member("a", ty.i32(), {MemberOffset(0)}),
Member("b", ty.f32(), {MemberOffset(4)})}, Member("b", ty.f32(), {MemberOffset(4)})},
ast::StructDecorationList{}); ast::DecorationList{});
auto* s = ty.struct_("Data", str); auto* s = ty.struct_("Data", str);
type::AccessControl ac(ast::AccessControl::kReadOnly, s); type::AccessControl ac(ast::AccessControl::kReadOnly, s);
AST().AddConstructedType(s); AST().AddConstructedType(s);
Global("coord", &ac, ast::StorageClass::kStorage, nullptr, Global("coord", &ac, ast::StorageClass::kStorage, nullptr,
ast::VariableDecorationList{create<ast::BindingDecoration>(0), ast::DecorationList{create<ast::BindingDecoration>(0),
create<ast::GroupDecoration>(1)}); create<ast::GroupDecoration>(1)});
auto* var = Var("v", ty.f32(), ast::StorageClass::kFunction, auto* var = Var("v", ty.f32(), ast::StorageClass::kFunction,
MemberAccessor("coord", "b")); MemberAccessor("coord", "b"));
@ -309,7 +305,7 @@ TEST_F(MslGeneratorImplTest,
create<ast::VariableDeclStatement>(var), create<ast::VariableDeclStatement>(var),
create<ast::ReturnStatement>(), create<ast::ReturnStatement>(),
}, },
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment), create<ast::StageDecoration>(ast::PipelineStage::kFragment),
}); });
@ -334,15 +330,15 @@ fragment void frag_main(const device Data& coord [[buffer(0)]]) {
TEST_F( TEST_F(
MslGeneratorImplTest, MslGeneratorImplTest,
Emit_FunctionDecoration_Called_By_EntryPoints_WithLocationGlobals_And_Params) { // NOLINT Emit_Decoration_Called_By_EntryPoints_WithLocationGlobals_And_Params) { // NOLINT
Global("foo", ty.f32(), ast::StorageClass::kInput, nullptr, Global("foo", ty.f32(), ast::StorageClass::kInput, nullptr,
ast::VariableDecorationList{create<ast::LocationDecoration>(0)}); ast::DecorationList{create<ast::LocationDecoration>(0)});
Global("bar", ty.f32(), ast::StorageClass::kOutput, nullptr, Global("bar", ty.f32(), ast::StorageClass::kOutput, nullptr,
ast::VariableDecorationList{create<ast::LocationDecoration>(1)}); ast::DecorationList{create<ast::LocationDecoration>(1)});
Global("val", ty.f32(), ast::StorageClass::kOutput, nullptr, Global("val", ty.f32(), ast::StorageClass::kOutput, nullptr,
ast::VariableDecorationList{create<ast::LocationDecoration>(0)}); ast::DecorationList{create<ast::LocationDecoration>(0)});
ast::VariableList params; ast::VariableList params;
params.push_back(Var("param", ty.f32(), ast::StorageClass::kFunction)); params.push_back(Var("param", ty.f32(), ast::StorageClass::kFunction));
@ -352,7 +348,7 @@ TEST_F(
create<ast::AssignmentStatement>(Expr("val"), Expr("param")), create<ast::AssignmentStatement>(Expr("val"), Expr("param")),
create<ast::ReturnStatement>(Expr("foo"))}; create<ast::ReturnStatement>(Expr("foo"))};
Func("sub_func", params, ty.f32(), body, ast::FunctionDecorationList{}); Func("sub_func", params, ty.f32(), body, ast::DecorationList{});
body = ast::StatementList{ body = ast::StatementList{
create<ast::AssignmentStatement>(Expr("bar"), Call("sub_func", 1.0f)), create<ast::AssignmentStatement>(Expr("bar"), Call("sub_func", 1.0f)),
@ -360,7 +356,7 @@ TEST_F(
}; };
Func("ep_1", ast::VariableList{}, ty.void_(), body, Func("ep_1", ast::VariableList{}, ty.void_(), body,
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment), create<ast::StageDecoration>(ast::PipelineStage::kFragment),
}); });
@ -395,9 +391,9 @@ fragment ep_1_out ep_1(ep_1_in _tint_in [[stage_in]]) {
} }
TEST_F(MslGeneratorImplTest, TEST_F(MslGeneratorImplTest,
Emit_FunctionDecoration_Called_By_EntryPoints_NoUsedGlobals) { Emit_Decoration_Called_By_EntryPoints_NoUsedGlobals) {
Global("depth", ty.f32(), ast::StorageClass::kOutput, nullptr, Global("depth", ty.f32(), ast::StorageClass::kOutput, nullptr,
ast::VariableDecorationList{ ast::DecorationList{
create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth)}); create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth)});
ast::VariableList params; ast::VariableList params;
@ -407,7 +403,7 @@ TEST_F(MslGeneratorImplTest,
ast::StatementList{ ast::StatementList{
create<ast::ReturnStatement>(Expr("param")), create<ast::ReturnStatement>(Expr("param")),
}, },
ast::FunctionDecorationList{}); ast::DecorationList{});
auto body = ast::StatementList{ auto body = ast::StatementList{
create<ast::AssignmentStatement>(Expr("depth"), Call("sub_func", 1.0f)), create<ast::AssignmentStatement>(Expr("depth"), Call("sub_func", 1.0f)),
@ -415,7 +411,7 @@ TEST_F(MslGeneratorImplTest,
}; };
Func("ep_1", ast::VariableList{}, ty.void_(), body, Func("ep_1", ast::VariableList{}, ty.void_(), body,
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment), create<ast::StageDecoration>(ast::PipelineStage::kFragment),
}); });
@ -444,13 +440,13 @@ fragment ep_1_out ep_1() {
TEST_F( TEST_F(
MslGeneratorImplTest, MslGeneratorImplTest,
Emit_FunctionDecoration_Called_By_EntryPoints_WithBuiltinGlobals_And_Params) { // NOLINT Emit_Decoration_Called_By_EntryPoints_WithBuiltinGlobals_And_Params) { // NOLINT
Global("coord", ty.vec4<f32>(), ast::StorageClass::kInput, nullptr, Global("coord", ty.vec4<f32>(), ast::StorageClass::kInput, nullptr,
ast::VariableDecorationList{ ast::DecorationList{
create<ast::BuiltinDecoration>(ast::Builtin::kFragCoord)}); create<ast::BuiltinDecoration>(ast::Builtin::kFragCoord)});
Global("depth", ty.f32(), ast::StorageClass::kOutput, nullptr, Global("depth", ty.f32(), ast::StorageClass::kOutput, nullptr,
ast::VariableDecorationList{ ast::DecorationList{
create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth)}); create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth)});
ast::VariableList params; ast::VariableList params;
@ -462,7 +458,7 @@ TEST_F(
create<ast::ReturnStatement>(Expr("param")), create<ast::ReturnStatement>(Expr("param")),
}; };
Func("sub_func", params, ty.f32(), body, ast::FunctionDecorationList{}); Func("sub_func", params, ty.f32(), body, ast::DecorationList{});
body = ast::StatementList{ body = ast::StatementList{
create<ast::AssignmentStatement>(Expr("depth"), Call("sub_func", 1.0f)), create<ast::AssignmentStatement>(Expr("depth"), Call("sub_func", 1.0f)),
@ -470,7 +466,7 @@ TEST_F(
}; };
Func("ep_1", ast::VariableList{}, ty.void_(), body, Func("ep_1", ast::VariableList{}, ty.void_(), body,
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment), create<ast::StageDecoration>(ast::PipelineStage::kFragment),
}); });
@ -499,10 +495,10 @@ fragment ep_1_out ep_1(float4 coord [[position]]) {
} }
TEST_F(MslGeneratorImplTest, TEST_F(MslGeneratorImplTest,
Emit_FunctionDecoration_Called_By_EntryPoint_With_Uniform) { Emit_Decoration_Called_By_EntryPoint_With_Uniform) {
Global("coord", ty.vec4<f32>(), ast::StorageClass::kUniform, nullptr, Global("coord", ty.vec4<f32>(), ast::StorageClass::kUniform, nullptr,
ast::VariableDecorationList{create<ast::BindingDecoration>(0), ast::DecorationList{create<ast::BindingDecoration>(0),
create<ast::GroupDecoration>(1)}); create<ast::GroupDecoration>(1)});
ast::VariableList params; ast::VariableList params;
params.push_back(Var("param", ty.f32(), ast::StorageClass::kFunction)); params.push_back(Var("param", ty.f32(), ast::StorageClass::kFunction));
@ -511,7 +507,7 @@ TEST_F(MslGeneratorImplTest,
create<ast::ReturnStatement>(MemberAccessor("coord", "x")), create<ast::ReturnStatement>(MemberAccessor("coord", "x")),
}; };
Func("sub_func", params, ty.f32(), body, ast::FunctionDecorationList{}); Func("sub_func", params, ty.f32(), body, ast::DecorationList{});
ast::ExpressionList expr; ast::ExpressionList expr;
expr.push_back(Expr(1.0f)); expr.push_back(Expr(1.0f));
@ -524,7 +520,7 @@ TEST_F(MslGeneratorImplTest,
create<ast::VariableDeclStatement>(var), create<ast::VariableDeclStatement>(var),
create<ast::ReturnStatement>(), create<ast::ReturnStatement>(),
}, },
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment), create<ast::StageDecoration>(ast::PipelineStage::kFragment),
}); });
@ -547,19 +543,19 @@ fragment void frag_main(constant float4& coord [[buffer(0)]]) {
} }
TEST_F(MslGeneratorImplTest, TEST_F(MslGeneratorImplTest,
Emit_FunctionDecoration_Called_By_EntryPoint_With_RW_StorageBuffer) { Emit_Decoration_Called_By_EntryPoint_With_RW_StorageBuffer) {
auto* str = create<ast::Struct>( auto* str = create<ast::Struct>(
ast::StructMemberList{Member("a", ty.i32(), {MemberOffset(0)}), ast::StructMemberList{Member("a", ty.i32(), {MemberOffset(0)}),
Member("b", ty.f32(), {MemberOffset(4)})}, Member("b", ty.f32(), {MemberOffset(4)})},
ast::StructDecorationList{}); ast::DecorationList{});
auto* s = ty.struct_("Data", str); auto* s = ty.struct_("Data", str);
type::AccessControl ac(ast::AccessControl::kReadWrite, s); type::AccessControl ac(ast::AccessControl::kReadWrite, s);
AST().AddConstructedType(s); AST().AddConstructedType(s);
Global("coord", &ac, ast::StorageClass::kStorage, nullptr, Global("coord", &ac, ast::StorageClass::kStorage, nullptr,
ast::VariableDecorationList{create<ast::BindingDecoration>(0), ast::DecorationList{create<ast::BindingDecoration>(0),
create<ast::GroupDecoration>(1)}); create<ast::GroupDecoration>(1)});
ast::VariableList params; ast::VariableList params;
params.push_back(Var("param", ty.f32(), ast::StorageClass::kFunction)); params.push_back(Var("param", ty.f32(), ast::StorageClass::kFunction));
@ -567,7 +563,7 @@ TEST_F(MslGeneratorImplTest,
auto body = ast::StatementList{ auto body = ast::StatementList{
create<ast::ReturnStatement>(MemberAccessor("coord", "b"))}; create<ast::ReturnStatement>(MemberAccessor("coord", "b"))};
Func("sub_func", params, ty.f32(), body, ast::FunctionDecorationList{}); Func("sub_func", params, ty.f32(), body, ast::DecorationList{});
auto* var = auto* var =
Var("v", ty.f32(), ast::StorageClass::kFunction, Call("sub_func", 1.0f)); Var("v", ty.f32(), ast::StorageClass::kFunction, Call("sub_func", 1.0f));
@ -577,7 +573,7 @@ TEST_F(MslGeneratorImplTest,
create<ast::VariableDeclStatement>(var), create<ast::VariableDeclStatement>(var),
create<ast::ReturnStatement>(), create<ast::ReturnStatement>(),
}, },
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment), create<ast::StageDecoration>(ast::PipelineStage::kFragment),
}); });
@ -605,19 +601,19 @@ fragment void frag_main(device Data& coord [[buffer(0)]]) {
} }
TEST_F(MslGeneratorImplTest, TEST_F(MslGeneratorImplTest,
Emit_FunctionDecoration_Called_By_EntryPoint_With_RO_StorageBuffer) { Emit_Decoration_Called_By_EntryPoint_With_RO_StorageBuffer) {
auto* str = create<ast::Struct>( auto* str = create<ast::Struct>(
ast::StructMemberList{Member("a", ty.i32(), {MemberOffset(0)}), ast::StructMemberList{Member("a", ty.i32(), {MemberOffset(0)}),
Member("b", ty.f32(), {MemberOffset(4)})}, Member("b", ty.f32(), {MemberOffset(4)})},
ast::StructDecorationList{}); ast::DecorationList{});
auto* s = ty.struct_("Data", str); auto* s = ty.struct_("Data", str);
type::AccessControl ac(ast::AccessControl::kReadOnly, s); type::AccessControl ac(ast::AccessControl::kReadOnly, s);
AST().AddConstructedType(s); AST().AddConstructedType(s);
Global("coord", &ac, ast::StorageClass::kStorage, nullptr, Global("coord", &ac, ast::StorageClass::kStorage, nullptr,
ast::VariableDecorationList{create<ast::BindingDecoration>(0), ast::DecorationList{create<ast::BindingDecoration>(0),
create<ast::GroupDecoration>(1)}); create<ast::GroupDecoration>(1)});
ast::VariableList params; ast::VariableList params;
params.push_back(Var("param", ty.f32(), ast::StorageClass::kFunction)); params.push_back(Var("param", ty.f32(), ast::StorageClass::kFunction));
@ -625,7 +621,7 @@ TEST_F(MslGeneratorImplTest,
auto body = ast::StatementList{ auto body = ast::StatementList{
create<ast::ReturnStatement>(MemberAccessor("coord", "b"))}; create<ast::ReturnStatement>(MemberAccessor("coord", "b"))};
Func("sub_func", params, ty.f32(), body, ast::FunctionDecorationList{}); Func("sub_func", params, ty.f32(), body, ast::DecorationList{});
ast::ExpressionList expr; ast::ExpressionList expr;
expr.push_back(Expr(1.0f)); expr.push_back(Expr(1.0f));
@ -638,7 +634,7 @@ TEST_F(MslGeneratorImplTest,
create<ast::VariableDeclStatement>(var), create<ast::VariableDeclStatement>(var),
create<ast::ReturnStatement>(), create<ast::ReturnStatement>(),
}, },
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment), create<ast::StageDecoration>(ast::PipelineStage::kFragment),
}); });
@ -666,9 +662,9 @@ fragment void frag_main(const device Data& coord [[buffer(0)]]) {
} }
TEST_F(MslGeneratorImplTest, TEST_F(MslGeneratorImplTest,
Emit_FunctionDecoration_EntryPoints_WithGlobal_Nested_Return) { Emit_Decoration_EntryPoints_WithGlobal_Nested_Return) {
Global("bar", ty.f32(), ast::StorageClass::kOutput, nullptr, Global("bar", ty.f32(), ast::StorageClass::kOutput, nullptr,
ast::VariableDecorationList{create<ast::LocationDecoration>(1)}); ast::DecorationList{create<ast::LocationDecoration>(1)});
auto* list = create<ast::BlockStatement>(ast::StatementList{ auto* list = create<ast::BlockStatement>(ast::StatementList{
create<ast::ReturnStatement>(), create<ast::ReturnStatement>(),
@ -683,7 +679,7 @@ TEST_F(MslGeneratorImplTest,
}; };
Func("ep_1", ast::VariableList{}, ty.void_(), body, Func("ep_1", ast::VariableList{}, ty.void_(), body,
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment), create<ast::StageDecoration>(ast::PipelineStage::kFragment),
}); });
@ -717,7 +713,7 @@ TEST_F(MslGeneratorImplTest, Emit_Function_WithArrayParams) {
ast::StatementList{ ast::StatementList{
create<ast::ReturnStatement>(), create<ast::ReturnStatement>(),
}, },
ast::FunctionDecorationList{}); ast::DecorationList{});
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
@ -752,7 +748,7 @@ TEST_F(MslGeneratorImplTest,
// return; // return;
// } // }
ast::StructDecorationList s_decos; ast::DecorationList s_decos;
s_decos.push_back(create<ast::StructBlockDecoration>()); s_decos.push_back(create<ast::StructBlockDecoration>());
auto* str = create<ast::Struct>( auto* str = create<ast::Struct>(
@ -762,8 +758,8 @@ TEST_F(MslGeneratorImplTest,
type::AccessControl ac(ast::AccessControl::kReadWrite, s); type::AccessControl ac(ast::AccessControl::kReadWrite, s);
Global("data", &ac, ast::StorageClass::kStorage, nullptr, Global("data", &ac, ast::StorageClass::kStorage, nullptr,
ast::VariableDecorationList{create<ast::BindingDecoration>(0), ast::DecorationList{create<ast::BindingDecoration>(0),
create<ast::GroupDecoration>(0)}); create<ast::GroupDecoration>(0)});
AST().AddConstructedType(s); AST().AddConstructedType(s);
@ -776,7 +772,7 @@ TEST_F(MslGeneratorImplTest,
create<ast::VariableDeclStatement>(var), create<ast::VariableDeclStatement>(var),
create<ast::ReturnStatement>(), create<ast::ReturnStatement>(),
}, },
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kCompute), create<ast::StageDecoration>(ast::PipelineStage::kCompute),
}); });
} }
@ -788,7 +784,7 @@ TEST_F(MslGeneratorImplTest,
Func("b", ast::VariableList{}, ty.void_(), Func("b", ast::VariableList{}, ty.void_(),
ast::StatementList{create<ast::VariableDeclStatement>(var), ast::StatementList{create<ast::VariableDeclStatement>(var),
create<ast::ReturnStatement>()}, create<ast::ReturnStatement>()},
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kCompute)}); create<ast::StageDecoration>(ast::PipelineStage::kCompute)});
} }

View File

@ -27,7 +27,7 @@ TEST_F(MslGeneratorImplTest, EmitExpression_MemberAccessor) {
ast::StructMemberList{ ast::StructMemberList{
Member("mem", ty.f32()), Member("mem", ty.f32()),
}, },
ast::StructDecorationList{})), ast::DecorationList{})),
ast::StorageClass::kPrivate); ast::StorageClass::kPrivate);
auto* expr = MemberAccessor("str", "mem"); auto* expr = MemberAccessor("str", "mem");
WrapInFunction(expr); WrapInFunction(expr);

View File

@ -33,7 +33,7 @@ TEST_F(MslGeneratorImplTest, Emit_ModuleConstant) {
TEST_F(MslGeneratorImplTest, Emit_SpecConstant) { TEST_F(MslGeneratorImplTest, Emit_SpecConstant) {
auto* var = Const("pos", ty.f32(), Expr(3.f), auto* var = Const("pos", ty.f32(), Expr(3.f),
ast::VariableDecorationList{ ast::DecorationList{
create<ast::ConstantIdDecoration>(23), create<ast::ConstantIdDecoration>(23),
}); });

View File

@ -24,7 +24,7 @@ using MslGeneratorImplTest = TestHelper;
TEST_F(MslGeneratorImplTest, Generate) { TEST_F(MslGeneratorImplTest, Generate) {
Func("my_func", ast::VariableList{}, ty.void_(), ast::StatementList{}, Func("my_func", ast::VariableList{}, ty.void_(), ast::StatementList{},
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kCompute), create<ast::StageDecoration>(ast::PipelineStage::kCompute),
}); });
@ -139,7 +139,7 @@ TEST_F(MslGeneratorImplTest, calculate_alignment_size_struct) {
ast::StructMemberList{Member("a", ty.i32(), {MemberOffset(4)}), ast::StructMemberList{Member("a", ty.i32(), {MemberOffset(4)}),
Member("b", ty.f32(), {MemberOffset(32)}), Member("b", ty.f32(), {MemberOffset(32)}),
Member("c", ty.f32(), {MemberOffset(128)})}, Member("c", ty.f32(), {MemberOffset(128)})},
ast::StructDecorationList{}); ast::DecorationList{});
auto* s = ty.struct_("S", str); auto* s = ty.struct_("S", str);
@ -153,7 +153,7 @@ TEST_F(MslGeneratorImplTest, calculate_alignment_size_struct_of_struct) {
ast::StructMemberList{Member("a", ty.i32(), {MemberOffset(0)}), ast::StructMemberList{Member("a", ty.i32(), {MemberOffset(0)}),
Member("b", ty.vec3<f32>(), {MemberOffset(16)}), Member("b", ty.vec3<f32>(), {MemberOffset(16)}),
Member("c", ty.f32(), {MemberOffset(32)})}, Member("c", ty.f32(), {MemberOffset(32)})},
ast::StructDecorationList{}); ast::DecorationList{});
auto* inner_s = ty.struct_("Inner", inner_str); auto* inner_s = ty.struct_("Inner", inner_str);
@ -161,7 +161,7 @@ TEST_F(MslGeneratorImplTest, calculate_alignment_size_struct_of_struct) {
ast::StructMemberList{Member("d", ty.f32(), {MemberOffset(0)}), ast::StructMemberList{Member("d", ty.f32(), {MemberOffset(0)}),
Member("e", inner_s, {MemberOffset(32)}), Member("e", inner_s, {MemberOffset(32)}),
Member("f", ty.f32(), {MemberOffset(64)})}, Member("f", ty.f32(), {MemberOffset(64)})},
ast::StructDecorationList{}); ast::DecorationList{});
auto* outer_s = ty.struct_("Outer", outer_str); auto* outer_s = ty.struct_("Outer", outer_str);

View File

@ -146,7 +146,7 @@ TEST_F(MslGeneratorImplTest, EmitType_Struct) {
auto* str = create<ast::Struct>( auto* str = create<ast::Struct>(
ast::StructMemberList{Member("a", ty.i32()), ast::StructMemberList{Member("a", ty.i32()),
Member("b", ty.f32(), {MemberOffset(4)})}, Member("b", ty.f32(), {MemberOffset(4)})},
ast::StructDecorationList{}); ast::DecorationList{});
auto* s = ty.struct_("S", str); auto* s = ty.struct_("S", str);
@ -160,7 +160,7 @@ TEST_F(MslGeneratorImplTest, EmitType_StructDecl) {
auto* str = create<ast::Struct>( auto* str = create<ast::Struct>(
ast::StructMemberList{Member("a", ty.i32()), ast::StructMemberList{Member("a", ty.i32()),
Member("b", ty.f32(), {MemberOffset(4)})}, Member("b", ty.f32(), {MemberOffset(4)})},
ast::StructDecorationList{}); ast::DecorationList{});
auto* s = ty.struct_("S", str); auto* s = ty.struct_("S", str);
@ -181,7 +181,7 @@ TEST_F(MslGeneratorImplTest, EmitType_Struct_InjectPadding) {
Member("b", ty.f32(), {MemberOffset(32)}), Member("b", ty.f32(), {MemberOffset(32)}),
Member("c", ty.f32(), {MemberOffset(128)}), Member("c", ty.f32(), {MemberOffset(128)}),
}, },
ast::StructDecorationList{}); ast::DecorationList{});
auto* s = ty.struct_("S", str); auto* s = ty.struct_("S", str);
@ -201,7 +201,7 @@ TEST_F(MslGeneratorImplTest, EmitType_Struct_InjectPadding) {
// TODO(dsinclair): How to translate [[block]] // TODO(dsinclair): How to translate [[block]]
TEST_F(MslGeneratorImplTest, DISABLED_EmitType_Struct_WithDecoration) { TEST_F(MslGeneratorImplTest, DISABLED_EmitType_Struct_WithDecoration) {
ast::StructDecorationList decos; ast::DecorationList decos;
decos.push_back(create<ast::StructBlockDecoration>()); decos.push_back(create<ast::StructBlockDecoration>());
auto* str = create<ast::Struct>( auto* str = create<ast::Struct>(
ast::StructMemberList{Member("a", ty.i32()), ast::StructMemberList{Member("a", ty.i32()),

View File

@ -49,7 +49,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Const) {
} }
TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Array) { TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Array) {
type::Array ary(ty.f32(), 5, ast::ArrayDecorationList{}); type::Array ary(ty.f32(), 5, ast::DecorationList{});
auto* var = Var("a", &ary, ast::StorageClass::kNone); auto* var = Var("a", &ary, ast::StorageClass::kNone);
auto* stmt = create<ast::VariableDeclStatement>(var); auto* stmt = create<ast::VariableDeclStatement>(var);
@ -67,7 +67,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Struct) {
auto* str = create<ast::Struct>( auto* str = create<ast::Struct>(
ast::StructMemberList{Member("a", ty.f32()), ast::StructMemberList{Member("a", ty.f32()),
Member("b", ty.f32(), {MemberOffset(4)})}, Member("b", ty.f32(), {MemberOffset(4)})},
ast::StructDecorationList{}); ast::DecorationList{});
auto* s = ty.struct_("S", str); auto* s = ty.struct_("S", str);
auto* var = Var("a", s, ast::StorageClass::kNone); auto* var = Var("a", s, ast::StorageClass::kNone);

View File

@ -135,7 +135,7 @@ TEST_F(BuilderTest, ArrayAccessor_Dynamic) {
} }
TEST_F(BuilderTest, ArrayAccessor_MultiLevel) { TEST_F(BuilderTest, ArrayAccessor_MultiLevel) {
type::Array ary4(ty.vec3<f32>(), 4, ast::ArrayDecorationList{}); type::Array ary4(ty.vec3<f32>(), 4, ast::DecorationList{});
// ary = array<vec3<f32>, 4> // ary = array<vec3<f32>, 4>
// ary[3][2]; // ary[3][2];
@ -173,7 +173,7 @@ TEST_F(BuilderTest, ArrayAccessor_MultiLevel) {
} }
TEST_F(BuilderTest, Accessor_ArrayWithSwizzle) { TEST_F(BuilderTest, Accessor_ArrayWithSwizzle) {
type::Array ary4(ty.vec3<f32>(), 4, ast::ArrayDecorationList{}); type::Array ary4(ty.vec3<f32>(), 4, ast::DecorationList{});
// var a : array<vec3<f32>, 4>; // var a : array<vec3<f32>, 4>;
// a[2].xy; // a[2].xy;
@ -221,7 +221,7 @@ TEST_F(BuilderTest, MemberAccessor) {
auto* s = create<ast::Struct>( auto* s = create<ast::Struct>(
ast::StructMemberList{Member("a", ty.f32()), Member("b", ty.f32())}, ast::StructMemberList{Member("a", ty.f32()), Member("b", ty.f32())},
ast::StructDecorationList{}); ast::DecorationList{});
auto* s_type = ty.struct_("my_struct", s); auto* s_type = ty.struct_("my_struct", s);
auto* var = Global("ident", s_type, ast::StorageClass::kFunction); auto* var = Global("ident", s_type, ast::StorageClass::kFunction);
@ -265,12 +265,12 @@ TEST_F(BuilderTest, MemberAccessor_Nested) {
auto* inner_struct = ty.struct_( auto* inner_struct = ty.struct_(
"Inner", create<ast::Struct>(ast::StructMemberList{Member("a", ty.f32()), "Inner", create<ast::Struct>(ast::StructMemberList{Member("a", ty.f32()),
Member("b", ty.f32())}, Member("b", ty.f32())},
ast::StructDecorationList{})); ast::DecorationList{}));
auto* s_type = ty.struct_( auto* s_type = ty.struct_(
"my_struct", "my_struct",
create<ast::Struct>(ast::StructMemberList{Member("inner", inner_struct)}, create<ast::Struct>(ast::StructMemberList{Member("inner", inner_struct)},
ast::StructDecorationList{})); ast::DecorationList{}));
auto* var = Global("ident", s_type, ast::StorageClass::kFunction); auto* var = Global("ident", s_type, ast::StorageClass::kFunction);
auto* expr = MemberAccessor(MemberAccessor("ident", "inner"), "a"); auto* expr = MemberAccessor(MemberAccessor("ident", "inner"), "a");
@ -314,13 +314,13 @@ TEST_F(BuilderTest, MemberAccessor_Nested_WithAlias) {
auto* inner_struct = ty.struct_( auto* inner_struct = ty.struct_(
"Inner", create<ast::Struct>(ast::StructMemberList{Member("a", ty.f32()), "Inner", create<ast::Struct>(ast::StructMemberList{Member("a", ty.f32()),
Member("b", ty.f32())}, Member("b", ty.f32())},
ast::StructDecorationList{})); ast::DecorationList{}));
auto* alias = ty.alias("Inner", inner_struct); auto* alias = ty.alias("Inner", inner_struct);
auto* s_type = ty.struct_( auto* s_type = ty.struct_(
"Outer", "Outer",
create<ast::Struct>(ast::StructMemberList{Member("inner", alias)}, create<ast::Struct>(ast::StructMemberList{Member("inner", alias)},
ast::StructDecorationList{})); ast::DecorationList{}));
auto* var = Global("ident", s_type, ast::StorageClass::kFunction); auto* var = Global("ident", s_type, ast::StorageClass::kFunction);
auto* expr = MemberAccessor(MemberAccessor("ident", "inner"), "a"); auto* expr = MemberAccessor(MemberAccessor("ident", "inner"), "a");
@ -363,12 +363,12 @@ TEST_F(BuilderTest, MemberAccessor_Nested_Assignment_LHS) {
auto* inner_struct = ty.struct_( auto* inner_struct = ty.struct_(
"Inner", create<ast::Struct>(ast::StructMemberList{Member("a", ty.f32()), "Inner", create<ast::Struct>(ast::StructMemberList{Member("a", ty.f32()),
Member("b", ty.f32())}, Member("b", ty.f32())},
ast::StructDecorationList{})); ast::DecorationList{}));
auto* s_type = ty.struct_( auto* s_type = ty.struct_(
"my_struct", "my_struct",
create<ast::Struct>(ast::StructMemberList{Member("inner", inner_struct)}, create<ast::Struct>(ast::StructMemberList{Member("inner", inner_struct)},
ast::StructDecorationList{})); ast::DecorationList{}));
auto* var = Global("ident", s_type, ast::StorageClass::kFunction); auto* var = Global("ident", s_type, ast::StorageClass::kFunction);
auto* expr = create<ast::AssignmentStatement>( auto* expr = create<ast::AssignmentStatement>(
@ -415,12 +415,12 @@ TEST_F(BuilderTest, MemberAccessor_Nested_Assignment_RHS) {
auto* inner_struct = ty.struct_( auto* inner_struct = ty.struct_(
"Inner", create<ast::Struct>(ast::StructMemberList{Member("a", ty.f32()), "Inner", create<ast::Struct>(ast::StructMemberList{Member("a", ty.f32()),
Member("b", ty.f32())}, Member("b", ty.f32())},
ast::StructDecorationList{})); ast::DecorationList{}));
auto* s_type = ty.struct_( auto* s_type = ty.struct_(
"my_struct", "my_struct",
create<ast::Struct>(ast::StructMemberList{Member("inner", inner_struct)}, create<ast::Struct>(ast::StructMemberList{Member("inner", inner_struct)},
ast::StructDecorationList{})); ast::DecorationList{}));
auto* var = Global("ident", s_type, ast::StorageClass::kFunction); auto* var = Global("ident", s_type, ast::StorageClass::kFunction);
auto* store = Global("store", ty.f32(), ast::StorageClass::kFunction); auto* store = Global("store", ty.f32(), ast::StorageClass::kFunction);
@ -627,18 +627,18 @@ TEST_F(BuilderTest, Accessor_Mixed_ArrayAndMember) {
auto* s = auto* s =
create<ast::Struct>(ast::StructMemberList{Member("baz", ty.vec3<f32>())}, create<ast::Struct>(ast::StructMemberList{Member("baz", ty.vec3<f32>())},
ast::StructDecorationList{}); ast::DecorationList{});
auto* c_type = ty.struct_("C", s); auto* c_type = ty.struct_("C", s);
s = create<ast::Struct>(ast::StructMemberList{Member("bar", c_type)}, s = create<ast::Struct>(ast::StructMemberList{Member("bar", c_type)},
ast::StructDecorationList{}); ast::DecorationList{});
auto* b_type = ty.struct_("B", s); auto* b_type = ty.struct_("B", s);
type::Array b_ary_type(b_type, 3, ast::ArrayDecorationList{}); type::Array b_ary_type(b_type, 3, ast::DecorationList{});
s = create<ast::Struct>(ast::StructMemberList{Member("foo", &b_ary_type)}, s = create<ast::Struct>(ast::StructMemberList{Member("foo", &b_ary_type)},
ast::StructDecorationList{}); ast::DecorationList{});
auto* a_type = ty.struct_("A", s); auto* a_type = ty.struct_("A", s);
type::Array a_ary_type(a_type, 2, ast::ArrayDecorationList{}); type::Array a_ary_type(a_type, 2, ast::DecorationList{});
auto* var = Global("index", &a_ary_type, ast::StorageClass::kFunction); auto* var = Global("index", &a_ary_type, ast::StorageClass::kFunction);
auto* expr = MemberAccessor( auto* expr = MemberAccessor(
MemberAccessor( MemberAccessor(
@ -693,7 +693,7 @@ TEST_F(BuilderTest, Accessor_Array_Of_Vec) {
// vec2<f32>(0.5, -0.5)); // vec2<f32>(0.5, -0.5));
// pos[1] // pos[1]
type::Array arr(ty.vec2<f32>(), 3, ast::ArrayDecorationList{}); type::Array arr(ty.vec2<f32>(), 3, ast::DecorationList{});
auto* var = auto* var =
GlobalConst("pos", &arr, GlobalConst("pos", &arr,

View File

@ -178,7 +178,7 @@ TEST_F(BuilderTest, Assign_StructMember) {
auto* s = create<ast::Struct>( auto* s = create<ast::Struct>(
ast::StructMemberList{Member("a", ty.f32()), Member("b", ty.f32())}, ast::StructMemberList{Member("a", ty.f32()), Member("b", ty.f32())},
ast::StructDecorationList{}); ast::DecorationList{});
auto* s_type = ty.struct_("my_struct", s); auto* s_type = ty.struct_("my_struct", s);
auto* v = Global("ident", s_type, ast::StorageClass::kFunction); auto* v = Global("ident", s_type, ast::StorageClass::kFunction);

View File

@ -32,10 +32,10 @@ TEST_F(BuilderTest, Expression_Call) {
auto* a_func = auto* a_func =
Func("a_func", func_params, ty.f32(), Func("a_func", func_params, ty.f32(),
ast::StatementList{create<ast::ReturnStatement>(Add("a", "b"))}, ast::StatementList{create<ast::ReturnStatement>(Add("a", "b"))},
ast::FunctionDecorationList{}); ast::DecorationList{});
auto* func = Func("main", {}, ty.void_(), ast::StatementList{}, auto* func =
ast::FunctionDecorationList{}); Func("main", {}, ty.void_(), ast::StatementList{}, ast::DecorationList{});
auto* expr = Call("a_func", 1.f, 1.f); auto* expr = Call("a_func", 1.f, 1.f);
@ -81,10 +81,10 @@ TEST_F(BuilderTest, Statement_Call) {
auto* a_func = auto* a_func =
Func("a_func", func_params, ty.void_(), Func("a_func", func_params, ty.void_(),
ast::StatementList{create<ast::ReturnStatement>(Add("a", "b"))}, ast::StatementList{create<ast::ReturnStatement>(Add("a", "b"))},
ast::FunctionDecorationList{}); ast::DecorationList{});
auto* func = Func("main", {}, ty.void_(), ast::StatementList{}, auto* func =
ast::FunctionDecorationList{}); Func("main", {}, ty.void_(), ast::StatementList{}, ast::DecorationList{});
auto* expr = create<ast::CallStatement>(Call("a_func", 1.f, 1.f)); auto* expr = create<ast::CallStatement>(Call("a_func", 1.f, 1.f));

View File

@ -979,7 +979,7 @@ TEST_F(SpvBuilderConstructorTest, Type_Struct) {
Member("a", ty.f32()), Member("a", ty.f32()),
Member("b", ty.vec3<f32>()), Member("b", ty.vec3<f32>()),
}, },
ast::StructDecorationList{}); ast::DecorationList{});
auto* s_type = ty.struct_("my_struct", s); auto* s_type = ty.struct_("my_struct", s);
auto* t = Construct(s_type, 2.0f, vec3<f32>(2.0f, 2.0f, 2.0f)); auto* t = Construct(s_type, 2.0f, vec3<f32>(2.0f, 2.0f, 2.0f));
@ -1131,7 +1131,7 @@ TEST_F(SpvBuilderConstructorTest, Type_ZeroInit_Struct) {
ast::StructMemberList{ ast::StructMemberList{
Member("a", ty.f32()), Member("a", ty.f32()),
}, },
ast::StructDecorationList{}); ast::DecorationList{});
auto* s_type = ty.struct_("my_struct", s); auto* s_type = ty.struct_("my_struct", s);
auto* t = Construct(s_type); auto* t = Construct(s_type);
WrapInFunction(t); WrapInFunction(t);
@ -1569,7 +1569,7 @@ TEST_F(SpvBuilderConstructorTest, IsConstructorConst_Struct) {
Member("a", ty.f32()), Member("a", ty.f32()),
Member("b", ty.vec3<f32>()), Member("b", ty.vec3<f32>()),
}, },
ast::StructDecorationList{}); ast::DecorationList{});
auto* s_type = ty.struct_("my_struct", s); auto* s_type = ty.struct_("my_struct", s);
auto* t = Construct(s_type, 2.f, vec3<f32>(2.f, 2.f, 2.f)); auto* t = Construct(s_type, 2.f, vec3<f32>(2.f, 2.f, 2.f));
WrapInFunction(t); WrapInFunction(t);
@ -1587,7 +1587,7 @@ TEST_F(SpvBuilderConstructorTest,
Member("a", ty.f32()), Member("a", ty.f32()),
Member("b", ty.vec3<f32>()), Member("b", ty.vec3<f32>()),
}, },
ast::StructDecorationList{}); ast::DecorationList{});
auto* s_type = ty.struct_("my_struct", s); auto* s_type = ty.struct_("my_struct", s);
auto* t = Construct(s_type, 2.f, "a", 2.f); auto* t = Construct(s_type, 2.f, "a", 2.f);

View File

@ -51,7 +51,7 @@ TEST_F(BuilderTest, EntryPoint_Parameters) {
auto* col = Var("col", f32, ast::StorageClass::kFunction, mul, {}); auto* col = Var("col", f32, ast::StorageClass::kFunction, mul, {});
Func("frag_main", ast::VariableList{coord, loc1}, ty.void_(), Func("frag_main", ast::VariableList{coord, loc1}, ty.void_(),
ast::StatementList{WrapInStatement(col)}, ast::StatementList{WrapInStatement(col)},
ast::FunctionDecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment), create<ast::StageDecoration>(ast::PipelineStage::kFragment),
}); });

Some files were not shown because too many files have changed in this diff Show More