Chromium Code Reviews| 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" | |
| 11 #include "SkSLModifiers.h" | 12 #include "SkSLModifiers.h" |
| 12 #include "SkSLSymbol.h" | 13 #include "SkSLSymbol.h" |
| 13 #include "SkSLSymbolTable.h" | 14 #include "SkSLSymbolTable.h" |
| 14 #include "SkSLType.h" | 15 #include "SkSLType.h" |
| 15 #include "SkSLVariable.h" | 16 #include "SkSLVariable.h" |
| 16 | 17 |
| 17 namespace SkSL { | 18 namespace SkSL { |
| 18 | 19 |
| 19 /** | 20 /** |
| 20 * A function declaration (not a definition -- does not contain a body). | 21 * A function declaration (not a definition -- does not contain a body). |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 48 return false; | 49 return false; |
| 49 } | 50 } |
| 50 for (size_t i = 0; i < fParameters.size(); i++) { | 51 for (size_t i = 0; i < fParameters.size(); i++) { |
| 51 if (fParameters[i]->fType != f.fParameters[i]->fType) { | 52 if (fParameters[i]->fType != f.fParameters[i]->fType) { |
| 52 return false; | 53 return false; |
| 53 } | 54 } |
| 54 } | 55 } |
| 55 return true; | 56 return true; |
| 56 } | 57 } |
| 57 | 58 |
| 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])) { | |
|
dogben
2016/10/25 13:56:50
Is it always the case that a generic type's coerci
| |
| 81 genericIndex = j; | |
| 82 break; | |
| 83 } | |
| 84 } | |
| 85 if (genericIndex == -1) { | |
| 86 return false; | |
| 87 } | |
| 88 } | |
|
dogben
2016/10/25 13:56:50
Do we need a range check here? i.e.
...
} else {
| |
| 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 | |
| 58 mutable bool fDefined; | 103 mutable bool fDefined; |
| 59 bool fBuiltin; | 104 bool fBuiltin; |
| 60 const std::vector<const Variable*> fParameters; | 105 const std::vector<const Variable*> fParameters; |
| 61 const Type& fReturnType; | 106 const Type& fReturnType; |
| 62 | 107 |
| 63 typedef Symbol INHERITED; | 108 typedef Symbol INHERITED; |
| 64 }; | 109 }; |
| 65 | 110 |
| 66 } // namespace | 111 } // namespace |
| 67 | 112 |
| 68 #endif | 113 #endif |
| OLD | NEW |