From 0941ba9be1c48735de27b3edc72a6358da5f9f39 Mon Sep 17 00:00:00 2001 From: Konstantin Kuznetsov Date: Wed, 21 Feb 2024 09:22:56 +0300 Subject: [PATCH 1/5] Update AST Verifier checks Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/I91NGP Also issue I91NHH Removed the following restrictions from the AST Verifier: ``` (ast->AsIdentifier()->Parent() != nullptr && ast->AsIdentifier()->Parent()->IsProperty()) ast->AsIdentifier()->Name().Utf8().find("Void") == 0 ``` Signed-off-by: Konstantin Kuznetsov --- ets2panda/compiler/core/ASTVerifier.cpp | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/ets2panda/compiler/core/ASTVerifier.cpp b/ets2panda/compiler/core/ASTVerifier.cpp index 5af36a6f..81c84c40 100644 --- a/ets2panda/compiler/core/ASTVerifier.cpp +++ b/ets2panda/compiler/core/ASTVerifier.cpp @@ -441,9 +441,7 @@ public: * varbinder and checker */ if (ast->AsIdentifier()->Variable() != nullptr || ast->AsIdentifier()->IsReference() || - ast->AsIdentifier()->Name().Empty() || ast->AsIdentifier()->Name() == "Void" || - ast->AsIdentifier()->Name().Utf8().find("lambda$invoke$") == 0 || - (ast->AsIdentifier()->Parent() != nullptr && ast->AsIdentifier()->Parent()->IsProperty())) { + ast->AsIdentifier()->Name().Empty() || ast->AsIdentifier()->Name().Utf8().find("lambda$invoke$") == 0) { return {CheckDecision::CORRECT, CheckAction::CONTINUE}; } @@ -574,9 +572,7 @@ public: * Should removed in future */ if (ast->AsIdentifier()->IsReference() || ast->AsIdentifier()->TypeAnnotation() != nullptr || - ast->AsIdentifier()->Name().Empty() || ast->AsIdentifier()->Name().Utf8().find("Void") == 0 || - ast->AsIdentifier()->Name().Utf8().find("lambda$invoke$") == 0 || - (ast->AsIdentifier()->Parent() != nullptr && ast->AsIdentifier()->Parent()->IsProperty())) { + ast->AsIdentifier()->Name().Empty() || ast->AsIdentifier()->Name().Utf8().find("lambda$invoke$") == 0) { return {CheckDecision::CORRECT, CheckAction::CONTINUE}; } @@ -609,10 +605,8 @@ public: * Should removed in future */ if (ast->AsIdentifier()->IsReference() || ast->AsIdentifier()->TypeAnnotation() != nullptr || - ast->AsIdentifier()->Name().Empty() || ast->AsIdentifier()->Name().Utf8().find("Void") == 0 || - ast->AsIdentifier()->Name().Utf8().find("field") == 0 || - ast->AsIdentifier()->Name().Utf8().find("lambda$invoke$") == 0 || - (ast->AsIdentifier()->Parent() != nullptr && ast->AsIdentifier()->Parent()->IsProperty())) { + ast->AsIdentifier()->Name().Empty() || ast->AsIdentifier()->Name().Utf8().find("field") == 0 || + ast->AsIdentifier()->Name().Utf8().find("lambda$invoke$") == 0) { return std::nullopt; } -- Gitee From 9cf14daa86960cd4870a9f499b05be15774d9638 Mon Sep 17 00:00:00 2001 From: Konstantin Kuznetsov Date: Wed, 21 Feb 2024 10:40:06 +0300 Subject: [PATCH 2/5] Remove isReference check for AST Verifier --- ets2panda/compiler/core/ASTVerifier.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/ets2panda/compiler/core/ASTVerifier.cpp b/ets2panda/compiler/core/ASTVerifier.cpp index 81c84c40..c15a8bc0 100644 --- a/ets2panda/compiler/core/ASTVerifier.cpp +++ b/ets2panda/compiler/core/ASTVerifier.cpp @@ -440,7 +440,8 @@ public: * That should be removed in future after fix issues in * varbinder and checker */ - if (ast->AsIdentifier()->Variable() != nullptr || ast->AsIdentifier()->IsReference() || + if (ast->AsIdentifier()->Variable() != nullptr || + // ast->AsIdentifier()->IsReference() || ast->AsIdentifier()->Name().Empty() || ast->AsIdentifier()->Name().Utf8().find("lambda$invoke$") == 0) { return {CheckDecision::CORRECT, CheckAction::CONTINUE}; } @@ -571,8 +572,10 @@ public: * NOTICE: That is temporary exclusion for identifies without variable * Should removed in future */ - if (ast->AsIdentifier()->IsReference() || ast->AsIdentifier()->TypeAnnotation() != nullptr || - ast->AsIdentifier()->Name().Empty() || ast->AsIdentifier()->Name().Utf8().find("lambda$invoke$") == 0) { + if ( + // ast->AsIdentifier()->IsReference() || + ast->AsIdentifier()->TypeAnnotation() != nullptr || ast->AsIdentifier()->Name().Empty() || + ast->AsIdentifier()->Name().Utf8().find("lambda$invoke$") == 0) { return {CheckDecision::CORRECT, CheckAction::CONTINUE}; } @@ -604,8 +607,10 @@ public: * NOTICE: That is temporary exclusion for identifies without variable and scope * Should removed in future */ - if (ast->AsIdentifier()->IsReference() || ast->AsIdentifier()->TypeAnnotation() != nullptr || - ast->AsIdentifier()->Name().Empty() || ast->AsIdentifier()->Name().Utf8().find("field") == 0 || + if ( + // ast->AsIdentifier()->IsReference() || + ast->AsIdentifier()->TypeAnnotation() != nullptr || ast->AsIdentifier()->Name().Empty() || + ast->AsIdentifier()->Name().Utf8().find("field") == 0 || ast->AsIdentifier()->Name().Utf8().find("lambda$invoke$") == 0) { return std::nullopt; } -- Gitee From 04a4ecb7779b10aa28c8928d5439b9cfb0043c51 Mon Sep 17 00:00:00 2001 From: Stanislav Malishevskiy Date: Tue, 27 Feb 2024 16:33:04 +0300 Subject: [PATCH 3/5] Replace identifier by name in labels Signed-off-by: Stanislav Malishevskiy --- ets2panda/checker/ETSAnalyzer.cpp | 4 ++-- ets2panda/checker/ETSchecker.h | 3 ++- ets2panda/checker/ets/helpers.cpp | 4 ++-- ets2panda/compiler/core/ETSCompiler.cpp | 4 ++-- ets2panda/compiler/core/JSCompiler.cpp | 4 ++-- ets2panda/compiler/core/codeGen.cpp | 8 +++---- ets2panda/compiler/core/codeGen.h | 4 ++-- ets2panda/compiler/core/dynamicContext.cpp | 6 ++--- ets2panda/ir/statements/breakStatement.cpp | 20 ++++------------ ets2panda/ir/statements/breakStatement.h | 8 +++---- ets2panda/ir/statements/continueStatement.cpp | 23 ++++++++----------- ets2panda/ir/statements/continueStatement.h | 10 ++++---- ets2panda/ir/statements/labelledStatement.cpp | 7 ++---- ets2panda/ir/statements/labelledStatement.h | 10 ++++---- ets2panda/parser/statementParser.cpp | 18 +++------------ 15 files changed, 53 insertions(+), 80 deletions(-) diff --git a/ets2panda/checker/ETSAnalyzer.cpp b/ets2panda/checker/ETSAnalyzer.cpp index 2491daa7..55ea3031 100644 --- a/ets2panda/checker/ETSAnalyzer.cpp +++ b/ets2panda/checker/ETSAnalyzer.cpp @@ -1978,7 +1978,7 @@ checker::Type *ETSAnalyzer::Check(ir::BlockStatement *st) const checker::Type *ETSAnalyzer::Check(ir::BreakStatement *st) const { ETSChecker *checker = GetETSChecker(); - st->target_ = checker->FindJumpTarget(st->Type(), st, st->Ident()); + st->target_ = checker->FindJumpTarget(st->Type(), st, st->Label()); return nullptr; } @@ -1992,7 +1992,7 @@ checker::Type *ETSAnalyzer::Check(ir::ClassDeclaration *st) const checker::Type *ETSAnalyzer::Check(ir::ContinueStatement *st) const { ETSChecker *checker = GetETSChecker(); - st->target_ = checker->FindJumpTarget(st->Type(), st, st->Ident()); + st->target_ = checker->FindJumpTarget(st->Type(), st, st->Label()); return nullptr; } diff --git a/ets2panda/checker/ETSchecker.h b/ets2panda/checker/ETSchecker.h index b88160bb..9180a3e6 100644 --- a/ets2panda/checker/ETSchecker.h +++ b/ets2panda/checker/ETSchecker.h @@ -475,7 +475,8 @@ public: { return type->IsETSReferenceType(); } - const ir::AstNode *FindJumpTarget(ir::AstNodeType nodeType, const ir::AstNode *node, const ir::Identifier *target); + const ir::AstNode *FindJumpTarget(ir::AstNodeType nodeType, const ir::AstNode *node, + const util::StringView &target); void ValidatePropertyAccess(varbinder::Variable *var, ETSObjectType *obj, const lexer::SourcePosition &pos); varbinder::VariableFlags GetAccessFlagFromNode(const ir::AstNode *node); void CheckSwitchDiscriminant(ir::Expression *discriminant); diff --git a/ets2panda/checker/ets/helpers.cpp b/ets2panda/checker/ets/helpers.cpp index 164d5b6b..2e28e09b 100644 --- a/ets2panda/checker/ets/helpers.cpp +++ b/ets2panda/checker/ets/helpers.cpp @@ -1642,14 +1642,14 @@ bool ETSChecker::IsTypeBuiltinType(const Type *type) const } const ir::AstNode *ETSChecker::FindJumpTarget(ir::AstNodeType nodeType, const ir::AstNode *node, - const ir::Identifier *target) + const util::StringView &target) { const auto *iter = node->Parent(); while (iter != nullptr) { switch (iter->Type()) { case ir::AstNodeType::LABELLED_STATEMENT: { - if (const auto *labelled = iter->AsLabelledStatement(); labelled->Ident()->Name() == target->Name()) { + if (const auto *labelled = iter->AsLabelledStatement(); labelled->Name() == target) { return nodeType == ir::AstNodeType::CONTINUE_STATEMENT ? labelled->GetReferencedStatement() : labelled; } diff --git a/ets2panda/compiler/core/ETSCompiler.cpp b/ets2panda/compiler/core/ETSCompiler.cpp index b4294f32..441dac41 100644 --- a/ets2panda/compiler/core/ETSCompiler.cpp +++ b/ets2panda/compiler/core/ETSCompiler.cpp @@ -1497,7 +1497,7 @@ void ETSCompiler::Compile(const ir::BlockStatement *st) const template static void CompileImpl(const ir::BreakStatement *self, [[maybe_unused]] CodeGen *cg) { - compiler::Label *target = cg->ControlFlowChangeBreak(self->Ident()); + compiler::Label *target = cg->ControlFlowChangeBreak(self->Label()); cg->Branch(self, target); } @@ -1517,7 +1517,7 @@ void ETSCompiler::Compile([[maybe_unused]] const ir::ClassDeclaration *st) const static void CompileImpl(const ir::ContinueStatement *self, ETSGen *etsg) { - compiler::Label *target = etsg->ControlFlowChangeContinue(self->Ident()); + compiler::Label *target = etsg->ControlFlowChangeContinue(self->Label()); etsg->Branch(self, target); } diff --git a/ets2panda/compiler/core/JSCompiler.cpp b/ets2panda/compiler/core/JSCompiler.cpp index 8d07f3f7..f6ab02ba 100644 --- a/ets2panda/compiler/core/JSCompiler.cpp +++ b/ets2panda/compiler/core/JSCompiler.cpp @@ -1470,7 +1470,7 @@ void JSCompiler::Compile(const ir::BlockStatement *st) const template static void CompileImpl(const ir::BreakStatement *self, [[maybe_unused]] CodeGen *cg) { - compiler::Label *target = cg->ControlFlowChangeBreak(self->Ident()); + compiler::Label *target = cg->ControlFlowChangeBreak(self->Label()); cg->Branch(self, target); } void JSCompiler::Compile(const ir::BreakStatement *st) const @@ -1489,7 +1489,7 @@ void JSCompiler::Compile(const ir::ClassDeclaration *st) const static void CompileImpl(const ir::ContinueStatement *self, PandaGen *cg) { - compiler::Label *target = cg->ControlFlowChangeContinue(self->Ident()); + compiler::Label *target = cg->ControlFlowChangeContinue(self->Label()); cg->Branch(self, target); } diff --git a/ets2panda/compiler/core/codeGen.cpp b/ets2panda/compiler/core/codeGen.cpp index f7a00e0d..535801aa 100644 --- a/ets2panda/compiler/core/codeGen.cpp +++ b/ets2panda/compiler/core/codeGen.cpp @@ -199,11 +199,11 @@ bool CodeGen::CheckControlFlowChange() const return false; } -Label *CodeGen::ControlFlowChangeBreak(const ir::Identifier *label) +Label *CodeGen::ControlFlowChangeBreak(const util::StringView &label) { auto *iter = dynamicContext_; - util::StringView labelName = label != nullptr ? label->Name() : LabelTarget::BREAK_LABEL; + util::StringView labelName = label.Empty() ? LabelTarget::BREAK_LABEL : label; Label *breakTarget = nullptr; while (iter != nullptr) { @@ -226,10 +226,10 @@ Label *CodeGen::ControlFlowChangeBreak(const ir::Identifier *label) return breakTarget; } -Label *CodeGen::ControlFlowChangeContinue(const ir::Identifier *label) +Label *CodeGen::ControlFlowChangeContinue(const util::StringView &label) { auto *iter = dynamicContext_; - util::StringView labelName = label != nullptr ? label->Name() : LabelTarget::CONTINUE_LABEL; + util::StringView labelName = label.Empty() ? LabelTarget::CONTINUE_LABEL : label; Label *continueTarget = nullptr; while (iter != nullptr) { diff --git a/ets2panda/compiler/core/codeGen.h b/ets2panda/compiler/core/codeGen.h index 6fd6a635..d6b6e1a6 100644 --- a/ets2panda/compiler/core/codeGen.h +++ b/ets2panda/compiler/core/codeGen.h @@ -132,8 +132,8 @@ public: void SetLabel(const ir::AstNode *node, Label *label); void Branch(const ir::AstNode *node, class Label *label); [[nodiscard]] bool CheckControlFlowChange() const; - Label *ControlFlowChangeBreak(const ir::Identifier *label = nullptr); - [[nodiscard]] Label *ControlFlowChangeContinue(const ir::Identifier *label); + Label *ControlFlowChangeBreak(const util::StringView &label = ""); + [[nodiscard]] Label *ControlFlowChangeContinue(const util::StringView &label); uint32_t TryDepth() const; [[nodiscard]] CatchTable *CreateCatchTable(util::StringView exceptionType = ""); diff --git a/ets2panda/compiler/core/dynamicContext.cpp b/ets2panda/compiler/core/dynamicContext.cpp index d1d3179c..476d3163 100644 --- a/ets2panda/compiler/core/dynamicContext.cpp +++ b/ets2panda/compiler/core/dynamicContext.cpp @@ -42,7 +42,7 @@ DynamicContext::~DynamicContext() } LabelContext::LabelContext(CodeGen *cg, const ir::LabelledStatement *labelledStmt) - : DynamicContext(cg, LabelTarget(labelledStmt->Ident()->Name())), labelledStmt_(labelledStmt) + : DynamicContext(cg, LabelTarget(labelledStmt->Name())), labelledStmt_(labelledStmt) { if (!labelledStmt->Body()->IsBlockStatement()) { return; @@ -263,10 +263,10 @@ void ETSTryContext::EmitFinalizer( etsg->ReturnAcc(tryStmt_); } } else if (insertion.second->IsBreakStatement()) { - compiler::Label *target = etsg->ControlFlowChangeBreak(insertion.second->AsBreakStatement()->Ident()); + compiler::Label *target = etsg->ControlFlowChangeBreak(insertion.second->AsBreakStatement()->Label()); etsg->Branch(tryStmt_, target); } else if (insertion.second->IsContinueStatement()) { - compiler::Label *target = etsg->ControlFlowChangeContinue(insertion.second->AsContinueStatement()->Ident()); + compiler::Label *target = etsg->ControlFlowChangeContinue(insertion.second->AsContinueStatement()->Label()); etsg->Branch(tryStmt_, target); } else { UNREACHABLE(); diff --git a/ets2panda/ir/statements/breakStatement.cpp b/ets2panda/ir/statements/breakStatement.cpp index f31ee1cc..f6e88e2f 100644 --- a/ets2panda/ir/statements/breakStatement.cpp +++ b/ets2panda/ir/statements/breakStatement.cpp @@ -24,31 +24,21 @@ #include "checker/ETSchecker.h" namespace ark::es2panda::ir { -void BreakStatement::TransformChildren(const NodeTransformer &cb) -{ - if (ident_ != nullptr) { - ident_ = cb(ident_)->AsIdentifier(); - } -} +void BreakStatement::TransformChildren(const NodeTransformer & /*cb*/) {} -void BreakStatement::Iterate(const NodeTraverser &cb) const -{ - if (ident_ != nullptr) { - cb(ident_); - } -} +void BreakStatement::Iterate(const NodeTraverser & /*cb*/) const {} void BreakStatement::Dump(ir::AstDumper *dumper) const { - dumper->Add({{"type", "BreakStatement"}, {"label", AstDumper::Nullish(ident_)}}); + dumper->Add({{"type", "BreakStatement"}, {"label", label_}}); } void BreakStatement::Dump(ir::SrcDumper *dumper) const { dumper->Add("break"); - if (ident_ != nullptr) { + if (!label_.Empty()) { dumper->Add(" "); - ident_->Dump(dumper); + dumper->Add(std::string(label_)); } dumper->Add(";"); } diff --git a/ets2panda/ir/statements/breakStatement.h b/ets2panda/ir/statements/breakStatement.h index 4e37906e..d4c3de44 100644 --- a/ets2panda/ir/statements/breakStatement.h +++ b/ets2panda/ir/statements/breakStatement.h @@ -32,14 +32,14 @@ class Identifier; class BreakStatement : public Statement { public: explicit BreakStatement() : Statement(AstNodeType::BREAK_STATEMENT) {} - explicit BreakStatement(Identifier *ident) : Statement(AstNodeType::BREAK_STATEMENT), ident_(ident) {} + explicit BreakStatement(util::StringView const label) : Statement(AstNodeType::BREAK_STATEMENT), label_(label) {} friend checker::ETSAnalyzer; friend compiler::ETSCompiler; - const Identifier *Ident() const + const util::StringView &Label() const { - return ident_; + return label_; } const ir::AstNode *Target() const @@ -62,7 +62,7 @@ public: } private: - Identifier *ident_ {}; + util::StringView label_ {}; const ir::AstNode *target_ {}; }; } // namespace ark::es2panda::ir diff --git a/ets2panda/ir/statements/continueStatement.cpp b/ets2panda/ir/statements/continueStatement.cpp index d952b408..13b2176f 100644 --- a/ets2panda/ir/statements/continueStatement.cpp +++ b/ets2panda/ir/statements/continueStatement.cpp @@ -22,28 +22,23 @@ #include "ir/srcDump.h" namespace ark::es2panda::ir { -void ContinueStatement::TransformChildren(const NodeTransformer &cb) -{ - if (ident_ != nullptr) { - ident_ = cb(ident_)->AsIdentifier(); - } -} +void ContinueStatement::TransformChildren(const NodeTransformer & /*cb*/) {} -void ContinueStatement::Iterate(const NodeTraverser &cb) const -{ - if (ident_ != nullptr) { - cb(ident_); - } -} +void ContinueStatement::Iterate(const NodeTraverser & /*cb*/) const {} void ContinueStatement::Dump(ir::AstDumper *dumper) const { - dumper->Add({{"type", "ContinueStatement"}, {"label", AstDumper::Nullish(ident_)}}); + dumper->Add({{"type", "ContinueStatement"}, {"label", label_}}); } void ContinueStatement::Dump(ir::SrcDumper *dumper) const { - dumper->Add("continue;"); + dumper->Add("continue"); + if (!label_.Empty()) { + dumper->Add(" "); + dumper->Add(std::string(label_)); + } + dumper->Add(";"); } void ContinueStatement::Compile(compiler::PandaGen *pg) const diff --git a/ets2panda/ir/statements/continueStatement.h b/ets2panda/ir/statements/continueStatement.h index 78a1dfda..4b94aa17 100644 --- a/ets2panda/ir/statements/continueStatement.h +++ b/ets2panda/ir/statements/continueStatement.h @@ -31,15 +31,17 @@ namespace ark::es2panda::ir { class ContinueStatement : public Statement { public: explicit ContinueStatement() : Statement(AstNodeType::CONTINUE_STATEMENT) {} - explicit ContinueStatement(Identifier *ident) : Statement(AstNodeType::CONTINUE_STATEMENT), ident_(ident) {} + explicit ContinueStatement(util::StringView const label) : Statement(AstNodeType::CONTINUE_STATEMENT), label_(label) + { + } // NOTE (csabahurton): these friend relationships can be removed once there are getters for private fields friend class checker::ETSAnalyzer; friend class compiler::ETSCompiler; - const Identifier *Ident() const + const util::StringView &Label() const { - return ident_; + return label_; } const ir::AstNode *Target() const @@ -62,7 +64,7 @@ public: } private: - Identifier *ident_ {}; + util::StringView label_ {}; const ir::AstNode *target_ {}; }; } // namespace ark::es2panda::ir diff --git a/ets2panda/ir/statements/labelledStatement.cpp b/ets2panda/ir/statements/labelledStatement.cpp index 7f5c185b..9b5625f9 100644 --- a/ets2panda/ir/statements/labelledStatement.cpp +++ b/ets2panda/ir/statements/labelledStatement.cpp @@ -24,25 +24,22 @@ namespace ark::es2panda::ir { void LabelledStatement::TransformChildren(const NodeTransformer &cb) { - ident_ = cb(ident_)->AsIdentifier(); body_ = cb(body_)->AsStatement(); } void LabelledStatement::Iterate(const NodeTraverser &cb) const { - cb(ident_); cb(body_); } void LabelledStatement::Dump(ir::AstDumper *dumper) const { - dumper->Add({{"type", "LabelledStatement"}, {"label", ident_}, {"body", body_}}); + dumper->Add({{"type", "LabelledStatement"}, {"label", name_}, {"body", body_}}); } void LabelledStatement::Dump(ir::SrcDumper *dumper) const { - ASSERT(ident_ != nullptr); - ident_->Dump(dumper); + dumper->Add(std::string(name_)); dumper->Add(":"); dumper->Endl(); body_->Dump(dumper); diff --git a/ets2panda/ir/statements/labelledStatement.h b/ets2panda/ir/statements/labelledStatement.h index 82e5fe5c..5bc507b2 100644 --- a/ets2panda/ir/statements/labelledStatement.h +++ b/ets2panda/ir/statements/labelledStatement.h @@ -28,8 +28,8 @@ class Identifier; class LabelledStatement : public Statement { public: - explicit LabelledStatement(Identifier *ident, Statement *body) - : Statement(AstNodeType::LABELLED_STATEMENT), ident_(ident), body_(body) + explicit LabelledStatement(util::StringView const name, Statement *body) + : Statement(AstNodeType::LABELLED_STATEMENT), name_(name), body_(body) { } @@ -41,9 +41,9 @@ public: return body_; } - const Identifier *Ident() const + const util::StringView &Name() const { - return ident_; + return name_; } const ir::AstNode *GetReferencedStatement() const; @@ -70,7 +70,7 @@ public: } private: - Identifier *ident_; + util::StringView name_; Statement *body_; }; } // namespace ark::es2panda::ir diff --git a/ets2panda/parser/statementParser.cpp b/ets2panda/parser/statementParser.cpp index 99e669f2..18f8d210 100644 --- a/ets2panda/parser/statementParser.cpp +++ b/ets2panda/parser/statementParser.cpp @@ -460,11 +460,7 @@ ir::BreakStatement *ParserImpl::ParseBreakStatement() ThrowSyntaxError("Undefined label"); } - auto *identNode = AllocNode(label, Allocator()); - identNode->SetReference(); - identNode->SetRange(lexer_->GetToken().Loc()); - - auto *breakStatement = AllocNode(identNode); + auto *breakStatement = AllocNode(label); breakStatement->SetRange({startLoc, lexer_->GetToken().End()}); lexer_->NextToken(); @@ -516,11 +512,7 @@ ir::ContinueStatement *ParserImpl::ParseContinueStatement() ThrowSyntaxError("Undefined label"); } - auto *identNode = AllocNode(label, Allocator()); - identNode->SetReference(); - identNode->SetRange(lexer_->GetToken().Loc()); - - auto *continueStatement = AllocNode(identNode); + auto *continueStatement = AllocNode(label); continueStatement->SetRange({startLoc, lexer_->GetToken().End()}); lexer_->NextToken(); @@ -1007,17 +999,13 @@ ir::LabelledStatement *ParserImpl::ParseLabelledStatement(const lexer::LexerPosi SavedParserContext newCtx(this, ParserStatus::IN_LABELED, actualLabel); - auto *identNode = AllocNode(actualLabel, Allocator()); - identNode->SetReference(); - identNode->SetRange(pos.GetToken().Loc()); - lexer_->NextToken(); ValidateLabeledStatement(Lexer()->GetToken().Type()); ir::Statement *body = ParseStatement(StatementParsingFlags::LABELLED); - auto *labeledStatement = AllocNode(identNode, body); + auto *labeledStatement = AllocNode(actualLabel, body); labeledStatement->SetRange({pos.GetToken().Start(), body->End()}); return labeledStatement; -- Gitee From 0d58c97ce7abca462b9df42e46ecb216ce201efd Mon Sep 17 00:00:00 2001 From: Konstantin Kuznetsov Date: Wed, 28 Feb 2024 16:15:38 +0300 Subject: [PATCH 4/5] Update expected ast trees for parser tests --- ...tchStatementCorrectConversion-expected.txt | 14 +-- .../switchStatementWrongBoxing-expected.txt | 2 +- .../parser/ets/AccessFannkuch-expected.txt | 2 +- .../test/parser/ets/StringBase64-expected.txt | 2 +- ets2panda/test/parser/ets/break-expected.txt | 2 +- .../test/parser/ets/continue-expected.txt | 2 +- .../parser/ets/for_with_break-expected.txt | 2 +- .../ets/labeledDoWhileStatement-expected.txt | 48 +------- .../ets/labeledForStatement-expected.txt | 96 +--------------- .../ets/labeledSwitchStatement-expected.txt | 68 +----------- .../ets/labeledWhileStatement-expected.txt | 98 ++--------------- ets2panda/test/parser/ets/loops-expected.txt | 104 ++---------------- ets2panda/test/parser/ets/switch-expected.txt | 4 +- .../test/parser/ets/switch2-expected.txt | 4 +- .../parser/ets/switch_alive_3-expected.txt | 32 +----- .../parser/ets/switch_alive_4-expected.txt | 4 +- .../ets/switch_char_compare_num-expected.txt | 4 +- ...st_int_compare_char_duplicate-expected.txt | 6 +- .../test/parser/ets/switch_enum-expected.txt | 6 +- .../test/parser/ets/switch_enum2-expected.txt | 4 +- .../switch_enum_case_duplicate-expected.txt | 6 +- .../ets/switch_num_compare_char-expected.txt | 4 +- ...ch_num_compare_char_duplicate-expected.txt | 4 +- .../ets/switch_readonly_member-expected.txt | 6 +- ..._readonly_member_compare_char-expected.txt | 8 +- ...eadonly_member_compare_char_2-expected.txt | 8 +- ...eadonly_member_different_enum-expected.txt | 6 +- ...donly_member_different_enum_2-expected.txt | 6 +- ...eadonly_member_enum_duplicate-expected.txt | 6 +- ...donly_member_number_duplicate-expected.txt | 6 +- .../parser/ets/swtich_not_const-expected.txt | 4 +- 31 files changed, 95 insertions(+), 473 deletions(-) diff --git a/ets2panda/test/compiler/ets/switchStatementCorrectConversion-expected.txt b/ets2panda/test/compiler/ets/switchStatementCorrectConversion-expected.txt index f5a81fbd..7d0099cd 100644 --- a/ets2panda/test/compiler/ets/switchStatementCorrectConversion-expected.txt +++ b/ets2panda/test/compiler/ets/switchStatementCorrectConversion-expected.txt @@ -219,7 +219,7 @@ "consequent": [ { "type": "BreakStatement", - "label": null, + "label": "", "loc": { "start": { "line": 21, @@ -262,7 +262,7 @@ "consequent": [ { "type": "BreakStatement", - "label": null, + "label": "", "loc": { "start": { "line": 23, @@ -305,7 +305,7 @@ "consequent": [ { "type": "BreakStatement", - "label": null, + "label": "", "loc": { "start": { "line": 25, @@ -348,7 +348,7 @@ "consequent": [ { "type": "BreakStatement", - "label": null, + "label": "", "loc": { "start": { "line": 27, @@ -391,7 +391,7 @@ "consequent": [ { "type": "BreakStatement", - "label": null, + "label": "", "loc": { "start": { "line": 29, @@ -634,7 +634,7 @@ "consequent": [ { "type": "BreakStatement", - "label": null, + "label": "", "loc": { "start": { "line": 36, @@ -678,7 +678,7 @@ "consequent": [ { "type": "BreakStatement", - "label": null, + "label": "", "loc": { "start": { "line": 38, diff --git a/ets2panda/test/compiler/ets/switchStatementWrongBoxing-expected.txt b/ets2panda/test/compiler/ets/switchStatementWrongBoxing-expected.txt index f893cf2c..2956874f 100644 --- a/ets2panda/test/compiler/ets/switchStatementWrongBoxing-expected.txt +++ b/ets2panda/test/compiler/ets/switchStatementWrongBoxing-expected.txt @@ -319,7 +319,7 @@ "consequent": [ { "type": "BreakStatement", - "label": null, + "label": "", "loc": { "start": { "line": 23, diff --git a/ets2panda/test/parser/ets/AccessFannkuch-expected.txt b/ets2panda/test/parser/ets/AccessFannkuch-expected.txt index bf878c72..1c188e09 100644 --- a/ets2panda/test/parser/ets/AccessFannkuch-expected.txt +++ b/ets2panda/test/parser/ets/AccessFannkuch-expected.txt @@ -4619,7 +4619,7 @@ }, "consequent": { "type": "BreakStatement", - "label": null, + "label": "", "loc": { "start": { "line": 78, diff --git a/ets2panda/test/parser/ets/StringBase64-expected.txt b/ets2panda/test/parser/ets/StringBase64-expected.txt index c47c0dce..a29f1210 100644 --- a/ets2panda/test/parser/ets/StringBase64-expected.txt +++ b/ets2panda/test/parser/ets/StringBase64-expected.txt @@ -8407,7 +8407,7 @@ "statements": [ { "type": "ContinueStatement", - "label": null, + "label": "", "loc": { "start": { "line": 54, diff --git a/ets2panda/test/parser/ets/break-expected.txt b/ets2panda/test/parser/ets/break-expected.txt index c1658611..ed28aa48 100644 --- a/ets2panda/test/parser/ets/break-expected.txt +++ b/ets2panda/test/parser/ets/break-expected.txt @@ -480,7 +480,7 @@ }, "consequent": { "type": "BreakStatement", - "label": null, + "label": "", "loc": { "start": { "line": 19, diff --git a/ets2panda/test/parser/ets/continue-expected.txt b/ets2panda/test/parser/ets/continue-expected.txt index cd8cfe6f..55230739 100644 --- a/ets2panda/test/parser/ets/continue-expected.txt +++ b/ets2panda/test/parser/ets/continue-expected.txt @@ -480,7 +480,7 @@ }, "consequent": { "type": "ContinueStatement", - "label": null, + "label": "", "loc": { "start": { "line": 19, diff --git a/ets2panda/test/parser/ets/for_with_break-expected.txt b/ets2panda/test/parser/ets/for_with_break-expected.txt index ec654926..371da34c 100644 --- a/ets2panda/test/parser/ets/for_with_break-expected.txt +++ b/ets2panda/test/parser/ets/for_with_break-expected.txt @@ -618,7 +618,7 @@ "statements": [ { "type": "BreakStatement", - "label": null, + "label": "", "loc": { "start": { "line": 23, diff --git a/ets2panda/test/parser/ets/labeledDoWhileStatement-expected.txt b/ets2panda/test/parser/ets/labeledDoWhileStatement-expected.txt index bac5b0dd..60e94162 100644 --- a/ets2panda/test/parser/ets/labeledDoWhileStatement-expected.txt +++ b/ets2panda/test/parser/ets/labeledDoWhileStatement-expected.txt @@ -265,21 +265,7 @@ }, { "type": "LabelledStatement", - "label": { - "type": "Identifier", - "name": "label1", - "decorators": [], - "loc": { - "start": { - "line": 19, - "column": 3 - }, - "end": { - "line": 19, - "column": 9 - } - } - }, + "label": "label1", "body": { "type": "DoWhileStatement", "body": { @@ -419,21 +405,7 @@ "statements": [ { "type": "ContinueStatement", - "label": { - "type": "Identifier", - "name": "label1", - "decorators": [], - "loc": { - "start": { - "line": 23, - "column": 16 - }, - "end": { - "line": 23, - "column": 22 - } - } - }, + "label": "label1", "loc": { "start": { "line": 23, @@ -462,21 +434,7 @@ "statements": [ { "type": "BreakStatement", - "label": { - "type": "Identifier", - "name": "label1", - "decorators": [], - "loc": { - "start": { - "line": 25, - "column": 13 - }, - "end": { - "line": 25, - "column": 19 - } - } - }, + "label": "label1", "loc": { "start": { "line": 25, diff --git a/ets2panda/test/parser/ets/labeledForStatement-expected.txt b/ets2panda/test/parser/ets/labeledForStatement-expected.txt index cc597d92..b4d3d6be 100644 --- a/ets2panda/test/parser/ets/labeledForStatement-expected.txt +++ b/ets2panda/test/parser/ets/labeledForStatement-expected.txt @@ -207,21 +207,7 @@ "statements": [ { "type": "LabelledStatement", - "label": { - "type": "Identifier", - "name": "label1", - "decorators": [], - "loc": { - "start": { - "line": 17, - "column": 3 - }, - "end": { - "line": 17, - "column": 9 - } - } - }, + "label": "label1", "body": { "type": "ForUpdateStatement", "init": { @@ -408,21 +394,7 @@ "statements": [ { "type": "ContinueStatement", - "label": { - "type": "Identifier", - "name": "label1", - "decorators": [], - "loc": { - "start": { - "line": 20, - "column": 16 - }, - "end": { - "line": 20, - "column": 22 - } - } - }, + "label": "label1", "loc": { "start": { "line": 20, @@ -451,21 +423,7 @@ "statements": [ { "type": "BreakStatement", - "label": { - "type": "Identifier", - "name": "label1", - "decorators": [], - "loc": { - "start": { - "line": 22, - "column": 13 - }, - "end": { - "line": 22, - "column": 19 - } - } - }, + "label": "label1", "loc": { "start": { "line": 22, @@ -536,21 +494,7 @@ }, { "type": "LabelledStatement", - "label": { - "type": "Identifier", - "name": "label2", - "decorators": [], - "loc": { - "start": { - "line": 26, - "column": 3 - }, - "end": { - "line": 26, - "column": 9 - } - } - }, + "label": "label2", "body": { "type": "ForUpdateStatement", "init": { @@ -930,21 +874,7 @@ "statements": [ { "type": "ContinueStatement", - "label": { - "type": "Identifier", - "name": "label2", - "decorators": [], - "loc": { - "start": { - "line": 30, - "column": 18 - }, - "end": { - "line": 30, - "column": 24 - } - } - }, + "label": "label2", "loc": { "start": { "line": 30, @@ -973,21 +903,7 @@ "statements": [ { "type": "BreakStatement", - "label": { - "type": "Identifier", - "name": "label2", - "decorators": [], - "loc": { - "start": { - "line": 32, - "column": 15 - }, - "end": { - "line": 32, - "column": 21 - } - } - }, + "label": "label2", "loc": { "start": { "line": 32, diff --git a/ets2panda/test/parser/ets/labeledSwitchStatement-expected.txt b/ets2panda/test/parser/ets/labeledSwitchStatement-expected.txt index a8ffaf63..8fc72b69 100644 --- a/ets2panda/test/parser/ets/labeledSwitchStatement-expected.txt +++ b/ets2panda/test/parser/ets/labeledSwitchStatement-expected.txt @@ -336,21 +336,7 @@ }, { "type": "LabelledStatement", - "label": { - "type": "Identifier", - "name": "label1", - "decorators": [], - "loc": { - "start": { - "line": 20, - "column": 5 - }, - "end": { - "line": 20, - "column": 11 - } - } - }, + "label": "label1", "body": { "type": "ForUpdateStatement", "init": { @@ -608,7 +594,7 @@ }, { "type": "BreakStatement", - "label": null, + "label": "", "loc": { "start": { "line": 26, @@ -707,21 +693,7 @@ }, { "type": "ContinueStatement", - "label": { - "type": "Identifier", - "name": "label1", - "decorators": [], - "loc": { - "start": { - "line": 29, - "column": 26 - }, - "end": { - "line": 29, - "column": 32 - } - } - }, + "label": "label1", "loc": { "start": { "line": 29, @@ -1266,21 +1238,7 @@ "statements": [ { "type": "LabelledStatement", - "label": { - "type": "Identifier", - "name": "label1", - "decorators": [], - "loc": { - "start": { - "line": 41, - "column": 9 - }, - "end": { - "line": 41, - "column": 15 - } - } - }, + "label": "label1", "body": { "type": "SwitchStatement", "discriminant": { @@ -1402,7 +1360,7 @@ }, { "type": "BreakStatement", - "label": null, + "label": "", "loc": { "start": { "line": 46, @@ -1501,21 +1459,7 @@ }, { "type": "BreakStatement", - "label": { - "type": "Identifier", - "name": "label1", - "decorators": [], - "loc": { - "start": { - "line": 49, - "column": 23 - }, - "end": { - "line": 49, - "column": 29 - } - } - }, + "label": "label1", "loc": { "start": { "line": 49, diff --git a/ets2panda/test/parser/ets/labeledWhileStatement-expected.txt b/ets2panda/test/parser/ets/labeledWhileStatement-expected.txt index c7ac60a0..45b5e30e 100644 --- a/ets2panda/test/parser/ets/labeledWhileStatement-expected.txt +++ b/ets2panda/test/parser/ets/labeledWhileStatement-expected.txt @@ -381,21 +381,7 @@ }, { "type": "LabelledStatement", - "label": { - "type": "Identifier", - "name": "label1", - "decorators": [], - "loc": { - "start": { - "line": 21, - "column": 3 - }, - "end": { - "line": 21, - "column": 9 - } - } - }, + "label": "label1", "body": { "type": "WhileStatement", "test": { @@ -565,21 +551,7 @@ }, { "type": "ContinueStatement", - "label": { - "type": "Identifier", - "name": "label1", - "decorators": [], - "loc": { - "start": { - "line": 25, - "column": 16 - }, - "end": { - "line": 25, - "column": 22 - } - } - }, + "label": "label1", "loc": { "start": { "line": 25, @@ -608,21 +580,7 @@ "statements": [ { "type": "BreakStatement", - "label": { - "type": "Identifier", - "name": "label1", - "decorators": [], - "loc": { - "start": { - "line": 27, - "column": 13 - }, - "end": { - "line": 27, - "column": 19 - } - } - }, + "label": "label1", "loc": { "start": { "line": 27, @@ -693,21 +651,7 @@ }, { "type": "LabelledStatement", - "label": { - "type": "Identifier", - "name": "label2", - "decorators": [], - "loc": { - "start": { - "line": 31, - "column": 3 - }, - "end": { - "line": 31, - "column": 9 - } - } - }, + "label": "label2", "body": { "type": "WhileStatement", "test": { @@ -806,7 +750,7 @@ "statements": [ { "type": "BreakStatement", - "label": null, + "label": "", "loc": { "start": { "line": 34, @@ -941,21 +885,7 @@ "statements": [ { "type": "BreakStatement", - "label": { - "type": "Identifier", - "name": "label2", - "decorators": [], - "loc": { - "start": { - "line": 39, - "column": 15 - }, - "end": { - "line": 39, - "column": 21 - } - } - }, + "label": "label2", "loc": { "start": { "line": 39, @@ -1084,21 +1014,7 @@ }, { "type": "ContinueStatement", - "label": { - "type": "Identifier", - "name": "label2", - "decorators": [], - "loc": { - "start": { - "line": 43, - "column": 18 - }, - "end": { - "line": 43, - "column": 24 - } - } - }, + "label": "label2", "loc": { "start": { "line": 43, diff --git a/ets2panda/test/parser/ets/loops-expected.txt b/ets2panda/test/parser/ets/loops-expected.txt index c30aa0c5..12440139 100644 --- a/ets2panda/test/parser/ets/loops-expected.txt +++ b/ets2panda/test/parser/ets/loops-expected.txt @@ -340,7 +340,7 @@ }, "body": { "type": "ContinueStatement", - "label": null, + "label": "", "loc": { "start": { "line": 17, @@ -541,7 +541,7 @@ }, "body": { "type": "ContinueStatement", - "label": null, + "label": "", "loc": { "start": { "line": 19, @@ -787,7 +787,7 @@ "statements": [ { "type": "ContinueStatement", - "label": null, + "label": "", "loc": { "start": { "line": 23, @@ -1017,7 +1017,7 @@ }, "body": { "type": "BreakStatement", - "label": null, + "label": "", "loc": { "start": { "line": 31, @@ -1626,21 +1626,7 @@ "statements": [ { "type": "LabelledStatement", - "label": { - "type": "Identifier", - "name": "loop1", - "decorators": [], - "loc": { - "start": { - "line": 47, - "column": 3 - }, - "end": { - "line": 47, - "column": 8 - } - } - }, + "label": "loop1", "body": { "type": "ForUpdateStatement", "init": { @@ -1779,21 +1765,7 @@ "statements": [ { "type": "LabelledStatement", - "label": { - "type": "Identifier", - "name": "loop2", - "decorators": [], - "loc": { - "start": { - "line": 49, - "column": 5 - }, - "end": { - "line": 49, - "column": 10 - } - } - }, + "label": "loop2", "body": { "type": "ForUpdateStatement", "init": { @@ -1932,21 +1904,7 @@ "statements": [ { "type": "BreakStatement", - "label": { - "type": "Identifier", - "name": "loop1", - "decorators": [], - "loc": { - "start": { - "line": 51, - "column": 13 - }, - "end": { - "line": 51, - "column": 18 - } - } - }, + "label": "loop1", "loc": { "start": { "line": 51, @@ -2164,21 +2122,7 @@ "statements": [ { "type": "LabelledStatement", - "label": { - "type": "Identifier", - "name": "loop1", - "decorators": [], - "loc": { - "start": { - "line": 58, - "column": 3 - }, - "end": { - "line": 58, - "column": 8 - } - } - }, + "label": "loop1", "body": { "type": "ForUpdateStatement", "init": { @@ -2317,21 +2261,7 @@ "statements": [ { "type": "LabelledStatement", - "label": { - "type": "Identifier", - "name": "loop2", - "decorators": [], - "loc": { - "start": { - "line": 60, - "column": 5 - }, - "end": { - "line": 60, - "column": 10 - } - } - }, + "label": "loop2", "body": { "type": "ForUpdateStatement", "init": { @@ -2470,21 +2400,7 @@ "statements": [ { "type": "ContinueStatement", - "label": { - "type": "Identifier", - "name": "loop1", - "decorators": [], - "loc": { - "start": { - "line": 62, - "column": 16 - }, - "end": { - "line": 62, - "column": 21 - } - } - }, + "label": "loop1", "loc": { "start": { "line": 62, diff --git a/ets2panda/test/parser/ets/switch-expected.txt b/ets2panda/test/parser/ets/switch-expected.txt index bf956fcd..ad6b40e7 100644 --- a/ets2panda/test/parser/ets/switch-expected.txt +++ b/ets2panda/test/parser/ets/switch-expected.txt @@ -511,7 +511,7 @@ }, { "type": "BreakStatement", - "label": null, + "label": "", "loc": { "start": { "line": 24, @@ -610,7 +610,7 @@ }, { "type": "BreakStatement", - "label": null, + "label": "", "loc": { "start": { "line": 27, diff --git a/ets2panda/test/parser/ets/switch2-expected.txt b/ets2panda/test/parser/ets/switch2-expected.txt index 0f1939f6..c63e4340 100644 --- a/ets2panda/test/parser/ets/switch2-expected.txt +++ b/ets2panda/test/parser/ets/switch2-expected.txt @@ -468,7 +468,7 @@ }, { "type": "BreakStatement", - "label": null, + "label": "", "loc": { "start": { "line": 24, @@ -567,7 +567,7 @@ }, { "type": "BreakStatement", - "label": null, + "label": "", "loc": { "start": { "line": 27, diff --git a/ets2panda/test/parser/ets/switch_alive_3-expected.txt b/ets2panda/test/parser/ets/switch_alive_3-expected.txt index 192c2db5..6aae12bf 100644 --- a/ets2panda/test/parser/ets/switch_alive_3-expected.txt +++ b/ets2panda/test/parser/ets/switch_alive_3-expected.txt @@ -250,21 +250,7 @@ }, { "type": "LabelledStatement", - "label": { - "type": "Identifier", - "name": "label", - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 2 - }, - "end": { - "line": 18, - "column": 7 - } - } - }, + "label": "label", "body": { "type": "SwitchStatement", "discriminant": { @@ -430,21 +416,7 @@ "consequent": [ { "type": "BreakStatement", - "label": { - "type": "Identifier", - "name": "label", - "decorators": [], - "loc": { - "start": { - "line": 24, - "column": 10 - }, - "end": { - "line": 24, - "column": 15 - } - } - }, + "label": "label", "loc": { "start": { "line": 24, diff --git a/ets2panda/test/parser/ets/switch_alive_4-expected.txt b/ets2panda/test/parser/ets/switch_alive_4-expected.txt index 82326cbb..2f560957 100644 --- a/ets2panda/test/parser/ets/switch_alive_4-expected.txt +++ b/ets2panda/test/parser/ets/switch_alive_4-expected.txt @@ -256,7 +256,7 @@ "consequent": [ { "type": "BreakStatement", - "label": null, + "label": "", "loc": { "start": { "line": 19, @@ -299,7 +299,7 @@ "consequent": [ { "type": "BreakStatement", - "label": null, + "label": "", "loc": { "start": { "line": 21, diff --git a/ets2panda/test/parser/ets/switch_char_compare_num-expected.txt b/ets2panda/test/parser/ets/switch_char_compare_num-expected.txt index 8036ad04..283fe753 100644 --- a/ets2panda/test/parser/ets/switch_char_compare_num-expected.txt +++ b/ets2panda/test/parser/ets/switch_char_compare_num-expected.txt @@ -259,7 +259,7 @@ "consequent": [ { "type": "BreakStatement", - "label": null, + "label": "", "loc": { "start": { "line": 20, @@ -302,7 +302,7 @@ "consequent": [ { "type": "BreakStatement", - "label": null, + "label": "", "loc": { "start": { "line": 22, diff --git a/ets2panda/test/parser/ets/switch_const_int_compare_char_duplicate-expected.txt b/ets2panda/test/parser/ets/switch_const_int_compare_char_duplicate-expected.txt index f9440905..6d9cfea9 100644 --- a/ets2panda/test/parser/ets/switch_const_int_compare_char_duplicate-expected.txt +++ b/ets2panda/test/parser/ets/switch_const_int_compare_char_duplicate-expected.txt @@ -331,7 +331,7 @@ "consequent": [ { "type": "BreakStatement", - "label": null, + "label": "", "loc": { "start": { "line": 21, @@ -374,7 +374,7 @@ "consequent": [ { "type": "BreakStatement", - "label": null, + "label": "", "loc": { "start": { "line": 23, @@ -404,7 +404,7 @@ "consequent": [ { "type": "BreakStatement", - "label": null, + "label": "", "loc": { "start": { "line": 25, diff --git a/ets2panda/test/parser/ets/switch_enum-expected.txt b/ets2panda/test/parser/ets/switch_enum-expected.txt index f4d9debe..2dd8d965 100644 --- a/ets2panda/test/parser/ets/switch_enum-expected.txt +++ b/ets2panda/test/parser/ets/switch_enum-expected.txt @@ -460,7 +460,7 @@ "consequent": [ { "type": "BreakStatement", - "label": null, + "label": "", "loc": { "start": { "line": 20, @@ -534,7 +534,7 @@ "consequent": [ { "type": "BreakStatement", - "label": null, + "label": "", "loc": { "start": { "line": 21, @@ -564,7 +564,7 @@ "consequent": [ { "type": "BreakStatement", - "label": null, + "label": "", "loc": { "start": { "line": 23, diff --git a/ets2panda/test/parser/ets/switch_enum2-expected.txt b/ets2panda/test/parser/ets/switch_enum2-expected.txt index 59ed0f5c..d8214510 100644 --- a/ets2panda/test/parser/ets/switch_enum2-expected.txt +++ b/ets2panda/test/parser/ets/switch_enum2-expected.txt @@ -429,7 +429,7 @@ "consequent": [ { "type": "BreakStatement", - "label": null, + "label": "", "loc": { "start": { "line": 20, @@ -459,7 +459,7 @@ "consequent": [ { "type": "BreakStatement", - "label": null, + "label": "", "loc": { "start": { "line": 22, diff --git a/ets2panda/test/parser/ets/switch_enum_case_duplicate-expected.txt b/ets2panda/test/parser/ets/switch_enum_case_duplicate-expected.txt index 7a806708..6bf4b5f3 100644 --- a/ets2panda/test/parser/ets/switch_enum_case_duplicate-expected.txt +++ b/ets2panda/test/parser/ets/switch_enum_case_duplicate-expected.txt @@ -519,7 +519,7 @@ "consequent": [ { "type": "BreakStatement", - "label": null, + "label": "", "loc": { "start": { "line": 24, @@ -593,7 +593,7 @@ "consequent": [ { "type": "BreakStatement", - "label": null, + "label": "", "loc": { "start": { "line": 26, @@ -667,7 +667,7 @@ "consequent": [ { "type": "BreakStatement", - "label": null, + "label": "", "loc": { "start": { "line": 28, diff --git a/ets2panda/test/parser/ets/switch_num_compare_char-expected.txt b/ets2panda/test/parser/ets/switch_num_compare_char-expected.txt index 2882c108..3ec3a360 100644 --- a/ets2panda/test/parser/ets/switch_num_compare_char-expected.txt +++ b/ets2panda/test/parser/ets/switch_num_compare_char-expected.txt @@ -259,7 +259,7 @@ "consequent": [ { "type": "BreakStatement", - "label": null, + "label": "", "loc": { "start": { "line": 20, @@ -302,7 +302,7 @@ "consequent": [ { "type": "BreakStatement", - "label": null, + "label": "", "loc": { "start": { "line": 22, diff --git a/ets2panda/test/parser/ets/switch_num_compare_char_duplicate-expected.txt b/ets2panda/test/parser/ets/switch_num_compare_char_duplicate-expected.txt index e57b79c7..17d261e9 100644 --- a/ets2panda/test/parser/ets/switch_num_compare_char_duplicate-expected.txt +++ b/ets2panda/test/parser/ets/switch_num_compare_char_duplicate-expected.txt @@ -259,7 +259,7 @@ "consequent": [ { "type": "BreakStatement", - "label": null, + "label": "", "loc": { "start": { "line": 20, @@ -302,7 +302,7 @@ "consequent": [ { "type": "BreakStatement", - "label": null, + "label": "", "loc": { "start": { "line": 22, diff --git a/ets2panda/test/parser/ets/switch_readonly_member-expected.txt b/ets2panda/test/parser/ets/switch_readonly_member-expected.txt index a0429f6a..5371c7c8 100644 --- a/ets2panda/test/parser/ets/switch_readonly_member-expected.txt +++ b/ets2panda/test/parser/ets/switch_readonly_member-expected.txt @@ -664,7 +664,7 @@ "consequent": [ { "type": "BreakStatement", - "label": null, + "label": "", "loc": { "start": { "line": 28, @@ -738,7 +738,7 @@ "consequent": [ { "type": "BreakStatement", - "label": null, + "label": "", "loc": { "start": { "line": 30, @@ -768,7 +768,7 @@ "consequent": [ { "type": "BreakStatement", - "label": null, + "label": "", "loc": { "start": { "line": 31, diff --git a/ets2panda/test/parser/ets/switch_readonly_member_compare_char-expected.txt b/ets2panda/test/parser/ets/switch_readonly_member_compare_char-expected.txt index 04b54186..9305a669 100644 --- a/ets2panda/test/parser/ets/switch_readonly_member_compare_char-expected.txt +++ b/ets2panda/test/parser/ets/switch_readonly_member_compare_char-expected.txt @@ -664,7 +664,7 @@ "consequent": [ { "type": "BreakStatement", - "label": null, + "label": "", "loc": { "start": { "line": 28, @@ -738,7 +738,7 @@ "consequent": [ { "type": "BreakStatement", - "label": null, + "label": "", "loc": { "start": { "line": 30, @@ -781,7 +781,7 @@ "consequent": [ { "type": "BreakStatement", - "label": null, + "label": "", "loc": { "start": { "line": 32, @@ -811,7 +811,7 @@ "consequent": [ { "type": "BreakStatement", - "label": null, + "label": "", "loc": { "start": { "line": 33, diff --git a/ets2panda/test/parser/ets/switch_readonly_member_compare_char_2-expected.txt b/ets2panda/test/parser/ets/switch_readonly_member_compare_char_2-expected.txt index 0f99422e..cb2b9941 100644 --- a/ets2panda/test/parser/ets/switch_readonly_member_compare_char_2-expected.txt +++ b/ets2panda/test/parser/ets/switch_readonly_member_compare_char_2-expected.txt @@ -633,7 +633,7 @@ "consequent": [ { "type": "BreakStatement", - "label": null, + "label": "", "loc": { "start": { "line": 28, @@ -707,7 +707,7 @@ "consequent": [ { "type": "BreakStatement", - "label": null, + "label": "", "loc": { "start": { "line": 30, @@ -781,7 +781,7 @@ "consequent": [ { "type": "BreakStatement", - "label": null, + "label": "", "loc": { "start": { "line": 32, @@ -811,7 +811,7 @@ "consequent": [ { "type": "BreakStatement", - "label": null, + "label": "", "loc": { "start": { "line": 33, diff --git a/ets2panda/test/parser/ets/switch_readonly_member_different_enum-expected.txt b/ets2panda/test/parser/ets/switch_readonly_member_different_enum-expected.txt index 8ce63778..69de309c 100644 --- a/ets2panda/test/parser/ets/switch_readonly_member_different_enum-expected.txt +++ b/ets2panda/test/parser/ets/switch_readonly_member_different_enum-expected.txt @@ -1071,7 +1071,7 @@ "consequent": [ { "type": "BreakStatement", - "label": null, + "label": "", "loc": { "start": { "line": 36, @@ -1145,7 +1145,7 @@ "consequent": [ { "type": "BreakStatement", - "label": null, + "label": "", "loc": { "start": { "line": 38, @@ -1175,7 +1175,7 @@ "consequent": [ { "type": "BreakStatement", - "label": null, + "label": "", "loc": { "start": { "line": 39, diff --git a/ets2panda/test/parser/ets/switch_readonly_member_different_enum_2-expected.txt b/ets2panda/test/parser/ets/switch_readonly_member_different_enum_2-expected.txt index 5891ffb6..a6a6fe04 100644 --- a/ets2panda/test/parser/ets/switch_readonly_member_different_enum_2-expected.txt +++ b/ets2panda/test/parser/ets/switch_readonly_member_different_enum_2-expected.txt @@ -1071,7 +1071,7 @@ "consequent": [ { "type": "BreakStatement", - "label": null, + "label": "", "loc": { "start": { "line": 35, @@ -1145,7 +1145,7 @@ "consequent": [ { "type": "BreakStatement", - "label": null, + "label": "", "loc": { "start": { "line": 37, @@ -1175,7 +1175,7 @@ "consequent": [ { "type": "BreakStatement", - "label": null, + "label": "", "loc": { "start": { "line": 38, diff --git a/ets2panda/test/parser/ets/switch_readonly_member_enum_duplicate-expected.txt b/ets2panda/test/parser/ets/switch_readonly_member_enum_duplicate-expected.txt index c37cacff..ad5e2627 100644 --- a/ets2panda/test/parser/ets/switch_readonly_member_enum_duplicate-expected.txt +++ b/ets2panda/test/parser/ets/switch_readonly_member_enum_duplicate-expected.txt @@ -1071,7 +1071,7 @@ "consequent": [ { "type": "BreakStatement", - "label": null, + "label": "", "loc": { "start": { "line": 36, @@ -1145,7 +1145,7 @@ "consequent": [ { "type": "BreakStatement", - "label": null, + "label": "", "loc": { "start": { "line": 38, @@ -1175,7 +1175,7 @@ "consequent": [ { "type": "BreakStatement", - "label": null, + "label": "", "loc": { "start": { "line": 39, diff --git a/ets2panda/test/parser/ets/switch_readonly_member_number_duplicate-expected.txt b/ets2panda/test/parser/ets/switch_readonly_member_number_duplicate-expected.txt index 2ce1ff96..ba97b752 100644 --- a/ets2panda/test/parser/ets/switch_readonly_member_number_duplicate-expected.txt +++ b/ets2panda/test/parser/ets/switch_readonly_member_number_duplicate-expected.txt @@ -664,7 +664,7 @@ "consequent": [ { "type": "BreakStatement", - "label": null, + "label": "", "loc": { "start": { "line": 28, @@ -738,7 +738,7 @@ "consequent": [ { "type": "BreakStatement", - "label": null, + "label": "", "loc": { "start": { "line": 30, @@ -768,7 +768,7 @@ "consequent": [ { "type": "BreakStatement", - "label": null, + "label": "", "loc": { "start": { "line": 31, diff --git a/ets2panda/test/parser/ets/swtich_not_const-expected.txt b/ets2panda/test/parser/ets/swtich_not_const-expected.txt index a049cd59..1dbeda62 100644 --- a/ets2panda/test/parser/ets/swtich_not_const-expected.txt +++ b/ets2panda/test/parser/ets/swtich_not_const-expected.txt @@ -318,7 +318,7 @@ "consequent": [ { "type": "BreakStatement", - "label": null, + "label": "", "loc": { "start": { "line": 21, @@ -361,7 +361,7 @@ "consequent": [ { "type": "BreakStatement", - "label": null, + "label": "", "loc": { "start": { "line": 23, -- Gitee From 300d4ab8cda051d434075984e0f9fc3c30e4e877 Mon Sep 17 00:00:00 2001 From: Konstantin Kuznetsov Date: Thu, 22 Feb 2024 09:55:16 +0300 Subject: [PATCH 5/5] Fixes for reference identifiers --- ets2panda/checker/ETSAnalyzer.cpp | 8 ++ ets2panda/compiler/core/ASTVerifier.cpp | 114 +++++++++++++++++- .../ets/interfacePropertyDeclarations.cpp | 7 +- .../compiler/lowering/ets/unionLowering.cpp | 6 +- ets2panda/parser/ETSparser.cpp | 2 - 5 files changed, 129 insertions(+), 8 deletions(-) diff --git a/ets2panda/checker/ETSAnalyzer.cpp b/ets2panda/checker/ETSAnalyzer.cpp index 55ea3031..f55b72e3 100644 --- a/ets2panda/checker/ETSAnalyzer.cpp +++ b/ets2panda/checker/ETSAnalyzer.cpp @@ -1015,6 +1015,12 @@ static checker::Signature *ResolveCallForETSExtensionFuncHelperType(checker::ETS type->ClassMethodType()->CallSignatures(), expr, expr->Start(), checker::TypeRelationFlag::NO_THROW); if (signature != nullptr) { + if (expr->Callee()->IsMemberExpression()) { + auto memberExpr = expr->Callee()->AsMemberExpression(); + auto var = type->ClassMethodType()->Variable(); + memberExpr->Property()->AsIdentifier()->SetVariable(var); + } + return signature; } @@ -1290,6 +1296,7 @@ checker::Type *ETSAnalyzer::SetAndAdjustType(ETSChecker *checker, ir::MemberExpr expr->SetObjectType(objectType); auto [resType, resVar] = expr->ResolveObjectMember(checker); expr->SetPropVar(resVar); + expr->Property()->AsIdentifier()->SetVariable(resVar); return expr->AdjustType(checker, resType); } @@ -1336,6 +1343,7 @@ checker::Type *ETSAnalyzer::Check(ir::MemberExpression *expr) const checker->AddBoxingUnboxingFlagsToNode(expr, expr->ObjType()); auto [resType, resVar] = expr->ResolveObjectMember(checker); expr->SetPropVar(resVar); + expr->Property()->AsIdentifier()->SetVariable(resVar); return expr->AdjustType(checker, resType); } diff --git a/ets2panda/compiler/core/ASTVerifier.cpp b/ets2panda/compiler/core/ASTVerifier.cpp index c15a8bc0..eb590a55 100644 --- a/ets2panda/compiler/core/ASTVerifier.cpp +++ b/ets2panda/compiler/core/ASTVerifier.cpp @@ -435,6 +435,42 @@ public: return {CheckDecision::CORRECT, CheckAction::CONTINUE}; } + const auto *id = ast->AsIdentifier(); + if (id->Parent() != nullptr && id->Parent()->IsMemberExpression() && id->Name().Is("length")) { + // NOTE(kkonsw): confirm whether this case should be allowed + return {CheckDecision::CORRECT, CheckAction::CONTINUE}; + } + + if (id->Parent() != nullptr && id->Parent()->IsLabelledStatement()) { + // NOTE(kkonsw): confirm whether this case should be allowed + return {CheckDecision::CORRECT, CheckAction::CONTINUE}; + } + + if (id->Parent()->IsImportSpecifier()) { + // NOTE(kkonsw): confirm whether this case should be allowed + return {CheckDecision::CORRECT, CheckAction::CONTINUE}; + } + + if (id->Parent()->IsImportNamespaceSpecifier()) { + // NOTE(kkonsw): confirm whether this case should be allowed + return {CheckDecision::CORRECT, CheckAction::CONTINUE}; + } + + if (id->Parent()->IsImportDefaultSpecifier()) { + // NOTE(kkonsw): confirm whether this case should be allowed + return {CheckDecision::CORRECT, CheckAction::CONTINUE}; + } + + if (id->Parent()->IsTSQualifiedName()) { + // NOTE(kkonsw): confirm whether this case should be allowed + return {CheckDecision::CORRECT, CheckAction::CONTINUE}; + } + + if (id->Parent()->Parent() != nullptr && id->Parent()->Parent()->IsETSNewClassInstanceExpression()) { + // NOTE(kkonsw): confirm whether this case should be allowed + return {CheckDecision::CORRECT, CheckAction::CONTINUE}; + } + /* * NOTICE: That is temporary fix for identifies without variable * That should be removed in future after fix issues in @@ -446,7 +482,16 @@ public: return {CheckDecision::CORRECT, CheckAction::CONTINUE}; } - const auto *id = ast->AsIdentifier(); + // NOTE(kkonsw): skip package declarations + auto parent = ast->Parent(); + while (parent != nullptr) { + if (parent->IsETSPackageDeclaration()) { + return {CheckDecision::CORRECT, CheckAction::CONTINUE}; + } + + parent = parent->Parent(); + } + ctx.AddCheckMessage("NULL_VARIABLE", *id, id->Start()); return {CheckDecision::INCORRECT, CheckAction::CONTINUE}; } @@ -603,6 +648,52 @@ public: return std::nullopt; } + const auto *id = ast->AsIdentifier(); + if (id->Parent()->IsMemberExpression() && id->Name().Is("length")) { + // NOTE(kkonsw): confirm whether this case should be allowed + return std::nullopt; + } + + if (id->Parent()->IsLabelledStatement()) { + // NOTE(kkonsw): confirm whether this case should be allowed + return std::nullopt; + } + + if (id->Parent()->IsImportSpecifier()) { + // NOTE(kkonsw): confirm whether this case should be allowed + return std::nullopt; + } + + if (id->Parent()->IsImportNamespaceSpecifier()) { + // NOTE(kkonsw): confirm whether this case should be allowed + return std::nullopt; + } + + if (id->Parent()->IsImportDefaultSpecifier()) { + // NOTE(kkonsw): confirm whether this case should be allowed + return std::nullopt; + } + + if (id->Parent()->IsTSQualifiedName()) { + // NOTE(kkonsw): confirm whether this case should be allowed + return std::nullopt; + } + + if (id->Parent()->Parent() != nullptr && id->Parent()->Parent()->IsETSNewClassInstanceExpression()) { + // NOTE(kkonsw): confirm whether this case should be allowed + return std::nullopt; + } + + // NOTE(kkonsw): skip package declarations + auto parent = ast->Parent(); + while (parent != nullptr) { + if (parent->IsETSPackageDeclaration()) { + return std::nullopt; + } + + parent = parent->Parent(); + } + /* * NOTICE: That is temporary exclusion for identifies without variable and scope * Should removed in future @@ -725,7 +816,28 @@ public: const auto node = scope->Node(); auto result = std::make_tuple(CheckDecision::CORRECT, CheckAction::CONTINUE); if (!IsContainedIn(ast, node)) { + if (node->Parent() != nullptr && node->Parent()->IsCatchClause()) { + // NOTE(kkonsw): confirm whether this case should be allowed + return {CheckDecision::CORRECT, CheckAction::CONTINUE}; + } + result = {CheckDecision::INCORRECT, CheckAction::CONTINUE}; + + // NOTE(kkonsw): skip check for lambdas with references outside of lambda + auto parent = node->Parent(); + while (parent != nullptr) { + if (parent->IsFunctionExpression()) { + auto script = parent->AsFunctionExpression()->Function(); + if (script->Id()->Name().Utf8().find("lambda$invoke$") == 0) { + return {CheckDecision::CORRECT, CheckAction::CONTINUE}; + } + + break; + } + + parent = parent->Parent(); + } + ctx.AddCheckMessage("VARIABLE_NOT_ENCLOSE_SCOPE", *ast, ast->Start()); } if (!IsContainedIn(scope, encloseScope)) { diff --git a/ets2panda/compiler/lowering/ets/interfacePropertyDeclarations.cpp b/ets2panda/compiler/lowering/ets/interfacePropertyDeclarations.cpp index 9e099a1f..7f4ad112 100644 --- a/ets2panda/compiler/lowering/ets/interfacePropertyDeclarations.cpp +++ b/ets2panda/compiler/lowering/ets/interfacePropertyDeclarations.cpp @@ -76,6 +76,7 @@ static ir::MethodDefinition *GenerateGetterOrSetter(checker::ETSChecker *const c auto var = functionScope->AddDecl(checker->Allocator(), decl, ScriptExtension::ETS); methodIdent->SetVariable(var); + methodIdent->SetTsTypeAnnotation(nullptr); auto *funcExpr = checker->AllocNode(func); funcExpr->SetRange(func->Range()); @@ -94,8 +95,8 @@ static ir::MethodDefinition *GenerateGetterOrSetter(checker::ETSChecker *const c return method; } -static ir::Expression *UpdateInterfacePropertys(checker::ETSChecker *const checker, - ir::TSInterfaceBody *const interface) +static ir::Expression *UpdateInterfaceProperties(checker::ETSChecker *const checker, + ir::TSInterfaceBody *const interface) { if (interface->Body().empty()) { return interface; @@ -166,7 +167,7 @@ bool InterfacePropertyDeclarationsPhase::Perform(public_lib::Context *ctx, parse checker::ETSChecker *const checker = ctx->checker->AsETSChecker(); program->Ast()->TransformChildrenRecursively([checker](ir::AstNode *const ast) -> ir::AstNode * { - return ast->IsTSInterfaceBody() ? UpdateInterfacePropertys(checker, ast->AsTSInterfaceBody()) : ast; + return ast->IsTSInterfaceBody() ? UpdateInterfaceProperties(checker, ast->AsTSInterfaceBody()) : ast; }); return true; diff --git a/ets2panda/compiler/lowering/ets/unionLowering.cpp b/ets2panda/compiler/lowering/ets/unionLowering.cpp index ce7cb9be..e16500ce 100644 --- a/ets2panda/compiler/lowering/ets/unionLowering.cpp +++ b/ets2panda/compiler/lowering/ets/unionLowering.cpp @@ -112,8 +112,10 @@ void HandleUnionPropertyAccess(checker::ETSChecker *checker, varbinder::VarBinde !parent->AsCallExpression()->Signature()->HasSignatureFlag(checker::SignatureFlags::TYPE)) { return; } - expr->SetPropVar( - CreateUnionFieldClassProperty(checker, vbind, expr->TsType(), expr->Property()->AsIdentifier()->Name())); + + auto var = CreateUnionFieldClassProperty(checker, vbind, expr->TsType(), expr->Property()->AsIdentifier()->Name()); + expr->SetPropVar(var); + expr->Property()->AsIdentifier()->SetVariable(var); ASSERT(expr->PropVar() != nullptr); } diff --git a/ets2panda/parser/ETSparser.cpp b/ets2panda/parser/ETSparser.cpp index 423ba880..ae36178d 100644 --- a/ets2panda/parser/ETSparser.cpp +++ b/ets2panda/parser/ETSparser.cpp @@ -1126,8 +1126,6 @@ ir::MethodDefinition *ETSParser::ParseClassMethodDefinition(ir::Identifier *meth funcExpr, modifiers, Allocator(), false); method->SetRange(funcExpr->Range()); - func->Id()->SetReference(); - fieldMap_.insert({methodName->Name(), method}); return method; -- Gitee