| 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 #ifndef SKSL_FUNCTIONDECLARATION | 8 #ifndef SKSL_FUNCTIONDECLARATION |
| 9 #define SKSL_FUNCTIONDECLARATION | 9 #define SKSL_FUNCTIONDECLARATION |
| 10 | 10 |
| 11 #include "SkSLExpression.h" | |
| 12 #include "SkSLModifiers.h" | 11 #include "SkSLModifiers.h" |
| 13 #include "SkSLSymbol.h" | 12 #include "SkSLSymbol.h" |
| 14 #include "SkSLSymbolTable.h" | 13 #include "SkSLSymbolTable.h" |
| 15 #include "SkSLType.h" | 14 #include "SkSLType.h" |
| 16 #include "SkSLVariable.h" | 15 #include "SkSLVariable.h" |
| 17 | 16 |
| 18 namespace SkSL { | 17 namespace SkSL { |
| 19 | 18 |
| 20 /** | 19 /** |
| 21 * A function declaration (not a definition -- does not contain a body). | 20 * A function declaration (not a definition -- does not contain a body). |
| (...skipping 27 matching lines...) Expand all Loading... |
| 49 return false; | 48 return false; |
| 50 } | 49 } |
| 51 for (size_t i = 0; i < fParameters.size(); i++) { | 50 for (size_t i = 0; i < fParameters.size(); i++) { |
| 52 if (fParameters[i]->fType != f.fParameters[i]->fType) { | 51 if (fParameters[i]->fType != f.fParameters[i]->fType) { |
| 53 return false; | 52 return false; |
| 54 } | 53 } |
| 55 } | 54 } |
| 56 return true; | 55 return true; |
| 57 } | 56 } |
| 58 | 57 |
| 59 /** | |
| 60 * Determine the effective types of this function's parameters and return va
lue when called with | |
| 61 * the given arguments. This is relevant for functions with generic paramete
r types, where this | |
| 62 * will collapse the generic types down into specific concrete types. | |
| 63 * | |
| 64 * Returns true if it was able to select a concrete set of types for the gen
eric function, false | |
| 65 * if there is no possible way this can match the argument types. Note that
even a true return | |
| 66 * does not guarantee that the function can be successfully called with thos
e arguments, merely | |
| 67 * indicates that an attempt should be made. If false is returned, the state
of | |
| 68 * outParameterTypes and outReturnType are undefined. | |
| 69 */ | |
| 70 bool determineFinalTypes(const std::vector<std::unique_ptr<Expression>>& arg
uments, | |
| 71 std::vector<const Type*>* outParameterTypes, | |
| 72 const Type** outReturnType) const { | |
| 73 assert(arguments.size() == fParameters.size()); | |
| 74 int genericIndex = -1; | |
| 75 for (size_t i = 0; i < arguments.size(); i++) { | |
| 76 if (fParameters[i]->fType.kind() == Type::kGeneric_Kind) { | |
| 77 std::vector<const Type*> types = fParameters[i]->fType.coercible
Types(); | |
| 78 if (genericIndex == -1) { | |
| 79 for (size_t j = 0; j < types.size(); j++) { | |
| 80 if (arguments[i]->fType.canCoerceTo(*types[j])) { | |
| 81 genericIndex = j; | |
| 82 break; | |
| 83 } | |
| 84 } | |
| 85 if (genericIndex == -1) { | |
| 86 return false; | |
| 87 } | |
| 88 } | |
| 89 outParameterTypes->push_back(types[genericIndex]); | |
| 90 } else { | |
| 91 outParameterTypes->push_back(&fParameters[i]->fType); | |
| 92 } | |
| 93 } | |
| 94 if (fReturnType.kind() == Type::kGeneric_Kind) { | |
| 95 assert(genericIndex != -1); | |
| 96 *outReturnType = fReturnType.coercibleTypes()[genericIndex]; | |
| 97 } else { | |
| 98 *outReturnType = &fReturnType; | |
| 99 } | |
| 100 return true; | |
| 101 } | |
| 102 | |
| 103 mutable bool fDefined; | 58 mutable bool fDefined; |
| 104 bool fBuiltin; | 59 bool fBuiltin; |
| 105 const std::vector<const Variable*> fParameters; | 60 const std::vector<const Variable*> fParameters; |
| 106 const Type& fReturnType; | 61 const Type& fReturnType; |
| 107 | 62 |
| 108 typedef Symbol INHERITED; | 63 typedef Symbol INHERITED; |
| 109 }; | 64 }; |
| 110 | 65 |
| 111 } // namespace | 66 } // namespace |
| 112 | 67 |
| 113 #endif | 68 #endif |
| OLD | NEW |