summaryrefslogtreecommitdiff
path: root/source/slang/slang-check-decl.cpp
diff options
context:
space:
mode:
authorAlexandre Bléron <alex.bleron@gmail.com>2025-02-26 22:43:57 +0100
committerGitHub <noreply@github.com>2025-02-26 13:43:57 -0800
commit86669cbb781840f8de180b1f793275f4511d3b65 (patch)
treec28f261a15e3ea69f8a0ab533d484140fa780ec2 /source/slang/slang-check-decl.cpp
parent519e866ff44ec728f95c191fff8a200b66a5377e (diff)
expose value of constant integers in module reflection (#6367)
* Expose value of constant integers in module reflection This commit adds `VariableReflection::getDefaultValueInt` to get the value of a variable if it is a compile-time constant integer. TODO: currently it works only if the initializer expression is an integer literal, references to other constant values are not handled. * Update VarDecl folded constant value during DeclBodyVisitor Constant folding for integer values is already done internally by _validateCircularVarDefinition, this just reuses the result. * Address review comments & formatting * Formatting --------- Co-authored-by: Yong He <yonghe@outlook.com>
Diffstat (limited to 'source/slang/slang-check-decl.cpp')
-rw-r--r--source/slang/slang-check-decl.cpp17
1 files changed, 13 insertions, 4 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
{