@@ -18,6 +18,9 @@ static std::string FormatTokenKinds(ArrayRef<TokenKind> Kinds) {
18
18
Out << " , " ;
19
19
switch (Kind) {
20
20
case TokenKind::invalid:
21
+ Out << " uninitialized" ;
22
+ break ;
23
+ case TokenKind::end_of_stream:
21
24
break ;
22
25
case TokenKind::int_literal:
23
26
Out << " integer literal" ;
@@ -215,42 +218,33 @@ std::optional<RootSignatureToken> RootSignatureLexer::PeekNextToken() {
215
218
216
219
// Parser Definitions
217
220
218
- RootSignatureParser::RootSignatureParser (
219
- SmallVector<RootElement> &Elements,
220
- const SmallVector<RootSignatureToken> &Tokens, DiagnosticsEngine &Diags)
221
- : Elements(Elements), Diags(Diags) {
222
- CurTok = Tokens.begin ();
223
- LastTok = Tokens.end ();
224
- }
221
+ RootSignatureParser::RootSignatureParser (SmallVector<RootElement> &Elements,
222
+ RootSignatureLexer &Lexer,
223
+ DiagnosticsEngine &Diags)
224
+ : Elements(Elements), Lexer(Lexer), Diags(Diags) {}
225
225
226
226
bool RootSignatureParser::Parse () {
227
227
// Handle edge-case of empty RootSignature()
228
- if (CurTok == LastTok )
228
+ if (Lexer. EndOfBuffer () )
229
229
return false ;
230
230
231
- bool First = true ;
232
231
// Iterate as many RootElements as possible
233
- while (!ParseRootElement (First)) {
234
- First = false ;
235
- // Avoid use of ConsumeNextToken here to skip incorrect end of tokens error
236
- CurTok++;
237
- if (CurTok == LastTok)
232
+ while (!ParseRootElement ()) {
233
+ if (Lexer.EndOfBuffer ())
238
234
return false ;
239
- if (EnsureExpectedToken (TokenKind::pu_comma))
235
+ if (ConsumeExpectedToken (TokenKind::pu_comma))
240
236
return true ;
241
237
}
242
238
243
239
return true ;
244
240
}
245
241
246
- bool RootSignatureParser::ParseRootElement (bool First) {
247
- if (First && EnsureExpectedToken (TokenKind::kw_DescriptorTable))
248
- return true ;
249
- if (!First && ConsumeExpectedToken (TokenKind::kw_DescriptorTable))
242
+ bool RootSignatureParser::ParseRootElement () {
243
+ if (ConsumeExpectedToken (TokenKind::kw_DescriptorTable))
250
244
return true ;
251
245
252
246
// Dispatch onto the correct parse method
253
- switch (CurTok-> Kind ) {
247
+ switch (CurToken. Kind ) {
254
248
case TokenKind::kw_DescriptorTable:
255
249
return ParseDescriptorTable ();
256
250
default :
@@ -277,8 +271,8 @@ bool RootSignatureParser::ParseDescriptorTable() {
277
271
// Handle the visibility parameter
278
272
if (!TryConsumeExpectedToken (TokenKind::kw_visibility)) {
279
273
if (SeenVisibility) {
280
- Diags.Report (CurTok-> TokLoc , diag::err_hlsl_rootsig_repeat_param)
281
- << FormatTokenKinds (CurTok-> Kind );
274
+ Diags.Report (CurToken. TokLoc , diag::err_hlsl_rootsig_repeat_param)
275
+ << FormatTokenKinds (CurToken. Kind );
282
276
return true ;
283
277
}
284
278
SeenVisibility = true ;
@@ -306,7 +300,7 @@ bool RootSignatureParser::ParseDescriptorTableClause() {
306
300
return true ;
307
301
308
302
DescriptorTableClause Clause;
309
- switch (CurTok-> Kind ) {
303
+ switch (CurToken. Kind ) {
310
304
case TokenKind::kw_CBV:
311
305
Clause.Type = ClauseType::CBuffer;
312
306
break ;
@@ -391,9 +385,9 @@ bool RootSignatureParser::ParseOptionalParams(
391
385
if (ConsumeExpectedToken (ParamKeywords))
392
386
return true ;
393
387
394
- TokenKind ParamKind = CurTok-> Kind ;
388
+ TokenKind ParamKind = CurToken. Kind ;
395
389
if (Seen.contains (ParamKind)) {
396
- Diags.Report (CurTok-> TokLoc , diag::err_hlsl_rootsig_repeat_param)
390
+ Diags.Report (CurToken. TokLoc , diag::err_hlsl_rootsig_repeat_param)
397
391
<< FormatTokenKinds (ParamKind);
398
392
return true ;
399
393
}
@@ -412,25 +406,25 @@ bool RootSignatureParser::ParseDescriptorRangeOffset(DescriptorRangeOffset *X) {
412
406
return true ;
413
407
414
408
// Edge case for the offset enum -> static value
415
- if (CurTok-> Kind == TokenKind::en_DescriptorRangeOffsetAppend) {
409
+ if (CurToken. Kind == TokenKind::en_DescriptorRangeOffsetAppend) {
416
410
*X = DescriptorTableOffsetAppend;
417
411
return false ;
418
412
}
419
413
420
- *X = DescriptorRangeOffset (CurTok-> NumLiteral .getInt ().getExtValue ());
414
+ *X = DescriptorRangeOffset (CurToken. NumLiteral .getInt ().getExtValue ());
421
415
return false ;
422
416
}
423
417
424
418
bool RootSignatureParser::ParseUInt (uint32_t *X) {
425
419
if (ConsumeExpectedToken (TokenKind::int_literal))
426
420
return true ;
427
421
428
- *X = CurTok-> NumLiteral .getInt ().getExtValue ();
422
+ *X = CurToken. NumLiteral .getInt ().getExtValue ();
429
423
return false ;
430
424
}
431
425
432
426
bool RootSignatureParser::ParseRegister (Register *Register) {
433
- switch (CurTok-> Kind ) {
427
+ switch (CurToken. Kind ) {
434
428
case TokenKind::bReg:
435
429
Register->ViewType = RegisterType::BReg;
436
430
break ;
@@ -447,7 +441,7 @@ bool RootSignatureParser::ParseRegister(Register *Register) {
447
441
llvm_unreachable (" Switch for an expected token was not provided" );
448
442
}
449
443
450
- Register->Number = CurTok-> NumLiteral .getInt ().getExtValue ();
444
+ Register->Number = CurToken. NumLiteral .getInt ().getExtValue ();
451
445
452
446
return false ;
453
447
}
@@ -466,9 +460,9 @@ bool RootSignatureParser::ParseEnum(
466
460
return true ;
467
461
468
462
// Handle the edge case when '0' is used to specify None
469
- if (CurTok-> Kind == TokenKind::int_literal) {
470
- if (CurTok-> NumLiteral .getInt () != 0 ) {
471
- Diags.Report (CurTok-> TokLoc , diag::err_hlsl_rootsig_non_zero_flag);
463
+ if (CurToken. Kind == TokenKind::int_literal) {
464
+ if (CurToken. NumLiteral .getInt () != 0 ) {
465
+ Diags.Report (CurToken. TokLoc , diag::err_hlsl_rootsig_non_zero_flag);
472
466
return true ;
473
467
}
474
468
// Set enum to None equivalent
@@ -478,7 +472,7 @@ bool RootSignatureParser::ParseEnum(
478
472
479
473
// Effectively a switch statement on the token kinds
480
474
for (auto EnumPair : EnumMap)
481
- if (CurTok-> Kind == EnumPair.first ) {
475
+ if (CurToken. Kind == EnumPair.first ) {
482
476
*Enum = EnumPair.second ;
483
477
return false ;
484
478
}
@@ -528,25 +522,6 @@ bool RootSignatureParser::ParseShaderVisibility(ShaderVisibility *Enum) {
528
522
return ParseEnum (EnumMap, Enum);
529
523
}
530
524
531
- RootSignatureToken RootSignatureParser::PeekNextToken () {
532
- // Create an invalid token
533
- RootSignatureToken Token = RootSignatureToken (SourceLocation ());
534
- if (CurTok != LastTok)
535
- Token = *(CurTok + 1 );
536
- return Token;
537
- }
538
-
539
- bool RootSignatureParser::ConsumeNextToken () {
540
- SourceLocation EndLoc = CurTok->TokLoc ;
541
- CurTok++;
542
- if (LastTok == CurTok) {
543
- // Report unexpected end of tokens error
544
- Diags.Report (EndLoc, diag::err_hlsl_rootsig_unexpected_eos);
545
- return true ;
546
- }
547
- return false ;
548
- }
549
-
550
525
// Is given token one of the expected kinds
551
526
static bool IsExpectedToken (TokenKind Kind, ArrayRef<TokenKind> AnyExpected) {
552
527
for (auto Expected : AnyExpected)
@@ -560,11 +535,11 @@ bool RootSignatureParser::EnsureExpectedToken(TokenKind Expected) {
560
535
}
561
536
562
537
bool RootSignatureParser::EnsureExpectedToken (ArrayRef<TokenKind> AnyExpected) {
563
- if (IsExpectedToken (CurTok-> Kind , AnyExpected))
538
+ if (IsExpectedToken (CurToken. Kind , AnyExpected))
564
539
return false ;
565
540
566
541
// Report unexpected token kind error
567
- Diags.Report (CurTok-> TokLoc , diag::err_hlsl_rootsig_unexpected_token_kind)
542
+ Diags.Report (CurToken. TokLoc , diag::err_hlsl_rootsig_unexpected_token_kind)
568
543
<< (unsigned )(AnyExpected.size () != 1 ) << FormatTokenKinds (AnyExpected);
569
544
return true ;
570
545
}
@@ -574,10 +549,10 @@ bool RootSignatureParser::PeekExpectedToken(TokenKind Expected) {
574
549
}
575
550
576
551
bool RootSignatureParser::PeekExpectedToken (ArrayRef<TokenKind> AnyExpected) {
577
- RootSignatureToken Token = PeekNextToken ();
578
- if (Token. Kind == TokenKind::invalid )
552
+ auto Result = Lexer. PeekNextToken ();
553
+ if (!Result )
579
554
return true ;
580
- if (IsExpectedToken (Token. Kind , AnyExpected))
555
+ if (IsExpectedToken (Result-> Kind , AnyExpected))
581
556
return false ;
582
557
return true ;
583
558
}
0 commit comments