resolver: Ensure that decorations aren't duplicated

Fixed: tint:525
Change-Id: I993b60f82ac5d5e07e1c76980604e6aaf1b94fb3
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/53806
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: James Price <jrprice@google.com>
This commit is contained in:
Ben Clayton
2021-06-09 18:53:57 +00:00
parent c58738a49e
commit 241c16d626
41 changed files with 320 additions and 39 deletions

View File

@@ -14,6 +14,8 @@
#include "src/ast/access_decoration.h"
#include <string>
#include "src/program_builder.h"
TINT_INSTANTIATE_TYPEINFO(tint::ast::AccessDecoration);
@@ -28,6 +30,10 @@ AccessDecoration::AccessDecoration(ProgramID program_id,
AccessDecoration::~AccessDecoration() = default;
std::string AccessDecoration::name() const {
return "access";
}
void AccessDecoration::to_str(const sem::Info&,
std::ostream& out,
size_t indent) const {

View File

@@ -15,6 +15,8 @@
#ifndef SRC_AST_ACCESS_DECORATION_H_
#define SRC_AST_ACCESS_DECORATION_H_
#include <string>
#include "src/ast/access.h"
#include "src/ast/decoration.h"
@@ -35,6 +37,9 @@ class AccessDecoration : public Castable<AccessDecoration, Decoration> {
/// @returns the access control value
Access value() const { return value_; }
/// @returns the WGSL name for the decoration
std::string name() const override;
/// Outputs the decoration to the given stream
/// @param sem the semantic info for the program
/// @param out the stream to write to

View File

@@ -14,6 +14,8 @@
#include "src/ast/binding_decoration.h"
#include <string>
#include "src/program_builder.h"
TINT_INSTANTIATE_TYPEINFO(tint::ast::BindingDecoration);
@@ -28,6 +30,10 @@ BindingDecoration::BindingDecoration(ProgramID program_id,
BindingDecoration::~BindingDecoration() = default;
std::string BindingDecoration::name() const {
return "binding";
}
void BindingDecoration::to_str(const sem::Info&,
std::ostream& out,
size_t indent) const {

View File

@@ -15,6 +15,8 @@
#ifndef SRC_AST_BINDING_DECORATION_H_
#define SRC_AST_BINDING_DECORATION_H_
#include <string>
#include "src/ast/decoration.h"
namespace tint {
@@ -33,6 +35,9 @@ class BindingDecoration : public Castable<BindingDecoration, Decoration> {
/// @returns the binding value
uint32_t value() const { return value_; }
/// @returns the WGSL name for the decoration
std::string name() const override;
/// Outputs the decoration to the given stream
/// @param sem the semantic info for the program
/// @param out the stream to write to

View File

@@ -14,6 +14,8 @@
#include "src/ast/builtin_decoration.h"
#include <string>
#include "src/program_builder.h"
TINT_INSTANTIATE_TYPEINFO(tint::ast::BuiltinDecoration);
@@ -28,6 +30,10 @@ BuiltinDecoration::BuiltinDecoration(ProgramID program_id,
BuiltinDecoration::~BuiltinDecoration() = default;
std::string BuiltinDecoration::name() const {
return "builtin";
}
void BuiltinDecoration::to_str(const sem::Info&,
std::ostream& out,
size_t indent) const {

View File

@@ -15,6 +15,8 @@
#ifndef SRC_AST_BUILTIN_DECORATION_H_
#define SRC_AST_BUILTIN_DECORATION_H_
#include <string>
#include "src/ast/builtin.h"
#include "src/ast/decoration.h"
@@ -36,6 +38,9 @@ class BuiltinDecoration : public Castable<BuiltinDecoration, Decoration> {
/// @returns the builtin value
Builtin value() const { return builtin_; }
/// @returns the WGSL name for the decoration
std::string name() const override;
/// Outputs the decoration to the given stream
/// @param sem the semantic info for the program
/// @param out the stream to write to

View File

@@ -15,6 +15,7 @@
#ifndef SRC_AST_DECORATION_H_
#define SRC_AST_DECORATION_H_
#include <string>
#include <vector>
#include "src/ast/node.h"
@@ -27,6 +28,9 @@ class Decoration : public Castable<Decoration, Node> {
public:
~Decoration() override;
/// @returns the WGSL name for the decoration
virtual std::string name() const = 0;
protected:
/// Constructor
/// @param program_id the identifier of the program that owns this node

View File

@@ -28,7 +28,7 @@ DisableValidationDecoration::DisableValidationDecoration(
DisableValidationDecoration::~DisableValidationDecoration() = default;
std::string DisableValidationDecoration::Name() const {
std::string DisableValidationDecoration::InternalName() const {
switch (validation_) {
case DisabledValidation::kFunctionHasNoBody:
return "disable_validation__function_has_no_body";

View File

@@ -56,7 +56,7 @@ class DisableValidationDecoration
/// @return a short description of the internal decoration which will be
/// displayed in WGSL as `[[internal(<name>)]]` (but is not parsable).
std::string Name() const override;
std::string InternalName() const override;
/// Performs a deep clone of this object using the CloneContext `ctx`.
/// @param ctx the clone context

View File

@@ -14,6 +14,8 @@
#include "src/ast/group_decoration.h"
#include <string>
#include "src/program_builder.h"
TINT_INSTANTIATE_TYPEINFO(tint::ast::GroupDecoration);
@@ -28,6 +30,10 @@ GroupDecoration::GroupDecoration(ProgramID program_id,
GroupDecoration::~GroupDecoration() = default;
std::string GroupDecoration::name() const {
return "group";
}
void GroupDecoration::to_str(const sem::Info&,
std::ostream& out,
size_t indent) const {

View File

@@ -15,6 +15,8 @@
#ifndef SRC_AST_GROUP_DECORATION_H_
#define SRC_AST_GROUP_DECORATION_H_
#include <string>
#include "src/ast/decoration.h"
namespace tint {
@@ -33,6 +35,9 @@ class GroupDecoration : public Castable<GroupDecoration, Decoration> {
/// @returns the group value
uint32_t value() const { return value_; }
/// @returns the WGSL name for the decoration
std::string name() const override;
/// Outputs the decoration to the given stream
/// @param sem the semantic info for the program
/// @param out the stream to write to

View File

@@ -24,11 +24,15 @@ InternalDecoration::InternalDecoration(ProgramID program_id)
InternalDecoration::~InternalDecoration() = default;
std::string InternalDecoration::name() const {
return "internal";
}
void InternalDecoration::to_str(const sem::Info&,
std::ostream& out,
size_t indent) const {
make_indent(out, indent);
out << "tint_internal(" << Name() << ")" << std::endl;
out << "tint_internal(" << InternalName() << ")" << std::endl;
}
} // namespace ast

View File

@@ -36,7 +36,10 @@ class InternalDecoration : public Castable<InternalDecoration, Decoration> {
/// @return a short description of the internal decoration which will be
/// displayed in WGSL as `[[internal(<name>)]]` (but is not parsable).
virtual std::string Name() const = 0;
virtual std::string InternalName() const = 0;
/// @returns the WGSL name for the decoration
std::string name() const override;
/// Writes a representation of the node to the output stream
/// @param sem the semantic info for the program

View File

@@ -14,6 +14,8 @@
#include "src/ast/location_decoration.h"
#include <string>
#include "src/program_builder.h"
TINT_INSTANTIATE_TYPEINFO(tint::ast::LocationDecoration);
@@ -28,6 +30,10 @@ LocationDecoration::LocationDecoration(ProgramID program_id,
LocationDecoration::~LocationDecoration() = default;
std::string LocationDecoration::name() const {
return "location";
}
void LocationDecoration::to_str(const sem::Info&,
std::ostream& out,
size_t indent) const {

View File

@@ -15,6 +15,8 @@
#ifndef SRC_AST_LOCATION_DECORATION_H_
#define SRC_AST_LOCATION_DECORATION_H_
#include <string>
#include "src/ast/decoration.h"
namespace tint {
@@ -35,6 +37,9 @@ class LocationDecoration : public Castable<LocationDecoration, Decoration> {
/// @returns the location value
uint32_t value() const { return value_; }
/// @returns the WGSL name for the decoration
std::string name() const override;
/// Outputs the decoration to the given stream
/// @param sem the semantic info for the program
/// @param out the stream to write to

View File

@@ -14,6 +14,8 @@
#include "src/ast/override_decoration.h"
#include <string>
#include "src/program_builder.h"
TINT_INSTANTIATE_TYPEINFO(tint::ast::OverrideDecoration);
@@ -32,6 +34,10 @@ OverrideDecoration::OverrideDecoration(ProgramID program_id,
OverrideDecoration::~OverrideDecoration() = default;
std::string OverrideDecoration::name() const {
return "override";
}
void OverrideDecoration::to_str(const sem::Info&,
std::ostream& out,
size_t indent) const {

View File

@@ -15,6 +15,8 @@
#ifndef SRC_AST_OVERRIDE_DECORATION_H_
#define SRC_AST_OVERRIDE_DECORATION_H_
#include <string>
#include "src/ast/decoration.h"
namespace tint {
@@ -40,6 +42,9 @@ class OverrideDecoration : public Castable<OverrideDecoration, Decoration> {
/// @returns the override id value
uint32_t value() const { return value_; }
/// @returns the WGSL name for the decoration
std::string name() const override;
/// Outputs the decoration to the given stream
/// @param sem the semantic info for the program
/// @param out the stream to write to

View File

@@ -14,6 +14,8 @@
#include "src/ast/stage_decoration.h"
#include <string>
#include "src/program_builder.h"
TINT_INSTANTIATE_TYPEINFO(tint::ast::StageDecoration);
@@ -28,6 +30,10 @@ StageDecoration::StageDecoration(ProgramID program_id,
StageDecoration::~StageDecoration() = default;
std::string StageDecoration::name() const {
return "stage";
}
void StageDecoration::to_str(const sem::Info&,
std::ostream& out,
size_t indent) const {

View File

@@ -15,6 +15,8 @@
#ifndef SRC_AST_STAGE_DECORATION_H_
#define SRC_AST_STAGE_DECORATION_H_
#include <string>
#include "src/ast/decoration.h"
#include "src/ast/pipeline_stage.h"
@@ -36,6 +38,9 @@ class StageDecoration : public Castable<StageDecoration, Decoration> {
/// @returns the stage
PipelineStage value() const { return stage_; }
/// @returns the WGSL name for the decoration
std::string name() const override;
/// Outputs the decoration to the given stream
/// @param sem the semantic info for the program
/// @param out the stream to write to

View File

@@ -14,6 +14,8 @@
#include "src/ast/stride_decoration.h"
#include <string>
#include "src/program_builder.h"
TINT_INSTANTIATE_TYPEINFO(tint::ast::StrideDecoration);
@@ -28,6 +30,10 @@ StrideDecoration::StrideDecoration(ProgramID program_id,
StrideDecoration::~StrideDecoration() = default;
std::string StrideDecoration::name() const {
return "stride";
}
void StrideDecoration::to_str(const sem::Info&,
std::ostream& out,
size_t indent) const {

View File

@@ -15,6 +15,8 @@
#ifndef SRC_AST_STRIDE_DECORATION_H_
#define SRC_AST_STRIDE_DECORATION_H_
#include <string>
#include "src/ast/decoration.h"
namespace tint {
@@ -33,6 +35,9 @@ class StrideDecoration : public Castable<StrideDecoration, Decoration> {
/// @returns the stride value
uint32_t stride() const { return stride_; }
/// @returns the WGSL name for the decoration
std::string name() const override;
/// Outputs the decoration to the given stream
/// @param sem the semantic info for the program
/// @param out the stream to write to

View File

@@ -14,6 +14,8 @@
#include "src/ast/struct_block_decoration.h"
#include <string>
#include "src/program_builder.h"
TINT_INSTANTIATE_TYPEINFO(tint::ast::StructBlockDecoration);
@@ -27,6 +29,10 @@ StructBlockDecoration::StructBlockDecoration(ProgramID program_id,
StructBlockDecoration::~StructBlockDecoration() = default;
std::string StructBlockDecoration::name() const {
return "block";
}
void StructBlockDecoration::to_str(const sem::Info&,
std::ostream& out,
size_t indent) const {

View File

@@ -15,6 +15,7 @@
#ifndef SRC_AST_STRUCT_BLOCK_DECORATION_H_
#define SRC_AST_STRUCT_BLOCK_DECORATION_H_
#include <string>
#include <vector>
#include "src/ast/decoration.h"
@@ -32,6 +33,9 @@ class StructBlockDecoration
StructBlockDecoration(ProgramID program_id, const Source& source);
~StructBlockDecoration() override;
/// @returns the WGSL name for the decoration
std::string name() const override;
/// Outputs the decoration to the given stream
/// @param sem the semantic info for the program
/// @param out the stream to write to

View File

@@ -14,6 +14,8 @@
#include "src/ast/struct_member_align_decoration.h"
#include <string>
#include "src/clone_context.h"
#include "src/program_builder.h"
@@ -29,6 +31,10 @@ StructMemberAlignDecoration::StructMemberAlignDecoration(ProgramID program_id,
StructMemberAlignDecoration::~StructMemberAlignDecoration() = default;
std::string StructMemberAlignDecoration::name() const {
return "align";
}
void StructMemberAlignDecoration::to_str(const sem::Info&,
std::ostream& out,
size_t indent) const {

View File

@@ -16,6 +16,7 @@
#define SRC_AST_STRUCT_MEMBER_ALIGN_DECORATION_H_
#include <stddef.h>
#include <string>
#include "src/ast/decoration.h"
@@ -38,6 +39,9 @@ class StructMemberAlignDecoration
/// @returns the align value
uint32_t align() const { return align_; }
/// @returns the WGSL name for the decoration
std::string name() const override;
/// Outputs the decoration to the given stream
/// @param sem the semantic info for the program
/// @param out the stream to write to

View File

@@ -14,6 +14,8 @@
#include "src/ast/struct_member_offset_decoration.h"
#include <string>
#include "src/program_builder.h"
TINT_INSTANTIATE_TYPEINFO(tint::ast::StructMemberOffsetDecoration);
@@ -28,6 +30,10 @@ StructMemberOffsetDecoration::StructMemberOffsetDecoration(ProgramID program_id,
StructMemberOffsetDecoration::~StructMemberOffsetDecoration() = default;
std::string StructMemberOffsetDecoration::name() const {
return "offset";
}
void StructMemberOffsetDecoration::to_str(const sem::Info&,
std::ostream& out,
size_t indent) const {

View File

@@ -15,6 +15,8 @@
#ifndef SRC_AST_STRUCT_MEMBER_OFFSET_DECORATION_H_
#define SRC_AST_STRUCT_MEMBER_OFFSET_DECORATION_H_
#include <string>
#include "src/ast/decoration.h"
namespace tint {
@@ -45,6 +47,9 @@ class StructMemberOffsetDecoration
/// @returns the offset value
uint32_t offset() const { return offset_; }
/// @returns the WGSL name for the decoration
std::string name() const override;
/// Outputs the decoration to the given stream
/// @param sem the semantic info for the program
/// @param out the stream to write to

View File

@@ -14,6 +14,8 @@
#include "src/ast/struct_member_size_decoration.h"
#include <string>
#include "src/clone_context.h"
#include "src/program_builder.h"
@@ -29,6 +31,10 @@ StructMemberSizeDecoration::StructMemberSizeDecoration(ProgramID program_id,
StructMemberSizeDecoration::~StructMemberSizeDecoration() = default;
std::string StructMemberSizeDecoration::name() const {
return "size";
}
void StructMemberSizeDecoration::to_str(const sem::Info&,
std::ostream& out,
size_t indent) const {

View File

@@ -16,6 +16,7 @@
#define SRC_AST_STRUCT_MEMBER_SIZE_DECORATION_H_
#include <stddef.h>
#include <string>
#include "src/ast/decoration.h"
@@ -38,6 +39,9 @@ class StructMemberSizeDecoration
/// @returns the size value
uint32_t size() const { return size_; }
/// @returns the WGSL name for the decoration
std::string name() const override;
/// Outputs the decoration to the given stream
/// @param sem the semantic info for the program
/// @param out the stream to write to

View File

@@ -14,6 +14,8 @@
#include "src/ast/workgroup_decoration.h"
#include <string>
#include "src/program_builder.h"
TINT_INSTANTIATE_TYPEINFO(tint::ast::WorkgroupDecoration);
@@ -30,6 +32,10 @@ WorkgroupDecoration::WorkgroupDecoration(ProgramID program_id,
WorkgroupDecoration::~WorkgroupDecoration() = default;
std::string WorkgroupDecoration::name() const {
return "workgroup_size";
}
void WorkgroupDecoration::to_str(const sem::Info& sem,
std::ostream& out,
size_t indent) const {

View File

@@ -16,6 +16,7 @@
#define SRC_AST_WORKGROUP_DECORATION_H_
#include <array>
#include <string>
#include "src/ast/decoration.h"
@@ -45,6 +46,9 @@ class WorkgroupDecoration : public Castable<WorkgroupDecoration, Decoration> {
/// @returns the workgroup dimensions
std::array<ast::Expression*, 3> values() const { return {x_, y_, z_}; }
/// @returns the WGSL name for the decoration
std::string name() const override;
/// Outputs the decoration to the given stream
/// @param sem the semantic info for the program
/// @param out the stream to write to