diff --git a/ets2panda/BUILD.gn b/ets2panda/BUILD.gn index 6f8dbb58986ae8b6d5bc1d09b18e74fd118afbe6..f2baf91fda51536f0de9fc551a831f27504669cb 100644 --- a/ets2panda/BUILD.gn +++ b/ets2panda/BUILD.gn @@ -233,7 +233,6 @@ libes2panda_sources = [ "compiler/lowering/ets/lateInitialization.cpp", "compiler/lowering/ets/lambdaLowering.cpp", "compiler/lowering/ets/dynamicImport.cpp", - "compiler/lowering/ets/localClassLowering.cpp", "compiler/lowering/ets/objectIndexAccess.cpp", "compiler/lowering/ets/objectIterator.cpp", "compiler/lowering/ets/objectLiteralLowering.cpp", diff --git a/ets2panda/CMakeLists.txt b/ets2panda/CMakeLists.txt index ca1b8beaaf6110a89ee78c455437f8cafb8435cc..d90fb9459392bd399c3b6a22dd44a414daf806f0 100644 --- a/ets2panda/CMakeLists.txt +++ b/ets2panda/CMakeLists.txt @@ -293,7 +293,6 @@ set(ES2PANDA_LIB_SRC compiler/lowering/ets/dynamicImport.cpp compiler/lowering/ets/restTupleLowering.cpp compiler/lowering/ets/spreadLowering.cpp - compiler/lowering/ets/localClassLowering.cpp compiler/lowering/ets/objectIndexAccess.cpp compiler/lowering/ets/objectIterator.cpp compiler/lowering/ets/insertOptionalParametersAnnotation.cpp diff --git a/ets2panda/REVIEWERS b/ets2panda/REVIEWERS index 6835ef0e177c1a0d670ba4032586e508f06d7e6e..8c8a73c98b8f671a65906508fd6690993b3fe508 100644 --- a/ets2panda/REVIEWERS +++ b/ets2panda/REVIEWERS @@ -66,7 +66,6 @@ /ets2panda/checker/types/ets/wildcardType.* ^vpukhov @gogabr ^igelhaus ^Prof1983 /ets2panda/compiler/lowering/ets/ @akmaevaleksey ^igelhaus ^Prof1983 ^zelentsovdmitry /ets2panda/compiler/lowering/ets/lambdaLowering.cpp ^vpukhov @akmaevaleksey @gogabr ^igelhaus ^Prof1983 -/ets2panda/compiler/lowering/ets/localClassLowering.cpp @gogabr ^igelhaus ^Prof1983 /ets2panda/compiler/lowering/ets/optionalLowering.cpp ^vpukhov @akmaevaleksey ^igelhaus ^Prof1983 /ets2panda/compiler/lowering/ets/unionLowering.cpp ^vpukhov @akmaevaleksey ^igelhaus ^Prof1983 /ets2panda/compiler/lowering/ets/topLevelStmts/.* ^vpukhov @akmaevaleksey ^igelhaus ^Prof1983 diff --git a/ets2panda/compiler/lowering/ets/localClassLowering.cpp b/ets2panda/compiler/lowering/ets/localClassLowering.cpp deleted file mode 100644 index 439208e64049e26c6c466099f051d5311a90f348..0000000000000000000000000000000000000000 --- a/ets2panda/compiler/lowering/ets/localClassLowering.cpp +++ /dev/null @@ -1,297 +0,0 @@ -/* - * Copyright (c) 2023-2025 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 "localClassLowering.h" - -#include "checker/ETSchecker.h" -#include "../util.h" - -namespace ark::es2panda::compiler { - -std::string_view LocalClassConstructionPhase::Name() const -{ - return "LocalClassConstructionPhase"; -} - -static ir::ClassProperty *CreateCapturedField(public_lib::Context *ctx, const varbinder::Variable *capturedVar, - varbinder::ClassScope *scope, size_t &idx) -{ - auto *allocator = ctx->Allocator(); - auto *varBinder = ctx->GetChecker()->AsETSChecker()->VarBinder(); - - // Enter the lambda class instance field scope, every property will be bound to the lambda instance itself - auto fieldCtx = varbinder::LexicalScope::Enter(varBinder, scope->InstanceFieldScope()); - - // Create the name for the synthetic property node - util::UString fieldName(util::StringView("field#"), allocator); - fieldName.Append(std::to_string(idx)); - // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) - auto *fieldIdent = allocator->New(fieldName.View(), allocator); - - // Create the synthetic class property node - auto *field = - allocator->New(fieldIdent, nullptr, nullptr, ir::ModifierFlags::NONE, allocator, false); - fieldIdent->SetParent(field); - - // Add the declaration to the scope, and set the type based on the captured variable's scope - auto [decl, var] = varBinder->NewVarDecl(fieldIdent->Start(), fieldIdent->Name()); - var->SetScope(scope->InstanceFieldScope()); - var->AddFlag(varbinder::VariableFlags::PROPERTY); - var->SetTsType(capturedVar->TsType()); - - fieldIdent->SetVariable(var); - field->SetTsType(capturedVar->TsType()); - decl->BindNode(field); - return field; -} - -static ir::Statement *CreateCtorFieldInit(public_lib::Context *ctx, util::StringView name, varbinder::Variable *var) -{ - // Create synthetic field initializers for the local class fields - // The node structure is the following: this.field0 = field0, where the left hand side refers to the local - // classes field, and the right hand side is refers to the constructors parameter - // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) - auto *allocator = ctx->Allocator(); - - auto *thisExpr = allocator->New(); - auto *fieldAccessExpr = allocator->New(name, allocator); - auto *leftHandSide = util::NodeAllocator::ForceSetParent( - allocator, thisExpr, fieldAccessExpr, ir::MemberExpressionKind::PROPERTY_ACCESS, false, false); - auto *rightHandSide = allocator->New(name, allocator); - rightHandSide->SetVariable(var); - auto *initializer = util::NodeAllocator::ForceSetParent( - allocator, leftHandSide, rightHandSide, lexer::TokenType::PUNCTUATOR_SUBSTITUTION); - initializer->SetTsType(var->TsType()); - return util::NodeAllocator::ForceSetParent(allocator, initializer); -} - -void LocalClassConstructionPhase::CreateClassPropertiesForCapturedVariables( - public_lib::Context *ctx, ir::ClassDefinition *classDef, ArenaSet const &capturedVars, - ArenaMap &variableMap, - ArenaMap &propertyMap) -{ - size_t idx = 0; - ArenaVector properties(ctx->allocator->Adapter()); - for (auto var : capturedVars) { - ES2PANDA_ASSERT(classDef->Scope()->Type() == varbinder::ScopeType::CLASS); - auto *property = - CreateCapturedField(ctx, var, reinterpret_cast(classDef->Scope()), idx); - LOG(DEBUG, ES2PANDA) << " - Creating property (" << property->Id()->Name() - << ") for captured variable: " << var->Name(); - properties.push_back(property); - variableMap[var] = property->Id()->Variable(); - propertyMap[var] = property; - idx++; - } - - classDef->AddProperties(std::move(properties)); -} - -ir::ETSParameterExpression *LocalClassConstructionPhase::CreateParam(public_lib::Context *ctx, - varbinder::FunctionParamScope *scope, - util::StringView name, checker::Type *type) -{ - auto *checker = ctx->GetChecker()->AsETSChecker(); - auto newParam = checker->AddParam(name, nullptr); - newParam->SetTsType(type); - newParam->Ident()->SetTsType(type); - auto paramCtx = varbinder::LexicalScope::Enter(checker->VarBinder(), scope, false); - - auto *paramVar = checker->VarBinder()->AddParamDecl(newParam); - paramVar->SetTsType(newParam->TsType()); - newParam->Ident()->SetVariable(paramVar); - return newParam; -} - -void LocalClassConstructionPhase::ModifyConstructorParameters( - public_lib::Context *ctx, ir::ClassDefinition *classDef, ArenaSet const &capturedVars, - ArenaMap &variableMap, - ArenaMap ¶meterMap) - -{ - auto *classType = classDef->TsType()->AsETSObjectType(); - - for (auto *signature : classType->ConstructSignatures()) { - LOG(DEBUG, ES2PANDA) << " - Modifying Constructor: " << signature->InternalName(); - auto constructor = signature->Function(); - auto &sigParams = signature->Params(); - auto ¶meters = constructor->ParamsForUpdate(); - signature->GetSignatureInfo()->minArgCount += capturedVars.size(); - - ES2PANDA_ASSERT(signature == constructor->Signature()); - for (auto var : capturedVars) { - auto *newParam = CreateParam(ctx, constructor->Scope()->ParamScope(), var->Name(), var->TsType()); - newParam->SetParent(constructor); - // NOTE(psiket) : Moving the parameter after the 'this'. Should modify the AddParam - // to be able to insert after the this. - auto ¶mScopeParams = constructor->Scope()->ParamScope()->Params(); - auto thisParamIt = ++paramScopeParams.begin(); - paramScopeParams.insert(thisParamIt, paramScopeParams.back()); - paramScopeParams.pop_back(); - - parameters.insert(parameters.begin(), newParam); - ES2PANDA_ASSERT(newParam->Variable()->Type() == varbinder::VariableType::LOCAL); - sigParams.insert(sigParams.begin(), newParam->Ident()->Variable()->AsLocalVariable()); - parameterMap[var] = newParam->Ident()->Variable()->AsLocalVariable(); - } - reinterpret_cast(ctx->GetChecker()->AsETSChecker()->VarBinder()) - ->BuildFunctionName(constructor); - LOG(DEBUG, ES2PANDA) << " Transformed Constructor: " << signature->InternalName(); - - auto *body = constructor->Body(); - ArenaVector initStatements(ctx->allocator->Adapter()); - for (auto var : capturedVars) { - auto *propertyVar = variableMap[var]; - auto *initStatement = CreateCtorFieldInit(ctx, propertyVar->Name(), propertyVar); - auto *fieldInit = initStatement->AsExpressionStatement()->GetExpression()->AsAssignmentExpression(); - auto *ctorParamVar = parameterMap[var]; - auto *fieldVar = variableMap[var]; - auto *leftHandSide = fieldInit->Left(); - leftHandSide->AsMemberExpression()->SetObjectType(classType); - leftHandSide->AsMemberExpression()->SetPropVar(fieldVar->AsLocalVariable()); - leftHandSide->AsMemberExpression()->SetIgnoreBox(); - leftHandSide->AsMemberExpression()->SetTsType(fieldVar->TsType()); - leftHandSide->AsMemberExpression()->Object()->SetTsType(classType); - fieldInit->Right()->AsIdentifier()->SetVariable(ctorParamVar); - fieldInit->Right()->SetTsType(ctorParamVar->TsType()); - initStatement->SetParent(body); - initStatements.push_back(initStatement); - } - if (body != nullptr && body->IsBlockStatement()) { - auto &statements = body->AsBlockStatement()->StatementsForUpdates(); - statements.insert(statements.begin(), initStatements.begin(), initStatements.end()); - } - } -} - -void LocalClassConstructionPhase::RemapReferencesFromCapturedVariablesToClassProperties( - ir::ClassDefinition *classDef, ArenaMap &variableMap) -{ - auto *classType = classDef->TsType()->AsETSObjectType(); - auto remapCapturedVariables = [&variableMap](ir::AstNode *childNode) { - if (childNode->Type() == ir::AstNodeType::IDENTIFIER) { - LOG(DEBUG, ES2PANDA) << " checking var:" << (void *)childNode; - const auto &mapIt = variableMap.find(childNode->AsIdentifier()->Variable()); - if (mapIt != variableMap.end()) { - LOG(DEBUG, ES2PANDA) << " Remap: " << childNode->AsIdentifier()->Name() - << " (identifier:" << (void *)childNode - << ") variable:" << (void *)childNode->AsIdentifier()->Variable() - << " -> property variable:" << (void *)mapIt->second; - childNode->AsIdentifier()->SetVariable(mapIt->second); - } else { - } - } - }; - - for (auto *it : classDef->Body()) { - if (it->IsMethodDefinition() && !it->AsMethodDefinition()->IsConstructor()) { - LOG(DEBUG, ES2PANDA) << " - Rebinding variable rerferences in: " - << it->AsMethodDefinition()->Id()->Name().Mutf8().c_str(); - if (it->AsMethodDefinition()->Function()->Body() == nullptr && - it->AsMethodDefinition()->AsyncPairMethod() != nullptr) { - it->AsMethodDefinition()->AsyncPairMethod()->Function()->Body()->IterateRecursively( - remapCapturedVariables); - } else { - it->AsMethodDefinition()->Function()->Body()->IterateRecursively(remapCapturedVariables); - } - } - } - // Since the constructor with zero parameter is not listed in the class_def body the constructors - // processed separately - for (auto *signature : classType->ConstructSignatures()) { - auto *constructor = signature->Function(); - LOG(DEBUG, ES2PANDA) << " - Rebinding variable rerferences in: " << constructor->Id()->Name(); - if (constructor->Body() != nullptr) { - constructor->Body()->IterateRecursively(remapCapturedVariables); - } - } -} - -void LocalClassConstructionPhase::HandleLocalClass( - public_lib::Context *ctx, - ArenaUnorderedMap> &capturedVarsMap, - ir::ClassDefinition *classDef) -{ - LOG(DEBUG, ES2PANDA) << "Altering local class with the captured variables: " << classDef->InternalName(); - auto capturedVars = FindCaptured(ctx->allocator, classDef); - // Map the captured variable to the variable of the class property - ArenaMap variableMap(ctx->allocator->Adapter()); - // Map the captured variable to the class property - ArenaMap propertyMap(ctx->allocator->Adapter()); - // Map the captured variable to the constructor parameter - ArenaMap parameterMap(ctx->allocator->Adapter()); - - CreateClassPropertiesForCapturedVariables(ctx, classDef, capturedVars, variableMap, propertyMap); - ModifyConstructorParameters(ctx, classDef, capturedVars, variableMap, parameterMap); - RemapReferencesFromCapturedVariablesToClassProperties(classDef, variableMap); - capturedVarsMap.emplace(classDef, std::move(capturedVars)); -} - -bool LocalClassConstructionPhase::PerformForModule(public_lib::Context *ctx, parser::Program *program) -{ - checker::ETSChecker *const checker = ctx->GetChecker()->AsETSChecker(); - ArenaUnorderedMap> capturedVarsMap { - ctx->allocator->Adapter()}; - - program->Ast()->IterateRecursivelyPostorder([&](ir::AstNode *ast) { - if (ast->IsClassDefinition() && ast->AsClassDefinition()->IsLocal()) { - HandleLocalClass(ctx, capturedVarsMap, ast->AsClassDefinition()); - } - }); - - // Alter the instantiations - auto handleLocalClassInstantiation = [ctx, &capturedVarsMap](ir::ClassDefinition *classDef, - ir::ETSNewClassInstanceExpression *newExpr) { - LOG(DEBUG, ES2PANDA) << "Instantiating local class: " << classDef->Ident()->Name(); - auto capturedVarsIt = capturedVarsMap.find(classDef); - ES2PANDA_ASSERT(capturedVarsIt != capturedVarsMap.cend()); - auto &capturedVars = capturedVarsIt->second; - for (auto *var : capturedVars) { - LOG(DEBUG, ES2PANDA) << " - Extending constructor argument with captured variable: " << var->Name(); - - auto *param = ctx->AllocNode(var->Name(), ctx->allocator); - param->SetVariable(var); - param->SetIgnoreBox(); - param->SetTsType(param->Variable()->TsType()); - param->SetParent(newExpr); - newExpr->AddToArgumentsFront(param); - } - }; - - program->Ast()->IterateRecursivelyPostorder([&](ir::AstNode *ast) { - if (ast->IsETSNewClassInstanceExpression()) { - auto *newExpr = ast->AsETSNewClassInstanceExpression(); - checker::Type *calleeType = newExpr->GetTypeRef()->Check(checker); - if (calleeType->IsETSAnyType()) { - return; - } - - ES2PANDA_ASSERT(calleeType->IsETSObjectType()); - auto *calleeObj = calleeType->AsETSObjectType(); - if (!calleeObj->GetDeclNode()->IsClassDefinition()) { - return; - } - - auto *classDef = calleeObj->GetDeclNode()->AsClassDefinition(); - if (classDef->IsLocal()) { - handleLocalClassInstantiation(classDef, newExpr); - } - } - }); - - return true; -} - -} // namespace ark::es2panda::compiler diff --git a/ets2panda/compiler/lowering/ets/localClassLowering.h b/ets2panda/compiler/lowering/ets/localClassLowering.h deleted file mode 100644 index 08ee325919ec75916df1e57fa295a0375ba2bd75..0000000000000000000000000000000000000000 --- a/ets2panda/compiler/lowering/ets/localClassLowering.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2023-2025 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 ES2PANDA_COMPILER_LOWERING_LOCAL_CLASS_LOWERING_H -#define ES2PANDA_COMPILER_LOWERING_LOCAL_CLASS_LOWERING_H - -#include "compiler/lowering/phase.h" - -namespace ark::es2panda::compiler { - -class LocalClassConstructionPhase : public PhaseForBodies { -public: - std::string_view Name() const override; - bool PerformForModule(public_lib::Context *ctx, parser::Program *program) override; - -protected: - void CreateClassPropertiesForCapturedVariables(public_lib::Context *ctx, ir::ClassDefinition *classDef, - ArenaSet const &capturedVars, - ArenaMap &variableMap, - ArenaMap &propertyMap); - - void ModifyConstructorParameters(public_lib::Context *ctx, ir::ClassDefinition *classDef, - ArenaSet const &capturedVars, - ArenaMap &variableMap, - ArenaMap ¶meterMap); - - void RemapReferencesFromCapturedVariablesToClassProperties( - ir::ClassDefinition *classDef, ArenaMap &variableMap); - - void HandleLocalClass(public_lib::Context *ctx, - ArenaUnorderedMap> &capturedVarsMap, - ir::ClassDefinition *classDef); - - ir::ETSParameterExpression *CreateParam(public_lib::Context *ctx, varbinder::FunctionParamScope *scope, - util::StringView name, checker::Type *type); -}; - -} // namespace ark::es2panda::compiler - -#endif diff --git a/ets2panda/compiler/lowering/phase.cpp b/ets2panda/compiler/lowering/phase.cpp index 18eefa5f2dd8eacfa0f168cd55b4e7755f7a4949..d16a2558ace992d1b397ac37d8bbc058d9d8d9e2 100644 --- a/ets2panda/compiler/lowering/phase.cpp +++ b/ets2panda/compiler/lowering/phase.cpp @@ -47,7 +47,6 @@ #include "compiler/lowering/ets/interfacePropertyDeclarations.h" #include "compiler/lowering/ets/lambdaLowering.h" #include "compiler/lowering/ets/dynamicImport.h" -#include "compiler/lowering/ets/localClassLowering.h" #include "compiler/lowering/ets/objectIndexAccess.h" #include "compiler/lowering/ets/objectIterator.h" #include "compiler/lowering/ets/objectLiteralLowering.h" @@ -150,7 +149,6 @@ std::vector GetETSPhaseList() new LambdaConversionPhase, new UnionLowering, new ExpandBracketsPhase, - new LocalClassConstructionPhase, new PartialExportClassGen, new InterfaceObjectLiteralLowering, // must be put after all classes are generated. new ObjectLiteralLowering, diff --git a/ets2panda/parser/ETSparserStatements.cpp b/ets2panda/parser/ETSparserStatements.cpp index 3a3bcf9294d53d5659622ed6731eaba11bc2beb7..d65ff8c4238a6cc7972bc07d2f541e71b5694989 100644 --- a/ets2panda/parser/ETSparserStatements.cpp +++ b/ets2panda/parser/ETSparserStatements.cpp @@ -350,9 +350,13 @@ ir::Statement *ETSParser::ParseClassStatement([[maybe_unused]] StatementParsingF ir::ClassDefinitionModifiers modifiers, ir::ModifierFlags modFlags) { modFlags |= ParseClassModifiers(); - return ParseClassDeclaration(modifiers | ir::ClassDefinitionModifiers::ID_REQUIRED | - ir::ClassDefinitionModifiers::CLASS_DECL | ir::ClassDefinitionModifiers::LOCAL, - modFlags); + const auto &rangeClass = Lexer()->GetToken().Loc(); + LogError(diagnostic::ILLEGAL_START_STRUCT_CLASS, {"CLASS"}, rangeClass.start); + // Try to parse class and drop the result. + ParseClassDeclaration(modifiers | ir::ClassDefinitionModifiers::ID_REQUIRED | + ir::ClassDefinitionModifiers::CLASS_DECL | ir::ClassDefinitionModifiers::LOCAL, + modFlags); + return AllocBrokenStatement(rangeClass); } // NOLINTNEXTLINE(google-default-arguments) @@ -360,10 +364,11 @@ ir::Statement *ETSParser::ParseStructStatement([[maybe_unused]] StatementParsing ir::ClassDefinitionModifiers modifiers, ir::ModifierFlags modFlags) { const auto &rangeStruct = Lexer()->GetToken().Loc(); - LogError(diagnostic::ILLEGAL_START_STRUCT, {}, rangeStruct.start); + LogError(diagnostic::ILLEGAL_START_STRUCT_CLASS, {"STRUCT"}, rangeStruct.start); + // Try to parse struct and drop the result. ParseClassDeclaration(modifiers | ir::ClassDefinitionModifiers::ID_REQUIRED | ir::ClassDefinitionModifiers::CLASS_DECL | ir::ClassDefinitionModifiers::LOCAL, - modFlags); // Try to parse struct and drop the result. + modFlags); return AllocBrokenStatement(rangeStruct); } diff --git a/ets2panda/parser/statementParser.cpp b/ets2panda/parser/statementParser.cpp index dfff3756ec9406aa2265af9755f401aec67a1051..2d0312a4c4f4f49130e825c8feab5566758a894a 100644 --- a/ets2panda/parser/statementParser.cpp +++ b/ets2panda/parser/statementParser.cpp @@ -297,7 +297,7 @@ ir::Statement *ParserImpl::ParsePotentialExpressionStatement(StatementParsingFla ir::Statement *ParserImpl::ParseStructStatement([[maybe_unused]] StatementParsingFlags flags, ir::ClassDefinitionModifiers modifiers, ir::ModifierFlags modFlags) { - LogError(diagnostic::ILLEGAL_START_STRUCT); + LogError(diagnostic::ILLEGAL_START_STRUCT_CLASS, {"STRUCT"}); return ParseStructDeclaration(modifiers, modFlags); } diff --git a/ets2panda/test/parser/ets/local-class-expected.txt b/ets2panda/test/parser/ets/local-class-expected.txt deleted file mode 100644 index 8b51c20764435b9364c1b05cfd81cd26c986c368..0000000000000000000000000000000000000000 --- a/ets2panda/test/parser/ets/local-class-expected.txt +++ /dev/null @@ -1,481 +0,0 @@ -{ - "type": "Program", - "statements": [ - { - "type": "ClassDeclaration", - "definition": { - "id": { - "type": "Identifier", - "name": "ETSGLOBAL", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 1, - "program": "local-class.ets" - }, - "end": { - "line": 1, - "column": 1, - "program": "local-class.ets" - } - } - }, - "superClass": null, - "implements": [], - "body": [ - { - "type": "MethodDefinition", - "key": { - "type": "Identifier", - "name": "_$init$_", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 1, - "program": null - }, - "end": { - "line": 1, - "column": 1, - "program": null - } - } - }, - "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, - "program": null - }, - "end": { - "line": 1, - "column": 1, - "program": null - } - } - }, - "generator": false, - "async": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "statements": [], - "loc": { - "start": { - "line": 1, - "column": 1, - "program": null - }, - "end": { - "line": 1, - "column": 1, - "program": null - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 1, - "program": null - }, - "end": { - "line": 1, - "column": 1, - "program": null - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 1, - "program": null - }, - "end": { - "line": 1, - "column": 1, - "program": null - } - } - }, - "overloads": [], - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 1, - "program": "local-class.ets" - }, - "end": { - "line": 1, - "column": 1, - "program": "local-class.ets" - } - } - }, - { - "type": "MethodDefinition", - "key": { - "type": "Identifier", - "name": "main", - "decorators": [], - "loc": { - "start": { - "line": 16, - "column": 10, - "program": "local-class.ets" - }, - "end": { - "line": 16, - "column": 14, - "program": "local-class.ets" - } - } - }, - "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": 16, - "column": 10, - "program": "local-class.ets" - }, - "end": { - "line": 16, - "column": 14, - "program": "local-class.ets" - } - } - }, - "generator": false, - "async": false, - "expression": false, - "params": [], - "returnType": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 16, - "column": 19, - "program": "local-class.ets" - }, - "end": { - "line": 16, - "column": 22, - "program": "local-class.ets" - } - } - }, - "body": { - "type": "BlockStatement", - "statements": [ - { - "type": "ClassDeclaration", - "definition": { - "id": { - "type": "Identifier", - "name": "LocalClass", - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 11, - "program": "local-class.ets" - }, - "end": { - "line": 18, - "column": 21, - "program": "local-class.ets" - } - } - }, - "superClass": null, - "implements": [], - "body": [ - { - "type": "MethodDefinition", - "key": { - "type": "Identifier", - "name": "constructor", - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 23, - "program": "local-class.ets" - }, - "end": { - "line": 18, - "column": 23, - "program": "local-class.ets" - } - } - }, - "kind": "constructor", - "static": false, - "optional": false, - "computed": false, - "value": { - "type": "FunctionExpression", - "function": { - "type": "ScriptFunction", - "id": { - "type": "Identifier", - "name": "constructor", - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 23, - "program": "local-class.ets" - }, - "end": { - "line": 18, - "column": 23, - "program": "local-class.ets" - } - } - }, - "generator": false, - "async": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "statements": [], - "loc": { - "start": { - "line": 18, - "column": 23, - "program": "local-class.ets" - }, - "end": { - "line": 18, - "column": 23, - "program": "local-class.ets" - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 23, - "program": "local-class.ets" - }, - "end": { - "line": 18, - "column": 23, - "program": "local-class.ets" - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 23, - "program": "local-class.ets" - }, - "end": { - "line": 18, - "column": 23, - "program": "local-class.ets" - } - } - }, - "overloads": [], - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 1, - "program": null - }, - "end": { - "line": 1, - "column": 1, - "program": null - } - } - } - ], - "loc": { - "start": { - "line": 18, - "column": 22, - "program": "local-class.ets" - }, - "end": { - "line": 19, - "column": 11, - "program": "local-class.ets" - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 5, - "program": "local-class.ets" - }, - "end": { - "line": 19, - "column": 11, - "program": "local-class.ets" - } - } - }, - { - "type": "ReturnStatement", - "argument": { - "type": "NumberLiteral", - "value": 0, - "loc": { - "start": { - "line": 19, - "column": 12, - "program": "local-class.ets" - }, - "end": { - "line": 19, - "column": 13, - "program": "local-class.ets" - } - } - }, - "loc": { - "start": { - "line": 19, - "column": 5, - "program": "local-class.ets" - }, - "end": { - "line": 19, - "column": 14, - "program": "local-class.ets" - } - } - } - ], - "loc": { - "start": { - "line": 17, - "column": 1, - "program": "local-class.ets" - }, - "end": { - "line": 20, - "column": 2, - "program": "local-class.ets" - } - } - }, - "loc": { - "start": { - "line": 16, - "column": 10, - "program": "local-class.ets" - }, - "end": { - "line": 20, - "column": 2, - "program": "local-class.ets" - } - } - }, - "loc": { - "start": { - "line": 16, - "column": 10, - "program": "local-class.ets" - }, - "end": { - "line": 20, - "column": 2, - "program": "local-class.ets" - } - } - }, - "overloads": [], - "decorators": [], - "loc": { - "start": { - "line": 16, - "column": 1, - "program": "local-class.ets" - }, - "end": { - "line": 20, - "column": 2, - "program": "local-class.ets" - } - } - } - ], - "loc": { - "start": { - "line": 1, - "column": 1, - "program": "local-class.ets" - }, - "end": { - "line": 1, - "column": 1, - "program": "local-class.ets" - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 1, - "program": "local-class.ets" - }, - "end": { - "line": 1, - "column": 1, - "program": "local-class.ets" - } - } - } - ], - "loc": { - "start": { - "line": 1, - "column": 1, - "program": "local-class.ets" - }, - "end": { - "line": 20, - "column": 2, - "program": "local-class.ets" - } - } -} diff --git a/ets2panda/test/parser/ets/local-class.ets b/ets2panda/test/parser/ets/local-class.ets deleted file mode 100644 index 94e03361a4137d274d079cf3232dc94c77aa1efd..0000000000000000000000000000000000000000 --- a/ets2panda/test/parser/ets/local-class.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (c) 2024-2025 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() : int -{ - class LocalClass { } - return 0; -} \ No newline at end of file diff --git a/ets2panda/test/runtime/ets/InterfaceInBlock.ets b/ets2panda/test/runtime/ets/InterfaceInBlock.ets deleted file mode 100644 index 793e09c283fb2e713196303928e6a9d3f2dd6ade..0000000000000000000000000000000000000000 --- a/ets2panda/test/runtime/ets/InterfaceInBlock.ets +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2025 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 - { - foo(): int; - } - - class C implements I - { - foo(): int - { - return 1; - } - } - - arktest.assertEQ(new C().foo(), 1); -} \ No newline at end of file diff --git a/ets2panda/test/runtime/ets/lambdaWithLocalClassAccess.ets b/ets2panda/test/runtime/ets/lambdaWithLocalClassAccess.ets deleted file mode 100644 index 3358bc602432ae36da489e3febb45649c1b5a1c7..0000000000000000000000000000000000000000 --- a/ets2panda/test/runtime/ets/lambdaWithLocalClassAccess.ets +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2024-2025 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() { - class C { - x: boolean = true - } - let lam = (c: C): boolean => { return c.x } - arktest.assertTrue(lam(new C())) -} - -function main() { - f() -} diff --git a/ets2panda/test/runtime/ets/lambda_with_default.ets b/ets2panda/test/runtime/ets/lambda_with_default.ets deleted file mode 100644 index ec2260dd6d72acfba87ca594ce985559b66442d9..0000000000000000000000000000000000000000 --- a/ets2panda/test/runtime/ets/lambda_with_default.ets +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 2024-2025 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() { - ()=> { - class A { - foo(x :String ="aa"){ - return x; - } - } - } - arktest.assertTrue(true) -} diff --git a/ets2panda/test/runtime/ets/local-class-capture-boxing.ets b/ets2panda/test/runtime/ets/local-class-capture-boxing.ets deleted file mode 100644 index a5821cacb6c23c1c154a405d29f023c5102d448e..0000000000000000000000000000000000000000 --- a/ets2panda/test/runtime/ets/local-class-capture-boxing.ets +++ /dev/null @@ -1,218 +0,0 @@ -/* - * Copyright (c) 2021-2025 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 UserClassType -{ - v : int = 0; - constructor (p : int) - { - this.v = p; - } - - override toString() : string { - return Int.valueOf(this.v).toString(); - } -} - -enum UserEnumType -{ - Red, - Green, - Blue -}; - -let g_array : int [] = [1,2,3]; -let g_array2 : int [] = [11,12,13]; -let g_Array : Array = new Array(new Int(4), new Int(5), new Int(6)); -let g_Array2 : Array = new Array(new Int(14), new Int(15), new Int(16)); -let g_Object : Object = new Object(); -let g_Object2 : Object = new Object(); -let g_Class : UserClassType = new UserClassType(25); -let g_Class2 : UserClassType = new UserClassType(250); - - - -class GlobalClass -{ - static s_field : int = 13; - field : int = 14; - - static s_method_boxing_local_class() { - // predefined value types - let l_number : number = 1; - let l_byte : byte = 2; - let l_short : short = 3; - let l_int : int = 4; - let l_long : long = 5; - let l_float : float = 6.0f; - let l_double : double = 7.0; - let l_boolean : boolean = false; - let l_char : char = c'x'; - - // user defined value types - let l_enum : UserEnumType = UserEnumType.Red; - - // predefined reference types - let l_Number : Number = new Number(11); - let l_Byte : Byte = new Byte(12 as byte); - let l_Short : Short = new Short(13 as short); - let l_Int : Int = new Int(14 as int); - let l_Long : Long = new Long(15 as long); - let l_Float : Float = new Float(16.0); - let l_Double : Double = new Double(17.0); - let l_Boolean: Boolean = new Boolean(false); - let l_Char : Char = new Char(c'X'); - - let l_string : string = "something"; - let l_String : String = new String("Something"); - let l_array : int [] = g_array; - let l_Array : Array = g_Array; - //let l_bigint : bigint = 20n; - //let l_BigInt : BigInt = new BigInt(21n); - let l_Object : Object = g_Object; - - // user defined reference types - let l_Class : UserClassType = g_Class; - - class LocalClassBoxing - { - local_field : int = 1000; - static local_s_field : int = 2000; - - static local_s_method(lp : int) : void - { - arktest.assertEQ(lp, 300) - arktest.assertEQ(LocalClassBoxing.local_s_field, 2000) - - LocalClassBoxing.local_s_field = 5000; - arktest.assertEQ(LocalClassBoxing.local_s_field, 5000) - } - - local_method(lp : int) : void - { - // Parameter - arktest.assertEQ(lp, 400) - // Local class object field - arktest.assertEQ(this.local_field, 1000) - // Local class static field - arktest.assertEQ(LocalClassBoxing.local_s_field, 5000) - // Outer class static field - arktest.assertEQ(GlobalClass.s_field, 13) - // Predefined value types - arktest.assertEQ(l_number, 1) - arktest.assertEQ(l_byte, 2) - arktest.assertEQ(l_short, 3) - arktest.assertEQ(l_int, 4) - arktest.assertEQ(l_long, 5) - arktest.assertEQ(l_float, 6) - arktest.assertEQ(l_double, 7) - arktest.assertEQ(l_boolean, false) - arktest.assertEQ(l_char, c'x') - // User defined value type - arktest.assertEQ(l_enum, UserEnumType.Red) - // Predefined reference types - arktest.assertEQ(l_Number, Number.valueOf(11)) - arktest.assertEQ(l_Byte, Byte.valueOf(12 as byte)) - arktest.assertEQ(l_Short, Short.valueOf(13 as short)) - arktest.assertEQ(l_Int, Int.valueOf(14 as int)) - arktest.assertEQ(l_Long, Long.valueOf(15 as long)) - arktest.assertEQ(l_Float, Float.valueOf(16 as float)) - arktest.assertEQ(l_Double, Double.valueOf(17 as double)) - arktest.assertEQ(l_Boolean, Boolean.valueOf(false)) - arktest.assertEQ(l_Char, Char.valueOf(c'X')) - arktest.assertEQ(l_string, "something") - arktest.assertEQ(l_String, "Something") - // arktest.assertEQ(l_array, g_array) - // arktest.assertEQ(l_Array, g_Array) - arktest.assertEQ(l_Object, g_Object) - arktest.assertEQ(l_Class, g_Class) - - this.local_field = 1100; - LocalClassBoxing.local_s_field = 5100; - - l_number = 101; - l_byte = 102; - l_short = 103; - l_int = 104; - l_long = 105; - l_float = Double.toFloat(106.0); - l_double = 107.0; - l_boolean = true; - l_char = c'y'; - //l_enum = UserEnumType.Green; - - l_Number = new Number(111); - l_Byte = new Byte(112 as byte); - l_Short = new Short(113 as short); - l_Int = new Int(114 as int); - l_Long = new Long(115 as long); - l_Float = new Float(116.0); - l_Double = new Double(117.0); - l_Boolean = new Boolean(true); - l_Char = new Char(c'Y'); - - l_string = "something new"; - l_String = new String("Something new"); - l_array = g_array2; - l_Array = g_Array2; - l_Object = g_Object2; - l_Class = g_Class2; - } - }; - LocalClassBoxing.local_s_field = 2000; // due to the jit loop - LocalClassBoxing.local_s_method(300); - - let lcb = new LocalClassBoxing(); - lcb.local_method(400); - - arktest.assertEQ(lcb.local_field, 1100) - arktest.assertEQ(LocalClassBoxing.local_s_field, 5100) - arktest.assertEQ(l_number, 101) - arktest.assertEQ(l_byte, 102) - arktest.assertEQ(l_short, 103) - arktest.assertEQ(l_int, 104) - arktest.assertEQ(l_long, 105) - arktest.assertEQ(l_float, 106) - arktest.assertEQ(l_double, 107) - arktest.assertEQ(l_boolean, true) - arktest.assertEQ(l_char, c'y') - - //arktest.assertEQ(l_enum, UserEnumType.Green) - - // Predefined reference types - arktest.assertEQ(l_Number, Number.valueOf(111)) - arktest.assertEQ(l_Byte, Byte.valueOf(112 as byte)) - arktest.assertEQ(l_Short, Short.valueOf(113 as short)) - arktest.assertEQ(l_Int, Int.valueOf(114 as int)) - arktest.assertEQ(l_Long, Long.valueOf(115 as long)) - arktest.assertEQ(l_Float, Float.valueOf(116 as float)) - arktest.assertEQ(l_Double, Double.valueOf(117 as double)) - arktest.assertEQ(l_Boolean, Boolean.valueOf(true)) - arktest.assertEQ(l_Char, Char.valueOf(c'Y')) - arktest.assertEQ(l_string, "something new") - arktest.assertEQ(l_String, "Something new") - //arktest.assertEQ(l_array, g_array2) - //arktest.assertEQ(l_Array, g_Array2) - arktest.assertEQ(l_Object, g_Object2) - arktest.assertEQ(l_Class, g_Class2) - } -} - - -function main() : int -{ - GlobalClass.s_method_boxing_local_class(); - return 0; -} diff --git a/ets2panda/test/runtime/ets/local-class-capture-not-boxing.ets b/ets2panda/test/runtime/ets/local-class-capture-not-boxing.ets deleted file mode 100644 index 9d477c5e7c1529b70bcb385b45ed5b87ffb2fe1a..0000000000000000000000000000000000000000 --- a/ets2panda/test/runtime/ets/local-class-capture-not-boxing.ets +++ /dev/null @@ -1,151 +0,0 @@ -/* - * Copyright (c) 2021-2025 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 UserClassType -{ - v : int = 0; - constructor (p : int) - { - this.v = p; - } - - override toString() : string { - return Int.valueOf(this.v).toString(); - } -} - -enum UserEnumType -{ - Red, - Green, - Blue -}; - -let g_array : int [] = [1,2,3]; -let g_array2 : int [] = [11,12,13]; -let g_Array : Array = new Array(new Int(4), new Int(5), new Int(6)); -let g_Array2 : Array = new Array(new Int(14), new Int(15), new Int(16)); -let g_Object : Object = new Object(); -let g_Object2 : Object = new Object(); -let g_Class : UserClassType = new UserClassType(25); -let g_Class2 : UserClassType = new UserClassType(250); - - - -class GlobalClass -{ - static s_field : int = 13; - field : int = 14; - - static s_method_not_boxing_local_class() { - // predefined value types - let l_number : number = 1; - let l_byte : byte = 2; - let l_short : short = 3; - let l_int : int = 4; - let l_long : long = 5; - let l_float : float = 6.0f; - let l_double : double = 7.0; - let l_boolean : boolean = false; - let l_char : char = c'x'; - - // user defined value types - let l_enum : UserEnumType = UserEnumType.Red; - - // predefined reference types - let l_Number : Number = new Number(11); - let l_Byte : Byte = new Byte(12 as byte); - let l_Short : Short = new Short(13 as short); - let l_Int : Int = new Int(14 as int); - let l_Long : Long = new Long(15 as long); - let l_Float : Float = new Float(16.0); - let l_Double : Double = new Double(17.0); - let l_Boolean: Boolean = new Boolean(false); - let l_Char : Char = new Char(c'X'); - - let l_string : string = "something"; - let l_String : String = new String("Something"); - let l_array : int [] = g_array; - let l_Array : Array = g_Array; - //let l_bigint : bigint = 20n; - //let l_BigInt : BigInt = new BigInt(21n); - let l_Object : Object = g_Object; - - // user defined reference types - let l_Class : UserClassType = g_Class; - - class LocalClassNotBoxing - { - local_field : int = 100; - static local_s_field : int = 200; - - static local_s_method(lp : int) : void - { - arktest.assertEQ(lp, 30) - arktest.assertEQ(LocalClassNotBoxing.local_s_field, 200) - } - - local_method(lp : int) : void - { - // Parameter - arktest.assertEQ(lp, 40) - // Local class object field - arktest.assertEQ(this.local_field, 100) - // Local class static field - arktest.assertEQ(LocalClassNotBoxing.local_s_field, 200) - // Predefined value types - arktest.assertEQ(l_number, 1) - arktest.assertEQ(l_byte, 2) - arktest.assertEQ(l_short, 3) - arktest.assertEQ(l_int, 4) - arktest.assertEQ(l_long, 5) - arktest.assertEQ(l_float, 6) - arktest.assertEQ(l_double, 7) - arktest.assertEQ(l_boolean, false) - arktest.assertEQ(l_char, c'x') - // User defined value type - arktest.assertEQ(l_enum, UserEnumType.Red) - // Predefined reference types - arktest.assertEQ(l_Number, Number.valueOf(11)) - arktest.assertEQ(l_Byte, Byte.valueOf(12 as byte)) - arktest.assertEQ(l_Short, Short.valueOf(13 as short)) - arktest.assertEQ(l_Int, Int.valueOf(14 as int)) - arktest.assertEQ(l_Long, Long.valueOf(15 as long)) - arktest.assertEQ(l_Float, Float.valueOf(16 as float)) - arktest.assertEQ(l_Double, Double.valueOf(17 as double)) - arktest.assertEQ(l_Boolean, Boolean.valueOf(false)) - arktest.assertEQ(l_Char, Char.valueOf(c'X')) - arktest.assertEQ(l_string, "something") - arktest.assertEQ(l_String, "Something") - arktest.assertEQ(l_array, g_array) - arktest.assertEQ(l_Array, g_Array) - arktest.assertEQ(l_Object, g_Object) - arktest.assertEQ(l_Class, g_Class) - } - }; - - LocalClassNotBoxing.local_s_method(30); - - let lc = new LocalClassNotBoxing(); - lc.local_method(40); - } -} - - -function main() : int -{ - GlobalClass.s_method_not_boxing_local_class(); - return 0; -} diff --git a/ets2panda/test/runtime/ets/local-class-capture-parameter.ets b/ets2panda/test/runtime/ets/local-class-capture-parameter.ets deleted file mode 100644 index 5ca80d7d79c83f33fe32bf6e4c4f64ea7276c3ef..0000000000000000000000000000000000000000 --- a/ets2panda/test/runtime/ets/local-class-capture-parameter.ets +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2021-2025 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 GlobalClass -{ - static capture_param_method(param : int) - { - class LocalClass - { - method() - { - arktest.assertEQ(param, 1) - } - } - - let lc = new LocalClass(); - lc.method() - } -} - -function main() : int -{ - GlobalClass.capture_param_method(1); - - return 0; -} diff --git a/ets2panda/test/runtime/ets/local-class-in-local-class.ets b/ets2panda/test/runtime/ets/local-class-in-local-class.ets deleted file mode 100644 index 6b00db07b3d901cb8764ace2da208e6afeaa28e8..0000000000000000000000000000000000000000 --- a/ets2panda/test/runtime/ets/local-class-in-local-class.ets +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2021-2025 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() : int -{ - let l_int = 0; - - class LocalClassLevel1 - { - m_int1 = 11; - - method1() - { - let l_int2 = 12; - arktest.assertEQ(this.m_int1, 11) - arktest.assertEQ(l_int, 0) - l_int = 1; - - class LocalClassLevel2 - { - m_int2 : int = 22; - - method2() { - arktest.assertEQ(this.m_int2, 22) - arktest.assertEQ(l_int2, 12) - l_int2 = 13; - } - } - - let lcl2 = new LocalClassLevel2(); - lcl2.method2(); - arktest.assertEQ(l_int2, 13) - } - } - - let lcl1 = new LocalClassLevel1(); - lcl1.method1(); - arktest.assertEQ(l_int, 1) - - return 0; -} diff --git a/ets2panda/test/runtime/ets/local-class-mixed-capture.ets b/ets2panda/test/runtime/ets/local-class-mixed-capture.ets deleted file mode 100644 index 6456d9b22a43a9d6538c34b8b179204b673c1903..0000000000000000000000000000000000000000 --- a/ets2panda/test/runtime/ets/local-class-mixed-capture.ets +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2021-2025 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() : int -{ - // Since the BoxingLocalClass modifies the 'i' it has to be boxed and use it as a boxed - // variable in the NotBoxingLocalClass too - let i : int = 1; - - class NotBoxingLocalClass - { - local_method() - { - arktest.assertEQ(i, 1) - } - } - - class BoxingLocalClass - { - local_method() - { - arktest.assertEQ(i, 1) - i = 2; - } - } - - let nblc = new NotBoxingLocalClass(); - nblc.local_method(); - - let blc = new BoxingLocalClass(); - blc.local_method(); - arktest.assertEQ(i, 2) - return 0; -} diff --git a/ets2panda/test/runtime/ets/local-class-modify-captured-parameter.ets b/ets2panda/test/runtime/ets/local-class-modify-captured-parameter.ets deleted file mode 100644 index 706a7b683664d64a2a3857dbc9de7c89ebbebcc0..0000000000000000000000000000000000000000 --- a/ets2panda/test/runtime/ets/local-class-modify-captured-parameter.ets +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2021-2025 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 GlobalClass -{ - static capture_param_method(param : int) - { - class LocalClass - { - method() - { - arktest.assertEQ(param, 1) - param = 3; - } - } - - let lc = new LocalClass(); - lc.method() - arktest.assertEQ(param, 3) - } -} - -function main() : int -{ - GlobalClass.capture_param_method(1); - - return 0; -} diff --git a/ets2panda/test/runtime/ets/local-class-standard-example1.ets b/ets2panda/test/runtime/ets/local-class-standard-example1.ets deleted file mode 100644 index 3e668fdc9f8503e61f0939eab60fb19637ff869f..0000000000000000000000000000000000000000 --- a/ets2panda/test/runtime/ets/local-class-standard-example1.ets +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2021-2025 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 foo (parameter: number) { - let local: string = "function local"; - interface LocalInterface { // Local interface in a top-level function - method (): void; // It has a method - field: string; // and a property - } - class LocalClass implements LocalInterface { // Class implements interface - // Local class in a top-level function - override method () { - console.log ("Instance field = " + this.field + " par = " + parameter + " loc = " + local ) - arktest.assertEQ(this.field, "`instance field value`") - arktest.assertEQ(parameter, 42) - arktest.assertEQ(local, "function local") - } - field: string = "`instance field value`" - static s_method () { - console.log ("Static field = " + LocalClass.s_field) - arktest.assertEQ(LocalClass.s_field, "`class/static field value`") - - } - static s_field: string = "`class/static field value`" - } - - let lc: LocalInterface = new LocalClass(); - // Both local types can be freely used in the top-level function scope - lc.method() - LocalClass.s_method() -} - -function main() : int -{ - foo(42); - return 0; -} diff --git a/ets2panda/test/runtime/ets/local-class-standard-example2.ets b/ets2panda/test/runtime/ets/local-class-standard-example2.ets deleted file mode 100644 index 8d6505f4e69cd216c9213f72c9fddf9f6df5bc0e..0000000000000000000000000000000000000000 --- a/ets2panda/test/runtime/ets/local-class-standard-example2.ets +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (c) 2021-2025 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_class { - field: number = 1234 // Not visible for the local class - method (parameter: number) { - let local: string = "instance local" - - interface LocalInterface { - method (): void - field: string - } - - class LocalClass implements LocalInterface { - override method () { - console.log ("Instance field = " + this.field + " par = " + parameter + " loc = " + local ) - arktest.assertEQ(this.field, "`instance method instance field value`") - arktest.assertEQ(parameter, 42) - arktest.assertEQ(local, "instance local") - - } - field: string = "`instance method instance field value`" - static s_method () { - console.log ("Static field = " + LocalClass.s_field) - arktest.assertEQ(LocalClass.s_field, "`instance method class/static field value`") - } - static s_field: string = "`instance method class/static field value`" - } - - let lc: LocalInterface = new LocalClass - lc.method() - LocalClass.s_method() - } - - static s_method (parameter: number) { - let local: string = "class/static local" - interface LocalInterface { - method (): void - field: string - } - - class LocalClass implements LocalInterface { - override method () { - console.log ("Instance field = " + this.field + " par = " + parameter + " loc = " + local) - arktest.assertEQ(this.field, "`static method instance field value`") - arktest.assertEQ(parameter, 72) - arktest.assertEQ(local, "class/static local") - } - field: string = "`static method instance field value`" - static s_method () { - console.log ("Static field = " + LocalClass.s_field) - arktest.assertEQ(LocalClass.s_field, "`static method class/static field value`") - } - static s_field: string = "`static method class/static field value`" - } - let lc: LocalInterface = new LocalClass - lc.method() - LocalClass.s_method() - } -} - -function main() : int -{ - A_class.s_method(72); - - let a = new A_class(); - a.method(42) - - return 0; -} diff --git a/ets2panda/test/runtime/ets/local_class_in_classfunction.ets b/ets2panda/test/runtime/ets/local_class_in_classfunction.ets deleted file mode 100644 index 511ba88ceee3379f5eeb8c677436478e85c94863..0000000000000000000000000000000000000000 --- a/ets2panda/test/runtime/ets/local_class_in_classfunction.ets +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2024-2025 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_class{ - foo(){ - let localfield:string = "localstring"; - abstract class AbstractLocalClass{ - field1:int = 100; - } - class LocalClass extends AbstractLocalClass{ - field2:int = 200; - static staticfield = 300; - method1(){ - arktest.assertEQ(this.field1, 100) - arktest.assertEQ(this.field2, 200) - arktest.assertEQ(localfield, "localstring") - } - static method2(){ - arktest.assertEQ(LocalClass.staticfield, 300) - } - } - final class FinalLocalClass{ - field1:int = 100; - static staticfield = 300; - method1(){ - arktest.assertEQ(this.field1, 100) - arktest.assertEQ(localfield, "localstring") - } - static method2(){ - arktest.assertEQ(LocalClass.staticfield, 300) - } - } - - let x:AbstractLocalClass = new LocalClass(); - arktest.assertEQ(x.field1, 100) - arktest.assertEQ(x.field2, 200) - arktest.assertEQ(LocalClass.staticfield, 300) - x.method1(); - LocalClass.method2(); - - let x2:FinalLocalClass = new FinalLocalClass(); - arktest.assertEQ(x2.field1, 100) - arktest.assertEQ(FinalLocalClass.staticfield, 300) - x2.method1() - FinalLocalClass.method2(); - } -} - -function main():void -{ - let x3:A_class = new A_class; - x3.foo(); -} \ No newline at end of file diff --git a/ets2panda/test/runtime/ets/local_class_in_function.ets b/ets2panda/test/runtime/ets/local_class_in_function.ets deleted file mode 100644 index 1433c62871583468a1b7c3b585c235e79eda2894..0000000000000000000000000000000000000000 --- a/ets2panda/test/runtime/ets/local_class_in_function.ets +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2024-2025 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 -{ - let localint:int = 200; - - abstract class AbstractLocalClass{ - field1:int = 10; - } - - class LocalClass extends AbstractLocalClass{ - field2:int = 20; - static staticfield = 30; - method1(){ - arktest.assertEQ(this.field1, 10) - arktest.assertEQ(this.field2, 20) - arktest.assertEQ(localint, 200) - } - static method2(){ - arktest.assertEQ(LocalClass.staticfield, 30) - } - } - - final class FinalLocalClass{ - field1:int = 10; - static staticfield = 30; - method1(){ - arktest.assertEQ(this.field1, 10) - arktest.assertEQ(localint, 200) - } - static method2(){ - arktest.assertEQ(FinalLocalClass.staticfield, 30) - } - } - - let x:AbstractLocalClass = new LocalClass(); - arktest.assertEQ(x.field1, 10) - arktest.assertEQ(x.field2, 20) - arktest.assertEQ(LocalClass.staticfield, 30) - x.method1(); - LocalClass.method2(); - - let x2:FinalLocalClass = new FinalLocalClass(); - arktest.assertEQ(x2.field1, 10) - arktest.assertEQ(FinalLocalClass.staticfield, 30) - x2.method1() - FinalLocalClass.method2(); -} \ No newline at end of file diff --git a/ets2panda/test/runtime/ets/statement_after_local_class.ets b/ets2panda/test/runtime/ets/statement_after_local_class.ets deleted file mode 100644 index db15a0eb8623f5616e184011c5ac1422390ccb78..0000000000000000000000000000000000000000 --- a/ets2panda/test/runtime/ets/statement_after_local_class.ets +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) 2024-2025 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 { - class MyClass { - constructor() { - } - - foo(): number { - return 1.0 - } - } - - let m = new MyClass() - - arktest.assertEQ(m.foo(), 1.0) -} diff --git a/ets2panda/util/diagnostic/syntax.yaml b/ets2panda/util/diagnostic/syntax.yaml index fef5d62ff27ad612df4680c0c147b50164cb8958..5a6faaeb5cfc8527183bcb51c4cf31a12b839b2f 100644 --- a/ets2panda/util/diagnostic/syntax.yaml +++ b/ets2panda/util/diagnostic/syntax.yaml @@ -168,9 +168,9 @@ syntax: id: 39 message: "A try statement should contain either finally clause or at least one catch clause." -- name: ILLEGAL_START_STRUCT +- name: ILLEGAL_START_STRUCT_CLASS id: 40 - message: "Illegal start of STRUCT expression." + message: "Illegal start of {} expression." - name: ONLY_EXPORT_CLASS_OR_INTERFACE id: 41