| 243 | } |
| 244 | |
| 245 | bool BfConstResolver::PrepareMethodArguments(BfAstNode* targetSrc, BfMethodMatcher* methodMatcher, Array<BfIRValue>& llvmArgs) |
| 246 | { |
| 247 | int argIdx = 0; |
| 248 | int paramIdx = 0; |
| 249 | |
| 250 | int extendedParamIdx = 0; |
| 251 | |
| 252 | SetAndRestoreValue<bool> ignoreWrites(mModule->mBfIRBuilder->mIgnoreWrites, true); |
| 253 | |
| 254 | llvm::SmallVector<BfIRValue, 4> expandedParamsConstValues; |
| 255 | BfType* expandedParamsElementType = NULL; |
| 256 | |
| 257 | // We don't do GetMethodInstance in mModule, because our module may not have init finished yet |
| 258 | //auto targetModule = methodMatcher->mBestMethodTypeInstance->mModule; |
| 259 | auto targetModule = mModule->mContext->mUnreifiedModule; |
| 260 | auto moduleMethodInstance = targetModule->GetMethodInstance(methodMatcher->mBestMethodTypeInstance, methodMatcher->mBestMethodDef, methodMatcher->mBestMethodGenericArguments); |
| 261 | auto methodInstance = moduleMethodInstance.mMethodInstance; |
| 262 | |
| 263 | if (methodInstance->mReturnType == NULL) |
| 264 | { |
| 265 | mModule->AssertErrorState(); |
| 266 | return false; |
| 267 | } |
| 268 | |
| 269 | auto methodDef = methodMatcher->mBestMethodDef; |
| 270 | auto& arguments = methodMatcher->mArguments; |
| 271 | |
| 272 | mModule->AddDependency(methodInstance->mReturnType, mModule->mCurTypeInstance, BfDependencyMap::DependencyFlag_LocalUsage); |
| 273 | for (int paramIdx = 0; paramIdx < methodInstance->GetParamCount(); paramIdx++) |
| 274 | { |
| 275 | auto paramType = methodInstance->GetParamType(paramIdx); |
| 276 | mModule->AddDependency(paramType, mModule->mCurTypeInstance, BfDependencyMap::DependencyFlag_LocalUsage); |
| 277 | } |
| 278 | |
| 279 | while (true) |
| 280 | { |
| 281 | if (paramIdx >= (int)methodInstance->GetParamCount()) |
| 282 | { |
| 283 | if (argIdx < (int)arguments.size()) |
| 284 | { |
| 285 | BfAstNode* errorRef = arguments[methodInstance->GetParamCount()].mExpression; |
| 286 | if (errorRef->GetSourceData() == NULL) |
| 287 | errorRef = targetSrc; |
| 288 | mModule->Fail(StrFormat("Too many arguments. Expected %d fewer.", (int)arguments.size() - methodInstance->GetParamCount()), errorRef); |
| 289 | if (methodInstance->mMethodDef->mMethodDeclaration != NULL) |
| 290 | mModule->mCompiler->mPassInstance->MoreInfo(StrFormat("See method declaration"), methodInstance->mMethodDef->mMethodDeclaration); |
| 291 | return false; |
| 292 | } |
| 293 | break; |
| 294 | } |
| 295 | |
| 296 | BfType* wantType = NULL; |
| 297 | if (expandedParamsElementType != NULL) |
| 298 | { |
| 299 | wantType = expandedParamsElementType; |
| 300 | } |
| 301 | else |
| 302 | { |
no test coverage detected