From 939688e963fde7a0485f210ef2674c27692021a4 Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Tue, 7 Nov 2017 14:05:22 -0800 Subject: Add reflection API to get type name (#263) This is currently only useful for `struct` types. I implemented a special-case exception so that the auto-generated `struct` types used for `cbuffer` members don't show their internal name. I did *not* implement any logic to avoid returning the name `vector` for a vector type, etc., since they are all `DeclRefType`s and it seemed easiest to just let the user access information they can't really use. --- source/slang/reflection.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'source/slang/reflection.cpp') diff --git a/source/slang/reflection.cpp b/source/slang/reflection.cpp index 3ed182750..9fc032c76 100644 --- a/source/slang/reflection.cpp +++ b/source/slang/reflection.cpp @@ -392,6 +392,27 @@ SLANG_API SlangResourceAccess spReflectionType_GetResourceAccess(SlangReflection return SLANG_RESOURCE_ACCESS_NONE; } +SLANG_API char const* spReflectionType_GetName(SlangReflectionType* inType) +{ + auto type = convert(inType); + + if( auto declRefType = type->As() ) + { + auto declRef = declRefType->declRef; + + // Don't return a name for auto-generated anonymous types + // that represent `cbuffer` members, etc. + auto decl = declRef.getDecl(); + if(decl->HasModifier()) + return nullptr; + + return getText(declRef.GetName()).begin(); + } + + return nullptr; +} + + SLANG_API SlangReflectionType* spReflectionType_GetResourceResultType(SlangReflectionType* inType) { auto type = convert(inType); -- cgit v1.2.3