From b13dd718bb6e0934ae24cc9725717efbf9ca5a7e Mon Sep 17 00:00:00 2001 From: Zhelyapov Aleksey Date: Mon, 30 Jun 2025 22:17:44 +0300 Subject: [PATCH] Fixed codecheck Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICIYVM Signed-off-by: Zhelyapov Aleksey --- ets2panda/compiler/core/ETSGen.cpp | 45 +++++++++++++++++-- ets2panda/compiler/core/ETSGen.h | 3 +- ets2panda/compiler/core/function.cpp | 1 + .../lowering/scopesInit/scopesInitPhase.cpp | 10 ++++- ets2panda/util/doubleLinkedList.h | 3 ++ ets2panda/util/generateBin.cpp | 1 + ets2panda/util/helpers.cpp | 1 + ets2panda/util/options.cpp | 1 + ets2panda/util/path.cpp | 8 ++-- ets2panda/util/ustring.h | 3 ++ ets2panda/varbinder/ETSBinder.cpp | 13 +++++- ets2panda/varbinder/scope.cpp | 9 ++-- 12 files changed, 82 insertions(+), 16 deletions(-) diff --git a/ets2panda/compiler/core/ETSGen.cpp b/ets2panda/compiler/core/ETSGen.cpp index 84960c75e6..bd7cb0bcbe 100644 --- a/ets2panda/compiler/core/ETSGen.cpp +++ b/ets2panda/compiler/core/ETSGen.cpp @@ -86,6 +86,7 @@ void ETSGen::CompileAndCheck(const ir::Expression *expr) return; } + ES2PANDA_ASSERT(accType != nullptr); if (accType->IsETSPrimitiveType() && ((accType->TypeFlags() ^ exprType->TypeFlags()) & ~checker::TypeFlag::CONSTANT) == 0) { return; @@ -216,6 +217,7 @@ checker::Type const *ETSGen::TypeForVar(varbinder::Variable const *var) const no void ETSGen::MoveVreg(const ir::AstNode *const node, const VReg vd, const VReg vs) { const auto *const sourceType = GetVRegType(vs); + ES2PANDA_ASSERT(sourceType != nullptr); if (sourceType->IsETSReferenceType()) { Ra().Emit(node, vd, vs); @@ -270,6 +272,8 @@ void ETSGen::LoadDynamicModuleVariable(const ir::AstNode *node, varbinder::Varia RegScope rs(this); auto *data = VarBinder()->DynamicImportDataForVar(var); + ES2PANDA_ASSERT(data != nullptr); + auto *import = data->import; LoadStaticProperty(node, var->TsType(), FormDynamicModulePropReference(var)); @@ -310,6 +314,7 @@ void ETSGen::LoadVar(const ir::Identifier *node, varbinder::Variable const *cons break; } case ReferenceKind::FIELD: { + ES2PANDA_ASSERT(GetVRegType(GetThisReg()) != nullptr); const auto fullName = FormClassPropReference(GetVRegType(GetThisReg())->AsETSObjectType(), var->Name()); LoadProperty(node, var->TsType(), GetThisReg(), fullName); break; @@ -361,6 +366,7 @@ void ETSGen::StoreVar(const ir::Identifier *node, const varbinder::ConstScopeFin util::StringView ETSGen::FormClassPropReference(const checker::ETSObjectType *classType, const util::StringView &name) { std::stringstream ss; + ES2PANDA_ASSERT(classType != nullptr); ss << classType->AssemblerName().Mutf8() << Signatures::METHOD_SEPARATOR << name; return util::StringView(*ProgElement()->Strings().emplace(ss.str()).first); } @@ -393,6 +399,7 @@ void ETSGen::StoreStaticProperty(const ir::AstNode *const node, const checker::T void ETSGen::LoadStaticProperty(const ir::AstNode *const node, const checker::Type *propType, const util::StringView &fullName) { + ES2PANDA_ASSERT(propType != nullptr); if (propType->IsETSReferenceType()) { Sa().Emit(node, fullName); } else if (IsWidePrimitiveType(propType)) { @@ -407,6 +414,7 @@ void ETSGen::LoadStaticProperty(const ir::AstNode *const node, const checker::Ty void ETSGen::StoreProperty(const ir::AstNode *const node, const checker::Type *propType, const VReg objReg, const util::StringView &name) { + ES2PANDA_ASSERT(Checker()->GetApparentType(GetVRegType(objReg)) != nullptr); auto *objType = Checker()->GetApparentType(GetVRegType(objReg))->AsETSObjectType(); const auto fullName = FormClassPropReference(objType, name); @@ -475,6 +483,7 @@ void ETSGen::LoadPropertyByName([[maybe_unused]] const ir::AstNode *const node, void ETSGen::StorePropertyDynamic(const ir::AstNode *node, const checker::Type *propType, VReg objReg, const util::StringView &propName) { + ES2PANDA_ASSERT(GetVRegType(objReg) != nullptr); auto const lang = GetVRegType(objReg)->AsETSDynamicType()->Language(); std::string_view methodName {}; if (propType->IsETSBooleanType()) { @@ -523,6 +532,7 @@ void ETSGen::StorePropertyDynamic(const ir::AstNode *node, const checker::Type * void ETSGen::LoadPropertyDynamic(const ir::AstNode *node, const checker::Type *propType, VReg objReg, std::variant property) { + ES2PANDA_ASSERT(propType != nullptr && GetVRegType(objReg) != nullptr); auto const lang = GetVRegType(objReg)->AsETSDynamicType()->Language(); auto *type = propType; std::string_view methodName {}; @@ -577,6 +587,7 @@ void ETSGen::LoadPropertyDynamic(const ir::AstNode *node, const checker::Type *p void ETSGen::StoreElementDynamic(const ir::AstNode *node, VReg objectReg, VReg index) { + ES2PANDA_ASSERT(GetVRegType(objectReg) != nullptr); auto const lang = GetVRegType(objectReg)->AsETSDynamicType()->Language(); std::string_view methodName = Signatures::Dynamic::SetElementDynamicBuiltin(lang); @@ -592,6 +603,7 @@ void ETSGen::StoreElementDynamic(const ir::AstNode *node, VReg objectReg, VReg i void ETSGen::LoadElementDynamic(const ir::AstNode *node, VReg objectReg) { + ES2PANDA_ASSERT(GetVRegType(objectReg) != nullptr); auto const lang = GetVRegType(objectReg)->AsETSDynamicType()->Language(); std::string_view methodName = Signatures::Dynamic::GetElementDynamicBuiltin(lang); @@ -682,6 +694,7 @@ void ETSGen::EmitReturnVoid(const ir::AstNode *node) void ETSGen::ReturnAcc(const ir::AstNode *node) { const auto *const accType = GetAccumulatorType(); + ES2PANDA_ASSERT(accType != nullptr); if (accType->IsETSReferenceType()) { Sa().Emit(node); @@ -694,6 +707,7 @@ void ETSGen::ReturnAcc(const ir::AstNode *node) static bool IsNullUnsafeObjectType(checker::Type const *type) { + ES2PANDA_ASSERT(type != nullptr); return type->IsETSObjectType() && type->AsETSObjectType()->IsGlobalETSObjectType(); } @@ -727,6 +741,7 @@ void ETSGen::IsInstanceDynamic(const ir::BinaryExpression *const node, const VRe // return false Label *ifFalse = AllocLabel(); Language lang = rhsType->AsETSDynamicType()->Language(); + ES2PANDA_ASSERT(Checker()->GlobalBuiltinDynamicType(lang) != nullptr); VReg dynTypeReg = MoveAccToReg(node); LoadAccumulator(node, srcReg); EmitIsInstance(node, Checker()->GlobalBuiltinDynamicType(lang)->AssemblerName()); @@ -844,7 +859,7 @@ void ETSGen::BranchIfIsInstance(const ir::AstNode *const node, const VReg srcReg void ETSGen::IsInstance(const ir::AstNode *const node, const VReg srcReg, const checker::Type *target) { target = Checker()->GetApparentType(target); - ES2PANDA_ASSERT(target->IsETSReferenceType()); + ES2PANDA_ASSERT(target->IsETSReferenceType() && GetAccumulatorType() != nullptr); if (target->IsETSAnyType()) { // should be IsSupertypeOf(target, source) LoadAccumulatorBoolean(node, true); @@ -903,6 +918,7 @@ void ETSGen::CheckedReferenceNarrowingObject(const ir::AstNode *node, const chec bool nullishCheck = false; auto *source = GetAccumulatorType(); + ES2PANDA_ASSERT(source != nullptr); if (source->PossiblyETSUndefined()) { nullishCheck = true; BranchIfUndefined(node, isNullish); @@ -1207,6 +1223,7 @@ void ETSGen::EmitUnboxedCall(const ir::AstNode *node, std::string_view signature // to cast to primitive types we probably have to cast to corresponding boxed built-in types first. auto *const checker = Checker()->AsETSChecker(); auto const *accumulatorType = GetAccumulatorType(); + ES2PANDA_ASSERT(accumulatorType != nullptr); if (accumulatorType->IsETSObjectType() && //! accumulatorType->DefinitelyNotETSNullish() && !checker->Relation()->IsIdenticalTo(const_cast(accumulatorType), const_cast(boxedType))) { @@ -1662,6 +1679,7 @@ void ETSGen::CastToReftype(const ir::AstNode *const node, const checker::Type *c ES2PANDA_ASSERT(GetAccumulatorType()->IsETSReferenceType()); const auto *const sourceType = GetAccumulatorType(); + ES2PANDA_ASSERT(sourceType != nullptr); if (sourceType->IsETSDynamicType()) { CastDynamicToObject(node, targetType); @@ -1748,6 +1766,7 @@ void ETSGen::CastDynamicToObject(const ir::AstNode *node, const checker::Type *t void ETSGen::CastToString(const ir::AstNode *const node) { const auto *const sourceType = GetAccumulatorType(); + ES2PANDA_ASSERT(sourceType != nullptr); if (sourceType->IsETSStringType()) { return; } @@ -1783,6 +1802,7 @@ void ETSGen::CastToDynamic(const ir::AstNode *node, const checker::ETSDynamicTyp case checker::TypeFlag::ETS_PARTIAL_TYPE_PARAMETER: case checker::TypeFlag::ETS_UNION: // NOTE(vpukhov): refine dynamic type cast rules case checker::TypeFlag::ETS_ANY: + ES2PANDA_ASSERT(GetAccumulatorType() != nullptr); if (GetAccumulatorType()->IsETSStringType()) { methodName = compiler::Signatures::Dynamic::NewStringBuiltin(type->Language()); break; @@ -1818,6 +1838,7 @@ void ETSGen::CastDynamicTo(const ir::AstNode *node, enum checker::TypeFlag typeF { std::string_view methodName {}; checker::Type *objectType {}; + ES2PANDA_ASSERT(GetAccumulatorType() != nullptr); auto type = GetAccumulatorType()->AsETSDynamicType(); switch (typeFlag) { case checker::TypeFlag::ETS_BOOLEAN: { @@ -2040,6 +2061,7 @@ template void ETSGen::ResolveConditionalResultFloat(const ir::AstNode *node, Label *realEndLabel) { auto type = GetAccumulatorType(); + ES2PANDA_ASSERT(type != nullptr); VReg tmpReg = AllocReg(); StoreAccumulator(node, tmpReg); if (type->IsFloatType()) { @@ -2104,6 +2126,7 @@ void ETSGen::ResolveConditionalResultReference(const ir::AstNode *node) }; auto type = GetAccumulatorType(); + ES2PANDA_ASSERT(type != nullptr); if (!type->PossiblyETSString()) { Sa().Emit(node, 1); return; @@ -2118,6 +2141,7 @@ void ETSGen::ResolveConditionalResultReference(const ir::AstNode *node) compiler::VReg objReg = AllocReg(); StoreAccumulator(node, objReg); + ES2PANDA_ASSERT(Checker()->GlobalBuiltinETSStringType() != nullptr); EmitIsInstance(node, Checker()->GlobalBuiltinETSStringType()->AssemblerName()); BranchIfTrue(node, isString); Sa().Emit(node, 1); @@ -2133,6 +2157,7 @@ template void ETSGen::ResolveConditionalResult(const ir::AstNode *node, [[maybe_unused]] Label *ifFalse) { auto type = GetAccumulatorType(); + ES2PANDA_ASSERT(type != nullptr); #ifdef PANDA_WITH_ETS if (type->IsETSReferenceType()) { VReg valReg = AllocReg(); @@ -2195,6 +2220,7 @@ template void ETSGen::BranchConditional(const ir::AstNode *node, Label *endLabel) { auto type = GetAccumulatorType(); + ES2PANDA_ASSERT(type != nullptr); if (type->IsETSReferenceType()) { VReg valReg = AllocReg(); StoreAccumulator(node, valReg); @@ -2213,6 +2239,7 @@ void ETSGen::BranchConditional(const ir::AstNode *node, Label *endLabel) void ETSGen::ConditionalFloat(const ir::AstNode *node) { auto type = GetAccumulatorType(); + ES2PANDA_ASSERT(type != nullptr); VReg tmpReg = AllocReg(); VReg isNaNReg = AllocReg(); @@ -2252,6 +2279,7 @@ void ETSGen::BranchConditionalIfTrue(const ir::AstNode *node, Label *endLabel) void ETSGen::BranchIfNullish(const ir::AstNode *node, Label *ifNullish) { auto *const type = GetAccumulatorType(); + ES2PANDA_ASSERT(type != nullptr); if (type->IsETSVoidType()) { // NOTE(): #19701 need void refactoring @@ -2294,6 +2322,7 @@ void ETSGen::BranchIfNotNullish(const ir::AstNode *node, Label *ifNotNullish) void ETSGen::AssumeNonNullish(const ir::AstNode *node, checker::Type const *targetType) { auto const *nullishType = GetAccumulatorType(); + ES2PANDA_ASSERT(nullishType != nullptr); if (nullishType->PossiblyETSNull()) { // clear 'null' dataflow EmitCheckCast(node, ToAssemblerType(targetType)); @@ -2482,6 +2511,7 @@ void ETSGen::HandleDefinitelyNullishEquality(const ir::AstNode *node, VReg lhs, } else { auto *checker = const_cast(Checker()); auto ltype = checker->GetNonConstantType(const_cast(GetVRegType(lhs))); + ES2PANDA_ASSERT(ltype != nullptr); LoadAccumulator(node, ltype->DefinitelyETSNullish() ? rhs : lhs); BranchIfNotNullish(node, ifFalse); } @@ -2518,6 +2548,7 @@ static std::optional> SelectL { auto alhs = checker->GetApparentType(checker->GetNonNullishType(lhs)); auto arhs = checker->GetApparentType(checker->GetNonNullishType(rhs)); + ES2PANDA_ASSERT(alhs != nullptr && arhs != nullptr); alhs = alhs->IsETSStringType() ? checker->GlobalBuiltinETSStringType() : alhs; arhs = arhs->IsETSStringType() ? checker->GlobalBuiltinETSStringType() : arhs; if (!alhs->IsETSObjectType() || !arhs->IsETSObjectType()) { @@ -2592,6 +2623,7 @@ void ETSGen::RefEqualityLoose(const ir::AstNode *node, VReg lhs, VReg rhs, Label auto *checker = const_cast(Checker()); auto ltype = checker->GetNonConstantType(const_cast(GetVRegType(lhs))); auto rtype = checker->GetNonConstantType(const_cast(GetVRegType(rhs))); + ES2PANDA_ASSERT(ltype != nullptr && rtype != nullptr); if (ltype->IsETSDynamicType() || rtype->IsETSDynamicType()) { RefEqualityLooseDynamic(node, lhs, rhs, ifFalse); return; @@ -2769,6 +2801,7 @@ void ETSGen::Unary(const ir::AstNode *node, lexer::TokenType op) void ETSGen::UnaryMinus(const ir::AstNode *node) { + ES2PANDA_ASSERT(GetAccumulatorType() != nullptr); if (GetAccumulatorType()->IsETSBigIntType()) { const VReg value = AllocReg(); StoreAccumulator(node, value); @@ -2804,6 +2837,7 @@ void ETSGen::UnaryMinus(const ir::AstNode *node) void ETSGen::UnaryTilde(const ir::AstNode *node) { + ES2PANDA_ASSERT(GetAccumulatorType() != nullptr); if (GetAccumulatorType()->IsETSBigIntType()) { const VReg value = AllocReg(); StoreAccumulator(node, value); @@ -2889,6 +2923,7 @@ void ETSGen::StringBuilderAppend(const ir::AstNode *node, VReg builder) signature = Signatures::BUILTIN_STRING_BUILDER_APPEND_BUILTIN_STRING; } + ES2PANDA_ASSERT(GetAccumulatorType() != nullptr); if (GetAccumulatorType()->IsETSReferenceType() && !GetAccumulatorType()->IsETSStringType()) { if (GetAccumulatorType()->PossiblyETSUndefined()) { Label *ifUndefined = AllocLabel(); @@ -3041,6 +3076,7 @@ void ETSGen::LoadResizableArrayLength(const ir::AstNode *node) void ETSGen::LoadResizableArrayElement(const ir::AstNode *node, const VReg arrObj, const VReg arrIndex) { auto *vRegType = GetVRegType(arrObj); + ES2PANDA_ASSERT(vRegType != nullptr); auto *elementType = vRegType->AsETSResizableArrayType()->ElementType(); Ra().Emit(node, Signatures::BUILTIN_ARRAY_GET_ELEMENT, arrObj, arrIndex); SetAccumulatorType(elementType); @@ -3054,6 +3090,7 @@ void ETSGen::LoadArrayLength(const ir::AstNode *node, VReg arrayReg) void ETSGen::LoadArrayElement(const ir::AstNode *node, VReg objectReg) { + ES2PANDA_ASSERT(GetVRegType(objectReg) != nullptr); auto *elementType = GetVRegType(objectReg)->AsETSArrayType()->ElementType(); if (elementType->IsETSReferenceType()) { Ra().Emit(node, objectReg); @@ -3150,7 +3187,7 @@ util::StringView ETSGen::GetTupleMemberNameForIndex(const std::size_t index) con void ETSGen::LoadTupleElement(const ir::AstNode *node, VReg objectReg, const checker::Type *elementType, std::size_t index) { - ES2PANDA_ASSERT(GetVRegType(objectReg)->IsETSTupleType()); + ES2PANDA_ASSERT(GetVRegType(objectReg) != nullptr && GetVRegType(objectReg)->IsETSTupleType()); const auto propName = FormClassPropReference(GetVRegType(objectReg)->AsETSTupleType()->GetWrapperType(), GetTupleMemberNameForIndex(index)); @@ -3162,7 +3199,7 @@ void ETSGen::LoadTupleElement(const ir::AstNode *node, VReg objectReg, const che void ETSGen::StoreTupleElement(const ir::AstNode *node, VReg objectReg, const checker::Type *elementType, std::size_t index) { - ES2PANDA_ASSERT(GetVRegType(objectReg)->IsETSTupleType()); + ES2PANDA_ASSERT(GetVRegType(objectReg) != nullptr && GetVRegType(objectReg)->IsETSTupleType()); const auto *const tupleType = GetVRegType(objectReg)->AsETSTupleType(); SetVRegType(objectReg, tupleType->GetWrapperType()); @@ -3296,7 +3333,7 @@ bool ETSGen::ExtendWithFinalizer(ir::AstNode const *node, const ir::AstNode *ori util::StringView ETSGen::ToAssemblerType(const es2panda::checker::Type *type) const { - ES2PANDA_ASSERT(type->IsETSReferenceType()); + ES2PANDA_ASSERT(type != nullptr && type->IsETSReferenceType()); std::stringstream ss; type->ToAssemblerTypeWithRank(ss); diff --git a/ets2panda/compiler/core/ETSGen.h b/ets2panda/compiler/core/ETSGen.h index 6b3400e02c..7142782c56 100644 --- a/ets2panda/compiler/core/ETSGen.h +++ b/ets2panda/compiler/core/ETSGen.h @@ -298,7 +298,7 @@ public: bool IsDevirtualizedSignature(const checker::Signature *signature) { - ES2PANDA_ASSERT(!signature->HasSignatureFlag(checker::SignatureFlags::STATIC)); + ES2PANDA_ASSERT(signature != nullptr && !signature->HasSignatureFlag(checker::SignatureFlags::STATIC)); return signature->HasSignatureFlag(checker::SignatureFlags::FINAL | checker::SignatureFlags::PRIVATE | checker::SignatureFlags::CONSTRUCTOR); } @@ -435,6 +435,7 @@ public: if (isEtsPrimitive) { // NOTE: SzD. LoadStaticProperty if ETS stdlib has static TYPE constants otherwise fallback to LdaType } else { + ES2PANDA_ASSERT(GetAccumulatorType() != nullptr); auto classRef = GetAccumulatorType()->AsETSObjectType()->AssemblerName(); Sa().Emit(node, classRef); } diff --git a/ets2panda/compiler/core/function.cpp b/ets2panda/compiler/core/function.cpp index 685ed2c89e..e5c05ca78b 100644 --- a/ets2panda/compiler/core/function.cpp +++ b/ets2panda/compiler/core/function.cpp @@ -128,6 +128,7 @@ static void CompileFunctionParameterDeclaration(PandaGen *pg, const ir::ScriptFu void Function::LoadClassContexts(const ir::AstNode *node, PandaGen *pg, VReg ctor, const util::StringView &name) { auto *classDef = util::Helpers::GetContainingClassDefinition(node); + ES2PANDA_ASSERT(classDef != nullptr); do { auto res = pg->Scope()->Find(classDef->InternalName()); diff --git a/ets2panda/compiler/lowering/scopesInit/scopesInitPhase.cpp b/ets2panda/compiler/lowering/scopesInit/scopesInitPhase.cpp index 49bec80f6e..9ddc20f714 100644 --- a/ets2panda/compiler/lowering/scopesInit/scopesInitPhase.cpp +++ b/ets2panda/compiler/lowering/scopesInit/scopesInitPhase.cpp @@ -570,6 +570,7 @@ void ScopeInitTyped::VisitTSModuleDeclaration(ir::TSModuleDeclaration *moduleDec if (!moduleDecl->IsExternalOrAmbient()) { auto name = moduleDecl->Name()->AsIdentifier()->Name(); auto *decl = AddOrGetDecl(VarBinder(), name, moduleDecl, moduleDecl->Name()->Start(), name); + ES2PANDA_ASSERT(decl != nullptr); decl->BindNode(moduleDecl); } auto localCtx = LexicalScopeCreateOrEnter(VarBinder(), moduleDecl); @@ -631,6 +632,7 @@ void ScopeInitTyped::VisitTSInterfaceDeclaration(ir::TSInterfaceDeclaration *int auto localScope = LexicalScopeCreateOrEnter(VarBinder(), interfDecl); auto *identDecl = AddOrGetDecl(VarBinder(), ident->Name(), interfDecl, ident->Start(), ident->Name()); + ES2PANDA_ASSERT(identDecl != nullptr); identDecl->BindNode(interfDecl); BindScopeNode(localScope.GetScope(), interfDecl); @@ -769,6 +771,7 @@ void InitScopesPhaseTs::CreateFuncDecl(ir::ScriptFunction *func) decl = currentDecl->AsFunctionDecl(); } + ES2PANDA_ASSERT(decl != nullptr); decl->Add(func); } @@ -952,13 +955,14 @@ void AddOverload(ir::MethodDefinition *overload, varbinder::Variable *variable) { auto *currentNode = variable->Declaration()->Node(); currentNode->AsMethodDefinition()->AddOverload(overload); + ES2PANDA_ASSERT(overload->Id() != nullptr); overload->Id()->SetVariable(variable); overload->SetParent(currentNode); } void InitScopesPhaseETS::DeclareClassMethod(ir::MethodDefinition *method) { - ES2PANDA_ASSERT(VarBinder()->GetScope()->IsClassScope()); + ES2PANDA_ASSERT(VarBinder()->GetScope()->IsClassScope() && method->AsMethodDefinition()->Function() != nullptr); if ((method->AsMethodDefinition()->Function()->Flags() & ir::ScriptFunctionFlags::OVERLOAD) != 0) { return; @@ -1014,7 +1018,8 @@ void InitScopesPhaseETS::MaybeAddOverload(ir::MethodDefinition *method, ir::Iden if (methodName->Name().Is(compiler::Signatures::MAIN) && clsScope->Parent()->IsGlobalScope()) { LogDiagnostic(diagnostic::OVERLOADED_MAIN, methodName->Start()); } - ES2PANDA_ASSERT((method->Function()->Flags() & ir::ScriptFunctionFlags::OVERLOAD) == 0U); + ES2PANDA_ASSERT(method->Function() != nullptr && + (method->Function()->Flags() & ir::ScriptFunctionFlags::OVERLOAD) == 0U); AddOverload(method, found); method->Function()->AddFlag(ir::ScriptFunctionFlags::OVERLOAD); @@ -1088,6 +1093,7 @@ void InitScopesPhaseETS::VisitTSEnumMember(ir::TSEnumMember *enumMember) void InitScopesPhaseETS::VisitMethodDefinition(ir::MethodDefinition *method) { + ES2PANDA_ASSERT(method->Function() != nullptr); if (method->Function()->Scope() != nullptr) { return; } diff --git a/ets2panda/util/doubleLinkedList.h b/ets2panda/util/doubleLinkedList.h index a4d5a5a919..f2289bc185 100644 --- a/ets2panda/util/doubleLinkedList.h +++ b/ets2panda/util/doubleLinkedList.h @@ -54,6 +54,7 @@ public: Item *Append(const T &data) { auto item = allocator_->New(); + ES2PANDA_ASSERT(item != nullptr); item->data = data; Append(item); return item; @@ -77,6 +78,7 @@ public: Item *Prepend(const T &data) { auto item = allocator_->New(); + ES2PANDA_ASSERT(item != nullptr); item->data = data; Prepend(item); return item; @@ -100,6 +102,7 @@ public: Item *Insert(Item *after, const T &data) { auto item = allocator_->New(); + ES2PANDA_ASSERT(item != nullptr); item->data = data; Insert(after, item); return item; diff --git a/ets2panda/util/generateBin.cpp b/ets2panda/util/generateBin.cpp index 33abd21586..4c9f5220ea 100644 --- a/ets2panda/util/generateBin.cpp +++ b/ets2panda/util/generateBin.cpp @@ -82,6 +82,7 @@ static int GenerateProgramImpl(ark::pandasm::Program *prog, const util::Options std::cout << "Panda file size statistic:" << std::endl; constexpr std::array INFO_STATS = {"instructions_number", "codesize"}; + ES2PANDA_ASSERT(statp != nullptr); auto &stat = *statp; for (const auto &[name, size] : stat) { if (find(INFO_STATS.begin(), INFO_STATS.end(), name) != INFO_STATS.end()) { diff --git a/ets2panda/util/helpers.cpp b/ets2panda/util/helpers.cpp index 41e971809e..11228d33fe 100644 --- a/ets2panda/util/helpers.cpp +++ b/ets2panda/util/helpers.cpp @@ -766,6 +766,7 @@ bool Helpers::IsAsyncMethod(ir::AstNode const *node) return false; } auto *method = node->AsMethodDefinition(); + ES2PANDA_ASSERT(method->Function() != nullptr); return method->Function()->IsAsyncFunc() && !method->Function()->IsProxy(); } diff --git a/ets2panda/util/options.cpp b/ets2panda/util/options.cpp index 699c636e5b..82dc27f031 100644 --- a/ets2panda/util/options.cpp +++ b/ets2panda/util/options.cpp @@ -303,6 +303,7 @@ void Options::InitializeWarnings() {"subset_aware", {ETSWarnings::SUBSET_AWARE_FIRST, ETSWarnings::SUBSET_AWARE_LAST}}, {"subset_unaware", {ETSWarnings::SUBSET_UNAWARE_FIRST, ETSWarnings::SUBSET_UNAWARE_LAST}}}; const auto setWarningRange = [&warningSet, v](size_t first, size_t last) { + ES2PANDA_ASSERT(last < ETSWarnings::COUNT); for (size_t i = first; i <= last; i++) { warningSet[i] = v; } diff --git a/ets2panda/util/path.cpp b/ets2panda/util/path.cpp index 995424b524..ad902018c6 100644 --- a/ets2panda/util/path.cpp +++ b/ets2panda/util/path.cpp @@ -75,7 +75,7 @@ void Path::InitializeFileName() } } - int extensionPosition = fileNameWithExtension_.Mutf8().find_last_of('.'); + size_t extensionPosition = fileNameWithExtension_.Mutf8().find_last_of('.'); fileName_ = fileNameWithExtension_.Substr(0, extensionPosition); } @@ -85,7 +85,7 @@ void Path::InitializeFileNameWithExtension() return; } - int position = path_.Mutf8().find_last_of(PATH_DELIMITER); + size_t position = path_.Mutf8().find_last_of(PATH_DELIMITER); fileNameWithExtension_ = path_.Substr(position + 1, path_.Length()); } @@ -114,7 +114,7 @@ void Path::InitializeAbsoluteParentFolder() return; } - int position = absolutePath_.Mutf8().find_last_of(PATH_DELIMITER); + size_t position = absolutePath_.Mutf8().find_last_of(PATH_DELIMITER); absoluteParentFolder_ = absolutePath_.Substr(0, position); } @@ -125,7 +125,7 @@ void Path::InitializeParentFolder() return; } - int position = path_.Mutf8().find_last_of(PATH_DELIMITER); + size_t position = path_.Mutf8().find_last_of(PATH_DELIMITER); parentFolder_ = path_.Substr(0, position); } diff --git a/ets2panda/util/ustring.h b/ets2panda/util/ustring.h index be6a745d60..b9106cc62b 100644 --- a/ets2panda/util/ustring.h +++ b/ets2panda/util/ustring.h @@ -202,6 +202,7 @@ public: inline void Reset(size_t offset) { + ES2PANDA_ASSERT(sv_.begin() + offset <= sv_.end()); iter_ = sv_.begin() + offset; } @@ -360,6 +361,7 @@ private: void Alloc() { str_ = allocator_->New(allocator_->Adapter()); + ES2PANDA_ASSERT(str_ != nullptr); } protected: @@ -481,6 +483,7 @@ std::string StringView::EscapeSymbol() const template void StringView::Utf8Encode(T *str, char32_t cu) { + ES2PANDA_ASSERT(str != nullptr); if (cu < Constants::UTF8_1BYTE_LIMIT) { str->push_back(static_cast(cu)); } else if (cu < Constants::UTF8_2BYTE_LIMIT) { diff --git a/ets2panda/varbinder/ETSBinder.cpp b/ets2panda/varbinder/ETSBinder.cpp index 7b44def38d..27d9d01460 100644 --- a/ets2panda/varbinder/ETSBinder.cpp +++ b/ets2panda/varbinder/ETSBinder.cpp @@ -105,6 +105,7 @@ static void CreateDummyVariable(ETSBinder *varBinder, ir::Identifier *ident) void ETSBinder::LookupTypeReference(ir::Identifier *ident, bool allowDynamicNamespaces) { + ES2PANDA_ASSERT(ident != nullptr); if (ident->Variable() != nullptr && ident->Variable()->Declaration()->Node() == ident) { return; } @@ -258,6 +259,7 @@ void ETSBinder::LookupIdentReference(ir::Identifier *ident) if (res.level != 0) { ES2PANDA_ASSERT(res.variable != nullptr); + ES2PANDA_ASSERT(GetScope()->EnclosingVariableScope() != nullptr); auto *outerFunction = GetScope()->EnclosingVariableScope()->Node(); if ((!outerFunction->IsScriptFunction() || !outerFunction->AsScriptFunction()->IsArrow()) && @@ -361,6 +363,7 @@ void ETSBinder::ResolveInterfaceDeclaration(ir::TSInterfaceDeclaration *decl) ResolveReference(stmt); + ES2PANDA_ASSERT(stmt->AsClassProperty()->Id() != nullptr); auto fieldVar = ResolvePropertyReference(stmt->AsClassProperty(), decl->Scope()->AsClassScope()) ->FindLocal(stmt->AsClassProperty()->Id()->Name(), varbinder::ResolveBindingOptions::BINDINGS); @@ -394,6 +397,7 @@ void ETSBinder::BuildMethodDefinition(ir::MethodDefinition *methodDef) methodDef->BaseOverloadMethod()->GetTopStatement() != methodDef->GetTopStatement()) { return; } + ES2PANDA_ASSERT(methodDef->Function() != nullptr); if (methodDef->Function()->TypeParams() != nullptr) { auto scopeCtx = LexicalScope::Enter(this, methodDef->Function()->TypeParams()->Scope()); ResolveReferences(methodDef->Function()->TypeParams()); @@ -451,6 +455,7 @@ void ETSBinder::ResolveMethodDefinition(ir::MethodDefinition *methodDef) } auto *thisParam = AddMandatoryParam(MANDATORY_PARAM_THIS); + ES2PANDA_ASSERT(thisParam != nullptr); thisParam->Declaration()->BindNode(thisParam_); } @@ -510,6 +515,7 @@ void ETSBinder::BuildClassDefinitionImpl(ir::ClassDefinition *classDef) auto *const prop = stmt->AsClassProperty(); auto fieldScope = ResolvePropertyReference(prop, classDef->Scope()->AsClassScope()); + ES2PANDA_ASSERT(prop->Id() != nullptr); auto fieldName = prop->Id()->Name(); if (auto fieldVar = fieldScope->FindLocal(fieldName, varbinder::ResolveBindingOptions::BINDINGS); fieldVar != nullptr) { @@ -544,6 +550,7 @@ void ETSBinder::AddFunctionThisParam(ir::ScriptFunction *func) { auto paramScopeCtx = LexicalScope::Enter(this, func->Scope()->ParamScope()); auto *thisParam = AddMandatoryParam(MANDATORY_PARAM_THIS); + ES2PANDA_ASSERT(thisParam != nullptr); thisParam->Declaration()->BindNode(thisParam_); } @@ -555,7 +562,7 @@ void ETSBinder::AddDynamicImport(ir::ETSImportDeclaration *import) void ETSBinder::BuildProxyMethod(ir::ScriptFunction *func, const util::StringView &containingClassName, bool isExternal) { - ES2PANDA_ASSERT(!containingClassName.Empty()); + ES2PANDA_ASSERT(!containingClassName.Empty() && func != nullptr); func->Scope()->BindName(containingClassName); if (!func->IsAsyncFunc() && !isExternal) { @@ -641,6 +648,7 @@ void AddOverloadFlag(ArenaAllocator *allocator, bool isStdLib, varbinder::Variab return; } + ES2PANDA_ASSERT(method->Function() != nullptr); if (!method->Overloads().empty() && !method->HasOverload(currentNode)) { method->AddOverload(currentNode); currentNode->Function()->Id()->SetVariable(importedVar); @@ -1514,6 +1522,7 @@ void ETSBinder::ValidateReexportDeclaration(ir::ETSReExportDeclaration *decl) bool ETSBinder::ImportGlobalPropertiesForNotDefaultedExports(varbinder::Variable *var, const util::StringView &name, const ir::ClassElement *classElement) { + ES2PANDA_ASSERT(var != nullptr); if (var->Declaration()->Node()->IsDefaultExported()) { return false; } @@ -1554,7 +1563,7 @@ void ETSBinder::ImportGlobalProperties(const ir::ClassDefinition *const classDef continue; } - ES2PANDA_ASSERT(classElement->IsStatic()); + ES2PANDA_ASSERT(classElement->IsStatic() && classElement->Id() != nullptr); const auto &name = classElement->Id()->Name(); auto *const var = scopeCtx.GetScope()->FindLocal(name, ResolveBindingOptions::ALL); ES2PANDA_ASSERT(var != nullptr); diff --git a/ets2panda/varbinder/scope.cpp b/ets2panda/varbinder/scope.cpp index fb13142b90..3fb54162e2 100644 --- a/ets2panda/varbinder/scope.cpp +++ b/ets2panda/varbinder/scope.cpp @@ -429,6 +429,7 @@ Variable *ParamScope::AddParameter(ArenaAllocator *allocator, Decl *newDecl, Var ES2PANDA_ASSERT(newDecl->IsParameterDecl()); auto *param = allocator->New(newDecl, flags); + ES2PANDA_ASSERT(param != nullptr); param->SetScope(this); params_.emplace_back(param); @@ -492,13 +493,12 @@ Variable *AnnotationParamScope::AddBinding([[maybe_unused]] ArenaAllocator *allo [[maybe_unused]] ScriptExtension extension) { auto *ident = newDecl->Node()->AsClassProperty()->Id(); + ES2PANDA_ASSERT(ident != nullptr); auto annoVar = allocator->New(newDecl, VariableFlags::PROPERTY); auto var = InsertBinding(ident->Name(), annoVar).first->second; if (var != nullptr) { var->SetScope(this); - if (ident != nullptr) { - ident->SetVariable(var); - } + ident->SetVariable(var); } return var; } @@ -718,6 +718,7 @@ void ModuleScope::AddImportDecl(ir::ImportDeclaration *importDecl, ImportDeclLis void ModuleScope::AddExportDecl(ir::AstNode *exportDecl, ExportDecl *decl) { + ES2PANDA_ASSERT(decl != nullptr); decl->BindNode(exportDecl); ArenaVector decls(allocator_->Adapter()); @@ -747,6 +748,7 @@ Variable *ModuleScope::AddImport(ArenaAllocator *allocator, Variable *currentVar } auto *variable = allocator->New(newDecl, VariableFlags::NONE); + ES2PANDA_ASSERT(variable != nullptr); variable->ExoticName() = newDecl->AsImportDecl()->ImportName(); InsertBinding(newDecl->Name(), variable); return variable; @@ -1007,6 +1009,7 @@ void LoopDeclarationScope::ConvertToVariableScope(ArenaAllocator *allocator) if (loopType_ == ScopeType::LOOP_DECL) { auto *parentVarScope = Parent()->EnclosingVariableScope(); + ES2PANDA_ASSERT(parentVarScope != nullptr); slotIndex_ = std::max(slotIndex_, parentVarScope->LexicalSlots()); evalBindings_ = parentVarScope->EvalBindings(); initScope_ = allocator->New(allocator, Parent()); -- Gitee