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 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 } | 324 } |
325 std::vector<Type::Field> fields; | 325 std::vector<Type::Field> fields; |
326 while (this->peek().fKind != Token::RBRACE) { | 326 while (this->peek().fKind != Token::RBRACE) { |
327 std::unique_ptr<ASTVarDeclarations> decl = this->varDeclarations(); | 327 std::unique_ptr<ASTVarDeclarations> decl = this->varDeclarations(); |
328 if (!decl) { | 328 if (!decl) { |
329 return nullptr; | 329 return nullptr; |
330 } | 330 } |
331 for (const auto& var : decl->fVars) { | 331 for (const auto& var : decl->fVars) { |
332 auto type = (const Type*) fTypes[decl->fType->fName]; | 332 auto type = (const Type*) fTypes[decl->fType->fName]; |
333 for (int i = (int) var.fSizes.size() - 1; i >= 0; i--) { | 333 for (int i = (int) var.fSizes.size() - 1; i >= 0; i--) { |
334 if (var.fSizes[i]->fKind != ASTExpression::kInt_Kind) { | 334 if (!var.fSizes[i] || var.fSizes[i]->fKind != ASTExpression::kIn
t_Kind) { |
335 this->error(decl->fPosition, "array size in struct field mus
t be a constant"); | 335 this->error(decl->fPosition, "array size in struct field mus
t be a constant"); |
| 336 return nullptr; |
336 } | 337 } |
337 uint64_t columns = ((ASTIntLiteral&) *var.fSizes[i]).fValue; | 338 uint64_t columns = ((ASTIntLiteral&) *var.fSizes[i]).fValue; |
338 std::string name = type->name() + "[" + to_string(columns) + "]"
; | 339 std::string name = type->name() + "[" + to_string(columns) + "]"
; |
339 type = new Type(name, Type::kArray_Kind, *type, (int) columns); | 340 type = new Type(name, Type::kArray_Kind, *type, (int) columns); |
340 fTypes.takeOwnership((Type*) type); | 341 fTypes.takeOwnership((Type*) type); |
341 } | 342 } |
342 fields.push_back(Type::Field(decl->fModifiers, var.fName, type)); | 343 fields.push_back(Type::Field(decl->fModifiers, var.fName, type)); |
343 if (var.fValue) { | 344 if (var.fValue) { |
344 this->error(decl->fPosition, "initializers are not permitted on
struct fields"); | 345 this->error(decl->fPosition, "initializers are not permitted on
struct fields"); |
345 } | 346 } |
(...skipping 1098 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1444 bool Parser::identifier(std::string* dest) { | 1445 bool Parser::identifier(std::string* dest) { |
1445 Token t; | 1446 Token t; |
1446 if (this->expect(Token::IDENTIFIER, "identifier", &t)) { | 1447 if (this->expect(Token::IDENTIFIER, "identifier", &t)) { |
1447 *dest = t.fText; | 1448 *dest = t.fText; |
1448 return true; | 1449 return true; |
1449 } | 1450 } |
1450 return false; | 1451 return false; |
1451 } | 1452 } |
1452 | 1453 |
1453 } // namespace | 1454 } // namespace |
OLD | NEW |