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

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

Issue 2131223002: SkSL performance improvements (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: Created 4 years, 5 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
« no previous file with comments | « src/sksl/SkSLIRGenerator.cpp ('k') | src/sksl/SkSLSPIRVCodeGenerator.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 #include "ast/SkSLASTPrefixExpression.h" 45 #include "ast/SkSLASTPrefixExpression.h"
46 #include "ast/SkSLASTReturnStatement.h" 46 #include "ast/SkSLASTReturnStatement.h"
47 #include "ast/SkSLASTStatement.h" 47 #include "ast/SkSLASTStatement.h"
48 #include "ast/SkSLASTSuffixExpression.h" 48 #include "ast/SkSLASTSuffixExpression.h"
49 #include "ast/SkSLASTTernaryExpression.h" 49 #include "ast/SkSLASTTernaryExpression.h"
50 #include "ast/SkSLASTType.h" 50 #include "ast/SkSLASTType.h"
51 #include "ast/SkSLASTVarDeclaration.h" 51 #include "ast/SkSLASTVarDeclaration.h"
52 #include "ast/SkSLASTVarDeclarationStatement.h" 52 #include "ast/SkSLASTVarDeclarationStatement.h"
53 #include "ast/SkSLASTWhileStatement.h" 53 #include "ast/SkSLASTWhileStatement.h"
54 #include "ir/SkSLSymbolTable.h" 54 #include "ir/SkSLSymbolTable.h"
55 #include "ir/SkSLType.h"
55 56
56 namespace SkSL { 57 namespace SkSL {
57 58
58 Parser::Parser(std::string text, SymbolTable& types, ErrorReporter& errors) 59 Parser::Parser(std::string text, SymbolTable& types, ErrorReporter& errors)
59 : fPushback(Position(-1, -1), Token::INVALID_TOKEN, "") 60 : fPushback(Position(-1, -1), Token::INVALID_TOKEN, "")
60 , fTypes(types) 61 , fTypes(types)
61 , fErrors(errors) { 62 , fErrors(errors) {
62 sksllex_init(&fScanner); 63 sksllex_init(&fScanner);
63 fBuffer = sksl_scan_string(text.c_str(), fScanner); 64 fBuffer = sksl_scan_string(text.c_str(), fScanner);
64 skslset_lineno(1, fScanner); 65 skslset_lineno(1, fScanner);
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 if (!this->expect(Token::LBRACE, "'{'")) { 284 if (!this->expect(Token::LBRACE, "'{'")) {
284 return nullptr; 285 return nullptr;
285 } 286 }
286 std::vector<Type::Field> fields; 287 std::vector<Type::Field> fields;
287 while (this->peek().fKind != Token::RBRACE) { 288 while (this->peek().fKind != Token::RBRACE) {
288 std::unique_ptr<ASTVarDeclaration> decl = this->varDeclaration(); 289 std::unique_ptr<ASTVarDeclaration> decl = this->varDeclaration();
289 if (!decl) { 290 if (!decl) {
290 return nullptr; 291 return nullptr;
291 } 292 }
292 for (size_t i = 0; i < decl->fNames.size(); i++) { 293 for (size_t i = 0; i < decl->fNames.size(); i++) {
293 auto type = std::static_pointer_cast<Type>(fTypes[decl->fType->fName ]); 294 auto type = (const Type*) fTypes[decl->fType->fName];
294 for (int j = (int) decl->fSizes[i].size() - 1; j >= 0; j--) { 295 for (int j = (int) decl->fSizes[i].size() - 1; j >= 0; j--) {
295 if (decl->fSizes[i][j]->fKind == ASTExpression::kInt_Kind) { 296 if (decl->fSizes[i][j]->fKind != ASTExpression::kInt_Kind) {
296 this->error(decl->fPosition, "array size in struct field mus t be a constant"); 297 this->error(decl->fPosition, "array size in struct field mus t be a constant");
297 } 298 }
298 uint64_t columns = ((ASTIntLiteral&) *decl->fSizes[i][j]).fValue ; 299 uint64_t columns = ((ASTIntLiteral&) *decl->fSizes[i][j]).fValue ;
299 std::string name = type->name() + "[" + to_string(columns) + "]" ; 300 std::string name = type->name() + "[" + to_string(columns) + "]" ;
300 type = std::shared_ptr<Type>(new Type(name, Type::kArray_Kind, s td::move(type), 301 type = new Type(name, Type::kArray_Kind, *type, (int) columns);
301 (int) columns)); 302 fTypes.takeOwnership((Type*) type);
302 } 303 }
303 fields.push_back(Type::Field(decl->fModifiers, decl->fNames[i], std: :move(type))); 304 fields.push_back(Type::Field(decl->fModifiers, decl->fNames[i], *typ e));
304 if (decl->fValues[i]) { 305 if (decl->fValues[i]) {
305 this->error(decl->fPosition, "initializers are not permitted on struct fields"); 306 this->error(decl->fPosition, "initializers are not permitted on struct fields");
306 } 307 }
307 } 308 }
308 } 309 }
309 if (!this->expect(Token::RBRACE, "'}'")) { 310 if (!this->expect(Token::RBRACE, "'}'")) {
310 return nullptr; 311 return nullptr;
311 } 312 }
312 std::shared_ptr<Type> type(new Type(name.fText, fields)); 313 fTypes.add(name.fText, std::unique_ptr<Type>(new Type(name.fText, fields)));
313 fTypes.add(type->fName, type); 314 return std::unique_ptr<ASTType>(new ASTType(name.fPosition, name.fText,
314 return std::unique_ptr<ASTType>(new ASTType(name.fPosition, type->fName,
315 ASTType::kStruct_Kind)); 315 ASTType::kStruct_Kind));
316 } 316 }
317 317
318 /* structDeclaration ((IDENTIFIER varDeclarationEnd) | SEMICOLON) */ 318 /* structDeclaration ((IDENTIFIER varDeclarationEnd) | SEMICOLON) */
319 std::unique_ptr<ASTVarDeclaration> Parser::structVarDeclaration(ASTModifiers mod ifiers) { 319 std::unique_ptr<ASTVarDeclaration> Parser::structVarDeclaration(ASTModifiers mod ifiers) {
320 std::unique_ptr<ASTType> type = this->structDeclaration(); 320 std::unique_ptr<ASTType> type = this->structDeclaration();
321 if (!type) { 321 if (!type) {
322 return nullptr; 322 return nullptr;
323 } 323 }
324 if (peek().fKind == Token::IDENTIFIER) { 324 if (peek().fKind == Token::IDENTIFIER) {
(...skipping 1057 matching lines...) Expand 10 before | Expand all | Expand 10 after
1382 bool Parser::identifier(std::string* dest) { 1382 bool Parser::identifier(std::string* dest) {
1383 Token t; 1383 Token t;
1384 if (this->expect(Token::IDENTIFIER, "identifier", &t)) { 1384 if (this->expect(Token::IDENTIFIER, "identifier", &t)) {
1385 *dest = t.fText; 1385 *dest = t.fText;
1386 return true; 1386 return true;
1387 } 1387 }
1388 return false; 1388 return false;
1389 } 1389 }
1390 1390
1391 } // namespace 1391 } // namespace
OLDNEW
« no previous file with comments | « src/sksl/SkSLIRGenerator.cpp ('k') | src/sksl/SkSLSPIRVCodeGenerator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698