ast: Add virtual GetKind() instead of kind member
Reduces the per-instance size for an extra vtable entry. Change-Id: Ie087e0b8d8524adf85663ab1224fb0ae1a5e0000 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/34300 Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
parent
b062bbdce8
commit
11c9de63aa
|
@ -20,10 +20,14 @@ namespace ast {
|
|||
constexpr const DecorationKind AccessDecoration::Kind;
|
||||
|
||||
AccessDecoration::AccessDecoration(AccessControl val, const Source& source)
|
||||
: TypeDecoration(Kind, source), value_(val) {}
|
||||
: TypeDecoration(source), value_(val) {}
|
||||
|
||||
AccessDecoration::~AccessDecoration() = default;
|
||||
|
||||
DecorationKind AccessDecoration::GetKind() const {
|
||||
return Kind;
|
||||
}
|
||||
|
||||
bool AccessDecoration::IsKind(DecorationKind kind) const {
|
||||
return kind == Kind || TypeDecoration::IsKind(kind);
|
||||
}
|
||||
|
|
|
@ -35,6 +35,9 @@ class AccessDecoration : public TypeDecoration {
|
|||
explicit AccessDecoration(AccessControl value, const Source& source);
|
||||
~AccessDecoration() override;
|
||||
|
||||
/// @return the decoration kind
|
||||
DecorationKind GetKind() const override;
|
||||
|
||||
/// @param kind the decoration kind
|
||||
/// @return true if this Decoration is of the (or derives from) the given
|
||||
/// kind.
|
||||
|
|
|
@ -23,11 +23,14 @@ namespace ast {
|
|||
|
||||
constexpr const DecorationKind ArrayDecoration::Kind;
|
||||
|
||||
ArrayDecoration::ArrayDecoration(DecorationKind kind, const Source& source)
|
||||
: Decoration(kind, source) {}
|
||||
ArrayDecoration::ArrayDecoration(const Source& source) : Decoration(source) {}
|
||||
|
||||
ArrayDecoration::~ArrayDecoration() = default;
|
||||
|
||||
DecorationKind ArrayDecoration::GetKind() const {
|
||||
return Kind;
|
||||
}
|
||||
|
||||
bool ArrayDecoration::IsKind(DecorationKind kind) const {
|
||||
return kind == Kind;
|
||||
}
|
||||
|
|
|
@ -34,6 +34,9 @@ class ArrayDecoration : public Decoration {
|
|||
|
||||
~ArrayDecoration() override;
|
||||
|
||||
/// @return the decoration kind
|
||||
DecorationKind GetKind() const override;
|
||||
|
||||
/// @param kind the decoration kind
|
||||
/// @return true if this Decoration is of the (or derives from) the given
|
||||
/// kind.
|
||||
|
@ -47,9 +50,8 @@ class ArrayDecoration : public Decoration {
|
|||
|
||||
protected:
|
||||
/// Constructor
|
||||
/// @param kind the decoration kind
|
||||
/// @param source the source of this decoration
|
||||
ArrayDecoration(DecorationKind kind, const Source& source);
|
||||
explicit ArrayDecoration(const Source& source);
|
||||
};
|
||||
|
||||
/// A list of array decorations
|
||||
|
|
|
@ -20,10 +20,14 @@ namespace ast {
|
|||
constexpr const DecorationKind BindingDecoration::Kind;
|
||||
|
||||
BindingDecoration::BindingDecoration(uint32_t val, const Source& source)
|
||||
: VariableDecoration(Kind, source), value_(val) {}
|
||||
: VariableDecoration(source), value_(val) {}
|
||||
|
||||
BindingDecoration::~BindingDecoration() = default;
|
||||
|
||||
DecorationKind BindingDecoration::GetKind() const {
|
||||
return Kind;
|
||||
}
|
||||
|
||||
bool BindingDecoration::IsKind(DecorationKind kind) const {
|
||||
return kind == Kind || VariableDecoration::IsKind(kind);
|
||||
}
|
||||
|
|
|
@ -34,6 +34,9 @@ class BindingDecoration : public VariableDecoration {
|
|||
BindingDecoration(uint32_t value, const Source& source);
|
||||
~BindingDecoration() override;
|
||||
|
||||
/// @return the decoration kind
|
||||
DecorationKind GetKind() const override;
|
||||
|
||||
/// @param kind the decoration kind
|
||||
/// @return true if this Decoration is of the (or derives from) the given
|
||||
/// kind.
|
||||
|
|
|
@ -20,10 +20,14 @@ namespace ast {
|
|||
constexpr const DecorationKind BuiltinDecoration::Kind;
|
||||
|
||||
BuiltinDecoration::BuiltinDecoration(Builtin builtin, const Source& source)
|
||||
: VariableDecoration(Kind, source), builtin_(builtin) {}
|
||||
: VariableDecoration(source), builtin_(builtin) {}
|
||||
|
||||
BuiltinDecoration::~BuiltinDecoration() = default;
|
||||
|
||||
DecorationKind BuiltinDecoration::GetKind() const {
|
||||
return Kind;
|
||||
}
|
||||
|
||||
bool BuiltinDecoration::IsKind(DecorationKind kind) const {
|
||||
return kind == Kind || VariableDecoration::IsKind(kind);
|
||||
}
|
||||
|
|
|
@ -33,6 +33,9 @@ class BuiltinDecoration : public VariableDecoration {
|
|||
BuiltinDecoration(Builtin builtin, const Source& source);
|
||||
~BuiltinDecoration() override;
|
||||
|
||||
/// @return the decoration kind
|
||||
DecorationKind GetKind() const override;
|
||||
|
||||
/// @param kind the decoration kind
|
||||
/// @return true if this Decoration is of the (or derives from) the given
|
||||
/// kind.
|
||||
|
|
|
@ -20,10 +20,14 @@ namespace ast {
|
|||
constexpr const DecorationKind ConstantIdDecoration::Kind;
|
||||
|
||||
ConstantIdDecoration::ConstantIdDecoration(uint32_t val, const Source& source)
|
||||
: VariableDecoration(Kind, source), value_(val) {}
|
||||
: VariableDecoration(source), value_(val) {}
|
||||
|
||||
ConstantIdDecoration::~ConstantIdDecoration() = default;
|
||||
|
||||
DecorationKind ConstantIdDecoration::GetKind() const {
|
||||
return Kind;
|
||||
}
|
||||
|
||||
bool ConstantIdDecoration::IsKind(DecorationKind kind) const {
|
||||
return kind == Kind || VariableDecoration::IsKind(kind);
|
||||
}
|
||||
|
|
|
@ -33,6 +33,9 @@ class ConstantIdDecoration : public VariableDecoration {
|
|||
ConstantIdDecoration(uint32_t val, const Source& source);
|
||||
~ConstantIdDecoration() override;
|
||||
|
||||
/// @return the decoration kind
|
||||
DecorationKind GetKind() const override;
|
||||
|
||||
/// @param kind the decoration kind
|
||||
/// @return true if this Decoration is of the (or derives from) the given
|
||||
/// kind.
|
||||
|
|
|
@ -51,6 +51,9 @@ class Decoration : public Node {
|
|||
public:
|
||||
~Decoration() override;
|
||||
|
||||
/// @return the decoration kind
|
||||
virtual DecorationKind GetKind() const = 0;
|
||||
|
||||
/// @param kind the decoration kind
|
||||
/// @return true if this Decoration is of the (or derives from) the given
|
||||
/// kind.
|
||||
|
@ -62,21 +65,13 @@ class Decoration : public Node {
|
|||
return IsKind(TO::Kind);
|
||||
}
|
||||
|
||||
/// @return the decoration kind
|
||||
DecorationKind GetKind() const { return kind_; }
|
||||
|
||||
/// @returns true if the node is valid
|
||||
bool IsValid() const override;
|
||||
|
||||
protected:
|
||||
/// Constructor
|
||||
/// @param kind represents the derived type
|
||||
/// @param source the source of this decoration
|
||||
Decoration(DecorationKind kind, const Source& source)
|
||||
: Node(source), kind_(kind) {}
|
||||
|
||||
private:
|
||||
DecorationKind const kind_;
|
||||
explicit Decoration(const Source& source) : Node(source) {}
|
||||
};
|
||||
|
||||
/// As dynamically casts |deco| to the target type |TO|.
|
||||
|
|
|
@ -24,12 +24,15 @@ namespace ast {
|
|||
|
||||
constexpr const DecorationKind FunctionDecoration::Kind;
|
||||
|
||||
FunctionDecoration::FunctionDecoration(DecorationKind kind,
|
||||
const Source& source)
|
||||
: Decoration(kind, source) {}
|
||||
FunctionDecoration::FunctionDecoration(const Source& source)
|
||||
: Decoration(source) {}
|
||||
|
||||
FunctionDecoration::~FunctionDecoration() = default;
|
||||
|
||||
DecorationKind FunctionDecoration::GetKind() const {
|
||||
return Kind;
|
||||
}
|
||||
|
||||
bool FunctionDecoration::IsKind(DecorationKind kind) const {
|
||||
return kind == Kind;
|
||||
}
|
||||
|
|
|
@ -35,6 +35,9 @@ class FunctionDecoration : public Decoration {
|
|||
|
||||
~FunctionDecoration() override;
|
||||
|
||||
/// @return the decoration kind
|
||||
DecorationKind GetKind() const override;
|
||||
|
||||
/// @param kind the decoration kind
|
||||
/// @return true if this Decoration is of the (or derives from) the given
|
||||
/// kind.
|
||||
|
@ -52,9 +55,8 @@ class FunctionDecoration : public Decoration {
|
|||
|
||||
protected:
|
||||
/// Constructor
|
||||
/// @param kind the decoration kind
|
||||
/// @param source the source of this decoration
|
||||
FunctionDecoration(DecorationKind kind, const Source& source);
|
||||
explicit FunctionDecoration(const Source& source);
|
||||
};
|
||||
|
||||
/// A list of function decorations
|
||||
|
|
|
@ -20,10 +20,14 @@ namespace ast {
|
|||
constexpr const DecorationKind LocationDecoration::Kind;
|
||||
|
||||
LocationDecoration::LocationDecoration(uint32_t val, const Source& source)
|
||||
: VariableDecoration(Kind, source), value_(val) {}
|
||||
: VariableDecoration(source), value_(val) {}
|
||||
|
||||
LocationDecoration::~LocationDecoration() = default;
|
||||
|
||||
DecorationKind LocationDecoration::GetKind() const {
|
||||
return Kind;
|
||||
}
|
||||
|
||||
bool LocationDecoration::IsKind(DecorationKind kind) const {
|
||||
return kind == Kind || VariableDecoration::IsKind(kind);
|
||||
}
|
||||
|
|
|
@ -34,6 +34,9 @@ class LocationDecoration : public VariableDecoration {
|
|||
explicit LocationDecoration(uint32_t value, const Source& source);
|
||||
~LocationDecoration() override;
|
||||
|
||||
/// @return the decoration kind
|
||||
DecorationKind GetKind() const override;
|
||||
|
||||
/// @param kind the decoration kind
|
||||
/// @return true if this Decoration is of the (or derives from) the given
|
||||
/// kind.
|
||||
|
|
|
@ -18,7 +18,7 @@ namespace tint {
|
|||
namespace ast {
|
||||
|
||||
SetDecoration::SetDecoration(uint32_t val, const Source& source)
|
||||
: VariableDecoration(Kind, source), value_(val) {}
|
||||
: VariableDecoration(source), value_(val) {}
|
||||
|
||||
SetDecoration::~SetDecoration() = default;
|
||||
|
||||
|
|
|
@ -20,10 +20,14 @@ namespace ast {
|
|||
constexpr const DecorationKind StageDecoration::Kind;
|
||||
|
||||
StageDecoration::StageDecoration(ast::PipelineStage stage, const Source& source)
|
||||
: FunctionDecoration(Kind, source), stage_(stage) {}
|
||||
: FunctionDecoration(source), stage_(stage) {}
|
||||
|
||||
StageDecoration::~StageDecoration() = default;
|
||||
|
||||
DecorationKind StageDecoration::GetKind() const {
|
||||
return Kind;
|
||||
}
|
||||
|
||||
bool StageDecoration::IsKind(DecorationKind kind) const {
|
||||
return kind == Kind || FunctionDecoration::IsKind(kind);
|
||||
}
|
||||
|
|
|
@ -33,6 +33,9 @@ class StageDecoration : public FunctionDecoration {
|
|||
StageDecoration(ast::PipelineStage stage, const Source& source);
|
||||
~StageDecoration() override;
|
||||
|
||||
/// @return the decoration kind
|
||||
DecorationKind GetKind() const override;
|
||||
|
||||
/// @param kind the decoration kind
|
||||
/// @return true if this Decoration is of the (or derives from) the given
|
||||
/// kind.
|
||||
|
|
|
@ -20,7 +20,11 @@ namespace ast {
|
|||
constexpr const DecorationKind StrideDecoration::Kind;
|
||||
|
||||
StrideDecoration::StrideDecoration(uint32_t stride, const Source& source)
|
||||
: ArrayDecoration(Kind, source), stride_(stride) {}
|
||||
: ArrayDecoration(source), stride_(stride) {}
|
||||
|
||||
DecorationKind StrideDecoration::GetKind() const {
|
||||
return Kind;
|
||||
}
|
||||
|
||||
bool StrideDecoration::IsKind(DecorationKind kind) const {
|
||||
return kind == Kind || ArrayDecoration::IsKind(kind);
|
||||
|
|
|
@ -36,6 +36,9 @@ class StrideDecoration : public ArrayDecoration {
|
|||
StrideDecoration(uint32_t stride, const Source& source);
|
||||
~StrideDecoration() override;
|
||||
|
||||
/// @return the decoration kind
|
||||
DecorationKind GetKind() const override;
|
||||
|
||||
/// @param kind the decoration kind
|
||||
/// @return true if this Decoration is of the (or derives from) the given
|
||||
/// kind.
|
||||
|
|
|
@ -18,7 +18,7 @@ namespace tint {
|
|||
namespace ast {
|
||||
|
||||
StructBlockDecoration::StructBlockDecoration(const Source& source)
|
||||
: StructDecoration(Kind, source) {}
|
||||
: StructDecoration(source) {}
|
||||
|
||||
StructBlockDecoration::~StructBlockDecoration() = default;
|
||||
|
||||
|
|
|
@ -19,11 +19,14 @@ namespace ast {
|
|||
|
||||
constexpr const DecorationKind StructDecoration::Kind;
|
||||
|
||||
StructDecoration::StructDecoration(DecorationKind kind, const Source& source)
|
||||
: Decoration(kind, source) {}
|
||||
StructDecoration::StructDecoration(const Source& source) : Decoration(source) {}
|
||||
|
||||
StructDecoration::~StructDecoration() = default;
|
||||
|
||||
DecorationKind StructDecoration::GetKind() const {
|
||||
return Kind;
|
||||
}
|
||||
|
||||
bool StructDecoration::IsKind(DecorationKind kind) const {
|
||||
return kind == Kind;
|
||||
}
|
||||
|
|
|
@ -32,6 +32,9 @@ class StructDecoration : public Decoration {
|
|||
|
||||
~StructDecoration() override;
|
||||
|
||||
/// @return the decoration kind
|
||||
DecorationKind GetKind() const override;
|
||||
|
||||
/// @param kind the decoration kind
|
||||
/// @return true if this Decoration is of the (or derives from) the given
|
||||
/// kind.
|
||||
|
@ -42,9 +45,8 @@ class StructDecoration : public Decoration {
|
|||
|
||||
protected:
|
||||
/// Constructor
|
||||
/// @param kind the decoration kind
|
||||
/// @param source the source of this decoration
|
||||
explicit StructDecoration(DecorationKind kind, const Source& source);
|
||||
explicit StructDecoration(const Source& source);
|
||||
};
|
||||
|
||||
/// List of struct decorations
|
||||
|
|
|
@ -23,12 +23,15 @@ namespace ast {
|
|||
|
||||
constexpr const DecorationKind StructMemberDecoration::Kind;
|
||||
|
||||
StructMemberDecoration::StructMemberDecoration(DecorationKind kind,
|
||||
const Source& source)
|
||||
: Decoration(kind, source) {}
|
||||
StructMemberDecoration::StructMemberDecoration(const Source& source)
|
||||
: Decoration(source) {}
|
||||
|
||||
StructMemberDecoration::~StructMemberDecoration() = default;
|
||||
|
||||
DecorationKind StructMemberDecoration::GetKind() const {
|
||||
return Kind;
|
||||
}
|
||||
|
||||
bool StructMemberDecoration::IsKind(DecorationKind kind) const {
|
||||
return kind == Kind;
|
||||
}
|
||||
|
|
|
@ -34,6 +34,9 @@ class StructMemberDecoration : public Decoration {
|
|||
|
||||
~StructMemberDecoration() override;
|
||||
|
||||
/// @return the decoration kind
|
||||
DecorationKind GetKind() const override;
|
||||
|
||||
/// @param kind the decoration kind
|
||||
/// @return true if this Decoration is of the (or derives from) the given
|
||||
/// kind.
|
||||
|
@ -47,9 +50,8 @@ class StructMemberDecoration : public Decoration {
|
|||
|
||||
protected:
|
||||
/// Constructor
|
||||
/// @param kind the decoration kind
|
||||
/// @param source the source of this decoration
|
||||
explicit StructMemberDecoration(DecorationKind kind, const Source& source);
|
||||
explicit StructMemberDecoration(const Source& source);
|
||||
};
|
||||
|
||||
/// A list of struct member decorations
|
||||
|
|
|
@ -21,7 +21,11 @@ constexpr const DecorationKind StructMemberOffsetDecoration::Kind;
|
|||
|
||||
StructMemberOffsetDecoration::StructMemberOffsetDecoration(uint32_t offset,
|
||||
const Source& source)
|
||||
: StructMemberDecoration(Kind, source), offset_(offset) {}
|
||||
: StructMemberDecoration(source), offset_(offset) {}
|
||||
|
||||
DecorationKind StructMemberOffsetDecoration::GetKind() const {
|
||||
return Kind;
|
||||
}
|
||||
|
||||
bool StructMemberOffsetDecoration::IsKind(DecorationKind kind) const {
|
||||
return kind == Kind || StructMemberDecoration::IsKind(kind);
|
||||
|
|
|
@ -37,6 +37,9 @@ class StructMemberOffsetDecoration : public StructMemberDecoration {
|
|||
StructMemberOffsetDecoration(uint32_t offset, const Source& source);
|
||||
~StructMemberOffsetDecoration() override;
|
||||
|
||||
/// @return the decoration kind
|
||||
DecorationKind GetKind() const override;
|
||||
|
||||
/// @param kind the decoration kind
|
||||
/// @return true if this Decoration is of the (or derives from) the given
|
||||
/// kind.
|
||||
|
|
|
@ -23,11 +23,14 @@ namespace ast {
|
|||
|
||||
constexpr const DecorationKind TypeDecoration::Kind;
|
||||
|
||||
TypeDecoration::TypeDecoration(DecorationKind kind, const Source& source)
|
||||
: Decoration(kind, source) {}
|
||||
TypeDecoration::TypeDecoration(const Source& source) : Decoration(source) {}
|
||||
|
||||
TypeDecoration::~TypeDecoration() = default;
|
||||
|
||||
DecorationKind TypeDecoration::GetKind() const {
|
||||
return Kind;
|
||||
}
|
||||
|
||||
bool TypeDecoration::IsKind(DecorationKind kind) const {
|
||||
return kind == Kind;
|
||||
}
|
||||
|
|
|
@ -35,6 +35,9 @@ class TypeDecoration : public Decoration {
|
|||
|
||||
~TypeDecoration() override;
|
||||
|
||||
/// @return the decoration kind
|
||||
DecorationKind GetKind() const override;
|
||||
|
||||
/// @param kind the decoration kind
|
||||
/// @return true if this Decoration is of the (or derives from) the given
|
||||
/// kind.
|
||||
|
@ -48,9 +51,8 @@ class TypeDecoration : public Decoration {
|
|||
|
||||
protected:
|
||||
/// Constructor
|
||||
/// @param kind the decoration kind
|
||||
/// @param source the source of this decoration
|
||||
explicit TypeDecoration(DecorationKind kind, const Source& source);
|
||||
explicit TypeDecoration(const Source& source);
|
||||
};
|
||||
|
||||
/// A list of type decorations
|
||||
|
|
|
@ -27,12 +27,15 @@ namespace ast {
|
|||
|
||||
constexpr const DecorationKind VariableDecoration::Kind;
|
||||
|
||||
VariableDecoration::VariableDecoration(DecorationKind kind,
|
||||
const Source& source)
|
||||
: Decoration(kind, source) {}
|
||||
VariableDecoration::VariableDecoration(const Source& source)
|
||||
: Decoration(source) {}
|
||||
|
||||
VariableDecoration::~VariableDecoration() = default;
|
||||
|
||||
DecorationKind VariableDecoration::GetKind() const {
|
||||
return Kind;
|
||||
}
|
||||
|
||||
bool VariableDecoration::IsKind(DecorationKind kind) const {
|
||||
return kind == Kind;
|
||||
}
|
||||
|
|
|
@ -39,6 +39,9 @@ class VariableDecoration : public Decoration {
|
|||
|
||||
~VariableDecoration() override;
|
||||
|
||||
/// @return the decoration kind
|
||||
DecorationKind GetKind() const override;
|
||||
|
||||
/// @param kind the decoration kind
|
||||
/// @return true if this Decoration is of the (or derives from) the given
|
||||
/// kind.
|
||||
|
@ -68,9 +71,8 @@ class VariableDecoration : public Decoration {
|
|||
|
||||
protected:
|
||||
/// Constructor
|
||||
/// @param kind the decoration kind
|
||||
/// @param source the source of this decoration
|
||||
VariableDecoration(DecorationKind kind, const Source& source);
|
||||
explicit VariableDecoration(const Source& source);
|
||||
};
|
||||
|
||||
/// A list of variable decorations
|
||||
|
|
|
@ -20,21 +20,25 @@ namespace ast {
|
|||
constexpr const DecorationKind WorkgroupDecoration::Kind;
|
||||
|
||||
WorkgroupDecoration::WorkgroupDecoration(uint32_t x, const Source& source)
|
||||
: FunctionDecoration(Kind, source), x_(x) {}
|
||||
: FunctionDecoration(source), x_(x) {}
|
||||
|
||||
WorkgroupDecoration::WorkgroupDecoration(uint32_t x,
|
||||
uint32_t y,
|
||||
const Source& source)
|
||||
: FunctionDecoration(Kind, source), x_(x), y_(y) {}
|
||||
: FunctionDecoration(source), x_(x), y_(y) {}
|
||||
|
||||
WorkgroupDecoration::WorkgroupDecoration(uint32_t x,
|
||||
uint32_t y,
|
||||
uint32_t z,
|
||||
const Source& source)
|
||||
: FunctionDecoration(Kind, source), x_(x), y_(y), z_(z) {}
|
||||
: FunctionDecoration(source), x_(x), y_(y), z_(z) {}
|
||||
|
||||
WorkgroupDecoration::~WorkgroupDecoration() = default;
|
||||
|
||||
DecorationKind WorkgroupDecoration::GetKind() const {
|
||||
return Kind;
|
||||
}
|
||||
|
||||
bool WorkgroupDecoration::IsKind(DecorationKind kind) const {
|
||||
return kind == Kind || FunctionDecoration::IsKind(kind);
|
||||
}
|
||||
|
|
|
@ -47,6 +47,9 @@ class WorkgroupDecoration : public FunctionDecoration {
|
|||
WorkgroupDecoration(uint32_t x, uint32_t y, uint32_t z, const Source& source);
|
||||
~WorkgroupDecoration() override;
|
||||
|
||||
/// @return the decoration kind
|
||||
DecorationKind GetKind() const override;
|
||||
|
||||
/// @param kind the decoration kind
|
||||
/// @return true if this Decoration is of the (or derives from) the given
|
||||
/// kind.
|
||||
|
|
Loading…
Reference in New Issue