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

@@ -16,13 +16,13 @@
#define SRC_AST_ACCESS_DECORATION_H_
#include "src/ast/access_control.h"
#include "src/ast/type_decoration.h"
#include "src/ast/decoration.h"
namespace tint {
namespace ast {
/// An access decoration
class AccessDecoration : public Castable<AccessDecoration, TypeDecoration> {
class AccessDecoration : public Castable<AccessDecoration, Decoration> {
public:
/// constructor
/// @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_
#define SRC_AST_BINDING_DECORATION_H_
#include "src/ast/variable_decoration.h"
#include "src/ast/decoration.h"
namespace tint {
namespace ast {
/// A binding decoration
class BindingDecoration
: public Castable<BindingDecoration, VariableDecoration> {
class BindingDecoration : public Castable<BindingDecoration, Decoration> {
public:
/// constructor
/// @param value the binding value

View File

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

View File

@@ -15,14 +15,13 @@
#ifndef 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 ast {
/// A constant id decoration
class ConstantIdDecoration
: public Castable<ConstantIdDecoration, VariableDecoration> {
class ConstantIdDecoration : public Castable<ConstantIdDecoration, Decoration> {
public:
/// constructor
/// @param source the source of this decoration

View File

@@ -21,23 +21,5 @@ namespace ast {
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 tint

View File

@@ -22,26 +22,11 @@
namespace tint {
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
class Decoration : public Castable<Decoration, Node> {
public:
~Decoration() override;
/// @return the decoration kind
virtual DecorationKind GetKind() const = 0;
protected:
/// Constructor
/// @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,
type::Type* return_type,
BlockStatement* body,
FunctionDecorationList decorations)
DecorationList decorations)
: Base(source),
symbol_(symbol),
params_(std::move(params)),

View File

@@ -23,7 +23,7 @@
#include "src/ast/binding_decoration.h"
#include "src/ast/block_statement.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/location_decoration.h"
#include "src/ast/pipeline_stage.h"
@@ -47,7 +47,7 @@ class Function : public Castable<Function, Node> {
VariableList params,
type::Type* return_type,
BlockStatement* body,
FunctionDecorationList decorations);
DecorationList decorations);
/// Move constructor
Function(Function&&);
@@ -59,7 +59,7 @@ class Function : public Castable<Function, Node> {
const VariableList& params() const { return params_; }
/// @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
/// return if no workgroup size was set.
@@ -107,7 +107,7 @@ class Function : public Castable<Function, Node> {
VariableList const params_;
type::Type* const return_type_;
BlockStatement* const body_;
FunctionDecorationList const decorations_;
DecorationList const decorations_;
};
/// 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));
auto* var = params[0];
auto* f = Func("func", params, ty.void_(), StatementList{},
FunctionDecorationList{});
auto* f = Func("func", params, ty.void_(), StatementList{}, DecorationList{});
EXPECT_EQ(f->symbol(), Symbols().Get("func"));
ASSERT_EQ(f->params().size(), 1u);
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));
auto* f = Func(Source{Source::Location{20, 2}}, "func", params, ty.void_(),
StatementList{}, FunctionDecorationList{});
StatementList{}, DecorationList{});
auto src = f->source();
EXPECT_EQ(src.range.begin.line, 20u);
EXPECT_EQ(src.range.begin.column, 2u);
@@ -53,7 +52,7 @@ TEST_F(FunctionTest, Assert_InvalidName) {
{
ProgramBuilder b;
b.Func("", VariableList{}, b.ty.void_(), StatementList{},
FunctionDecorationList{});
DecorationList{});
},
"internal compiler error");
}
@@ -62,8 +61,7 @@ TEST_F(FunctionTest, Assert_NullReturnType) {
EXPECT_FATAL_FAILURE(
{
ProgramBuilder b;
b.Func("f", VariableList{}, nullptr, StatementList{},
FunctionDecorationList{});
b.Func("f", VariableList{}, nullptr, StatementList{}, DecorationList{});
},
"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(nullptr);
b.Func("f", params, b.ty.void_(), StatementList{},
FunctionDecorationList{});
b.Func("f", params, b.ty.void_(), StatementList{}, DecorationList{});
},
"internal compiler error");
}
@@ -87,7 +84,7 @@ TEST_F(FunctionTest, ToStr) {
StatementList{
create<DiscardStatement>(),
},
FunctionDecorationList{});
DecorationList{});
EXPECT_EQ(str(f), R"(Function func -> __void
()
@@ -102,7 +99,7 @@ TEST_F(FunctionTest, ToStr_WithDecoration) {
StatementList{
create<DiscardStatement>(),
},
FunctionDecorationList{create<WorkgroupDecoration>(2, 4, 6)});
DecorationList{create<WorkgroupDecoration>(2, 4, 6)});
EXPECT_EQ(str(f), R"(Function func -> __void
WorkgroupDecoration{2 4 6}
@@ -121,7 +118,7 @@ TEST_F(FunctionTest, ToStr_WithParams) {
StatementList{
create<DiscardStatement>(),
},
FunctionDecorationList{});
DecorationList{});
EXPECT_EQ(str(f), R"(Function func -> __void
(
@@ -139,7 +136,7 @@ TEST_F(FunctionTest, ToStr_WithParams) {
TEST_F(FunctionTest, TypeName) {
auto* f = Func("func", VariableList{}, ty.void_(), StatementList{},
FunctionDecorationList{});
DecorationList{});
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("var2", ty.f32(), StorageClass::kNone));
auto* f = Func("func", params, ty.void_(), StatementList{},
FunctionDecorationList{});
auto* f = Func("func", params, ty.void_(), StatementList{}, DecorationList{});
EXPECT_EQ(f->type_name(), "__func__void__i32__f32");
}
TEST_F(FunctionTest, GetLastStatement) {
VariableList params;
auto* stmt = create<DiscardStatement>();
auto* f = Func("func", params, ty.void_(), StatementList{stmt},
FunctionDecorationList{});
auto* f =
Func("func", params, ty.void_(), StatementList{stmt}, DecorationList{});
EXPECT_EQ(f->get_last_statement(), stmt);
}
TEST_F(FunctionTest, GetLastStatement_nullptr) {
VariableList params;
auto* f = Func("func", params, ty.void_(), StatementList{},
FunctionDecorationList{});
auto* f = Func("func", params, ty.void_(), StatementList{}, DecorationList{});
EXPECT_EQ(f->get_last_statement(), nullptr);
}
TEST_F(FunctionTest, WorkgroupSize_NoneSet) {
auto* f = Func("func", VariableList{}, ty.void_(), StatementList{},
FunctionDecorationList{});
DecorationList{});
uint32_t x = 0;
uint32_t y = 0;
uint32_t z = 0;
@@ -183,9 +178,8 @@ TEST_F(FunctionTest, WorkgroupSize_NoneSet) {
}
TEST_F(FunctionTest, WorkgroupSize) {
auto* f =
Func("func", VariableList{}, ty.void_(), StatementList{},
FunctionDecorationList{create<WorkgroupDecoration>(2u, 4u, 6u)});
auto* f = Func("func", VariableList{}, ty.void_(), StatementList{},
DecorationList{create<WorkgroupDecoration>(2u, 4u, 6u)});
uint32_t x = 0;
uint32_t y = 0;
@@ -200,7 +194,7 @@ using FunctionListTest = TestHelper;
TEST_F(FunctionListTest, FindSymbol) {
auto* func = Func("main", VariableList{}, ty.f32(), StatementList{},
ast::FunctionDecorationList{});
ast::DecorationList{});
FunctionList list;
list.Add(func);
EXPECT_EQ(func, list.Find(Symbols().Register("main")));
@@ -213,11 +207,11 @@ TEST_F(FunctionListTest, FindSymbolMissing) {
TEST_F(FunctionListTest, FindSymbolStage) {
auto* fs = Func("main", VariableList{}, ty.f32(), StatementList{},
ast::FunctionDecorationList{
ast::DecorationList{
create<ast::StageDecoration>(PipelineStage::kFragment),
});
auto* vs = Func("main", VariableList{}, ty.f32(), StatementList{},
ast::FunctionDecorationList{
ast::DecorationList{
create<ast::StageDecoration>(PipelineStage::kVertex),
});
FunctionList list;
@@ -231,7 +225,7 @@ TEST_F(FunctionListTest, FindSymbolStage) {
TEST_F(FunctionListTest, FindSymbolStageMissing) {
FunctionList list;
list.Add(Func("main", VariableList{}, ty.f32(), StatementList{},
ast::FunctionDecorationList{
ast::DecorationList{
create<ast::StageDecoration>(PipelineStage::kFragment),
}));
EXPECT_EQ(nullptr,
@@ -241,7 +235,7 @@ TEST_F(FunctionListTest, FindSymbolStageMissing) {
TEST_F(FunctionListTest, HasStage) {
FunctionList list;
list.Add(Func("main", VariableList{}, ty.f32(), StatementList{},
ast::FunctionDecorationList{
ast::DecorationList{
create<ast::StageDecoration>(PipelineStage::kFragment),
}));
EXPECT_TRUE(list.HasStage(PipelineStage::kFragment));

View File

@@ -15,13 +15,13 @@
#ifndef 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 ast {
/// A group decoration
class GroupDecoration : public Castable<GroupDecoration, VariableDecoration> {
class GroupDecoration : public Castable<GroupDecoration, Decoration> {
public:
/// constructor
/// @param value the group value

View File

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

View File

@@ -15,14 +15,13 @@
#ifndef 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 ast {
/// A location decoration
class LocationDecoration
: public Castable<LocationDecoration, VariableDecoration> {
class LocationDecoration : public Castable<LocationDecoration, Decoration> {
public:
/// constructor
/// @param source the source of this decoration

View File

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

View File

@@ -15,14 +15,14 @@
#ifndef 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"
namespace tint {
namespace ast {
/// A workgroup decoration
class StageDecoration : public Castable<StageDecoration, FunctionDecoration> {
class StageDecoration : public Castable<StageDecoration, Decoration> {
public:
/// constructor
/// @param stage the pipeline stage

View File

@@ -15,13 +15,13 @@
#ifndef 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 ast {
/// A stride decoration
class StrideDecoration : public Castable<StrideDecoration, ArrayDecoration> {
class StrideDecoration : public Castable<StrideDecoration, Decoration> {
public:
/// constructor
/// @param stride the stride value

View File

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

View File

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

View File

@@ -17,14 +17,14 @@
#include <vector>
#include "src/ast/struct_decoration.h"
#include "src/ast/decoration.h"
namespace tint {
namespace ast {
/// The struct decorations
class StructBlockDecoration
: public Castable<StructBlockDecoration, StructDecoration> {
: public Castable<StructBlockDecoration, Decoration> {
public:
/// constructor
/// @param source the source of this decoration
@@ -47,7 +47,7 @@ class StructBlockDecoration
};
/// List of struct decorations
using StructDecorationList = std::vector<StructDecoration*>;
using DecorationList = std::vector<Decoration*>;
} // namespace ast
} // 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,
const Symbol& sym,
type::Type* type,
StructMemberDecorationList decorations)
DecorationList decorations)
: Base(source),
symbol_(sym),
type_(type),

View File

@@ -18,7 +18,7 @@
#include <utility>
#include <vector>
#include "src/ast/struct_member_decoration.h"
#include "src/ast/decoration.h"
namespace tint {
namespace ast {
@@ -34,7 +34,7 @@ class StructMember : public Castable<StructMember, Node> {
StructMember(const Source& source,
const Symbol& sym,
type::Type* type,
StructMemberDecorationList decorations);
DecorationList decorations);
/// Move constructor
StructMember(StructMember&&);
@@ -46,7 +46,7 @@ class StructMember : public Castable<StructMember, Node> {
type::Type* type() const { return type_; }
/// @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
bool has_offset_decoration() const;
@@ -72,7 +72,7 @@ class StructMember : public Castable<StructMember, Node> {
Symbol const symbol_;
type::Type* const type_;
StructMemberDecorationList const decorations_;
DecorationList const decorations_;
};
/// 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_
#define SRC_AST_STRUCT_MEMBER_OFFSET_DECORATION_H_
#include "src/ast/struct_member_decoration.h"
#include "src/ast/decoration.h"
namespace tint {
namespace ast {
/// A struct member offset decoration
class StructMemberOffsetDecoration
: public Castable<StructMemberOffsetDecoration, StructMemberDecoration> {
: public Castable<StructMemberOffsetDecoration, Decoration> {
public:
/// constructor
/// @param source the source of this decoration

View File

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

View File

@@ -18,9 +18,9 @@
#include <utility>
#include <vector>
#include "src/ast/decoration.h"
#include "src/ast/expression.h"
#include "src/ast/storage_class.h"
#include "src/ast/variable_decoration.h"
namespace tint {
namespace ast {
@@ -90,7 +90,7 @@ class Variable : public Castable<Variable, Node> {
type::Type* type,
bool is_const,
Expression* constructor,
VariableDecorationList decorations);
DecorationList decorations);
/// Move constructor
Variable(Variable&&);
@@ -115,7 +115,7 @@ class Variable : public Castable<Variable, Node> {
bool is_const() const { return is_const_; }
/// @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
bool HasLocationDecoration() const;
@@ -169,7 +169,7 @@ class Variable : public Castable<Variable, Node> {
type::Type* const type_;
bool const is_const_;
Expression* const constructor_;
VariableDecorationList const decorations_;
DecorationList const decorations_;
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) {
auto* v = Var(
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->declared_storage_class(), StorageClass::kPrivate);
@@ -51,8 +51,7 @@ TEST_F(VariableTest, CreationWithSource) {
TEST_F(VariableTest, CreationEmpty) {
auto* v = Var(
Source{Source::Range{Source::Location{27, 4}, Source::Location{27, 7}}},
"a_var", ty.i32(), StorageClass::kWorkgroup, nullptr,
VariableDecorationList{});
"a_var", ty.i32(), StorageClass::kWorkgroup, nullptr, DecorationList{});
EXPECT_EQ(v->symbol(), Symbol(1));
EXPECT_EQ(v->declared_storage_class(), StorageClass::kWorkgroup);
@@ -93,7 +92,7 @@ TEST_F(VariableTest, to_str) {
TEST_F(VariableTest, WithDecorations) {
auto* var = Var("my_var", ty.i32(), StorageClass::kFunction, nullptr,
VariableDecorationList{
DecorationList{
create<LocationDecoration>(1),
create<BuiltinDecoration>(Builtin::kPosition),
create<ConstantIdDecoration>(1200),
@@ -110,7 +109,7 @@ TEST_F(VariableTest, WithDecorations) {
TEST_F(VariableTest, ConstantId) {
auto* var = Var("my_var", ty.i32(), StorageClass::kFunction, nullptr,
VariableDecorationList{
DecorationList{
create<ConstantIdDecoration>(1200),
});
@@ -119,7 +118,7 @@ TEST_F(VariableTest, ConstantId) {
TEST_F(VariableTest, Decorated_to_str) {
auto* var = Var("my_var", ty.f32(), StorageClass::kFunction, Expr("expr"),
VariableDecorationList{
DecorationList{
create<BindingDecoration>(2),
create<GroupDecoration>(1),
});

View File

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