Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions source/slang/slang-reflection-api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,7 @@ SLANG_API SlangReflectionFunction* spReflection_FindFunctionByName(
Lexer::sourceLocationLexer);

auto astBuilder = program->getLinkage()->getASTBuilder();
SLANG_AST_BUILDER_RAII(astBuilder);
try
{
return tryConvertExprToFunctionReflection(
Expand Down Expand Up @@ -948,6 +949,7 @@ SLANG_API SlangReflectionFunction* spReflection_FindFunctionByNameInType(
Lexer::sourceLocationLexer);

auto astBuilder = program->getLinkage()->getASTBuilder();
SLANG_AST_BUILDER_RAII(astBuilder);

try
{
Expand Down Expand Up @@ -1065,6 +1067,7 @@ DeclRef<Decl> getInnermostGenericParent(DeclRef<Decl> declRef)
{
auto decl = declRef.getDecl();
auto astBuilder = getModule(decl)->getLinkage()->getASTBuilder();
SLANG_AST_BUILDER_RAII(astBuilder);
auto parentDecl = decl;
while (parentDecl)
{
Expand Down Expand Up @@ -3064,6 +3067,7 @@ SLANG_API SlangReflectionType* spReflectionVariable_GetType(SlangReflectionVaria
return nullptr;

auto astBuilder = getModule(var.getDecl())->getLinkage()->getASTBuilder();
SLANG_AST_BUILDER_RAII(astBuilder);

if (auto inheritanceDecl = as<InheritanceDecl>(var.getDecl()))
return convert(inheritanceDecl->base.type);
Expand Down Expand Up @@ -3197,6 +3201,7 @@ SLANG_API SlangReflectionVariable* spReflectionVariable_applySpecializations(
return nullptr;

auto astBuilder = getModule(declRef.getDecl())->getLinkage()->getASTBuilder();
SLANG_AST_BUILDER_RAII(astBuilder);

auto substDeclRef = substituteDeclRef(SubstitutionSet(genericDeclRef), astBuilder, declRef);
return convert(substDeclRef);
Expand Down Expand Up @@ -3406,6 +3411,7 @@ SLANG_API SlangReflectionType* spReflectionFunction_GetResultType(SlangReflectio

auto rawType = func.getDecl()->returnType.type;
auto astBuilder = rawType->getASTBuilderForReflection();
SLANG_AST_BUILDER_RAII(astBuilder);

return convert((Type*)rawType->substitute(astBuilder, SubstitutionSet(func.declRefBase)));
}
Expand Down Expand Up @@ -3474,6 +3480,7 @@ SLANG_API SlangReflectionVariable* spReflectionFunction_GetParameter(
return nullptr;

auto astBuilder = getModule(func.getDecl())->getLinkage()->getASTBuilder();
SLANG_AST_BUILDER_RAII(astBuilder);

return convert(getParameters(astBuilder, func)[index]);
}
Expand All @@ -3498,6 +3505,7 @@ SLANG_API SlangReflectionFunction* spReflectionFunction_applySpecializations(
return nullptr;

auto astBuilder = getModule(declRef.getDecl())->getLinkage()->getASTBuilder();
SLANG_AST_BUILDER_RAII(astBuilder);

auto substDeclRef = substituteDeclRef(SubstitutionSet(genericDeclRef), astBuilder, declRef);
return convert(substDeclRef.as<FunctionDeclBase>());
Expand Down Expand Up @@ -3582,6 +3590,7 @@ SLANG_API SlangReflectionFunction* spReflectionFunction_getOverload(
else if (auto genericDeclRef = declRef.as<GenericDecl>())
{
auto astBuilder = getModule(genericDeclRef.getDecl())->getLinkage()->getASTBuilder();
SLANG_AST_BUILDER_RAII(astBuilder);
auto innerDeclRef = substituteDeclRef(
SubstitutionSet(genericDeclRef),
astBuilder,
Expand Down Expand Up @@ -3702,6 +3711,7 @@ SLANG_API SlangReflectionType* spReflection_getTypeFromDecl(SlangReflectionDecl*
Decl* slangDecl = (Decl*)decl;

ASTBuilder* builder = getModule(slangDecl)->getLinkage()->getASTBuilder();
SLANG_AST_BUILDER_RAII(builder);
// TODO: create default substitutions
if (auto type = DeclRefType::create(builder, slangDecl->getDefaultDeclRef()))
{
Expand Down Expand Up @@ -3744,6 +3754,7 @@ SLANG_API unsigned int spReflectionGeneric_GetTypeParameterCount(SlangReflection
if (!slangGeneric)
return 0;
auto astBuilder = getModule(slangGeneric.getDecl())->getLinkage()->getASTBuilder();
SLANG_AST_BUILDER_RAII(astBuilder);

return (unsigned int)getMembersOfType<GenericTypeParamDecl>(
astBuilder,
Expand All @@ -3759,6 +3770,7 @@ SLANG_API SlangReflectionVariable* spReflectionGeneric_GetTypeParameter(
if (!slangGeneric)
return nullptr;
auto astBuilder = getModule(slangGeneric.getDecl())->getLinkage()->getASTBuilder();
SLANG_AST_BUILDER_RAII(astBuilder);

auto paramDeclRef = getMembersOfType<GenericTypeParamDecl>(
astBuilder,
Expand All @@ -3773,6 +3785,7 @@ SLANG_API unsigned int spReflectionGeneric_GetValueParameterCount(SlangReflectio
if (!slangGeneric)
return 0;
auto astBuilder = getModule(slangGeneric.getDecl())->getLinkage()->getASTBuilder();
SLANG_AST_BUILDER_RAII(astBuilder);

return (unsigned int)getMembersOfType<GenericValueParamDecl>(
astBuilder,
Expand All @@ -3788,6 +3801,7 @@ SLANG_API SlangReflectionVariable* spReflectionGeneric_GetValueParameter(
if (!slangGeneric)
return nullptr;
auto astBuilder = getModule(slangGeneric.getDecl())->getLinkage()->getASTBuilder();
SLANG_AST_BUILDER_RAII(astBuilder);

auto paramDeclRef = getMembersOfType<GenericValueParamDecl>(
astBuilder,
Expand All @@ -3804,6 +3818,7 @@ SLANG_API unsigned int spReflectionGeneric_GetTypeParameterConstraintCount(
if (!slangGeneric)
return 0;
auto astBuilder = getModule(slangGeneric.getDecl())->getLinkage()->getASTBuilder();
SLANG_AST_BUILDER_RAII(astBuilder);

if (auto typeParamDecl = as<GenericTypeParamDecl>(convert(typeParam).getDecl()))
{
Expand All @@ -3825,6 +3840,7 @@ SLANG_API SlangReflectionType* spReflectionGeneric_GetTypeParameterConstraintTyp
if (!slangGeneric)
return nullptr;
auto astBuilder = getModule(slangGeneric.getDecl())->getLinkage()->getASTBuilder();
SLANG_AST_BUILDER_RAII(astBuilder);

if (auto typeParamDecl = as<GenericTypeParamDecl>(convert(typeParam).getDecl()))
{
Expand Down Expand Up @@ -3864,6 +3880,7 @@ SLANG_API SlangReflectionGeneric* spReflectionGeneric_GetOuterGenericContainer(
auto declRef = convertGenericToDeclRef(generic);

auto astBuilder = getModule(declRef.getDecl())->getLinkage()->getASTBuilder();
SLANG_AST_BUILDER_RAII(astBuilder);

return convertDeclToGeneric(getInnermostGenericParent(substituteDeclRef(
SubstitutionSet(declRef),
Expand All @@ -3882,6 +3899,7 @@ SLANG_API SlangReflectionType* spReflectionGeneric_GetConcreteType(
if (!slangGeneric)
return nullptr;
auto astBuilder = getModule(slangGeneric.getDecl())->getLinkage()->getASTBuilder();
SLANG_AST_BUILDER_RAII(astBuilder);

auto genericType = DeclRefType::create(astBuilder, convert(typeParam));

Expand All @@ -3903,6 +3921,7 @@ SLANG_API int64_t spReflectionGeneric_GetConcreteIntVal(
if (!slangGeneric)
return 0;
auto astBuilder = getModule(slangGeneric.getDecl())->getLinkage()->getASTBuilder();
SLANG_AST_BUILDER_RAII(astBuilder);

auto valueParamDeclRef = convert(valueParam);

Expand Down Expand Up @@ -3932,6 +3951,7 @@ SLANG_API SlangReflectionGeneric* spReflectionGeneric_applySpecializations(
return nullptr;

auto astBuilder = getModule(declRef.getDecl())->getLinkage()->getASTBuilder();
SLANG_AST_BUILDER_RAII(astBuilder);

auto substDeclRef = substituteDeclRef(SubstitutionSet(genericDeclRef), astBuilder, declRef);
return convertDeclToGeneric(substDeclRef);
Expand Down Expand Up @@ -4404,6 +4424,7 @@ SLANG_API SlangReflectionGeneric* spReflection_specializeGeneric(
if (!slangGeneric)
return nullptr;
auto astBuilder = getModule(slangGeneric.getDecl())->getLinkage()->getASTBuilder();
SLANG_AST_BUILDER_RAII(astBuilder);

auto linkage = programLayout->getProgram()->getLinkage();

Expand Down
Loading