From 6e85e5788373aa90214d959eeffc4ca9f933f624 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/ICIYVN Signed-off-by: Zhelyapov Aleksey --- ets2panda/compiler/core/ETSGen.cpp | 33 ++++++++++++++++--- 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, 70 insertions(+), 16 deletions(-) diff --git a/ets2panda/compiler/core/ETSGen.cpp b/ets2panda/compiler/core/ETSGen.cpp index 4e62393a95..64969cbd23 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); @@ -247,6 +249,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; @@ -298,6 +301,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); } @@ -345,6 +349,7 @@ static bool StaticAccessRequiresReferenceSafetyCheck(const ir::AstNode *const no 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); if (StaticAccessRequiresReferenceSafetyCheck(node, propType)) { @@ -362,6 +367,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); @@ -574,6 +580,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); @@ -586,6 +593,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(); } @@ -663,7 +671,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); @@ -731,6 +739,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); @@ -1470,6 +1479,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()) { @@ -1534,6 +1544,7 @@ void ETSGen::ResolveConditionalResultReference(const ir::AstNode *node) }; auto type = GetAccumulatorType(); + ES2PANDA_ASSERT(type != nullptr); if (!type->PossiblyETSString()) { Sa().Emit(node, 1); return; @@ -1548,6 +1559,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); @@ -1563,6 +1575,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(); @@ -1625,6 +1638,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); @@ -1643,6 +1657,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(); @@ -1682,6 +1697,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 @@ -1724,6 +1740,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)); @@ -1904,6 +1921,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); } @@ -1940,6 +1958,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()) { @@ -2014,6 +2033,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->DefinitelyETSNullish() || rtype->DefinitelyETSNullish()) { HandleDefinitelyNullishEquality(node, lhs, rhs, ifFalse); } else if (auto spec = SelectLooseObjComparator( // try to select specific type @@ -2177,6 +2197,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); @@ -2212,6 +2233,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); @@ -2297,6 +2319,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(); @@ -2449,6 +2472,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); @@ -2462,6 +2486,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); @@ -2558,7 +2583,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)); @@ -2570,7 +2595,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()); @@ -2708,7 +2733,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 6707dcca73..1fd7c62350 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); } @@ -456,6 +456,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 c5a51475ae..780c1346a8 100644 --- a/ets2panda/compiler/lowering/scopesInit/scopesInitPhase.cpp +++ b/ets2panda/compiler/lowering/scopesInit/scopesInitPhase.cpp @@ -582,6 +582,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); @@ -643,6 +644,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); @@ -786,6 +788,7 @@ void InitScopesPhaseTs::CreateFuncDecl(ir::ScriptFunction *func) decl = currentDecl->AsFunctionDecl(); } + ES2PANDA_ASSERT(decl != nullptr); decl->Add(func); } @@ -972,13 +975,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; @@ -1034,7 +1038,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); @@ -1198,6 +1203,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 442bd41bc4..134b2c9511 100644 --- a/ets2panda/util/generateBin.cpp +++ b/ets2panda/util/generateBin.cpp @@ -83,6 +83,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 9bde843fb2..acc599db41 100644 --- a/ets2panda/util/helpers.cpp +++ b/ets2panda/util/helpers.cpp @@ -820,6 +820,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 f3e1ea181f..e2818c61a2 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 ce4d9475a3..f59a8972b7 100644 --- a/ets2panda/varbinder/ETSBinder.cpp +++ b/ets2panda/varbinder/ETSBinder.cpp @@ -91,6 +91,7 @@ static void CreateDummyVariable(ETSBinder *varBinder, ir::Identifier *ident) void ETSBinder::LookupTypeReference(ir::Identifier *ident) { + ES2PANDA_ASSERT(ident != nullptr); if (ident->Variable() != nullptr && ident->Variable()->Declaration()->Node() == ident) { return; } @@ -237,6 +238,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()) && @@ -339,6 +341,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); @@ -372,6 +375,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()); @@ -429,6 +433,7 @@ void ETSBinder::ResolveMethodDefinition(ir::MethodDefinition *methodDef) } auto *thisParam = AddMandatoryParam(MANDATORY_PARAM_THIS); + ES2PANDA_ASSERT(thisParam != nullptr); thisParam->Declaration()->BindNode(thisParam_); } @@ -493,6 +498,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) { @@ -527,6 +533,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_); } @@ -538,7 +545,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) { @@ -587,6 +594,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); @@ -1469,6 +1477,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; } @@ -1509,7 +1518,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 f6888b5055..4b20637e66 100644 --- a/ets2panda/varbinder/scope.cpp +++ b/ets2panda/varbinder/scope.cpp @@ -432,6 +432,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); @@ -495,13 +496,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; } @@ -721,6 +721,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()); @@ -750,6 +751,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; @@ -1010,6 +1012,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