From bb906611a2a5e14ac92a1df7bc88b2a5834317c9 Mon Sep 17 00:00:00 2001 From: Soma Simon Date: Wed, 14 Feb 2024 13:22:02 +0100 Subject: [PATCH 01/22] Implement export/import type Create new type exported flag for nodes, make typed field for import declarations, handle the wrong cases by the spec Fixes internal issue #14586 Issue: https://gitee.com/openharmony/arkcompiler_runtime_core/issues/I97LAF Testing: all CI tests passed. Results are availible in gg watcher. Change-Id: I867d2846413cc4d550335b1d865eb7af2b7e4d09 Signed-off-by: Soma Simon --- ets2panda/checker/ets/helpers.cpp | 4 +- ets2panda/compiler/core/ASTVerifier.cpp | 2 +- .../ets/topLevelStmts/importExportDecls.cpp | 91 +- .../ets/topLevelStmts/importExportDecls.h | 2 + ets2panda/ir/astNode.cpp | 9 + ets2panda/ir/astNode.h | 2 + ets2panda/ir/astNodeFlags.h | 4 +- ets2panda/ir/ets/etsImportDeclaration.h | 5 +- ets2panda/ir/module/importDeclaration.h | 13 +- ets2panda/parser/ETSparser.cpp | 22 +- .../export_and_export_type_class-expected.txt | 1 + .../ets/export_and_export_type_class.ets | 17 + ...ort_and_export_type_interface-expected.txt | 1 + .../ets/export_and_export_type_interface.ets | 17 + ...at_decl_and_selective_binding-expected.txt | 1 + ...ame_type_at_decl_and_selective_binding.ets | 18 + .../compiler/ets/export_type-expected.txt | 607 ++++++++++ ets2panda/test/compiler/ets/export_type.ets | 21 + ...ort_type_class_multiple_times-expected.txt | 1 + .../ets/export_type_class_multiple_times.ets | 20 + .../ets/export_type_enum-expected.txt | 1 + .../test/compiler/ets/export_type_enum.ets | 18 + .../ets/export_type_function-expected.txt | 1 + .../compiler/ets/export_type_function.ets | 20 + ...type_interface_multiple_times-expected.txt | 1 + .../export_type_interface_multiple_times.ets | 20 + .../ets/export_type_variable-expected.txt | 1 + .../compiler/ets/export_type_variable.ets | 18 + ...t_type_variable_at_definition-expected.txt | 1 + .../export_type_variable_at_definition.ets | 16 + .../compiler/ets/import_type-expected.txt | 1068 +++++++++++++++++ ets2panda/test/compiler/ets/import_type.ets | 21 + ...port_type_with_invalid_syntax-expected.txt | 1 + .../ets/import_type_with_invalid_syntax.ets | 20 + .../import_type_without_export-expected.txt | 646 ++++++++++ .../ets/import_type_without_export.ets | 19 + ets2panda/varbinder/ETSBinder.cpp | 6 +- ets2panda/varbinder/scope.cpp | 2 +- 38 files changed, 2723 insertions(+), 15 deletions(-) create mode 100644 ets2panda/test/compiler/ets/export_and_export_type_class-expected.txt create mode 100644 ets2panda/test/compiler/ets/export_and_export_type_class.ets create mode 100644 ets2panda/test/compiler/ets/export_and_export_type_interface-expected.txt create mode 100644 ets2panda/test/compiler/ets/export_and_export_type_interface.ets create mode 100644 ets2panda/test/compiler/ets/export_same_type_at_decl_and_selective_binding-expected.txt create mode 100644 ets2panda/test/compiler/ets/export_same_type_at_decl_and_selective_binding.ets create mode 100644 ets2panda/test/compiler/ets/export_type-expected.txt create mode 100644 ets2panda/test/compiler/ets/export_type.ets create mode 100644 ets2panda/test/compiler/ets/export_type_class_multiple_times-expected.txt create mode 100644 ets2panda/test/compiler/ets/export_type_class_multiple_times.ets create mode 100644 ets2panda/test/compiler/ets/export_type_enum-expected.txt create mode 100644 ets2panda/test/compiler/ets/export_type_enum.ets create mode 100644 ets2panda/test/compiler/ets/export_type_function-expected.txt create mode 100644 ets2panda/test/compiler/ets/export_type_function.ets create mode 100644 ets2panda/test/compiler/ets/export_type_interface_multiple_times-expected.txt create mode 100644 ets2panda/test/compiler/ets/export_type_interface_multiple_times.ets create mode 100644 ets2panda/test/compiler/ets/export_type_variable-expected.txt create mode 100644 ets2panda/test/compiler/ets/export_type_variable.ets create mode 100644 ets2panda/test/compiler/ets/export_type_variable_at_definition-expected.txt create mode 100644 ets2panda/test/compiler/ets/export_type_variable_at_definition.ets create mode 100644 ets2panda/test/compiler/ets/import_type-expected.txt create mode 100644 ets2panda/test/compiler/ets/import_type.ets create mode 100644 ets2panda/test/compiler/ets/import_type_with_invalid_syntax-expected.txt create mode 100644 ets2panda/test/compiler/ets/import_type_with_invalid_syntax.ets create mode 100644 ets2panda/test/compiler/ets/import_type_without_export-expected.txt create mode 100644 ets2panda/test/compiler/ets/import_type_without_export.ets diff --git a/ets2panda/checker/ets/helpers.cpp b/ets2panda/checker/ets/helpers.cpp index a5ee1b3bb6..9110965cc3 100644 --- a/ets2panda/checker/ets/helpers.cpp +++ b/ets2panda/checker/ets/helpers.cpp @@ -1142,7 +1142,9 @@ void ETSChecker::BindingsModuleObjectAddProperty(checker::ETSObjectType *moduleO for (auto [_, var] : bindings) { (void)_; auto [found, aliasedName] = FindSpecifierForModuleObject(importDecl, var->AsLocalVariable()->Name()); - if (var->AsLocalVariable()->Declaration()->Node()->IsExported() && found) { + if ((var->AsLocalVariable()->Declaration()->Node()->IsExported() || + var->AsLocalVariable()->Declaration()->Node()->IsExportedType()) && + found) { if (!aliasedName.Empty()) { moduleObjType->AddReExportAlias(var->Declaration()->Name(), aliasedName); } diff --git a/ets2panda/compiler/core/ASTVerifier.cpp b/ets2panda/compiler/core/ASTVerifier.cpp index faa26247ca..5c376a434a 100644 --- a/ets2panda/compiler/core/ASTVerifier.cpp +++ b/ets2panda/compiler/core/ASTVerifier.cpp @@ -1005,7 +1005,7 @@ private: if (node == nullptr) { return false; } - return node->IsExported(); + return node->IsExported() || node->IsExportedType(); } bool InvariantImportExportMethod(const std::unordered_set &importedVariables, diff --git a/ets2panda/compiler/lowering/ets/topLevelStmts/importExportDecls.cpp b/ets2panda/compiler/lowering/ets/topLevelStmts/importExportDecls.cpp index eb13cef95e..a79f97beb2 100644 --- a/ets2panda/compiler/lowering/ets/topLevelStmts/importExportDecls.cpp +++ b/ets2panda/compiler/lowering/ets/topLevelStmts/importExportDecls.cpp @@ -29,20 +29,25 @@ void ImportExportDecls::ParseDefaultSources() void ImportExportDecls::HandleGlobalStmts(const ArenaVector &programs) { VerifySingleExportDefault(programs); + VerifyTypeExports(programs); for (const auto &program : programs) { auto errorHandler = util::ErrorHandler(program); fieldMap_.clear(); exportNameMap_.clear(); + exportedTypes_.clear(); for (auto stmt : program->Ast()->Statements()) { stmt->Accept(this); } for (auto &[exportName, startLoc] : exportNameMap_) { - if (fieldMap_.count(exportName) == 0) { + const bool isType = exportedTypes_.find(exportName) != exportedTypes_.end(); + if ((fieldMap_.count(exportName) == 0 && !isType)) { auto errorStr = "Cannot find name '" + std::string(exportName.Utf8()) + "' to export."; errorHandler.ThrowSyntaxError(errorStr, startLoc); } - auto field = fieldMap_[exportName]; - field->AddModifier(ir::ModifierFlags::EXPORT); + if (!isType) { + auto field = fieldMap_[exportName]; + field->AddModifier(ir::ModifierFlags::EXPORT); + } } } } @@ -65,10 +70,90 @@ void ImportExportDecls::VisitExportNamedDeclaration(ir::ExportNamedDeclaration * { for (auto spec : exportDecl->Specifiers()) { auto local = spec->Local(); + if (exportDecl->IsExportedType()) { + exportedTypes_.insert(local->Name()); + } exportNameMap_.emplace(local->Name(), local->Start()); } } +void HandleSimpleType(std::set &exportedTypes, std::set &exportedStatements, + ir::Statement *stmt, util::StringView name, parser::Program *program, lexer::SourcePosition pos) +{ + if (stmt->IsExported()) { + exportedStatements.insert(name); + } + + if (!stmt->IsExportedType()) { + return; + } + + if (exportedStatements.find(name) != exportedStatements.end()) { + util::ErrorHandler::ThrowSyntaxError( + program, "Name '" + name.Mutf8() + "' cannot be exported and type exported at the same time.", pos); + } + + if (exportedTypes.find(name) != exportedTypes.end()) { + util::ErrorHandler::ThrowSyntaxError(program, "Cannot export the same '" + name.Mutf8() + "' type twice.", pos); + } else { + exportedTypes.insert(name); + } +} + +void ImportExportDecls::VerifyTypeExports(const ArenaVector &programs) +{ + std::set exportedTypes; + std::set exportedStatements; + std::map typesMap; + auto verifyType = [&exportedTypes, &exportedStatements, &typesMap](ir::Statement *stmt, parser::Program *program) { + if (stmt->IsClassDeclaration()) { + typesMap.insert({stmt->AsClassDeclaration()->Definition()->Ident()->Name(), stmt}); + return HandleSimpleType(exportedTypes, exportedStatements, stmt, + stmt->AsClassDeclaration()->Definition()->Ident()->Name(), program, stmt->Start()); + } + + if (stmt->IsTSInterfaceDeclaration()) { + typesMap.insert({stmt->AsTSInterfaceDeclaration()->Id()->Name(), stmt}); + return HandleSimpleType(exportedTypes, exportedStatements, stmt, + stmt->AsTSInterfaceDeclaration()->Id()->Name(), program, stmt->Start()); + } + + if (stmt->IsTSTypeAliasDeclaration()) { + typesMap.insert({stmt->AsTSTypeAliasDeclaration()->Id()->Name(), stmt}); + return HandleSimpleType(exportedTypes, exportedStatements, stmt, + stmt->AsTSTypeAliasDeclaration()->Id()->Name(), program, stmt->Start()); + } + + if (!stmt->IsExportedType()) { + return; + } + + if (!stmt->IsExportNamedDeclaration()) { + util::ErrorHandler::ThrowSyntaxError(program, "Can only type export class or interface!", stmt->Start()); + } + + for (auto spec : stmt->AsExportNamedDeclaration()->Specifiers()) { + util::StringView name = spec->Local()->Name(); + + auto element = typesMap.find(name); + if (element == typesMap.end()) { + util::ErrorHandler::ThrowSyntaxError(program, "Can only type export class or interface!", + spec->Local()->Start()); + } + if (!element->second->IsExportedType()) { + element->second->AddModifier(ir::ModifierFlags::EXPORT_TYPE); + } + HandleSimpleType(exportedTypes, exportedStatements, stmt, name, program, spec->Local()->Start()); + } + }; + + for (const auto &program : programs) { + for (auto stmt : program->Ast()->Statements()) { + verifyType(stmt, program); + } + } +} + void ImportExportDecls::VerifySingleExportDefault(const ArenaVector &programs) { bool metDefaultExport = false; diff --git a/ets2panda/compiler/lowering/ets/topLevelStmts/importExportDecls.h b/ets2panda/compiler/lowering/ets/topLevelStmts/importExportDecls.h index 950558ea54..f92c9a13e9 100644 --- a/ets2panda/compiler/lowering/ets/topLevelStmts/importExportDecls.h +++ b/ets2panda/compiler/lowering/ets/topLevelStmts/importExportDecls.h @@ -56,6 +56,7 @@ public: * @param global_stmts program global statements */ void HandleGlobalStmts(const ArenaVector &programs); + void VerifyTypeExports(const ArenaVector &programs); void VerifySingleExportDefault(const ArenaVector &programs); @@ -68,6 +69,7 @@ private: varbinder::ETSBinder *varbinder_ {nullptr}; std::map fieldMap_; std::map exportNameMap_; + std::set exportedTypes_; parser::ETSParser *parser_ {nullptr}; }; } // namespace ark::es2panda::compiler diff --git a/ets2panda/ir/astNode.cpp b/ets2panda/ir/astNode.cpp index a17cc9d0fd..b7a83d408b 100644 --- a/ets2panda/ir/astNode.cpp +++ b/ets2panda/ir/astNode.cpp @@ -30,6 +30,15 @@ AstNode::AstNode(AstNode const &other) // boxing_unboxing_flags_ {}; leave default value! } +[[nodiscard]] bool ir::AstNode::IsExportedType() const noexcept +{ + if (UNLIKELY(IsClassDefinition())) { + return this->parent_->IsExportedType(); + } + + return (flags_ & ModifierFlags::EXPORT_TYPE) != 0; +} + template static R GetTopStatementImpl(T *self) { diff --git a/ets2panda/ir/astNode.h b/ets2panda/ir/astNode.h index 3f6537ca5c..b24e618f53 100644 --- a/ets2panda/ir/astNode.h +++ b/ets2panda/ir/astNode.h @@ -381,6 +381,8 @@ public: return (flags_ & ModifierFlags::DEFAULT_EXPORT) != 0; } + [[nodiscard]] bool IsExportedType() const noexcept; + [[nodiscard]] bool IsDeclare() const noexcept { return (flags_ & ModifierFlags::DECLARE) != 0; diff --git a/ets2panda/ir/astNodeFlags.h b/ets2panda/ir/astNodeFlags.h index 3b1d2f0a23..9ae838d974 100644 --- a/ets2panda/ir/astNodeFlags.h +++ b/ets2panda/ir/astNodeFlags.h @@ -52,12 +52,14 @@ enum class ModifierFlags : uint32_t { GETTER = 1U << 21U, SETTER = 1U << 22U, DEFAULT_EXPORT = 1U << 23U, + EXPORT_TYPE = 1U << 24U, ACCESS = PUBLIC | PROTECTED | PRIVATE | INTERNAL, ALL = STATIC | ASYNC | ACCESS | DECLARE | READONLY | ABSTRACT, ALLOWED_IN_CTOR_PARAMETER = ACCESS | READONLY, INTERNAL_PROTECTED = INTERNAL | PROTECTED, ACCESSOR_MODIFIERS = ABSTRACT | FINAL, - GETTER_SETTER = GETTER | SETTER + GETTER_SETTER = GETTER | SETTER, + EXPORTED = EXPORT | DEFAULT_EXPORT | EXPORT_TYPE }; enum class PrivateFieldKind { FIELD, METHOD, GET, SET, STATIC_FIELD, STATIC_METHOD, STATIC_GET, STATIC_SET }; diff --git a/ets2panda/ir/ets/etsImportDeclaration.h b/ets2panda/ir/ets/etsImportDeclaration.h index b46d39d893..c09cdba2ad 100644 --- a/ets2panda/ir/ets/etsImportDeclaration.h +++ b/ets2panda/ir/ets/etsImportDeclaration.h @@ -26,8 +26,9 @@ class StringLiteral; class ETSImportDeclaration : public ImportDeclaration { public: - explicit ETSImportDeclaration(ImportSource *source, const ArenaVector &specifiers) - : ImportDeclaration(source->Source(), specifiers), source_(source) + explicit ETSImportDeclaration(ImportSource *source, const ArenaVector &specifiers, + const ImportKinds importKind = ImportKinds::VALUE) + : ImportDeclaration(source->Source(), specifiers, importKind), source_(source) { SetType(AstNodeType::ETS_IMPORT_DECLARATION); } diff --git a/ets2panda/ir/module/importDeclaration.h b/ets2panda/ir/module/importDeclaration.h index c9096366dc..9a1c5e4fa5 100644 --- a/ets2panda/ir/module/importDeclaration.h +++ b/ets2panda/ir/module/importDeclaration.h @@ -21,10 +21,13 @@ namespace ark::es2panda::ir { class StringLiteral; +enum class ImportKinds { VALUE, TYPE }; + class ImportDeclaration : public Statement { public: - explicit ImportDeclaration(StringLiteral *source, ArenaVector const &specifiers) - : Statement(AstNodeType::IMPORT_DECLARATION), source_(source), specifiers_(specifiers) + explicit ImportDeclaration(StringLiteral *source, ArenaVector const &specifiers, + const ImportKinds importKind = ImportKinds::VALUE) + : Statement(AstNodeType::IMPORT_DECLARATION), source_(source), specifiers_(specifiers), importKind_(importKind) { } @@ -57,9 +60,15 @@ public: v->Accept(this); } + bool IsTypeKind() const + { + return importKind_ == ImportKinds::TYPE; + } + private: StringLiteral *source_; ArenaVector specifiers_; + ImportKinds importKind_; }; } // namespace ark::es2panda::ir diff --git a/ets2panda/parser/ETSparser.cpp b/ets2panda/parser/ETSparser.cpp index 773822beff..e3036eb88a 100644 --- a/ets2panda/parser/ETSparser.cpp +++ b/ets2panda/parser/ETSparser.cpp @@ -295,7 +295,7 @@ ArenaVector ETSParser::ParseTopLevelStatements() ir::Statement *ETSParser::ParseTopLevelDeclStatement(StatementParsingFlags flags) { auto [memberModifiers, startLoc] = ParseMemberModifiers(); - if ((memberModifiers & (ir::ModifierFlags::EXPORT | ir::ModifierFlags::DEFAULT_EXPORT)) != 0U && + if ((memberModifiers & (ir::ModifierFlags::EXPORTED)) != 0U && (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_MULTIPLY || Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_LEFT_BRACE)) { return ParseExport(startLoc, memberModifiers); @@ -332,10 +332,14 @@ ir::Statement *ETSParser::ParseTopLevelDeclStatement(StatementParsingFlags flags break; } default: { - break; } } if (result != nullptr) { + if ((memberModifiers & ir::ModifierFlags::EXPORT_TYPE) != 0U && + !(result->IsClassDeclaration() || result->IsTSInterfaceDeclaration() || + result->IsTSTypeAliasDeclaration())) { + ThrowSyntaxError("Can only type export class or interface!"); + } result->AddModifier(memberModifiers); } return result; @@ -2429,9 +2433,15 @@ ArenaVector ETSParser::ParseImportDeclarations() auto startLoc = Lexer()->GetToken().Start(); Lexer()->NextToken(); // eat import + ir::ImportKinds importKind = + Lexer()->TryEatTokenKeyword(lexer::TokenType::KEYW_TYPE) ? ir::ImportKinds::TYPE : ir::ImportKinds::VALUE; + ArenaVector specifiers(Allocator()->Adapter()); if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_MULTIPLY) { + if (importKind == ir::ImportKinds::TYPE) { + ThrowSyntaxError("Type import requires selective binding to define the required imported elements."); + } ParseNameSpaceSpecifier(&specifiers); } else if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_LEFT_BRACE) { auto specs = ParseNamedSpecifiers(); @@ -2443,7 +2453,7 @@ ArenaVector ETSParser::ParseImportDeclarations() ir::ImportSource *importSource = ParseSourceFromClause(true); lexer::SourcePosition endLoc = importSource->Source()->End(); - auto *importDeclaration = AllocNode(importSource, std::move(specifiers)); + auto *importDeclaration = AllocNode(importSource, std::move(specifiers), importKind); importDeclaration->SetRange({startLoc, endLoc}); ConsumeSemicolon(importDeclaration); @@ -4136,8 +4146,14 @@ std::pair ETSParser::ParseMemberModifi auto memberModifiers = ir::ModifierFlags::STATIC | ir::ModifierFlags::PUBLIC; if (Lexer()->TryEatTokenType(lexer::TokenType::KEYW_EXPORT)) { + const auto savedPos = Lexer()->Save(); if (Lexer()->TryEatTokenKeyword(lexer::TokenType::KEYW_DEFAULT)) { memberModifiers |= ir::ModifierFlags::DEFAULT_EXPORT; + } else if (Lexer()->TryEatTokenKeyword(lexer::TokenType::KEYW_TYPE)) { + if (Lexer()->GetToken().Type() == lexer::TokenType::LITERAL_IDENT) { + Lexer()->Rewind(savedPos); + } + memberModifiers |= ir::ModifierFlags::EXPORT_TYPE; } else { memberModifiers |= ir::ModifierFlags::EXPORT; } diff --git a/ets2panda/test/compiler/ets/export_and_export_type_class-expected.txt b/ets2panda/test/compiler/ets/export_and_export_type_class-expected.txt new file mode 100644 index 0000000000..1a3e6a97c6 --- /dev/null +++ b/ets2panda/test/compiler/ets/export_and_export_type_class-expected.txt @@ -0,0 +1 @@ +SyntaxError: Name 'A' cannot be exported and type exported at the same time. [export_and_export_type_class.ets:17:14] diff --git a/ets2panda/test/compiler/ets/export_and_export_type_class.ets b/ets2panda/test/compiler/ets/export_and_export_type_class.ets new file mode 100644 index 0000000000..9d4f7d8845 --- /dev/null +++ b/ets2panda/test/compiler/ets/export_and_export_type_class.ets @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export class A {} +export type {A} diff --git a/ets2panda/test/compiler/ets/export_and_export_type_interface-expected.txt b/ets2panda/test/compiler/ets/export_and_export_type_interface-expected.txt new file mode 100644 index 0000000000..a40e4b221c --- /dev/null +++ b/ets2panda/test/compiler/ets/export_and_export_type_interface-expected.txt @@ -0,0 +1 @@ +SyntaxError: Name 'I' cannot be exported and type exported at the same time. [export_and_export_type_interface.ets:17:14] diff --git a/ets2panda/test/compiler/ets/export_and_export_type_interface.ets b/ets2panda/test/compiler/ets/export_and_export_type_interface.ets new file mode 100644 index 0000000000..5c96ef79d0 --- /dev/null +++ b/ets2panda/test/compiler/ets/export_and_export_type_interface.ets @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export interface I {} +export type {I} diff --git a/ets2panda/test/compiler/ets/export_same_type_at_decl_and_selective_binding-expected.txt b/ets2panda/test/compiler/ets/export_same_type_at_decl_and_selective_binding-expected.txt new file mode 100644 index 0000000000..f1a41963b3 --- /dev/null +++ b/ets2panda/test/compiler/ets/export_same_type_at_decl_and_selective_binding-expected.txt @@ -0,0 +1 @@ +SyntaxError: Cannot export the same 'A' type twice. [export_same_type_at_decl_and_selective_binding.ets:17:14] diff --git a/ets2panda/test/compiler/ets/export_same_type_at_decl_and_selective_binding.ets b/ets2panda/test/compiler/ets/export_same_type_at_decl_and_selective_binding.ets new file mode 100644 index 0000000000..871c63ec97 --- /dev/null +++ b/ets2panda/test/compiler/ets/export_same_type_at_decl_and_selective_binding.ets @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export type class A {} +export type {A} + diff --git a/ets2panda/test/compiler/ets/export_type-expected.txt b/ets2panda/test/compiler/ets/export_type-expected.txt new file mode 100644 index 0000000000..38d02fc55f --- /dev/null +++ b/ets2panda/test/compiler/ets/export_type-expected.txt @@ -0,0 +1,607 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 7 + }, + "end": { + "line": 16, + "column": 8 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 11 + }, + "end": { + "line": 16, + "column": 11 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 11 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 16, + "column": 11 + } + } + }, + { + "type": "TSInterfaceDeclaration", + "body": { + "type": "TSInterfaceBody", + "body": [], + "loc": { + "start": { + "line": 17, + "column": 13 + }, + "end": { + "line": 17, + "column": 15 + } + } + }, + "id": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 11 + }, + "end": { + "line": 17, + "column": 12 + } + } + }, + "extends": [], + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 19, + "column": 7 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 14 + }, + "end": { + "line": 19, + "column": 15 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 18 + }, + "end": { + "line": 19, + "column": 18 + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 16 + }, + "end": { + "line": 19, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 8 + }, + "end": { + "line": 19, + "column": 18 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "D", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 19 + }, + "end": { + "line": 21, + "column": 20 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 23 + }, + "end": { + "line": 21, + "column": 23 + } + } + } + ], + "loc": { + "start": { + "line": 21, + "column": 21 + }, + "end": { + "line": 21, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 13 + }, + "end": { + "line": 21, + "column": 23 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 22, + "column": 1 + } + } +} diff --git a/ets2panda/test/compiler/ets/export_type.ets b/ets2panda/test/compiler/ets/export_type.ets new file mode 100644 index 0000000000..53d5c94441 --- /dev/null +++ b/ets2panda/test/compiler/ets/export_type.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +class A {} +interface B {} + +export class C {} +export type {A, B} +export type class D {} diff --git a/ets2panda/test/compiler/ets/export_type_class_multiple_times-expected.txt b/ets2panda/test/compiler/ets/export_type_class_multiple_times-expected.txt new file mode 100644 index 0000000000..9cb362a6ef --- /dev/null +++ b/ets2panda/test/compiler/ets/export_type_class_multiple_times-expected.txt @@ -0,0 +1 @@ +SyntaxError: Cannot export the same 'MyA' type twice. [export_type_class_multiple_times.ets:20:14] diff --git a/ets2panda/test/compiler/ets/export_type_class_multiple_times.ets b/ets2panda/test/compiler/ets/export_type_class_multiple_times.ets new file mode 100644 index 0000000000..2b5afbebef --- /dev/null +++ b/ets2panda/test/compiler/ets/export_type_class_multiple_times.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +class A {} + +export type {A} +export type MyA = A +export type {MyA} diff --git a/ets2panda/test/compiler/ets/export_type_enum-expected.txt b/ets2panda/test/compiler/ets/export_type_enum-expected.txt new file mode 100644 index 0000000000..c1e7b9f5b2 --- /dev/null +++ b/ets2panda/test/compiler/ets/export_type_enum-expected.txt @@ -0,0 +1 @@ +SyntaxError: Can only type export class or interface! [export_type_enum.ets:18:14] diff --git a/ets2panda/test/compiler/ets/export_type_enum.ets b/ets2panda/test/compiler/ets/export_type_enum.ets new file mode 100644 index 0000000000..4cdb42f4d3 --- /dev/null +++ b/ets2panda/test/compiler/ets/export_type_enum.ets @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +enum E { A = 5, B = 5 } + +export type {E} diff --git a/ets2panda/test/compiler/ets/export_type_function-expected.txt b/ets2panda/test/compiler/ets/export_type_function-expected.txt new file mode 100644 index 0000000000..b0d3996957 --- /dev/null +++ b/ets2panda/test/compiler/ets/export_type_function-expected.txt @@ -0,0 +1 @@ +SyntaxError: Can only type export class or interface! [export_type_function.ets:20:14] diff --git a/ets2panda/test/compiler/ets/export_type_function.ets b/ets2panda/test/compiler/ets/export_type_function.ets new file mode 100644 index 0000000000..a2160ce0e1 --- /dev/null +++ b/ets2panda/test/compiler/ets/export_type_function.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +function f(){ + return 1; +} + +export type {f} diff --git a/ets2panda/test/compiler/ets/export_type_interface_multiple_times-expected.txt b/ets2panda/test/compiler/ets/export_type_interface_multiple_times-expected.txt new file mode 100644 index 0000000000..d9df14f0aa --- /dev/null +++ b/ets2panda/test/compiler/ets/export_type_interface_multiple_times-expected.txt @@ -0,0 +1 @@ +SyntaxError: Cannot export the same 'MyI' type twice. [export_type_interface_multiple_times.ets:20:14] diff --git a/ets2panda/test/compiler/ets/export_type_interface_multiple_times.ets b/ets2panda/test/compiler/ets/export_type_interface_multiple_times.ets new file mode 100644 index 0000000000..fc7d0bfeb8 --- /dev/null +++ b/ets2panda/test/compiler/ets/export_type_interface_multiple_times.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +interface I {} + +export type {I} +export type MyI = I +export type {MyI} diff --git a/ets2panda/test/compiler/ets/export_type_variable-expected.txt b/ets2panda/test/compiler/ets/export_type_variable-expected.txt new file mode 100644 index 0000000000..3374cd51e4 --- /dev/null +++ b/ets2panda/test/compiler/ets/export_type_variable-expected.txt @@ -0,0 +1 @@ +SyntaxError: Can only type export class or interface! [export_type_variable.ets:18:14] diff --git a/ets2panda/test/compiler/ets/export_type_variable.ets b/ets2panda/test/compiler/ets/export_type_variable.ets new file mode 100644 index 0000000000..58c9c2a52b --- /dev/null +++ b/ets2panda/test/compiler/ets/export_type_variable.ets @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +let a = 5; + +export type {a} diff --git a/ets2panda/test/compiler/ets/export_type_variable_at_definition-expected.txt b/ets2panda/test/compiler/ets/export_type_variable_at_definition-expected.txt new file mode 100644 index 0000000000..2e24f525ff --- /dev/null +++ b/ets2panda/test/compiler/ets/export_type_variable_at_definition-expected.txt @@ -0,0 +1 @@ +SyntaxError: Can only type export class or interface! [export_type_variable_at_definition.ets:17:1] diff --git a/ets2panda/test/compiler/ets/export_type_variable_at_definition.ets b/ets2panda/test/compiler/ets/export_type_variable_at_definition.ets new file mode 100644 index 0000000000..b7a1766318 --- /dev/null +++ b/ets2panda/test/compiler/ets/export_type_variable_at_definition.ets @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export type let a = 5; diff --git a/ets2panda/test/compiler/ets/import_type-expected.txt b/ets2panda/test/compiler/ets/import_type-expected.txt new file mode 100644 index 0000000000..8c41b088cf --- /dev/null +++ b/ets2panda/test/compiler/ets/import_type-expected.txt @@ -0,0 +1,1068 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ImportDeclaration", + "source": { + "type": "StringLiteral", + "value": "./export_type.ets", + "loc": { + "start": { + "line": 16, + "column": 28 + }, + "end": { + "line": 16, + "column": 47 + } + } + }, + "specifiers": [ + { + "type": "ImportSpecifier", + "local": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 14 + }, + "end": { + "line": 16, + "column": 15 + } + } + }, + "imported": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 14 + }, + "end": { + "line": 16, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 14 + }, + "end": { + "line": 16, + "column": 15 + } + } + }, + { + "type": "ImportSpecifier", + "local": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 17 + }, + "end": { + "line": 16, + "column": 18 + } + } + }, + "imported": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 17 + }, + "end": { + "line": 16, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 17 + }, + "end": { + "line": 16, + "column": 18 + } + } + }, + { + "type": "ImportSpecifier", + "local": { + "type": "Identifier", + "name": "D", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 20 + }, + "end": { + "line": 16, + "column": 21 + } + } + }, + "imported": { + "type": "Identifier", + "name": "D", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 20 + }, + "end": { + "line": 16, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 20 + }, + "end": { + "line": 16, + "column": 21 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 16, + "column": 47 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 7 + }, + "end": { + "line": 19, + "column": 8 + } + } + }, + "superClass": null, + "implements": [ + { + "type": "TSClassImplements", + "expression": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 20 + }, + "end": { + "line": 19, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 20 + }, + "end": { + "line": 19, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 20 + }, + "end": { + "line": 19, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 20 + }, + "end": { + "line": 19, + "column": 23 + } + } + } + ], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 24 + }, + "end": { + "line": 19, + "column": 24 + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 22 + }, + "end": { + "line": 19, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 1 + }, + "end": { + "line": 19, + "column": 24 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "a", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 6 + } + } + }, + "right": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 18, + "column": 14 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 18, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 18, + "column": 15 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 17 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 17 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 17 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "c", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 6 + } + } + }, + "right": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 13 + }, + "end": { + "line": 20, + "column": 14 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 13 + }, + "end": { + "line": 20, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 13 + }, + "end": { + "line": 20, + "column": 15 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 20, + "column": 9 + }, + "end": { + "line": 21, + "column": 4 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 21, + "column": 4 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 21, + "column": 4 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "d", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 5 + }, + "end": { + "line": 21, + "column": 6 + } + } + }, + "right": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "D", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 13 + }, + "end": { + "line": 21, + "column": 14 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 13 + }, + "end": { + "line": 21, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 13 + }, + "end": { + "line": 21, + "column": 15 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 21, + "column": 9 + }, + "end": { + "line": 22, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 5 + }, + "end": { + "line": 22, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 5 + }, + "end": { + "line": 22, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "a", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 6 + } + } + }, + "value": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 18, + "column": 14 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 18, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 18, + "column": 15 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 17 + } + } + }, + "accessibility": "public", + "static": true, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 17 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "c", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 6 + } + } + }, + "value": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 13 + }, + "end": { + "line": 20, + "column": 14 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 13 + }, + "end": { + "line": 20, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 13 + }, + "end": { + "line": 20, + "column": 15 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 20, + "column": 9 + }, + "end": { + "line": 21, + "column": 4 + } + } + }, + "accessibility": "public", + "static": true, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 21, + "column": 4 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "d", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 5 + }, + "end": { + "line": 21, + "column": 6 + } + } + }, + "value": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "D", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 13 + }, + "end": { + "line": 21, + "column": 14 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 13 + }, + "end": { + "line": 21, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 13 + }, + "end": { + "line": 21, + "column": 15 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 21, + "column": 9 + }, + "end": { + "line": 22, + "column": 1 + } + } + }, + "accessibility": "public", + "static": true, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 5 + }, + "end": { + "line": 22, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 22, + "column": 1 + } + } +} diff --git a/ets2panda/test/compiler/ets/import_type.ets b/ets2panda/test/compiler/ets/import_type.ets new file mode 100644 index 0000000000..1170a3ddbd --- /dev/null +++ b/ets2panda/test/compiler/ets/import_type.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import type {A, B, D} from './export_type.ets' + +let a = new A(); +class C implements B {}; +let c = new C() +let d = new D() diff --git a/ets2panda/test/compiler/ets/import_type_with_invalid_syntax-expected.txt b/ets2panda/test/compiler/ets/import_type_with_invalid_syntax-expected.txt new file mode 100644 index 0000000000..597df0de5a --- /dev/null +++ b/ets2panda/test/compiler/ets/import_type_with_invalid_syntax-expected.txt @@ -0,0 +1 @@ +SyntaxError: Type import requires selective binding to define the required imported elements. [import_type_with_invalid_syntax.ets:16:13] diff --git a/ets2panda/test/compiler/ets/import_type_with_invalid_syntax.ets b/ets2panda/test/compiler/ets/import_type_with_invalid_syntax.ets new file mode 100644 index 0000000000..ac8b47de37 --- /dev/null +++ b/ets2panda/test/compiler/ets/import_type_with_invalid_syntax.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import type * from './export_type.ets' + +let a = new A(); +class C implements B {}; +let c = new C() diff --git a/ets2panda/test/compiler/ets/import_type_without_export-expected.txt b/ets2panda/test/compiler/ets/import_type_without_export-expected.txt new file mode 100644 index 0000000000..7e54c7d7b6 --- /dev/null +++ b/ets2panda/test/compiler/ets/import_type_without_export-expected.txt @@ -0,0 +1,646 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ImportDeclaration", + "source": { + "type": "StringLiteral", + "value": "./export_type.ets", + "loc": { + "start": { + "line": 16, + "column": 25 + }, + "end": { + "line": 16, + "column": 44 + } + } + }, + "specifiers": [ + { + "type": "ImportSpecifier", + "local": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 14 + }, + "end": { + "line": 16, + "column": 15 + } + } + }, + "imported": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 14 + }, + "end": { + "line": 16, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 14 + }, + "end": { + "line": 16, + "column": 15 + } + } + }, + { + "type": "ImportSpecifier", + "local": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 17 + }, + "end": { + "line": 16, + "column": 18 + } + } + }, + "imported": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 17 + }, + "end": { + "line": 16, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 17 + }, + "end": { + "line": 16, + "column": 18 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 16, + "column": 44 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "a", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 6 + } + } + }, + "right": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 18, + "column": 14 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 18, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 18, + "column": 15 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 17 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 17 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 17 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "b", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 6 + } + } + }, + "right": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 13 + }, + "end": { + "line": 19, + "column": 14 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 13 + }, + "end": { + "line": 19, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 13 + }, + "end": { + "line": 19, + "column": 15 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 17 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 17 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 17 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "a", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 6 + } + } + }, + "value": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 18, + "column": 14 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 18, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 18, + "column": 15 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 17 + } + } + }, + "accessibility": "public", + "static": true, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 17 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "b", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 6 + } + } + }, + "value": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 13 + }, + "end": { + "line": 19, + "column": 14 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 13 + }, + "end": { + "line": 19, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 13 + }, + "end": { + "line": 19, + "column": 15 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 17 + } + } + }, + "accessibility": "public", + "static": true, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 17 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 20, + "column": 1 + } + } +} +SyntaxError: Cannot import 'C', imported type imports only exported types. [import_type_without_export.ets:16:25] diff --git a/ets2panda/test/compiler/ets/import_type_without_export.ets b/ets2panda/test/compiler/ets/import_type_without_export.ets new file mode 100644 index 0000000000..cb85867cb1 --- /dev/null +++ b/ets2panda/test/compiler/ets/import_type_without_export.ets @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import type {A, C} from './export_type.ets' + +let a = new A(); +let b = new C(); diff --git a/ets2panda/varbinder/ETSBinder.cpp b/ets2panda/varbinder/ETSBinder.cpp index 8fcb688088..b2ca3807ca 100644 --- a/ets2panda/varbinder/ETSBinder.cpp +++ b/ets2panda/varbinder/ETSBinder.cpp @@ -659,8 +659,12 @@ bool ETSBinder::AddImportSpecifiersToTopBindings(ir::AstNode *const specifier, if (var->Declaration()->Node()->IsDefaultExported()) { ThrowError(importPath->Start(), "Use the default import syntax to import a default exported element"); } + if (import->IsTypeKind() && !var->Declaration()->Node()->IsExportedType()) { + ThrowError(importPath->Start(), + "Cannot import '" + imported.Mutf8() + "', imported type imports only exported types."); + } - if (!var->Declaration()->Node()->IsExported()) { + if (!var->Declaration()->Node()->IsExported() && !var->Declaration()->Node()->IsExportedType()) { ThrowError(importPath->Start(), "Imported element not exported '" + var->Declaration()->Name().Mutf8() + "'"); } diff --git a/ets2panda/varbinder/scope.cpp b/ets2panda/varbinder/scope.cpp index d6bb722e42..28008db5ab 100644 --- a/ets2panda/varbinder/scope.cpp +++ b/ets2panda/varbinder/scope.cpp @@ -551,7 +551,7 @@ Scope::InsertResult GlobalScope::InsertImpl(const util::StringView &name, Variab if (!isDynamic && isForeign && !var->Declaration()->Name().Is(compiler::Signatures::ETS_GLOBAL)) { const auto *const node = var->Declaration()->Node(); - if (!(node->IsExported() || node->IsDefaultExported())) { + if (!(node->IsExported() || node->IsDefaultExported() || node->IsExportedType())) { return Scope::InsertResult {Bindings().end(), false}; } } -- Gitee From 2d3c7227581c82b49dba5edc48d388cfd0b90271 Mon Sep 17 00:00:00 2001 From: Vyacheslav Cherkashin Date: Mon, 29 Jan 2024 14:40:45 +0300 Subject: [PATCH 02/22] Add ACC_VARARGS flag for rest parameters Issue: #I8ZQQX Testing: CI tests passed Signed-off-by: Vyacheslav Cherkashin Signed-off-by: churkinaleksey --- ets2panda/checker/types/signature.h | 5 + ets2panda/compiler/core/ETSemitter.cpp | 8 +- ets2panda/ir/base/scriptFunction.h | 6 + ets2panda/test/CMakeLists.txt | 11 + .../test/unit/rest_parameter_flag_test.cpp | 411 ++++++++++++++++++ 5 files changed, 439 insertions(+), 2 deletions(-) create mode 100644 ets2panda/test/unit/rest_parameter_flag_test.cpp diff --git a/ets2panda/checker/types/signature.h b/ets2panda/checker/types/signature.h index e0ea0292e5..6f613bbee1 100644 --- a/ets2panda/checker/types/signature.h +++ b/ets2panda/checker/types/signature.h @@ -239,6 +239,11 @@ public: ss << compiler::Signatures::MANGLE_SEPARATOR; } + if (signatureInfo_->restVar != nullptr) { + MaybeBoxedType(context->Checker(), signatureInfo_->restVar)->ToAssemblerTypeWithRank(ss); + ss << compiler::Signatures::MANGLE_SEPARATOR; + } + returnType_->ToAssemblerTypeWithRank(ss); ss << compiler::Signatures::MANGLE_SEPARATOR; } diff --git a/ets2panda/compiler/core/ETSemitter.cpp b/ets2panda/compiler/core/ETSemitter.cpp index a35a088569..ba49cbcf2f 100644 --- a/ets2panda/compiler/core/ETSemitter.cpp +++ b/ets2panda/compiler/core/ETSemitter.cpp @@ -111,7 +111,6 @@ static pandasm::Function GenScriptFunction(CompilerContext const *context, const auto *paramScope = funcScope->ParamScope(); auto func = pandasm::Function(funcScope->InternalName().Mutf8(), EXTENSION); - func.params.reserve(paramScope->Params().size()); for (const auto *var : paramScope->Params()) { @@ -125,10 +124,15 @@ static pandasm::Function GenScriptFunction(CompilerContext const *context, const func.returnType = PandasmTypeWithRank(scriptFunc->Signature()->ReturnType()); } + uint32_t accessFlags = 0; if (!scriptFunc->IsStaticBlock()) { const auto *methodDef = util::Helpers::GetContainingClassMethodDefinition(scriptFunc); - func.metadata->SetAccessFlags(TranslateModifierFlags(methodDef->Modifiers())); + accessFlags |= TranslateModifierFlags(methodDef->Modifiers()); + } + if (scriptFunc->HasRestParameter()) { + accessFlags |= ACC_VARARGS; } + func.metadata->SetAccessFlags(accessFlags); return func; } diff --git a/ets2panda/ir/base/scriptFunction.h b/ets2panda/ir/base/scriptFunction.h index 2ca76dd107..7511ae3a26 100644 --- a/ets2panda/ir/base/scriptFunction.h +++ b/ets2panda/ir/base/scriptFunction.h @@ -17,6 +17,7 @@ #define ES2PANDA_PARSER_INCLUDE_AST_SCRIPT_FUNCTION_H #include "ir/statements/returnStatement.h" +#include "checker/types/signature.h" #include "ir/astNode.h" #include "varbinder/scope.h" #include "util/enumbitops.h" @@ -214,6 +215,11 @@ public: return body_ != nullptr; } + [[nodiscard]] bool HasRestParameter() const noexcept + { + return signature_->RestVar() != nullptr; + } + [[nodiscard]] bool IsThrowing() const noexcept { return (funcFlags_ & ir::ScriptFunctionFlags::THROWS) != 0; diff --git a/ets2panda/test/CMakeLists.txt b/ets2panda/test/CMakeLists.txt index 5e81e2016a..d82d4a9aa6 100644 --- a/ets2panda/test/CMakeLists.txt +++ b/ets2panda/test/CMakeLists.txt @@ -162,6 +162,17 @@ if(PANDA_REGRESSION_TESTS) ${PANDA_SANITIZERS_LIST} ) + # NOTE: es2panda_rest_parameter_flag test runs a lot of time on qemu, so let's disable it + if (NOT PANDA_QEMU_BUILD) + panda_add_gtest( + NAME es2panda_rest_parameter_flag + SOURCES unit/rest_parameter_flag_test.cpp + LIBRARIES es2panda-public es2panda-lib arkassembler arkbytecodeopt + INCLUDE_DIRS ${ES2PANDA_PATH} ${ES2PANDA_BINARY_ROOT} + SANITIZERS ${PANDA_SANITIZERS_LIST} + ) + endif() + add_subdirectory(tsconfig) endif() diff --git a/ets2panda/test/unit/rest_parameter_flag_test.cpp b/ets2panda/test/unit/rest_parameter_flag_test.cpp new file mode 100644 index 0000000000..c78f7f6e86 --- /dev/null +++ b/ets2panda/test/unit/rest_parameter_flag_test.cpp @@ -0,0 +1,411 @@ +/** + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "assembler/assembly-program.h" +#include "es2panda.h" +#include "generated/signatures.h" +#include "libpandabase/mem/mem.h" +#include "macros.h" +#include "mem/pool_manager.h" +#include "util/options.h" + +namespace ark::es2panda::compiler::test { + +class RestParameterTest : public testing::Test { +public: + RestParameterTest() + { + constexpr auto COMPILER_SIZE = 268435456; + + mem::MemConfig::Initialize(0, 0, COMPILER_SIZE, 0, 0, 0); + PoolManager::Initialize(PoolType::MMAP); + } + ~RestParameterTest() override + { + PoolManager::Finalize(); + mem::MemConfig::Finalize(); + } + + void SetCurrentProgram(std::string_view src) + { + int argc = 1; + const char *argv = "../../../bin/es2panda"; // NOLINT(modernize-avoid-c-arrays) + static constexpr std::string_view FILE_NAME = "dummy.ets"; + + program_ = GetProgram(argc, &argv, FILE_NAME, src); + ASSERT_NE(program_.get(), nullptr); + } + + void CheckRestParameterFlag(std::string_view functionName) + { + pandasm::Function *fn = GetFunction(functionName); + ASSERT_TRUE(fn != nullptr) << "Function '" << functionName << "' not found"; + ASSERT_TRUE(HasRestParameterFlag(fn)) << "Function '" << fn->name << "' doesn't have ACC_VARARGS flag"; + } + + void CheckNoRestParameterFlag(std::string_view functionName) + { + pandasm::Function *fn = GetFunction(functionName); + ASSERT_TRUE(fn != nullptr) << "Function '" << functionName << "' not found"; + ASSERT_FALSE(HasRestParameterFlag(fn)) << "Function '" << fn->name << "' has ACC_VARARGS flag"; + } + +private: + bool HasRestParameterFlag(pandasm::Function *fn) + { + return (fn->metadata->GetAccessFlags() & ACC_VARARGS) != 0; + } + + NO_COPY_SEMANTIC(RestParameterTest); + NO_MOVE_SEMANTIC(RestParameterTest); + + static std::unique_ptr GetProgram(int argc, const char **argv, std::string_view fileName, + std::string_view src) + { + auto options = std::make_unique(); + if (!options->Parse(argc, argv)) { + std::cerr << options->ErrorMsg() << std::endl; + return nullptr; + } + + Logger::ComponentMask mask {}; + mask.set(Logger::Component::ES2PANDA); + Logger::InitializeStdLogging(Logger::LevelFromString(options->LogLevel()), mask); + + es2panda::Compiler compiler(options->Extension(), options->ThreadCount()); + es2panda::SourceFile input(fileName, src, options->ParseModule()); + + return std::unique_ptr(compiler.Compile(input, options->CompilerOptions())); + } + + pandasm::Function *GetFunction(std::string_view functionName) + { + auto it = program_->functionTable.find(functionName.data()); + if (it == program_->functionTable.end()) { + return nullptr; + } + return &it->second; + } + +private: + std::unique_ptr program_ {}; +}; + +// === Function === +TEST_F(RestParameterTest, function_without_rest_parameters_0) +{ + SetCurrentProgram(R"( + function fn(): void { + } + )"); + CheckNoRestParameterFlag("ETSGLOBAL.fn:void;"); +} + +TEST_F(RestParameterTest, function_without_rest_parameters_1) +{ + SetCurrentProgram(R"( + function fn(args: int[]): void { + } + )"); + CheckNoRestParameterFlag("ETSGLOBAL.fn:i32[];void;"); +} + +TEST_F(RestParameterTest, function_without_rest_parameters_2) +{ + SetCurrentProgram(R"( + function fn(arg0: int, args: String[]): void { + } + )"); + CheckNoRestParameterFlag("ETSGLOBAL.fn:i32;std.core.String[];void;"); +} + +TEST_F(RestParameterTest, function_with_rest_parameter_0) +{ + SetCurrentProgram(R"( + function fn(...args: String[]): void { + } + )"); + CheckRestParameterFlag("ETSGLOBAL.fn:std.core.String[];void;"); +} + +TEST_F(RestParameterTest, function_with_rest_parameter_1) +{ + SetCurrentProgram(R"( + function fn(o: Object, ...args: int[]): void { + } + )"); + CheckRestParameterFlag("ETSGLOBAL.fn:std.core.Object;i32[];void;"); +} + +// === Method of class === +TEST_F(RestParameterTest, class_method_without_rest_parameters_0) +{ + SetCurrentProgram(R"( + class A { + fn() {}; + } + )"); + CheckNoRestParameterFlag("A.fn:void;"); +} + +TEST_F(RestParameterTest, class_method_without_rest_parameters_1) +{ + SetCurrentProgram(R"( + class A { + fn(arg0: int) {}; + } + )"); + CheckNoRestParameterFlag("A.fn:i32;void;"); +} + +TEST_F(RestParameterTest, class_method_with_rest_parameters_0) +{ + SetCurrentProgram(R"( + class A { + fn(...args: int[]) {}; + } + )"); + CheckRestParameterFlag("A.fn:i32[];void;"); +} + +// === Static method of class === +TEST_F(RestParameterTest, static_class_method_without_rest_parameters_0) +{ + SetCurrentProgram(R"( + class A { + static fn() {}; + } + )"); + CheckNoRestParameterFlag("A.fn:void;"); +} + +TEST_F(RestParameterTest, static_class_method_without_rest_parameters_1) +{ + SetCurrentProgram(R"( + class A { + static fn(arg0: int) {}; + } + )"); + CheckNoRestParameterFlag("A.fn:i32;void;"); +} + +TEST_F(RestParameterTest, static_class_method_with_rest_parameters_0) +{ + SetCurrentProgram(R"( + class A { + static fn(...args: int[]) {}; + } + )"); + CheckRestParameterFlag("A.fn:i32[];void;"); +} + +TEST_F(RestParameterTest, static_class_method_with_rest_parameters_1) +{ + SetCurrentProgram(R"( + class A { + static fn(a: String[], ...args: int[]) {}; + } + )"); + CheckRestParameterFlag("A.fn:std.core.String[];i32[];void;"); +} + +// === Constructor of class === +TEST_F(RestParameterTest, class_constructor_without_rest_parameters_0) +{ + SetCurrentProgram(R"( + class A { + constructor() {}; + } + )"); + CheckNoRestParameterFlag("A.:void;"); +} + +TEST_F(RestParameterTest, class_constructor_without_rest_parameters_1) +{ + SetCurrentProgram(R"( + class A { + constructor(args: String[]) {}; + } + )"); + CheckNoRestParameterFlag("A.:std.core.String[];void;"); +} + +TEST_F(RestParameterTest, class_constructor_with_rest_parameters_0) +{ + SetCurrentProgram(R"( + class A { + constructor(...args: int[]) {}; + } + )"); + CheckRestParameterFlag("A.:i32[];void;"); +} + +TEST_F(RestParameterTest, class_constructor_with_rest_parameters_1) +{ + SetCurrentProgram(R"( + class A { + constructor(v0: long, ...args: String[]) {}; + } + )"); + CheckRestParameterFlag("A.:i64;std.core.String[];void;"); +} + +// === Method of interface === +TEST_F(RestParameterTest, interface_without_rest_parameters_0) +{ + SetCurrentProgram(R"( + interface A { + fn() {}; + } + )"); + CheckNoRestParameterFlag("A.fn:void;"); +} + +TEST_F(RestParameterTest, interface_without_rest_parameters_1) +{ + SetCurrentProgram(R"( + interface A { + fn(args: String[]) {}; + } + )"); + CheckNoRestParameterFlag("A.fn:std.core.String[];void;"); +} + +TEST_F(RestParameterTest, interface_with_rest_parameters_0) +{ + SetCurrentProgram(R"( + interface A { + fn(...args: Object[]) {}; + } + )"); + CheckRestParameterFlag("A.fn:std.core.Object[];void;"); +} + +TEST_F(RestParameterTest, interface_with_rest_parameters_1) +{ + SetCurrentProgram(R"( + interface A { + fn(o: Object, ...args: String[]) {}; + } + )"); + CheckRestParameterFlag("A.fn:std.core.Object;std.core.String[];void;"); +} + +// === Lambda method === +TEST_F(RestParameterTest, lambda_without_rest_parameters_0) +{ + SetCurrentProgram(R"( + let fn: ()=>int = (): int => { + return 1; + } + )"); + CheckNoRestParameterFlag("LambdaObject-ETSGLOBAL-lambda$invoke$0-i32-0.invoke:i32;"); +} + +TEST_F(RestParameterTest, lambda_without_rest_parameters_1) +{ + SetCurrentProgram(R"( + let fn: (args: long[])=>int = (args: long[]): int => { + return 1; + } + )"); + CheckNoRestParameterFlag("LambdaObject-ETSGLOBAL-lambda$invoke$0-i64[]-i32-0.invoke:i64[];i32;"); +} + +// NOTE(aleksisch): lambda with rest broken, throws CTE +// TEST_F(RestParameterTest, lambda_with_rest_parameters_0) +//{ +// SetCurrentProgram(R"( +// let fn = (...args: long[]): int => { +// return 1; +// } +// )"); +// CheckRestParameterFlag("FunctionalInterface-i64[]-i32-0.invoke:i64[];i32;"); +//} + +// TEST_F(RestParameterTest, lambda_with_rest_parameters_1) +//{ +// SetCurrentProgram(R"( +// class A { +// fn = (...args: long[]): int => { +// return 1; +// } +// } +// +// let fn = (o: Object, ...args: long[]): int => { +// return 1; +// } +// )"); +// CheckRestParameterFlag("FunctionalInterface-i64[]-i32-0.invoke:i64[];i32;"); +// CheckRestParameterFlag("FunctionalInterface-std-core-Object-i64[]-i32-0.invoke:std.core.Object;i64[];i32;"); +// } + +// === Abstract method of abstract class === +TEST_F(RestParameterTest, abstract_function_without_rest_parameter_0) +{ + SetCurrentProgram(R"( + abstract class A { + abstract fn(): void + } + )"); + CheckNoRestParameterFlag("A.fn:void;"); +} + +TEST_F(RestParameterTest, abstract_function_without_rest_parameter_1) +{ + SetCurrentProgram(R"( + abstract class A { + abstract fn(args: String[]): void + } + )"); + CheckNoRestParameterFlag("A.fn:std.core.String[];void;"); +} + +TEST_F(RestParameterTest, abstract_function_with_rest_parameter_0) +{ + SetCurrentProgram(R"( + abstract class A { + abstract fn(...args: String[]): void + } + )"); + CheckRestParameterFlag("A.fn:std.core.String[];void;"); +} + +TEST_F(RestParameterTest, abstract_function_with_rest_parameter_1) +{ + SetCurrentProgram(R"( + abstract class A { + abstract fn(v: int, ...args: String[]): void + } + )"); + CheckRestParameterFlag("A.fn:i32;std.core.String[];void;"); +} + +// === External methods === +TEST_F(RestParameterTest, external_function_with_rest_parameter_0) +{ + SetCurrentProgram(""); + CheckRestParameterFlag("std.core.LambdaValue.invoke:std.core.Object[];std.core.Object;"); +} + +TEST_F(RestParameterTest, external_function_with_rest_parameter_1) +{ + SetCurrentProgram(""); + CheckRestParameterFlag("escompat.Math.max:f64[];f64;"); +} + +} // namespace ark::es2panda::compiler::test -- Gitee From 58f4336cf025ab08633fedf1788726a9fc0cc005 Mon Sep 17 00:00:00 2001 From: churkinaleksey Date: Thu, 4 Apr 2024 13:37:29 +0300 Subject: [PATCH 03/22] fix namespace alias import for dynamic Issue: https://gitee.com/openharmony/arkcompiler_runtime_core/issues/I9EYR5 Testing: all CI tests passed. Results are availible in gg watcher. Signed-off-by: churkinaleksey --- ets2panda/checker/ets/helpers.cpp | 2 +- ets2panda/checker/ets/validateHelpers.cpp | 5 + .../lowering/scopesInit/scopesInitPhase.cpp | 10 + .../lowering/scopesInit/scopesInitPhase.h | 2 +- ets2panda/ir/module/importDeclaration.cpp | 1 + ets2panda/parser/ETSparser.cpp | 2 +- ets2panda/test/CMakeLists.txt | 83 +---- .../import_all_alias_neg-expected.txt | 349 ++++++++++++++++++ .../ets/import_tests/import_all_alias_neg.ets | 18 + .../test/unit/dynamic/dynamic_call_test.cpp | 13 +- .../test/unit/rest_parameter_flag_test.cpp | 32 +- ets2panda/varbinder/ETSBinder.cpp | 33 +- 12 files changed, 414 insertions(+), 136 deletions(-) create mode 100644 ets2panda/test/parser/ets/import_tests/import_all_alias_neg-expected.txt create mode 100644 ets2panda/test/parser/ets/import_tests/import_all_alias_neg.ets diff --git a/ets2panda/checker/ets/helpers.cpp b/ets2panda/checker/ets/helpers.cpp index 9110965cc3..a253885c1a 100644 --- a/ets2panda/checker/ets/helpers.cpp +++ b/ets2panda/checker/ets/helpers.cpp @@ -253,13 +253,13 @@ checker::Type *ETSChecker::ResolveIdentifier(ir::Identifier *const ident) resolved = FindVariableInGlobal(ident); } + ident->SetVariable(resolved); // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) ValidateResolvedIdentifier(ident, resolved); ValidatePropertyAccess(resolved, Context().ContainingClass(), ident->Start()); SaveCapturedVariable(resolved, ident); - ident->SetVariable(resolved); return GetTypeOfVariable(resolved); } diff --git a/ets2panda/checker/ets/validateHelpers.cpp b/ets2panda/checker/ets/validateHelpers.cpp index 93a4ed518b..f78c1f608b 100644 --- a/ets2panda/checker/ets/validateHelpers.cpp +++ b/ets2panda/checker/ets/validateHelpers.cpp @@ -88,6 +88,11 @@ void ETSChecker::ValidateCallExpressionIdentifier(ir::Identifier *const ident, T if (ident->Parent()->AsCallExpression()->Callee() != ident) { return; } + if (ident->Variable() != nullptr && // It should always be true! + ident->Variable()->Declaration()->Node() != nullptr && + ident->Variable()->Declaration()->Node()->IsImportNamespaceSpecifier()) { + ThrowTypeError({"Namespace style identifier ", ident->Name(), " is not callable."}, ident->Start()); + } if (type->IsETSFunctionType() || type->IsETSDynamicType() || (type->IsETSObjectType() && type->AsETSObjectType()->HasObjectFlag(ETSObjectFlags::FUNCTIONAL))) { return; diff --git a/ets2panda/compiler/lowering/scopesInit/scopesInitPhase.cpp b/ets2panda/compiler/lowering/scopesInit/scopesInitPhase.cpp index be8ee46864..66028b32b4 100644 --- a/ets2panda/compiler/lowering/scopesInit/scopesInitPhase.cpp +++ b/ets2panda/compiler/lowering/scopesInit/scopesInitPhase.cpp @@ -740,6 +740,16 @@ void InitScopesPhaseETS::VisitImportNamespaceSpecifier(ir::ImportNamespaceSpecif Iterate(importSpec); } +void InitScopesPhaseETS::VisitImportSpecifier(ir::ImportSpecifier *importSpec) +{ + if (importSpec->Parent()->AsETSImportDeclaration()->IsPureDynamic()) { + auto [decl, var] = + VarBinder()->NewVarDecl(importSpec->Start(), importSpec->Local()->Name(), importSpec); + var->AddFlag(varbinder::VariableFlags::INITIALIZED); + } + Iterate(importSpec); +} + // Auxiliary method to avoid extra nested levels and too large function size void AddOverload(ir::MethodDefinition *overload, varbinder::Variable *variable) noexcept { diff --git a/ets2panda/compiler/lowering/scopesInit/scopesInitPhase.h b/ets2panda/compiler/lowering/scopesInit/scopesInitPhase.h index 29bed5afae..77dc1c45d6 100644 --- a/ets2panda/compiler/lowering/scopesInit/scopesInitPhase.h +++ b/ets2panda/compiler/lowering/scopesInit/scopesInitPhase.h @@ -337,7 +337,7 @@ private: void VisitClassStaticBlock(ir::ClassStaticBlock *staticBlock) override; void VisitBlockExpression(ir::BlockExpression *blockExpr) override; void VisitImportNamespaceSpecifier(ir::ImportNamespaceSpecifier *importSpec) override; - void VisitImportSpecifier([[maybe_unused]] ir::ImportSpecifier *importSpec) override {}; + void VisitImportSpecifier([[maybe_unused]] ir::ImportSpecifier *importSpec) override; void VisitImportDefaultSpecifier([[maybe_unused]] ir::ImportDefaultSpecifier *importSpec) override {}; void VisitETSReExportDeclaration(ir::ETSReExportDeclaration *reExport) override; void VisitETSParameterExpression(ir::ETSParameterExpression *paramExpr) override; diff --git a/ets2panda/ir/module/importDeclaration.cpp b/ets2panda/ir/module/importDeclaration.cpp index aa25c7a4f7..f2c577a806 100644 --- a/ets2panda/ir/module/importDeclaration.cpp +++ b/ets2panda/ir/module/importDeclaration.cpp @@ -22,6 +22,7 @@ #include "ir/srcDump.h" namespace ark::es2panda::ir { + void ImportDeclaration::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { if (auto *transformedNode = cb(source_); source_ != transformedNode) { diff --git a/ets2panda/parser/ETSparser.cpp b/ets2panda/parser/ETSparser.cpp index e3036eb88a..2646d717a0 100644 --- a/ets2panda/parser/ETSparser.cpp +++ b/ets2panda/parser/ETSparser.cpp @@ -2337,7 +2337,7 @@ ir::Statement *ETSParser::ParseExport(lexer::SourcePosition startLoc, ir::Modifi ir::ImportSource *reExportSource = ParseSourceFromClause(true); lexer::SourcePosition endLoc = reExportSource->Source()->End(); - auto *reExportDeclaration = AllocNode(reExportSource, specifiers); + auto *reExportDeclaration = AllocNode(reExportSource, std::move(specifiers)); reExportDeclaration->SetRange({startLoc, endLoc}); ConsumeSemicolon(reExportDeclaration); diff --git a/ets2panda/test/CMakeLists.txt b/ets2panda/test/CMakeLists.txt index d82d4a9aa6..83235a3e2e 100644 --- a/ets2panda/test/CMakeLists.txt +++ b/ets2panda/test/CMakeLists.txt @@ -46,12 +46,12 @@ function(ets2panda_add_gtest TARGET) NAME ${TARGET} SOURCES ${ARG_CPP_SOURCES} LIBRARIES - es2panda-public es2panda-lib + es2panda-public es2panda-lib arkassembler arkbytecodeopt INCLUDE_DIRS - ${ES2PANDA_PATH} - ${ES2PANDA_BINARY_ROOT} + ${ES2PANDA_PATH} + ${ES2PANDA_BINARY_ROOT} SANITIZERS - ${PANDA_SANITIZERS_LIST} + ${PANDA_SANITIZERS_LIST} ) endfunction(ets2panda_add_gtest) @@ -92,75 +92,12 @@ if(PANDA_REGRESSION_TESTS) add_dependencies(es2panda-plugin-test es2panda e2p_test_plugin) add_dependencies(es2panda_tests es2panda-plugin-test) - ets2panda_add_gtest(es2panda_dynamic_call_test - CPP_SOURCES unit/dynamic/dynamic_call_test.cpp - ) - - panda_add_gtest( - NAME es2panda_astverifier_tests - SOURCES - unit/public/ast_verifier_test.cpp - LIBRARIES - es2panda-public es2panda-lib - INCLUDE_DIRS - ${ES2PANDA_PATH} - ${ES2PANDA_BINARY_ROOT} - SANITIZERS - ${PANDA_SANITIZERS_LIST} - ) - - if(PANDA_WITH_ETS) - panda_add_gtest( - NAME scopes_initialization_test - SOURCES - unit/lowerings/scopes_initialization.cpp - LIBRARIES - es2panda-lib es2panda-public arkassembler arkbytecodeopt - INCLUDE_DIRS - ${ES2PANDA_PATH} - ${OUTPUT_DIR} - - SANITIZERS - ${PANDA_SANITIZERS_LIST} - ) - panda_add_gtest( - NAME es2panda_checker_tests - SOURCES - unit/checker_test.cpp - LIBRARIES - es2panda-public es2panda-lib - INCLUDE_DIRS - ${ES2PANDA_ROOT} - SANITIZERS - ${PANDA_SANITIZERS_LIST} - ) - - endif() - - panda_add_gtest( - NAME es2panda_astdumper_tests - SOURCES - unit/ast_dumper_test.cpp - LIBRARIES - es2panda-public es2panda-lib arkassembler arkbytecodeopt - INCLUDE_DIRS - ${ES2PANDA_PATH} - SANITIZERS - ${PANDA_SANITIZERS_LIST} - ) - - panda_add_gtest( - NAME es2panda_union_normalization_tests - SOURCES - unit/union_normalization_test.cpp - LIBRARIES - es2panda-public es2panda-lib arkassembler arkbytecodeopt - INCLUDE_DIRS - ${ES2PANDA_PATH} - ${ES2PANDA_BINARY_ROOT} - SANITIZERS - ${PANDA_SANITIZERS_LIST} - ) + ets2panda_add_gtest(es2panda_dynamic_call_test CPP_SOURCES unit/dynamic/dynamic_call_test.cpp) + ets2panda_add_gtest(es2panda_astverifier_tests CPP_SOURCES unit/public/ast_verifier_test.cpp) + ets2panda_add_gtest(scopes_initialization_test CPP_SOURCES unit/lowerings/scopes_initialization.cpp) + ets2panda_add_gtest(es2panda_checker_tests CPP_SOURCES unit/checker_test.cpp) + ets2panda_add_gtest(es2panda_astdumper_tests CPP_SOURCES unit/ast_dumper_test.cpp) + ets2panda_add_gtest(es2panda_union_normalization_tests CPP_SOURCES unit/union_normalization_test.cpp) # NOTE: es2panda_rest_parameter_flag test runs a lot of time on qemu, so let's disable it if (NOT PANDA_QEMU_BUILD) diff --git a/ets2panda/test/parser/ets/import_tests/import_all_alias_neg-expected.txt b/ets2panda/test/parser/ets/import_tests/import_all_alias_neg-expected.txt new file mode 100644 index 0000000000..feb58d3f2f --- /dev/null +++ b/ets2panda/test/parser/ets/import_tests/import_all_alias_neg-expected.txt @@ -0,0 +1,349 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ImportDeclaration", + "source": { + "type": "StringLiteral", + "value": "import_tests/packages", + "loc": { + "start": { + "line": 16, + "column": 23 + }, + "end": { + "line": 16, + "column": 46 + } + } + }, + "specifiers": [ + { + "type": "ImportNamespaceSpecifier", + "local": { + "type": "Identifier", + "name": "Test", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 13 + }, + "end": { + "line": 16, + "column": 17 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 16, + "column": 17 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 16, + "column": 47 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 14 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "Test", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 19 + }, + "end": { + "line": 18, + "column": 23 + } + } + }, + "arguments": [], + "optional": false, + "loc": { + "start": { + "line": 18, + "column": 19 + }, + "end": { + "line": 18, + "column": 25 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 19 + }, + "end": { + "line": 18, + "column": 25 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 17 + }, + "end": { + "line": 18, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 18, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 18, + "column": 27 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 18, + "column": 27 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 18, + "column": 27 + } + } +} +TypeError: Namespace style identifier Test is not callable. [import_all_alias_neg.ets:18:19] diff --git a/ets2panda/test/parser/ets/import_tests/import_all_alias_neg.ets b/ets2panda/test/parser/ets/import_tests/import_all_alias_neg.ets new file mode 100644 index 0000000000..d5aa69dbb2 --- /dev/null +++ b/ets2panda/test/parser/ets/import_tests/import_all_alias_neg.ets @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import * as Test from "import_tests/packages"; + +function main() { Test() } \ No newline at end of file diff --git a/ets2panda/test/unit/dynamic/dynamic_call_test.cpp b/ets2panda/test/unit/dynamic/dynamic_call_test.cpp index ad7a3fa7fd..bc293db96b 100644 --- a/ets2panda/test/unit/dynamic/dynamic_call_test.cpp +++ b/ets2panda/test/unit/dynamic/dynamic_call_test.cpp @@ -23,6 +23,8 @@ #include "ir/ets/etsTypeReferencePart.h" #include "ir/ets/etsTypeReference.h" #include "ir/ts/tsQualifiedName.h" +#include "util/helpers.h" +#include "compiler/lowering/scopesInit/scopesInitPhase.h" #include "util/language.h" #include "parser/ETSparser.h" @@ -77,13 +79,16 @@ public: void AddDynImport(const char *specifierName, varbinder::ETSBinder *varbinder, ir::Identifier *node) { auto aIdent = Allocator()->New(specifierName, Allocator()); + ArenaVector specifiers {Allocator()->Adapter()}; auto specifier = Allocator()->New(aIdent, aIdent); - auto importSrc = Allocator()->New(Allocator()->New(), + specifiers.emplace_back(specifier); + auto importSrc = Allocator()->New(Allocator()->New("/tmp"), Allocator()->New(), - Language::FromString("ets").value(), false); + Language::FromString("js").value(), false); auto importDecl = - Allocator()->New(importSrc, ArenaVector {Allocator()->Adapter()}); - varbinder->AddDynamicSpecifiersToTopBindings(specifier, importDecl); + util::NodeAllocator::Alloc(Allocator(), importSrc, std::move(specifiers)); + compiler::InitScopesPhaseETS::RunExternalNode(importDecl, varbinder); + varbinder->BuildImportDeclaration(importDecl); auto var = varbinder->TopScope()->Find(specifierName); node->SetVariable(var.variable); } diff --git a/ets2panda/test/unit/rest_parameter_flag_test.cpp b/ets2panda/test/unit/rest_parameter_flag_test.cpp index c78f7f6e86..62b3f40159 100644 --- a/ets2panda/test/unit/rest_parameter_flag_test.cpp +++ b/ets2panda/test/unit/rest_parameter_flag_test.cpp @@ -29,9 +29,9 @@ class RestParameterTest : public testing::Test { public: RestParameterTest() { - constexpr auto COMPILER_SIZE = 268435456; + const auto compilerSize = 268435456; - mem::MemConfig::Initialize(0, 0, COMPILER_SIZE, 0, 0, 0); + mem::MemConfig::Initialize(0, 0, compilerSize, 0, 0, 0); PoolManager::Initialize(PoolType::MMAP); } ~RestParameterTest() override @@ -326,34 +326,6 @@ TEST_F(RestParameterTest, lambda_without_rest_parameters_1) CheckNoRestParameterFlag("LambdaObject-ETSGLOBAL-lambda$invoke$0-i64[]-i32-0.invoke:i64[];i32;"); } -// NOTE(aleksisch): lambda with rest broken, throws CTE -// TEST_F(RestParameterTest, lambda_with_rest_parameters_0) -//{ -// SetCurrentProgram(R"( -// let fn = (...args: long[]): int => { -// return 1; -// } -// )"); -// CheckRestParameterFlag("FunctionalInterface-i64[]-i32-0.invoke:i64[];i32;"); -//} - -// TEST_F(RestParameterTest, lambda_with_rest_parameters_1) -//{ -// SetCurrentProgram(R"( -// class A { -// fn = (...args: long[]): int => { -// return 1; -// } -// } -// -// let fn = (o: Object, ...args: long[]): int => { -// return 1; -// } -// )"); -// CheckRestParameterFlag("FunctionalInterface-i64[]-i32-0.invoke:i64[];i32;"); -// CheckRestParameterFlag("FunctionalInterface-std-core-Object-i64[]-i32-0.invoke:std.core.Object;i64[];i32;"); -// } - // === Abstract method of abstract class === TEST_F(RestParameterTest, abstract_function_without_rest_parameter_0) { diff --git a/ets2panda/varbinder/ETSBinder.cpp b/ets2panda/varbinder/ETSBinder.cpp index b2ca3807ca..6d61725646 100644 --- a/ets2panda/varbinder/ETSBinder.cpp +++ b/ets2panda/varbinder/ETSBinder.cpp @@ -438,13 +438,9 @@ void ETSBinder::AddDynamicSpecifiersToTopBindings(ir::AstNode *const specifier, return specifier->AsImportSpecifier()->Local()->Name(); }(); - auto *const decl = Allocator()->New(name, specifier); - auto *const var = Allocator()->New(decl, varbinder::VariableFlags::STATIC); - var->AddFlag(VariableFlags::INITIALIZED); - - dynamicImportVars_.emplace(var, DynamicImportData {import, specifier, var}); - - TopScope()->InsertDynamicBinding(name, var); + ASSERT(GetScope()->Find(name, ResolveBindingOptions::DECLARATION).variable != nullptr); + auto specDecl = GetScope()->Find(name, ResolveBindingOptions::DECLARATION); + dynamicImportVars_.emplace(specDecl.variable, DynamicImportData {import, specifier, specDecl.variable}); } void ETSBinder::InsertForeignBinding(ir::AstNode *const specifier, const ir::ETSImportDeclaration *const import, @@ -512,7 +508,7 @@ bool ETSBinder::AddImportNamespaceSpecifiersToTopBindings(ir::AstNode *const spe } for (auto it : item->GetETSImportDeclarations()->Specifiers()) { - if (it->IsImportNamespaceSpecifier() && !specifier->AsImportNamespaceSpecifier()->Local()->Name().Empty()) { + if (it->IsImportNamespaceSpecifier() && !namespaceSpecifier->Local()->Name().Empty()) { continue; } @@ -604,13 +600,6 @@ bool ETSBinder::AddImportSpecifiersToTopBindings(ir::AstNode *const specifier, return false; } const ir::StringLiteral *const importPath = import->Source(); - auto insertForeignBinding = [this, specifier, import](const util::StringView &name, Variable *var) { - if (import->Language().IsDynamic()) { - dynamicImportVars_.emplace(var, DynamicImportData {import, specifier, var}); - } - - TopScope()->InsertForeignBinding(name, var); - }; const auto *const importSpecifier = specifier->AsImportSpecifier(); @@ -668,7 +657,7 @@ bool ETSBinder::AddImportSpecifiersToTopBindings(ir::AstNode *const specifier, ThrowError(importPath->Start(), "Imported element not exported '" + var->Declaration()->Name().Mutf8() + "'"); } - insertForeignBinding(localName, var); + InsertForeignBinding(specifier, import, localName, var); return true; } @@ -720,14 +709,6 @@ void ETSBinder::AddSpecifiersToTopBindings(ir::AstNode *const specifier, const i const auto *const importGlobalScope = importProgram->GlobalScope(); const auto &globalBindings = importGlobalScope->Bindings(); - auto insertForeignBinding = [this, specifier, import](const util::StringView &name, Variable *var) { - if (import->Language().IsDynamic()) { - dynamicImportVars_.emplace(var, DynamicImportData {import, specifier, var}); - } - - TopScope()->InsertForeignBinding(name, var); - }; - if (AddImportNamespaceSpecifiersToTopBindings(specifier, globalBindings, importProgram, importGlobalScope, import)) { return; @@ -742,12 +723,12 @@ void ETSBinder::AddSpecifiersToTopBindings(ir::AstNode *const specifier, const i auto item = std::find_if(globalBindings.begin(), globalBindings.end(), predicateFunc); if (item == globalBindings.end()) { - insertForeignBinding(specifier->AsImportDefaultSpecifier()->Local()->Name(), + InsertForeignBinding(specifier, import, specifier->AsImportDefaultSpecifier()->Local()->Name(), FindStaticBinding(record, importPath)); return; } - insertForeignBinding(specifier->AsImportDefaultSpecifier()->Local()->Name(), item->second); + InsertForeignBinding(specifier, import, specifier->AsImportDefaultSpecifier()->Local()->Name(), item->second); } void ETSBinder::HandleCustomNodes(ir::AstNode *childNode) -- Gitee From e8178ccf815f0e8dc73be3d8e4a352f1a072788c Mon Sep 17 00:00:00 2001 From: Vyacheslav Cherkashin Date: Mon, 15 Jan 2024 15:21:56 +0300 Subject: [PATCH 04/22] Support instanceof for dynamic declarations Issue: #I8WD6G Testing: CI tests passed Signed-off-by: Vyacheslav Cherkashin --- ets2panda/checker/ets/arithmetic.cpp | 6 +- ets2panda/checker/ets/helpers.cpp | 24 +- ets2panda/compiler/base/condition.cpp | 5 +- ets2panda/compiler/core/ETSCompiler.cpp | 7 +- ets2panda/compiler/core/ETSGen.cpp | 72 +- ets2panda/compiler/core/ETSGen.h | 13 +- ets2panda/compiler/scripts/signatures.yaml | 12 +- ets2panda/compiler/templates/isa.h.erb | 12 +- ets2panda/ir/ets/etsTypeReferencePart.cpp | 43 +- ets2panda/ir/expressions/binaryExpression.cpp | 14 + ets2panda/ir/expressions/binaryExpression.h | 2 + .../instanceof_dyndecl_dynvalue-expected.txt | 1 + .../ets/instanceof_dyndecl_dynvalue.ets | 26 + .../instanceof_dyndecl_jsvalue-expected.txt | 1 + .../ets/instanceof_dyndecl_jsvalue.ets | 24 + .../instanceof_dynvalue_dynvalue-expected.txt | 1 + .../ets/instanceof_dynvalue_dynvalue.ets | 24 + .../instanceof_dynvalue_jsvalue-expected.txt | 1 + .../ets/instanceof_dynvalue_jsvalue.ets | 24 + ...instanceof_etsobject_dynvalue-expected.txt | 1 + .../ets/instanceof_etsobject_dynvalue.ets | 26 + .../instanceof_etsobject_jsvalue-expected.txt | 1 + .../ets/instanceof_etsobject_jsvalue.ets | 24 + .../instanceof_jsvalue_dynvalue-expected.txt | 1 + .../ets/instanceof_jsvalue_dynvalue.ets | 24 + .../instanceof_jsvalue_jsvalue-expected.txt | 1 + .../ets/instanceof_jsvalue_jsvalue.ets | 22 + .../instanceof_object_dynvalue-expected.txt | 1 + .../ets/instanceof_object_dynvalue.ets | 24 + .../instanceof_object_jsvalue-expected.txt | 1 + .../ets/instanceof_object_jsvalue.ets | 22 + .../ets/instanceof_object_long-expected.txt | 1 + .../compiler/ets/instanceof_object_long.ets | 22 + .../ets/instanceof_x_dyndecl-expected.txt | 2189 +++++++++++++++++ .../compiler/ets/instanceof_x_dyndecl.ets | 43 + ....txt => instanceof_x_etstype-expected.txt} | 2126 ++++++++-------- .../compiler/ets/instanceof_x_etstype.ets | 44 + .../ets/instanceof_x_object-expected.txt | 2146 ++++++++++++++++ .../test/compiler/ets/instanceof_x_object.ets | 43 + .../dynamic_decl_import-expected.txt | 4 +- .../dynamic_decl_import.ets | 4 +- .../modules/instanceof-expected.txt | 427 ++++ .../modules/instanceof.ets} | 18 +- .../test-lists/parser/parser-js-ignored.txt | 3 - 44 files changed, 6381 insertions(+), 1149 deletions(-) create mode 100644 ets2panda/test/compiler/ets/instanceof_dyndecl_dynvalue-expected.txt create mode 100644 ets2panda/test/compiler/ets/instanceof_dyndecl_dynvalue.ets create mode 100644 ets2panda/test/compiler/ets/instanceof_dyndecl_jsvalue-expected.txt create mode 100644 ets2panda/test/compiler/ets/instanceof_dyndecl_jsvalue.ets create mode 100644 ets2panda/test/compiler/ets/instanceof_dynvalue_dynvalue-expected.txt create mode 100644 ets2panda/test/compiler/ets/instanceof_dynvalue_dynvalue.ets create mode 100644 ets2panda/test/compiler/ets/instanceof_dynvalue_jsvalue-expected.txt create mode 100644 ets2panda/test/compiler/ets/instanceof_dynvalue_jsvalue.ets create mode 100644 ets2panda/test/compiler/ets/instanceof_etsobject_dynvalue-expected.txt create mode 100644 ets2panda/test/compiler/ets/instanceof_etsobject_dynvalue.ets create mode 100644 ets2panda/test/compiler/ets/instanceof_etsobject_jsvalue-expected.txt create mode 100644 ets2panda/test/compiler/ets/instanceof_etsobject_jsvalue.ets create mode 100644 ets2panda/test/compiler/ets/instanceof_jsvalue_dynvalue-expected.txt create mode 100644 ets2panda/test/compiler/ets/instanceof_jsvalue_dynvalue.ets create mode 100644 ets2panda/test/compiler/ets/instanceof_jsvalue_jsvalue-expected.txt create mode 100644 ets2panda/test/compiler/ets/instanceof_jsvalue_jsvalue.ets create mode 100644 ets2panda/test/compiler/ets/instanceof_object_dynvalue-expected.txt create mode 100644 ets2panda/test/compiler/ets/instanceof_object_dynvalue.ets create mode 100644 ets2panda/test/compiler/ets/instanceof_object_jsvalue-expected.txt create mode 100644 ets2panda/test/compiler/ets/instanceof_object_jsvalue.ets create mode 100644 ets2panda/test/compiler/ets/instanceof_object_long-expected.txt create mode 100644 ets2panda/test/compiler/ets/instanceof_object_long.ets create mode 100644 ets2panda/test/compiler/ets/instanceof_x_dyndecl-expected.txt create mode 100644 ets2panda/test/compiler/ets/instanceof_x_dyndecl.ets rename ets2panda/test/compiler/ets/{dynamic_instanceof-expected.txt => instanceof_x_etstype-expected.txt} (58%) create mode 100644 ets2panda/test/compiler/ets/instanceof_x_etstype.ets create mode 100644 ets2panda/test/compiler/ets/instanceof_x_object-expected.txt create mode 100644 ets2panda/test/compiler/ets/instanceof_x_object.ets create mode 100644 ets2panda/test/parser/ets/dynamic_import_tests/modules/instanceof-expected.txt rename ets2panda/test/{compiler/ets/dynamic_instanceof.ets => parser/ets/dynamic_import_tests/modules/instanceof.ets} (71%) diff --git a/ets2panda/checker/ets/arithmetic.cpp b/ets2panda/checker/ets/arithmetic.cpp index 6def0c73b1..b0798dd1a7 100644 --- a/ets2panda/checker/ets/arithmetic.cpp +++ b/ets2panda/checker/ets/arithmetic.cpp @@ -507,10 +507,8 @@ std::tuple ETSChecker::CheckBinaryOperatorInstanceOf(lexer::Sour ThrowTypeError("Bad operand type, the types of the operands must be same type.", pos); } - if (rightType->IsETSDynamicType() || leftType->IsETSDynamicType()) { - if (!(rightType->IsETSDynamicType() && leftType->IsETSDynamicType())) { - ThrowTypeError("Bad operand type, both types of the operands must be dynamic.", pos); - } + if (rightType->IsETSDynamicType() && !rightType->AsETSDynamicType()->HasDecl()) { + ThrowTypeError("Right-hand side of instanceof expression must represent a type.", pos); } tsType = GlobalETSBooleanType(); diff --git a/ets2panda/checker/ets/helpers.cpp b/ets2panda/checker/ets/helpers.cpp index a253885c1a..4f40f721aa 100644 --- a/ets2panda/checker/ets/helpers.cpp +++ b/ets2panda/checker/ets/helpers.cpp @@ -1198,8 +1198,7 @@ Type *ETSChecker::GetReferencedTypeFromBase([[maybe_unused]] Type *baseType, [[m Type *ETSChecker::GetReferencedTypeBase(ir::Expression *name) { if (name->IsTSQualifiedName()) { - auto *qualified = name->AsTSQualifiedName(); - return qualified->Check(this); + return name->Check(this); } ASSERT(name->IsIdentifier() && name->AsIdentifier()->Variable() != nullptr); @@ -1207,34 +1206,43 @@ Type *ETSChecker::GetReferencedTypeBase(ir::Expression *name) // NOTE: kbaladurin. forbid usage imported entities as types without declarations auto *importData = VarBinder()->AsETSBinder()->DynamicImportDataForVar(name->AsIdentifier()->Variable()); if (importData != nullptr && importData->import->IsPureDynamic()) { - return GlobalBuiltinDynamicType(importData->import->Language()); + name->SetTsType(GlobalBuiltinDynamicType(importData->import->Language())); + return name->TsType(); } auto *refVar = name->AsIdentifier()->Variable()->AsLocalVariable(); + checker::Type *tsType = nullptr; switch (refVar->Declaration()->Node()->Type()) { case ir::AstNodeType::TS_INTERFACE_DECLARATION: { - return GetTypeFromInterfaceReference(refVar); + tsType = GetTypeFromInterfaceReference(refVar); + break; } case ir::AstNodeType::CLASS_DECLARATION: case ir::AstNodeType::STRUCT_DECLARATION: case ir::AstNodeType::CLASS_DEFINITION: { - return GetTypeFromClassReference(refVar); + tsType = GetTypeFromClassReference(refVar); + break; } case ir::AstNodeType::TS_ENUM_DECLARATION: { // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) - return GetTypeFromEnumReference(refVar); + tsType = GetTypeFromEnumReference(refVar); + break; } case ir::AstNodeType::TS_TYPE_PARAMETER: { - return GetTypeFromTypeParameterReference(refVar, name->Start()); + tsType = GetTypeFromTypeParameterReference(refVar, name->Start()); + break; } case ir::AstNodeType::TS_TYPE_ALIAS_DECLARATION: { - return GetTypeFromTypeAliasReference(refVar); + tsType = GetTypeFromTypeAliasReference(refVar); + break; } default: { UNREACHABLE(); } } + name->SetTsType(tsType); + return tsType; } void ETSChecker::ConcatConstantString(util::UString &target, Type *type) diff --git a/ets2panda/compiler/base/condition.cpp b/ets2panda/compiler/base/condition.cpp index 618de0ab7e..87a82b2d09 100644 --- a/ets2panda/compiler/base/condition.cpp +++ b/ets2panda/compiler/base/condition.cpp @@ -260,10 +260,7 @@ bool Condition::CompileBinaryExpr(ETSGen *etsg, const ir::BinaryExpression *binE RegScope rs(etsg); VReg lhs = etsg->AllocReg(); - binExpr->Left()->Compile(etsg); - etsg->ApplyConversionAndStoreAccumulator(binExpr->Left(), lhs, binExpr->OperationType()); - binExpr->Right()->Compile(etsg); - etsg->ApplyConversion(binExpr->Right(), binExpr->OperationType()); + binExpr->CompileOperands(etsg, lhs); etsg->Condition(binExpr, binExpr->OperatorType(), lhs, falseLabel); return true; } diff --git a/ets2panda/compiler/core/ETSCompiler.cpp b/ets2panda/compiler/core/ETSCompiler.cpp index 8b837ef382..e30ad376fb 100644 --- a/ets2panda/compiler/core/ETSCompiler.cpp +++ b/ets2panda/compiler/core/ETSCompiler.cpp @@ -580,7 +580,7 @@ static void CompileInstanceof(compiler::ETSGen *etsg, const ir::BinaryExpression expr->Left()->Compile(etsg); etsg->ApplyConversionAndStoreAccumulator(expr->Left(), lhs, expr->OperationType()); - if (expr->Right()->TsType()->IsETSDynamicType()) { + if (expr->Left()->TsType()->IsETSDynamicType() || expr->Right()->TsType()->IsETSDynamicType()) { auto rhs = etsg->AllocReg(); expr->Right()->Compile(etsg); etsg->StoreAccumulator(expr, rhs); @@ -691,10 +691,7 @@ void ETSCompiler::Compile(const ir::BinaryExpression *expr) const return; } - expr->Left()->Compile(etsg); - etsg->ApplyConversionAndStoreAccumulator(expr->Left(), lhs, expr->OperationType()); - expr->Right()->Compile(etsg); - etsg->ApplyConversion(expr->Right(), expr->OperationType()); + expr->CompileOperands(etsg, lhs); if (expr->OperationType()->IsIntType()) { etsg->ApplyCast(expr->Right(), expr->OperationType()); } diff --git a/ets2panda/compiler/core/ETSGen.cpp b/ets2panda/compiler/core/ETSGen.cpp index fbdfd5f110..8d0eee7393 100644 --- a/ets2panda/compiler/core/ETSGen.cpp +++ b/ets2panda/compiler/core/ETSGen.cpp @@ -773,11 +773,75 @@ static bool IsAnyReferenceSupertype(checker::Type const *type) }); } -void ETSGen::IsInstanceDynamic(const ir::AstNode *const node, const VReg srcReg, [[maybe_unused]] const VReg tgtReg) +void ETSGen::IsInstanceDynamic(const ir::BinaryExpression *const node, const VReg srcReg, + [[maybe_unused]] const VReg tgtReg) { - ASSERT(Checker()->GetApparentType(GetVRegType(tgtReg))->IsETSDynamicType() && - GetVRegType(srcReg)->IsETSDynamicType()); - Ra().Emit(node, Signatures::BUILTIN_JSRUNTIME_INSTANCE_OF, srcReg, MoveAccToReg(node)); + ASSERT(node->OperatorType() == lexer::TokenType::KEYW_INSTANCEOF); + const checker::Type *lhsType = node->Left()->TsType(); + const checker::Type *rhsType = node->Right()->TsType(); + ASSERT(rhsType->IsETSDynamicType() || lhsType->IsETSDynamicType()); + + const RegScope rs(this); + if (rhsType->IsETSDynamicType()) { + ASSERT(node->Right()->TsType()->AsETSDynamicType()->HasDecl()); + if (lhsType->IsETSDynamicType()) { + VReg dynTypeReg = MoveAccToReg(node); + // Semantics: + // let dyn_val: JSValue = ... + // dyn_value instanceof DynamicDecl + // Bytecode: + // call runtime intrinsic_dynamic + CallStatic2(node, Signatures::BUILTIN_JSRUNTIME_INSTANCE_OF_DYNAMIC, srcReg, dynTypeReg); + } else if (lhsType == Checker()->GlobalETSObjectType()) { + // Semantics: + // let obj: Object = ... + // obj instanceof DynamicDecl + // Bytecode: + // if isinstance : + // checkcast + // return call runtime intrinsic_dynamic + // return false + Label *ifFalse = AllocLabel(); + Language lang = rhsType->AsETSDynamicType()->Language(); + VReg dynTypeReg = MoveAccToReg(node); + LoadAccumulator(node, srcReg); + Sa().Emit(node, Checker()->GlobalBuiltinDynamicType(lang)->AssemblerName()); + BranchIfFalse(node, ifFalse); + LoadAccumulator(node, srcReg); + Sa().Emit(node, Checker()->GlobalBuiltinDynamicType(lang)->AssemblerName()); + CallStatic2(node, Signatures::BUILTIN_JSRUNTIME_INSTANCE_OF_DYNAMIC, srcReg, dynTypeReg); + SetLabel(node, ifFalse); + } else { + // Semantics: + // let obj: EtsType = ... + // obj instanceof DynamicDecl + // Bytecode: + // False + Sa().Emit(node, 0); + } + } else { + if (lhsType->IsETSDynamicType()) { + if (rhsType == Checker()->GlobalETSObjectType()) { + // Semantics: + // let dyn_val: JSValue = ... + // dyn_val instanceof Object + // Bytecode: + // True + Sa().Emit(node, 1); + } else { + // Semantics: + // let dyn_val: JSValue = ... + // dyn_val instanceof EtsType + // Bytecode: + // lda.type + call runtime instrinsic_static + Sa().Emit(node, rhsType->AsETSObjectType()->AssemblerName()); + VReg typeReg = MoveAccToReg(node); + CallStatic2(node, Signatures::BUILTIN_JSRUNTIME_INSTANCE_OF_STATIC, srcReg, typeReg); + } + } else { + UNREACHABLE(); + } + } SetAccumulatorType(Checker()->GlobalETSBooleanType()); } diff --git a/ets2panda/compiler/core/ETSGen.h b/ets2panda/compiler/core/ETSGen.h index 42267cbd54..1fc18ebe3b 100644 --- a/ets2panda/compiler/core/ETSGen.h +++ b/ets2panda/compiler/core/ETSGen.h @@ -93,7 +93,7 @@ public: void BranchIfIsInstance(const ir::AstNode *node, VReg srcReg, const checker::Type *target, Label *ifTrue); void IsInstance(const ir::AstNode *node, VReg srcReg, checker::Type const *target); - void IsInstanceDynamic(const ir::AstNode *node, VReg srcReg, VReg tgtReg); + void IsInstanceDynamic(const ir::BinaryExpression *node, VReg srcReg, VReg tgtReg); void EmitFailedTypeCastException(const ir::AstNode *node, VReg src, checker::Type const *target); void Binary(const ir::AstNode *node, lexer::TokenType op, VReg lhs); @@ -564,6 +564,16 @@ public: Ra().Emit(node, name, dummyReg_, dummyReg_); } + void CallStatic1(const ir::AstNode *const node, const util::StringView name, const VReg arg0) + { + Ra().Emit(node, name, arg0, dummyReg_); + } + + void CallStatic2(const ir::AstNode *const node, const util::StringView name, const VReg arg0, const VReg arg1) + { + Ra().Emit(node, name, arg0, arg1); + } + void CallThisStatic0(const ir::AstNode *const node, const VReg ctor, const util::StringView name) { Ra().Emit(node, name, ctor, dummyReg_); @@ -1041,6 +1051,7 @@ private: void CallImpl(const ir::AstNode *node, checker::Signature const *signature, const ArenaVector &arguments) { + ASSERT(signature != nullptr); RegScope rs(this); if (ResolveStringFromNullishBuiltin(node, signature, arguments)) { return; diff --git a/ets2panda/compiler/scripts/signatures.yaml b/ets2panda/compiler/scripts/signatures.yaml index 20746ed7eb..813c238ee0 100644 --- a/ets2panda/compiler/scripts/signatures.yaml +++ b/ets2panda/compiler/scripts/signatures.yaml @@ -1136,10 +1136,18 @@ signatures: ref: BUILTIN_JSRUNTIME_STRICT_EQUAL - callee: BUILTIN_JSRUNTIME - method_name: instanceOf + method_name: instanceOfDynamic params: [BUILTIN_JSVALUE, BUILTIN_JSVALUE] return_type: PRIMITIVE_BOOLEAN - ref: BUILTIN_JSRUNTIME_INSTANCE_OF + ref: BUILTIN_JSRUNTIME_INSTANCE_OF_DYNAMIC + + - callee: BUILTIN_JSRUNTIME + method_name: instanceOfStatic + # NOTE(v.cherkashin): + # Replace BUILTIN_OBJECT by BUILTIN_TYPE when issue #15273 was resolved + params: [BUILTIN_JSVALUE, BUILTIN_OBJECT] # 2nd argument is ClassClass + return_type: PRIMITIVE_BOOLEAN + ref: BUILTIN_JSRUNTIME_INSTANCE_OF_STATIC - callee: BUILTIN_JSVALUE method_name: toString diff --git a/ets2panda/compiler/templates/isa.h.erb b/ets2panda/compiler/templates/isa.h.erb index 588d7702cf..226519bcdf 100644 --- a/ets2panda/compiler/templates/isa.h.erb +++ b/ets2panda/compiler/templates/isa.h.erb @@ -126,9 +126,17 @@ private: class <%= class_name %> : public <%= base_class %> { public: - explicit <%= class_name %>(<%= ctor_args %>) : <%= base_class %>(node)<%= ops %> {} + explicit <%= class_name %>(<%= ctor_args %>) : <%= base_class %>(node)<%= ops %> + { +% insn.operands.each do |operand| +% if operand.id? && operand.name != :string_id + ASSERT(!string_id.Empty()); +% end +% end + } - Formats GetFormats() const override { + Formats GetFormats() const override + { return Span(<%= get_format_name(insn.mnemonic) %>); } diff --git a/ets2panda/ir/ets/etsTypeReferencePart.cpp b/ets2panda/ir/ets/etsTypeReferencePart.cpp index 44c6a4ba6b..fbc40255c9 100644 --- a/ets2panda/ir/ets/etsTypeReferencePart.cpp +++ b/ets2panda/ir/ets/etsTypeReferencePart.cpp @@ -99,32 +99,31 @@ checker::Type *ETSTypeReferencePart::GetType(checker::ETSChecker *checker) { if (prev_ == nullptr) { if (name_->IsIdentifier()) { - if ((name_->AsIdentifier()->Variable() != nullptr) && - (name_->AsIdentifier()->Variable()->Declaration()->IsTypeAliasDecl())) { - return checker->HandleTypeAlias(name_, typeParams_); - } - if (name_->AsIdentifier()->Name() == compiler::Signatures::UNDEFINED) { - return checker->GlobalETSUndefinedType(); - } - - if (name_->AsIdentifier()->Name() == compiler::Signatures::NULL_LITERAL) { - return checker->GlobalETSNullType(); + const auto ident = name_->AsIdentifier(); + if ((ident->Variable() != nullptr) && (ident->Variable()->Declaration()->IsTypeAliasDecl())) { + SetTsType(checker->HandleTypeAlias(name_, typeParams_)); + } else if (ident->Name() == compiler::Signatures::UNDEFINED) { + SetTsType(checker->GlobalETSUndefinedType()); + } else if (ident->Name() == compiler::Signatures::NULL_LITERAL) { + SetTsType(checker->GlobalETSNullType()); } } - - checker::Type *baseType = checker->GetReferencedTypeBase(name_); - - ASSERT(baseType != nullptr); - if (baseType->IsETSObjectType()) { - checker::InstantiationContext ctx(checker, baseType->AsETSObjectType(), typeParams_, Start()); - return ctx.Result(); + if (TsType() == nullptr) { + checker::Type *baseType = checker->GetReferencedTypeBase(name_); + + ASSERT(baseType != nullptr); + if (baseType->IsETSObjectType()) { + checker::InstantiationContext ctx(checker, baseType->AsETSObjectType(), typeParams_, Start()); + SetTsType(ctx.Result()); + } else { + SetTsType(baseType); + } } - - return baseType; + } else { + checker::Type *baseType = prev_->GetType(checker); + SetTsType(checker->GetReferencedTypeFromBase(baseType, name_)); } - - checker::Type *baseType = prev_->GetType(checker); - return checker->GetReferencedTypeFromBase(baseType, name_); + return TsType(); } ETSTypeReferencePart *ETSTypeReferencePart::Clone(ArenaAllocator *const allocator, AstNode *const parent) diff --git a/ets2panda/ir/expressions/binaryExpression.cpp b/ets2panda/ir/expressions/binaryExpression.cpp index 438e05239d..7f189a7c87 100644 --- a/ets2panda/ir/expressions/binaryExpression.cpp +++ b/ets2panda/ir/expressions/binaryExpression.cpp @@ -74,6 +74,20 @@ void BinaryExpression::Compile(compiler::ETSGen *etsg) const etsg->GetAstCompiler()->Compile(this); } +void BinaryExpression::CompileOperands(compiler::ETSGen *etsg, compiler::VReg lhs) const +{ + left_->Compile(etsg); + + if (operator_ == lexer::TokenType::KEYW_INSTANCEOF) { + etsg->StoreAccumulator(left_, lhs); + } else { + etsg->ApplyConversionAndStoreAccumulator(left_, lhs, operationType_); + } + + right_->Compile(etsg); + etsg->ApplyConversion(right_, operationType_); +} + checker::Type *BinaryExpression::Check(checker::TSChecker *checker) { return checker->GetAnalyzer()->Check(this); diff --git a/ets2panda/ir/expressions/binaryExpression.h b/ets2panda/ir/expressions/binaryExpression.h index d0ed782aa0..8865ac101d 100644 --- a/ets2panda/ir/expressions/binaryExpression.h +++ b/ets2panda/ir/expressions/binaryExpression.h @@ -17,6 +17,7 @@ #define ES2PANDA_IR_EXPRESSION_BINARY_EXPRESSION_H #include "checker/checkerContext.h" +#include "compiler/core/vReg.h" #include "ir/expression.h" namespace ark::es2panda::checker { @@ -157,6 +158,7 @@ public: void Dump(ir::SrcDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; void Compile(compiler::ETSGen *etsg) const override; + void CompileOperands(compiler::ETSGen *etsg, compiler::VReg lhs) const; checker::Type *Check(checker::TSChecker *checker) override; checker::Type *Check(checker::ETSChecker *checker) override; diff --git a/ets2panda/test/compiler/ets/instanceof_dyndecl_dynvalue-expected.txt b/ets2panda/test/compiler/ets/instanceof_dyndecl_dynvalue-expected.txt new file mode 100644 index 0000000000..e781c4e753 --- /dev/null +++ b/ets2panda/test/compiler/ets/instanceof_dyndecl_dynvalue-expected.txt @@ -0,0 +1 @@ +TypeError: Right-hand side of instanceof expression must represent a type. [instanceof_dyndecl_dynvalue.ets:24:12] diff --git a/ets2panda/test/compiler/ets/instanceof_dyndecl_dynvalue.ets b/ets2panda/test/compiler/ets/instanceof_dyndecl_dynvalue.ets new file mode 100644 index 0000000000..fa9938a3f7 --- /dev/null +++ b/ets2panda/test/compiler/ets/instanceof_dyndecl_dynvalue.ets @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*--- +flags: [dynamic-ast] +---*/ + +import { A } from "dynamic_js_import_tests" +import { ADeclared } from "dynamic_import_tests/modules/instanceof" + +function fn(o: ADeclared): boolean { + return o instanceof A; +} + diff --git a/ets2panda/test/compiler/ets/instanceof_dyndecl_jsvalue-expected.txt b/ets2panda/test/compiler/ets/instanceof_dyndecl_jsvalue-expected.txt new file mode 100644 index 0000000000..b36abe05bb --- /dev/null +++ b/ets2panda/test/compiler/ets/instanceof_dyndecl_jsvalue-expected.txt @@ -0,0 +1 @@ +TypeError: Right-hand side of instanceof expression must represent a type. [instanceof_dyndecl_jsvalue.ets:23:12] diff --git a/ets2panda/test/compiler/ets/instanceof_dyndecl_jsvalue.ets b/ets2panda/test/compiler/ets/instanceof_dyndecl_jsvalue.ets new file mode 100644 index 0000000000..2a81461d09 --- /dev/null +++ b/ets2panda/test/compiler/ets/instanceof_dyndecl_jsvalue.ets @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*--- +flags: [dynamic-ast] +---*/ + +import { ADeclared } from "dynamic_import_tests/modules/instanceof" + +function fn_dyn_decl(o: ADeclared): boolean { + return o instanceof JSValue; +} diff --git a/ets2panda/test/compiler/ets/instanceof_dynvalue_dynvalue-expected.txt b/ets2panda/test/compiler/ets/instanceof_dynvalue_dynvalue-expected.txt new file mode 100644 index 0000000000..01d89967b9 --- /dev/null +++ b/ets2panda/test/compiler/ets/instanceof_dynvalue_dynvalue-expected.txt @@ -0,0 +1 @@ +TypeError: Right-hand side of instanceof expression must represent a type. [instanceof_dynvalue_dynvalue.ets:23:12] diff --git a/ets2panda/test/compiler/ets/instanceof_dynvalue_dynvalue.ets b/ets2panda/test/compiler/ets/instanceof_dynvalue_dynvalue.ets new file mode 100644 index 0000000000..8ca37c3bec --- /dev/null +++ b/ets2panda/test/compiler/ets/instanceof_dynvalue_dynvalue.ets @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*--- +flags: [dynamic-ast] +---*/ + +import { A, B } from "dynamic_js_import_tests" + +function fn(o: B): boolean { + return o instanceof A; +} diff --git a/ets2panda/test/compiler/ets/instanceof_dynvalue_jsvalue-expected.txt b/ets2panda/test/compiler/ets/instanceof_dynvalue_jsvalue-expected.txt new file mode 100644 index 0000000000..e207a90d75 --- /dev/null +++ b/ets2panda/test/compiler/ets/instanceof_dynvalue_jsvalue-expected.txt @@ -0,0 +1 @@ +TypeError: Right-hand side of instanceof expression must represent a type. [instanceof_dynvalue_jsvalue.ets:23:12] diff --git a/ets2panda/test/compiler/ets/instanceof_dynvalue_jsvalue.ets b/ets2panda/test/compiler/ets/instanceof_dynvalue_jsvalue.ets new file mode 100644 index 0000000000..f9278149ca --- /dev/null +++ b/ets2panda/test/compiler/ets/instanceof_dynvalue_jsvalue.ets @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*--- +flags: [dynamic-ast] +---*/ + +import { A } from "dynamic_js_import_tests" + +function fn(o: A): boolean { + return o instanceof JSValue; +} diff --git a/ets2panda/test/compiler/ets/instanceof_etsobject_dynvalue-expected.txt b/ets2panda/test/compiler/ets/instanceof_etsobject_dynvalue-expected.txt new file mode 100644 index 0000000000..995ed14f79 --- /dev/null +++ b/ets2panda/test/compiler/ets/instanceof_etsobject_dynvalue-expected.txt @@ -0,0 +1 @@ +TypeError: Right-hand side of instanceof expression must represent a type. [instanceof_etsobject_dynvalue.ets:25:12] diff --git a/ets2panda/test/compiler/ets/instanceof_etsobject_dynvalue.ets b/ets2panda/test/compiler/ets/instanceof_etsobject_dynvalue.ets new file mode 100644 index 0000000000..9b7cfc0afb --- /dev/null +++ b/ets2panda/test/compiler/ets/instanceof_etsobject_dynvalue.ets @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*--- +flags: [dynamic-ast] +---*/ + +import { A } from "dynamic_js_import_tests" + +class B {} + +function fn(o: B): boolean { + return o instanceof A; +} diff --git a/ets2panda/test/compiler/ets/instanceof_etsobject_jsvalue-expected.txt b/ets2panda/test/compiler/ets/instanceof_etsobject_jsvalue-expected.txt new file mode 100644 index 0000000000..579f0aa567 --- /dev/null +++ b/ets2panda/test/compiler/ets/instanceof_etsobject_jsvalue-expected.txt @@ -0,0 +1 @@ +TypeError: Right-hand side of instanceof expression must represent a type. [instanceof_etsobject_jsvalue.ets:23:12] diff --git a/ets2panda/test/compiler/ets/instanceof_etsobject_jsvalue.ets b/ets2panda/test/compiler/ets/instanceof_etsobject_jsvalue.ets new file mode 100644 index 0000000000..d96765c6be --- /dev/null +++ b/ets2panda/test/compiler/ets/instanceof_etsobject_jsvalue.ets @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*--- +flags: [dynamic-ast] +---*/ + +class A {} + +function fn(o: A): boolean { + return o instanceof JSValue; +} diff --git a/ets2panda/test/compiler/ets/instanceof_jsvalue_dynvalue-expected.txt b/ets2panda/test/compiler/ets/instanceof_jsvalue_dynvalue-expected.txt new file mode 100644 index 0000000000..2487a7ed86 --- /dev/null +++ b/ets2panda/test/compiler/ets/instanceof_jsvalue_dynvalue-expected.txt @@ -0,0 +1 @@ +TypeError: Right-hand side of instanceof expression must represent a type. [instanceof_jsvalue_dynvalue.ets:23:12] diff --git a/ets2panda/test/compiler/ets/instanceof_jsvalue_dynvalue.ets b/ets2panda/test/compiler/ets/instanceof_jsvalue_dynvalue.ets new file mode 100644 index 0000000000..7d534d8049 --- /dev/null +++ b/ets2panda/test/compiler/ets/instanceof_jsvalue_dynvalue.ets @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*--- +flags: [dynamic-ast] +---*/ + +import { A } from "dynamic_js_import_tests" + +function fn(o: JSValue): boolean { + return o instanceof A; +} diff --git a/ets2panda/test/compiler/ets/instanceof_jsvalue_jsvalue-expected.txt b/ets2panda/test/compiler/ets/instanceof_jsvalue_jsvalue-expected.txt new file mode 100644 index 0000000000..04bfe221d1 --- /dev/null +++ b/ets2panda/test/compiler/ets/instanceof_jsvalue_jsvalue-expected.txt @@ -0,0 +1 @@ +TypeError: Right-hand side of instanceof expression must represent a type. [instanceof_jsvalue_jsvalue.ets:21:12] diff --git a/ets2panda/test/compiler/ets/instanceof_jsvalue_jsvalue.ets b/ets2panda/test/compiler/ets/instanceof_jsvalue_jsvalue.ets new file mode 100644 index 0000000000..ab7ae309c6 --- /dev/null +++ b/ets2panda/test/compiler/ets/instanceof_jsvalue_jsvalue.ets @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*--- +flags: [dynamic-ast] +---*/ + +function fn(o: JSValue): boolean { + return o instanceof JSValue; +} diff --git a/ets2panda/test/compiler/ets/instanceof_object_dynvalue-expected.txt b/ets2panda/test/compiler/ets/instanceof_object_dynvalue-expected.txt new file mode 100644 index 0000000000..65b0bb51f3 --- /dev/null +++ b/ets2panda/test/compiler/ets/instanceof_object_dynvalue-expected.txt @@ -0,0 +1 @@ +TypeError: Right-hand side of instanceof expression must represent a type. [instanceof_object_dynvalue.ets:23:12] diff --git a/ets2panda/test/compiler/ets/instanceof_object_dynvalue.ets b/ets2panda/test/compiler/ets/instanceof_object_dynvalue.ets new file mode 100644 index 0000000000..bddd3c6f00 --- /dev/null +++ b/ets2panda/test/compiler/ets/instanceof_object_dynvalue.ets @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*--- +flags: [dynamic-ast] +---*/ + +import { A } from "dynamic_js_import_tests" + +function fn(o: Object): boolean { + return o instanceof A; +} diff --git a/ets2panda/test/compiler/ets/instanceof_object_jsvalue-expected.txt b/ets2panda/test/compiler/ets/instanceof_object_jsvalue-expected.txt new file mode 100644 index 0000000000..bad900e767 --- /dev/null +++ b/ets2panda/test/compiler/ets/instanceof_object_jsvalue-expected.txt @@ -0,0 +1 @@ +TypeError: Right-hand side of instanceof expression must represent a type. [instanceof_object_jsvalue.ets:21:12] diff --git a/ets2panda/test/compiler/ets/instanceof_object_jsvalue.ets b/ets2panda/test/compiler/ets/instanceof_object_jsvalue.ets new file mode 100644 index 0000000000..0103287ad8 --- /dev/null +++ b/ets2panda/test/compiler/ets/instanceof_object_jsvalue.ets @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*--- +flags: [dynamic-ast] +---*/ + +function fn(o: Object): boolean { + return o instanceof JSValue; +} diff --git a/ets2panda/test/compiler/ets/instanceof_object_long-expected.txt b/ets2panda/test/compiler/ets/instanceof_object_long-expected.txt new file mode 100644 index 0000000000..009b4e6694 --- /dev/null +++ b/ets2panda/test/compiler/ets/instanceof_object_long-expected.txt @@ -0,0 +1 @@ +TypeError: Bad operand type, the types of the operands must be same type. [instanceof_object_long.ets:21:12] diff --git a/ets2panda/test/compiler/ets/instanceof_object_long.ets b/ets2panda/test/compiler/ets/instanceof_object_long.ets new file mode 100644 index 0000000000..4ebec908d6 --- /dev/null +++ b/ets2panda/test/compiler/ets/instanceof_object_long.ets @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*--- +flags: [dynamic-ast] +---*/ + +function fn(o: Object): boolean { + return o instanceof long; +} diff --git a/ets2panda/test/compiler/ets/instanceof_x_dyndecl-expected.txt b/ets2panda/test/compiler/ets/instanceof_x_dyndecl-expected.txt new file mode 100644 index 0000000000..8e2be440f7 --- /dev/null +++ b/ets2panda/test/compiler/ets/instanceof_x_dyndecl-expected.txt @@ -0,0 +1,2189 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ImportDeclaration", + "source": { + "type": "StringLiteral", + "value": "dynamic_js_import_tests", + "loc": { + "start": { + "line": 20, + "column": 24 + }, + "end": { + "line": 20, + "column": 49 + } + } + }, + "specifiers": [ + { + "type": "ImportSpecifier", + "local": { + "type": "Identifier", + "name": "AValue", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 10 + }, + "end": { + "line": 20, + "column": 16 + } + } + }, + "imported": { + "type": "Identifier", + "name": "AValue", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 10 + }, + "end": { + "line": 20, + "column": 16 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 10 + }, + "end": { + "line": 20, + "column": 16 + } + } + } + ], + "loc": { + "start": { + "line": 20, + "column": 1 + }, + "end": { + "line": 20, + "column": 49 + } + } + }, + { + "type": "ImportDeclaration", + "source": { + "type": "StringLiteral", + "value": "dynamic_import_tests/modules/instanceof", + "loc": { + "start": { + "line": 21, + "column": 38 + }, + "end": { + "line": 21, + "column": 79 + } + } + }, + "specifiers": [ + { + "type": "ImportSpecifier", + "local": { + "type": "Identifier", + "name": "ADeclared", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 10 + }, + "end": { + "line": 21, + "column": 19 + } + } + }, + "imported": { + "type": "Identifier", + "name": "ADeclared", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 10 + }, + "end": { + "line": 21, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 10 + }, + "end": { + "line": 21, + "column": 19 + } + } + }, + { + "type": "ImportSpecifier", + "local": { + "type": "Identifier", + "name": "BDeclared", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 21 + }, + "end": { + "line": 21, + "column": 30 + } + } + }, + "imported": { + "type": "Identifier", + "name": "BDeclared", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 21 + }, + "end": { + "line": 21, + "column": 30 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 21 + }, + "end": { + "line": 21, + "column": 30 + } + } + } + ], + "loc": { + "start": { + "line": 21, + "column": 1 + }, + "end": { + "line": 21, + "column": 79 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "fn_object", + "decorators": [], + "loc": { + "start": { + "line": 25, + "column": 10 + }, + "end": { + "line": 25, + "column": 19 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "fn_object", + "decorators": [], + "loc": { + "start": { + "line": 25, + "column": 10 + }, + "end": { + "line": 25, + "column": 19 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "o", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], + "loc": { + "start": { + "line": 25, + "column": 23 + }, + "end": { + "line": 25, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 25, + "column": 23 + }, + "end": { + "line": 25, + "column": 30 + } + } + }, + "loc": { + "start": { + "line": 25, + "column": 23 + }, + "end": { + "line": 25, + "column": 30 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 25, + "column": 20 + }, + "end": { + "line": 25, + "column": 30 + } + } + }, + "loc": { + "start": { + "line": 25, + "column": 20 + }, + "end": { + "line": 25, + "column": 30 + } + } + } + ], + "returnType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 25, + "column": 32 + }, + "end": { + "line": 25, + "column": 39 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "BinaryExpression", + "operator": "instanceof", + "left": { + "type": "Identifier", + "name": "o", + "decorators": [], + "loc": { + "start": { + "line": 26, + "column": 12 + }, + "end": { + "line": 26, + "column": 13 + } + } + }, + "right": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "BDeclared", + "decorators": [], + "loc": { + "start": { + "line": 26, + "column": 25 + }, + "end": { + "line": 26, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 25 + }, + "end": { + "line": 26, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 25 + }, + "end": { + "line": 26, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 12 + }, + "end": { + "line": 26, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 5 + }, + "end": { + "line": 26, + "column": 35 + } + } + } + ], + "loc": { + "start": { + "line": 25, + "column": 40 + }, + "end": { + "line": 27, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 25, + "column": 19 + }, + "end": { + "line": 27, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 25, + "column": 19 + }, + "end": { + "line": 27, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 25, + "column": 1 + }, + "end": { + "line": 27, + "column": 2 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "fn_ets_object", + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 10 + }, + "end": { + "line": 29, + "column": 23 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "fn_ets_object", + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 10 + }, + "end": { + "line": 29, + "column": 23 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "o", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 27 + }, + "end": { + "line": 29, + "column": 28 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 27 + }, + "end": { + "line": 29, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 27 + }, + "end": { + "line": 29, + "column": 29 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 24 + }, + "end": { + "line": 29, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 24 + }, + "end": { + "line": 29, + "column": 29 + } + } + } + ], + "returnType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 29, + "column": 31 + }, + "end": { + "line": 29, + "column": 38 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "BinaryExpression", + "operator": "instanceof", + "left": { + "type": "Identifier", + "name": "o", + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 12 + }, + "end": { + "line": 30, + "column": 13 + } + } + }, + "right": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "BDeclared", + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 25 + }, + "end": { + "line": 30, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 25 + }, + "end": { + "line": 30, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 25 + }, + "end": { + "line": 30, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 12 + }, + "end": { + "line": 30, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 5 + }, + "end": { + "line": 30, + "column": 35 + } + } + } + ], + "loc": { + "start": { + "line": 29, + "column": 39 + }, + "end": { + "line": 31, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 23 + }, + "end": { + "line": 31, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 23 + }, + "end": { + "line": 31, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 1 + }, + "end": { + "line": 31, + "column": 2 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "fn_jsvalue", + "decorators": [], + "loc": { + "start": { + "line": 33, + "column": 10 + }, + "end": { + "line": 33, + "column": 20 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "fn_jsvalue", + "decorators": [], + "loc": { + "start": { + "line": 33, + "column": 10 + }, + "end": { + "line": 33, + "column": 20 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "o", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "JSValue", + "decorators": [], + "loc": { + "start": { + "line": 33, + "column": 24 + }, + "end": { + "line": 33, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 33, + "column": 24 + }, + "end": { + "line": 33, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 33, + "column": 24 + }, + "end": { + "line": 33, + "column": 32 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 33, + "column": 21 + }, + "end": { + "line": 33, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 33, + "column": 21 + }, + "end": { + "line": 33, + "column": 32 + } + } + } + ], + "returnType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 33, + "column": 34 + }, + "end": { + "line": 33, + "column": 41 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "BinaryExpression", + "operator": "instanceof", + "left": { + "type": "Identifier", + "name": "o", + "decorators": [], + "loc": { + "start": { + "line": 34, + "column": 12 + }, + "end": { + "line": 34, + "column": 13 + } + } + }, + "right": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "BDeclared", + "decorators": [], + "loc": { + "start": { + "line": 34, + "column": 25 + }, + "end": { + "line": 34, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 34, + "column": 25 + }, + "end": { + "line": 34, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 34, + "column": 25 + }, + "end": { + "line": 34, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 34, + "column": 12 + }, + "end": { + "line": 34, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 34, + "column": 5 + }, + "end": { + "line": 34, + "column": 35 + } + } + } + ], + "loc": { + "start": { + "line": 33, + "column": 42 + }, + "end": { + "line": 35, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 33, + "column": 20 + }, + "end": { + "line": 35, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 33, + "column": 20 + }, + "end": { + "line": 35, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 33, + "column": 1 + }, + "end": { + "line": 35, + "column": 2 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "fn_dyn_value", + "decorators": [], + "loc": { + "start": { + "line": 37, + "column": 10 + }, + "end": { + "line": 37, + "column": 22 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "fn_dyn_value", + "decorators": [], + "loc": { + "start": { + "line": 37, + "column": 10 + }, + "end": { + "line": 37, + "column": 22 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "o", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "AValue", + "decorators": [], + "loc": { + "start": { + "line": 37, + "column": 26 + }, + "end": { + "line": 37, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 37, + "column": 26 + }, + "end": { + "line": 37, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 37, + "column": 26 + }, + "end": { + "line": 37, + "column": 33 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 37, + "column": 23 + }, + "end": { + "line": 37, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 37, + "column": 23 + }, + "end": { + "line": 37, + "column": 33 + } + } + } + ], + "returnType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 37, + "column": 35 + }, + "end": { + "line": 37, + "column": 42 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "BinaryExpression", + "operator": "instanceof", + "left": { + "type": "Identifier", + "name": "o", + "decorators": [], + "loc": { + "start": { + "line": 38, + "column": 12 + }, + "end": { + "line": 38, + "column": 13 + } + } + }, + "right": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "BDeclared", + "decorators": [], + "loc": { + "start": { + "line": 38, + "column": 25 + }, + "end": { + "line": 38, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 38, + "column": 25 + }, + "end": { + "line": 38, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 38, + "column": 25 + }, + "end": { + "line": 38, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 38, + "column": 12 + }, + "end": { + "line": 38, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 38, + "column": 5 + }, + "end": { + "line": 38, + "column": 35 + } + } + } + ], + "loc": { + "start": { + "line": 37, + "column": 43 + }, + "end": { + "line": 39, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 37, + "column": 22 + }, + "end": { + "line": 39, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 37, + "column": 22 + }, + "end": { + "line": 39, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 37, + "column": 1 + }, + "end": { + "line": 39, + "column": 2 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "fn_dyn_decl", + "decorators": [], + "loc": { + "start": { + "line": 41, + "column": 10 + }, + "end": { + "line": 41, + "column": 21 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "fn_dyn_decl", + "decorators": [], + "loc": { + "start": { + "line": 41, + "column": 10 + }, + "end": { + "line": 41, + "column": 21 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "o", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "ADeclared", + "decorators": [], + "loc": { + "start": { + "line": 41, + "column": 25 + }, + "end": { + "line": 41, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 41, + "column": 25 + }, + "end": { + "line": 41, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 41, + "column": 25 + }, + "end": { + "line": 41, + "column": 35 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 41, + "column": 22 + }, + "end": { + "line": 41, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 41, + "column": 22 + }, + "end": { + "line": 41, + "column": 35 + } + } + } + ], + "returnType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 41, + "column": 37 + }, + "end": { + "line": 41, + "column": 44 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "BinaryExpression", + "operator": "instanceof", + "left": { + "type": "Identifier", + "name": "o", + "decorators": [], + "loc": { + "start": { + "line": 42, + "column": 12 + }, + "end": { + "line": 42, + "column": 13 + } + } + }, + "right": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "BDeclared", + "decorators": [], + "loc": { + "start": { + "line": 42, + "column": 25 + }, + "end": { + "line": 42, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 42, + "column": 25 + }, + "end": { + "line": 42, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 42, + "column": 25 + }, + "end": { + "line": 42, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 42, + "column": 12 + }, + "end": { + "line": 42, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 42, + "column": 5 + }, + "end": { + "line": 42, + "column": 35 + } + } + } + ], + "loc": { + "start": { + "line": 41, + "column": 45 + }, + "end": { + "line": 43, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 41, + "column": 21 + }, + "end": { + "line": 43, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 41, + "column": 21 + }, + "end": { + "line": 43, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 41, + "column": 1 + }, + "end": { + "line": 43, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 7 + }, + "end": { + "line": 23, + "column": 8 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 11 + }, + "end": { + "line": 23, + "column": 11 + } + } + } + ], + "loc": { + "start": { + "line": 23, + "column": 9 + }, + "end": { + "line": 23, + "column": 11 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 1 + }, + "end": { + "line": 23, + "column": 11 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "$dynmodule", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "dynamic_js_import_tests0", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "accessibility": "public", + "static": true, + "readonly": true, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "OpaqueType", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassStaticBlock", + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": true, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "$dynmodule", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "dynamic_js_import_tests0", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "right": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "JSRuntime", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "loadModule", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "StringLiteral", + "value": "dynamic_js_import_tests", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "init", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "init", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 44, + "column": 1 + } + } +} diff --git a/ets2panda/test/compiler/ets/instanceof_x_dyndecl.ets b/ets2panda/test/compiler/ets/instanceof_x_dyndecl.ets new file mode 100644 index 0000000000..2c35b20e34 --- /dev/null +++ b/ets2panda/test/compiler/ets/instanceof_x_dyndecl.ets @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*--- +flags: [dynamic-ast] +---*/ + +import { AValue } from "dynamic_js_import_tests" +import { ADeclared, BDeclared } from "dynamic_import_tests/modules/instanceof" + +class A {} + +function fn_object(o: Object): boolean { + return o instanceof BDeclared; +} + +function fn_ets_object(o: A): boolean { + return o instanceof BDeclared; +} + +function fn_jsvalue(o: JSValue): boolean { + return o instanceof BDeclared; +} + +function fn_dyn_value(o: AValue): boolean { + return o instanceof BDeclared; +} + +function fn_dyn_decl(o: ADeclared): boolean { + return o instanceof BDeclared; +} diff --git a/ets2panda/test/compiler/ets/dynamic_instanceof-expected.txt b/ets2panda/test/compiler/ets/instanceof_x_etstype-expected.txt similarity index 58% rename from ets2panda/test/compiler/ets/dynamic_instanceof-expected.txt rename to ets2panda/test/compiler/ets/instanceof_x_etstype-expected.txt index 73cfb55aeb..ddff810f78 100644 --- a/ets2panda/test/compiler/ets/dynamic_instanceof-expected.txt +++ b/ets2panda/test/compiler/ets/instanceof_x_etstype-expected.txt @@ -9,11 +9,11 @@ "loc": { "start": { "line": 20, - "column": 30 + "column": 24 }, "end": { "line": 20, - "column": 55 + "column": 49 } } }, @@ -22,7 +22,7 @@ "type": "ImportSpecifier", "local": { "type": "Identifier", - "name": "A", + "name": "AValue", "decorators": [], "loc": { "start": { @@ -31,13 +31,13 @@ }, "end": { "line": 20, - "column": 11 + "column": 16 } } }, "imported": { "type": "Identifier", - "name": "A", + "name": "AValue", "decorators": [], "loc": { "start": { @@ -46,7 +46,7 @@ }, "end": { "line": 20, - "column": 11 + "column": 16 } } }, @@ -57,105 +57,91 @@ }, "end": { "line": 20, - "column": 11 + "column": 16 } } + } + ], + "loc": { + "start": { + "line": 20, + "column": 1 }, - { - "type": "ImportSpecifier", - "local": { - "type": "Identifier", - "name": "B", - "decorators": [], - "loc": { - "start": { - "line": 20, - "column": 13 - }, - "end": { - "line": 20, - "column": 14 - } - } - }, - "imported": { - "type": "Identifier", - "name": "B", - "decorators": [], - "loc": { - "start": { - "line": 20, - "column": 13 - }, - "end": { - "line": 20, - "column": 14 - } - } + "end": { + "line": 20, + "column": 49 + } + } + }, + { + "type": "ImportDeclaration", + "source": { + "type": "StringLiteral", + "value": "dynamic_import_tests/modules/instanceof", + "loc": { + "start": { + "line": 21, + "column": 27 }, - "loc": { - "start": { - "line": 20, - "column": 13 - }, - "end": { - "line": 20, - "column": 14 - } + "end": { + "line": 21, + "column": 68 } - }, + } + }, + "specifiers": [ { "type": "ImportSpecifier", "local": { "type": "Identifier", - "name": "jsfunc", + "name": "ADeclared", "decorators": [], "loc": { "start": { - "line": 20, - "column": 16 + "line": 21, + "column": 10 }, "end": { - "line": 20, - "column": 22 + "line": 21, + "column": 19 } } }, "imported": { "type": "Identifier", - "name": "jsfunc", + "name": "ADeclared", "decorators": [], "loc": { "start": { - "line": 20, - "column": 16 + "line": 21, + "column": 10 }, "end": { - "line": 20, - "column": 22 + "line": 21, + "column": 19 } } }, "loc": { "start": { - "line": 20, - "column": 16 + "line": 21, + "column": 10 }, "end": { - "line": 20, - "column": 22 + "line": 21, + "column": 19 } } } ], "loc": { "start": { - "line": 20, + "line": 21, "column": 1 }, "end": { - "line": 20, - "column": 55 + "line": 21, + "column": 68 } } }, @@ -278,16 +264,16 @@ "type": "MethodDefinition", "key": { "type": "Identifier", - "name": "foo", + "name": "fn_object", "decorators": [], "loc": { "start": { - "line": 22, + "line": 26, "column": 10 }, "end": { - "line": 22, - "column": 13 + "line": 26, + "column": 19 } } }, @@ -302,155 +288,126 @@ "type": "ScriptFunction", "id": { "type": "Identifier", - "name": "foo", + "name": "fn_object", "decorators": [], "loc": { "start": { - "line": 22, + "line": 26, "column": 10 }, "end": { - "line": 22, - "column": 13 + "line": 26, + "column": 19 } } }, "generator": false, "async": false, "expression": false, - "params": [], - "returnType": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 22, - "column": 17 - }, - "end": { - "line": 22, - "column": 20 - } - } - }, - "body": { - "type": "BlockStatement", - "statements": [ - { - "type": "VariableDeclaration", - "declarations": [ - { - "type": "VariableDeclarator", - "id": { + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "o", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { "type": "Identifier", - "name": "a", + "name": "Object", "decorators": [], "loc": { "start": { - "line": 23, - "column": 7 - }, - "end": { - "line": 23, - "column": 8 - } - } - }, - "init": { - "type": "ETSNewClassInstanceExpression", - "typeReference": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "A", - "decorators": [], - "loc": { - "start": { - "line": 23, - "column": 15 - }, - "end": { - "line": 23, - "column": 16 - } - } - }, - "loc": { - "start": { - "line": 23, - "column": 15 - }, - "end": { - "line": 23, - "column": 17 - } - } - }, - "loc": { - "start": { - "line": 23, - "column": 15 - }, - "end": { - "line": 23, - "column": 17 - } - } - }, - "arguments": [], - "loc": { - "start": { - "line": 23, - "column": 11 + "line": 26, + "column": 23 }, "end": { - "line": 23, - "column": 19 + "line": 26, + "column": 29 } } }, "loc": { "start": { - "line": 23, - "column": 7 + "line": 26, + "column": 23 }, "end": { - "line": 23, - "column": 19 + "line": 26, + "column": 30 } } + }, + "loc": { + "start": { + "line": 26, + "column": 23 + }, + "end": { + "line": 26, + "column": 30 + } } - ], - "kind": "let", + }, + "decorators": [], "loc": { "start": { - "line": 23, - "column": 3 + "line": 26, + "column": 20 }, "end": { - "line": 23, - "column": 19 + "line": 26, + "column": 30 } } }, + "loc": { + "start": { + "line": 26, + "column": 20 + }, + "end": { + "line": 26, + "column": 30 + } + } + } + ], + "returnType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 26, + "column": 32 + }, + "end": { + "line": 26, + "column": 39 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ { - "type": "IfStatement", - "test": { + "type": "ReturnStatement", + "argument": { "type": "BinaryExpression", "operator": "instanceof", "left": { "type": "Identifier", - "name": "a", + "name": "o", "decorators": [], "loc": { "start": { - "line": 24, - "column": 7 + "line": 27, + "column": 12 }, "end": { - "line": 24, - "column": 8 + "line": 27, + "column": 13 } } }, @@ -460,450 +417,93 @@ "type": "ETSTypeReferencePart", "name": { "type": "Identifier", - "name": "A", + "name": "B", "decorators": [], "loc": { "start": { - "line": 24, - "column": 20 + "line": 27, + "column": 25 }, "end": { - "line": 24, - "column": 21 + "line": 27, + "column": 26 } } }, "loc": { "start": { - "line": 24, - "column": 20 + "line": 27, + "column": 25 }, "end": { - "line": 24, - "column": 22 + "line": 27, + "column": 27 } } }, "loc": { "start": { - "line": 24, - "column": 20 + "line": 27, + "column": 25 }, "end": { - "line": 24, - "column": 22 + "line": 27, + "column": 27 } } }, "loc": { "start": { - "line": 24, - "column": 7 - }, - "end": { - "line": 24, - "column": 22 - } - } - }, - "consequent": { - "type": "BlockStatement", - "statements": [ - { - "type": "ReturnStatement", - "argument": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 25, - "column": 12 - }, - "end": { - "line": 25, - "column": 13 - } - } - }, - "loc": { - "start": { - "line": 25, - "column": 5 - }, - "end": { - "line": 25, - "column": 14 - } - } - } - ], - "loc": { - "start": { - "line": 24, - "column": 23 - }, - "end": { - "line": 26, - "column": 4 - } - } - }, - "alternate": { - "type": "BlockStatement", - "statements": [ - { - "type": "VariableDeclaration", - "declarations": [ - { - "type": "VariableDeclarator", - "id": { - "type": "Identifier", - "name": "x", - "decorators": [], - "loc": { - "start": { - "line": 27, - "column": 9 - }, - "end": { - "line": 27, - "column": 10 - } - } - }, - "init": { - "type": "CallExpression", - "callee": { - "type": "Identifier", - "name": "jsfunc", - "decorators": [], - "loc": { - "start": { - "line": 27, - "column": 13 - }, - "end": { - "line": 27, - "column": 19 - } - } - }, - "arguments": [], - "optional": false, - "loc": { - "start": { - "line": 27, - "column": 13 - }, - "end": { - "line": 27, - "column": 21 - } - } - }, - "loc": { - "start": { - "line": 27, - "column": 9 - }, - "end": { - "line": 27, - "column": 21 - } - } - } - ], - "kind": "let", - "loc": { - "start": { - "line": 27, - "column": 5 - }, - "end": { - "line": 27, - "column": 22 - } - } - }, - { - "type": "VariableDeclaration", - "declarations": [ - { - "type": "VariableDeclarator", - "id": { - "type": "Identifier", - "name": "b", - "decorators": [], - "loc": { - "start": { - "line": 28, - "column": 9 - }, - "end": { - "line": 28, - "column": 10 - } - } - }, - "init": { - "type": "BinaryExpression", - "operator": "instanceof", - "left": { - "type": "Identifier", - "name": "x", - "decorators": [], - "loc": { - "start": { - "line": 28, - "column": 13 - }, - "end": { - "line": 28, - "column": 14 - } - } - }, - "right": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "B", - "decorators": [], - "loc": { - "start": { - "line": 28, - "column": 26 - }, - "end": { - "line": 28, - "column": 27 - } - } - }, - "loc": { - "start": { - "line": 28, - "column": 26 - }, - "end": { - "line": 28, - "column": 28 - } - } - }, - "loc": { - "start": { - "line": 28, - "column": 26 - }, - "end": { - "line": 28, - "column": 28 - } - } - }, - "loc": { - "start": { - "line": 28, - "column": 13 - }, - "end": { - "line": 28, - "column": 28 - } - } - }, - "loc": { - "start": { - "line": 28, - "column": 9 - }, - "end": { - "line": 28, - "column": 28 - } - } - } - ], - "kind": "let", - "loc": { - "start": { - "line": 28, - "column": 5 - }, - "end": { - "line": 28, - "column": 28 - } - } - }, - { - "type": "IfStatement", - "test": { - "type": "Identifier", - "name": "b", - "decorators": [], - "loc": { - "start": { - "line": 29, - "column": 9 - }, - "end": { - "line": 29, - "column": 10 - } - } - }, - "consequent": { - "type": "BlockStatement", - "statements": [ - { - "type": "ReturnStatement", - "argument": { - "type": "NumberLiteral", - "value": 2, - "loc": { - "start": { - "line": 30, - "column": 14 - }, - "end": { - "line": 30, - "column": 15 - } - } - }, - "loc": { - "start": { - "line": 30, - "column": 7 - }, - "end": { - "line": 30, - "column": 16 - } - } - } - ], - "loc": { - "start": { - "line": 29, - "column": 12 - }, - "end": { - "line": 31, - "column": 6 - } - } - }, - "alternate": { - "type": "BlockStatement", - "statements": [ - { - "type": "ReturnStatement", - "argument": { - "type": "NumberLiteral", - "value": 3, - "loc": { - "start": { - "line": 32, - "column": 14 - }, - "end": { - "line": 32, - "column": 15 - } - } - }, - "loc": { - "start": { - "line": 32, - "column": 7 - }, - "end": { - "line": 32, - "column": 16 - } - } - } - ], - "loc": { - "start": { - "line": 31, - "column": 12 - }, - "end": { - "line": 33, - "column": 6 - } - } - }, - "loc": { - "start": { - "line": 29, - "column": 5 - }, - "end": { - "line": 33, - "column": 6 - } - } - } - ], - "loc": { - "start": { - "line": 26, - "column": 10 + "line": 27, + "column": 12 }, "end": { - "line": 34, - "column": 4 + "line": 27, + "column": 27 } } }, "loc": { "start": { - "line": 24, - "column": 3 + "line": 27, + "column": 5 }, "end": { - "line": 34, - "column": 4 + "line": 27, + "column": 27 } } } ], "loc": { "start": { - "line": 22, - "column": 21 + "line": 26, + "column": 40 }, "end": { - "line": 35, + "line": 28, "column": 2 } } }, "loc": { "start": { - "line": 22, - "column": 13 + "line": 26, + "column": 19 }, "end": { - "line": 35, + "line": 28, "column": 2 } } }, "loc": { "start": { - "line": 22, - "column": 13 + "line": 26, + "column": 19 }, "end": { - "line": 35, + "line": 28, "column": 2 } } @@ -912,266 +512,273 @@ "decorators": [], "loc": { "start": { - "line": 22, + "line": 26, "column": 1 }, "end": { - "line": 35, + "line": 28, "column": 2 } } - } - ], - "loc": { - "start": { - "line": 1, - "column": 1 }, - "end": { - "line": 1, - "column": 1 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, - { - "type": "ClassDeclaration", - "definition": { - "id": { - "type": "Identifier", - "name": "$jsnew", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, - "superClass": null, - "implements": [], - "body": [ { - "type": "ClassProperty", + "type": "MethodDefinition", "key": { "type": "Identifier", - "name": "qname_start_from", + "name": "fn_ets_object", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 30, + "column": 10 }, "end": { - "line": 1, - "column": 1 + "line": 30, + "column": 23 } } }, - "accessibility": "private", + "kind": "method", + "accessibility": "public", "static": true, - "readonly": true, - "declare": false, "optional": false, "computed": false, - "typeAnnotation": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, - "definite": false, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, - { - "type": "ClassStaticBlock", "value": { "type": "FunctionExpression", "function": { "type": "ScriptFunction", "id": { "type": "Identifier", - "name": "", + "name": "fn_ets_object", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 30, + "column": 10 }, "end": { - "line": 1, - "column": 1 + "line": 30, + "column": 23 } } }, "generator": false, "async": false, - "expression": true, - "params": [], - "body": { - "type": "BlockStatement", - "statements": [ - { - "type": "ExpressionStatement", - "expression": { - "type": "CallExpression", - "callee": { - "type": "MemberExpression", - "object": { + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "o", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { "type": "Identifier", - "name": "JSRuntime", + "name": "A", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 30, + "column": 27 }, "end": { - "line": 1, - "column": 1 + "line": 30, + "column": 28 } } }, - "property": { - "type": "Identifier", - "name": "__initJSNewClass", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } + "loc": { + "start": { + "line": 30, + "column": 27 + }, + "end": { + "line": 30, + "column": 29 } + } + }, + "loc": { + "start": { + "line": 30, + "column": 27 }, - "computed": false, - "optional": false, + "end": { + "line": 30, + "column": 29 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 24 + }, + "end": { + "line": 30, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 24 + }, + "end": { + "line": 30, + "column": 29 + } + } + } + ], + "returnType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 30, + "column": 31 + }, + "end": { + "line": 30, + "column": 38 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "BinaryExpression", + "operator": "instanceof", + "left": { + "type": "Identifier", + "name": "o", + "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 31, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 31, + "column": 13 } } }, - "arguments": [ - { - "type": "StringLiteral", - "value": "L$jsnew;", + "right": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 31, + "column": 25 + }, + "end": { + "line": 31, + "column": 26 + } + } + }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 31, + "column": 25 }, "end": { - "line": 1, - "column": 1 + "line": 31, + "column": 27 } } + }, + "loc": { + "start": { + "line": 31, + "column": 25 + }, + "end": { + "line": 31, + "column": 27 + } } - ], - "optional": false, + }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 31, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 31, + "column": 27 } } }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 31, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 31, + "column": 27 } } } ], "loc": { "start": { - "line": 1, - "column": 1 + "line": 30, + "column": 39 }, "end": { - "line": 1, - "column": 1 + "line": 32, + "column": 2 } } }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 30, + "column": 23 }, "end": { - "line": 1, - "column": 1 + "line": 32, + "column": 2 } } }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 30, + "column": 23 }, "end": { - "line": 1, - "column": 1 + "line": 32, + "column": 2 } } }, + "overloads": [], + "decorators": [], "loc": { "start": { - "line": 1, + "line": 30, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 32, + "column": 2 } } }, @@ -1179,16 +786,16 @@ "type": "MethodDefinition", "key": { "type": "Identifier", - "name": "invoke", + "name": "fn_jsvalue", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 34, + "column": 10 }, "end": { - "line": 1, - "column": 1 + "line": 34, + "column": 20 } } }, @@ -1203,16 +810,16 @@ "type": "ScriptFunction", "id": { "type": "Identifier", - "name": "invoke", + "name": "fn_jsvalue", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 34, + "column": 10 }, "end": { - "line": 1, - "column": 1 + "line": 34, + "column": 20 } } }, @@ -1224,158 +831,724 @@ "type": "ETSParameterExpression", "name": { "type": "Identifier", - "name": "obj", + "name": "o", "typeAnnotation": { - "type": "OpaqueType", + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "JSValue", + "decorators": [], + "loc": { + "start": { + "line": 34, + "column": 24 + }, + "end": { + "line": 34, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 34, + "column": 24 + }, + "end": { + "line": 34, + "column": 32 + } + } + }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 34, + "column": 24 }, "end": { - "line": 1, - "column": 1 + "line": 34, + "column": 32 } } }, "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 34, + "column": 21 }, "end": { - "line": 1, - "column": 1 + "line": 34, + "column": 32 } } }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 34, + "column": 21 }, "end": { - "line": 1, - "column": 1 + "line": 34, + "column": 32 } } - }, - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "qname_start", - "typeAnnotation": { - "type": "ETSPrimitiveType", - "loc": { + } + ], + "returnType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 34, + "column": 34 + }, + "end": { + "line": 34, + "column": 41 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "BinaryExpression", + "operator": "instanceof", + "left": { + "type": "Identifier", + "name": "o", + "decorators": [], + "loc": { + "start": { + "line": 35, + "column": 12 + }, + "end": { + "line": 35, + "column": 13 + } + } + }, + "right": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 35, + "column": 25 + }, + "end": { + "line": 35, + "column": 26 + } + } + }, + "loc": { + "start": { + "line": 35, + "column": 25 + }, + "end": { + "line": 35, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 35, + "column": 25 + }, + "end": { + "line": 35, + "column": 27 + } + } + }, + "loc": { "start": { - "line": 1, - "column": 1 + "line": 35, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 35, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 35, + "column": 5 + }, + "end": { + "line": 35, + "column": 27 + } + } + } + ], + "loc": { + "start": { + "line": 34, + "column": 42 + }, + "end": { + "line": 36, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 34, + "column": 20 + }, + "end": { + "line": 36, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 34, + "column": 20 + }, + "end": { + "line": 36, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 34, + "column": 1 + }, + "end": { + "line": 36, + "column": 2 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "fn_dyn_value", + "decorators": [], + "loc": { + "start": { + "line": 38, + "column": 10 + }, + "end": { + "line": 38, + "column": 22 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "fn_dyn_value", + "decorators": [], + "loc": { + "start": { + "line": 38, + "column": 10 + }, + "end": { + "line": 38, + "column": 22 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "o", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "AValue", + "decorators": [], + "loc": { + "start": { + "line": 38, + "column": 26 + }, + "end": { + "line": 38, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 38, + "column": 26 + }, + "end": { + "line": 38, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 38, + "column": 26 + }, + "end": { + "line": 38, + "column": 33 } } }, "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 38, + "column": 23 }, "end": { - "line": 1, - "column": 1 + "line": 38, + "column": 33 } } }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 38, + "column": 23 }, "end": { - "line": 1, - "column": 1 + "line": 38, + "column": 33 + } + } + } + ], + "returnType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 38, + "column": 35 + }, + "end": { + "line": 38, + "column": 42 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "BinaryExpression", + "operator": "instanceof", + "left": { + "type": "Identifier", + "name": "o", + "decorators": [], + "loc": { + "start": { + "line": 39, + "column": 12 + }, + "end": { + "line": 39, + "column": 13 + } + } + }, + "right": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 39, + "column": 25 + }, + "end": { + "line": 39, + "column": 26 + } + } + }, + "loc": { + "start": { + "line": 39, + "column": 25 + }, + "end": { + "line": 39, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 39, + "column": 25 + }, + "end": { + "line": 39, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 39, + "column": 12 + }, + "end": { + "line": 39, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 39, + "column": 5 + }, + "end": { + "line": 39, + "column": 27 + } } } + ], + "loc": { + "start": { + "line": 38, + "column": 43 + }, + "end": { + "line": 40, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 38, + "column": 22 }, + "end": { + "line": 40, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 38, + "column": 22 + }, + "end": { + "line": 40, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 38, + "column": 1 + }, + "end": { + "line": 40, + "column": 2 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "fn_dyn_decl", + "decorators": [], + "loc": { + "start": { + "line": 42, + "column": 10 + }, + "end": { + "line": 42, + "column": 21 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "fn_dyn_decl", + "decorators": [], + "loc": { + "start": { + "line": 42, + "column": 10 + }, + "end": { + "line": 42, + "column": 21 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ { "type": "ETSParameterExpression", "name": { "type": "Identifier", - "name": "qname_len", + "name": "o", "typeAnnotation": { - "type": "ETSPrimitiveType", + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "ADeclared", + "decorators": [], + "loc": { + "start": { + "line": 42, + "column": 25 + }, + "end": { + "line": 42, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 42, + "column": 25 + }, + "end": { + "line": 42, + "column": 35 + } + } + }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 42, + "column": 25 }, "end": { - "line": 1, - "column": 1 + "line": 42, + "column": 35 } } }, "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 42, + "column": 22 }, "end": { - "line": 1, - "column": 1 + "line": 42, + "column": 35 } } }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 42, + "column": 22 }, "end": { - "line": 1, - "column": 1 + "line": 42, + "column": 35 } } } ], "returnType": { - "type": "OpaqueType", + "type": "ETSPrimitiveType", "loc": { "start": { - "line": 1, - "column": 1 + "line": 42, + "column": 37 }, "end": { - "line": 1, - "column": 1 + "line": 42, + "column": 44 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "BinaryExpression", + "operator": "instanceof", + "left": { + "type": "Identifier", + "name": "o", + "decorators": [], + "loc": { + "start": { + "line": 43, + "column": 12 + }, + "end": { + "line": 43, + "column": 13 + } + } + }, + "right": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 43, + "column": 25 + }, + "end": { + "line": 43, + "column": 26 + } + } + }, + "loc": { + "start": { + "line": 43, + "column": 25 + }, + "end": { + "line": 43, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 43, + "column": 25 + }, + "end": { + "line": 43, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 43, + "column": 12 + }, + "end": { + "line": 43, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 43, + "column": 5 + }, + "end": { + "line": 43, + "column": 27 + } + } + } + ], + "loc": { + "start": { + "line": 42, + "column": 45 + }, + "end": { + "line": 44, + "column": 2 } } }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 42, + "column": 21 }, "end": { - "line": 1, - "column": 1 + "line": 44, + "column": 2 } } }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 42, + "column": 21 }, "end": { - "line": 1, - "column": 1 + "line": 44, + "column": 2 } } }, @@ -1383,12 +1556,12 @@ "decorators": [], "loc": { "start": { - "line": 1, + "line": 42, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 44, + "column": 2 } } } @@ -1420,16 +1593,16 @@ "definition": { "id": { "type": "Identifier", - "name": "$jscall", + "name": "A", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 23, + "column": 7 }, "end": { - "line": 1, - "column": 1 + "line": 23, + "column": 8 } } }, @@ -1437,10 +1610,10 @@ "implements": [], "body": [ { - "type": "ClassProperty", + "type": "MethodDefinition", "key": { "type": "Identifier", - "name": "qname_start_from", + "name": "constructor", "decorators": [], "loc": { "start": { @@ -1451,49 +1624,19 @@ "line": 1, "column": 1 } - } - }, - "accessibility": "private", - "static": true, - "readonly": true, - "declare": false, - "optional": false, - "computed": false, - "typeAnnotation": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, - "definite": false, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, - { - "type": "ClassStaticBlock", + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, "value": { "type": "FunctionExpression", "function": { "type": "ScriptFunction", "id": { "type": "Identifier", - "name": "", + "name": "constructor", "decorators": [], "loc": { "start": { @@ -1508,100 +1651,11 @@ }, "generator": false, "async": false, - "expression": true, + "expression": false, "params": [], "body": { "type": "BlockStatement", - "statements": [ - { - "type": "ExpressionStatement", - "expression": { - "type": "CallExpression", - "callee": { - "type": "MemberExpression", - "object": { - "type": "Identifier", - "name": "JSRuntime", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, - "property": { - "type": "Identifier", - "name": "__initJSCallClass", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, - "computed": false, - "optional": false, - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, - "arguments": [ - { - "type": "StringLiteral", - "value": "L$jscall;", - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - } - ], - "optional": false, - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - } - ], + "statements": [], "loc": { "start": { "line": 1, @@ -1635,22 +1689,68 @@ } } }, + "overloads": [], + "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 23, + "column": 11 }, "end": { - "line": 1, - "column": 1 + "line": 23, + "column": 11 } } + } + ], + "loc": { + "start": { + "line": 23, + "column": 9 }, + "end": { + "line": 23, + "column": 11 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 1 + }, + "end": { + "line": 23, + "column": 11 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 7 + }, + "end": { + "line": 24, + "column": 8 + } + } + }, + "superClass": null, + "implements": [], + "body": [ { "type": "MethodDefinition", "key": { "type": "Identifier", - "name": "invoke", + "name": "constructor", "decorators": [], "loc": { "start": { @@ -1663,9 +1763,8 @@ } } }, - "kind": "method", - "accessibility": "public", - "static": true, + "kind": "constructor", + "static": false, "optional": false, "computed": false, "value": { @@ -1674,7 +1773,7 @@ "type": "ScriptFunction", "id": { "type": "Identifier", - "name": "invoke", + "name": "constructor", "decorators": [], "loc": { "start": { @@ -1690,133 +1789,10 @@ "generator": false, "async": false, "expression": false, - "params": [ - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "obj", - "typeAnnotation": { - "type": "OpaqueType", - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "qname_start", - "typeAnnotation": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "qname_len", - "typeAnnotation": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - } - ], - "returnType": { - "type": "OpaqueType", + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], "loc": { "start": { "line": 1, @@ -1854,35 +1830,35 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 24, + "column": 11 }, "end": { - "line": 1, - "column": 1 + "line": 24, + "column": 11 } } } ], "loc": { "start": { - "line": 1, - "column": 1 + "line": 24, + "column": 9 }, "end": { - "line": 1, - "column": 1 + "line": 24, + "column": 11 } } }, "loc": { "start": { - "line": 1, + "line": 24, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 24, + "column": 11 } } }, @@ -2300,7 +2276,7 @@ "column": 1 }, "end": { - "line": 37, + "line": 45, "column": 1 } } diff --git a/ets2panda/test/compiler/ets/instanceof_x_etstype.ets b/ets2panda/test/compiler/ets/instanceof_x_etstype.ets new file mode 100644 index 0000000000..5d723962bb --- /dev/null +++ b/ets2panda/test/compiler/ets/instanceof_x_etstype.ets @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*--- +flags: [dynamic-ast] +---*/ + +import { AValue } from "dynamic_js_import_tests" +import { ADeclared } from "dynamic_import_tests/modules/instanceof" + +class A {} +class B {} + +function fn_object(o: Object): boolean { + return o instanceof B; +} + +function fn_ets_object(o: A): boolean { + return o instanceof B; +} + +function fn_jsvalue(o: JSValue): boolean { + return o instanceof B; +} + +function fn_dyn_value(o: AValue): boolean { + return o instanceof B; +} + +function fn_dyn_decl(o: ADeclared): boolean { + return o instanceof B; +} diff --git a/ets2panda/test/compiler/ets/instanceof_x_object-expected.txt b/ets2panda/test/compiler/ets/instanceof_x_object-expected.txt new file mode 100644 index 0000000000..2b42c302e5 --- /dev/null +++ b/ets2panda/test/compiler/ets/instanceof_x_object-expected.txt @@ -0,0 +1,2146 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ImportDeclaration", + "source": { + "type": "StringLiteral", + "value": "dynamic_js_import_tests", + "loc": { + "start": { + "line": 20, + "column": 24 + }, + "end": { + "line": 20, + "column": 49 + } + } + }, + "specifiers": [ + { + "type": "ImportSpecifier", + "local": { + "type": "Identifier", + "name": "AValue", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 10 + }, + "end": { + "line": 20, + "column": 16 + } + } + }, + "imported": { + "type": "Identifier", + "name": "AValue", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 10 + }, + "end": { + "line": 20, + "column": 16 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 10 + }, + "end": { + "line": 20, + "column": 16 + } + } + } + ], + "loc": { + "start": { + "line": 20, + "column": 1 + }, + "end": { + "line": 20, + "column": 49 + } + } + }, + { + "type": "ImportDeclaration", + "source": { + "type": "StringLiteral", + "value": "dynamic_import_tests/modules/instanceof", + "loc": { + "start": { + "line": 21, + "column": 27 + }, + "end": { + "line": 21, + "column": 68 + } + } + }, + "specifiers": [ + { + "type": "ImportSpecifier", + "local": { + "type": "Identifier", + "name": "ADeclared", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 10 + }, + "end": { + "line": 21, + "column": 19 + } + } + }, + "imported": { + "type": "Identifier", + "name": "ADeclared", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 10 + }, + "end": { + "line": 21, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 10 + }, + "end": { + "line": 21, + "column": 19 + } + } + } + ], + "loc": { + "start": { + "line": 21, + "column": 1 + }, + "end": { + "line": 21, + "column": 68 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "fn_object", + "decorators": [], + "loc": { + "start": { + "line": 25, + "column": 10 + }, + "end": { + "line": 25, + "column": 19 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "fn_object", + "decorators": [], + "loc": { + "start": { + "line": 25, + "column": 10 + }, + "end": { + "line": 25, + "column": 19 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "o", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], + "loc": { + "start": { + "line": 25, + "column": 23 + }, + "end": { + "line": 25, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 25, + "column": 23 + }, + "end": { + "line": 25, + "column": 30 + } + } + }, + "loc": { + "start": { + "line": 25, + "column": 23 + }, + "end": { + "line": 25, + "column": 30 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 25, + "column": 20 + }, + "end": { + "line": 25, + "column": 30 + } + } + }, + "loc": { + "start": { + "line": 25, + "column": 20 + }, + "end": { + "line": 25, + "column": 30 + } + } + } + ], + "returnType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 25, + "column": 32 + }, + "end": { + "line": 25, + "column": 39 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "BinaryExpression", + "operator": "instanceof", + "left": { + "type": "Identifier", + "name": "o", + "decorators": [], + "loc": { + "start": { + "line": 26, + "column": 12 + }, + "end": { + "line": 26, + "column": 13 + } + } + }, + "right": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], + "loc": { + "start": { + "line": 26, + "column": 25 + }, + "end": { + "line": 26, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 25 + }, + "end": { + "line": 26, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 25 + }, + "end": { + "line": 26, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 12 + }, + "end": { + "line": 26, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 5 + }, + "end": { + "line": 26, + "column": 32 + } + } + } + ], + "loc": { + "start": { + "line": 25, + "column": 40 + }, + "end": { + "line": 27, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 25, + "column": 19 + }, + "end": { + "line": 27, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 25, + "column": 19 + }, + "end": { + "line": 27, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 25, + "column": 1 + }, + "end": { + "line": 27, + "column": 2 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "fn_ets_object", + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 10 + }, + "end": { + "line": 29, + "column": 23 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "fn_ets_object", + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 10 + }, + "end": { + "line": 29, + "column": 23 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "o", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 27 + }, + "end": { + "line": 29, + "column": 28 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 27 + }, + "end": { + "line": 29, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 27 + }, + "end": { + "line": 29, + "column": 29 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 24 + }, + "end": { + "line": 29, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 24 + }, + "end": { + "line": 29, + "column": 29 + } + } + } + ], + "returnType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 29, + "column": 31 + }, + "end": { + "line": 29, + "column": 38 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "BinaryExpression", + "operator": "instanceof", + "left": { + "type": "Identifier", + "name": "o", + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 12 + }, + "end": { + "line": 30, + "column": 13 + } + } + }, + "right": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 25 + }, + "end": { + "line": 30, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 25 + }, + "end": { + "line": 30, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 25 + }, + "end": { + "line": 30, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 12 + }, + "end": { + "line": 30, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 5 + }, + "end": { + "line": 30, + "column": 32 + } + } + } + ], + "loc": { + "start": { + "line": 29, + "column": 39 + }, + "end": { + "line": 31, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 23 + }, + "end": { + "line": 31, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 23 + }, + "end": { + "line": 31, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 1 + }, + "end": { + "line": 31, + "column": 2 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "fn_jsvalue", + "decorators": [], + "loc": { + "start": { + "line": 33, + "column": 10 + }, + "end": { + "line": 33, + "column": 20 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "fn_jsvalue", + "decorators": [], + "loc": { + "start": { + "line": 33, + "column": 10 + }, + "end": { + "line": 33, + "column": 20 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "o", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "JSValue", + "decorators": [], + "loc": { + "start": { + "line": 33, + "column": 24 + }, + "end": { + "line": 33, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 33, + "column": 24 + }, + "end": { + "line": 33, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 33, + "column": 24 + }, + "end": { + "line": 33, + "column": 32 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 33, + "column": 21 + }, + "end": { + "line": 33, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 33, + "column": 21 + }, + "end": { + "line": 33, + "column": 32 + } + } + } + ], + "returnType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 33, + "column": 34 + }, + "end": { + "line": 33, + "column": 41 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "BinaryExpression", + "operator": "instanceof", + "left": { + "type": "Identifier", + "name": "o", + "decorators": [], + "loc": { + "start": { + "line": 34, + "column": 12 + }, + "end": { + "line": 34, + "column": 13 + } + } + }, + "right": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], + "loc": { + "start": { + "line": 34, + "column": 25 + }, + "end": { + "line": 34, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 34, + "column": 25 + }, + "end": { + "line": 34, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 34, + "column": 25 + }, + "end": { + "line": 34, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 34, + "column": 12 + }, + "end": { + "line": 34, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 34, + "column": 5 + }, + "end": { + "line": 34, + "column": 32 + } + } + } + ], + "loc": { + "start": { + "line": 33, + "column": 42 + }, + "end": { + "line": 35, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 33, + "column": 20 + }, + "end": { + "line": 35, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 33, + "column": 20 + }, + "end": { + "line": 35, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 33, + "column": 1 + }, + "end": { + "line": 35, + "column": 2 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "fn_dyn_value", + "decorators": [], + "loc": { + "start": { + "line": 37, + "column": 10 + }, + "end": { + "line": 37, + "column": 22 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "fn_dyn_value", + "decorators": [], + "loc": { + "start": { + "line": 37, + "column": 10 + }, + "end": { + "line": 37, + "column": 22 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "o", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "AValue", + "decorators": [], + "loc": { + "start": { + "line": 37, + "column": 26 + }, + "end": { + "line": 37, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 37, + "column": 26 + }, + "end": { + "line": 37, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 37, + "column": 26 + }, + "end": { + "line": 37, + "column": 33 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 37, + "column": 23 + }, + "end": { + "line": 37, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 37, + "column": 23 + }, + "end": { + "line": 37, + "column": 33 + } + } + } + ], + "returnType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 37, + "column": 35 + }, + "end": { + "line": 37, + "column": 42 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "BinaryExpression", + "operator": "instanceof", + "left": { + "type": "Identifier", + "name": "o", + "decorators": [], + "loc": { + "start": { + "line": 38, + "column": 12 + }, + "end": { + "line": 38, + "column": 13 + } + } + }, + "right": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], + "loc": { + "start": { + "line": 38, + "column": 25 + }, + "end": { + "line": 38, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 38, + "column": 25 + }, + "end": { + "line": 38, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 38, + "column": 25 + }, + "end": { + "line": 38, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 38, + "column": 12 + }, + "end": { + "line": 38, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 38, + "column": 5 + }, + "end": { + "line": 38, + "column": 32 + } + } + } + ], + "loc": { + "start": { + "line": 37, + "column": 43 + }, + "end": { + "line": 39, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 37, + "column": 22 + }, + "end": { + "line": 39, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 37, + "column": 22 + }, + "end": { + "line": 39, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 37, + "column": 1 + }, + "end": { + "line": 39, + "column": 2 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "fn_dyn_decl", + "decorators": [], + "loc": { + "start": { + "line": 41, + "column": 10 + }, + "end": { + "line": 41, + "column": 21 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "fn_dyn_decl", + "decorators": [], + "loc": { + "start": { + "line": 41, + "column": 10 + }, + "end": { + "line": 41, + "column": 21 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "o", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "ADeclared", + "decorators": [], + "loc": { + "start": { + "line": 41, + "column": 25 + }, + "end": { + "line": 41, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 41, + "column": 25 + }, + "end": { + "line": 41, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 41, + "column": 25 + }, + "end": { + "line": 41, + "column": 35 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 41, + "column": 22 + }, + "end": { + "line": 41, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 41, + "column": 22 + }, + "end": { + "line": 41, + "column": 35 + } + } + } + ], + "returnType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 41, + "column": 37 + }, + "end": { + "line": 41, + "column": 44 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "BinaryExpression", + "operator": "instanceof", + "left": { + "type": "Identifier", + "name": "o", + "decorators": [], + "loc": { + "start": { + "line": 42, + "column": 12 + }, + "end": { + "line": 42, + "column": 13 + } + } + }, + "right": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], + "loc": { + "start": { + "line": 42, + "column": 25 + }, + "end": { + "line": 42, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 42, + "column": 25 + }, + "end": { + "line": 42, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 42, + "column": 25 + }, + "end": { + "line": 42, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 42, + "column": 12 + }, + "end": { + "line": 42, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 42, + "column": 5 + }, + "end": { + "line": 42, + "column": 32 + } + } + } + ], + "loc": { + "start": { + "line": 41, + "column": 45 + }, + "end": { + "line": 43, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 41, + "column": 21 + }, + "end": { + "line": 43, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 41, + "column": 21 + }, + "end": { + "line": 43, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 41, + "column": 1 + }, + "end": { + "line": 43, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 7 + }, + "end": { + "line": 23, + "column": 8 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 11 + }, + "end": { + "line": 23, + "column": 11 + } + } + } + ], + "loc": { + "start": { + "line": 23, + "column": 9 + }, + "end": { + "line": 23, + "column": 11 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 1 + }, + "end": { + "line": 23, + "column": 11 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "$dynmodule", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "dynamic_js_import_tests0", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "accessibility": "public", + "static": true, + "readonly": true, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "OpaqueType", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassStaticBlock", + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": true, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "$dynmodule", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "dynamic_js_import_tests0", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "right": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "JSRuntime", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "loadModule", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "StringLiteral", + "value": "dynamic_js_import_tests", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "init", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "init", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 44, + "column": 1 + } + } +} diff --git a/ets2panda/test/compiler/ets/instanceof_x_object.ets b/ets2panda/test/compiler/ets/instanceof_x_object.ets new file mode 100644 index 0000000000..93dde6e64f --- /dev/null +++ b/ets2panda/test/compiler/ets/instanceof_x_object.ets @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*--- +flags: [dynamic-ast] +---*/ + +import { AValue } from "dynamic_js_import_tests" +import { ADeclared } from "dynamic_import_tests/modules/instanceof" + +class A {} + +function fn_object(o: Object): boolean { + return o instanceof Object; +} + +function fn_ets_object(o: A): boolean { + return o instanceof Object; +} + +function fn_jsvalue(o: JSValue): boolean { + return o instanceof Object; +} + +function fn_dyn_value(o: AValue): boolean { + return o instanceof Object; +} + +function fn_dyn_decl(o: ADeclared): boolean { + return o instanceof Object; +} diff --git a/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_decl_import-expected.txt b/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_decl_import-expected.txt index f260ab4148..9e70f26122 100644 --- a/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_decl_import-expected.txt +++ b/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_decl_import-expected.txt @@ -1693,8 +1693,8 @@ "column": 1 }, "end": { - "line": 40, - "column": 2 + "line": 41, + "column": 1 } } } diff --git a/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_decl_import.ets b/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_decl_import.ets index 9a0d3a8396..589c492ad7 100644 --- a/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_decl_import.ets +++ b/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_decl_import.ets @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2023 Huawei Device Co., Ltd. + * Copyright (c) 2021-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -37,4 +37,4 @@ function main(): void { A.f2 = f2 foo(obj) -} \ No newline at end of file +} diff --git a/ets2panda/test/parser/ets/dynamic_import_tests/modules/instanceof-expected.txt b/ets2panda/test/parser/ets/dynamic_import_tests/modules/instanceof-expected.txt new file mode 100644 index 0000000000..327b214546 --- /dev/null +++ b/ets2panda/test/parser/ets/dynamic_import_tests/modules/instanceof-expected.txt @@ -0,0 +1,427 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ADeclared", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 22 + }, + "end": { + "line": 20, + "column": 31 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 2 + }, + "end": { + "line": 21, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 20, + "column": 32 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 16 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "BDeclared", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 22 + }, + "end": { + "line": 23, + "column": 31 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 2 + }, + "end": { + "line": 24, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 23, + "column": 32 + }, + "end": { + "line": 24, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 16 + }, + "end": { + "line": 24, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 25, + "column": 1 + } + } +} diff --git a/ets2panda/test/compiler/ets/dynamic_instanceof.ets b/ets2panda/test/parser/ets/dynamic_import_tests/modules/instanceof.ets similarity index 71% rename from ets2panda/test/compiler/ets/dynamic_instanceof.ets rename to ets2panda/test/parser/ets/dynamic_import_tests/modules/instanceof.ets index 01b06b980a..73f81409b2 100644 --- a/ets2panda/test/compiler/ets/dynamic_instanceof.ets +++ b/ets2panda/test/parser/ets/dynamic_import_tests/modules/instanceof.ets @@ -17,20 +17,8 @@ flags: [dynamic-ast] ---*/ -import { A, B, jsfunc } from "dynamic_js_import_tests" - -function foo(): int { - let a = new A(); - if (a instanceof A) { - return 1; - } else { - let x = jsfunc(); - let b = x instanceof B; - if (b) { - return 2; - } else { - return 3; - } - } +export declare class ADeclared { } +export declare class BDeclared { +} diff --git a/ets2panda/test/test-lists/parser/parser-js-ignored.txt b/ets2panda/test/test-lists/parser/parser-js-ignored.txt index d4a6eab971..8c25b65436 100644 --- a/ets2panda/test/test-lists/parser/parser-js-ignored.txt +++ b/ets2panda/test/test-lists/parser/parser-js-ignored.txt @@ -26,9 +26,6 @@ compiler/ets/override3.ets compiler/ets/override4.ets compiler/ets/override5.ets -# 13086 -compiler/ets/dynamic_instanceof.ets - # Requires smart casts parser/ets/null-coalesc-negative.ets -- Gitee From fd4e1a719f46bd032e6f60f2b1e4f6831078d7bb Mon Sep 17 00:00:00 2001 From: l00799755 Date: Sun, 28 Apr 2024 20:31:55 +0800 Subject: [PATCH 05/22] Add test case of issue Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/I9KGU4 Reason: the issue has been fixed on master branch, test case needs to be added as well. Description: Add test case of the issue. Testing: All required pre-merge tests passed. Results are available in the ggwatcher. Signed-off-by: l00799755 --- .../optional_field_variable_2-expected.txt | 1146 +++++++++++++++++ .../parser/ets/optional_field_variable_2.ets | 25 + .../runtime/ets/optional_field_variable.ets | 37 + 3 files changed, 1208 insertions(+) create mode 100644 ets2panda/test/parser/ets/optional_field_variable_2-expected.txt create mode 100644 ets2panda/test/parser/ets/optional_field_variable_2.ets create mode 100644 ets2panda/test/runtime/ets/optional_field_variable.ets diff --git a/ets2panda/test/parser/ets/optional_field_variable_2-expected.txt b/ets2panda/test/parser/ets/optional_field_variable_2-expected.txt new file mode 100644 index 0000000000..0304436df8 --- /dev/null +++ b/ets2panda/test/parser/ets/optional_field_variable_2-expected.txt @@ -0,0 +1,1146 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 15, + "column": 7 + }, + "end": { + "line": 15, + "column": 8 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "once", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 5 + }, + "end": { + "line": 16, + "column": 9 + } + } + }, + "value": { + "type": "BooleanLiteral", + "value": true, + "loc": { + "start": { + "line": 16, + "column": 22 + }, + "end": { + "line": 16, + "column": 26 + } + } + }, + "accessibility": "public", + "static": false, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 16, + "column": 12 + }, + "end": { + "line": 16, + "column": 19 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 5 + }, + "end": { + "line": 16, + "column": 26 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 2 + }, + "end": { + "line": 17, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 15, + "column": 9 + }, + "end": { + "line": 17, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 15, + "column": 1 + }, + "end": { + "line": 17, + "column": 2 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 7 + }, + "end": { + "line": 19, + "column": 8 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 8 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 8 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "global", + "typeAnnotation": { + "type": "ETSUnionType", + "types": [ + { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 21, + "column": 22 + }, + "end": { + "line": 21, + "column": 29 + } + } + }, + { + "type": "ETSUndefinedType", + "loc": { + "start": { + "line": 21, + "column": 32 + }, + "end": { + "line": 21, + "column": 41 + } + } + } + ], + "loc": { + "start": { + "line": 21, + "column": 22 + }, + "end": { + "line": 21, + "column": 41 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 13 + }, + "end": { + "line": 21, + "column": 19 + } + } + }, + "init": { + "type": "BooleanLiteral", + "value": true, + "loc": { + "start": { + "line": 21, + "column": 44 + }, + "end": { + "line": 21, + "column": 48 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 13 + }, + "end": { + "line": 21, + "column": 48 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 21, + "column": 9 + }, + "end": { + "line": 21, + "column": 48 + } + } + }, + { + "type": "IfStatement", + "test": { + "type": "BinaryExpression", + "operator": "==", + "left": { + "type": "Identifier", + "name": "global", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 13 + }, + "end": { + "line": 22, + "column": 19 + } + } + }, + "right": { + "type": "UndefinedLiteral", + "value": undefined, + "loc": { + "start": { + "line": 22, + "column": 23 + }, + "end": { + "line": 22, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 13 + }, + "end": { + "line": 22, + "column": 32 + } + } + }, + "consequent": { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "global", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 34 + }, + "end": { + "line": 22, + "column": 40 + } + } + }, + "right": { + "type": "BinaryExpression", + "operator": "!=", + "left": { + "type": "BlockExpression", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "gensym$_2", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "init": { + "type": "MemberExpression", + "object": { + "type": "ThisExpression", + "loc": { + "start": { + "line": 22, + "column": 43 + }, + "end": { + "line": 22, + "column": 47 + } + } + }, + "property": { + "type": "Identifier", + "name": "current", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 48 + }, + "end": { + "line": 22, + "column": 55 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 22, + "column": 43 + }, + "end": { + "line": 22, + "column": 55 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 22, + "column": 43 + }, + "end": { + "line": 22, + "column": 69 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "ConditionalExpression", + "test": { + "type": "BinaryExpression", + "operator": "==", + "left": { + "type": "Identifier", + "name": "gensym$_2", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "right": { + "type": "NullLiteral", + "value": null, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "consequent": { + "type": "UndefinedLiteral", + "value": undefined, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "alternate": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "gensym$_2", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 43 + }, + "end": { + "line": 22, + "column": 61 + } + } + }, + "property": { + "type": "Identifier", + "name": "once", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 57 + }, + "end": { + "line": 22, + "column": 61 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 22, + "column": 43 + }, + "end": { + "line": 22, + "column": 61 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + } + ], + "loc": { + "start": { + "line": 22, + "column": 43 + }, + "end": { + "line": 22, + "column": 69 + } + } + }, + "right": { + "type": "BooleanLiteral", + "value": true, + "loc": { + "start": { + "line": 22, + "column": 65 + }, + "end": { + "line": 22, + "column": 69 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 43 + }, + "end": { + "line": 22, + "column": 69 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 34 + }, + "end": { + "line": 22, + "column": 69 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 34 + }, + "end": { + "line": 22, + "column": 69 + } + } + }, + "alternate": null, + "loc": { + "start": { + "line": 22, + "column": 9 + }, + "end": { + "line": 22, + "column": 69 + } + } + } + ], + "loc": { + "start": { + "line": 20, + "column": 11 + }, + "end": { + "line": 23, + "column": 6 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 8 + }, + "end": { + "line": 23, + "column": 6 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 8 + }, + "end": { + "line": 23, + "column": 6 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 23, + "column": 6 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "current", + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 5 + }, + "end": { + "line": 24, + "column": 12 + } + } + }, + "accessibility": "public", + "static": false, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "ETSUnionType", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 15 + }, + "end": { + "line": 24, + "column": 16 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 15 + }, + "end": { + "line": 24, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 15 + }, + "end": { + "line": 24, + "column": 18 + } + } + }, + { + "type": "ETSUndefinedType", + "loc": { + "start": { + "line": 24, + "column": 19 + }, + "end": { + "line": 24, + "column": 28 + } + } + } + ], + "loc": { + "start": { + "line": 24, + "column": 15 + }, + "end": { + "line": 24, + "column": 28 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 5 + }, + "end": { + "line": 24, + "column": 28 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 25, + "column": 2 + }, + "end": { + "line": 25, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 25, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 1 + }, + "end": { + "line": 25, + "column": 2 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 26, + "column": 1 + } + } +} diff --git a/ets2panda/test/parser/ets/optional_field_variable_2.ets b/ets2panda/test/parser/ets/optional_field_variable_2.ets new file mode 100644 index 0000000000..5359d7012d --- /dev/null +++ b/ets2panda/test/parser/ets/optional_field_variable_2.ets @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +class C { + once : boolean = true +} + +class A { + foo() { + let global : boolean | undefined = true + if (global == undefined) global = this.current?.once != true + } + current : C | undefined +} diff --git a/ets2panda/test/runtime/ets/optional_field_variable.ets b/ets2panda/test/runtime/ets/optional_field_variable.ets new file mode 100644 index 0000000000..3ad579abb7 --- /dev/null +++ b/ets2panda/test/runtime/ets/optional_field_variable.ets @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +class C { + once : boolean = true +} + +class A { + global : boolean | undefined = undefined + current : C | undefined + + foo () { + if (this.global == undefined) this.global = this.current?.once != true + } +} + +function main(): void { + let a = new A() + a.foo() + assert(a.global == true) + + a.global = undefined + a.current = new C() + a.foo() + assert(a.global == false) +} -- Gitee From 039e09facf1319001c068406ecc43974e02a5c5d Mon Sep 17 00:00:00 2001 From: Tamas Toth Date: Wed, 24 Jan 2024 10:21:26 +0100 Subject: [PATCH 06/22] [ETS] Add test for "Fix reexport it can only use first export" Fixes #16105 internal issue Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/I97YKO Testing: all CI tests passed. Results are availible in gg watcher. Signed-off-by: Tamas Toth Change-Id: Ie28fa989d839a101bec40c51f040cd1073db70f2 --- .../re_export/folderIndex2/index-expected.txt | 323 ++++++++++ .../ets/re_export/folderIndex2/index.ets | 17 + .../re_export/folderIndex2/key-expected.txt | 581 ++++++++++++++++++ .../parser/ets/re_export/folderIndex2/key.ets | 21 + .../re_export/folderIndex2/type-expected.txt | 222 +++++++ .../ets/re_export/folderIndex2/type.ets | 16 + .../ets/re_export/import_index_3-expected.txt | 268 ++++++++ .../parser/ets/re_export/import_index_3.ets | 16 + 8 files changed, 1464 insertions(+) create mode 100644 ets2panda/test/parser/ets/re_export/folderIndex2/index-expected.txt create mode 100644 ets2panda/test/parser/ets/re_export/folderIndex2/index.ets create mode 100644 ets2panda/test/parser/ets/re_export/folderIndex2/key-expected.txt create mode 100644 ets2panda/test/parser/ets/re_export/folderIndex2/key.ets create mode 100644 ets2panda/test/parser/ets/re_export/folderIndex2/type-expected.txt create mode 100644 ets2panda/test/parser/ets/re_export/folderIndex2/type.ets create mode 100644 ets2panda/test/parser/ets/re_export/import_index_3-expected.txt create mode 100644 ets2panda/test/parser/ets/re_export/import_index_3.ets diff --git a/ets2panda/test/parser/ets/re_export/folderIndex2/index-expected.txt b/ets2panda/test/parser/ets/re_export/folderIndex2/index-expected.txt new file mode 100644 index 0000000000..0a9a54e4c4 --- /dev/null +++ b/ets2panda/test/parser/ets/re_export/folderIndex2/index-expected.txt @@ -0,0 +1,323 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ETSReExportDeclaration", + "ets_import_declarations": { + "type": "ImportDeclaration", + "source": { + "type": "StringLiteral", + "value": "./key", + "loc": { + "start": { + "line": 16, + "column": 21 + }, + "end": { + "line": 16, + "column": 28 + } + } + }, + "specifiers": [ + { + "type": "ImportSpecifier", + "local": { + "type": "Identifier", + "name": "Test1", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 14 + } + } + }, + "imported": { + "type": "Identifier", + "name": "Test1", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 14 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 14 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 16, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ETSReExportDeclaration", + "ets_import_declarations": { + "type": "ImportDeclaration", + "source": { + "type": "StringLiteral", + "value": "./type", + "loc": { + "start": { + "line": 17, + "column": 21 + }, + "end": { + "line": 17, + "column": 29 + } + } + }, + "specifiers": [ + { + "type": "ImportSpecifier", + "local": { + "type": "Identifier", + "name": "int32", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 9 + }, + "end": { + "line": 17, + "column": 14 + } + } + }, + "imported": { + "type": "Identifier", + "name": "int32", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 9 + }, + "end": { + "line": 17, + "column": 14 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 9 + }, + "end": { + "line": 17, + "column": 14 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 8 + }, + "end": { + "line": 17, + "column": 30 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 18, + "column": 1 + } + } +} diff --git a/ets2panda/test/parser/ets/re_export/folderIndex2/index.ets b/ets2panda/test/parser/ets/re_export/folderIndex2/index.ets new file mode 100644 index 0000000000..f982d78aae --- /dev/null +++ b/ets2panda/test/parser/ets/re_export/folderIndex2/index.ets @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export {Test1} from "./key"; +export {int32} from "./type"; diff --git a/ets2panda/test/parser/ets/re_export/folderIndex2/key-expected.txt b/ets2panda/test/parser/ets/re_export/folderIndex2/key-expected.txt new file mode 100644 index 0000000000..7b3d527b0e --- /dev/null +++ b/ets2panda/test/parser/ets/re_export/folderIndex2/key-expected.txt @@ -0,0 +1,581 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "Test1", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 14 + }, + "end": { + "line": 16, + "column": 19 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "name", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 5 + }, + "end": { + "line": 17, + "column": 9 + } + } + }, + "accessibility": "public", + "static": false, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "String", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 10 + }, + "end": { + "line": 17, + "column": 16 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 10 + }, + "end": { + "line": 17, + "column": 17 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 10 + }, + "end": { + "line": 17, + "column": 17 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 5 + }, + "end": { + "line": 17, + "column": 17 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 2 + }, + "end": { + "line": 18, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 19 + }, + "end": { + "line": 18, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 18, + "column": 2 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "Test2", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 14 + }, + "end": { + "line": 19, + "column": 19 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "name", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 9 + } + } + }, + "accessibility": "public", + "static": false, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "String", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 10 + }, + "end": { + "line": 20, + "column": 16 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 10 + }, + "end": { + "line": 20, + "column": 17 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 10 + }, + "end": { + "line": 20, + "column": 17 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 17 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 2 + }, + "end": { + "line": 21, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 19 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 8 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 22, + "column": 1 + } + } +} diff --git a/ets2panda/test/parser/ets/re_export/folderIndex2/key.ets b/ets2panda/test/parser/ets/re_export/folderIndex2/key.ets new file mode 100644 index 0000000000..4bcccea396 --- /dev/null +++ b/ets2panda/test/parser/ets/re_export/folderIndex2/key.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export class Test1{ + name:String; +} +export class Test2{ + name:String; +} diff --git a/ets2panda/test/parser/ets/re_export/folderIndex2/type-expected.txt b/ets2panda/test/parser/ets/re_export/folderIndex2/type-expected.txt new file mode 100644 index 0000000000..ff5a6456fc --- /dev/null +++ b/ets2panda/test/parser/ets/re_export/folderIndex2/type-expected.txt @@ -0,0 +1,222 @@ +{ + "type": "Program", + "statements": [ + { + "type": "TSTypeAliasDeclaration", + "id": { + "type": "Identifier", + "name": "int32", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 13 + }, + "end": { + "line": 16, + "column": 18 + } + } + }, + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Number", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 21 + }, + "end": { + "line": 16, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 21 + }, + "end": { + "line": 17, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 21 + }, + "end": { + "line": 17, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 17, + "column": 1 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 17, + "column": 1 + } + } +} diff --git a/ets2panda/test/parser/ets/re_export/folderIndex2/type.ets b/ets2panda/test/parser/ets/re_export/folderIndex2/type.ets new file mode 100644 index 0000000000..12ea65fec5 --- /dev/null +++ b/ets2panda/test/parser/ets/re_export/folderIndex2/type.ets @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export type int32 = Number diff --git a/ets2panda/test/parser/ets/re_export/import_index_3-expected.txt b/ets2panda/test/parser/ets/re_export/import_index_3-expected.txt new file mode 100644 index 0000000000..accfb2f111 --- /dev/null +++ b/ets2panda/test/parser/ets/re_export/import_index_3-expected.txt @@ -0,0 +1,268 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ImportDeclaration", + "source": { + "type": "StringLiteral", + "value": "./folderIndex2", + "loc": { + "start": { + "line": 16, + "column": 28 + }, + "end": { + "line": 16, + "column": 44 + } + } + }, + "specifiers": [ + { + "type": "ImportSpecifier", + "local": { + "type": "Identifier", + "name": "Test1", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 14 + } + } + }, + "imported": { + "type": "Identifier", + "name": "Test1", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 14 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 14 + } + } + }, + { + "type": "ImportSpecifier", + "local": { + "type": "Identifier", + "name": "int32", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 16 + }, + "end": { + "line": 16, + "column": 21 + } + } + }, + "imported": { + "type": "Identifier", + "name": "int32", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 16 + }, + "end": { + "line": 16, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 16 + }, + "end": { + "line": 16, + "column": 21 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 16, + "column": 45 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 17, + "column": 1 + } + } +} diff --git a/ets2panda/test/parser/ets/re_export/import_index_3.ets b/ets2panda/test/parser/ets/re_export/import_index_3.ets new file mode 100644 index 0000000000..8c548f2eaf --- /dev/null +++ b/ets2panda/test/parser/ets/re_export/import_index_3.ets @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import {Test1, int32} from "./folderIndex2"; -- Gitee From 5768295eddb466462f9bcf4e73fd82f702f37884 Mon Sep 17 00:00:00 2001 From: Zelentsov Dmitry Date: Fri, 19 Apr 2024 17:14:14 +0300 Subject: [PATCH 07/22] Title: Preserve accumulator type invariant. Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/I9H58O?from=project-issue Tests: build, CI Signed-off-by: Zelentsov Dmitry --- ets2panda/checker/ETSAnalyzer.cpp | 12 +- ets2panda/checker/ETSchecker.h | 3 +- ets2panda/checker/ets/function.cpp | 9 +- ets2panda/checker/ets/helpers.cpp | 1 + ets2panda/checker/types/typeRelation.cpp | 9 +- ets2panda/checker/types/typeRelation.h | 12 +- ets2panda/compiler/core/ETSCompiler.cpp | 206 +++++++++++------- ets2panda/compiler/core/ETSGen.cpp | 32 ++- ets2panda/compiler/core/ETSGen.h | 4 +- .../topLevelStmts/globalDeclTransformer.cpp | 3 +- ets2panda/ir/ets/etsClassLiteral.h | 7 +- 11 files changed, 181 insertions(+), 117 deletions(-) diff --git a/ets2panda/checker/ETSAnalyzer.cpp b/ets2panda/checker/ETSAnalyzer.cpp index c52f3f3482..f88f0a752b 100644 --- a/ets2panda/checker/ETSAnalyzer.cpp +++ b/ets2panda/checker/ETSAnalyzer.cpp @@ -269,20 +269,22 @@ checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::ETSScript *node) const checker::Type *ETSAnalyzer::Check(ir::ETSClassLiteral *expr) const { ETSChecker *checker = GetETSChecker(); - checker->ThrowTypeError("Class literal is not yet supported.", expr->expr_->Start()); + auto *const literal = expr->Expr(); - expr->expr_->Check(checker); - auto *exprType = expr->expr_->GetType(checker); + checker->ThrowTypeError("Class literal is not yet supported.", literal->Start()); + + auto *exprType = literal->Check(checker); if (exprType->IsETSVoidType()) { - checker->ThrowTypeError("Invalid .class reference", expr->expr_->Start()); + checker->ThrowTypeError("Invalid .class reference", literal->Start()); } ArenaVector typeArgTypes(checker->Allocator()->Adapter()); typeArgTypes.push_back(exprType); // NOTE: Box it if it's a primitive type - checker::InstantiationContext ctx(checker, checker->GlobalBuiltinTypeType(), typeArgTypes, expr->range_.start); + checker::InstantiationContext ctx(checker, checker->GlobalBuiltinTypeType(), typeArgTypes, expr->Range().start); expr->SetTsType(ctx.Result()); + return expr->TsType(); } diff --git a/ets2panda/checker/ETSchecker.h b/ets2panda/checker/ETSchecker.h index c512dfb658..60f105cc52 100644 --- a/ets2panda/checker/ETSchecker.h +++ b/ets2panda/checker/ETSchecker.h @@ -385,7 +385,8 @@ public: void CreateLambdaObjectForFunctionReference(ir::AstNode *refNode, Signature *signature, ETSObjectType *functionalInterface); ir::AstNode *CreateLambdaImplicitField(varbinder::ClassScope *scope, const lexer::SourcePosition &pos); - ir::MethodDefinition *CreateLambdaImplicitCtor(const lexer::SourceRange &pos, bool isStaticReference); + ir::MethodDefinition *CreateLambdaImplicitCtor(const lexer::SourceRange &pos, bool isStaticReference, + ETSObjectType *functionalInterface); ir::MethodDefinition *CreateLambdaImplicitCtor(ArenaVector &properties); ir::MethodDefinition *CreateProxyMethodForLambda(ir::ClassDefinition *klass, ir::ArrowFunctionExpression *lambda, ArenaVector &captured, bool isStatic); diff --git a/ets2panda/checker/ets/function.cpp b/ets2panda/checker/ets/function.cpp index 3f127702f5..1dcdf79665 100644 --- a/ets2panda/checker/ets/function.cpp +++ b/ets2panda/checker/ets/function.cpp @@ -2438,6 +2438,7 @@ ir::Statement *ETSChecker::CreateLambdaCtorFieldInit(util::StringView name, varb auto *initializer = // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) AllocNode(leftHandSide, rightHandSide, lexer::TokenType::PUNCTUATOR_SUBSTITUTION); + initializer->SetTsType(var->TsType()); // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) return AllocNode(initializer); } @@ -2470,7 +2471,7 @@ void ETSChecker::CreateLambdaObjectForFunctionReference(ir::AstNode *refNode, Si // Create the synthetic constructor node, where we will initialize the synthetic field (if present) to the // instance object // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) - auto *ctor = CreateLambdaImplicitCtor(refNode->Range(), isStaticReference); + auto *ctor = CreateLambdaImplicitCtor(refNode->Range(), isStaticReference, functionalInterface); properties.push_back(ctor); // Create the template for the synthetic invoke function which will propagate the function call to the saved @@ -2534,7 +2535,8 @@ ir::AstNode *ETSChecker::CreateLambdaImplicitField(varbinder::ClassScope *scope, return field; } -ir::MethodDefinition *ETSChecker::CreateLambdaImplicitCtor(const lexer::SourceRange &pos, bool isStaticReference) +ir::MethodDefinition *ETSChecker::CreateLambdaImplicitCtor(const lexer::SourceRange &pos, bool isStaticReference, + ETSObjectType *functionalInterface) { ArenaVector params(Allocator()->Adapter()); ArenaVector statements(Allocator()->Adapter()); @@ -2542,6 +2544,9 @@ ir::MethodDefinition *ETSChecker::CreateLambdaImplicitCtor(const lexer::SourceRa // Create the parameters for the synthetic constructor // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto [funcParamScope, var] = CreateLambdaCtorImplicitParam(params, pos, isStaticReference); + if (var != nullptr && var->TsType() == nullptr) { + var->SetTsType(functionalInterface); + } // Create the scopes auto paramCtx = varbinder::LexicalScope::Enter(VarBinder(), funcParamScope, false); diff --git a/ets2panda/checker/ets/helpers.cpp b/ets2panda/checker/ets/helpers.cpp index 4f40f721aa..ace6b22d2f 100644 --- a/ets2panda/checker/ets/helpers.cpp +++ b/ets2panda/checker/ets/helpers.cpp @@ -2106,6 +2106,7 @@ void ETSChecker::GenerateGetterSetterBody(ArenaVector &stmts, A auto *assignmentExpression = AllocNode( memberExpression, paramExpression->Clone(Allocator(), nullptr), lexer::TokenType::PUNCTUATOR_SUBSTITUTION); + assignmentExpression->SetTsType(paramVar->TsType()); assignmentExpression->SetRange({field->Start(), field->End()}); // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) diff --git a/ets2panda/checker/types/typeRelation.cpp b/ets2panda/checker/types/typeRelation.cpp index 95b2f59266..bba03d35ed 100644 --- a/ets2panda/checker/types/typeRelation.cpp +++ b/ets2panda/checker/types/typeRelation.cpp @@ -51,9 +51,12 @@ RelationResult TypeRelation::CacheLookup(const Type *source, const Type *target, bool TypeRelation::IsIdenticalTo(Type *source, Type *target) { + if (source == nullptr || target == nullptr) { + return Result(false); + } + if (source == target) { - Result(true); - return true; + return Result(true); } result_ = CacheLookup(source, target, checker_->IdenticalResults(), RelationType::IDENTICAL); @@ -65,7 +68,7 @@ bool TypeRelation::IsIdenticalTo(Type *source, Type *target) checker_->IdenticalResults().cached.insert({{source->Id(), target->Id()}, {result_, RelationType::IDENTICAL}}); } - return result_ == RelationResult::TRUE; + return IsTrue(); } bool TypeRelation::IsCompatibleTo(Signature *source, Signature *target) diff --git a/ets2panda/checker/types/typeRelation.h b/ets2panda/checker/types/typeRelation.h index 264512afd4..0e1770639d 100644 --- a/ets2panda/checker/types/typeRelation.h +++ b/ets2panda/checker/types/typeRelation.h @@ -21,11 +21,6 @@ #include "util/ustring.h" #include "util/enumbitops.h" -#include "macros.h" - -#include -#include - namespace ark::es2panda::ir { class Expression; } // namespace ark::es2panda::ir @@ -275,6 +270,13 @@ public: instantiationRecursionMap_.erase(type); } + // NOTE: special overloading to be used mainly in ETSCompiler where types and nodes are 'const'. + // Unfortunately now we cannot have only a single method with 'const Types *' because it affects + // a lot of non-const references... :((( + bool IsIdenticalTo(Type const *source, Type const *target) + { + return IsIdenticalTo(const_cast(source), const_cast(target)); + } bool IsIdenticalTo(Type *source, Type *target); bool IsIdenticalTo(IndexInfo *source, IndexInfo *target); bool IsCompatibleTo(Signature *source, Signature *target); diff --git a/ets2panda/compiler/core/ETSCompiler.cpp b/ets2panda/compiler/core/ETSCompiler.cpp index e30ad376fb..370fcd4fa8 100644 --- a/ets2panda/compiler/core/ETSCompiler.cpp +++ b/ets2panda/compiler/core/ETSCompiler.cpp @@ -23,7 +23,6 @@ #include "compiler/function/functionBuilder.h" #include "checker/types/ets/etsDynamicFunctionType.h" #include "parser/ETSparser.h" -#include "programElement.h" namespace ark::es2panda::compiler { @@ -32,7 +31,6 @@ ETSGen *ETSCompiler::GetETSGen() const return static_cast(GetCodeGen()); } -// from as folder void ETSCompiler::Compile([[maybe_unused]] const ir::NamedType *node) const { UNREACHABLE(); @@ -42,7 +40,7 @@ void ETSCompiler::Compile([[maybe_unused]] const ir::PrefixAssertionExpression * { UNREACHABLE(); } -// from base folder + void ETSCompiler::Compile(const ir::CatchClause *st) const { ETSGen *etsg = GetETSGen(); @@ -121,6 +119,7 @@ void ETSCompiler::Compile(const ir::TemplateElement *expr) const { ETSGen *etsg = GetETSGen(); etsg->LoadAccumulatorString(expr, expr->Cooked()); + ASSERT(etsg->Checker()->Relation()->IsIdenticalTo(etsg->GetAccumulatorType(), expr->TsType())); } void ETSCompiler::Compile([[maybe_unused]] const ir::TSIndexSignature *node) const @@ -142,7 +141,7 @@ void ETSCompiler::Compile([[maybe_unused]] const ir::TSSignatureDeclaration *nod { UNREACHABLE(); } -// from ets folder + void ETSCompiler::Compile([[maybe_unused]] const ir::ETSScript *node) const { UNREACHABLE(); @@ -151,26 +150,31 @@ void ETSCompiler::Compile([[maybe_unused]] const ir::ETSScript *node) const void ETSCompiler::Compile(const ir::ETSClassLiteral *expr) const { ETSGen *etsg = GetETSGen(); - if (expr->expr_->TsType()->IsETSReferenceType()) { - expr->expr_->Compile(etsg); - etsg->GetType(expr, false); + + auto *literal = expr->Expr(); + auto *literalType = literal->TsType(); + + bool const isPrimitive = !literalType->IsETSReferenceType(); + if (!isPrimitive) { + literal->Compile(etsg); } else { - ASSERT(expr->expr_->TsType()->HasTypeFlag(checker::TypeFlag::ETS_PRIMITIVE)); - etsg->SetAccumulatorType(expr->expr_->TsType()); - etsg->GetType(expr, true); + ASSERT(literalType->HasTypeFlag(checker::TypeFlag::ETS_PRIMITIVE)); + etsg->SetAccumulatorType(literalType); } + + etsg->GetType(expr, isPrimitive); + ASSERT(etsg->Checker()->Relation()->IsIdenticalTo(etsg->GetAccumulatorType(), expr->TsType())); } void ETSCompiler::Compile(const ir::ETSFunctionType *node) const { ETSGen *etsg = GetETSGen(); - etsg->LoadAccumulatorNull(node, node->TsType()); + ASSERT(etsg->Checker()->Relation()->IsIdenticalTo(etsg->GetAccumulatorType(), node->TsType())); } -void ETSCompiler::Compile(const ir::ETSTuple *node) const +void ETSCompiler::Compile([[maybe_unused]] const ir::ETSTuple *node) const { - (void)node; UNREACHABLE(); } @@ -254,6 +258,8 @@ void ETSCompiler::Compile(const ir::ETSNewArrayInstanceExpression *expr) const etsg->SetVRegType(arr, expr->TsType()); etsg->LoadAccumulator(expr, arr); + + ASSERT(etsg->Checker()->Relation()->IsIdenticalTo(etsg->GetAccumulatorType(), expr->TsType())); } static std::pair LoadDynamicName(compiler::ETSGen *etsg, const ir::AstNode *node, @@ -347,7 +353,14 @@ void ETSCompiler::Compile([[maybe_unused]] const ir::ETSPackageDeclaration *st) void ETSCompiler::Compile(const ir::ETSParameterExpression *expr) const { ETSGen *etsg = GetETSGen(); - expr->Ident()->Identifier::Compile(etsg); + expr->Ident()->Compile(etsg); + + if (auto *const paramType = expr->TsType(); + !etsg->Checker()->AsETSChecker()->Relation()->IsIdenticalTo(paramType, etsg->GetAccumulatorType())) { + etsg->SetAccumulatorType(paramType); + } + + ASSERT(etsg->Checker()->Relation()->IsIdenticalTo(etsg->GetAccumulatorType(), expr->TsType())); } void ETSCompiler::Compile([[maybe_unused]] const ir::ETSPrimitiveType *node) const @@ -364,29 +377,28 @@ void ETSCompiler::Compile(const ir::ETSTypeReference *node) const { ETSGen *etsg = GetETSGen(); node->Part()->Compile(etsg); + ASSERT(etsg->Checker()->Relation()->IsIdenticalTo(etsg->GetAccumulatorType(), node->TsType())); } void ETSCompiler::Compile(const ir::ETSTypeReferencePart *node) const { ETSGen *etsg = GetETSGen(); node->Name()->Compile(etsg); + ASSERT(etsg->Checker()->Relation()->IsIdenticalTo(etsg->GetAccumulatorType(), node->TsType())); } -void ETSCompiler::Compile(const ir::ETSNullType *node) const +void ETSCompiler::Compile([[maybe_unused]] const ir::ETSNullType *node) const { - (void)node; UNREACHABLE(); } -void ETSCompiler::Compile(const ir::ETSUndefinedType *node) const +void ETSCompiler::Compile([[maybe_unused]] const ir::ETSUndefinedType *node) const { - (void)node; UNREACHABLE(); } -void ETSCompiler::Compile(const ir::ETSUnionType *node) const +void ETSCompiler::Compile([[maybe_unused]] const ir::ETSUnionType *node) const { - (void)node; UNREACHABLE(); } @@ -395,7 +407,7 @@ void ETSCompiler::Compile([[maybe_unused]] const ir::ETSWildcardType *node) cons ETSGen *etsg = GetETSGen(); etsg->Unimplemented(); } -// compile methods for EXPRESSIONS in alphabetical order + void ETSCompiler::Compile(const ir::ArrayExpression *expr) const { ETSGen *etsg = GetETSGen(); @@ -431,6 +443,7 @@ void ETSCompiler::Compile(const ir::ArrayExpression *expr) const } etsg->LoadAccumulator(expr, arr); + ASSERT(etsg->Checker()->Relation()->IsIdenticalTo(etsg->GetAccumulatorType(), expr->TsType())); } void ETSCompiler::Compile(const ir::ArrowFunctionExpression *expr) const @@ -460,15 +473,18 @@ void ETSCompiler::Compile(const ir::AssignmentExpression *expr) const ETSGen *etsg = GetETSGen(); // All other operations are handled in OpAssignmentLowering ASSERT(expr->OperatorType() == lexer::TokenType::PUNCTUATOR_SUBSTITUTION); + auto *const exprType = expr->TsType(); + compiler::RegScope rs(etsg); auto lref = compiler::ETSLReference::Create(etsg, expr->Left(), false); - auto ttctx = compiler::TargetTypeContext(etsg, expr->TsType()); + auto ttctx = compiler::TargetTypeContext(etsg, exprType); if (expr->Right()->IsNullLiteral()) { - etsg->LoadAccumulatorNull(expr, expr->Left()->TsType()); + etsg->LoadAccumulatorNull(expr, exprType); } else { expr->Right()->Compile(etsg); - etsg->ApplyConversion(expr->Right(), expr->TsType()); + etsg->ApplyConversion(expr->Right(), exprType); + etsg->SetAccumulatorType(exprType); } if (expr->Right()->TsType()->IsETSBigIntType()) { @@ -478,6 +494,9 @@ void ETSCompiler::Compile(const ir::AssignmentExpression *expr) const etsg->CreateBigIntObject(expr, value, Signatures::BUILTIN_BIGINT_CTOR_BIGINT); } + ASSERT(etsg->Checker()->Relation()->IsIdenticalTo(etsg->GetAccumulatorType(), exprType) || + etsg->Checker()->Relation()->IsIdenticalTo(etsg->GetAccumulatorType(), + etsg->Checker()->GlobalBuiltinJSValueType())); lref.SetValue(); } @@ -568,6 +587,8 @@ static void CompileLogical(compiler::ETSGen *etsg, const ir::BinaryExpression *e etsg->SetLabel(expr, endLabel); etsg->SetAccumulatorType(expr->TsType()); etsg->ApplyConversion(expr, expr->OperationType()); + + ASSERT(etsg->Checker()->Relation()->IsIdenticalTo(etsg->GetAccumulatorType(), expr->TsType())); } static void CompileInstanceof(compiler::ETSGen *etsg, const ir::BinaryExpression *expr) @@ -588,7 +609,7 @@ static void CompileInstanceof(compiler::ETSGen *etsg, const ir::BinaryExpression } else { etsg->IsInstance(expr, lhs, expr->Right()->TsType()); } - ASSERT(etsg->GetAccumulatorType() == expr->TsType()); + ASSERT(etsg->Checker()->Relation()->IsIdenticalTo(etsg->GetAccumulatorType(), expr->TsType())); } std::map &GetBigintSignatures() @@ -657,6 +678,7 @@ static bool CompileBigInt(compiler::ETSGen *etsg, const ir::BinaryExpression *ex break; } + ASSERT(etsg->Checker()->Relation()->IsIdenticalTo(etsg->GetAccumulatorType(), expr->TsType())); return true; } @@ -697,6 +719,7 @@ void ETSCompiler::Compile(const ir::BinaryExpression *expr) const } etsg->Binary(expr, expr->OperatorType(), lhs); + ASSERT(etsg->Checker()->Relation()->IsIdenticalTo(etsg->GetAccumulatorType(), expr->TsType())); } static void ConvertRestArguments(checker::ETSChecker *const checker, const ir::CallExpression *expr, @@ -901,18 +924,18 @@ void ETSCompiler::Compile(const ir::CallExpression *expr) const compiler::RegScope rs(etsg); compiler::VReg calleeReg = etsg->AllocReg(); - const auto isProxy = expr->Signature()->HasSignatureFlag(checker::SignatureFlags::PROXY); - if (isProxy && expr->Callee()->IsMemberExpression()) { + checker::Signature *signature = expr->Signature(); + + if (signature->HasSignatureFlag(checker::SignatureFlags::PROXY) && expr->Callee()->IsMemberExpression()) { if (IsSucceedCompilationProxyMemberExpr(expr)) { return; } } - bool isStatic = expr->Signature()->HasSignatureFlag(checker::SignatureFlags::STATIC); - bool isReference = expr->Signature()->HasSignatureFlag(checker::SignatureFlags::TYPE); + bool isStatic = signature->HasSignatureFlag(checker::SignatureFlags::STATIC); + bool isReference = signature->HasSignatureFlag(checker::SignatureFlags::TYPE); bool isDynamic = expr->Callee()->TsType()->HasTypeFlag(checker::TypeFlag::ETS_DYNAMIC_FLAG); - checker::Signature *signature = expr->Signature(); if (isReference) { signature = ConvertArgumentsForFunctionReference(etsg, expr); } @@ -944,6 +967,11 @@ void ETSCompiler::Compile(const ir::CallExpression *expr) const etsg->StoreAccumulator(expr, calleeReg); EmitCall(expr, calleeReg, isStatic, signature, isReference); } + + if (expr->HasBoxingUnboxingFlags(ir::BoxingUnboxingFlags::UNBOXING_FLAG | ir::BoxingUnboxingFlags::BOXING_FLAG)) { + etsg->ApplyConversion(expr, expr->TsType()); + } + etsg->SetAccumulatorType(expr->TsType()); } void ETSCompiler::Compile([[maybe_unused]] const ir::ChainExpression *expr) const @@ -1007,20 +1035,18 @@ void ETSCompiler::Compile(const ir::Identifier *expr) const ASSERT(expr->Variable() != nullptr); if (!expr->Variable()->HasFlag(varbinder::VariableFlags::TYPE_ALIAS)) { etsg->LoadVar(expr, expr->Variable()); - } else { - etsg->SetAccumulatorType(smartType); } + etsg->SetAccumulatorType(smartType); - // In case when smart cast type of identifier differs from common variable type - // set the accumulator type to the correct actual value and perform cast if required - if (!etsg->Checker()->AsETSChecker()->Relation()->IsIdenticalTo(const_cast(smartType), - expr->Variable()->TsType())) { - etsg->SetAccumulatorType(smartType); - if (smartType->IsETSReferenceType() && //! smartType->DefinitelyNotETSNullish() && - (expr->Parent() == nullptr || !expr->Parent()->IsTSAsExpression())) { + // In case when smart cast type of identifier differs from initial variable type perform cast if required + if (!etsg->Checker()->AsETSChecker()->Relation()->IsIdenticalTo(smartType, expr->Variable()->TsType())) { + if (smartType->IsETSReferenceType() && (expr->Parent() == nullptr || !expr->Parent()->IsTSAsExpression())) { etsg->CastToReftype(expr, smartType, false); + etsg->SetAccumulatorType(smartType); } } + + ASSERT(etsg->Checker()->Relation()->IsIdenticalTo(etsg->GetAccumulatorType(), smartType)); } void ETSCompiler::Compile([[maybe_unused]] const ir::ImportExpression *expr) const @@ -1041,6 +1067,8 @@ bool ETSCompiler::CompileComputed(compiler::ETSGen *etsg, const ir::MemberExpres compiler::VReg objReg = etsg->AllocReg(); etsg->StoreAccumulator(expr, objReg); + auto pttctx = compiler::TargetTypeContext(etsg, expr->Property()->TsType()); + etsg->CompileAndCheck(expr->Property()); etsg->ApplyConversion(expr->Property(), expr->Property()->TsType()); @@ -1054,6 +1082,8 @@ bool ETSCompiler::CompileComputed(compiler::ETSGen *etsg, const ir::MemberExpres etsg->GuardUncheckedType(expr, expr->UncheckedType(), expr->TsType()); etsg->ApplyConversion(expr); + + ASSERT(etsg->Checker()->Relation()->IsIdenticalTo(etsg->GetAccumulatorType(), expr->TsType())); return true; } @@ -1108,6 +1138,8 @@ void ETSCompiler::Compile(const ir::MemberExpression *expr) const etsg->LoadProperty(expr, expr->TsType(), objReg, fullName); } etsg->GuardUncheckedType(expr, expr->UncheckedType(), expr->TsType()); + + ASSERT(etsg->Checker()->Relation()->IsIdenticalTo(etsg->GetAccumulatorType(), expr->TsType())); } bool ETSCompiler::HandleLambdaObject(const ir::MemberExpression *expr, ETSGen *etsg) const @@ -1174,6 +1206,8 @@ bool ETSCompiler::HandleStaticProperties(const ir::MemberExpression *expr, ETSGe util::StringView fullName = etsg->FormClassPropReference(expr->Object()->TsType()->AsETSObjectType(), propName); etsg->LoadStaticProperty(expr, expr->TsType(), fullName); + + ASSERT(etsg->Checker()->Relation()->IsIdenticalTo(etsg->GetAccumulatorType(), expr->TsType())); return true; } return false; @@ -1228,6 +1262,7 @@ void ETSCompiler::Compile(const ir::ObjectExpression *expr) const } etsg->LoadAccumulator(expr, objReg); + ASSERT(etsg->Checker()->Relation()->IsIdenticalTo(etsg->GetAccumulatorType(), expr->TsType())); } void ETSCompiler::Compile([[maybe_unused]] const ir::OmittedExpression *expr) const @@ -1253,6 +1288,7 @@ void ETSCompiler::Compile(const ir::SuperExpression *expr) const ETSGen *etsg = GetETSGen(); etsg->LoadThis(expr); etsg->SetAccumulatorType(etsg->GetAccumulatorType()->AsETSObjectType()->SuperType()); + ASSERT(etsg->Checker()->Relation()->IsIdenticalTo(etsg->GetAccumulatorType(), expr->TsType())); } void ETSCompiler::Compile([[maybe_unused]] const ir::TaggedTemplateExpression *expr) const @@ -1264,12 +1300,14 @@ void ETSCompiler::Compile(const ir::TemplateLiteral *expr) const { ETSGen *etsg = GetETSGen(); etsg->BuildTemplateString(expr); + ASSERT(etsg->Checker()->Relation()->IsIdenticalTo(etsg->GetAccumulatorType(), expr->TsType())); } void ETSCompiler::Compile(const ir::ThisExpression *expr) const { ETSGen *etsg = GetETSGen(); etsg->LoadThis(expr); + ASSERT(etsg->Checker()->Relation()->IsIdenticalTo(etsg->GetAccumulatorType(), expr->TsType())); } void ETSCompiler::Compile([[maybe_unused]] const ir::TypeofExpression *expr) const @@ -1312,17 +1350,17 @@ void ETSCompiler::Compile(const ir::UnaryExpression *expr) const { ETSGen *etsg = GetETSGen(); auto ttctx = compiler::TargetTypeContext(etsg, expr->TsType()); + if (!etsg->TryLoadConstantExpression(expr->Argument())) { expr->Argument()->Compile(etsg); } etsg->ApplyConversion(expr->Argument(), nullptr); - - if (expr->OperatorType() == lexer::TokenType::PUNCTUATOR_TILDE) { - etsg->ApplyCast(expr->Argument(), expr->TsType()); - } + etsg->ApplyCast(expr->Argument(), expr->TsType()); etsg->Unary(expr, expr->OperatorType()); + + ASSERT(etsg->Checker()->Relation()->IsIdenticalTo(etsg->GetAccumulatorType(), expr->TsType())); } void ETSCompiler::Compile(const ir::UpdateExpression *expr) const @@ -1378,16 +1416,22 @@ void ETSCompiler::Compile(const ir::UpdateExpression *expr) const expr->Argument()->SetBoxingUnboxingFlags(argumentBoxingFlags); etsg->ApplyConversion(expr->Argument(), expr->Argument()->TsType()); + ASSERT(etsg->Checker()->Relation()->IsIdenticalTo(etsg->GetAccumulatorType(), expr->Argument()->TsType())); + lref.SetValue(); etsg->LoadAccumulator(expr->Argument(), originalValueReg); + if (expr->HasBoxingUnboxingFlags(ir::BoxingUnboxingFlags::UNBOXING_FLAG | ir::BoxingUnboxingFlags::BOXING_FLAG)) { + etsg->ApplyConversion(expr, expr->TsType()); + } + ASSERT(etsg->Checker()->Relation()->IsIdenticalTo(etsg->GetAccumulatorType(), expr->TsType())); } void ETSCompiler::Compile([[maybe_unused]] const ir::YieldExpression *expr) const { UNREACHABLE(); } -// compile methods for LITERAL EXPRESSIONS in alphabetical order + void ETSCompiler::Compile([[maybe_unused]] const ir::BigIntLiteral *expr) const { ETSGen *etsg = GetETSGen(); @@ -1397,58 +1441,54 @@ void ETSCompiler::Compile([[maybe_unused]] const ir::BigIntLiteral *expr) const const compiler::VReg value = etsg->AllocReg(); etsg->StoreAccumulator(expr, value); etsg->CreateBigIntObject(expr, value); + ASSERT(etsg->Checker()->Relation()->IsIdenticalTo(etsg->GetAccumulatorType(), expr->TsType())); } void ETSCompiler::Compile(const ir::BooleanLiteral *expr) const { ETSGen *etsg = GetETSGen(); etsg->LoadAccumulatorBoolean(expr, expr->Value()); + ASSERT(etsg->Checker()->Relation()->IsIdenticalTo(etsg->GetAccumulatorType(), expr->TsType())); } void ETSCompiler::Compile(const ir::CharLiteral *expr) const { ETSGen *etsg = GetETSGen(); etsg->LoadAccumulatorChar(expr, expr->Char()); + ASSERT(etsg->Checker()->Relation()->IsIdenticalTo(etsg->GetAccumulatorType(), expr->TsType())); } void ETSCompiler::Compile(const ir::NullLiteral *expr) const { ETSGen *etsg = GetETSGen(); etsg->LoadAccumulatorNull(expr, expr->TsType()); + ASSERT(etsg->Checker()->Relation()->IsIdenticalTo(etsg->GetAccumulatorType(), expr->TsType())); } void ETSCompiler::Compile(const ir::NumberLiteral *expr) const { ETSGen *etsg = GetETSGen(); auto ttctx = compiler::TargetTypeContext(etsg, expr->TsType()); + if (expr->Number().IsInt()) { if (util::Helpers::IsTargetFitInSourceRange( expr->Number().GetInt())) { etsg->LoadAccumulatorByte(expr, static_cast(expr->Number().GetInt())); - return; - } - - if (util::Helpers::IsTargetFitInSourceRange( - expr->Number().GetInt())) { + } else if (util::Helpers::IsTargetFitInSourceRange( + expr->Number().GetInt())) { etsg->LoadAccumulatorShort(expr, static_cast(expr->Number().GetInt())); - return; + } else { + etsg->LoadAccumulatorInt(expr, static_cast(expr->Number().GetInt())); } - - etsg->LoadAccumulatorInt(expr, static_cast(expr->Number().GetInt())); - return; - } - - if (expr->Number().IsLong()) { + } else if (expr->Number().IsLong()) { etsg->LoadAccumulatorWideInt(expr, expr->Number().GetLong()); - return; - } - - if (expr->Number().IsFloat()) { + } else if (expr->Number().IsFloat()) { etsg->LoadAccumulatorFloat(expr, expr->Number().GetFloat()); - return; + } else { + etsg->LoadAccumulatorDouble(expr, expr->Number().GetDouble()); } - etsg->LoadAccumulatorDouble(expr, expr->Number().GetDouble()); + ASSERT(etsg->Checker()->Relation()->IsIdenticalTo(etsg->GetAccumulatorType(), expr->TsType())); } void ETSCompiler::Compile([[maybe_unused]] const ir::RegExpLiteral *expr) const @@ -1463,13 +1503,11 @@ void ETSCompiler::Compile(const ir::StringLiteral *expr) const etsg->SetAccumulatorType(expr->TsType()); } -void ETSCompiler::Compile(const ir::UndefinedLiteral *expr) const +void ETSCompiler::Compile([[maybe_unused]] const ir::UndefinedLiteral *expr) const { - (void)expr; UNREACHABLE(); } -// compile methods for MODULE-related nodes in alphabetical order void ETSCompiler::Compile([[maybe_unused]] const ir::ExportAllDeclaration *st) const { UNREACHABLE(); @@ -1528,7 +1566,7 @@ static void ThrowError(compiler::ETSGen *const etsg, const ir::AssertStatement * etsg->CallThisStatic1(st, assertionError, compiler::Signatures::BUILTIN_ASSERTION_ERROR_CTOR, message); etsg->EmitThrow(st, assertionError); } -// compile methods for STATEMENTS in alphabetical order + void ETSCompiler::Compile(const ir::AssertStatement *st) const { ETSGen *etsg = GetETSGen(); @@ -1970,7 +2008,7 @@ void ETSCompiler::Compile(const ir::WhileStatement *st) const ETSGen *etsg = GetETSGen(); CompileImpl(st, etsg); } -// from ts folder + void ETSCompiler::Compile([[maybe_unused]] const ir::TSAnyKeyword *node) const { UNREACHABLE(); @@ -1979,7 +2017,6 @@ void ETSCompiler::Compile([[maybe_unused]] const ir::TSAnyKeyword *node) const void ETSCompiler::Compile(const ir::TSArrayType *node) const { ETSGen *etsg = GetETSGen(); - etsg->LoadAccumulatorNull(node, node->TsType()); } @@ -2127,6 +2164,7 @@ void ETSCompiler::Compile(const ir::TSAsExpression *expr) const } CompileCast(expr); + ASSERT(etsg->Checker()->Relation()->IsIdenticalTo(etsg->GetAccumulatorType(), targetType)); } void ETSCompiler::Compile([[maybe_unused]] const ir::TSBigintKeyword *node) const @@ -2248,27 +2286,27 @@ void ETSCompiler::Compile(const ir::TSNonNullExpression *expr) const expr->Expr()->Compile(etsg); - if (etsg->GetAccumulatorType()->DefinitelyNotETSNullish()) { - return; - } + if (!etsg->GetAccumulatorType()->DefinitelyNotETSNullish()) { + if (etsg->GetAccumulatorType()->DefinitelyETSNullish()) { + etsg->EmitNullishException(expr); + return; + } - if (etsg->GetAccumulatorType()->DefinitelyETSNullish()) { - etsg->EmitNullishException(expr); - return; - } + auto arg = etsg->AllocReg(); + etsg->StoreAccumulator(expr, arg); + etsg->LoadAccumulator(expr, arg); - auto arg = etsg->AllocReg(); - etsg->StoreAccumulator(expr, arg); - etsg->LoadAccumulator(expr, arg); + auto endLabel = etsg->AllocLabel(); - auto endLabel = etsg->AllocLabel(); + etsg->BranchIfNotNullish(expr, endLabel); + etsg->EmitNullishException(expr); - etsg->BranchIfNotNullish(expr, endLabel); - etsg->EmitNullishException(expr); + etsg->SetLabel(expr, endLabel); + etsg->LoadAccumulator(expr, arg); + etsg->AssumeNonNullish(expr, expr->OriginalType()); + } - etsg->SetLabel(expr, endLabel); - etsg->LoadAccumulator(expr, arg); - etsg->AssumeNonNullish(expr, expr->OriginalType()); + ASSERT(etsg->Checker()->Relation()->IsIdenticalTo(etsg->GetAccumulatorType(), expr->OriginalType())); } void ETSCompiler::Compile([[maybe_unused]] const ir::TSNullKeyword *node) const diff --git a/ets2panda/compiler/core/ETSGen.cpp b/ets2panda/compiler/core/ETSGen.cpp index 8d0eee7393..c72da309ce 100644 --- a/ets2panda/compiler/core/ETSGen.cpp +++ b/ets2panda/compiler/core/ETSGen.cpp @@ -545,7 +545,7 @@ void ETSGen::StorePropertyDynamic(const ir::AstNode *node, const checker::Type * // Set property by name Ra().Emit(node, methodName, objReg, propNameReg, propValueReg, dummyReg_); - SetAccumulatorType(nullptr); + SetAccumulatorType(Checker()->GlobalBuiltinJSValueType()); } void ETSGen::LoadPropertyDynamic(const ir::AstNode *node, const checker::Type *propType, VReg objReg, @@ -1042,9 +1042,8 @@ void ETSGen::GuardUncheckedType(const ir::AstNode *node, const checker::Type *un if (unchecked != nullptr) { SetAccumulatorType(unchecked); CheckedReferenceNarrowing(node, Checker()->MaybePromotedBuiltinType(target)); - } else { - SetAccumulatorType(target); } + SetAccumulatorType(target); } void ETSGen::EmitFailedTypeCastException(const ir::AstNode *node, const VReg src, checker::Type const *target) @@ -1282,6 +1281,9 @@ void ETSGen::EmitUnboxedCall(const ir::AstNode *node, std::string_view signature Ra().Emit(node, signatureFlag, dummyReg_, 0); SetAccumulatorType(targetType); + if (node->IsExpression()) { + const_cast(node->AsExpression())->SetTsType(const_cast(targetType)); + } } void ETSGen::EmitUnboxingConversion(const ir::AstNode *node) @@ -1345,51 +1347,57 @@ void ETSGen::EmitBoxingConversion(const ir::AstNode *node) RegScope rs(this); ApplyCastToBoxingFlags(node, boxingFlag); + checker::Type *boxedType; switch (boxingFlag) { case ir::BoxingUnboxingFlags::BOX_TO_BOOLEAN: { Ra().Emit(node, Signatures::BUILTIN_BOOLEAN_VALUE_OF, dummyReg_, 0); - SetAccumulatorType(Checker()->GetGlobalTypesHolder()->GlobalETSBooleanBuiltinType()); + boxedType = Checker()->GetGlobalTypesHolder()->GlobalETSBooleanBuiltinType(); break; } case ir::BoxingUnboxingFlags::BOX_TO_BYTE: { Ra().Emit(node, Signatures::BUILTIN_BYTE_VALUE_OF, dummyReg_, 0); - SetAccumulatorType(Checker()->GetGlobalTypesHolder()->GlobalByteBuiltinType()); + boxedType = Checker()->GetGlobalTypesHolder()->GlobalByteBuiltinType(); break; } case ir::BoxingUnboxingFlags::BOX_TO_CHAR: { Ra().Emit(node, Signatures::BUILTIN_CHAR_VALUE_OF, dummyReg_, 0); - SetAccumulatorType(Checker()->GetGlobalTypesHolder()->GlobalCharBuiltinType()); + boxedType = Checker()->GetGlobalTypesHolder()->GlobalCharBuiltinType(); break; } case ir::BoxingUnboxingFlags::BOX_TO_SHORT: { Ra().Emit(node, Signatures::BUILTIN_SHORT_VALUE_OF, dummyReg_, 0); - SetAccumulatorType(Checker()->GetGlobalTypesHolder()->GlobalShortBuiltinType()); + boxedType = Checker()->GetGlobalTypesHolder()->GlobalShortBuiltinType(); break; } case ir::BoxingUnboxingFlags::BOX_TO_INT: { Ra().Emit(node, Signatures::BUILTIN_INT_VALUE_OF, dummyReg_, 0); - SetAccumulatorType(Checker()->GetGlobalTypesHolder()->GlobalIntegerBuiltinType()); + boxedType = Checker()->GetGlobalTypesHolder()->GlobalIntegerBuiltinType(); break; } case ir::BoxingUnboxingFlags::BOX_TO_LONG: { Ra().Emit(node, Signatures::BUILTIN_LONG_VALUE_OF, dummyReg_, 0); - SetAccumulatorType(Checker()->GetGlobalTypesHolder()->GlobalLongBuiltinType()); + boxedType = Checker()->GetGlobalTypesHolder()->GlobalLongBuiltinType(); break; } case ir::BoxingUnboxingFlags::BOX_TO_FLOAT: { Ra().Emit(node, Signatures::BUILTIN_FLOAT_VALUE_OF, dummyReg_, 0); - SetAccumulatorType(Checker()->GetGlobalTypesHolder()->GlobalFloatBuiltinType()); + boxedType = Checker()->GetGlobalTypesHolder()->GlobalFloatBuiltinType(); break; } case ir::BoxingUnboxingFlags::BOX_TO_DOUBLE: { Ra().Emit(node, Signatures::BUILTIN_DOUBLE_VALUE_OF, dummyReg_, 0); - SetAccumulatorType(Checker()->GetGlobalTypesHolder()->GlobalDoubleBuiltinType()); + boxedType = Checker()->GetGlobalTypesHolder()->GlobalDoubleBuiltinType(); break; } default: UNREACHABLE(); } + + SetAccumulatorType(boxedType); + if (node->IsExpression()) { + const_cast(node->AsExpression())->SetTsType(boxedType); + } } void ETSGen::SwapBinaryOpArgs(const ir::AstNode *const node, const VReg lhs) @@ -1512,6 +1520,7 @@ void ETSGen::EmitLocalBoxSet(ir::AstNode const *node, varbinder::LocalVariable * Ra().Emit(node, Signatures::BUILTIN_BOX_SET, vreg, 1); break; } + SetAccumulatorType(Checker()->GetGlobalTypesHolder()->GlobalVoidType()); } @@ -1560,6 +1569,7 @@ void ETSGen::EmitPropertyBoxSet(const ir::AstNode *const node, const checker::Ty Ra().Emit(node, Signatures::BUILTIN_BOX_SET, field, 1); break; } + SetAccumulatorType(Checker()->GetGlobalTypesHolder()->GlobalVoidType()); } diff --git a/ets2panda/compiler/core/ETSGen.h b/ets2panda/compiler/core/ETSGen.h index 1fc18ebe3b..1f76640253 100644 --- a/ets2panda/compiler/core/ETSGen.h +++ b/ets2panda/compiler/core/ETSGen.h @@ -339,7 +339,7 @@ public: { Sa().Emit(node, value ? 1 : 0); SetAccumulatorType(Checker()->GlobalETSBooleanType()); - ApplyConversion(node, nullptr); + ApplyConversion(node, Checker()->GlobalETSBooleanType()); } void LoadAccumulatorString(const ir::AstNode *node, util::StringView str) @@ -374,7 +374,7 @@ public: { Sa().Emit(node, value); SetAccumulatorType(Checker()->GlobalCharType()); - ApplyConversion(node); + ApplyConversion(node, Checker()->GlobalCharType()); } void LoadAccumulatorDynamicModule(const ir::AstNode *node, const ir::ETSImportDeclaration *import); diff --git a/ets2panda/compiler/lowering/ets/topLevelStmts/globalDeclTransformer.cpp b/ets2panda/compiler/lowering/ets/topLevelStmts/globalDeclTransformer.cpp index 6f463c7f71..1e9029342d 100644 --- a/ets2panda/compiler/lowering/ets/topLevelStmts/globalDeclTransformer.cpp +++ b/ets2panda/compiler/lowering/ets/topLevelStmts/globalDeclTransformer.cpp @@ -94,6 +94,7 @@ ir::ExpressionStatement *GlobalDeclTransformer::InitTopLevelProperty(ir::ClassPr allocator_, ident, initializer->Clone(allocator_, nullptr)->AsExpression(), lexer::TokenType::PUNCTUATOR_SUBSTITUTION); assignmentExpression->SetRange({ident->Start(), initializer->End()}); + assignmentExpression->SetTsType(initializer->TsType()); auto expressionStatement = util::NodeAllocator::Alloc(allocator_, assignmentExpression); @@ -122,4 +123,4 @@ void GlobalDeclTransformer::HandleNode(ir::AstNode *node) } } -} // namespace ark::es2panda::compiler \ No newline at end of file +} // namespace ark::es2panda::compiler diff --git a/ets2panda/ir/ets/etsClassLiteral.h b/ets2panda/ir/ets/etsClassLiteral.h index de38063141..1307f1a305 100644 --- a/ets2panda/ir/ets/etsClassLiteral.h +++ b/ets2panda/ir/ets/etsClassLiteral.h @@ -40,9 +40,10 @@ public: [[nodiscard]] ETSClassLiteral *Clone(ArenaAllocator *allocator, AstNode *parent) override; - // NOTE (csabahurton): these friend relationships can be removed once there are getters for private fields - friend class checker::ETSAnalyzer; - friend class compiler::ETSCompiler; + [[nodiscard]] ir::TypeNode *Expr() const noexcept + { + return expr_; + } void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; -- Gitee From c718b8165d48b237420c79fe03810bb7ff2540d4 Mon Sep 17 00:00:00 2001 From: Pogosov Date: Wed, 3 Apr 2024 15:29:36 +0300 Subject: [PATCH 08/22] add support for global constants Issue: https://gitee.com/openharmony/arkcompiler_runtime_core/issues/I9NXJB?from=project-issue Testing: all CI tests passed. Results are availible in gg watcher. Signed-off-by: Pogosov --- ets2panda/declgen_ets2ts/declgenEts2Ts.cpp | 28 ++++++++++++++++++++-- ets2panda/declgen_ets2ts/declgenEts2Ts.h | 1 + 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/ets2panda/declgen_ets2ts/declgenEts2Ts.cpp b/ets2panda/declgen_ets2ts/declgenEts2Ts.cpp index d46d1c6fac..bbea99ee9d 100644 --- a/ets2panda/declgen_ets2ts/declgenEts2Ts.cpp +++ b/ets2panda/declgen_ets2ts/declgenEts2Ts.cpp @@ -66,6 +66,8 @@ void TSDeclGen::Generate() license << " */\n\n"; Out(license.str()); Out("declare const exports: any;"); + OutEndl(); + Out("let ETSGLOBAL: any = (globalThis as any).Panda.getClass('LETSGLOBAL;');"); OutEndl(2U); for (auto *globalStatement : program_->Ast()->Statements()) { @@ -556,8 +558,7 @@ void TSDeclGen::GenMethodDeclaration(const ir::MethodDefinition *methodDef) OutEndl(); if (state_.inGlobalClass) { - Out("(", methodName, " as any) = (globalThis as any).Panda.getFunction('", state_.currentClassDescriptor, - "', '", methodName, "');"); + Out("(", methodName, " as any) = ETSGLOBAL.", methodName, ";"); OutEndl(); GenExports(methodName); if (methodName == compiler::Signatures::INIT_METHOD) { @@ -570,6 +571,7 @@ void TSDeclGen::GenMethodDeclaration(const ir::MethodDefinition *methodDef) void TSDeclGen::GenPropDeclaration(const ir::ClassProperty *classProp) { if (state_.inGlobalClass) { + GenGlobalVarDeclaration(classProp); return; } @@ -589,6 +591,28 @@ void TSDeclGen::GenPropDeclaration(const ir::ClassProperty *classProp) OutEndl(); } +void TSDeclGen::GenGlobalVarDeclaration(const ir::ClassProperty *globalVar) +{ + if (!globalVar->IsExported() && !globalVar->IsDefaultExported()) { + return; + } + + const auto varName = GetKeyName(globalVar->Key()); + DebugPrint("GenGlobalVarDeclaration: " + varName); + if (!globalVar->IsConst()) { + Warning("Not constant global variables are not supported, variable \"" + varName + "\" was skipped"); + return; + } + + Out("const ", varName, ": "); + GenType(globalVar->TsType()); + Out(" = ETSGLOBAL.", varName, ';'); + OutEndl(); + + GenExports(varName); + OutEndl(); +} + bool GenerateTsDeclarations(checker::ETSChecker *checker, const ark::es2panda::parser::Program *program, const std::string &outPath) { diff --git a/ets2panda/declgen_ets2ts/declgenEts2Ts.h b/ets2panda/declgen_ets2ts/declgenEts2Ts.h index 1934c19cab..984f1cd316 100644 --- a/ets2panda/declgen_ets2ts/declgenEts2Ts.h +++ b/ets2panda/declgen_ets2ts/declgenEts2Ts.h @@ -61,6 +61,7 @@ private: void GenClassDeclaration(const ir::ClassDeclaration *classDecl); void GenMethodDeclaration(const ir::MethodDefinition *methodDef); void GenPropDeclaration(const ir::ClassProperty *classProp); + void GenGlobalVarDeclaration(const ir::ClassProperty *globalVar); void GenLiteral(const ir::Literal *literal); template -- Gitee From bd3f68dd5555c5ed0affa6496eb350f3ca1cd81f Mon Sep 17 00:00:00 2001 From: Aleksandr Semenov Date: Sun, 28 Apr 2024 11:28:17 +0300 Subject: [PATCH 09/22] Split and refactoring structure of ASTVerifier tests Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/I9KE9W Testing: All required pre-merge tests has passed. Results are availible in ggwatcher Signed-off-by: Aleksandr Semenov --- ets2panda/test/CMakeLists.txt | 60 +- ets2panda/test/tsconfig/CMakeLists.txt | 4 + ets2panda/test/unit/CMakeLists.txt | 43 + ets2panda/test/unit/dynamic/CMakeLists.txt | 16 + ets2panda/test/unit/lowerings/CMakeLists.txt | 20 + ets2panda/test/unit/public/CMakeLists.txt | 60 + ...ifier_private_access_negative_test_1_4.cpp | 174 +++ ...ifier_private_access_negative_test_5_7.cpp | 179 +++ ...e_protected_public_access_correct_test.cpp | 82 ++ ...verifier_protected_access_correct_test.cpp | 57 + ...ier_protected_access_negative_test_1_3.cpp | 137 +++ ...ier_protected_access_negative_test_4_6.cpp | 180 +++ .../unit/public/ast_verifier_short_test.cpp | 265 +++++ .../test/unit/public/ast_verifier_test.cpp | 1004 ----------------- .../test/unit/public/ast_verifier_test.h | 77 ++ .../test/unit/rest_parameter_flag_test.cpp | 2 +- 16 files changed, 1304 insertions(+), 1056 deletions(-) create mode 100644 ets2panda/test/unit/CMakeLists.txt create mode 100644 ets2panda/test/unit/dynamic/CMakeLists.txt create mode 100644 ets2panda/test/unit/lowerings/CMakeLists.txt create mode 100644 ets2panda/test/unit/public/CMakeLists.txt create mode 100644 ets2panda/test/unit/public/ast_verifier_private_access_negative_test_1_4.cpp create mode 100644 ets2panda/test/unit/public/ast_verifier_private_access_negative_test_5_7.cpp create mode 100644 ets2panda/test/unit/public/ast_verifier_private_protected_public_access_correct_test.cpp create mode 100644 ets2panda/test/unit/public/ast_verifier_protected_access_correct_test.cpp create mode 100644 ets2panda/test/unit/public/ast_verifier_protected_access_negative_test_1_3.cpp create mode 100644 ets2panda/test/unit/public/ast_verifier_protected_access_negative_test_4_6.cpp create mode 100644 ets2panda/test/unit/public/ast_verifier_short_test.cpp delete mode 100644 ets2panda/test/unit/public/ast_verifier_test.cpp create mode 100644 ets2panda/test/unit/public/ast_verifier_test.h diff --git a/ets2panda/test/CMakeLists.txt b/ets2panda/test/CMakeLists.txt index 83235a3e2e..74efc75be0 100644 --- a/ets2panda/test/CMakeLists.txt +++ b/ets2panda/test/CMakeLists.txt @@ -42,11 +42,16 @@ function(ets2panda_add_gtest TARGET) ) MESSAGE(${TARGET}) + panda_add_gtest( NAME ${TARGET} - SOURCES ${ARG_CPP_SOURCES} + SOURCES + ${ARG_CPP_SOURCES} LIBRARIES - es2panda-public es2panda-lib arkassembler arkbytecodeopt + es2panda-public + es2panda-lib + arkassembler + arkbytecodeopt INCLUDE_DIRS ${ES2PANDA_PATH} ${ES2PANDA_BINARY_ROOT} @@ -64,53 +69,6 @@ if(PANDA_WITH_ETS) endif() endif() -if(PANDA_REGRESSION_TESTS) - panda_add_gtest( - NAME es2panda_public_test - SOURCES - unit/public/es2panda_public_test.cpp - LIBRARIES - es2panda-public es2panda-lib arkassembler arkbytecodeopt - INCLUDE_DIRS - ${ES2PANDA_ROOT} - SANITIZERS - ${PANDA_SANITIZERS_LIST} - ) - - panda_add_library(e2p_test_plugin SHARED unit/public/e2p_test_plugin.c) - panda_target_include_directories(e2p_test_plugin PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/..") - panda_target_link_libraries(e2p_test_plugin es2panda-public) - - add_custom_target(es2panda-plugin-test - COMMENT "Test es2panda plugin functionality" - COMMAND ${CMAKE_COMMAND} -E env - LD_LIBRARY_PATH=${CMAKE_LIBRARY_OUTPUT_DIRECTORY} ${PANDA_RUN_PREFIX} $ --plugins=e2p_test_plugin - "${CMAKE_CURRENT_SOURCE_DIR}/unit/public/t.ets" > "${CMAKE_CURRENT_BINARY_DIR}/plugin_test.out" - COMMAND ${CMAKE_COMMAND} -E compare_files - "${CMAKE_CURRENT_BINARY_DIR}/plugin_test.out" "${CMAKE_CURRENT_SOURCE_DIR}/unit/public/plugin_test.expected.txt" - ) - add_dependencies(es2panda-plugin-test es2panda e2p_test_plugin) - add_dependencies(es2panda_tests es2panda-plugin-test) - - ets2panda_add_gtest(es2panda_dynamic_call_test CPP_SOURCES unit/dynamic/dynamic_call_test.cpp) - ets2panda_add_gtest(es2panda_astverifier_tests CPP_SOURCES unit/public/ast_verifier_test.cpp) - ets2panda_add_gtest(scopes_initialization_test CPP_SOURCES unit/lowerings/scopes_initialization.cpp) - ets2panda_add_gtest(es2panda_checker_tests CPP_SOURCES unit/checker_test.cpp) - ets2panda_add_gtest(es2panda_astdumper_tests CPP_SOURCES unit/ast_dumper_test.cpp) - ets2panda_add_gtest(es2panda_union_normalization_tests CPP_SOURCES unit/union_normalization_test.cpp) - - # NOTE: es2panda_rest_parameter_flag test runs a lot of time on qemu, so let's disable it - if (NOT PANDA_QEMU_BUILD) - panda_add_gtest( - NAME es2panda_rest_parameter_flag - SOURCES unit/rest_parameter_flag_test.cpp - LIBRARIES es2panda-public es2panda-lib arkassembler arkbytecodeopt - INCLUDE_DIRS ${ES2PANDA_PATH} ${ES2PANDA_BINARY_ROOT} - SANITIZERS ${PANDA_SANITIZERS_LIST} - ) - endif() - - add_subdirectory(tsconfig) -endif() - +add_subdirectory(tsconfig) add_subdirectory(options) +add_subdirectory(unit) diff --git a/ets2panda/test/tsconfig/CMakeLists.txt b/ets2panda/test/tsconfig/CMakeLists.txt index a4eaa7e6c2..9dc7525634 100644 --- a/ets2panda/test/tsconfig/CMakeLists.txt +++ b/ets2panda/test/tsconfig/CMakeLists.txt @@ -11,6 +11,10 @@ # See the License for the specific language governing permissions and # limitations under the License. +if(NOT PANDA_REGRESSION_TESTS) + return() +endif() + function(add_es2panda_tsconfig_test tsproject) set(TSPROJECT_TARGET_NAME es2panda-tsconfig-test-${tsproject}) add_custom_target(${TSPROJECT_TARGET_NAME} diff --git a/ets2panda/test/unit/CMakeLists.txt b/ets2panda/test/unit/CMakeLists.txt new file mode 100644 index 0000000000..4516e2a1f5 --- /dev/null +++ b/ets2panda/test/unit/CMakeLists.txt @@ -0,0 +1,43 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +if(NOT PANDA_REGRESSION_TESTS) + return() +endif() + +add_subdirectory(dynamic) +add_subdirectory(lowerings) +add_subdirectory(public) + +ets2panda_add_gtest(es2panda_astdumper_tests + CPP_SOURCES ast_dumper_test.cpp +) + +ets2panda_add_gtest(es2panda_union_normalization_tests + CPP_SOURCES union_normalization_test.cpp +) + +# NOTE: es2panda_rest_parameter_flag test runs a lot of time on qemu, so let's disable it +if (NOT PANDA_QEMU_BUILD) + ets2panda_add_gtest(es2panda_rest_parameter_flag + CPP_SOURCES rest_parameter_flag_test.cpp + ) +endif() + +if(NOT PANDA_WITH_ETS) + return() +endif() + +ets2panda_add_gtest(es2panda_checker_tests + CPP_SOURCES checker_test.cpp +) diff --git a/ets2panda/test/unit/dynamic/CMakeLists.txt b/ets2panda/test/unit/dynamic/CMakeLists.txt new file mode 100644 index 0000000000..bb987ef237 --- /dev/null +++ b/ets2panda/test/unit/dynamic/CMakeLists.txt @@ -0,0 +1,16 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +ets2panda_add_gtest(es2panda_dynamic_call_test + CPP_SOURCES dynamic_call_test.cpp +) diff --git a/ets2panda/test/unit/lowerings/CMakeLists.txt b/ets2panda/test/unit/lowerings/CMakeLists.txt new file mode 100644 index 0000000000..8ccede80dd --- /dev/null +++ b/ets2panda/test/unit/lowerings/CMakeLists.txt @@ -0,0 +1,20 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +if(NOT PANDA_WITH_ETS) + return() +endif() + +ets2panda_add_gtest(scopes_initialization_test + CPP_SOURCES scopes_initialization.cpp +) diff --git a/ets2panda/test/unit/public/CMakeLists.txt b/ets2panda/test/unit/public/CMakeLists.txt new file mode 100644 index 0000000000..1d43b31134 --- /dev/null +++ b/ets2panda/test/unit/public/CMakeLists.txt @@ -0,0 +1,60 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +ets2panda_add_gtest(es2panda_public_test + CPP_SOURCES es2panda_public_test.cpp +) + +ets2panda_add_gtest(ast_verifier_short_test + CPP_SOURCES ast_verifier_short_test.cpp +) + +ets2panda_add_gtest(ast_verifier_private_protected_public_access_correct_test + CPP_SOURCES ast_verifier_private_protected_public_access_correct_test.cpp +) + +ets2panda_add_gtest(ast_verifier_private_access_negative_test_1_4 + CPP_SOURCES ast_verifier_private_access_negative_test_1_4.cpp +) + +ets2panda_add_gtest(ast_verifier_private_access_negative_test_5_7 + CPP_SOURCES ast_verifier_private_access_negative_test_5_7.cpp +) + +ets2panda_add_gtest(ast_verifier_protected_access_correct_test + CPP_SOURCES ast_verifier_protected_access_correct_test.cpp +) + +ets2panda_add_gtest(ast_verifier_protected_access_negative_test_1_3 + CPP_SOURCES ast_verifier_protected_access_negative_test_1_3.cpp +) + +ets2panda_add_gtest(ast_verifier_protected_access_negative_test_4_6 + CPP_SOURCES ast_verifier_protected_access_negative_test_4_6.cpp +) + +panda_add_library(e2p_test_plugin SHARED e2p_test_plugin.c) +panda_target_include_directories(e2p_test_plugin PRIVATE "${ES2PANDA_PATH}") +panda_target_link_libraries(e2p_test_plugin es2panda-public) + +add_custom_target(es2panda-plugin-test + COMMENT "Test es2panda plugin functionality" + COMMAND ${CMAKE_COMMAND} -E env + LD_LIBRARY_PATH=${CMAKE_LIBRARY_OUTPUT_DIRECTORY} ${PANDA_RUN_PREFIX} $ --plugins=e2p_test_plugin + "${CMAKE_CURRENT_SOURCE_DIR}/t.ets" > "${CMAKE_CURRENT_BINARY_DIR}/plugin_test.out" + COMMAND ${CMAKE_COMMAND} -E compare_files + "${CMAKE_CURRENT_BINARY_DIR}/plugin_test.out" "${CMAKE_CURRENT_SOURCE_DIR}/plugin_test.expected.txt" +) + +add_dependencies(es2panda-plugin-test es2panda e2p_test_plugin) +add_dependencies(es2panda_tests es2panda-plugin-test) diff --git a/ets2panda/test/unit/public/ast_verifier_private_access_negative_test_1_4.cpp b/ets2panda/test/unit/public/ast_verifier_private_access_negative_test_1_4.cpp new file mode 100644 index 0000000000..14db5a0a64 --- /dev/null +++ b/ets2panda/test/unit/public/ast_verifier_private_access_negative_test_1_4.cpp @@ -0,0 +1,174 @@ +/** + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ast_verifier_test.h" +#include "checker/ETSchecker.h" + +using ark::es2panda::compiler::ast_verifier::ASTVerifier; +using ark::es2panda::compiler::ast_verifier::InvariantNameSet; +using ark::es2panda::ir::ETSScript; + +TEST_F(ASTVerifierTest, PrivateAccessTestNegative1) +{ + ASTVerifier verifier {Allocator()}; + + char const *text = R"( + class Base { + public a: int = 1; + } + class Derived extends Base { + public b: int = this.a; + } + )"; + es2panda_Context *ctx = impl_->CreateContextFromString(cfg_, text, "dummy.ets"); + impl_->ProceedToState(ctx, ES2PANDA_STATE_CHECKED); + ASSERT_EQ(impl_->ContextState(ctx), ES2PANDA_STATE_CHECKED); + + auto *ast = reinterpret_cast(impl_->ProgramAst(impl_->ContextProgram(ctx))); + + ast->AsETSScript() + ->Statements()[1] + ->AsClassDeclaration() + ->Definition() + ->AsClassDefinition() + ->Body()[0] + ->AsClassProperty() + ->AddModifier(ark::es2panda::ir::ModifierFlags::PRIVATE); + + InvariantNameSet checks; + checks.insert("ModifierAccessValidForAll"); + const auto &messages = verifier.Verify(ast, checks); + ASSERT_EQ(messages.size(), 1); + + ASSERT_NE(checks.find(messages[0].Invariant()), checks.end()); + + impl_->DestroyContext(ctx); +} + +TEST_F(ASTVerifierTest, PrivateAccessTestNegative2) +{ + ASTVerifier verifier {Allocator()}; + + char const *text = R"( + class Base { + public a: int = 1; + } + function main(): void { + let base: Base = new Base(); + let a = base.a; + } + )"; + es2panda_Context *ctx = impl_->CreateContextFromString(cfg_, text, "dummy.ets"); + impl_->ProceedToState(ctx, ES2PANDA_STATE_CHECKED); + ASSERT_EQ(impl_->ContextState(ctx), ES2PANDA_STATE_CHECKED); + + auto *ast = reinterpret_cast(impl_->ProgramAst(impl_->ContextProgram(ctx))); + + ast->AsETSScript() + ->Statements()[1] + ->AsClassDeclaration() + ->Definition() + ->AsClassDefinition() + ->Body()[0] + ->AsClassProperty() + ->AddModifier(ark::es2panda::ir::ModifierFlags::PRIVATE); + + InvariantNameSet checks; + checks.insert("ModifierAccessValidForAll"); + const auto &messages = verifier.Verify(ast, checks); + ASSERT_EQ(messages.size(), 1); + + ASSERT_NE(checks.find(messages[0].Invariant()), checks.end()); + + impl_->DestroyContext(ctx); +} + +TEST_F(ASTVerifierTest, PrivateAccessTestNegative3) +{ + ASTVerifier verifier {Allocator()}; + + char const *text = R"( + class Base { + public a: int = 1; + } + class Derived extends Base {} + function main(): void { + let derived: Derived = new Derived(); + let a = derived.a; + } + )"; + es2panda_Context *ctx = impl_->CreateContextFromString(cfg_, text, "dummy.ets"); + impl_->ProceedToState(ctx, ES2PANDA_STATE_CHECKED); + ASSERT_EQ(impl_->ContextState(ctx), ES2PANDA_STATE_CHECKED); + + auto *ast = reinterpret_cast(impl_->ProgramAst(impl_->ContextProgram(ctx))); + + ast->AsETSScript() + ->Statements()[1] + ->AsClassDeclaration() + ->Definition() + ->AsClassDefinition() + ->Body()[0] + ->AsClassProperty() + ->AddModifier(ark::es2panda::ir::ModifierFlags::PRIVATE); + + InvariantNameSet checks; + checks.insert("ModifierAccessValidForAll"); + const auto &messages = verifier.Verify(ast, checks); + ASSERT_EQ(messages.size(), 1); + + ASSERT_NE(checks.find(messages[0].Invariant()), checks.end()); + + impl_->DestroyContext(ctx); +} + +TEST_F(ASTVerifierTest, PrivateAccessTestNegative4) +{ + ASTVerifier verifier {Allocator()}; + + char const *text = R"( + class Base { + public a: int = 1; + } + class Derived extends Base {} + function main(): void { + let derived: Base = new Derived(); + let a = derived.a; + } + )"; + es2panda_Context *ctx = impl_->CreateContextFromString(cfg_, text, "dummy.ets"); + impl_->ProceedToState(ctx, ES2PANDA_STATE_CHECKED); + ASSERT_EQ(impl_->ContextState(ctx), ES2PANDA_STATE_CHECKED); + + auto *ast = reinterpret_cast(impl_->ProgramAst(impl_->ContextProgram(ctx))); + + ast->AsETSScript() + ->Statements()[1] + ->AsClassDeclaration() + ->Definition() + ->AsClassDefinition() + ->Body()[0] + ->AsClassProperty() + ->AddModifier(ark::es2panda::ir::ModifierFlags::PRIVATE); + + InvariantNameSet checks; + checks.insert("ModifierAccessValidForAll"); + const auto &messages = verifier.Verify(ast, checks); + ASSERT_EQ(messages.size(), 1); + + ASSERT_NE(checks.find(messages[0].Invariant()), checks.end()); + + impl_->DestroyContext(ctx); +} diff --git a/ets2panda/test/unit/public/ast_verifier_private_access_negative_test_5_7.cpp b/ets2panda/test/unit/public/ast_verifier_private_access_negative_test_5_7.cpp new file mode 100644 index 0000000000..df0e93e385 --- /dev/null +++ b/ets2panda/test/unit/public/ast_verifier_private_access_negative_test_5_7.cpp @@ -0,0 +1,179 @@ +/** + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ast_verifier_test.h" +#include "checker/ETSchecker.h" + +using ark::es2panda::compiler::ast_verifier::ASTVerifier; +using ark::es2panda::compiler::ast_verifier::InvariantNameSet; +using ark::es2panda::ir::ETSScript; + +TEST_F(ASTVerifierTest, PrivateAccessTestNegative5) +{ + ASTVerifier verifier {Allocator()}; + + char const *text = R"( + class Base { + public a: int = 1; + public privateMethod() { + this.a = 2; + } + } + function main(): void { + let base: Base = new Base(); + base.privateMethod(); + } + )"; + es2panda_Context *ctx = impl_->CreateContextFromString(cfg_, text, "dummy.ets"); + impl_->ProceedToState(ctx, ES2PANDA_STATE_CHECKED); + ASSERT_EQ(impl_->ContextState(ctx), ES2PANDA_STATE_CHECKED); + + auto *ast = reinterpret_cast(impl_->ProgramAst(impl_->ContextProgram(ctx))); + + ast->AsETSScript() + ->Statements()[0] + ->AsClassDeclaration() + ->Definition() + ->AsClassDefinition() + ->Body()[1] + ->AsClassElement() + ->Value() + ->AsFunctionExpression() + ->Function() + ->AsScriptFunction() + ->Body() + ->AsBlockStatement() + ->Statements()[1] + ->AsExpressionStatement() + ->GetExpression() + ->AsCallExpression() + ->Signature() + ->AddSignatureFlag(ark::es2panda::checker::SignatureFlags::PRIVATE); + + InvariantNameSet checks; + checks.insert("ModifierAccessValidForAll"); + const auto &messages = verifier.Verify(ast, checks); + ASSERT_EQ(messages.size(), 1); + + ASSERT_NE(checks.find(messages[0].Invariant()), checks.end()); + + impl_->DestroyContext(ctx); +} + +TEST_F(ASTVerifierTest, PrivateAccessTestNegative6) +{ + ASTVerifier verifier {Allocator()}; + + char const *text = R"( + class Base { + public a: int = 1; + public privateMethod() { + this.a = 2; + } + } + class Derived extends Base {} + function main(): void { + let derived: Derived = new Derived(); + derived.privateMethod(); + } + )"; + es2panda_Context *ctx = impl_->CreateContextFromString(cfg_, text, "dummy.ets"); + impl_->ProceedToState(ctx, ES2PANDA_STATE_CHECKED); + ASSERT_EQ(impl_->ContextState(ctx), ES2PANDA_STATE_CHECKED); + + auto *ast = reinterpret_cast(impl_->ProgramAst(impl_->ContextProgram(ctx))); + + ast->AsETSScript() + ->Statements()[0] + ->AsClassDeclaration() + ->Definition() + ->AsClassDefinition() + ->Body()[1] + ->AsClassElement() + ->Value() + ->AsFunctionExpression() + ->Function() + ->AsScriptFunction() + ->Body() + ->AsBlockStatement() + ->Statements()[1] + ->AsExpressionStatement() + ->GetExpression() + ->AsCallExpression() + ->Signature() + ->AddSignatureFlag(ark::es2panda::checker::SignatureFlags::PRIVATE); + + InvariantNameSet checks; + checks.insert("ModifierAccessValidForAll"); + const auto &messages = verifier.Verify(ast, checks); + ASSERT_EQ(messages.size(), 1); + + ASSERT_NE(checks.find(messages[0].Invariant()), checks.end()); + + impl_->DestroyContext(ctx); +} + +TEST_F(ASTVerifierTest, PrivateAccessTestNegative7) +{ + ASTVerifier verifier {Allocator()}; + + char const *text = R"( + class Base { + public a: int = 1; + public privateMethod() { + this.a = 2; + } + } + class Derived extends Base {} + function main(): void { + let derived: Base = new Derived(); + derived.privateMethod(); + } + )"; + es2panda_Context *ctx = impl_->CreateContextFromString(cfg_, text, "dummy.ets"); + impl_->ProceedToState(ctx, ES2PANDA_STATE_CHECKED); + ASSERT_EQ(impl_->ContextState(ctx), ES2PANDA_STATE_CHECKED); + + auto *ast = reinterpret_cast(impl_->ProgramAst(impl_->ContextProgram(ctx))); + + ast->AsETSScript() + ->Statements()[0] + ->AsClassDeclaration() + ->Definition() + ->AsClassDefinition() + ->Body()[1] + ->AsClassElement() + ->Value() + ->AsFunctionExpression() + ->Function() + ->AsScriptFunction() + ->Body() + ->AsBlockStatement() + ->Statements()[1] + ->AsExpressionStatement() + ->GetExpression() + ->AsCallExpression() + ->Signature() + ->AddSignatureFlag(ark::es2panda::checker::SignatureFlags::PRIVATE); + + InvariantNameSet checks; + checks.insert("ModifierAccessValidForAll"); + const auto &messages = verifier.Verify(ast, checks); + ASSERT_EQ(messages.size(), 1); + + ASSERT_NE(checks.find(messages[0].Invariant()), checks.end()); + + impl_->DestroyContext(ctx); +} diff --git a/ets2panda/test/unit/public/ast_verifier_private_protected_public_access_correct_test.cpp b/ets2panda/test/unit/public/ast_verifier_private_protected_public_access_correct_test.cpp new file mode 100644 index 0000000000..8d83ed334f --- /dev/null +++ b/ets2panda/test/unit/public/ast_verifier_private_protected_public_access_correct_test.cpp @@ -0,0 +1,82 @@ +/** + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ast_verifier_test.h" +#include "checker/ETSchecker.h" + +using ark::es2panda::compiler::ast_verifier::ASTVerifier; +using ark::es2panda::compiler::ast_verifier::InvariantNameSet; +using ark::es2panda::ir::AstNode; + +constexpr char const *PRIVATE_PROTECTED_PUBLIC_TEST = + R"( + class Base { + public a: int = 1; + protected b: int = 2; + private c: int = 3; + public publicMethod() { + this.a = 4; + this.protectedMethod(); + this.privateMethod(); + } + protected protectedMethod() { + this.b = 5; + this.publicMethod(); + this.privateMethod(); + } + private privateMethod() { + this.c = 6; + this.publicMethod(); + this.protectedMethod(); + } + } + class Derived extends Base { + foo () { + this.a = 7; + this.b = 8; + this.publicMethod(); + this.protectedMethod(); + } + } + function main(): void { + let base: Base = new Base(); + let a = base.a; + base.publicMethod(); + let derived1: Derived = new Derived(); + let b = derived1.a; + derived1.publicMethod(); + derived1.foo(); + let derived2: Base = new Derived(); + let c = derived2.a; + derived2.publicMethod(); + } + )"; + +TEST_F(ASTVerifierTest, PrivateProtectedPublicAccessTestCorrect) +{ + ASTVerifier verifier {Allocator()}; + + es2panda_Context *ctx = impl_->CreateContextFromString(cfg_, PRIVATE_PROTECTED_PUBLIC_TEST, "dummy.ets"); + impl_->ProceedToState(ctx, ES2PANDA_STATE_CHECKED); + ASSERT_EQ(impl_->ContextState(ctx), ES2PANDA_STATE_CHECKED); + + auto *ast = reinterpret_cast(impl_->ProgramAst(impl_->ContextProgram(ctx))); + InvariantNameSet checks; + checks.insert("ModifierAccessValidForAll"); + const auto &messages = verifier.Verify(ast, checks); + + ASSERT_EQ(messages.size(), 0); + impl_->DestroyContext(ctx); +} diff --git a/ets2panda/test/unit/public/ast_verifier_protected_access_correct_test.cpp b/ets2panda/test/unit/public/ast_verifier_protected_access_correct_test.cpp new file mode 100644 index 0000000000..530c6771f4 --- /dev/null +++ b/ets2panda/test/unit/public/ast_verifier_protected_access_correct_test.cpp @@ -0,0 +1,57 @@ +/** + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ast_verifier_test.h" +#include "checker/ETSchecker.h" + +using ark::es2panda::compiler::ast_verifier::ASTVerifier; +using ark::es2panda::compiler::ast_verifier::InvariantNameSet; +using ark::es2panda::ir::ETSScript; + +TEST_F(ASTVerifierTest, ProtectedAccessTestCorrect) +{ + ASTVerifier verifier {Allocator()}; + + char const *text = R"( + class A { + public a: int = 1; + } + class B extends A { + public b: int = this.a; + } + )"; + es2panda_Context *ctx = impl_->CreateContextFromString(cfg_, text, "dummy.ets"); + impl_->ProceedToState(ctx, ES2PANDA_STATE_CHECKED); + ASSERT_EQ(impl_->ContextState(ctx), ES2PANDA_STATE_CHECKED); + + auto *ast = reinterpret_cast(impl_->ProgramAst(impl_->ContextProgram(ctx))); + + ast->AsETSScript() + ->Statements()[1] + ->AsClassDeclaration() + ->Definition() + ->AsClassDefinition() + ->Body()[0] + ->AsClassProperty() + ->AddModifier(ark::es2panda::ir::ModifierFlags::PROTECTED); + + InvariantNameSet checks; + checks.insert("ModifierAccessValidForAll"); + const auto &messages = verifier.Verify(ast, checks); + + ASSERT_EQ(messages.size(), 0); + + impl_->DestroyContext(ctx); +} diff --git a/ets2panda/test/unit/public/ast_verifier_protected_access_negative_test_1_3.cpp b/ets2panda/test/unit/public/ast_verifier_protected_access_negative_test_1_3.cpp new file mode 100644 index 0000000000..478d06ebb3 --- /dev/null +++ b/ets2panda/test/unit/public/ast_verifier_protected_access_negative_test_1_3.cpp @@ -0,0 +1,137 @@ +/** + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ast_verifier_test.h" +#include "checker/ETSchecker.h" + +using ark::es2panda::compiler::ast_verifier::ASTVerifier; +using ark::es2panda::compiler::ast_verifier::InvariantNameSet; +using ark::es2panda::ir::ETSScript; + +TEST_F(ASTVerifierTest, ProtectedAccessTestNegative1) +{ + ASTVerifier verifier {Allocator()}; + + char const *text = R"( + class Base { + public a: int = 1; + } + function main(): void { + let base: Base = new Base(); + let a = base.a; + } + )"; + es2panda_Context *ctx = impl_->CreateContextFromString(cfg_, text, "dummy.ets"); + impl_->ProceedToState(ctx, ES2PANDA_STATE_CHECKED); + ASSERT_EQ(impl_->ContextState(ctx), ES2PANDA_STATE_CHECKED); + + auto *ast = reinterpret_cast(impl_->ProgramAst(impl_->ContextProgram(ctx))); + + ast->AsETSScript() + ->Statements()[1] + ->AsClassDeclaration() + ->Definition() + ->AsClassDefinition() + ->Body()[0] + ->AsClassProperty() + ->AddModifier(ark::es2panda::ir::ModifierFlags::PROTECTED); + + InvariantNameSet checks; + checks.insert("ModifierAccessValidForAll"); + const auto &messages = verifier.Verify(ast, checks); + ASSERT_EQ(messages.size(), 1); + + ASSERT_NE(checks.find(messages[0].Invariant()), checks.end()); + + impl_->DestroyContext(ctx); +} + +TEST_F(ASTVerifierTest, ProtectedAccessTestNegative2) +{ + ASTVerifier verifier {Allocator()}; + + char const *text = R"( + class Base { + public a: int = 1; + } + class Derived extends Base {} + function main(): void { + let derived: Derived = new Derived(); + let a = derived.a; + } + )"; + es2panda_Context *ctx = impl_->CreateContextFromString(cfg_, text, "dummy.ets"); + impl_->ProceedToState(ctx, ES2PANDA_STATE_CHECKED); + ASSERT_EQ(impl_->ContextState(ctx), ES2PANDA_STATE_CHECKED); + + auto *ast = reinterpret_cast(impl_->ProgramAst(impl_->ContextProgram(ctx))); + + ast->AsETSScript() + ->Statements()[1] + ->AsClassDeclaration() + ->Definition() + ->AsClassDefinition() + ->Body()[0] + ->AsClassProperty() + ->AddModifier(ark::es2panda::ir::ModifierFlags::PROTECTED); + + InvariantNameSet checks; + checks.insert("ModifierAccessValidForAll"); + const auto &messages = verifier.Verify(ast, checks); + ASSERT_EQ(messages.size(), 1); + + ASSERT_NE(checks.find(messages[0].Invariant()), checks.end()); + + impl_->DestroyContext(ctx); +} + +TEST_F(ASTVerifierTest, ProtectedAccessTestNegative3) +{ + ASTVerifier verifier {Allocator()}; + + char const *text = R"( + class Base { + public a: int = 1; + } + class Derived extends Base {} + function main(): void { + let derived: Base = new Derived(); + let a = derived.a; + } + )"; + es2panda_Context *ctx = impl_->CreateContextFromString(cfg_, text, "dummy.ets"); + impl_->ProceedToState(ctx, ES2PANDA_STATE_CHECKED); + ASSERT_EQ(impl_->ContextState(ctx), ES2PANDA_STATE_CHECKED); + + auto *ast = reinterpret_cast(impl_->ProgramAst(impl_->ContextProgram(ctx))); + + ast->AsETSScript() + ->Statements()[1] + ->AsClassDeclaration() + ->Definition() + ->AsClassDefinition() + ->Body()[0] + ->AsClassProperty() + ->AddModifier(ark::es2panda::ir::ModifierFlags::PROTECTED); + + InvariantNameSet checks; + checks.insert("ModifierAccessValidForAll"); + const auto &messages = verifier.Verify(ast, checks); + ASSERT_EQ(messages.size(), 1); + + ASSERT_NE(checks.find(messages[0].Invariant()), checks.end()); + + impl_->DestroyContext(ctx); +} diff --git a/ets2panda/test/unit/public/ast_verifier_protected_access_negative_test_4_6.cpp b/ets2panda/test/unit/public/ast_verifier_protected_access_negative_test_4_6.cpp new file mode 100644 index 0000000000..71c1e6e417 --- /dev/null +++ b/ets2panda/test/unit/public/ast_verifier_protected_access_negative_test_4_6.cpp @@ -0,0 +1,180 @@ +/** + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ast_verifier_test.h" +#include "checker/ETSchecker.h" + +using ark::es2panda::compiler::ast_verifier::ASTVerifier; +using ark::es2panda::compiler::ast_verifier::InvariantNameSet; +using ark::es2panda::ir::ETSScript; + +TEST_F(ASTVerifierTest, ProtectedAccessTestNegative4) +{ + ASTVerifier verifier {Allocator()}; + + char const *text = R"( + class Base { + public a: int = 1; + public protectedMethod() { + this.a = 2; + } + } + function main(): void { + let base: Base = new Base(); + base.protectedMethod(); + } + )"; + es2panda_Context *ctx = impl_->CreateContextFromString(cfg_, text, "dummy.ets"); + impl_->ProceedToState(ctx, ES2PANDA_STATE_CHECKED); + ASSERT_EQ(impl_->ContextState(ctx), ES2PANDA_STATE_CHECKED); + + auto *ast = reinterpret_cast(impl_->ProgramAst(impl_->ContextProgram(ctx))); + + ast->AsETSScript() + ->Statements()[0] + ->AsClassDeclaration() + ->Definition() + ->AsClassDefinition() + ->Body()[1] + ->AsClassElement() + ->Value() + ->AsFunctionExpression() + ->Function() + ->AsScriptFunction() + ->Body() + ->AsBlockStatement() + ->Statements()[1] + ->AsExpressionStatement() + ->GetExpression() + ->AsCallExpression() + ->Signature() + ->AddSignatureFlag(ark::es2panda::checker::SignatureFlags::PROTECTED); + + InvariantNameSet checks; + checks.insert("ModifierAccessValidForAll"); + const auto &messages = verifier.Verify(ast, checks); + ASSERT_EQ(messages.size(), 1); + + ASSERT_NE(checks.find(messages[0].Invariant()), checks.end()); + + impl_->DestroyContext(ctx); +} + +TEST_F(ASTVerifierTest, ProtectedAccessTestNegative5) +{ + ASTVerifier verifier {Allocator()}; + + char const *text = R"( + class Base { + public a: int = 1; + public protectedMethod() { + this.a = 2; + } + } + class Derived extends Base {} + function main(): void { + let derived: Derived = new Derived(); + derived.protectedMethod(); + } + )"; + es2panda_Context *ctx = impl_->CreateContextFromString(cfg_, text, "dummy.ets"); + impl_->ProceedToState(ctx, ES2PANDA_STATE_CHECKED); + ASSERT_EQ(impl_->ContextState(ctx), ES2PANDA_STATE_CHECKED); + + auto *ast = reinterpret_cast(impl_->ProgramAst(impl_->ContextProgram(ctx))); + + ast->AsETSScript() + ->Statements()[0] + ->AsClassDeclaration() + ->Definition() + ->AsClassDefinition() + ->Body()[1] + ->AsClassElement() + ->Value() + ->AsFunctionExpression() + ->Function() + ->AsScriptFunction() + ->Body() + ->AsBlockStatement() + ->Statements()[1] + ->AsExpressionStatement() + ->GetExpression() + ->AsCallExpression() + ->Signature() + ->AddSignatureFlag(ark::es2panda::checker::SignatureFlags::PROTECTED); + + InvariantNameSet checks; + checks.insert("ModifierAccessValidForAll"); + const auto &messages = verifier.Verify(ast, checks); + ASSERT_EQ(messages.size(), 1); + + ASSERT_NE(checks.find(messages[0].Invariant()), checks.end()); + + impl_->DestroyContext(ctx); +} + +TEST_F(ASTVerifierTest, ProtectedAccessTestNegative6) +{ + ASTVerifier verifier {Allocator()}; + + char const *text = R"( + class Base { + public a: int = 1; + public protectedMethod() { + this.a = 2; + } + } + class Derived extends Base {} + function main(): void { + let derived: Base = new Derived(); + derived.protectedMethod(); + } + )"; + es2panda_Context *ctx = impl_->CreateContextFromString(cfg_, text, "dummy.ets"); + impl_->ProceedToState(ctx, ES2PANDA_STATE_CHECKED); + ASSERT_EQ(impl_->ContextState(ctx), ES2PANDA_STATE_CHECKED); + + auto *ast = reinterpret_cast(impl_->ProgramAst(impl_->ContextProgram(ctx))); + + ast->AsETSScript() + ->Statements()[0] + ->AsClassDeclaration() + ->Definition() + ->AsClassDefinition() + ->Body()[1] + ->AsClassElement() + ->Value() + ->AsFunctionExpression() + ->Function() + ->AsScriptFunction() + ->Body() + ->AsBlockStatement() + ->Statements()[1] + ->AsExpressionStatement() + ->GetExpression() + ->AsCallExpression() + ->Signature() + ->AddSignatureFlag(ark::es2panda::checker::SignatureFlags::PROTECTED); + + InvariantNameSet checks; + checks.insert("ModifierAccessValidForAll"); + + const auto &messages = verifier.Verify(ast, checks); + ASSERT_EQ(messages.size(), 1); + + ASSERT_NE(checks.find(messages[0].Invariant()), checks.end()); + + impl_->DestroyContext(ctx); +} diff --git a/ets2panda/test/unit/public/ast_verifier_short_test.cpp b/ets2panda/test/unit/public/ast_verifier_short_test.cpp new file mode 100644 index 0000000000..5564389bbc --- /dev/null +++ b/ets2panda/test/unit/public/ast_verifier_short_test.cpp @@ -0,0 +1,265 @@ +/** + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ast_verifier_test.h" +#include "checker/ETSchecker.h" +#include "ir/expressions/literals/stringLiteral.h" +#include "ir/expressions/identifier.h" +#include "ir/expressions/literals/numberLiteral.h" +#include "ir/expressions/literals/booleanLiteral.h" +#include "macros.h" +#include "parser/ETSparser.h" +#include "varbinder/ETSBinder.h" + +#include + +using ark::es2panda::CompilerOptions; +using ark::es2panda::ScriptExtension; +using ark::es2panda::checker::ETSChecker; +using ark::es2panda::compiler::ast_verifier::ASTVerifier; +using ark::es2panda::compiler::ast_verifier::InvariantNameSet; +using ark::es2panda::ir::BinaryExpression; +using ark::es2panda::ir::BooleanLiteral; +using ark::es2panda::ir::Expression; +using ark::es2panda::ir::Identifier; +using ark::es2panda::ir::NumberLiteral; +using ark::es2panda::ir::SequenceExpression; +using ark::es2panda::ir::StringLiteral; +using ark::es2panda::lexer::Number; +using ark::es2panda::lexer::TokenType; +using ark::es2panda::parser::ETSParser; +using ark::es2panda::parser::Program; +using ark::es2panda::util::StringView; +using ark::es2panda::varbinder::ETSBinder; +using ark::es2panda::varbinder::FunctionScope; +using ark::es2panda::varbinder::LetDecl; +using ark::es2panda::varbinder::LocalScope; +using ark::es2panda::varbinder::LocalVariable; +using ark::es2panda::varbinder::VariableFlags; + +TEST_F(ASTVerifierTest, NullParent) +{ + ark::es2panda::compiler::ast_verifier::ASTVerifier verifier {Allocator()}; + StringLiteral emptyNode; + + const auto check = "NodeHasParent"; + auto checks = ark::es2panda::compiler::ast_verifier::InvariantNameSet {}; + checks.insert(check); + const auto &messages = verifier.Verify(&emptyNode, checks); + bool hasParent = messages.empty(); + ASSERT_FALSE(hasParent); + ASSERT_EQ(messages.size(), 1); + + ASSERT_EQ(messages[0].Invariant(), check); +} + +TEST_F(ASTVerifierTest, NullRange) +{ + ark::es2panda::compiler::ast_verifier::ASTVerifier verifier {Allocator()}; + StringLiteral emptyNode; + + const auto check = "NodeHasSourceRange"; + auto checks = ark::es2panda::compiler::ast_verifier::InvariantNameSet {}; + checks.insert(check); + const auto &messages = verifier.Verify(&emptyNode, checks); + bool hasSourceRange = messages.empty(); + ASSERT_FALSE(hasSourceRange); + ASSERT_EQ(messages.size(), 1); + + ASSERT_EQ(messages[0].Invariant(), check); +} + +TEST_F(ASTVerifierTest, NullType) +{ + ASTVerifier verifier {Allocator()}; + StringLiteral emptyNode; + + auto check = "NodeHasType"; + auto checks = InvariantNameSet {}; + checks.insert(check); + const auto &messages = verifier.Verify(&emptyNode, checks); + bool hasType = messages.empty(); + ASSERT_EQ(hasType, false); + ASSERT_NE(messages.size(), 0); + + ASSERT_EQ(messages[0].Invariant(), check); +} + +TEST_F(ASTVerifierTest, WithoutScope) +{ + ASTVerifier verifier {Allocator()}; + StringLiteral emptyNode; + + auto checks = InvariantNameSet {}; + checks.insert("VariableHasScope"); + const auto &messages = verifier.Verify(&emptyNode, checks); + + ASSERT_EQ(messages.size(), 0); +} + +TEST_F(ASTVerifierTest, ScopeTest) +{ + ASTVerifier verifier {Allocator()}; + Identifier ident(StringView("var_decl"), Allocator()); + LetDecl decl("test", &ident); + LocalVariable local(&decl, VariableFlags::LOCAL); + ident.SetVariable(&local); + + LocalScope scope(Allocator(), nullptr); + FunctionScope parentScope(Allocator(), nullptr); + scope.SetParent(&parentScope); + scope.AddDecl(Allocator(), &decl, ScriptExtension::ETS); + scope.BindNode(&ident); + + local.SetScope(&scope); + + auto checks = InvariantNameSet {}; + checks.insert("VariableHasScope"); + const auto &messages = verifier.Verify(&ident, checks); + + ASSERT_EQ(messages.size(), 0); +} + +TEST_F(ASTVerifierTest, ScopeNodeTest) +{ + ASTVerifier verifier {Allocator()}; + Identifier ident(StringView("var_decl"), Allocator()); + LetDecl decl("test", &ident); + LocalVariable local(&decl, VariableFlags::LOCAL); + ident.SetVariable(&local); + + LocalScope scope(Allocator(), nullptr); + FunctionScope parentScope(Allocator(), nullptr); + scope.SetParent(&parentScope); + scope.AddDecl(Allocator(), &decl, ScriptExtension::ETS); + scope.BindNode(&ident); + parentScope.BindNode(&ident); + + local.SetScope(&scope); + + auto checks = InvariantNameSet {}; + checks.insert("VariableHasEnclosingScope"); + const auto &messages = verifier.Verify(&ident, checks); + + ASSERT_EQ(messages.size(), 0); +} + +TEST_F(ASTVerifierTest, ArithmeticExpressionCorrect1) +{ + ETSChecker etschecker {}; + ASTVerifier verifier {Allocator()}; + auto program = Program::NewProgram(Allocator()); + auto parser = ETSParser(&program, CompilerOptions {}); + + auto left = NumberLiteral(Number {1}); + auto right = NumberLiteral(Number {6}); + auto arithmeticExpression = BinaryExpression(&left, &right, TokenType::PUNCTUATOR_PLUS); + + left.SetTsType(etschecker.GlobalIntType()); + right.SetTsType(etschecker.GlobalIntType()); + + auto checks = InvariantNameSet {}; + checks.insert("ArithmeticOperationValid"); + const auto &messages = verifier.Verify(arithmeticExpression.AsBinaryExpression(), checks); + ASSERT_EQ(messages.size(), 0); +} + +TEST_F(ASTVerifierTest, ArithmeticExpressionCorrect2) +{ + ETSChecker etschecker {}; + ASTVerifier verifier {Allocator()}; + auto program = Program::NewProgram(Allocator()); + auto parser = ETSParser(&program, CompilerOptions {}); + + constexpr uint32_t LEFT1_PARAM = 1; + constexpr uint32_t LEFT2_PARAM = 12; + constexpr uint32_t RIGHT2_PARAM = 6; + auto left1 = NumberLiteral(Number {LEFT1_PARAM}); + auto left2 = NumberLiteral(Number {LEFT2_PARAM}); + auto right2 = NumberLiteral(Number {RIGHT2_PARAM}); + auto right1 = BinaryExpression(&left2, &right2, TokenType::PUNCTUATOR_MULTIPLY); + auto arithmeticExpression = BinaryExpression(&left1, &right1, TokenType::PUNCTUATOR_PLUS); + + left1.SetTsType(etschecker.GlobalIntType()); + right1.SetTsType(etschecker.GlobalIntType()); + left2.SetTsType(etschecker.GlobalIntType()); + right2.SetTsType(etschecker.GlobalIntType()); + + auto checks = InvariantNameSet {}; + checks.insert("ArithmeticOperationValid"); + const auto &messages = verifier.Verify(arithmeticExpression.AsBinaryExpression(), checks); + ASSERT_EQ(messages.size(), 0); +} + +TEST_F(ASTVerifierTest, ArithmeticExpressionNegative1) +{ + ETSChecker etschecker {}; + ASTVerifier verifier {Allocator()}; + auto program = Program::NewProgram(Allocator()); + auto parser = ETSParser(&program, CompilerOptions {}); + + const StringView leftParam("1"); + constexpr uint32_t RIGHT_PARAM = 1; + auto left = StringLiteral(leftParam); + auto right = NumberLiteral(Number {RIGHT_PARAM}); + auto arithmeticExpression = BinaryExpression(&left, &right, TokenType::PUNCTUATOR_DIVIDE); + + left.SetTsType(etschecker.GlobalETSStringLiteralType()); + right.SetTsType(etschecker.GlobalIntType()); + + auto checks = InvariantNameSet {}; + checks.insert("ArithmeticOperationValid"); + const auto &messages = verifier.Verify(arithmeticExpression.AsBinaryExpression(), checks); + + ASSERT_EQ(messages.size(), 1); +} + +TEST_F(ASTVerifierTest, ArithmeticExpressionNegative2) +{ + ETSChecker etschecker {}; + ASTVerifier verifier {Allocator()}; + auto program = Program::NewProgram(Allocator()); + auto parser = ETSParser(&program, CompilerOptions {}); + auto left = BooleanLiteral(true); + auto right = NumberLiteral(Number {1}); + auto arithmeticExpression = BinaryExpression(&left, &right, TokenType::PUNCTUATOR_DIVIDE); + + left.SetTsType(etschecker.GlobalETSStringLiteralType()); + right.SetTsType(etschecker.GlobalIntType()); + + auto checks = InvariantNameSet {}; + checks.insert("ArithmeticOperationValid"); + const auto &messages = verifier.Verify(arithmeticExpression.AsBinaryExpression(), checks); + + ASSERT_EQ(messages.size(), 1); +} + +TEST_F(ASTVerifierTest, SequenceExpressionType) +{ + ASTVerifier verifier {Allocator()}; + auto checker = ETSChecker(); + auto *last = Tree(Node(Number {3})); + auto *sequenceExpression = Tree(Node( + Nodes(Node(Number {1}), Node(Number {2}), last))); + + last->SetTsType(checker.GlobalIntType()); + sequenceExpression->SetTsType(checker.GlobalIntType()); + + auto checks = InvariantNameSet {}; + checks.insert("SequenceExpressionHasLastType"); + const auto &messages = verifier.Verify(sequenceExpression, checks); + + ASSERT_EQ(messages.size(), 0); +} diff --git a/ets2panda/test/unit/public/ast_verifier_test.cpp b/ets2panda/test/unit/public/ast_verifier_test.cpp deleted file mode 100644 index 7c82b31884..0000000000 --- a/ets2panda/test/unit/public/ast_verifier_test.cpp +++ /dev/null @@ -1,1004 +0,0 @@ -/** - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "checker/ETSchecker.h" -#include "ir/expressions/literals/stringLiteral.h" -#include "ir/expressions/identifier.h" -#include "ir/expressions/literals/numberLiteral.h" -#include "ir/expressions/literals/booleanLiteral.h" -#include "macros.h" -#include "parser/ETSparser.h" -#include "varbinder/ETSBinder.h" -#include "compiler/core/ASTVerifier.h" -#include "test/utils/panda_executable_path_getter.h" - -#include - -using ark::es2panda::CompilerOptions; -using ark::es2panda::ScriptExtension; -using ark::es2panda::checker::ETSChecker; -using ark::es2panda::compiler::ast_verifier::ASTVerifier; -using ark::es2panda::compiler::ast_verifier::InvariantNameSet; -using ark::es2panda::ir::AstNode; -using ark::es2panda::ir::BinaryExpression; -using ark::es2panda::ir::BooleanLiteral; -using ark::es2panda::ir::ETSScript; -using ark::es2panda::ir::Expression; -using ark::es2panda::ir::Identifier; -using ark::es2panda::ir::NumberLiteral; -using ark::es2panda::ir::SequenceExpression; -using ark::es2panda::ir::StringLiteral; -using ark::es2panda::lexer::Number; -using ark::es2panda::lexer::TokenType; -using ark::es2panda::parser::ETSParser; -using ark::es2panda::parser::Program; -using ark::es2panda::util::StringView; -using ark::es2panda::varbinder::ETSBinder; -using ark::es2panda::varbinder::FunctionScope; -using ark::es2panda::varbinder::LetDecl; -using ark::es2panda::varbinder::LocalScope; -using ark::es2panda::varbinder::LocalVariable; -using ark::es2panda::varbinder::VariableFlags; - -class ASTVerifierTest : public testing::Test { -public: - ASTVerifierTest() - { - impl_ = es2panda_GetImpl(ES2PANDA_LIB_VERSION); - auto es2pandaPath = test::utils::PandaExecutablePathGetter {}.Get(); - // NOLINTNEXTLINE(modernize-avoid-c-arrays) - char const *argv[] = {es2pandaPath.c_str()}; - cfg_ = impl_->CreateConfig(1, argv); - allocator_ = new ark::ArenaAllocator(ark::SpaceType::SPACE_TYPE_COMPILER); - } - ~ASTVerifierTest() override - { - delete allocator_; - impl_->DestroyConfig(cfg_); - } - - ark::ArenaAllocator *Allocator() - { - return allocator_; - } - - NO_COPY_SEMANTIC(ASTVerifierTest); - NO_MOVE_SEMANTIC(ASTVerifierTest); - -protected: - template - Type *Tree(Type *node) - { - return node; - } - - template - Type *Node(Args &&...args) - { - return allocator_->New(std::forward(args)...); - } - - template - ark::ArenaVector Nodes(Args &&...args) - { - auto v = ark::ArenaVector {allocator_->Adapter()}; - v.insert(v.end(), {std::forward(args)...}); - return v; - } - - // NOLINTBEGIN(misc-non-private-member-variables-in-classes) - es2panda_Impl const *impl_; - es2panda_Config *cfg_; - ark::ArenaAllocator *allocator_; - // NOLINTEND(misc-non-private-member-variables-in-classes) -}; - -TEST_F(ASTVerifierTest, NullParent) -{ - ark::es2panda::compiler::ast_verifier::ASTVerifier verifier {Allocator()}; - StringLiteral emptyNode; - - const auto check = "NodeHasParent"; - auto checks = ark::es2panda::compiler::ast_verifier::InvariantNameSet {}; - checks.insert(check); - const auto &messages = verifier.Verify(&emptyNode, checks); - bool hasParent = messages.empty(); - ASSERT_FALSE(hasParent); - ASSERT_EQ(messages.size(), 1); - - ASSERT_EQ(messages[0].Invariant(), check); -} - -TEST_F(ASTVerifierTest, NullRange) -{ - ark::es2panda::compiler::ast_verifier::ASTVerifier verifier {Allocator()}; - StringLiteral emptyNode; - - const auto check = "NodeHasSourceRange"; - auto checks = ark::es2panda::compiler::ast_verifier::InvariantNameSet {}; - checks.insert(check); - const auto &messages = verifier.Verify(&emptyNode, checks); - bool hasSourceRange = messages.empty(); - ASSERT_FALSE(hasSourceRange); - ASSERT_EQ(messages.size(), 1); - - ASSERT_EQ(messages[0].Invariant(), check); -} - -TEST_F(ASTVerifierTest, NullType) -{ - ASTVerifier verifier {Allocator()}; - StringLiteral emptyNode; - - auto check = "NodeHasType"; - auto checks = InvariantNameSet {}; - checks.insert(check); - const auto &messages = verifier.Verify(&emptyNode, checks); - bool hasType = messages.empty(); - ASSERT_EQ(hasType, false); - ASSERT_NE(messages.size(), 0); - - ASSERT_EQ(messages[0].Invariant(), check); -} - -TEST_F(ASTVerifierTest, WithoutScope) -{ - ASTVerifier verifier {Allocator()}; - StringLiteral emptyNode; - - auto checks = InvariantNameSet {}; - checks.insert("VariableHasScope"); - const auto &messages = verifier.Verify(&emptyNode, checks); - - ASSERT_EQ(messages.size(), 0); -} - -TEST_F(ASTVerifierTest, ScopeTest) -{ - ASTVerifier verifier {Allocator()}; - Identifier ident(StringView("var_decl"), Allocator()); - LetDecl decl("test", &ident); - LocalVariable local(&decl, VariableFlags::LOCAL); - ident.SetVariable(&local); - - LocalScope scope(Allocator(), nullptr); - FunctionScope parentScope(Allocator(), nullptr); - scope.SetParent(&parentScope); - scope.AddDecl(Allocator(), &decl, ScriptExtension::ETS); - scope.BindNode(&ident); - - local.SetScope(&scope); - - auto checks = InvariantNameSet {}; - checks.insert("VariableHasScope"); - const auto &messages = verifier.Verify(&ident, checks); - - ASSERT_EQ(messages.size(), 0); -} - -TEST_F(ASTVerifierTest, ScopeNodeTest) -{ - ASTVerifier verifier {Allocator()}; - Identifier ident(StringView("var_decl"), Allocator()); - LetDecl decl("test", &ident); - LocalVariable local(&decl, VariableFlags::LOCAL); - ident.SetVariable(&local); - - LocalScope scope(Allocator(), nullptr); - FunctionScope parentScope(Allocator(), nullptr); - scope.SetParent(&parentScope); - scope.AddDecl(Allocator(), &decl, ScriptExtension::ETS); - scope.BindNode(&ident); - parentScope.BindNode(&ident); - - local.SetScope(&scope); - - auto checks = InvariantNameSet {}; - checks.insert("VariableHasEnclosingScope"); - const auto &messages = verifier.Verify(&ident, checks); - - ASSERT_EQ(messages.size(), 0); -} - -TEST_F(ASTVerifierTest, ArithmeticExpressionCorrect1) -{ - ETSChecker etschecker {}; - ASTVerifier verifier {Allocator()}; - auto program = Program::NewProgram(Allocator()); - auto parser = ETSParser(&program, CompilerOptions {}); - - auto left = NumberLiteral(Number {1}); - auto right = NumberLiteral(Number {6}); - auto arithmeticExpression = BinaryExpression(&left, &right, TokenType::PUNCTUATOR_PLUS); - - left.SetTsType(etschecker.GlobalIntType()); - right.SetTsType(etschecker.GlobalIntType()); - - auto checks = InvariantNameSet {}; - checks.insert("ArithmeticOperationValid"); - const auto &messages = verifier.Verify(arithmeticExpression.AsBinaryExpression(), checks); - ASSERT_EQ(messages.size(), 0); -} - -TEST_F(ASTVerifierTest, ArithmeticExpressionCorrect2) -{ - ETSChecker etschecker {}; - ASTVerifier verifier {Allocator()}; - auto program = Program::NewProgram(Allocator()); - auto parser = ETSParser(&program, CompilerOptions {}); - - constexpr uint32_t LEFT1_PARAM = 1; - constexpr uint32_t LEFT2_PARAM = 12; - constexpr uint32_t RIGHT2_PARAM = 6; - auto left1 = NumberLiteral(Number {LEFT1_PARAM}); - auto left2 = NumberLiteral(Number {LEFT2_PARAM}); - auto right2 = NumberLiteral(Number {RIGHT2_PARAM}); - auto right1 = BinaryExpression(&left2, &right2, TokenType::PUNCTUATOR_MULTIPLY); - auto arithmeticExpression = BinaryExpression(&left1, &right1, TokenType::PUNCTUATOR_PLUS); - - left1.SetTsType(etschecker.GlobalIntType()); - right1.SetTsType(etschecker.GlobalIntType()); - left2.SetTsType(etschecker.GlobalIntType()); - right2.SetTsType(etschecker.GlobalIntType()); - - auto checks = InvariantNameSet {}; - checks.insert("ArithmeticOperationValid"); - const auto &messages = verifier.Verify(arithmeticExpression.AsBinaryExpression(), checks); - ASSERT_EQ(messages.size(), 0); -} - -TEST_F(ASTVerifierTest, ArithmeticExpressionNegative1) -{ - ETSChecker etschecker {}; - ASTVerifier verifier {Allocator()}; - auto program = Program::NewProgram(Allocator()); - auto parser = ETSParser(&program, CompilerOptions {}); - - const StringView leftParam("1"); - constexpr uint32_t RIGHT_PARAM = 1; - auto left = StringLiteral(leftParam); - auto right = NumberLiteral(Number {RIGHT_PARAM}); - auto arithmeticExpression = BinaryExpression(&left, &right, TokenType::PUNCTUATOR_DIVIDE); - - left.SetTsType(etschecker.GlobalETSStringLiteralType()); - right.SetTsType(etschecker.GlobalIntType()); - - auto checks = InvariantNameSet {}; - checks.insert("ArithmeticOperationValid"); - const auto &messages = verifier.Verify(arithmeticExpression.AsBinaryExpression(), checks); - - ASSERT_EQ(messages.size(), 1); -} - -TEST_F(ASTVerifierTest, ArithmeticExpressionNegative2) -{ - ETSChecker etschecker {}; - ASTVerifier verifier {Allocator()}; - auto program = Program::NewProgram(Allocator()); - auto parser = ETSParser(&program, CompilerOptions {}); - auto left = BooleanLiteral(true); - auto right = NumberLiteral(Number {1}); - auto arithmeticExpression = BinaryExpression(&left, &right, TokenType::PUNCTUATOR_DIVIDE); - - left.SetTsType(etschecker.GlobalETSStringLiteralType()); - right.SetTsType(etschecker.GlobalIntType()); - - auto checks = InvariantNameSet {}; - checks.insert("ArithmeticOperationValid"); - const auto &messages = verifier.Verify(arithmeticExpression.AsBinaryExpression(), checks); - - ASSERT_EQ(messages.size(), 1); -} - -TEST_F(ASTVerifierTest, SequenceExpressionType) -{ - ASTVerifier verifier {Allocator()}; - auto checker = ETSChecker(); - auto *last = Tree(Node(Number {3})); - auto *sequenceExpression = Tree(Node( - Nodes(Node(Number {1}), Node(Number {2}), last))); - - last->SetTsType(checker.GlobalIntType()); - sequenceExpression->SetTsType(checker.GlobalIntType()); - - auto checks = InvariantNameSet {}; - checks.insert("SequenceExpressionHasLastType"); - const auto &messages = verifier.Verify(sequenceExpression, checks); - - ASSERT_EQ(messages.size(), 0); -} - -constexpr char const *PRIVATE_PROTECTED_PUBLIC_TEST = - R"( - class Base { - public a: int = 1; - protected b: int = 2; - private c: int = 3; - public publicMethod() { - this.a = 4; - this.protectedMethod(); - this.privateMethod(); - } - protected protectedMethod() { - this.b = 5; - this.publicMethod(); - this.privateMethod(); - } - private privateMethod() { - this.c = 6; - this.publicMethod(); - this.protectedMethod(); - } - } - class Derived extends Base { - foo () { - this.a = 7; - this.b = 8; - this.publicMethod(); - this.protectedMethod(); - } - } - function main(): void { - let base: Base = new Base(); - let a = base.a; - base.publicMethod(); - let derived1: Derived = new Derived(); - let b = derived1.a; - derived1.publicMethod(); - derived1.foo(); - let derived2: Base = new Derived(); - let c = derived2.a; - derived2.publicMethod(); - } - )"; - -TEST_F(ASTVerifierTest, PrivateProtectedPublicAccessTestCorrect) -{ - ASTVerifier verifier {Allocator()}; - - es2panda_Context *ctx = impl_->CreateContextFromString(cfg_, PRIVATE_PROTECTED_PUBLIC_TEST, "dummy.ets"); - impl_->ProceedToState(ctx, ES2PANDA_STATE_CHECKED); - ASSERT_EQ(impl_->ContextState(ctx), ES2PANDA_STATE_CHECKED); - - auto *ast = reinterpret_cast(impl_->ProgramAst(impl_->ContextProgram(ctx))); - InvariantNameSet checks; - checks.insert("ModifierAccessValidForAll"); - const auto &messages = verifier.Verify(ast, checks); - - ASSERT_EQ(messages.size(), 0); - impl_->DestroyContext(ctx); -} - -TEST_F(ASTVerifierTest, PrivateAccessTestNegative1) -{ - ASTVerifier verifier {Allocator()}; - - char const *text = R"( - class Base { - public a: int = 1; - } - class Derived extends Base { - public b: int = this.a; - } - )"; - es2panda_Context *ctx = impl_->CreateContextFromString(cfg_, text, "dummy.ets"); - impl_->ProceedToState(ctx, ES2PANDA_STATE_CHECKED); - ASSERT_EQ(impl_->ContextState(ctx), ES2PANDA_STATE_CHECKED); - - auto *ast = reinterpret_cast(impl_->ProgramAst(impl_->ContextProgram(ctx))); - - ast->AsETSScript() - ->Statements()[1] - ->AsClassDeclaration() - ->Definition() - ->AsClassDefinition() - ->Body()[0] - ->AsClassProperty() - ->AddModifier(ark::es2panda::ir::ModifierFlags::PRIVATE); - - InvariantNameSet checks; - checks.insert("ModifierAccessValidForAll"); - const auto &messages = verifier.Verify(ast, checks); - ASSERT_EQ(messages.size(), 1); - - ASSERT_NE(checks.find(messages[0].Invariant()), checks.end()); - - impl_->DestroyContext(ctx); -} - -TEST_F(ASTVerifierTest, PrivateAccessTestNegative2) -{ - ASTVerifier verifier {Allocator()}; - - char const *text = R"( - class Base { - public a: int = 1; - } - function main(): void { - let base: Base = new Base(); - let a = base.a; - } - )"; - es2panda_Context *ctx = impl_->CreateContextFromString(cfg_, text, "dummy.ets"); - impl_->ProceedToState(ctx, ES2PANDA_STATE_CHECKED); - ASSERT_EQ(impl_->ContextState(ctx), ES2PANDA_STATE_CHECKED); - - auto *ast = reinterpret_cast(impl_->ProgramAst(impl_->ContextProgram(ctx))); - - ast->AsETSScript() - ->Statements()[1] - ->AsClassDeclaration() - ->Definition() - ->AsClassDefinition() - ->Body()[0] - ->AsClassProperty() - ->AddModifier(ark::es2panda::ir::ModifierFlags::PRIVATE); - - InvariantNameSet checks; - checks.insert("ModifierAccessValidForAll"); - const auto &messages = verifier.Verify(ast, checks); - ASSERT_EQ(messages.size(), 1); - - ASSERT_NE(checks.find(messages[0].Invariant()), checks.end()); - - impl_->DestroyContext(ctx); -} - -TEST_F(ASTVerifierTest, PrivateAccessTestNegative3) -{ - ASTVerifier verifier {Allocator()}; - - char const *text = R"( - class Base { - public a: int = 1; - } - class Derived extends Base {} - function main(): void { - let derived: Derived = new Derived(); - let a = derived.a; - } - )"; - es2panda_Context *ctx = impl_->CreateContextFromString(cfg_, text, "dummy.ets"); - impl_->ProceedToState(ctx, ES2PANDA_STATE_CHECKED); - ASSERT_EQ(impl_->ContextState(ctx), ES2PANDA_STATE_CHECKED); - - auto *ast = reinterpret_cast(impl_->ProgramAst(impl_->ContextProgram(ctx))); - - ast->AsETSScript() - ->Statements()[1] - ->AsClassDeclaration() - ->Definition() - ->AsClassDefinition() - ->Body()[0] - ->AsClassProperty() - ->AddModifier(ark::es2panda::ir::ModifierFlags::PRIVATE); - - InvariantNameSet checks; - checks.insert("ModifierAccessValidForAll"); - const auto &messages = verifier.Verify(ast, checks); - ASSERT_EQ(messages.size(), 1); - - ASSERT_NE(checks.find(messages[0].Invariant()), checks.end()); - - impl_->DestroyContext(ctx); -} - -TEST_F(ASTVerifierTest, PrivateAccessTestNegative4) -{ - ASTVerifier verifier {Allocator()}; - - char const *text = R"( - class Base { - public a: int = 1; - } - class Derived extends Base {} - function main(): void { - let derived: Base = new Derived(); - let a = derived.a; - } - )"; - es2panda_Context *ctx = impl_->CreateContextFromString(cfg_, text, "dummy.ets"); - impl_->ProceedToState(ctx, ES2PANDA_STATE_CHECKED); - ASSERT_EQ(impl_->ContextState(ctx), ES2PANDA_STATE_CHECKED); - - auto *ast = reinterpret_cast(impl_->ProgramAst(impl_->ContextProgram(ctx))); - - ast->AsETSScript() - ->Statements()[1] - ->AsClassDeclaration() - ->Definition() - ->AsClassDefinition() - ->Body()[0] - ->AsClassProperty() - ->AddModifier(ark::es2panda::ir::ModifierFlags::PRIVATE); - - InvariantNameSet checks; - checks.insert("ModifierAccessValidForAll"); - const auto &messages = verifier.Verify(ast, checks); - ASSERT_EQ(messages.size(), 1); - - ASSERT_NE(checks.find(messages[0].Invariant()), checks.end()); - - impl_->DestroyContext(ctx); -} - -TEST_F(ASTVerifierTest, PrivateAccessTestNegative5) -{ - ASTVerifier verifier {Allocator()}; - - char const *text = R"( - class Base { - public a: int = 1; - public privateMethod() { - this.a = 2; - } - } - function main(): void { - let base: Base = new Base(); - base.privateMethod(); - } - )"; - es2panda_Context *ctx = impl_->CreateContextFromString(cfg_, text, "dummy.ets"); - impl_->ProceedToState(ctx, ES2PANDA_STATE_CHECKED); - ASSERT_EQ(impl_->ContextState(ctx), ES2PANDA_STATE_CHECKED); - - auto *ast = reinterpret_cast(impl_->ProgramAst(impl_->ContextProgram(ctx))); - - ast->AsETSScript() - ->Statements()[0] - ->AsClassDeclaration() - ->Definition() - ->AsClassDefinition() - ->Body()[1] - ->AsClassElement() - ->Value() - ->AsFunctionExpression() - ->Function() - ->AsScriptFunction() - ->Body() - ->AsBlockStatement() - ->Statements()[1] - ->AsExpressionStatement() - ->GetExpression() - ->AsCallExpression() - ->Signature() - ->AddSignatureFlag(ark::es2panda::checker::SignatureFlags::PRIVATE); - - InvariantNameSet checks; - checks.insert("ModifierAccessValidForAll"); - const auto &messages = verifier.Verify(ast, checks); - ASSERT_EQ(messages.size(), 1); - - ASSERT_NE(checks.find(messages[0].Invariant()), checks.end()); - - impl_->DestroyContext(ctx); -} - -TEST_F(ASTVerifierTest, PrivateAccessTestNegative6) -{ - ASTVerifier verifier {Allocator()}; - - char const *text = R"( - class Base { - public a: int = 1; - public privateMethod() { - this.a = 2; - } - } - class Derived extends Base {} - function main(): void { - let derived: Derived = new Derived(); - derived.privateMethod(); - } - )"; - es2panda_Context *ctx = impl_->CreateContextFromString(cfg_, text, "dummy.ets"); - impl_->ProceedToState(ctx, ES2PANDA_STATE_CHECKED); - ASSERT_EQ(impl_->ContextState(ctx), ES2PANDA_STATE_CHECKED); - - auto *ast = reinterpret_cast(impl_->ProgramAst(impl_->ContextProgram(ctx))); - - ast->AsETSScript() - ->Statements()[0] - ->AsClassDeclaration() - ->Definition() - ->AsClassDefinition() - ->Body()[1] - ->AsClassElement() - ->Value() - ->AsFunctionExpression() - ->Function() - ->AsScriptFunction() - ->Body() - ->AsBlockStatement() - ->Statements()[1] - ->AsExpressionStatement() - ->GetExpression() - ->AsCallExpression() - ->Signature() - ->AddSignatureFlag(ark::es2panda::checker::SignatureFlags::PRIVATE); - - InvariantNameSet checks; - checks.insert("ModifierAccessValidForAll"); - const auto &messages = verifier.Verify(ast, checks); - ASSERT_EQ(messages.size(), 1); - - ASSERT_NE(checks.find(messages[0].Invariant()), checks.end()); - - impl_->DestroyContext(ctx); -} - -TEST_F(ASTVerifierTest, PrivateAccessTestNegative7) -{ - ASTVerifier verifier {Allocator()}; - - char const *text = R"( - class Base { - public a: int = 1; - public privateMethod() { - this.a = 2; - } - } - class Derived extends Base {} - function main(): void { - let derived: Base = new Derived(); - derived.privateMethod(); - } - )"; - es2panda_Context *ctx = impl_->CreateContextFromString(cfg_, text, "dummy.ets"); - impl_->ProceedToState(ctx, ES2PANDA_STATE_CHECKED); - ASSERT_EQ(impl_->ContextState(ctx), ES2PANDA_STATE_CHECKED); - - auto *ast = reinterpret_cast(impl_->ProgramAst(impl_->ContextProgram(ctx))); - - ast->AsETSScript() - ->Statements()[0] - ->AsClassDeclaration() - ->Definition() - ->AsClassDefinition() - ->Body()[1] - ->AsClassElement() - ->Value() - ->AsFunctionExpression() - ->Function() - ->AsScriptFunction() - ->Body() - ->AsBlockStatement() - ->Statements()[1] - ->AsExpressionStatement() - ->GetExpression() - ->AsCallExpression() - ->Signature() - ->AddSignatureFlag(ark::es2panda::checker::SignatureFlags::PRIVATE); - - InvariantNameSet checks; - checks.insert("ModifierAccessValidForAll"); - const auto &messages = verifier.Verify(ast, checks); - ASSERT_EQ(messages.size(), 1); - - ASSERT_NE(checks.find(messages[0].Invariant()), checks.end()); - - impl_->DestroyContext(ctx); -} - -TEST_F(ASTVerifierTest, ProtectedAccessTestCorrect) -{ - ASTVerifier verifier {Allocator()}; - - char const *text = R"( - class A { - public a: int = 1; - } - class B extends A { - public b: int = this.a; - } - )"; - es2panda_Context *ctx = impl_->CreateContextFromString(cfg_, text, "dummy.ets"); - impl_->ProceedToState(ctx, ES2PANDA_STATE_CHECKED); - ASSERT_EQ(impl_->ContextState(ctx), ES2PANDA_STATE_CHECKED); - - auto *ast = reinterpret_cast(impl_->ProgramAst(impl_->ContextProgram(ctx))); - - ast->AsETSScript() - ->Statements()[1] - ->AsClassDeclaration() - ->Definition() - ->AsClassDefinition() - ->Body()[0] - ->AsClassProperty() - ->AddModifier(ark::es2panda::ir::ModifierFlags::PROTECTED); - - InvariantNameSet checks; - checks.insert("ModifierAccessValidForAll"); - const auto &messages = verifier.Verify(ast, checks); - - ASSERT_EQ(messages.size(), 0); - - impl_->DestroyContext(ctx); -} - -TEST_F(ASTVerifierTest, ProtectedAccessTestNegative1) -{ - ASTVerifier verifier {Allocator()}; - - char const *text = R"( - class Base { - public a: int = 1; - } - function main(): void { - let base: Base = new Base(); - let a = base.a; - } - )"; - es2panda_Context *ctx = impl_->CreateContextFromString(cfg_, text, "dummy.ets"); - impl_->ProceedToState(ctx, ES2PANDA_STATE_CHECKED); - ASSERT_EQ(impl_->ContextState(ctx), ES2PANDA_STATE_CHECKED); - - auto *ast = reinterpret_cast(impl_->ProgramAst(impl_->ContextProgram(ctx))); - - ast->AsETSScript() - ->Statements()[1] - ->AsClassDeclaration() - ->Definition() - ->AsClassDefinition() - ->Body()[0] - ->AsClassProperty() - ->AddModifier(ark::es2panda::ir::ModifierFlags::PROTECTED); - - InvariantNameSet checks; - checks.insert("ModifierAccessValidForAll"); - const auto &messages = verifier.Verify(ast, checks); - ASSERT_EQ(messages.size(), 1); - - ASSERT_NE(checks.find(messages[0].Invariant()), checks.end()); - - impl_->DestroyContext(ctx); -} - -TEST_F(ASTVerifierTest, ProtectedAccessTestNegative2) -{ - ASTVerifier verifier {Allocator()}; - - char const *text = R"( - class Base { - public a: int = 1; - } - class Derived extends Base {} - function main(): void { - let derived: Derived = new Derived(); - let a = derived.a; - } - )"; - es2panda_Context *ctx = impl_->CreateContextFromString(cfg_, text, "dummy.ets"); - impl_->ProceedToState(ctx, ES2PANDA_STATE_CHECKED); - ASSERT_EQ(impl_->ContextState(ctx), ES2PANDA_STATE_CHECKED); - - auto *ast = reinterpret_cast(impl_->ProgramAst(impl_->ContextProgram(ctx))); - - ast->AsETSScript() - ->Statements()[1] - ->AsClassDeclaration() - ->Definition() - ->AsClassDefinition() - ->Body()[0] - ->AsClassProperty() - ->AddModifier(ark::es2panda::ir::ModifierFlags::PROTECTED); - - InvariantNameSet checks; - checks.insert("ModifierAccessValidForAll"); - const auto &messages = verifier.Verify(ast, checks); - ASSERT_EQ(messages.size(), 1); - - ASSERT_NE(checks.find(messages[0].Invariant()), checks.end()); - - impl_->DestroyContext(ctx); -} - -TEST_F(ASTVerifierTest, ProtectedAccessTestNegative3) -{ - ASTVerifier verifier {Allocator()}; - - char const *text = R"( - class Base { - public a: int = 1; - } - class Derived extends Base {} - function main(): void { - let derived: Base = new Derived(); - let a = derived.a; - } - )"; - es2panda_Context *ctx = impl_->CreateContextFromString(cfg_, text, "dummy.ets"); - impl_->ProceedToState(ctx, ES2PANDA_STATE_CHECKED); - ASSERT_EQ(impl_->ContextState(ctx), ES2PANDA_STATE_CHECKED); - - auto *ast = reinterpret_cast(impl_->ProgramAst(impl_->ContextProgram(ctx))); - - ast->AsETSScript() - ->Statements()[1] - ->AsClassDeclaration() - ->Definition() - ->AsClassDefinition() - ->Body()[0] - ->AsClassProperty() - ->AddModifier(ark::es2panda::ir::ModifierFlags::PROTECTED); - - InvariantNameSet checks; - checks.insert("ModifierAccessValidForAll"); - const auto &messages = verifier.Verify(ast, checks); - ASSERT_EQ(messages.size(), 1); - - ASSERT_NE(checks.find(messages[0].Invariant()), checks.end()); - - impl_->DestroyContext(ctx); -} - -TEST_F(ASTVerifierTest, ProtectedAccessTestNegative4) -{ - ASTVerifier verifier {Allocator()}; - - char const *text = R"( - class Base { - public a: int = 1; - public protectedMethod() { - this.a = 2; - } - } - function main(): void { - let base: Base = new Base(); - base.protectedMethod(); - } - )"; - es2panda_Context *ctx = impl_->CreateContextFromString(cfg_, text, "dummy.ets"); - impl_->ProceedToState(ctx, ES2PANDA_STATE_CHECKED); - ASSERT_EQ(impl_->ContextState(ctx), ES2PANDA_STATE_CHECKED); - - auto *ast = reinterpret_cast(impl_->ProgramAst(impl_->ContextProgram(ctx))); - - ast->AsETSScript() - ->Statements()[0] - ->AsClassDeclaration() - ->Definition() - ->AsClassDefinition() - ->Body()[1] - ->AsClassElement() - ->Value() - ->AsFunctionExpression() - ->Function() - ->AsScriptFunction() - ->Body() - ->AsBlockStatement() - ->Statements()[1] - ->AsExpressionStatement() - ->GetExpression() - ->AsCallExpression() - ->Signature() - ->AddSignatureFlag(ark::es2panda::checker::SignatureFlags::PROTECTED); - - InvariantNameSet checks; - checks.insert("ModifierAccessValidForAll"); - const auto &messages = verifier.Verify(ast, checks); - ASSERT_EQ(messages.size(), 1); - - ASSERT_NE(checks.find(messages[0].Invariant()), checks.end()); - - impl_->DestroyContext(ctx); -} - -TEST_F(ASTVerifierTest, ProtectedAccessTestNegative5) -{ - ASTVerifier verifier {Allocator()}; - - char const *text = R"( - class Base { - public a: int = 1; - public protectedMethod() { - this.a = 2; - } - } - class Derived extends Base {} - function main(): void { - let derived: Derived = new Derived(); - derived.protectedMethod(); - } - )"; - es2panda_Context *ctx = impl_->CreateContextFromString(cfg_, text, "dummy.ets"); - impl_->ProceedToState(ctx, ES2PANDA_STATE_CHECKED); - ASSERT_EQ(impl_->ContextState(ctx), ES2PANDA_STATE_CHECKED); - - auto *ast = reinterpret_cast(impl_->ProgramAst(impl_->ContextProgram(ctx))); - - ast->AsETSScript() - ->Statements()[0] - ->AsClassDeclaration() - ->Definition() - ->AsClassDefinition() - ->Body()[1] - ->AsClassElement() - ->Value() - ->AsFunctionExpression() - ->Function() - ->AsScriptFunction() - ->Body() - ->AsBlockStatement() - ->Statements()[1] - ->AsExpressionStatement() - ->GetExpression() - ->AsCallExpression() - ->Signature() - ->AddSignatureFlag(ark::es2panda::checker::SignatureFlags::PROTECTED); - - InvariantNameSet checks; - checks.insert("ModifierAccessValidForAll"); - const auto &messages = verifier.Verify(ast, checks); - ASSERT_EQ(messages.size(), 1); - - ASSERT_NE(checks.find(messages[0].Invariant()), checks.end()); - - impl_->DestroyContext(ctx); -} - -TEST_F(ASTVerifierTest, ProtectedAccessTestNegative6) -{ - ASTVerifier verifier {Allocator()}; - - char const *text = R"( - class Base { - public a: int = 1; - public protectedMethod() { - this.a = 2; - } - } - class Derived extends Base {} - function main(): void { - let derived: Base = new Derived(); - derived.protectedMethod(); - } - )"; - es2panda_Context *ctx = impl_->CreateContextFromString(cfg_, text, "dummy.ets"); - impl_->ProceedToState(ctx, ES2PANDA_STATE_CHECKED); - ASSERT_EQ(impl_->ContextState(ctx), ES2PANDA_STATE_CHECKED); - - auto *ast = reinterpret_cast(impl_->ProgramAst(impl_->ContextProgram(ctx))); - - ast->AsETSScript() - ->Statements()[0] - ->AsClassDeclaration() - ->Definition() - ->AsClassDefinition() - ->Body()[1] - ->AsClassElement() - ->Value() - ->AsFunctionExpression() - ->Function() - ->AsScriptFunction() - ->Body() - ->AsBlockStatement() - ->Statements()[1] - ->AsExpressionStatement() - ->GetExpression() - ->AsCallExpression() - ->Signature() - ->AddSignatureFlag(ark::es2panda::checker::SignatureFlags::PROTECTED); - - InvariantNameSet checks; - checks.insert("ModifierAccessValidForAll"); - - const auto &messages = verifier.Verify(ast, checks); - ASSERT_EQ(messages.size(), 1); - - ASSERT_NE(checks.find(messages[0].Invariant()), checks.end()); - - impl_->DestroyContext(ctx); -} diff --git a/ets2panda/test/unit/public/ast_verifier_test.h b/ets2panda/test/unit/public/ast_verifier_test.h new file mode 100644 index 0000000000..8fe3fb3e63 --- /dev/null +++ b/ets2panda/test/unit/public/ast_verifier_test.h @@ -0,0 +1,77 @@ +/** + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_UNIT_PUBLIC_AST_VERIFIER_TEST_H +#define TEST_UNIT_PUBLIC_AST_VERIFIER_TEST_H + +#include "compiler/core/ASTVerifier.h" +#include "test/utils/panda_executable_path_getter.h" + +#include + +class ASTVerifierTest : public testing::Test { +public: + ASTVerifierTest() + { + impl_ = es2panda_GetImpl(ES2PANDA_LIB_VERSION); + auto es2pandaPath = test::utils::PandaExecutablePathGetter {}.Get(); + // NOLINTNEXTLINE(modernize-avoid-c-arrays) + char const *argv[] = {es2pandaPath.c_str()}; + cfg_ = impl_->CreateConfig(1, argv); + allocator_ = new ark::ArenaAllocator(ark::SpaceType::SPACE_TYPE_COMPILER); + } + ~ASTVerifierTest() override + { + delete allocator_; + impl_->DestroyConfig(cfg_); + } + + ark::ArenaAllocator *Allocator() + { + return allocator_; + } + + NO_COPY_SEMANTIC(ASTVerifierTest); + NO_MOVE_SEMANTIC(ASTVerifierTest); + +protected: + template + Type *Tree(Type *node) + { + return node; + } + + template + Type *Node(Args &&...args) + { + return allocator_->New(std::forward(args)...); + } + + template + ark::ArenaVector Nodes(Args &&...args) + { + auto v = ark::ArenaVector {allocator_->Adapter()}; + v.insert(v.end(), {std::forward(args)...}); + return v; + } + + // NOLINTBEGIN(misc-non-private-member-variables-in-classes) + es2panda_Impl const *impl_; + es2panda_Config *cfg_; + ark::ArenaAllocator *allocator_; + // NOLINTEND(misc-non-private-member-variables-in-classes) +}; + +#endif // TEST_UNIT_PUBLIC_AST_VERIFIER_TEST_H diff --git a/ets2panda/test/unit/rest_parameter_flag_test.cpp b/ets2panda/test/unit/rest_parameter_flag_test.cpp index 62b3f40159..b92cf6453a 100644 --- a/ets2panda/test/unit/rest_parameter_flag_test.cpp +++ b/ets2panda/test/unit/rest_parameter_flag_test.cpp @@ -43,7 +43,7 @@ public: void SetCurrentProgram(std::string_view src) { int argc = 1; - const char *argv = "../../../bin/es2panda"; // NOLINT(modernize-avoid-c-arrays) + const char *argv = "../../../../bin/es2panda"; // NOLINT(modernize-avoid-c-arrays) static constexpr std::string_view FILE_NAME = "dummy.ets"; program_ = GetProgram(argc, &argv, FILE_NAME, src); -- Gitee From adb7973af397dc922cabc2fd7ea60b5a1a476778 Mon Sep 17 00:00:00 2001 From: Csaba Hurton Date: Tue, 12 Mar 2024 15:25:56 +0100 Subject: [PATCH 10/22] Make top-level statements valid entry points In case of a missing main() function in entry point source, an empty bodied main() is generated if there is at least one top-level statement. Fixes #15343 internal issue. Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/I97ZGD Testing: - created some new runtime tests to test new cases and the order of running: test/runtime/ets/entrypoint*.ets - some expected files of parser tests without main functions have to be updated. - one cts-test param has been updated to avoid clashing with an interface named `main` Signed-off-by: Csaba Hurton Change-Id: Ibbfd4362b6b57992e2a59fcd6ecc192d3b0c9cf5 --- .../ets/topLevelStmts/globalClassHandler.cpp | 87 +++++++++++------ .../ets/topLevelStmts/globalClassHandler.h | 8 +- .../compiler/ets/FunctionType5-expected.txt | 94 +++++++++++++++++++ ...ing_with_chaining_non_nullish-expected.txt | 94 +++++++++++++++++++ ...ndexing_with_chaining_nullish-expected.txt | 94 +++++++++++++++++++ ..._without_chaining_non_nullish-expected.txt | 94 +++++++++++++++++++ ...xing_without_chaining_nullish-expected.txt | 94 +++++++++++++++++++ .../ets/boxingConversion10-expected.txt | 94 +++++++++++++++++++ .../ets/boxingConversion5-expected.txt | 94 +++++++++++++++++++ .../ets/boxingConversion6-expected.txt | 94 +++++++++++++++++++ .../ets/boxingConversion7-expected.txt | 94 +++++++++++++++++++ .../ets/boxingConversion8-expected.txt | 94 +++++++++++++++++++ .../ets/boxingConversion9-expected.txt | 94 +++++++++++++++++++ .../ets/identifierReference2-expected.txt | 94 +++++++++++++++++++ .../ets/identifierReference3-expected.txt | 94 +++++++++++++++++++ .../ets/identifierReference4-expected.txt | 94 +++++++++++++++++++ .../compiler/ets/import_type-expected.txt | 94 +++++++++++++++++++ .../import_type_without_export-expected.txt | 94 +++++++++++++++++++ .../ets/inferTypeOfArray-expected.txt | 94 +++++++++++++++++++ .../inferTypeOfArrayNegative1-expected.txt | 94 +++++++++++++++++++ .../inferTypeOfArrayNegative2-expected.txt | 94 +++++++++++++++++++ .../inferTypeOfArrayNegative3-expected.txt | 94 +++++++++++++++++++ ...type_return_lambda_expression-expected.txt | 94 +++++++++++++++++++ .../ets/objectLiteralAbstract-expected.txt | 94 +++++++++++++++++++ .../ets/objectLiteralBadKey-expected.txt | 94 +++++++++++++++++++ .../objectLiteralInaccessibleKey-expected.txt | 94 +++++++++++++++++++ .../ets/objectLiteralInterface-expected.txt | 94 +++++++++++++++++++ .../objectLiteralNoContextType-expected.txt | 94 +++++++++++++++++++ ...ralNoParameterlessConstructor-expected.txt | 94 +++++++++++++++++++ .../ets/objectLiteralNoSuchKey-expected.txt | 94 +++++++++++++++++++ ...ctLiteralPrimitiveContextType-expected.txt | 94 +++++++++++++++++++ ...jectLiteralPrivateConstructor-expected.txt | 94 +++++++++++++++++++ .../ets/objectLiteralReadonlyKey-expected.txt | 94 +++++++++++++++++++ .../objectLiteralWrongValueType-expected.txt | 94 +++++++++++++++++++ .../ets/throwingFunctionCheck1-expected.txt | 94 +++++++++++++++++++ .../test/compiler/ets/typeAlias-expected.txt | 94 +++++++++++++++++++ .../parser/ets/Dollar_dollar_1-expected.txt | 94 +++++++++++++++++++ .../parser/ets/Dollar_dollar_3-expected.txt | 94 +++++++++++++++++++ .../parser/ets/Dollar_dollar_4-expected.txt | 94 +++++++++++++++++++ ets2panda/test/parser/ets/array-expected.txt | 94 +++++++++++++++++++ .../parser/ets/await_keyword-expected.txt | 94 +++++++++++++++++++ .../test/parser/ets/binary_op-expected.txt | 94 +++++++++++++++++++ ets2panda/test/parser/ets/blocks-expected.txt | 94 +++++++++++++++++++ .../parser/ets/blocks_scopes-expected.txt | 94 +++++++++++++++++++ .../test/parser/ets/boolean-expected.txt | 94 +++++++++++++++++++ .../parser/ets/cast_expressions5-expected.txt | 94 +++++++++++++++++++ .../parser/ets/class_instance-expected.txt | 94 +++++++++++++++++++ .../test/parser/ets/decl_infer-expected.txt | 94 +++++++++++++++++++ .../test/parser/ets/exports-expected.txt | 94 +++++++++++++++++++ ...unction_implicit_return_type3-expected.txt | 94 +++++++++++++++++++ .../ets/genericDefaultParam_1-expected.txt | 94 +++++++++++++++++++ .../ets/genericDefaultParam_3-expected.txt | 94 +++++++++++++++++++ .../test/parser/ets/identifier-expected.txt | 94 +++++++++++++++++++ .../parser/ets/import_folder-expected.txt | 94 +++++++++++++++++++ .../import_tests/diamond/test2-expected.txt | 94 +++++++++++++++++++ .../import_tests/diamond/test3-expected.txt | 94 +++++++++++++++++++ .../import_tests/diamond/test4-expected.txt | 94 +++++++++++++++++++ .../import_alias/export-expected.txt | 94 +++++++++++++++++++ .../ets/import_tests/import_all-expected.txt | 94 +++++++++++++++++++ .../import_all_alias_1-expected.txt | 94 +++++++++++++++++++ .../import_all_alias_2-expected.txt | 94 +++++++++++++++++++ .../import_all_type_alias-expected.txt | 94 +++++++++++++++++++ .../import_extension_1-expected.txt | 94 +++++++++++++++++++ .../import_extension_2-expected.txt | 94 +++++++++++++++++++ .../import_tests/import_name_1-expected.txt | 94 +++++++++++++++++++ .../import_tests/import_name_2-expected.txt | 94 +++++++++++++++++++ .../import_name_alias_1-expected.txt | 94 +++++++++++++++++++ .../import_name_alias_2-expected.txt | 94 +++++++++++++++++++ .../import_relative_path-expected.txt | 94 +++++++++++++++++++ .../import_several_1-expected.txt | 94 +++++++++++++++++++ .../import_several_2-expected.txt | 94 +++++++++++++++++++ .../import_several_3-expected.txt | 94 +++++++++++++++++++ .../import_several_4-expected.txt | 94 +++++++++++++++++++ .../import_several_5-expected.txt | 94 +++++++++++++++++++ .../import_several_6-expected.txt | 94 +++++++++++++++++++ .../import_several_7-expected.txt | 94 +++++++++++++++++++ .../relative_import/alias2-expected.txt | 94 +++++++++++++++++++ .../parser/ets/index_expressions-expected.txt | 94 +++++++++++++++++++ .../ets/lambda_import_alias_1-2-expected.txt | 94 +++++++++++++++++++ .../launch_with_call_expression-expected.txt | 94 +++++++++++++++++++ .../test/parser/ets/null_invalid-expected.txt | 94 +++++++++++++++++++ .../test/parser/ets/null_valid-expected.txt | 94 +++++++++++++++++++ .../ets/re_export/diamond/A-expected.txt | 94 +++++++++++++++++++ .../ets/re_export/import_index-expected.txt | 94 +++++++++++++++++++ .../ets/re_export/import_index_2-expected.txt | 94 +++++++++++++++++++ .../test/parser/ets/simple_types-expected.txt | 94 +++++++++++++++++++ ets2panda/test/parser/ets/string-expected.txt | 94 +++++++++++++++++++ .../test/parser/ets/ternary-expected.txt | 94 +++++++++++++++++++ .../ets/test_jsvalue_get_double-expected.txt | 94 +++++++++++++++++++ .../test_jsvalue_get_property_1-expected.txt | 94 +++++++++++++++++++ .../test_jsvalue_get_property_2-expected.txt | 94 +++++++++++++++++++ .../parser/ets/test_type_alias9-expected.txt | 94 +++++++++++++++++++ .../throwsRethrowsAsVariables-expected.txt | 94 +++++++++++++++++++ ...ot_transform_trailing_block_1-expected.txt | 94 +++++++++++++++++++ .../test/parser/ets/tuple_type_1-expected.txt | 94 +++++++++++++++++++ .../test/parser/ets/unary_op-expected.txt | 94 +++++++++++++++++++ .../parser/ets/user_defined_22-expected.txt | 94 +++++++++++++++++++ ...trypoint-with-main-and-top-level-stmts.ets | 22 +++++ .../test/runtime/ets/entrypoint-with-main.ets | 19 ++++ .../test/runtime/ets/entrypoint-wout-main.ets | 18 ++++ 100 files changed, 9048 insertions(+), 36 deletions(-) create mode 100644 ets2panda/test/runtime/ets/entrypoint-with-main-and-top-level-stmts.ets create mode 100644 ets2panda/test/runtime/ets/entrypoint-with-main.ets create mode 100644 ets2panda/test/runtime/ets/entrypoint-wout-main.ets diff --git a/ets2panda/compiler/lowering/ets/topLevelStmts/globalClassHandler.cpp b/ets2panda/compiler/lowering/ets/topLevelStmts/globalClassHandler.cpp index e8a5d5e635..506adef2d0 100644 --- a/ets2panda/compiler/lowering/ets/topLevelStmts/globalClassHandler.cpp +++ b/ets2panda/compiler/lowering/ets/topLevelStmts/globalClassHandler.cpp @@ -34,6 +34,17 @@ namespace ark::es2panda::compiler { using util::NodeAllocator; +static bool MainFunctionExists(const ArenaVector &statements) +{ + for (auto stmt : statements) { + if (stmt->IsFunctionDeclaration() && + stmt->AsFunctionDeclaration()->Function()->Id()->Name().Is(compiler::Signatures::MAIN)) { + return true; + } + } + return false; +} + void GlobalClassHandler::InitGlobalClass(const ArenaVector &programs) { if (programs.empty()) { @@ -55,53 +66,57 @@ void GlobalClassHandler::InitGlobalClass(const ArenaVector &p }; ArenaVector statements(allocator_->Adapter()); + bool mainExists = false; + bool topLevelStatementsExist = false; for (auto program : programs) { program->Ast()->IterateRecursively(addCCtor); + if (program->IsEntryPoint() && !mainExists && MainFunctionExists(program->Ast()->Statements())) { + mainExists = true; + } auto stmts = MakeGlobalStatements(program->Ast(), globalClass, !program->GetPackageName().Empty()); + if (!topLevelStatementsExist && !stmts.empty()) { + topLevelStatementsExist = true; + } statements.emplace_back(GlobalStmts {program, std::move(stmts)}); program->SetGlobalClass(globalClass); } - InitCallToCCTOR(programs.front(), statements); -} - -ir::MethodDefinition *GlobalClassHandler::CreateAndFillInitMethod(const ArenaVector &initStatements) -{ - auto initMethod = CreateInitMethod(); - - for (const auto &stmts : initStatements) { - for (auto stmt : stmts.statements) { - initMethod->Function()->Body()->AsBlockStatement()->Statements().emplace_back(stmt); - stmt->SetParent(initMethod->Function()->Body()); - } - } - return initMethod; + InitCallToCCTOR(programs.front(), statements, mainExists, topLevelStatementsExist); } -ir::MethodDefinition *GlobalClassHandler::CreateInitMethod() +static ir::MethodDefinition *CreateAndFillTopLevelMethod( + const ArenaVector &initStatements, ArenaAllocator *allocator, + const std::string_view name) { const auto functionFlags = ir::ScriptFunctionFlags::NONE; const auto functionModifiers = ir::ModifierFlags::STATIC | ir::ModifierFlags::PUBLIC; - auto *initIdent = NodeAllocator::Alloc(allocator_, INIT_NAME, allocator_); + auto *ident = NodeAllocator::Alloc(allocator, name, allocator); - ArenaVector params(allocator_->Adapter()); + ArenaVector params(allocator->Adapter()); - ArenaVector statements(allocator_->Adapter()); - auto *initBody = NodeAllocator::Alloc(allocator_, allocator_, std::move(statements)); + ArenaVector statements(allocator->Adapter()); + auto *body = NodeAllocator::Alloc(allocator, allocator, std::move(statements)); auto funcSignature = ir::FunctionSignature(nullptr, std::move(params), nullptr); - auto *initFunc = NodeAllocator::Alloc( - allocator_, allocator_, + auto *func = NodeAllocator::Alloc( + allocator, allocator, ir::ScriptFunction::ScriptFunctionData { - initBody, std::move(funcSignature), functionFlags, {}, false, Language(Language::Id::ETS)}); + body, std::move(funcSignature), functionFlags, {}, false, Language(Language::Id::ETS)}); + + func->SetIdent(ident); + func->AddModifier(functionModifiers); - initFunc->SetIdent(initIdent); - initFunc->AddModifier(functionModifiers); + auto *funcExpr = NodeAllocator::Alloc(allocator, func); + auto methodDef = NodeAllocator::Alloc(allocator, ir::MethodDefinitionKind::METHOD, + ident->Clone(allocator, nullptr)->AsExpression(), + funcExpr, functionModifiers, allocator, false); - auto *funcExpr = NodeAllocator::Alloc(allocator_, initFunc); - auto methodDef = NodeAllocator::Alloc(allocator_, ir::MethodDefinitionKind::METHOD, - initIdent->Clone(allocator_, nullptr)->AsExpression(), - funcExpr, functionModifiers, allocator_, false); + for (const auto &stmts : initStatements) { + for (auto stmt : stmts.statements) { + methodDef->Function()->Body()->AsBlockStatement()->Statements().emplace_back(stmt); + stmt->SetParent(methodDef->Function()->Body()); + } + } return methodDef; } @@ -211,7 +226,8 @@ ir::ClassDeclaration *GlobalClassHandler::CreateGlobalClass() return classDecl; } -void GlobalClassHandler::InitCallToCCTOR(parser::Program *program, const ArenaVector &initStatements) +void GlobalClassHandler::InitCallToCCTOR(parser::Program *program, const ArenaVector &initStatements, + bool mainExists, bool topLevelStatementsExist) { auto globalClass = program->GlobalClass(); auto globalDecl = globalClass->Parent()->AsClassDeclaration(); @@ -220,7 +236,12 @@ void GlobalClassHandler::InitCallToCCTOR(parser::Program *program, const ArenaVe InitGlobalClass(globalClass, program->Kind()); auto &globalBody = globalClass->Body(); if (program->GetPackageName().Empty() && program->Kind() != parser::ScriptKind::STDLIB) { - ir::MethodDefinition *initMethod = CreateAndFillInitMethod(initStatements); + ir::MethodDefinition *initMethod = CreateAndFillTopLevelMethod(initStatements, allocator_, INIT_NAME); + ir::MethodDefinition *mainMethod = nullptr; + if (!mainExists && topLevelStatementsExist) { + const ArenaVector emptyStatements(allocator_->Adapter()); + mainMethod = CreateAndFillTopLevelMethod(emptyStatements, allocator_, compiler::Signatures::MAIN); + } if (initMethod != nullptr) { initMethod->SetParent(program->GlobalClass()); globalBody.insert(globalBody.begin(), initMethod); @@ -228,7 +249,11 @@ void GlobalClassHandler::InitCallToCCTOR(parser::Program *program, const ArenaVe AddInitCall(program->GlobalClass(), initMethod); } } + if (mainMethod != nullptr) { + mainMethod->SetParent(program->GlobalClass()); + globalBody.insert(globalBody.begin(), mainMethod); + } } } -} // namespace ark::es2panda::compiler \ No newline at end of file +} // namespace ark::es2panda::compiler diff --git a/ets2panda/compiler/lowering/ets/topLevelStmts/globalClassHandler.h b/ets2panda/compiler/lowering/ets/topLevelStmts/globalClassHandler.h index 8433d0822e..491838311c 100644 --- a/ets2panda/compiler/lowering/ets/topLevelStmts/globalClassHandler.h +++ b/ets2panda/compiler/lowering/ets/topLevelStmts/globalClassHandler.h @@ -23,12 +23,11 @@ namespace ark::es2panda::compiler { class GlobalClassHandler { +public: struct GlobalStmts { parser::Program *program; ArenaVector statements; }; - -public: explicit GlobalClassHandler(ArenaAllocator *allocator) : allocator_(allocator) {}; /** @@ -44,7 +43,8 @@ private: * @param program program of module * @param init_statements statements which should be executed */ - void InitCallToCCTOR(parser::Program *program, const ArenaVector &initStatements); + void InitCallToCCTOR(parser::Program *program, const ArenaVector &initStatements, + bool mainExists = false, bool topLevelStatementsExist = false); private: void InitGlobalClass(ir::ClassDefinition *classDef, parser::ScriptKind scriptKind); @@ -62,8 +62,6 @@ private: ArenaVector MakeGlobalStatements(ir::BlockStatement *globalStmts, ir::ClassDefinition *classDef, bool isPackage); - ir::MethodDefinition *CreateAndFillInitMethod(const ArenaVector &initStatements); - ir::MethodDefinition *CreateInitMethod(); void AddInitCall(ir::ClassDefinition *globalClass, ir::MethodDefinition *initMethod); ir::Identifier *RefIdent(const util::StringView &name); diff --git a/ets2panda/test/compiler/ets/FunctionType5-expected.txt b/ets2panda/test/compiler/ets/FunctionType5-expected.txt index 1a02058a93..d1fe63d93d 100644 --- a/ets2panda/test/compiler/ets/FunctionType5-expected.txt +++ b/ets2panda/test/compiler/ets/FunctionType5-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/compiler/ets/array_indexing_with_chaining_non_nullish-expected.txt b/ets2panda/test/compiler/ets/array_indexing_with_chaining_non_nullish-expected.txt index fbcb2d6d44..67feb0b46a 100644 --- a/ets2panda/test/compiler/ets/array_indexing_with_chaining_non_nullish-expected.txt +++ b/ets2panda/test/compiler/ets/array_indexing_with_chaining_non_nullish-expected.txt @@ -159,6 +159,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/compiler/ets/array_indexing_with_chaining_nullish-expected.txt b/ets2panda/test/compiler/ets/array_indexing_with_chaining_nullish-expected.txt index 8e44cb782b..fc7f5b71f3 100644 --- a/ets2panda/test/compiler/ets/array_indexing_with_chaining_nullish-expected.txt +++ b/ets2panda/test/compiler/ets/array_indexing_with_chaining_nullish-expected.txt @@ -159,6 +159,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/compiler/ets/array_indexing_without_chaining_non_nullish-expected.txt b/ets2panda/test/compiler/ets/array_indexing_without_chaining_non_nullish-expected.txt index e3d9e2b92f..64368b82a2 100644 --- a/ets2panda/test/compiler/ets/array_indexing_without_chaining_non_nullish-expected.txt +++ b/ets2panda/test/compiler/ets/array_indexing_without_chaining_non_nullish-expected.txt @@ -159,6 +159,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/compiler/ets/array_indexing_without_chaining_nullish-expected.txt b/ets2panda/test/compiler/ets/array_indexing_without_chaining_nullish-expected.txt index 4331d93569..239799c8e9 100644 --- a/ets2panda/test/compiler/ets/array_indexing_without_chaining_nullish-expected.txt +++ b/ets2panda/test/compiler/ets/array_indexing_without_chaining_nullish-expected.txt @@ -159,6 +159,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/compiler/ets/boxingConversion10-expected.txt b/ets2panda/test/compiler/ets/boxingConversion10-expected.txt index 305e19af47..4bcb71a8f5 100644 --- a/ets2panda/test/compiler/ets/boxingConversion10-expected.txt +++ b/ets2panda/test/compiler/ets/boxingConversion10-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/compiler/ets/boxingConversion5-expected.txt b/ets2panda/test/compiler/ets/boxingConversion5-expected.txt index 23d54930c8..56650da869 100644 --- a/ets2panda/test/compiler/ets/boxingConversion5-expected.txt +++ b/ets2panda/test/compiler/ets/boxingConversion5-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/compiler/ets/boxingConversion6-expected.txt b/ets2panda/test/compiler/ets/boxingConversion6-expected.txt index 28d3661654..ed340f5d6c 100644 --- a/ets2panda/test/compiler/ets/boxingConversion6-expected.txt +++ b/ets2panda/test/compiler/ets/boxingConversion6-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/compiler/ets/boxingConversion7-expected.txt b/ets2panda/test/compiler/ets/boxingConversion7-expected.txt index 0dbd157105..b8192a7bf9 100644 --- a/ets2panda/test/compiler/ets/boxingConversion7-expected.txt +++ b/ets2panda/test/compiler/ets/boxingConversion7-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/compiler/ets/boxingConversion8-expected.txt b/ets2panda/test/compiler/ets/boxingConversion8-expected.txt index b88cf9cea5..494a5c5647 100644 --- a/ets2panda/test/compiler/ets/boxingConversion8-expected.txt +++ b/ets2panda/test/compiler/ets/boxingConversion8-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/compiler/ets/boxingConversion9-expected.txt b/ets2panda/test/compiler/ets/boxingConversion9-expected.txt index ac8bfdfce8..dd96498ac6 100644 --- a/ets2panda/test/compiler/ets/boxingConversion9-expected.txt +++ b/ets2panda/test/compiler/ets/boxingConversion9-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/compiler/ets/identifierReference2-expected.txt b/ets2panda/test/compiler/ets/identifierReference2-expected.txt index e533c263b4..42b3cf05de 100644 --- a/ets2panda/test/compiler/ets/identifierReference2-expected.txt +++ b/ets2panda/test/compiler/ets/identifierReference2-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/compiler/ets/identifierReference3-expected.txt b/ets2panda/test/compiler/ets/identifierReference3-expected.txt index 14afe7479d..106853cf9a 100644 --- a/ets2panda/test/compiler/ets/identifierReference3-expected.txt +++ b/ets2panda/test/compiler/ets/identifierReference3-expected.txt @@ -323,6 +323,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/compiler/ets/identifierReference4-expected.txt b/ets2panda/test/compiler/ets/identifierReference4-expected.txt index 8dc988a332..184b2438b9 100644 --- a/ets2panda/test/compiler/ets/identifierReference4-expected.txt +++ b/ets2panda/test/compiler/ets/identifierReference4-expected.txt @@ -577,6 +577,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/compiler/ets/import_type-expected.txt b/ets2panda/test/compiler/ets/import_type-expected.txt index 8c41b088cf..5be8032eba 100644 --- a/ets2panda/test/compiler/ets/import_type-expected.txt +++ b/ets2panda/test/compiler/ets/import_type-expected.txt @@ -372,6 +372,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/compiler/ets/import_type_without_export-expected.txt b/ets2panda/test/compiler/ets/import_type_without_export-expected.txt index 7e54c7d7b6..3eeb537ae2 100644 --- a/ets2panda/test/compiler/ets/import_type_without_export-expected.txt +++ b/ets2panda/test/compiler/ets/import_type_without_export-expected.txt @@ -137,6 +137,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/compiler/ets/inferTypeOfArray-expected.txt b/ets2panda/test/compiler/ets/inferTypeOfArray-expected.txt index bd192ee2e3..504d76b4bb 100644 --- a/ets2panda/test/compiler/ets/inferTypeOfArray-expected.txt +++ b/ets2panda/test/compiler/ets/inferTypeOfArray-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/compiler/ets/inferTypeOfArrayNegative1-expected.txt b/ets2panda/test/compiler/ets/inferTypeOfArrayNegative1-expected.txt index 7d12e35a6e..ac77ac91d9 100644 --- a/ets2panda/test/compiler/ets/inferTypeOfArrayNegative1-expected.txt +++ b/ets2panda/test/compiler/ets/inferTypeOfArrayNegative1-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/compiler/ets/inferTypeOfArrayNegative2-expected.txt b/ets2panda/test/compiler/ets/inferTypeOfArrayNegative2-expected.txt index 35a019dc88..1de3b1358f 100644 --- a/ets2panda/test/compiler/ets/inferTypeOfArrayNegative2-expected.txt +++ b/ets2panda/test/compiler/ets/inferTypeOfArrayNegative2-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/compiler/ets/inferTypeOfArrayNegative3-expected.txt b/ets2panda/test/compiler/ets/inferTypeOfArrayNegative3-expected.txt index 054d89e7f5..eff5986167 100644 --- a/ets2panda/test/compiler/ets/inferTypeOfArrayNegative3-expected.txt +++ b/ets2panda/test/compiler/ets/inferTypeOfArrayNegative3-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_return_lambda_expression-expected.txt b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_return_lambda_expression-expected.txt index f2b0e8782a..8649b7d478 100644 --- a/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_return_lambda_expression-expected.txt +++ b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_return_lambda_expression-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/compiler/ets/objectLiteralAbstract-expected.txt b/ets2panda/test/compiler/ets/objectLiteralAbstract-expected.txt index 5db12240c7..178d964164 100644 --- a/ets2panda/test/compiler/ets/objectLiteralAbstract-expected.txt +++ b/ets2panda/test/compiler/ets/objectLiteralAbstract-expected.txt @@ -159,6 +159,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/compiler/ets/objectLiteralBadKey-expected.txt b/ets2panda/test/compiler/ets/objectLiteralBadKey-expected.txt index 939b83aee6..6c1f4d0fbe 100644 --- a/ets2panda/test/compiler/ets/objectLiteralBadKey-expected.txt +++ b/ets2panda/test/compiler/ets/objectLiteralBadKey-expected.txt @@ -159,6 +159,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/compiler/ets/objectLiteralInaccessibleKey-expected.txt b/ets2panda/test/compiler/ets/objectLiteralInaccessibleKey-expected.txt index 169a5fc028..9d37e6edfa 100644 --- a/ets2panda/test/compiler/ets/objectLiteralInaccessibleKey-expected.txt +++ b/ets2panda/test/compiler/ets/objectLiteralInaccessibleKey-expected.txt @@ -208,6 +208,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/compiler/ets/objectLiteralInterface-expected.txt b/ets2panda/test/compiler/ets/objectLiteralInterface-expected.txt index 5cd0f4bddf..40bf6669c9 100644 --- a/ets2panda/test/compiler/ets/objectLiteralInterface-expected.txt +++ b/ets2panda/test/compiler/ets/objectLiteralInterface-expected.txt @@ -65,6 +65,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/compiler/ets/objectLiteralNoContextType-expected.txt b/ets2panda/test/compiler/ets/objectLiteralNoContextType-expected.txt index 1d661df1c8..2322196a59 100644 --- a/ets2panda/test/compiler/ets/objectLiteralNoContextType-expected.txt +++ b/ets2panda/test/compiler/ets/objectLiteralNoContextType-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/compiler/ets/objectLiteralNoParameterlessConstructor-expected.txt b/ets2panda/test/compiler/ets/objectLiteralNoParameterlessConstructor-expected.txt index 4ca426fbcd..81e600de0c 100644 --- a/ets2panda/test/compiler/ets/objectLiteralNoParameterlessConstructor-expected.txt +++ b/ets2panda/test/compiler/ets/objectLiteralNoParameterlessConstructor-expected.txt @@ -202,6 +202,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/compiler/ets/objectLiteralNoSuchKey-expected.txt b/ets2panda/test/compiler/ets/objectLiteralNoSuchKey-expected.txt index 5af2594c5c..0318130a1b 100644 --- a/ets2panda/test/compiler/ets/objectLiteralNoSuchKey-expected.txt +++ b/ets2panda/test/compiler/ets/objectLiteralNoSuchKey-expected.txt @@ -159,6 +159,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/compiler/ets/objectLiteralPrimitiveContextType-expected.txt b/ets2panda/test/compiler/ets/objectLiteralPrimitiveContextType-expected.txt index 6113219ccd..623df47693 100644 --- a/ets2panda/test/compiler/ets/objectLiteralPrimitiveContextType-expected.txt +++ b/ets2panda/test/compiler/ets/objectLiteralPrimitiveContextType-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/compiler/ets/objectLiteralPrivateConstructor-expected.txt b/ets2panda/test/compiler/ets/objectLiteralPrivateConstructor-expected.txt index 47d07f348f..f454f752f7 100644 --- a/ets2panda/test/compiler/ets/objectLiteralPrivateConstructor-expected.txt +++ b/ets2panda/test/compiler/ets/objectLiteralPrivateConstructor-expected.txt @@ -160,6 +160,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/compiler/ets/objectLiteralReadonlyKey-expected.txt b/ets2panda/test/compiler/ets/objectLiteralReadonlyKey-expected.txt index b919165f8e..71e5cb1cc7 100644 --- a/ets2panda/test/compiler/ets/objectLiteralReadonlyKey-expected.txt +++ b/ets2panda/test/compiler/ets/objectLiteralReadonlyKey-expected.txt @@ -208,6 +208,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/compiler/ets/objectLiteralWrongValueType-expected.txt b/ets2panda/test/compiler/ets/objectLiteralWrongValueType-expected.txt index e741bd36d0..225edd7890 100644 --- a/ets2panda/test/compiler/ets/objectLiteralWrongValueType-expected.txt +++ b/ets2panda/test/compiler/ets/objectLiteralWrongValueType-expected.txt @@ -208,6 +208,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/compiler/ets/throwingFunctionCheck1-expected.txt b/ets2panda/test/compiler/ets/throwingFunctionCheck1-expected.txt index 5909a76bf2..a8256dfb89 100644 --- a/ets2panda/test/compiler/ets/throwingFunctionCheck1-expected.txt +++ b/ets2panda/test/compiler/ets/throwingFunctionCheck1-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/compiler/ets/typeAlias-expected.txt b/ets2panda/test/compiler/ets/typeAlias-expected.txt index 2f9467386e..d1424726b9 100644 --- a/ets2panda/test/compiler/ets/typeAlias-expected.txt +++ b/ets2panda/test/compiler/ets/typeAlias-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/parser/ets/Dollar_dollar_1-expected.txt b/ets2panda/test/parser/ets/Dollar_dollar_1-expected.txt index e3d9bb2699..38e65071d5 100644 --- a/ets2panda/test/parser/ets/Dollar_dollar_1-expected.txt +++ b/ets2panda/test/parser/ets/Dollar_dollar_1-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/parser/ets/Dollar_dollar_3-expected.txt b/ets2panda/test/parser/ets/Dollar_dollar_3-expected.txt index d4d7953e1d..9a398fbcf6 100644 --- a/ets2panda/test/parser/ets/Dollar_dollar_3-expected.txt +++ b/ets2panda/test/parser/ets/Dollar_dollar_3-expected.txt @@ -159,6 +159,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/parser/ets/Dollar_dollar_4-expected.txt b/ets2panda/test/parser/ets/Dollar_dollar_4-expected.txt index ad15034d81..33a4ba9a82 100644 --- a/ets2panda/test/parser/ets/Dollar_dollar_4-expected.txt +++ b/ets2panda/test/parser/ets/Dollar_dollar_4-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/parser/ets/array-expected.txt b/ets2panda/test/parser/ets/array-expected.txt index 1d9580dc49..1235cfe436 100644 --- a/ets2panda/test/parser/ets/array-expected.txt +++ b/ets2panda/test/parser/ets/array-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/parser/ets/await_keyword-expected.txt b/ets2panda/test/parser/ets/await_keyword-expected.txt index 2e37ff1d07..374ab1867c 100644 --- a/ets2panda/test/parser/ets/await_keyword-expected.txt +++ b/ets2panda/test/parser/ets/await_keyword-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/parser/ets/binary_op-expected.txt b/ets2panda/test/parser/ets/binary_op-expected.txt index 1545494a35..79d30ca925 100644 --- a/ets2panda/test/parser/ets/binary_op-expected.txt +++ b/ets2panda/test/parser/ets/binary_op-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/parser/ets/blocks-expected.txt b/ets2panda/test/parser/ets/blocks-expected.txt index 137bd892a8..34e2ae3bcd 100644 --- a/ets2panda/test/parser/ets/blocks-expected.txt +++ b/ets2panda/test/parser/ets/blocks-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/parser/ets/blocks_scopes-expected.txt b/ets2panda/test/parser/ets/blocks_scopes-expected.txt index dcfccf797d..4f4e726209 100644 --- a/ets2panda/test/parser/ets/blocks_scopes-expected.txt +++ b/ets2panda/test/parser/ets/blocks_scopes-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/parser/ets/boolean-expected.txt b/ets2panda/test/parser/ets/boolean-expected.txt index bb679ea24a..8c5380ff44 100644 --- a/ets2panda/test/parser/ets/boolean-expected.txt +++ b/ets2panda/test/parser/ets/boolean-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/parser/ets/cast_expressions5-expected.txt b/ets2panda/test/parser/ets/cast_expressions5-expected.txt index 4ceb6d64d9..b06feafb32 100644 --- a/ets2panda/test/parser/ets/cast_expressions5-expected.txt +++ b/ets2panda/test/parser/ets/cast_expressions5-expected.txt @@ -593,6 +593,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/parser/ets/class_instance-expected.txt b/ets2panda/test/parser/ets/class_instance-expected.txt index ec3b1a26ab..ba10da040b 100644 --- a/ets2panda/test/parser/ets/class_instance-expected.txt +++ b/ets2panda/test/parser/ets/class_instance-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/parser/ets/decl_infer-expected.txt b/ets2panda/test/parser/ets/decl_infer-expected.txt index effb99d39e..f5a56f968b 100644 --- a/ets2panda/test/parser/ets/decl_infer-expected.txt +++ b/ets2panda/test/parser/ets/decl_infer-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/parser/ets/exports-expected.txt b/ets2panda/test/parser/ets/exports-expected.txt index 594900d4d1..0c256ff7d4 100644 --- a/ets2panda/test/parser/ets/exports-expected.txt +++ b/ets2panda/test/parser/ets/exports-expected.txt @@ -243,6 +243,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/parser/ets/function_implicit_return_type3-expected.txt b/ets2panda/test/parser/ets/function_implicit_return_type3-expected.txt index d3dab3e156..17becf8374 100644 --- a/ets2panda/test/parser/ets/function_implicit_return_type3-expected.txt +++ b/ets2panda/test/parser/ets/function_implicit_return_type3-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/parser/ets/genericDefaultParam_1-expected.txt b/ets2panda/test/parser/ets/genericDefaultParam_1-expected.txt index 8387f49f9a..4e691dcff7 100644 --- a/ets2panda/test/parser/ets/genericDefaultParam_1-expected.txt +++ b/ets2panda/test/parser/ets/genericDefaultParam_1-expected.txt @@ -1401,6 +1401,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/parser/ets/genericDefaultParam_3-expected.txt b/ets2panda/test/parser/ets/genericDefaultParam_3-expected.txt index 03c646f0d8..68b94563bb 100644 --- a/ets2panda/test/parser/ets/genericDefaultParam_3-expected.txt +++ b/ets2panda/test/parser/ets/genericDefaultParam_3-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/parser/ets/identifier-expected.txt b/ets2panda/test/parser/ets/identifier-expected.txt index 70df781844..1d5744de88 100644 --- a/ets2panda/test/parser/ets/identifier-expected.txt +++ b/ets2panda/test/parser/ets/identifier-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/parser/ets/import_folder-expected.txt b/ets2panda/test/parser/ets/import_folder-expected.txt index 792732b6a3..60694fa346 100644 --- a/ets2panda/test/parser/ets/import_folder-expected.txt +++ b/ets2panda/test/parser/ets/import_folder-expected.txt @@ -79,6 +79,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/parser/ets/import_tests/diamond/test2-expected.txt b/ets2panda/test/parser/ets/import_tests/diamond/test2-expected.txt index d799f95d2a..6c23ec8e93 100644 --- a/ets2panda/test/parser/ets/import_tests/diamond/test2-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/diamond/test2-expected.txt @@ -94,6 +94,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/parser/ets/import_tests/diamond/test3-expected.txt b/ets2panda/test/parser/ets/import_tests/diamond/test3-expected.txt index ce83883aad..b03a89b18a 100644 --- a/ets2panda/test/parser/ets/import_tests/diamond/test3-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/diamond/test3-expected.txt @@ -94,6 +94,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/parser/ets/import_tests/diamond/test4-expected.txt b/ets2panda/test/parser/ets/import_tests/diamond/test4-expected.txt index 96bbb0c8bb..9dc67756a1 100644 --- a/ets2panda/test/parser/ets/import_tests/diamond/test4-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/diamond/test4-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/parser/ets/import_tests/import_alias/export-expected.txt b/ets2panda/test/parser/ets/import_tests/import_alias/export-expected.txt index 73374c4ffc..99bb065816 100644 --- a/ets2panda/test/parser/ets/import_tests/import_alias/export-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_alias/export-expected.txt @@ -484,6 +484,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/parser/ets/import_tests/import_all-expected.txt b/ets2panda/test/parser/ets/import_tests/import_all-expected.txt index fff159977d..e807e2aaf0 100755 --- a/ets2panda/test/parser/ets/import_tests/import_all-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_all-expected.txt @@ -136,6 +136,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/parser/ets/import_tests/import_all_alias_1-expected.txt b/ets2panda/test/parser/ets/import_tests/import_all_alias_1-expected.txt index 1079f0ac8a..a5c4b5cc54 100644 --- a/ets2panda/test/parser/ets/import_tests/import_all_alias_1-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_all_alias_1-expected.txt @@ -79,6 +79,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/parser/ets/import_tests/import_all_alias_2-expected.txt b/ets2panda/test/parser/ets/import_tests/import_all_alias_2-expected.txt index 623e169b05..a1cd11efce 100755 --- a/ets2panda/test/parser/ets/import_tests/import_all_alias_2-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_all_alias_2-expected.txt @@ -79,6 +79,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/parser/ets/import_tests/import_all_type_alias-expected.txt b/ets2panda/test/parser/ets/import_tests/import_all_type_alias-expected.txt index c58e5d0af3..55f0875f8b 100644 --- a/ets2panda/test/parser/ets/import_tests/import_all_type_alias-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_all_type_alias-expected.txt @@ -79,6 +79,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/parser/ets/import_tests/import_extension/import_extension_1-expected.txt b/ets2panda/test/parser/ets/import_tests/import_extension/import_extension_1-expected.txt index 1192ec0859..5ca84eea3f 100644 --- a/ets2panda/test/parser/ets/import_tests/import_extension/import_extension_1-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_extension/import_extension_1-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/parser/ets/import_tests/import_extension/import_extension_2-expected.txt b/ets2panda/test/parser/ets/import_tests/import_extension/import_extension_2-expected.txt index db763b9353..5d57b716de 100644 --- a/ets2panda/test/parser/ets/import_tests/import_extension/import_extension_2-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_extension/import_extension_2-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/parser/ets/import_tests/import_name_1-expected.txt b/ets2panda/test/parser/ets/import_tests/import_name_1-expected.txt index 40e1725683..0463fe6654 100755 --- a/ets2panda/test/parser/ets/import_tests/import_name_1-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_name_1-expected.txt @@ -180,6 +180,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/parser/ets/import_tests/import_name_2-expected.txt b/ets2panda/test/parser/ets/import_tests/import_name_2-expected.txt index f994a5367e..6778f92a4f 100755 --- a/ets2panda/test/parser/ets/import_tests/import_name_2-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_name_2-expected.txt @@ -137,6 +137,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/parser/ets/import_tests/import_name_alias_1-expected.txt b/ets2panda/test/parser/ets/import_tests/import_name_alias_1-expected.txt index 5206b86417..ebba4f7344 100755 --- a/ets2panda/test/parser/ets/import_tests/import_name_alias_1-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_name_alias_1-expected.txt @@ -180,6 +180,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/parser/ets/import_tests/import_name_alias_2-expected.txt b/ets2panda/test/parser/ets/import_tests/import_name_alias_2-expected.txt index d072593243..0527544f35 100755 --- a/ets2panda/test/parser/ets/import_tests/import_name_alias_2-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_name_alias_2-expected.txt @@ -137,6 +137,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/parser/ets/import_tests/import_relative_path-expected.txt b/ets2panda/test/parser/ets/import_tests/import_relative_path-expected.txt index 47a8976e19..10ffc4241f 100755 --- a/ets2panda/test/parser/ets/import_tests/import_relative_path-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_relative_path-expected.txt @@ -79,6 +79,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/parser/ets/import_tests/import_several_1-expected.txt b/ets2panda/test/parser/ets/import_tests/import_several_1-expected.txt index f4fc0df83c..0c48238700 100755 --- a/ets2panda/test/parser/ets/import_tests/import_several_1-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_several_1-expected.txt @@ -238,6 +238,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/parser/ets/import_tests/import_several_2-expected.txt b/ets2panda/test/parser/ets/import_tests/import_several_2-expected.txt index a6b9200056..b172fc50bb 100755 --- a/ets2panda/test/parser/ets/import_tests/import_several_2-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_several_2-expected.txt @@ -137,6 +137,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/parser/ets/import_tests/import_several_3-expected.txt b/ets2panda/test/parser/ets/import_tests/import_several_3-expected.txt index 1d8e16a3b5..f07c570b17 100755 --- a/ets2panda/test/parser/ets/import_tests/import_several_3-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_several_3-expected.txt @@ -151,6 +151,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/parser/ets/import_tests/import_several_4-expected.txt b/ets2panda/test/parser/ets/import_tests/import_several_4-expected.txt index 6ea9c81dd2..b5de450311 100644 --- a/ets2panda/test/parser/ets/import_tests/import_several_4-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_several_4-expected.txt @@ -151,6 +151,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/parser/ets/import_tests/import_several_5-expected.txt b/ets2panda/test/parser/ets/import_tests/import_several_5-expected.txt index f96445626d..69fbb4be27 100755 --- a/ets2panda/test/parser/ets/import_tests/import_several_5-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_several_5-expected.txt @@ -151,6 +151,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/parser/ets/import_tests/import_several_6-expected.txt b/ets2panda/test/parser/ets/import_tests/import_several_6-expected.txt index 4f190cb5ec..b6fad9300f 100644 --- a/ets2panda/test/parser/ets/import_tests/import_several_6-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_several_6-expected.txt @@ -151,6 +151,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/parser/ets/import_tests/import_several_7-expected.txt b/ets2panda/test/parser/ets/import_tests/import_several_7-expected.txt index d4d3958526..72d1907d1a 100755 --- a/ets2panda/test/parser/ets/import_tests/import_several_7-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_several_7-expected.txt @@ -223,6 +223,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/parser/ets/import_tests/relative_import/alias2-expected.txt b/ets2panda/test/parser/ets/import_tests/relative_import/alias2-expected.txt index 37cfedf514..e73141cdc2 100644 --- a/ets2panda/test/parser/ets/import_tests/relative_import/alias2-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/relative_import/alias2-expected.txt @@ -253,6 +253,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/parser/ets/index_expressions-expected.txt b/ets2panda/test/parser/ets/index_expressions-expected.txt index 39fc2ad997..d55d46b694 100644 --- a/ets2panda/test/parser/ets/index_expressions-expected.txt +++ b/ets2panda/test/parser/ets/index_expressions-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/parser/ets/lambda_import_alias_1-2-expected.txt b/ets2panda/test/parser/ets/lambda_import_alias_1-2-expected.txt index 2821fed828..89812af2db 100644 --- a/ets2panda/test/parser/ets/lambda_import_alias_1-2-expected.txt +++ b/ets2panda/test/parser/ets/lambda_import_alias_1-2-expected.txt @@ -176,6 +176,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/parser/ets/launch_with_call_expression-expected.txt b/ets2panda/test/parser/ets/launch_with_call_expression-expected.txt index 2e69814082..543b7f5713 100644 --- a/ets2panda/test/parser/ets/launch_with_call_expression-expected.txt +++ b/ets2panda/test/parser/ets/launch_with_call_expression-expected.txt @@ -253,6 +253,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/parser/ets/null_invalid-expected.txt b/ets2panda/test/parser/ets/null_invalid-expected.txt index 991dd59ae5..60ac4d8d33 100644 --- a/ets2panda/test/parser/ets/null_invalid-expected.txt +++ b/ets2panda/test/parser/ets/null_invalid-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/parser/ets/null_valid-expected.txt b/ets2panda/test/parser/ets/null_valid-expected.txt index b1e599b104..a5cc81f611 100644 --- a/ets2panda/test/parser/ets/null_valid-expected.txt +++ b/ets2panda/test/parser/ets/null_valid-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/parser/ets/re_export/diamond/A-expected.txt b/ets2panda/test/parser/ets/re_export/diamond/A-expected.txt index 5c1d2aa74e..bc8150abb0 100644 --- a/ets2panda/test/parser/ets/re_export/diamond/A-expected.txt +++ b/ets2panda/test/parser/ets/re_export/diamond/A-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/parser/ets/re_export/import_index-expected.txt b/ets2panda/test/parser/ets/re_export/import_index-expected.txt index dd67fad02a..b56a0dd932 100644 --- a/ets2panda/test/parser/ets/re_export/import_index-expected.txt +++ b/ets2panda/test/parser/ets/re_export/import_index-expected.txt @@ -79,6 +79,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/parser/ets/re_export/import_index_2-expected.txt b/ets2panda/test/parser/ets/re_export/import_index_2-expected.txt index 8d4fa72dfe..e24ba9c385 100644 --- a/ets2panda/test/parser/ets/re_export/import_index_2-expected.txt +++ b/ets2panda/test/parser/ets/re_export/import_index_2-expected.txt @@ -94,6 +94,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/parser/ets/simple_types-expected.txt b/ets2panda/test/parser/ets/simple_types-expected.txt index 7c49b45744..74d12bdb54 100644 --- a/ets2panda/test/parser/ets/simple_types-expected.txt +++ b/ets2panda/test/parser/ets/simple_types-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/parser/ets/string-expected.txt b/ets2panda/test/parser/ets/string-expected.txt index 38083df2f9..130ae76cb6 100644 --- a/ets2panda/test/parser/ets/string-expected.txt +++ b/ets2panda/test/parser/ets/string-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/parser/ets/ternary-expected.txt b/ets2panda/test/parser/ets/ternary-expected.txt index f74401a8ee..920024304b 100644 --- a/ets2panda/test/parser/ets/ternary-expected.txt +++ b/ets2panda/test/parser/ets/ternary-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/parser/ets/test_jsvalue_get_double-expected.txt b/ets2panda/test/parser/ets/test_jsvalue_get_double-expected.txt index e95785906d..1c79ec21c0 100644 --- a/ets2panda/test/parser/ets/test_jsvalue_get_double-expected.txt +++ b/ets2panda/test/parser/ets/test_jsvalue_get_double-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/parser/ets/test_jsvalue_get_property_1-expected.txt b/ets2panda/test/parser/ets/test_jsvalue_get_property_1-expected.txt index 73bf02b622..7f7362df70 100644 --- a/ets2panda/test/parser/ets/test_jsvalue_get_property_1-expected.txt +++ b/ets2panda/test/parser/ets/test_jsvalue_get_property_1-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/parser/ets/test_jsvalue_get_property_2-expected.txt b/ets2panda/test/parser/ets/test_jsvalue_get_property_2-expected.txt index 69a2a714c4..6ec874fa24 100644 --- a/ets2panda/test/parser/ets/test_jsvalue_get_property_2-expected.txt +++ b/ets2panda/test/parser/ets/test_jsvalue_get_property_2-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/parser/ets/test_type_alias9-expected.txt b/ets2panda/test/parser/ets/test_type_alias9-expected.txt index f71a0b03d7..da996e2cfd 100644 --- a/ets2panda/test/parser/ets/test_type_alias9-expected.txt +++ b/ets2panda/test/parser/ets/test_type_alias9-expected.txt @@ -130,6 +130,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/parser/ets/throwsRethrowsAsVariables-expected.txt b/ets2panda/test/parser/ets/throwsRethrowsAsVariables-expected.txt index d1ea49ee75..347c036324 100644 --- a/ets2panda/test/parser/ets/throwsRethrowsAsVariables-expected.txt +++ b/ets2panda/test/parser/ets/throwsRethrowsAsVariables-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/parser/ets/trailing_lambda_tests/trailing_lambda_not_transform_trailing_block_1-expected.txt b/ets2panda/test/parser/ets/trailing_lambda_tests/trailing_lambda_not_transform_trailing_block_1-expected.txt index 99138c5325..697057163a 100644 --- a/ets2panda/test/parser/ets/trailing_lambda_tests/trailing_lambda_not_transform_trailing_block_1-expected.txt +++ b/ets2panda/test/parser/ets/trailing_lambda_tests/trailing_lambda_not_transform_trailing_block_1-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/parser/ets/tuple_type_1-expected.txt b/ets2panda/test/parser/ets/tuple_type_1-expected.txt index bca78f1e0e..3e49a8ea53 100644 --- a/ets2panda/test/parser/ets/tuple_type_1-expected.txt +++ b/ets2panda/test/parser/ets/tuple_type_1-expected.txt @@ -234,6 +234,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/parser/ets/unary_op-expected.txt b/ets2panda/test/parser/ets/unary_op-expected.txt index 32aa0ba97d..3bd5606906 100644 --- a/ets2panda/test/parser/ets/unary_op-expected.txt +++ b/ets2panda/test/parser/ets/unary_op-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/parser/ets/user_defined_22-expected.txt b/ets2panda/test/parser/ets/user_defined_22-expected.txt index f61d047d2f..2723b04939 100644 --- a/ets2panda/test/parser/ets/user_defined_22-expected.txt +++ b/ets2panda/test/parser/ets/user_defined_22-expected.txt @@ -319,6 +319,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "MethodDefinition", "key": { diff --git a/ets2panda/test/runtime/ets/entrypoint-with-main-and-top-level-stmts.ets b/ets2panda/test/runtime/ets/entrypoint-with-main-and-top-level-stmts.ets new file mode 100644 index 0000000000..93f438ebf3 --- /dev/null +++ b/ets2panda/test/runtime/ets/entrypoint-with-main-and-top-level-stmts.ets @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +let a : int = 0; + +function main() : void { + assert(a == b); +} + +let b : int = 0; \ No newline at end of file diff --git a/ets2panda/test/runtime/ets/entrypoint-with-main.ets b/ets2panda/test/runtime/ets/entrypoint-with-main.ets new file mode 100644 index 0000000000..c31e9f4599 --- /dev/null +++ b/ets2panda/test/runtime/ets/entrypoint-with-main.ets @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + function main() : void { // gets to result_.classProperties + let a = 0; + assert(a == 0); +} diff --git a/ets2panda/test/runtime/ets/entrypoint-wout-main.ets b/ets2panda/test/runtime/ets/entrypoint-wout-main.ets new file mode 100644 index 0000000000..e27a52ef64 --- /dev/null +++ b/ets2panda/test/runtime/ets/entrypoint-wout-main.ets @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +let a : int = 0; + +assert(a == 0); \ No newline at end of file -- Gitee From 72a0b87646e6a9bce28e69ce171d696127e11f87 Mon Sep 17 00:00:00 2001 From: Zelentsov Dmitry Date: Fri, 26 Apr 2024 12:52:49 +0300 Subject: [PATCH 11/22] Title: Wrong CTE "TypeError: Cannot cast type 'never' to 'PromiseLike'" Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/I9K0LW?from=project-issue Tests: U-Runner + CI Signed-off-by: Zelentsov Dmitry --- ets2panda/checker/types/ets/etsUnionType.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ets2panda/checker/types/ets/etsUnionType.cpp b/ets2panda/checker/types/ets/etsUnionType.cpp index d8ef4ce68b..3eab896690 100644 --- a/ets2panda/checker/types/ets/etsUnionType.cpp +++ b/ets2panda/checker/types/ets/etsUnionType.cpp @@ -486,6 +486,14 @@ bool ETSUnionType::ExtractType(checker::ETSChecker *checker, checker::ETSObjectT constituentTypes_.erase(it); return true; } + // Because 'instanceof' expression does not check for type parameters, then for generic types we should + // consider that expressions like 'SomeType' and 'SomeType' are identical for smart casting. + if (objectType->HasTypeFlag(TypeFlag::GENERIC) && sourceType->HasTypeFlag(TypeFlag::GENERIC) && + checker->Relation()->IsIdenticalTo(objectType->GetOriginalBaseType(), + sourceType->GetOriginalBaseType())) { + constituentTypes_.erase(it); + return true; + } if (auto const id = ETSObjectType::GetPrecedence(objectType); id > 0U) { numericTypes.emplace(id, it); } -- Gitee From 1cd4b8f8fab0889ba86869ba9c192dfa145e1e99 Mon Sep 17 00:00:00 2001 From: Peter Pronai Date: Wed, 21 Feb 2024 17:13:13 +0100 Subject: [PATCH 12/22] Skip capturing in lambdas from own scopes Previously the check was only for whether the variable came from any lambda, but that breaks with nested lambdas. Also adds more tests for nested lambdas. Fixes read-only bindings and some cases of mutation on `let` bindings. Mutation of parameters seems to crash `ark` and more elaborate tests involving assignment produce incorrect results. Fixes #16157 internal issue Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/I96G8Z Testing : all CI tests passed. Results are availible in gg watcher. Change-Id: I8921816840bb004ef69b6699aa60cff69865e3a6 Signed-off-by: Peter Pronai --- ets2panda/checker/ets/helpers.cpp | 2 +- ets2panda/ir/astNode.cpp | 8 ++ ets2panda/ir/astNode.h | 2 + .../expressions/arrowFunctionExpression.cpp | 15 ++ .../ir/expressions/arrowFunctionExpression.h | 1 + .../runtime/ets/nestedLambdaInnerConst.ets | 123 ++++++++++++++++ .../test/runtime/ets/nestedLambdaLet.ets | 134 ++++++++++++++++++ ets2panda/varbinder/scope.cpp | 11 ++ ets2panda/varbinder/scope.h | 2 + 9 files changed, 297 insertions(+), 1 deletion(-) create mode 100644 ets2panda/test/runtime/ets/nestedLambdaInnerConst.ets create mode 100644 ets2panda/test/runtime/ets/nestedLambdaLet.ets diff --git a/ets2panda/checker/ets/helpers.cpp b/ets2panda/checker/ets/helpers.cpp index ace6b22d2f..db7fa0974f 100644 --- a/ets2panda/checker/ets/helpers.cpp +++ b/ets2panda/checker/ets/helpers.cpp @@ -224,7 +224,7 @@ void ETSChecker::SaveCapturedVariable(varbinder::Variable *const var, ir::Identi } if ((!var->HasFlag(varbinder::VariableFlags::LOCAL) && !var->HasFlag(varbinder::VariableFlags::METHOD)) || - (var->GetScope()->Node()->IsScriptFunction() && var->GetScope()->Node()->AsScriptFunction()->IsArrow())) { + Context().ContainingLambda()->IsVarFromSubscope(var)) { return; } diff --git a/ets2panda/ir/astNode.cpp b/ets2panda/ir/astNode.cpp index b7a83d408b..64d2983a31 100644 --- a/ets2panda/ir/astNode.cpp +++ b/ets2panda/ir/astNode.cpp @@ -121,6 +121,14 @@ AstNode *AstNode::FindChild(const NodePredicate &cb) const return found; } +varbinder::Scope *AstNode::EnclosingScope(const ir::AstNode *expr) +{ + while (expr != nullptr && !expr->IsScopeBearer()) { + expr = expr->Parent(); + } + return expr != nullptr ? expr->Scope() : nullptr; +} + std::string AstNode::DumpJSON() const { ir::AstDumper dumper {this}; diff --git a/ets2panda/ir/astNode.h b/ets2panda/ir/astNode.h index b24e618f53..e2a69f5e99 100644 --- a/ets2panda/ir/astNode.h +++ b/ets2panda/ir/astNode.h @@ -465,6 +465,8 @@ public: return reinterpret_cast(this); } + static varbinder::Scope *EnclosingScope(const ir::AstNode *expr); + [[nodiscard]] virtual bool IsScopeBearer() const noexcept { return false; diff --git a/ets2panda/ir/expressions/arrowFunctionExpression.cpp b/ets2panda/ir/expressions/arrowFunctionExpression.cpp index 77d39416dd..02ae52b50a 100644 --- a/ets2panda/ir/expressions/arrowFunctionExpression.cpp +++ b/ets2panda/ir/expressions/arrowFunctionExpression.cpp @@ -149,12 +149,27 @@ ir::TypeNode *ArrowFunctionExpression::CreateTypeAnnotation(checker::ETSChecker void ArrowFunctionExpression::AddCapturedVar(varbinder::Variable *var) { + if (IsVarFromSubscope(var)) { + return; + } + // Not using an ArenaSet for now, simpler to do it this way. + if (std::find(capturedVars_.begin(), capturedVars_.end(), var) != capturedVars_.end()) { + return; + } capturedVars_.push_back(var); if (parentLambda_ != nullptr) { parentLambda_->AddCapturedVar(var); } } +bool ArrowFunctionExpression::IsVarFromSubscope(const varbinder::Variable *var) const +{ + // The parameter scope's and the function scope's common ancestor lives outside the function, so we have to check + // them separetely. + return Function()->Scope()->IsSuperscopeOf(var->GetScope()) || + Function()->Scope()->ParamScope()->IsSuperscopeOf(var->GetScope()); +} + void ArrowFunctionExpression::AddChildLambda(ArrowFunctionExpression *childLambda) { childLambdas_.push_back(childLambda); diff --git a/ets2panda/ir/expressions/arrowFunctionExpression.h b/ets2panda/ir/expressions/arrowFunctionExpression.h index dac4194054..104cdcf1d2 100644 --- a/ets2panda/ir/expressions/arrowFunctionExpression.h +++ b/ets2panda/ir/expressions/arrowFunctionExpression.h @@ -116,6 +116,7 @@ public: ir::TypeNode *CreateTypeAnnotation(checker::ETSChecker *checker); ir::TypeNode *CreateReturnNodeFromType(checker::ETSChecker *checker, checker::Type *returnType); void AddChildLambda(ArrowFunctionExpression *childLambda); + bool IsVarFromSubscope(const varbinder::Variable *var) const; void Accept(ASTVisitorT *v) override { diff --git a/ets2panda/test/runtime/ets/nestedLambdaInnerConst.ets b/ets2panda/test/runtime/ets/nestedLambdaInnerConst.ets new file mode 100644 index 0000000000..94a7bbc5ca --- /dev/null +++ b/ets2panda/test/runtime/ets/nestedLambdaInnerConst.ets @@ -0,0 +1,123 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +function force(thunk: ()=>void) { + thunk(); +} + +function bool2Levels(): void { + force(() => { + const a0 = true; + force(() => { + const a1 = a0; + assert a0 && a1; + }); + }); +} + +function bool4Levels(): void { + force(() => { + const a0 = true; + force(() => { + const a1 = a0; + force(()=>{ + const a2 = a1; + force(()=>{ + const a3 = a2; + assert a0 && a1 && a2 && a3; + }); + }); + }); + }); +} + +function number4Levels(): void { + force(() => { + const a0 = 1; + force(() => { + const a1 = a0; + force(()=>{ + const a2 = a1; + force(()=>{ + const a3 = a2; + assert 4==a0 + a1 + a2 + a3; + }); + }); + }); + }); +} + +function array4Levels(): void { + force(() => { + const a0 = [1,0,0,0]; + force(() => { + const a1 = a0; + a1[1]=a0[0]; + force(()=>{ + const a2 = a1; + a2[2]=a1[1]; + force(()=>{ + const a3 = a2; + a3[3]=a2[2]; + assert a0[0]+a0[1]+a0[2]+a0[3]==4; + }); + }); + }); + }); +} + +function arrayProp4Levels(): void { + force(() => { + const a0 = [1,0,0,0]; + force(() => { + const a1 = a0; + a1[1]=a0[0]; + force(()=>{ + const a2 = a1; + a2[2]=a1[1]; + force(()=>{ + const a3 = a2; + a3[3]=a2[2]; + assert a0.length == 4; + assert a0[0]+a0[1]+a0[2]+a0[3] == 4; + }); + }); + }); + }); +} + +function paramCapture(): void { + const v0 = 1 + const f0 = (p0:number)=>{ + const a0 = p0; + const f1 = (p1:number)=>{ + const a1 = a0; + const a2 = p1; + const a3 = v0; + assert a0 + a1 + a2 + a3 == 4; + } + f1(p0); + } + f0(v0); +} + + +function main():void { + bool2Levels(); + bool4Levels(); + number4Levels(); + array4Levels(); + paramCapture(); +} diff --git a/ets2panda/test/runtime/ets/nestedLambdaLet.ets b/ets2panda/test/runtime/ets/nestedLambdaLet.ets new file mode 100644 index 0000000000..80953fa77b --- /dev/null +++ b/ets2panda/test/runtime/ets/nestedLambdaLet.ets @@ -0,0 +1,134 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +function force(thunk: () => void) { + thunk(); +} + +function bool2Levels(): void { + force(() => { + let a0 = true; + force(() => { + let a1 = a0; + assert a0 && a1; + a0 = false; + assert !a0 && a1; + a0 = true; + a1 = false; + assert a0 && !a1; + }); + }); +} + +function bool4Levels(): void { + force(() => { + let a0 = true; + force(() => { + let a1 = a0; + force(() => { + let a2 = a1; + force(() => { + let a3 = a2; + assert a0 && a1 && a2 && a3; + a0 = false; + assert !a0 && a1 && a2 && a3; + a3 = false; + assert !a0 && a1 && a2 && !a3; + }); + }); + }); + }); +} + +function bool4LevelsBi(): void { + force(() => { + let a0 = true; + force(() => { + let a1 = a0; + force(() => { + let a2 = a1; + force(() => { + let a3 = a2; + assert a0 && a1 && a2 && a3; + a0 = false; + assert !a0 && a1 && a2 && a3; + a3 = a0; + assert !a0 && a1 && a2 && !a3; + }); + force(() => { + a2 = a0; + assert !a0 && a1 && !a2; + }); + }); + force(() => { + assert !a0 && a1; + }); + }); + force(() => { + assert !a0; + }); + }); +} + +function number4Levels(): void { + force(() => { + let a0 = 1; + force(() => { + let a1 = a0++; + force(() => { + let a2 = a1++; + force(() => { + let a3 = a2++; + a3++; + assert 8 == a0 + a1 + a2 + a3; + }); + }); + }); + }); +} + +function arrays(): void { + force(() => { + let a0 = [1, 0, 0, 0]; + force(() => { + let a1 = a0; + a1[1]=a0[0]; + force(() => { + let a2 = a1; + a2[2] = a1[1]; + force(() => { + let a3 = a2; + force(() => { + a3[3] = a2[2]; + assert a0[0] + a0[1] + a0[2] + a0[3] == 4; + a0 = new double[5]; + assert a0.length == 5; + assert a0[0] + a0[1] + a0[2] + a0[3] + a0[4] == 0; + assert a1[0] + a1[1] + a1[2] + a1[3] == 4; + assert a1 == a2 && a2 == a3; + }) + }); + }); + }); + }); +} + +function main():void { + bool2Levels(); + bool4Levels(); + bool4LevelsBi(); + number4Levels(); + arrays(); +} diff --git a/ets2panda/varbinder/scope.cpp b/ets2panda/varbinder/scope.cpp index 28008db5ab..f89de5345d 100644 --- a/ets2panda/varbinder/scope.cpp +++ b/ets2panda/varbinder/scope.cpp @@ -73,6 +73,17 @@ const VariableScope *Scope::EnclosingVariableScope() const return nullptr; } +bool Scope::IsSuperscopeOf(const varbinder::Scope *subscope) const +{ + while (subscope != nullptr) { + if (subscope == this) { + return true; + } + subscope = ir::AstNode::EnclosingScope(subscope->Node()->Parent()); + } + return false; +} + // NOTE(psiket): Duplication ClassScope *Scope::EnclosingClassScope() { diff --git a/ets2panda/varbinder/scope.h b/ets2panda/varbinder/scope.h index 0aa277b0b4..5876e9fd9a 100644 --- a/ets2panda/varbinder/scope.h +++ b/ets2panda/varbinder/scope.h @@ -260,6 +260,8 @@ public: virtual Variable *FindLocal(const util::StringView &name, ResolveBindingOptions options) const; + bool IsSuperscopeOf(const varbinder::Scope *subscope) const; + ConstScopeFindResult Find(const util::StringView &name, ResolveBindingOptions options = ResolveBindingOptions::BINDINGS) const; -- Gitee From 39d8fcc69e96ea049d8f7773354ebe36b630f1cf Mon Sep 17 00:00:00 2001 From: Vivien Voros Date: Mon, 29 Apr 2024 19:43:23 +0200 Subject: [PATCH 13/22] Fix the conversion from -Infinity to byte, short, char, int, float, long. Fixes internal issue #16911 Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/I9KT2W Testing : all CI tests passed. Results are availible in gg watcher. Change-Id: I6171e6c923ee43f0ad4819029681bf737b198dd2 Signed-off-by: Vivien Voros --- ets2panda/checker/ets/narrowingConverter.h | 35 +++++++------------ .../runtime/ets/conversionFromInfinity.ets | 12 +++++++ 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/ets2panda/checker/ets/narrowingConverter.h b/ets2panda/checker/ets/narrowingConverter.h index 8c9a6562cb..111d84dcd6 100644 --- a/ets2panda/checker/ets/narrowingConverter.h +++ b/ets2panda/checker/ets/narrowingConverter.h @@ -104,38 +104,29 @@ private: } template - int CalculateIntValue(Type *target, SType value) + int CalculateIntValue(SType value) { - switch (ETSChecker::ETSChecker::ETSType(target)) { - case TypeFlag::BYTE: - case TypeFlag::CHAR: - case TypeFlag::SHORT: { - if (std::isinf(value)) { - return std::numeric_limits::max(); - } - if (std::signbit(std::isinf(value))) { - return std::numeric_limits::min(); - } - if (std::isnan(value)) { - return 0; - } - return static_cast(value); - } - default: { - return 0; + if (std::isinf(value)) { + if (std::signbit(value)) { + return std::numeric_limits::min(); } + return std::numeric_limits::max(); } + if (std::isnan(value)) { + return 0; + } + return static_cast(value); } template To CastFloatingPointToIntOrLong(From value) { if (std::isinf(value)) { + if (std::signbit(value)) { + return std::numeric_limits::min(); + } return std::numeric_limits::max(); } - if (std::signbit(std::isinf(value))) { - return std::numeric_limits::min(); - } ASSERT(std::is_floating_point_v); ASSERT(std::is_integral_v); To minInt = std::numeric_limits::min(); @@ -162,7 +153,7 @@ private: case TypeFlag::BYTE: case TypeFlag::CHAR: case TypeFlag::SHORT: { - return CalculateIntValue(target, value); + return CalculateIntValue(value); } case TypeFlag::INT: case TypeFlag::LONG: { diff --git a/ets2panda/test/runtime/ets/conversionFromInfinity.ets b/ets2panda/test/runtime/ets/conversionFromInfinity.ets index 812df0fe9e..f87376cb6a 100644 --- a/ets2panda/test/runtime/ets/conversionFromInfinity.ets +++ b/ets2panda/test/runtime/ets/conversionFromInfinity.ets @@ -44,42 +44,54 @@ assert(b3 == -1) let l1 = Infinity as long let l2: double = Infinity let l3 = l2 as long +let l4 = -Infinity as long assert(l1 == 9223372036854775807) assert(l3 == 9223372036854775807) +assert(l4 == -9223372036854775808) let i1 = Infinity as int let i2: double = Infinity let i3 = i2 as int +let i4 = -Infinity as int assert(i1 == 2147483647) assert(i3 == 2147483647) +assert(i4 == -2147483648) let s1 = Infinity as short let s2: double = Infinity let s3 = s2 as short +let s4 = -Infinity as short assert(s1 == -1) assert(s3 == -1) +assert(s4 == 0) let c1 = Infinity as char let c2: double = Infinity let c3 = c2 as char +let c4 = -Infinity as char assert(c1 == 65535) assert(c3 == 65535) +assert(c4 == 0) let f1 = Infinity as float let f2: double = Infinity let f3 = f2 as float +let f4 = -Infinity as float assert(f1 == Infinity) assert(f3 == Infinity) +assert(f4 == -Infinity) let d1 = Infinity as double let d2: double = Infinity let d3 = d2 as double +let d4 = -Infinity as double assert(d1 == Infinity) assert(d3 == Infinity) +assert(d4 == -Infinity) } -- Gitee From aa261ad9500341b724e5b0e95fccbce3d2f98628 Mon Sep 17 00:00:00 2001 From: peterseres Date: Wed, 28 Feb 2024 10:55:52 +0100 Subject: [PATCH 14/22] Fix abstract classes and interfaces instantied with array creation operator Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/I97J8W Testing: I create two test case. One of them testing abstract classes instantiating with array creation expression the other one testing the interfaces. Signed-off-by: Peter Seres --- ets2panda/checker/ETSAnalyzer.cpp | 6 +- ...ith_array_creation_expression-expected.txt | 480 ++++++++++++++++++ ...t_class_with_array_creation_expression.ets | 20 + ...ith_array_creation_expression-expected.txt | 386 ++++++++++++++ ...terface_with_array_creation_expression.ets | 20 + 5 files changed, 911 insertions(+), 1 deletion(-) create mode 100644 ets2panda/test/parser/ets/instantied_abstract_class_with_array_creation_expression-expected.txt create mode 100644 ets2panda/test/parser/ets/instantied_abstract_class_with_array_creation_expression.ets create mode 100644 ets2panda/test/parser/ets/instantied_interface_with_array_creation_expression-expected.txt create mode 100644 ets2panda/test/parser/ets/instantied_interface_with_array_creation_expression.ets diff --git a/ets2panda/checker/ETSAnalyzer.cpp b/ets2panda/checker/ETSAnalyzer.cpp index f88f0a752b..2ebfd84bc4 100644 --- a/ets2panda/checker/ETSAnalyzer.cpp +++ b/ets2panda/checker/ETSAnalyzer.cpp @@ -379,11 +379,15 @@ checker::Type *ETSAnalyzer::Check(ir::ETSNewArrayInstanceExpression *expr) const if (!elementType->HasTypeFlag(TypeFlag::ETS_PRIMITIVE)) { if (elementType->IsETSObjectType()) { auto *calleeObj = elementType->AsETSObjectType(); - if (!calleeObj->HasObjectFlag(checker::ETSObjectFlags::ABSTRACT)) { + const auto flags = checker::ETSObjectFlags::ABSTRACT | checker::ETSObjectFlags::INTERFACE; + if (!calleeObj->HasObjectFlag(flags)) { // A workaround check for new Interface[...] in test cases expr->SetSignature( checker->CollectParameterlessConstructor(calleeObj->ConstructSignatures(), expr->Start())); checker->ValidateSignatureAccessibility(calleeObj, nullptr, expr->Signature(), expr->Start()); + } else { + checker->ThrowTypeError("Cannot use array creation expression with abstract classes and interfaces.", + expr->Start()); } } } diff --git a/ets2panda/test/parser/ets/instantied_abstract_class_with_array_creation_expression-expected.txt b/ets2panda/test/parser/ets/instantied_abstract_class_with_array_creation_expression-expected.txt new file mode 100644 index 0000000000..469ca893fd --- /dev/null +++ b/ets2panda/test/parser/ets/instantied_abstract_class_with_array_creation_expression-expected.txt @@ -0,0 +1,480 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "cls", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 16 + }, + "end": { + "line": 16, + "column": 19 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 22 + }, + "end": { + "line": 16, + "column": 22 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 20 + }, + "end": { + "line": 16, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 10 + }, + "end": { + "line": 16, + "column": 22 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 14 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 18, + "column": 18 + }, + "end": { + "line": 18, + "column": 22 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "ETSNewArrayInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "cls", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 7 + }, + "end": { + "line": 19, + "column": 10 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 7 + }, + "end": { + "line": 19, + "column": 11 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 7 + }, + "end": { + "line": 19, + "column": 11 + } + } + }, + "dimension": { + "type": "NumberLiteral", + "value": 10, + "loc": { + "start": { + "line": 19, + "column": 11 + }, + "end": { + "line": 19, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 3 + }, + "end": { + "line": 19, + "column": 14 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 3 + }, + "end": { + "line": 19, + "column": 15 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 23 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 20, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 21, + "column": 1 + } + } +} +TypeError: Cannot use array creation expression with abstract classes and interfaces. [instantied_abstract_class_with_array_creation_expression.ets:19:3] diff --git a/ets2panda/test/parser/ets/instantied_abstract_class_with_array_creation_expression.ets b/ets2panda/test/parser/ets/instantied_abstract_class_with_array_creation_expression.ets new file mode 100644 index 0000000000..90455edc51 --- /dev/null +++ b/ets2panda/test/parser/ets/instantied_abstract_class_with_array_creation_expression.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +abstract class cls {} + +function main(): void { + new cls[10]; +} diff --git a/ets2panda/test/parser/ets/instantied_interface_with_array_creation_expression-expected.txt b/ets2panda/test/parser/ets/instantied_interface_with_array_creation_expression-expected.txt new file mode 100644 index 0000000000..d3d577fa5d --- /dev/null +++ b/ets2panda/test/parser/ets/instantied_interface_with_array_creation_expression-expected.txt @@ -0,0 +1,386 @@ +{ + "type": "Program", + "statements": [ + { + "type": "TSInterfaceDeclaration", + "body": { + "type": "TSInterfaceBody", + "body": [], + "loc": { + "start": { + "line": 16, + "column": 17 + }, + "end": { + "line": 16, + "column": 19 + } + } + }, + "id": { + "type": "Identifier", + "name": "iface", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 11 + }, + "end": { + "line": 16, + "column": 16 + } + } + }, + "extends": [], + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 18, + "column": 9 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 14 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 18, + "column": 18 + }, + "end": { + "line": 18, + "column": 22 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "ETSNewArrayInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "iface", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 7 + }, + "end": { + "line": 19, + "column": 12 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 7 + }, + "end": { + "line": 19, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 7 + }, + "end": { + "line": 19, + "column": 13 + } + } + }, + "dimension": { + "type": "NumberLiteral", + "value": 5, + "loc": { + "start": { + "line": 19, + "column": 13 + }, + "end": { + "line": 19, + "column": 14 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 3 + }, + "end": { + "line": 19, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 3 + }, + "end": { + "line": 19, + "column": 16 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 23 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 20, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 21, + "column": 1 + } + } +} +TypeError: Cannot use array creation expression with abstract classes and interfaces. [instantied_interface_with_array_creation_expression.ets:19:3] diff --git a/ets2panda/test/parser/ets/instantied_interface_with_array_creation_expression.ets b/ets2panda/test/parser/ets/instantied_interface_with_array_creation_expression.ets new file mode 100644 index 0000000000..a31234d060 --- /dev/null +++ b/ets2panda/test/parser/ets/instantied_interface_with_array_creation_expression.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +interface iface {} + +function main(): void { + new iface[5]; +} -- Gitee From a6233c577e781f0eaa25f02832e51bdcc02ab825 Mon Sep 17 00:00:00 2001 From: Soma Simon Date: Wed, 24 Apr 2024 14:18:00 +0200 Subject: [PATCH 15/22] Fix verifier error at union lowering Remove unnesesary TSAsExpression from the chain when handling union lowering. Fixes internal issue #16595 Issue: https://gitee.com/openharmony/arkcompiler_runtime_core/issues/I9JEBA Testing : all CI tests passed. Results are availible in gg watcher. Change-Id: I933f23266aac1a1567efd58eebba824c5d16ae48 Signed-off-by: Soma Simon --- .../compiler/lowering/ets/unionLowering.cpp | 7 ++++-- ets2panda/test/runtime/ets/castUnion.ets | 24 +++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 ets2panda/test/runtime/ets/castUnion.ets diff --git a/ets2panda/compiler/lowering/ets/unionLowering.cpp b/ets2panda/compiler/lowering/ets/unionLowering.cpp index e0152017b7..79ccb624cf 100644 --- a/ets2panda/compiler/lowering/ets/unionLowering.cpp +++ b/ets2panda/compiler/lowering/ets/unionLowering.cpp @@ -161,8 +161,11 @@ static ir::TSAsExpression *HandleUnionCastToPrimitive(checker::ETSChecker *check } auto *const unboxableUnionType = sourceType != nullptr ? sourceType : unionType->FindUnboxableType(); auto *const unboxedUnionType = checker->ETSBuiltinTypeAsPrimitiveType(unboxableUnionType); - expr->SetExpr(UnionCastToPrimitive(checker, unboxableUnionType->AsETSObjectType(), unboxedUnionType, expr->Expr())); - return expr; + auto *const node = + UnionCastToPrimitive(checker, unboxableUnionType->AsETSObjectType(), unboxedUnionType, expr->Expr()); + node->SetParent(expr->Parent()); + + return node; } bool UnionLowering::Perform(public_lib::Context *ctx, parser::Program *program) diff --git a/ets2panda/test/runtime/ets/castUnion.ets b/ets2panda/test/runtime/ets/castUnion.ets new file mode 100644 index 0000000000..3b32fb6a0e --- /dev/null +++ b/ets2panda/test/runtime/ets/castUnion.ets @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +class A1 { + s: Byte | Short = new Byte() + bad_field: short = this.s as Byte +} + +function main() { + let a = new A1() +} + -- Gitee From 66ad2fe085b04d5269e0ccdc7dab0d31d6380605 Mon Sep 17 00:00:00 2001 From: Otto Eotvos Date: Tue, 9 Apr 2024 12:45:46 +0200 Subject: [PATCH 16/22] [ETS] Fix generated getters and setters Generated getters and setters are missing their 'external' flag when the containing file is parsed as an external source. Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/I97ZQ6 Testing: all CI tests passed. Results are availible in gg watcher. Also fixes the following internal issues: #15939, #15973 Change-Id: I9716a8e55050971afc24691948b8dc0b142c343b Signed-off-by: Otto Eotvos --- ets2panda/checker/ETSchecker.h | 3 + ets2panda/checker/ets/helpers.cpp | 55 +- ets2panda/checker/ets/object.cpp | 6 + ets2panda/compiler/core/ETSemitter.cpp | 5 + ets2panda/ir/astNodeFlags.h | 1 + ...rt_class_with_getters_setters-expected.txt | 1083 +++++++++++++++++ .../export_class_with_getters_setters.ets | 24 + ...rt_class_with_getters_setters-expected.txt | 789 ++++++++++++ .../import_class_with_getters_setters.ets | 23 + 9 files changed, 1972 insertions(+), 17 deletions(-) create mode 100644 ets2panda/test/compiler/ets/import_tests/export_class_with_getters_setters-expected.txt create mode 100644 ets2panda/test/compiler/ets/import_tests/export_class_with_getters_setters.ets create mode 100644 ets2panda/test/compiler/ets/import_tests/import_class_with_getters_setters-expected.txt create mode 100644 ets2panda/test/compiler/ets/import_tests/import_class_with_getters_setters.ets diff --git a/ets2panda/checker/ETSchecker.h b/ets2panda/checker/ETSchecker.h index 60f105cc52..e7edba09bd 100644 --- a/ets2panda/checker/ETSchecker.h +++ b/ets2panda/checker/ETSchecker.h @@ -588,6 +588,9 @@ public: varbinder::ClassScope *scope, bool isSetter, ETSChecker *checker); void GenerateGetterSetterPropertyAndMethod(ir::ClassProperty *originalProp, ETSObjectType *classType); + ir::MethodDefinition *GenerateSetterForProperty(ir::ClassProperty *originalProp, ir::ClassProperty *interfaceProp, + ir::ClassProperty *classProp, ETSObjectType *classType, + ir::MethodDefinition *getter); ETSObjectType *GetImportSpecifierObjectType(ir::ETSImportDeclaration *importDecl, ir::Identifier *ident); void ImportNamespaceObjectTypeAddReExportType(ir::ETSImportDeclaration *importDecl, checker::ETSObjectType *lastObjectType, ir::Identifier *ident); diff --git a/ets2panda/checker/ets/helpers.cpp b/ets2panda/checker/ets/helpers.cpp index db7fa0974f..25eee1652d 100644 --- a/ets2panda/checker/ets/helpers.cpp +++ b/ets2panda/checker/ets/helpers.cpp @@ -2174,7 +2174,11 @@ ir::MethodDefinition *ETSChecker::GenerateDefaultGetterSetter(ir::ClassProperty paramScope->BindNode(func); functionScope->BindNode(func); - checker->VarBinder()->AsETSBinder()->ResolveMethodDefinition(method); + { + auto classCtx = varbinder::LexicalScope::Enter(checker->VarBinder(), classScope); + checker->VarBinder()->AsETSBinder()->ResolveMethodDefinition(method); + } + functionScope->BindName(classScope->Node()->AsClassDefinition()->InternalName()); method->Check(checker); @@ -2185,7 +2189,7 @@ void ETSChecker::GenerateGetterSetterPropertyAndMethod(ir::ClassProperty *origin { auto *const classDef = classType->GetDeclNode()->AsClassDefinition(); auto *interfaceProp = originalProp->Clone(Allocator(), originalProp->Parent()); - interfaceProp->ClearModifier(ir::ModifierFlags::GETTER_SETTER); + interfaceProp->ClearModifier(ir::ModifierFlags::GETTER_SETTER | ir::ModifierFlags::EXTERNAL); ASSERT(Scope()->IsClassScope()); auto *const scope = Scope()->AsClassScope(); @@ -2214,21 +2218,9 @@ void ETSChecker::GenerateGetterSetterPropertyAndMethod(ir::ClassProperty *origin auto *const decl = Allocator()->New(Allocator(), name, getter); auto *var = methodScope->AddDecl(Allocator(), decl, ScriptExtension::ETS); - ir::MethodDefinition *setter = nullptr; - if (!classProp->IsConst()) { - // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) - setter = GenerateDefaultGetterSetter(interfaceProp, classProp, scope, true, this); - if (((originalProp->Modifiers() & ir::ModifierFlags::SETTER) != 0U)) { - setter->Function()->AddModifier(ir::ModifierFlags::OVERRIDE); - } - setter->SetParent(classDef); - setter->TsType()->AddTypeFlag(TypeFlag::SETTER); - getter->Variable()->TsType()->AsETSFunctionType()->AddCallSignature( - setter->TsType()->AsETSFunctionType()->CallSignatures()[0]); - classType->AddProperty(setter->Variable()->AsLocalVariable()); - - getter->AddOverload(setter); - } + ir::MethodDefinition *setter = + !classProp->IsConst() ? GenerateSetterForProperty(originalProp, interfaceProp, classProp, classType, getter) + : nullptr; if (var == nullptr) { auto *const prevDecl = methodScope->FindDecl(name); @@ -2241,10 +2233,39 @@ void ETSChecker::GenerateGetterSetterPropertyAndMethod(ir::ClassProperty *origin var = methodScope->FindLocal(name, varbinder::ResolveBindingOptions::BINDINGS); } + if ((originalProp->Modifiers() & ir::ModifierFlags::EXTERNAL) != 0U) { + getter->Function()->AddFlag(ir::ScriptFunctionFlags::EXTERNAL); + } + var->AddFlag(varbinder::VariableFlags::METHOD); getter->Function()->Id()->SetVariable(var); } +ir::MethodDefinition *ETSChecker::GenerateSetterForProperty(ir::ClassProperty *originalProp, + ir::ClassProperty *interfaceProp, + ir::ClassProperty *classProp, ETSObjectType *classType, + ir::MethodDefinition *getter) +{ + ir::MethodDefinition *setter = + GenerateDefaultGetterSetter(interfaceProp, classProp, Scope()->AsClassScope(), true, this); + if (((originalProp->Modifiers() & ir::ModifierFlags::SETTER) != 0U)) { + setter->Function()->AddModifier(ir::ModifierFlags::OVERRIDE); + } + + if ((originalProp->Modifiers() & ir::ModifierFlags::EXTERNAL) != 0U) { + setter->Function()->AddFlag(ir::ScriptFunctionFlags::EXTERNAL); + } + + setter->SetParent(classType->GetDeclNode()->AsClassDefinition()); + setter->TsType()->AddTypeFlag(TypeFlag::SETTER); + getter->Variable()->TsType()->AsETSFunctionType()->AddCallSignature( + setter->TsType()->AsETSFunctionType()->CallSignatures()[0]); + classType->AddProperty(setter->Variable()->AsLocalVariable()); + getter->AddOverload(setter); + + return setter; +} + const Type *ETSChecker::TryGettingFunctionTypeFromInvokeFunction(const Type *type) const { if (type->IsETSObjectType() && type->AsETSObjectType()->HasObjectFlag(ETSObjectFlags::FUNCTIONAL)) { diff --git a/ets2panda/checker/ets/object.cpp b/ets2panda/checker/ets/object.cpp index e8b4580683..384573a269 100644 --- a/ets2panda/checker/ets/object.cpp +++ b/ets2panda/checker/ets/object.cpp @@ -701,11 +701,13 @@ void ETSChecker::ValidateOverriding(ETSObjectType *classType, const lexer::Sourc bool functionOverridden = false; bool isGetter = false; bool isSetter = false; + bool isExternal = false; for (auto abstractSignature = (*it)->CallSignatures().begin(); abstractSignature != (*it)->CallSignatures().end();) { bool foundSignature = false; isGetter = (*abstractSignature)->HasSignatureFlag(SignatureFlags::GETTER); isSetter = (*abstractSignature)->HasSignatureFlag(SignatureFlags::SETTER); + isExternal = (*abstractSignature)->Function()->IsExternal(); for (auto *const implemented : implementedSignatures) { Signature *substImplemented = AdjustForTypeParameters(*abstractSignature, implemented); @@ -749,6 +751,10 @@ void ETSChecker::ValidateOverriding(ETSObjectType *classType, const lexer::Sourc for (auto *field : classType->Fields()) { if (field->Name() == (*it)->Name()) { + if (isExternal) { + field->Declaration()->Node()->AddModifier(ir::ModifierFlags::EXTERNAL); + } + field->Declaration()->Node()->AddModifier(isGetter && isSetter ? ir::ModifierFlags::GETTER_SETTER : isGetter ? ir::ModifierFlags::GETTER : ir::ModifierFlags::SETTER); diff --git a/ets2panda/compiler/core/ETSemitter.cpp b/ets2panda/compiler/core/ETSemitter.cpp index ba49cbcf2f..dd4c1fae8b 100644 --- a/ets2panda/compiler/core/ETSemitter.cpp +++ b/ets2panda/compiler/core/ETSemitter.cpp @@ -140,6 +140,11 @@ static pandasm::Function GenScriptFunction(CompilerContext const *context, const pandasm::Function *ETSFunctionEmitter::GenFunctionSignature() { auto func = GenScriptFunction(Cg()->Context(), Cg()->RootNode()->AsScriptFunction()); + + if (Cg()->RootNode()->AsScriptFunction()->IsExternal()) { + func.metadata->SetAttribute(Signatures::EXTERNAL); + } + auto *funcElement = new pandasm::Function(func.name, func.language); *funcElement = std::move(func); GetProgramElement()->SetFunction(funcElement); diff --git a/ets2panda/ir/astNodeFlags.h b/ets2panda/ir/astNodeFlags.h index 9ae838d974..ffd34027a9 100644 --- a/ets2panda/ir/astNodeFlags.h +++ b/ets2panda/ir/astNodeFlags.h @@ -53,6 +53,7 @@ enum class ModifierFlags : uint32_t { SETTER = 1U << 22U, DEFAULT_EXPORT = 1U << 23U, EXPORT_TYPE = 1U << 24U, + EXTERNAL = 1U << 25U, ACCESS = PUBLIC | PROTECTED | PRIVATE | INTERNAL, ALL = STATIC | ASYNC | ACCESS | DECLARE | READONLY | ABSTRACT, ALLOWED_IN_CTOR_PARAMETER = ACCESS | READONLY, diff --git a/ets2panda/test/compiler/ets/import_tests/export_class_with_getters_setters-expected.txt b/ets2panda/test/compiler/ets/import_tests/export_class_with_getters_setters-expected.txt new file mode 100644 index 0000000000..c59ee7adad --- /dev/null +++ b/ets2panda/test/compiler/ets/import_tests/export_class_with_getters_setters-expected.txt @@ -0,0 +1,1083 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "TestClass", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 14 + }, + "end": { + "line": 16, + "column": 23 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 26 + }, + "end": { + "line": 16, + "column": 26 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 24 + }, + "end": { + "line": 16, + "column": 26 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 16, + "column": 26 + } + } + }, + { + "type": "TSInterfaceDeclaration", + "body": { + "type": "TSInterfaceBody", + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "node", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "node", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "TestClass", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "declare": true, + "loc": { + "start": { + "line": 19, + "column": 3 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 3 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "overloads": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "node", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "node", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "node", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "TestClass", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 3 + }, + "end": { + "line": 19, + "column": 7 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 3 + }, + "end": { + "line": 19, + "column": 7 + } + } + } + ], + "declare": true, + "loc": { + "start": { + "line": 19, + "column": 3 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 3 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 3 + }, + "end": { + "line": 20, + "column": 2 + } + } + } + ], + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 3 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "node", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "node", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "node", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "TestClass", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 3 + }, + "end": { + "line": 19, + "column": 7 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 3 + }, + "end": { + "line": 19, + "column": 7 + } + } + } + ], + "declare": true, + "loc": { + "start": { + "line": 19, + "column": 3 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 3 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 3 + }, + "end": { + "line": 20, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 24 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "id": { + "type": "Identifier", + "name": "ManagedScope", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 11 + }, + "end": { + "line": 18, + "column": 23 + } + } + }, + "extends": [], + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 22, + "column": 7 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ScopeImpl", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 14 + }, + "end": { + "line": 22, + "column": 23 + } + } + }, + "superClass": null, + "implements": [ + { + "type": "TSClassImplements", + "expression": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "ManagedScope", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 35 + }, + "end": { + "line": 22, + "column": 47 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 35 + }, + "end": { + "line": 22, + "column": 49 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 35 + }, + "end": { + "line": 22, + "column": 49 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 35 + }, + "end": { + "line": 22, + "column": 49 + } + } + } + ], + "body": [ + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "node", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 3 + }, + "end": { + "line": 23, + "column": 7 + } + } + }, + "value": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "TestClass", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 25 + }, + "end": { + "line": 23, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 25 + }, + "end": { + "line": 23, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 25 + }, + "end": { + "line": 23, + "column": 35 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 23, + "column": 21 + }, + "end": { + "line": 24, + "column": 2 + } + } + }, + "accessibility": "public", + "static": false, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "TestClass", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 9 + }, + "end": { + "line": 23, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 9 + }, + "end": { + "line": 23, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 9 + }, + "end": { + "line": 23, + "column": 20 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 3 + }, + "end": { + "line": 24, + "column": 2 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 2 + }, + "end": { + "line": 24, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 22, + "column": 48 + }, + "end": { + "line": 24, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 8 + }, + "end": { + "line": 24, + "column": 2 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 25, + "column": 1 + } + } +} diff --git a/ets2panda/test/compiler/ets/import_tests/export_class_with_getters_setters.ets b/ets2panda/test/compiler/ets/import_tests/export_class_with_getters_setters.ets new file mode 100644 index 0000000000..08f480aa13 --- /dev/null +++ b/ets2panda/test/compiler/ets/import_tests/export_class_with_getters_setters.ets @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export class TestClass {} + +interface ManagedScope { + node: TestClass +} + +export class ScopeImpl implements ManagedScope { + node: TestClass = new TestClass() +} diff --git a/ets2panda/test/compiler/ets/import_tests/import_class_with_getters_setters-expected.txt b/ets2panda/test/compiler/ets/import_tests/import_class_with_getters_setters-expected.txt new file mode 100644 index 0000000000..665ead9d92 --- /dev/null +++ b/ets2panda/test/compiler/ets/import_tests/import_class_with_getters_setters-expected.txt @@ -0,0 +1,789 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ImportDeclaration", + "source": { + "type": "StringLiteral", + "value": "./export_class_with_getters_setters", + "loc": { + "start": { + "line": 16, + "column": 38 + }, + "end": { + "line": 16, + "column": 75 + } + } + }, + "specifiers": [ + { + "type": "ImportSpecifier", + "local": { + "type": "Identifier", + "name": "TestClass", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 10 + }, + "end": { + "line": 16, + "column": 19 + } + } + }, + "imported": { + "type": "Identifier", + "name": "TestClass", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 10 + }, + "end": { + "line": 16, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 10 + }, + "end": { + "line": 16, + "column": 19 + } + } + }, + { + "type": "ImportSpecifier", + "local": { + "type": "Identifier", + "name": "ScopeImpl", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 21 + }, + "end": { + "line": 16, + "column": 30 + } + } + }, + "imported": { + "type": "Identifier", + "name": "ScopeImpl", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 21 + }, + "end": { + "line": 16, + "column": 30 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 21 + }, + "end": { + "line": 16, + "column": 30 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 16, + "column": 76 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 14 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 18, + "column": 18 + }, + "end": { + "line": 18, + "column": 22 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "a", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 7 + }, + "end": { + "line": 19, + "column": 8 + } + } + }, + "init": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "ScopeImpl", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 15 + }, + "end": { + "line": 19, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 15 + }, + "end": { + "line": 19, + "column": 25 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 15 + }, + "end": { + "line": 19, + "column": 25 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 19, + "column": 11 + }, + "end": { + "line": 19, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 7 + }, + "end": { + "line": 19, + "column": 27 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 19, + "column": 3 + }, + "end": { + "line": 19, + "column": 27 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "b", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "TestClass", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 10 + }, + "end": { + "line": 20, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 10 + }, + "end": { + "line": 20, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 10 + }, + "end": { + "line": 20, + "column": 21 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 7 + }, + "end": { + "line": 20, + "column": 8 + } + } + }, + "init": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "TestClass", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 26 + }, + "end": { + "line": 20, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 26 + }, + "end": { + "line": 20, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 26 + }, + "end": { + "line": 20, + "column": 36 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 20, + "column": 22 + }, + "end": { + "line": 20, + "column": 38 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 7 + }, + "end": { + "line": 20, + "column": 38 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 20, + "column": 3 + }, + "end": { + "line": 20, + "column": 38 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "b", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 3 + }, + "end": { + "line": 21, + "column": 4 + } + } + }, + "right": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "a", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 7 + }, + "end": { + "line": 21, + "column": 8 + } + } + }, + "property": { + "type": "Identifier", + "name": "node", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 9 + }, + "end": { + "line": 21, + "column": 13 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 21, + "column": 7 + }, + "end": { + "line": 21, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 3 + }, + "end": { + "line": 21, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 3 + }, + "end": { + "line": 21, + "column": 14 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "a", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 3 + }, + "end": { + "line": 22, + "column": 4 + } + } + }, + "property": { + "type": "Identifier", + "name": "node", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 5 + }, + "end": { + "line": 22, + "column": 9 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 22, + "column": 3 + }, + "end": { + "line": 22, + "column": 9 + } + } + }, + "right": { + "type": "Identifier", + "name": "b", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 12 + }, + "end": { + "line": 22, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 3 + }, + "end": { + "line": 22, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 3 + }, + "end": { + "line": 22, + "column": 14 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 23 + }, + "end": { + "line": 23, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 23, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 23, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 23, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 24, + "column": 1 + } + } +} diff --git a/ets2panda/test/compiler/ets/import_tests/import_class_with_getters_setters.ets b/ets2panda/test/compiler/ets/import_tests/import_class_with_getters_setters.ets new file mode 100644 index 0000000000..72c06e675f --- /dev/null +++ b/ets2panda/test/compiler/ets/import_tests/import_class_with_getters_setters.ets @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { TestClass, ScopeImpl } from "./export_class_with_getters_setters"; + +function main(): void { + let a = new ScopeImpl(); + let b: TestClass = new TestClass(); + b = a.node; + a.node = b; +} -- Gitee From 2058b684f91745552c53db53a481e0f54e04c59a Mon Sep 17 00:00:00 2001 From: ozerovnikita Date: Thu, 4 Apr 2024 16:46:08 +0300 Subject: [PATCH 17/22] add error message for interface member initialization Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/I96ROK Testing: runner.sh --parser Signed-off-by: ozerovnikita --- ets2panda/parser/TypedParser.cpp | 3 +++ ...terface_member_initialization-expected.txt | 1 + .../ets/interface_member_initialization.ets | 23 +++++++++++++++++++ 3 files changed, 27 insertions(+) create mode 100644 ets2panda/test/parser/ets/interface_member_initialization-expected.txt create mode 100644 ets2panda/test/parser/ets/interface_member_initialization.ets diff --git a/ets2panda/parser/TypedParser.cpp b/ets2panda/parser/TypedParser.cpp index 037b2da827..6fc76a3fd3 100644 --- a/ets2panda/parser/TypedParser.cpp +++ b/ets2panda/parser/TypedParser.cpp @@ -547,6 +547,9 @@ ArenaVector TypedParser::ParseTypeLiteralOrInterfaceBody() if (Lexer()->GetToken().Type() != lexer::TokenType::PUNCTUATOR_COMMA && Lexer()->GetToken().Type() != lexer::TokenType::PUNCTUATOR_SEMI_COLON) { + if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_SUBSTITUTION) { + ThrowSyntaxError("Interface member initialization is prohibited"); + } if (!Lexer()->GetToken().NewLine()) { ThrowSyntaxError("',' expected"); } diff --git a/ets2panda/test/parser/ets/interface_member_initialization-expected.txt b/ets2panda/test/parser/ets/interface_member_initialization-expected.txt new file mode 100644 index 0000000000..bbc8b1c2e4 --- /dev/null +++ b/ets2panda/test/parser/ets/interface_member_initialization-expected.txt @@ -0,0 +1 @@ +SyntaxError: Interface member initialization is prohibited [interface_member_initialization.ets:17:14] diff --git a/ets2panda/test/parser/ets/interface_member_initialization.ets b/ets2panda/test/parser/ets/interface_member_initialization.ets new file mode 100644 index 0000000000..3aae74b02f --- /dev/null +++ b/ets2panda/test/parser/ets/interface_member_initialization.ets @@ -0,0 +1,23 @@ +/** + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +interface Colors { + Red: int = 1; +} + +function main() +{ + +} -- Gitee From fb19cc80f0b6dd69fda72e8e68720c71af1cc2fc Mon Sep 17 00:00:00 2001 From: Zelentsov Dmitry Date: Sat, 27 Apr 2024 14:07:06 +0300 Subject: [PATCH 18/22] Title: Formatted Parsing of Type Parameters. Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/I9K5C1 Tests: build, CI Signed-off-by: Zelentsov Dmitry --- ets2panda/parser/ETSFormattedParser.cpp | 23 ++++- ets2panda/parser/ETSparser.h | 1 + ets2panda/parser/TypedParser.cpp | 109 ++++++++++++++++-------- ets2panda/parser/TypedParser.h | 4 + ets2panda/parser/parserImpl.cpp | 9 +- ets2panda/parser/parserImpl.h | 2 + 6 files changed, 108 insertions(+), 40 deletions(-) diff --git a/ets2panda/parser/ETSFormattedParser.cpp b/ets2panda/parser/ETSFormattedParser.cpp index e593df2fea..5de9e17507 100644 --- a/ets2panda/parser/ETSFormattedParser.cpp +++ b/ets2panda/parser/ETSFormattedParser.cpp @@ -34,7 +34,6 @@ namespace ark::es2panda::parser { inline constexpr char const FORMAT_SIGNATURE = '@'; inline constexpr char const TYPE_FORMAT_NODE = 'T'; inline constexpr char const GENERAL_FORMAT_NODE = 'N'; -inline constexpr char const EXPRESSION_FORMAT_NODE = 'E'; inline constexpr char const IDENTIFIER_FORMAT_NODE = 'I'; static constexpr char const INVALID_NUMBER_NODE[] = "Invalid node number in format expression."; @@ -173,6 +172,28 @@ ir::Statement *ETSParser::ParseStatementFormatPlaceholder() const return insertingNode->AsStatement(); } +ir::AstNode *ETSParser::ParseTypeParametersFormatPlaceholder() const +{ + ParserImpl::NodeFormatType nodeFormat = GetFormatPlaceholderType(); + if (std::get<0>(nodeFormat) || std::get<1>(nodeFormat) != EXPRESSION_FORMAT_NODE) { + ThrowSyntaxError(INVALID_FORMAT_NODE, Lexer()->GetToken().Start()); + } + + auto const placeholderNumber = std::get<2>(nodeFormat); + if (placeholderNumber >= insertingNodes_.size()) { + ThrowSyntaxError(INSERT_NODE_ABSENT, Lexer()->GetToken().Start()); + } + + auto *const insertingNode = insertingNodes_[placeholderNumber]; + if (insertingNode != nullptr && !insertingNode->IsTSTypeParameterDeclaration() && + !insertingNode->IsTSTypeParameterInstantiation()) { + ThrowSyntaxError(INVALID_INSERT_NODE, Lexer()->GetToken().Start()); + } + + Lexer()->NextToken(); + return insertingNode; +} + ArenaVector &ETSParser::ParseAstNodesArrayFormatPlaceholder() const { if (insertingNodes_.empty()) { diff --git a/ets2panda/parser/ETSparser.h b/ets2panda/parser/ETSparser.h index 756aff605f..f08fdfa4d5 100644 --- a/ets2panda/parser/ETSparser.h +++ b/ets2panda/parser/ETSparser.h @@ -193,6 +193,7 @@ private: ir::Expression *ParseExpressionFormatPlaceholder(); ir::Identifier *ParseIdentifierFormatPlaceholder(std::optional nodeFormat) const override; ir::TypeNode *ParseTypeFormatPlaceholder(std::optional nodeFormat = std::nullopt); + ir::AstNode *ParseTypeParametersFormatPlaceholder() const override; ArenaVector &ParseAstNodesArrayFormatPlaceholder() const override; ArenaVector &ParseStatementsArrayFormatPlaceholder() const override; diff --git a/ets2panda/parser/TypedParser.cpp b/ets2panda/parser/TypedParser.cpp index 6fc76a3fd3..bfabd1423f 100644 --- a/ets2panda/parser/TypedParser.cpp +++ b/ets2panda/parser/TypedParser.cpp @@ -707,15 +707,12 @@ ir::TSTypeParameter *TypedParser::ParseTypeParameter(TypeAnnotationParsingOption return typeParam; } -ir::TSTypeParameterDeclaration *TypedParser::ParseTypeParameterDeclaration(TypeAnnotationParsingOptions *options) +// Auxiliary method to reduce the size of functions. +ir::AstNode *TypedParser::ParseTypeParameterDeclarationImpl(TypeAnnotationParsingOptions *options) { - ASSERT(Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_LESS_THAN); - - lexer::SourcePosition startLoc = Lexer()->GetToken().Start(); ArenaVector params(Allocator()->Adapter()); bool seenDefault = false; - size_t requiredParams = 0; - Lexer()->NextToken(); // eat '<' + size_t requiredParams = 0U; while (Lexer()->GetToken().Type() != lexer::TokenType::PUNCTUATOR_GREATER_THAN) { auto newOptions = *options | TypeAnnotationParsingOptions::ADD_TYPE_PARAMETER_BINDING; @@ -736,31 +733,52 @@ ir::TSTypeParameterDeclaration *TypedParser::ParseTypeParameterDeclaration(TypeA params.push_back(currentParam); - if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_COMMA) { - Lexer()->NextToken(); - continue; + if (Lexer()->GetToken().Type() != lexer::TokenType::PUNCTUATOR_COMMA) { + break; } - if (Lexer()->GetToken().Type() != lexer::TokenType::PUNCTUATOR_GREATER_THAN) { - if ((newOptions & TypeAnnotationParsingOptions::THROW_ERROR) == 0) { - return nullptr; - } - - ThrowSyntaxError("'>' expected"); - } + Lexer()->NextToken(); } if (params.empty()) { ThrowSyntaxError("Type parameter list cannot be empty."); } + return AllocNode(std::move(params), requiredParams); +} + +ir::TSTypeParameterDeclaration *TypedParser::ParseTypeParameterDeclaration(TypeAnnotationParsingOptions *options) +{ + ASSERT(Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_LESS_THAN); + + lexer::SourcePosition startLoc = Lexer()->GetToken().Start(); + Lexer()->NextToken(); // eat '<' + + ir::AstNode *typeParamDecl; + + if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_FORMAT && + Lexer()->Lookahead() == static_cast(EXPRESSION_FORMAT_NODE)) { + typeParamDecl = ParseTypeParametersFormatPlaceholder(); + } else { + typeParamDecl = ParseTypeParameterDeclarationImpl(options); + } + + if (Lexer()->GetToken().Type() != lexer::TokenType::PUNCTUATOR_GREATER_THAN) { + if ((*options & TypeAnnotationParsingOptions::THROW_ERROR) == 0) { + return nullptr; + } + ThrowSyntaxError("Expected closing '>'."); + } + lexer::SourcePosition endLoc = Lexer()->GetToken().End(); Lexer()->NextToken(); // eat '>' - auto *typeParamDecl = AllocNode(std::move(params), requiredParams); - typeParamDecl->SetRange({startLoc, endLoc}); + if (typeParamDecl != nullptr) { + typeParamDecl->SetRange({startLoc, endLoc}); + return typeParamDecl->AsTSTypeParameterDeclaration(); + } - return typeParamDecl; + return nullptr; } ir::Expression *TypedParser::ParseSuperClassReference() @@ -1210,19 +1228,14 @@ ir::Expression *TypedParser::ParseQualifiedReference(ir::Expression *typeName, E return typeName; } -ir::TSTypeParameterInstantiation *TypedParser::ParseTypeParameterInstantiation(TypeAnnotationParsingOptions *options) +// Auxiliary method to reduce the size of functions. +ir::AstNode *TypedParser::ParseTypeParameterInstantiationImpl(TypeAnnotationParsingOptions *options) { - ASSERT(Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_LESS_THAN); - bool throwError = ((*options) & TypeAnnotationParsingOptions::THROW_ERROR) != 0; - lexer::SourcePosition startLoc = Lexer()->GetToken().Start(); ArenaVector params(Allocator()->Adapter()); - Lexer()->NextToken(); // eat '<' while (Lexer()->GetToken().Type() != lexer::TokenType::PUNCTUATOR_GREATER_THAN) { - TypeAnnotationParsingOptions tmp = *options; - *options &= ~TypeAnnotationParsingOptions::IGNORE_FUNCTION_TYPE; - ir::TypeNode *currentParam = ParseTypeAnnotation(options); - *options = tmp; + TypeAnnotationParsingOptions tmpOptions = *options &= ~TypeAnnotationParsingOptions::IGNORE_FUNCTION_TYPE; + ir::TypeNode *currentParam = ParseTypeAnnotation(&tmpOptions); if (currentParam == nullptr) { return nullptr; @@ -1247,23 +1260,45 @@ ir::TSTypeParameterInstantiation *TypedParser::ParseTypeParameterInstantiation(T break; } default: { - if (throwError) { - ThrowSyntaxError("'>' expected"); - } - return nullptr; } } } - lexer::SourcePosition endLoc = Lexer()->GetToken().End(); - Lexer()->NextToken(); + return AllocNode(std::move(params)); +} + +ir::TSTypeParameterInstantiation *TypedParser::ParseTypeParameterInstantiation(TypeAnnotationParsingOptions *options) +{ + ASSERT(Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_LESS_THAN); + + lexer::SourcePosition startLoc = Lexer()->GetToken().Start(); + Lexer()->NextToken(); // eat '<' + + ir::AstNode *typeParamInst; + if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_FORMAT && + Lexer()->Lookahead() == static_cast(EXPRESSION_FORMAT_NODE)) { + typeParamInst = ParseTypeParametersFormatPlaceholder(); + } else { + typeParamInst = ParseTypeParameterInstantiationImpl(options); + } + + if (Lexer()->GetToken().Type() != lexer::TokenType::PUNCTUATOR_GREATER_THAN) { + if ((*options & TypeAnnotationParsingOptions::THROW_ERROR) == 0) { + return nullptr; + } + ThrowSyntaxError("Expected closing '>'."); + } - auto *typeParamInst = AllocNode(std::move(params)); + lexer::SourcePosition endLoc = Lexer()->GetToken().End(); + Lexer()->NextToken(); // eat '>' - typeParamInst->SetRange({startLoc, endLoc}); + if (typeParamInst != nullptr) { + typeParamInst->SetRange({startLoc, endLoc}); + return typeParamInst->AsTSTypeParameterInstantiation(); + } - return typeParamInst; + return nullptr; } ir::Statement *TypedParser::ParseDeclareAndDecorators(StatementParsingFlags flags) diff --git a/ets2panda/parser/TypedParser.h b/ets2panda/parser/TypedParser.h index 69d59dbc2d..4ad1a1ccc4 100644 --- a/ets2panda/parser/TypedParser.h +++ b/ets2panda/parser/TypedParser.h @@ -42,9 +42,13 @@ protected: ir::ArrowFunctionExpression *ParseGenericArrowFunction(); ir::TSTypeAssertion *ParseTypeAssertion(); + ir::TSTypeParameterInstantiation *ParseTypeParameterInstantiation(TypeAnnotationParsingOptions *options); + ir::AstNode *ParseTypeParameterInstantiationImpl(TypeAnnotationParsingOptions *options); ir::TSTypeParameterDeclaration *ParseTypeParameterDeclaration(TypeAnnotationParsingOptions *options); + ir::AstNode *ParseTypeParameterDeclarationImpl(TypeAnnotationParsingOptions *options); + ir::Expression *ParseQualifiedName(ExpressionParseFlags flags = ExpressionParseFlags::NO_OPTS); ir::Expression *ParseQualifiedReference(ir::Expression *typeName, ExpressionParseFlags flags = ExpressionParseFlags::NO_OPTS); diff --git a/ets2panda/parser/parserImpl.cpp b/ets2panda/parser/parserImpl.cpp index c9dcc97c70..2fef7d6575 100644 --- a/ets2panda/parser/parserImpl.cpp +++ b/ets2panda/parser/parserImpl.cpp @@ -1092,12 +1092,17 @@ void ParserImpl::ThrowParameterModifierError(ir::ModifierFlags status) const ir::Identifier *ParserImpl::ParseIdentifierFormatPlaceholder( [[maybe_unused]] std::optional nodeFormat) const { - ThrowSyntaxError("Identifier expected"); + ThrowSyntaxError("Identifier expected."); } ir::Statement *ParserImpl::ParseStatementFormatPlaceholder() const { - ThrowSyntaxError("Statement expected"); + ThrowSyntaxError("Statement expected."); +} + +ir::AstNode *ParserImpl::ParseTypeParametersFormatPlaceholder() const +{ + ThrowSyntaxError("Type parameter(s) expected."); } ArenaVector &ParserImpl::ParseStatementsArrayFormatPlaceholder() const diff --git a/ets2panda/parser/parserImpl.h b/ets2panda/parser/parserImpl.h index d63f7ebcef..9f24cbb4d4 100644 --- a/ets2panda/parser/parserImpl.h +++ b/ets2panda/parser/parserImpl.h @@ -99,6 +99,7 @@ using FunctionSignature = std::tuple; virtual ir::Identifier *ParseIdentifierFormatPlaceholder(std::optional nodeFormat) const; virtual ir::Statement *ParseStatementFormatPlaceholder() const; + virtual ir::AstNode *ParseTypeParametersFormatPlaceholder() const; virtual ArenaVector &ParseAstNodesArrayFormatPlaceholder() const; virtual ArenaVector &ParseStatementsArrayFormatPlaceholder() const; virtual ArenaVector &ParseExpressionsArrayFormatPlaceholder() const; -- Gitee From 833c25bfb35d12f9eda275e198576e3c0a6adf59 Mon Sep 17 00:00:00 2001 From: aakmaev Date: Tue, 7 May 2024 13:15:51 +0300 Subject: [PATCH 19/22] Fix copyright Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/I9LGZ4 Testing : all CI tests passed. Results are availible in gg watcher. Signed-off-by: Akmaev Alexey --- ets2panda/test/compiler/ets/instanceof_dyndecl_dynvalue.ets | 2 +- ets2panda/test/compiler/ets/instanceof_dyndecl_jsvalue.ets | 2 +- ets2panda/test/compiler/ets/instanceof_dynvalue_dynvalue.ets | 2 +- ets2panda/test/compiler/ets/instanceof_dynvalue_jsvalue.ets | 2 +- ets2panda/test/compiler/ets/instanceof_etsobject_dynvalue.ets | 2 +- ets2panda/test/compiler/ets/instanceof_etsobject_jsvalue.ets | 2 +- ets2panda/test/compiler/ets/instanceof_jsvalue_dynvalue.ets | 2 +- ets2panda/test/compiler/ets/instanceof_jsvalue_jsvalue.ets | 2 +- ets2panda/test/compiler/ets/instanceof_object_dynvalue.ets | 2 +- ets2panda/test/compiler/ets/instanceof_object_jsvalue.ets | 2 +- ets2panda/test/compiler/ets/instanceof_object_long.ets | 2 +- ets2panda/test/compiler/ets/instanceof_x_dyndecl.ets | 2 +- ets2panda/test/compiler/ets/instanceof_x_etstype.ets | 2 +- ets2panda/test/compiler/ets/instanceof_x_object.ets | 2 +- .../public/ast_verifier_private_access_negative_test_1_4.cpp | 2 +- .../public/ast_verifier_private_access_negative_test_5_7.cpp | 2 +- ...st_verifier_private_protected_public_access_correct_test.cpp | 2 +- .../unit/public/ast_verifier_protected_access_correct_test.cpp | 2 +- .../public/ast_verifier_protected_access_negative_test_1_3.cpp | 2 +- .../public/ast_verifier_protected_access_negative_test_4_6.cpp | 2 +- ets2panda/test/unit/public/ast_verifier_short_test.cpp | 2 +- 21 files changed, 21 insertions(+), 21 deletions(-) diff --git a/ets2panda/test/compiler/ets/instanceof_dyndecl_dynvalue.ets b/ets2panda/test/compiler/ets/instanceof_dyndecl_dynvalue.ets index fa9938a3f7..fe9e626df2 100644 --- a/ets2panda/test/compiler/ets/instanceof_dyndecl_dynvalue.ets +++ b/ets2panda/test/compiler/ets/instanceof_dyndecl_dynvalue.ets @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Copyright (c) 2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/ets2panda/test/compiler/ets/instanceof_dyndecl_jsvalue.ets b/ets2panda/test/compiler/ets/instanceof_dyndecl_jsvalue.ets index 2a81461d09..1f9079bfe8 100644 --- a/ets2panda/test/compiler/ets/instanceof_dyndecl_jsvalue.ets +++ b/ets2panda/test/compiler/ets/instanceof_dyndecl_jsvalue.ets @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Copyright (c) 2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/ets2panda/test/compiler/ets/instanceof_dynvalue_dynvalue.ets b/ets2panda/test/compiler/ets/instanceof_dynvalue_dynvalue.ets index 8ca37c3bec..cb22f8eaf2 100644 --- a/ets2panda/test/compiler/ets/instanceof_dynvalue_dynvalue.ets +++ b/ets2panda/test/compiler/ets/instanceof_dynvalue_dynvalue.ets @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Copyright (c) 2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/ets2panda/test/compiler/ets/instanceof_dynvalue_jsvalue.ets b/ets2panda/test/compiler/ets/instanceof_dynvalue_jsvalue.ets index f9278149ca..f2edb27aac 100644 --- a/ets2panda/test/compiler/ets/instanceof_dynvalue_jsvalue.ets +++ b/ets2panda/test/compiler/ets/instanceof_dynvalue_jsvalue.ets @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Copyright (c) 2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/ets2panda/test/compiler/ets/instanceof_etsobject_dynvalue.ets b/ets2panda/test/compiler/ets/instanceof_etsobject_dynvalue.ets index 9b7cfc0afb..706874e5dd 100644 --- a/ets2panda/test/compiler/ets/instanceof_etsobject_dynvalue.ets +++ b/ets2panda/test/compiler/ets/instanceof_etsobject_dynvalue.ets @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Copyright (c) 2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/ets2panda/test/compiler/ets/instanceof_etsobject_jsvalue.ets b/ets2panda/test/compiler/ets/instanceof_etsobject_jsvalue.ets index d96765c6be..03a61006d1 100644 --- a/ets2panda/test/compiler/ets/instanceof_etsobject_jsvalue.ets +++ b/ets2panda/test/compiler/ets/instanceof_etsobject_jsvalue.ets @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Copyright (c) 2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/ets2panda/test/compiler/ets/instanceof_jsvalue_dynvalue.ets b/ets2panda/test/compiler/ets/instanceof_jsvalue_dynvalue.ets index 7d534d8049..0737247320 100644 --- a/ets2panda/test/compiler/ets/instanceof_jsvalue_dynvalue.ets +++ b/ets2panda/test/compiler/ets/instanceof_jsvalue_dynvalue.ets @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Copyright (c) 2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/ets2panda/test/compiler/ets/instanceof_jsvalue_jsvalue.ets b/ets2panda/test/compiler/ets/instanceof_jsvalue_jsvalue.ets index ab7ae309c6..6946a5e861 100644 --- a/ets2panda/test/compiler/ets/instanceof_jsvalue_jsvalue.ets +++ b/ets2panda/test/compiler/ets/instanceof_jsvalue_jsvalue.ets @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Copyright (c) 2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/ets2panda/test/compiler/ets/instanceof_object_dynvalue.ets b/ets2panda/test/compiler/ets/instanceof_object_dynvalue.ets index bddd3c6f00..d2a16a112c 100644 --- a/ets2panda/test/compiler/ets/instanceof_object_dynvalue.ets +++ b/ets2panda/test/compiler/ets/instanceof_object_dynvalue.ets @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Copyright (c) 2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/ets2panda/test/compiler/ets/instanceof_object_jsvalue.ets b/ets2panda/test/compiler/ets/instanceof_object_jsvalue.ets index 0103287ad8..44985bb3ab 100644 --- a/ets2panda/test/compiler/ets/instanceof_object_jsvalue.ets +++ b/ets2panda/test/compiler/ets/instanceof_object_jsvalue.ets @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Copyright (c) 2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/ets2panda/test/compiler/ets/instanceof_object_long.ets b/ets2panda/test/compiler/ets/instanceof_object_long.ets index 4ebec908d6..2e163d7dfb 100644 --- a/ets2panda/test/compiler/ets/instanceof_object_long.ets +++ b/ets2panda/test/compiler/ets/instanceof_object_long.ets @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Copyright (c) 2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/ets2panda/test/compiler/ets/instanceof_x_dyndecl.ets b/ets2panda/test/compiler/ets/instanceof_x_dyndecl.ets index 2c35b20e34..e3185fe319 100644 --- a/ets2panda/test/compiler/ets/instanceof_x_dyndecl.ets +++ b/ets2panda/test/compiler/ets/instanceof_x_dyndecl.ets @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Copyright (c) 2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/ets2panda/test/compiler/ets/instanceof_x_etstype.ets b/ets2panda/test/compiler/ets/instanceof_x_etstype.ets index 5d723962bb..7579954ad3 100644 --- a/ets2panda/test/compiler/ets/instanceof_x_etstype.ets +++ b/ets2panda/test/compiler/ets/instanceof_x_etstype.ets @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Copyright (c) 2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/ets2panda/test/compiler/ets/instanceof_x_object.ets b/ets2panda/test/compiler/ets/instanceof_x_object.ets index 93dde6e64f..e7c8aa4019 100644 --- a/ets2panda/test/compiler/ets/instanceof_x_object.ets +++ b/ets2panda/test/compiler/ets/instanceof_x_object.ets @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Copyright (c) 2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/ets2panda/test/unit/public/ast_verifier_private_access_negative_test_1_4.cpp b/ets2panda/test/unit/public/ast_verifier_private_access_negative_test_1_4.cpp index 14db5a0a64..9fdfdeb220 100644 --- a/ets2panda/test/unit/public/ast_verifier_private_access_negative_test_1_4.cpp +++ b/ets2panda/test/unit/public/ast_verifier_private_access_negative_test_1_4.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Copyright (c) 2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/ets2panda/test/unit/public/ast_verifier_private_access_negative_test_5_7.cpp b/ets2panda/test/unit/public/ast_verifier_private_access_negative_test_5_7.cpp index df0e93e385..42cbab0dd5 100644 --- a/ets2panda/test/unit/public/ast_verifier_private_access_negative_test_5_7.cpp +++ b/ets2panda/test/unit/public/ast_verifier_private_access_negative_test_5_7.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Copyright (c) 2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/ets2panda/test/unit/public/ast_verifier_private_protected_public_access_correct_test.cpp b/ets2panda/test/unit/public/ast_verifier_private_protected_public_access_correct_test.cpp index 8d83ed334f..3a8684a558 100644 --- a/ets2panda/test/unit/public/ast_verifier_private_protected_public_access_correct_test.cpp +++ b/ets2panda/test/unit/public/ast_verifier_private_protected_public_access_correct_test.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Copyright (c) 2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/ets2panda/test/unit/public/ast_verifier_protected_access_correct_test.cpp b/ets2panda/test/unit/public/ast_verifier_protected_access_correct_test.cpp index 530c6771f4..dccd77f94d 100644 --- a/ets2panda/test/unit/public/ast_verifier_protected_access_correct_test.cpp +++ b/ets2panda/test/unit/public/ast_verifier_protected_access_correct_test.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Copyright (c) 2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/ets2panda/test/unit/public/ast_verifier_protected_access_negative_test_1_3.cpp b/ets2panda/test/unit/public/ast_verifier_protected_access_negative_test_1_3.cpp index 478d06ebb3..65f3c23ca2 100644 --- a/ets2panda/test/unit/public/ast_verifier_protected_access_negative_test_1_3.cpp +++ b/ets2panda/test/unit/public/ast_verifier_protected_access_negative_test_1_3.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Copyright (c) 2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/ets2panda/test/unit/public/ast_verifier_protected_access_negative_test_4_6.cpp b/ets2panda/test/unit/public/ast_verifier_protected_access_negative_test_4_6.cpp index 71c1e6e417..0c74daea04 100644 --- a/ets2panda/test/unit/public/ast_verifier_protected_access_negative_test_4_6.cpp +++ b/ets2panda/test/unit/public/ast_verifier_protected_access_negative_test_4_6.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Copyright (c) 2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/ets2panda/test/unit/public/ast_verifier_short_test.cpp b/ets2panda/test/unit/public/ast_verifier_short_test.cpp index 5564389bbc..8a8add093b 100644 --- a/ets2panda/test/unit/public/ast_verifier_short_test.cpp +++ b/ets2panda/test/unit/public/ast_verifier_short_test.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Copyright (c) 2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at -- Gitee From c791e95c434c2a50f2653ba6972f52ac2f278085 Mon Sep 17 00:00:00 2001 From: l00799755 Date: Mon, 29 Apr 2024 15:24:39 +0800 Subject: [PATCH 20/22] Fix syntaxError of declaring final class Issue:https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/I9KO3S Reason Cannot declare final class(ambient declarations) Description Add keyword 'final' when checking declare Tests ninja es2panda_tests bash ets_testtunner.sh --cts -r -rt All required pre-merge tests passed. Results are available in the ggwatcher. Signed-off-by: l00799755 --- ets2panda/parser/ETSparser.cpp | 1 + ...bient_declaration_final_class-expected.txt | 290 ++++++++++++++++++ .../ets/ambient_declaration_final_class.ets | 16 + 3 files changed, 307 insertions(+) create mode 100644 ets2panda/test/parser/ets/ambient_declaration_final_class-expected.txt create mode 100644 ets2panda/test/parser/ets/ambient_declaration_final_class.ets diff --git a/ets2panda/parser/ETSparser.cpp b/ets2panda/parser/ETSparser.cpp index 2646d717a0..4ee4c681c6 100644 --- a/ets2panda/parser/ETSparser.cpp +++ b/ets2panda/parser/ETSparser.cpp @@ -4082,6 +4082,7 @@ void ETSParser::CheckDeclare() case lexer::TokenType::KEYW_ENUM: case lexer::TokenType::KEYW_TYPE: case lexer::TokenType::KEYW_ABSTRACT: + case lexer::TokenType::KEYW_FINAL: case lexer::TokenType::KEYW_INTERFACE: { return; } diff --git a/ets2panda/test/parser/ets/ambient_declaration_final_class-expected.txt b/ets2panda/test/parser/ets/ambient_declaration_final_class-expected.txt new file mode 100644 index 0000000000..5e91432c72 --- /dev/null +++ b/ets2panda/test/parser/ets/ambient_declaration_final_class-expected.txt @@ -0,0 +1,290 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 21 + }, + "end": { + "line": 16, + "column": 22 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 25 + }, + "end": { + "line": 16, + "column": 25 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 23 + }, + "end": { + "line": 16, + "column": 25 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 15 + }, + "end": { + "line": 16, + "column": 25 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 17, + "column": 1 + } + } +} diff --git a/ets2panda/test/parser/ets/ambient_declaration_final_class.ets b/ets2panda/test/parser/ets/ambient_declaration_final_class.ets new file mode 100644 index 0000000000..9e8c53a242 --- /dev/null +++ b/ets2panda/test/parser/ets/ambient_declaration_final_class.ets @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +declare final class B {} -- Gitee From 12254ab50abd1cacf7f75a893dc18be00305a558 Mon Sep 17 00:00:00 2001 From: l00799755 Date: Thu, 25 Apr 2024 19:29:03 +0800 Subject: [PATCH 21/22] Fix bug in default generic parameter Issue:https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/I9KD9L Reason When no generic parameters are provided for instantiating, a type check failure occurs between the constructor and the instantiation arguments during the constructor call. This shouldn't happen, because the type of the instantiation argument is consistent with the default generic parameter type. Description Substitute typeParams with default generic parameters in instantiation. Tests ninja es2panda_tests bash ets_testtunner.sh --cts -r -rt All required pre-merge tests passed. Results are available in the ggwatcher. Signed-off-by: l00799755 --- ets2panda/checker/ets/typeRelationContext.cpp | 3 +- .../ets/genericDefaultParam_4-expected.txt | 887 ++++++++++++++++++ .../test/parser/ets/genericDefaultParam_4.ets | 24 + .../runtime/ets/generic_default_param.ets | 27 + 4 files changed, 940 insertions(+), 1 deletion(-) create mode 100644 ets2panda/test/parser/ets/genericDefaultParam_4-expected.txt create mode 100644 ets2panda/test/parser/ets/genericDefaultParam_4.ets create mode 100644 ets2panda/test/runtime/ets/generic_default_param.ets diff --git a/ets2panda/checker/ets/typeRelationContext.cpp b/ets2panda/checker/ets/typeRelationContext.cpp index 7d03ff0b84..86780f246f 100644 --- a/ets2panda/checker/ets/typeRelationContext.cpp +++ b/ets2panda/checker/ets/typeRelationContext.cpp @@ -156,7 +156,8 @@ void InstantiationContext::InstantiateType(ETSObjectType *type, ir::TSTypeParame } while (typeArgTypes.size() < type->TypeArguments().size()) { - typeArgTypes.push_back(type->TypeArguments().at(typeArgTypes.size())); + auto *defaultType = type->TypeArguments().at(typeArgTypes.size())->AsETSTypeParameter()->GetDefaultType(); + typeArgTypes.push_back(defaultType); } InstantiateType(type, typeArgTypes, (typeArgs == nullptr) ? lexer::SourcePosition() : typeArgs->Range().start); diff --git a/ets2panda/test/parser/ets/genericDefaultParam_4-expected.txt b/ets2panda/test/parser/ets/genericDefaultParam_4-expected.txt new file mode 100644 index 0000000000..95f5b509ac --- /dev/null +++ b/ets2panda/test/parser/ets/genericDefaultParam_4-expected.txt @@ -0,0 +1,887 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 15, + "column": 7 + }, + "end": { + "line": 15, + "column": 8 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 15, + "column": 9 + }, + "end": { + "line": 15, + "column": 10 + } + } + }, + "default": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "decorators": [], + "loc": { + "start": { + "line": 15, + "column": 11 + }, + "end": { + "line": 15, + "column": 17 + } + } + }, + "loc": { + "start": { + "line": 15, + "column": 11 + }, + "end": { + "line": 15, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 15, + "column": 11 + }, + "end": { + "line": 15, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 15, + "column": 9 + }, + "end": { + "line": 15, + "column": 18 + } + } + } + ], + "loc": { + "start": { + "line": 15, + "column": 8 + }, + "end": { + "line": 15, + "column": 18 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "data", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 5 + }, + "end": { + "line": 16, + "column": 9 + } + } + }, + "accessibility": "public", + "static": false, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 12 + }, + "end": { + "line": 16, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 12 + }, + "end": { + "line": 17, + "column": 16 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 12 + }, + "end": { + "line": 17, + "column": 16 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 5 + }, + "end": { + "line": 17, + "column": 16 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "accessibility": "public", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "t", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 21 + }, + "end": { + "line": 17, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 21 + }, + "end": { + "line": 17, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 21 + }, + "end": { + "line": 17, + "column": 23 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 17 + }, + "end": { + "line": 17, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 17 + }, + "end": { + "line": 17, + "column": 23 + } + } + } + ], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "MemberExpression", + "object": { + "type": "ThisExpression", + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 13 + } + } + }, + "property": { + "type": "Identifier", + "name": "data", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 18, + "column": 18 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 18 + } + } + }, + "right": { + "type": "Identifier", + "name": "t", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 21 + }, + "end": { + "line": 18, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 23 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 24 + }, + "end": { + "line": 19, + "column": 6 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 16 + }, + "end": { + "line": 19, + "column": 6 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 16 + }, + "end": { + "line": 19, + "column": 6 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 5 + }, + "end": { + "line": 19, + "column": 6 + } + } + } + ], + "loc": { + "start": { + "line": 15, + "column": 19 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 15, + "column": 1 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 10 + }, + "end": { + "line": 22, + "column": 14 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 10 + }, + "end": { + "line": 22, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 22, + "column": 19 + }, + "end": { + "line": 22, + "column": 23 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "a1", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 9 + }, + "end": { + "line": 23, + "column": 11 + } + } + }, + "init": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 18 + }, + "end": { + "line": 23, + "column": 19 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 20 + }, + "end": { + "line": 23, + "column": 26 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 20 + }, + "end": { + "line": 23, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 20 + }, + "end": { + "line": 23, + "column": 27 + } + } + } + ], + "loc": { + "start": { + "line": 23, + "column": 19 + }, + "end": { + "line": 23, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 18 + }, + "end": { + "line": 23, + "column": 28 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 18 + }, + "end": { + "line": 23, + "column": 28 + } + } + }, + "arguments": [ + { + "type": "StringLiteral", + "value": "hello", + "loc": { + "start": { + "line": 23, + "column": 28 + }, + "end": { + "line": 23, + "column": 35 + } + } + } + ], + "loc": { + "start": { + "line": 23, + "column": 14 + }, + "end": { + "line": 24, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 9 + }, + "end": { + "line": 24, + "column": 2 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 23, + "column": 5 + }, + "end": { + "line": 24, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 22, + "column": 24 + }, + "end": { + "line": 24, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 14 + }, + "end": { + "line": 24, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 14 + }, + "end": { + "line": 24, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 1 + }, + "end": { + "line": 24, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 25, + "column": 1 + } + } +} +TypeError: Type 'string' is not compatible with type 'Double' at index 1 [genericDefaultParam_4.ets:23:28] diff --git a/ets2panda/test/parser/ets/genericDefaultParam_4.ets b/ets2panda/test/parser/ets/genericDefaultParam_4.ets new file mode 100644 index 0000000000..c65b639d8b --- /dev/null +++ b/ets2panda/test/parser/ets/genericDefaultParam_4.ets @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +class A { + data : T + constructor(t : T) { + this.data = t; + } +} + +function main() : void { + let a1 = new A("hello") +} diff --git a/ets2panda/test/runtime/ets/generic_default_param.ets b/ets2panda/test/runtime/ets/generic_default_param.ets new file mode 100644 index 0000000000..91d44f2524 --- /dev/null +++ b/ets2panda/test/runtime/ets/generic_default_param.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +class A { + data : T + constructor(t : T) { + this.data = t; + } +} + +function main() : void { + let a = new A("hello"); + let a1 = new A("world") + assert a.data instanceof string + assert a1.data instanceof string +} -- Gitee From ba07ad17e37818bd3c1b637c67fe51197a19c834 Mon Sep 17 00:00:00 2001 From: Ede Monus Date: Mon, 13 May 2024 09:07:54 +0200 Subject: [PATCH 22/22] [ETS] Fix type inference and overloading for async functions Fixes the behaviour as the name suggests by revising the logic behind async function implmentation creation. Fixes #15920 internal issue Change-Id: I4f18b2b80e7a62fe7afe1ed835b28107d5e26455 Signed-off-by: Ede Monus --- ets2panda/checker/ETSAnalyzer.cpp | 9 ++- ets2panda/checker/ETSAnalyzerHelpers.cpp | 80 ++++++++++++++++--- ets2panda/checker/ETSAnalyzerHelpers.h | 3 + ets2panda/checker/ets/function.cpp | 56 ++++++++----- ets2panda/checker/ets/object.cpp | 21 ++--- .../types/ets/etsAsyncFuncReturnType.h | 10 +++ .../compiler/lowering/ets/promiseVoid.cpp | 6 +- ets2panda/ir/astNodeFlags.h | 3 +- ets2panda/ir/base/methodDefinition.h | 39 ++++++++- ets2panda/ir/base/scriptFunction.h | 10 +++ .../async-func-overload-and-type-infer.ets | 40 ++++++++++ 11 files changed, 228 insertions(+), 49 deletions(-) create mode 100644 ets2panda/test/runtime/ets/async-func-overload-and-type-infer.ets diff --git a/ets2panda/checker/ETSAnalyzer.cpp b/ets2panda/checker/ETSAnalyzer.cpp index 2ebfd84bc4..28dcfcdacc 100644 --- a/ets2panda/checker/ETSAnalyzer.cpp +++ b/ets2panda/checker/ETSAnalyzer.cpp @@ -22,6 +22,7 @@ #include "checker/ets/typeRelationContext.h" #include "checker/types/globalTypesHolder.h" #include "checker/types/ets/etsTupleType.h" +#include "checker/types/ets/etsAsyncFuncReturnType.h" namespace ark::es2panda::checker { @@ -163,13 +164,17 @@ checker::Type *ETSAnalyzer::Check(ir::MethodDefinition *node) const } } + if (IsAsyncMethod(node)) { + HandleAsyncMethodCheck(checker, node); + } + DoBodyTypeChecking(checker, node, scriptFunc); CheckPredefinedMethodReturnType(checker, scriptFunc); checker->CheckOverride(node->TsType()->AsETSFunctionType()->FindSignature(node->Function())); - for (auto *it : node->Overloads()) { - it->Check(checker); + for (auto *overload : node->Overloads()) { + overload->Check(checker); } if (scriptFunc->IsRethrowing()) { diff --git a/ets2panda/checker/ETSAnalyzerHelpers.cpp b/ets2panda/checker/ETSAnalyzerHelpers.cpp index 481c0fd71e..ddd15d67f1 100644 --- a/ets2panda/checker/ETSAnalyzerHelpers.cpp +++ b/ets2panda/checker/ETSAnalyzerHelpers.cpp @@ -14,6 +14,7 @@ */ #include "ETSAnalyzerHelpers.h" +#include "checker/types/ets/etsAsyncFuncReturnType.h" namespace ark::es2panda::checker { @@ -85,9 +86,10 @@ void DoBodyTypeChecking(ETSChecker *checker, ir::MethodDefinition *node, ir::Scr } if (scriptFunc->IsAsyncFunc()) { - auto *retType = scriptFunc->Signature()->ReturnType(); - if (!retType->IsETSObjectType() || - retType->AsETSObjectType()->GetOriginalBaseType() != checker->GlobalBuiltinPromiseType()) { + auto *asyncFuncReturnType = scriptFunc->Signature()->ReturnType(); + + if (!asyncFuncReturnType->IsETSObjectType() || + asyncFuncReturnType->AsETSObjectType()->GetOriginalBaseType() != checker->GlobalBuiltinPromiseType()) { checker->ThrowTypeError("Return type of async function must be 'Promise'.", scriptFunc->Start()); } } else if (scriptFunc->HasBody() && !scriptFunc->IsExternal()) { @@ -112,6 +114,10 @@ void DoBodyTypeChecking(ETSChecker *checker, ir::MethodDefinition *node, ir::Scr scriptFunc->Body()->Check(checker); if (scriptFunc->ReturnTypeAnnotation() == nullptr) { + if (scriptFunc->IsAsyncImplFunc()) { + SetAsyncImplFuncReturnType(checker, scriptFunc); + } + for (auto &returnStatement : scriptFunc->ReturnStatements()) { returnStatement->SetReturnType(checker, scriptFunc->Signature()->ReturnType()); } @@ -121,6 +127,54 @@ void DoBodyTypeChecking(ETSChecker *checker, ir::MethodDefinition *node, ir::Scr } } +void SetAsyncImplFuncReturnType(ETSChecker *checker, ir::ScriptFunction *scriptFunc) +{ + const auto &promiseGlobal = checker->GlobalBuiltinPromiseType()->AsETSObjectType(); + auto promiseType = + promiseGlobal->Instantiate(checker->Allocator(), checker->Relation(), checker->GetGlobalTypesHolder()) + ->AsETSObjectType(); + promiseType->AddTypeFlag(checker::TypeFlag::GENERIC); + promiseType->TypeArguments().clear(); + promiseType->TypeArguments().emplace_back(scriptFunc->Signature()->ReturnType()); + + auto *objectId = + checker->AllocNode(compiler::Signatures::BUILTIN_OBJECT_CLASS, checker->Allocator()); + objectId->SetReference(); + checker->VarBinder()->AsETSBinder()->LookupTypeReference(objectId, false); + auto *returnType = checker->AllocNode( + checker->AllocNode(objectId, nullptr, nullptr)); + objectId->SetParent(returnType->Part()); + returnType->Part()->SetParent(returnType); + returnType->SetTsType( + checker->Allocator()->New(checker->Allocator(), checker->Relation(), promiseType)); + returnType->Check(checker); + scriptFunc->Signature()->SetReturnType(returnType->TsType()); +} + +void HandleAsyncMethodCheck(ETSChecker *checker, ir::MethodDefinition *node) +{ + auto *classDef = node->Parent()->AsClassDefinition(); + auto *scriptFunc = node->Function(); + ir::MethodDefinition *implMethod = checker->CreateAsyncProxy(node, classDef); + + implMethod->Check(checker); + node->SetAsyncPairMethod(implMethod); + + if (scriptFunc->Signature()->HasSignatureFlag(SignatureFlags::NEED_RETURN_TYPE)) { + node->Function()->Signature()->SetReturnType( + implMethod->Function()->Signature()->ReturnType()->AsETSAsyncFuncReturnType()->PromiseType()); + scriptFunc->Signature()->RemoveSignatureFlag(SignatureFlags::NEED_RETURN_TYPE); + } + + if (node->Function()->IsOverload()) { + auto *overloadedImplMethod = node->Overloaded()->AsyncPairMethod(); + implMethod->Function()->Id()->SetVariable(overloadedImplMethod->Function()->Id()->Variable()); + overloadedImplMethod->AddOverload(implMethod); + } else { + classDef->Body().push_back(implMethod); + } +} + void CheckPredefinedMethodReturnType(ETSChecker *checker, ir::ScriptFunction *scriptFunc) { auto const &position = scriptFunc->Start(); @@ -522,6 +576,7 @@ void InferReturnType(ETSChecker *checker, ir::ScriptFunction *containingFunc, ch containingFunc->Signature()->SetReturnType(funcReturnType); containingFunc->Signature()->RemoveSignatureFlag(checker::SignatureFlags::NEED_RETURN_TYPE); + containingFunc->Signature()->AddSignatureFlag(checker::SignatureFlags::INFERRED_RETURN_TYPE); checker->VarBinder()->AsETSBinder()->BuildFunctionName(containingFunc); if (stArgument != nullptr && stArgument->IsObjectExpression()) { @@ -541,15 +596,6 @@ void ProcessReturnStatements(ETSChecker *checker, ir::ScriptFunction *containing st->Start()); } } else { - // previous return statement(s) don't have any value - if (funcReturnType->IsETSVoidType() || funcReturnType == checker->GlobalVoidType()) { - checker->ThrowTypeError("All return statements in the function should be empty or have a value.", - stArgument->Start()); - } - - const auto name = containingFunc->Scope()->InternalName().Mutf8(); - CheckArgumentVoidType(funcReturnType, checker, name, st); - if (stArgument->IsObjectExpression()) { stArgument->AsObjectExpression()->SetPreferredType(funcReturnType); } @@ -559,6 +605,16 @@ void ProcessReturnStatements(ETSChecker *checker, ir::ScriptFunction *containing } checker::Type *argumentType = stArgument->Check(checker); + + // previous return statement(s) don't have any value + if (funcReturnType->IsETSVoidType() && !argumentType->IsETSVoidType()) { + checker->ThrowTypeError("All return statements in the function should be empty or have a value.", + stArgument->Start()); + } + + const auto name = containingFunc->Scope()->InternalName().Mutf8(); + CheckArgumentVoidType(funcReturnType, checker, name, st); + // remove CONSTANT type modifier if exists if (argumentType->HasTypeFlag(checker::TypeFlag::CONSTANT)) { argumentType = diff --git a/ets2panda/checker/ETSAnalyzerHelpers.h b/ets2panda/checker/ETSAnalyzerHelpers.h index 5c0ee257fb..65bb5cd15d 100644 --- a/ets2panda/checker/ETSAnalyzerHelpers.h +++ b/ets2panda/checker/ETSAnalyzerHelpers.h @@ -33,6 +33,8 @@ void CheckExtensionIsShadowedByMethod(checker::ETSChecker *checker, checker::ETS ir::ScriptFunction *extensionFunc, checker::Signature *signature); void CheckExtensionMethod(checker::ETSChecker *checker, ir::ScriptFunction *extensionFunc, ir::MethodDefinition *node); void DoBodyTypeChecking(ETSChecker *checker, ir::MethodDefinition *node, ir::ScriptFunction *scriptFunc); +void SetAsyncImplFuncReturnType(ETSChecker *checker, ir::ScriptFunction *scriptFunc); +void HandleAsyncMethodCheck(ETSChecker *checker, ir::MethodDefinition *node); void CheckPredefinedMethodReturnType(ETSChecker *checker, ir::ScriptFunction *scriptFunc); checker::Type *InitAnonymousLambdaCallee(checker::ETSChecker *checker, ir::Expression *callee, checker::Type *calleeType); @@ -59,6 +61,7 @@ void InferReturnType(ETSChecker *checker, ir::ScriptFunction *containingFunc, ch ir::Expression *stArgument); void ProcessReturnStatements(ETSChecker *checker, ir::ScriptFunction *containingFunc, checker::Type *&funcReturnType, ir::ReturnStatement *st, ir::Expression *stArgument); +bool IsAsyncMethod(ir::AstNode *node); } // namespace ark::es2panda::checker #endif // ES2PANDA_CHECKER_ETSANALYZERHELPERS_H diff --git a/ets2panda/checker/ets/function.cpp b/ets2panda/checker/ets/function.cpp index 1dcdf79665..261d631ce9 100644 --- a/ets2panda/checker/ets/function.cpp +++ b/ets2panda/checker/ets/function.cpp @@ -3092,9 +3092,15 @@ ir::MethodDefinition *ETSChecker::CreateAsyncImplMethod(ir::MethodDefinition *as modifiers &= ~ir::ModifierFlags::ASYNC; ir::ScriptFunction *asyncFunc = asyncMethod->Function(); ir::ScriptFunctionFlags flags = ir::ScriptFunctionFlags::METHOD; + if (asyncFunc->IsProxy()) { flags |= ir::ScriptFunctionFlags::PROXY; } + + if (asyncFunc->HasReturnStatement()) { + flags |= ir::ScriptFunctionFlags::HAS_RETURN; + } + asyncMethod->AddModifier(ir::ModifierFlags::NATIVE); asyncFunc->AddModifier(ir::ModifierFlags::NATIVE); // Create async_impl method copied from CreateInvokeFunction @@ -3105,31 +3111,39 @@ ir::MethodDefinition *ETSChecker::CreateAsyncImplMethod(ir::MethodDefinition *as // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) varbinder::FunctionParamScope *paramScope = CopyParams(asyncFunc->Params(), params); - // Set impl method return type "Object" because it may return Promise as well as Promise parameter's type - auto *objectId = AllocNode(compiler::Signatures::BUILTIN_OBJECT_CLASS, Allocator()); - objectId->SetReference(); - VarBinder()->AsETSBinder()->LookupTypeReference(objectId, false); - auto *returnTypeAnn = - AllocNode(AllocNode(objectId, nullptr, nullptr)); - objectId->SetParent(returnTypeAnn->Part()); - returnTypeAnn->Part()->SetParent(returnTypeAnn); - auto *asyncFuncRetTypeAnn = asyncFunc->ReturnTypeAnnotation(); - auto *promiseType = [this](ir::TypeNode *type) { - if (type != nullptr) { - return type->GetType(this)->AsETSObjectType(); - } - - return GlobalBuiltinPromiseType()->AsETSObjectType(); - }(asyncFuncRetTypeAnn); - // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) - auto *retType = Allocator()->New(Allocator(), Relation(), promiseType); - returnTypeAnn->SetTsType(retType); + ir::ETSTypeReference *returnTypeAnn = nullptr; + + if (!asyncFunc->Signature()->HasSignatureFlag(SignatureFlags::NEED_RETURN_TYPE)) { + // Set impl method return type "Object" because it may return Promise as well as Promise parameter's type + auto *objectId = AllocNode(compiler::Signatures::BUILTIN_OBJECT_CLASS, Allocator()); + objectId->SetReference(); + VarBinder()->AsETSBinder()->LookupTypeReference(objectId, false); + returnTypeAnn = + AllocNode(AllocNode(objectId, nullptr, nullptr)); + objectId->SetParent(returnTypeAnn->Part()); + returnTypeAnn->Part()->SetParent(returnTypeAnn); + auto *asyncFuncRetTypeAnn = asyncFunc->ReturnTypeAnnotation(); + auto *promiseType = [this](ir::TypeNode *type) { + if (type != nullptr) { + return type->GetType(this)->AsETSObjectType(); + } - ir::MethodDefinition *implMethod = + return GlobalBuiltinPromiseType()->AsETSObjectType(); + }(asyncFuncRetTypeAnn); // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) + auto *retType = Allocator()->New(Allocator(), Relation(), promiseType); + returnTypeAnn->SetTsType(retType); + } + + ir::MethodDefinition *implMethod = CreateMethod(implName.View(), modifiers, flags, std::move(params), paramScope, returnTypeAnn, body); asyncFunc->SetBody(nullptr); - returnTypeAnn->SetParent(implMethod->Function()); + + if (returnTypeAnn != nullptr) { + returnTypeAnn->SetParent(implMethod->Function()); + } + + implMethod->Function()->AddFlag(ir::ScriptFunctionFlags::ASYNC_IMPL); implMethod->SetParent(asyncMethod->Parent()); return implMethod; } diff --git a/ets2panda/checker/ets/object.cpp b/ets2panda/checker/ets/object.cpp index 384573a269..8b259f18e5 100644 --- a/ets2panda/checker/ets/object.cpp +++ b/ets2panda/checker/ets/object.cpp @@ -853,8 +853,6 @@ void ETSChecker::CheckClassDefinition(ir::ClassDefinition *classDef) it->Check(this); } } - // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) - CreateAsyncProxyMethods(classDef); if (classDef->IsGlobal()) { return; @@ -881,7 +879,7 @@ void ETSChecker::CheckConstructors(ir::ClassDefinition *classDef, ETSObjectType } } -static bool IsAsyncMethod(ir::AstNode *node) +bool IsAsyncMethod(ir::AstNode *node) { if (!node->IsMethodDefinition()) { return false; @@ -893,24 +891,27 @@ static bool IsAsyncMethod(ir::AstNode *node) void ETSChecker::CreateAsyncProxyMethods(ir::ClassDefinition *classDef) { ArenaVector asyncImpls(Allocator()->Adapter()); + for (auto *it : classDef->Body()) { if (!IsAsyncMethod(it)) { continue; } - auto *method = it->AsMethodDefinition(); - // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) - asyncImpls.push_back(CreateAsyncProxy(method, classDef)); - auto *proxy = asyncImpls.back(); - for (auto *overload : method->Overloads()) { - if (!overload->IsAsync()) { + + auto *asyncMethod = it->AsMethodDefinition(); + auto *proxy = CreateAsyncProxy(asyncMethod, classDef); + asyncImpls.push_back(proxy); + + for (auto *overload : asyncMethod->Overloads()) { + if (!IsAsyncMethod(overload)) { continue; } - // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) + auto *impl = CreateAsyncProxy(overload, classDef, false); impl->Function()->Id()->SetVariable(proxy->Function()->Id()->Variable()); proxy->AddOverload(impl); } } + for (auto *it : asyncImpls) { it->SetParent(classDef); it->Check(this); diff --git a/ets2panda/checker/types/ets/etsAsyncFuncReturnType.h b/ets2panda/checker/types/ets/etsAsyncFuncReturnType.h index 71b0cede7b..d25df5c5b6 100644 --- a/ets2panda/checker/types/ets/etsAsyncFuncReturnType.h +++ b/ets2panda/checker/types/ets/etsAsyncFuncReturnType.h @@ -45,6 +45,16 @@ public: return promiseType_->TypeArguments()[0]; } + [[nodiscard]] const Type *PromiseType() const noexcept + { + return promiseType_; + } + + [[nodiscard]] Type *PromiseType() noexcept + { + return promiseType_; + } + private: ETSObjectType *promiseType_; }; diff --git a/ets2panda/compiler/lowering/ets/promiseVoid.cpp b/ets2panda/compiler/lowering/ets/promiseVoid.cpp index e9f5795641..b083174bc0 100644 --- a/ets2panda/compiler/lowering/ets/promiseVoid.cpp +++ b/ets2panda/compiler/lowering/ets/promiseVoid.cpp @@ -178,8 +178,10 @@ bool PromiseVoidInferencePhase::Perform(public_lib::Context *ctx, parser::Progra const auto hasPromiseVoid = CheckForPromiseVoid(returnAnn); if (!hasReturnAnn) { - const auto &loc = genTypeLocation(function); - function->SetReturnTypeAnnotation(CreatePromiseVoidType(checker, loc)); + if (!function->HasReturnStatement()) { + const auto &loc = genTypeLocation(function); + function->SetReturnTypeAnnotation(CreatePromiseVoidType(checker, loc)); + } if (function->HasBody()) { HandleAsyncScriptFunctionBody(checker, function->Body()->AsBlockStatement()); diff --git a/ets2panda/ir/astNodeFlags.h b/ets2panda/ir/astNodeFlags.h index ffd34027a9..2e1f3baecc 100644 --- a/ets2panda/ir/astNodeFlags.h +++ b/ets2panda/ir/astNodeFlags.h @@ -86,7 +86,8 @@ enum class ScriptFunctionFlags : uint32_t { SETTER = 1U << 16U, ENTRY_POINT = 1U << 17U, INSTANCE_EXTENSION_METHOD = 1U << 18U, - HAS_RETURN = 1U << 19U + HAS_RETURN = 1U << 19U, + ASYNC_IMPL = 1U << 20U, }; enum class TSOperatorType { READONLY, KEYOF, UNIQUE }; diff --git a/ets2panda/ir/base/methodDefinition.h b/ets2panda/ir/base/methodDefinition.h index 553cc44d18..1856c50ffc 100644 --- a/ets2panda/ir/base/methodDefinition.h +++ b/ets2panda/ir/base/methodDefinition.h @@ -43,7 +43,9 @@ public: ModifierFlags const modifiers, ArenaAllocator *const allocator, bool const isComputed) : ClassElement(AstNodeType::METHOD_DEFINITION, key, value, modifiers, allocator, isComputed), kind_(kind), - overloads_(allocator->Adapter()) + overloads_(allocator->Adapter()), + overloaded_(nullptr), + asyncPairMethod_(nullptr) { ASSERT(key_ != nullptr && value_ != nullptr); } @@ -71,6 +73,26 @@ public: return overloads_; } + [[nodiscard]] const MethodDefinition *Overloaded() const noexcept + { + return overloaded_; + } + + [[nodiscard]] MethodDefinition *Overloaded() noexcept + { + return overloaded_; + } + + [[nodiscard]] const MethodDefinition *AsyncPairMethod() const noexcept + { + return asyncPairMethod_; + } + + [[nodiscard]] MethodDefinition *AsyncPairMethod() noexcept + { + return asyncPairMethod_; + } + void SetOverloads(OverloadsT &&overloads) { overloads_ = std::move(overloads); @@ -84,6 +106,17 @@ public: void AddOverload(MethodDefinition *const overload) { overloads_.emplace_back(overload); + overload->SetOverloaded(this); + } + + void SetOverloaded(MethodDefinition *const overloaded) + { + overloaded_ = overloaded; + } + + void SetAsyncPairMethod(MethodDefinition *const method) + { + asyncPairMethod_ = method; } [[nodiscard]] bool HasOverload(MethodDefinition *overload) noexcept @@ -117,6 +150,10 @@ public: private: MethodDefinitionKind kind_; OverloadsT overloads_; + MethodDefinition *overloaded_; + // Pair method points at the original async method in case of an implement method and vice versa an implement + // method's point at the async method + MethodDefinition *asyncPairMethod_; }; } // namespace ark::es2panda::ir diff --git a/ets2panda/ir/base/scriptFunction.h b/ets2panda/ir/base/scriptFunction.h index 7511ae3a26..621fcd147b 100644 --- a/ets2panda/ir/base/scriptFunction.h +++ b/ets2panda/ir/base/scriptFunction.h @@ -150,6 +150,11 @@ public: return (funcFlags_ & ir::ScriptFunctionFlags::ASYNC) != 0; } + [[nodiscard]] bool IsAsyncImplFunc() const noexcept + { + return (funcFlags_ & ir::ScriptFunctionFlags::ASYNC_IMPL) != 0; + } + [[nodiscard]] bool IsArrow() const noexcept { return (funcFlags_ & ir::ScriptFunctionFlags::ARROW) != 0; @@ -220,6 +225,11 @@ public: return signature_->RestVar() != nullptr; } + [[nodiscard]] bool HasReturnStatement() const noexcept + { + return (funcFlags_ & ir::ScriptFunctionFlags::HAS_RETURN) != 0; + } + [[nodiscard]] bool IsThrowing() const noexcept { return (funcFlags_ & ir::ScriptFunctionFlags::THROWS) != 0; diff --git a/ets2panda/test/runtime/ets/async-func-overload-and-type-infer.ets b/ets2panda/test/runtime/ets/async-func-overload-and-type-infer.ets new file mode 100644 index 0000000000..c2ba82c218 --- /dev/null +++ b/ets2panda/test/runtime/ets/async-func-overload-and-type-infer.ets @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +async function multipleReturns(flag: boolean, foo: int) { + if (flag) { + return foo; + } + + return "string1" +} + + +async function multipleReturns(flag: boolean): Promise { + if (flag) { + return 2; + } + + return "string2" +} + +function main() { + let a: int|string = await multipleReturns(true, 42); + let b: int|string = await multipleReturns(false); + + assert a == 42; + assert b == "string2"; +} + -- Gitee