OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "stdio.h" | 8 #include "stdio.h" |
9 #include "SkSLParser.h" | 9 #include "SkSLParser.h" |
10 #include "SkSLToken.h" | 10 #include "SkSLToken.h" |
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 if (!this->expect(Token::EQ, "'='")) { | 528 if (!this->expect(Token::EQ, "'='")) { |
529 return -1; | 529 return -1; |
530 } | 530 } |
531 Token resultToken; | 531 Token resultToken; |
532 if (this->expect(Token::INT_LITERAL, "a non-negative integer", &resultToken)
) { | 532 if (this->expect(Token::INT_LITERAL, "a non-negative integer", &resultToken)
) { |
533 return SkSL::stoi(resultToken.fText); | 533 return SkSL::stoi(resultToken.fText); |
534 } | 534 } |
535 return -1; | 535 return -1; |
536 } | 536 } |
537 | 537 |
538 /* LAYOUT LPAREN IDENTIFIER EQ INT_LITERAL (COMMA IDENTIFIER EQ INT_LITERAL)* | 538 /* LAYOUT LPAREN IDENTIFIER (EQ INT_LITERAL)? (COMMA IDENTIFIER (EQ INT_LITERAL)
?)* RPAREN */ |
539 RPAREN */ | |
540 ASTLayout Parser::layout() { | 539 ASTLayout Parser::layout() { |
541 int location = -1; | 540 int location = -1; |
542 int binding = -1; | 541 int binding = -1; |
543 int index = -1; | 542 int index = -1; |
544 int set = -1; | 543 int set = -1; |
545 int builtin = -1; | 544 int builtin = -1; |
546 int inputAttachmentIndex = -1; | 545 int inputAttachmentIndex = -1; |
547 bool originUpperLeft = false; | 546 bool originUpperLeft = false; |
548 bool overrideCoverage = false; | 547 bool overrideCoverage = false; |
549 bool blendSupportAllEquations = false; | 548 bool blendSupportAllEquations = false; |
550 ASTLayout::Format format = ASTLayout::Format::kUnspecified; | 549 ASTLayout::Format format = ASTLayout::Format::kUnspecified; |
| 550 bool pushConstant = false; |
551 if (this->peek().fKind == Token::LAYOUT) { | 551 if (this->peek().fKind == Token::LAYOUT) { |
552 this->nextToken(); | 552 this->nextToken(); |
553 if (!this->expect(Token::LPAREN, "'('")) { | 553 if (!this->expect(Token::LPAREN, "'('")) { |
554 return ASTLayout(location, binding, index, set, builtin, inputAttach
mentIndex, | 554 return ASTLayout(location, binding, index, set, builtin, inputAttach
mentIndex, |
555 originUpperLeft, overrideCoverage, blendSupportAllE
quations, format); | 555 originUpperLeft, overrideCoverage, blendSupportAllE
quations, format, |
| 556 pushConstant); |
556 } | 557 } |
557 for (;;) { | 558 for (;;) { |
558 Token t = this->nextToken(); | 559 Token t = this->nextToken(); |
559 if (t.fText == "location") { | 560 if (t.fText == "location") { |
560 location = this->layoutInt(); | 561 location = this->layoutInt(); |
561 } else if (t.fText == "binding") { | 562 } else if (t.fText == "binding") { |
562 binding = this->layoutInt(); | 563 binding = this->layoutInt(); |
563 } else if (t.fText == "index") { | 564 } else if (t.fText == "index") { |
564 index = this->layoutInt(); | 565 index = this->layoutInt(); |
565 } else if (t.fText == "set") { | 566 } else if (t.fText == "set") { |
566 set = this->layoutInt(); | 567 set = this->layoutInt(); |
567 } else if (t.fText == "builtin") { | 568 } else if (t.fText == "builtin") { |
568 builtin = this->layoutInt(); | 569 builtin = this->layoutInt(); |
569 } else if (t.fText == "input_attachment_index") { | 570 } else if (t.fText == "input_attachment_index") { |
570 inputAttachmentIndex = this->layoutInt(); | 571 inputAttachmentIndex = this->layoutInt(); |
571 } else if (t.fText == "origin_upper_left") { | 572 } else if (t.fText == "origin_upper_left") { |
572 originUpperLeft = true; | 573 originUpperLeft = true; |
573 } else if (t.fText == "override_coverage") { | 574 } else if (t.fText == "override_coverage") { |
574 overrideCoverage = true; | 575 overrideCoverage = true; |
575 } else if (t.fText == "blend_support_all_equations") { | 576 } else if (t.fText == "blend_support_all_equations") { |
576 blendSupportAllEquations = true; | 577 blendSupportAllEquations = true; |
577 } else if (ASTLayout::ReadFormat(t.fText, &format)) { | 578 } else if (ASTLayout::ReadFormat(t.fText, &format)) { |
578 // AST::ReadFormat stored the result in 'format'. | 579 // AST::ReadFormat stored the result in 'format'. |
| 580 } else if (t.fText == "push_constant") { |
| 581 pushConstant = true; |
579 } else { | 582 } else { |
580 this->error(t.fPosition, ("'" + t.fText + | 583 this->error(t.fPosition, ("'" + t.fText + |
581 "' is not a valid layout qualifier").c
_str()); | 584 "' is not a valid layout qualifier").c
_str()); |
582 } | 585 } |
583 if (this->peek().fKind == Token::RPAREN) { | 586 if (this->peek().fKind == Token::RPAREN) { |
584 this->nextToken(); | 587 this->nextToken(); |
585 break; | 588 break; |
586 } | 589 } |
587 if (!this->expect(Token::COMMA, "','")) { | 590 if (!this->expect(Token::COMMA, "','")) { |
588 break; | 591 break; |
589 } | 592 } |
590 } | 593 } |
591 } | 594 } |
592 return ASTLayout(location, binding, index, set, builtin, inputAttachmentInde
x, originUpperLeft, | 595 return ASTLayout(location, binding, index, set, builtin, inputAttachmentInde
x, originUpperLeft, |
593 overrideCoverage, blendSupportAllEquations, format); | 596 overrideCoverage, blendSupportAllEquations, format, pushCon
stant); |
594 } | 597 } |
595 | 598 |
596 /* layout? (UNIFORM | CONST | IN | OUT | INOUT | LOWP | MEDIUMP | HIGHP | FLAT |
NOPERSPECTIVE)* */ | 599 /* layout? (UNIFORM | CONST | IN | OUT | INOUT | LOWP | MEDIUMP | HIGHP | FLAT |
NOPERSPECTIVE)* */ |
597 ASTModifiers Parser::modifiers() { | 600 ASTModifiers Parser::modifiers() { |
598 ASTLayout layout = this->layout(); | 601 ASTLayout layout = this->layout(); |
599 int flags = 0; | 602 int flags = 0; |
600 for (;;) { | 603 for (;;) { |
601 // TODO: handle duplicate / incompatible flags | 604 // TODO: handle duplicate / incompatible flags |
602 switch (peek().fKind) { | 605 switch (peek().fKind) { |
603 case Token::UNIFORM: | 606 case Token::UNIFORM: |
(...skipping 898 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1502 bool Parser::identifier(SkString* dest) { | 1505 bool Parser::identifier(SkString* dest) { |
1503 Token t; | 1506 Token t; |
1504 if (this->expect(Token::IDENTIFIER, "identifier", &t)) { | 1507 if (this->expect(Token::IDENTIFIER, "identifier", &t)) { |
1505 *dest = t.fText; | 1508 *dest = t.fText; |
1506 return true; | 1509 return true; |
1507 } | 1510 } |
1508 return false; | 1511 return false; |
1509 } | 1512 } |
1510 | 1513 |
1511 } // namespace | 1514 } // namespace |
OLD | NEW |