summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--source/slang/slang-ast-base.h8
-rw-r--r--source/slang/slang-ast-decl.h6
-rw-r--r--source/slang/slang-ast-expr.h6
-rw-r--r--source/slang/slang-ast-modifier.h7
-rw-r--r--source/slang/slang-ast-reflect.h52
-rw-r--r--source/slang/slang-ast-stmt.h6
-rw-r--r--source/slang/slang-ast-type.h6
-rw-r--r--source/slang/slang-ast-val.h7
8 files changed, 36 insertions, 62 deletions
diff --git a/source/slang/slang-ast-base.h b/source/slang/slang-ast-base.h
index ee044eae3..1175f0288 100644
--- a/source/slang/slang-ast-base.h
+++ b/source/slang/slang-ast-base.h
@@ -14,10 +14,6 @@
namespace Slang
{
-#define SLANG_ABSTRACT_CLASS(x) SLANG_ABSTRACT_CLASS_REFLECT(x)
-// We don't use SLANG_CLASS_REFLECT_WITH_ACCEPT(x), as we don't want accept method on these classes
-#define SLANG_CLASS(x) SLANG_CLASS_REFLECT_DEFAULT(x)
-
// Signals to C++ extractor that RefObject is a base class, that isn't reflected to C++ extractor
SLANG_REFLECT_BASE_CLASS(RefObject)
@@ -363,8 +359,4 @@ class Stmt : public ModifiableSyntaxNode
virtual void accept(IStmtVisitor* visitor, void* extra) = 0;
};
-#undef SLANG_ABSTRACT_CLASS
-#undef SLANG_CLASS
-
-
} // namespace Slang
diff --git a/source/slang/slang-ast-decl.h b/source/slang/slang-ast-decl.h
index f151b6ca0..5020debfa 100644
--- a/source/slang/slang-ast-decl.h
+++ b/source/slang/slang-ast-decl.h
@@ -6,9 +6,6 @@
namespace Slang {
-#define SLANG_ABSTRACT_CLASS(x) SLANG_ABSTRACT_CLASS_REFLECT(x)
-#define SLANG_CLASS(x) SLANG_CLASS_REFLECT_WITH_ACCEPT(x)
-
// Syntax class definitions for declarations.
// A group of declarations that should be treated as a unit
@@ -458,7 +455,4 @@ class AttributeDecl : public ContainerDecl
SyntaxClass<RefObject> syntaxClass;
};
-#undef SLANG_ABSTRACT_CLASS
-#undef SLANG_CLASS
-
} // namespace Slang
diff --git a/source/slang/slang-ast-expr.h b/source/slang/slang-ast-expr.h
index 31e3869d3..6bec297a4 100644
--- a/source/slang/slang-ast-expr.h
+++ b/source/slang/slang-ast-expr.h
@@ -6,9 +6,6 @@
namespace Slang {
-#define SLANG_ABSTRACT_CLASS(x) SLANG_ABSTRACT_CLASS_REFLECT(x)
-#define SLANG_CLASS(x) SLANG_CLASS_REFLECT_WITH_ACCEPT(x)
-
// Syntax class definitions for expressions.
// Base class for expressions that will reference declarations
@@ -305,7 +302,4 @@ class ThisTypeExpr: public Expr
RefPtr<Scope> scope;
};
-#undef SLANG_ABSTRACT_CLASS
-#undef SLANG_CLASS
-
} // namespace Slang
diff --git a/source/slang/slang-ast-modifier.h b/source/slang/slang-ast-modifier.h
index 440575171..6145c9192 100644
--- a/source/slang/slang-ast-modifier.h
+++ b/source/slang/slang-ast-modifier.h
@@ -6,9 +6,6 @@
namespace Slang {
-#define SLANG_ABSTRACT_CLASS(x) SLANG_ABSTRACT_CLASS_REFLECT(x)
-#define SLANG_CLASS(x) SLANG_CLASS_REFLECT_WITH_ACCEPT(x)
-
// Syntax class definitions for modifiers.
// Simple modifiers have no state beyond their identity
@@ -876,8 +873,4 @@ class UnsafeForceInlineEarlyAttribute : public Attribute
SLANG_CLASS(UnsafeForceInlineEarlyAttribute)
};
-
-#undef SLANG_ABSTRACT_CLASS
-#undef SLANG_CLASS
-
} // namespace Slang
diff --git a/source/slang/slang-ast-reflect.h b/source/slang/slang-ast-reflect.h
index 953c1eaf1..9c93d0621 100644
--- a/source/slang/slang-ast-reflect.h
+++ b/source/slang/slang-ast-reflect.h
@@ -5,33 +5,53 @@
#include "slang-ast-generated.h"
+// Switch based on node type - only inner and leaf classes define override
#define SLANG_AST_OVERRIDE_BASE
#define SLANG_AST_OVERRIDE_INNER override
#define SLANG_AST_OVERRIDE_LEAF override
-// Implement the part that uses the class definition
-#define SLANG_CLASS_REFLECT_DEFAULT_IMPL(NAME, SUPER, ORIGIN, LAST, MARKER, TYPE, param) \
+// Switch based on the origin - classes defined in slang-ast-base.h do not have accept defined on them
+// The 'origin' is based on the file where the class definition is located.
+
+// Define what the accept method looks like, so don't have to repeat
+#define SLANG_AST_ACCEPT_IMPL(NAME) virtual void accept(NAME::Visitor* visitor, void* extra) override;
+
+// A macro for *all* of the different origin/files where AST files are defined.
+#define SLANG_AST_ACCEPT_BASE(NAME)
+#define SLANG_AST_ACCEPT_DECL(NAME) SLANG_AST_ACCEPT_IMPL(NAME)
+#define SLANG_AST_ACCEPT_EXPR(NAME) SLANG_AST_ACCEPT_IMPL(NAME)
+#define SLANG_AST_ACCEPT_MODIFIER(NAME) SLANG_AST_ACCEPT_IMPL(NAME)
+#define SLANG_AST_ACCEPT_TYPE(NAME) SLANG_AST_ACCEPT_IMPL(NAME)
+#define SLANG_AST_ACCEPT_VAL(NAME) SLANG_AST_ACCEPT_IMPL(NAME)
+#define SLANG_AST_ACCEPT_STMT(NAME) SLANG_AST_ACCEPT_IMPL(NAME)
+
+// Implementation for SLANG_ABSTRACT_CLASS(x) using reflection from C++ extractor in slang-ast-generated.h
+#define SLANG_ABSTRACT_CLASS_REFLECT_IMPL(NAME, SUPER, ORIGIN, LAST, MARKER, TYPE, param) \
+ public: \
typedef SUPER Super; \
+ static const ASTNodeType kType = ASTNodeType::NAME; \
+ static const ReflectClassInfo kReflectClassInfo; \
SLANG_FORCE_INLINE static bool isDerivedFrom(ASTNodeType type) { return int(type) >= int(kType) && int(type) <= int(ASTNodeType::LAST); } \
virtual const ReflectClassInfo& getClassInfo() const SLANG_AST_OVERRIDE_##TYPE { return kReflectClassInfo; } \
-
-#define SLANG_CLASS_REFLECT_DEFAULT(NAME) \
+// Implementation for SLANG_CLASS(x) using reflection from C++ extractor in slang-ast-generated.h.
+// This implementation is the same as for SLANG_ABSTRACT_CLASS_REFLECT_IMPL, except for the SLANG_AST_ACCEPT_ line which inserts the accept
+// method for non 'BASE' origin classes.
+#define SLANG_CLASS_REFLECT_IMPL(NAME, SUPER, ORIGIN, LAST, MARKER, TYPE, param) \
public: \
+ typedef SUPER Super; \
static const ASTNodeType kType = ASTNodeType::NAME; \
- static const ReflectClassInfo kReflectClassInfo; \
- SLANG_ASTNode_##NAME(SLANG_CLASS_REFLECT_DEFAULT_IMPL, _)
-
-#define SLANG_CLASS_REFLECT_WITH_ACCEPT(NAME) \
- SLANG_CLASS_REFLECT_DEFAULT(NAME) \
- virtual void accept(NAME::Visitor* visitor, void* extra) override;
-
-#define SLANG_ABSTRACT_CLASS_REFLECT(NAME) SLANG_CLASS_REFLECT_DEFAULT(NAME)
-#define SLANG_CLASS_REFLECT(NAME) SLANG_CLASS_REFLECT_DEFAULT(NAME)
-
-// Used for C++ extractor, does nothing here
-#define SLANG_REFLECT_BASE_CLASS(x) /* ... */
+ static const ReflectClassInfo kReflectClassInfo; \
+ SLANG_FORCE_INLINE static bool isDerivedFrom(ASTNodeType type) { return int(type) >= int(kType) && int(type) <= int(ASTNodeType::LAST); } \
+ virtual const ReflectClassInfo& getClassInfo() const SLANG_AST_OVERRIDE_##TYPE { return kReflectClassInfo; } \
+ SLANG_AST_ACCEPT_##ORIGIN(NAME)
+// Macro definitions - use the SLANG_ASTNode_ definitions to invoke the IMPL to produce the code
+// injected into AST classes
+#define SLANG_ABSTRACT_CLASS(NAME) SLANG_ASTNode_##NAME(SLANG_ABSTRACT_CLASS_REFLECT_IMPL, _)
+#define SLANG_CLASS(NAME) SLANG_ASTNode_##NAME(SLANG_CLASS_REFLECT_IMPL, _)
+// Does nothing - just a mark to the C++ extractor
+#define SLANG_REFLECT_BASE_CLASS(NAME)
#endif // SLANG_AST_REFLECT_H
diff --git a/source/slang/slang-ast-stmt.h b/source/slang/slang-ast-stmt.h
index 28b8162a2..323f23d8a 100644
--- a/source/slang/slang-ast-stmt.h
+++ b/source/slang/slang-ast-stmt.h
@@ -6,9 +6,6 @@
namespace Slang {
-#define SLANG_ABSTRACT_CLASS(x) SLANG_ABSTRACT_CLASS_REFLECT(x)
-#define SLANG_CLASS(x) SLANG_CLASS_REFLECT_WITH_ACCEPT(x)
-
// Syntax class definitions for statements.
class ScopeStmt : public Stmt
@@ -207,7 +204,4 @@ class ExpressionStmt : public Stmt
RefPtr<Expr> Expression;
};
-#undef SLANG_ABSTRACT_CLASS
-#undef SLANG_CLASS
-
} // namespace Slang
diff --git a/source/slang/slang-ast-type.h b/source/slang/slang-ast-type.h
index 454b7228e..9134923e0 100644
--- a/source/slang/slang-ast-type.h
+++ b/source/slang/slang-ast-type.h
@@ -6,9 +6,6 @@
namespace Slang {
-#define SLANG_ABSTRACT_CLASS(x) SLANG_ABSTRACT_CLASS_REFLECT(x)
-#define SLANG_CLASS(x) SLANG_CLASS_REFLECT_WITH_ACCEPT(x)
-
// Syntax class definitions for types.
// The type of a reference to an overloaded name
@@ -684,7 +681,4 @@ class ThisType : public Type
};
-#undef SLANG_ABSTRACT_CLASS
-#undef SLANG_CLASS
-
} // namespace Slang
diff --git a/source/slang/slang-ast-val.h b/source/slang/slang-ast-val.h
index a47acc92d..8e82cdc98 100644
--- a/source/slang/slang-ast-val.h
+++ b/source/slang/slang-ast-val.h
@@ -6,9 +6,6 @@
namespace Slang {
-#define SLANG_ABSTRACT_CLASS(x) SLANG_ABSTRACT_CLASS_REFLECT(x)
-#define SLANG_CLASS(x) SLANG_CLASS_REFLECT_WITH_ACCEPT(x)
-
// Syntax class definitions for compile-time values.
// A compile-time integer (may not have a specific concrete value)
@@ -199,8 +196,4 @@ class TaggedUnionSubtypeWitness : public SubtypeWitness
virtual RefPtr<Val> SubstituteImpl(SubstitutionSet subst, int * ioDiff) override;
};
-
-#undef SLANG_ABSTRACT_CLASS
-#undef SLANG_CLASS
-
} // namespace Slang