diff --git a/ets2panda/compiler/core/ETSGen.cpp b/ets2panda/compiler/core/ETSGen.cpp index 4e62393a954b62facfe7f9675d6a93d5568f3c26..64969cbd232c5fbc3cc3c52d7dbd0b619e6ddd66 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 6707dcca73a6e12333960659e066c0a7727448d2..1fd7c62350a7dbec13b460a52de453213e7c3426 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 685ed2c89e3d19387ddcb9d0098f965e7fa3ef5d..e5c05ca78bfe3d808b61f171bb5099dc07e970d8 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 c5a51475aef146d5dd423816926f093f5f055521..780c1346a8de45da66b1ccd3040cffeef8875a04 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 a4d5a5a9197a794011563ddf8f266196f9bd6b98..f2289bc185167f9b3e7da6a861b6d6ce45be3f36 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 442bd41bc4ffd105a7a021fcdbe295e986c4faa3..134b2c9511a761a51fa5f546e98cd90d932f6c1a 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 9bde843fb28a80800f05f813e8606e78d13f4a23..acc599db41253d022ca824aac3c52516dafe5ebe 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 f3e1ea181fd670b6c610c5e7a05d9ed8cc0637bb..e2818c61a220a59f42bc3959d0a0926e6f4043a3 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 995424b52469d9bf82322cad60fed00adc5568df..ad902018c64df5ef51b052c237b756f65fa16083 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 be6a745d60eeb58ac60b8e767f1bb344cc9cf59f..b9106cc62b8ab5f26d9590eaea6d3be788d3f6a9 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 ce4d9475a3d4c5fa6e4ce822388bc4fac3dc07ab..f59a8972b758ab235056412eb339d12c2fc39d5a 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 f6888b5055bef81b8600af89cbb2bb719e29402f..4b20637e6603a8bf74aaf6660c8a0668ba1047e1 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());