| 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 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 FunctionDeclaration newDecl(f.fPosition, f.fName, parame
ters, *returnType); | 412 FunctionDeclaration newDecl(f.fPosition, f.fName, parame
ters, *returnType); |
| 413 fErrors.error(f.fPosition, "functions '" + newDecl.descr
iption() + | 413 fErrors.error(f.fPosition, "functions '" + newDecl.descr
iption() + |
| 414 "' and '" + other->descriptio
n() + | 414 "' and '" + other->descriptio
n() + |
| 415 "' differ only in return type
"); | 415 "' differ only in return type
"); |
| 416 return nullptr; | 416 return nullptr; |
| 417 } | 417 } |
| 418 decl = other; | 418 decl = other; |
| 419 for (size_t i = 0; i < parameters.size(); i++) { | 419 for (size_t i = 0; i < parameters.size(); i++) { |
| 420 if (parameters[i]->fModifiers != other->fParameters[i]->
fModifiers) { | 420 if (parameters[i]->fModifiers != other->fParameters[i]->
fModifiers) { |
| 421 fErrors.error(f.fPosition, "modifiers on parameter "
+ | 421 fErrors.error(f.fPosition, "modifiers on parameter "
+ |
| 422 to_string((uint64_t) i +
1) + | 422 to_string(i + 1) + " diff
er between " + |
| 423 " differ between declarat
ion and " | 423 "declaration and definiti
on"); |
| 424 "definition"); | |
| 425 return nullptr; | 424 return nullptr; |
| 426 } | 425 } |
| 427 } | 426 } |
| 428 if (other->fDefined) { | 427 if (other->fDefined) { |
| 429 fErrors.error(f.fPosition, "duplicate definition of " + | 428 fErrors.error(f.fPosition, "duplicate definition of " + |
| 430 other->description()); | 429 other->description()); |
| 431 } | 430 } |
| 432 break; | 431 break; |
| 433 } | 432 } |
| 434 } | 433 } |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 610 return nullptr; | 609 return nullptr; |
| 611 } | 610 } |
| 612 if (type.kind() == Type::kScalar_Kind) { | 611 if (type.kind() == Type::kScalar_Kind) { |
| 613 std::vector<std::unique_ptr<Expression>> args; | 612 std::vector<std::unique_ptr<Expression>> args; |
| 614 args.push_back(std::move(expr)); | 613 args.push_back(std::move(expr)); |
| 615 ASTIdentifier id(Position(), type.description()); | 614 ASTIdentifier id(Position(), type.description()); |
| 616 std::unique_ptr<Expression> ctor = this->convertIdentifier(id); | 615 std::unique_ptr<Expression> ctor = this->convertIdentifier(id); |
| 617 ASSERT(ctor); | 616 ASSERT(ctor); |
| 618 return this->call(Position(), std::move(ctor), std::move(args)); | 617 return this->call(Position(), std::move(ctor), std::move(args)); |
| 619 } | 618 } |
| 620 std::vector<std::unique_ptr<Expression>> args; | 619 ABORT("cannot coerce %s to %s", expr->fType.description().c_str(), |
| 621 args.push_back(std::move(expr)); | 620 type.description().c_str()); |
| 622 return std::unique_ptr<Expression>(new Constructor(Position(), type, std::mo
ve(args))); | |
| 623 } | 621 } |
| 624 | 622 |
| 625 static bool is_matrix_multiply(const Type& left, const Type& right) { | 623 static bool is_matrix_multiply(const Type& left, const Type& right) { |
| 626 if (left.kind() == Type::kMatrix_Kind) { | 624 if (left.kind() == Type::kMatrix_Kind) { |
| 627 return right.kind() == Type::kMatrix_Kind || right.kind() == Type::kVect
or_Kind; | 625 return right.kind() == Type::kMatrix_Kind || right.kind() == Type::kVect
or_Kind; |
| 628 } | 626 } |
| 629 return left.kind() == Type::kVector_Kind && right.kind() == Type::kMatrix_Ki
nd; | 627 return left.kind() == Type::kVector_Kind && right.kind() == Type::kMatrix_Ki
nd; |
| 630 } | 628 } |
| 631 /** | 629 /** |
| 632 * Determines the operand and result types of a binary expression. Returns true
if the expression is | 630 * Determines the operand and result types of a binary expression. Returns true
if the expression is |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 827 std::move(test), | 825 std::move(test), |
| 828 std::move(ifTrue), | 826 std::move(ifTrue), |
| 829 std::move(ifFalse))
); | 827 std::move(ifFalse))
); |
| 830 } | 828 } |
| 831 | 829 |
| 832 std::unique_ptr<Expression> IRGenerator::call(Position position, | 830 std::unique_ptr<Expression> IRGenerator::call(Position position, |
| 833 const FunctionDeclaration& functio
n, | 831 const FunctionDeclaration& functio
n, |
| 834 std::vector<std::unique_ptr<Expres
sion>> arguments) { | 832 std::vector<std::unique_ptr<Expres
sion>> arguments) { |
| 835 if (function.fParameters.size() != arguments.size()) { | 833 if (function.fParameters.size() != arguments.size()) { |
| 836 std::string msg = "call to '" + function.fName + "' expected " + | 834 std::string msg = "call to '" + function.fName + "' expected " + |
| 837 to_string((uint64_t) function.fParameters.size(
)) + | 835 to_string(function.fParameters.size()) + |
| 838 " argument"; | 836 " argument"; |
| 839 if (function.fParameters.size() != 1) { | 837 if (function.fParameters.size() != 1) { |
| 840 msg += "s"; | 838 msg += "s"; |
| 841 } | 839 } |
| 842 msg += ", but found " + to_string((uint64_t) arguments.size()); | 840 msg += ", but found " + to_string(arguments.size()); |
| 843 fErrors.error(position, msg); | 841 fErrors.error(position, msg); |
| 844 return nullptr; | 842 return nullptr; |
| 845 } | 843 } |
| 846 for (size_t i = 0; i < arguments.size(); i++) { | 844 for (size_t i = 0; i < arguments.size(); i++) { |
| 847 arguments[i] = this->coerce(std::move(arguments[i]), function.fParameter
s[i]->fType); | 845 arguments[i] = this->coerce(std::move(arguments[i]), function.fParameter
s[i]->fType); |
| 848 if (arguments[i] && (function.fParameters[i]->fModifiers.fFlags & Modifi
ers::kOut_Flag)) { | 846 if (arguments[i] && (function.fParameters[i]->fModifiers.fFlags & Modifi
ers::kOut_Flag)) { |
| 849 this->markWrittenTo(*arguments[i]); | 847 this->markWrittenTo(*arguments[i]); |
| 850 } | 848 } |
| 851 } | 849 } |
| 852 return std::unique_ptr<FunctionCall>(new FunctionCall(position, function, | 850 return std::unique_ptr<FunctionCall>(new FunctionCall(position, function, |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 933 return std::unique_ptr<Expression>(new FloatLiteral(fContext, position,
(double) value)); | 931 return std::unique_ptr<Expression>(new FloatLiteral(fContext, position,
(double) value)); |
| 934 } | 932 } |
| 935 if (args.size() == 1 && args[0]->fType == type) { | 933 if (args.size() == 1 && args[0]->fType == type) { |
| 936 // argument is already the right type, just return it | 934 // argument is already the right type, just return it |
| 937 return std::move(args[0]); | 935 return std::move(args[0]); |
| 938 } | 936 } |
| 939 if (type.isNumber()) { | 937 if (type.isNumber()) { |
| 940 if (args.size() != 1) { | 938 if (args.size() != 1) { |
| 941 fErrors.error(position, "invalid arguments to '" + type.description(
) + | 939 fErrors.error(position, "invalid arguments to '" + type.description(
) + |
| 942 "' constructor, (expected exactly 1 argument
, but found " + | 940 "' constructor, (expected exactly 1 argument
, but found " + |
| 943 to_string((uint64_t) args.size()) + ")"); | 941 to_string(args.size()) + ")"); |
| 944 } | 942 } |
| 945 if (args[0]->fType == *fContext.fBool_Type) { | 943 if (args[0]->fType == *fContext.fBool_Type) { |
| 946 std::unique_ptr<IntLiteral> zero(new IntLiteral(fContext, position,
0)); | 944 std::unique_ptr<IntLiteral> zero(new IntLiteral(fContext, position,
0)); |
| 947 std::unique_ptr<IntLiteral> one(new IntLiteral(fContext, position, 1
)); | 945 std::unique_ptr<IntLiteral> one(new IntLiteral(fContext, position, 1
)); |
| 948 return std::unique_ptr<Expression>( | 946 return std::unique_ptr<Expression>( |
| 949 new TernaryExpression(position, std::mo
ve(args[0]), | 947 new TernaryExpression(position, std::mo
ve(args[0]), |
| 950 this->coerce(std:
:move(one), type), | 948 this->coerce(std:
:move(one), type), |
| 951 this->coerce(std:
:move(zero), | 949 this->coerce(std:
:move(zero), |
| 952 type
))); | 950 type
))); |
| 953 } else if (!args[0]->fType.isNumber()) { | 951 } else if (!args[0]->fType.isNumber()) { |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1253 case Expression::kIndex_Kind: | 1251 case Expression::kIndex_Kind: |
| 1254 this->markWrittenTo(*((IndexExpression&) expr).fBase); | 1252 this->markWrittenTo(*((IndexExpression&) expr).fBase); |
| 1255 break; | 1253 break; |
| 1256 default: | 1254 default: |
| 1257 fErrors.error(expr.fPosition, "cannot assign to '" + expr.descriptio
n() + "'"); | 1255 fErrors.error(expr.fPosition, "cannot assign to '" + expr.descriptio
n() + "'"); |
| 1258 break; | 1256 break; |
| 1259 } | 1257 } |
| 1260 } | 1258 } |
| 1261 | 1259 |
| 1262 } | 1260 } |
| OLD | NEW |