From 199ffd07ade110320a0a1873eec5d42d4079555b Mon Sep 17 00:00:00 2001 From: Redkin Mikhail Date: Mon, 12 Feb 2024 15:52:11 +0300 Subject: [PATCH] Fix linter warnings Issue https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/I91LQZ Reason Added new checker Description Fixed linter warnings Tests All required pre-merge tests passed. Results are available in the ggwatcher. Signed-off-by: Redkin Mikhail --- ets2panda/checker/ETSchecker.cpp | 4 +- ets2panda/checker/ETSchecker.h | 1 + ets2panda/checker/ets/dynamic.cpp | 99 ++++++++++++++++++----- ets2panda/checker/ets/enum.cpp | 85 ++++++++++++++------ ets2panda/checker/ets/function.cpp | 105 +++++++++++++++++++++++-- ets2panda/checker/ets/helpers.cpp | 30 +++++-- ets2panda/checker/ets/object.cpp | 8 +- ets2panda/checker/ets/typeCreation.cpp | 17 ++++ 8 files changed, 294 insertions(+), 55 deletions(-) diff --git a/ets2panda/checker/ETSchecker.cpp b/ets2panda/checker/ETSchecker.cpp index 89e2e4a9e5..37a8bea978 100644 --- a/ets2panda/checker/ETSchecker.cpp +++ b/ets2panda/checker/ETSchecker.cpp @@ -182,9 +182,11 @@ bool ETSChecker::StartChecker([[maybe_unused]] varbinder::VarBinder *varbinder, } CheckProgram(Program(), true); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) BuildDynamicCallClass(true); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) BuildDynamicCallClass(false); - + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) BuildDynamicImportClass(); #ifndef NDEBUG diff --git a/ets2panda/checker/ETSchecker.h b/ets2panda/checker/ETSchecker.h index 83a8ff559d..1c90232f5b 100644 --- a/ets2panda/checker/ETSchecker.h +++ b/ets2panda/checker/ETSchecker.h @@ -618,6 +618,7 @@ public: template T *AllocNode(Args &&...args) { + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) return util::NodeAllocator::ForceSetParent(Allocator(), std::forward(args)...); } diff --git a/ets2panda/checker/ets/dynamic.cpp b/ets2panda/checker/ets/dynamic.cpp index 71d41cc679..80ac4bd698 100644 --- a/ets2panda/checker/ets/dynamic.cpp +++ b/ets2panda/checker/ets/dynamic.cpp @@ -51,7 +51,9 @@ ir::ETSParameterExpression *ETSChecker::AddParam(varbinder::FunctionParamScope * checker::Type *type) { auto paramCtx = varbinder::LexicalScope::Enter(VarBinder(), paramScope, false); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *paramIdent = AllocNode(name, Allocator()); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *param = AllocNode(paramIdent, nullptr); auto *paramVar = std::get<1>(VarBinder()->AddParamDecl(param)); paramVar->SetTsType(type); @@ -86,6 +88,7 @@ template ir::ScriptFunction *ETSChecker::CreateDynamicCallIntrinsic(ir::Expression *callee, const ArenaVector &arguments, Language lang) { + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *paramScope = Allocator()->New(Allocator(), nullptr); auto *scope = Allocator()->New(Allocator(), paramScope); @@ -96,17 +99,21 @@ ir::ScriptFunction *ETSChecker::CreateDynamicCallIntrinsic(ir::Expression *calle auto dynamicType = GlobalBuiltinDynamicType(lang); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *objParam = AddParam(paramScope, "obj", dynamicType); params.push_back(objParam); info->params.push_back(objParam->Ident()->Variable()->AsLocalVariable()); ir::ETSParameterExpression *param2; if (!IsByValueCall(VarBinder()->AsETSBinder(), callee)) { + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) param2 = AddParam(paramScope, "qname_start", GlobalIntType()); params.push_back(param2); info->params.push_back(param2->Ident()->Variable()->AsLocalVariable()); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) param2 = AddParam(paramScope, "qname_len", GlobalIntType()); } else { + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) param2 = AddParam(paramScope, "this", dynamicType); } @@ -117,11 +124,12 @@ ir::ScriptFunction *ETSChecker::CreateDynamicCallIntrinsic(ir::Expression *calle util::UString paramName("p" + std::to_string(i), Allocator()); Type *paramType = arguments[i]->TsType()->IsLambdaObject() ? GlobalBuiltinJSValueType() : arguments[i]->TsType(); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) ir::ETSParameterExpression *param = AddParam(paramScope, paramName.View(), paramType); params.push_back(param); info->params.push_back(param->Ident()->Variable()->AsLocalVariable()); } - + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *func = AllocNode( ir::FunctionSignature(nullptr, std::move(params), nullptr), nullptr, ir::ScriptFunction::ScriptFunctionData {ir::ScriptFunctionFlags::METHOD, ir::ModifierFlags::NONE}); @@ -228,6 +236,7 @@ Signature *ETSChecker::ResolveDynamicCallExpression(ir::Expression *callee, cons auto key = ss.str(); auto it = map.find(util::StringView(key)); if (it == map.end()) { + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *func = CreateDynamicCallIntrinsic(callee, arguments, lang); map.emplace(util::UString(key, Allocator()).View(), func); return func->Signature(); @@ -254,9 +263,12 @@ std::pair ETSChecker::CreateScriptFuncti if constexpr (IS_STATIC) { builder(scope, &statements, nullptr); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *body = AllocNode(Allocator(), std::move(statements)); body->SetScope(scope); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) id = AllocNode(compiler::Signatures::CCTOR, Allocator()); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) func = AllocNode( ir::FunctionSignature(nullptr, std::move(params), nullptr), body, ir::ScriptFunction::ScriptFunctionData {ir::ScriptFunctionFlags::STATIC_BLOCK | @@ -266,7 +278,9 @@ std::pair ETSChecker::CreateScriptFuncti builder(scope, &statements, ¶ms); auto *body = AllocNode(Allocator(), std::move(statements)); body->SetScope(scope); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) id = AllocNode(compiler::Signatures::CTOR, Allocator()); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) func = AllocNode( ir::FunctionSignature(nullptr, std::move(params), nullptr), body, ir::ScriptFunction::ScriptFunctionData { @@ -305,7 +319,7 @@ std::conditional_t ET signatureInfo->restVar = nullptr; auto *signature = CreateSignature(signatureInfo, GlobalVoidType(), func); func->SetSignature(signature); - + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *funcExpr = AllocNode(func); VarBinder()->AsETSBinder()->BuildInternalName(func); @@ -313,6 +327,7 @@ std::conditional_t ET VarBinder()->Functions().push_back(func->Scope()); if constexpr (IS_STATIC) { + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *staticBlock = AllocNode(funcExpr, Allocator()); staticBlock->AddModifier(ir::ModifierFlags::STATIC); return staticBlock; @@ -320,6 +335,7 @@ std::conditional_t ET type->AddConstructSignature(signature); auto *ctor = + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) AllocNode(ir::MethodDefinitionKind::CONSTRUCTOR, id->Clone(Allocator(), nullptr), funcExpr, ir::ModifierFlags::NONE, Allocator(), false); auto *funcType = CreateETSFunctionType(signature, id->Name()); @@ -331,14 +347,18 @@ std::conditional_t ET ir::ClassStaticBlock *ETSChecker::CreateDynamicCallClassInitializer(varbinder::ClassScope *classScope, Language lang, bool isConstruct) { + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) return CreateClassInitializer( classScope, [this, lang, isConstruct](varbinder::FunctionScope *scope, ArenaVector *statements, [[maybe_unused]] ArenaVector *params) { auto [builtin_class_name, builtin_method_name] = util::Helpers::SplitSignature(isConstruct ? compiler::Signatures::Dynamic::InitNewClassBuiltin(lang) : compiler::Signatures::Dynamic::InitCallClassBuiltin(lang)); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *classId = AllocNode(builtin_class_name, Allocator()); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *methodId = AllocNode(builtin_method_name, Allocator()); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *callee = AllocNode(classId, methodId, ir::MemberExpressionKind::PROPERTY_ACCESS, false, false); @@ -357,29 +377,30 @@ ir::ClassStaticBlock *ETSChecker::CreateDynamicCallClassInitializer(varbinder::C ss << packageStr << compiler::Signatures::NAMESPACE_SEPARATOR; } ss << name << compiler::Signatures::MANGLE_SEPARATOR; - + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *className = AllocNode(util::UString(ss.str(), Allocator()).View()); callParams.push_back(className); - + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *initCall = AllocNode(callee, std::move(callParams), nullptr, false); { ScopeContext ctx(this, scope); initCall->Check(this); } - + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) statements->push_back(AllocNode(initCall)); }); } void ETSChecker::BuildClass(util::StringView name, const ClassBuilder &builder) { + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *classId = AllocNode(name, Allocator()); auto [decl, var] = VarBinder()->NewVarDecl(classId->Start(), classId->Name()); classId->SetVariable(var); auto classCtx = varbinder::LexicalScope(VarBinder()); - + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *classDef = AllocNode(Allocator(), classId, ir::ClassDefinitionModifiers::DECLARATION, ir::ModifierFlags::NONE, Language(Language::Id::ETS)); classDef->SetScope(classCtx.GetScope()); @@ -389,6 +410,7 @@ void ETSChecker::BuildClass(util::StringView name, const ClassBuilder &builder) classDef, checker::ETSObjectFlags::CLASS, Relation()); classDef->SetTsType(classDefType); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *classDecl = AllocNode(classDef, Allocator()); classDecl->SetParent(VarBinder()->TopScope()->Node()); classDef->Scope()->BindNode(classDecl); @@ -441,15 +463,16 @@ void ETSChecker::BuildDynamicCallClass(bool isConstruct) auto &intrinsics = entry.second; auto className = isConstruct ? compiler::Signatures::Dynamic::NewClass(lang) : compiler::Signatures::Dynamic::CallClass(lang); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) BuildClass(className, [this, lang, &intrinsics, isConstruct](varbinder::ClassScope *scope, ArenaVector *classBody) { for (auto &[_, func] : intrinsics) { (void)_; func->Scope()->ParamScope()->SetParent(scope); - + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *funcExpr = AllocNode(func); - + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *method = AllocNode( ir::MethodDefinitionKind::METHOD, func->Id()->Clone(Allocator(), nullptr), funcExpr, ir::ModifierFlags::PUBLIC | ir::ModifierFlags::NATIVE | ir::ModifierFlags::STATIC, Allocator(), @@ -460,9 +483,9 @@ void ETSChecker::BuildDynamicCallClass(bool isConstruct) classBody->push_back(method); } - + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) classBody->push_back(CreateStaticReadonlyField(scope, "qname_start_from")); - + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) classBody->push_back(CreateDynamicCallClassInitializer(scope, lang, isConstruct)); }); } @@ -473,10 +496,12 @@ void ETSChecker::ClassInitializerFromImport(ir::ETSImportDeclaration *import, va { auto builtin = compiler::Signatures::Dynamic::LoadModuleBuiltin(import->Language()); auto [builtin_class_name, builtin_method_name] = util::Helpers::SplitSignature(builtin); - + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *classId = AllocNode(builtin_class_name, Allocator()); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *methodId = AllocNode(builtin_method_name, Allocator()); auto *callee = + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) AllocNode(classId, methodId, ir::MemberExpressionKind::PROPERTY_ACCESS, false, false); // Note(rsipka): this check could be avoided with appropriate language extensions @@ -487,11 +512,13 @@ void ETSChecker::ClassInitializerFromImport(ir::ETSImportDeclaration *import, va } else { callParams.push_back(import->ResolvedSource()); } - + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *loadCall = AllocNode(callee, std::move(callParams), nullptr, false); - + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *moduleClassId = AllocNode(compiler::Signatures::DYNAMIC_MODULE_CLASS, Allocator()); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *fieldId = AllocNode(import->AssemblerName(), Allocator()); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *property = AllocNode(moduleClassId, fieldId, ir::MemberExpressionKind::PROPERTY_ACCESS, false, false); @@ -508,6 +535,7 @@ void ETSChecker::ClassInitializerFromImport(ir::ETSImportDeclaration *import, va ir::ClassStaticBlock *ETSChecker::CreateDynamicModuleClassInitializer( varbinder::ClassScope *classScope, const std::vector &imports) { + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) return CreateClassInitializer( classScope, [this, imports](varbinder::FunctionScope *scope, ArenaVector *statements, [[maybe_unused]] ArenaVector *params) { @@ -535,8 +563,11 @@ ir::MethodDefinition *ETSChecker::CreateClassMethod(varbinder::ClassScope *class { auto classCtx = varbinder::LexicalScope::Enter(VarBinder(), classScope->StaticMethodScope()); ArenaVector params(Allocator()->Adapter()); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *paramScope = Allocator()->New(Allocator(), classScope); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *scope = Allocator()->New(Allocator(), paramScope); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *id = AllocNode(name, Allocator()); ArenaVector statements(Allocator()->Adapter()); @@ -544,9 +575,10 @@ ir::MethodDefinition *ETSChecker::CreateClassMethod(varbinder::ClassScope *class builder(scope, &statements, ¶ms, &returnType); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *body = AllocNode(Allocator(), std::move(statements)); body->SetScope(scope); - + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *func = AllocNode( ir::FunctionSignature(nullptr, std::move(params), nullptr), body, ir::ScriptFunction::ScriptFunctionData {ir::ScriptFunctionFlags::METHOD, modifierFlags}); @@ -566,8 +598,10 @@ ir::MethodDefinition *ETSChecker::CreateClassMethod(varbinder::ClassScope *class } func->SetSignature(signature); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *funcExpr = AllocNode(func); auto *method = + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) AllocNode(ir::MethodDefinitionKind::METHOD, func->Id()->Clone(Allocator(), nullptr), funcExpr, modifierFlags, Allocator(), false); @@ -593,6 +627,7 @@ ir::MethodDefinition *ETSChecker::CreateClassMethod(varbinder::ClassScope *class ir::MethodDefinition *ETSChecker::CreateDynamicModuleClassInitMethod(varbinder::ClassScope *classScope) { + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) return CreateClassMethod(classScope, compiler::Signatures::DYNAMIC_MODULE_CLASS_INIT, ir::ModifierFlags::PUBLIC | ir::ModifierFlags::STATIC, [this]([[maybe_unused]] varbinder::FunctionScope *scope, @@ -605,6 +640,7 @@ ir::MethodDefinition *ETSChecker::CreateLambdaObjectClassInvokeMethod(varbinder: Signature *invokeSignature, ir::TypeNode *retTypeAnnotation) { + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) return CreateClassMethod( classScope, compiler::Signatures::LAMBDA_OBJECT_INVOKE, ir::ModifierFlags::PUBLIC, [this, classScope, invokeSignature, @@ -612,6 +648,7 @@ ir::MethodDefinition *ETSChecker::CreateLambdaObjectClassInvokeMethod(varbinder: ArenaVector *params, Type **returnType) { util::UString thisParamName(std::string("this"), Allocator()); ir::ETSParameterExpression *thisParam = + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) AddParam(scope->Parent()->AsFunctionParamScope(), thisParamName.View(), classScope->Node()->AsClassDeclaration()->Definition()->TsType()->AsETSObjectType()); params->push_back(thisParam); @@ -619,6 +656,7 @@ ir::MethodDefinition *ETSChecker::CreateLambdaObjectClassInvokeMethod(varbinder: ArenaVector callParams(Allocator()->Adapter()); uint32_t idx = 0; for (auto *invokeParam : invokeSignature->Params()) { + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) ir::ETSParameterExpression *param = AddParam( scope->Parent()->AsFunctionParamScope(), util::UString(std::string("p") + std::to_string(idx), Allocator()).View(), invokeParam->TsType()); @@ -627,9 +665,12 @@ ir::MethodDefinition *ETSChecker::CreateLambdaObjectClassInvokeMethod(varbinder: ++idx; } + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *properyId = AllocNode("jsvalue_lambda", Allocator()); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *callee = AllocNode(thisParam->Clone(Allocator(), nullptr), properyId, ir::MemberExpressionKind::PROPERTY_ACCESS, false, false); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *callLambda = AllocNode(callee, std::move(callParams), nullptr, false); { @@ -638,8 +679,10 @@ ir::MethodDefinition *ETSChecker::CreateLambdaObjectClassInvokeMethod(varbinder: } auto *castToRetTypeExpr = + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) AllocNode(callLambda, retTypeAnnotation->Clone(Allocator(), nullptr), false); castToRetTypeExpr->SetTsType(invokeSignature->ReturnType()); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *retStatement = AllocNode(castToRetTypeExpr); statements->push_back(retStatement); @@ -658,19 +701,23 @@ void ETSChecker::EmitDynamicModuleClassInitCall() auto *staticBlock = (*it)->AsClassStaticBlock(); auto *cctorBody = staticBlock->Function()->Body()->AsBlockStatement(); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *classId = AllocNode(compiler::Signatures::DYNAMIC_MODULE_CLASS, Allocator()); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *methodId = AllocNode(compiler::Signatures::DYNAMIC_MODULE_CLASS_INIT, Allocator()); auto *callee = + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) AllocNode(classId, methodId, ir::MemberExpressionKind::PROPERTY_ACCESS, false, false); ArenaVector callParams(Allocator()->Adapter()); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *initCall = AllocNode(callee, std::move(callParams), nullptr, false); { ScopeContext ctx(this, cctorBody->Scope()); initCall->Check(this); } - + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *const node = AllocNode(initCall); node->SetParent(cctorBody); cctorBody->Statements().push_back(node); @@ -684,6 +731,7 @@ void ETSChecker::BuildDynamicImportClass() } // clang-format off + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) BuildClass(compiler::Signatures::DYNAMIC_MODULE_CLASS, [this, dynamicImports](varbinder::ClassScope *scope, ArenaVector *classBody) { std::unordered_set fields; @@ -706,10 +754,12 @@ void ETSChecker::BuildDynamicImportClass() fields.insert(import->AssemblerName()); imports.push_back(import); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *fieldIdent = AllocNode(import->AssemblerName(), Allocator()); // NOTE: remove const when readonly is properly supported auto flags = ir::ModifierFlags::STATIC | ir::ModifierFlags::PUBLIC | ir::ModifierFlags::READONLY | ir::ModifierFlags::CONST; + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *field = AllocNode(fieldIdent, nullptr, nullptr, flags, Allocator(), false); field->SetTsType(GlobalBuiltinDynamicType(import->Language())); @@ -727,35 +777,43 @@ void ETSChecker::BuildDynamicImportClass() classBody->push_back(field); } + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) classBody->push_back(CreateDynamicModuleClassInitializer(scope, imports)); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) classBody->push_back(CreateDynamicModuleClassInitMethod(scope)); }); // clang-format on - + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) EmitDynamicModuleClassInitCall(); } ir::MethodDefinition *ETSChecker::CreateLambdaObjectClassInitializer(varbinder::ClassScope *classScope, ETSObjectType *functionalInterface) { + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) return CreateClassInitializer( classScope, [this, classScope](varbinder::FunctionScope *scope, ArenaVector *statements, ArenaVector *params) { ir::ETSParameterExpression *thisParam = + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) AddParam(scope->Parent()->AsFunctionParamScope(), varbinder::VarBinder::MANDATORY_PARAM_THIS, classScope->Node()->AsClassDeclaration()->Definition()->TsType()->AsETSObjectType()); params->push_back(thisParam); util::UString jsvalueParamName(std::string("jsvalue_param"), Allocator()); ir::ETSParameterExpression *jsvalueParam = + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) AddParam(scope->Parent()->AsFunctionParamScope(), jsvalueParamName.View(), GlobalBuiltinJSValueType()); params->push_back(jsvalueParam); - + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *moduleClassId = AllocNode(varbinder::VarBinder::MANDATORY_PARAM_THIS, Allocator()); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *fieldId = AllocNode("jsvalue_lambda", Allocator()); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *property = AllocNode(moduleClassId, fieldId, ir::MemberExpressionKind::PROPERTY_ACCESS, false, false); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *initializer = AllocNode(property, jsvalueParam->Clone(Allocator(), nullptr), lexer::TokenType::PUNCTUATOR_SUBSTITUTION); { @@ -763,6 +821,7 @@ ir::MethodDefinition *ETSChecker::CreateLambdaObjectClassInitializer(varbinder:: initializer->Check(this); } + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) statements->push_back(AllocNode(initializer)); }, functionalInterface); @@ -786,6 +845,7 @@ void ETSChecker::BuildLambdaObjectClass(ETSObjectType *functionalInterface, ir:: return; } + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) BuildClass(util::StringView(syntheticLambdaObjName), [this, invokeSignature, retTypeAnnotation, functionalInterface](varbinder::ClassScope *scope, ArenaVector *classBody) { @@ -793,7 +853,9 @@ void ETSChecker::BuildLambdaObjectClass(ETSObjectType *functionalInterface, ir:: classType->AddInterface(functionalInterface); auto assemblyName = "jsvalue_lambda"; + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *fieldIdent = AllocNode(assemblyName, Allocator()); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *field = AllocNode(fieldIdent, nullptr, nullptr, ir::ModifierFlags::PRIVATE, Allocator(), false); field->SetTsType(GlobalBuiltinJSValueType()); @@ -810,8 +872,9 @@ void ETSChecker::BuildLambdaObjectClass(ETSObjectType *functionalInterface, ir:: classBody->push_back(field); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) classBody->push_back(CreateLambdaObjectClassInitializer(scope, functionalInterface)); - + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) classBody->push_back(CreateLambdaObjectClassInvokeMethod(scope, invokeSignature, retTypeAnnotation)); }); diff --git a/ets2panda/checker/ets/enum.cpp b/ets2panda/checker/ets/enum.cpp index 8c8e230845..771ab0d6f2 100644 --- a/ets2panda/checker/ets/enum.cpp +++ b/ets2panda/checker/ets/enum.cpp @@ -88,7 +88,7 @@ template for (const auto *const member : enumType->GetMembers()) { elements.push_back(elementMaker(member->AsTSEnumMember())); } - + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *const arrayExpr = checker->AllocNode(std::move(elements), checker->Allocator()); arrayExpr->SetPreferredType(elementType); arrayExpr->SetTsType(checker->CreateETSArrayType(elementType)); @@ -119,7 +119,9 @@ template const util::StringView &name, Type *const type) { const auto paramCtx = varbinder::LexicalScope::Enter(varbinder, scope, false); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *const paramIdent = checker->AllocNode(name, checker->Allocator()); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *const param = checker->AllocNode(paramIdent, nullptr); auto *const paramVar = std::get<1>(varbinder->AddParamDecl(param)); paramVar->SetTsType(type); @@ -131,10 +133,12 @@ template [[nodiscard]] ir::ETSTypeReference *MakeTypeReference(ETSChecker *const checker, const util::StringView &name) { + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *const ident = checker->AllocNode(name, checker->Allocator()); ident->SetReference(); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *const referencePart = checker->AllocNode(ident); - + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) return checker->AllocNode(referencePart); } @@ -144,10 +148,11 @@ template ArenaVector &&body, ir::TypeNode *const returnTypeAnnotation, bool isDeclare) { + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *const functionScope = varbinder->Allocator()->New(checker->Allocator(), paramScope); functionScope->BindParamScope(paramScope); paramScope->BindFunctionScope(functionScope); - + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *const bodyBlock = checker->AllocNode(checker->Allocator(), std::move(body)); bodyBlock->SetScope(functionScope); @@ -156,7 +161,7 @@ template if (isDeclare) { flags |= ir::ModifierFlags::DECLARE; } - + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *const function = checker->AllocNode( ir::FunctionSignature(nullptr, std::move(params), returnTypeAnnotation), bodyBlock, ir::ScriptFunction::ScriptFunctionData {ir::ScriptFunctionFlags::METHOD, flags, isDeclare}); @@ -173,7 +178,9 @@ template void MakeMethodDef(ETSChecker *const checker, varbinder::ETSBinder *const varbinder, ir::Identifier *const ident, ir::ScriptFunction *const function) { + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *const functionExpr = checker->AllocNode(function); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *const identClone = ident->Clone(checker->Allocator(), nullptr); identClone->SetTsType(ident->TsType()); @@ -226,9 +233,11 @@ void MakeMethodDef(ETSChecker *const checker, varbinder::ETSBinder *const varbin ir::Identifier *ETSChecker::CreateEnumNamesArray(ETSEnumInterface const *const enumType) { // clang-format off + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) return MakeArray(this, VarBinder()->AsETSBinder(), enumType, "NamesArray", GlobalBuiltinETSStringType(), [this](const ir::TSEnumMember *const member) { auto *const enumNameStringLiteral = + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) AllocNode(member->Key()->AsIdentifier()->Name()); enumNameStringLiteral->SetTsType(GlobalBuiltinETSStringType()); return enumNameStringLiteral; @@ -238,9 +247,11 @@ ir::Identifier *ETSChecker::CreateEnumNamesArray(ETSEnumInterface const *const e ir::Identifier *ETSChecker::CreateEnumValuesArray(ETSEnumType *const enumType) { + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) return MakeArray( this, VarBinder()->AsETSBinder(), enumType, "ValuesArray", GlobalIntType(), [this](const ir::TSEnumMember *const member) { + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *const enumValueLiteral = AllocNode(lexer::Number( member->AsTSEnumMember()->Init()->AsNumberLiteral()->Number().GetValue())); enumValueLiteral->SetTsType(GlobalIntType()); @@ -250,6 +261,7 @@ ir::Identifier *ETSChecker::CreateEnumValuesArray(ETSEnumType *const enumType) ir::Identifier *ETSChecker::CreateEnumStringValuesArray(ETSEnumInterface *const enumType) { + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) return MakeArray(this, VarBinder()->AsETSBinder(), enumType, "StringValuesArray", GlobalETSStringLiteralType(), [this, enumType](const ir::TSEnumMember *const member) { auto *const init = member->AsTSEnumMember()->Init(); @@ -272,6 +284,7 @@ ir::Identifier *ETSChecker::CreateEnumStringValuesArray(ETSEnumInterface *const ir::Identifier *ETSChecker::CreateEnumItemsArray(ETSEnumInterface *const enumType) { return MakeArray( + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) this, VarBinder()->AsETSBinder(), enumType, "ItemsArray", enumType, [this, enumType](const ir::TSEnumMember *const member) { auto *const enumTypeIdent = AllocNode(enumType->GetName(), Allocator()); @@ -279,6 +292,7 @@ ir::Identifier *ETSChecker::CreateEnumItemsArray(ETSEnumInterface *const enumTyp enumTypeIdent->SetReference(); auto *const enumMemberIdent = + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) AllocNode(member->AsTSEnumMember()->Key()->AsIdentifier()->Name(), Allocator()); enumMemberIdent->SetReference(); auto *const enumMemberExpr = AllocNode( @@ -293,15 +307,20 @@ ETSEnumType::Method ETSChecker::CreateEnumFromIntMethod(ir::Identifier *const na ETSEnumInterface *const enumType) { auto *const paramScope = + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) VarBinder()->Allocator()->New(Allocator(), Program()->GlobalScope()); auto *const inputOrdinalIdent = + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) MakeFunctionParam(this, VarBinder()->AsETSBinder(), paramScope, "ordinal", GlobalIntType()); auto *const inArraySizeExpr = [this, namesArrayIdent, inputOrdinalIdent]() { + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *const lengthIdent = AllocNode("length", Allocator()); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *const valuesArrayLengthExpr = AllocNode( namesArrayIdent, lengthIdent, ir::MemberExpressionKind::PROPERTY_ACCESS, false, false); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *const expr = AllocNode(inputOrdinalIdent, valuesArrayLengthExpr, lexer::TokenType::PUNCTUATOR_LESS_THAN); expr->SetOperationType(GlobalIntType()); @@ -312,6 +331,7 @@ ETSEnumType::Method ETSChecker::CreateEnumFromIntMethod(ir::Identifier *const na auto *const returnEnumStmt = [this, inputOrdinalIdent, enumType]() { auto *const identClone = inputOrdinalIdent->Clone(Allocator(), nullptr); identClone->SetTsType(enumType); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) return AllocNode(identClone); }(); @@ -323,10 +343,10 @@ ETSEnumType::Method ETSChecker::CreateEnumFromIntMethod(ir::Identifier *const na util::UString messageString(util::StringView("No enum constant in "), Allocator()); messageString.Append(enumType->GetName()); messageString.Append(" with ordinal value "); - + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *const identClone = inputOrdinalIdent->Clone(Allocator(), nullptr); identClone->SetTsType(GlobalIntType()); - + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *const message = AllocNode(messageString.View()); auto *const newExprArg = AllocNode(message, identClone, lexer::TokenType::PUNCTUATOR_PLUS); @@ -340,7 +360,7 @@ ETSEnumType::Method ETSChecker::CreateEnumFromIntMethod(ir::Identifier *const na newExpr->SetSignature( ResolveConstructExpression(GlobalBuiltinExceptionType(), newExpr->GetArguments(), newExpr->Start())); newExpr->SetTsType(GlobalBuiltinExceptionType()); - + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) return AllocNode(newExpr); }(); @@ -353,17 +373,19 @@ ETSEnumType::Method ETSChecker::CreateEnumFromIntMethod(ir::Identifier *const na body.push_back(ifOrdinalExistsStmt); body.push_back(throwNoEnumStmt); body.push_back(returnEnumStmt); - + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *const enumTypeAnnotation = MakeTypeReference(this, enumType->GetName()); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *const function = MakeFunction(this, VarBinder()->AsETSBinder(), paramScope, std::move(params), std::move(body), enumTypeAnnotation, enumType->GetDecl()->IsDeclare()); function->AddFlag(ir::ScriptFunctionFlags::THROWS); - + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *const ident = MakeQualifiedIdentifier(this, enumType->GetDecl(), ETSEnumType::FROM_INT_METHOD_NAME); function->SetIdent(ident); function->Scope()->BindInternalName(ident->Name()); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) MakeMethodDef(this, VarBinder()->AsETSBinder(), ident, function); ident->SetReference(); @@ -375,11 +397,13 @@ ETSEnumType::Method ETSChecker::CreateEnumToStringMethod(ir::Identifier *const s ETSEnumInterface *const enumType) { auto *const paramScope = + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) VarBinder()->Allocator()->New(Allocator(), Program()->GlobalClassScope()); - + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *const inputEnumIdent = MakeFunctionParam(this, VarBinder()->AsETSBinder(), paramScope, "ordinal", enumType); auto *const returnStmt = [this, inputEnumIdent, stringValuesArrayIdent]() { + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *const arrayAccessExpr = AllocNode( stringValuesArrayIdent, inputEnumIdent, ir::MemberExpressionKind::ELEMENT_ACCESS, true, false); arrayAccessExpr->SetTsType(GlobalETSStringLiteralType()); @@ -394,15 +418,16 @@ ETSEnumType::Method ETSChecker::CreateEnumToStringMethod(ir::Identifier *const s identClone->SetTsType(enumType); ArenaVector params(Allocator()->Adapter()); params.push_back(identClone); - + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *const stringTypeAnnotation = MakeTypeReference(this, GlobalBuiltinETSStringType()->Name()); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *const function = MakeFunction(this, VarBinder()->AsETSBinder(), paramScope, std::move(params), std::move(body), stringTypeAnnotation, enumType->GetDecl()->IsDeclare()); auto *const functionIdent = MakeQualifiedIdentifier(this, enumType->GetDecl(), ETSEnumType::TO_STRING_METHOD_NAME); function->SetIdent(functionIdent); function->Scope()->BindInternalName(functionIdent->Name()); - + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) MakeMethodDef(this, VarBinder()->AsETSBinder(), functionIdent, function); functionIdent->SetReference(); @@ -416,11 +441,14 @@ ETSEnumType::Method ETSChecker::CreateEnumGetValueMethod(ir::Identifier *const v ETSEnumType *const enumType) { auto *const paramScope = + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) VarBinder()->Allocator()->New(Allocator(), Program()->GlobalClassScope()); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *const inputEnumIdent = MakeFunctionParam(this, VarBinder()->AsETSBinder(), paramScope, "e", enumType); auto *const returnStmt = [this, inputEnumIdent, valuesArrayIdent]() { + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *const arrayAccessExpr = AllocNode( valuesArrayIdent, inputEnumIdent, ir::MemberExpressionKind::ELEMENT_ACCESS, true, false); arrayAccessExpr->SetTsType(GlobalIntType()); @@ -435,7 +463,7 @@ ETSEnumType::Method ETSChecker::CreateEnumGetValueMethod(ir::Identifier *const v identClone->SetTsType(enumType); ArenaVector params(Allocator()->Adapter()); params.push_back(identClone); - + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *const intTypeAnnotation = AllocNode(ir::PrimitiveType::INT); auto *const function = MakeFunction(this, VarBinder()->AsETSBinder(), paramScope, std::move(params), std::move(body), intTypeAnnotation, enumType->GetDecl()->IsDeclare()); @@ -456,11 +484,13 @@ ETSEnumType::Method ETSChecker::CreateEnumGetNameMethod(ir::Identifier *const na ETSEnumInterface *const enumType) { auto *const paramScope = + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) VarBinder()->Allocator()->New(Allocator(), Program()->GlobalScope()); - + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *const inputEnumIdent = MakeFunctionParam(this, VarBinder()->AsETSBinder(), paramScope, "ordinal", enumType); auto *const returnStmt = [this, inputEnumIdent, namesArrayIdent]() { + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *const arrayAccessExpr = AllocNode( namesArrayIdent, inputEnumIdent, ir::MemberExpressionKind::ELEMENT_ACCESS, true, false); arrayAccessExpr->SetTsType(GlobalBuiltinETSStringType()); @@ -475,12 +505,12 @@ ETSEnumType::Method ETSChecker::CreateEnumGetNameMethod(ir::Identifier *const na identClone->SetTsType(enumType); ArenaVector params(Allocator()->Adapter()); params.push_back(identClone); - + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *const stringTypeAnnotation = MakeTypeReference(this, GlobalBuiltinETSStringType()->Name()); auto *const function = MakeFunction(this, VarBinder()->AsETSBinder(), paramScope, std::move(params), std::move(body), stringTypeAnnotation, enumType->GetDecl()->IsDeclare()); - + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *const functionIdent = MakeQualifiedIdentifier(this, enumType->GetDecl(), ETSEnumType::GET_NAME_METHOD_NAME); function->SetIdent(functionIdent); function->Scope()->BindInternalName(functionIdent->Name()); @@ -497,11 +527,13 @@ ETSEnumType::Method ETSChecker::CreateEnumValueOfMethod(ir::Identifier *const na ETSEnumInterface *const enumType) { auto *const paramScope = + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) VarBinder()->Allocator()->New(Allocator(), Program()->GlobalScope()); varbinder::LexicalScope loopDeclScope(VarBinder()); auto *const forLoopIIdent = [this]() { + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *const ident = AllocNode("i", Allocator()); ident->SetTsType(GlobalIntType()); auto [decl, var] = VarBinder()->NewVarDecl(ident->Start(), ident->Name()); @@ -514,8 +546,10 @@ ETSEnumType::Method ETSChecker::CreateEnumValueOfMethod(ir::Identifier *const na }(); auto *const forLoopInitVarDecl = [this, forLoopIIdent]() { + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *const init = AllocNode("0"); init->SetTsType(GlobalIntType()); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *const decl = AllocNode(ir::VariableDeclaratorFlag::LET, forLoopIIdent, init); decl->SetTsType(GlobalIntType()); ArenaVector decls(Allocator()->Adapter()); @@ -538,6 +572,7 @@ ETSEnumType::Method ETSChecker::CreateEnumValueOfMethod(ir::Identifier *const na auto *const forLoopUpdate = [this, forLoopIIdent]() { auto *const incrementExpr = + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) AllocNode(forLoopIIdent, lexer::TokenType::PUNCTUATOR_PLUS_PLUS, true); incrementExpr->SetTsType(GlobalIntType()); return incrementExpr; @@ -554,17 +589,19 @@ ETSEnumType::Method ETSChecker::CreateEnumValueOfMethod(ir::Identifier *const na namesArrayElementExpr->SetTsType(GlobalBuiltinETSStringType()); auto *const namesEqualExpr = + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) AllocNode(inputNameIdent, namesArrayElementExpr, lexer::TokenType::PUNCTUATOR_EQUAL); namesEqualExpr->SetOperationType(GlobalBuiltinETSStringType()); namesEqualExpr->SetTsType(GlobalETSBooleanType()); auto *const returnStmt = AllocNode(forLoopIIdent); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) return AllocNode(namesEqualExpr, returnStmt, nullptr); }(); varbinder::LexicalScope loopScope(VarBinder()); loopScope.GetScope()->BindDecls(loopDeclScope.GetScope()); - + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *const forLoop = AllocNode(forLoopInitVarDecl, forLoopTest, forLoopUpdate, ifStmt); loopScope.GetScope()->BindNode(forLoop); forLoop->SetScope(loopScope.GetScope()); @@ -579,6 +616,7 @@ ETSEnumType::Method ETSChecker::CreateEnumValueOfMethod(ir::Identifier *const na identClone->SetTsType(inputNameIdent->TsType()); auto *const message = AllocNode(messageString.View()); auto *const newExprArg = + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) AllocNode(message, identClone, lexer::TokenType::PUNCTUATOR_PLUS); ArenaVector newExprArgs(Allocator()->Adapter()); @@ -592,7 +630,7 @@ ETSEnumType::Method ETSChecker::CreateEnumValueOfMethod(ir::Identifier *const na newExpr->SetSignature( ResolveConstructExpression(GlobalBuiltinExceptionType(), newExpr->GetArguments(), newExpr->Start())); newExpr->SetTsType(GlobalBuiltinExceptionType()); - + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) return AllocNode(newExpr); }(); @@ -604,13 +642,13 @@ ETSEnumType::Method ETSChecker::CreateEnumValueOfMethod(ir::Identifier *const na identClone->SetTsType(inputNameIdent->TsType()); ArenaVector params(Allocator()->Adapter()); params.push_back(identClone); - + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *const enumTypeAnnotation = MakeTypeReference(this, enumType->GetName()); auto *const function = MakeFunction(this, VarBinder()->AsETSBinder(), paramScope, std::move(params), std::move(body), enumTypeAnnotation, enumType->GetDecl()->IsDeclare()); function->AddFlag(ir::ScriptFunctionFlags::THROWS); - + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *const functionIdent = MakeQualifiedIdentifier(this, enumType->GetDecl(), ETSEnumType::VALUE_OF_METHOD_NAME); function->SetIdent(functionIdent); function->Scope()->BindInternalName(functionIdent->Name()); @@ -629,19 +667,20 @@ ETSEnumType::Method ETSChecker::CreateEnumValuesMethod(ir::Identifier *const ite ETSEnumInterface *const enumType) { auto *const paramScope = + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) VarBinder()->Allocator()->New(Allocator(), Program()->GlobalScope()); - + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *const returnStmt = AllocNode(itemsArrayIdent); ArenaVector body(Allocator()->Adapter()); body.push_back(returnStmt); ArenaVector params(Allocator()->Adapter()); - + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *const enumArrayTypeAnnotation = AllocNode(MakeTypeReference(this, enumType->GetName())); auto *const function = MakeFunction(this, VarBinder()->AsETSBinder(), paramScope, std::move(params), std::move(body), enumArrayTypeAnnotation, enumType->GetDecl()->IsDeclare()); - + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *const functionIdent = MakeQualifiedIdentifier(this, enumType->GetDecl(), ETSEnumType::VALUES_METHOD_NAME); function->SetIdent(functionIdent); function->Scope()->BindInternalName(functionIdent->Name()); diff --git a/ets2panda/checker/ets/function.cpp b/ets2panda/checker/ets/function.cpp index 438481b54f..7c21b89de4 100644 --- a/ets2panda/checker/ets/function.cpp +++ b/ets2panda/checker/ets/function.cpp @@ -656,10 +656,12 @@ Signature *ETSChecker::ResolveCallExpressionAndTrailingLambda(ArenaVectorTypeParams(), arguments, pos, "call", TypeRelationFlag::NO_THROW | TypeRelationFlag::NO_CHECK_TRAILING_LAMBDA); if (sig != nullptr) { + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) TransformTraillingLambda(callExpr); TypeInference(sig, callExpr->Arguments()); return sig; @@ -1349,6 +1351,7 @@ static std::pair, bool> CreateLambdaObjectPropertiesF // If the lambda captured a property in the current class, we have to make a synthetic class property to store // 'this' in it if (saveThis) { + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) properties.push_back(checker->CreateLambdaCapturedThis(classScope, idx, lambda->Start())); idx++; } @@ -1381,20 +1384,24 @@ void ETSChecker::CreateLambdaObjectForLambdaReference(ir::ArrowFunctionExpressio // Create the class scope for the synthetic lambda class node auto classCtx = varbinder::LexicalScope(VarBinder()); auto *classScope = classCtx.GetScope(); - + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto [properties, saveThis] = CreateLambdaObjectPropertiesForLambdaReference(this, lambda, classScope); auto *currentClassDef = Context().ContainingClass()->GetDeclNode()->AsClassDefinition(); // Create the synthetic proxy method node for the current class definiton, which we will use in the lambda // 'invoke' method to propagate the function call to the current class + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *proxyMethod = CreateProxyMethodForLambda(currentClassDef, lambda, properties, !saveThis); // Create the synthetic constructor node for the lambda class, to be able to save captured variables + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *ctor = CreateLambdaImplicitCtor(properties); properties.push_back(ctor); // Create the synthetic invoke node for the lambda class, which will propagate the call to the proxy method + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *invoke0Func = CreateLambdaInvokeProto(FUNCTIONAL_INTERFACE_INVOKE_METHOD_NAME); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *invokeFunc = CreateLambdaInvokeProto("invoke"); properties.push_back(invoke0Func); @@ -1406,8 +1413,10 @@ void ETSChecker::CreateLambdaObjectForLambdaReference(ir::ArrowFunctionExpressio CreateLambdaFuncDecl(invokeFunc, classScope->InstanceMethodScope()); // Create the synthetic lambda class node + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *identNode = AllocNode(util::StringView("LambdaObject"), Allocator()); auto *lambdaObject = + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) AllocNode(Allocator(), identNode, std::move(properties), ir::ClassDefinitionModifiers::DECLARATION, Language(Language::Id::ETS)); lambda->SetResolvedLambda(lambdaObject); @@ -1438,10 +1447,12 @@ void ETSChecker::CreateLambdaObjectForLambdaReference(ir::ArrowFunctionExpressio // Resolve the proxy method ResolveProxyMethod(currentClassDef, proxyMethod, lambda); if (lambda->Function()->IsAsyncFunc()) { + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) HandleAsyncFuncInLambda(this, lambda, proxyMethod, currentClassDef); } // Resolve the lambda object + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) ResolveLambdaObject(lambdaObject, functionalInterface, lambda, proxyMethod, saveThis); } @@ -1450,6 +1461,7 @@ void ETSChecker::ResolveLambdaObject(ir::ClassDefinition *lambdaObject, ETSObjec bool saveThis) { // Create the class type for the lambda + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *lambdaObjectType = Allocator()->New(Allocator(), lambdaObject->Ident()->Name(), lambdaObject->Ident()->Name(), lambdaObject, checker::ETSObjectFlags::CLASS, Relation()); @@ -1476,7 +1488,9 @@ void ETSChecker::ResolveLambdaObject(ir::ClassDefinition *lambdaObject, ETSObjec ResolveLambdaObjectCtor(lambdaObject); // Resolve the invoke function + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) ResolveLambdaObjectInvoke(lambdaObject, lambda, proxyMethod, !saveThis, true); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) ResolveLambdaObjectInvoke(lambdaObject, lambda, proxyMethod, !saveThis, false); } @@ -1559,6 +1573,7 @@ void ETSChecker::ResolveLambdaObjectInvoke(ir::ClassDefinition *lambdaObject, ir } // Fill out the type information for the body of the invoke function + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) ResolveLambdaObjectInvokeFuncBody(lambdaObject, lambda, proxyMethod, isStatic, ifaceOverride); } @@ -1665,6 +1680,7 @@ void ETSChecker::ResolveLambdaObjectInvokeFuncBody(ir::ClassDefinition *lambdaOb // If the proxy method is static, we should call it through the owner class itself if (isStatic) { + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) fieldIdent = AllocNode(proxySignature->Owner()->Name(), Allocator()); fieldPropType = proxySignature->Owner(); fieldIdent->SetVariable(proxySignature->Owner()->Variable()); @@ -1673,14 +1689,17 @@ void ETSChecker::ResolveLambdaObjectInvokeFuncBody(ir::ClassDefinition *lambdaOb auto *savedThis = lambdaBody[lambdaBody.size() - 4]->AsClassProperty(); auto *fieldProp = savedThis->Key()->AsIdentifier()->Variable(); fieldPropType = fieldProp->TsType()->AsETSObjectType(); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) fieldIdent = Allocator()->New(savedThis->Key()->AsIdentifier()->Name(), Allocator()); fieldIdent->SetVariable(fieldProp); } fieldIdent->SetTsType(fieldPropType); // Set the type information for the proxy function call + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *funcIdent = AllocNode(proxyMethod->Function()->Id()->Name(), Allocator()); auto *callee = + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) AllocNode(fieldIdent, funcIdent, ir::MemberExpressionKind::ELEMENT_ACCESS, false, false); callee->SetPropVar(proxySignature->OwnerVar()->AsLocalVariable()); callee->SetObjectType(fieldPropType); @@ -1689,17 +1708,21 @@ void ETSChecker::ResolveLambdaObjectInvokeFuncBody(ir::ClassDefinition *lambdaOb // Resolve the proxy method call arguments, first we add the captured fields to the call auto *invokeFunc = lambdaBody[lambdaBody.size() - (ifaceOverride ? 2 : 1)]->AsMethodDefinition()->Function(); ArenaVector callParams = + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) ResolveCallParametersForLambdaFuncBody(this, lambdaObject, lambda, invokeFunc, isStatic, ifaceOverride); // Create the synthetic call expression to the proxy method + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *resolvedCall = AllocNode(callee, std::move(callParams), nullptr, false); resolvedCall->SetTsType(proxySignature->ReturnType()); resolvedCall->SetSignature(proxySignature); ir::Expression *returnExpression = nullptr; if (proxySignature->ReturnType()->IsETSVoidType()) { + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *expressionStatementNode = AllocNode(resolvedCall); expressionStatementNode->SetParent(invokeFunc->Body()); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) invokeFunc->Body()->AsBlockStatement()->Statements().push_back(expressionStatementNode); if (ifaceOverride) { returnExpression = Allocator()->New(); @@ -1855,10 +1878,12 @@ ir::ScriptFunction *ETSChecker::CreateProxyFunc(ir::ArrowFunctionExpression *lam { // Create the synthetic parameters for the proxy method ArenaVector params(Allocator()->Adapter()); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *funcParamScope = CreateProxyMethodParams(lambda, params, captured, isStatic); // Create the scopes for the proxy method auto paramCtx = varbinder::LexicalScope::Enter(VarBinder(), funcParamScope, false); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *scope = VarBinder()->Allocator()->New(Allocator(), funcParamScope); auto *body = lambda->Function()->Body(); body->AsBlockStatement()->SetScope(scope); @@ -1867,6 +1892,7 @@ ir::ScriptFunction *ETSChecker::CreateProxyFunc(ir::ArrowFunctionExpression *lam if (lambda->Function()->IsAsyncFunc()) { funcFlags |= ir::ScriptFunctionFlags::ASYNC; } + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *func = Allocator()->New( ir::FunctionSignature(nullptr, std::move(params), lambda->Function()->ReturnTypeAnnotation()), body, ir::ScriptFunction::ScriptFunctionData {funcFlags, GetFlagsForProxyLambda(isStatic)}); @@ -1902,12 +1928,15 @@ ir::MethodDefinition *ETSChecker::CreateProxyMethodForLambda(ir::ClassDefinition ir::ArrowFunctionExpression *lambda, ArenaVector &captured, bool isStatic) { + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *func = CreateProxyFunc(lambda, captured, isStatic); // Create the synthetic proxy method + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *funcExpr = AllocNode(func); util::UString funcName(util::StringView("lambda$invoke$"), Allocator()); funcName.Append(std::to_string(ComputeProxyMethods(klass))); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *identNode = AllocNode(funcName.View(), Allocator()); func->SetIdent(identNode); @@ -2032,8 +2061,10 @@ varbinder::FunctionParamScope *ETSChecker::CreateProxyMethodParams(ir::ArrowFunc // "this" should be binded with the parameter of the proxy method if (this->HasStatus(checker::CheckerStatus::IN_INSTANCE_EXTENSION_METHOD) && lambda->CapturedVars()[i]->Name() == varbinder::VarBinder::MANDATORY_PARAM_THIS) { + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) paramIdent = AllocNode(varbinder::VarBinder::MANDATORY_PARAM_THIS, Allocator()); } else { + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) paramIdent = AllocNode(capturedVar->Name(), Allocator()); } @@ -2054,8 +2085,10 @@ varbinder::FunctionParamScope *ETSChecker::CreateProxyMethodParams(ir::ArrowFunc // Then add the lambda function parameters to the proxy method's parameter vector, and set the type from the // already computed types for the lambda parameters for (auto *const it : params) { + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *const oldParameter = it->AsETSParameterExpression(); auto *newParameter = oldParameter->Clone(Allocator(), nullptr); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto [_, var] = VarBinder()->AddParamDecl(newParameter); (void)_; var->SetTsType(oldParameter->Variable()->TsType()); @@ -2076,10 +2109,12 @@ ir::ClassProperty *ETSChecker::CreateLambdaCapturedThis(varbinder::ClassScope *s // Create the name for the synthetic property node util::UString fieldName(util::StringView("field"), Allocator()); fieldName.Append(std::to_string(idx)); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *fieldIdent = Allocator()->New(fieldName.View(), Allocator()); // Create the synthetic class property node auto *field = + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) Allocator()->New(fieldIdent, nullptr, nullptr, ir::ModifierFlags::NONE, Allocator(), false); // Add the declaration to the scope, and set the type based on the current class type, to be able to store the @@ -2104,10 +2139,12 @@ ir::ClassProperty *ETSChecker::CreateLambdaCapturedField(const varbinder::Variab // Create the name for the synthetic property node util::UString fieldName(util::StringView("field#"), Allocator()); fieldName.Append(std::to_string(idx)); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *fieldIdent = Allocator()->New(fieldName.View(), Allocator()); // Create the synthetic class property node auto *field = + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) Allocator()->New(fieldIdent, nullptr, nullptr, ir::ModifierFlags::NONE, Allocator(), false); fieldIdent->SetParent(field); @@ -2129,10 +2166,12 @@ ir::MethodDefinition *ETSChecker::CreateLambdaImplicitCtor(ArenaVector params(Allocator()->Adapter()); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *funcParamScope = CreateLambdaCtorImplicitParams(params, properties); // Create the scopes for the synthetic constructor node auto paramCtx = varbinder::LexicalScope::Enter(VarBinder(), funcParamScope, false); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *scope = VarBinder()->Allocator()->New(Allocator(), funcParamScope); // Complete the synthetic constructor node's body, to be able to initialize every field by copying every @@ -2140,13 +2179,16 @@ ir::MethodDefinition *ETSChecker::CreateLambdaImplicitCtor(ArenaVector statements(Allocator()->Adapter()); for (auto *it : properties) { auto *field = it->AsClassProperty()->Key()->AsIdentifier(); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) statements.push_back(CreateLambdaCtorFieldInit(field->Name(), field->Variable())); } // Create the synthetic constructor node + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *body = AllocNode(Allocator(), std::move(statements)); body->SetScope(scope); auto *func = + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) AllocNode(ir::FunctionSignature(nullptr, std::move(params), nullptr), body, ir::ScriptFunction::ScriptFunctionData {ir::ScriptFunctionFlags::CONSTRUCTOR}); func->SetScope(scope); @@ -2162,11 +2204,14 @@ ir::MethodDefinition *ETSChecker::CreateLambdaImplicitCtor(ArenaVector(func); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *key = AllocNode("constructor", Allocator()); func->SetIdent(key); auto *keyClone = key->Clone(Allocator(), nullptr); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *ctor = AllocNode(ir::MethodDefinitionKind::CONSTRUCTOR, keyClone, funcExpr, ir::ModifierFlags::NONE, Allocator(), false); @@ -2184,7 +2229,9 @@ varbinder::FunctionParamScope *ETSChecker::CreateLambdaCtorImplicitParams(ArenaV for (auto *it : properties) { auto *field = it->AsClassProperty()->Key()->AsIdentifier(); auto *paramField = field->Clone(Allocator(), nullptr); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *param = AllocNode(paramField, nullptr); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto [_, var] = VarBinder()->AddParamDecl(param); (void)_; auto *type = MaybeBoxedType(field->Variable()); @@ -2203,15 +2250,21 @@ ir::Statement *ETSChecker::CreateLambdaCtorFieldInit(util::StringView name, varb // Create synthetic field initializers for the lambda class fields // The node structure is the following: this.field0 = field0, where the left hand side refers to the lambda // classes field, and the right hand side is refers to the constructors parameter + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *thisExpr = AllocNode(); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *fieldAccessExpr = AllocNode(name, Allocator()); fieldAccessExpr->SetReference(); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *leftHandSide = AllocNode(thisExpr, fieldAccessExpr, ir::MemberExpressionKind::PROPERTY_ACCESS, false, false); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *rightHandSide = AllocNode(name, Allocator()); rightHandSide->SetVariable(var); auto *initializer = + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) AllocNode(leftHandSide, rightHandSide, lexer::TokenType::PUNCTUATOR_SUBSTITUTION); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) return AllocNode(initializer); } @@ -2236,11 +2289,13 @@ void ETSChecker::CreateLambdaObjectForFunctionReference(ir::AstNode *refNode, Si // reference through, if the referenced function is static, we won't need to store the instance object ArenaVector properties(Allocator()->Adapter()); if (!isStaticReference) { + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) properties.push_back(CreateLambdaImplicitField(classScope, refNode->Start())); } // Create the synthetic constructor node, where we will initialize the synthetic field (if present) to the // instance object + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *ctor = CreateLambdaImplicitCtor(refNode->Range(), isStaticReference); properties.push_back(ctor); @@ -2257,8 +2312,10 @@ void ETSChecker::CreateLambdaObjectForFunctionReference(ir::AstNode *refNode, Si CreateLambdaFuncDecl(invokeFunc, classScope->InstanceMethodScope()); // Create the synthetic lambda class node + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *identNode = Allocator()->New(util::StringView("LambdaObject"), Allocator()); auto *lambdaObject = + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) Allocator()->New(Allocator(), identNode, std::move(properties), ir::ClassDefinitionModifiers::DECLARATION, Language(Language::Id::ETS)); lambdaObject->SetScope(classScope); @@ -2277,6 +2334,7 @@ void ETSChecker::CreateLambdaObjectForFunctionReference(ir::AstNode *refNode, Si invokeFunc->Function()->IsExternal()); // Resolve the lambda object + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) ResolveLambdaObject(lambdaObject, trueSignature, functionalInterface, refNode); } @@ -2286,8 +2344,10 @@ ir::AstNode *ETSChecker::CreateLambdaImplicitField(varbinder::ClassScope *scope, auto fieldCtx = varbinder::LexicalScope::Enter(VarBinder(), scope->InstanceFieldScope()); // Create the synthetic class property node + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *fieldIdent = Allocator()->New("field0", Allocator()); auto *field = + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) Allocator()->New(fieldIdent, nullptr, nullptr, ir::ModifierFlags::NONE, Allocator(), false); // Add the declaration to the scope @@ -2306,21 +2366,25 @@ ir::MethodDefinition *ETSChecker::CreateLambdaImplicitCtor(const lexer::SourceRa ArenaVector statements(Allocator()->Adapter()); // Create the parameters for the synthetic constructor + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto [funcParamScope, var] = CreateLambdaCtorImplicitParam(params, pos, isStaticReference); // Create the scopes auto paramCtx = varbinder::LexicalScope::Enter(VarBinder(), funcParamScope, false); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *scope = VarBinder()->Allocator()->New(Allocator(), funcParamScope); // If the reference refers to a static function, the constructor will be empty, otherwise, we have to make a // synthetic initializer to initialize the lambda class field if (!isStaticReference) { + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) statements.push_back(CreateLambdaCtorFieldInit(util::StringView("field0"), var)); } - + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *body = AllocNode(Allocator(), std::move(statements)); body->SetScope(scope); auto *func = + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) AllocNode(ir::FunctionSignature(nullptr, std::move(params), nullptr), body, ir::ScriptFunction::ScriptFunctionData {ir::ScriptFunctionFlags::CONSTRUCTOR}); func->SetScope(scope); @@ -2335,11 +2399,14 @@ ir::MethodDefinition *ETSChecker::CreateLambdaImplicitCtor(const lexer::SourceRa } // Create the synthetic constructor + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *funcExpr = AllocNode(func); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *key = AllocNode("constructor", Allocator()); func->SetIdent(key); auto *keyClone = key->Clone(Allocator(), nullptr); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *ctor = AllocNode(ir::MethodDefinitionKind::CONSTRUCTOR, keyClone, funcExpr, ir::ModifierFlags::NONE, Allocator(), false); @@ -2356,7 +2423,9 @@ std::tuple ETSChecker::C // since when initializing the lambda class, we don't need to save the instance object which we tried to get the // function reference through if (!isStaticReference) { + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *paramIdent = AllocNode("field0", Allocator()); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *param = AllocNode(paramIdent, nullptr); paramIdent->SetRange(pos); auto [_, var] = VarBinder()->AddParamDecl(param); @@ -2374,13 +2443,17 @@ ir::MethodDefinition *ETSChecker::CreateLambdaInvokeProto(util::StringView invok // Create the template for the synthetic 'invoke' method, which will be used when the function type will be // called auto *paramScope = + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) VarBinder()->Allocator()->New(Allocator(), VarBinder()->GetScope()); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *scope = VarBinder()->Allocator()->New(Allocator(), paramScope); ArenaVector params(Allocator()->Adapter()); ArenaVector statements(Allocator()->Adapter()); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *body = AllocNode(Allocator(), std::move(statements)); body->SetScope(scope); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *func = AllocNode( ir::FunctionSignature(nullptr, std::move(params), nullptr), body, ir::ScriptFunction::ScriptFunctionData {ir::ScriptFunctionFlags::METHOD, ir::ModifierFlags::PUBLIC}); @@ -2390,13 +2463,14 @@ ir::MethodDefinition *ETSChecker::CreateLambdaInvokeProto(util::StringView invok paramScope->BindNode(func); scope->BindParamScope(paramScope); paramScope->BindFunctionScope(scope); - + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *name = AllocNode(invokeName, Allocator()); func->SetIdent(name); - + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *funcExpr = AllocNode(func); auto *nameClone = name->Clone(Allocator(), nullptr); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *method = AllocNode(ir::MethodDefinitionKind::METHOD, nameClone, funcExpr, ir::ModifierFlags::PUBLIC, Allocator(), false); @@ -2437,6 +2511,7 @@ void ETSChecker::ResolveLambdaObject(ir::ClassDefinition *lambdaObject, Signatur } // Create the class type for the lambda + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *lambdaObjectType = Allocator()->New(Allocator(), lambdaObject->Ident()->Name(), lambdaObject->Ident()->Name(), lambdaObject, checker::ETSObjectFlags::CLASS, Relation()); @@ -2457,7 +2532,9 @@ void ETSChecker::ResolveLambdaObject(ir::ClassDefinition *lambdaObject, Signatur ResolveLambdaObjectCtor(lambdaObject, isStaticReference); // Resolve the invoke function + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) ResolveLambdaObjectInvoke(lambdaObject, signature, true); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) ResolveLambdaObjectInvoke(lambdaObject, signature, false); } @@ -2689,6 +2766,7 @@ void ETSChecker::ResolveLambdaObjectInvokeFuncBody(ir::ClassDefinition *lambdaOb // reference auto *fieldProp = lambdaBody[0]->AsClassProperty()->Key()->AsIdentifier()->Variable(); fieldPropType = fieldProp->TsType()->AsETSObjectType(); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) fieldIdent = AllocNode("field0", Allocator()); fieldIdent->SetReference(); fieldIdent->SetVariable(fieldProp); @@ -2696,8 +2774,10 @@ void ETSChecker::ResolveLambdaObjectInvokeFuncBody(ir::ClassDefinition *lambdaOb fieldIdent->SetTsType(fieldPropType); // Set the type information for the function reference call + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *funcIdent = AllocNode(signatureRef->Function()->Id()->Name(), Allocator()); auto *callee = + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) AllocNode(fieldIdent, funcIdent, ir::MemberExpressionKind::ELEMENT_ACCESS, false, false); callee->SetPropVar(signatureRef->OwnerVar()->AsLocalVariable()); callee->SetObjectType(fieldPropType); @@ -2710,6 +2790,7 @@ void ETSChecker::ResolveLambdaObjectInvokeFuncBody(ir::ClassDefinition *lambdaOb ResolveCallParametersForLambdaFuncBody(this, signatureRef, invokeFunc, ifaceOverride); // Create the synthetic call expression to the referenced function + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *resolvedCall = AllocNode(callee, std::move(callParams), nullptr, false); resolvedCall->SetTsType(signatureRef->ReturnType()); resolvedCall->SetSignature(signatureRef); @@ -2799,6 +2880,7 @@ ir::MethodDefinition *ETSChecker::CreateAsyncImplMethod(ir::MethodDefinition *as varbinder::LexicalScope::Enter(VarBinder(), classDef->Scope()->AsClassScope()); auto *body = asyncFunc->Body(); ArenaVector params(Allocator()->Adapter()); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) varbinder::FunctionParamScope *paramScope = CopyParams(asyncFunc->Params(), params); // Set impl method return type "Object" because it may return Promise as well as Promise parameter's type @@ -2817,11 +2899,12 @@ ir::MethodDefinition *ETSChecker::CreateAsyncImplMethod(ir::MethodDefinition *as return GlobalBuiltinPromiseType()->AsETSObjectType(); }(asyncFuncRetTypeAnn); - + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *retType = Allocator()->New(Allocator(), Relation(), promiseType); returnTypeAnn->SetTsType(retType); ir::MethodDefinition *implMethod = + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) CreateMethod(implName.View(), modifiers, flags, std::move(params), paramScope, returnTypeAnn, body); asyncFunc->SetBody(nullptr); returnTypeAnn->SetParent(implMethod->Function()); @@ -2837,6 +2920,7 @@ ir::MethodDefinition *ETSChecker::CreateAsyncProxy(ir::MethodDefinition *asyncMe VarBinder()->AsETSBinder()->GetRecordTable()->Signatures().push_back(asyncFunc->Scope()); } + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) ir::MethodDefinition *implMethod = CreateAsyncImplMethod(asyncMethod, classDef); varbinder::FunctionScope *implFuncScope = implMethod->Function()->Scope(); for (auto *decl : asyncFunc->Scope()->Decls()) { @@ -2876,8 +2960,11 @@ ir::MethodDefinition *ETSChecker::CreateMethod(const util::StringView &name, ir: varbinder::FunctionParamScope *paramScope, ir::TypeNode *returnType, ir::AstNode *body) { + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *nameId = AllocNode(name, Allocator()); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *scope = VarBinder()->Allocator()->New(Allocator(), paramScope); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *const func = AllocNode(ir::FunctionSignature(nullptr, std::move(params), returnType), body, ir::ScriptFunction::ScriptFunctionData {flags, modifiers}); func->SetScope(scope); @@ -2889,9 +2976,10 @@ ir::MethodDefinition *ETSChecker::CreateMethod(const util::StringView &name, ir: paramScope->BindNode(func); scope->BindParamScope(paramScope); paramScope->BindFunctionScope(scope); - + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *funcExpr = AllocNode(func); auto *nameClone = nameId->Clone(Allocator(), nullptr); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *method = AllocNode(ir::MethodDefinitionKind::METHOD, nameClone, funcExpr, modifiers, Allocator(), false); return method; @@ -2904,6 +2992,7 @@ varbinder::FunctionParamScope *ETSChecker::CopyParams(const ArenaVectorAsETSParameterExpression(); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *const paramNew = paramOld->Clone(Allocator(), paramOld->Parent())->AsETSParameterExpression(); auto *const var = std::get<1>(VarBinder()->AddParamDecl(paramNew)); @@ -2984,6 +3073,7 @@ void ETSChecker::TransformTraillingLambda(ir::CallExpression *callExpr) ArenaVector params(Allocator()->Adapter()); auto *funcNode = + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) AllocNode(ir::FunctionSignature(nullptr, std::move(params), nullptr), trailingBlock, ir::ScriptFunction::ScriptFunctionData {ir::ScriptFunctionFlags::ARROW}); funcNode->SetScope(funcScope); @@ -2994,6 +3084,7 @@ void ETSChecker::TransformTraillingLambda(ir::CallExpression *callExpr) ReplaceScope(funcNode->Body(), trailingBlock, funcScope); callExpr->SetTrailingBlock(nullptr); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *arrowFuncNode = AllocNode(Allocator(), funcNode); arrowFuncNode->SetRange(trailingBlock->Range()); arrowFuncNode->SetParent(callExpr); @@ -3008,10 +3099,12 @@ ArenaVector ETSChecker::ExtendArgumentsWithFakeLamda(ir::CallE ArenaVector params(Allocator()->Adapter()); ArenaVector statements(Allocator()->Adapter()); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *body = AllocNode(Allocator(), std::move(statements)); body->SetScope(funcScope); auto *funcNode = + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) AllocNode(ir::FunctionSignature(nullptr, std::move(params), nullptr), body, ir::ScriptFunction::ScriptFunctionData {ir::ScriptFunctionFlags::ARROW}); funcNode->SetScope(funcScope); diff --git a/ets2panda/checker/ets/helpers.cpp b/ets2panda/checker/ets/helpers.cpp index e8565e50ba..5aec6ecd14 100644 --- a/ets2panda/checker/ets/helpers.cpp +++ b/ets2panda/checker/ets/helpers.cpp @@ -545,6 +545,7 @@ void ETSChecker::ValidateCallExpressionIdentifier(ir::Identifier *const ident, T (type->IsETSObjectType() && type->AsETSObjectType()->HasObjectFlag(ETSObjectFlags::FUNCTIONAL))) { return; } + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) if (TryTransformingToStaticInvoke(ident, type)) { return; } @@ -670,6 +671,7 @@ void ETSChecker::ValidateResolvedIdentifier(ir::Identifier *const ident, varbind switch (ident->Parent()->Type()) { case ir::AstNodeType::CALL_EXPRESSION: { + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) ValidateCallExpressionIdentifier(ident, resolvedType); break; } @@ -823,6 +825,7 @@ Type *ETSChecker::ResolveIdentifier(ir::Identifier *const ident) resolved = FindVariableInGlobal(ident); } + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) ValidateResolvedIdentifier(ident, resolved); ValidatePropertyAccess(resolved, Context().ContainingClass(), ident->Start()); @@ -1125,6 +1128,7 @@ checker::Type *ETSChecker::CheckArrayElements(ir::Identifier *ident, ir::ArrayEx ArenaVector elements = init->AsArrayExpression()->Elements(); checker::Type *annotationType = nullptr; if (elements.empty()) { + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) annotationType = Allocator()->New(GlobalETSObjectType()); } else { auto type = elements[0]->Check(this); @@ -1142,6 +1146,7 @@ checker::Type *ETSChecker::CheckArrayElements(ir::Identifier *ident, ir::ArrayEx ThrowTypeError({"Union type is not implemented yet!"}, ident->Start()); } } + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) annotationType = Allocator()->New(type); } return annotationType; @@ -1234,6 +1239,7 @@ checker::Type *ETSChecker::CheckVariableDeclaration(ir::Identifier *ident, ir::T (init->IsArrowFunctionExpression() || (init->IsTSAsExpression() && init->AsTSAsExpression()->Expr()->IsArrowFunctionExpression()))) { if (init->IsArrowFunctionExpression()) { + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) typeAnnotation = init->AsArrowFunctionExpression()->CreateTypeAnnotation(this); } else { typeAnnotation = init->AsTSAsExpression()->TypeAnnotation()->Clone(Allocator(), nullptr); @@ -1338,6 +1344,7 @@ Type *ETSChecker::GetTypeFromClassReference(varbinder::Variable *var) void ETSChecker::ValidateGenericTypeAliasForClonedNode(ir::TSTypeAliasDeclaration *const typeAliasNode, const ir::TSTypeParameterInstantiation *const exactTypeParams) { + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *const clonedNode = typeAliasNode->TypeAnnotation()->Clone(Allocator(), typeAliasNode); // Basic check, we really don't want to change the original type nodes, more precise checking should be made @@ -1401,6 +1408,7 @@ Type *ETSChecker::HandleTypeAlias(ir::Expression *const name, const ir::TSTypePa } if (typeParams == nullptr) { + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) return GetReferencedTypeBase(name); } @@ -1408,6 +1416,7 @@ Type *ETSChecker::HandleTypeAlias(ir::Expression *const name, const ir::TSTypePa origTypeParam->Check(this); } + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) Type *const aliasType = GetReferencedTypeBase(name); auto *const aliasSub = NewSubstitution(); @@ -1422,6 +1431,7 @@ Type *ETSChecker::HandleTypeAlias(ir::Expression *const name, const ir::TSTypePa } } + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) ValidateGenericTypeAliasForClonedNode(typeAliasNode->AsTSTypeAliasDeclaration(), typeParams); return aliasType->Substitute(Relation(), aliasSub); @@ -1435,8 +1445,10 @@ Type *ETSChecker::GetTypeFromEnumReference([[maybe_unused]] varbinder::Variable auto const *const enumDecl = var->Declaration()->Node()->AsTSEnumDeclaration(); if (auto *const itemInit = enumDecl->Members().front()->AsTSEnumMember()->Init(); itemInit->IsNumberLiteral()) { + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) return CreateETSEnumType(enumDecl); } else if (itemInit->IsStringLiteral()) { // NOLINT(readability-else-after-return) + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) return CreateETSStringEnumType(enumDecl); } else { // NOLINT(readability-else-after-return) ThrowTypeError("Invalid enumeration value type.", enumDecl->Start()); @@ -1558,6 +1570,7 @@ Type *ETSChecker::GetReferencedTypeBase(ir::Expression *name) return GetTypeFromClassReference(refVar); } case ir::AstNodeType::TS_ENUM_DECLARATION: { + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) return GetTypeFromEnumReference(refVar); } case ir::AstNodeType::TS_TYPE_PARAMETER: { @@ -2808,8 +2821,9 @@ void ETSChecker::GenerateGetterSetterBody(ArenaVector &stmts, A lexer::TokenType::PUNCTUATOR_SUBSTITUTION); assignmentExpression->SetRange({field->Start(), field->End()}); - + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) stmts.push_back(AllocNode(assignmentExpression)); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) stmts.push_back(Allocator()->New(nullptr)); } @@ -2828,18 +2842,19 @@ ir::MethodDefinition *ETSChecker::GenerateDefaultGetterSetter(ir::ClassProperty ArenaVector params(checker->Allocator()->Adapter()); ArenaVector stmts(checker->Allocator()->Adapter()); checker->GenerateGetterSetterBody(stmts, params, field, paramScope, isSetter); - + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *body = checker->AllocNode(checker->Allocator(), std::move(stmts)); auto funcFlags = isSetter ? ir::ScriptFunctionFlags::SETTER : ir::ScriptFunctionFlags::GETTER; auto *const returnTypeAnn = isSetter ? nullptr : field->TypeAnnotation()->Clone(checker->Allocator(), nullptr); auto *func = + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) checker->AllocNode(ir::FunctionSignature(nullptr, std::move(params), returnTypeAnn), body, ir::ScriptFunction::ScriptFunctionData {funcFlags, flags, true}); func->SetRange(field->Range()); func->SetScope(functionScope); body->SetScope(functionScope); - + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *methodIdent = field->Key()->AsIdentifier()->Clone(checker->Allocator(), nullptr); auto *decl = checker->Allocator()->New( checker->Allocator(), field->Key()->AsIdentifier()->Name(), @@ -2847,11 +2862,11 @@ ir::MethodDefinition *ETSChecker::GenerateDefaultGetterSetter(ir::ClassProperty auto *var = functionScope->AddDecl(checker->Allocator(), decl, ScriptExtension::ETS); methodIdent->SetVariable(var); - + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *funcExpr = checker->AllocNode(func); funcExpr->SetRange(func->Range()); func->AddFlag(ir::ScriptFunctionFlags::METHOD); - + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *method = checker->AllocNode(ir::MethodDefinitionKind::METHOD, methodIdent, funcExpr, flags, checker->Allocator(), false); @@ -2914,8 +2929,9 @@ bool ETSChecker::TryTransformingToStaticInvoke(ir::Identifier *const ident, cons ident->Start()); } // clang-format on - + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *classId = AllocNode(className, Allocator()); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *methodId = AllocNode(propertyName, Allocator()); if (propertyName == compiler::Signatures::STATIC_INSTANTIATE_METHOD) { methodId->SetVariable(instantiateMethod); @@ -2924,6 +2940,7 @@ bool ETSChecker::TryTransformingToStaticInvoke(ir::Identifier *const ident, cons } auto *transformedCallee = + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) AllocNode(classId, methodId, ir::MemberExpressionKind::PROPERTY_ACCESS, false, false); classId->SetRange(ident->Range()); @@ -2935,6 +2952,7 @@ bool ETSChecker::TryTransformingToStaticInvoke(ir::Identifier *const ident, cons callExpr->SetCallee(transformedCallee); if (instantiateMethod != nullptr) { + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *argExpr = GenerateImplicitInstantiateArg(instantiateMethod, std::string(className)); argExpr->SetParent(callExpr); diff --git a/ets2panda/checker/ets/object.cpp b/ets2panda/checker/ets/object.cpp index ff2eebd10f..59bbeb9a55 100644 --- a/ets2panda/checker/ets/object.cpp +++ b/ets2panda/checker/ets/object.cpp @@ -867,6 +867,7 @@ void ETSChecker::CheckClassDefinition(ir::ClassDefinition *classDef) it->Check(this); } } + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) CreateAsyncProxyMethods(classDef); if (classDef->IsGlobal()) { @@ -881,6 +882,7 @@ void ETSChecker::CheckClassDefinition(ir::ClassDefinition *classDef) } ValidateOverriding(classType, classDef->Start()); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) TransformProperties(classType); CheckValidInheritance(classType, classDef); CheckConstFields(classType); @@ -905,12 +907,14 @@ void ETSChecker::CreateAsyncProxyMethods(ir::ClassDefinition *classDef) continue; } auto *method = it->AsMethodDefinition(); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) asyncImpls.push_back(CreateAsyncProxy(method, classDef)); auto *proxy = asyncImpls.back(); for (auto *overload : method->Overloads()) { if (!overload->IsAsync()) { continue; } + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *impl = CreateAsyncProxy(overload, classDef, false); impl->Function()->Id()->SetVariable(proxy->Function()->Id()->Variable()); proxy->AddOverload(impl); @@ -1569,7 +1573,7 @@ void ETSChecker::TransformProperties(ETSObjectType *classType) auto *const scope = this->Scope(); ASSERT(scope->IsClassScope()); - + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) ir::MethodDefinition *getter = GenerateDefaultGetterSetter(classProp, scope->AsClassScope(), false, this); classDef->Body().push_back(getter); getter->SetParent(classDef); @@ -1589,6 +1593,7 @@ void ETSChecker::TransformProperties(ETSObjectType *classType) if (!classProp->IsReadonly()) { ir::MethodDefinition *const setter = + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) GenerateDefaultGetterSetter(classProp, scope->AsClassScope(), true, this); setter->SetParent(classDef); @@ -1603,6 +1608,7 @@ void ETSChecker::TransformProperties(ETSObjectType *classType) if (!classProp->IsReadonly()) { ir::MethodDefinition *const setter = + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) GenerateDefaultGetterSetter(classProp, scope->AsClassScope(), true, this); setter->SetParent(classDef); diff --git a/ets2panda/checker/ets/typeCreation.cpp b/ets2panda/checker/ets/typeCreation.cpp index 10b9b17bc4..ece4b88625 100644 --- a/ets2panda/checker/ets/typeCreation.cpp +++ b/ets2panda/checker/ets/typeCreation.cpp @@ -381,41 +381,51 @@ ETSEnumType *ETSChecker::CreateETSEnumType(ir::TSEnumDeclaration const *const en memberVar->SetTsType(enumLiteralType); } + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *const namesArrayIdent = CreateEnumNamesArray(enumType); auto *identClone = namesArrayIdent->Clone(Allocator(), nullptr); identClone->SetTsType(namesArrayIdent->TsType()); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto const getNameMethod = CreateEnumGetNameMethod(identClone, enumType); enumType->SetGetNameMethod(getNameMethod); identClone = namesArrayIdent->Clone(Allocator(), nullptr); identClone->SetTsType(namesArrayIdent->TsType()); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto const valueOfMethod = CreateEnumValueOfMethod(identClone, enumType); enumType->SetValueOfMethod(valueOfMethod); identClone = namesArrayIdent->Clone(Allocator(), nullptr); identClone->SetTsType(namesArrayIdent->TsType()); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto const fromIntMethod = CreateEnumFromIntMethod(identClone, enumType); enumType->SetFromIntMethod(fromIntMethod); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *const valuesArrayIdent = CreateEnumValuesArray(enumType); identClone = valuesArrayIdent->Clone(Allocator(), nullptr); identClone->SetTsType(valuesArrayIdent->TsType()); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto const getValueMethod = CreateEnumGetValueMethod(identClone, enumType); enumType->SetGetValueMethod(getValueMethod); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *const stringValuesArrayIdent = CreateEnumStringValuesArray(enumType); identClone = stringValuesArrayIdent->Clone(Allocator(), nullptr); identClone->SetTsType(stringValuesArrayIdent->TsType()); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto const toStringMethod = CreateEnumToStringMethod(identClone, enumType); enumType->SetToStringMethod(toStringMethod); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *const itemsArrayIdent = CreateEnumItemsArray(enumType); identClone = itemsArrayIdent->Clone(Allocator(), nullptr); identClone->SetTsType(itemsArrayIdent->TsType()); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto const valuesMethod = CreateEnumValuesMethod(identClone, enumType); enumType->SetValuesMethod(valuesMethod); @@ -448,23 +458,28 @@ ETSStringEnumType *ETSChecker::CreateETSStringEnumType(ir::TSEnumDeclaration con memberVar->SetTsType(enumLiteralType); } + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *const namesArrayIdent = CreateEnumNamesArray(enumType); auto *identClone = namesArrayIdent->Clone(Allocator(), nullptr); identClone->SetTsType(namesArrayIdent->TsType()); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto const getNameMethod = CreateEnumGetNameMethod(identClone, enumType); enumType->SetGetNameMethod(getNameMethod); identClone = namesArrayIdent->Clone(Allocator(), nullptr); identClone->SetTsType(namesArrayIdent->TsType()); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto const valueOfMethod = CreateEnumValueOfMethod(identClone, enumType); enumType->SetValueOfMethod(valueOfMethod); identClone = namesArrayIdent->Clone(Allocator(), nullptr); identClone->SetTsType(namesArrayIdent->TsType()); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto const fromIntMethod = CreateEnumFromIntMethod(identClone, enumType); enumType->SetFromIntMethod(fromIntMethod); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *const stringValuesArrayIdent = CreateEnumStringValuesArray(enumType); identClone = stringValuesArrayIdent->Clone(Allocator(), nullptr); @@ -473,10 +488,12 @@ ETSStringEnumType *ETSChecker::CreateETSStringEnumType(ir::TSEnumDeclaration con enumType->SetToStringMethod(toStringMethod); enumType->SetGetValueMethod(toStringMethod); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *const itemsArrayIdent = CreateEnumItemsArray(enumType); identClone = itemsArrayIdent->Clone(Allocator(), nullptr); identClone->SetTsType(itemsArrayIdent->TsType()); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto const valuesMethod = CreateEnumValuesMethod(identClone, enumType); enumType->SetValuesMethod(valuesMethod); -- Gitee