From 65733572ca80bb9f7ae2adbf5f5685fb5bc5eac8 Mon Sep 17 00:00:00 2001 From: yanpeng51 Date: Tue, 1 Jul 2025 14:58:02 +0800 Subject: [PATCH] "CodeCheck clear" Signed-off-by: yanpeng51 --- ets2panda/parser/TSparser.cpp | 7 +++++ ets2panda/parser/statementParser.cpp | 36 ++++++++++++++++++++++++++ ets2panda/parser/statementTSParser.cpp | 6 +++++ 3 files changed, 49 insertions(+) diff --git a/ets2panda/parser/TSparser.cpp b/ets2panda/parser/TSparser.cpp index 164f34c170..18e568d2da 100644 --- a/ets2panda/parser/TSparser.cpp +++ b/ets2panda/parser/TSparser.cpp @@ -199,6 +199,7 @@ ir::TSTypeAliasDeclaration *TSParser::ParseTypeAliasDeclaration() const util::StringView &ident = Lexer()->GetToken().Ident(); auto *id = AllocNode(ident, Allocator()); + CHECK_NOT_NULL(id); id->SetRange(Lexer()->GetToken().Loc()); Lexer()->NextToken(); @@ -544,6 +545,7 @@ ir::TypeNode *TSParser::ParseTypeOperatorOrTypeReference() auto *inferType = AllocNode(typeParam, Allocator()); + CHECK_NOT_NULL(inferType); inferType->SetRange({inferStart, Lexer()->GetToken().End()}); return inferType; @@ -1020,6 +1022,7 @@ ir::TSIntersectionType *TSParser::ParseIntersectionType(ir::Expression *type, bo auto *intersectionType = AllocNode(std::move(types), Allocator()); auto *typeVar = varbinder::Scope::CreateVar(Allocator(), "__type", varbinder::VariableFlags::TYPE, intersectionType); + CHECK_NOT_NULL(intersectionType); intersectionType->SetVariable(typeVar); intersectionType->SetRange({startLoc, endLoc}); @@ -1041,6 +1044,7 @@ private: return parser->AllocNode(bigintNode, parser->Allocator()); } auto *numberNode = parser->AllocNode(lexer->GetToken().GetNumber()); + CHECK_NOT_NULL(numberNode); numberNode->SetRange(lexer->GetToken().Loc()); return parser->AllocNode(numberNode, parser->Allocator()); @@ -1534,6 +1538,7 @@ ir::TSIndexSignature *TSParser::ParseIndexSignature(const lexer::SourcePosition ES2PANDA_ASSERT(Lexer()->GetToken().Type() == lexer::TokenType::LITERAL_IDENT); auto *key = AllocNode(Lexer()->GetToken().Ident(), Allocator()); + CHECK_NOT_NULL(key); key->SetRange(Lexer()->GetToken().Loc()); Lexer()->NextToken(); // eat key @@ -1905,6 +1910,7 @@ ir::MethodDefinition *TSParser::ParseClassMethod(ClassElementDescriptor *desc, ir::ScriptFunction *func = ParseFunction(desc->newStatus); + CHECK_NOT_NULL(func); if (func->IsOverload() && !desc->decorators.empty()) { ThrowSyntaxError("A decorator can only decorate a method implementation, not an overload.", desc->decorators.front()->Start()); @@ -2110,6 +2116,7 @@ ir::AstNode *TSParser::ParseImportDefaultSpecifier(ArenaVector *s } auto *specifier = AllocNode(local); + CHECK_NOT_NULL(specifier); specifier->SetRange(specifier->Local()->Range()); specifiers->push_back(specifier); diff --git a/ets2panda/parser/statementParser.cpp b/ets2panda/parser/statementParser.cpp index c4ff7e348a..1bd54cff84 100644 --- a/ets2panda/parser/statementParser.cpp +++ b/ets2panda/parser/statementParser.cpp @@ -230,6 +230,7 @@ ir::Statement *ParserImpl::ParseLetStatement(StatementParsingFlags flags) } auto *variableDecl = ParseVariableDeclaration(VariableParsingFlags::LET); + CHECK_NOT_NULL(variableDecl); if (variableDecl->IsBrokenStatement()) { // Error processing. return variableDecl; } @@ -248,6 +249,7 @@ ir::Statement *ParserImpl::ParseConstStatement(StatementParsingFlags flags) lexer_->NextToken(); auto *variableDecl = ParseVariableDeclaration(VariableParsingFlags::CONST | VariableParsingFlags::NO_SKIP_VAR_KIND); + CHECK_NOT_NULL(variableDecl); if (variableDecl->IsBrokenStatement()) { // Error processing. return variableDecl; } @@ -261,6 +263,7 @@ ir::Statement *ParserImpl::ParseConstStatement(StatementParsingFlags flags) ir::EmptyStatement *ParserImpl::ParseEmptyStatement() { auto *empty = AllocNode(); + CHECK_NOT_NULL(empty); empty->SetRange(lexer_->GetToken().Loc()); lexer_->NextToken(); return empty; @@ -269,6 +272,7 @@ ir::EmptyStatement *ParserImpl::ParseEmptyStatement() ir::Statement *ParserImpl::ParseDebuggerStatement() { auto *debuggerNode = AllocNode(); + CHECK_NOT_NULL(debuggerNode); debuggerNode->SetRange(lexer_->GetToken().Loc()); lexer_->NextToken(); ConsumeSemicolon(debuggerNode); @@ -288,6 +292,7 @@ ir::Statement *ParserImpl::ParseFunctionStatement(StatementParsingFlags flags) stmts.push_back(funcDecl); auto *localBlockStmt = AllocNode(Allocator(), std::move(stmts)); + CHECK_NOT_NULL(localBlockStmt); localBlockStmt->SetRange(funcDecl->Range()); return funcDecl; @@ -333,6 +338,7 @@ ir::Statement *ParserImpl::ParseStructDeclaration(ir::ClassDefinitionModifiers m lexer::SourcePosition endLoc = classDefinition->End(); auto *structDecl = AllocNode(classDefinition, Allocator()); + CHECK_NOT_NULL(structDecl); structDecl->SetRange({startLoc, endLoc}); return structDecl; } @@ -353,6 +359,7 @@ ir::Statement *ParserImpl::ParseClassDeclaration(ir::ClassDefinitionModifiers mo lexer::SourcePosition endLoc = classDefinition->End(); auto *classDecl = AllocNode(classDefinition, Allocator()); + CHECK_NOT_NULL(classDecl); classDecl->SetRange({startLoc, endLoc}); return classDecl; } @@ -376,6 +383,7 @@ void ParserImpl::CheckFunctionDeclaration(StatementParsingFlags flags) void ParserImpl::ConsumeSemicolon(ir::Statement *statement) { + CHECK_NOT_NULL(statement); auto const &token = lexer_->GetToken(); auto tokenType = token.Type(); if (tokenType == lexer::TokenType::PUNCTUATOR_SEMI_COLON) { @@ -464,6 +472,7 @@ ir::BlockStatement *ParserImpl::ParseBlockStatement() auto statements = ParseStatementList(); auto *blockNode = AllocNode(Allocator(), std::move(statements)); + CHECK_NOT_NULL(blockNode); blockNode->SetRange({startLoc, lexer_->GetToken().End()}); ExpectToken(lexer::TokenType::PUNCTUATOR_RIGHT_BRACE); @@ -495,6 +504,7 @@ ir::Statement *ParserImpl::ParseBreakStatement() } auto *breakStatement = AllocNode(); + CHECK_NOT_NULL(breakStatement); breakStatement->SetRange({startLoc, lexer_->GetToken().End()}); if (lexer_->GetToken().Type() == lexer::TokenType::PUNCTUATOR_SEMI_COLON) { @@ -570,6 +580,7 @@ ir::Statement *ParserImpl::ParseContinueStatement() identNode->SetRange(lexer_->GetToken().Loc()); auto *continueStatement = AllocNode(identNode); + CHECK_NOT_NULL(continueStatement); continueStatement->SetRange({startLoc, lexer_->GetToken().End()}); lexer_->NextToken(); @@ -618,6 +629,7 @@ ir::Statement *ParserImpl::ParseDoWhileStatement() ExpectToken(lexer::TokenType::PUNCTUATOR_RIGHT_PARENTHESIS); auto *doWhileStatement = AllocNode(body, condition); + CHECK_NOT_NULL(doWhileStatement); doWhileStatement->SetRange({startLoc, endLoc}); if (lexer_->GetToken().Type() == lexer::TokenType::PUNCTUATOR_SEMI_COLON) { @@ -664,6 +676,7 @@ ir::FunctionDeclaration *ParserImpl::ParseFunctionDeclaration(bool canBeAnonymou newStatus |= ParserStatus::FUNCTION_DECLARATION; ir::ScriptFunction *func = ParseFunction(newStatus | ParserStatus::NEED_RETURN_TYPE); + CHECK_NOT_NULL(func); func->SetIdent(identNode); func->SetStart(startLoc); @@ -726,6 +739,7 @@ ir::Statement *ParserImpl::ParseExpressionStatement(StatementParsingFlags flags) lexer::SourcePosition endPos = exprNode->End(); auto *exprStatementNode = AllocNode(exprNode); + CHECK_NOT_NULL(exprStatementNode); exprStatementNode->SetRange({startPos.GetToken().Start(), endPos}); ConsumeSemicolon(exprStatementNode); @@ -856,6 +870,7 @@ std::tuple ir::AstNode *initNode = lexer_->GetToken().Type() == lexer::TokenType::PUNCTUATOR_COMMA ? ParseSequenceExpression(expr) : expr; + CHECK_NOT_NULL(initNode); if (initNode->IsConditionalExpression()) { ir::ConditionalExpression *condExpr = initNode->AsConditionalExpression(); @@ -1008,6 +1023,7 @@ ir::Statement *ParserImpl::CreateForStatement(ForStatementNodes &&nodes, ForStat } } + CHECK_NOT_NULL(forStatement); forStatement->SetRange({startLoc, nodes.body->End()}); return forStatement; @@ -1085,6 +1101,7 @@ ir::Statement *ParserImpl::ParseIfStatement() } auto *ifStatement = AllocNode(test, consequent, alternate); + CHECK_NOT_NULL(ifStatement); ifStatement->SetRange({startLoc, endLoc}); return ifStatement; } @@ -1154,6 +1171,7 @@ ir::Statement *ParserImpl::ParseReturnStatement() returnStatement = AllocNode(); } + CHECK_NOT_NULL(returnStatement); returnStatement->SetRange({startLoc, endLoc}); ConsumeSemicolon(returnStatement); @@ -1209,6 +1227,7 @@ ir::SwitchCaseStatement *ParserImpl::ParseSwitchCaseStatement(bool *seenDefault) } auto *caseNode = AllocNode(testExpr, std::move(consequents)); + CHECK_NOT_NULL(caseNode); caseNode->SetRange({caseStartLoc, caseEndLoc}); return caseNode; } @@ -1240,6 +1259,7 @@ ir::Statement *ParserImpl::ParseSwitchStatement() ExpectToken(lexer::TokenType::PUNCTUATOR_RIGHT_BRACE); auto *switchStatement = AllocNode(discriminant, std::move(cases)); + CHECK_NOT_NULL(switchStatement); switchStatement->SetRange({startLoc, endLoc}); return switchStatement; } @@ -1264,6 +1284,7 @@ ir::Statement *ParserImpl::ParseThrowStatement() lexer::SourcePosition endLoc = expression->End(); auto *throwStatement = AllocNode(expression); + CHECK_NOT_NULL(throwStatement); throwStatement->SetRange({startLoc, endLoc}); ConsumeSemicolon(throwStatement); @@ -1362,6 +1383,7 @@ ir::Statement *ParserImpl::ParseTryStatement() lexer_->NextToken(); // eat 'finally' keyword finallyClause = ParseBlockStatement(); + CHECK_NOT_NULL(finallyClause); endLoc = finallyClause->End(); } @@ -1532,6 +1554,7 @@ ir::Statement *ParserImpl::ParseVariableDeclaration(VariableParsingFlags flags) lexer::SourcePosition endLoc = declarators.back()->End(); auto *declaration = AllocNode(varKind, Allocator(), std::move(declarators)); + CHECK_NOT_NULL(declaration); declaration->SetRange({startLoc, endLoc}); return declaration; @@ -1559,6 +1582,7 @@ ir::Statement *ParserImpl::ParseWhileStatement() lexer::SourcePosition endLoc = body->End(); auto *whileStatement = AllocNode(condition, body); + CHECK_NOT_NULL(whileStatement); whileStatement->SetRange({startLoc, endLoc}); return whileStatement; @@ -1609,6 +1633,7 @@ ir::ExportDefaultDeclaration *ParserImpl::ParseExportDefaultDeclaration(const le ES2PANDA_ASSERT(declNode != nullptr); lexer::SourcePosition endLoc = declNode->End(); auto *exportDeclaration = AllocNode(declNode, isExportEquals); + CHECK_NOT_NULL(exportDeclaration); exportDeclaration->SetRange({startLoc, endLoc}); if (eatSemicolon) { @@ -1632,6 +1657,7 @@ ir::Identifier *ParserImpl::ParseNamedExport(lexer::Token *exportedToken) const util::StringView &exportedString = exportedToken->Ident(); auto *exported = AllocNode(exportedString, Allocator()); + CHECK_NOT_NULL(exported); exported->SetRange(exportedToken->Loc()); return exported; @@ -1649,9 +1675,11 @@ ir::ExportAllDeclaration *ParserImpl::ParseExportAllDeclaration(const lexer::Sou lexer_->NextToken(); // eat exported name } ir::StringLiteral *source = ParseFromClause(); + CHECK_NOT_NULL(source); lexer::SourcePosition endLoc = source->End(); auto *exportDeclaration = AllocNode(source, exported); + CHECK_NOT_NULL(exportDeclaration); exportDeclaration->SetRange({startLoc, endLoc}); ConsumeSemicolon(exportDeclaration); @@ -1706,6 +1734,7 @@ ir::ExportNamedDeclaration *ParserImpl::ParseExportNamedSpecifiers(const lexer:: } auto *exportDeclaration = AllocNode(Allocator(), source, std::move(specifiers)); + CHECK_NOT_NULL(exportDeclaration); exportDeclaration->SetRange({startLoc, endPos}); ConsumeSemicolon(exportDeclaration); @@ -1760,6 +1789,7 @@ ir::Statement *ParserImpl::ParseNamedExportDeclaration(const lexer::SourcePositi lexer::SourcePosition endLoc = decl->End(); ArenaVector specifiers(Allocator()->Adapter()); auto *exportDeclaration = AllocNode(Allocator(), decl, std::move(specifiers)); + CHECK_NOT_NULL(exportDeclaration); exportDeclaration->SetRange({startLoc, endLoc}); return exportDeclaration; @@ -1808,6 +1838,7 @@ void ParserImpl::ParseNameSpaceImport(ArenaVector *specifiers) ir::Identifier *local = ParseNamedImport(&lexer_->GetToken()); auto *specifier = AllocNode(local); + CHECK_NOT_NULL(specifier); specifier->SetRange({namespaceStart, lexer_->GetToken().End()}); specifiers->push_back(specifier); @@ -1825,6 +1856,7 @@ ir::Identifier *ParserImpl::ParseNamedImport(lexer::Token *importedToken) CheckRestrictedBinding(importedToken->KeywordType()); auto *local = AllocNode(importedToken->Ident(), Allocator()); + CHECK_NOT_NULL(local); local->SetRange(importedToken->Loc()); return local; @@ -1871,6 +1903,7 @@ ir::AstNode *ParserImpl::ParseImportDefaultSpecifier(ArenaVector lexer_->NextToken(); // eat local name auto *specifier = AllocNode(local); + CHECK_NOT_NULL(specifier); specifier->SetRange(specifier->Local()->Range()); specifiers->push_back(specifier); @@ -1903,6 +1936,7 @@ ir::StringLiteral *ParserImpl::ParseFromClause(bool requireFrom) } auto *source = AllocNode(lexer_->GetToken().String()); + CHECK_NOT_NULL(source); source->SetRange(lexer_->GetToken().Loc()); lexer_->NextToken(); @@ -1976,6 +2010,7 @@ ir::Statement *ParserImpl::AllocBrokenStatement(const lexer::SourcePosition &pos ir::Statement *ParserImpl::AllocBrokenStatement(const lexer::SourceRange &range) { auto *broken = AllocNode(true); + CHECK_NOT_NULL(broken); broken->SetRange(range); return broken; } @@ -1991,6 +2026,7 @@ bool ParserImpl::IsBrokenStatement(ir::Statement *st) ir::Statement *ParserImpl::AllocEmptyStatement() { auto *empty = AllocNode(); + CHECK_NOT_NULL(empty); empty->SetRange(lexer_->GetToken().Loc()); return empty; } diff --git a/ets2panda/parser/statementTSParser.cpp b/ets2panda/parser/statementTSParser.cpp index 34dce05dc1..ce4f5ffe2b 100644 --- a/ets2panda/parser/statementTSParser.cpp +++ b/ets2panda/parser/statementTSParser.cpp @@ -131,6 +131,7 @@ ir::TSImportEqualsDeclaration *TSParser::ParseTsImportEqualsDeclaration(const le } auto *id = AllocNode(Lexer()->GetToken().Ident(), Allocator()); + CHECK_NOT_NULL(id); id->SetRange(Lexer()->GetToken().Loc()); Lexer()->NextToken(); // eat id name @@ -190,6 +191,7 @@ ir::ExportDefaultDeclaration *TSParser::ParseExportDefaultDeclaration(const lexe lexer::SourcePosition endLoc = declNode->End(); auto *exportDeclaration = AllocNode(declNode, isExportEquals); + CHECK_NOT_NULL(exportDeclaration); exportDeclaration->SetRange({startLoc, endLoc}); if (eatSemicolon) { @@ -265,6 +267,7 @@ ir::Statement *TSParser::ParseNamedExportDeclaration(const lexer::SourcePosition lexer::SourcePosition endLoc = decl->End(); ArenaVector specifiers(Allocator()->Adapter()); auto *exportDeclaration = AllocNode(Allocator(), decl, std::move(specifiers)); + CHECK_NOT_NULL(exportDeclaration); exportDeclaration->SetRange({startLoc, endLoc}); return exportDeclaration; @@ -293,6 +296,7 @@ ir::Statement *TSParser::ParseExportDeclaration(StatementParsingFlags flags) } default: { auto ret = ParseNamedExportDeclaration(startLoc); + CHECK_NOT_NULL(ret); if (ret->IsBrokenStatement()) { return ret; } @@ -322,6 +326,7 @@ ir::Statement *TSParser::ParseConstStatement(StatementParsingFlags flags) } auto *variableDecl = ParseVariableDeclaration(VariableParsingFlags::CONST | VariableParsingFlags::NO_SKIP_VAR_KIND); + CHECK_NOT_NULL(variableDecl); variableDecl->SetStart(constVarStar); ConsumeSemicolon(variableDecl); @@ -364,6 +369,7 @@ ir::Statement *TSParser::ParseImportDeclaration([[maybe_unused]] StatementParsin source = ParseFromClause(false); } + CHECK_NOT_NULL(source); lexer::SourcePosition endLoc = source->End(); auto *importDeclaration = AllocNode(source, std::move(specifiers)); importDeclaration->SetRange({startLoc, endLoc}); -- Gitee