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" |
11 | 11 |
12 #define register | 12 #define register |
13 #ifdef __clang__ | 13 #ifdef __clang__ |
14 #pragma clang diagnostic push | 14 #pragma clang diagnostic push |
15 #pragma clang diagnostic ignored "-Wunneeded-internal-declaration" | 15 #pragma clang diagnostic ignored "-Wunneeded-internal-declaration" |
16 #pragma clang diagnostic ignored "-Wnull-conversion" | 16 #pragma clang diagnostic ignored "-Wnull-conversion" |
| 17 #pragma clang diagnostic ignored "-Wsign-compare" |
| 18 #endif |
| 19 #ifdef __GNUC__ |
| 20 #pragma GCC diagnostic push |
| 21 #pragma GCC diagnostic ignored "-Wsign-compare" |
| 22 #endif |
| 23 #ifdef _MSC_VER |
| 24 #pragma warning(push) |
| 25 #pragma warning(disable:4018) |
17 #endif | 26 #endif |
18 #include "lex.sksl.c" | 27 #include "lex.sksl.c" |
19 #ifdef __clang__ | 28 #ifdef __clang__ |
20 #pragma clang diagnostic pop | 29 #pragma clang diagnostic pop |
21 #endif | 30 #endif |
| 31 #ifdef __GNUC__ |
| 32 #pragma GCC diagnostic pop |
| 33 #endif |
| 34 #ifdef _MSC_VER |
| 35 #pragma warning(pop) |
| 36 #endif |
22 #undef register | 37 #undef register |
23 | 38 |
24 #include "ast/SkSLASTBinaryExpression.h" | 39 #include "ast/SkSLASTBinaryExpression.h" |
25 #include "ast/SkSLASTBlock.h" | 40 #include "ast/SkSLASTBlock.h" |
26 #include "ast/SkSLASTBoolLiteral.h" | 41 #include "ast/SkSLASTBoolLiteral.h" |
27 #include "ast/SkSLASTBreakStatement.h" | 42 #include "ast/SkSLASTBreakStatement.h" |
28 #include "ast/SkSLASTCallSuffix.h" | 43 #include "ast/SkSLASTCallSuffix.h" |
29 #include "ast/SkSLASTContinueStatement.h" | 44 #include "ast/SkSLASTContinueStatement.h" |
30 #include "ast/SkSLASTDiscardStatement.h" | 45 #include "ast/SkSLASTDiscardStatement.h" |
31 #include "ast/SkSLASTDoStatement.h" | 46 #include "ast/SkSLASTDoStatement.h" |
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 } | 479 } |
465 | 480 |
466 /* LAYOUT LPAREN IDENTIFIER EQ INT_LITERAL (COMMA IDENTIFIER EQ INT_LITERAL)* | 481 /* LAYOUT LPAREN IDENTIFIER EQ INT_LITERAL (COMMA IDENTIFIER EQ INT_LITERAL)* |
467 RPAREN */ | 482 RPAREN */ |
468 ASTLayout Parser::layout() { | 483 ASTLayout Parser::layout() { |
469 int location = -1; | 484 int location = -1; |
470 int binding = -1; | 485 int binding = -1; |
471 int index = -1; | 486 int index = -1; |
472 int set = -1; | 487 int set = -1; |
473 int builtin = -1; | 488 int builtin = -1; |
| 489 bool originUpperLeft = false; |
474 if (this->peek().fKind == Token::LAYOUT) { | 490 if (this->peek().fKind == Token::LAYOUT) { |
475 this->nextToken(); | 491 this->nextToken(); |
476 if (!this->expect(Token::LPAREN, "'('")) { | 492 if (!this->expect(Token::LPAREN, "'('")) { |
477 return ASTLayout(location, binding, index, set, builtin); | 493 return ASTLayout(location, binding, index, set, builtin, originUpper
Left); |
478 } | 494 } |
479 for (;;) { | 495 for (;;) { |
480 Token t = this->nextToken(); | 496 Token t = this->nextToken(); |
481 if (t.fText == "location") { | 497 if (t.fText == "location") { |
482 location = this->layoutInt(); | 498 location = this->layoutInt(); |
483 } else if (t.fText == "binding") { | 499 } else if (t.fText == "binding") { |
484 binding = this->layoutInt(); | 500 binding = this->layoutInt(); |
485 } else if (t.fText == "index") { | 501 } else if (t.fText == "index") { |
486 index = this->layoutInt(); | 502 index = this->layoutInt(); |
487 } else if (t.fText == "set") { | 503 } else if (t.fText == "set") { |
488 set = this->layoutInt(); | 504 set = this->layoutInt(); |
489 } else if (t.fText == "builtin") { | 505 } else if (t.fText == "builtin") { |
490 builtin = this->layoutInt(); | 506 builtin = this->layoutInt(); |
| 507 } else if (t.fText == "origin_upper_left") { |
| 508 originUpperLeft = true; |
491 } else { | 509 } else { |
492 this->error(t.fPosition, ("'" + t.fText + | 510 this->error(t.fPosition, ("'" + t.fText + |
493 "' is not a valid layout qualifier").c
_str()); | 511 "' is not a valid layout qualifier").c
_str()); |
494 } | 512 } |
495 if (this->peek().fKind == Token::RPAREN) { | 513 if (this->peek().fKind == Token::RPAREN) { |
496 this->nextToken(); | 514 this->nextToken(); |
497 break; | 515 break; |
498 } | 516 } |
499 if (!this->expect(Token::COMMA, "','")) { | 517 if (!this->expect(Token::COMMA, "','")) { |
500 break; | 518 break; |
501 } | 519 } |
502 } | 520 } |
503 } | 521 } |
504 return ASTLayout(location, binding, index, set, builtin); | 522 return ASTLayout(location, binding, index, set, builtin, originUpperLeft); |
505 } | 523 } |
506 | 524 |
507 /* layout? (UNIFORM | CONST | IN | OUT | INOUT | LOWP | | 525 /* layout? (UNIFORM | CONST | IN | OUT | INOUT | LOWP | MEDIUMP | HIGHP | FLAT |
NOPERSPECTIVE)* */ |
508 MEDIUMP | HIGHP)* */ | |
509 ASTModifiers Parser::modifiers() { | 526 ASTModifiers Parser::modifiers() { |
510 ASTLayout layout = this->layout(); | 527 ASTLayout layout = this->layout(); |
511 int flags = 0; | 528 int flags = 0; |
512 for (;;) { | 529 for (;;) { |
513 // TODO: handle duplicate / incompatible flags | 530 // TODO: handle duplicate / incompatible flags |
514 switch (peek().fKind) { | 531 switch (peek().fKind) { |
515 case Token::UNIFORM: | 532 case Token::UNIFORM: |
516 this->nextToken(); | 533 this->nextToken(); |
517 flags |= ASTModifiers::kUniform_Flag; | 534 flags |= ASTModifiers::kUniform_Flag; |
518 break; | 535 break; |
(...skipping 19 matching lines...) Expand all Loading... |
538 flags |= ASTModifiers::kLowp_Flag; | 555 flags |= ASTModifiers::kLowp_Flag; |
539 break; | 556 break; |
540 case Token::MEDIUMP: | 557 case Token::MEDIUMP: |
541 this->nextToken(); | 558 this->nextToken(); |
542 flags |= ASTModifiers::kMediump_Flag; | 559 flags |= ASTModifiers::kMediump_Flag; |
543 break; | 560 break; |
544 case Token::HIGHP: | 561 case Token::HIGHP: |
545 this->nextToken(); | 562 this->nextToken(); |
546 flags |= ASTModifiers::kHighp_Flag; | 563 flags |= ASTModifiers::kHighp_Flag; |
547 break; | 564 break; |
| 565 case Token::FLAT: |
| 566 this->nextToken(); |
| 567 flags |= ASTModifiers::kFlat_Flag; |
| 568 break; |
| 569 case Token::NOPERSPECTIVE: |
| 570 this->nextToken(); |
| 571 flags |= ASTModifiers::kNoPerspective_Flag; |
| 572 break; |
548 default: | 573 default: |
549 return ASTModifiers(layout, flags); | 574 return ASTModifiers(layout, flags); |
550 } | 575 } |
551 } | 576 } |
552 } | 577 } |
553 | 578 |
554 ASTModifiers Parser::modifiersWithDefaults(int defaultFlags) { | 579 ASTModifiers Parser::modifiersWithDefaults(int defaultFlags) { |
555 ASTModifiers result = this->modifiers(); | 580 ASTModifiers result = this->modifiers(); |
556 if (!result.fFlags) { | 581 if (!result.fFlags) { |
557 return ASTModifiers(result.fLayout, defaultFlags); | 582 return ASTModifiers(result.fLayout, defaultFlags); |
(...skipping 824 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1382 bool Parser::identifier(std::string* dest) { | 1407 bool Parser::identifier(std::string* dest) { |
1383 Token t; | 1408 Token t; |
1384 if (this->expect(Token::IDENTIFIER, "identifier", &t)) { | 1409 if (this->expect(Token::IDENTIFIER, "identifier", &t)) { |
1385 *dest = t.fText; | 1410 *dest = t.fText; |
1386 return true; | 1411 return true; |
1387 } | 1412 } |
1388 return false; | 1413 return false; |
1389 } | 1414 } |
1390 | 1415 |
1391 } // namespace | 1416 } // namespace |
OLD | NEW |