From 92e9d90f6639169c94556770170a8524375dc752 Mon Sep 17 00:00:00 2001 From: yp9522 Date: Thu, 10 Jul 2025 20:46:34 +0800 Subject: [PATCH] 0328-fix-alert Signed-off-by: yp9522 --- ets2panda/checker/ETSAnalyzer.cpp | 7 ++++ ets2panda/checker/TSAnalyzer.cpp | 4 ++- ets2panda/checker/ets/aliveAnalyzer.cpp | 4 ++- ets2panda/checker/ets/function.cpp | 1 + ets2panda/checker/ets/helpers.cpp | 1 + ets2panda/checker/ets/utilityTypeHandlers.cpp | 4 ++- ets2panda/checker/ts/destructuringContext.cpp | 1 + ets2panda/checker/types/typeRelation.cpp | 1 + ets2panda/parser/ASparser.cpp | 3 ++ ets2panda/parser/ETSparser.cpp | 7 ++++ ets2panda/parser/ETSparserAnnotations.cpp | 1 + ets2panda/parser/ETSparserClasses.cpp | 32 +++++++++++++------ ets2panda/parser/ETSparserExpressions.cpp | 6 +++- ets2panda/parser/ETSparserNamespaces.cpp | 1 + ets2panda/parser/ETSparserTypes.cpp | 1 + ets2panda/parser/TSparser.cpp | 4 ++- ets2panda/parser/expressionParser.cpp | 5 ++- ets2panda/parser/parserImpl.cpp | 6 +++- ets2panda/parser/statementParser.cpp | 9 ++++++ ets2panda/parser/statementTSParser.cpp | 1 + 20 files changed, 82 insertions(+), 17 deletions(-) diff --git a/ets2panda/checker/ETSAnalyzer.cpp b/ets2panda/checker/ETSAnalyzer.cpp index 1fec1bafe8..8dc1ae46e3 100644 --- a/ets2panda/checker/ETSAnalyzer.cpp +++ b/ets2panda/checker/ETSAnalyzer.cpp @@ -462,6 +462,7 @@ checker::Type *ETSAnalyzer::Check(ir::ETSFunctionType *node) const checker->CheckFunctionSignatureAnnotations(node->Params(), node->TypeParams(), node->ReturnType()); auto *signatureInfo = checker->ComposeSignatureInfo(node->TypeParams(), node->Params()); + ES2PANDA_ASSERT(signatureInfo != nullptr); auto *returnType = node->IsExtensionFunction() && node->ReturnType()->IsTSThisType() ? signatureInfo->params.front()->TsType() : checker->ComposeReturnType(node->ReturnType(), node->IsAsync()); @@ -1862,6 +1863,7 @@ checker::Type *ETSAnalyzer::Check(ir::Identifier *expr) const } expr->SetTsType(identType); + ES2PANDA_ASSERT(identType != nullptr); if (!identType->IsTypeError()) { checker->Context().CheckIdentifierSmartCastCondition(expr); } @@ -1976,6 +1978,7 @@ checker::Type *ETSAnalyzer::Check(ir::MemberExpression *expr) const auto *baseType = checker->GetNonConstantType(checker->GetApparentType(expr->Object()->Check(checker))); // Note: don't use possible smart cast to null-like types. // Such situation should be correctly resolved in the subsequent lowering. + ES2PANDA_ASSERT(baseType != nullptr); if (baseType->DefinitelyETSNullish() && expr->Object()->IsIdentifier()) { baseType = expr->Object()->AsIdentifier()->Variable()->TsType(); } @@ -2677,6 +2680,7 @@ static checker::Type *ComputeTypeOfType(ETSChecker *checker, checker::Type *argT { checker::Type *ret = nullptr; ArenaVector types(checker->ProgramAllocator()->Adapter()); + ES2PANDA_ASSERT(argType != nullptr); if (argType->IsETSUnionType()) { for (auto *it : argType->AsETSUnionType()->ConstituentTypes()) { checker::Type *elType = ComputeTypeOfType(checker, it); @@ -2718,6 +2722,7 @@ checker::Type *ETSAnalyzer::Check(ir::UnaryExpression *expr) const checker::Type *type = checker->CreateETSBigIntLiteralType(argType->AsETSBigIntType()->GetValue()); // We do not need this const anymore as we are negating the bigint object in runtime + ES2PANDA_ASSERT(type != nullptr); type->RemoveTypeFlag(checker::TypeFlag::CONSTANT); expr->argument_->SetTsType(type); expr->SetTsType(type); @@ -3113,6 +3118,7 @@ checker::Type *ETSAnalyzer::Check(ir::AnnotationUsage *st) const ArenaUnorderedMap fieldMap {checker->ProgramAllocator()->Adapter()}; for (auto *it : annoDecl->Properties()) { auto *field = it->AsClassProperty(); + ES2PANDA_ASSERT(field->Id() != nullptr); fieldMap.insert(std::make_pair(field->Id()->Name(), field)); } @@ -3700,6 +3706,7 @@ checker::Type *ETSAnalyzer::Check(ir::TSAsExpression *expr) const checker->CheckAnnotations(expr->TypeAnnotation()->Annotations()); auto *const targetType = expr->TypeAnnotation()->AsTypeNode()->GetType(checker); + ES2PANDA_ASSERT(targetType != nullptr); if (targetType->IsTypeError()) { return checker->InvalidateType(expr); } diff --git a/ets2panda/checker/TSAnalyzer.cpp b/ets2panda/checker/TSAnalyzer.cpp index 44d5a3d824..655c154d5f 100644 --- a/ets2panda/checker/TSAnalyzer.cpp +++ b/ets2panda/checker/TSAnalyzer.cpp @@ -802,7 +802,7 @@ void TSAnalyzer::CheckNonComputed(checker::ObjectDescriptor *desc, ir::Expressio if (prop->Key()->IsNumberLiteral()) { memberVar->AddFlag(varbinder::VariableFlags::NUMERIC_NAME); } - + ES2PANDA_ASSERT(desc != nullptr); varbinder::LocalVariable *foundMember = desc->FindProperty(propName); allPropertiesMap.insert({propName, it->Start()}); @@ -1740,6 +1740,7 @@ static void AddEnumValueDeclaration(checker::TSChecker *checker, double number, enumScope->AddDecl(checker->Allocator(), decl, ScriptExtension::TS); res = enumScope->FindLocal(memberStr, varbinder::ResolveBindingOptions::BINDINGS); ES2PANDA_ASSERT(res && res->IsEnumVariable()); + ES2PANDA_ASSERT(enumVar != nullptr); enumVar = res->AsEnumVariable(); enumVar->AsEnumVariable()->SetBackReference(); enumVar->SetTsType(checker->GlobalStringType()); @@ -1747,6 +1748,7 @@ static void AddEnumValueDeclaration(checker::TSChecker *checker, double number, ES2PANDA_ASSERT(res->IsEnumVariable()); enumVar = res->AsEnumVariable(); auto *decl = checker->Allocator()->New(memberStr); + ES2PANDA_ASSERT(decl != nullptr); decl->BindNode(variable->Declaration()->Node()); enumVar->ResetDecl(decl); } diff --git a/ets2panda/checker/ets/aliveAnalyzer.cpp b/ets2panda/checker/ets/aliveAnalyzer.cpp index 13abe6b9ca..e4edb04a7a 100644 --- a/ets2panda/checker/ets/aliveAnalyzer.cpp +++ b/ets2panda/checker/ets/aliveAnalyzer.cpp @@ -243,7 +243,9 @@ void AliveAnalyzer::AnalyzeMethodDef(const ir::MethodDefinition *methodDef) status_ = LivenessStatus::ALIVE; AnalyzeStat(func->Body()); ES2PANDA_ASSERT(methodDef->TsType() && methodDef->TsType()->IsETSFunctionType()); - const auto *returnType = methodDef->TsType()->AsETSFunctionType()->FindSignature(func)->ReturnType(); + const auto *signature = methodDef->TsType()->AsETSFunctionType()->FindSignature(func); + ES2PANDA_ASSERT(signature != nullptr); + const auto *returnType = signature->ReturnType(); const auto isVoid = returnType->IsETSVoidType() || returnType == checker_->GlobalVoidType(); auto isPromiseVoid = false; diff --git a/ets2panda/checker/ets/function.cpp b/ets2panda/checker/ets/function.cpp index 5c22183d03..d7fea93106 100644 --- a/ets2panda/checker/ets/function.cpp +++ b/ets2panda/checker/ets/function.cpp @@ -1633,6 +1633,7 @@ SignatureInfo *ETSChecker::ComposeSignatureInfo(ir::TSTypeParameterDeclaration * ES2PANDA_ASSERT(IsAnyError()); // #23134 return nullptr; } + ES2PANDA_ASSERT(restParamType != nullptr); if (!restParamType->IsETSTupleType() && !restParamType->IsETSArrayType() && !restParamType->IsETSResizableArrayType()) { LogError(diagnostic::ONLY_ARRAY_OR_TUPLE_FOR_REST, {}, param->Start()); diff --git a/ets2panda/checker/ets/helpers.cpp b/ets2panda/checker/ets/helpers.cpp index 3a2652b5c4..8aaf9e1b1f 100644 --- a/ets2panda/checker/ets/helpers.cpp +++ b/ets2panda/checker/ets/helpers.cpp @@ -625,6 +625,7 @@ void ETSChecker::InferAliasLambdaType(ir::TypeNode *localTypeAnnotation, ir::Arr checker::Type *ETSChecker::FixOptionalVariableType(varbinder::Variable *const bindingVar, ir::ModifierFlags flags) { if ((flags & ir::ModifierFlags::OPTIONAL) != 0) { + ES2PANDA_ASSERT(bindingVar != nullptr); auto *variableType = bindingVar->TsType() != nullptr ? bindingVar->TsType() : GlobalTypeError(); bindingVar->SetTsType( !variableType->IsTypeError() ? CreateETSUnionType({GlobalETSUndefinedType(), variableType}) : variableType); diff --git a/ets2panda/checker/ets/utilityTypeHandlers.cpp b/ets2panda/checker/ets/utilityTypeHandlers.cpp index 0c9e1114a7..ede1e26906 100644 --- a/ets2panda/checker/ets/utilityTypeHandlers.cpp +++ b/ets2panda/checker/ets/utilityTypeHandlers.cpp @@ -249,10 +249,11 @@ ir::ClassProperty *ETSChecker::CreateNullishPropertyFromAccessor(ir::MethodDefin auto *prop = // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) ProgramAllocator()->New(ident, nullptr, nullptr, modifierFlag, ProgramAllocator(), false); - + ES2PANDA_ASSERT(prop != nullptr); prop->SetParent(newClassDefinition); ident->SetParent(prop); + ES2PANDA_ASSERT(accessor->Function() != nullptr); prop->SetTypeAnnotation(accessor->Function()->IsGetter() ? accessor->Function()->ReturnTypeAnnotation() : accessor->Function()->Params()[0]->AsETSParameterExpression()->TypeAnnotation()); @@ -268,6 +269,7 @@ ir::ClassProperty *ETSChecker::CreateNullishPropertyFromAccessor(ir::MethodDefin auto callSign = accessor->TsType()->AsETSFunctionType()->CallSignatures()[0]; + ES2PANDA_ASSERT(accessor->Function() != nullptr); auto tsType = accessor->Function()->IsGetter() ? callSign->ReturnType() : callSign->Params()[0]->TsType(); // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) diff --git a/ets2panda/checker/ts/destructuringContext.cpp b/ets2panda/checker/ts/destructuringContext.cpp index 62212a8fca..b3f516e2b8 100644 --- a/ets2panda/checker/ts/destructuringContext.cpp +++ b/ets2panda/checker/ts/destructuringContext.cpp @@ -332,6 +332,7 @@ Type *ArrayDestructuringContext::CreateTupleTypeForRest(TupleType *tuple) ES2PANDA_ASSERT(memberVar != nullptr); memberVar->SetTsType(tupleElementType); elementFlags.push_back(memberFlag); + ES2PANDA_ASSERT(desc != nullptr); desc->properties.push_back(memberVar); index_++; diff --git a/ets2panda/checker/types/typeRelation.cpp b/ets2panda/checker/types/typeRelation.cpp index d6de755722..67ba7f0312 100644 --- a/ets2panda/checker/types/typeRelation.cpp +++ b/ets2panda/checker/types/typeRelation.cpp @@ -161,6 +161,7 @@ bool TypeRelation::IsComparableTo(Type *source, Type *target) result_ = RelationResult::FALSE; target->Compare(this, source); + ES2PANDA_ASSERT(source != nullptr); auto key = RelationHolder::MakeKey(source->Id(), target->Id()); checker_->ComparableResults().Insert(key, {result_, RelationType::COMPARABLE}); } diff --git a/ets2panda/parser/ASparser.cpp b/ets2panda/parser/ASparser.cpp index f2567fef3d..2e0e102951 100644 --- a/ets2panda/parser/ASparser.cpp +++ b/ets2panda/parser/ASparser.cpp @@ -1122,6 +1122,7 @@ ArenaVector ASParser::ParseClassImplementClause() const lexer::SourcePosition &implementStart = Lexer()->GetToken().Start(); auto *implementsName = AllocNode(Lexer()->GetToken().Ident(), Allocator()); + ES2PANDA_ASSERT(implementsName != nullptr); implementsName->SetRange(Lexer()->GetToken().Loc()); auto *implementsClause = AllocNode(implementsName, Allocator()); ES2PANDA_ASSERT(implementsClause != nullptr); @@ -1137,6 +1138,7 @@ ArenaVector ASParser::ParseClassImplementClause() } implementsName = AllocNode(Lexer()->GetToken().Ident(), Allocator()); + ES2PANDA_ASSERT(implementsName != nullptr); implementsName->SetRange(Lexer()->GetToken().Loc()); auto *next = AllocNode(implementsName, Allocator()); current->SetRange(Lexer()->GetToken().Loc()); @@ -1740,6 +1742,7 @@ ir::Statement *ASParser::ParseImportDeclaration([[maybe_unused]] StatementParsin source = ParseFromClause(false); } + ES2PANDA_ASSERT(source != nullptr); lexer::SourcePosition endLoc = source->End(); auto *importDeclaration = AllocNode(source, std::move(specifiers)); ES2PANDA_ASSERT(importDeclaration != nullptr); diff --git a/ets2panda/parser/ETSparser.cpp b/ets2panda/parser/ETSparser.cpp index 9788c8d7af..75f5f6dafc 100644 --- a/ets2panda/parser/ETSparser.cpp +++ b/ets2panda/parser/ETSparser.cpp @@ -1025,6 +1025,7 @@ ir::TypeNode *ETSParser::ParseTypeReference(TypeAnnotationParsingOptions *option } typeRefPart = AllocNode(typeName, typeParams, typeRefPart, Allocator()); + ES2PANDA_ASSERT(typeRefPart != nullptr); typeRefPart->SetRange({partPos, Lexer()->GetToken().End()}); if (!Lexer()->TryEatTokenType(lexer::TokenType::PUNCTUATOR_PERIOD)) { @@ -1117,6 +1118,7 @@ ir::Statement *ETSParser::CreateReExportDeclarationNode(ir::ETSImportDeclaration } auto reExport = AllocNode(reExportDeclaration, std::vector(), GetProgram()->AbsoluteName(), Allocator()); + ES2PANDA_ASSERT(reExport != nullptr); reExport->AddModifier(modifiers); return reExport; } @@ -1221,6 +1223,7 @@ ir::ETSImportDeclaration *ETSParser::ParseImportPathBuildImport(ArenaVector(ERROR_LITERAL); + ES2PANDA_ASSERT(errorLiteral != nullptr); errorLiteral->SetRange(Lexer()->GetToken().Loc()); auto *const importDeclaration = AllocNode( errorLiteral, util::ImportPathManager::ImportMetadata {}, std::move(specifiers), importKind); @@ -1310,6 +1313,7 @@ ArenaVector ETSParser::ParseImportDeclarations() auto pos = Lexer()->Save(); if (!specifiers.empty()) { auto *const importDecl = ParseImportPathBuildImport(std::move(specifiers), true, startLoc, importKind); + ES2PANDA_ASSERT(importDecl != nullptr); statements.push_back(importDecl->AsETSImportDeclaration()); } @@ -1603,6 +1607,7 @@ ir::AnnotatedExpression *ETSParser::GetAnnotatedExpressionFromParam() switch (Lexer()->GetToken().Type()) { case lexer::TokenType::LITERAL_IDENT: { parameter = AllocNode(Lexer()->GetToken().Ident(), Allocator()); + ES2PANDA_ASSERT(parameter != nullptr); if (parameter->AsIdentifier()->Decorators().empty()) { parameter->SetRange(Lexer()->GetToken().Loc()); } else { @@ -1625,6 +1630,7 @@ ir::AnnotatedExpression *ETSParser::GetAnnotatedExpressionFromParam() restIdent->SetRange(Lexer()->GetToken().Loc()); parameter = AllocNode(ir::AstNodeType::REST_ELEMENT, Allocator(), restIdent); + ES2PANDA_ASSERT(parameter != nullptr); parameter->SetRange({startLoc, Lexer()->GetToken().End()}); break; } @@ -2319,6 +2325,7 @@ ir::FunctionDeclaration *ETSParser::ParseFunctionDeclaration(bool canBeAnonymous Lexer()->NextToken(); } + ES2PANDA_ASSERT(funcDecl != nullptr); funcDecl->SetRange(func->Range()); func->AddModifier(modifiers); func->SetStart(startLoc); diff --git a/ets2panda/parser/ETSparserAnnotations.cpp b/ets2panda/parser/ETSparserAnnotations.cpp index 1194431c69..2f904b8f63 100644 --- a/ets2panda/parser/ETSparserAnnotations.cpp +++ b/ets2panda/parser/ETSparserAnnotations.cpp @@ -392,6 +392,7 @@ ir::AnnotationUsage *ETSParser::ParseAnnotationUsage() } else if (Lexer()->GetToken().Type() != lexer::TokenType::PUNCTUATOR_RIGHT_PARENTHESIS) { // handle single field annotation auto *singleParamName = AllocNode(compiler::Signatures::ANNOTATION_KEY_VALUE, Allocator()); + ES2PANDA_ASSERT(singleParamName != nullptr); singleParamName->SetRange({Lexer()->GetToken().Start(), Lexer()->GetToken().End()}); const auto savePos = Lexer()->GetToken().Start(); diff --git a/ets2panda/parser/ETSparserClasses.cpp b/ets2panda/parser/ETSparserClasses.cpp index d682190205..0ae2994d4f 100644 --- a/ets2panda/parser/ETSparserClasses.cpp +++ b/ets2panda/parser/ETSparserClasses.cpp @@ -421,6 +421,7 @@ ir::TypeNode *ETSParser::ConvertToOptionalUnionType(ir::TypeNode *typeAnno) types.push_back(AllocNode(Allocator())); types.back()->SetRange(typeAnno->Range()); auto *newTypeAnno = AllocNode(std::move(types), Allocator()); + ES2PANDA_ASSERT(newTypeAnno != nullptr); newTypeAnno->SetRange(typeAnno->Range()); return newTypeAnno; } @@ -596,6 +597,7 @@ ir::MethodDefinition *ETSParser::ParseClassMethodDefinition(ir::Identifier *meth funcExpr->SetRange(func->Range()); func->AddModifier(modifiers); + ES2PANDA_ASSERT(methodName->Clone(Allocator(), nullptr) != nullptr); auto *method = AllocNode(methodKind, methodName->Clone(Allocator(), nullptr)->AsExpression(), funcExpr, modifiers, Allocator(), false); ES2PANDA_ASSERT(method != nullptr); @@ -634,6 +636,7 @@ ir::MethodDefinition *ETSParser::ParseClassMethod(ClassElementDescriptor *desc, auto *method = AllocNode(desc->methodKind, propName->Clone(Allocator(), nullptr)->AsExpression(), funcExpr, desc->modifiers, Allocator(), desc->isComputed); + ES2PANDA_ASSERT(method != nullptr); method->SetRange(funcExpr->Range()); return method; @@ -841,13 +844,16 @@ ir::MethodDefinition *ETSParser::ParseClassGetterSetterMethod(const ArenaVector< lexer::SourcePosition propEnd = methodName->End(); ir::MethodDefinition *method = ParseClassMethod(&desc, properties, methodName, &propEnd); + ES2PANDA_ASSERT(method != nullptr); method->SetDefaultAccessModifier(isDefault); - method->Function()->AddModifier(desc.modifiers); + auto *func = method->Function(); + ES2PANDA_ASSERT(func != nullptr); + func->AddModifier(desc.modifiers); method->SetRange({desc.propStart, propEnd}); if (desc.methodKind == ir::MethodDefinitionKind::GET) { - method->Function()->AddFlag(ir::ScriptFunctionFlags::GETTER); + func->AddFlag(ir::ScriptFunctionFlags::GETTER); } else { - method->Function()->AddFlag(ir::ScriptFunctionFlags::SETTER); + func->AddFlag(ir::ScriptFunctionFlags::SETTER); } return method; @@ -864,23 +870,25 @@ ir::MethodDefinition *ETSParser::ParseInterfaceGetterSetterMethod(const ir::Modi return nullptr; } method->AddModifier(ir::ModifierFlags::PUBLIC); - auto id = method->Id(); + auto *id = method->Id(); + auto *func = method->Function(); ES2PANDA_ASSERT(id != nullptr); + ES2PANDA_ASSERT(func != nullptr); if (methodKind == ir::MethodDefinitionKind::GET) { id->SetAccessor(); - method->Function()->AddFlag(ir::ScriptFunctionFlags::GETTER); + func->AddFlag(ir::ScriptFunctionFlags::GETTER); } else { id->SetMutator(); - method->Function()->AddFlag(ir::ScriptFunctionFlags::SETTER); + func->AddFlag(ir::ScriptFunctionFlags::SETTER); } method->AddModifier(ir::ModifierFlags::PUBLIC); - method->Function()->SetIdent(id->Clone(Allocator(), nullptr)); - method->Function()->AddModifier(method->Modifiers()); + func->SetIdent(id->Clone(Allocator(), nullptr)); + func->AddModifier(method->Modifiers()); - bool hasReturn = method->Function()->ReturnTypeAnnotation() != nullptr; + bool hasReturn = func->ReturnTypeAnnotation() != nullptr; if (hasReturn && methodKind == ir::MethodDefinitionKind::SET) { - LogError(diagnostic::SETTER_NO_RETURN_TYPE, {}, method->Function()->Range().start); + LogError(diagnostic::SETTER_NO_RETURN_TYPE, {}, func->Range().start); } return method; @@ -1109,6 +1117,7 @@ ir::AstNode *ETSParser::ParseInterfaceField() return AllocBrokenExpression(Lexer()->GetToken().Start()); } + ES2PANDA_ASSERT(name != nullptr); name->SetRange(Lexer()->GetToken().Loc()); Lexer()->NextToken(); bool optionalField = false; @@ -1178,6 +1187,7 @@ ir::MethodDefinition *ETSParser::ParseInterfaceMethod(ir::ModifierFlags flags, i name = AllocBrokenExpression(Lexer()->GetToken().Loc()); } else { name = AllocNode(Lexer()->GetToken().Ident(), Allocator()); + ES2PANDA_ASSERT(name != nullptr); name->SetRange(Lexer()->GetToken().Loc()); Lexer()->NextToken(); } @@ -1226,8 +1236,10 @@ ir::MethodDefinition *ETSParser::ParseInterfaceMethod(ir::ModifierFlags flags, i func->AddFlag(ir::ScriptFunctionFlags::METHOD); func->SetIdent(name); + ES2PANDA_ASSERT(name->Clone(Allocator(), nullptr) != nullptr); auto *method = AllocNode(methodKind, name->Clone(Allocator(), nullptr)->AsExpression(), funcExpr, flags, Allocator(), false); + ES2PANDA_ASSERT(method != nullptr); method->SetRange(funcExpr->Range()); ConsumeSemicolon(method); diff --git a/ets2panda/parser/ETSparserExpressions.cpp b/ets2panda/parser/ETSparserExpressions.cpp index d07eb07208..707d44ad1b 100644 --- a/ets2panda/parser/ETSparserExpressions.cpp +++ b/ets2panda/parser/ETSparserExpressions.cpp @@ -41,11 +41,11 @@ static std::string GetArgumentsSourceView(lexer::Lexer *lexer, const util::Strin ir::Expression *ETSParser::ParseFunctionParameterExpression(ir::AnnotatedExpression *const paramIdent, bool isOptional) { ir::ETSParameterExpression *paramExpression; + ES2PANDA_ASSERT(paramIdent != nullptr); if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_SUBSTITUTION) { auto const lexerPos = Lexer()->Save().Iterator(); Lexer()->NextToken(); // eat '=' - ES2PANDA_ASSERT(paramIdent != nullptr); if (paramIdent->IsRestElement()) { LogError(diagnostic::NO_DEFAULT_FOR_REST); } @@ -76,9 +76,11 @@ ir::Expression *ETSParser::ParseFunctionParameterExpression(ir::AnnotatedExpress paramExpression->SetRange({paramIdent->Start(), paramExpression->Initializer()->End()}); } else if (paramIdent->IsIdentifier()) { paramExpression = AllocNode(paramIdent->AsIdentifier(), isOptional, Allocator()); + ES2PANDA_ASSERT(paramExpression != nullptr); paramExpression->SetRange({paramIdent->Start(), paramIdent->End()}); } else { paramExpression = AllocNode(paramIdent->AsRestElement(), false, Allocator()); + ES2PANDA_ASSERT(paramExpression != nullptr); paramExpression->SetRange({paramIdent->Start(), paramIdent->End()}); } return paramExpression; @@ -181,6 +183,7 @@ ir::Expression *ETSParser::ParseUnaryOrPrefixUpdateExpression(ExpressionParseFla } ir::Expression *returnExpr = CreateUnaryExpressionFromArgument(argument, operatorType, beginningChar); + ES2PANDA_ASSERT(returnExpr != nullptr); returnExpr->SetRange({start, argument->End()}); return returnExpr; } @@ -218,6 +221,7 @@ ir::Expression *ETSParser::ParsePropertyDefinition(ExpressionParseFlags flags) if (propertyKind == ir::PropertyKind::INIT) { returnProperty = AllocNode(propertyKind, key, value, methodStatus != ParserStatus::NO_OPTS, isComputed); + ES2PANDA_ASSERT(returnProperty != nullptr); returnProperty->SetRange({start, end}); } else { returnProperty = AllocBrokenExpression(key->Start()); diff --git a/ets2panda/parser/ETSparserNamespaces.cpp b/ets2panda/parser/ETSparserNamespaces.cpp index d3ecaeedf6..9360e2431f 100644 --- a/ets2panda/parser/ETSparserNamespaces.cpp +++ b/ets2panda/parser/ETSparserNamespaces.cpp @@ -70,6 +70,7 @@ ir::ETSModule *ETSParser::ParseNamespaceImp(ir::ModifierFlags flags) Lexer()->NextToken(); auto *result = AllocNode(Allocator(), ArenaVector(Allocator()->Adapter()), ExpectIdentifier(), ir::ModuleFlag::NAMESPACE, globalProgram_); + ES2PANDA_ASSERT(result != nullptr); ir::ETSModule *parent = result; ir::ETSModule *child = nullptr; while (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_PERIOD) { diff --git a/ets2panda/parser/ETSparserTypes.cpp b/ets2panda/parser/ETSparserTypes.cpp index 44e5712193..918223fb9d 100644 --- a/ets2panda/parser/ETSparserTypes.cpp +++ b/ets2panda/parser/ETSparserTypes.cpp @@ -178,6 +178,7 @@ ir::TypeNode *ETSParser::ParseWildcardType(TypeAnnotationParsingOptions *options ir::ETSTypeReference *typeReference = nullptr; if (!isUnboundOut) { auto reference = ParseTypeReference(options); + ES2PANDA_ASSERT(reference != nullptr); typeReference = reference->AsETSTypeReference(); } diff --git a/ets2panda/parser/TSparser.cpp b/ets2panda/parser/TSparser.cpp index d2545ce425..4c41a234a3 100644 --- a/ets2panda/parser/TSparser.cpp +++ b/ets2panda/parser/TSparser.cpp @@ -515,7 +515,7 @@ ir::TypeNode *TSParser::ParseTypeOperatorOrTypeReference() } auto *typeOperator = AllocNode(type, ir::TSOperatorType::READONLY, Allocator()); - + ES2PANDA_ASSERT(typeOperator != nullptr); typeOperator->SetRange({typeOperatorStart, type->End()}); return typeOperator; @@ -1934,6 +1934,7 @@ ir::MethodDefinition *TSParser::ParseClassMethod(ClassElementDescriptor *desc, } auto *funcExpr = AllocNode(func); + ES2PANDA_ASSERT(funcExpr != nullptr); funcExpr->SetRange(func->Range()); if (desc->methodKind == ir::MethodDefinitionKind::SET) { @@ -1946,6 +1947,7 @@ ir::MethodDefinition *TSParser::ParseClassMethod(ClassElementDescriptor *desc, func->AddFlag(ir::ScriptFunctionFlags::METHOD); auto *method = AllocNode(desc->methodKind, propName, funcExpr, desc->modifiers, Allocator(), desc->isComputed); + ES2PANDA_ASSERT(method != nullptr); method->SetRange(funcExpr->Range()); return method; diff --git a/ets2panda/parser/expressionParser.cpp b/ets2panda/parser/expressionParser.cpp index 596a70e086..ebc744397b 100644 --- a/ets2panda/parser/expressionParser.cpp +++ b/ets2panda/parser/expressionParser.cpp @@ -348,6 +348,7 @@ ir::ArrowFunctionExpression *ParserImpl::ParseArrowFunctionExpressionBody(ArrowF funcNode->SetRange({desc->startLoc, endLoc}); auto *arrowFuncNode = AllocNode(funcNode, Allocator()); + ES2PANDA_ASSERT(arrowFuncNode != nullptr); arrowFuncNode->SetRange(funcNode->Range()); return arrowFuncNode; @@ -2370,7 +2371,7 @@ ir::Expression *ParserImpl::ParseUnaryOrPrefixUpdateExpression(ExpressionParseFl returnExpr = AllocNode(argument, operatorType); } - ES2PANDA_ASSERT(returnExpr); + ES2PANDA_ASSERT(returnExpr != nullptr); returnExpr->SetRange({start, end}); return returnExpr; @@ -2416,6 +2417,7 @@ ir::Expression *ParserImpl::ParseImportExpression() ExpectToken(lexer::TokenType::PUNCTUATOR_RIGHT_PARENTHESIS); auto *importExpression = AllocNode(source); + ES2PANDA_ASSERT(importExpression != nullptr); importExpression->SetRange({startLoc, endImportLoc}); return importExpression; @@ -2451,6 +2453,7 @@ ir::FunctionExpression *ParserImpl::ParseFunctionExpression(ParserStatus newStat } ir::ScriptFunction *functionNode = ParseFunction(newStatus); + ES2PANDA_ASSERT(functionNode != nullptr); functionNode->SetStart(startLoc); auto *funcExpr = AllocNode(ident, functionNode); diff --git a/ets2panda/parser/parserImpl.cpp b/ets2panda/parser/parserImpl.cpp index 2b6e9ce481..ae8dd74781 100644 --- a/ets2panda/parser/parserImpl.cpp +++ b/ets2panda/parser/parserImpl.cpp @@ -480,6 +480,7 @@ ir::MethodDefinition *ParserImpl::ParseClassMethod(ClassElementDescriptor *desc, : propName; auto *method = AllocNode(desc->methodKind, ident, funcExpr, desc->modifiers, Allocator(), desc->isComputed); + ES2PANDA_ASSERT(method != nullptr); method->SetRange(funcExpr->Range()); return method; @@ -495,6 +496,7 @@ ir::ClassElement *ParserImpl::ParseClassProperty(ClassElementDescriptor *desc, if (desc->classMethod) { property = ParseClassMethod(desc, properties, propName, &propEnd); + ES2PANDA_ASSERT(property != nullptr); property->SetRange({desc->propStart, propEnd}); return property; } @@ -514,7 +516,7 @@ ir::ClassElement *ParserImpl::ParseClassProperty(ClassElementDescriptor *desc, property = AllocNode(propName, value, typeAnnotation, desc->modifiers, Allocator(), desc->isComputed); - + ES2PANDA_ASSERT(property != nullptr); property->SetRange({desc->propStart, propEnd}); return property; @@ -685,6 +687,7 @@ ir::MethodDefinition *ParserImpl::BuildImplicitConstructor(ir::ClassDefinitionMo auto *key = AllocNode("constructor", Allocator()); if ((modifiers & ir::ClassDefinitionModifiers::SET_CTOR_ID) != 0U) { + ES2PANDA_ASSERT(key != nullptr); func->SetIdent(key->Clone(Allocator(), nullptr)); } @@ -710,6 +713,7 @@ void ParserImpl::CreateImplicitConstructor(ir::MethodDefinition *&ctor, ctor = BuildImplicitConstructor(modifiers, startLoc); if ((flags & ir::ModifierFlags::DECLARE) != 0) { + ES2PANDA_ASSERT(ctor != nullptr); auto *ctorFunc = ctor->Function(); ES2PANDA_ASSERT(ctorFunc != nullptr); ctorFunc->AddFlag(ir::ScriptFunctionFlags::EXTERNAL); diff --git a/ets2panda/parser/statementParser.cpp b/ets2panda/parser/statementParser.cpp index c311d81ec3..cb374f95f3 100644 --- a/ets2panda/parser/statementParser.cpp +++ b/ets2panda/parser/statementParser.cpp @@ -525,9 +525,11 @@ ir::Statement *ParserImpl::ParseBreakStatement() } auto *identNode = AllocNode(label, Allocator()); + ES2PANDA_ASSERT(identNode != nullptr); identNode->SetRange(lexer_->GetToken().Loc()); auto *breakStatement = AllocNode(identNode); + ES2PANDA_ASSERT(breakStatement != nullptr); breakStatement->SetRange({startLoc, lexer_->GetToken().End()}); lexer_->NextToken(); @@ -580,6 +582,7 @@ ir::Statement *ParserImpl::ParseContinueStatement() } auto *identNode = AllocNode(label, Allocator()); + ES2PANDA_ASSERT(identNode != nullptr); identNode->SetRange(lexer_->GetToken().Loc()); auto *continueStatement = AllocNode(identNode); @@ -662,9 +665,11 @@ ir::FunctionDeclaration *ParserImpl::ParseFunctionDeclaration(bool canBeAnonymou if (lexer_->GetToken().Type() != lexer::TokenType::LITERAL_IDENT) { if (canBeAnonymous) { ir::ScriptFunction *func = ParseFunction(newStatus | ParserStatus::NEED_RETURN_TYPE); + ES2PANDA_ASSERT(func != nullptr); func->SetStart(startLoc); auto *funcDecl = AllocNode(Allocator(), func, true); + ES2PANDA_ASSERT(funcDecl != nullptr); funcDecl->SetRange(func->Range()); return funcDecl; } @@ -684,6 +689,7 @@ ir::FunctionDeclaration *ParserImpl::ParseFunctionDeclaration(bool canBeAnonymou func->SetIdent(identNode); func->SetStart(startLoc); auto *funcDecl = AllocNode(Allocator(), func); + ES2PANDA_ASSERT(funcDecl != nullptr); funcDecl->SetRange(func->Range()); if (func->IsOverload() && lexer_->GetToken().Type() == lexer::TokenType::PUNCTUATOR_SEMI_COLON) { @@ -1383,6 +1389,7 @@ ir::Statement *ParserImpl::ParseTryStatement() while (lexer_->GetToken().Type() == lexer::TokenType::KEYW_CATCH) { catchClause = ParseCatchClause(); + ES2PANDA_ASSERT(catchClause != nullptr); endLoc = catchClause->End(); catchClauses.push_back(catchClause); } @@ -1398,6 +1405,7 @@ ir::Statement *ParserImpl::ParseTryStatement() ArenaVector> finalizerInsertions(Allocator()->Adapter()); auto *tryStatement = AllocNode(body, std::move(catchClauses), finallyClause, finalizerInsertions); + ES2PANDA_ASSERT(tryStatement != nullptr); tryStatement->SetRange({startLoc, endLoc}); return tryStatement; } @@ -2001,6 +2009,7 @@ ir::Statement *ParserImpl::ParseImportDeclaration(StatementParsingFlags flags) source = ParseFromClause(false); } + ES2PANDA_ASSERT(source != nullptr); lexer::SourcePosition endLoc = source->End(); auto *importDeclaration = AllocNode(source, std::move(specifiers)); ES2PANDA_ASSERT(importDeclaration != nullptr); diff --git a/ets2panda/parser/statementTSParser.cpp b/ets2panda/parser/statementTSParser.cpp index 4cd60c24db..b0a451bcd3 100644 --- a/ets2panda/parser/statementTSParser.cpp +++ b/ets2panda/parser/statementTSParser.cpp @@ -372,6 +372,7 @@ ir::Statement *TSParser::ParseImportDeclaration([[maybe_unused]] StatementParsin ES2PANDA_ASSERT(source != nullptr); lexer::SourcePosition endLoc = source->End(); auto *importDeclaration = AllocNode(source, std::move(specifiers)); + ES2PANDA_ASSERT(importDeclaration != nullptr); importDeclaration->SetRange({startLoc, endLoc}); ConsumeSemicolon(importDeclaration); -- Gitee