summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorSai Praveen Bangaru <31557731+saipraveenb25@users.noreply.github.com>2024-08-07 02:04:37 -0400
committerGitHub <noreply@github.com>2024-08-07 02:04:37 -0400
commit2f2ae8c31490ab01ce0d0cc76d5d7fcf1d21efe7 (patch)
tree135cb2109f2717dba3a11929c4cdf163b5ad5c50 /include
parent366c9b4526b4b940c8aafce459d6784211e862bc (diff)
More reflection API features. (#4740)
* More reflection API features. + Lookup methods and members (by string) on types + Fix issue with looking up non-static members through the scope operator '::' + `GenericReflection`: Cast a decl to generic to access unspecialized generic parameter names and constraints + `GenericReflection`: Use `getGenericContainer()` from function, variable or type to access the 'nearest' generic parent along with specialization info + `GenericReflection::getConcreteType` and `GenericReflection::getConcreteIntVal`: to get the concrete type of a param in the context of the reflection object + `GenericReflection::getOuterGenericContainer` to go up one level and get the outer generic declarations (if there are more than one enclosing generic scopes) + `DeclReflection::getParent`: go to parent declaration. + Change `VariableReflection` to be a `DeclRef` rather than a decl (allows us to return properly substituted types for methods, members, and more) * Fix Falcor issue
Diffstat (limited to 'include')
-rw-r--r--include/slang.h147
1 files changed, 143 insertions, 4 deletions
diff --git a/include/slang.h b/include/slang.h
index c68157759..05ab1a0ce 100644
--- a/include/slang.h
+++ b/include/slang.h
@@ -2121,6 +2121,7 @@ extern "C"
typedef struct SlangReflectionTypeParameter SlangReflectionTypeParameter;
typedef struct SlangReflectionUserAttribute SlangReflectionUserAttribute;
typedef struct SlangReflectionFunction SlangReflectionFunction;
+ typedef struct SlangReflectionGeneric SlangReflectionGeneric;
/*
Type aliases to maintain backward compatibility.
@@ -2469,6 +2470,7 @@ extern "C"
SLANG_API char const* spReflectionType_GetName(SlangReflectionType* type);
SLANG_API SlangResult spReflectionType_GetFullName(SlangReflectionType* type, ISlangBlob** outNameBlob);
+ SLANG_API SlangReflectionGeneric* spReflectionType_GetGenericContainer(SlangReflectionType* type);
// Type Layout Reflection
@@ -2553,6 +2555,7 @@ extern "C"
SLANG_API SlangReflectionUserAttribute* spReflectionVariable_GetUserAttribute(SlangReflectionVariable* var, unsigned int index);
SLANG_API SlangReflectionUserAttribute* spReflectionVariable_FindUserAttributeByName(SlangReflectionVariable* var, SlangSession * globalSession, char const* name);
SLANG_API bool spReflectionVariable_HasDefaultValue(SlangReflectionVariable* inVar);
+ SLANG_API SlangReflectionGeneric* spReflectionVariable_GetGenericContainer(SlangReflectionVariable* var);
// Variable Layout Reflection
@@ -2578,6 +2581,7 @@ extern "C"
SLANG_API unsigned int spReflectionFunction_GetParameterCount(SlangReflectionFunction* func);
SLANG_API SlangReflectionVariable* spReflectionFunction_GetParameter(SlangReflectionFunction* func, unsigned index);
SLANG_API SlangReflectionType* spReflectionFunction_GetResultType(SlangReflectionFunction* func);
+ SLANG_API SlangReflectionGeneric* spReflectionFunction_GetGenericContainer(SlangReflectionFunction* func);
// Abstract Decl Reflection
@@ -2586,8 +2590,26 @@ extern "C"
SLANG_API SlangDeclKind spReflectionDecl_getKind(SlangReflectionDecl* decl);
SLANG_API SlangReflectionFunction* spReflectionDecl_castToFunction(SlangReflectionDecl* decl);
SLANG_API SlangReflectionVariable* spReflectionDecl_castToVariable(SlangReflectionDecl* decl);
- SLANG_API SlangReflectionType* spReflection_getTypeFromDecl(SlangSession* session, SlangReflectionDecl* decl);
-
+ SLANG_API SlangReflectionGeneric* spReflectionDecl_castToGeneric(SlangReflectionDecl* decl);
+ SLANG_API SlangReflectionType* spReflection_getTypeFromDecl(SlangReflectionDecl* decl);
+ SLANG_API SlangReflectionDecl* spReflectionDecl_getParent(SlangReflectionDecl* decl);
+
+ // Generic Reflection
+
+ SLANG_API SlangReflectionDecl* spReflectionGeneric_asDecl(SlangReflectionGeneric* generic);
+ SLANG_API char const* spReflectionGeneric_GetName(SlangReflectionGeneric* generic);
+ SLANG_API unsigned int spReflectionGeneric_GetTypeParameterCount(SlangReflectionGeneric* generic);
+ SLANG_API SlangReflectionVariable* spReflectionGeneric_GetTypeParameter(SlangReflectionGeneric* generic, unsigned index);
+ SLANG_API unsigned int spReflectionGeneric_GetValueParameterCount(SlangReflectionGeneric* generic);
+ SLANG_API SlangReflectionVariable* spReflectionGeneric_GetValueParameter(SlangReflectionGeneric* generic, unsigned index);
+ SLANG_API unsigned int spReflectionGeneric_GetTypeParameterConstraintCount(SlangReflectionGeneric* generic, SlangReflectionVariable* typeParam);
+ SLANG_API SlangReflectionType* spReflectionGeneric_GetTypeParameterConstraintType(SlangReflectionGeneric* generic, SlangReflectionVariable* typeParam, unsigned index);
+ SLANG_API SlangDeclKind spReflectionGeneric_GetInnerKind(SlangReflectionGeneric* generic);
+ SLANG_API SlangReflectionDecl* spReflectionGeneric_GetInnerDecl(SlangReflectionGeneric* generic);
+ SLANG_API SlangReflectionGeneric* spReflectionGeneric_GetOuterGenericContainer(SlangReflectionGeneric* generic);
+ SLANG_API SlangReflectionType* spReflectionGeneric_GetConcreteType(SlangReflectionGeneric* generic, SlangReflectionVariable* typeParam);
+ SLANG_API int64_t spReflectionGeneric_GetConcreteIntVal(SlangReflectionGeneric* generic, SlangReflectionVariable* valueParam);
+
/** Get the stage that a variable belongs to (if any).
@@ -2678,6 +2700,8 @@ extern "C"
SLANG_API SlangReflectionTypeLayout* spReflection_GetTypeLayout(SlangReflection* reflection, SlangReflectionType* reflectionType, SlangLayoutRules rules);
SLANG_API SlangReflectionFunction* spReflection_FindFunctionByName(SlangReflection* reflection, char const* name);
+ SLANG_API SlangReflectionFunction* spReflection_FindFunctionByNameInType(SlangReflection* reflection, SlangReflectionType* reflType, char const* name);
+ SLANG_API SlangReflectionVariable* spReflection_FindVarByNameInType(SlangReflection* reflection, SlangReflectionType* reflType, char const* name);
SLANG_API SlangUInt spReflection_getEntryPointCount(SlangReflection* reflection);
SLANG_API SlangReflectionEntryPoint* spReflection_getEntryPointByIndex(SlangReflection* reflection, SlangUInt index);
@@ -2735,6 +2759,8 @@ namespace slang
struct TypeReflection;
struct VariableLayoutReflection;
struct VariableReflection;
+ struct FunctionReflection;
+ struct GenericReflection;
struct UserAttribute
{
@@ -2913,6 +2939,11 @@ namespace slang
{
return (UserAttribute*)spReflectionType_FindUserAttributeByName((SlangReflectionType*)this, name);
}
+
+ SlangReflectionGeneric* getGenericContainer()
+ {
+ return (SlangReflectionGeneric*) spReflectionType_GetGenericContainer((SlangReflectionType*) this);
+ }
};
enum ParameterCategory : SlangParameterCategoryIntegral
@@ -3360,10 +3391,12 @@ namespace slang
{
return spReflectionVariable_GetUserAttributeCount((SlangReflectionVariable*)this);
}
+
UserAttribute* getUserAttributeByIndex(unsigned int index)
{
return (UserAttribute*)spReflectionVariable_GetUserAttribute((SlangReflectionVariable*)this, index);
}
+
UserAttribute* findUserAttributeByName(SlangSession* globalSession, char const* name)
{
return (UserAttribute*)spReflectionVariable_FindUserAttributeByName((SlangReflectionVariable*)this, globalSession, name);
@@ -3373,6 +3406,11 @@ namespace slang
{
return spReflectionVariable_HasDefaultValue((SlangReflectionVariable*)this);
}
+
+ GenericReflection* getGenericContainer()
+ {
+ return (GenericReflection*)spReflectionVariable_GetGenericContainer((SlangReflectionVariable*)this);
+ }
};
struct VariableLayoutReflection
@@ -3498,6 +3536,81 @@ namespace slang
{
return (Modifier*)spReflectionFunction_FindModifier((SlangReflectionFunction*)this, (SlangModifierID)id);
}
+
+ GenericReflection* getGenericContainer()
+ {
+ return (GenericReflection*)spReflectionFunction_GetGenericContainer((SlangReflectionFunction*)this);
+ }
+ };
+
+ struct GenericReflection
+ {
+
+ DeclReflection* asDecl()
+ {
+ return (DeclReflection*)spReflectionGeneric_asDecl((SlangReflectionGeneric*)this);
+ }
+
+ char const* getName()
+ {
+ return spReflectionGeneric_GetName((SlangReflectionGeneric*)this);
+ }
+
+ unsigned int getTypeParameterCount()
+ {
+ return spReflectionGeneric_GetTypeParameterCount((SlangReflectionGeneric*)this);
+ }
+
+ VariableReflection* getTypeParameter(unsigned index)
+ {
+ return (VariableReflection*)spReflectionGeneric_GetTypeParameter((SlangReflectionGeneric*)this, index);
+ }
+
+ unsigned int getValueParameterCount()
+ {
+ return spReflectionGeneric_GetValueParameterCount((SlangReflectionGeneric*)this);
+ }
+
+ VariableReflection* getValueParameter(unsigned index)
+ {
+ return (VariableReflection*)spReflectionGeneric_GetValueParameter((SlangReflectionGeneric*)this, index);
+ }
+
+ unsigned int getTypeParameterConstraintCount(VariableReflection* typeParam)
+ {
+ return spReflectionGeneric_GetTypeParameterConstraintCount((SlangReflectionGeneric*)this, (SlangReflectionVariable*)typeParam);
+ }
+
+ TypeReflection* getTypeParameterConstraintType(VariableReflection* typeParam, unsigned index)
+ {
+ return (TypeReflection*)spReflectionGeneric_GetTypeParameterConstraintType((SlangReflectionGeneric*)this, (SlangReflectionVariable*)typeParam, index);
+ }
+
+ DeclReflection* getInnerDecl()
+ {
+ return (DeclReflection*)spReflectionGeneric_GetInnerDecl((SlangReflectionGeneric*)this);
+ }
+
+ SlangDeclKind getInnerKind()
+ {
+ return spReflectionGeneric_GetInnerKind((SlangReflectionGeneric*)this);
+ }
+
+ GenericReflection* getOuterGenericContainer()
+ {
+ return (GenericReflection*)spReflectionGeneric_GetOuterGenericContainer((SlangReflectionGeneric*)this);
+ }
+
+ TypeReflection* getConcreteType(VariableReflection* typeParam)
+ {
+ return (TypeReflection*)spReflectionGeneric_GetConcreteType((SlangReflectionGeneric*)this, (SlangReflectionVariable*)typeParam);
+ }
+
+ int64_t getConcreteIntVal(VariableReflection* valueParam)
+ {
+ return spReflectionGeneric_GetConcreteIntVal((SlangReflectionGeneric*)this, (SlangReflectionVariable*)valueParam);
+ }
+
};
struct EntryPointReflection
@@ -3672,6 +3785,22 @@ namespace slang
name);
}
+ FunctionReflection* findFunctionByNameInType(TypeReflection* type, const char* name)
+ {
+ return (FunctionReflection*)spReflection_FindFunctionByNameInType(
+ (SlangReflection*) this,
+ (SlangReflectionType*) type,
+ name);
+ }
+
+ VariableReflection* findVarByNameInType(TypeReflection* type, const char* name)
+ {
+ return (VariableReflection*)spReflection_FindVarByNameInType(
+ (SlangReflection*) this,
+ (SlangReflectionType*) type,
+ name);
+ }
+
TypeLayoutReflection* getTypeLayout(
TypeReflection* type,
LayoutRules rules = LayoutRules::Default)
@@ -3749,9 +3878,9 @@ namespace slang
return (DeclReflection*)spReflectionDecl_getChild((SlangReflectionDecl*)this, index);
}
- TypeReflection* getType(SlangSession* session)
+ TypeReflection* getType()
{
- return (TypeReflection*)spReflection_getTypeFromDecl(session, (SlangReflectionDecl*)this);
+ return (TypeReflection*)spReflection_getTypeFromDecl((SlangReflectionDecl*)this);
}
VariableReflection* asVariable()
@@ -3764,6 +3893,16 @@ namespace slang
return (FunctionReflection*)spReflectionDecl_castToFunction((SlangReflectionDecl*)this);
}
+ GenericReflection* asGeneric()
+ {
+ return (GenericReflection*)spReflectionDecl_castToGeneric((SlangReflectionDecl*)this);
+ }
+
+ DeclReflection* getParent()
+ {
+ return (DeclReflection*)spReflectionDecl_getParent((SlangReflectionDecl*)this);
+ }
+
template <Kind K>
struct FilteredList
{