@@ -213,7 +213,7 @@ namespace nzsl::Ast
213
213
FunctionData* currentFunction = nullptr ;
214
214
bool allowUnknownIdentifiers = false ;
215
215
bool inLoop = false ;
216
- unsigned int conditionalStatementIndex = 0 ;
216
+ unsigned int currentConditionalIndex = 0 ;
217
217
unsigned int nextConditionalIndex = 1 ;
218
218
};
219
219
@@ -324,7 +324,12 @@ namespace nzsl::Ast
324
324
const auto & env = *m_context->modules [moduleIndex].environment ;
325
325
identifierData = FindIdentifier (env, node.identifiers .front ().identifier );
326
326
if (identifierData)
327
+ {
328
+ if (m_context->options .partialSanitization && identifierData->conditionalIndex != m_context->currentConditionalIndex )
329
+ return Cloner::Clone (node);
330
+
327
331
return HandleIdentifier (identifierData, node.identifiers .front ().sourceLocation );
332
+ }
328
333
}
329
334
}
330
335
@@ -448,7 +453,7 @@ namespace nzsl::Ast
448
453
449
454
if (!fieldPtr)
450
455
{
451
- if (s->conditionIndex != m_context->conditionalStatementIndex )
456
+ if (s->conditionIndex != m_context->currentConditionalIndex )
452
457
return Cloner::Clone (node); // < unresolved
453
458
454
459
throw CompilerUnknownFieldError{ indexedExpr->sourceLocation , identifierEntry.identifier };
@@ -1151,6 +1156,9 @@ namespace nzsl::Ast
1151
1156
if (identifierData->category == IdentifierCategory::Unresolved)
1152
1157
return Cloner::Clone (node);
1153
1158
1159
+ if (m_context->options .partialSanitization && identifierData->conditionalIndex != m_context->currentConditionalIndex )
1160
+ return Cloner::Clone (node);
1161
+
1154
1162
return HandleIdentifier (identifierData, node.sourceLocation );
1155
1163
}
1156
1164
@@ -1355,9 +1363,9 @@ namespace nzsl::Ast
1355
1363
1356
1364
if (!conditionValue.has_value ())
1357
1365
{
1358
- unsigned int prevCondStatementIndex = m_context->conditionalStatementIndex ;
1359
- m_context->conditionalStatementIndex = m_context->nextConditionalIndex ++;
1360
- Nz::CallOnExit restoreCond ([=] { m_context->conditionalStatementIndex = prevCondStatementIndex; });
1366
+ unsigned int prevCondStatementIndex = m_context->currentConditionalIndex ;
1367
+ m_context->currentConditionalIndex = m_context->nextConditionalIndex ++;
1368
+ Nz::CallOnExit restoreCond ([=] { m_context->currentConditionalIndex = prevCondStatementIndex; });
1361
1369
1362
1370
// Unresolvable condition
1363
1371
auto condStatement = ShaderBuilder::ConditionalStatement (std::move (cloneCondition), Cloner::Clone (*node.statement ));
@@ -1448,7 +1456,7 @@ namespace nzsl::Ast
1448
1456
std::uint64_t bindingKey = BuildBindingKey (bindingSet, bindingIndex + i);
1449
1457
if (auto it = m_context->usedBindingIndexes .find (bindingKey); it != m_context->usedBindingIndexes .end ())
1450
1458
{
1451
- if (it->second .conditionalStatementIndex == m_context->conditionalStatementIndex || usedBindingData.conditionalStatementIndex == m_context->conditionalStatementIndex )
1459
+ if (it->second .conditionalStatementIndex == m_context->currentConditionalIndex || usedBindingData.conditionalStatementIndex == m_context->currentConditionalIndex )
1452
1460
throw CompilerExtBindingAlreadyUsedError{ sourceLoc, bindingSet, bindingIndex };
1453
1461
}
1454
1462
@@ -1463,11 +1471,11 @@ namespace nzsl::Ast
1463
1471
auto & extVar = clone->externalVars [i];
1464
1472
1465
1473
Context::UsedExternalData usedBindingData;
1466
- usedBindingData.conditionalStatementIndex = m_context->conditionalStatementIndex ;
1474
+ usedBindingData.conditionalStatementIndex = m_context->currentConditionalIndex ;
1467
1475
1468
1476
if (auto it = m_context->declaredExternalVar .find (extVar.name ); it != m_context->declaredExternalVar .end ())
1469
1477
{
1470
- if (it->second .conditionalStatementIndex == m_context->conditionalStatementIndex || usedBindingData.conditionalStatementIndex == m_context->conditionalStatementIndex )
1478
+ if (it->second .conditionalStatementIndex == m_context->currentConditionalIndex || usedBindingData.conditionalStatementIndex == m_context->currentConditionalIndex )
1471
1479
throw CompilerExtAlreadyDeclaredError{ extVar.sourceLocation , extVar.name };
1472
1480
}
1473
1481
@@ -1587,7 +1595,7 @@ namespace nzsl::Ast
1587
1595
bindingIndex++;
1588
1596
1589
1597
Context::UsedExternalData usedBindingData;
1590
- usedBindingData.conditionalStatementIndex = m_context->conditionalStatementIndex ;
1598
+ usedBindingData.conditionalStatementIndex = m_context->currentConditionalIndex ;
1591
1599
1592
1600
extVar.bindingIndex = bindingIndex;
1593
1601
RegisterBinding (arraySize, bindingSet, bindingIndex, usedBindingData, extVar.sourceLocation );
@@ -1913,7 +1921,7 @@ namespace nzsl::Ast
1913
1921
}
1914
1922
}
1915
1923
1916
- clone->description .conditionIndex = m_context->conditionalStatementIndex ;
1924
+ clone->description .conditionIndex = m_context->currentConditionalIndex ;
1917
1925
1918
1926
clone->structIndex = RegisterStruct (clone->description .name , &clone->description , clone->structIndex , clone->sourceLocation );
1919
1927
SanitizeIdentifier (clone->description .name , IdentifierScope::Struct);
@@ -3548,7 +3556,7 @@ namespace nzsl::Ast
3548
3556
bool unresolved = false ;
3549
3557
if (const IdentifierData* identifierData = FindIdentifier (name))
3550
3558
{
3551
- if (identifierData->conditionalIndex == m_context->conditionalStatementIndex )
3559
+ if (identifierData->conditionalIndex == m_context->currentConditionalIndex )
3552
3560
throw CompilerIdentifierAlreadyUsedError{ sourceLocation, name };
3553
3561
else
3554
3562
unresolved = true ;
@@ -3572,7 +3580,7 @@ namespace nzsl::Ast
3572
3580
{
3573
3581
aliasIndex,
3574
3582
IdentifierCategory::Alias,
3575
- m_context->conditionalStatementIndex
3583
+ m_context->currentConditionalIndex
3576
3584
}
3577
3585
});
3578
3586
}
@@ -3603,7 +3611,7 @@ namespace nzsl::Ast
3603
3611
{
3604
3612
constantIndex,
3605
3613
IdentifierCategory::Constant,
3606
- m_context->conditionalStatementIndex
3614
+ m_context->currentConditionalIndex
3607
3615
}
3608
3616
});
3609
3617
@@ -3655,7 +3663,7 @@ namespace nzsl::Ast
3655
3663
{
3656
3664
functionIndex,
3657
3665
IdentifierCategory::Function,
3658
- m_context->conditionalStatementIndex
3666
+ m_context->currentConditionalIndex
3659
3667
}
3660
3668
});
3661
3669
@@ -3674,7 +3682,7 @@ namespace nzsl::Ast
3674
3682
{
3675
3683
intrinsicIndex,
3676
3684
IdentifierCategory::Intrinsic,
3677
- m_context->conditionalStatementIndex
3685
+ m_context->currentConditionalIndex
3678
3686
}
3679
3687
});
3680
3688
@@ -3693,7 +3701,7 @@ namespace nzsl::Ast
3693
3701
{
3694
3702
moduleIndex,
3695
3703
IdentifierCategory::Module,
3696
- m_context->conditionalStatementIndex
3704
+ m_context->currentConditionalIndex
3697
3705
}
3698
3706
});
3699
3707
@@ -3707,7 +3715,7 @@ namespace nzsl::Ast
3707
3715
{
3708
3716
std::numeric_limits<std::size_t >::max (),
3709
3717
IdentifierCategory::ReservedName,
3710
- m_context->conditionalStatementIndex
3718
+ m_context->currentConditionalIndex
3711
3719
}
3712
3720
});
3713
3721
}
@@ -3717,7 +3725,7 @@ namespace nzsl::Ast
3717
3725
bool unresolved = false ;
3718
3726
if (const IdentifierData* identifierData = FindIdentifier (name))
3719
3727
{
3720
- if (identifierData->conditionalIndex == m_context->conditionalStatementIndex )
3728
+ if (identifierData->conditionalIndex == m_context->currentConditionalIndex )
3721
3729
throw CompilerIdentifierAlreadyUsedError{ sourceLocation, name };
3722
3730
else
3723
3731
unresolved = true ;
@@ -3741,7 +3749,7 @@ namespace nzsl::Ast
3741
3749
{
3742
3750
structIndex,
3743
3751
IdentifierCategory::Struct,
3744
- m_context->conditionalStatementIndex
3752
+ m_context->currentConditionalIndex
3745
3753
}
3746
3754
});
3747
3755
}
@@ -3772,7 +3780,7 @@ namespace nzsl::Ast
3772
3780
{
3773
3781
typeIndex,
3774
3782
IdentifierCategory::Type,
3775
- m_context->conditionalStatementIndex
3783
+ m_context->currentConditionalIndex
3776
3784
}
3777
3785
});
3778
3786
@@ -3806,7 +3814,7 @@ namespace nzsl::Ast
3806
3814
{
3807
3815
typeIndex,
3808
3816
IdentifierCategory::Type,
3809
- m_context->conditionalStatementIndex
3817
+ m_context->currentConditionalIndex
3810
3818
}
3811
3819
});
3812
3820
@@ -3820,7 +3828,7 @@ namespace nzsl::Ast
3820
3828
{
3821
3829
std::numeric_limits<std::size_t >::max (),
3822
3830
IdentifierCategory::Unresolved,
3823
- m_context->conditionalStatementIndex
3831
+ m_context->currentConditionalIndex
3824
3832
}
3825
3833
});
3826
3834
}
@@ -3834,7 +3842,7 @@ namespace nzsl::Ast
3834
3842
if (identifier->category != IdentifierCategory::Variable)
3835
3843
throw CompilerIdentifierAlreadyUsedError{ sourceLocation, name };
3836
3844
3837
- if (identifier->conditionalIndex != m_context->conditionalStatementIndex )
3845
+ if (identifier->conditionalIndex != m_context->currentConditionalIndex )
3838
3846
unresolved = true ; // < right variable isn't know from this point
3839
3847
}
3840
3848
@@ -3856,7 +3864,7 @@ namespace nzsl::Ast
3856
3864
{
3857
3865
varIndex,
3858
3866
IdentifierCategory::Variable,
3859
- m_context->conditionalStatementIndex
3867
+ m_context->currentConditionalIndex
3860
3868
}
3861
3869
});
3862
3870
}
@@ -4104,7 +4112,10 @@ namespace nzsl::Ast
4104
4112
4105
4113
const ExpressionType* exprType = GetExpressionType (*node.expression );
4106
4114
if (!exprType)
4115
+ {
4116
+ RegisterUnresolved (node.name );
4107
4117
return ValidationResult::Unresolved;
4118
+ }
4108
4119
4109
4120
const ExpressionType& resolvedType = ResolveAlias (*exprType);
4110
4121
0 commit comments