summaryrefslogtreecommitdiffstats
path: root/source/slang/syntax.h
diff options
context:
space:
mode:
authorTim Foley <tfoley@nvidia.com>2017-07-10 15:40:42 -0700
committerTim Foley <tfoley@nvidia.com>2017-07-11 12:07:09 -0700
commitbd7105ff8683a680d1270eca8cd74f9002144dbd (patch)
tree2e4911b6da6573d334117a08130be5c945c31b15 /source/slang/syntax.h
parent672332936ad7a4610ce0595493152c117476e823 (diff)
Initial work on handling resources in structs during cross-compilation
- The basic idea is that during the "lowering" pass, some types (notably: aggregate types that contain resource variables) will get turned into "tuple" types, which are pseduo-types that aren't meant to survive lowering. - An attempt to declare a variable with a tuple type expands into a tuple of declarations - An attempt to reference such a tuple-ified variable leads to a tuple of expressions - An attempt to extract a member from such a tuple expression will pick the appropriate sub-element - Dereference a tuple by dereferencing the primary expression - Expand a tuple in the argument list to a call into N arguments (by recursively flattening the tuple) - Don't create tuple types when not generating GLSL - Make sure to preserve the specialized type of a call expression through lowering, since emission of unchecked calls relies on that info. - TODO: maybe the infix/prefix/postifx/select information should come in as a side-band? Should we have modifiers on expressions? - Make sure to offset the layout for a nested field based on teh base offset of its parent variable, when generating declarations for nested fields
Diffstat (limited to 'source/slang/syntax.h')
-rw-r--r--source/slang/syntax.h59
1 files changed, 59 insertions, 0 deletions
diff --git a/source/slang/syntax.h b/source/slang/syntax.h
index de5467c71..83b2f5801 100644
--- a/source/slang/syntax.h
+++ b/source/slang/syntax.h
@@ -231,6 +231,65 @@ namespace Slang
RefPtr<ExpressionType> operator->() { return type; }
};
+ // A reference to a class of syntax node, that can be
+ // used to create instances on the fly
+ struct SyntaxClassBase
+ {
+ typedef void* (*CreateFunc)();
+
+ SyntaxClassBase()
+ {}
+
+ SyntaxClassBase(CreateFunc createFunc)
+ : createFunc(createFunc)
+ {}
+
+ void* createInstanceImpl()
+ {
+ return createFunc ? createFunc() : nullptr;
+ }
+
+ CreateFunc createFunc = nullptr;
+
+ template<typename T>
+ struct Impl
+ {
+ static void* createFunc();
+ };
+ };
+
+ template<typename T>
+ struct SyntaxClass : SyntaxClassBase
+ {
+ SyntaxClass()
+ {}
+
+ template <typename U>
+ SyntaxClass(SyntaxClass<U> const& other,
+ typename EnableIf<IsConvertible<T*, U*>::Value, void>::type* = 0)
+ : SyntaxClassBase(other.createFunc)
+ {
+ }
+
+ T* createInstance()
+ {
+ return (T*)createInstanceImpl();
+ }
+
+ static SyntaxClass<T> getClass()
+ {
+ SyntaxClass<T> result;
+ result.createFunc = &SyntaxClass::Impl<T>::createFunc;
+ return result;
+ }
+ };
+
+ template<typename T>
+ SyntaxClass<T> getClass()
+ {
+ return SyntaxClass<T>::getClass();
+ }
+
// A reference to a declaration, which may include
// substitutions for generic parameters.