@@ -199,10 +199,15 @@ std::optional<RootDescriptor> RootSignatureParser::parseRootDescriptor() {
199
199
}
200
200
Descriptor.setDefaultFlags (Version);
201
201
202
- auto Params = parseRootDescriptorParams (ExpectedReg);
202
+ auto Params = parseRootDescriptorParams (DescriptorKind, ExpectedReg);
203
203
if (!Params.has_value ())
204
204
return std::nullopt;
205
205
206
+ if (consumeExpectedToken (TokenKind::pu_r_paren,
207
+ diag::err_hlsl_unexpected_end_of_params,
208
+ /* param of=*/ DescriptorKind))
209
+ return std::nullopt;
210
+
206
211
// Check mandatory parameters were provided
207
212
if (!Params->Reg .has_value ()) {
208
213
reportDiag (diag::err_hlsl_rootsig_missing_param) << ExpectedReg;
@@ -221,11 +226,6 @@ std::optional<RootDescriptor> RootSignatureParser::parseRootDescriptor() {
221
226
if (Params->Flags .has_value ())
222
227
Descriptor.Flags = Params->Flags .value ();
223
228
224
- if (consumeExpectedToken (TokenKind::pu_r_paren,
225
- diag::err_hlsl_unexpected_end_of_params,
226
- /* param of=*/ TokenKind::kw_RootConstants))
227
- return std::nullopt;
228
-
229
229
return Descriptor;
230
230
}
231
231
@@ -493,14 +493,15 @@ RootSignatureParser::parseRootConstantParams() {
493
493
}
494
494
495
495
std::optional<RootSignatureParser::ParsedRootDescriptorParams>
496
- RootSignatureParser::parseRootDescriptorParams (TokenKind RegType) {
496
+ RootSignatureParser::parseRootDescriptorParams (TokenKind DescType,
497
+ TokenKind RegType) {
497
498
assert (CurToken.TokKind == TokenKind::pu_l_paren &&
498
499
" Expects to only be invoked starting at given token" );
499
500
500
501
ParsedRootDescriptorParams Params;
501
- do {
502
- // ( `b` | `t` | `u`) POS_INT
502
+ while (!peekExpectedToken (TokenKind::pu_r_paren)) {
503
503
if (tryConsumeExpectedToken (RegType)) {
504
+ // ( `b` | `t` | `u`) POS_INT
504
505
if (Params.Reg .has_value ()) {
505
506
reportDiag (diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind ;
506
507
return std::nullopt;
@@ -509,10 +510,8 @@ RootSignatureParser::parseRootDescriptorParams(TokenKind RegType) {
509
510
if (!Reg.has_value ())
510
511
return std::nullopt;
511
512
Params.Reg = Reg;
512
- }
513
-
514
- // `space` `=` POS_INT
515
- if (tryConsumeExpectedToken (TokenKind::kw_space)) {
513
+ } else if (tryConsumeExpectedToken (TokenKind::kw_space)) {
514
+ // `space` `=` POS_INT
516
515
if (Params.Space .has_value ()) {
517
516
reportDiag (diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind ;
518
517
return std::nullopt;
@@ -525,10 +524,8 @@ RootSignatureParser::parseRootDescriptorParams(TokenKind RegType) {
525
524
if (!Space.has_value ())
526
525
return std::nullopt;
527
526
Params.Space = Space;
528
- }
529
-
530
- // `visibility` `=` SHADER_VISIBILITY
531
- if (tryConsumeExpectedToken (TokenKind::kw_visibility)) {
527
+ } else if (tryConsumeExpectedToken (TokenKind::kw_visibility)) {
528
+ // `visibility` `=` SHADER_VISIBILITY
532
529
if (Params.Visibility .has_value ()) {
533
530
reportDiag (diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind ;
534
531
return std::nullopt;
@@ -541,10 +538,8 @@ RootSignatureParser::parseRootDescriptorParams(TokenKind RegType) {
541
538
if (!Visibility.has_value ())
542
539
return std::nullopt;
543
540
Params.Visibility = Visibility;
544
- }
545
-
546
- // `flags` `=` ROOT_DESCRIPTOR_FLAGS
547
- if (tryConsumeExpectedToken (TokenKind::kw_flags)) {
541
+ } else if (tryConsumeExpectedToken (TokenKind::kw_flags)) {
542
+ // `flags` `=` ROOT_DESCRIPTOR_FLAGS
548
543
if (Params.Flags .has_value ()) {
549
544
reportDiag (diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind ;
550
545
return std::nullopt;
@@ -558,7 +553,11 @@ RootSignatureParser::parseRootDescriptorParams(TokenKind RegType) {
558
553
return std::nullopt;
559
554
Params.Flags = Flags;
560
555
}
561
- } while (tryConsumeExpectedToken (TokenKind::pu_comma));
556
+
557
+ // ',' denotes another element, otherwise, expected to be at ')'
558
+ if (!tryConsumeExpectedToken (TokenKind::pu_comma))
559
+ break ;
560
+ }
562
561
563
562
return Params;
564
563
}
0 commit comments