Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(129)

Side by Side Diff: src/sksl/SkSLParser.cpp

Issue 2185393003: added initial GLSL support to skslc (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fixes! Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
17 #endif 22 #endif
18 #include "lex.sksl.c" 23 #include "lex.sksl.c"
19 #ifdef __clang__ 24 #ifdef __clang__
20 #pragma clang diagnostic pop 25 #pragma clang diagnostic pop
21 #endif 26 #endif
27 #ifdef __GNUC__
28 #pragma GCC diagnostic pop
29 #endif
22 #undef register 30 #undef register
23 31
24 #include "ast/SkSLASTBinaryExpression.h" 32 #include "ast/SkSLASTBinaryExpression.h"
25 #include "ast/SkSLASTBlock.h" 33 #include "ast/SkSLASTBlock.h"
26 #include "ast/SkSLASTBoolLiteral.h" 34 #include "ast/SkSLASTBoolLiteral.h"
27 #include "ast/SkSLASTBreakStatement.h" 35 #include "ast/SkSLASTBreakStatement.h"
28 #include "ast/SkSLASTCallSuffix.h" 36 #include "ast/SkSLASTCallSuffix.h"
29 #include "ast/SkSLASTContinueStatement.h" 37 #include "ast/SkSLASTContinueStatement.h"
30 #include "ast/SkSLASTDiscardStatement.h" 38 #include "ast/SkSLASTDiscardStatement.h"
31 #include "ast/SkSLASTDoStatement.h" 39 #include "ast/SkSLASTDoStatement.h"
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 } 472 }
465 473
466 /* LAYOUT LPAREN IDENTIFIER EQ INT_LITERAL (COMMA IDENTIFIER EQ INT_LITERAL)* 474 /* LAYOUT LPAREN IDENTIFIER EQ INT_LITERAL (COMMA IDENTIFIER EQ INT_LITERAL)*
467 RPAREN */ 475 RPAREN */
468 ASTLayout Parser::layout() { 476 ASTLayout Parser::layout() {
469 int location = -1; 477 int location = -1;
470 int binding = -1; 478 int binding = -1;
471 int index = -1; 479 int index = -1;
472 int set = -1; 480 int set = -1;
473 int builtin = -1; 481 int builtin = -1;
482 bool originUpperLeft = false;
474 if (this->peek().fKind == Token::LAYOUT) { 483 if (this->peek().fKind == Token::LAYOUT) {
475 this->nextToken(); 484 this->nextToken();
476 if (!this->expect(Token::LPAREN, "'('")) { 485 if (!this->expect(Token::LPAREN, "'('")) {
477 return ASTLayout(location, binding, index, set, builtin); 486 return ASTLayout(location, binding, index, set, builtin, originUpper Left);
478 } 487 }
479 for (;;) { 488 for (;;) {
480 Token t = this->nextToken(); 489 Token t = this->nextToken();
481 if (t.fText == "location") { 490 if (t.fText == "location") {
482 location = this->layoutInt(); 491 location = this->layoutInt();
483 } else if (t.fText == "binding") { 492 } else if (t.fText == "binding") {
484 binding = this->layoutInt(); 493 binding = this->layoutInt();
485 } else if (t.fText == "index") { 494 } else if (t.fText == "index") {
486 index = this->layoutInt(); 495 index = this->layoutInt();
487 } else if (t.fText == "set") { 496 } else if (t.fText == "set") {
488 set = this->layoutInt(); 497 set = this->layoutInt();
489 } else if (t.fText == "builtin") { 498 } else if (t.fText == "builtin") {
490 builtin = this->layoutInt(); 499 builtin = this->layoutInt();
500 } else if (t.fText == "origin_upper_left") {
501 originUpperLeft = true;
491 } else { 502 } else {
492 this->error(t.fPosition, ("'" + t.fText + 503 this->error(t.fPosition, ("'" + t.fText +
493 "' is not a valid layout qualifier").c _str()); 504 "' is not a valid layout qualifier").c _str());
494 } 505 }
495 if (this->peek().fKind == Token::RPAREN) { 506 if (this->peek().fKind == Token::RPAREN) {
496 this->nextToken(); 507 this->nextToken();
497 break; 508 break;
498 } 509 }
499 if (!this->expect(Token::COMMA, "','")) { 510 if (!this->expect(Token::COMMA, "','")) {
500 break; 511 break;
501 } 512 }
502 } 513 }
503 } 514 }
504 return ASTLayout(location, binding, index, set, builtin); 515 return ASTLayout(location, binding, index, set, builtin, originUpperLeft);
505 } 516 }
506 517
507 /* layout? (UNIFORM | CONST | IN | OUT | INOUT | LOWP | 518 /* layout? (UNIFORM | CONST | IN | OUT | INOUT | LOWP | MEDIUMP | HIGHP | FLAT | NOPERSPECTIVE)* */
508 MEDIUMP | HIGHP)* */
509 ASTModifiers Parser::modifiers() { 519 ASTModifiers Parser::modifiers() {
510 ASTLayout layout = this->layout(); 520 ASTLayout layout = this->layout();
511 int flags = 0; 521 int flags = 0;
512 for (;;) { 522 for (;;) {
513 // TODO: handle duplicate / incompatible flags 523 // TODO: handle duplicate / incompatible flags
514 switch (peek().fKind) { 524 switch (peek().fKind) {
515 case Token::UNIFORM: 525 case Token::UNIFORM:
516 this->nextToken(); 526 this->nextToken();
517 flags |= ASTModifiers::kUniform_Flag; 527 flags |= ASTModifiers::kUniform_Flag;
518 break; 528 break;
(...skipping 19 matching lines...) Expand all
538 flags |= ASTModifiers::kLowp_Flag; 548 flags |= ASTModifiers::kLowp_Flag;
539 break; 549 break;
540 case Token::MEDIUMP: 550 case Token::MEDIUMP:
541 this->nextToken(); 551 this->nextToken();
542 flags |= ASTModifiers::kMediump_Flag; 552 flags |= ASTModifiers::kMediump_Flag;
543 break; 553 break;
544 case Token::HIGHP: 554 case Token::HIGHP:
545 this->nextToken(); 555 this->nextToken();
546 flags |= ASTModifiers::kHighp_Flag; 556 flags |= ASTModifiers::kHighp_Flag;
547 break; 557 break;
558 case Token::FLAT:
559 this->nextToken();
560 flags |= ASTModifiers::kFlat_Flag;
561 break;
562 case Token::NOPERSPECTIVE:
563 this->nextToken();
564 flags |= ASTModifiers::kNoPerspective_Flag;
565 break;
548 default: 566 default:
549 return ASTModifiers(layout, flags); 567 return ASTModifiers(layout, flags);
550 } 568 }
551 } 569 }
552 } 570 }
553 571
554 ASTModifiers Parser::modifiersWithDefaults(int defaultFlags) { 572 ASTModifiers Parser::modifiersWithDefaults(int defaultFlags) {
555 ASTModifiers result = this->modifiers(); 573 ASTModifiers result = this->modifiers();
556 if (!result.fFlags) { 574 if (!result.fFlags) {
557 return ASTModifiers(result.fLayout, defaultFlags); 575 return ASTModifiers(result.fLayout, defaultFlags);
(...skipping 824 matching lines...) Expand 10 before | Expand all | Expand 10 after
1382 bool Parser::identifier(std::string* dest) { 1400 bool Parser::identifier(std::string* dest) {
1383 Token t; 1401 Token t;
1384 if (this->expect(Token::IDENTIFIER, "identifier", &t)) { 1402 if (this->expect(Token::IDENTIFIER, "identifier", &t)) {
1385 *dest = t.fText; 1403 *dest = t.fText;
1386 return true; 1404 return true;
1387 } 1405 }
1388 return false; 1406 return false;
1389 } 1407 }
1390 1408
1391 } // namespace 1409 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698