diff options
| author | Yong He <yonghe@outlook.com> | 2018-01-03 18:09:35 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-01-03 18:09:35 -0800 |
| commit | e90dfcfd6a0a6d92688012b1216c46c24965cfc0 (patch) | |
| tree | 89b1e0e3f0e95ea0bf586bd67fa36066f0021ce7 /source/slang/reflection.cpp | |
| parent | 5da16a6360e40b9fd4d2275a5ef5b1af740c4abb (diff) | |
| parent | 550405d2de2ca617046e73fe5ec7e5e1765a5c97 (diff) | |
Merge pull request #349 from csyonghe/master
Add API for querying TypeLayout from a Type
Diffstat (limited to 'source/slang/reflection.cpp')
| -rw-r--r-- | source/slang/reflection.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/source/slang/reflection.cpp b/source/slang/reflection.cpp index 5270df8b4..c9de75d6e 100644 --- a/source/slang/reflection.cpp +++ b/source/slang/reflection.cpp @@ -428,6 +428,42 @@ SLANG_API char const* spReflectionType_GetName(SlangReflectionType* inType) return nullptr; } +SLANG_API SlangReflectionType * spReflection_FindTypeByName(SlangReflection * reflection, char const * name) +{ + auto context = convert(reflection); + auto compileRequest = context->targetRequest->compileRequest; + + RefPtr<Type> result; + if (compileRequest->types.TryGetValue(name, result)) + return (SlangReflectionType*)result.Ptr(); + + auto nameObj = compileRequest->getNamePool()->getName(name); + Decl* resultDecl = compileRequest->lookupGlobalDecl(nameObj); + if (resultDecl) + { + RefPtr<DeclRefType> declRefType = new DeclRefType(); + declRefType->declRef.decl = resultDecl; + compileRequest->types[name] = declRefType; + return (SlangReflectionType*)declRefType.Ptr(); + } + return nullptr; +} + +SLANG_API SlangReflectionTypeLayout* spReflection_GetTypeLayout( + SlangReflection* reflection, + SlangReflectionType* inType, + SlangLayoutRules /*rules*/) +{ + auto context = convert(reflection); + auto type = convert(inType); + auto layoutContext = getInitialLayoutContextForTarget(context->targetRequest); + RefPtr<TypeLayout> result; + if (context->targetRequest->typeLayouts.TryGetValue(type, result)) + return (SlangReflectionTypeLayout*)result.Ptr(); + result = CreateTypeLayout(layoutContext, type); + context->targetRequest->typeLayouts[type] = result; + return (SlangReflectionTypeLayout*)result.Ptr(); +} SLANG_API SlangReflectionType* spReflectionType_GetResourceResultType(SlangReflectionType* inType) { |
