@@ -185,7 +185,7 @@ namespace nzsl::Ast
185
185
186
186
struct UsedExternalData
187
187
{
188
- bool isConditional ;
188
+ unsigned int conditionalStatementIndex ;
189
189
};
190
190
191
191
static constexpr std::size_t ModuleIdSentinel = std::numeric_limits<std::size_t >::max();
@@ -212,8 +212,9 @@ namespace nzsl::Ast
212
212
Options options;
213
213
FunctionData* currentFunction = nullptr ;
214
214
bool allowUnknownIdentifiers = false ;
215
- bool inConditionalStatement = false ;
216
215
bool inLoop = false ;
216
+ unsigned int conditionalStatementIndex = 0 ;
217
+ unsigned int nextConditionalIndex = 1 ;
217
218
};
218
219
219
220
ModulePtr SanitizeVisitor::Sanitize (const Module& module , const Options& options, std::string* error)
@@ -447,7 +448,7 @@ namespace nzsl::Ast
447
448
448
449
if (!fieldPtr)
449
450
{
450
- if (s->isConditional )
451
+ if (s->conditionIndex != m_context-> conditionalStatementIndex )
451
452
return Cloner::Clone (node); // < unresolved
452
453
453
454
throw CompilerUnknownFieldError{ indexedExpr->sourceLocation , identifierEntry.identifier };
@@ -1354,9 +1355,9 @@ namespace nzsl::Ast
1354
1355
1355
1356
if (!conditionValue.has_value ())
1356
1357
{
1357
- bool wasInConditionalStatement = m_context->inConditionalStatement ;
1358
- m_context->inConditionalStatement = true ;
1359
- Nz::CallOnExit restoreCond ([=] { m_context->inConditionalStatement = wasInConditionalStatement ; });
1358
+ unsigned int prevCondStatementIndex = m_context->conditionalStatementIndex ;
1359
+ m_context->conditionalStatementIndex = m_context-> nextConditionalIndex ++ ;
1360
+ Nz::CallOnExit restoreCond ([=] { m_context->conditionalStatementIndex = prevCondStatementIndex ; });
1360
1361
1361
1362
// Unresolvable condition
1362
1363
auto condStatement = ShaderBuilder::ConditionalStatement (std::move (cloneCondition), Cloner::Clone (*node.statement ));
@@ -1447,7 +1448,7 @@ namespace nzsl::Ast
1447
1448
std::uint64_t bindingKey = BuildBindingKey (bindingSet, bindingIndex + i);
1448
1449
if (auto it = m_context->usedBindingIndexes .find (bindingKey); it != m_context->usedBindingIndexes .end ())
1449
1450
{
1450
- if (! it->second .isConditional || ! usedBindingData.isConditional )
1451
+ if (it->second .conditionalStatementIndex == m_context-> conditionalStatementIndex || usedBindingData.conditionalStatementIndex == m_context-> conditionalStatementIndex )
1451
1452
throw CompilerExtBindingAlreadyUsedError{ sourceLoc, bindingSet, bindingIndex };
1452
1453
}
1453
1454
@@ -1462,11 +1463,11 @@ namespace nzsl::Ast
1462
1463
auto & extVar = clone->externalVars [i];
1463
1464
1464
1465
Context::UsedExternalData usedBindingData;
1465
- usedBindingData.isConditional = m_context->inConditionalStatement ;
1466
+ usedBindingData.conditionalStatementIndex = m_context->conditionalStatementIndex ;
1466
1467
1467
1468
if (auto it = m_context->declaredExternalVar .find (extVar.name ); it != m_context->declaredExternalVar .end ())
1468
1469
{
1469
- if (! it->second .isConditional || ! usedBindingData.isConditional )
1470
+ if (it->second .conditionalStatementIndex == m_context-> conditionalStatementIndex || usedBindingData.conditionalStatementIndex == m_context-> conditionalStatementIndex )
1470
1471
throw CompilerExtAlreadyDeclaredError{ extVar.sourceLocation , extVar.name };
1471
1472
}
1472
1473
@@ -1586,7 +1587,7 @@ namespace nzsl::Ast
1586
1587
bindingIndex++;
1587
1588
1588
1589
Context::UsedExternalData usedBindingData;
1589
- usedBindingData.isConditional = m_context->inConditionalStatement ;
1590
+ usedBindingData.conditionalStatementIndex = m_context->conditionalStatementIndex ;
1590
1591
1591
1592
extVar.bindingIndex = bindingIndex;
1592
1593
RegisterBinding (arraySize, bindingSet, bindingIndex, usedBindingData, extVar.sourceLocation );
@@ -1912,7 +1913,7 @@ namespace nzsl::Ast
1912
1913
}
1913
1914
}
1914
1915
1915
- clone->description .isConditional = m_context->inConditionalStatement ;
1916
+ clone->description .conditionIndex = m_context->conditionalStatementIndex ;
1916
1917
1917
1918
clone->structIndex = RegisterStruct (clone->description .name , &clone->description , clone->structIndex , clone->sourceLocation );
1918
1919
SanitizeIdentifier (clone->description .name , IdentifierScope::Struct);
@@ -3547,7 +3548,7 @@ namespace nzsl::Ast
3547
3548
bool unresolved = false ;
3548
3549
if (const IdentifierData* identifierData = FindIdentifier (name))
3549
3550
{
3550
- if (!m_context-> inConditionalStatement || !identifierData-> isConditional )
3551
+ if (identifierData-> conditionalIndex == m_context-> conditionalStatementIndex )
3551
3552
throw CompilerIdentifierAlreadyUsedError{ sourceLocation, name };
3552
3553
else
3553
3554
unresolved = true ;
@@ -3571,7 +3572,7 @@ namespace nzsl::Ast
3571
3572
{
3572
3573
aliasIndex,
3573
3574
IdentifierCategory::Alias,
3574
- m_context->inConditionalStatement
3575
+ m_context->conditionalStatementIndex
3575
3576
}
3576
3577
});
3577
3578
}
@@ -3602,7 +3603,7 @@ namespace nzsl::Ast
3602
3603
{
3603
3604
constantIndex,
3604
3605
IdentifierCategory::Constant,
3605
- m_context->inConditionalStatement
3606
+ m_context->conditionalStatementIndex
3606
3607
}
3607
3608
});
3608
3609
@@ -3654,7 +3655,7 @@ namespace nzsl::Ast
3654
3655
{
3655
3656
functionIndex,
3656
3657
IdentifierCategory::Function,
3657
- m_context->inConditionalStatement
3658
+ m_context->conditionalStatementIndex
3658
3659
}
3659
3660
});
3660
3661
@@ -3673,7 +3674,7 @@ namespace nzsl::Ast
3673
3674
{
3674
3675
intrinsicIndex,
3675
3676
IdentifierCategory::Intrinsic,
3676
- m_context->inConditionalStatement
3677
+ m_context->conditionalStatementIndex
3677
3678
}
3678
3679
});
3679
3680
@@ -3692,7 +3693,7 @@ namespace nzsl::Ast
3692
3693
{
3693
3694
moduleIndex,
3694
3695
IdentifierCategory::Module,
3695
- m_context->inConditionalStatement
3696
+ m_context->conditionalStatementIndex
3696
3697
}
3697
3698
});
3698
3699
@@ -3706,7 +3707,7 @@ namespace nzsl::Ast
3706
3707
{
3707
3708
std::numeric_limits<std::size_t >::max (),
3708
3709
IdentifierCategory::ReservedName,
3709
- m_context->inConditionalStatement
3710
+ m_context->conditionalStatementIndex
3710
3711
}
3711
3712
});
3712
3713
}
@@ -3716,7 +3717,7 @@ namespace nzsl::Ast
3716
3717
bool unresolved = false ;
3717
3718
if (const IdentifierData* identifierData = FindIdentifier (name))
3718
3719
{
3719
- if (!m_context-> inConditionalStatement || !identifierData-> isConditional )
3720
+ if (identifierData-> conditionalIndex == m_context-> conditionalStatementIndex )
3720
3721
throw CompilerIdentifierAlreadyUsedError{ sourceLocation, name };
3721
3722
else
3722
3723
unresolved = true ;
@@ -3740,7 +3741,7 @@ namespace nzsl::Ast
3740
3741
{
3741
3742
structIndex,
3742
3743
IdentifierCategory::Struct,
3743
- m_context->inConditionalStatement
3744
+ m_context->conditionalStatementIndex
3744
3745
}
3745
3746
});
3746
3747
}
@@ -3771,7 +3772,7 @@ namespace nzsl::Ast
3771
3772
{
3772
3773
typeIndex,
3773
3774
IdentifierCategory::Type,
3774
- m_context->inConditionalStatement
3775
+ m_context->conditionalStatementIndex
3775
3776
}
3776
3777
});
3777
3778
@@ -3805,7 +3806,7 @@ namespace nzsl::Ast
3805
3806
{
3806
3807
typeIndex,
3807
3808
IdentifierCategory::Type,
3808
- m_context->inConditionalStatement
3809
+ m_context->conditionalStatementIndex
3809
3810
}
3810
3811
});
3811
3812
@@ -3819,7 +3820,7 @@ namespace nzsl::Ast
3819
3820
{
3820
3821
std::numeric_limits<std::size_t >::max (),
3821
3822
IdentifierCategory::Unresolved,
3822
- m_context->inConditionalStatement
3823
+ m_context->conditionalStatementIndex
3823
3824
}
3824
3825
});
3825
3826
}
@@ -3832,7 +3833,8 @@ namespace nzsl::Ast
3832
3833
// Allow variable shadowing
3833
3834
if (identifier->category != IdentifierCategory::Variable)
3834
3835
throw CompilerIdentifierAlreadyUsedError{ sourceLocation, name };
3835
- else if (identifier->isConditional && m_context->inConditionalStatement )
3836
+
3837
+ if (identifier->conditionalIndex != m_context->conditionalStatementIndex )
3836
3838
unresolved = true ; // < right variable isn't know from this point
3837
3839
}
3838
3840
@@ -3854,7 +3856,7 @@ namespace nzsl::Ast
3854
3856
{
3855
3857
varIndex,
3856
3858
IdentifierCategory::Variable,
3857
- m_context->inConditionalStatement
3859
+ m_context->conditionalStatementIndex
3858
3860
}
3859
3861
});
3860
3862
}
0 commit comments