src/typechecker/FunctionManager.cpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // Copyright (c) 2021-2026 ChilliBits. All rights reserved. | ||
| 2 | |||
| 3 | #include "FunctionManager.h" | ||
| 4 | |||
| 5 | #include <limits> | ||
| 6 | |||
| 7 | #include <ast/ASTNodes.h> | ||
| 8 | #include <exception/SemanticError.h> | ||
| 9 | #include <model/GenericType.h> | ||
| 10 | #include <symboltablebuilder/Scope.h> | ||
| 11 | #include <symboltablebuilder/SymbolTableBuilder.h> | ||
| 12 | #include <typechecker/TypeChecker.h> | ||
| 13 | #include <typechecker/TypeMatcher.h> | ||
| 14 | #include <util/CodeLoc.h> | ||
| 15 | #include <util/CustomHashFunctions.h> | ||
| 16 | |||
| 17 | namespace spice::compiler { | ||
| 18 | |||
| 19 | // Static member initialization | ||
| 20 | std::unordered_map<uint64_t, Function *> FunctionManager::lookupCache = {}; | ||
| 21 | size_t FunctionManager::lookupCacheHits = 0; | ||
| 22 | size_t FunctionManager::lookupCacheMisses = 0; | ||
| 23 | |||
| 24 | 35949 | Function *FunctionManager::insert(Scope *insertScope, const Function &baseFunction, std::vector<Function *> *nodeFunctionList) { | |
| 25 | // Open a new manifestation list for the function definition | ||
| 26 |
3/6✓ Branch 2 → 3 taken 35949 times.
✗ Branch 2 → 49 not taken.
✓ Branch 3 → 4 taken 35949 times.
✗ Branch 3 → 46 not taken.
✓ Branch 4 → 5 taken 35949 times.
✗ Branch 4 → 44 not taken.
|
35949 | const std::string fctId = baseFunction.name + ":" + baseFunction.declNode->codeLoc.toPrettyLineAndColumn(); |
| 27 |
1/2✓ Branch 8 → 9 taken 35949 times.
✗ Branch 8 → 50 not taken.
|
35949 | insertScope->functions.emplace(fctId, FunctionManifestationList()); |
| 28 | |||
| 29 | // Collect substantiations | ||
| 30 | 35949 | std::vector<Function> manifestations; | |
| 31 |
1/2✓ Branch 10 → 11 taken 35949 times.
✗ Branch 10 → 54 not taken.
|
35949 | substantiateOptionalParams(baseFunction, manifestations); |
| 32 |
1/2✗ Branch 12 → 13 not taken.
✓ Branch 12 → 14 taken 35949 times.
|
35949 | assert(!manifestations.empty()); |
| 33 | |||
| 34 | // Save substantiations in declaration node | ||
| 35 | 35949 | Function *manifestationPtr = nullptr; | |
| 36 |
2/2✓ Branch 32 → 16 taken 38164 times.
✓ Branch 32 → 33 taken 35947 times.
|
110060 | for (const Function &manifestation : manifestations) { |
| 37 |
2/2✓ Branch 18 → 19 taken 38162 times.
✓ Branch 18 → 53 taken 2 times.
|
38164 | manifestationPtr = insertSubstantiation(insertScope, manifestation, baseFunction.declNode); |
| 38 |
1/2✗ Branch 19 → 20 not taken.
✓ Branch 19 → 21 taken 38162 times.
|
38162 | assert(manifestationPtr != nullptr); |
| 39 |
1/2✓ Branch 21 → 22 taken 38162 times.
✗ Branch 21 → 23 not taken.
|
38162 | if (nodeFunctionList) |
| 40 |
1/2✓ Branch 22 → 23 taken 38162 times.
✗ Branch 22 → 53 not taken.
|
38162 | nodeFunctionList->push_back(manifestationPtr); |
| 41 | } | ||
| 42 | |||
| 43 |
1/2✗ Branch 33 → 34 not taken.
✓ Branch 33 → 35 taken 35947 times.
|
35947 | if (!nodeFunctionList) |
| 44 | ✗ | return manifestationPtr; | |
| 45 | |||
| 46 |
1/2✗ Branch 36 → 37 not taken.
✓ Branch 36 → 38 taken 35947 times.
|
35947 | assert(!nodeFunctionList->empty()); |
| 47 | 35947 | return nodeFunctionList->front(); | |
| 48 | 35951 | } | |
| 49 | |||
| 50 | /** | ||
| 51 | * Create definite functions from ambiguous ones, in regard to optional arguments. | ||
| 52 | * | ||
| 53 | * Example: | ||
| 54 | * int testFunc(string, int?, double?) | ||
| 55 | * gets | ||
| 56 | * int testFunc(string) | ||
| 57 | * int testFunc(string, int) | ||
| 58 | * int testFunc(string, int, double) | ||
| 59 | * | ||
| 60 | * This method also accepts functions, that are already definite, but does nothing to them. | ||
| 61 | * | ||
| 62 | * @param baseFunction Ambiguous base function | ||
| 63 | * @param manifestations Vector to store the definite manifestations | ||
| 64 | * @return True, if there were optional arguments found | ||
| 65 | */ | ||
| 66 | 35949 | void FunctionManager::substantiateOptionalParams(const Function &baseFunction, std::vector<Function> &manifestations) { | |
| 67 | // Handle the case of no parameters -> simply return the base function | ||
| 68 |
2/2✓ Branch 3 → 4 taken 9983 times.
✓ Branch 3 → 6 taken 25966 times.
|
35949 | if (baseFunction.paramList.empty()) { |
| 69 |
1/2✓ Branch 4 → 5 taken 9983 times.
✗ Branch 4 → 47 not taken.
|
9983 | manifestations.push_back(baseFunction); |
| 70 | 9983 | return; | |
| 71 | } | ||
| 72 | |||
| 73 | 25966 | ParamList currentFunctionParamTypes; | |
| 74 |
1/2✓ Branch 7 → 8 taken 25966 times.
✗ Branch 7 → 45 not taken.
|
25966 | currentFunctionParamTypes.reserve(baseFunction.paramList.size()); |
| 75 | 25966 | bool metFirstOptionalParam = false; | |
| 76 |
1/2✓ Branch 8 → 9 taken 25966 times.
✗ Branch 8 → 45 not taken.
|
25966 | Function manifestation = baseFunction; |
| 77 | |||
| 78 | // Loop over all parameters | ||
| 79 |
2/2✓ Branch 32 → 11 taken 39866 times.
✓ Branch 32 → 33 taken 25966 times.
|
91798 | for (const auto &[qualType, isOptional] : baseFunction.paramList) { |
| 80 | // Check if we have a mandatory parameter | ||
| 81 |
2/2✓ Branch 13 → 14 taken 37651 times.
✓ Branch 13 → 16 taken 2215 times.
|
39866 | if (!isOptional) { |
| 82 |
1/2✓ Branch 14 → 15 taken 37651 times.
✗ Branch 14 → 40 not taken.
|
37651 | currentFunctionParamTypes.push_back({qualType, /*optional=*/false}); |
| 83 | 37651 | continue; | |
| 84 | } | ||
| 85 | |||
| 86 | // Add substantiation without the optional parameter | ||
| 87 |
2/2✓ Branch 16 → 17 taken 2101 times.
✓ Branch 16 → 20 taken 114 times.
|
2215 | if (!metFirstOptionalParam) { |
| 88 |
1/2✓ Branch 17 → 18 taken 2101 times.
✗ Branch 17 → 42 not taken.
|
2101 | manifestation.paramList = currentFunctionParamTypes; |
| 89 |
1/2✓ Branch 18 → 19 taken 2101 times.
✗ Branch 18 → 42 not taken.
|
2101 | manifestations.push_back(manifestation); |
| 90 | // Now we cannot accept mandatory parameters anymore | ||
| 91 | 2101 | metFirstOptionalParam = true; | |
| 92 | } | ||
| 93 | |||
| 94 | // Add substantiation with the optional parameter | ||
| 95 |
1/2✓ Branch 20 → 21 taken 2215 times.
✗ Branch 20 → 41 not taken.
|
2215 | currentFunctionParamTypes.push_back({qualType, /*optional=*/false}); |
| 96 |
1/2✓ Branch 21 → 22 taken 2215 times.
✗ Branch 21 → 42 not taken.
|
2215 | manifestation.paramList = currentFunctionParamTypes; |
| 97 |
1/2✓ Branch 22 → 23 taken 2215 times.
✗ Branch 22 → 42 not taken.
|
2215 | manifestations.push_back(manifestation); |
| 98 | } | ||
| 99 | |||
| 100 | // Ensure at least once manifestation | ||
| 101 |
2/2✓ Branch 34 → 35 taken 23865 times.
✓ Branch 34 → 36 taken 2101 times.
|
25966 | if (manifestations.empty()) |
| 102 |
1/2✓ Branch 35 → 36 taken 23865 times.
✗ Branch 35 → 43 not taken.
|
23865 | manifestations.push_back(baseFunction); |
| 103 | 25966 | } | |
| 104 | |||
| 105 | 6 | Function FunctionManager::createMainFunction(SymbolTableEntry *entry, const QualTypeList ¶mTypes, ASTNode *declNode) { | |
| 106 | 6 | ParamList paramList; | |
| 107 |
2/2✓ Branch 16 → 4 taken 2 times.
✓ Branch 16 → 17 taken 6 times.
|
14 | for (const QualType ¶mType : paramTypes) |
| 108 |
1/2✓ Branch 6 → 7 taken 2 times.
✗ Branch 6 → 33 not taken.
|
2 | paramList.push_back({paramType, false}); |
| 109 |
5/10✓ Branch 19 → 20 taken 6 times.
✗ Branch 19 → 45 not taken.
✓ Branch 20 → 21 taken 6 times.
✗ Branch 20 → 42 not taken.
✓ Branch 21 → 22 taken 6 times.
✗ Branch 21 → 41 not taken.
✓ Branch 22 → 23 taken 6 times.
✗ Branch 22 → 40 not taken.
✓ Branch 24 → 25 taken 6 times.
✗ Branch 24 → 35 not taken.
|
18 | return {MAIN_FUNCTION_NAME, entry, QualType(TY_DYN), QualType(TY_INT), paramList, {}, declNode}; |
| 110 | 6 | } | |
| 111 | |||
| 112 | 49086 | Function *FunctionManager::insertSubstantiation(Scope *insertScope, const Function &newManifestation, const ASTNode *declNode) { | |
| 113 |
2/4✓ Branch 2 → 3 taken 49086 times.
✗ Branch 2 → 70 not taken.
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 49086 times.
|
49086 | assert(newManifestation.hasSubstantiatedParams()); |
| 114 | |||
| 115 |
1/2✓ Branch 5 → 6 taken 49086 times.
✗ Branch 5 → 70 not taken.
|
49086 | const std::string signature = newManifestation.getSignature(true, true, false, true); |
| 116 | |||
| 117 | // Check if the function exists already | ||
| 118 |
5/8✓ Branch 6 → 7 taken 49086 times.
✗ Branch 6 → 59 not taken.
✓ Branch 7 → 8 taken 49086 times.
✗ Branch 7 → 59 not taken.
✓ Branch 8 → 9 taken 49086 times.
✗ Branch 8 → 59 not taken.
✓ Branch 30 → 10 taken 822458 times.
✓ Branch 30 → 31 taken 49084 times.
|
871542 | for (const auto &manifestations : insertScope->functions | std::views::values) { |
| 119 |
3/4✓ Branch 11 → 12 taken 822458 times.
✗ Branch 11 → 59 not taken.
✓ Branch 12 → 13 taken 2 times.
✓ Branch 12 → 28 taken 822456 times.
|
822458 | if (manifestations.contains(signature)) { |
| 120 |
2/2✓ Branch 16 → 17 taken 1 time.
✓ Branch 16 → 18 taken 1 time.
|
2 | const SemanticErrorType errorType = newManifestation.isFunction() ? FUNCTION_DECLARED_TWICE : PROCEDURE_DECLARED_TWICE; |
| 121 |
4/8✓ Branch 20 → 21 taken 2 times.
✗ Branch 20 → 53 not taken.
✓ Branch 21 → 22 taken 2 times.
✗ Branch 21 → 51 not taken.
✓ Branch 22 → 23 taken 2 times.
✗ Branch 22 → 49 not taken.
✓ Branch 23 → 24 taken 2 times.
✗ Branch 23 → 47 not taken.
|
2 | throw SemanticError(declNode, errorType, "'" + newManifestation.getSignature(true, false) + "' is declared twice"); |
| 122 | } | ||
| 123 | } | ||
| 124 | |||
| 125 | // Retrieve the matching manifestation list of the scope | ||
| 126 |
3/6✓ Branch 31 → 32 taken 49084 times.
✗ Branch 31 → 65 not taken.
✓ Branch 32 → 33 taken 49084 times.
✗ Branch 32 → 62 not taken.
✓ Branch 33 → 34 taken 49084 times.
✗ Branch 33 → 60 not taken.
|
49084 | const std::string fctId = newManifestation.name + ":" + declNode->codeLoc.toPrettyLineAndColumn(); |
| 127 |
2/4✓ Branch 36 → 37 taken 49084 times.
✗ Branch 36 → 66 not taken.
✗ Branch 37 → 38 not taken.
✓ Branch 37 → 39 taken 49084 times.
|
49084 | assert(insertScope->functions.contains(fctId)); |
| 128 |
1/2✓ Branch 39 → 40 taken 49084 times.
✗ Branch 39 → 66 not taken.
|
49084 | FunctionManifestationList &manifestationList = insertScope->functions.at(fctId); |
| 129 | |||
| 130 | // Add substantiated function | ||
| 131 |
1/2✓ Branch 40 → 41 taken 49084 times.
✗ Branch 40 → 66 not taken.
|
49084 | manifestationList.emplace(signature, newManifestation); |
| 132 |
1/2✓ Branch 41 → 42 taken 49084 times.
✗ Branch 41 → 66 not taken.
|
98168 | return &manifestationList.at(signature); |
| 133 | 49086 | } | |
| 134 | |||
| 135 | /** | ||
| 136 | * Checks if a function exists by matching it, but not setting it to used | ||
| 137 | * | ||
| 138 | * @param matchScope Scope to match against | ||
| 139 | * @param reqName Function name requirement | ||
| 140 | * @param reqThisType This type requirement | ||
| 141 | * @param reqArgs Argument requirement | ||
| 142 | * @param strictQualifierMatching Match argument and this type qualifiers strictly | ||
| 143 | * @return Found function or nullptr | ||
| 144 | */ | ||
| 145 | 37554 | const Function *FunctionManager::lookup(Scope *matchScope, const std::string &reqName, const QualType &reqThisType, | |
| 146 | const ArgList &reqArgs, bool strictQualifierMatching) { | ||
| 147 |
2/4✓ Branch 2 → 3 taken 37554 times.
✗ Branch 2 → 64 not taken.
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 37554 times.
|
37554 | assert(reqThisType.isOneOf({TY_DYN, TY_STRUCT})); |
| 148 | |||
| 149 | // Do cache lookup | ||
| 150 | 37554 | const uint64_t cacheKey = getCacheKey(matchScope, reqName, reqThisType, reqArgs, {}); | |
| 151 |
3/4✓ Branch 8 → 9 taken 37554 times.
✗ Branch 8 → 65 not taken.
✓ Branch 11 → 12 taken 8122 times.
✓ Branch 11 → 14 taken 29432 times.
|
37554 | if (const auto it = lookupCache.find(cacheKey); it != lookupCache.end()) { |
| 152 | 8122 | lookupCacheHits++; | |
| 153 | 8122 | return it->second; | |
| 154 | } | ||
| 155 | 29432 | lookupCacheMisses++; | |
| 156 | |||
| 157 | 9929 | const auto pred = [&](const Arg &arg) { return arg.first.hasAnyGenericParts(); }; | |
| 158 |
4/8✓ Branch 14 → 15 taken 29432 times.
✗ Branch 14 → 74 not taken.
✓ Branch 15 → 16 taken 29432 times.
✗ Branch 15 → 19 not taken.
✓ Branch 16 → 17 taken 29432 times.
✗ Branch 16 → 74 not taken.
✓ Branch 17 → 18 taken 29432 times.
✗ Branch 17 → 19 not taken.
|
29432 | const bool requestedFullySubstantiated = !reqThisType.hasAnyGenericParts() && std::ranges::none_of(reqArgs, pred); |
| 159 | |||
| 160 | // Loop over function registry to find functions, that match the requirements of the call | ||
| 161 | 29432 | std::vector<const Function *> matches; | |
| 162 |
2/2✓ Branch 54 → 22 taken 204800 times.
✓ Branch 54 → 55 taken 29432 times.
|
234232 | for (const auto &[defCodeLocStr, manifestations] : matchScope->functions) { |
| 163 |
2/2✓ Branch 51 → 27 taken 239135 times.
✓ Branch 51 → 52 taken 97228 times.
|
336363 | for (const auto &[signature, presetFunction] : manifestations) { |
| 164 |
2/4✓ Branch 30 → 31 taken 239135 times.
✗ Branch 30 → 69 not taken.
✗ Branch 31 → 32 not taken.
✓ Branch 31 → 33 taken 239135 times.
|
239135 | assert(presetFunction.hasSubstantiatedParams()); // No optional params are allowed at this point |
| 165 | |||
| 166 | // - search for concrete fct: Only match against fully substantiated versions to prevent double matching of a function | ||
| 167 | // - search for generic fct: Only match against generic preset functions | ||
| 168 |
3/4✓ Branch 33 → 34 taken 239135 times.
✗ Branch 33 → 69 not taken.
✓ Branch 34 → 35 taken 106519 times.
✓ Branch 34 → 36 taken 132616 times.
|
239135 | if (presetFunction.isFullySubstantiated() != requestedFullySubstantiated) |
| 169 | 131563 | continue; | |
| 170 | |||
| 171 | // Copy the function to be able to substantiate types | ||
| 172 |
1/2✓ Branch 36 → 37 taken 132616 times.
✗ Branch 36 → 69 not taken.
|
132616 | Function candidate = presetFunction; |
| 173 | |||
| 174 | // Create empty type mapping | ||
| 175 | 132616 | TypeMapping &typeMapping = candidate.typeMapping; | |
| 176 | |||
| 177 | 132616 | bool forceSubstantiation = false; | |
| 178 |
1/2✓ Branch 37 → 38 taken 132616 times.
✗ Branch 37 → 67 not taken.
|
132616 | const MatchResult matchResult = matchManifestation(candidate, matchScope, reqName, reqThisType, reqArgs, typeMapping, |
| 179 | strictQualifierMatching, forceSubstantiation, nullptr); | ||
| 180 |
2/2✓ Branch 38 → 39 taken 99517 times.
✓ Branch 38 → 40 taken 33099 times.
|
132616 | if (matchResult == MatchResult::SKIP_FUNCTION) |
| 181 | 99517 | break; // Leave the whole function | |
| 182 |
2/2✓ Branch 40 → 41 taken 25044 times.
✓ Branch 40 → 42 taken 8055 times.
|
33099 | if (matchResult == MatchResult::SKIP_MANIFESTATION) |
| 183 | 25044 | continue; // Leave this manifestation and try the next one | |
| 184 | |||
| 185 | // Add to matches | ||
| 186 |
3/6✓ Branch 42 → 43 taken 8055 times.
✗ Branch 42 → 66 not taken.
✓ Branch 43 → 44 taken 8055 times.
✗ Branch 43 → 66 not taken.
✓ Branch 44 → 45 taken 8055 times.
✗ Branch 44 → 66 not taken.
|
8055 | matches.push_back(&matchScope->functions.at(defCodeLocStr).at(signature)); |
| 187 | |||
| 188 | 8055 | break; // Leave the whole manifestation list to not double-match the manifestation | |
| 189 |
2/2✓ Branch 47 → 48 taken 25044 times.
✓ Branch 47 → 49 taken 107572 times.
|
132616 | } |
| 190 | } | ||
| 191 | |||
| 192 | // Return the very match or a nullptr | ||
| 193 |
2/2✓ Branch 56 → 57 taken 8038 times.
✓ Branch 56 → 59 taken 21394 times.
|
29432 | return !matches.empty() ? matches.front() : nullptr; |
| 194 | 29432 | } | |
| 195 | |||
| 196 | /** | ||
| 197 | * Check if there is a function in the scope, fulfilling all given requirements and if found, return it. | ||
| 198 | * If more than one function matches the requirement, an error gets thrown. | ||
| 199 | * | ||
| 200 | * @param matchScope Scope to match against | ||
| 201 | * @param reqName Function name requirement | ||
| 202 | * @param reqThisType This type requirement | ||
| 203 | * @param reqArgs Argument requirement | ||
| 204 | * @param templateTypeHints Template type requirement | ||
| 205 | * @param strictQualifierMatching Match argument and this type qualifiers strictly | ||
| 206 | * @param callNode Call AST node for printing error messages | ||
| 207 | * @return Matched function or nullptr | ||
| 208 | */ | ||
| 209 | 369528 | Function *FunctionManager::match(Scope *matchScope, const std::string &reqName, const QualType &reqThisType, | |
| 210 | const ArgList &reqArgs, const QualTypeList &templateTypeHints, bool strictQualifierMatching, | ||
| 211 | const ASTNode *callNode) { | ||
| 212 |
2/4✓ Branch 2 → 3 taken 369528 times.
✗ Branch 2 → 181 not taken.
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 369528 times.
|
369528 | assert(reqThisType.isOneOf({TY_DYN, TY_STRUCT, TY_INTERFACE})); |
| 213 | |||
| 214 | // Do cache lookup | ||
| 215 | 369528 | const uint64_t cacheKey = getCacheKey(matchScope, reqName, reqThisType, reqArgs, templateTypeHints); | |
| 216 |
3/4✓ Branch 6 → 7 taken 369528 times.
✗ Branch 6 → 182 not taken.
✓ Branch 9 → 10 taken 53893 times.
✓ Branch 9 → 12 taken 315635 times.
|
369528 | if (const auto it = lookupCache.find(cacheKey); it != lookupCache.end()) { |
| 217 | 53893 | lookupCacheHits++; | |
| 218 | 53893 | return it->second; | |
| 219 | } | ||
| 220 | 315635 | lookupCacheMisses++; | |
| 221 | |||
| 222 | // Loop over function registry to find functions, that match the requirements of the call | ||
| 223 | 315635 | std::vector<Function *> matches; | |
| 224 |
2/2✓ Branch 140 → 14 taken 3574895 times.
✓ Branch 140 → 141 taken 315634 times.
|
3890529 | for (auto &[fctId, manifestations] : matchScope->functions) { |
| 225 |
2/2✓ Branch 137 → 19 taken 3676207 times.
✓ Branch 137 → 138 taken 137460 times.
|
3813667 | for (const auto &[signature, presetFunction] : manifestations) { |
| 226 |
2/4✓ Branch 22 → 23 taken 3676207 times.
✗ Branch 22 → 205 not taken.
✗ Branch 23 → 24 not taken.
✓ Branch 23 → 25 taken 3676207 times.
|
3676207 | assert(presetFunction.hasSubstantiatedParams()); // No optional params are allowed at this point |
| 227 | |||
| 228 | // Skip generic and newly inserted substantiations to prevent double matching of a function | ||
| 229 |
6/8✓ Branch 25 → 26 taken 3676207 times.
✗ Branch 25 → 205 not taken.
✓ Branch 26 → 27 taken 3579462 times.
✓ Branch 26 → 28 taken 96745 times.
✗ Branch 27 → 28 not taken.
✓ Branch 27 → 29 taken 3579462 times.
✓ Branch 30 → 31 taken 96745 times.
✓ Branch 30 → 32 taken 3579462 times.
|
3676207 | if (presetFunction.isGenericSubstantiation() || presetFunction.isNewlyInserted) |
| 230 | 238772 | continue; | |
| 231 | |||
| 232 | // Copy the function to be able to substantiate types | ||
| 233 |
1/2✓ Branch 32 → 33 taken 3579462 times.
✗ Branch 32 → 205 not taken.
|
3579462 | Function candidate = presetFunction; |
| 234 | |||
| 235 | // Prepare type mapping, based on the given initial type mapping | ||
| 236 | 3579462 | TypeMapping &typeMapping = candidate.typeMapping; | |
| 237 | 3579462 | typeMapping.clear(); | |
| 238 |
2/2✓ Branch 43 → 35 taken 55157 times.
✓ Branch 43 → 44 taken 3579462 times.
|
3634619 | for (size_t i = 0; i < std::min(templateTypeHints.size(), candidate.templateTypes.size()); i++) { |
| 239 |
2/4✓ Branch 35 → 36 taken 55157 times.
✗ Branch 35 → 203 not taken.
✓ Branch 36 → 37 taken 55157 times.
✗ Branch 36 → 203 not taken.
|
55157 | const std::string &typeName = candidate.templateTypes.at(i).getSubType(); |
| 240 |
1/2✓ Branch 37 → 38 taken 55157 times.
✗ Branch 37 → 203 not taken.
|
55157 | const QualType &templateType = templateTypeHints.at(i); |
| 241 |
1/2✓ Branch 38 → 39 taken 55157 times.
✗ Branch 38 → 203 not taken.
|
55157 | typeMapping.emplace(typeName, templateType); |
| 242 | } | ||
| 243 | |||
| 244 | 3579462 | bool forceSubstantiation = false; | |
| 245 |
2/2✓ Branch 44 → 45 taken 3579461 times.
✓ Branch 44 → 203 taken 1 time.
|
3579462 | const MatchResult matchResult = matchManifestation(candidate, matchScope, reqName, reqThisType, reqArgs, typeMapping, |
| 246 | strictQualifierMatching, forceSubstantiation, callNode); | ||
| 247 |
2/2✓ Branch 45 → 46 taken 3425429 times.
✓ Branch 45 → 47 taken 154032 times.
|
3579461 | if (matchResult == MatchResult::SKIP_FUNCTION) |
| 248 | 3425429 | break; // Leave the whole function | |
| 249 |
2/2✓ Branch 47 → 48 taken 127064 times.
✓ Branch 47 → 49 taken 26968 times.
|
154032 | if (matchResult == MatchResult::SKIP_MANIFESTATION) |
| 250 | 127064 | continue; // Leave this manifestation and try the next one | |
| 251 | |||
| 252 | // We found a match! -> Set the actual candidate and its entry to used | ||
| 253 | 26968 | candidate.used = true; | |
| 254 | 26968 | candidate.entry->used = true; | |
| 255 | |||
| 256 | // Check if the function is generic needs to be substantiated | ||
| 257 |
6/6✓ Branch 50 → 51 taken 15198 times.
✓ Branch 50 → 53 taken 11770 times.
✓ Branch 51 → 52 taken 14963 times.
✓ Branch 51 → 53 taken 235 times.
✓ Branch 54 → 55 taken 14963 times.
✓ Branch 54 → 67 taken 12005 times.
|
26968 | if (presetFunction.templateTypes.empty() && !forceSubstantiation) { |
| 258 |
5/10✓ Branch 55 → 56 taken 14963 times.
✗ Branch 55 → 183 not taken.
✓ Branch 56 → 57 taken 14963 times.
✗ Branch 56 → 61 not taken.
✓ Branch 57 → 58 taken 14963 times.
✗ Branch 57 → 183 not taken.
✓ Branch 58 → 59 taken 14963 times.
✗ Branch 58 → 183 not taken.
✓ Branch 59 → 60 taken 14963 times.
✗ Branch 59 → 61 not taken.
|
14963 | assert(matchScope->functions.contains(fctId) && matchScope->functions.at(fctId).contains(signature)); |
| 259 |
2/4✓ Branch 62 → 63 taken 14963 times.
✗ Branch 62 → 183 not taken.
✓ Branch 63 → 64 taken 14963 times.
✗ Branch 63 → 183 not taken.
|
14963 | Function *match = &matchScope->functions.at(fctId).at(signature); |
| 260 | 14963 | match->used = true; | |
| 261 |
1/2✓ Branch 64 → 65 taken 14963 times.
✗ Branch 64 → 183 not taken.
|
14963 | matches.push_back(match); |
| 262 | 14963 | continue; // Match was successful -> match the next function | |
| 263 | 14963 | } | |
| 264 | |||
| 265 | // Check if we already have this manifestation and can simply re-use it | ||
| 266 |
1/2✓ Branch 67 → 68 taken 12005 times.
✗ Branch 67 → 203 not taken.
|
12005 | const std::string newSignature = candidate.getSignature(true, true, false, true); |
| 267 |
3/4✓ Branch 68 → 69 taken 12005 times.
✗ Branch 68 → 185 not taken.
✓ Branch 71 → 72 taken 1083 times.
✓ Branch 71 → 76 taken 10922 times.
|
12005 | if (const auto it = manifestations.find(newSignature); it != manifestations.end()) { |
| 268 | 1083 | it->second.used = true; | |
| 269 |
1/2✓ Branch 74 → 75 taken 1083 times.
✗ Branch 74 → 184 not taken.
|
1083 | matches.push_back(&it->second); |
| 270 | 1083 | break; // Leave the whole manifestation list to not double-match the manifestation | |
| 271 | } | ||
| 272 | |||
| 273 | // Insert the substantiated version if required | ||
| 274 |
1/2✓ Branch 76 → 78 taken 10922 times.
✗ Branch 76 → 201 not taken.
|
10922 | Function *substantiatedFunction = insertSubstantiation(matchScope, candidate, presetFunction.declNode); |
| 275 |
2/4✓ Branch 78 → 79 taken 10922 times.
✗ Branch 78 → 201 not taken.
✓ Branch 79 → 80 taken 10922 times.
✗ Branch 79 → 201 not taken.
|
10922 | substantiatedFunction->genericPreset = &matchScope->functions.at(fctId).at(signature); |
| 276 | 10922 | substantiatedFunction->alreadyTypeChecked = false; | |
| 277 |
2/4✓ Branch 80 → 81 taken 10922 times.
✗ Branch 80 → 201 not taken.
✓ Branch 81 → 82 taken 10922 times.
✗ Branch 81 → 201 not taken.
|
10922 | substantiatedFunction->declNode->getFctManifestations(reqName)->push_back(substantiatedFunction); |
| 278 | 10922 | substantiatedFunction->isNewlyInserted = true; // To not iterate over it in the same matching | |
| 279 | |||
| 280 | // Copy function entry | ||
| 281 |
1/2✓ Branch 82 → 83 taken 10922 times.
✗ Branch 82 → 201 not taken.
|
10922 | const std::string newScopeName = substantiatedFunction->getScopeName(); |
| 282 |
1/2✓ Branch 83 → 84 taken 10922 times.
✗ Branch 83 → 199 not taken.
|
10922 | matchScope->lookupStrict(presetFunction.entry->name)->used = true; |
| 283 |
1/2✓ Branch 86 → 87 taken 10922 times.
✗ Branch 86 → 199 not taken.
|
10922 | substantiatedFunction->entry = matchScope->symbolTable.copySymbol(presetFunction.entry->name, newScopeName); |
| 284 |
1/2✗ Branch 87 → 88 not taken.
✓ Branch 87 → 89 taken 10922 times.
|
10922 | assert(substantiatedFunction->entry != nullptr); |
| 285 | |||
| 286 | // Copy function scope | ||
| 287 |
1/2✓ Branch 89 → 90 taken 10922 times.
✗ Branch 89 → 199 not taken.
|
10922 | const std::string oldScopeName = presetFunction.getScopeName(); |
| 288 |
1/2✓ Branch 90 → 91 taken 10922 times.
✗ Branch 90 → 197 not taken.
|
10922 | Scope *childScope = matchScope->copyChildScope(oldScopeName, newScopeName); |
| 289 |
1/2✗ Branch 91 → 92 not taken.
✓ Branch 91 → 93 taken 10922 times.
|
10922 | assert(childScope != nullptr); |
| 290 | 10922 | childScope->isGenericScope = false; | |
| 291 | 10922 | substantiatedFunction->bodyScope = childScope; | |
| 292 | |||
| 293 | // Insert symbols for generic type names with concrete types into the child block | ||
| 294 |
2/2✓ Branch 103 → 95 taken 13772 times.
✓ Branch 103 → 104 taken 10922 times.
|
24694 | for (const auto &[typeName, concreteType] : substantiatedFunction->typeMapping) |
| 295 |
2/4✓ Branch 98 → 99 taken 13772 times.
✗ Branch 98 → 188 not taken.
✓ Branch 99 → 100 taken 13772 times.
✗ Branch 99 → 186 not taken.
|
13772 | childScope->insertGenericType(typeName, GenericType(concreteType)); |
| 296 | |||
| 297 | // Substantiate the 'this' entry in the new function scope | ||
| 298 |
6/6✓ Branch 107 → 108 taken 9031 times.
✓ Branch 107 → 111 taken 1891 times.
✓ Branch 109 → 110 taken 9029 times.
✓ Branch 109 → 111 taken 2 times.
✓ Branch 112 → 113 taken 9029 times.
✓ Branch 112 → 126 taken 1893 times.
|
10922 | if (presetFunction.isMethod() && !presetFunction.templateTypes.empty()) { |
| 299 |
1/2✓ Branch 115 → 116 taken 9029 times.
✗ Branch 115 → 192 not taken.
|
27087 | SymbolTableEntry *thisEntry = childScope->lookupStrict(THIS_VARIABLE_NAME); |
| 300 |
1/2✗ Branch 121 → 122 not taken.
✓ Branch 121 → 123 taken 9029 times.
|
9029 | assert(thisEntry != nullptr); |
| 301 |
2/4✓ Branch 123 → 124 taken 9029 times.
✗ Branch 123 → 196 not taken.
✓ Branch 124 → 125 taken 9029 times.
✗ Branch 124 → 196 not taken.
|
9029 | thisEntry->updateType(candidate.thisType.toPtr(callNode), /*overwriteExistingType=*/true); |
| 302 | } | ||
| 303 | |||
| 304 | // Add to matched functions | ||
| 305 |
1/2✓ Branch 126 → 127 taken 10922 times.
✗ Branch 126 → 197 not taken.
|
10922 | matches.push_back(substantiatedFunction); |
| 306 | |||
| 307 | 10922 | break; // Leave the whole manifestation list to not double-match the manifestation | |
| 308 |
2/2✓ Branch 133 → 134 taken 142027 times.
✓ Branch 133 → 135 taken 3437434 times.
|
3591467 | } |
| 309 | } | ||
| 310 | |||
| 311 | // If no matches were found, return a nullptr | ||
| 312 |
2/2✓ Branch 142 → 143 taken 288679 times.
✓ Branch 142 → 144 taken 26955 times.
|
315634 | if (matches.empty()) |
| 313 | 288679 | return nullptr; | |
| 314 | |||
| 315 | // Tie-breaking: if multiple candidates match, narrow them by qualifier specificity (see breakOverloadTie). | ||
| 316 |
1/2✓ Branch 144 → 145 taken 26955 times.
✗ Branch 144 → 221 not taken.
|
26955 | breakOverloadTie(matches, reqArgs); |
| 317 | |||
| 318 | // Check if more than one function matches the requirements | ||
| 319 |
2/2✓ Branch 146 → 147 taken 1 time.
✓ Branch 146 → 174 taken 26954 times.
|
26955 | if (matches.size() > 1) { |
| 320 |
1/2✓ Branch 147 → 148 taken 1 time.
✗ Branch 147 → 220 not taken.
|
1 | std::stringstream errorMessage; |
| 321 |
3/6✓ Branch 148 → 149 taken 1 time.
✗ Branch 148 → 218 not taken.
✓ Branch 149 → 150 taken 1 time.
✗ Branch 149 → 218 not taken.
✓ Branch 150 → 151 taken 1 time.
✗ Branch 150 → 218 not taken.
|
1 | errorMessage << "The function/procedure '" << reqName << "' is ambiguous. All of the following match the requested criteria:"; |
| 322 |
2/2✓ Branch 168 → 153 taken 2 times.
✓ Branch 168 → 169 taken 1 time.
|
4 | for (const Function *match : matches) |
| 323 |
3/6✓ Branch 155 → 156 taken 2 times.
✗ Branch 155 → 211 not taken.
✓ Branch 156 → 157 taken 2 times.
✗ Branch 156 → 210 not taken.
✓ Branch 157 → 158 taken 2 times.
✗ Branch 157 → 208 not taken.
|
2 | errorMessage << "\n " << match->getSignature(); |
| 324 |
2/4✓ Branch 170 → 171 taken 1 time.
✗ Branch 170 → 215 not taken.
✓ Branch 171 → 172 taken 1 time.
✗ Branch 171 → 212 not taken.
|
1 | throw SemanticError(callNode, FUNCTION_AMBIGUITY, errorMessage.str()); |
| 325 | 1 | } | |
| 326 | 26954 | Function *matchedFunction = matches.front(); | |
| 327 | 26954 | matchedFunction->isNewlyInserted = false; | |
| 328 | |||
| 329 | // Insert into cache | ||
| 330 |
1/2✓ Branch 175 → 176 taken 26954 times.
✗ Branch 175 → 221 not taken.
|
26954 | lookupCache[cacheKey] = matchedFunction; |
| 331 | |||
| 332 | // Trigger revisit in type checker if required | ||
| 333 |
1/2✓ Branch 176 → 177 taken 26954 times.
✗ Branch 176 → 221 not taken.
|
26954 | TypeChecker::requestRevisitIfRequired(matchedFunction); |
| 334 | |||
| 335 | // Return the very match | ||
| 336 | 26954 | return matchedFunction; | |
| 337 | 315635 | } | |
| 338 | |||
| 339 | 3712078 | MatchResult FunctionManager::matchManifestation(Function &candidate, Scope *&matchScope, const std::string &reqName, | |
| 340 | const QualType &reqThisType, const ArgList &reqArgs, TypeMapping &typeMapping, | ||
| 341 | bool strictQualifierMatching, bool &forceSubstantiation, | ||
| 342 | const ASTNode *callNode) { | ||
| 343 | // Check name requirement | ||
| 344 |
2/2✓ Branch 3 → 4 taken 3524946 times.
✓ Branch 3 → 5 taken 187132 times.
|
3712078 | if (!matchName(candidate, reqName)) |
| 345 | 3524946 | return MatchResult::SKIP_FUNCTION; // Leave the whole manifestation list, because all have the same name | |
| 346 | |||
| 347 | // Check 'this' type requirement | ||
| 348 |
1/2✗ Branch 6 → 7 not taken.
✓ Branch 6 → 8 taken 187132 times.
|
187132 | if (!matchThisType(candidate, reqThisType, typeMapping, strictQualifierMatching, callNode)) |
| 349 | ✗ | return MatchResult::SKIP_MANIFESTATION; // Leave this manifestation and try the next one | |
| 350 | |||
| 351 | // Check arg types requirement | ||
| 352 |
2/2✓ Branch 9 → 10 taken 152106 times.
✓ Branch 9 → 11 taken 35025 times.
|
187132 | if (!matchArgTypes(candidate, reqArgs, typeMapping, strictQualifierMatching, forceSubstantiation, callNode)) |
| 353 | 152106 | return MatchResult::SKIP_MANIFESTATION; // Leave this manifestation and try the next one | |
| 354 | |||
| 355 | // Check if there are unresolved generic types | ||
| 356 |
2/2✓ Branch 13 → 14 taken 2 times.
✓ Branch 13 → 15 taken 35023 times.
|
35025 | if (typeMapping.size() < candidate.templateTypes.size()) |
| 357 | 2 | return MatchResult::SKIP_MANIFESTATION; // Leave this manifestation and try the next one | |
| 358 | |||
| 359 | // Substantiate return type | ||
| 360 | 35023 | substantiateReturnType(candidate, typeMapping, callNode); | |
| 361 | |||
| 362 | // Set the match scope to the scope of the concrete substantiation | ||
| 363 | 35023 | const QualType &thisType = candidate.thisType; | |
| 364 |
2/2✓ Branch 17 → 18 taken 25413 times.
✓ Branch 17 → 25 taken 9610 times.
|
35023 | if (!thisType.is(TY_DYN)) { |
| 365 | // If we only have the generic struct scope, lookup the concrete manifestation scope | ||
| 366 |
2/2✓ Branch 18 → 19 taken 118 times.
✓ Branch 18 → 23 taken 25295 times.
|
25413 | if (matchScope->isGenericScope) { |
| 367 | 118 | const Struct *spiceStruct = thisType.getStruct(candidate.declNode); | |
| 368 |
1/2✗ Branch 20 → 21 not taken.
✓ Branch 20 → 22 taken 118 times.
|
118 | assert(spiceStruct != nullptr); |
| 369 | 118 | matchScope = spiceStruct->scope; | |
| 370 | } | ||
| 371 |
1/2✓ Branch 23 → 24 taken 25413 times.
✗ Branch 23 → 27 not taken.
|
25413 | candidate.thisType = candidate.thisType.getWithBodyScope(matchScope); |
| 372 | } | ||
| 373 | |||
| 374 | 35023 | return MatchResult::MATCHED; | |
| 375 | } | ||
| 376 | |||
| 377 | /** | ||
| 378 | * Checks if the matching candidate fulfills the name requirement | ||
| 379 | * | ||
| 380 | * @param candidate Matching candidate function | ||
| 381 | * @param reqName Requested function name | ||
| 382 | * @return Fulfilled or not | ||
| 383 | */ | ||
| 384 | 3712078 | bool FunctionManager::matchName(const Function &candidate, const std::string &reqName) { return candidate.name == reqName; } | |
| 385 | |||
| 386 | /** | ||
| 387 | * Checks if the matching candidate fulfills the 'this' type requirement | ||
| 388 | * | ||
| 389 | * @param candidate Matching candidate function | ||
| 390 | * @param reqThisType Requested 'this' type | ||
| 391 | * @param typeMapping Concrete template type mapping | ||
| 392 | * @param strictQualifierMatching Match qualifiers strictly | ||
| 393 | * @param callNode Call AST node for printing error messages | ||
| 394 | * @return Fulfilled or not | ||
| 395 | */ | ||
| 396 | 187132 | bool FunctionManager::matchThisType(Function &candidate, const QualType &reqThisType, TypeMapping &typeMapping, | |
| 397 | bool strictQualifierMatching, const ASTNode *callNode) { | ||
| 398 | 187132 | QualType &candidateThisType = candidate.thisType; | |
| 399 | |||
| 400 | // Shortcut for procedures | ||
| 401 |
7/10✓ Branch 2 → 3 taken 187132 times.
✗ Branch 2 → 23 not taken.
✓ Branch 3 → 4 taken 117689 times.
✓ Branch 3 → 7 taken 69443 times.
✓ Branch 4 → 5 taken 117689 times.
✗ Branch 4 → 23 not taken.
✓ Branch 5 → 6 taken 117689 times.
✗ Branch 5 → 7 not taken.
✓ Branch 8 → 9 taken 117689 times.
✓ Branch 8 → 10 taken 69443 times.
|
187132 | if (candidateThisType.is(TY_DYN) && reqThisType.is(TY_DYN)) |
| 402 | 117689 | return true; | |
| 403 | |||
| 404 | // Give the type matcher a way to retrieve instances of GenericType by their name | ||
| 405 | 151544 | TypeMatcher::ResolverFct genericTypeResolver = [&](const std::string &genericTypeName) { | |
| 406 | 12658 | return getGenericTypeOfCandidateByName(candidate, genericTypeName); | |
| 407 | 69443 | }; | |
| 408 | |||
| 409 | // Check if the requested 'this' type matches the candidate 'this' type. The type mapping may be extended | ||
| 410 |
2/4✓ Branch 11 → 12 taken 69443 times.
✗ Branch 11 → 21 not taken.
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 14 taken 69443 times.
|
69443 | if (!TypeMatcher::matchRequestedToCandidateType(candidateThisType, reqThisType, typeMapping, genericTypeResolver, |
| 411 | strictQualifierMatching)) | ||
| 412 | ✗ | return false; | |
| 413 | |||
| 414 | // Substantiate the candidate param type, based on the type mapping | ||
| 415 |
3/4✓ Branch 14 → 15 taken 69443 times.
✗ Branch 14 → 21 not taken.
✓ Branch 15 → 16 taken 13739 times.
✓ Branch 15 → 17 taken 55704 times.
|
69443 | if (candidateThisType.hasAnyGenericParts()) |
| 416 |
1/2✓ Branch 16 → 17 taken 13739 times.
✗ Branch 16 → 21 not taken.
|
13739 | TypeMatcher::substantiateTypeWithTypeMapping(candidateThisType, typeMapping, callNode); |
| 417 | |||
| 418 | 69443 | return true; | |
| 419 | 69443 | } | |
| 420 | |||
| 421 | /** | ||
| 422 | * Checks if the matching candidate fulfills the argument types requirement | ||
| 423 | * | ||
| 424 | * @param candidate Matching candidate function | ||
| 425 | * @param reqArgs Requested argument types | ||
| 426 | * @param typeMapping Concrete template type mapping | ||
| 427 | * @param strictQualifierMatching Match qualifiers strictly | ||
| 428 | * @param needsSubstantiation We want to create a substantiation after successfully matching | ||
| 429 | * @param callNode Call AST node for printing error messages | ||
| 430 | * @return Fulfilled or not | ||
| 431 | */ | ||
| 432 | 187132 | bool FunctionManager::matchArgTypes(Function &candidate, const ArgList &reqArgs, TypeMapping &typeMapping, | |
| 433 | bool strictQualifierMatching, bool &needsSubstantiation, const ASTNode *callNode) { | ||
| 434 | 187132 | std::vector<Param> &candidateParamList = candidate.paramList; | |
| 435 | |||
| 436 | // If the number of arguments does not match with the number of params, the matching fails | ||
| 437 |
6/6✓ Branch 2 → 3 taken 186901 times.
✓ Branch 2 → 7 taken 231 times.
✓ Branch 5 → 6 taken 30088 times.
✓ Branch 5 → 7 taken 156813 times.
✓ Branch 8 → 9 taken 30088 times.
✓ Branch 8 → 10 taken 157044 times.
|
187132 | if (!candidate.isVararg && reqArgs.size() != candidateParamList.size()) |
| 438 | 30088 | return false; | |
| 439 | // In the case of a vararg function, we only disallow fewer arguments than parameters | ||
| 440 |
4/6✓ Branch 10 → 11 taken 231 times.
✓ Branch 10 → 15 taken 156813 times.
✗ Branch 13 → 14 not taken.
✓ Branch 13 → 15 taken 231 times.
✗ Branch 16 → 17 not taken.
✓ Branch 16 → 18 taken 157044 times.
|
157044 | if (candidate.isVararg && reqArgs.size() < candidateParamList.size()) |
| 441 | ✗ | return false; | |
| 442 | |||
| 443 | // Give the type matcher a way to retrieve instances of GenericType by their name | ||
| 444 | 325527 | TypeMatcher::ResolverFct genericTypeResolver = [&](const std::string &genericTypeName) { | |
| 445 | 11439 | return getGenericTypeOfCandidateByName(candidate, genericTypeName); | |
| 446 | 157044 | }; | |
| 447 | |||
| 448 | // Loop over all parameters | ||
| 449 |
2/2✓ Branch 66 → 20 taken 161826 times.
✓ Branch 66 → 67 taken 35025 times.
|
196851 | for (size_t i = 0; i < reqArgs.size(); i++) { |
| 450 | // In the case of a vararg function candidate, we can accept additional arguments, that are not defined in the candidate, | ||
| 451 | // but we need to modify the candidate param list to accept them | ||
| 452 |
6/6✓ Branch 20 → 21 taken 943 times.
✓ Branch 20 → 24 taken 160883 times.
✓ Branch 22 → 23 taken 253 times.
✓ Branch 22 → 24 taken 690 times.
✓ Branch 25 → 26 taken 253 times.
✓ Branch 25 → 29 taken 161573 times.
|
161826 | if (candidate.isVararg && i >= candidateParamList.size()) { |
| 453 |
2/4✓ Branch 26 → 27 taken 253 times.
✗ Branch 26 → 71 not taken.
✓ Branch 27 → 28 taken 253 times.
✗ Branch 27 → 71 not taken.
|
253 | candidateParamList.push_back(Param(reqArgs.at(i).first, false)); |
| 454 | 253 | needsSubstantiation = true; // We need to modify the candidate param types | |
| 455 | 253 | continue; | |
| 456 | } | ||
| 457 | |||
| 458 | // Retrieve actual and requested types | ||
| 459 |
2/4✓ Branch 29 → 30 taken 161573 times.
✗ Branch 29 → 84 not taken.
✗ Branch 30 → 31 not taken.
✓ Branch 30 → 32 taken 161573 times.
|
161573 | assert(!candidateParamList.at(i).isOptional); |
| 460 |
1/2✓ Branch 32 → 33 taken 161573 times.
✗ Branch 32 → 84 not taken.
|
161573 | QualType &candidateType = candidateParamList.at(i).qualType; |
| 461 |
1/2✓ Branch 33 → 34 taken 161573 times.
✗ Branch 33 → 84 not taken.
|
161573 | const auto &[requestedType, isArgTemporary] = reqArgs.at(i); |
| 462 | |||
| 463 | // Check if the requested param type matches the candidate param type. The type mapping may be extended | ||
| 464 |
3/4✓ Branch 36 → 37 taken 161573 times.
✗ Branch 36 → 84 not taken.
✓ Branch 37 → 38 taken 122018 times.
✓ Branch 37 → 39 taken 39555 times.
|
161573 | if (!TypeMatcher::matchRequestedToCandidateType(candidateType, requestedType, typeMapping, genericTypeResolver, |
| 465 | strictQualifierMatching)) | ||
| 466 | 122018 | return false; | |
| 467 | |||
| 468 | // Substantiate the candidate param type, based on the type mapping | ||
| 469 |
3/4✓ Branch 39 → 40 taken 39555 times.
✗ Branch 39 → 84 not taken.
✓ Branch 40 → 41 taken 9823 times.
✓ Branch 40 → 42 taken 29732 times.
|
39555 | if (candidateType.hasAnyGenericParts()) |
| 470 |
1/2✓ Branch 41 → 42 taken 9823 times.
✗ Branch 41 → 84 not taken.
|
9823 | TypeMatcher::substantiateTypeWithTypeMapping(candidateType, typeMapping, callNode); |
| 471 | |||
| 472 | // Check if we try to bind a non-ref temporary to a non-const ref parameter | ||
| 473 |
3/4✓ Branch 42 → 43 taken 39555 times.
✗ Branch 42 → 84 not taken.
✓ Branch 43 → 44 taken 1 time.
✓ Branch 43 → 54 taken 39554 times.
|
39555 | if (!candidateType.canBind(requestedType, isArgTemporary)) { |
| 474 |
1/2✓ Branch 44 → 45 taken 1 time.
✗ Branch 44 → 53 not taken.
|
1 | if (callNode) |
| 475 |
2/4✓ Branch 48 → 49 taken 1 time.
✗ Branch 48 → 75 not taken.
✓ Branch 49 → 50 taken 1 time.
✗ Branch 49 → 72 not taken.
|
3 | throw SemanticError(callNode, TEMP_TO_NON_CONST_REF, "Temporary values can only be bound to const reference parameters"); |
| 476 | ✗ | return false; | |
| 477 | } | ||
| 478 | |||
| 479 | // If we have a function/procedure type we need to take care of the information, if it takes captures | ||
| 480 |
9/12✓ Branch 54 → 55 taken 39554 times.
✗ Branch 54 → 81 not taken.
✓ Branch 55 → 56 taken 39554 times.
✗ Branch 55 → 81 not taken.
✓ Branch 56 → 57 taken 62 times.
✓ Branch 56 → 60 taken 39492 times.
✓ Branch 57 → 58 taken 62 times.
✗ Branch 57 → 81 not taken.
✓ Branch 58 → 59 taken 9 times.
✓ Branch 58 → 60 taken 53 times.
✓ Branch 61 → 62 taken 9 times.
✓ Branch 61 → 64 taken 39545 times.
|
39554 | if (requestedType.getBase().isOneOf({TY_FUNCTION, TY_PROCEDURE}) && requestedType.hasLambdaCaptures()) { |
| 481 |
1/2✓ Branch 62 → 63 taken 9 times.
✗ Branch 62 → 83 not taken.
|
9 | candidateType = candidateType.getWithLambdaCaptures(); |
| 482 | 9 | needsSubstantiation = true; | |
| 483 | } | ||
| 484 | } | ||
| 485 | |||
| 486 | 35025 | return true; | |
| 487 | 157044 | } | |
| 488 | |||
| 489 | /** | ||
| 490 | * Substantiates the candidate return type, based on the given type mapping | ||
| 491 | * | ||
| 492 | * @param candidate Matching candidate function | ||
| 493 | * @param typeMapping Concrete template type mapping | ||
| 494 | * @param callNode AST node for error messages | ||
| 495 | */ | ||
| 496 | 35023 | void FunctionManager::substantiateReturnType(Function &candidate, const TypeMapping &typeMapping, const ASTNode *callNode) { | |
| 497 |
2/2✓ Branch 3 → 4 taken 3507 times.
✓ Branch 3 → 5 taken 31516 times.
|
35023 | if (candidate.returnType.hasAnyGenericParts()) |
| 498 | 3507 | TypeMatcher::substantiateTypeWithTypeMapping(candidate.returnType, typeMapping, callNode); | |
| 499 | 35023 | } | |
| 500 | |||
| 501 | /** | ||
| 502 | * Searches the candidate template types for a generic type object with a certain name and return it | ||
| 503 | * | ||
| 504 | * @param candidate Matching candidate function | ||
| 505 | * @param templateTypeName Template type name | ||
| 506 | * @return Generic type object | ||
| 507 | */ | ||
| 508 | 24097 | const GenericType *FunctionManager::getGenericTypeOfCandidateByName(const Function &candidate, | |
| 509 | const std::string &templateTypeName) { | ||
| 510 |
1/2✓ Branch 19 → 4 taken 27210 times.
✗ Branch 19 → 20 not taken.
|
51307 | for (const GenericType &templateType : candidate.templateTypes) { |
| 511 |
3/4✓ Branch 6 → 7 taken 27210 times.
✗ Branch 6 → 22 not taken.
✓ Branch 8 → 9 taken 24097 times.
✓ Branch 8 → 10 taken 3113 times.
|
27210 | if (templateType.getSubType() == templateTypeName) |
| 512 | 24097 | return &templateType; | |
| 513 | } | ||
| 514 | ✗ | return nullptr; | |
| 515 | } | ||
| 516 | |||
| 517 | /** | ||
| 518 | * Narrow a multi-match overload set by preferring the candidate whose parameter qualifiers most closely match | ||
| 519 | * the argument qualifiers. This resolves the typical copy-vs-move ctor ambiguity where both a `const T&` | ||
| 520 | * (copy) and a `T&` (move) ctor match a non-const lvalue argument - we prefer the non-const-ref candidate | ||
| 521 | * (move) since it requires no constification. When the argument is const, we prefer the const-ref candidate | ||
| 522 | * (copy) since binding to a non-const ref would require const-loss. | ||
| 523 | * | ||
| 524 | * Modifies `matches` in place, removing any candidate that scores worse than the best one. A no-op if there | ||
| 525 | * are fewer than two candidates. | ||
| 526 | * | ||
| 527 | * @param matches Candidate list to narrow | ||
| 528 | * @param reqArgs Argument list from the call site | ||
| 529 | */ | ||
| 530 | 26955 | void FunctionManager::breakOverloadTie(std::vector<Function *> &matches, const ArgList &reqArgs) { | |
| 531 |
2/2✓ Branch 3 → 4 taken 26942 times.
✓ Branch 3 → 5 taken 13 times.
|
26955 | if (matches.size() < 2) |
| 532 | 26942 | return; | |
| 533 | |||
| 534 | 13 | constexpr int CONSTIFY_PENALTY = 1; | |
| 535 | 13 | constexpr int CONST_LOSS_PENALTY = 100; | |
| 536 | // An exact type match is always preferred over a match that required an implicit upcast (struct to | ||
| 537 | // implemented interface, or struct to composed base struct). This keeps e.g. 'f(Derived)' preferred | ||
| 538 | // over 'f(Base)' when called with a Derived, instead of reporting an ambiguity. | ||
| 539 | 13 | constexpr int UPCAST_PENALTY = 1000; | |
| 540 | 65 | const auto scoreSpecificity = [&](const Function *f) { | |
| 541 | 52 | int penalty = 0; | |
| 542 |
2/2✓ Branch 23 → 3 taken 52 times.
✓ Branch 23 → 24 taken 52 times.
|
104 | for (size_t i = 0; i < std::min(reqArgs.size(), f->paramList.size()); i++) { |
| 543 |
1/2✓ Branch 3 → 4 taken 52 times.
✗ Branch 3 → 28 not taken.
|
52 | const QualType ¶mType = f->paramList.at(i).qualType; |
| 544 |
1/2✓ Branch 4 → 5 taken 52 times.
✗ Branch 4 → 28 not taken.
|
52 | const QualType &argType = reqArgs.at(i).first; |
| 545 |
2/4✓ Branch 5 → 6 taken 52 times.
✗ Branch 5 → 26 not taken.
✓ Branch 6 → 7 taken 52 times.
✗ Branch 6 → 26 not taken.
|
52 | const bool paramIsConst = paramType.removeReferenceWrapper().isConst(); |
| 546 |
2/4✓ Branch 7 → 8 taken 52 times.
✗ Branch 7 → 27 not taken.
✓ Branch 8 → 9 taken 52 times.
✗ Branch 8 → 27 not taken.
|
52 | const bool argIsConst = argType.removeReferenceWrapper().isConst(); |
| 547 |
4/4✓ Branch 9 → 10 taken 28 times.
✓ Branch 9 → 12 taken 24 times.
✓ Branch 10 → 11 taken 8 times.
✓ Branch 10 → 12 taken 20 times.
|
52 | if (paramIsConst && !argIsConst) |
| 548 | 8 | penalty += CONSTIFY_PENALTY; | |
| 549 |
4/4✓ Branch 12 → 13 taken 24 times.
✓ Branch 12 → 15 taken 20 times.
✓ Branch 13 → 14 taken 4 times.
✓ Branch 13 → 15 taken 20 times.
|
44 | else if (!paramIsConst && argIsConst) |
| 550 | 4 | penalty += CONST_LOSS_PENALTY; | |
| 551 | // Penalize matches that were only possible through an implicit upcast | ||
| 552 | 52 | QualType paramBase = paramType; | |
| 553 | 52 | QualType argBase = argType; | |
| 554 |
1/2✓ Branch 15 → 16 taken 52 times.
✗ Branch 15 → 28 not taken.
|
52 | QualType::unwrapBothWithRefWrappers(paramBase, argBase); |
| 555 |
3/4✓ Branch 16 → 17 taken 52 times.
✗ Branch 16 → 28 not taken.
✓ Branch 17 → 18 taken 12 times.
✓ Branch 17 → 19 taken 40 times.
|
52 | if (!paramBase.matches(argBase, true, true, true)) |
| 556 | 12 | penalty += UPCAST_PENALTY; | |
| 557 | } | ||
| 558 | 52 | return penalty; | |
| 559 | 13 | }; | |
| 560 | |||
| 561 | 13 | int bestScore = std::numeric_limits<int>::max(); | |
| 562 |
2/2✓ Branch 20 → 7 taken 26 times.
✓ Branch 20 → 21 taken 13 times.
|
52 | for (const Function *m : matches) |
| 563 |
1/2✓ Branch 9 → 10 taken 26 times.
✗ Branch 9 → 46 not taken.
|
26 | bestScore = std::min(bestScore, scoreSpecificity(m)); |
| 564 | 13 | std::vector<Function *> filtered; | |
| 565 |
1/2✓ Branch 22 → 23 taken 13 times.
✗ Branch 22 → 49 not taken.
|
13 | filtered.reserve(matches.size()); |
| 566 |
2/2✓ Branch 39 → 25 taken 26 times.
✓ Branch 39 → 40 taken 13 times.
|
52 | for (Function *m : matches) |
| 567 |
3/4✓ Branch 27 → 28 taken 26 times.
✗ Branch 27 → 48 not taken.
✓ Branch 28 → 29 taken 14 times.
✓ Branch 28 → 30 taken 12 times.
|
26 | if (scoreSpecificity(m) == bestScore) |
| 568 |
1/2✓ Branch 29 → 30 taken 14 times.
✗ Branch 29 → 48 not taken.
|
14 | filtered.push_back(m); |
| 569 | 13 | matches = std::move(filtered); | |
| 570 | 13 | } | |
| 571 | |||
| 572 | /** | ||
| 573 | * Calculate the cache key for the function lookup cache | ||
| 574 | * | ||
| 575 | * @param scope Scope to match against | ||
| 576 | * @param name Function name requirement | ||
| 577 | * @param thisType This type requirement | ||
| 578 | * @param args Argument requirement | ||
| 579 | * @param templateTypes Template type requirement | ||
| 580 | * @return Cache key | ||
| 581 | */ | ||
| 582 | 407082 | uint64_t FunctionManager::getCacheKey(const Scope *scope, const std::string &name, const QualType &thisType, const ArgList &args, | |
| 583 | const QualTypeList &templateTypes) { | ||
| 584 | 407082 | uint64_t hash = 0; | |
| 585 | 407082 | hashCombine64(hash, hashPointer(scope)); | |
| 586 | 407082 | hashCombine64(hash, std::hash<std::string>{}(name)); | |
| 587 | 407082 | hashCombine64(hash, std::hash<QualType>{}(thisType)); | |
| 588 |
2/2✓ Branch 27 → 10 taken 637008 times.
✓ Branch 27 → 28 taken 407082 times.
|
2088180 | for (const auto &[first, second] : args) { |
| 589 | 637008 | hashCombine64(hash, std::hash<QualType>{}(first)); | |
| 590 | 637008 | hashCombine64(hash, std::hash<bool>{}(second)); | |
| 591 | } | ||
| 592 | 407082 | hashCombine64(hash, hashVector(templateTypes)); | |
| 593 | 407082 | return hash; | |
| 594 | } | ||
| 595 | |||
| 596 | 10451 | bool FunctionManager::hasCtor(const Scope *matchScope, CtorKind kind) { | |
| 597 |
5/8✓ Branch 2 → 3 taken 10451 times.
✗ Branch 2 → 60 not taken.
✓ Branch 3 → 4 taken 10451 times.
✗ Branch 3 → 60 not taken.
✓ Branch 4 → 5 taken 10451 times.
✗ Branch 4 → 60 not taken.
✓ Branch 55 → 6 taken 46219 times.
✓ Branch 55 → 56 taken 6173 times.
|
52392 | for (const auto &manifestations : matchScope->functions | std::views::values) { |
| 598 |
5/8✓ Branch 7 → 8 taken 46219 times.
✗ Branch 7 → 59 not taken.
✓ Branch 8 → 9 taken 46219 times.
✗ Branch 8 → 59 not taken.
✓ Branch 9 → 10 taken 46219 times.
✗ Branch 9 → 59 not taken.
✓ Branch 51 → 11 taken 51332 times.
✓ Branch 51 → 52 taken 41941 times.
|
93273 | for (const auto &function : manifestations | std::views::values) { |
| 599 | // If it is no ctor, skip it | ||
| 600 |
3/4✓ Branch 12 → 13 taken 51332 times.
✗ Branch 12 → 59 not taken.
✓ Branch 13 → 14 taken 30997 times.
✓ Branch 13 → 15 taken 20335 times.
|
51332 | if (function.name != CTOR_FUNCTION_NAME) |
| 601 | 30997 | continue; | |
| 602 | // Classify the ctor based on its parameter list | ||
| 603 |
6/8✓ Branch 16 → 17 taken 13120 times.
✓ Branch 16 → 25 taken 7215 times.
✓ Branch 17 → 18 taken 13120 times.
✗ Branch 17 → 58 not taken.
✓ Branch 18 → 19 taken 13120 times.
✗ Branch 18 → 58 not taken.
✓ Branch 19 → 20 taken 5635 times.
✓ Branch 19 → 25 taken 7485 times.
|
25970 | const bool singleSelfRefParam = function.paramList.size() == 1 && function.paramList.at(0).qualType.isRef() && |
| 604 |
5/8✓ Branch 20 → 21 taken 5635 times.
✗ Branch 20 → 58 not taken.
✓ Branch 21 → 22 taken 5635 times.
✗ Branch 21 → 58 not taken.
✓ Branch 22 → 23 taken 5635 times.
✗ Branch 22 → 58 not taken.
✓ Branch 23 → 24 taken 4651 times.
✓ Branch 23 → 25 taken 984 times.
|
5635 | function.paramList.at(0).qualType.getBase() == function.thisType; |
| 605 |
6/8✓ Branch 26 → 27 taken 4651 times.
✓ Branch 26 → 31 taken 15684 times.
✓ Branch 27 → 28 taken 4651 times.
✗ Branch 27 → 59 not taken.
✓ Branch 28 → 29 taken 4651 times.
✗ Branch 28 → 59 not taken.
✓ Branch 29 → 30 taken 4638 times.
✓ Branch 29 → 31 taken 13 times.
|
20335 | const bool isCopyCtor = singleSelfRefParam && function.paramList.at(0).qualType.isConstRef(); |
| 606 |
6/8✓ Branch 32 → 33 taken 4651 times.
✓ Branch 32 → 37 taken 15684 times.
✓ Branch 33 → 34 taken 4651 times.
✗ Branch 33 → 59 not taken.
✓ Branch 34 → 35 taken 4651 times.
✗ Branch 34 → 59 not taken.
✓ Branch 35 → 36 taken 13 times.
✓ Branch 35 → 37 taken 4638 times.
|
20335 | const bool isMoveCtor = singleSelfRefParam && !function.paramList.at(0).qualType.isConstRef(); |
| 607 |
3/4✓ Branch 38 → 39 taken 13101 times.
✓ Branch 38 → 42 taken 4512 times.
✓ Branch 38 → 45 taken 2722 times.
✗ Branch 38 → 49 not taken.
|
20335 | switch (kind) { |
| 608 | 13101 | case CtorKind::COPY: | |
| 609 |
2/2✓ Branch 39 → 40 taken 2345 times.
✓ Branch 39 → 41 taken 10756 times.
|
13101 | if (isCopyCtor) |
| 610 | 4278 | return true; | |
| 611 | 10756 | break; | |
| 612 | 4512 | case CtorKind::MOVE: | |
| 613 |
2/2✓ Branch 42 → 43 taken 4 times.
✓ Branch 42 → 44 taken 4508 times.
|
4512 | if (isMoveCtor) |
| 614 | 4 | return true; | |
| 615 | 4508 | break; | |
| 616 | 2722 | case CtorKind::ANY_NON_COPY_NON_MOVE: | |
| 617 |
4/4✓ Branch 45 → 46 taken 1931 times.
✓ Branch 45 → 48 taken 791 times.
✓ Branch 46 → 47 taken 1929 times.
✓ Branch 46 → 48 taken 2 times.
|
2722 | if (!isCopyCtor && !isMoveCtor) |
| 618 | 1929 | return true; | |
| 619 | 793 | break; | |
| 620 | } | ||
| 621 | } | ||
| 622 | } | ||
| 623 | 6173 | return false; | |
| 624 | } | ||
| 625 | |||
| 626 | 2023 | bool FunctionManager::hasAnyNonCopyCtor(const Scope *matchScope) { return hasCtor(matchScope, CtorKind::ANY_NON_COPY_NON_MOVE); } | |
| 627 | |||
| 628 | 6372 | bool FunctionManager::hasCopyCtor(const Scope *matchScope) { return hasCtor(matchScope, CtorKind::COPY); } | |
| 629 | |||
| 630 | 2052 | bool FunctionManager::hasUserCopyCtor(const Scope *matchScope) { | |
| 631 |
5/8✓ Branch 2 → 3 taken 2052 times.
✗ Branch 2 → 42 not taken.
✓ Branch 3 → 4 taken 2052 times.
✗ Branch 3 → 42 not taken.
✓ Branch 4 → 5 taken 2052 times.
✗ Branch 4 → 42 not taken.
✓ Branch 37 → 6 taken 8620 times.
✓ Branch 37 → 38 taken 1855 times.
|
10475 | for (const auto &manifestations : matchScope->functions | std::views::values) { |
| 632 |
5/8✓ Branch 7 → 8 taken 8620 times.
✗ Branch 7 → 41 not taken.
✓ Branch 8 → 9 taken 8620 times.
✗ Branch 8 → 41 not taken.
✓ Branch 9 → 10 taken 8620 times.
✗ Branch 9 → 41 not taken.
✓ Branch 34 → 11 taken 9431 times.
✓ Branch 34 → 35 taken 8423 times.
|
17854 | for (const auto &function : manifestations | std::views::values) { |
| 633 |
7/8✓ Branch 12 → 13 taken 9431 times.
✗ Branch 12 → 41 not taken.
✓ Branch 13 → 14 taken 4501 times.
✓ Branch 13 → 15 taken 4930 times.
✓ Branch 14 → 15 taken 1396 times.
✓ Branch 14 → 16 taken 3105 times.
✓ Branch 17 → 18 taken 6326 times.
✓ Branch 17 → 19 taken 3105 times.
|
9431 | if (function.name != CTOR_FUNCTION_NAME || function.implicitDefault) |
| 634 | 6326 | continue; | |
| 635 |
6/8✓ Branch 20 → 21 taken 2174 times.
✓ Branch 20 → 29 taken 931 times.
✓ Branch 21 → 22 taken 2174 times.
✗ Branch 21 → 40 not taken.
✓ Branch 22 → 23 taken 2174 times.
✗ Branch 22 → 40 not taken.
✓ Branch 23 → 24 taken 315 times.
✓ Branch 23 → 29 taken 1859 times.
|
3420 | const bool isCopyCtor = function.paramList.size() == 1 && function.paramList.at(0).qualType.isConstRef() && |
| 636 |
5/8✓ Branch 24 → 25 taken 315 times.
✗ Branch 24 → 40 not taken.
✓ Branch 25 → 26 taken 315 times.
✗ Branch 25 → 40 not taken.
✓ Branch 26 → 27 taken 315 times.
✗ Branch 26 → 40 not taken.
✓ Branch 27 → 28 taken 197 times.
✓ Branch 27 → 29 taken 118 times.
|
315 | function.paramList.at(0).qualType.getBase() == function.thisType; |
| 637 |
2/2✓ Branch 30 → 31 taken 197 times.
✓ Branch 30 → 32 taken 2908 times.
|
3105 | if (isCopyCtor) |
| 638 | 197 | return true; | |
| 639 | } | ||
| 640 | } | ||
| 641 | 1855 | return false; | |
| 642 | } | ||
| 643 | |||
| 644 | 2056 | bool FunctionManager::hasMoveCtor(const Scope *matchScope) { return hasCtor(matchScope, CtorKind::MOVE); } | |
| 645 | |||
| 646 | 12722 | Function *FunctionManager::findMoveCtor(Scope *matchScope) { | |
| 647 |
5/8✓ Branch 2 → 3 taken 12722 times.
✗ Branch 2 → 41 not taken.
✓ Branch 3 → 4 taken 12722 times.
✗ Branch 3 → 41 not taken.
✓ Branch 4 → 5 taken 12722 times.
✗ Branch 4 → 41 not taken.
✓ Branch 36 → 6 taken 117571 times.
✓ Branch 36 → 37 taken 12675 times.
|
130246 | for (auto &manifestations : matchScope->functions | std::views::values) { |
| 648 |
5/8✓ Branch 7 → 8 taken 117571 times.
✗ Branch 7 → 40 not taken.
✓ Branch 8 → 9 taken 117571 times.
✗ Branch 8 → 40 not taken.
✓ Branch 9 → 10 taken 117571 times.
✗ Branch 9 → 40 not taken.
✓ Branch 33 → 11 taken 153650 times.
✓ Branch 33 → 34 taken 117524 times.
|
271174 | for (auto &function : manifestations | std::views::values) { |
| 649 |
3/4✓ Branch 12 → 13 taken 153650 times.
✗ Branch 12 → 40 not taken.
✓ Branch 13 → 14 taken 116642 times.
✓ Branch 13 → 15 taken 37008 times.
|
153650 | if (function.name != CTOR_FUNCTION_NAME) |
| 650 | 116642 | continue; | |
| 651 |
4/6✓ Branch 17 → 18 taken 26625 times.
✗ Branch 17 → 39 not taken.
✓ Branch 18 → 19 taken 26625 times.
✗ Branch 18 → 39 not taken.
✓ Branch 19 → 20 taken 16156 times.
✓ Branch 19 → 28 taken 10469 times.
|
63633 | const bool isMoveCtor = function.paramList.size() == 1 && function.paramList.at(0).qualType.isRef() && |
| 652 |
6/8✓ Branch 16 → 17 taken 26625 times.
✓ Branch 16 → 28 taken 10383 times.
✓ Branch 20 → 21 taken 16156 times.
✗ Branch 20 → 39 not taken.
✓ Branch 21 → 22 taken 16156 times.
✗ Branch 21 → 39 not taken.
✓ Branch 22 → 23 taken 2882 times.
✓ Branch 22 → 28 taken 13274 times.
|
66515 | !function.paramList.at(0).qualType.isConstRef() && |
| 653 |
5/8✓ Branch 23 → 24 taken 2882 times.
✗ Branch 23 → 39 not taken.
✓ Branch 24 → 25 taken 2882 times.
✗ Branch 24 → 39 not taken.
✓ Branch 25 → 26 taken 2882 times.
✗ Branch 25 → 39 not taken.
✓ Branch 26 → 27 taken 47 times.
✓ Branch 26 → 28 taken 2835 times.
|
2882 | function.paramList.at(0).qualType.getBase() == function.thisType; |
| 654 |
2/2✓ Branch 29 → 30 taken 47 times.
✓ Branch 29 → 31 taken 36961 times.
|
37008 | if (isMoveCtor) |
| 655 | 47 | return &function; | |
| 656 | } | ||
| 657 | } | ||
| 658 | 12675 | return nullptr; | |
| 659 | } | ||
| 660 | |||
| 661 | 15859 | bool FunctionManager::hasDtor(const Scope *matchScope) { | |
| 662 |
5/8✓ Branch 2 → 3 taken 15859 times.
✗ Branch 2 → 24 not taken.
✓ Branch 3 → 4 taken 15859 times.
✗ Branch 3 → 24 not taken.
✓ Branch 4 → 5 taken 15859 times.
✗ Branch 4 → 24 not taken.
✓ Branch 20 → 6 taken 125195 times.
✓ Branch 20 → 21 taken 9475 times.
|
134670 | for (const auto &manifestations : matchScope->functions | std::views::values) |
| 663 |
5/8✓ Branch 7 → 8 taken 125195 times.
✗ Branch 7 → 23 not taken.
✓ Branch 8 → 9 taken 125195 times.
✗ Branch 8 → 23 not taken.
✓ Branch 9 → 10 taken 125195 times.
✗ Branch 9 → 23 not taken.
✓ Branch 17 → 11 taken 143520 times.
✓ Branch 17 → 18 taken 118811 times.
|
262331 | for (const auto &function : manifestations | std::views::values) |
| 664 |
3/4✓ Branch 12 → 13 taken 143520 times.
✗ Branch 12 → 23 not taken.
✓ Branch 13 → 14 taken 6384 times.
✓ Branch 13 → 15 taken 137136 times.
|
143520 | if (function.name == DTOR_FUNCTION_NAME) |
| 665 | 6384 | return true; | |
| 666 | 9475 | return false; | |
| 667 | } | ||
| 668 | |||
| 669 | /** | ||
| 670 | * Clear the lookup cache | ||
| 671 | */ | ||
| 672 | 547 | void FunctionManager::cleanup() { | |
| 673 | 547 | lookupCache.clear(); | |
| 674 | 547 | lookupCacheHits = 0; | |
| 675 | 547 | lookupCacheMisses = 0; | |
| 676 | 547 | } | |
| 677 | |||
| 678 | /** | ||
| 679 | * Dump usage statistics for the lookup cache | ||
| 680 | */ | ||
| 681 | 306 | std::string FunctionManager::dumpLookupCacheStatistics() { | |
| 682 |
1/2✓ Branch 2 → 3 taken 306 times.
✗ Branch 2 → 22 not taken.
|
306 | std::stringstream stats; |
| 683 |
2/4✓ Branch 3 → 4 taken 306 times.
✗ Branch 3 → 20 not taken.
✓ Branch 4 → 5 taken 306 times.
✗ Branch 4 → 20 not taken.
|
306 | stats << "FunctionManager lookup cache statistics:" << std::endl; |
| 684 |
3/6✓ Branch 5 → 6 taken 306 times.
✗ Branch 5 → 20 not taken.
✓ Branch 7 → 8 taken 306 times.
✗ Branch 7 → 20 not taken.
✓ Branch 8 → 9 taken 306 times.
✗ Branch 8 → 20 not taken.
|
306 | stats << " lookup cache entries: " << lookupCache.size() << std::endl; |
| 685 |
3/6✓ Branch 9 → 10 taken 306 times.
✗ Branch 9 → 20 not taken.
✓ Branch 10 → 11 taken 306 times.
✗ Branch 10 → 20 not taken.
✓ Branch 11 → 12 taken 306 times.
✗ Branch 11 → 20 not taken.
|
306 | stats << " lookup cache hits: " << lookupCacheHits << std::endl; |
| 686 |
3/6✓ Branch 12 → 13 taken 306 times.
✗ Branch 12 → 20 not taken.
✓ Branch 13 → 14 taken 306 times.
✗ Branch 13 → 20 not taken.
✓ Branch 14 → 15 taken 306 times.
✗ Branch 14 → 20 not taken.
|
306 | stats << " lookup cache misses: " << lookupCacheMisses << std::endl; |
| 687 |
1/2✓ Branch 15 → 16 taken 306 times.
✗ Branch 15 → 20 not taken.
|
612 | return stats.str(); |
| 688 | 306 | } | |
| 689 | |||
| 690 | } // namespace spice::compiler | ||
| 691 |