Lines Matching +full:allocator +full:-
2 * Copyright (c) 2024-2025 Huawei Device Co., Ltd.
7 * http://www.apache.org/licenses/LICENSE-2.0
59 for (ir::AstNode *curr = ast->Parent(); curr != nullptr; curr = curr->Parent()) { in FindEnclosingClassAndFunction()
60 if (curr->IsClassDeclaration()) { in FindEnclosingClassAndFunction()
61 return {curr->AsClassDeclaration(), function}; in FindEnclosingClassAndFunction()
63 if (curr->IsScriptFunction()) { in FindEnclosingClassAndFunction()
64 function = curr->AsScriptFunction(); in FindEnclosingClassAndFunction()
73 return lambda->IsAnyChild([&checker, &lambdaClass](ir::AstNode *ast) { in CheckIfNeedThis()
74 return (ast->IsThisExpression() || ast->IsSuperExpression()) && in CheckIfNeedThis()
75 checker->Relation()->IsIdenticalTo(lambdaClass, ContainingClass(ast)); in CheckIfNeedThis()
87 static util::StringView CreateCalleeName(ArenaAllocator *allocator) in CreateCalleeName() argument
89 auto name = util::UString(util::StringView("lambda$invoke$"), allocator); in CreateCalleeName()
99 auto *allocator = ctx->allocator; in ProcessTypeParameterProperties() local
100 auto *checker = ctx->checker->AsETSChecker(); in ProcessTypeParameterProperties()
102 if (auto *oldConstraint = oldTypeParam->GetConstraintType(); oldConstraint != nullptr) { in ProcessTypeParameterProperties()
103 auto *newConstraint = oldConstraint->Substitute(checker->Relation(), substitution); in ProcessTypeParameterProperties()
104 newTypeParam->SetConstraintType(newConstraint); in ProcessTypeParameterProperties()
105 auto *newConstraintNode = allocator->New<ir::OpaqueTypeNode>(newConstraint, allocator); in ProcessTypeParameterProperties()
106 newTypeParamNode->SetConstraint(newConstraintNode); in ProcessTypeParameterProperties()
107 newConstraintNode->SetParent(newTypeParamNode); in ProcessTypeParameterProperties()
110 if (auto *oldDefault = oldTypeParam->GetDefaultType(); oldDefault != nullptr) { in ProcessTypeParameterProperties()
111 auto *newDefault = oldDefault->Substitute(checker->Relation(), substitution); in ProcessTypeParameterProperties()
112 newTypeParam->SetDefaultType(newDefault); in ProcessTypeParameterProperties()
113 auto *newDefaultNode = allocator->New<ir::OpaqueTypeNode>(newDefault, allocator); in ProcessTypeParameterProperties()
114 newTypeParamNode->SetDefaultType(newDefaultNode); in ProcessTypeParameterProperties()
115 newDefaultNode->SetParent(newTypeParamNode); in ProcessTypeParameterProperties()
127 auto *allocator = ctx->allocator; in CloneTypeParams() local
128 auto *checker = ctx->checker->AsETSChecker(); in CloneTypeParams()
130 auto *newScope = allocator->New<varbinder::LocalScope>(allocator, enclosingScope); in CloneTypeParams()
131 auto newTypeParams = ArenaVector<checker::ETSTypeParameter *>(allocator->Adapter()); in CloneTypeParams()
132 auto newTypeParamNodes = ArenaVector<ir::TSTypeParameter *>(allocator->Adapter()); in CloneTypeParams()
133 auto *substitution = checker->NewSubstitution(); in CloneTypeParams()
136 for (size_t ix = 0; ix < oldIrTypeParams->Params().size(); ix++) { in CloneTypeParams()
137 auto *oldTypeParamNode = oldIrTypeParams->Params()[ix]; in CloneTypeParams()
138 auto *oldTypeParam = enclosingFunction->Signature()->TypeParams()[ix]->AsETSTypeParameter(); in CloneTypeParams()
139 …auto *newTypeParamId = allocator->New<ir::Identifier>(oldTypeParamNode->Name()->Name(), allocator); in CloneTypeParams()
140 …auto *newTypeParamNode = util::NodeAllocator::ForceSetParent<ir::TSTypeParameter>(allocator, newTy… in CloneTypeParams()
141 … nullptr, nullptr, allocator); in CloneTypeParams()
142 auto *newTypeParam = allocator->New<checker::ETSTypeParameter>(); in CloneTypeParams()
143 … auto *newTypeParamDecl = allocator->New<varbinder::TypeParameterDecl>(newTypeParamId->Name()); in CloneTypeParams()
145 …allocator->New<varbinder::LocalVariable>(newTypeParamDecl, varbinder::VariableFlags::TYPE_PARAMETE… in CloneTypeParams()
147 newTypeParam->SetDeclNode(newTypeParamNode); in CloneTypeParams()
149 newTypeParamDecl->BindNode(newTypeParamNode); in CloneTypeParams()
150 newTypeParamVar->SetTsType(newTypeParam); in CloneTypeParams()
151 newScope->InsertBinding(newTypeParamId->Name(), newTypeParamVar); in CloneTypeParams()
152 newTypeParamId->SetVariable(newTypeParamVar); in CloneTypeParams()
156 substitution->emplace(oldTypeParam, newTypeParam); in CloneTypeParams()
159 for (size_t ix = 0; ix < oldIrTypeParams->Params().size(); ix++) { in CloneTypeParams()
160 auto *oldTypeParam = enclosingFunction->Signature()->TypeParams()[ix]->AsETSTypeParameter(); in CloneTypeParams()
165 allocator, std::move(newTypeParamNodes), oldIrTypeParams->RequiredParams()); in CloneTypeParams()
167 newIrTypeParams->SetScope(newScope); in CloneTypeParams()
181 auto *var = varBinder->AddParamDecl(param); in InitNewParameterVariable()
182 var->SetTsType(newParamType); in InitNewParameterVariable()
183 var->SetScope(paramScope); in InitNewParameterVariable()
184 param->SetVariable(var); in InitNewParameterVariable()
185 param->SetTsType(newParamType); in InitNewParameterVariable()
193 auto allocator = ctx->allocator; in CreateLambdaCalleeParameters() local
194 auto checker = ctx->checker->AsETSChecker(); in CreateLambdaCalleeParameters()
195 auto varBinder = ctx->checker->VarBinder(); in CreateLambdaCalleeParameters()
196 auto resParams = ArenaVector<ir::Expression *>(allocator->Adapter()); in CreateLambdaCalleeParameters()
197 auto varMap = ArenaMap<varbinder::Variable *, varbinder::Variable *>(allocator->Adapter()); in CreateLambdaCalleeParameters()
202 auto *newType = capturedVar->TsType()->Substitute(checker->Relation(), substitution); in CreateLambdaCalleeParameters()
204 …allocator, capturedVar->Name(), allocator->New<ir::OpaqueTypeNode>(newType, allocator), allocator); in CreateLambdaCalleeParameters()
206 …til::NodeAllocator::ForceSetParent<ir::ETSParameterExpression>(allocator, newId, false, allocator); in CreateLambdaCalleeParameters()
213 for (auto *oldParam : lambda->Function()->Params()) { in CreateLambdaCalleeParameters()
214 auto *oldParamType = oldParam->AsETSParameterExpression()->Ident()->TsType(); in CreateLambdaCalleeParameters()
215 auto *newParamType = oldParamType->Substitute(checker->Relation(), substitution); in CreateLambdaCalleeParameters()
216 auto *newParam = oldParam->AsETSParameterExpression()->Clone(allocator, nullptr); in CreateLambdaCalleeParameters()
218 if (newParam->IsOptional()) { in CreateLambdaCalleeParameters()
219 newParam->SetOptional(false); in CreateLambdaCalleeParameters()
220 … newParamType = checker->CreateETSUnionType({newParamType, checker->GlobalETSUndefinedType()}); in CreateLambdaCalleeParameters()
223 newParam->SetTypeAnnotation(allocator->New<ir::OpaqueTypeNode>(newParamType, allocator)); in CreateLambdaCalleeParameters()
225 newParam->Ident()->SetTsType(newParamType); in CreateLambdaCalleeParameters()
226 if (newParam->IsRestParameter()) { in CreateLambdaCalleeParameters()
227 newParam->TypeAnnotation()->SetParent(newParam->RestParameter()); in CreateLambdaCalleeParameters()
228 newParam->RestParameter()->SetTsType(newParamType); in CreateLambdaCalleeParameters()
230 newParam->TypeAnnotation()->SetParent(newParam->Ident()); in CreateLambdaCalleeParameters()
233 varMap[oldParam->AsETSParameterExpression()->Variable()] = var; in CreateLambdaCalleeParameters()
235 if (newParam->TypeAnnotation()->IsETSFunctionType()) { in CreateLambdaCalleeParameters()
238 InitScopesPhaseETS::RunExternalNode(newParam->TypeAnnotation(), varBinder); in CreateLambdaCalleeParameters()
252 body->Scope()->SetParent(paramScope); in ProcessCalleeMethodBody()
253 body->IterateRecursively([&](ir::AstNode *node) { in ProcessCalleeMethodBody()
254 if (node->IsIdentifier()) { in ProcessCalleeMethodBody()
255 auto *id = node->AsIdentifier(); in ProcessCalleeMethodBody()
256 if (auto ref = varMap.find(id->Variable()); ref != varMap.end()) { in ProcessCalleeMethodBody()
257 id->SetVariable(ref->second); in ProcessCalleeMethodBody()
258 id->Check(checker); in ProcessCalleeMethodBody()
264 if (node->IsTyped() && node->AsTyped()->TsType() != nullptr) { in ProcessCalleeMethodBody()
265 …node->AsTyped()->SetTsType(node->AsTyped()->TsType()->Substitute(checker->Relation(), substitution… in ProcessCalleeMethodBody()
266 if (node->IsTSNonNullExpression()) { in ProcessCalleeMethodBody()
267 auto expr = node->AsTSNonNullExpression(); in ProcessCalleeMethodBody()
268 … expr->SetOriginalType(expr->OriginalType()->Substitute(checker->Relation(), substitution)); in ProcessCalleeMethodBody()
271 if (node->IsCallExpression()) { in ProcessCalleeMethodBody()
272 node->AsCallExpression()->SetSignature( in ProcessCalleeMethodBody()
273 … node->AsCallExpression()->Signature()->Substitute(checker->Relation(), substitution)); in ProcessCalleeMethodBody()
275 if (node->IsETSNewClassInstanceExpression()) { in ProcessCalleeMethodBody()
276 node->AsETSNewClassInstanceExpression()->SetSignature( in ProcessCalleeMethodBody()
277 …node->AsETSNewClassInstanceExpression()->GetSignature()->Substitute(checker->Relation(), substitut… in ProcessCalleeMethodBody()
279 if (node->IsScriptFunction()) { in ProcessCalleeMethodBody()
280 node->AsScriptFunction()->SetSignature( in ProcessCalleeMethodBody()
281 … node->AsScriptFunction()->Signature()->Substitute(checker->Relation(), substitution)); in ProcessCalleeMethodBody()
283 if (node->IsVariableDeclarator()) { in ProcessCalleeMethodBody()
284 auto *id = node->AsVariableDeclarator()->Id(); in ProcessCalleeMethodBody()
285 …id->Variable()->SetTsType(id->Variable()->TsType()->Substitute(checker->Relation(), substitution)); in ProcessCalleeMethodBody()
294 auto *allocator = ctx->allocator; in SetUpCalleeMethod() local
295 auto *varBinder = ctx->checker->VarBinder()->AsETSBinder(); in SetUpCalleeMethod()
297 auto *calleeClass = info->calleeClass; in SetUpCalleeMethod()
298 auto *funcScope = func->Scope(); in SetUpCalleeMethod()
299 auto *paramScope = funcScope->ParamScope(); in SetUpCalleeMethod()
301 … (info->callReceiver != nullptr ? ir::ModifierFlags::NONE : ir::ModifierFlags::STATIC) | in SetUpCalleeMethod()
302 cmInfo->auxModifierFlags; in SetUpCalleeMethod()
304 auto *calleeNameId = allocator->New<ir::Identifier>(cmInfo->calleeName, allocator); in SetUpCalleeMethod()
305 func->SetIdent(calleeNameId); in SetUpCalleeMethod()
306 calleeNameId->SetParent(func); in SetUpCalleeMethod()
308 auto *calleeNameClone = calleeNameId->Clone(allocator, nullptr); in SetUpCalleeMethod()
309 auto *funcExpr = util::NodeAllocator::ForceSetParent<ir::FunctionExpression>(allocator, func); in SetUpCalleeMethod()
311 …allocator, ir::MethodDefinitionKind::METHOD, calleeNameClone, funcExpr, modifierFlags, allocator, … in SetUpCalleeMethod()
312 calleeClass->Definition()->Body().push_back(method); in SetUpCalleeMethod()
313 method->SetParent(calleeClass->Definition()); in SetUpCalleeMethod()
316 …std::get<1>(varBinder->NewVarDecl<varbinder::FunctionDecl>(func->Start(), allocator, cmInfo->calle… in SetUpCalleeMethod()
317 var->AddFlag(varbinder::VariableFlags::METHOD); in SetUpCalleeMethod()
318 var->SetScope(scopeForMethod); in SetUpCalleeMethod()
319 func->Id()->SetVariable(var); in SetUpCalleeMethod()
320 ES2PANDA_ASSERT(method->Id()); in SetUpCalleeMethod()
321 method->Id()->SetVariable(var); in SetUpCalleeMethod()
322 if (info->callReceiver != nullptr) { in SetUpCalleeMethod()
324 varBinder->AddMandatoryParam(varbinder::TypedBinder::MANDATORY_PARAM_THIS); in SetUpCalleeMethod()
325 …calleeClass->Definition()->TsType()->AsETSObjectType()->AddProperty<checker::PropertyType::INSTANC… in SetUpCalleeMethod()
326 var->AsLocalVariable()); in SetUpCalleeMethod()
328 …calleeClass->Definition()->TsType()->AsETSObjectType()->AddProperty<checker::PropertyType::STATIC_… in SetUpCalleeMethod()
329 var->AsLocalVariable()); in SetUpCalleeMethod()
332 varbinder::BoundContext bctx {varBinder->GetRecordTable(), calleeClass->Definition(), true}; in SetUpCalleeMethod()
333 varBinder->ResolveReferencesForScopeWithContext(func, funcScope); in SetUpCalleeMethod()
335 auto checkerCtx = checker::SavedCheckerContext(ctx->checker, checker::CheckerStatus::IN_CLASS, in SetUpCalleeMethod()
336 … calleeClass->Definition()->TsType()->AsETSObjectType()); in SetUpCalleeMethod()
337 method->Check(ctx->checker->AsETSChecker()); in SetUpCalleeMethod()
346 auto *allocator = ctx->allocator; in CreateCalleeMethod() local
347 auto *varBinder = ctx->checker->VarBinder()->AsETSBinder(); in CreateCalleeMethod()
348 auto *checker = ctx->checker->AsETSChecker(); in CreateCalleeMethod()
350 auto *classScope = info->calleeClass->Definition()->Scope()->AsClassScope(); in CreateCalleeMethod()
352 …auto *oldTypeParams = (info->enclosingFunction != nullptr) ? info->enclosingFunction->TypeParams()… in CreateCalleeMethod()
354 …info->callReceiver != nullptr ? classScope->InstanceMethodScope() : classScope->StaticMethodScope(… in CreateCalleeMethod()
356 …auto [newTypeParams, subst0] = CloneTypeParams(ctx, oldTypeParams, info->enclosingFunction, enclos… in CreateCalleeMethod()
358 auto *scopeForMethod = newTypeParams != nullptr ? newTypeParams->Scope() : enclosingScope; in CreateCalleeMethod()
361 auto paramScope = allocator->New<varbinder::FunctionParamScope>(allocator, scopeForMethod); in CreateCalleeMethod()
363 …auto [params, vMap] = CreateLambdaCalleeParameters(ctx, lambda, *info->capturedVars, paramScope, s… in CreateCalleeMethod()
366 …auto *alternative = lambda->Function()->Signature()->ReturnType()->Substitute(checker->Relation(),… in CreateCalleeMethod()
367 auto *returnType = cmInfo->forcedReturnType != nullptr ? cmInfo->forcedReturnType : alternative; in CreateCalleeMethod()
368 auto returnTypeAnnotation = allocator->New<ir::OpaqueTypeNode>(returnType, allocator); in CreateCalleeMethod()
370 auto funcFlags = ir::ScriptFunctionFlags::METHOD | cmInfo->auxFunctionFlags; in CreateCalleeMethod()
372 … (info->callReceiver != nullptr ? ir::ModifierFlags::NONE : ir::ModifierFlags::STATIC) | in CreateCalleeMethod()
373 cmInfo->auxModifierFlags; in CreateCalleeMethod()
376 allocator, allocator, in CreateCalleeMethod()
377 ISS {cmInfo->body, in CreateCalleeMethod()
379 lambda->Function()->HasReceiver()), in CreateCalleeMethod()
381 …auto *funcScope = cmInfo->body == nullptr ? allocator->New<varbinder::FunctionScope>(allocator, pa… in CreateCalleeMethod()
382 : cmInfo->body->Scope()->AsFunctionScope(); in CreateCalleeMethod()
384 …funcScope->BindName(info->calleeClass->Definition()->TsType()->AsETSObjectType()->AssemblerName()); in CreateCalleeMethod()
385 func->SetScope(funcScope); in CreateCalleeMethod()
386 ProcessCalleeMethodBody(cmInfo->body, checker, paramScope, substitution, varMap); in CreateCalleeMethod()
388 for (auto *param : func->Params()) { in CreateCalleeMethod()
389 param->SetParent(func); in CreateCalleeMethod()
393 funcScope->BindNode(func); in CreateCalleeMethod()
394 paramScope->BindNode(func); in CreateCalleeMethod()
395 funcScope->AssignParamScope(paramScope); in CreateCalleeMethod()
396 paramScope->BindFunctionScope(funcScope); in CreateCalleeMethod()
402 ES2PANDA_ASSERT(ov->Name() == nv->Name()); in CreateCalleeMethod()
403 funcScope->EraseBinding(ov->Name()); in CreateCalleeMethod()
404 funcScope->InsertBinding(ov->Name(), nv); in CreateCalleeMethod()
413 auto *allocator = ctx->allocator; in CreateCallee() local
414 auto *checker = ctx->checker->AsETSChecker(); in CreateCallee()
415 auto *body = lambda->Function()->Body()->AsBlockStatement(); in CreateCallee()
416 auto calleeName = lambda->Function()->IsAsyncFunc() in CreateCallee()
417 … ? (util::UString {checker::ETSChecker::GetAsyncImplName(info->name), allocator}).View() in CreateCallee()
418 : info->name; in CreateCallee()
419 …auto *forcedReturnType = lambda->Function()->IsAsyncFunc() ? checker->GlobalETSAnyType() : nullptr; in CreateCallee()
427 if (lambda->Function()->IsAsyncFunc()) { in CreateCallee()
429 cmInfoAsync.calleeName = info->name; in CreateCallee()
451 auto *allocator = ctx->allocator; in CreateLambdaClassFields() local
452 auto *parser = ctx->parser->AsETSParser(); in CreateLambdaClassFields()
453 auto *checker = ctx->checker->AsETSChecker(); in CreateLambdaClassFields()
454 auto props = ArenaVector<ir::AstNode *>(allocator->Adapter()); in CreateLambdaClassFields()
456 checker::Type *objectType = info->objType != nullptr in CreateLambdaClassFields()
457 ? info->objType in CreateLambdaClassFields()
458 … : (info->calleeClass != nullptr ? info->calleeClass->Definition()->TsType() in CreateLambdaClassFields()
459 … : info->calleeInterface->TsType()); in CreateLambdaClassFields()
461 if (info->callReceiver != nullptr) { in CreateLambdaClassFields()
462 auto *outerThisDeclaration = parser->CreateFormattedClassFieldDefinition( in CreateLambdaClassFields()
463 "@@I1: @@T2", "$this", objectType->Substitute(checker->Relation(), substitution)); in CreateLambdaClassFields()
467 for (auto *captured : *info->capturedVars) { in CreateLambdaClassFields()
468 auto *varDeclaration = parser->CreateFormattedClassFieldDefinition( in CreateLambdaClassFields()
469 "@@I1: @@T2", AvoidMandatoryThis(captured->Name()), in CreateLambdaClassFields()
470 captured->TsType()->Substitute(checker->Relation(), substitution)); in CreateLambdaClassFields()
474 classDefinition->AddProperties(std::move(props)); in CreateLambdaClassFields()
480 auto *allocator = ctx->allocator; in CreateLambdaClassConstructor() local
481 auto *parser = ctx->parser->AsETSParser(); in CreateLambdaClassConstructor()
482 auto *checker = ctx->checker->AsETSChecker(); in CreateLambdaClassConstructor()
484 auto params = ArenaVector<ir::Expression *>(allocator->Adapter()); in CreateLambdaClassConstructor()
485 …auto makeParam = [checker, allocator, substitution, ¶ms](util::StringView name, checker::Type … in CreateLambdaClassConstructor()
486 auto *substitutedType = type->Substitute(checker->Relation(), substitution); in CreateLambdaClassConstructor()
488 … allocator, name, allocator->New<ir::OpaqueTypeNode>(substitutedType, allocator), allocator); in CreateLambdaClassConstructor()
489 …= util::NodeAllocator::ForceSetParent<ir::ETSParameterExpression>(allocator, id, false, allocator); in CreateLambdaClassConstructor()
493 checker::Type *objectType = info->objType != nullptr in CreateLambdaClassConstructor()
494 ? info->objType in CreateLambdaClassConstructor()
495 … : (info->calleeClass != nullptr ? info->calleeClass->Definition()->TsType() in CreateLambdaClassConstructor()
496 … : info->calleeInterface->TsType()); in CreateLambdaClassConstructor()
498 if (info->callReceiver != nullptr) { in CreateLambdaClassConstructor()
501 for (auto *var : *info->capturedVars) { in CreateLambdaClassConstructor()
502 makeParam(AvoidMandatoryThis(var->Name()), var->TsType()); in CreateLambdaClassConstructor()
505 auto bodyStmts = ArenaVector<ir::Statement *>(allocator->Adapter()); in CreateLambdaClassConstructor()
508 …bodyStmts.push_back(parser->CreateFormattedStatement("this.@@I1 = @@I2", adjustedName, adjustedNam… in CreateLambdaClassConstructor()
510 if (info->callReceiver != nullptr) { in CreateLambdaClassConstructor()
513 for (auto *var : *info->capturedVars) { in CreateLambdaClassConstructor()
514 makeStatement(var->Name()); in CreateLambdaClassConstructor()
517 …auto *body = util::NodeAllocator::ForceSetParent<ir::BlockStatement>(allocator, allocator, std::mo… in CreateLambdaClassConstructor()
519 auto *constructorId = allocator->New<ir::Identifier>("constructor", allocator); in CreateLambdaClassConstructor()
522 allocator, allocator, in CreateLambdaClassConstructor()
527 func->SetIdent(constructorId); in CreateLambdaClassConstructor()
528 auto *funcExpr = util::NodeAllocator::ForceSetParent<ir::FunctionExpression>(allocator, func); in CreateLambdaClassConstructor()
531 …allocator, ir::MethodDefinitionKind::CONSTRUCTOR, constructorId->Clone(allocator, nullptr), funcEx… in CreateLambdaClassConstructor()
532 ir::ModifierFlags::NONE, allocator, false); in CreateLambdaClassConstructor()
534 classDefinition->Body().push_back(ctor); in CreateLambdaClassConstructor()
535 ctor->SetParent(classDefinition); in CreateLambdaClassConstructor()
539 // CC-OFFNXT(G.FUN.01, huge_method) solid logic
543 if (!lciInfo->lambdaSignature->HasRestParameter()) { in CreateRestArgumentsArrayReallocation()
544 return ArenaVector<ir::Statement *>(ctx->allocator->Adapter()); in CreateRestArgumentsArrayReallocation()
547 auto *allocator = ctx->allocator; in CreateRestArgumentsArrayReallocation() local
548 auto *parser = ctx->parser->AsETSParser(); in CreateRestArgumentsArrayReallocation()
549 auto *checker = ctx->checker->AsETSChecker(); in CreateRestArgumentsArrayReallocation()
551 auto *restParameterType = lciInfo->lambdaSignature->RestVar()->TsType(); in CreateRestArgumentsArrayReallocation()
552 …auto *restParameterSubstituteType = restParameterType->Substitute(checker->Relation(), lciInfo->su… in CreateRestArgumentsArrayReallocation()
553 bool isFixedArray = restParameterSubstituteType->IsETSArrayType(); in CreateRestArgumentsArrayReallocation()
554 auto *elementType = checker->GetElementTypeOfArray(restParameterSubstituteType); in CreateRestArgumentsArrayReallocation()
556 auto restParameterIndex = GenName(allocator).View(); in CreateRestArgumentsArrayReallocation()
557 auto spreadArrIterator = GenName(allocator).View(); in CreateRestArgumentsArrayReallocation()
560 auto tmpArray = GenName(allocator).View(); in CreateRestArgumentsArrayReallocation()
562 if (elementType->IsETSReferenceType()) { in CreateRestArgumentsArrayReallocation()
563 …// NOTE(vpukhov): this is a clear null-safety violation that should be rewitten with a runtime int… in CreateRestArgumentsArrayReallocation()
569 // CC-OFFNXT(G.FMT.06) false positive in CreateRestArgumentsArrayReallocation()
571 // CC-OFFNXT(G.FMT.06) false positive in CreateRestArgumentsArrayReallocation()
573 // CC-OFFNXT(G.FMT.06) false positive in CreateRestArgumentsArrayReallocation()
576 args = parser->CreateFormattedStatement( in CreateRestArgumentsArrayReallocation()
577 …statements.str(), restParameterIndex, tmpArray, elementType, elementType, lciInfo->restParameterId… in CreateRestArgumentsArrayReallocation()
578 …lciInfo->restArgumentIdentifier, tmpArray, elementType, spreadArrIterator, checker->GlobalETSAnyTy… in CreateRestArgumentsArrayReallocation()
579 …lciInfo->restParameterIdentifier, lciInfo->restArgumentIdentifier, restParameterIndex, spreadArrIt… in CreateRestArgumentsArrayReallocation()
580 … checker->MaybeBoxType(elementType), elementType, restParameterIndex, restParameterIndex); in CreateRestArgumentsArrayReallocation()
582 auto *typeNode = allocator->New<ir::OpaqueTypeNode>( in CreateRestArgumentsArrayReallocation()
583 … checker->GetElementTypeOfArray(lciInfo->lambdaSignature->RestVar()->TsType()), allocator); in CreateRestArgumentsArrayReallocation()
585 // CC-OFFNXT(G.FMT.06) false positive in CreateRestArgumentsArrayReallocation()
587 // CC-OFFNXT(G.FMT.06) false positive in CreateRestArgumentsArrayReallocation()
589 // CC-OFFNXT(G.FMT.06) false positive in CreateRestArgumentsArrayReallocation()
591 // CC-OFFNXT(G.FMT.06) false positive in CreateRestArgumentsArrayReallocation()
593 // CC-OFFNXT(G.FMT.06) false positive in CreateRestArgumentsArrayReallocation()
595 args = parser->CreateFormattedStatement( in CreateRestArgumentsArrayReallocation()
596 statements.str(), restParameterIndex, lciInfo->restArgumentIdentifier, typeNode, in CreateRestArgumentsArrayReallocation()
597 lciInfo->restParameterIdentifier, spreadArrIterator, checker->GlobalETSAnyType(), in CreateRestArgumentsArrayReallocation()
598 …lciInfo->restParameterIdentifier, lciInfo->restArgumentIdentifier, restParameterIndex, spreadArrIt… in CreateRestArgumentsArrayReallocation()
599 checker->MaybeBoxType(elementType), restParameterIndex, restParameterIndex); in CreateRestArgumentsArrayReallocation()
602 return ArenaVector<ir::Statement *>(std::move(args->AsBlockStatement()->Statements())); in CreateRestArgumentsArrayReallocation()
608 auto *allocator = ctx->allocator; in CreateInvokeMethodRestParameter() local
609 auto *checker = ctx->checker->AsETSChecker(); in CreateInvokeMethodRestParameter()
611 auto *restIdent = Gensym(allocator); in CreateInvokeMethodRestParameter()
613 lciInfo->restParameterIdentifier = restIdent->Name(); in CreateInvokeMethodRestParameter()
614 lciInfo->restArgumentIdentifier = GenName(allocator).View(); in CreateInvokeMethodRestParameter()
615 …auto *spread = allocator->New<ir::SpreadElement>(ir::AstNodeType::REST_ELEMENT, allocator, restIde… in CreateInvokeMethodRestParameter()
617 auto *arr = lciInfo->lambdaSignature->RestVar()->TsType()->IsETSTupleType() in CreateInvokeMethodRestParameter()
618 ? lciInfo->lambdaSignature->RestVar()->TsType() in CreateInvokeMethodRestParameter()
619 : checker->CreateETSArrayType(checker->GlobalETSAnyType()); in CreateInvokeMethodRestParameter()
620 auto *typeAnnotation = allocator->New<ir::OpaqueTypeNode>(arr, allocator); in CreateInvokeMethodRestParameter()
622 spread->SetTsTypeAnnotation(typeAnnotation); in CreateInvokeMethodRestParameter()
623 spread->SetTsType(arr); in CreateInvokeMethodRestParameter()
624 restIdent->SetTsType(arr); in CreateInvokeMethodRestParameter()
625 auto *param = allocator->New<ir::ETSParameterExpression>(spread, nullptr, allocator); in CreateInvokeMethodRestParameter()
627 restIdent->SetParent(spread); in CreateInvokeMethodRestParameter()
628 typeAnnotation->SetParent(spread); in CreateInvokeMethodRestParameter()
629 spread->SetParent(param); in CreateInvokeMethodRestParameter()
630 params->push_back(param); in CreateInvokeMethodRestParameter()
638 auto *allocator = ctx->allocator; in CreateCallArgumentsForLambdaClassInvoke() local
639 auto *parser = ctx->parser->AsETSParser(); in CreateCallArgumentsForLambdaClassInvoke()
640 auto *checker = ctx->checker->AsETSChecker(); in CreateCallArgumentsForLambdaClassInvoke()
642 auto callArguments = ArenaVector<ir::Expression *>(allocator->Adapter()); in CreateCallArgumentsForLambdaClassInvoke()
643 for (auto *captured : *info->capturedVars) { in CreateCallArgumentsForLambdaClassInvoke()
644 … auto *arg = parser->CreateFormattedExpression("this.@@I1", AvoidMandatoryThis(captured->Name())); in CreateCallArgumentsForLambdaClassInvoke()
647 for (size_t idx = 0; idx < lciInfo->lambdaSignature->ArgCount(); ++idx) { in CreateCallArgumentsForLambdaClassInvoke()
648 auto lambdaParam = lciInfo->lambdaSignature->Params().at(idx); in CreateCallArgumentsForLambdaClassInvoke()
649 if (idx >= lciInfo->arity) { in CreateCallArgumentsForLambdaClassInvoke()
650 callArguments.push_back(allocator->New<ir::UndefinedLiteral>()); in CreateCallArgumentsForLambdaClassInvoke()
653 auto argName = lambdaParam->Name(); in CreateCallArgumentsForLambdaClassInvoke()
654 auto *type = lambdaParam->TsType()->Substitute(checker->Relation(), lciInfo->substitution); in CreateCallArgumentsForLambdaClassInvoke()
655 … auto *arg = wrapToObject ? parser->CreateFormattedExpression("@@I1 as @@T2 as @@T3", argName, in CreateCallArgumentsForLambdaClassInvoke()
656 … checker->MaybeBoxType(type), type) in CreateCallArgumentsForLambdaClassInvoke()
657 : allocator->New<ir::Identifier>(argName, allocator); in CreateCallArgumentsForLambdaClassInvoke()
661 if (lciInfo->lambdaSignature->HasRestParameter()) { in CreateCallArgumentsForLambdaClassInvoke()
662 … auto *restIdent = allocator->New<ir::Identifier>(lciInfo->restArgumentIdentifier, allocator); in CreateCallArgumentsForLambdaClassInvoke()
663 if (lciInfo->lambdaSignature->RestVar()->TsType()->IsETSArrayType()) { in CreateCallArgumentsForLambdaClassInvoke()
664 …auto *spread = allocator->New<ir::SpreadElement>(ir::AstNodeType::SPREAD_ELEMENT, allocator, restI… in CreateCallArgumentsForLambdaClassInvoke()
665 restIdent->SetParent(spread); in CreateCallArgumentsForLambdaClassInvoke()
668 restIdent->AddAstNodeFlags(ir::AstNodeFlags::RESIZABLE_REST); in CreateCallArgumentsForLambdaClassInvoke()
678 auto *allocator = ctx->allocator; in CreateCallForLambdaClassInvoke() local
679 auto *parser = ctx->parser->AsETSParser(); in CreateCallForLambdaClassInvoke()
683 if (info->callReceiver != nullptr) { in CreateCallForLambdaClassInvoke()
684 calleeReceiver = parser->CreateFormattedExpression("this.@@I1", "$this"); in CreateCallForLambdaClassInvoke()
686 …calleeReceiver = lciInfo->callee->Parent()->AsClassDefinition()->Ident()->Clone(allocator, nullptr… in CreateCallForLambdaClassInvoke()
690 … allocator, calleeReceiver, lciInfo->callee->Key()->Clone(allocator, nullptr)->AsExpression(), in CreateCallForLambdaClassInvoke()
692 …auto *call = parser->CreateFormattedExpression("@@E1(@@[E2)", calleeMemberExpr, std::move(callArgu… in CreateCallForLambdaClassInvoke()
693 ->AsCallExpression(); in CreateCallForLambdaClassInvoke()
695 if (lciInfo->classDefinition->TypeParams() != nullptr) { in CreateCallForLambdaClassInvoke()
696 auto typeArgs = ArenaVector<ir::TypeNode *>(allocator->Adapter()); in CreateCallForLambdaClassInvoke()
697 for (auto *tp : lciInfo->classDefinition->TypeParams()->Params()) { in CreateCallForLambdaClassInvoke()
699 … allocator->New<ir::OpaqueTypeNode>(tp->Name()->AsIdentifier()->Variable()->TsType(), allocator)); in CreateCallForLambdaClassInvoke()
702 …util::NodeAllocator::ForceSetParent<ir::TSTypeParameterInstantiation>(allocator, std::move(typeArg… in CreateCallForLambdaClassInvoke()
703 call->SetTypeParams(typeArg); in CreateCallForLambdaClassInvoke()
704 typeArg->SetParent(call); in CreateCallForLambdaClassInvoke()
713 auto *allocator = ctx->allocator; in CreateLambdaClassInvokeBody() local
714 auto *parser = ctx->parser->AsETSParser(); in CreateLambdaClassInvokeBody()
715 auto *checker = ctx->checker->AsETSChecker(); in CreateLambdaClassInvokeBody()
716 auto *anyType = checker->GlobalETSAnyType(); in CreateLambdaClassInvokeBody()
721 if (lciInfo->lambdaSignature->ReturnType() == checker->GlobalVoidType()) { in CreateLambdaClassInvokeBody()
722 … auto *callStmt = util::NodeAllocator::ForceSetParent<ir::ExpressionStatement>(allocator, call); in CreateLambdaClassInvokeBody()
726 allocator, allocator->New<ir::UndefinedLiteral>()); in CreateLambdaClassInvokeBody()
730 …auto *returnExpr = wrapToObject ? parser->CreateFormattedExpression("@@E1 as @@T2", call, anyType)… in CreateLambdaClassInvokeBody()
731 …auto *returnStmt = util::NodeAllocator::ForceSetParent<ir::ReturnStatement>(allocator, returnExpr); in CreateLambdaClassInvokeBody()
735 …return util::NodeAllocator::ForceSetParent<ir::BlockStatement>(allocator, allocator, std::move(bod… in CreateLambdaClassInvokeBody()
742 auto *allocator = ctx->allocator; in CreateLambdaClassInvokeMethod() local
743 auto *checker = ctx->checker->AsETSChecker(); in CreateLambdaClassInvokeMethod()
744 auto *anyType = checker->GlobalETSAnyType(); in CreateLambdaClassInvokeMethod()
746 auto params = ArenaVector<ir::Expression *>(allocator->Adapter()); in CreateLambdaClassInvokeMethod()
747 for (size_t idx = 0; idx < lciInfo->arity; ++idx) { in CreateLambdaClassInvokeMethod()
748 auto lparam = lciInfo->lambdaSignature->Params().at(idx); in CreateLambdaClassInvokeMethod()
749 …auto *type = wrapToObject ? anyType : lparam->TsType()->Substitute(checker->Relation(), lciInfo->s… in CreateLambdaClassInvokeMethod()
751 … allocator, lparam->Name(), allocator->New<ir::OpaqueTypeNode>(type, allocator), allocator); in CreateLambdaClassInvokeMethod()
752 …= util::NodeAllocator::ForceSetParent<ir::ETSParameterExpression>(allocator, id, false, allocator); in CreateLambdaClassInvokeMethod()
756 if (lciInfo->lambdaSignature->HasRestParameter()) { in CreateLambdaClassInvokeMethod()
760 auto *returnType2 = allocator->New<ir::OpaqueTypeNode>( in CreateLambdaClassInvokeMethod()
762 … : lciInfo->lambdaSignature->ReturnType()->Substitute(checker->Relation(), lciInfo->substitution), in CreateLambdaClassInvokeMethod()
763 allocator); in CreateLambdaClassInvokeMethod()
764 …bool hasReceiver = lciInfo->lambdaSignature->HasSignatureFlag(checker::SignatureFlags::EXTENSION_F… in CreateLambdaClassInvokeMethod()
767 allocator, allocator, in CreateLambdaClassInvokeMethod()
772 auto *invokeId = allocator->New<ir::Identifier>(methodName, allocator); in CreateLambdaClassInvokeMethod()
773 func->SetIdent(invokeId); in CreateLambdaClassInvokeMethod()
775 auto *funcExpr = util::NodeAllocator::ForceSetParent<ir::FunctionExpression>(allocator, func); in CreateLambdaClassInvokeMethod()
777 auto *invokeIdClone = invokeId->Clone(allocator, nullptr); in CreateLambdaClassInvokeMethod()
779 …allocator, ir::MethodDefinitionKind::METHOD, invokeIdClone, funcExpr, ir::ModifierFlags::NONE, all… in CreateLambdaClassInvokeMethod()
781 ES2PANDA_ASSERT(!invokeMethod->IsStatic()); in CreateLambdaClassInvokeMethod()
783 lciInfo->classDefinition->Body().push_back(invokeMethod); in CreateLambdaClassInvokeMethod()
784 invokeMethod->SetParent(lciInfo->classDefinition); in CreateLambdaClassInvokeMethod()
790 if (signature->RestVar() != nullptr) { in FunctionTypeToLambdaProviderType()
791 ES2PANDA_ASSERT(checker->GlobalBuiltinLambdaType(signature->ArgCount(), true)); in FunctionTypeToLambdaProviderType()
792 return checker->GlobalBuiltinLambdaType(signature->ArgCount(), true)->AsETSObjectType(); in FunctionTypeToLambdaProviderType()
795 if (signature->ArgCount() >= checker->GlobalBuiltinFunctionTypeVariadicThreshold()) { in FunctionTypeToLambdaProviderType()
798 return checker->GlobalBuiltinLambdaType(signature->ArgCount(), false)->AsETSObjectType(); in FunctionTypeToLambdaProviderType()
807 auto *classScope = lambdaClass->Definition()->Scope(); in CorrectTheTrueThisForExtensionLambda()
808 ArenaVector<varbinder::Variable *> invokeFuncsOfLambda(ctx->Allocator()->Adapter()); in CorrectTheTrueThisForExtensionLambda()
811 …classScope->FindLocal(compiler::Signatures::LAMBDA_OBJECT_INVOKE, varbinder::ResolveBindingOptions… in CorrectTheTrueThisForExtensionLambda()
813 … classScope->FindLocal(util::StringView(invokeName), varbinder::ResolveBindingOptions::METHODS)); in CorrectTheTrueThisForExtensionLambda()
818 auto *scriptFunc = invokeFuncOfLambda->Declaration() in CorrectTheTrueThisForExtensionLambda()
819 ->AsFunctionDecl() in CorrectTheTrueThisForExtensionLambda()
820 ->Node() in CorrectTheTrueThisForExtensionLambda()
821 ->AsMethodDefinition() in CorrectTheTrueThisForExtensionLambda()
822 ->Value() in CorrectTheTrueThisForExtensionLambda()
823 ->AsFunctionExpression() in CorrectTheTrueThisForExtensionLambda()
824 ->Function(); in CorrectTheTrueThisForExtensionLambda()
825 … if (!scriptFunc->Signature()->HasSignatureFlag(checker::SignatureFlags::EXTENSION_FUNCTION)) { in CorrectTheTrueThisForExtensionLambda()
826 ES2PANDA_ASSERT(!scriptFunc->IsExtensionMethod()); in CorrectTheTrueThisForExtensionLambda()
829 ES2PANDA_ASSERT(scriptFunc->IsExtensionMethod()); in CorrectTheTrueThisForExtensionLambda()
830 auto *functionScope = scriptFunc->Scope(); in CorrectTheTrueThisForExtensionLambda()
831 auto *functionParamScope = scriptFunc->Scope()->ParamScope(); in CorrectTheTrueThisForExtensionLambda()
832 auto *theTrueThisVar = functionParamScope->Params()[0]; in CorrectTheTrueThisForExtensionLambda()
833 auto &bindings = const_cast<varbinder::Scope::VariableMap &>(functionScope->Bindings()); in CorrectTheTrueThisForExtensionLambda()
844 auto *allocator = ctx->allocator; in CreateEmptyLambdaClassDeclaration() local
845 auto *parser = ctx->parser->AsETSParser(); in CreateEmptyLambdaClassDeclaration()
846 auto *checker = ctx->checker->AsETSChecker(); in CreateEmptyLambdaClassDeclaration()
847 auto *varBinder = ctx->checker->VarBinder()->AsETSBinder(); in CreateEmptyLambdaClassDeclaration()
849 auto lambdaClassName = util::UString {std::string_view {"LambdaObject-"}, allocator}; in CreateEmptyLambdaClassDeclaration()
851 …util::StringView &objectName = info->calleeClass != nullptr ? info->calleeClass->Definition()->Ide… in CreateEmptyLambdaClassDeclaration()
852 … : info->calleeInterface->Id()->Name(); in CreateEmptyLambdaClassDeclaration()
854 lambdaClassName.Append(objectName).Append("$").Append(info->name); in CreateEmptyLambdaClassDeclaration()
857 auto *providerTypeReference = checker->AllocNode<ir::ETSTypeReference>( in CreateEmptyLambdaClassDeclaration()
858 checker->AllocNode<ir::ETSTypeReferencePart>( in CreateEmptyLambdaClassDeclaration()
859 …checker->AllocNode<ir::Identifier>(lambdaProviderClass->AsETSObjectType()->Name(), checker->Alloca… in CreateEmptyLambdaClassDeclaration()
860 nullptr, nullptr, allocator), in CreateEmptyLambdaClassDeclaration()
861 allocator); in CreateEmptyLambdaClassDeclaration()
864 stream << "@" << Signatures::NAMED_FUNCTION_OBJECT << "({name: \"" << info->originalFuncName in CreateEmptyLambdaClassDeclaration()
868 …parser->CreateFormattedTopLevelStatement(stream.str(), lambdaClassName, providerTypeReference, fnI… in CreateEmptyLambdaClassDeclaration()
869 ->AsClassDeclaration(); in CreateEmptyLambdaClassDeclaration()
870 auto *classDefinition = classDeclaration->Definition(); in CreateEmptyLambdaClassDeclaration()
873 classDefinition->Body().clear(); // remove the default empty constructor in CreateEmptyLambdaClassDeclaration()
874 classDefinition->AddModifier(ir::ModifierFlags::PUBLIC | ir::ModifierFlags::FUNCTIONAL); in CreateEmptyLambdaClassDeclaration()
876 classDefinition->SetTypeParams(newTypeParams); in CreateEmptyLambdaClassDeclaration()
877 newTypeParams->SetParent(classDefinition); in CreateEmptyLambdaClassDeclaration()
880 auto *program = varBinder->GetRecordTable()->Program(); in CreateEmptyLambdaClassDeclaration()
881 program->Ast()->Statements().push_back(classDeclaration); in CreateEmptyLambdaClassDeclaration()
882 classDeclaration->SetParent(program->Ast()); in CreateEmptyLambdaClassDeclaration()
890 auto *checker = ctx->checker->AsETSChecker(); in CreateLambdaClass()
891 auto *varBinder = ctx->checker->VarBinder()->AsETSBinder(); in CreateLambdaClass()
893 …auto *oldTypeParams = (info->enclosingFunction != nullptr) ? info->enclosingFunction->TypeParams()… in CreateLambdaClass()
895 …CloneTypeParams(ctx, oldTypeParams, info->enclosingFunction, ctx->parserProgram->GlobalClassScope(… in CreateLambdaClass()
898 …auto fnInterface = fntype->Substitute(checker->Relation(), substitution)->ArrowToFunctionalInterfa… in CreateLambdaClass()
899 auto lambdaProviderClass = FunctionTypeToLambdaProviderType(checker, fntype->ArrowSignature()); in CreateLambdaClass()
901 …auto lexScope = varbinder::LexicalScope<varbinder::Scope>::Enter(varBinder, ctx->parserProgram->Gl… in CreateLambdaClass()
905 auto classDefinition = classDeclaration->Definition(); in CreateLambdaClass()
906 if (info->isFunctionReference) { in CreateLambdaClass()
907 ES2PANDA_ASSERT(callee->Function()); in CreateLambdaClass()
908 classDefinition->SetFunctionalReferenceReferencedMethod(callee); in CreateLambdaClass()
909 classDefinition->SetModifiers(classDefinition->Modifiers() | in CreateLambdaClass()
916 auto signature = fntype->ArrowSignature(); in CreateLambdaClass()
924 for (size_t arity = signature->MinArgCount(); arity <= signature->ArgCount(); ++arity) { in CreateLambdaClass()
927 …ring {checker::FunctionalInterfaceInvokeName(arity, signature->HasRestParameter()), ctx->allocator} in CreateLambdaClass()
930 // NOTE(vpukhov): for optional methods, the required invokeRk k={min, max-1} is not emitted in CreateLambdaClass()
935 varBinder->ResolveReferencesForScopeWithContext(classDeclaration, varBinder->TopScope()); in CreateLambdaClass()
936 classDeclaration->Check(checker); in CreateLambdaClass()
937 CorrectTheTrueThisForExtensionLambda(ctx, classDeclaration, signature->MinArgCount(), in CreateLambdaClass()
938 signature->HasRestParameter()); in CreateLambdaClass()
946 auto *allocator = ctx->allocator; in CreateConstructorCall() local
947 auto *varBinder = ctx->checker->VarBinder()->AsETSBinder(); in CreateConstructorCall()
948 auto *checker = ctx->checker->AsETSChecker(); in CreateConstructorCall()
950 auto args = ArenaVector<ir::Expression *>(allocator->Adapter()); in CreateConstructorCall()
951 if (info->callReceiver != nullptr) { in CreateConstructorCall()
952 args.push_back(info->callReceiver); in CreateConstructorCall()
954 for (auto captured : *info->capturedVars) { in CreateConstructorCall()
955 auto *id = allocator->New<ir::Identifier>(captured->Name(), allocator); in CreateConstructorCall()
959 … checker::ETSObjectType *constructedType = lambdaClass->Definition()->TsType()->AsETSObjectType(); in CreateConstructorCall()
960 if (info->enclosingFunction != nullptr) { in CreateConstructorCall()
961 constructedType = constructedType->SubstituteArguments(checker->Relation(), in CreateConstructorCall()
962 … info->enclosingFunction->Signature()->TypeParams()); in CreateConstructorCall()
965 allocator, allocator->New<ir::OpaqueTypeNode>(constructedType, allocator), std::move(args)); in CreateConstructorCall()
966 auto *lambdaOrFuncRefParent = lambdaOrFuncRef->Parent(); in CreateConstructorCall()
968 newExpr->SetParent(lambdaOrFuncRefParent); in CreateConstructorCall()
969 // NOTE(dslynko, #19869): Required for correct debug-info generation in CreateConstructorCall()
971 …newExpr->SetRange(lambdaOrFuncRefParent != nullptr ? lambdaOrFuncRefParent->Range() : lambdaOrFunc… in CreateConstructorCall()
975 varBinder->ResolveReferencesForScopeWithContext(newExpr, nearestScope); in CreateConstructorCall()
978 …info->calleeClass != nullptr ? info->calleeClass->Definition()->TsType() : info->calleeInterface->… in CreateConstructorCall()
980 …checker::SavedCheckerContext(ctx->checker, checker::CheckerStatus::IN_CLASS, objectType->AsETSObje… in CreateConstructorCall()
981 auto scopeCtx = checker::ScopeContext(ctx->checker, nearestScope); in CreateConstructorCall()
982 newExpr->Check(checker); in CreateConstructorCall()
989 auto *allocator = ctx->allocator; in ConvertLambda() local
990 auto *checker = ctx->checker->AsETSChecker(); in ConvertLambda()
992 lambda->Check(checker); in ConvertLambda()
993 ES2PANDA_ASSERT(lambda->TsType()->IsETSFunctionType()); in ConvertLambda()
997 info.name = CreateCalleeName(allocator); in ConvertLambda()
999 if ((lambda->Parent() != nullptr) && lambda->Parent()->IsVariableDeclarator()) { in ConvertLambda()
1000 … info.originalFuncName = lambda->Parent()->AsVariableDeclarator()->Id()->AsIdentifier()->Name(); in ConvertLambda()
1001 } else if ((lambda->Parent() != nullptr) && lambda->Parent()->IsClassProperty()) { in ConvertLambda()
1002 info.originalFuncName = lambda->Parent()->AsClassProperty()->Id()->Name(); in ConvertLambda()
1005 auto capturedVars = FindCaptured(allocator, lambda); in ConvertLambda()
1007 …info.callReceiver = CheckIfNeedThis(lambda, checker) ? allocator->New<ir::ThisExpression>() : null… in ConvertLambda()
1011 auto *lambdaType = lambda->TsType()->AsETSFunctionType(); in ConvertLambda()
1019 auto *allocator = ctx->allocator; in GetWrappingLambdaParentFunction() local
1020 ArenaVector<ir::Expression *> params {allocator->Adapter()}; in GetWrappingLambdaParentFunction()
1021 for (auto *p : signature->Params()) { in GetWrappingLambdaParentFunction()
1023 allocator, in GetWrappingLambdaParentFunction()
1024 …allocator->New<ir::Identifier>(p->Name(), allocator->New<ir::OpaqueTypeNode>(p->TsType(), allocato… in GetWrappingLambdaParentFunction()
1025 allocator), in GetWrappingLambdaParentFunction()
1026 false, allocator)); in GetWrappingLambdaParentFunction()
1029 allocator, allocator, in GetWrappingLambdaParentFunction()
1033 … allocator->New<ir::OpaqueTypeNode>(signature->ReturnType(), allocator)}, in GetWrappingLambdaParentFunction()
1036 ArenaVector<ir::Statement *> bodyStmts {allocator->Adapter()}; in GetWrappingLambdaParentFunction()
1037 ArenaVector<ir::Expression *> callArgs {allocator->Adapter()}; in GetWrappingLambdaParentFunction()
1039 for (auto *p : func->Params()) { in GetWrappingLambdaParentFunction()
1040 ir::Identifier *clone = p->AsETSParameterExpression()->Ident()->Clone(allocator, nullptr); in GetWrappingLambdaParentFunction()
1042 if (clone->IsIdentifier() && (clone->IsReference(ScriptExtension::ETS)) && in GetWrappingLambdaParentFunction()
1043 (clone->TypeAnnotation() != nullptr)) { in GetWrappingLambdaParentFunction()
1044 clone->SetTsTypeAnnotation(nullptr); in GetWrappingLambdaParentFunction()
1048 …auto *callExpr = util::NodeAllocator::ForceSetParent<ir::CallExpression>(allocator, funcRef, std::… in GetWrappingLambdaParentFunction()
1051 if (signature->ReturnType() == ctx->checker->AsETSChecker()->GlobalVoidType()) { in GetWrappingLambdaParentFunction()
1052 stmt = util::NodeAllocator::ForceSetParent<ir::ExpressionStatement>(allocator, callExpr); in GetWrappingLambdaParentFunction()
1054 stmt = util::NodeAllocator::ForceSetParent<ir::ReturnStatement>(allocator, callExpr); in GetWrappingLambdaParentFunction()
1057 …func->SetBody(util::NodeAllocator::ForceSetParent<ir::BlockStatement>(allocator, allocator, std::m… in GetWrappingLambdaParentFunction()
1058 ES2PANDA_ASSERT(func->Body()); in GetWrappingLambdaParentFunction()
1059 func->Body()->SetParent(func); in GetWrappingLambdaParentFunction()
1065 auto *allocator = ctx->allocator; in CreateWrappingLambda() local
1066 auto *varBinder = ctx->checker->VarBinder()->AsETSBinder(); in CreateWrappingLambda()
1067 ES2PANDA_ASSERT(funcRef->TsType()->IsETSArrowType()); in CreateWrappingLambda()
1068 auto signature = funcRef->TsType()->AsETSFunctionType()->ArrowSignature(); in CreateWrappingLambda()
1070 auto *parent = funcRef->Parent(); in CreateWrappingLambda()
1073 …bda = util::NodeAllocator::ForceSetParent<ir::ArrowFunctionExpression>(allocator, func, allocator); in CreateWrappingLambda()
1075 lambda->SetParent(parent); in CreateWrappingLambda()
1080 varBinder->ResolveReferencesForScopeWithContext(lambda, nearestScope); in CreateWrappingLambda()
1084 auto checkerCtx = checker::SavedCheckerContext(ctx->checker, checker::CheckerStatus::IN_CLASS, in CreateWrappingLambda()
1085 … enclosingClass->Definition()->TsType()->AsETSObjectType()); in CreateWrappingLambda()
1086 auto scopeCtx = checker::ScopeContext(ctx->checker, nearestScope); in CreateWrappingLambda()
1087 lambda->Check(ctx->checker->AsETSChecker()); in CreateWrappingLambda()
1095 auto *allocator = ctx->allocator; in GenerateLambdaInfoForFunctionReference() local
1097 if (method->Parent()->Parent()->IsClassDeclaration()) { in GenerateLambdaInfoForFunctionReference()
1098 info.calleeClass = method->Parent()->Parent()->AsClassDeclaration(); in GenerateLambdaInfoForFunctionReference()
1099 } else if (method->Parent()->Parent()->IsTSInterfaceDeclaration()) { in GenerateLambdaInfoForFunctionReference()
1100 info.calleeInterface = method->Parent()->Parent()->AsTSInterfaceDeclaration(); in GenerateLambdaInfoForFunctionReference()
1105 info.name = CreateCalleeName(allocator); in GenerateLambdaInfoForFunctionReference()
1106 info.originalFuncName = method->Id()->Name(); in GenerateLambdaInfoForFunctionReference()
1107 info.capturedVars = allocator->New<ArenaSet<varbinder::Variable *>>(allocator->Adapter()); in GenerateLambdaInfoForFunctionReference()
1109 if (method->IsStatic()) { in GenerateLambdaInfoForFunctionReference()
1112 ES2PANDA_ASSERT(funcRef->IsMemberExpression()); in GenerateLambdaInfoForFunctionReference()
1113 info.callReceiver = funcRef->AsMemberExpression()->Object(); in GenerateLambdaInfoForFunctionReference()
1115 if (funcRef->IsMemberExpression()) { in GenerateLambdaInfoForFunctionReference()
1116 info.objType = funcRef->AsMemberExpression()->ObjType(); in GenerateLambdaInfoForFunctionReference()
1123 ES2PANDA_ASSERT(funcRef->IsIdentifier() || in ConvertFunctionReference()
1124 (funcRef->IsMemberExpression() && in ConvertFunctionReference()
1125 … funcRef->AsMemberExpression()->Kind() == ir::MemberExpressionKind::PROPERTY_ACCESS && in ConvertFunctionReference()
1126 funcRef->AsMemberExpression()->Property()->IsIdentifier())); in ConvertFunctionReference()
1128 if (funcRef->IsIdentifier()) { in ConvertFunctionReference()
1129 var = funcRef->AsIdentifier()->Variable(); in ConvertFunctionReference()
1131 auto *mexpr = funcRef->AsMemberExpression(); in ConvertFunctionReference()
1132 …// NOTE(gogabr): mexpr->PropVar() is a synthetic variable wwith no reference to the method definit… in ConvertFunctionReference()
1133 auto refVar = ctx->checker->AsETSChecker()->GetTargetRef(mexpr); in ConvertFunctionReference()
1136 if (refVar != nullptr && refVar->HasFlag(varbinder::VariableFlags::CLASS)) { in ConvertFunctionReference()
1143 …mexpr->Object()->TsType()->AsETSObjectType()->GetProperty(mexpr->Property()->AsIdentifier()->Name(… in ConvertFunctionReference()
1147 ES2PANDA_ASSERT(var->Declaration()->Node()->IsMethodDefinition()); in ConvertFunctionReference()
1148 auto *method = var->Declaration()->Node()->AsMethodDefinition(); in ConvertFunctionReference()
1150 if (method->IsPrivate() || method->IsProtected()) { in ConvertFunctionReference()
1159 ES2PANDA_ASSERT(funcRef->TsType()->IsETSArrowType()); in ConvertFunctionReference()
1160 … auto *lambdaClass = CreateLambdaClass(ctx, funcRef->TsType()->AsETSFunctionType(), method, &info); in ConvertFunctionReference()
1163 if (constructorCall->TsType()->IsETSObjectType()) { in ConvertFunctionReference()
1164 …constructorCall->TsType()->AsETSObjectType()->AddObjectFlag(checker::ETSObjectFlags::FUNCTIONAL_RE… in ConvertFunctionReference()
1177 auto const *callee = node->Callee(); in IsFunctionOrMethodCall()
1178 if (callee->TsType() != nullptr && callee->TsType()->IsETSExtensionFuncHelperType()) { in IsFunctionOrMethodCall()
1184 if (callee->IsMemberExpression()) { in IsFunctionOrMethodCall()
1185 auto me = callee->AsMemberExpression(); in IsFunctionOrMethodCall()
1186 ES2PANDA_ASSERT(me->TsType() != nullptr); in IsFunctionOrMethodCall()
1187 …if (me->Object()->TsType() != nullptr && checker->GetApparentType(me->Object()->TsType())->IsETSUn… in IsFunctionOrMethodCall()
1188 me->TsType()->IsETSMethodType()) { in IsFunctionOrMethodCall()
1194 if (callee->IsMemberExpression() && in IsFunctionOrMethodCall()
1195 (callee->AsMemberExpression()->Kind() & ir::MemberExpressionKind::PROPERTY_ACCESS) != 0) { in IsFunctionOrMethodCall()
1196 var = callee->AsMemberExpression()->Property()->Variable(); in IsFunctionOrMethodCall()
1197 } else if (callee->IsIdentifier()) { in IsFunctionOrMethodCall()
1198 var = callee->AsIdentifier()->Variable(); in IsFunctionOrMethodCall()
1201 …return var != nullptr && !IsVariableOriginalAccessor(var) && (var->Flags() & varbinder::VariableFl… in IsFunctionOrMethodCall()
1206 auto *allocator = ctx->allocator; in InsertInvokeCall() local
1207 auto *checker = ctx->checker->AsETSChecker(); in InsertInvokeCall()
1208 auto *varBinder = checker->VarBinder()->AsETSBinder(); in InsertInvokeCall()
1210 auto *oldCallee = call->Callee(); in InsertInvokeCall()
1211 auto *oldType = checker->GetApparentType(oldCallee->TsType()); in InsertInvokeCall()
1213 size_t arity = call->Arguments().size(); in InsertInvokeCall()
1214 auto *ifaceType = oldType->IsETSObjectType() in InsertInvokeCall()
1215 ? oldType->AsETSObjectType() in InsertInvokeCall()
1216 … : oldType->AsETSFunctionType()->ArrowToFunctionalInterfaceDesiredArity(checker, arity); in InsertInvokeCall()
1218 if (ifaceType->IsETSDynamicType()) { in InsertInvokeCall()
1222 …oldType->IsETSFunctionType() && oldType->AsETSFunctionType()->ArrowSignature()->HasRestParameter(); in InsertInvokeCall()
1224 … util::UString {checker::FunctionalInterfaceInvokeName(arity, hasRestParam), allocator}.View(); in InsertInvokeCall()
1225 …auto *prop = ifaceType->GetProperty(invokeMethodName, checker::PropertySearchFlags::SEARCH_INSTANC… in InsertInvokeCall()
1228 auto *invoke0Id = allocator->New<ir::Identifier>(invokeMethodName, allocator); in InsertInvokeCall()
1230 invoke0Id->SetTsType(prop->TsType()); in InsertInvokeCall()
1231 invoke0Id->SetVariable(prop); in InsertInvokeCall()
1234 allocator, oldCallee, invoke0Id, ir::MemberExpressionKind::PROPERTY_ACCESS, false, false); in InsertInvokeCall()
1236 newCallee->SetTsType(prop->TsType()); in InsertInvokeCall()
1237 newCallee->SetObjectType(ifaceType); in InsertInvokeCall()
1239 call->SetCallee(newCallee); in InsertInvokeCall()
1240 call->SetSignature(prop->TsType()->AsETSFunctionType()->CallSignatures()[0]); in InsertInvokeCall()
1246 for (auto *arg : call->Arguments()) { in InsertInvokeCall()
1247 auto boxingFlags = arg->GetBoxingUnboxingFlags(); in InsertInvokeCall()
1248 Recheck(ctx->phaseManager, varBinder, checker, arg); in InsertInvokeCall()
1249 arg->SetBoxingUnboxingFlags(boxingFlags); in InsertInvokeCall()
1257 return expr->Callee()->IsThisExpression() || expr->Callee()->IsSuperExpression(); in IsRedirectingConstructorCall()
1262 … return expr->Parent()->IsCallExpression() && expr->Parent()->AsCallExpression()->Callee() == expr; in IsInCalleePosition()
1267 if (id->Parent() != nullptr && id->Parent()->IsMemberExpression()) { in IsEnumFunctionCall()
1268 const auto *const expr = id->Parent()->AsMemberExpression(); in IsEnumFunctionCall()
1269 if (expr->Object()->TsType()->IsETSEnumType()) { in IsEnumFunctionCall()
1280 … return var != nullptr && var->Declaration() != nullptr && var->Declaration()->IsFunctionDecl() && in IsValidFunctionDeclVar()
1281 !var->TsType()->HasTypeFlag(checker::TypeFlag::GETTER_SETTER); in IsValidFunctionDeclVar()
1286 if (node->IsArrowFunctionExpression()) { in BuildLambdaClassWhenNeeded()
1287 return ConvertLambda(ctx, node->AsArrowFunctionExpression()); in BuildLambdaClassWhenNeeded()
1290 if (node->IsIdentifier()) { in BuildLambdaClassWhenNeeded()
1291 auto *id = node->AsIdentifier(); in BuildLambdaClassWhenNeeded()
1292 auto *var = id->Variable(); in BuildLambdaClassWhenNeeded()
1295 …if (id->IsReference(ScriptExtension::ETS) && id->TsType() != nullptr && id->TsType()->IsETSFunctio… in BuildLambdaClassWhenNeeded()
1300 if (node->IsMemberExpression()) { in BuildLambdaClassWhenNeeded()
1301 auto *mexpr = node->AsMemberExpression(); in BuildLambdaClassWhenNeeded()
1302 … if (mexpr->Kind() == ir::MemberExpressionKind::PROPERTY_ACCESS && mexpr->TsType() != nullptr && in BuildLambdaClassWhenNeeded()
1303 mexpr->TsType()->IsETSFunctionType() && mexpr->Object()->TsType()->IsETSObjectType()) { in BuildLambdaClassWhenNeeded()
1304 ES2PANDA_ASSERT(mexpr->Property()->IsIdentifier()); in BuildLambdaClassWhenNeeded()
1305 auto *var = mexpr->Object()->TsType()->AsETSObjectType()->GetProperty( in BuildLambdaClassWhenNeeded()
1306 mexpr->Property()->AsIdentifier()->Name(), in BuildLambdaClassWhenNeeded()
1320 if (!node->IsExpression() || !node->AsExpression()->IsTypeNode()) { in LowerTypeNodeIfNeeded()
1324 auto type = node->AsExpression()->AsTypeNode()->TsType(); in LowerTypeNodeIfNeeded()
1325 if (type == nullptr || !type->IsETSArrowType()) { in LowerTypeNodeIfNeeded()
1329 auto allocator = ctx->allocator; in LowerTypeNodeIfNeeded() local
1330 auto checker = ctx->checker->AsETSChecker(); in LowerTypeNodeIfNeeded()
1333 …allocator->New<ir::OpaqueTypeNode>(type->AsETSFunctionType()->ArrowToFunctionalInterface(checker),… in LowerTypeNodeIfNeeded()
1334 newTypeNode->SetParent(node->Parent()); in LowerTypeNodeIfNeeded()
1340 auto *varBinder = ctx->checker->VarBinder()->AsETSBinder(); in PerformForModule()
1341 … varbinder::RecordTableContext bctx {varBinder, program == ctx->parserProgram ? nullptr : program}; in PerformForModule()
1342 …parser::SavedFormattingFileName savedFormattingName(ctx->parser->AsETSParser(), "lambda-conversion… in PerformForModule()
1346 if (program == ctx->parserProgram && in PerformForModule()
1347 … ctx->config->options->GetCompilationMode() != CompilationMode::GEN_ABC_FOR_EXTERNAL_SOURCE) { in PerformForModule()
1351 program->Ast()->TransformChildrenRecursivelyPostorder( in PerformForModule()
1354 program->Ast()->TransformChildrenRecursivelyPreorder( in PerformForModule()
1358 if (node->IsCallExpression() && in PerformForModule()
1359 !IsFunctionOrMethodCall(ctx->checker->AsETSChecker(), node->AsCallExpression()) && in PerformForModule()
1360 !IsRedirectingConstructorCall(node->AsCallExpression())) { in PerformForModule()
1361 return InsertInvokeCall(ctx, node->AsCallExpression()); in PerformForModule()
1367 program->Ast()->TransformChildrenRecursivelyPreorder(insertInvokeIfNeeded, Name()); in PerformForModule()
1375 …return !program->Ast()->IsAnyChild([](ir::AstNode const *node) { return node->IsArrowFunctionExpre… in PostconditionForModule()