summaryrefslogtreecommitdiff
path: root/source/slang/visitor.h
diff options
context:
space:
mode:
authorTim Foley <tfoley@nvidia.com>2017-07-07 12:31:38 -0700
committerTim Foley <tfoley@nvidia.com>2017-07-07 12:37:15 -0700
commitc0bcb9c358e22a5c61c3efe77a14a368632bac70 (patch)
treeed4adfdd34793f2656b7010f86a18c99f9eeb7cb /source/slang/visitor.h
parent6da1782f34e8022774dce8d253bc5c3ab9b496cc (diff)
Overhaul emit logic to use visitor abstraction
- This is in preparation for splitting out HLSL vs. GLSL emit as different cases. - Along the way, I added more cases to the visitor implementation, to handle visitors with arguments - This is getting a bit busy, though, and we might be reaching the breaking point where a more general bit of meta-magic is needed to clean things up (either going further down the ugly template route, or plugging in a more real code generation strategy)
Diffstat (limited to 'source/slang/visitor.h')
-rw-r--r--source/slang/visitor.h82
1 files changed, 82 insertions, 0 deletions
diff --git a/source/slang/visitor.h b/source/slang/visitor.h
index eaddc5f32..7000927c7 100644
--- a/source/slang/visitor.h
+++ b/source/slang/visitor.h
@@ -80,6 +80,33 @@ struct TypeVisitor<Derived,void,Base> : Base
#include "object-meta-end.h"
};
+template<typename Derived, typename Arg, typename Base = ITypeVisitor>
+struct TypeVisitorWithArg : Base
+{
+ void dispatch(ExpressionType* type, Arg const& arg)
+ {
+ type->accept(this, (void*)&arg);
+ }
+
+#define ABSTRACT_SYNTAX_CLASS(NAME,BASE) /* empty */
+#define SYNTAX_CLASS(NAME, BASE) \
+ virtual void dispatch_##NAME(NAME* obj, void* arg) override \
+ { ((Derived*) this)->visit##NAME(obj, *(Arg*)arg); }
+
+#include "object-meta-begin.h"
+#include "type-defs.h"
+#include "object-meta-end.h"
+
+#define ABSTRACT_SYNTAX_CLASS(NAME,BASE) SYNTAX_CLASS(NAME, BASE)
+#define SYNTAX_CLASS(NAME, BASE) \
+ void visit##NAME(NAME* obj, Arg const& arg) \
+ { ((Derived*) this)->visit##BASE(obj, arg); }
+
+#include "object-meta-begin.h"
+#include "type-defs.h"
+#include "object-meta-end.h"
+};
+
//
// Expression Visitors
//
@@ -151,6 +178,33 @@ struct ExprVisitor<Derived,void> : IExprVisitor
#include "object-meta-end.h"
};
+template<typename Derived, typename Arg>
+struct ExprVisitorWithArg : IExprVisitor
+{
+ void dispatch(ExpressionSyntaxNode* obj, Arg const& arg)
+ {
+ obj->accept(this, (void*)&arg);
+ }
+
+#define ABSTRACT_SYNTAX_CLASS(NAME,BASE) /* empty */
+#define SYNTAX_CLASS(NAME, BASE) \
+ virtual void dispatch_##NAME(NAME* obj, void* arg) override \
+ { ((Derived*) this)->visit##NAME(obj, *(Arg*)arg); }
+
+#include "object-meta-begin.h"
+#include "expr-defs.h"
+#include "object-meta-end.h"
+
+#define ABSTRACT_SYNTAX_CLASS(NAME,BASE) SYNTAX_CLASS(NAME, BASE)
+#define SYNTAX_CLASS(NAME, BASE) \
+ void visit##NAME(NAME* obj, Arg const& arg) \
+ { ((Derived*) this)->visit##BASE(obj, arg); }
+
+#include "object-meta-begin.h"
+#include "expr-defs.h"
+#include "object-meta-end.h"
+};
+
//
// Statement Visitors
//
@@ -293,6 +347,34 @@ struct DeclVisitor<Derived,void> : IDeclVisitor
#include "object-meta-end.h"
};
+template<typename Derived, typename Arg>
+struct DeclVisitorWithArg : IDeclVisitor
+{
+ void dispatch(DeclBase* obj, Arg const& arg)
+ {
+ obj->accept(this, (void*)&arg);
+ }
+
+#define ABSTRACT_SYNTAX_CLASS(NAME,BASE) /* empty */
+#define SYNTAX_CLASS(NAME, BASE) \
+ virtual void dispatch_##NAME(NAME* obj, void* arg) override \
+ { ((Derived*) this)->visit##NAME(obj, *(Arg*)arg); }
+
+#include "object-meta-begin.h"
+#include "decl-defs.h"
+#include "object-meta-end.h"
+
+#define ABSTRACT_SYNTAX_CLASS(NAME,BASE) SYNTAX_CLASS(NAME, BASE)
+#define SYNTAX_CLASS(NAME, BASE) \
+ void visit##NAME(NAME* obj, Arg const& arg) \
+ { ((Derived*) this)->visit##BASE(obj, arg); }
+
+#include "object-meta-begin.h"
+#include "decl-defs.h"
+#include "object-meta-end.h"
+};
+
+
//
// Modifier Visitors
//