diff options
Diffstat (limited to 'source')
| -rw-r--r-- | source/slang/slang-check-decl.cpp | 17 | ||||
| -rw-r--r-- | source/slang/slang-check-impl.h | 2 | ||||
| -rw-r--r-- | source/slang/slang-reflection-api.cpp | 16 |
3 files changed, 30 insertions, 5 deletions
diff --git a/source/slang/slang-check-decl.cpp b/source/slang/slang-check-decl.cpp index 0c42817c8..1659a161b 100644 --- a/source/slang/slang-check-decl.cpp +++ b/source/slang/slang-check-decl.cpp @@ -1430,7 +1430,7 @@ bool SemanticsVisitor::shouldSkipChecking(Decl* decl, DeclCheckState state) return false; } -void SemanticsVisitor::_validateCircularVarDefinition(VarDeclBase* varDecl) +IntVal* SemanticsVisitor::_validateCircularVarDefinition(VarDeclBase* varDecl) { // The easiest way to test if the declaration is circular is to // validate it as a constant. @@ -1444,8 +1444,11 @@ void SemanticsVisitor::_validateCircularVarDefinition(VarDeclBase* varDecl) // // if (!isScalarIntegerType(varDecl->type)) - return; - tryConstantFoldDeclRef(DeclRef<VarDeclBase>(varDecl), ConstantFoldingKind::LinkTime, nullptr); + return nullptr; + return tryConstantFoldDeclRef( + DeclRef<VarDeclBase>(varDecl), + ConstantFoldingKind::LinkTime, + nullptr); } void SemanticsDeclModifiersVisitor::visitStructDecl(StructDecl* structDecl) @@ -2350,7 +2353,13 @@ void SemanticsDeclBodyVisitor::checkVarDeclCommon(VarDeclBase* varDecl) // a constant with a circular definition. // varDecl->setCheckState(DeclCheckState::DefinitionChecked); - _validateCircularVarDefinition(varDecl); + + // Update constant value + // + if (!varDecl->val) + { + varDecl->val = _validateCircularVarDefinition(varDecl); + } } else { diff --git a/source/slang/slang-check-impl.h b/source/slang/slang-check-impl.h index edb199299..ba3792af7 100644 --- a/source/slang/slang-check-impl.h +++ b/source/slang/slang-check-impl.h @@ -1496,7 +1496,7 @@ public: /// by calling a function that indirectly reads the variable) will be allowed and then /// exhibit undefined behavior at runtime. /// - void _validateCircularVarDefinition(VarDeclBase* varDecl); + IntVal* _validateCircularVarDefinition(VarDeclBase* varDecl); bool shouldSkipChecking(Decl* decl, DeclCheckState state); diff --git a/source/slang/slang-reflection-api.cpp b/source/slang/slang-reflection-api.cpp index 52047a751..9295bfdf6 100644 --- a/source/slang/slang-reflection-api.cpp +++ b/source/slang/slang-reflection-api.cpp @@ -3164,6 +3164,22 @@ SLANG_API bool spReflectionVariable_HasDefaultValue(SlangReflectionVariable* inV return false; } +SLANG_API SlangResult +spReflectionVariable_GetDefaultValueInt(SlangReflectionVariable* inVar, int64_t* rs) +{ + auto decl = convert(inVar).getDecl(); + if (auto varDecl = as<VarDeclBase>(decl)) + { + if (auto constantVal = as<ConstantIntVal>(varDecl->val)) + { + *rs = constantVal->getValue(); + return 0; + } + } + + return SLANG_E_INVALID_ARG; +} + SLANG_API SlangReflectionGeneric* spReflectionVariable_GetGenericContainer( SlangReflectionVariable* var) { |
