@@ -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" ;
@@ -243,42 +246,33 @@ std::optional<RootSignatureToken> RootSignatureLexer::PeekNextToken() {
243
246
244
247
// Parser Definitions
245
248
246
- RootSignatureParser::RootSignatureParser (
247
- SmallVector<RootElement> &Elements,
248
- const SmallVector<RootSignatureToken> &Tokens, DiagnosticsEngine &Diags)
249
- : Elements(Elements), Diags(Diags) {
250
- CurTok = Tokens.begin ();
251
- LastTok = Tokens.end ();
252
- }
249
+ RootSignatureParser::RootSignatureParser (SmallVector<RootElement> &Elements,
250
+ RootSignatureLexer &Lexer,
251
+ DiagnosticsEngine &Diags)
252
+ : Elements(Elements), Lexer(Lexer), Diags(Diags) {}
253
253
254
254
bool RootSignatureParser::Parse () {
255
255
// Handle edge-case of empty RootSignature()
256
- if (CurTok == LastTok )
256
+ if (Lexer. EndOfBuffer () )
257
257
return false ;
258
258
259
- bool First = true ;
260
259
// Iterate as many RootElements as possible
261
- while (!ParseRootElement (First)) {
262
- First = false ;
263
- // Avoid use of ConsumeNextToken here to skip incorrect end of tokens error
264
- CurTok++;
265
- if (CurTok == LastTok)
260
+ while (!ParseRootElement ()) {
261
+ if (Lexer.EndOfBuffer ())
266
262
return false ;
267
- if (EnsureExpectedToken (TokenKind::pu_comma))
263
+ if (ConsumeExpectedToken (TokenKind::pu_comma))
268
264
return true ;
269
265
}
270
266
271
267
return true ;
272
268
}
273
269
274
- bool RootSignatureParser::ParseRootElement (bool First) {
275
- if (First && EnsureExpectedToken (TokenKind::kw_DescriptorTable))
276
- return true ;
277
- if (!First && ConsumeExpectedToken (TokenKind::kw_DescriptorTable))
270
+ bool RootSignatureParser::ParseRootElement () {
271
+ if (ConsumeExpectedToken (TokenKind::kw_DescriptorTable))
278
272
return true ;
279
273
280
274
// Dispatch onto the correct parse method
281
- switch (CurTok-> Kind ) {
275
+ switch (CurToken. Kind ) {
282
276
case TokenKind::kw_DescriptorTable:
283
277
return ParseDescriptorTable ();
284
278
default :
@@ -305,8 +299,8 @@ bool RootSignatureParser::ParseDescriptorTable() {
305
299
// Handle the visibility parameter
306
300
if (!TryConsumeExpectedToken (TokenKind::kw_visibility)) {
307
301
if (SeenVisibility) {
308
- Diags.Report (CurTok-> TokLoc , diag::err_hlsl_rootsig_repeat_param)
309
- << FormatTokenKinds (CurTok-> Kind );
302
+ Diags.Report (CurToken. TokLoc , diag::err_hlsl_rootsig_repeat_param)
303
+ << FormatTokenKinds (CurToken. Kind );
310
304
return true ;
311
305
}
312
306
SeenVisibility = true ;
@@ -334,7 +328,7 @@ bool RootSignatureParser::ParseDescriptorTableClause() {
334
328
return true ;
335
329
336
330
DescriptorTableClause Clause;
337
- switch (CurTok-> Kind ) {
331
+ switch (CurToken. Kind ) {
338
332
case TokenKind::kw_CBV:
339
333
Clause.Type = ClauseType::CBuffer;
340
334
break ;
@@ -419,9 +413,9 @@ bool RootSignatureParser::ParseOptionalParams(
419
413
if (ConsumeExpectedToken (ParamKeywords))
420
414
return true ;
421
415
422
- TokenKind ParamKind = CurTok-> Kind ;
416
+ TokenKind ParamKind = CurToken. Kind ;
423
417
if (Seen.contains (ParamKind)) {
424
- Diags.Report (CurTok-> TokLoc , diag::err_hlsl_rootsig_repeat_param)
418
+ Diags.Report (CurToken. TokLoc , diag::err_hlsl_rootsig_repeat_param)
425
419
<< FormatTokenKinds (ParamKind);
426
420
return true ;
427
421
}
@@ -440,25 +434,25 @@ bool RootSignatureParser::ParseDescriptorRangeOffset(DescriptorRangeOffset *X) {
440
434
return true ;
441
435
442
436
// Edge case for the offset enum -> static value
443
- if (CurTok-> Kind == TokenKind::en_DescriptorRangeOffsetAppend) {
437
+ if (CurToken. Kind == TokenKind::en_DescriptorRangeOffsetAppend) {
444
438
*X = DescriptorTableOffsetAppend;
445
439
return false ;
446
440
}
447
441
448
- *X = DescriptorRangeOffset (CurTok-> NumLiteral .getInt ().getExtValue ());
442
+ *X = DescriptorRangeOffset (CurToken. NumLiteral .getInt ().getExtValue ());
449
443
return false ;
450
444
}
451
445
452
446
bool RootSignatureParser::ParseUInt (uint32_t *X) {
453
447
if (ConsumeExpectedToken (TokenKind::int_literal))
454
448
return true ;
455
449
456
- *X = CurTok-> NumLiteral .getInt ().getExtValue ();
450
+ *X = CurToken. NumLiteral .getInt ().getExtValue ();
457
451
return false ;
458
452
}
459
453
460
454
bool RootSignatureParser::ParseRegister (Register *Register) {
461
- switch (CurTok-> Kind ) {
455
+ switch (CurToken. Kind ) {
462
456
case TokenKind::bReg:
463
457
Register->ViewType = RegisterType::BReg;
464
458
break ;
@@ -475,7 +469,7 @@ bool RootSignatureParser::ParseRegister(Register *Register) {
475
469
llvm_unreachable (" Switch for an expected token was not provided" );
476
470
}
477
471
478
- Register->Number = CurTok-> NumLiteral .getInt ().getExtValue ();
472
+ Register->Number = CurToken. NumLiteral .getInt ().getExtValue ();
479
473
480
474
return false ;
481
475
}
@@ -494,9 +488,9 @@ bool RootSignatureParser::ParseEnum(
494
488
return true ;
495
489
496
490
// Handle the edge case when '0' is used to specify None
497
- if (CurTok-> Kind == TokenKind::int_literal) {
498
- if (CurTok-> NumLiteral .getInt () != 0 ) {
499
- Diags.Report (CurTok-> TokLoc , diag::err_hlsl_rootsig_non_zero_flag);
491
+ if (CurToken. Kind == TokenKind::int_literal) {
492
+ if (CurToken. NumLiteral .getInt () != 0 ) {
493
+ Diags.Report (CurToken. TokLoc , diag::err_hlsl_rootsig_non_zero_flag);
500
494
return true ;
501
495
}
502
496
// Set enum to None equivalent
@@ -506,7 +500,7 @@ bool RootSignatureParser::ParseEnum(
506
500
507
501
// Effectively a switch statement on the token kinds
508
502
for (auto EnumPair : EnumMap)
509
- if (CurTok-> Kind == EnumPair.first ) {
503
+ if (CurToken. Kind == EnumPair.first ) {
510
504
*Enum = EnumPair.second ;
511
505
return false ;
512
506
}
@@ -556,25 +550,6 @@ bool RootSignatureParser::ParseShaderVisibility(ShaderVisibility *Enum) {
556
550
return ParseEnum (EnumMap, Enum);
557
551
}
558
552
559
- RootSignatureToken RootSignatureParser::PeekNextToken () {
560
- // Create an invalid token
561
- RootSignatureToken Token = RootSignatureToken (SourceLocation ());
562
- if (CurTok != LastTok)
563
- Token = *(CurTok + 1 );
564
- return Token;
565
- }
566
-
567
- bool RootSignatureParser::ConsumeNextToken () {
568
- SourceLocation EndLoc = CurTok->TokLoc ;
569
- CurTok++;
570
- if (LastTok == CurTok) {
571
- // Report unexpected end of tokens error
572
- Diags.Report (EndLoc, diag::err_hlsl_rootsig_unexpected_eos);
573
- return true ;
574
- }
575
- return false ;
576
- }
577
-
578
553
// Is given token one of the expected kinds
579
554
static bool IsExpectedToken (TokenKind Kind, ArrayRef<TokenKind> AnyExpected) {
580
555
for (auto Expected : AnyExpected)
@@ -588,11 +563,11 @@ bool RootSignatureParser::EnsureExpectedToken(TokenKind Expected) {
588
563
}
589
564
590
565
bool RootSignatureParser::EnsureExpectedToken (ArrayRef<TokenKind> AnyExpected) {
591
- if (IsExpectedToken (CurTok-> Kind , AnyExpected))
566
+ if (IsExpectedToken (CurToken. Kind , AnyExpected))
592
567
return false ;
593
568
594
569
// Report unexpected token kind error
595
- Diags.Report (CurTok-> TokLoc , diag::err_hlsl_rootsig_unexpected_token_kind)
570
+ Diags.Report (CurToken. TokLoc , diag::err_hlsl_rootsig_unexpected_token_kind)
596
571
<< (unsigned )(AnyExpected.size () != 1 ) << FormatTokenKinds (AnyExpected);
597
572
return true ;
598
573
}
@@ -602,10 +577,10 @@ bool RootSignatureParser::PeekExpectedToken(TokenKind Expected) {
602
577
}
603
578
604
579
bool RootSignatureParser::PeekExpectedToken (ArrayRef<TokenKind> AnyExpected) {
605
- RootSignatureToken Token = PeekNextToken ();
606
- if (Token. Kind == TokenKind::invalid )
580
+ auto Result = Lexer. PeekNextToken ();
581
+ if (!Result )
607
582
return true ;
608
- if (IsExpectedToken (Token. Kind , AnyExpected))
583
+ if (IsExpectedToken (Result-> Kind , AnyExpected))
609
584
return false ;
610
585
return true ;
611
586
}
0 commit comments