sem: Have sem::Type derive from sem::Node

Having a common base class will tighten up some of the dynamic casting that we do.

Bug: tint:724
Change-Id: I45c6f200e1ec242ddb08ce75bd1c4c037a21a38d
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49882
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: James Price <jrprice@google.com>
This commit is contained in:
Ben Clayton 2021-05-06 15:52:33 +00:00 committed by Commit Bot service account
parent a0174e613f
commit 58750eab19
4 changed files with 16 additions and 3 deletions

View File

@ -304,7 +304,10 @@ class ProgramBuilder {
/// @param args the arguments to pass to the type constructor
/// @returns the node pointer
template <typename T, typename... ARGS>
traits::EnableIfIsType<T, sem::Node>* create(ARGS&&... args) {
traits::EnableIf<traits::IsTypeOrDerived<T, sem::Node>::value &&
!traits::IsTypeOrDerived<T, sem::Type>::value,
T>*
create(ARGS&&... args) {
AssertNotMoved();
return sem_nodes_.Create<T>(std::forward<ARGS>(args)...);
}

View File

@ -19,6 +19,10 @@ TINT_INSTANTIATE_TYPEINFO(tint::sem::Node);
namespace tint {
namespace sem {
Node::Node() = default;
Node::Node(const Node&) = default;
Node::~Node() = default;
} // namespace sem

View File

@ -23,6 +23,12 @@ namespace sem {
/// Node is the base class for all semantic nodes
class Node : public Castable<Node> {
public:
/// Constructor
Node();
/// Copy constructor
Node(const Node&);
/// Destructor
~Node() override;
};

View File

@ -17,7 +17,7 @@
#include <string>
#include "src/castable.h"
#include "src/sem/node.h"
namespace tint {
@ -31,7 +31,7 @@ namespace sem {
enum class MemoryLayout { kUniformBuffer, kStorageBuffer };
/// Base class for a type in the system
class Type : public Castable<Type> {
class Type : public Castable<Type, Node> {
public:
/// Move constructor
Type(Type&&);