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

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: added initial GLSL support to skslc 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"
17 #endif 18 #endif
18 #include "lex.sksl.c" 19 #include "lex.sksl.c"
19 #ifdef __clang__ 20 #ifdef __clang__
20 #pragma clang diagnostic pop 21 #pragma clang diagnostic pop
21 #endif 22 #endif
22 #undef register 23 #undef register
23 24
24 #include "ast/SkSLASTBinaryExpression.h" 25 #include "ast/SkSLASTBinaryExpression.h"
25 #include "ast/SkSLASTBlock.h" 26 #include "ast/SkSLASTBlock.h"
26 #include "ast/SkSLASTBoolLiteral.h" 27 #include "ast/SkSLASTBoolLiteral.h"
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 } 465 }
465 466
466 /* LAYOUT LPAREN IDENTIFIER EQ INT_LITERAL (COMMA IDENTIFIER EQ INT_LITERAL)* 467 /* LAYOUT LPAREN IDENTIFIER EQ INT_LITERAL (COMMA IDENTIFIER EQ INT_LITERAL)*
467 RPAREN */ 468 RPAREN */
468 ASTLayout Parser::layout() { 469 ASTLayout Parser::layout() {
469 int location = -1; 470 int location = -1;
470 int binding = -1; 471 int binding = -1;
471 int index = -1; 472 int index = -1;
472 int set = -1; 473 int set = -1;
473 int builtin = -1; 474 int builtin = -1;
475 bool originUpperLeft = false;
474 if (this->peek().fKind == Token::LAYOUT) { 476 if (this->peek().fKind == Token::LAYOUT) {
475 this->nextToken(); 477 this->nextToken();
476 if (!this->expect(Token::LPAREN, "'('")) { 478 if (!this->expect(Token::LPAREN, "'('")) {
477 return ASTLayout(location, binding, index, set, builtin); 479 return ASTLayout(location, binding, index, set, builtin, originUpper Left);
478 } 480 }
479 for (;;) { 481 for (;;) {
480 Token t = this->nextToken(); 482 Token t = this->nextToken();
481 if (t.fText == "location") { 483 if (t.fText == "location") {
482 location = this->layoutInt(); 484 location = this->layoutInt();
483 } else if (t.fText == "binding") { 485 } else if (t.fText == "binding") {
484 binding = this->layoutInt(); 486 binding = this->layoutInt();
485 } else if (t.fText == "index") { 487 } else if (t.fText == "index") {
486 index = this->layoutInt(); 488 index = this->layoutInt();
487 } else if (t.fText == "set") { 489 } else if (t.fText == "set") {
488 set = this->layoutInt(); 490 set = this->layoutInt();
489 } else if (t.fText == "builtin") { 491 } else if (t.fText == "builtin") {
490 builtin = this->layoutInt(); 492 builtin = this->layoutInt();
493 } else if (t.fText == "origin_upper_left") {
494 originUpperLeft = true;
491 } else { 495 } else {
492 this->error(t.fPosition, ("'" + t.fText + 496 this->error(t.fPosition, ("'" + t.fText +
493 "' is not a valid layout qualifier").c _str()); 497 "' is not a valid layout qualifier").c _str());
494 } 498 }
495 if (this->peek().fKind == Token::RPAREN) { 499 if (this->peek().fKind == Token::RPAREN) {
496 this->nextToken(); 500 this->nextToken();
497 break; 501 break;
498 } 502 }
499 if (!this->expect(Token::COMMA, "','")) { 503 if (!this->expect(Token::COMMA, "','")) {
500 break; 504 break;
501 } 505 }
502 } 506 }
503 } 507 }
504 return ASTLayout(location, binding, index, set, builtin); 508 return ASTLayout(location, binding, index, set, builtin, originUpperLeft);
505 } 509 }
506 510
507 /* layout? (UNIFORM | CONST | IN | OUT | INOUT | LOWP | 511 /* layout? (UNIFORM | CONST | IN | OUT | INOUT | LOWP | MEDIUMP | HIGHP | FLAT | NOPERSPECTIVE)* */
508 MEDIUMP | HIGHP)* */
509 ASTModifiers Parser::modifiers() { 512 ASTModifiers Parser::modifiers() {
510 ASTLayout layout = this->layout(); 513 ASTLayout layout = this->layout();
511 int flags = 0; 514 int flags = 0;
512 for (;;) { 515 for (;;) {
513 // TODO: handle duplicate / incompatible flags 516 // TODO: handle duplicate / incompatible flags
514 switch (peek().fKind) { 517 switch (peek().fKind) {
515 case Token::UNIFORM: 518 case Token::UNIFORM:
516 this->nextToken(); 519 this->nextToken();
517 flags |= ASTModifiers::kUniform_Flag; 520 flags |= ASTModifiers::kUniform_Flag;
518 break; 521 break;
(...skipping 19 matching lines...) Expand all
538 flags |= ASTModifiers::kLowp_Flag; 541 flags |= ASTModifiers::kLowp_Flag;
539 break; 542 break;
540 case Token::MEDIUMP: 543 case Token::MEDIUMP:
541 this->nextToken(); 544 this->nextToken();
542 flags |= ASTModifiers::kMediump_Flag; 545 flags |= ASTModifiers::kMediump_Flag;
543 break; 546 break;
544 case Token::HIGHP: 547 case Token::HIGHP:
545 this->nextToken(); 548 this->nextToken();
546 flags |= ASTModifiers::kHighp_Flag; 549 flags |= ASTModifiers::kHighp_Flag;
547 break; 550 break;
551 case Token::FLAT:
552 this->nextToken();
553 flags |= ASTModifiers::kFlat_Flag;
554 break;
555 case Token::NOPERSPECTIVE:
556 this->nextToken();
557 flags |= ASTModifiers::kNoPerspective_Flag;
558 break;
548 default: 559 default:
549 return ASTModifiers(layout, flags); 560 return ASTModifiers(layout, flags);
550 } 561 }
551 } 562 }
552 } 563 }
553 564
554 ASTModifiers Parser::modifiersWithDefaults(int defaultFlags) { 565 ASTModifiers Parser::modifiersWithDefaults(int defaultFlags) {
555 ASTModifiers result = this->modifiers(); 566 ASTModifiers result = this->modifiers();
556 if (!result.fFlags) { 567 if (!result.fFlags) {
557 return ASTModifiers(result.fLayout, defaultFlags); 568 return ASTModifiers(result.fLayout, defaultFlags);
(...skipping 824 matching lines...) Expand 10 before | Expand all | Expand 10 after
1382 bool Parser::identifier(std::string* dest) { 1393 bool Parser::identifier(std::string* dest) {
1383 Token t; 1394 Token t;
1384 if (this->expect(Token::IDENTIFIER, "identifier", &t)) { 1395 if (this->expect(Token::IDENTIFIER, "identifier", &t)) {
1385 *dest = t.fText; 1396 *dest = t.fText;
1386 return true; 1397 return true;
1387 } 1398 }
1388 return false; 1399 return false;
1389 } 1400 }
1390 1401
1391 } // namespace 1402 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698