@@ -320,10 +320,15 @@ RootSignatureParser::parseDescriptorTableClause() {
320
320
}
321
321
Clause.setDefaultFlags (Version);
322
322
323
- auto Params = parseDescriptorTableClauseParams (ExpectedReg);
323
+ auto Params = parseDescriptorTableClauseParams (ParamKind, ExpectedReg);
324
324
if (!Params.has_value ())
325
325
return std::nullopt;
326
326
327
+ if (consumeExpectedToken (TokenKind::pu_r_paren,
328
+ diag::err_hlsl_unexpected_end_of_params,
329
+ /* param of=*/ ParamKind))
330
+ return std::nullopt;
331
+
327
332
// Check mandatory parameters were provided
328
333
if (!Params->Reg .has_value ()) {
329
334
reportDiag (diag::err_hlsl_rootsig_missing_param) << ExpectedReg;
@@ -345,11 +350,6 @@ RootSignatureParser::parseDescriptorTableClause() {
345
350
if (Params->Flags .has_value ())
346
351
Clause.Flags = Params->Flags .value ();
347
352
348
- if (consumeExpectedToken (TokenKind::pu_r_paren,
349
- diag::err_hlsl_unexpected_end_of_params,
350
- /* param of=*/ ParamKind))
351
- return std::nullopt;
352
-
353
353
return Clause;
354
354
}
355
355
@@ -563,14 +563,15 @@ RootSignatureParser::parseRootDescriptorParams(TokenKind DescType,
563
563
}
564
564
565
565
std::optional<RootSignatureParser::ParsedClauseParams>
566
- RootSignatureParser::parseDescriptorTableClauseParams (TokenKind RegType) {
566
+ RootSignatureParser::parseDescriptorTableClauseParams (TokenKind DescType,
567
+ TokenKind RegType) {
567
568
assert (CurToken.TokKind == TokenKind::pu_l_paren &&
568
569
" Expects to only be invoked starting at given token" );
569
570
570
571
ParsedClauseParams Params;
571
- do {
572
- // ( `b` | `t` | `u` | `s`) POS_INT
572
+ while (!peekExpectedToken (TokenKind::pu_r_paren)) {
573
573
if (tryConsumeExpectedToken (RegType)) {
574
+ // ( `b` | `t` | `u` | `s`) POS_INT
574
575
if (Params.Reg .has_value ()) {
575
576
reportDiag (diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind ;
576
577
return std::nullopt;
@@ -579,10 +580,8 @@ RootSignatureParser::parseDescriptorTableClauseParams(TokenKind RegType) {
579
580
if (!Reg.has_value ())
580
581
return std::nullopt;
581
582
Params.Reg = Reg;
582
- }
583
-
584
- // `numDescriptors` `=` POS_INT | unbounded
585
- if (tryConsumeExpectedToken (TokenKind::kw_numDescriptors)) {
583
+ } else if (tryConsumeExpectedToken (TokenKind::kw_numDescriptors)) {
584
+ // `numDescriptors` `=` POS_INT | unbounded
586
585
if (Params.NumDescriptors .has_value ()) {
587
586
reportDiag (diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind ;
588
587
return std::nullopt;
@@ -601,10 +600,8 @@ RootSignatureParser::parseDescriptorTableClauseParams(TokenKind RegType) {
601
600
}
602
601
603
602
Params.NumDescriptors = NumDescriptors;
604
- }
605
-
606
- // `space` `=` POS_INT
607
- if (tryConsumeExpectedToken (TokenKind::kw_space)) {
603
+ } else if (tryConsumeExpectedToken (TokenKind::kw_space)) {
604
+ // `space` `=` POS_INT
608
605
if (Params.Space .has_value ()) {
609
606
reportDiag (diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind ;
610
607
return std::nullopt;
@@ -617,10 +614,8 @@ RootSignatureParser::parseDescriptorTableClauseParams(TokenKind RegType) {
617
614
if (!Space.has_value ())
618
615
return std::nullopt;
619
616
Params.Space = Space;
620
- }
621
-
622
- // `offset` `=` POS_INT | DESCRIPTOR_RANGE_OFFSET_APPEND
623
- if (tryConsumeExpectedToken (TokenKind::kw_offset)) {
617
+ } else if (tryConsumeExpectedToken (TokenKind::kw_offset)) {
618
+ // `offset` `=` POS_INT | DESCRIPTOR_RANGE_OFFSET_APPEND
624
619
if (Params.Offset .has_value ()) {
625
620
reportDiag (diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind ;
626
621
return std::nullopt;
@@ -639,10 +634,8 @@ RootSignatureParser::parseDescriptorTableClauseParams(TokenKind RegType) {
639
634
}
640
635
641
636
Params.Offset = Offset;
642
- }
643
-
644
- // `flags` `=` DESCRIPTOR_RANGE_FLAGS
645
- if (tryConsumeExpectedToken (TokenKind::kw_flags)) {
637
+ } else if (tryConsumeExpectedToken (TokenKind::kw_flags)) {
638
+ // `flags` `=` DESCRIPTOR_RANGE_FLAGS
646
639
if (Params.Flags .has_value ()) {
647
640
reportDiag (diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind ;
648
641
return std::nullopt;
@@ -657,7 +650,10 @@ RootSignatureParser::parseDescriptorTableClauseParams(TokenKind RegType) {
657
650
Params.Flags = Flags;
658
651
}
659
652
660
- } while (tryConsumeExpectedToken (TokenKind::pu_comma));
653
+ // ',' denotes another element, otherwise, expected to be at ')'
654
+ if (!tryConsumeExpectedToken (TokenKind::pu_comma))
655
+ break ;
656
+ }
661
657
662
658
return Params;
663
659
}
0 commit comments