diff options
| author | Tim Foley <tfoley@nvidia.com> | 2017-06-15 16:35:10 -0700 |
|---|---|---|
| committer | Tim Foley <tfoley@nvidia.com> | 2017-06-15 16:35:10 -0700 |
| commit | e0389f5a1f32cb611e5a595a5974ee1d5c15f43d (patch) | |
| tree | 7bee1ed3a1f235ac97de9f8d9893f2994015c5c3 /source/slang/reflection.cpp | |
| parent | 04d43cd71f081f1b8d2f0fd803a47cb6342e4fcd (diff) | |
Replace `DeclRef` approach
For context: a `DeclRef` is supposed to capture both a pointer to a particualr declaration, and also any information needed to specialize that declaration for a context (e.g., generic parameter substitutions).
The existing approach had a hiearchy of specialized decl-ref types that mirrored the AST hierarchy, but that led to a lot of boilerplate where you had to recapitulate the exact same hierarchy.
The new appraoch basically treats `DeclRef<T>` as a sort of "smart pointer" in that it wraps a pointer to a `T` (the declaration), plus a side field for the specialization info, and then allows it to be cast as needed to other types (where the pointer cast would be allowed), while carrying along the side info.
To enable this, all the things that used to be member functions of declaration-reference types are now free functions that take a `DeclRef<T>` for some specific `T` as a parameter.
Diffstat (limited to 'source/slang/reflection.cpp')
| -rw-r--r-- | source/slang/reflection.cpp | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/source/slang/reflection.cpp b/source/slang/reflection.cpp index 220e5bcdf..89fd94093 100644 --- a/source/slang/reflection.cpp +++ b/source/slang/reflection.cpp @@ -135,7 +135,7 @@ SLANG_API SlangTypeKind spReflectionType_GetKind(SlangReflectionType* inType) else if( auto declRefType = type->As<DeclRefType>() ) { auto declRef = declRefType->declRef; - if( auto structDeclRef = declRef.As<StructDeclRef>() ) + if( auto structDeclRef = declRef.As<StructSyntaxNode>() ) { return SLANG_TYPE_KIND_STRUCT; } @@ -155,9 +155,9 @@ SLANG_API unsigned int spReflectionType_GetFieldCount(SlangReflectionType* inTyp if(auto declRefType = dynamic_cast<DeclRefType*>(type)) { auto declRef = declRefType->declRef; - if( auto structDeclRef = declRef.As<StructDeclRef>()) + if( auto structDeclRef = declRef.As<StructSyntaxNode>()) { - return structDeclRef.GetFields().Count(); + return GetFields(structDeclRef).Count(); } } @@ -174,10 +174,10 @@ SLANG_API SlangReflectionVariable* spReflectionType_GetFieldByIndex(SlangReflect if(auto declRefType = dynamic_cast<DeclRefType*>(type)) { auto declRef = declRefType->declRef; - if( auto structDeclRef = declRef.As<StructDeclRef>()) + if( auto structDeclRef = declRef.As<StructSyntaxNode>()) { - auto fieldDeclRef = structDeclRef.GetFields().ToArray()[index]; - return (SlangReflectionVariable*) fieldDeclRef.GetDecl(); + auto fieldDeclRef = GetFields(structDeclRef).ToArray()[index]; + return (SlangReflectionVariable*) fieldDeclRef.getDecl(); } } @@ -573,7 +573,7 @@ SLANG_API SlangReflectionVariable* spReflectionVariableLayout_GetVariable(SlangR auto varLayout = convert(inVarLayout); if(!varLayout) return nullptr; - return convert(varLayout->varDecl.GetDecl()); + return convert(varLayout->varDecl.getDecl()); } SLANG_API SlangReflectionTypeLayout* spReflectionVariableLayout_GetTypeLayout(SlangReflectionVariableLayout* inVarLayout) |
