| 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 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 auto type = (const Type*) fTypes[decl->fType->fName]; | 309 auto type = (const Type*) fTypes[decl->fType->fName]; |
| 310 for (int j = (int) decl->fSizes[i].size() - 1; j >= 0; j--) { | 310 for (int j = (int) decl->fSizes[i].size() - 1; j >= 0; j--) { |
| 311 if (decl->fSizes[i][j]->fKind != ASTExpression::kInt_Kind) { | 311 if (decl->fSizes[i][j]->fKind != ASTExpression::kInt_Kind) { |
| 312 this->error(decl->fPosition, "array size in struct field mus
t be a constant"); | 312 this->error(decl->fPosition, "array size in struct field mus
t be a constant"); |
| 313 } | 313 } |
| 314 uint64_t columns = ((ASTIntLiteral&) *decl->fSizes[i][j]).fValue
; | 314 uint64_t columns = ((ASTIntLiteral&) *decl->fSizes[i][j]).fValue
; |
| 315 std::string name = type->name() + "[" + to_string(columns) + "]"
; | 315 std::string name = type->name() + "[" + to_string(columns) + "]"
; |
| 316 type = new Type(name, Type::kArray_Kind, *type, (int) columns); | 316 type = new Type(name, Type::kArray_Kind, *type, (int) columns); |
| 317 fTypes.takeOwnership((Type*) type); | 317 fTypes.takeOwnership((Type*) type); |
| 318 } | 318 } |
| 319 fields.push_back(Type::Field(decl->fModifiers, decl->fNames[i], *typ
e)); | 319 fields.push_back(Type::Field(decl->fModifiers, decl->fNames[i], type
)); |
| 320 if (decl->fValues[i]) { | 320 if (decl->fValues[i]) { |
| 321 this->error(decl->fPosition, "initializers are not permitted on
struct fields"); | 321 this->error(decl->fPosition, "initializers are not permitted on
struct fields"); |
| 322 } | 322 } |
| 323 } | 323 } |
| 324 } | 324 } |
| 325 if (!this->expect(Token::RBRACE, "'}'")) { | 325 if (!this->expect(Token::RBRACE, "'}'")) { |
| 326 return nullptr; | 326 return nullptr; |
| 327 } | 327 } |
| 328 fTypes.add(name.fText, std::unique_ptr<Type>(new Type(name.fText, fields))); | 328 fTypes.add(name.fText, std::unique_ptr<Type>(new Type(name.fText, fields))); |
| 329 return std::unique_ptr<ASTType>(new ASTType(name.fPosition, name.fText, | 329 return std::unique_ptr<ASTType>(new ASTType(name.fPosition, name.fText, |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 601 case Token::BREAK: | 601 case Token::BREAK: |
| 602 return this->breakStatement(); | 602 return this->breakStatement(); |
| 603 case Token::CONTINUE: | 603 case Token::CONTINUE: |
| 604 return this->continueStatement(); | 604 return this->continueStatement(); |
| 605 case Token::DISCARD: | 605 case Token::DISCARD: |
| 606 return this->discardStatement(); | 606 return this->discardStatement(); |
| 607 case Token::LBRACE: | 607 case Token::LBRACE: |
| 608 return this->block(); | 608 return this->block(); |
| 609 case Token::SEMICOLON: | 609 case Token::SEMICOLON: |
| 610 this->nextToken(); | 610 this->nextToken(); |
| 611 return std::unique_ptr<ASTStatement>(new ASTBlock(start.fPosition, {
})); | 611 return std::unique_ptr<ASTStatement>(new ASTBlock(start.fPosition, |
| 612 std::vector<std::unique_ptr
<ASTStatement>>())); |
| 612 case Token::CONST: // fall through | 613 case Token::CONST: // fall through |
| 613 case Token::HIGHP: // fall through | 614 case Token::HIGHP: // fall through |
| 614 case Token::MEDIUMP: // fall through | 615 case Token::MEDIUMP: // fall through |
| 615 case Token::LOWP: { | 616 case Token::LOWP: { |
| 616 auto decl = this->varDeclaration(); | 617 auto decl = this->varDeclaration(); |
| 617 if (!decl) { | 618 if (!decl) { |
| 618 return nullptr; | 619 return nullptr; |
| 619 } | 620 } |
| 620 return std::unique_ptr<ASTStatement>(new ASTVarDeclarationStatement(
std::move(decl))); | 621 return std::unique_ptr<ASTStatement>(new ASTVarDeclarationStatement(
std::move(decl))); |
| 621 } | 622 } |
| (...skipping 785 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1407 bool Parser::identifier(std::string* dest) { | 1408 bool Parser::identifier(std::string* dest) { |
| 1408 Token t; | 1409 Token t; |
| 1409 if (this->expect(Token::IDENTIFIER, "identifier", &t)) { | 1410 if (this->expect(Token::IDENTIFIER, "identifier", &t)) { |
| 1410 *dest = t.fText; | 1411 *dest = t.fText; |
| 1411 return true; | 1412 return true; |
| 1412 } | 1413 } |
| 1413 return false; | 1414 return false; |
| 1414 } | 1415 } |
| 1415 | 1416 |
| 1416 } // namespace | 1417 } // namespace |
| OLD | NEW |