From e0389f5a1f32cb611e5a595a5974ee1d5c15f43d Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Thu, 15 Jun 2017 16:35:10 -0700 Subject: 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` 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` for some specific `T` as a parameter. --- source/slang/reflection.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'source/slang/reflection.cpp') 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() ) { auto declRef = declRefType->declRef; - if( auto structDeclRef = declRef.As() ) + if( auto structDeclRef = declRef.As() ) { return SLANG_TYPE_KIND_STRUCT; } @@ -155,9 +155,9 @@ SLANG_API unsigned int spReflectionType_GetFieldCount(SlangReflectionType* inTyp if(auto declRefType = dynamic_cast(type)) { auto declRef = declRefType->declRef; - if( auto structDeclRef = declRef.As()) + if( auto structDeclRef = declRef.As()) { - return structDeclRef.GetFields().Count(); + return GetFields(structDeclRef).Count(); } } @@ -174,10 +174,10 @@ SLANG_API SlangReflectionVariable* spReflectionType_GetFieldByIndex(SlangReflect if(auto declRefType = dynamic_cast(type)) { auto declRef = declRefType->declRef; - if( auto structDeclRef = declRef.As()) + if( auto structDeclRef = declRef.As()) { - 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) -- cgit v1.2.3