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 "SkSLIRGenerator.h" | 8 #include "SkSLIRGenerator.h" |
9 | 9 |
10 #include "limits.h" | 10 #include "limits.h" |
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
518 | 518 |
519 std::unique_ptr<InterfaceBlock> IRGenerator::convertInterfaceBlock(const ASTInte
rfaceBlock& intf) { | 519 std::unique_ptr<InterfaceBlock> IRGenerator::convertInterfaceBlock(const ASTInte
rfaceBlock& intf) { |
520 std::shared_ptr<SymbolTable> old = fSymbolTable; | 520 std::shared_ptr<SymbolTable> old = fSymbolTable; |
521 AutoSymbolTable table(this); | 521 AutoSymbolTable table(this); |
522 Modifiers mods = this->convertModifiers(intf.fModifiers); | 522 Modifiers mods = this->convertModifiers(intf.fModifiers); |
523 std::vector<Type::Field> fields; | 523 std::vector<Type::Field> fields; |
524 for (size_t i = 0; i < intf.fDeclarations.size(); i++) { | 524 for (size_t i = 0; i < intf.fDeclarations.size(); i++) { |
525 std::unique_ptr<VarDeclarations> decl = this->convertVarDeclarations( | 525 std::unique_ptr<VarDeclarations> decl = this->convertVarDeclarations( |
526 *intf.f
Declarations[i], | 526 *intf.f
Declarations[i], |
527 Variabl
e::kGlobal_Storage); | 527 Variabl
e::kGlobal_Storage); |
| 528 if (!decl) { |
| 529 return nullptr; |
| 530 } |
528 for (const auto& var : decl->fVars) { | 531 for (const auto& var : decl->fVars) { |
529 fields.push_back(Type::Field(var.fVar->fModifiers, var.fVar->fName, | 532 fields.push_back(Type::Field(var.fVar->fModifiers, var.fVar->fName, |
530 &var.fVar->fType)); | 533 &var.fVar->fType)); |
531 if (var.fValue) { | 534 if (var.fValue) { |
532 fErrors.error(decl->fPosition, | 535 fErrors.error(decl->fPosition, |
533 "initializers are not permitted on interface block
fields"); | 536 "initializers are not permitted on interface block
fields"); |
534 } | 537 } |
535 if (var.fVar->fModifiers.fFlags & (Modifiers::kIn_Flag | | 538 if (var.fVar->fModifiers.fFlags & (Modifiers::kIn_Flag | |
536 Modifiers::kOut_Flag | | 539 Modifiers::kOut_Flag | |
537 Modifiers::kUniform_Flag | | 540 Modifiers::kUniform_Flag | |
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1017 } else { | 1020 } else { |
1018 ASSERT(kind == Type::kVector_Kind || kind == Type::kMatrix_Kind); | 1021 ASSERT(kind == Type::kVector_Kind || kind == Type::kMatrix_Kind); |
1019 int actual = 0; | 1022 int actual = 0; |
1020 for (size_t i = 0; i < args.size(); i++) { | 1023 for (size_t i = 0; i < args.size(); i++) { |
1021 if (args[i]->fType.kind() == Type::kVector_Kind || | 1024 if (args[i]->fType.kind() == Type::kVector_Kind || |
1022 args[i]->fType.kind() == Type::kMatrix_Kind) { | 1025 args[i]->fType.kind() == Type::kMatrix_Kind) { |
1023 int columns = args[i]->fType.columns(); | 1026 int columns = args[i]->fType.columns(); |
1024 int rows = args[i]->fType.rows(); | 1027 int rows = args[i]->fType.rows(); |
1025 args[i] = this->coerce(std::move(args[i]), | 1028 args[i] = this->coerce(std::move(args[i]), |
1026 type.componentType().toCompound(fContext,
columns, rows)); | 1029 type.componentType().toCompound(fContext,
columns, rows)); |
| 1030 if (!args[i]) { |
| 1031 return nullptr; |
| 1032 } |
1027 actual += args[i]->fType.rows() * args[i]->fType.columns(); | 1033 actual += args[i]->fType.rows() * args[i]->fType.columns(); |
1028 } else if (args[i]->fType.kind() == Type::kScalar_Kind) { | 1034 } else if (args[i]->fType.kind() == Type::kScalar_Kind) { |
1029 actual += 1; | 1035 actual += 1; |
1030 if (type.kind() != Type::kScalar_Kind) { | 1036 if (type.kind() != Type::kScalar_Kind) { |
1031 args[i] = this->coerce(std::move(args[i]), type.componentTyp
e()); | 1037 args[i] = this->coerce(std::move(args[i]), type.componentTyp
e()); |
| 1038 if (!args[i]) { |
| 1039 return nullptr; |
| 1040 } |
1032 } | 1041 } |
1033 } else { | 1042 } else { |
1034 fErrors.error(position, "'" + args[i]->fType.description() + "'
is not a valid " | 1043 fErrors.error(position, "'" + args[i]->fType.description() + "'
is not a valid " |
1035 "parameter to '" + type.description() +
"' constructor"); | 1044 "parameter to '" + type.description() +
"' constructor"); |
1036 return nullptr; | 1045 return nullptr; |
1037 } | 1046 } |
1038 } | 1047 } |
1039 int min = type.rows() * type.columns(); | 1048 int min = type.rows() * type.columns(); |
1040 int max = type.columns() > 1 ? INT_MAX : min; | 1049 int max = type.columns() > 1 ? INT_MAX : min; |
1041 if ((actual < min || actual > max) && | 1050 if ((actual < min || actual > max) && |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1221 return this->convertIndex(std::move(base), *expr); | 1230 return this->convertIndex(std::move(base), *expr); |
1222 } else if (base->fKind == Expression::kTypeReference_Kind) { | 1231 } else if (base->fKind == Expression::kTypeReference_Kind) { |
1223 const Type& oldType = ((TypeReference&) *base).fValue; | 1232 const Type& oldType = ((TypeReference&) *base).fValue; |
1224 Type* newType = new Type(oldType.name() + "[]", Type::kArray_Kin
d, oldType, | 1233 Type* newType = new Type(oldType.name() + "[]", Type::kArray_Kin
d, oldType, |
1225 -1); | 1234 -1); |
1226 fSymbolTable->takeOwnership(newType); | 1235 fSymbolTable->takeOwnership(newType); |
1227 return std::unique_ptr<Expression>(new TypeReference(fContext, b
ase->fPosition, | 1236 return std::unique_ptr<Expression>(new TypeReference(fContext, b
ase->fPosition, |
1228 *newType)); | 1237 *newType)); |
1229 } else { | 1238 } else { |
1230 fErrors.error(expression.fPosition, "'[]' must follow a type nam
e"); | 1239 fErrors.error(expression.fPosition, "'[]' must follow a type nam
e"); |
| 1240 return nullptr; |
1231 } | 1241 } |
1232 } | 1242 } |
1233 case ASTSuffix::kCall_Kind: { | 1243 case ASTSuffix::kCall_Kind: { |
1234 auto rawArguments = &((ASTCallSuffix&) *expression.fSuffix).fArgumen
ts; | 1244 auto rawArguments = &((ASTCallSuffix&) *expression.fSuffix).fArgumen
ts; |
1235 std::vector<std::unique_ptr<Expression>> arguments; | 1245 std::vector<std::unique_ptr<Expression>> arguments; |
1236 for (size_t i = 0; i < rawArguments->size(); i++) { | 1246 for (size_t i = 0; i < rawArguments->size(); i++) { |
1237 std::unique_ptr<Expression> converted = | 1247 std::unique_ptr<Expression> converted = |
1238 this->convertExpression(*(*rawArguments)[i]); | 1248 this->convertExpression(*(*rawArguments)[i]); |
1239 if (!converted) { | 1249 if (!converted) { |
1240 return nullptr; | 1250 return nullptr; |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1335 case Expression::kIndex_Kind: | 1345 case Expression::kIndex_Kind: |
1336 this->markWrittenTo(*((IndexExpression&) expr).fBase); | 1346 this->markWrittenTo(*((IndexExpression&) expr).fBase); |
1337 break; | 1347 break; |
1338 default: | 1348 default: |
1339 fErrors.error(expr.fPosition, "cannot assign to '" + expr.descriptio
n() + "'"); | 1349 fErrors.error(expr.fPosition, "cannot assign to '" + expr.descriptio
n() + "'"); |
1340 break; | 1350 break; |
1341 } | 1351 } |
1342 } | 1352 } |
1343 | 1353 |
1344 } | 1354 } |
OLD | NEW |