Skip to content

Commit

Permalink
Flatten ast::Decoration class hierarchy
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
jrprice authored and Commit Bot service account committed Mar 11, 2021
1 parent f1773c6 commit 95d4077
Show file tree
Hide file tree
Showing 114 changed files with 1,225 additions and 1,411 deletions.
14 changes: 1 addition & 13 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,6 @@ source_set("libtint_core_src") {
"src/ast/access_decoration.h",
"src/ast/array_accessor_expression.cc",
"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.h",
"src/ast/binary_expression.cc",
Expand Down Expand Up @@ -276,8 +274,6 @@ source_set("libtint_core_src") {
"src/ast/float_literal.h",
"src/ast/function.cc",
"src/ast/function.h",
"src/ast/function_decoration.cc",
"src/ast/function_decoration.h",
"src/ast/group_decoration.cc",
"src/ast/group_decoration.h",
"src/ast/identifier_expression.cc",
Expand Down Expand Up @@ -320,20 +316,14 @@ source_set("libtint_core_src") {
"src/ast/struct.h",
"src/ast/struct_block_decoration.cc",
"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.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.h",
"src/ast/switch_statement.cc",
"src/ast/switch_statement.h",
"src/ast/type_constructor_expression.cc",
"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.h",
"src/ast/unary_op.cc",
Expand All @@ -344,8 +334,6 @@ source_set("libtint_core_src") {
"src/ast/variable.h",
"src/ast/variable_decl_statement.cc",
"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.h",
"src/block_allocator.h",
Expand Down Expand Up @@ -797,7 +785,6 @@ source_set("tint_unittests_core_src") {
"src/ast/case_statement_test.cc",
"src/ast/constant_id_decoration_test.cc",
"src/ast/continue_statement_test.cc",
"src/ast/decoration_test.cc",
"src/ast/discard_statement_test.cc",
"src/ast/else_statement_test.cc",
"src/ast/fallthrough_statement_test.cc",
Expand Down Expand Up @@ -883,6 +870,7 @@ source_set("tint_unittests_core_src") {
"src/utils/unique_vector_test.cc",
"src/validator/validator_builtins_test.cc",
"src/validator/validator_control_block_test.cc",
"src/validator/validator_decoration_test.cc",
"src/validator/validator_function_test.cc",
"src/validator/validator_test.cc",
"src/validator/validator_test_helper.cc",
Expand Down
14 changes: 1 addition & 13 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ set(TINT_LIB_SRCS
ast/access_decoration.h
ast/array_accessor_expression.cc
ast/array_accessor_expression.h
ast/array_decoration.cc
ast/array_decoration.h
ast/assignment_statement.cc
ast/assignment_statement.h
ast/binary_expression.cc
Expand Down Expand Up @@ -90,8 +88,6 @@ set(TINT_LIB_SRCS
ast/float_literal.h
ast/function.cc
ast/function.h
ast/function_decoration.cc
ast/function_decoration.h
ast/group_decoration.cc
ast/group_decoration.h
ast/identifier_expression.cc
Expand Down Expand Up @@ -134,20 +130,14 @@ set(TINT_LIB_SRCS
ast/struct.h
ast/struct_block_decoration.cc
ast/struct_block_decoration.h
ast/struct_decoration.cc
ast/struct_decoration.h
ast/struct_member.cc
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.h
ast/switch_statement.cc
ast/switch_statement.h
ast/type_constructor_expression.cc
ast/type_constructor_expression.h
ast/type_decoration.cc
ast/type_decoration.h
ast/uint_literal.cc
ast/uint_literal.h
ast/unary_op.cc
Expand All @@ -156,8 +146,6 @@ set(TINT_LIB_SRCS
ast/unary_op_expression.h
ast/variable.cc
ast/variable.h
ast/variable_decoration.cc
ast/variable_decoration.h
ast/variable_decl_statement.cc
ast/variable_decl_statement.h
ast/workgroup_decoration.cc
Expand Down Expand Up @@ -426,7 +414,6 @@ if(${TINT_BUILD_TESTS})
ast/case_statement_test.cc
ast/constant_id_decoration_test.cc
ast/continue_statement_test.cc
ast/decoration_test.cc
ast/discard_statement_test.cc
ast/else_statement_test.cc
ast/fallthrough_statement_test.cc
Expand Down Expand Up @@ -506,6 +493,7 @@ if(${TINT_BUILD_TESTS})
utils/unique_vector_test.cc
validator/validator_builtins_test.cc
validator/validator_control_block_test.cc
validator/validator_decoration_test.cc
validator/validator_function_test.cc
validator/validator_test.cc
validator/validator_type_test.cc
Expand Down
4 changes: 2 additions & 2 deletions src/ast/access_decoration.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
50 changes: 0 additions & 50 deletions src/ast/array_decoration.h

This file was deleted.

5 changes: 2 additions & 3 deletions src/ast/binding_decoration.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions src/ast/builtin_decoration.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions src/ast/constant_id_decoration.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 0 additions & 18 deletions src/ast/decoration.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 0 additions & 15 deletions src/ast/decoration.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
67 changes: 0 additions & 67 deletions src/ast/decoration_test.cc

This file was deleted.

2 changes: 1 addition & 1 deletion src/ast/function.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down
Loading

0 comments on commit 95d4077

Please sign in to comment.