diff --git a/ets2panda/aot/main.cpp b/ets2panda/aot/main.cpp index b8f59a420fea54dce7a69cf402702fc0455fa874..2782245c60729568f3bdd27dfb6f447d4ed284b2 100644 --- a/ets2panda/aot/main.cpp +++ b/ets2panda/aot/main.cpp @@ -100,6 +100,15 @@ static int CompileMultipleFiles(es2panda::Compiler &compiler, std::vector &parserInputs, unsigned int returnCode) +{ + for (auto *input : parserInputs) { + delete input; + } + parserInputs.clear(); + return returnCode; +} + static unsigned int CompileFromConfig(es2panda::Compiler &compiler, util::Options *options, util::DiagnosticEngine &diagnosticEngine) { @@ -110,6 +119,7 @@ static unsigned int CompileFromConfig(es2panda::Compiler &compiler, util::Option } std::vector inputs {}; + std::vector parserInputs; unsigned int overallRes = 0; for (auto &[src, dst] : compilationList) { std::ifstream inputStream(src); @@ -119,14 +129,14 @@ static unsigned int CompileFromConfig(es2panda::Compiler &compiler, util::Option } std::stringstream ss; ss << inputStream.rdbuf(); - auto *parserInput = new std::string(ss.str()); + parserInputs.push_back(new std::string(ss.str())); inputStream.close(); - es2panda::SourceFile input(src, *parserInput, options->IsModule(), std::string_view(dst)); + es2panda::SourceFile input(src, *parserInputs.back(), options->IsModule(), std::string_view(dst)); inputs.push_back(input); } if (options->IsPermArena() && (options->GetExtension() == util::gen::extension::ETS)) { - return CompileMultipleFiles(compiler, inputs, options, diagnosticEngine); + return ReleaseInputsAndReturn(parserInputs, CompileMultipleFiles(compiler, inputs, options, diagnosticEngine)); } for (auto &input : inputs) { @@ -140,7 +150,7 @@ static unsigned int CompileFromConfig(es2panda::Compiler &compiler, util::Option overallRes |= static_cast(res); } } - return overallRes; + return ReleaseInputsAndReturn(parserInputs, overallRes); } static std::optional> InitializePlugins(std::vector const &names, diff --git a/ets2panda/checker/ts/destructuringContext.cpp b/ets2panda/checker/ts/destructuringContext.cpp index 62212a8fcac53a0723d372e7ae9608ebbcab3005..3a0994723ca0ffd68a3d15853f554291f2c4cc74 100644 --- a/ets2panda/checker/ts/destructuringContext.cpp +++ b/ets2panda/checker/ts/destructuringContext.cpp @@ -157,6 +157,7 @@ void DestructuringContext::HandleAssignmentPattern(ir::AssignmentExpression *ass ES2PANDA_ASSERT(defaultType != nullptr); if (validateDefault && assignmentPattern->Right()->IsObjectExpression() && assignmentPattern->Left()->IsObjectPattern()) { + ES2PANDA_ASSERT(defaultType != nullptr); ValidateObjectLiteralType(defaultType->AsObjectType(), assignmentPattern->Left()->AsObjectPattern()); } diff --git a/ets2panda/compiler/core/compilerImpl.cpp b/ets2panda/compiler/core/compilerImpl.cpp index 0f206c0f0d92ffe169ef35e7671b1e08a4cb9a74..5a0a5ce4e14cc9f87f7d5ecc6220b99559a0b674 100644 --- a/ets2panda/compiler/core/compilerImpl.cpp +++ b/ets2panda/compiler/core/compilerImpl.cpp @@ -427,10 +427,22 @@ static bool ExecuteParsingAndCompiling(const CompilationUnit &unit, public_lib:: return !context->diagnosticEngine->IsAnyError(); } +static pandasm::Program *ClearContextAndReturnProgam(public_lib::Context *context, pandasm::Program *program) +{ + context->config = nullptr; + context->parser = nullptr; + context->checker->SetAnalyzer(nullptr); + context->checker = nullptr; + context->analyzer = nullptr; + context->phaseManager = nullptr; + context->parserProgram = nullptr; + context->emitter = nullptr; + return program; +} + template -static pandasm::Program *Compile(const CompilationUnit &unit, CompilerImpl *compilerImpl, - [[maybe_unused]] public_lib::Context *context) +static pandasm::Program *Compile(const CompilationUnit &unit, CompilerImpl *compilerImpl, public_lib::Context *context) { auto config = public_lib::ConfigImpl {}; context->config = &config; @@ -475,9 +487,9 @@ static pandasm::Program *Compile(const CompilationUnit &unit, CompilerImpl *comp context->checker->Initialize(varbinder); if (!ExecuteParsingAndCompiling(unit, context)) { - return nullptr; + return ClearContextAndReturnProgam(context, nullptr); } - return EmitProgram(compilerImpl, context, unit); + return ClearContextAndReturnProgam(context, EmitProgram(compilerImpl, context, unit)); } pandasm::Program *CompilerImpl::Compile(const CompilationUnit &unit, public_lib::Context *context) diff --git a/ets2panda/compiler/lowering/ets/enumLowering.cpp b/ets2panda/compiler/lowering/ets/enumLowering.cpp index 5212c1dc3aa91576605416533d3baf9bac12d896..115baffb4beea723c17aafb83c1e4411c288518b 100644 --- a/ets2panda/compiler/lowering/ets/enumLowering.cpp +++ b/ets2panda/compiler/lowering/ets/enumLowering.cpp @@ -152,6 +152,7 @@ template auto *const arrayClassProp = AllocNode( arrayIdent, arrayExpr, typeAnnotation, ir::ModifierFlags::STATIC | ir::ModifierFlags::PRIVATE | ir::ModifierFlags::READONLY, Allocator(), false); + ES2PANDA_ASSERT(arrayClassProp != nullptr); arrayClassProp->SetParent(enumClass); enumClass->Body().push_back(arrayClassProp); @@ -316,6 +317,7 @@ void EnumLoweringPhase::CreateCCtorForEnumClass(ir::ClassDefinition *const enumC auto *const methodDef = AllocNode(ir::MethodDefinitionKind::METHOD, identClone, funcExpr, ir::ModifierFlags::PRIVATE | ir::ModifierFlags::STATIC, Allocator(), false); + ES2PANDA_ASSERT(methodDef != nullptr); methodDef->SetParent(enumClass); enumClass->Body().push_back(methodDef); } diff --git a/ets2panda/compiler/lowering/ets/interfacePropertyDeclarations.cpp b/ets2panda/compiler/lowering/ets/interfacePropertyDeclarations.cpp index f9832dc3c3444d6b2c7390c7a77b187eb43555ae..14ab736122a3d56fc1eb634c19c124df90d06dec 100644 --- a/ets2panda/compiler/lowering/ets/interfacePropertyDeclarations.cpp +++ b/ets2panda/compiler/lowering/ets/interfacePropertyDeclarations.cpp @@ -85,6 +85,7 @@ ir::FunctionSignature InterfacePropertyDeclarationsPhase::GenerateGetterOrSetter InitScopesPhaseETS::RunExternalNode(paramIdent, varbinder); auto *const paramExpression = ctx->AllocNode(paramIdent, false, ctx->Allocator()); + ES2PANDA_ASSERT(paramExpression != nullptr); paramExpression->SetRange(paramIdent->Range()); auto [paramVar, node] = paramScope->AddParamDecl(ctx->Allocator(), varbinder, paramExpression); if (node != nullptr) { @@ -108,6 +109,7 @@ ir::MethodDefinition *InterfacePropertyDeclarationsPhase::GenerateGetterOrSetter auto classScope = NearestScope(field); auto *paramScope = ctx->Allocator()->New(ctx->Allocator(), classScope); auto *functionScope = ctx->Allocator()->New(ctx->Allocator(), paramScope); + ES2PANDA_ASSERT(functionScope != nullptr); functionScope->BindParamScope(paramScope); paramScope->BindFunctionScope(functionScope); @@ -253,6 +255,7 @@ ir::Expression *InterfacePropertyDeclarationsPhase::UpdateInterfaceProperties(pu } auto newInterface = ctx->AllocNode(std::move(newPropertyList)); + ES2PANDA_ASSERT(newInterface != nullptr); newInterface->SetRange(interface->Range()); newInterface->SetParent(interface->Parent()); diff --git a/ets2panda/declgen_ets2ts/declgenEts2Ts.cpp b/ets2panda/declgen_ets2ts/declgenEts2Ts.cpp index d14977f265c828aed4d1afa55dc978e1df4f0974..51ef162a7cf2aeaf649e95d1a856dc9cd885ef0b 100644 --- a/ets2panda/declgen_ets2ts/declgenEts2Ts.cpp +++ b/ets2panda/declgen_ets2ts/declgenEts2Ts.cpp @@ -618,6 +618,7 @@ void TSDeclGen::GenFunctionType(const checker::ETSFunctionType *etsFunctionType, const bool isSetter = methodDef != nullptr ? methodDef->Kind() == ir::MethodDefinitionKind::SET : false; // CC-OFFNXT(G.FMT.14-CPP) project code style const auto *sig = GetFuncSignature(etsFunctionType, methodDef); + ES2PANDA_ASSERT(sig != nullptr); if (sig->HasFunction()) { GenTypeParameters(sig->Function()->TypeParams()); const auto *funcBody = sig->Function()->Body(); diff --git a/ets2panda/ir/brokenTypeNode.cpp b/ets2panda/ir/brokenTypeNode.cpp index 110222066dbaa978f61131669aba4f5c5f98cdc8..05ef63679f55f15117eaf0cf22f9f0ef00f2546b 100644 --- a/ets2panda/ir/brokenTypeNode.cpp +++ b/ets2panda/ir/brokenTypeNode.cpp @@ -72,6 +72,7 @@ checker::VerifiedType BrokenTypeNode::Check([[maybe_unused]] checker::ETSChecker BrokenTypeNode *BrokenTypeNode::Clone(ArenaAllocator *const allocator, AstNode *const parent) { auto *const clone = allocator->New(allocator); + ES2PANDA_ASSERT(clone != nullptr); if (parent != nullptr) { clone->SetParent(parent); } diff --git a/ets2panda/ir/ts/tsTupleType.cpp b/ets2panda/ir/ts/tsTupleType.cpp index c6f8052957c926946303004d8e736f79bbf1bebc..45d7df04c4cdedb9e838935ec1f0e3cef517bee6 100644 --- a/ets2panda/ir/ts/tsTupleType.cpp +++ b/ets2panda/ir/ts/tsTupleType.cpp @@ -93,6 +93,7 @@ checker::Type *GetNumberIndexType(ArenaVector numberIndexTypes, static void SetMemberVarType(checker::Type *memberType, varbinder::LocalVariable *memberVar) { + ES2PANDA_ASSERT(memberType != nullptr); memberType->SetVariable(memberVar); memberVar->SetTsType(memberType); }