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 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 if (!this->expect(Token::LBRACE, "'{'")) { | 283 if (!this->expect(Token::LBRACE, "'{'")) { |
284 return nullptr; | 284 return nullptr; |
285 } | 285 } |
286 std::vector<Type::Field> fields; | 286 std::vector<Type::Field> fields; |
287 while (this->peek().fKind != Token::RBRACE) { | 287 while (this->peek().fKind != Token::RBRACE) { |
288 std::unique_ptr<ASTVarDeclaration> decl = this->varDeclaration(); | 288 std::unique_ptr<ASTVarDeclaration> decl = this->varDeclaration(); |
289 if (!decl) { | 289 if (!decl) { |
290 return nullptr; | 290 return nullptr; |
291 } | 291 } |
292 for (size_t i = 0; i < decl->fNames.size(); i++) { | 292 for (size_t i = 0; i < decl->fNames.size(); i++) { |
293 auto type = std::static_pointer_cast<Type>(fTypes[decl->fType->fName
]); | 293 auto type = (const Type*) fTypes[decl->fType->fName]; |
294 for (int j = (int) decl->fSizes[i].size() - 1; j >= 0; j--) { | 294 for (int j = (int) decl->fSizes[i].size() - 1; j >= 0; j--) { |
295 if (decl->fSizes[i][j]->fKind == ASTExpression::kInt_Kind) { | 295 if (decl->fSizes[i][j]->fKind != ASTExpression::kInt_Kind) { |
296 this->error(decl->fPosition, "array size in struct field mus
t be a constant"); | 296 this->error(decl->fPosition, "array size in struct field mus
t be a constant"); |
297 } | 297 } |
298 uint64_t columns = ((ASTIntLiteral&) *decl->fSizes[i][j]).fValue
; | 298 uint64_t columns = ((ASTIntLiteral&) *decl->fSizes[i][j]).fValue
; |
299 std::string name = type->name() + "[" + to_string(columns) + "]"
; | 299 std::string name = type->name() + "[" + to_string(columns) + "]"
; |
300 type = std::shared_ptr<Type>(new Type(name, Type::kArray_Kind, s
td::move(type), | 300 type = new Type(name, Type::kArray_Kind, *type, (int) columns); |
301 (int) columns)); | 301 fTypes.takeOwnership((Type*) type); |
302 } | 302 } |
303 fields.push_back(Type::Field(decl->fModifiers, decl->fNames[i], std:
:move(type))); | 303 fields.push_back(Type::Field(decl->fModifiers, decl->fNames[i], *typ
e)); |
304 if (decl->fValues[i]) { | 304 if (decl->fValues[i]) { |
305 this->error(decl->fPosition, "initializers are not permitted on
struct fields"); | 305 this->error(decl->fPosition, "initializers are not permitted on
struct fields"); |
306 } | 306 } |
307 } | 307 } |
308 } | 308 } |
309 if (!this->expect(Token::RBRACE, "'}'")) { | 309 if (!this->expect(Token::RBRACE, "'}'")) { |
310 return nullptr; | 310 return nullptr; |
311 } | 311 } |
312 std::shared_ptr<Type> type(new Type(name.fText, fields)); | 312 Type* type = new Type(name.fText, fields); |
313 fTypes.add(type->fName, type); | 313 fTypes.add(type->fName, type); |
314 return std::unique_ptr<ASTType>(new ASTType(name.fPosition, type->fName, | 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; |
(...skipping 1059 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 |
OLD | NEW |