diff --git a/ets2panda/checker/ETSAnalyzer.cpp b/ets2panda/checker/ETSAnalyzer.cpp index 8501a207fd06f2864a94f0987220a93c7c9c94d1..359b48f15bbd685db3160927f2c18da742438741 100644 --- a/ets2panda/checker/ETSAnalyzer.cpp +++ b/ets2panda/checker/ETSAnalyzer.cpp @@ -1109,6 +1109,21 @@ checker::Type *ETSAnalyzer::SetAndAdjustType(ETSChecker *checker, ir::MemberExpr return expr->AdjustType(checker, resType); } +std::pair SearchReExportsType(Type *baseType, ir::MemberExpression *expr, + util::StringView aliasName) +{ + for (auto item : baseType->AsETSObjectType()->ReExports()) { + auto name = item->AsETSObjectType()->GetReExportAliasValue(aliasName); + if (item->GetProperty(name, PropertySearchFlags::SEARCH_ALL) != nullptr) { + return std::make_pair(item, name); + } + if (auto reExportType = SearchReExportsType(item, expr, name); reExportType.first != nullptr) { + return reExportType; + } + } + return std::make_pair(nullptr, util::StringView()); +} + checker::Type *ETSAnalyzer::Check(ir::MemberExpression *expr) const { if (expr->TsType() != nullptr) { @@ -1123,6 +1138,18 @@ checker::Type *ETSAnalyzer::Check(ir::MemberExpression *expr) const if (baseType->DefinitelyETSNullish() && expr->Object()->IsIdentifier()) { baseType = expr->Object()->AsIdentifier()->Variable()->TsType(); } + + if (baseType->IsETSObjectType() && !baseType->AsETSObjectType()->ReExports().empty() && + baseType->AsETSObjectType()->GetProperty(expr->Property()->AsIdentifier()->Name(), + PropertySearchFlags::SEARCH_ALL) == nullptr) { + if (auto reExportType = SearchReExportsType(baseType, expr, expr->Property()->AsIdentifier()->Name()); + reExportType.first != nullptr) { + baseType = reExportType.first; + expr->object_->AsIdentifier()->SetTsType(baseType); + expr->property_->AsIdentifier()->SetName(reExportType.second); + } + } + checker->CheckNonNullish(expr->Object()); if (expr->IsComputed()) { @@ -1639,7 +1666,6 @@ checker::Type *ETSAnalyzer::Check(ir::ImportNamespaceSpecifier *st) const } auto *importDecl = st->Parent()->AsETSImportDeclaration(); - auto importPath = importDecl->ResolvedSource()->Str(); if (importDecl->IsPureDynamic()) { auto *type = checker->GlobalBuiltinDynamicType(importDecl->Language()); @@ -1647,39 +1673,7 @@ checker::Type *ETSAnalyzer::Check(ir::ImportNamespaceSpecifier *st) const return type; } - auto [moduleName, isPackageModule] = checker->VarBinder()->AsETSBinder()->GetModuleInfo(importPath); - - std::vector syntheticNames = checker->GetNameForSynteticObjectType(moduleName); - - ASSERT(!syntheticNames.empty()); - - auto assemblerName = syntheticNames[0]; - if (!isPackageModule) { - assemblerName = util::UString(assemblerName.Mutf8().append(".").append(compiler::Signatures::ETS_GLOBAL), - checker->Allocator()) - .View(); - } - - auto *moduleObjectType = checker->Allocator()->New( - checker->Allocator(), syntheticNames[0], assemblerName, st->Local()->AsIdentifier(), - checker::ETSObjectFlags::CLASS, checker->Relation()); - - auto *rootDecl = checker->Allocator()->New(syntheticNames[0]); - varbinder::LocalVariable *rootVar = - checker->Allocator()->New(rootDecl, varbinder::VariableFlags::NONE); - rootVar->SetTsType(moduleObjectType); - - syntheticNames.erase(syntheticNames.begin()); - checker::ETSObjectType *lastObjectType(moduleObjectType); - - for (const auto &syntheticName : syntheticNames) { - lastObjectType = CreateSyntheticType(checker, syntheticName, lastObjectType, st->Local()->AsIdentifier()); - } - - checker->SetPropertiesForModuleObject(lastObjectType, importPath); - checker->SetrModuleObjectTsType(st->Local(), lastObjectType); - - return moduleObjectType; + return checker->GetImportSpecifierObjectType(importDecl, st->Local()->AsIdentifier()); } checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::ImportSpecifier *st) const @@ -2290,6 +2284,10 @@ checker::Type *ETSAnalyzer::Check(ir::TSAsExpression *expr) const checker->CreateBuiltinArraySignature(targetArrayType, targetArrayType->Rank()); } + if (targetType == checker->GetGlobalTypesHolder()->GlobalBuiltinNeverType()) { + checker->ThrowTypeError("Cast to 'never' is prohibited", expr->Start()); + } + checker->ComputeApparentType(targetType); expr->SetTsType(targetType); return expr->TsType(); @@ -2471,7 +2469,7 @@ checker::Type *ETSAnalyzer::Check(ir::TSNonNullExpression *expr) const expr->SetTsType(checker->GetNonNullishType(exprType)); } - + expr->SetOriginalType(expr->TsType()); return expr->TsType(); } diff --git a/ets2panda/checker/ETSchecker.h b/ets2panda/checker/ETSchecker.h index c9b686cb7157f9a4b4f91365840c4026f645732f..3e8a0d8a4a7483554907780770856a0807f01a7b 100644 --- a/ets2panda/checker/ETSchecker.h +++ b/ets2panda/checker/ETSchecker.h @@ -449,7 +449,11 @@ public: static std::string GetAsyncImplName(const util::StringView &name); static std::string GetAsyncImplName(ir::MethodDefinition *asyncMethod); std::vector GetNameForSynteticObjectType(const util::StringView &source); - void SetPropertiesForModuleObject(checker::ETSObjectType *moduleObjType, const util::StringView &importPath); + template + void BindingsModuleObjectAddProperty(checker::ETSObjectType *moduleObjType, ir::ETSImportDeclaration *importDecl, + const varbinder::Scope::VariableMap &bindings); + void SetPropertiesForModuleObject(checker::ETSObjectType *moduleObjType, const util::StringView &importPath, + ir::ETSImportDeclaration *importDecl = nullptr); void SetrModuleObjectTsType(ir::Identifier *local, checker::ETSObjectType *moduleObjType); Type *GetReferencedTypeFromBase(Type *baseType, ir::Expression *name); Type *GetReferencedTypeBase(ir::Expression *name); @@ -465,6 +469,7 @@ public: bool IsNullLikeOrVoidExpression(const ir::Expression *expr) const; bool IsConstantExpression(ir::Expression *expr, Type *type); void ValidateUnaryOperatorOperand(varbinder::Variable *variable); + void InferAliasLambdaType(ir::TypeNode *localTypeAnnotation, ir::Expression *init); bool TestUnionType(Type *type, TypeFlag test); bool CheckPossibilityPromotion(Type *left, Type *right, TypeFlag test); std::tuple ApplyBinaryOperatorPromotion(Type *left, Type *right, TypeFlag test, @@ -578,6 +583,11 @@ public: varbinder::ClassScope *scope, bool isSetter, ETSChecker *checker); void GenerateGetterSetterPropertyAndMethod(ir::ClassProperty *originalProp, ETSObjectType *classType); + ETSObjectType *GetImportSpecifierObjectType(ir::ETSImportDeclaration *importDecl, ir::Identifier *ident); + void ImportNamespaceObjectTypeAddReExportType(ir::ETSImportDeclaration *importDecl, + checker::ETSObjectType *lastObjectType, ir::Identifier *ident); + checker::ETSObjectType *CreateSyntheticType(util::StringView const &syntheticName, + checker::ETSObjectType *lastObjectType, ir::Identifier *id); // Smart cast support [[nodiscard]] checker::Type *ResolveSmartType(checker::Type *sourceType, checker::Type *targetType); @@ -683,6 +693,8 @@ private: void ValidateGetterSetter(const ir::MemberExpression *memberExpr, const varbinder::LocalVariable *prop, PropertySearchFlags searchFlag); void ValidateVarDeclaratorOrClassProperty(const ir::MemberExpression *memberExpr, varbinder::LocalVariable *prop); + void ResolveMemberReferenceValidate(varbinder::LocalVariable *prop, PropertySearchFlags searchFlag, + const ir::MemberExpression *const memberExpr); std::tuple IsResolvedAndValue(const ir::Expression *expr, Type *type) const; PropertySearchFlags GetSearchFlags(const ir::MemberExpression *memberExpr, const varbinder::Variable *targetRef); PropertySearchFlags GetInitialSearchFlags(const ir::MemberExpression *memberExpr); diff --git a/ets2panda/checker/ets/function.cpp b/ets2panda/checker/ets/function.cpp index 5190784fc5030b1f4127db3635ccc723394f38f7..5d263da0b12ce0739eea15685c418efb651323e9 100644 --- a/ets2panda/checker/ets/function.cpp +++ b/ets2panda/checker/ets/function.cpp @@ -1324,7 +1324,8 @@ void ETSChecker::ValidateSignatureAccessibility(ETSObjectType *callee, const ir: bool isSignatureInherited = callee->IsSignatureInherited(signature); const auto *currentOutermost = containingClass->OutermostClass(); - if (((signature->HasSignatureFlag(SignatureFlags::PROTECTED) && containingClass->IsDescendantOf(callee)) || + if (!signature->HasSignatureFlag(SignatureFlags::PRIVATE) && + ((signature->HasSignatureFlag(SignatureFlags::PROTECTED) && containingClass->IsDescendantOf(callee)) || (currentOutermost != nullptr && currentOutermost == callee->OutermostClass())) && isSignatureInherited) { return; diff --git a/ets2panda/checker/ets/helpers.cpp b/ets2panda/checker/ets/helpers.cpp index 20a7065b2a3323ed2c0aa9b5b2740c7536fdd666..374564cbe9d0e07c39f9507b87d7b692d14adfce 100644 --- a/ets2panda/checker/ets/helpers.cpp +++ b/ets2panda/checker/ets/helpers.cpp @@ -564,6 +564,37 @@ checker::Type *ETSChecker::CheckArrayElements(ir::Identifier *ident, ir::ArrayEx return annotationType; } +void ETSChecker::InferAliasLambdaType(ir::TypeNode *localTypeAnnotation, ir::Expression *init) +{ + if (localTypeAnnotation != nullptr && localTypeAnnotation->IsETSTypeReference()) { + bool isAnnotationTypeAlias = true; + while (localTypeAnnotation->IsETSTypeReference() && isAnnotationTypeAlias) { + auto *node = localTypeAnnotation->AsETSTypeReference() + ->Part() + ->Name() + ->AsIdentifier() + ->Variable() + ->Declaration() + ->Node(); + + isAnnotationTypeAlias = node->IsTSTypeAliasDeclaration(); + if (isAnnotationTypeAlias) { + localTypeAnnotation = node->AsTSTypeAliasDeclaration()->TypeAnnotation(); + } + } + } + + if (localTypeAnnotation != nullptr && localTypeAnnotation->IsETSFunctionType() && + init->IsArrowFunctionExpression()) { + auto *const arrowFuncExpr = init->AsArrowFunctionExpression(); + ir::ScriptFunction *const lambda = arrowFuncExpr->Function(); + if (lambda->Params().size() == localTypeAnnotation->AsETSFunctionType()->Params().size() && + NeedTypeInference(lambda)) { + InferTypesForLambda(lambda, localTypeAnnotation->AsETSFunctionType()); + } + } +} + checker::Type *ETSChecker::FixOptionalVariableType(varbinder::Variable *const bindingVar, ir::ModifierFlags flags) { if ((flags & ir::ModifierFlags::OPTIONAL) != 0) { @@ -633,14 +664,8 @@ checker::Type *ETSChecker::CheckVariableDeclaration(ir::Identifier *ident, ir::T init->AsObjectExpression()->SetPreferredType(annotationType); } - if (typeAnnotation != nullptr && typeAnnotation->IsETSFunctionType() && init->IsArrowFunctionExpression()) { - auto *const arrowFuncExpr = init->AsArrowFunctionExpression(); - ir::ScriptFunction *const lambda = arrowFuncExpr->Function(); - if (lambda->Params().size() == typeAnnotation->AsETSFunctionType()->Params().size() && - NeedTypeInference(lambda)) { - InferTypesForLambda(lambda, typeAnnotation->AsETSFunctionType()); - } - } + InferAliasLambdaType(typeAnnotation, init); + checker::Type *initType = init->Check(this); if (initType == nullptr) { @@ -1091,7 +1116,43 @@ std::vector ETSChecker::GetNameForSynteticObjectType(const uti return syntheticName; } -void ETSChecker::SetPropertiesForModuleObject(checker::ETSObjectType *moduleObjType, const util::StringView &importPath) +std::pair FindSpecifierForModuleObject(ir::ETSImportDeclaration *importDecl, + util::StringView const &name) +{ + if (importDecl == nullptr) { + return std::make_pair(true, util::StringView()); + } + + for (auto item : importDecl->Specifiers()) { + if (item->IsImportSpecifier() && item->AsImportSpecifier()->Imported()->Name().Is(name.Mutf8())) { + if (!item->AsImportSpecifier()->Imported()->Name().Is(item->AsImportSpecifier()->Local()->Name().Mutf8())) { + return std::make_pair(true, item->AsImportSpecifier()->Local()->Name()); + } + return std::make_pair(true, util::StringView()); + } + } + return std::make_pair(false, util::StringView()); +} + +template +void ETSChecker::BindingsModuleObjectAddProperty(checker::ETSObjectType *moduleObjType, + ir::ETSImportDeclaration *importDecl, + const varbinder::Scope::VariableMap &bindings) +{ + for (auto [_, var] : bindings) { + (void)_; + auto [found, aliasedName] = FindSpecifierForModuleObject(importDecl, var->AsLocalVariable()->Name()); + if (var->AsLocalVariable()->Declaration()->Node()->IsExported() && found) { + if (!aliasedName.Empty()) { + moduleObjType->AddReExportAlias(var->Declaration()->Name(), aliasedName); + } + moduleObjType->AddProperty(var->AsLocalVariable()); + } + } +} + +void ETSChecker::SetPropertiesForModuleObject(checker::ETSObjectType *moduleObjType, const util::StringView &importPath, + ir::ETSImportDeclaration *importDecl) { auto *etsBinder = static_cast(VarBinder()); @@ -1103,33 +1164,17 @@ void ETSChecker::SetPropertiesForModuleObject(checker::ETSObjectType *moduleObjT // Check imported properties before assigning them to module object res->second.front()->Ast()->Check(this); - for (auto [_, var] : res->second.front()->GlobalClassScope()->StaticFieldScope()->Bindings()) { - (void)_; - if (var->AsLocalVariable()->Declaration()->Node()->IsExported()) { - moduleObjType->AddProperty(var->AsLocalVariable()); - } - } + BindingsModuleObjectAddProperty( + moduleObjType, importDecl, res->second.front()->GlobalClassScope()->StaticFieldScope()->Bindings()); - for (auto [_, var] : res->second.front()->GlobalClassScope()->StaticMethodScope()->Bindings()) { - (void)_; - if (var->AsLocalVariable()->Declaration()->Node()->IsExported()) { - moduleObjType->AddProperty(var->AsLocalVariable()); - } - } + BindingsModuleObjectAddProperty( + moduleObjType, importDecl, res->second.front()->GlobalClassScope()->StaticMethodScope()->Bindings()); - for (auto [_, var] : res->second.front()->GlobalClassScope()->InstanceDeclScope()->Bindings()) { - (void)_; - if (var->AsLocalVariable()->Declaration()->Node()->IsExported()) { - moduleObjType->AddProperty(var->AsLocalVariable()); - } - } + BindingsModuleObjectAddProperty( + moduleObjType, importDecl, res->second.front()->GlobalClassScope()->InstanceDeclScope()->Bindings()); - for (auto [_, var] : res->second.front()->GlobalClassScope()->TypeAliasScope()->Bindings()) { - (void)_; - if (var->AsLocalVariable()->Declaration()->Node()->IsExported()) { - moduleObjType->AddProperty(var->AsLocalVariable()); - } - } + BindingsModuleObjectAddProperty( + moduleObjType, importDecl, res->second.front()->GlobalClassScope()->TypeAliasScope()->Bindings()); } void ETSChecker::SetrModuleObjectTsType(ir::Identifier *local, checker::ETSObjectType *moduleObjType) @@ -2273,4 +2318,77 @@ bool ETSChecker::TryTransformingToStaticInvoke(ir::Identifier *const ident, cons return true; } + +checker::ETSObjectType *ETSChecker::CreateSyntheticType(util::StringView const &syntheticName, + checker::ETSObjectType *lastObjectType, ir::Identifier *id) +{ + auto *syntheticObjType = Allocator()->New(Allocator(), syntheticName, syntheticName, id, + checker::ETSObjectFlags::NO_OPTS); + + auto *classDecl = Allocator()->New(syntheticName); + varbinder::LocalVariable *var = + Allocator()->New(classDecl, varbinder::VariableFlags::CLASS); + var->SetTsType(syntheticObjType); + lastObjectType->AddProperty(var); + syntheticObjType->SetEnclosingType(lastObjectType); + return syntheticObjType; +} + +void ETSChecker::ImportNamespaceObjectTypeAddReExportType(ir::ETSImportDeclaration *importDecl, + checker::ETSObjectType *lastObjectType, ir::Identifier *ident) +{ + for (auto item : VarBinder()->AsETSBinder()->ReExportImports()) { + if (!importDecl->ResolvedSource()->Str().Is(item->GetProgramPath().Mutf8())) { + continue; + } + auto *reExportType = GetImportSpecifierObjectType(item->GetETSImportDeclarations(), ident); + lastObjectType->AddReExports(reExportType); + for (auto node : importDecl->Specifiers()) { + if (node->IsImportSpecifier()) { + auto specifier = node->AsImportSpecifier(); + lastObjectType->AddReExportAlias(specifier->Imported()->Name(), specifier->Local()->Name()); + } + } + } +} + +ETSObjectType *ETSChecker::GetImportSpecifierObjectType(ir::ETSImportDeclaration *importDecl, ir::Identifier *ident) +{ + auto importPath = importDecl->ResolvedSource()->Str(); + + auto [moduleName, isPackageModule] = VarBinder()->AsETSBinder()->GetModuleInfo(importPath); + + std::vector syntheticNames = GetNameForSynteticObjectType(moduleName); + + ASSERT(!syntheticNames.empty()); + + auto assemblerName = syntheticNames[0]; + if (!isPackageModule) { + assemblerName = + util::UString(assemblerName.Mutf8().append(".").append(compiler::Signatures::ETS_GLOBAL), Allocator()) + .View(); + } + + auto *moduleObjectType = Allocator()->New( + Allocator(), syntheticNames[0], assemblerName, ident, checker::ETSObjectFlags::CLASS, Relation()); + + auto *rootDecl = Allocator()->New(syntheticNames[0]); + varbinder::LocalVariable *rootVar = + Allocator()->New(rootDecl, varbinder::VariableFlags::NONE); + rootVar->SetTsType(moduleObjectType); + + syntheticNames.erase(syntheticNames.begin()); + checker::ETSObjectType *lastObjectType(moduleObjectType); + + for (const auto &syntheticName : syntheticNames) { + lastObjectType = CreateSyntheticType(syntheticName, lastObjectType, ident); + } + + ImportNamespaceObjectTypeAddReExportType(importDecl, lastObjectType, ident); + SetPropertiesForModuleObject(lastObjectType, importPath, + importDecl->Specifiers()[0]->IsImportNamespaceSpecifier() ? nullptr : importDecl); + SetrModuleObjectTsType(ident, lastObjectType); + + return moduleObjectType; +} } // namespace ark::es2panda::checker diff --git a/ets2panda/checker/ets/narrowingConverter.h b/ets2panda/checker/ets/narrowingConverter.h index f40621b034b21eb5253eb1869cdf7417c155e1a1..8c9a6562cbc5a062ae9349e74773ddd4c257e8d9 100644 --- a/ets2panda/checker/ets/narrowingConverter.h +++ b/ets2panda/checker/ets/narrowingConverter.h @@ -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 @@ -103,6 +103,84 @@ private: } } + template + int CalculateIntValue(Type *target, 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; + } + } + } + + template + To CastFloatingPointToIntOrLong(From value) + { + if (std::isinf(value)) { + 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(); + To maxInt = std::numeric_limits::max(); + auto floatMinInt = static_cast(minInt); + auto floatMaxInt = static_cast(maxInt); + + if (value > floatMinInt) { + if (value < floatMaxInt) { + return static_cast(value); + } + return maxInt; + } + if (std::isnan(value)) { + return 0; + } + return minInt; + } + + template + TType CalculateNarrowedValue(Type *target, Type *source, SType value) + { + switch (ETSChecker::ETSChecker::ETSType(target)) { + case TypeFlag::BYTE: + case TypeFlag::CHAR: + case TypeFlag::SHORT: { + return CalculateIntValue(target, value); + } + case TypeFlag::INT: + case TypeFlag::LONG: { + if (source->HasTypeFlag(checker::TypeFlag::DOUBLE) || source->HasTypeFlag(checker::TypeFlag::FLOAT)) { + return CastFloatingPointToIntOrLong(value); + } + return static_cast(value); + } + case TypeFlag::FLOAT: + case TypeFlag::DOUBLE: { + return static_cast(value); + } + default: { + UNREACHABLE(); + } + } + } + template void ApplyNarrowing() { @@ -112,7 +190,9 @@ private: if (Source()->HasTypeFlag(TypeFlag::CONSTANT)) { SType value = reinterpret_cast(Source())->GetValue(); if (Relation()->InCastingContext() || util::Helpers::IsTargetFitInSourceRange(value)) { - Relation()->GetNode()->SetTsType(Checker()->Allocator()->New(static_cast(value))); + auto narrowedValue = CalculateNarrowedValue(Target(), Source(), value); + TargetType *newType = Checker()->Allocator()->New(narrowedValue); + Relation()->GetNode()->SetTsType(newType); Relation()->Result(true); return; } diff --git a/ets2panda/checker/ets/object.cpp b/ets2panda/checker/ets/object.cpp index ac1fd5a89ea63a8a05655a4dd0952bff1c092286..e8b45806837da9f2cc5528104cba7297e06a02c3 100644 --- a/ets2panda/checker/ets/object.cpp +++ b/ets2panda/checker/ets/object.cpp @@ -1540,7 +1540,12 @@ std::vector ETSChecker::ResolveMemberReference(const ir::Member searchFlag |= PropertySearchFlags::SEARCH_ALL; } - auto *const prop = target->GetProperty(memberExpr->Property()->AsIdentifier()->Name(), searchFlag); + auto searchName = target->GetReExportAliasValue(memberExpr->Property()->AsIdentifier()->Name()); + auto *const prop = target->GetProperty(searchName, searchFlag); + + if (memberExpr->Parent()->IsCallExpression() && memberExpr->Parent()->AsCallExpression()->Callee() == memberExpr) { + globalFunctionVar = ResolveInstanceExtension(memberExpr); + } if (globalFunctionVar == nullptr || (targetRef != nullptr && targetRef->HasFlag(varbinder::VariableFlags::CLASS_OR_INTERFACE))) { @@ -1570,6 +1575,15 @@ std::vector ETSChecker::ResolveMemberReference(const ir::Member resolveRes.emplace_back(Allocator()->New(prop, ResolvedKind::PROPERTY)); + ResolveMemberReferenceValidate(prop, searchFlag, memberExpr); + + return resolveRes; +} + +void ETSChecker::ResolveMemberReferenceValidate(varbinder::LocalVariable *const prop, + PropertySearchFlags const searchFlag, + const ir::MemberExpression *const memberExpr) +{ if (prop->HasFlag(varbinder::VariableFlags::METHOD) && !IsVariableGetterSetter(prop) && (searchFlag & PropertySearchFlags::IS_FUNCTIONAL) == 0) { ThrowTypeError("Method used in wrong context", memberExpr->Property()->Start()); @@ -1585,8 +1599,6 @@ std::vector ETSChecker::ResolveMemberReference(const ir::Member if (memberExpr->Parent()->IsVariableDeclarator() || memberExpr->Parent()->IsClassProperty()) { ValidateVarDeclaratorOrClassProperty(memberExpr, prop); } - - return resolveRes; } void ETSChecker::CheckValidInheritance(ETSObjectType *classType, ir::ClassDefinition *classDef) diff --git a/ets2panda/checker/ets/validateHelpers.cpp b/ets2panda/checker/ets/validateHelpers.cpp index 54577a59e6defcb8850b9b2f067b8d754b293baf..93a4ed518b3d835c3def7c9822416c9d67f8c039 100644 --- a/ets2panda/checker/ets/validateHelpers.cpp +++ b/ets2panda/checker/ets/validateHelpers.cpp @@ -13,12 +13,9 @@ * limitations under the License. */ -#include "compiler/lowering/scopesInit/scopesInitPhase.h" #include "varbinder/variableFlags.h" #include "checker/checker.h" #include "checker/checkerContext.h" -#include "checker/ets/narrowingWideningConverter.h" -#include "checker/types/globalTypesHolder.h" #include "checker/types/ets/etsObjectType.h" #include "checker/types/ets/etsTupleType.h" #include "ir/astNode.h" @@ -29,47 +26,27 @@ #include "ir/base/scriptFunction.h" #include "ir/base/classProperty.h" #include "ir/base/methodDefinition.h" -#include "ir/statements/blockStatement.h" -#include "ir/statements/classDeclaration.h" #include "ir/statements/variableDeclarator.h" #include "ir/statements/switchCaseStatement.h" #include "ir/expressions/identifier.h" #include "ir/expressions/arrayExpression.h" -#include "ir/expressions/objectExpression.h" #include "ir/expressions/callExpression.h" #include "ir/expressions/memberExpression.h" -#include "ir/expressions/literals/booleanLiteral.h" -#include "ir/expressions/literals/charLiteral.h" #include "ir/expressions/binaryExpression.h" #include "ir/expressions/assignmentExpression.h" -#include "ir/expressions/arrowFunctionExpression.h" -#include "ir/expressions/literals/numberLiteral.h" -#include "ir/expressions/literals/undefinedLiteral.h" -#include "ir/expressions/literals/nullLiteral.h" #include "ir/statements/labelledStatement.h" -#include "ir/statements/tryStatement.h" #include "ir/ets/etsFunctionType.h" #include "ir/ets/etsNewClassInstanceExpression.h" -#include "ir/ets/etsParameterExpression.h" -#include "ir/ts/tsAsExpression.h" #include "ir/ts/tsTypeAliasDeclaration.h" #include "ir/ts/tsEnumMember.h" #include "ir/ts/tsTypeParameter.h" #include "ir/ets/etsTypeReference.h" #include "ir/ets/etsTypeReferencePart.h" -#include "ir/ets/etsPrimitiveType.h" -#include "ir/ts/tsQualifiedName.h" #include "varbinder/variable.h" #include "varbinder/scope.h" #include "varbinder/declaration.h" -#include "parser/ETSparser.h" -#include "parser/program/program.h" #include "checker/ETSchecker.h" -#include "varbinder/ETSBinder.h" #include "checker/ets/typeRelationContext.h" -#include "checker/ets/boxingConverter.h" -#include "checker/ets/unboxingConverter.h" -#include "checker/types/ets/types.h" #include "util/helpers.h" namespace ark::es2panda::checker { @@ -268,6 +245,8 @@ void ETSChecker::ValidateUnaryOperatorOperand(varbinder::Variable *variable) void ETSChecker::ValidateGenericTypeAliasForClonedNode(ir::TSTypeAliasDeclaration *const typeAliasNode, const ir::TSTypeParameterInstantiation *const exactTypeParams) { + static std::string_view const TRANSFORMATION_NAME = __func__; + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *const clonedNode = typeAliasNode->TypeAnnotation()->Clone(Allocator(), typeAliasNode); @@ -280,7 +259,7 @@ void ETSChecker::ValidateGenericTypeAliasForClonedNode(ir::TSTypeAliasDeclaratio // Only transforming a temporary cloned node, so no modification is made in the AST clonedNode->TransformChildrenRecursively( - [&checkTypealias, &exactTypeParams, typeAliasNode](ir::AstNode *const node) -> ir::AstNode * { + [this, &checkTypealias, &exactTypeParams, typeAliasNode](ir::AstNode *const node) -> ir::AstNode * { if (!node->IsETSTypeReference()) { return node; } @@ -306,8 +285,9 @@ void ETSChecker::ValidateGenericTypeAliasForClonedNode(ir::TSTypeAliasDeclaratio return node; } - return typeParamType; - }); + return typeParamType->Clone(Allocator(), nullptr); + }, + TRANSFORMATION_NAME); if (checkTypealias) { clonedNode->Check(this); diff --git a/ets2panda/checker/types/ets/etsObjectType.cpp b/ets2panda/checker/types/ets/etsObjectType.cpp index 3fcdf820d0f071d3d10a1df9a83b24639fd1ec5f..213a39833303b37240c4210f2634a2dfda9b9753 100644 --- a/ets2panda/checker/types/ets/etsObjectType.cpp +++ b/ets2panda/checker/types/ets/etsObjectType.cpp @@ -970,4 +970,47 @@ std::uint32_t ETSObjectType::GetPrecedence(ETSObjectType const *type) noexcept } return 0U; } +void ETSObjectType::AddReExports(ETSObjectType *reExport) +{ + if (std::find(reExports_.begin(), reExports_.end(), reExport) == reExports_.end()) { + reExports_.push_back(reExport); + } +} + +void ETSObjectType::AddReExportAlias(util::StringView const &value, util::StringView const &key) +{ + reExportAlias_.insert({key, value}); +} + +util::StringView ETSObjectType::GetReExportAliasValue(util::StringView const &key) const +{ + auto ret = reExportAlias_.find(key); + if (reExportAlias_.end() == ret) { + return key; + } + return ret->second; +} + +const ArenaVector &ETSObjectType::ReExports() const +{ + return reExports_; +} + +void ETSObjectType::ToAssemblerType([[maybe_unused]] std::stringstream &ss) const +{ + ss << assemblerName_; +} + +void ETSObjectType::ToDebugInfoType(std::stringstream &ss) const +{ + DebugInfoTypeFromName(ss, assemblerName_); +} + +void ETSObjectType::ToDebugInfoSignatureType(std::stringstream &ss) const +{ + ss << compiler::Signatures::GENERIC_BEGIN; + ss << assemblerName_; + ss << compiler::Signatures::GENERIC_END; +} + } // namespace ark::es2panda::checker diff --git a/ets2panda/checker/types/ets/etsObjectType.h b/ets2panda/checker/types/ets/etsObjectType.h index 42fa39e9bc3ea4830886ca952418f2a6b07bd1d2..aa2c7f54ce35edec08163604080bb68310e4cf80 100644 --- a/ets2panda/checker/types/ets/etsObjectType.h +++ b/ets2panda/checker/types/ets/etsObjectType.h @@ -379,25 +379,15 @@ public: bool DefaultObjectTypeChecks(const ETSChecker *etsChecker, TypeRelation *relation, Type *source); void IsSupertypeOf(TypeRelation *relation, Type *source) override; Type *AsSuper(Checker *checker, varbinder::Variable *sourceVar) override; - - void ToAssemblerType([[maybe_unused]] std::stringstream &ss) const override - { - ss << assemblerName_; - } - + void ToAssemblerType([[maybe_unused]] std::stringstream &ss) const override; static void DebugInfoTypeFromName(std::stringstream &ss, util::StringView asmName); + void ToDebugInfoType(std::stringstream &ss) const override; + void ToDebugInfoSignatureType(std::stringstream &ss) const; - void ToDebugInfoType(std::stringstream &ss) const override - { - DebugInfoTypeFromName(ss, assemblerName_); - } - - void ToDebugInfoSignatureType(std::stringstream &ss) const - { - ss << compiler::Signatures::GENERIC_BEGIN; - ss << assemblerName_; - ss << compiler::Signatures::GENERIC_END; - } + void AddReExports(ETSObjectType *reExport); + void AddReExportAlias(util::StringView const &value, util::StringView const &key); + util::StringView GetReExportAliasValue(util::StringView const &key) const; + const ArenaVector &ReExports() const; ArenaAllocator *Allocator() const { @@ -430,6 +420,8 @@ private: assemblerName_(assemblerName), declNode_(declNode), interfaces_(allocator->Adapter()), + reExports_(allocator->Adapter()), + reExportAlias_(allocator->Adapter()), flags_(flags), instantiationMap_(allocator->Adapter()), typeArguments_(allocator->Adapter()), @@ -475,6 +467,8 @@ private: util::StringView assemblerName_; ir::AstNode *declNode_; ArenaVector interfaces_; + ArenaVector reExports_; + ArenaMap reExportAlias_; ETSObjectFlags flags_; InstantiationMap instantiationMap_; ArenaVector typeArguments_; diff --git a/ets2panda/compiler/core/ETSCompiler.cpp b/ets2panda/compiler/core/ETSCompiler.cpp index 876becbdebf6f9c0f026c2424090b630518bc9a2..8b837ef3828cef376407e4077e312b0ee39f1cba 100644 --- a/ets2panda/compiler/core/ETSCompiler.cpp +++ b/ets2panda/compiler/core/ETSCompiler.cpp @@ -2271,7 +2271,7 @@ void ETSCompiler::Compile(const ir::TSNonNullExpression *expr) const etsg->SetLabel(expr, endLabel); etsg->LoadAccumulator(expr, arg); - etsg->AssumeNonNullish(expr, expr->TsType()); + etsg->AssumeNonNullish(expr, expr->OriginalType()); } void ETSCompiler::Compile([[maybe_unused]] const ir::TSNullKeyword *node) const diff --git a/ets2panda/compiler/lowering/ets/bigintLowering.cpp b/ets2panda/compiler/lowering/ets/bigintLowering.cpp index 506fb3b03d990471e16c296a20be14ad8c7379e6..61354c558406ddb2331e9ee1d6e250a08e5b529b 100644 --- a/ets2panda/compiler/lowering/ets/bigintLowering.cpp +++ b/ets2panda/compiler/lowering/ets/bigintLowering.cpp @@ -15,9 +15,6 @@ #include "bigintLowering.h" -#include "checker/ETSchecker.h" -#include "macros.h" - namespace ark::es2panda::compiler { std::string_view BigIntLowering::Name() const @@ -25,6 +22,22 @@ std::string_view BigIntLowering::Name() const return "BigIntLowering"; } +void CreateBigInt(parser::ETSParser *parser, ir::ClassProperty *property) +{ + if (property != nullptr && property->Value() != nullptr && property->Value()->IsBigIntLiteral()) { + auto literal = property->Value()->AsBigIntLiteral(); + auto value = literal->Str(); + + // This will change the bigint literal node into the new class instance expression. + std::string src {"new BigInt("}; + src += value.Utf8(); + src += ")"; + auto newValue = parser->AsETSParser()->CreateExpression(src); + newValue->SetParent(property); + property->SetValue(newValue); + } +} + bool BigIntLowering::Perform(public_lib::Context *const ctx, parser::Program *const program) { for (const auto &[_, ext_programs] : program->ExternalSources()) { @@ -34,24 +47,17 @@ bool BigIntLowering::Perform(public_lib::Context *const ctx, parser::Program *co } } - program->Ast()->TransformChildrenRecursively([ctx](ir::AstNode *const ast) -> ir::AstNode * { - if (ast != nullptr && ast->IsClassProperty()) { - auto property = ast->AsClassProperty(); - if (property != nullptr && property->Value() != nullptr && property->Value()->IsBigIntLiteral()) { - auto literal = property->Value()->AsBigIntLiteral(); - auto value = literal->Str(); - - // This will change the bigint literal node into the new class instance expression. - std::stringstream src; - src << "new BigInt(" << value << ")"; - auto newValue = ctx->parser->AsETSParser()->CreateExpression(src.str()); - newValue->SetParent(property); - property->SetValue(newValue); + auto *const parser = ctx->parser->AsETSParser(); + + program->Ast()->TransformChildrenRecursively( + [parser](ir::AstNode *ast) -> ir::AstNode * { + if (ast->IsClassProperty()) { + CreateBigInt(parser, ast->AsClassProperty()); } - } - return ast; - }); + return ast; + }, + Name()); return true; } diff --git a/ets2panda/compiler/lowering/ets/expandBrackets.cpp b/ets2panda/compiler/lowering/ets/expandBrackets.cpp index 40712001492804378c987e8aa9f3774574cc54d3..ff1d28ecc54aa8bd1e55a0cc333f47ab8d72f347 100644 --- a/ets2panda/compiler/lowering/ets/expandBrackets.cpp +++ b/ets2panda/compiler/lowering/ets/expandBrackets.cpp @@ -165,18 +165,20 @@ bool ExpandBracketsPhase::Perform(public_lib::Context *ctx, parser::Program *pro auto *const checker = ctx->checker->AsETSChecker(); ASSERT(checker != nullptr); - program->Ast()->TransformChildrenRecursively([this, parser, checker](ir::AstNode *const ast) -> ir::AstNode * { - if (ast->IsETSNewArrayInstanceExpression()) { - return ProcessNewArrayInstanceExpression(parser, checker, ast->AsETSNewArrayInstanceExpression()); - } + program->Ast()->TransformChildrenRecursively( + [this, parser, checker](ir::AstNode *const ast) -> ir::AstNode * { + if (ast->IsETSNewArrayInstanceExpression()) { + return ProcessNewArrayInstanceExpression(parser, checker, ast->AsETSNewArrayInstanceExpression()); + } - if (ast->IsETSNewMultiDimArrayInstanceExpression()) { - return ProcessNewMultiDimArrayInstanceExpression(parser, checker, - ast->AsETSNewMultiDimArrayInstanceExpression()); - } + if (ast->IsETSNewMultiDimArrayInstanceExpression()) { + return ProcessNewMultiDimArrayInstanceExpression(parser, checker, + ast->AsETSNewMultiDimArrayInstanceExpression()); + } - return ast; - }); + return ast; + }, + Name()); return true; } diff --git a/ets2panda/compiler/lowering/ets/interfacePropertyDeclarations.cpp b/ets2panda/compiler/lowering/ets/interfacePropertyDeclarations.cpp index 53e8181d14b5b8e19a8af644ea25b03822904168..6c1cd2833d585995faec00883a4394573683ccae 100644 --- a/ets2panda/compiler/lowering/ets/interfacePropertyDeclarations.cpp +++ b/ets2panda/compiler/lowering/ets/interfacePropertyDeclarations.cpp @@ -110,8 +110,9 @@ static ir::MethodDefinition *GenerateGetterOrSetter(checker::ETSChecker *const c func->SetScope(functionScope); - auto methodIdent = field->Key()->AsIdentifier()->Clone(checker->Allocator(), nullptr); - auto *decl = checker->Allocator()->New(field->Key()->AsIdentifier()->Name()); + auto const &name = field->Key()->AsIdentifier()->Name(); + auto methodIdent = checker->AllocNode(name, checker->Allocator()); + auto *decl = checker->Allocator()->New(name); auto var = functionScope->AddDecl(checker->Allocator(), decl, ScriptExtension::ETS); methodIdent->SetVariable(var); @@ -182,7 +183,6 @@ static ir::Expression *UpdateInterfacePropertys(checker::ETSChecker *const check newPropertyList.emplace_back(setter); getter->AddOverload(setter); } - getter->Function()->Id()->SetVariable(var); scope->AsClassScope()->InstanceFieldScope()->EraseBinding(name); } @@ -204,9 +204,11 @@ bool InterfacePropertyDeclarationsPhase::Perform(public_lib::Context *ctx, parse checker::ETSChecker *const checker = ctx->checker->AsETSChecker(); - program->Ast()->TransformChildrenRecursively([checker](ir::AstNode *const ast) -> ir::AstNode * { - return ast->IsTSInterfaceBody() ? UpdateInterfacePropertys(checker, ast->AsTSInterfaceBody()) : ast; - }); + program->Ast()->TransformChildrenRecursively( + [checker](ir::AstNode *const ast) -> ir::AstNode * { + return ast->IsTSInterfaceBody() ? UpdateInterfacePropertys(checker, ast->AsTSInterfaceBody()) : ast; + }, + Name()); return true; } diff --git a/ets2panda/compiler/lowering/ets/lambdaLowering.cpp b/ets2panda/compiler/lowering/ets/lambdaLowering.cpp index d338f74efbdf78e8fcc51b553d02fa58c7bbb1c7..e25ab3d6b1f3d5cbd8e19a60df62138d5b49f457 100644 --- a/ets2panda/compiler/lowering/ets/lambdaLowering.cpp +++ b/ets2panda/compiler/lowering/ets/lambdaLowering.cpp @@ -58,14 +58,16 @@ bool LambdaConstructionPhase::Perform(public_lib::Context *ctx, parser::Program checker::ETSChecker *const checker = ctx->checker->AsETSChecker(); - program->Ast()->TransformChildrenRecursively([checker](ir::AstNode *const node) -> AstNodePtr { - if (node->IsArrowFunctionExpression() && - node->AsArrowFunctionExpression()->Function()->Body()->IsExpression()) { - return ConvertExpression(checker, node->AsArrowFunctionExpression()); - } + program->Ast()->TransformChildrenRecursively( + [checker](ir::AstNode *const node) -> AstNodePtr { + if (node->IsArrowFunctionExpression() && + node->AsArrowFunctionExpression()->Function()->Body()->IsExpression()) { + return ConvertExpression(checker, node->AsArrowFunctionExpression()); + } - return node; - }); + return node; + }, + Name()); return true; } diff --git a/ets2panda/compiler/lowering/ets/objectIndexAccess.cpp b/ets2panda/compiler/lowering/ets/objectIndexAccess.cpp index de87fdccdda6655aa8b63250984092b5f55d38f3..e9fd37fda5b580954a39a1a382ad23c1119e7686 100644 --- a/ets2panda/compiler/lowering/ets/objectIndexAccess.cpp +++ b/ets2panda/compiler/lowering/ets/objectIndexAccess.cpp @@ -80,28 +80,33 @@ bool ObjectIndexLowering::Perform(public_lib::Context *ctx, parser::Program *pro auto *const checker = ctx->checker->AsETSChecker(); ASSERT(checker != nullptr); - program->Ast()->TransformChildrenRecursively([this, parser, checker](ir::AstNode *const ast) -> ir::AstNode * { - if (ast->IsAssignmentExpression() && ast->AsAssignmentExpression()->Left()->IsMemberExpression() && - ast->AsAssignmentExpression()->Left()->AsMemberExpression()->Kind() == - ir::MemberExpressionKind::ELEMENT_ACCESS) { - if (auto const *const objectType = ast->AsAssignmentExpression()->Left()->AsMemberExpression()->ObjType(); - objectType != nullptr && !objectType->IsETSDynamicType()) { - return ProcessIndexSetAccess(parser, checker, ast->AsAssignmentExpression()); + program->Ast()->TransformChildrenRecursively( + [this, parser, checker](ir::AstNode *const ast) -> ir::AstNode * { + if (ast->IsAssignmentExpression() && ast->AsAssignmentExpression()->Left()->IsMemberExpression() && + ast->AsAssignmentExpression()->Left()->AsMemberExpression()->Kind() == + ir::MemberExpressionKind::ELEMENT_ACCESS) { + if (auto const *const objectType = + ast->AsAssignmentExpression()->Left()->AsMemberExpression()->ObjType(); + objectType != nullptr && !objectType->IsETSDynamicType()) { + return ProcessIndexSetAccess(parser, checker, ast->AsAssignmentExpression()); + } } - } - return ast; - }); - - program->Ast()->TransformChildrenRecursively([this, parser, checker](ir::AstNode *const ast) -> ir::AstNode * { - if (ast->IsMemberExpression() && - ast->AsMemberExpression()->Kind() == ir::MemberExpressionKind::ELEMENT_ACCESS) { - if (auto const *const objectType = ast->AsMemberExpression()->ObjType(); - objectType != nullptr && !objectType->IsETSDynamicType()) { - return ProcessIndexGetAccess(parser, checker, ast->AsMemberExpression()); + return ast; + }, + Name()); + + program->Ast()->TransformChildrenRecursively( + [this, parser, checker](ir::AstNode *const ast) -> ir::AstNode * { + if (ast->IsMemberExpression() && + ast->AsMemberExpression()->Kind() == ir::MemberExpressionKind::ELEMENT_ACCESS) { + if (auto const *const objectType = ast->AsMemberExpression()->ObjType(); + objectType != nullptr && !objectType->IsETSDynamicType()) { + return ProcessIndexGetAccess(parser, checker, ast->AsMemberExpression()); + } } - } - return ast; - }); + return ast; + }, + Name()); return true; } diff --git a/ets2panda/compiler/lowering/ets/objectIterator.cpp b/ets2panda/compiler/lowering/ets/objectIterator.cpp index 7efc373d78dd9cb9df9c7de872ab1ffa4e0c482d..ea7117dbe9c3fa1e1acba1c233e766647a7d8c90 100644 --- a/ets2panda/compiler/lowering/ets/objectIterator.cpp +++ b/ets2panda/compiler/lowering/ets/objectIterator.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 - 2024 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 @@ -160,16 +160,18 @@ bool ObjectIteratorLowering::Perform(public_lib::Context *ctx, parser::Program * auto *const varbinder = ctx->compilerContext->VarBinder()->AsETSBinder(); ASSERT(varbinder != nullptr); - program->Ast()->TransformChildrenRecursively([this, parser, checker, varbinder](ir::AstNode *ast) -> ir::AstNode * { - if (ast->IsForOfStatement()) { - if (auto const *const exprType = ast->AsForOfStatement()->Right()->TsType(); - exprType != nullptr && ((exprType->IsETSObjectType() && !exprType->IsETSStringType()) || - exprType->IsETSUnionType() || exprType->IsETSTypeParameter())) { - return ProcessObjectIterator(parser, checker, varbinder, ast->AsForOfStatement()); + program->Ast()->TransformChildrenRecursively( + [this, parser, checker, varbinder](ir::AstNode *ast) -> ir::AstNode * { + if (ast->IsForOfStatement()) { + if (auto const *const exprType = ast->AsForOfStatement()->Right()->TsType(); + exprType != nullptr && ((exprType->IsETSObjectType() && !exprType->IsETSStringType()) || + exprType->IsETSUnionType() || exprType->IsETSTypeParameter())) { + return ProcessObjectIterator(parser, checker, varbinder, ast->AsForOfStatement()); + } } - } - return ast; - }); + return ast; + }, + Name()); return true; } diff --git a/ets2panda/compiler/lowering/ets/objectLiteralLowering.cpp b/ets2panda/compiler/lowering/ets/objectLiteralLowering.cpp index 07f6c9f7cfe335f58e7458a818e42c73698cb31d..458e5830e6fef3a930ac297d9a11aa85adbc8ba8 100644 --- a/ets2panda/compiler/lowering/ets/objectLiteralLowering.cpp +++ b/ets2panda/compiler/lowering/ets/objectLiteralLowering.cpp @@ -165,14 +165,17 @@ bool ObjectLiteralLowering::Perform(public_lib::Context *ctx, parser::Program *p } } - program->Ast()->TransformChildrenRecursively([ctx](ir::AstNode *ast) -> ir::AstNode * { - // Skip processing dynamic objects - if (ast->IsObjectExpression() && !ast->AsObjectExpression()->PreferredType()->AsETSObjectType()->HasObjectFlag( - checker::ETSObjectFlags::DYNAMIC)) { - return HandleObjectLiteralLowering(ctx, ast->AsObjectExpression()); - } - return ast; - }); + program->Ast()->TransformChildrenRecursively( + [ctx](ir::AstNode *ast) -> ir::AstNode * { + // Skip processing dynamic objects + if (ast->IsObjectExpression() && + !ast->AsObjectExpression()->PreferredType()->AsETSObjectType()->HasObjectFlag( + checker::ETSObjectFlags::DYNAMIC)) { + return HandleObjectLiteralLowering(ctx, ast->AsObjectExpression()); + } + return ast; + }, + Name()); return true; } diff --git a/ets2panda/compiler/lowering/ets/opAssignment.cpp b/ets2panda/compiler/lowering/ets/opAssignment.cpp index 3425d450100c4d1fa2f285ab68d9e17e204b61cd..07360a679dde5d09f047d7df4e4dcddf99f8b28f 100644 --- a/ets2panda/compiler/lowering/ets/opAssignment.cpp +++ b/ets2panda/compiler/lowering/ets/opAssignment.cpp @@ -222,14 +222,16 @@ bool OpAssignmentLowering::Perform(public_lib::Context *ctx, parser::Program *pr auto *const parser = ctx->parser->AsETSParser(); checker::ETSChecker *checker = ctx->checker->AsETSChecker(); - program->Ast()->TransformChildrenRecursively([ctx, checker, parser](ir::AstNode *ast) -> ir::AstNode * { - if (ast->IsAssignmentExpression() && - ast->AsAssignmentExpression()->OperatorType() != lexer::TokenType::PUNCTUATOR_SUBSTITUTION) { - return HandleOpAssignment(ctx, checker, parser, ast->AsAssignmentExpression()); - } + program->Ast()->TransformChildrenRecursively( + [ctx, checker, parser](ir::AstNode *ast) -> ir::AstNode * { + if (ast->IsAssignmentExpression() && + ast->AsAssignmentExpression()->OperatorType() != lexer::TokenType::PUNCTUATOR_SUBSTITUTION) { + return HandleOpAssignment(ctx, checker, parser, ast->AsAssignmentExpression()); + } - return ast; - }); + return ast; + }, + Name()); return true; } diff --git a/ets2panda/compiler/lowering/ets/optionalLowering.cpp b/ets2panda/compiler/lowering/ets/optionalLowering.cpp index 029d4cb16b4dcb4e58bc653650817c5809af941b..3040d0a530802e82260149e71a3b710e6115adbd 100644 --- a/ets2panda/compiler/lowering/ets/optionalLowering.cpp +++ b/ets2panda/compiler/lowering/ets/optionalLowering.cpp @@ -131,12 +131,14 @@ bool OptionalLowering::Perform(public_lib::Context *ctx, parser::Program *progra } } - program->Ast()->TransformChildrenRecursively([ctx](ir::AstNode *const node) -> ir::AstNode * { - if (node->IsChainExpression()) { - return RefineSourceRanges(LowerChain(ctx, node->AsChainExpression())); - } - return node; - }); + program->Ast()->TransformChildrenRecursively( + [ctx](ir::AstNode *const node) -> ir::AstNode * { + if (node->IsChainExpression()) { + return RefineSourceRanges(LowerChain(ctx, node->AsChainExpression())); + } + return node; + }, + Name()); return true; } diff --git a/ets2panda/compiler/lowering/ets/promiseVoid.cpp b/ets2panda/compiler/lowering/ets/promiseVoid.cpp index be6913e87c639fd169c65c1ee6e98c1eea404519..e9f57956419a41649dfb859852303afbd6993e2a 100644 --- a/ets2panda/compiler/lowering/ets/promiseVoid.cpp +++ b/ets2panda/compiler/lowering/ets/promiseVoid.cpp @@ -32,36 +32,43 @@ #include "util/ustring.h" namespace ark::es2panda::compiler { -static ir::BlockStatement *HandleAsyncScriptFunctionBody(checker::ETSChecker *checker, ir::BlockStatement *body) +ir::BlockStatement *PromiseVoidInferencePhase::HandleAsyncScriptFunctionBody(checker::ETSChecker *checker, + ir::BlockStatement *body) { (void)checker; - body->TransformChildrenRecursively([checker](ir::AstNode *ast) -> ir::AstNode * { - if (ast->IsReturnStatement()) { - auto *returnStmt = ast->AsReturnStatement(); - const auto *arg = returnStmt->Argument(); - if (arg == nullptr) { - auto *voidId = - checker->AllocNode(compiler::Signatures::UNDEFINED, checker->Allocator()); - const auto &returnLoc = returnStmt->Range(); - voidId->SetRange({returnLoc.end, returnLoc.end}); - returnStmt->SetArgument(voidId); + body->TransformChildrenRecursively( + [checker](ir::AstNode *ast) -> ir::AstNode * { + if (ast->IsReturnStatement()) { + auto *returnStmt = ast->AsReturnStatement(); + const auto *arg = returnStmt->Argument(); + if (arg == nullptr) { + auto *voidId = + checker->AllocNode(compiler::Signatures::UNDEFINED, checker->Allocator()); + const auto &returnLoc = returnStmt->Range(); + voidId->SetRange({returnLoc.end, returnLoc.end}); + returnStmt->SetArgument(voidId); + } } - } - return ast; - }); + return ast; + }, + Name()); + return body; } -static void SetRangeRecursively(ir::TypeNode *node, const lexer::SourceRange &loc) +void PromiseVoidInferencePhase::SetRangeRecursively(ir::TypeNode *node, const lexer::SourceRange &loc) { node->SetRange(loc); - node->TransformChildrenRecursively([loc](ir::AstNode *ast) -> ir::AstNode * { - ast->SetRange(loc); - return ast; - }); + node->TransformChildrenRecursively( + [loc](ir::AstNode *ast) -> ir::AstNode * { + ast->SetRange(loc); + return ast; + }, + Name()); } -static ir::TypeNode *CreatePromiseVoidType(checker::ETSChecker *checker, const lexer::SourceRange &loc) +ir::TypeNode *PromiseVoidInferencePhase::CreatePromiseVoidType(checker::ETSChecker *checker, + const lexer::SourceRange &loc) { auto *voidParam = [checker]() { auto paramsVector = ArenaVector(checker->Allocator()->Adapter()); @@ -160,7 +167,7 @@ bool PromiseVoidInferencePhase::Perform(public_lib::Context *ctx, parser::Progra return {loc.end, loc.end}; }; - const auto transformer = [checker, genTypeLocation](ir::AstNode *ast) -> AstNodePtr { + const auto transformer = [this, checker, genTypeLocation](ir::AstNode *ast) -> AstNodePtr { if (!(ast->IsScriptFunction() && ast->AsScriptFunction()->IsAsyncFunc())) { return ast; } @@ -184,7 +191,7 @@ bool PromiseVoidInferencePhase::Perform(public_lib::Context *ctx, parser::Progra return ast; }; - program->Ast()->TransformChildrenRecursively(transformer); + program->Ast()->TransformChildrenRecursively(transformer, Name()); return true; } diff --git a/ets2panda/compiler/lowering/ets/promiseVoid.h b/ets2panda/compiler/lowering/ets/promiseVoid.h index a5dfe40ab6fe56c00a6601ce59fb434d2d0316ca..3864f644b5249993213280ecad2c89f64fd4c4f6 100644 --- a/ets2panda/compiler/lowering/ets/promiseVoid.h +++ b/ets2panda/compiler/lowering/ets/promiseVoid.h @@ -31,6 +31,9 @@ public: bool Postcondition(public_lib::Context *ctx, const parser::Program *program) override; private: + ir::BlockStatement *HandleAsyncScriptFunctionBody(checker::ETSChecker *checker, ir::BlockStatement *body); + void SetRangeRecursively(ir::TypeNode *node, const lexer::SourceRange &loc); + ir::TypeNode *CreatePromiseVoidType(checker::ETSChecker *checker, const lexer::SourceRange &loc); }; } // namespace ark::es2panda::compiler diff --git a/ets2panda/compiler/lowering/ets/recordLowering.cpp b/ets2panda/compiler/lowering/ets/recordLowering.cpp index b6f287dbb019424793481ac54cfa6f2380a26ba2..4a87c4a5cde908565af0268e6b96eeed791ce256 100644 --- a/ets2panda/compiler/lowering/ets/recordLowering.cpp +++ b/ets2panda/compiler/lowering/ets/recordLowering.cpp @@ -53,13 +53,15 @@ bool RecordLowering::Perform(public_lib::Context *ctx, parser::Program *program) } // Replace Record Object Expressions with Block Expressions - program->Ast()->TransformChildrenRecursively([this, ctx](ir::AstNode *ast) -> ir::AstNode * { - if (ast->IsObjectExpression()) { - return UpdateObjectExpression(ast->AsObjectExpression(), ctx); - } - - return ast; - }); + program->Ast()->TransformChildrenRecursively( + [this, ctx](ir::AstNode *ast) -> ir::AstNode * { + if (ast->IsObjectExpression()) { + return UpdateObjectExpression(ast->AsObjectExpression(), ctx); + } + + return ast; + }, + Name()); return true; } diff --git a/ets2panda/compiler/lowering/ets/structLowering.cpp b/ets2panda/compiler/lowering/ets/structLowering.cpp index 4c3f8094c30b0ffd0b1b2976524e377be126b6eb..fe1e370dcf70627725c3b326e9b2206fc313cfaa 100644 --- a/ets2panda/compiler/lowering/ets/structLowering.cpp +++ b/ets2panda/compiler/lowering/ets/structLowering.cpp @@ -92,15 +92,17 @@ bool StructLowering::Perform(public_lib::Context *ctx, parser::Program *program) checker::ETSChecker *checker = ctx->checker->AsETSChecker(); - program->Ast()->TransformChildrenRecursively([checker](ir::AstNode *ast) -> AstNodePtr { - if (ast->IsETSStructDeclaration()) { - auto *typeRef = CreateStructTypeReference(checker, ast->AsETSStructDeclaration()); - ast->AsETSStructDeclaration()->Definition()->SetSuper(typeRef); - ast->AsETSStructDeclaration()->Definition()->AddModifier(ir::ModifierFlags::FINAL); - } - - return ast; - }); + program->Ast()->TransformChildrenRecursively( + [checker](ir::AstNode *ast) -> AstNodePtr { + if (ast->IsETSStructDeclaration()) { + auto *typeRef = CreateStructTypeReference(checker, ast->AsETSStructDeclaration()); + ast->AsETSStructDeclaration()->Definition()->SetSuper(typeRef); + ast->AsETSStructDeclaration()->Definition()->AddModifier(ir::ModifierFlags::FINAL); + } + + return ast; + }, + Name()); return true; } diff --git a/ets2panda/compiler/lowering/ets/tupleLowering.cpp b/ets2panda/compiler/lowering/ets/tupleLowering.cpp index d945e2cb95061c984f07164c34a025c4750a45b8..f90404c6d1cfcaa1300b9363051e6d3f99e7b0f5 100644 --- a/ets2panda/compiler/lowering/ets/tupleLowering.cpp +++ b/ets2panda/compiler/lowering/ets/tupleLowering.cpp @@ -219,19 +219,21 @@ bool TupleLowering::Perform(public_lib::Context *const ctx, parser::Program *con checker::ETSChecker *const checker = ctx->checker->AsETSChecker(); - program->Ast()->TransformChildrenRecursively([checker](ir::AstNode *const ast) -> ir::AstNode * { - // Check if node is an 'assignment expression', with a member expression on the left (potentially tuple) - if (ast->IsAssignmentExpression() && ast->AsAssignmentExpression()->Left()->IsMemberExpression()) { - return ConvertTupleAssignment(checker, ast->AsAssignmentExpression()); - } + program->Ast()->TransformChildrenRecursively( + [checker](ir::AstNode *const ast) -> ir::AstNode * { + // Check if node is an 'assignment expression', with a member expression on the left (potentially tuple) + if (ast->IsAssignmentExpression() && ast->AsAssignmentExpression()->Left()->IsMemberExpression()) { + return ConvertTupleAssignment(checker, ast->AsAssignmentExpression()); + } - // Check if node is an 'update expression', with a member expression as an argument (potentially tuple) - if (ast->IsUpdateExpression() && ast->AsUpdateExpression()->Argument()->IsMemberExpression()) { - return ConvertTupleUpdate(checker, ast->AsUpdateExpression()); - } + // Check if node is an 'update expression', with a member expression as an argument (potentially tuple) + if (ast->IsUpdateExpression() && ast->AsUpdateExpression()->Argument()->IsMemberExpression()) { + return ConvertTupleUpdate(checker, ast->AsUpdateExpression()); + } - return ast; - }); + return ast; + }, + Name()); return true; } diff --git a/ets2panda/compiler/lowering/ets/unionLowering.cpp b/ets2panda/compiler/lowering/ets/unionLowering.cpp index 114beb8e79f9f2070c52e8c1b250ebd18b7c53d8..e0152017b78e7649945d4b27f2e47814602e7ead 100644 --- a/ets2panda/compiler/lowering/ets/unionLowering.cpp +++ b/ets2panda/compiler/lowering/ets/unionLowering.cpp @@ -176,25 +176,27 @@ bool UnionLowering::Perform(public_lib::Context *ctx, parser::Program *program) checker::ETSChecker *checker = ctx->checker->AsETSChecker(); - program->Ast()->TransformChildrenRecursively([checker](ir::AstNode *ast) -> ir::AstNode * { - if (ast->IsMemberExpression() && ast->AsMemberExpression()->Object()->TsType() != nullptr) { - auto *objType = - checker->GetApparentType(checker->GetNonNullishType(ast->AsMemberExpression()->Object()->TsType())); - if (objType->IsETSUnionType()) { - HandleUnionPropertyAccess(checker, checker->VarBinder(), ast->AsMemberExpression()); - return ast; + program->Ast()->TransformChildrenRecursively( + [checker](ir::AstNode *ast) -> ir::AstNode * { + if (ast->IsMemberExpression() && ast->AsMemberExpression()->Object()->TsType() != nullptr) { + auto *objType = + checker->GetApparentType(checker->GetNonNullishType(ast->AsMemberExpression()->Object()->TsType())); + if (objType->IsETSUnionType()) { + HandleUnionPropertyAccess(checker, checker->VarBinder(), ast->AsMemberExpression()); + return ast; + } } - } - if (ast->IsTSAsExpression() && ast->AsTSAsExpression()->Expr()->TsType() != nullptr && - ast->AsTSAsExpression()->Expr()->TsType()->IsETSUnionType() && - ast->AsTSAsExpression()->TsType() != nullptr && - ast->AsTSAsExpression()->TsType()->HasTypeFlag(checker::TypeFlag::ETS_PRIMITIVE)) { - return HandleUnionCastToPrimitive(checker, ast->AsTSAsExpression()); - } + if (ast->IsTSAsExpression() && ast->AsTSAsExpression()->Expr()->TsType() != nullptr && + ast->AsTSAsExpression()->Expr()->TsType()->IsETSUnionType() && + ast->AsTSAsExpression()->TsType() != nullptr && + ast->AsTSAsExpression()->TsType()->HasTypeFlag(checker::TypeFlag::ETS_PRIMITIVE)) { + return HandleUnionCastToPrimitive(checker, ast->AsTSAsExpression()); + } - return ast; - }); + return ast; + }, + Name()); return true; } diff --git a/ets2panda/compiler/lowering/scopesInit/scopesInitPhase.cpp b/ets2panda/compiler/lowering/scopesInit/scopesInitPhase.cpp index 17755b07e531b2b77282cc1cfebfb90aad99a790..be8ee46864b0d84b8e0de04178de45fa8fd89f95 100644 --- a/ets2panda/compiler/lowering/scopesInit/scopesInitPhase.cpp +++ b/ets2panda/compiler/lowering/scopesInit/scopesInitPhase.cpp @@ -880,10 +880,8 @@ void InitScopesPhaseETS::VisitETSNewClassInstanceExpression(ir::ETSNewClassInsta parentClassScope = parentClassScope->Parent(); } auto classCtx = varbinder::LexicalScope(VarBinder()); - auto *classScope = classCtx.GetScope(); util::UString anonymousName(util::StringView("#"), Allocator()); anonymousName.Append(std::to_string(parentClassScope->AsClassScope()->GetAndIncrementAnonymousClassIdx())); - BindScopeNode(classScope, classDef); classDef->SetInternalName(anonymousName.View()); classDef->Ident()->SetName(anonymousName.View()); classDef->Ident()->SetReference(); diff --git a/ets2panda/ir/as/namedType.cpp b/ets2panda/ir/as/namedType.cpp index b88bd4d0e040fc6c068d479b90196d00cfe6f385..81fd12ddd8d8e0d4a4e45fd790330084fee70975 100644 --- a/ets2panda/ir/as/namedType.cpp +++ b/ets2panda/ir/as/namedType.cpp @@ -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 @@ -24,16 +24,25 @@ #include "ir/srcDump.h" namespace ark::es2panda::ir { -void NamedType::TransformChildren(const NodeTransformer &cb) +void NamedType::TransformChildren(const NodeTransformer &cb, std::string_view const transformationName) { - name_ = cb(name_)->AsIdentifier(); + if (auto *transformedNode = cb(name_); name_ != transformedNode) { + name_->SetTransformedNode(transformationName, transformedNode); + name_ = transformedNode->AsIdentifier(); + } if (typeParams_ != nullptr) { - typeParams_ = cb(typeParams_)->AsTSTypeParameterInstantiation(); + if (auto *transformedNode = cb(typeParams_); typeParams_ != transformedNode) { + typeParams_->SetTransformedNode(transformationName, transformedNode); + typeParams_ = transformedNode->AsTSTypeParameterInstantiation(); + } } if (next_ != nullptr) { - next_ = cb(next_)->AsNamedType(); + if (auto *transformedNode = cb(next_); next_ != transformedNode) { + next_->SetTransformedNode(transformationName, transformedNode); + next_ = transformedNode->AsNamedType(); + } } } diff --git a/ets2panda/ir/as/namedType.h b/ets2panda/ir/as/namedType.h index b1d4c5386be89890bc4c1f772d58922737556368..c646c623fb41e8c8005b4eebf5ce7ebbf1632cc9 100644 --- a/ets2panda/ir/as/namedType.h +++ b/ets2panda/ir/as/namedType.h @@ -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 @@ -56,7 +56,7 @@ public: typeParams_ = typeParams; } - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/as/prefixAssertionExpression.cpp b/ets2panda/ir/as/prefixAssertionExpression.cpp index 3fdd301bcd7e6a1b2f2254667ec3dd2ad6aa3bb7..0a4100a80965d202de3e9d173bf4b3cd32ff620c 100644 --- a/ets2panda/ir/as/prefixAssertionExpression.cpp +++ b/ets2panda/ir/as/prefixAssertionExpression.cpp @@ -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 @@ -23,10 +23,17 @@ #include "ir/typeNode.h" namespace ark::es2panda::ir { -void PrefixAssertionExpression::TransformChildren(const NodeTransformer &cb) +void PrefixAssertionExpression::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { - type_ = static_cast(cb(type_)); - expr_ = cb(expr_)->AsExpression(); + if (auto *transformedNode = cb(type_); type_ != transformedNode) { + type_->SetTransformedNode(transformationName, transformedNode); + type_ = static_cast(transformedNode); + } + + if (auto *transformedNode = cb(expr_); expr_ != transformedNode) { + expr_->SetTransformedNode(transformationName, transformedNode); + expr_ = transformedNode->AsExpression(); + } } void PrefixAssertionExpression::Iterate(const NodeTraverser &cb) const diff --git a/ets2panda/ir/as/prefixAssertionExpression.h b/ets2panda/ir/as/prefixAssertionExpression.h index 6ccaaf28f633cc65cb6abb8f2a4360a9b03ccab4..b06eded0d06b1d5df1c1ff3dd46f390677d101ef 100644 --- a/ets2panda/ir/as/prefixAssertionExpression.h +++ b/ets2panda/ir/as/prefixAssertionExpression.h @@ -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 @@ -36,7 +36,7 @@ public: return type_; } - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/astNode.cpp b/ets2panda/ir/astNode.cpp index 1709ed2fc30272929cce089fc4e7c7fb2dfcc5ea..a17cc9d0fd40cbbdff1bdccfa138e1de09b65ff8 100644 --- a/ets2panda/ir/astNode.cpp +++ b/ets2panda/ir/astNode.cpp @@ -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 @@ -16,7 +16,6 @@ #include "astNode.h" #include "ir/astDump.h" #include "ir/srcDump.h" -#include "typeNode.h" namespace ark::es2panda::ir { @@ -53,12 +52,14 @@ const ir::BlockStatement *AstNode::GetTopStatement() const return GetTopStatementImpl(this); } -void AstNode::TransformChildrenRecursively(const NodeTransformer &cb) +void AstNode::TransformChildrenRecursively(const NodeTransformer &cb, std::string_view transformationName) { - TransformChildren([=](AstNode *child) { - child->TransformChildrenRecursively(cb); - return cb(child); - }); + TransformChildren( + [=](AstNode *child) { + child->TransformChildrenRecursively(cb, transformationName); + return cb(child); + }, + transformationName); } void AstNode::IterateRecursively(const NodeTraverser &cb) const @@ -122,4 +123,17 @@ std::string AstNode::DumpEtsSrc() const ir::SrcDumper dumper {this}; return dumper.Str(); } + +void AstNode::SetOriginalNode(AstNode *originalNode) +{ + ASSERT(originalNode_ == nullptr); + originalNode_ = originalNode; +} + +void AstNode::SetTransformedNode(std::string_view const transformationName, AstNode *transformedNode) +{ + ASSERT(!transformedNode_.has_value()); + transformedNode->SetOriginalNode(this); + transformedNode_ = std::make_optional(std::make_pair(transformationName, transformedNode)); +} } // namespace ark::es2panda::ir diff --git a/ets2panda/ir/astNode.h b/ets2panda/ir/astNode.h index 2262ce13c0ca61462ad9316f23ddfd5ef82700fc..3f6537ca5c49ecb6590f82fd83bb9880280ee1c8 100644 --- a/ets2panda/ir/astNode.h +++ b/ets2panda/ir/astNode.h @@ -257,7 +257,7 @@ public: return variable_; } - void SetVariable(varbinder::Variable *const variable) noexcept + void SetVariable(varbinder::Variable *variable) noexcept { variable_ = variable; } @@ -463,12 +463,12 @@ public: return reinterpret_cast(this); } - [[nodiscard]] virtual bool IsScopeBearer() const + [[nodiscard]] virtual bool IsScopeBearer() const noexcept { return false; } - virtual varbinder::Scope *Scope() const + [[nodiscard]] virtual varbinder::Scope *Scope() const noexcept { UNREACHABLE(); } @@ -482,9 +482,9 @@ public: UNREACHABLE(); } - virtual void TransformChildren(const NodeTransformer &cb) = 0; + virtual void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) = 0; virtual void Iterate(const NodeTraverser &cb) const = 0; - void TransformChildrenRecursively(const NodeTransformer &cb); + void TransformChildrenRecursively(const NodeTransformer &cb, std::string_view transformationName); void IterateRecursively(const NodeTraverser &cb) const; bool IsAnyChild(const NodePredicate &cb) const; AstNode *FindChild(const NodePredicate &cb) const; @@ -499,6 +499,8 @@ public: virtual checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) = 0; virtual checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) = 0; + void SetTransformedNode(std::string_view transformationName, AstNode *transformedNode); + using ASTVisitorT = visitor::ASTAbstractVisitor; virtual void Accept(ASTVisitorT *v) = 0; @@ -521,11 +523,18 @@ protected: AstNode *parent_ {}; lexer::SourceRange range_ {}; AstNodeType type_; - varbinder::Variable *variable_ {}; ModifierFlags flags_ {}; mutable AstNodeFlags astNodeFlags_ {}; mutable BoxingUnboxingFlags boxingUnboxingFlags_ {}; // NOLINTEND(misc-non-private-member-variables-in-classes) + +private: + varbinder::Variable *variable_ {}; + AstNode *originalNode_ = nullptr; + // {lowering_phase_name, new_generated_node} + std::optional> transformedNode_ = std::nullopt; + + void SetOriginalNode(AstNode *originalNode); }; template diff --git a/ets2panda/ir/base/catchClause.cpp b/ets2panda/ir/base/catchClause.cpp index 4c982f9249721ce12d4abcc942efd60275d45e86..08267ade0438e9444c8231bd9785af36ed8ff43e 100644 --- a/ets2panda/ir/base/catchClause.cpp +++ b/ets2panda/ir/base/catchClause.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 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 @@ -24,13 +24,19 @@ #include "ir/statements/blockStatement.h" namespace ark::es2panda::ir { -void CatchClause::TransformChildren(const NodeTransformer &cb) +void CatchClause::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { if (param_ != nullptr) { - param_ = cb(param_)->AsExpression(); + if (auto *transformedNode = cb(param_); param_ != transformedNode) { + param_->SetTransformedNode(transformationName, transformedNode); + param_ = transformedNode->AsExpression(); + } } - body_ = cb(body_)->AsBlockStatement(); + if (auto *transformedNode = cb(body_); body_ != transformedNode) { + body_->SetTransformedNode(transformationName, transformedNode); + body_ = transformedNode->AsBlockStatement(); + } } void CatchClause::Iterate(const NodeTraverser &cb) const diff --git a/ets2panda/ir/base/catchClause.h b/ets2panda/ir/base/catchClause.h index ded5f3545c0f08d02dceaf2b609c9e3c345fdf4b..69b7561b26116df248ee4709945509d2e639d0cc 100644 --- a/ets2panda/ir/base/catchClause.h +++ b/ets2panda/ir/base/catchClause.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 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 @@ -50,23 +50,24 @@ public: return body_; } - bool IsScopeBearer() const override + [[nodiscard]] bool IsScopeBearer() const noexcept override { return true; } - varbinder::CatchScope *Scope() const override + [[nodiscard]] varbinder::CatchScope *Scope() const noexcept override { return scope_; } void SetScope(varbinder::CatchScope *scope) { + ASSERT(scope_ == nullptr); scope_ = scope; } bool IsDefaultCatchClause() const; - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/base/classDefinition.cpp b/ets2panda/ir/base/classDefinition.cpp index ff13e4cb4252c545beb04779a8b5851ab7cda057..49f04411f447a9fa1de76454f3a695560b7bf60e 100644 --- a/ets2panda/ir/base/classDefinition.cpp +++ b/ets2panda/ir/base/classDefinition.cpp @@ -55,34 +55,55 @@ bool ClassDefinition::HasMatchingPrivateKey(const util::StringView &name) const }); } -void ClassDefinition::TransformChildren(const NodeTransformer &cb) +void ClassDefinition::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { if (ident_ != nullptr) { - ident_ = cb(ident_)->AsIdentifier(); + if (auto *transformedNode = cb(ident_); ident_ != transformedNode) { + ident_->SetTransformedNode(transformationName, transformedNode); + ident_ = transformedNode->AsIdentifier(); + } } if (typeParams_ != nullptr) { - typeParams_ = cb(typeParams_)->AsTSTypeParameterDeclaration(); + if (auto *transformedNode = cb(typeParams_); typeParams_ != transformedNode) { + typeParams_->SetTransformedNode(transformationName, transformedNode); + typeParams_ = transformedNode->AsTSTypeParameterDeclaration(); + } } if (superClass_ != nullptr) { - superClass_ = cb(superClass_)->AsExpression(); + if (auto *transformedNode = cb(superClass_); superClass_ != transformedNode) { + superClass_->SetTransformedNode(transformationName, transformedNode); + superClass_ = transformedNode->AsExpression(); + } } if (superTypeParams_ != nullptr) { - superTypeParams_ = cb(superTypeParams_)->AsTSTypeParameterInstantiation(); + if (auto *transformedNode = cb(superTypeParams_); superTypeParams_ != transformedNode) { + superTypeParams_->SetTransformedNode(transformationName, transformedNode); + superTypeParams_ = transformedNode->AsTSTypeParameterInstantiation(); + } } for (auto *&it : implements_) { - it = cb(it)->AsTSClassImplements(); + if (auto *transformedNode = cb(it); it != transformedNode) { + it->SetTransformedNode(transformationName, transformedNode); + it = transformedNode->AsTSClassImplements(); + } } if (ctor_ != nullptr) { - ctor_ = cb(ctor_)->AsMethodDefinition(); + if (auto *transformedNode = cb(ctor_); ctor_ != transformedNode) { + ctor_->SetTransformedNode(transformationName, transformedNode); + ctor_ = transformedNode->AsMethodDefinition(); + } } for (auto *&it : body_) { - it = cb(it); + if (auto *transformedNode = cb(it); it != transformedNode) { + it->SetTransformedNode(transformationName, transformedNode); + it = transformedNode; + } } } diff --git a/ets2panda/ir/base/classDefinition.h b/ets2panda/ir/base/classDefinition.h index 8e8e391569d8a3d9332f2e3e3e84b2a97773d960..6a0f7816d8249dbc876a45b818ecc498b93a185f 100644 --- a/ets2panda/ir/base/classDefinition.h +++ b/ets2panda/ir/base/classDefinition.h @@ -114,18 +114,19 @@ public: { } - bool IsScopeBearer() const override + [[nodiscard]] bool IsScopeBearer() const noexcept override { return true; } - varbinder::LocalScope *Scope() const override + [[nodiscard]] varbinder::LocalScope *Scope() const noexcept override { return scope_; } void SetScope(varbinder::LocalScope *scope) { + ASSERT(scope_ == nullptr); scope_ = scope; } @@ -342,7 +343,7 @@ public: bool HasComputedInstanceField() const; bool HasMatchingPrivateKey(const util::StringView &name) const; - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; diff --git a/ets2panda/ir/base/classProperty.cpp b/ets2panda/ir/base/classProperty.cpp index 860ced757e6df039a757ea0266aeee51f8396384..7a07160d7b9125d8f7f12ac3ae74529346f9d1e1 100644 --- a/ets2panda/ir/base/classProperty.cpp +++ b/ets2panda/ir/base/classProperty.cpp @@ -23,20 +23,32 @@ #include "ir/srcDump.h" namespace ark::es2panda::ir { -void ClassProperty::TransformChildren(const NodeTransformer &cb) +void ClassProperty::TransformChildren(const NodeTransformer &cb, std::string_view const transformationName) { - key_ = cb(key_)->AsExpression(); + if (auto *transformedNode = cb(key_); key_ != transformedNode) { + key_->SetTransformedNode(transformationName, transformedNode); + key_ = transformedNode->AsExpression(); + } if (value_ != nullptr) { - value_ = cb(value_)->AsExpression(); + if (auto *transformedNode = cb(value_); value_ != transformedNode) { + value_->SetTransformedNode(transformationName, transformedNode); + value_ = transformedNode->AsExpression(); + } } if (typeAnnotation_ != nullptr) { - typeAnnotation_ = static_cast(cb(typeAnnotation_)); + if (auto *transformedNode = cb(typeAnnotation_); typeAnnotation_ != transformedNode) { + typeAnnotation_->SetTransformedNode(transformationName, transformedNode); + typeAnnotation_ = static_cast(transformedNode); + } } for (auto *&it : decorators_) { - it = cb(it)->AsDecorator(); + if (auto *transformedNode = cb(it); it != transformedNode) { + it->SetTransformedNode(transformationName, transformedNode); + it = transformedNode->AsDecorator(); + } } } diff --git a/ets2panda/ir/base/classProperty.h b/ets2panda/ir/base/classProperty.h index 5ac78b991bbdffa053a5d426b9ad96bf8244a0cd..b9bb0adad54d65bca1b282ae704406822e847b34 100644 --- a/ets2panda/ir/base/classProperty.h +++ b/ets2panda/ir/base/classProperty.h @@ -58,7 +58,7 @@ public: [[nodiscard]] ClassProperty *Clone(ArenaAllocator *allocator, AstNode *parent) override; - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; diff --git a/ets2panda/ir/base/classStaticBlock.cpp b/ets2panda/ir/base/classStaticBlock.cpp index 42221ffcc2d15b896bc4fe28341011e7b2327a94..6602116964915b2f2f338c77d1e8bd561bda1271 100644 --- a/ets2panda/ir/base/classStaticBlock.cpp +++ b/ets2panda/ir/base/classStaticBlock.cpp @@ -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 @@ -15,7 +15,6 @@ #include "classStaticBlock.h" -#include "varbinder/scope.h" #include "checker/ETSchecker.h" #include "checker/TSchecker.h" #include "compiler/core/ETSGen.h" @@ -28,13 +27,13 @@ #include "ir/expressions/identifier.h" #include "ir/expressions/functionExpression.h" -#include -#include - namespace ark::es2panda::ir { -void ClassStaticBlock::TransformChildren(const NodeTransformer &cb) +void ClassStaticBlock::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { - value_ = cb(value_)->AsExpression(); + if (auto *transformedNode = cb(value_); value_ != transformedNode) { + value_->SetTransformedNode(transformationName, transformedNode); + value_ = transformedNode->AsExpression(); + } } void ClassStaticBlock::Iterate(const NodeTraverser &cb) const diff --git a/ets2panda/ir/base/classStaticBlock.h b/ets2panda/ir/base/classStaticBlock.h index 00c7e72b50436f0df8be95f52be56ababed42325..edf701e2c8a8b430eb3b6b241188803d35e03573 100644 --- a/ets2panda/ir/base/classStaticBlock.h +++ b/ets2panda/ir/base/classStaticBlock.h @@ -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,7 +37,7 @@ public: const ir::ScriptFunction *Function() const; const util::StringView &Name() const; - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/base/decorator.cpp b/ets2panda/ir/base/decorator.cpp index 7702bb16348a23f945c43994087cb137a5440936..231a3035462d108f41664a8fa0f21aad15503cc1 100644 --- a/ets2panda/ir/base/decorator.cpp +++ b/ets2panda/ir/base/decorator.cpp @@ -25,9 +25,12 @@ #include "compiler/core/pandagen.h" namespace ark::es2panda::ir { -void Decorator::TransformChildren(const NodeTransformer &cb) +void Decorator::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { - expr_ = cb(expr_)->AsExpression(); + if (auto *transformedNode = cb(expr_); expr_ != transformedNode) { + expr_->SetTransformedNode(transformationName, transformedNode); + expr_ = transformedNode->AsExpression(); + } } void Decorator::Iterate(const NodeTraverser &cb) const diff --git a/ets2panda/ir/base/decorator.h b/ets2panda/ir/base/decorator.h index 2ec941e4bb02a509b8926f62bfbf4f3143c19ac9..d2fd5c8df757bfcb45b635a6d07d131acef78705 100644 --- a/ets2panda/ir/base/decorator.h +++ b/ets2panda/ir/base/decorator.h @@ -38,7 +38,7 @@ public: [[nodiscard]] Decorator *Clone(ArenaAllocator *allocator, AstNode *parent) override; - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/base/metaProperty.cpp b/ets2panda/ir/base/metaProperty.cpp index a0fb8c0b1949a826ac6ab2abcc5e1211e4fa61cd..e5a988229202f77d22df253b44861fa3b59d6e36 100644 --- a/ets2panda/ir/base/metaProperty.cpp +++ b/ets2panda/ir/base/metaProperty.cpp @@ -22,7 +22,11 @@ #include "ir/srcDump.h" namespace ark::es2panda::ir { -void MetaProperty::TransformChildren([[maybe_unused]] const NodeTransformer &cb) {} +void MetaProperty::TransformChildren([[maybe_unused]] const NodeTransformer &cb, + [[maybe_unused]] std::string_view const transformationName) +{ +} + void MetaProperty::Iterate([[maybe_unused]] const NodeTraverser &cb) const {} void MetaProperty::Dump(ir::AstDumper *dumper) const diff --git a/ets2panda/ir/base/metaProperty.h b/ets2panda/ir/base/metaProperty.h index f36a894431ffcd4a42fe7376361db725f6ff68ef..1a48f79dd4218605bf5a68f01ff3662d17969e22 100644 --- a/ets2panda/ir/base/metaProperty.h +++ b/ets2panda/ir/base/metaProperty.h @@ -41,7 +41,7 @@ public: return kind_; } - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; [[nodiscard]] MetaProperty *Clone(ArenaAllocator *allocator, AstNode *parent) override; diff --git a/ets2panda/ir/base/methodDefinition.cpp b/ets2panda/ir/base/methodDefinition.cpp index 8dc4d303c8d4e360f903896ef3bc31e038770c50..eaee6ad174666e2d753bf79ef1ddbc0a3f0d9c5f 100644 --- a/ets2panda/ir/base/methodDefinition.cpp +++ b/ets2panda/ir/base/methodDefinition.cpp @@ -81,17 +81,30 @@ void MethodDefinition::Iterate(const NodeTraverser &cb) const } } -void MethodDefinition::TransformChildren(const NodeTransformer &cb) +void MethodDefinition::TransformChildren(const NodeTransformer &cb, std::string_view const transformationName) { - key_ = cb(key_)->AsExpression(); - value_ = cb(value_)->AsExpression(); + if (auto *transformedNode = cb(key_); key_ != transformedNode) { + key_->SetTransformedNode(transformationName, transformedNode); + key_ = transformedNode->AsExpression(); + } + + if (auto *transformedNode = cb(value_); value_ != transformedNode) { + value_->SetTransformedNode(transformationName, transformedNode); + value_ = transformedNode->AsExpression(); + } for (auto *&it : overloads_) { - it = cb(it)->AsMethodDefinition(); + if (auto *transformedNode = cb(it); it != transformedNode) { + it->SetTransformedNode(transformationName, transformedNode); + it = transformedNode->AsMethodDefinition(); + } } for (auto *&it : decorators_) { - it = cb(it)->AsDecorator(); + if (auto *transformedNode = cb(it); it != transformedNode) { + it->SetTransformedNode(transformationName, transformedNode); + it = transformedNode->AsDecorator(); + } } } diff --git a/ets2panda/ir/base/methodDefinition.h b/ets2panda/ir/base/methodDefinition.h index a813097a6325faa7cf0c61e11f1685541b0ab74f..553cc44d1887add24dd2ae4a7b8967266017cab7 100644 --- a/ets2panda/ir/base/methodDefinition.h +++ b/ets2panda/ir/base/methodDefinition.h @@ -97,7 +97,7 @@ public: [[nodiscard]] MethodDefinition *Clone(ArenaAllocator *allocator, AstNode *parent) override; - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void ResolveReferences(const NodeTraverser &cb) const; diff --git a/ets2panda/ir/base/property.cpp b/ets2panda/ir/base/property.cpp index b46ceb41ca445b4d64e0e6c659a9f870e9d79af5..f0b73bf0025f86f947c36f2ef7387d1352650c78 100644 --- a/ets2panda/ir/base/property.cpp +++ b/ets2panda/ir/base/property.cpp @@ -121,10 +121,17 @@ ValidationInfo Property::ValidateExpression() return info; } -void Property::TransformChildren(const NodeTransformer &cb) +void Property::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { - key_ = cb(key_)->AsExpression(); - value_ = cb(value_)->AsExpression(); + if (auto *transformedNode = cb(key_); key_ != transformedNode) { + key_->SetTransformedNode(transformationName, transformedNode); + key_ = transformedNode->AsExpression(); + } + + if (auto *transformedNode = cb(value_); value_ != transformedNode) { + value_->SetTransformedNode(transformationName, transformedNode); + value_ = transformedNode->AsExpression(); + } } void Property::Iterate(const NodeTraverser &cb) const diff --git a/ets2panda/ir/base/property.h b/ets2panda/ir/base/property.h index baa35fed411491dfbc1698ebc0a37559ac95cba9..36997c8186f9be5697d9f614dd2586578440d7f1 100644 --- a/ets2panda/ir/base/property.h +++ b/ets2panda/ir/base/property.h @@ -107,7 +107,7 @@ public: bool ConvertibleToPatternProperty(); ValidationInfo ValidateExpression(); - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/base/scriptFunction.cpp b/ets2panda/ir/base/scriptFunction.cpp index ee693836604b71b63f2fbbd1d1b86d9fdf1d0d10..1072d429ac77f39544e98aa6c729dfe9067d08c5 100644 --- a/ets2panda/ir/base/scriptFunction.cpp +++ b/ets2panda/ir/base/scriptFunction.cpp @@ -66,14 +66,22 @@ void ScriptFunction::SetIdent(Identifier *id) noexcept id_->SetParent(this); } -void ScriptFunction::TransformChildren(const NodeTransformer &cb) +void ScriptFunction::TransformChildren(const NodeTransformer &cb, std::string_view const transformationName) { if (id_ != nullptr) { - id_ = cb(id_)->AsIdentifier(); + if (auto *transformedNode = cb(id_); id_ != transformedNode) { + id_->SetTransformedNode(transformationName, transformedNode); + id_ = transformedNode->AsIdentifier(); + } } - irSignature_.TransformChildren(cb); + + irSignature_.TransformChildren(cb, transformationName); + if (body_ != nullptr) { - body_ = cb(body_); + if (auto *transformedNode = cb(body_); body_ != transformedNode) { + body_->SetTransformedNode(transformationName, transformedNode); + body_ = transformedNode; + } } } diff --git a/ets2panda/ir/base/scriptFunction.h b/ets2panda/ir/base/scriptFunction.h index 82355f42da3e83432df440259f3851cdf004f8fb..2ca76dd1079a763757b6c1526810994145ff26ae 100644 --- a/ets2panda/ir/base/scriptFunction.h +++ b/ets2panda/ir/base/scriptFunction.h @@ -263,27 +263,27 @@ public: [[nodiscard]] std::size_t FormalParamsLength() const noexcept; - bool IsScopeBearer() const override + [[nodiscard]] bool IsScopeBearer() const noexcept override { return true; } - varbinder::FunctionScope *Scope() const override + [[nodiscard]] varbinder::FunctionScope *Scope() const noexcept override { return scope_; } - void SetScope(varbinder::FunctionScope *scope) + void SetScope(varbinder::FunctionScope *scope) noexcept { scope_ = scope; } - [[nodiscard]] es2panda::Language Language() const + [[nodiscard]] es2panda::Language Language() const noexcept { return lang_; } - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; diff --git a/ets2panda/ir/base/scriptFunctionSignature.cpp b/ets2panda/ir/base/scriptFunctionSignature.cpp index 548c1f35a6468a78bce3a95cec1538042b9d5d2b..4b4214c1db9728f6667c64c10083b40dbe9f6d73 100644 --- a/ets2panda/ir/base/scriptFunctionSignature.cpp +++ b/ets2panda/ir/base/scriptFunctionSignature.cpp @@ -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 @@ -34,18 +34,27 @@ void FunctionSignature::Iterate(const NodeTraverser &cb) const } } -void FunctionSignature::TransformChildren(const NodeTransformer &cb) +void FunctionSignature::TransformChildren(const NodeTransformer &cb, std::string_view const transformationName) { if (typeParams_ != nullptr) { - typeParams_ = cb(typeParams_)->AsTSTypeParameterDeclaration(); + if (auto *transformedNode = cb(typeParams_); typeParams_ != transformedNode) { + typeParams_->SetTransformedNode(transformationName, transformedNode); + typeParams_ = transformedNode->AsTSTypeParameterDeclaration(); + } } for (auto *&it : params_) { - it = cb(it)->AsExpression(); + if (auto *transformedNode = cb(it); it != transformedNode) { + it->SetTransformedNode(transformationName, transformedNode); + it = transformedNode->AsExpression(); + } } if (returnTypeAnnotation_ != nullptr) { - returnTypeAnnotation_ = static_cast(cb(returnTypeAnnotation_)); + if (auto *transformedNode = cb(returnTypeAnnotation_); returnTypeAnnotation_ != transformedNode) { + returnTypeAnnotation_->SetTransformedNode(transformationName, transformedNode); + returnTypeAnnotation_ = static_cast(transformedNode); + } } } } // namespace ark::es2panda::ir diff --git a/ets2panda/ir/base/scriptFunctionSignature.h b/ets2panda/ir/base/scriptFunctionSignature.h index 72ced7dc6f2eec6d30afcca7b0a048601531d9f7..5236874645142df51a22101222900704d17fa1b9 100644 --- a/ets2panda/ir/base/scriptFunctionSignature.h +++ b/ets2panda/ir/base/scriptFunctionSignature.h @@ -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 @@ -68,7 +68,7 @@ public: void Iterate(const NodeTraverser &cb) const; - void TransformChildren(const NodeTransformer &cb); + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName); private: TSTypeParameterDeclaration *typeParams_; diff --git a/ets2panda/ir/base/spreadElement.cpp b/ets2panda/ir/base/spreadElement.cpp index a47f51d5277c22196bc32ca46d0bf463877d766c..dddb1f6c57fbfb713a6b0b3ef00959a1aef153e0 100644 --- a/ets2panda/ir/base/spreadElement.cpp +++ b/ets2panda/ir/base/spreadElement.cpp @@ -106,16 +106,25 @@ bool SpreadElement::ConvertibleToRest(bool isDeclaration, bool allowPattern) return convResult; } -void SpreadElement::TransformChildren(const NodeTransformer &cb) +void SpreadElement::TransformChildren(const NodeTransformer &cb, std::string_view const transformationName) { for (auto *&it : decorators_) { - it = cb(it)->AsDecorator(); + if (auto *transformedNode = cb(it); it != transformedNode) { + it->SetTransformedNode(transformationName, transformedNode); + it = transformedNode->AsDecorator(); + } } - argument_ = cb(argument_)->AsExpression(); + if (auto *transformedNode = cb(argument_); argument_ != transformedNode) { + argument_->SetTransformedNode(transformationName, transformedNode); + argument_ = transformedNode->AsExpression(); + } - if (TypeAnnotation() != nullptr) { - SetTsTypeAnnotation(static_cast(cb(TypeAnnotation()))); + if (auto *const typeAnnotation = TypeAnnotation(); typeAnnotation != nullptr) { + if (auto *transformedNode = cb(typeAnnotation); typeAnnotation != transformedNode) { + typeAnnotation->SetTransformedNode(transformationName, transformedNode); + SetTsTypeAnnotation(static_cast(transformedNode)); + } } } diff --git a/ets2panda/ir/base/spreadElement.h b/ets2panda/ir/base/spreadElement.h index 1f135e637dfee30a06217cf477c75fb08b732fef..3d317fe5683a123668cdc9b3f547f5af3217ac2d 100644 --- a/ets2panda/ir/base/spreadElement.h +++ b/ets2panda/ir/base/spreadElement.h @@ -83,7 +83,7 @@ public: ValidationInfo ValidateExpression(); [[nodiscard]] bool ConvertibleToRest(bool isDeclaration, bool allowPattern = true); - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/base/templateElement.cpp b/ets2panda/ir/base/templateElement.cpp index 3699f71c8f4d82baf9b244e9d56dab776a6bf4ef..7c50515220bb5b184436d4c040396378cc2cd5da 100644 --- a/ets2panda/ir/base/templateElement.cpp +++ b/ets2panda/ir/base/templateElement.cpp @@ -22,7 +22,11 @@ #include "ir/srcDump.h" namespace ark::es2panda::ir { -void TemplateElement::TransformChildren([[maybe_unused]] const NodeTransformer &cb) {} +void TemplateElement::TransformChildren([[maybe_unused]] const NodeTransformer &cb, + [[maybe_unused]] std::string_view const transformationName) +{ +} + void TemplateElement::Iterate([[maybe_unused]] const NodeTraverser &cb) const {} void TemplateElement::Dump(ir::AstDumper *dumper) const diff --git a/ets2panda/ir/base/templateElement.h b/ets2panda/ir/base/templateElement.h index 716b8f96d34e670e46b5801bfad13e1bceb54720..fb4cf79085c24c338854fd7f75091460cd9c9260 100644 --- a/ets2panda/ir/base/templateElement.h +++ b/ets2panda/ir/base/templateElement.h @@ -46,7 +46,7 @@ public: [[nodiscard]] TemplateElement *Clone(ArenaAllocator *allocator, AstNode *parent) override; - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/base/tsIndexSignature.cpp b/ets2panda/ir/base/tsIndexSignature.cpp index fb899cd423fac46878d5f9c2f6595ff8ea53e749..9490e09a5dbd83f0eb28c566ad5e96e794108978 100644 --- a/ets2panda/ir/base/tsIndexSignature.cpp +++ b/ets2panda/ir/base/tsIndexSignature.cpp @@ -27,10 +27,17 @@ TSIndexSignature::TSIndexSignatureKind TSIndexSignature::Kind() const noexcept : TSIndexSignatureKind::STRING; } -void TSIndexSignature::TransformChildren(const NodeTransformer &cb) +void TSIndexSignature::TransformChildren(const NodeTransformer &cb, std::string_view const transformationName) { - param_ = cb(param_)->AsExpression(); - typeAnnotation_ = static_cast(cb(typeAnnotation_)); + if (auto *transformedNode = cb(param_); param_ != transformedNode) { + param_->SetTransformedNode(transformationName, transformedNode); + param_ = transformedNode->AsExpression(); + } + + if (auto *transformedNode = cb(typeAnnotation_); typeAnnotation_ != transformedNode) { + typeAnnotation_->SetTransformedNode(transformationName, transformedNode); + typeAnnotation_ = static_cast(transformedNode); + } } void TSIndexSignature::Iterate(const NodeTraverser &cb) const diff --git a/ets2panda/ir/base/tsIndexSignature.h b/ets2panda/ir/base/tsIndexSignature.h index 6b82ef1a47f04738a5daecd9edfb6709f62e61d4..7d576e5ca0740df820148b43e8c546f7330d0b5b 100644 --- a/ets2panda/ir/base/tsIndexSignature.h +++ b/ets2panda/ir/base/tsIndexSignature.h @@ -62,7 +62,7 @@ public: [[nodiscard]] TSIndexSignature *Clone(ArenaAllocator *allocator, AstNode *parent) override; - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; diff --git a/ets2panda/ir/base/tsMethodSignature.cpp b/ets2panda/ir/base/tsMethodSignature.cpp index b2625f8a4825113b50247dbc66f972d2a0c70201..57a18042103820838e5a2e894cc4a724bf0bf09f 100644 --- a/ets2panda/ir/base/tsMethodSignature.cpp +++ b/ets2panda/ir/base/tsMethodSignature.cpp @@ -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 @@ -16,16 +16,19 @@ #include "tsMethodSignature.h" #include "ir/astDump.h" #include "ir/srcDump.h" -#include "varbinder/scope.h" #include "checker/TSchecker.h" #include "compiler/core/ETSGen.h" #include "compiler/core/pandagen.h" namespace ark::es2panda::ir { -void TSMethodSignature::TransformChildren(const NodeTransformer &cb) +void TSMethodSignature::TransformChildren(const NodeTransformer &cb, std::string_view const transformationName) { - key_ = cb(key_)->AsExpression(); - signature_.TransformChildren(cb); + if (auto *transformedNode = cb(key_); key_ != transformedNode) { + key_->SetTransformedNode(transformationName, transformedNode); + key_ = transformedNode->AsExpression(); + } + + signature_.TransformChildren(cb, transformationName); } void TSMethodSignature::Iterate(const NodeTraverser &cb) const diff --git a/ets2panda/ir/base/tsMethodSignature.h b/ets2panda/ir/base/tsMethodSignature.h index d16e8fe9a23090633c6641f986c9d543fe5dfc31..293156ad2eb5d921d2bd174124bca1873067fb1c 100644 --- a/ets2panda/ir/base/tsMethodSignature.h +++ b/ets2panda/ir/base/tsMethodSignature.h @@ -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 @@ -47,18 +47,19 @@ public: // NOTE (csabahurton): friend relationship can be removed once there are getters for private fields friend class checker::TSAnalyzer; - bool IsScopeBearer() const override + [[nodiscard]] bool IsScopeBearer() const noexcept override { return true; } - varbinder::Scope *Scope() const override + [[nodiscard]] varbinder::Scope *Scope() const noexcept override { return scope_; } void SetScope(varbinder::Scope *scope) { + ASSERT(scope_ == nullptr); scope_ = scope; } @@ -107,7 +108,7 @@ public: return optional_; } - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; diff --git a/ets2panda/ir/base/tsPropertySignature.cpp b/ets2panda/ir/base/tsPropertySignature.cpp index 4ec1a41ad87bb258d5ac165e1400b037877a74ce..9c621f96513cdeab07b5ec90c1d6fb685473caf4 100644 --- a/ets2panda/ir/base/tsPropertySignature.cpp +++ b/ets2panda/ir/base/tsPropertySignature.cpp @@ -21,12 +21,18 @@ #include "compiler/core/pandagen.h" namespace ark::es2panda::ir { -void TSPropertySignature::TransformChildren(const NodeTransformer &cb) +void TSPropertySignature::TransformChildren(const NodeTransformer &cb, std::string_view const transformationName) { - key_ = cb(key_)->AsExpression(); + if (auto *transformedNode = cb(key_); key_ != transformedNode) { + key_->SetTransformedNode(transformationName, transformedNode); + key_ = transformedNode->AsExpression(); + } - if (TypeAnnotation() != nullptr) { - SetTsTypeAnnotation(static_cast(cb(TypeAnnotation()))); + if (auto *const typeAnnotation = TypeAnnotation(); typeAnnotation != nullptr) { + if (auto *transformedNode = cb(typeAnnotation); typeAnnotation != transformedNode) { + typeAnnotation->SetTransformedNode(transformationName, transformedNode); + SetTsTypeAnnotation(static_cast(transformedNode)); + } } } diff --git a/ets2panda/ir/base/tsPropertySignature.h b/ets2panda/ir/base/tsPropertySignature.h index 8de1dd5bca7701b54e80573be3e11946f1a51969..6c4fdf6a66403ca060eb5c5f049882bd08ea2994 100644 --- a/ets2panda/ir/base/tsPropertySignature.h +++ b/ets2panda/ir/base/tsPropertySignature.h @@ -65,7 +65,7 @@ public: [[nodiscard]] TSPropertySignature *Clone(ArenaAllocator *allocator, AstNode *parent) override; - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; diff --git a/ets2panda/ir/base/tsSignatureDeclaration.cpp b/ets2panda/ir/base/tsSignatureDeclaration.cpp index e4e7461f5d144f0c3fac58bee36add4e66ddba91..4b36c1bb38ae3a4864f55c32a2fd3875550048f1 100644 --- a/ets2panda/ir/base/tsSignatureDeclaration.cpp +++ b/ets2panda/ir/base/tsSignatureDeclaration.cpp @@ -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 @@ -15,7 +15,6 @@ #include "tsSignatureDeclaration.h" -#include "varbinder/scope.h" #include "checker/ETSchecker.h" #include "checker/TSchecker.h" #include "compiler/core/ETSGen.h" @@ -24,9 +23,9 @@ #include "ir/srcDump.h" namespace ark::es2panda::ir { -void TSSignatureDeclaration::TransformChildren(const NodeTransformer &cb) +void TSSignatureDeclaration::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { - signature_.TransformChildren(cb); + signature_.TransformChildren(cb, transformationName); } void TSSignatureDeclaration::Iterate(const NodeTraverser &cb) const diff --git a/ets2panda/ir/base/tsSignatureDeclaration.h b/ets2panda/ir/base/tsSignatureDeclaration.h index 76564731002bd696653d28f566c234b83c00587e..034b9a40d68d9d88226a2b3592b10757e49f283d 100644 --- a/ets2panda/ir/base/tsSignatureDeclaration.h +++ b/ets2panda/ir/base/tsSignatureDeclaration.h @@ -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 @@ -44,18 +44,19 @@ public: // NOTE (csabahurton): friend relationship can be removed once there are getters for private fields friend class checker::TSAnalyzer; - bool IsScopeBearer() const override + [[nodiscard]] bool IsScopeBearer() const noexcept override { return true; } - varbinder::Scope *Scope() const override + [[nodiscard]] varbinder::Scope *Scope() const noexcept override { return scope_; } void SetScope(varbinder::Scope *scope) { + ASSERT(scope_ == nullptr); scope_ = scope; } @@ -89,7 +90,7 @@ public: return kind_; } - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; diff --git a/ets2panda/ir/ets/etsClassLiteral.cpp b/ets2panda/ir/ets/etsClassLiteral.cpp index 7c1bdb16842b9e6b5711bb3cd30e087ad4e7994f..d4597151fb860c57df898c9bf894f6733d68db67 100644 --- a/ets2panda/ir/ets/etsClassLiteral.cpp +++ b/ets2panda/ir/ets/etsClassLiteral.cpp @@ -22,9 +22,12 @@ #include "ir/srcDump.h" namespace ark::es2panda::ir { -void ETSClassLiteral::TransformChildren(const NodeTransformer &cb) +void ETSClassLiteral::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { - expr_ = static_cast(cb(expr_)); + if (auto *transformedNode = cb(expr_); expr_ != transformedNode) { + expr_->SetTransformedNode(transformationName, transformedNode); + expr_ = static_cast(transformedNode); + } } void ETSClassLiteral::Iterate([[maybe_unused]] const NodeTraverser &cb) const diff --git a/ets2panda/ir/ets/etsClassLiteral.h b/ets2panda/ir/ets/etsClassLiteral.h index 056c13ba7d079ded786166e3d11d02895d1b6546..de3806314117330cd238937eab3df014da0462e8 100644 --- a/ets2panda/ir/ets/etsClassLiteral.h +++ b/ets2panda/ir/ets/etsClassLiteral.h @@ -44,7 +44,7 @@ public: friend class checker::ETSAnalyzer; friend class compiler::ETSCompiler; - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/ets/etsFunctionType.cpp b/ets2panda/ir/ets/etsFunctionType.cpp index ad3db61603efee4fcfe814fbb006b0a16f2f2f96..284573ac5a4557dbcf4e18c74191913f203feaf9 100644 --- a/ets2panda/ir/ets/etsFunctionType.cpp +++ b/ets2panda/ir/ets/etsFunctionType.cpp @@ -15,7 +15,6 @@ #include "etsFunctionType.h" -#include "varbinder/scope.h" #include "checker/TSchecker.h" #include "checker/ETSchecker.h" #include "compiler/core/ETSGen.h" @@ -24,9 +23,9 @@ #include "ir/srcDump.h" namespace ark::es2panda::ir { -void ETSFunctionType::TransformChildren(const NodeTransformer &cb) +void ETSFunctionType::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { - signature_.TransformChildren(cb); + signature_.TransformChildren(cb, transformationName); } void ETSFunctionType::Iterate(const NodeTraverser &cb) const diff --git a/ets2panda/ir/ets/etsFunctionType.h b/ets2panda/ir/ets/etsFunctionType.h index 434297ef508dd1646f942a18467472bc9f271e7a..cf1539f8f205753c53fd61a9d2986bd09fd1b71f 100644 --- a/ets2panda/ir/ets/etsFunctionType.h +++ b/ets2panda/ir/ets/etsFunctionType.h @@ -33,18 +33,19 @@ public: { } - bool IsScopeBearer() const override + [[nodiscard]] bool IsScopeBearer() const noexcept override { return true; } - varbinder::Scope *Scope() const override + [[nodiscard]] varbinder::Scope *Scope() const noexcept override { return scope_; } void SetScope(varbinder::Scope *scope) { + ASSERT(scope_ == nullptr); scope_ = scope; } @@ -98,7 +99,7 @@ public: return (funcFlags_ & ir::ScriptFunctionFlags::RETHROWS) != 0; } - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/ets/etsLaunchExpression.cpp b/ets2panda/ir/ets/etsLaunchExpression.cpp index c665c43066a64bf05239a9388aeac147c5fd3cef..dbae6bde93513476498122b28c2331990913c3f7 100644 --- a/ets2panda/ir/ets/etsLaunchExpression.cpp +++ b/ets2panda/ir/ets/etsLaunchExpression.cpp @@ -28,9 +28,12 @@ ETSLaunchExpression::ETSLaunchExpression(CallExpression *expr) { } -void ETSLaunchExpression::TransformChildren(const NodeTransformer &cb) +void ETSLaunchExpression::TransformChildren(const NodeTransformer &cb, std::string_view const transformationName) { - expr_ = cb(expr_)->AsCallExpression(); + if (auto *transformedNode = cb(expr_); expr_ != transformedNode) { + expr_->SetTransformedNode(transformationName, transformedNode); + expr_ = transformedNode->AsCallExpression(); + } } void ETSLaunchExpression::Iterate(const NodeTraverser &cb) const diff --git a/ets2panda/ir/ets/etsLaunchExpression.h b/ets2panda/ir/ets/etsLaunchExpression.h index d9babe97543917d1c7894ce050aae69595d0b586..f69098725232a80b17ba3db57ca7512631ee79c7 100644 --- a/ets2panda/ir/ets/etsLaunchExpression.h +++ b/ets2panda/ir/ets/etsLaunchExpression.h @@ -46,7 +46,7 @@ public: [[nodiscard]] ETSLaunchExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/ets/etsNewArrayInstanceExpression.cpp b/ets2panda/ir/ets/etsNewArrayInstanceExpression.cpp index a8568dbdae8c387253a199175fcb49ecd21a8d88..92ecb42e048f92a1aaf45c6e8be9ccb59cc01ece 100644 --- a/ets2panda/ir/ets/etsNewArrayInstanceExpression.cpp +++ b/ets2panda/ir/ets/etsNewArrayInstanceExpression.cpp @@ -24,10 +24,18 @@ #include "ir/typeNode.h" namespace ark::es2panda::ir { -void ETSNewArrayInstanceExpression::TransformChildren(const NodeTransformer &cb) +void ETSNewArrayInstanceExpression::TransformChildren(const NodeTransformer &cb, + std::string_view const transformationName) { - typeReference_ = static_cast(cb(typeReference_)); - dimension_ = cb(dimension_)->AsExpression(); + if (auto *transformedNode = cb(typeReference_); typeReference_ != transformedNode) { + typeReference_->SetTransformedNode(transformationName, transformedNode); + typeReference_ = static_cast(transformedNode); + } + + if (auto *transformedNode = cb(dimension_); dimension_ != transformedNode) { + dimension_->SetTransformedNode(transformationName, transformedNode); + dimension_ = transformedNode->AsExpression(); + } } void ETSNewArrayInstanceExpression::Iterate(const NodeTraverser &cb) const diff --git a/ets2panda/ir/ets/etsNewArrayInstanceExpression.h b/ets2panda/ir/ets/etsNewArrayInstanceExpression.h index 7a1cbbdda445c5b6453b85485df1c889c52f6458..f7376ee48133a33e73a848b271f75ecad4f847e3 100644 --- a/ets2panda/ir/ets/etsNewArrayInstanceExpression.h +++ b/ets2panda/ir/ets/etsNewArrayInstanceExpression.h @@ -89,7 +89,7 @@ public: [[nodiscard]] ETSNewArrayInstanceExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/ets/etsNewClassInstanceExpression.cpp b/ets2panda/ir/ets/etsNewClassInstanceExpression.cpp index 44871cc065f1fc6c2ad70c67d2e1e69559e63f2c..73df7244d881c890b5ba194c231e6773e071d69e 100644 --- a/ets2panda/ir/ets/etsNewClassInstanceExpression.cpp +++ b/ets2panda/ir/ets/etsNewClassInstanceExpression.cpp @@ -22,16 +22,25 @@ #include "ir/srcDump.h" namespace ark::es2panda::ir { -void ETSNewClassInstanceExpression::TransformChildren(const NodeTransformer &cb) +void ETSNewClassInstanceExpression::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { - typeReference_ = cb(typeReference_)->AsExpression(); + if (auto *transformedNode = cb(typeReference_); typeReference_ != transformedNode) { + typeReference_->SetTransformedNode(transformationName, transformedNode); + typeReference_ = transformedNode->AsExpression(); + } for (auto *&arg : arguments_) { - arg = cb(arg)->AsExpression(); + if (auto *transformedNode = cb(arg); arg != transformedNode) { + arg->SetTransformedNode(transformationName, transformedNode); + arg = transformedNode->AsExpression(); + } } if (classDef_ != nullptr) { - classDef_ = cb(classDef_)->AsClassDefinition(); + if (auto *transformedNode = cb(classDef_); classDef_ != transformedNode) { + classDef_->SetTransformedNode(transformationName, transformedNode); + classDef_ = transformedNode->AsClassDefinition(); + } } } diff --git a/ets2panda/ir/ets/etsNewClassInstanceExpression.h b/ets2panda/ir/ets/etsNewClassInstanceExpression.h index 8a61de62883f778275854fd2af1e22317ca9f7dc..2f1b1cfa60d6ecb038a68cd37fccb86fb5d92dc7 100644 --- a/ets2panda/ir/ets/etsNewClassInstanceExpression.h +++ b/ets2panda/ir/ets/etsNewClassInstanceExpression.h @@ -92,7 +92,7 @@ public: [[nodiscard]] ETSNewClassInstanceExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; diff --git a/ets2panda/ir/ets/etsNewMultiDimArrayInstanceExpression.cpp b/ets2panda/ir/ets/etsNewMultiDimArrayInstanceExpression.cpp index 6692d17bf7a5a9186fd7827cfbdbb41d792c80cb..e321b0f7e64c762f8a1275846aa8c024df47db7d 100644 --- a/ets2panda/ir/ets/etsNewMultiDimArrayInstanceExpression.cpp +++ b/ets2panda/ir/ets/etsNewMultiDimArrayInstanceExpression.cpp @@ -15,7 +15,6 @@ #include "etsNewMultiDimArrayInstanceExpression.h" -#include "varbinder/ETSBinder.h" #include "checker/TSchecker.h" #include "compiler/core/ETSGen.h" #include "compiler/core/pandagen.h" @@ -23,11 +22,19 @@ #include "ir/srcDump.h" namespace ark::es2panda::ir { -void ETSNewMultiDimArrayInstanceExpression::TransformChildren(const NodeTransformer &cb) +void ETSNewMultiDimArrayInstanceExpression::TransformChildren(const NodeTransformer &cb, + std::string_view const transformationName) { - typeReference_ = static_cast(cb(typeReference_)); + if (auto *transformedNode = cb(typeReference_); typeReference_ != transformedNode) { + typeReference_->SetTransformedNode(transformationName, transformedNode); + typeReference_ = static_cast(transformedNode); + } + for (auto *&dim : dimensions_) { - dim = cb(dim)->AsExpression(); + if (auto *transformedNode = cb(dim); dim != transformedNode) { + dim->SetTransformedNode(transformationName, transformedNode); + dim = transformedNode->AsExpression(); + } } } diff --git a/ets2panda/ir/ets/etsNewMultiDimArrayInstanceExpression.h b/ets2panda/ir/ets/etsNewMultiDimArrayInstanceExpression.h index fa5587a8cf740db5ed3c3f0206593749e5b07ae5..2892a7f462578e54a0ef10c42ebeeb2c377b01fd 100644 --- a/ets2panda/ir/ets/etsNewMultiDimArrayInstanceExpression.h +++ b/ets2panda/ir/ets/etsNewMultiDimArrayInstanceExpression.h @@ -85,7 +85,7 @@ public: [[nodiscard]] ETSNewMultiDimArrayInstanceExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; diff --git a/ets2panda/ir/ets/etsNullishTypes.cpp b/ets2panda/ir/ets/etsNullishTypes.cpp index eb7df7a7748902ee725c96dc00bf1d260d96c392..7c1312a423f41e5976d2d9227ba74ee8df0a1c52 100644 --- a/ets2panda/ir/ets/etsNullishTypes.cpp +++ b/ets2panda/ir/ets/etsNullishTypes.cpp @@ -19,7 +19,10 @@ #include "ir/astDump.h" namespace ark::es2panda::ir { -void ETSUndefinedType::TransformChildren([[maybe_unused]] const NodeTransformer &cb) {} +void ETSUndefinedType::TransformChildren([[maybe_unused]] const NodeTransformer &cb, + [[maybe_unused]] std::string_view const transformationName) +{ +} void ETSUndefinedType::Iterate([[maybe_unused]] const NodeTraverser &cb) const {} @@ -65,7 +68,10 @@ ETSUndefinedType *ETSUndefinedType::Clone(ArenaAllocator *allocator, AstNode *pa return nullptr; } -void ETSNullType::TransformChildren([[maybe_unused]] const NodeTransformer &cb) {} +void ETSNullType::TransformChildren([[maybe_unused]] const NodeTransformer &cb, + [[maybe_unused]] std::string_view const transformationName) +{ +} void ETSNullType::Iterate([[maybe_unused]] const NodeTraverser &cb) const {} diff --git a/ets2panda/ir/ets/etsNullishTypes.h b/ets2panda/ir/ets/etsNullishTypes.h index f4ab45ad4094c32179825242109604a74cd858a5..2dec9030c5e886f12a70871f72ce9abbe427dd0b 100644 --- a/ets2panda/ir/ets/etsNullishTypes.h +++ b/ets2panda/ir/ets/etsNullishTypes.h @@ -24,7 +24,7 @@ class ETSNullType : public TypeNode { public: explicit ETSNullType() : TypeNode(AstNodeType::ETS_NULL_TYPE) {} - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; @@ -44,7 +44,7 @@ class ETSUndefinedType : public TypeNode { public: explicit ETSUndefinedType() : TypeNode(AstNodeType::ETS_UNDEFINED_TYPE) {} - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/ets/etsPackageDeclaration.cpp b/ets2panda/ir/ets/etsPackageDeclaration.cpp index 1f1625d73d07ccb506a8ae3b45f851b9c89139d2..7e2a45616eb8d98e6745a6dec6384e3c183eec2f 100644 --- a/ets2panda/ir/ets/etsPackageDeclaration.cpp +++ b/ets2panda/ir/ets/etsPackageDeclaration.cpp @@ -22,9 +22,12 @@ #include "ir/srcDump.h" namespace ark::es2panda::ir { -void ETSPackageDeclaration::TransformChildren(const NodeTransformer &cb) +void ETSPackageDeclaration::TransformChildren(const NodeTransformer &cb, std::string_view const transformationName) { - name_ = cb(name_)->AsExpression(); + if (auto *transformedNode = cb(name_); name_ != transformedNode) { + name_->SetTransformedNode(transformationName, transformedNode); + name_ = transformedNode->AsExpression(); + } } void ETSPackageDeclaration::Iterate([[maybe_unused]] const NodeTraverser &cb) const diff --git a/ets2panda/ir/ets/etsPackageDeclaration.h b/ets2panda/ir/ets/etsPackageDeclaration.h index 4ae8643d291222fd8879ce453939fe06eb3e98b0..6d74cbd698533b1d4667d4e4600d68b5aebb1237 100644 --- a/ets2panda/ir/ets/etsPackageDeclaration.h +++ b/ets2panda/ir/ets/etsPackageDeclaration.h @@ -35,7 +35,7 @@ public: [[nodiscard]] ETSPackageDeclaration *Clone(ArenaAllocator *allocator, AstNode *parent) override; - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; diff --git a/ets2panda/ir/ets/etsParameterExpression.cpp b/ets2panda/ir/ets/etsParameterExpression.cpp index 01e69587e4445a392462ba2436def296f46da9fe..4b15f70473ec16f9418ca5f77d5d922e25412676 100644 --- a/ets2panda/ir/ets/etsParameterExpression.cpp +++ b/ets2panda/ir/ets/etsParameterExpression.cpp @@ -107,17 +107,26 @@ util::StringView ETSParameterExpression::LexerSaved() const noexcept return savedLexer_; } -void ETSParameterExpression::TransformChildren(const NodeTransformer &cb) +void ETSParameterExpression::TransformChildren(const NodeTransformer &cb, std::string_view const transformationName) { if (IsRestParameter()) { - spread_ = cb(spread_)->AsRestElement(); + if (auto *transformedNode = cb(spread_); spread_ != transformedNode) { + spread_->SetTransformedNode(transformationName, transformedNode); + spread_ = transformedNode->AsRestElement(); + } ident_ = spread_->Argument()->AsIdentifier(); } else { - ident_ = cb(ident_)->AsIdentifier(); + if (auto *transformedNode = cb(ident_); ident_ != transformedNode) { + ident_->SetTransformedNode(transformationName, transformedNode); + ident_ = transformedNode->AsIdentifier(); + } } if (IsDefault()) { - initializer_ = cb(initializer_)->AsExpression(); + if (auto *transformedNode = cb(initializer_); initializer_ != transformedNode) { + initializer_->SetTransformedNode(transformationName, transformedNode); + initializer_ = transformedNode->AsExpression(); + } } } diff --git a/ets2panda/ir/ets/etsParameterExpression.h b/ets2panda/ir/ets/etsParameterExpression.h index 98339d8d3650baf35a077cd7f0e46bfeef9b8cab..d56056b28e283c2f731ef7c4dc97476534cbe10d 100644 --- a/ets2panda/ir/ets/etsParameterExpression.h +++ b/ets2panda/ir/ets/etsParameterExpression.h @@ -78,7 +78,7 @@ public: [[nodiscard]] ETSParameterExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; void Iterate(const NodeTraverser &cb) const override; - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; diff --git a/ets2panda/ir/ets/etsPrimitiveType.cpp b/ets2panda/ir/ets/etsPrimitiveType.cpp index 8bceeec7b5f1781ca2454fb4306e1f0d0ff3a614..e3d13a07c0a86bcc0fd19e53dbcf741c64a95d03 100644 --- a/ets2panda/ir/ets/etsPrimitiveType.cpp +++ b/ets2panda/ir/ets/etsPrimitiveType.cpp @@ -23,7 +23,11 @@ #include "ir/srcDump.h" namespace ark::es2panda::ir { -void ETSPrimitiveType::TransformChildren([[maybe_unused]] const NodeTransformer &cb) {} +void ETSPrimitiveType::TransformChildren([[maybe_unused]] const NodeTransformer &cb, + [[maybe_unused]] std::string_view const transformationName) +{ +} + void ETSPrimitiveType::Iterate([[maybe_unused]] const NodeTraverser &cb) const {} void ETSPrimitiveType::Dump(ir::AstDumper *dumper) const diff --git a/ets2panda/ir/ets/etsPrimitiveType.h b/ets2panda/ir/ets/etsPrimitiveType.h index e1332cef764bfb13b46a91eccf070641c44cb77a..3073137ba0981cd6d92718c2dc9928b1fdf20b21 100644 --- a/ets2panda/ir/ets/etsPrimitiveType.h +++ b/ets2panda/ir/ets/etsPrimitiveType.h @@ -30,7 +30,7 @@ public: return type_; } - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/ets/etsReExportDeclaration.cpp b/ets2panda/ir/ets/etsReExportDeclaration.cpp index 40d24158f63fa5bfd1c9c4c09dd6e3991b6fddba..1ec07019bb2f00e658301cc6ec0ef9e361e62b2f 100644 --- a/ets2panda/ir/ets/etsReExportDeclaration.cpp +++ b/ets2panda/ir/ets/etsReExportDeclaration.cpp @@ -31,10 +31,13 @@ ETSReExportDeclaration::ETSReExportDeclaration(ETSImportDeclaration *etsImportDe } } -void ETSReExportDeclaration::TransformChildren(const NodeTransformer &cb) +void ETSReExportDeclaration::TransformChildren(const NodeTransformer &cb, std::string_view const transformationName) { if (etsImportDeclarations_ != nullptr) { - etsImportDeclarations_ = cb(etsImportDeclarations_)->AsETSImportDeclaration(); + if (auto *transformedNode = cb(etsImportDeclarations_); etsImportDeclarations_ != transformedNode) { + etsImportDeclarations_->SetTransformedNode(transformationName, transformedNode); + etsImportDeclarations_ = transformedNode->AsETSImportDeclaration(); + } } } diff --git a/ets2panda/ir/ets/etsReExportDeclaration.h b/ets2panda/ir/ets/etsReExportDeclaration.h index b35c84392c1fadb3d78efe69e93fc772424c7e14..aab4c894016420ed3baae47dafbc83b81560a5bf 100644 --- a/ets2panda/ir/ets/etsReExportDeclaration.h +++ b/ets2panda/ir/ets/etsReExportDeclaration.h @@ -49,7 +49,7 @@ public: return programPath_; } - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/ets/etsStructDeclaration.cpp b/ets2panda/ir/ets/etsStructDeclaration.cpp index e7b08d20fda3a92fd270b1b4f82f82dad54032f8..7e452a8c3bd158cffb4d758bf4556cc2d1a8f177 100644 --- a/ets2panda/ir/ets/etsStructDeclaration.cpp +++ b/ets2panda/ir/ets/etsStructDeclaration.cpp @@ -23,16 +23,21 @@ #include "ir/srcDump.h" #include "ir/base/classDefinition.h" #include "ir/base/decorator.h" -#include "ir/expressions/identifier.h" namespace ark::es2panda::ir { -void ETSStructDeclaration::TransformChildren(const NodeTransformer &cb) +void ETSStructDeclaration::TransformChildren(const NodeTransformer &cb, std::string_view const transformationName) { for (auto *&it : decorators_) { - it = cb(it)->AsDecorator(); + if (auto *transformedNode = cb(it); it != transformedNode) { + it->SetTransformedNode(transformationName, transformedNode); + it = transformedNode->AsDecorator(); + } } - def_ = cb(def_)->AsClassDefinition(); + if (auto *transformedNode = cb(def_); def_ != transformedNode) { + def_->SetTransformedNode(transformationName, transformedNode); + def_ = transformedNode->AsClassDefinition(); + } } void ETSStructDeclaration::Iterate(const NodeTraverser &cb) const diff --git a/ets2panda/ir/ets/etsStructDeclaration.h b/ets2panda/ir/ets/etsStructDeclaration.h index 095554dac640f229c31495955556145d2d5ef535..747d605e64dd0307fc80e3b51fce78a61938792b 100644 --- a/ets2panda/ir/ets/etsStructDeclaration.h +++ b/ets2panda/ir/ets/etsStructDeclaration.h @@ -69,7 +69,7 @@ public: [[nodiscard]] ETSStructDeclaration *Clone(ArenaAllocator *allocator, AstNode *parent) override; - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; diff --git a/ets2panda/ir/ets/etsTuple.cpp b/ets2panda/ir/ets/etsTuple.cpp index f7d23886a3a4a9a449fdcd5b0191a71d94c5afc3..518aa98657233612bee75bb21caf1b9f0d8e10bd 100644 --- a/ets2panda/ir/ets/etsTuple.cpp +++ b/ets2panda/ir/ets/etsTuple.cpp @@ -20,18 +20,24 @@ namespace ark::es2panda::ir { -void ETSTuple::TransformChildren([[maybe_unused]] const NodeTransformer &cb) +void ETSTuple::TransformChildren(const NodeTransformer &cb, std::string_view const transformationName) { for (auto *&it : GetTupleTypeAnnotationsList()) { - it = static_cast(cb(it)); + if (auto *transformedNode = cb(it); it != transformedNode) { + it->SetTransformedNode(transformationName, transformedNode); + it = static_cast(transformedNode); + } } if (HasSpreadType()) { - cb(spreadType_); + if (auto *transformedNode = cb(spreadType_); spreadType_ != transformedNode) { + spreadType_->SetTransformedNode(transformationName, transformedNode); + spreadType_ = static_cast(transformedNode); + } } } -void ETSTuple::Iterate([[maybe_unused]] const NodeTraverser &cb) const +void ETSTuple::Iterate(const NodeTraverser &cb) const { for (auto *const it : GetTupleTypeAnnotationsList()) { cb(it); diff --git a/ets2panda/ir/ets/etsTuple.h b/ets2panda/ir/ets/etsTuple.h index 1de42d15baf6d0f8d113a9e7a64a1277a40f0d7c..bc388560415962087b25b0cc085713c4c43c96cc 100644 --- a/ets2panda/ir/ets/etsTuple.h +++ b/ets2panda/ir/ets/etsTuple.h @@ -66,7 +66,7 @@ public: typeAnnotationList_ = typeNodeList; } - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/ets/etsTypeReference.cpp b/ets2panda/ir/ets/etsTypeReference.cpp index fe5b08888a1d4eb6ca82324392a6164f7b1df14c..01b456600aea1d247f9cfc3f21f119385fade803 100644 --- a/ets2panda/ir/ets/etsTypeReference.cpp +++ b/ets2panda/ir/ets/etsTypeReference.cpp @@ -25,9 +25,12 @@ #include "ir/ets/etsTypeReferencePart.h" namespace ark::es2panda::ir { -void ETSTypeReference::TransformChildren(const NodeTransformer &cb) +void ETSTypeReference::TransformChildren(const NodeTransformer &cb, std::string_view const transformationName) { - part_ = cb(part_)->AsETSTypeReferencePart(); + if (auto *transformedNode = cb(part_); part_ != transformedNode) { + part_->SetTransformedNode(transformationName, transformedNode); + part_ = transformedNode->AsETSTypeReferencePart(); + } } void ETSTypeReference::Iterate(const NodeTraverser &cb) const diff --git a/ets2panda/ir/ets/etsTypeReference.h b/ets2panda/ir/ets/etsTypeReference.h index 62e14abd40d4a9a1053b39223af469a9a28fb733..475edde311e40d2f3550cce408b1a3bffb2a4964 100644 --- a/ets2panda/ir/ets/etsTypeReference.h +++ b/ets2panda/ir/ets/etsTypeReference.h @@ -38,7 +38,7 @@ public: ir::Identifier *BaseName() const; - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/ets/etsTypeReferencePart.cpp b/ets2panda/ir/ets/etsTypeReferencePart.cpp index d1ccc84180aecd764c9225e4d4dd6e6199481b9e..44c6a4ba6b5316213624bd00b33c9814e802afb1 100644 --- a/ets2panda/ir/ets/etsTypeReferencePart.cpp +++ b/ets2panda/ir/ets/etsTypeReferencePart.cpp @@ -22,19 +22,27 @@ #include "compiler/core/pandagen.h" #include "ir/astDump.h" #include "ir/srcDump.h" -#include "macros.h" namespace ark::es2panda::ir { -void ETSTypeReferencePart::TransformChildren(const NodeTransformer &cb) +void ETSTypeReferencePart::TransformChildren(const NodeTransformer &cb, std::string_view const transformationName) { - name_ = cb(name_)->AsExpression(); + if (auto *transformedNode = cb(name_); name_ != transformedNode) { + name_->SetTransformedNode(transformationName, transformedNode); + name_ = transformedNode->AsExpression(); + } if (typeParams_ != nullptr) { - typeParams_ = cb(typeParams_)->AsTSTypeParameterInstantiation(); + if (auto *transformedNode = cb(typeParams_); typeParams_ != transformedNode) { + typeParams_->SetTransformedNode(transformationName, transformedNode); + typeParams_ = transformedNode->AsTSTypeParameterInstantiation(); + } } if (prev_ != nullptr) { - prev_ = cb(prev_)->AsETSTypeReferencePart(); + if (auto *transformedNode = cb(prev_); prev_ != transformedNode) { + prev_->SetTransformedNode(transformationName, transformedNode); + prev_ = transformedNode->AsETSTypeReferencePart(); + } } } diff --git a/ets2panda/ir/ets/etsTypeReferencePart.h b/ets2panda/ir/ets/etsTypeReferencePart.h index a75ce1d075b49b3851d6551aaf0f14a0b2222dc3..41b1cd2293a7af76c15515b422f87edaab52bb62 100644 --- a/ets2panda/ir/ets/etsTypeReferencePart.h +++ b/ets2panda/ir/ets/etsTypeReferencePart.h @@ -55,7 +55,7 @@ public: return name_; } - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/ets/etsUnionType.cpp b/ets2panda/ir/ets/etsUnionType.cpp index e7a06155ff06d23083f7b508d45ea9bd459ef0a0..b8ff6122ae28b9243095c7416f7d36d0617cdc20 100644 --- a/ets2panda/ir/ets/etsUnionType.cpp +++ b/ets2panda/ir/ets/etsUnionType.cpp @@ -20,10 +20,13 @@ #include "ir/srcDump.h" namespace ark::es2panda::ir { -void ETSUnionType::TransformChildren(const NodeTransformer &cb) +void ETSUnionType::TransformChildren(const NodeTransformer &cb, std::string_view const transformationName) { for (auto *&it : types_) { - it = static_cast(cb(it)); + if (auto *transformedNode = cb(it); it != transformedNode) { + it->SetTransformedNode(transformationName, transformedNode); + it = static_cast(transformedNode); + } } } diff --git a/ets2panda/ir/ets/etsUnionType.h b/ets2panda/ir/ets/etsUnionType.h index 75c81f4ff04ce4fe67122330f489ac66e5a362ca..9070dc2c456a124d823d8b4ad881138909b47ac3 100644 --- a/ets2panda/ir/ets/etsUnionType.h +++ b/ets2panda/ir/ets/etsUnionType.h @@ -31,7 +31,7 @@ public: return types_; } - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/ets/etsWildcardType.cpp b/ets2panda/ir/ets/etsWildcardType.cpp index 1c1cc6fd2e0e8e97494dd9b2e322021550c8a59f..44033cf71961d2564a5c5feb0e89af9177e74955 100644 --- a/ets2panda/ir/ets/etsWildcardType.cpp +++ b/ets2panda/ir/ets/etsWildcardType.cpp @@ -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 @@ -24,10 +24,13 @@ #include "ir/ets/etsTypeReference.h" namespace ark::es2panda::ir { -void ETSWildcardType::TransformChildren(const NodeTransformer &cb) +void ETSWildcardType::TransformChildren(const NodeTransformer &cb, std::string_view const transformationName) { if (typeReference_ != nullptr) { - typeReference_ = cb(typeReference_)->AsETSTypeReference(); + if (auto *transformedNode = cb(typeReference_); typeReference_ != transformedNode) { + typeReference_->SetTransformedNode(transformationName, transformedNode); + typeReference_ = transformedNode->AsETSTypeReference(); + } } } diff --git a/ets2panda/ir/ets/etsWildcardType.h b/ets2panda/ir/ets/etsWildcardType.h index 01aa519d0ea1542f491728852288980a24b28e5b..e574ef2f513921c5e04537ad3225b86da9227f65 100644 --- a/ets2panda/ir/ets/etsWildcardType.h +++ b/ets2panda/ir/ets/etsWildcardType.h @@ -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 @@ -34,7 +34,7 @@ public: return typeReference_; } - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/expressions/arrayExpression.cpp b/ets2panda/ir/expressions/arrayExpression.cpp index 07cafdd76b65dede41ea7a90d2fa5ac403733ab8..275bf113765dabc6a17d945ac1d9f3542d2a5c7d 100644 --- a/ets2panda/ir/expressions/arrayExpression.cpp +++ b/ets2panda/ir/expressions/arrayExpression.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021-2024 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 @@ -165,18 +165,27 @@ ValidationInfo ArrayExpression::ValidateExpression() return info; } -void ArrayExpression::TransformChildren(const NodeTransformer &cb) +void ArrayExpression::TransformChildren(const NodeTransformer &cb, std::string_view const transformationName) { for (auto *&it : decorators_) { - it = cb(it)->AsDecorator(); + if (auto *transformedNode = cb(it); it != transformedNode) { + it->SetTransformedNode(transformationName, transformedNode); + it = transformedNode->AsDecorator(); + } } for (auto *&it : elements_) { - it = cb(it)->AsExpression(); + if (auto *transformedNode = cb(it); it != transformedNode) { + it->SetTransformedNode(transformationName, transformedNode); + it = transformedNode->AsExpression(); + } } - if (TypeAnnotation() != nullptr) { - SetTsTypeAnnotation(static_cast(cb(TypeAnnotation()))); + if (auto *typeAnnotation = TypeAnnotation(); typeAnnotation != nullptr) { + if (auto *transformedNode = cb(typeAnnotation); typeAnnotation != transformedNode) { + typeAnnotation->SetTransformedNode(transformationName, transformedNode); + SetTsTypeAnnotation(static_cast(transformedNode)); + } } } diff --git a/ets2panda/ir/expressions/arrayExpression.h b/ets2panda/ir/expressions/arrayExpression.h index bf0e9c2841ea0d0ce8b8e5b3639d0d505fb4002e..2ebdeb235aaf72c3842fb2444fd7a4183b8ca4e0 100644 --- a/ets2panda/ir/expressions/arrayExpression.h +++ b/ets2panda/ir/expressions/arrayExpression.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021-2024 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 @@ -123,7 +123,7 @@ public: [[nodiscard]] bool ConvertibleToArrayPattern(); [[nodiscard]] ValidationInfo ValidateExpression(); - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/expressions/arrowFunctionExpression.cpp b/ets2panda/ir/expressions/arrowFunctionExpression.cpp index 112cd5bceff09c31f53f6bcc244801abccf523e5..77d39416dd9051ea2de320db3bc14054924feed8 100644 --- a/ets2panda/ir/expressions/arrowFunctionExpression.cpp +++ b/ets2panda/ir/expressions/arrowFunctionExpression.cpp @@ -29,9 +29,12 @@ #include "ir/statements/variableDeclarator.h" namespace ark::es2panda::ir { -void ArrowFunctionExpression::TransformChildren(const NodeTransformer &cb) +void ArrowFunctionExpression::TransformChildren(const NodeTransformer &cb, std::string_view const transformationName) { - func_ = cb(func_)->AsScriptFunction(); + if (auto *transformedNode = cb(func_); func_ != transformedNode) { + func_->SetTransformedNode(transformationName, transformedNode); + func_ = transformedNode->AsScriptFunction(); + } } void ArrowFunctionExpression::Iterate(const NodeTraverser &cb) const diff --git a/ets2panda/ir/expressions/arrowFunctionExpression.h b/ets2panda/ir/expressions/arrowFunctionExpression.h index 2edbb01e48663d0bd29a7927260c75ea6f947eb5..dac4194054533d754af34b3d0ed858b697f84d37 100644 --- a/ets2panda/ir/expressions/arrowFunctionExpression.h +++ b/ets2panda/ir/expressions/arrowFunctionExpression.h @@ -105,7 +105,7 @@ public: [[nodiscard]] ArrowFunctionExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/expressions/assignmentExpression.cpp b/ets2panda/ir/expressions/assignmentExpression.cpp index bd61dd8989b9a4dbbe9af837399df82fc2839396..0f02e9ab6011aed32a9cd2fa43b148d6634ba45c 100644 --- a/ets2panda/ir/expressions/assignmentExpression.cpp +++ b/ets2panda/ir/expressions/assignmentExpression.cpp @@ -21,13 +21,9 @@ #include "compiler/core/regScope.h" #include "ir/astDump.h" #include "ir/srcDump.h" -#include "ir/base/scriptFunction.h" #include "ir/base/spreadElement.h" -#include "ir/expressions/identifier.h" #include "ir/expressions/arrayExpression.h" -#include "ir/expressions/binaryExpression.h" #include "ir/expressions/objectExpression.h" -#include "ir/expressions/memberExpression.h" #include "checker/TSchecker.h" #include "checker/ts/destructuringContext.h" @@ -99,10 +95,17 @@ bool AssignmentExpression::ConvertibleToAssignmentPattern(bool mustBePattern) return convResult; } -void AssignmentExpression::TransformChildren(const NodeTransformer &cb) +void AssignmentExpression::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { - left_ = cb(left_)->AsExpression(); - right_ = cb(right_)->AsExpression(); + if (auto *transformedNode = cb(left_); left_ != transformedNode) { + left_->SetTransformedNode(transformationName, transformedNode); + left_ = transformedNode->AsExpression(); + } + + if (auto *transformedNode = cb(right_); right_ != transformedNode) { + right_->SetTransformedNode(transformationName, transformedNode); + right_ = transformedNode->AsExpression(); + } } void AssignmentExpression::Iterate(const NodeTraverser &cb) const diff --git a/ets2panda/ir/expressions/assignmentExpression.h b/ets2panda/ir/expressions/assignmentExpression.h index 1f8a61e0cb5ccdd7b1fda64a5a43fcaa3a649a41..ecdd1a9159ef5a2400a65e48113e97e1b3ff5291 100644 --- a/ets2panda/ir/expressions/assignmentExpression.h +++ b/ets2panda/ir/expressions/assignmentExpression.h @@ -125,7 +125,7 @@ public: [[nodiscard]] bool ConvertibleToAssignmentPattern(bool mustBePattern = true); - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/expressions/awaitExpression.cpp b/ets2panda/ir/expressions/awaitExpression.cpp index 8eba7efe659f589429c7252e23d55b1889492cc2..4654850eecb4de99bc38808ce0dda9a2b56cfc2e 100644 --- a/ets2panda/ir/expressions/awaitExpression.cpp +++ b/ets2panda/ir/expressions/awaitExpression.cpp @@ -22,10 +22,13 @@ #include "ir/srcDump.h" namespace ark::es2panda::ir { -void AwaitExpression::TransformChildren(const NodeTransformer &cb) +void AwaitExpression::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { if (argument_ != nullptr) { - argument_ = cb(argument_)->AsExpression(); + if (auto *transformedNode = cb(argument_); argument_ != transformedNode) { + argument_->SetTransformedNode(transformationName, transformedNode); + argument_ = transformedNode->AsExpression(); + } } } diff --git a/ets2panda/ir/expressions/awaitExpression.h b/ets2panda/ir/expressions/awaitExpression.h index ea4febd7ab446a1c427e5ccba2ff9dda02cdc658..0b24363c4471c3ebcd97e952564d1253950cc928 100644 --- a/ets2panda/ir/expressions/awaitExpression.h +++ b/ets2panda/ir/expressions/awaitExpression.h @@ -43,7 +43,7 @@ public: [[nodiscard]] AwaitExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/expressions/binaryExpression.cpp b/ets2panda/ir/expressions/binaryExpression.cpp index 19c716ba9c6604be7dbc0977501618bd029c46e4..438e05239d35548a966f2e3a35efdcc50b10869e 100644 --- a/ets2panda/ir/expressions/binaryExpression.cpp +++ b/ets2panda/ir/expressions/binaryExpression.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 - 2024 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 @@ -24,10 +24,17 @@ #include "ir/visitor/AstVisitor.h" namespace ark::es2panda::ir { -void BinaryExpression::TransformChildren(const NodeTransformer &cb) +void BinaryExpression::TransformChildren(const NodeTransformer &cb, std::string_view const transformationName) { - left_ = cb(left_)->AsExpression(); - right_ = cb(right_)->AsExpression(); + if (auto *transformedNode = cb(left_); left_ != transformedNode) { + left_->SetTransformedNode(transformationName, transformedNode); + left_ = transformedNode->AsExpression(); + } + + if (auto *transformedNode = cb(right_); right_ != transformedNode) { + right_->SetTransformedNode(transformationName, transformedNode); + right_ = transformedNode->AsExpression(); + } } void BinaryExpression::Iterate(const NodeTraverser &cb) const diff --git a/ets2panda/ir/expressions/binaryExpression.h b/ets2panda/ir/expressions/binaryExpression.h index 9b60317962983a0b6d248b5c6fa586617d059c6c..d0ed782aa0ac6e281b66ada5b553266df08744f4 100644 --- a/ets2panda/ir/expressions/binaryExpression.h +++ b/ets2panda/ir/expressions/binaryExpression.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 - 2024 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 @@ -151,7 +151,7 @@ public: [[nodiscard]] BinaryExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/expressions/blockExpression.cpp b/ets2panda/ir/expressions/blockExpression.cpp index 47342446048a91a2d3448c27b5d8a64268290830..e753ef9b8d7de6510c0d3ae753877608cfff5962 100644 --- a/ets2panda/ir/expressions/blockExpression.cpp +++ b/ets2panda/ir/expressions/blockExpression.cpp @@ -51,10 +51,13 @@ BlockExpression *BlockExpression::Clone(ArenaAllocator *const allocator, AstNode throw Error(ErrorType::GENERIC, "", CLONE_ALLOCATION_ERROR); } -void BlockExpression::TransformChildren(const NodeTransformer &cb) +void BlockExpression::TransformChildren(const NodeTransformer &cb, std::string_view const transformationName) { for (auto *&node : statements_) { - node = cb(node)->AsStatement(); + if (auto *transformedNode = cb(node); node != transformedNode) { + node->SetTransformedNode(transformationName, transformedNode); + node = transformedNode->AsStatement(); + } } } diff --git a/ets2panda/ir/expressions/blockExpression.h b/ets2panda/ir/expressions/blockExpression.h index 05430c809a8e8ec31c45d110b13b6b54454034cd..80afdc38da74c28782cc818335a763b751c40513 100644 --- a/ets2panda/ir/expressions/blockExpression.h +++ b/ets2panda/ir/expressions/blockExpression.h @@ -63,22 +63,23 @@ public: [[nodiscard]] BlockExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; - bool IsScopeBearer() const noexcept override + [[nodiscard]] bool IsScopeBearer() const noexcept override { return true; } - varbinder::Scope *Scope() const noexcept override + [[nodiscard]] varbinder::Scope *Scope() const noexcept override { return scope_; } void SetScope(varbinder::Scope *scope) { + ASSERT(scope_ == nullptr); scope_ = scope; } - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/expressions/callExpression.cpp b/ets2panda/ir/expressions/callExpression.cpp index 7469d617c7af7288475fdc7c6d96581bd9d798a3..441a47c5272330d0740d780adc4ad6c00b6fcff7 100644 --- a/ets2panda/ir/expressions/callExpression.cpp +++ b/ets2panda/ir/expressions/callExpression.cpp @@ -22,16 +22,25 @@ #include "ir/srcDump.h" namespace ark::es2panda::ir { -void CallExpression::TransformChildren(const NodeTransformer &cb) +void CallExpression::TransformChildren(const NodeTransformer &cb, std::string_view const transformationName) { - callee_ = cb(callee_)->AsExpression(); + if (auto *transformedNode = cb(callee_); callee_ != transformedNode) { + callee_->SetTransformedNode(transformationName, transformedNode); + callee_ = transformedNode->AsExpression(); + } if (typeParams_ != nullptr) { - typeParams_ = cb(typeParams_)->AsTSTypeParameterInstantiation(); + if (auto *transformedNode = cb(typeParams_); typeParams_ != transformedNode) { + typeParams_->SetTransformedNode(transformationName, transformedNode); + typeParams_ = transformedNode->AsTSTypeParameterInstantiation(); + } } for (auto *&it : arguments_) { - it = cb(it)->AsExpression(); + if (auto *transformedNode = cb(it); it != transformedNode) { + it->SetTransformedNode(transformationName, transformedNode); + it = transformedNode->AsExpression(); + } } } diff --git a/ets2panda/ir/expressions/callExpression.h b/ets2panda/ir/expressions/callExpression.h index 04fa873bfafb1ae2a4cc6a2bd5a8ed9c3f0804d7..23655a80aebeea4b5ab6f0abcf1e371a5cb43742 100644 --- a/ets2panda/ir/expressions/callExpression.h +++ b/ets2panda/ir/expressions/callExpression.h @@ -17,7 +17,6 @@ #define ES2PANDA_IR_EXPRESSION_CALL_EXPRESSION_H #include "varbinder/variable.h" -#include "checker/types/ets/etsFunctionType.h" #include "ir/expression.h" namespace ark::es2panda::checker { @@ -148,7 +147,7 @@ public: [[nodiscard]] CallExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; diff --git a/ets2panda/ir/expressions/chainExpression.cpp b/ets2panda/ir/expressions/chainExpression.cpp index fdaf5bc4a3a51c48ff3aefd5a1905698e0236215..eaf383ec2699b9faf26087c246fde265d36fe9fe 100644 --- a/ets2panda/ir/expressions/chainExpression.cpp +++ b/ets2panda/ir/expressions/chainExpression.cpp @@ -23,9 +23,12 @@ #include "ir/expressions/memberExpression.h" namespace ark::es2panda::ir { -void ChainExpression::TransformChildren(const NodeTransformer &cb) +void ChainExpression::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { - expression_ = cb(expression_)->AsExpression(); + if (auto *transformedNode = cb(expression_); expression_ != transformedNode) { + expression_->SetTransformedNode(transformationName, transformedNode); + expression_ = transformedNode->AsExpression(); + } } void ChainExpression::Iterate(const NodeTraverser &cb) const diff --git a/ets2panda/ir/expressions/chainExpression.h b/ets2panda/ir/expressions/chainExpression.h index 4fe2fae37bb0bd39b5aecee2cb56602ac8efab41..8caa0a49057aa4c1661ff78804df098a17e73eb5 100644 --- a/ets2panda/ir/expressions/chainExpression.h +++ b/ets2panda/ir/expressions/chainExpression.h @@ -52,7 +52,7 @@ public: [[nodiscard]] ChainExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/expressions/classExpression.cpp b/ets2panda/ir/expressions/classExpression.cpp index e66e16f1e4519cd6629ad7693db39f7f5aeed666..94be8ff983a1ee33cb9c1ec1dc23cd41e582b1d2 100644 --- a/ets2panda/ir/expressions/classExpression.cpp +++ b/ets2panda/ir/expressions/classExpression.cpp @@ -22,9 +22,12 @@ #include "ir/srcDump.h" namespace ark::es2panda::ir { -void ClassExpression::TransformChildren(const NodeTransformer &cb) +void ClassExpression::TransformChildren(const NodeTransformer &cb, std::string_view const transformationName) { - def_ = cb(def_)->AsClassDefinition(); + if (auto *transformedNode = cb(def_); def_ != transformedNode) { + def_->SetTransformedNode(transformationName, transformedNode); + def_ = transformedNode->AsClassDefinition(); + } } void ClassExpression::Iterate(const NodeTraverser &cb) const diff --git a/ets2panda/ir/expressions/classExpression.h b/ets2panda/ir/expressions/classExpression.h index 73c4451fd94c5fdfc0e0edd9cfe0c83d1c7c7259..2a77bbb0e91ed0cbf88a43738c28ce74916d1f6c 100644 --- a/ets2panda/ir/expressions/classExpression.h +++ b/ets2panda/ir/expressions/classExpression.h @@ -38,7 +38,7 @@ public: [[nodiscard]] ClassExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; diff --git a/ets2panda/ir/expressions/conditionalExpression.cpp b/ets2panda/ir/expressions/conditionalExpression.cpp index bd7b5add97e14602a8751656f8d0465268a55756..6bb5967cb7d6b05b54635ad10460d9f61c374d50 100644 --- a/ets2panda/ir/expressions/conditionalExpression.cpp +++ b/ets2panda/ir/expressions/conditionalExpression.cpp @@ -22,11 +22,22 @@ #include "ir/srcDump.h" namespace ark::es2panda::ir { -void ConditionalExpression::TransformChildren(const NodeTransformer &cb) +void ConditionalExpression::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { - test_ = cb(test_)->AsExpression(); - consequent_ = cb(consequent_)->AsExpression(); - alternate_ = cb(alternate_)->AsExpression(); + if (auto *transformedNode = cb(test_); test_ != transformedNode) { + test_->SetTransformedNode(transformationName, transformedNode); + test_ = transformedNode->AsExpression(); + } + + if (auto *transformedNode = cb(consequent_); consequent_ != transformedNode) { + consequent_->SetTransformedNode(transformationName, transformedNode); + consequent_ = transformedNode->AsExpression(); + } + + if (auto *transformedNode = cb(alternate_); alternate_ != transformedNode) { + alternate_->SetTransformedNode(transformationName, transformedNode); + alternate_ = transformedNode->AsExpression(); + } } void ConditionalExpression::Iterate(const NodeTraverser &cb) const diff --git a/ets2panda/ir/expressions/conditionalExpression.h b/ets2panda/ir/expressions/conditionalExpression.h index 8cd6031ad033c9dcc6d2ecc7d1a3f8731e7a7cdf..95c74db4f147108149b3ee11a1dfaad742bd5fbe 100644 --- a/ets2panda/ir/expressions/conditionalExpression.h +++ b/ets2panda/ir/expressions/conditionalExpression.h @@ -87,7 +87,7 @@ public: [[nodiscard]] ConditionalExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/expressions/functionExpression.cpp b/ets2panda/ir/expressions/functionExpression.cpp index 28de21f65091f29b270e9518bc3f1e26fd2e5117..f31cab4596057bc9626860aa63c34e2b368f9e9a 100644 --- a/ets2panda/ir/expressions/functionExpression.cpp +++ b/ets2panda/ir/expressions/functionExpression.cpp @@ -22,9 +22,12 @@ #include "ir/srcDump.h" namespace ark::es2panda::ir { -void FunctionExpression::TransformChildren(const NodeTransformer &cb) +void FunctionExpression::TransformChildren(const NodeTransformer &cb, std::string_view const transformationName) { - func_ = cb(func_)->AsScriptFunction(); + if (auto *transformedNode = cb(func_); func_ != transformedNode) { + func_->SetTransformedNode(transformationName, transformedNode); + func_ = transformedNode->AsScriptFunction(); + } } void FunctionExpression::Iterate(const NodeTraverser &cb) const diff --git a/ets2panda/ir/expressions/functionExpression.h b/ets2panda/ir/expressions/functionExpression.h index 4d585fae1fe69e5fa838a331dff1678416c502b3..fc5cbbb7ee022791ae7bba01315005d77cf2a24c 100644 --- a/ets2panda/ir/expressions/functionExpression.h +++ b/ets2panda/ir/expressions/functionExpression.h @@ -60,7 +60,7 @@ public: [[nodiscard]] FunctionExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; diff --git a/ets2panda/ir/expressions/identifier.cpp b/ets2panda/ir/expressions/identifier.cpp index 8d2fe53153ff7c6aab1a80385945828c1dcd4aae..33ae22c066a3660b326d20a4c7210ab431abec87 100644 --- a/ets2panda/ir/expressions/identifier.cpp +++ b/ets2panda/ir/expressions/identifier.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 - 2024 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 @@ -53,14 +53,20 @@ Identifier *Identifier::Clone(ArenaAllocator *const allocator, AstNode *const pa throw Error(ErrorType::GENERIC, "", CLONE_ALLOCATION_ERROR); } -void Identifier::TransformChildren(const NodeTransformer &cb) +void Identifier::TransformChildren(const NodeTransformer &cb, std::string_view const transformationName) { - if (TypeAnnotation() != nullptr) { - SetTsTypeAnnotation(static_cast(cb(TypeAnnotation()))); + if (auto *typeAnnotation = TypeAnnotation(); typeAnnotation != nullptr) { + if (auto *transformedNode = cb(typeAnnotation); typeAnnotation != transformedNode) { + typeAnnotation->SetTransformedNode(transformationName, transformedNode); + SetTsTypeAnnotation(static_cast(transformedNode)); + } } for (auto *&it : decorators_) { - it = cb(it)->AsDecorator(); + if (auto *transformedNode = cb(it); it != transformedNode) { + it->SetTransformedNode(transformationName, transformedNode); + it = transformedNode->AsDecorator(); + } } } diff --git a/ets2panda/ir/expressions/identifier.h b/ets2panda/ir/expressions/identifier.h index acfa6b6eb648f2f892de641743874af75cef7bec..d28633830869c7ef1e1c670d826af3f9c4a7c114 100644 --- a/ets2panda/ir/expressions/identifier.h +++ b/ets2panda/ir/expressions/identifier.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 - 2024 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 @@ -184,7 +184,7 @@ public: [[nodiscard]] ValidationInfo ValidateExpression(); - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/expressions/importExpression.cpp b/ets2panda/ir/expressions/importExpression.cpp index 5858dc1a8c6fce73aac8b2ff97473132fd1f0caa..212f1a1050d11e08506c2f2cfaf9df802122393e 100644 --- a/ets2panda/ir/expressions/importExpression.cpp +++ b/ets2panda/ir/expressions/importExpression.cpp @@ -22,9 +22,12 @@ #include "ir/srcDump.h" namespace ark::es2panda::ir { -void ImportExpression::TransformChildren(const NodeTransformer &cb) +void ImportExpression::TransformChildren(const NodeTransformer &cb, std::string_view const transformationName) { - source_ = cb(source_)->AsExpression(); + if (auto *transformedNode = cb(source_); source_ != transformedNode) { + source_->SetTransformedNode(transformationName, transformedNode); + source_ = transformedNode->AsExpression(); + } } void ImportExpression::Iterate(const NodeTraverser &cb) const diff --git a/ets2panda/ir/expressions/importExpression.h b/ets2panda/ir/expressions/importExpression.h index 9249ae8cba990ec510bd2293aab1c4db28766334..7c09e79a0cd44c3bd052deb1c9baa44f8234c394 100644 --- a/ets2panda/ir/expressions/importExpression.h +++ b/ets2panda/ir/expressions/importExpression.h @@ -36,7 +36,7 @@ public: [[nodiscard]] ImportExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/expressions/literals/bigIntLiteral.cpp b/ets2panda/ir/expressions/literals/bigIntLiteral.cpp index e69a26435e98aaefe7a8c6de1913b2488360fba8..98506dcf702f45e7c757ae17b92eca4fbd08d6d3 100644 --- a/ets2panda/ir/expressions/literals/bigIntLiteral.cpp +++ b/ets2panda/ir/expressions/literals/bigIntLiteral.cpp @@ -23,7 +23,11 @@ #include "ir/srcDump.h" namespace ark::es2panda::ir { -void BigIntLiteral::TransformChildren([[maybe_unused]] const NodeTransformer &cb) {} +void BigIntLiteral::TransformChildren([[maybe_unused]] const NodeTransformer &cb, + [[maybe_unused]] std::string_view const transformationName) +{ +} + void BigIntLiteral::Iterate([[maybe_unused]] const NodeTraverser &cb) const {} void BigIntLiteral::Dump(ir::AstDumper *dumper) const diff --git a/ets2panda/ir/expressions/literals/bigIntLiteral.h b/ets2panda/ir/expressions/literals/bigIntLiteral.h index 616a3fb02e19ed80e37394e113f1966c59018673..af40283d55ff02804d6e18b234c6ba054d8316a1 100644 --- a/ets2panda/ir/expressions/literals/bigIntLiteral.h +++ b/ets2panda/ir/expressions/literals/bigIntLiteral.h @@ -37,7 +37,7 @@ public: [[nodiscard]] BigIntLiteral *Clone(ArenaAllocator *allocator, AstNode *parent) override; - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/expressions/literals/booleanLiteral.cpp b/ets2panda/ir/expressions/literals/booleanLiteral.cpp index a3c86ad5a5f2f8f4fa948a4d4ebcd7101bcf8cb3..3de6cae64f06ff271142be86e4bce3464bf26219 100644 --- a/ets2panda/ir/expressions/literals/booleanLiteral.cpp +++ b/ets2panda/ir/expressions/literals/booleanLiteral.cpp @@ -23,7 +23,11 @@ #include "ir/srcDump.h" namespace ark::es2panda::ir { -void BooleanLiteral::TransformChildren([[maybe_unused]] const NodeTransformer &cb) {} +void BooleanLiteral::TransformChildren([[maybe_unused]] const NodeTransformer &cb, + [[maybe_unused]] std::string_view const transformationName) +{ +} + void BooleanLiteral::Iterate([[maybe_unused]] const NodeTraverser &cb) const {} void BooleanLiteral::Dump(ir::AstDumper *dumper) const diff --git a/ets2panda/ir/expressions/literals/booleanLiteral.h b/ets2panda/ir/expressions/literals/booleanLiteral.h index 3c1e305cea527a68a0367d50e225312212b684de..7f25bbb8a53b636a68b9aa9b8ebd9064959bd121 100644 --- a/ets2panda/ir/expressions/literals/booleanLiteral.h +++ b/ets2panda/ir/expressions/literals/booleanLiteral.h @@ -36,7 +36,7 @@ public: [[nodiscard]] BooleanLiteral *Clone(ArenaAllocator *allocator, AstNode *parent) override; - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/expressions/literals/charLiteral.cpp b/ets2panda/ir/expressions/literals/charLiteral.cpp index cad47f79163da6e82952a8d19fa987a88143d86a..786fb1d4173ee86258217b7bec5c7afee740858b 100644 --- a/ets2panda/ir/expressions/literals/charLiteral.cpp +++ b/ets2panda/ir/expressions/literals/charLiteral.cpp @@ -22,11 +22,12 @@ #include "ir/astDump.h" #include "ir/srcDump.h" -#include -#include - namespace ark::es2panda::ir { -void CharLiteral::TransformChildren([[maybe_unused]] const NodeTransformer &cb) {} +void CharLiteral::TransformChildren([[maybe_unused]] const NodeTransformer &cb, + [[maybe_unused]] std::string_view const transformationName) +{ +} + void CharLiteral::Iterate([[maybe_unused]] const NodeTraverser &cb) const {} void CharLiteral::Dump(ir::AstDumper *dumper) const diff --git a/ets2panda/ir/expressions/literals/charLiteral.h b/ets2panda/ir/expressions/literals/charLiteral.h index ad1ebd6594ecd2a41e6f9a711851d7a58728e5d3..53915fbe577a1ba41edf176fc7e7b8430e2b12fc 100644 --- a/ets2panda/ir/expressions/literals/charLiteral.h +++ b/ets2panda/ir/expressions/literals/charLiteral.h @@ -42,7 +42,7 @@ public: [[nodiscard]] CharLiteral *Clone(ArenaAllocator *allocator, AstNode *parent) override; - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/expressions/literals/nullLiteral.cpp b/ets2panda/ir/expressions/literals/nullLiteral.cpp index 9efb1ac51bccb6c8520e05b15705f965c37384fc..e4750295c2d00a6a30ec50650ef3657a5a4e294e 100644 --- a/ets2panda/ir/expressions/literals/nullLiteral.cpp +++ b/ets2panda/ir/expressions/literals/nullLiteral.cpp @@ -22,7 +22,11 @@ #include "ir/srcDump.h" namespace ark::es2panda::ir { -void NullLiteral::TransformChildren([[maybe_unused]] const NodeTransformer &cb) {} +void NullLiteral::TransformChildren([[maybe_unused]] const NodeTransformer &cb, + [[maybe_unused]] std::string_view const transformationName) +{ +} + void NullLiteral::Iterate([[maybe_unused]] const NodeTraverser &cb) const {} void NullLiteral::Dump(ir::AstDumper *dumper) const diff --git a/ets2panda/ir/expressions/literals/nullLiteral.h b/ets2panda/ir/expressions/literals/nullLiteral.h index 1f4c0f839751673e61239ff752f2cf3008274dda..f9fcb454cd77a73bea472ba02402d27635956cbe 100644 --- a/ets2panda/ir/expressions/literals/nullLiteral.h +++ b/ets2panda/ir/expressions/literals/nullLiteral.h @@ -30,7 +30,7 @@ public: [[nodiscard]] NullLiteral *Clone(ArenaAllocator *allocator, AstNode *parent) override; - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/expressions/literals/numberLiteral.cpp b/ets2panda/ir/expressions/literals/numberLiteral.cpp index 48d8a61793c1ddc3c69e309240b0d51ce352ba99..b890233582381495638538ad7abeec60a3663574 100644 --- a/ets2panda/ir/expressions/literals/numberLiteral.cpp +++ b/ets2panda/ir/expressions/literals/numberLiteral.cpp @@ -14,7 +14,6 @@ */ #include "numberLiteral.h" -#include #include "checker/TSchecker.h" #include "compiler/core/ETSGen.h" @@ -23,7 +22,11 @@ #include "ir/srcDump.h" namespace ark::es2panda::ir { -void NumberLiteral::TransformChildren([[maybe_unused]] const NodeTransformer &cb) {} +void NumberLiteral::TransformChildren([[maybe_unused]] const NodeTransformer &cb, + [[maybe_unused]] std::string_view const transformationName) +{ +} + void NumberLiteral::Iterate([[maybe_unused]] const NodeTraverser &cb) const {} void NumberLiteral::Dump(ir::AstDumper *dumper) const diff --git a/ets2panda/ir/expressions/literals/numberLiteral.h b/ets2panda/ir/expressions/literals/numberLiteral.h index e1539cb53986229dcb10f312dd0c881b8673524a..bd9ce5a5e1dcd4e3a5208a1c665763a00d962202 100644 --- a/ets2panda/ir/expressions/literals/numberLiteral.h +++ b/ets2panda/ir/expressions/literals/numberLiteral.h @@ -51,7 +51,7 @@ public: [[nodiscard]] NumberLiteral *Clone(ArenaAllocator *allocator, AstNode *parent) override; - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/expressions/literals/regExpLiteral.cpp b/ets2panda/ir/expressions/literals/regExpLiteral.cpp index 4bee6c40971e818f2154e9e479254c32ac6b5311..5df047ea88217dcf1a11400c5c7cc3b035e2bf4b 100644 --- a/ets2panda/ir/expressions/literals/regExpLiteral.cpp +++ b/ets2panda/ir/expressions/literals/regExpLiteral.cpp @@ -15,7 +15,6 @@ #include "regExpLiteral.h" -#include "varbinder/variable.h" #include "compiler/core/pandagen.h" #include "compiler/core/regScope.h" #include "checker/TSchecker.h" @@ -24,7 +23,11 @@ #include "ir/srcDump.h" namespace ark::es2panda::ir { -void RegExpLiteral::TransformChildren([[maybe_unused]] const NodeTransformer &cb) {} +void RegExpLiteral::TransformChildren([[maybe_unused]] const NodeTransformer &cb, + [[maybe_unused]] std::string_view const transformationName) +{ +} + void RegExpLiteral::Iterate([[maybe_unused]] const NodeTraverser &cb) const {} void RegExpLiteral::Dump(ir::AstDumper *dumper) const diff --git a/ets2panda/ir/expressions/literals/regExpLiteral.h b/ets2panda/ir/expressions/literals/regExpLiteral.h index 069a4e0b9b044b08d2f7e6614350c792b8ba52b2..37e91589a7c4c86315f1d0a3ca281c81c1b84d44 100644 --- a/ets2panda/ir/expressions/literals/regExpLiteral.h +++ b/ets2panda/ir/expressions/literals/regExpLiteral.h @@ -46,7 +46,7 @@ public: [[nodiscard]] RegExpLiteral *Clone(ArenaAllocator *allocator, AstNode *parent) override; - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/expressions/literals/stringLiteral.cpp b/ets2panda/ir/expressions/literals/stringLiteral.cpp index c5b96aabda64a907565b878b998078f36e8f6037..6112363bc6c761ae97866832edac7f9a8504d017 100644 --- a/ets2panda/ir/expressions/literals/stringLiteral.cpp +++ b/ets2panda/ir/expressions/literals/stringLiteral.cpp @@ -14,17 +14,19 @@ */ #include "stringLiteral.h" -#include #include "checker/TSchecker.h" #include "compiler/core/ETSGen.h" #include "compiler/core/pandagen.h" #include "ir/astDump.h" #include "ir/srcDump.h" -#include "macros.h" namespace ark::es2panda::ir { -void StringLiteral::TransformChildren([[maybe_unused]] const NodeTransformer &cb) {} +void StringLiteral::TransformChildren([[maybe_unused]] const NodeTransformer &cb, + [[maybe_unused]] std::string_view const transformationName) +{ +} + void StringLiteral::Iterate([[maybe_unused]] const NodeTraverser &cb) const {} void StringLiteral::Dump(ir::AstDumper *dumper) const diff --git a/ets2panda/ir/expressions/literals/stringLiteral.h b/ets2panda/ir/expressions/literals/stringLiteral.h index f1c859a8ddb32d7de4e9e7d13500c94c9dd3587b..0e89efd5663daf473d9adc5cd308374e5c94145a 100644 --- a/ets2panda/ir/expressions/literals/stringLiteral.h +++ b/ets2panda/ir/expressions/literals/stringLiteral.h @@ -43,7 +43,7 @@ public: [[nodiscard]] StringLiteral *Clone(ArenaAllocator *allocator, AstNode *parent) override; - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/expressions/literals/undefinedLiteral.cpp b/ets2panda/ir/expressions/literals/undefinedLiteral.cpp index 5420279a40c899ea1b6a471a5f4036d853a5fb99..2b2ccfa46b308395b9b3d1df5f1d94993c79841e 100644 --- a/ets2panda/ir/expressions/literals/undefinedLiteral.cpp +++ b/ets2panda/ir/expressions/literals/undefinedLiteral.cpp @@ -23,7 +23,11 @@ #include "ir/srcDump.h" namespace ark::es2panda::ir { -void UndefinedLiteral::TransformChildren([[maybe_unused]] const NodeTransformer &cb) {} +void UndefinedLiteral::TransformChildren([[maybe_unused]] const NodeTransformer &cb, + [[maybe_unused]] std::string_view const transformationName) +{ +} + void UndefinedLiteral::Iterate([[maybe_unused]] const NodeTraverser &cb) const {} void UndefinedLiteral::Dump(ir::AstDumper *dumper) const diff --git a/ets2panda/ir/expressions/literals/undefinedLiteral.h b/ets2panda/ir/expressions/literals/undefinedLiteral.h index e011b1bdd307d867f84f545c7b1eb0f76fc451c8..d38db7de7fc4208b4cb0e812cc53f18ca9c87b29 100644 --- a/ets2panda/ir/expressions/literals/undefinedLiteral.h +++ b/ets2panda/ir/expressions/literals/undefinedLiteral.h @@ -30,7 +30,7 @@ public: [[nodiscard]] UndefinedLiteral *Clone(ArenaAllocator *allocator, AstNode *parent) override; - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/expressions/memberExpression.cpp b/ets2panda/ir/expressions/memberExpression.cpp index 94b6931ec23978b2389cb97d06a3b843cf27da14..b3fabfcd8aaa5fde66a721acfca02b3e21d92173 100644 --- a/ets2panda/ir/expressions/memberExpression.cpp +++ b/ets2panda/ir/expressions/memberExpression.cpp @@ -37,10 +37,17 @@ bool MemberExpression::IsPrivateReference() const noexcept return property_->IsIdentifier() && property_->AsIdentifier()->IsPrivateIdent(); } -void MemberExpression::TransformChildren(const NodeTransformer &cb) +void MemberExpression::TransformChildren(const NodeTransformer &cb, std::string_view const transformationName) { - object_ = cb(object_)->AsExpression(); - property_ = cb(property_)->AsExpression(); + if (auto *transformedNode = cb(object_); object_ != transformedNode) { + object_->SetTransformedNode(transformationName, transformedNode); + object_ = transformedNode->AsExpression(); + } + + if (auto *transformedNode = cb(property_); property_ != transformedNode) { + property_->SetTransformedNode(transformationName, transformedNode); + property_ = transformedNode->AsExpression(); + } } void MemberExpression::Iterate(const NodeTraverser &cb) const diff --git a/ets2panda/ir/expressions/memberExpression.h b/ets2panda/ir/expressions/memberExpression.h index 7fae0d0ab579f057408e5202b4116c3f76bb01f9..399179f1679997511e5785aac99fe7cde772425b 100644 --- a/ets2panda/ir/expressions/memberExpression.h +++ b/ets2panda/ir/expressions/memberExpression.h @@ -176,7 +176,7 @@ public: [[nodiscard]] MemberExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/expressions/newExpression.cpp b/ets2panda/ir/expressions/newExpression.cpp index e5489c93bef6d17f33c7e9a8a8b8c74d9cde6625..5cf94d3579d0d24f4c5ed0d6d43756397b8bf2f1 100644 --- a/ets2panda/ir/expressions/newExpression.cpp +++ b/ets2panda/ir/expressions/newExpression.cpp @@ -47,12 +47,18 @@ NewExpression *NewExpression::Clone(ArenaAllocator *const allocator, AstNode *co throw Error(ErrorType::GENERIC, "", CLONE_ALLOCATION_ERROR); } -void NewExpression::TransformChildren(const NodeTransformer &cb) +void NewExpression::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { - callee_ = cb(callee_)->AsExpression(); + if (auto *transformedNode = cb(callee_); callee_ != transformedNode) { + callee_->SetTransformedNode(transformationName, transformedNode); + callee_ = transformedNode->AsExpression(); + } for (auto *&it : arguments_) { - it = cb(it)->AsExpression(); + if (auto *transformedNode = cb(it); it != transformedNode) { + it->SetTransformedNode(transformationName, transformedNode); + it = transformedNode->AsExpression(); + } } } diff --git a/ets2panda/ir/expressions/newExpression.h b/ets2panda/ir/expressions/newExpression.h index 46e9bb40ea5a5ce915d1302ea592a57e17636b22..b79c384a1aa3746d306889266f4e72f2ae2ac701 100644 --- a/ets2panda/ir/expressions/newExpression.h +++ b/ets2panda/ir/expressions/newExpression.h @@ -55,7 +55,7 @@ public: [[nodiscard]] NewExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/expressions/objectExpression.cpp b/ets2panda/ir/expressions/objectExpression.cpp index c7704b0f29a5fc27dc4f845ed32d3dc11bf8c00b..7882cc2db0e35fc543025a59a93c114d3ba3e390 100644 --- a/ets2panda/ir/expressions/objectExpression.cpp +++ b/ets2panda/ir/expressions/objectExpression.cpp @@ -30,19 +30,11 @@ #include "ir/base/property.h" #include "ir/base/scriptFunction.h" #include "ir/base/spreadElement.h" -#include "ir/ets/etsTypeReference.h" -#include "ir/ets/etsTypeReferencePart.h" -#include "ir/ets/etsNewClassInstanceExpression.h" #include "ir/expressions/arrayExpression.h" #include "ir/expressions/assignmentExpression.h" -#include "ir/expressions/functionExpression.h" #include "ir/expressions/identifier.h" -#include "ir/expressions/literals/nullLiteral.h" -#include "ir/expressions/literals/stringLiteral.h" -#include "ir/expressions/literals/numberLiteral.h" #include "ir/statements/variableDeclarator.h" #include "ir/validationInfo.h" -#include "util/bitset.h" namespace ark::es2panda::ir { ObjectExpression::ObjectExpression([[maybe_unused]] Tag const tag, ObjectExpression const &other, @@ -190,18 +182,27 @@ void ObjectExpression::SetOptional(bool optional) optional_ = optional; } -void ObjectExpression::TransformChildren(const NodeTransformer &cb) +void ObjectExpression::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { for (auto *&it : decorators_) { - it = cb(it)->AsDecorator(); + if (auto *transformedNode = cb(it); it != transformedNode) { + it->SetTransformedNode(transformationName, transformedNode); + it = transformedNode->AsDecorator(); + } } for (auto *&it : properties_) { - it = cb(it)->AsExpression(); + if (auto *transformedNode = cb(it); it != transformedNode) { + it->SetTransformedNode(transformationName, transformedNode); + it = transformedNode->AsExpression(); + } } - if (TypeAnnotation() != nullptr) { - SetTsTypeAnnotation(static_cast(cb(TypeAnnotation()))); + if (auto *typeAnnotation = TypeAnnotation(); typeAnnotation != nullptr) { + if (auto *transformedNode = cb(typeAnnotation); typeAnnotation != transformedNode) { + typeAnnotation->SetTransformedNode(transformationName, transformedNode); + SetTsTypeAnnotation(static_cast(transformedNode)); + } } } diff --git a/ets2panda/ir/expressions/objectExpression.h b/ets2panda/ir/expressions/objectExpression.h index e5ebc5f3bfd2005a9898a457b16106b868624199..9386e2dc0633aaa0d45511fb64696ee8419ab5e9 100644 --- a/ets2panda/ir/expressions/objectExpression.h +++ b/ets2panda/ir/expressions/objectExpression.h @@ -102,7 +102,7 @@ public: [[nodiscard]] bool ConvertibleToObjectPattern(); void SetDeclaration(); void SetOptional(bool optional); - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/expressions/omittedExpression.cpp b/ets2panda/ir/expressions/omittedExpression.cpp index 749605da9a30e51645f5d55da3bc7761354c9f45..a9b76bf21cb0373f6f716adfdc346faeded9cd95 100644 --- a/ets2panda/ir/expressions/omittedExpression.cpp +++ b/ets2panda/ir/expressions/omittedExpression.cpp @@ -22,7 +22,11 @@ #include "ir/srcDump.h" namespace ark::es2panda::ir { -void OmittedExpression::TransformChildren([[maybe_unused]] const NodeTransformer &cb) {} +void OmittedExpression::TransformChildren([[maybe_unused]] const NodeTransformer &cb, + [[maybe_unused]] std::string_view const transformationName) +{ +} + void OmittedExpression::Iterate([[maybe_unused]] const NodeTraverser &cb) const {} void OmittedExpression::Dump(ir::AstDumper *dumper) const diff --git a/ets2panda/ir/expressions/omittedExpression.h b/ets2panda/ir/expressions/omittedExpression.h index 8f5a37d511b5f8a41a1fa7ef8903b0490b43558a..f210c6bee7b33c2ea93de8230e6125da259c7659 100644 --- a/ets2panda/ir/expressions/omittedExpression.h +++ b/ets2panda/ir/expressions/omittedExpression.h @@ -28,7 +28,7 @@ public: explicit OmittedExpression() : Expression(AstNodeType::OMITTED_EXPRESSION) {} - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; [[nodiscard]] OmittedExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; diff --git a/ets2panda/ir/expressions/sequenceExpression.cpp b/ets2panda/ir/expressions/sequenceExpression.cpp index 61fb0fd1c328b6385f640425f5450a84e8765889..22f63f8cf7491dd25e05af6d3ddf930d1fb355cc 100644 --- a/ets2panda/ir/expressions/sequenceExpression.cpp +++ b/ets2panda/ir/expressions/sequenceExpression.cpp @@ -43,10 +43,13 @@ SequenceExpression *SequenceExpression::Clone(ArenaAllocator *const allocator, A throw Error(ErrorType::GENERIC, "", CLONE_ALLOCATION_ERROR); } -void SequenceExpression::TransformChildren(const NodeTransformer &cb) +void SequenceExpression::TransformChildren(const NodeTransformer &cb, std::string_view const transformationName) { for (auto *&it : sequence_) { - it = cb(it)->AsExpression(); + if (auto *transformedNode = cb(it); it != transformedNode) { + it->SetTransformedNode(transformationName, transformedNode); + it = transformedNode->AsExpression(); + } } } diff --git a/ets2panda/ir/expressions/sequenceExpression.h b/ets2panda/ir/expressions/sequenceExpression.h index b7fa57717e90e70e738e6dcd11a7d28fcd9b3d00..9ea96d2b5e33a5a190a20016ad5872bb3cde2acc 100644 --- a/ets2panda/ir/expressions/sequenceExpression.h +++ b/ets2panda/ir/expressions/sequenceExpression.h @@ -49,7 +49,7 @@ public: [[nodiscard]] SequenceExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/expressions/superExpression.cpp b/ets2panda/ir/expressions/superExpression.cpp index 51de4e9f2c5ea4f2a82c3d50f8eb8765d26cc88c..98af08a26b41ecac3b99db77b8cc5d647961d1cb 100644 --- a/ets2panda/ir/expressions/superExpression.cpp +++ b/ets2panda/ir/expressions/superExpression.cpp @@ -24,7 +24,11 @@ #include "ir/srcDump.h" namespace ark::es2panda::ir { -void SuperExpression::TransformChildren([[maybe_unused]] const NodeTransformer &cb) {} +void SuperExpression::TransformChildren([[maybe_unused]] const NodeTransformer &cb, + [[maybe_unused]] std::string_view const transformationName) +{ +} + void SuperExpression::Iterate([[maybe_unused]] const NodeTraverser &cb) const {} void SuperExpression::Dump(ir::AstDumper *dumper) const diff --git a/ets2panda/ir/expressions/superExpression.h b/ets2panda/ir/expressions/superExpression.h index a830f5165233a6baf1a6eefb9589330f26945f5f..982c67d0abf957a7e2344dc394e5227098cd5e47 100644 --- a/ets2panda/ir/expressions/superExpression.h +++ b/ets2panda/ir/expressions/superExpression.h @@ -30,7 +30,7 @@ public: [[nodiscard]] SuperExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/expressions/taggedTemplateExpression.cpp b/ets2panda/ir/expressions/taggedTemplateExpression.cpp index 019a4cad1e5da9af9bed158e9a564e21ab68ef79..3f00a6b12be543a73e5fd9a3865de35afc1cc252 100644 --- a/ets2panda/ir/expressions/taggedTemplateExpression.cpp +++ b/ets2panda/ir/expressions/taggedTemplateExpression.cpp @@ -23,19 +23,28 @@ #include "checker/TSchecker.h" #include "ir/astDump.h" #include "ir/srcDump.h" -#include "ir/expressions/memberExpression.h" #include "ir/expressions/templateLiteral.h" #include "ir/ts/tsTypeParameterInstantiation.h" namespace ark::es2panda::ir { -void TaggedTemplateExpression::TransformChildren(const NodeTransformer &cb) +void TaggedTemplateExpression::TransformChildren(const NodeTransformer &cb, std::string_view const transformationName) { if (typeParams_ != nullptr) { - typeParams_ = cb(typeParams_)->AsTSTypeParameterInstantiation(); + if (auto *transformedNode = cb(typeParams_); typeParams_ != transformedNode) { + typeParams_->SetTransformedNode(transformationName, transformedNode); + typeParams_ = transformedNode->AsTSTypeParameterInstantiation(); + } + } + + if (auto *transformedNode = cb(tag_); tag_ != transformedNode) { + tag_->SetTransformedNode(transformationName, transformedNode); + tag_ = transformedNode->AsExpression(); } - tag_ = cb(tag_)->AsExpression(); - quasi_ = cb(quasi_)->AsTemplateLiteral(); + if (auto *transformedNode = cb(quasi_); quasi_ != transformedNode) { + quasi_->SetTransformedNode(transformationName, transformedNode); + quasi_ = transformedNode->AsTemplateLiteral(); + } } void TaggedTemplateExpression::Iterate(const NodeTraverser &cb) const diff --git a/ets2panda/ir/expressions/taggedTemplateExpression.h b/ets2panda/ir/expressions/taggedTemplateExpression.h index 591b0a1f3f93685768ea9adbe7b8bde7a62028a8..ca71b0784fdb92a047145d5114867be6e71b481e 100644 --- a/ets2panda/ir/expressions/taggedTemplateExpression.h +++ b/ets2panda/ir/expressions/taggedTemplateExpression.h @@ -52,7 +52,7 @@ public: [[nodiscard]] TaggedTemplateExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/expressions/templateLiteral.cpp b/ets2panda/ir/expressions/templateLiteral.cpp index c282559ca9351b726f33ce9fd493338f638b60db..2e3979d492aaeb2e2c8b4e56a297436842a43694 100644 --- a/ets2panda/ir/expressions/templateLiteral.cpp +++ b/ets2panda/ir/expressions/templateLiteral.cpp @@ -50,14 +50,20 @@ TemplateLiteral *TemplateLiteral::Clone(ArenaAllocator *const allocator, AstNode throw Error(ErrorType::GENERIC, "", CLONE_ALLOCATION_ERROR); } -void TemplateLiteral::TransformChildren(const NodeTransformer &cb) +void TemplateLiteral::TransformChildren(const NodeTransformer &cb, std::string_view const transformationName) { for (auto *&it : expressions_) { - it = cb(it)->AsExpression(); + if (auto *transformedNode = cb(it); it != transformedNode) { + it->SetTransformedNode(transformationName, transformedNode); + it = transformedNode->AsExpression(); + } } for (auto *&it : quasis_) { - it = cb(it)->AsTemplateElement(); + if (auto *transformedNode = cb(it); it != transformedNode) { + it->SetTransformedNode(transformationName, transformedNode); + it = transformedNode->AsTemplateElement(); + } } } diff --git a/ets2panda/ir/expressions/templateLiteral.h b/ets2panda/ir/expressions/templateLiteral.h index 45a4a3fadc55e2271bef6589c06fe3342ec12e4e..1adad2f0332c504f6c7fc1f38351d6822c48da7d 100644 --- a/ets2panda/ir/expressions/templateLiteral.h +++ b/ets2panda/ir/expressions/templateLiteral.h @@ -50,7 +50,7 @@ public: [[nodiscard]] TemplateLiteral *Clone(ArenaAllocator *allocator, AstNode *parent) override; - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/expressions/thisExpression.cpp b/ets2panda/ir/expressions/thisExpression.cpp index 5a9c370edcf467c2d3c85e31305cfb4441b47211..38db4296522ec1ddb138e2432e43546748aa42e9 100644 --- a/ets2panda/ir/expressions/thisExpression.cpp +++ b/ets2panda/ir/expressions/thisExpression.cpp @@ -21,16 +21,15 @@ #include "compiler/core/ETSGen.h" #include "checker/TSchecker.h" #include "checker/ETSchecker.h" -#include "ir/base/classDefinition.h" -#include "ir/base/scriptFunction.h" -#include "ir/base/methodDefinition.h" -#include "ir/statements/blockStatement.h" #include "ir/astDump.h" #include "ir/srcDump.h" -#include "ir/expressions/callExpression.h" namespace ark::es2panda::ir { -void ThisExpression::TransformChildren([[maybe_unused]] const NodeTransformer &cb) {} +void ThisExpression::TransformChildren([[maybe_unused]] const NodeTransformer &cb, + [[maybe_unused]] std::string_view const transformationName) +{ +} + void ThisExpression::Iterate([[maybe_unused]] const NodeTraverser &cb) const {} void ThisExpression::Dump(ir::AstDumper *dumper) const diff --git a/ets2panda/ir/expressions/thisExpression.h b/ets2panda/ir/expressions/thisExpression.h index 3fdb08595269d28a7eca66919500fc426d4ab67a..07f42ca31cc69dfc107ad03dcd2cc788b801b038 100644 --- a/ets2panda/ir/expressions/thisExpression.h +++ b/ets2panda/ir/expressions/thisExpression.h @@ -30,7 +30,7 @@ public: [[nodiscard]] ThisExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/expressions/typeofExpression.cpp b/ets2panda/ir/expressions/typeofExpression.cpp index 2b2f813fd4b5f2f4a9ee9fcde7a680cf89ee2283..83cdd2d63c5b736460dd0a1814be8d5ceac3aeda 100644 --- a/ets2panda/ir/expressions/typeofExpression.cpp +++ b/ets2panda/ir/expressions/typeofExpression.cpp @@ -23,10 +23,14 @@ #include "ir/srcDump.h" namespace ark::es2panda::ir { -void TypeofExpression::TransformChildren([[maybe_unused]] const NodeTransformer &cb) +void TypeofExpression::TransformChildren(const NodeTransformer &cb, std::string_view const transformationName) { - argument_ = cb(argument_)->AsExpression(); + if (auto *transformedNode = cb(argument_); argument_ != transformedNode) { + argument_->SetTransformedNode(transformationName, transformedNode); + argument_ = transformedNode->AsExpression(); + } } + void TypeofExpression::Iterate([[maybe_unused]] const NodeTraverser &cb) const { cb(argument_); diff --git a/ets2panda/ir/expressions/typeofExpression.h b/ets2panda/ir/expressions/typeofExpression.h index e9704675a52e2f5434b988a175d12d2b18137fa8..94b25b1b852ef57d543dce2f4217da135b4c9084 100644 --- a/ets2panda/ir/expressions/typeofExpression.h +++ b/ets2panda/ir/expressions/typeofExpression.h @@ -39,7 +39,7 @@ public: // NOLINTNEXTLINE(default-arguments) [[nodiscard]] TypeofExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/expressions/unaryExpression.cpp b/ets2panda/ir/expressions/unaryExpression.cpp index 8b0478c8ea7baa017af13ea5862afe1f1242f380..3e018224dbd463a0d7778c94b219219afe164df8 100644 --- a/ets2panda/ir/expressions/unaryExpression.cpp +++ b/ets2panda/ir/expressions/unaryExpression.cpp @@ -22,9 +22,12 @@ #include "ir/astDump.h" namespace ark::es2panda::ir { -void UnaryExpression::TransformChildren(const NodeTransformer &cb) +void UnaryExpression::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { - argument_ = cb(argument_)->AsExpression(); + if (auto *transformedNode = cb(argument_); argument_ != transformedNode) { + argument_->SetTransformedNode(transformationName, transformedNode); + argument_ = transformedNode->AsExpression(); + } } void UnaryExpression::Iterate(const NodeTraverser &cb) const diff --git a/ets2panda/ir/expressions/unaryExpression.h b/ets2panda/ir/expressions/unaryExpression.h index 94c3f00a825ca0848d1706a150d893b9b989bf46..d9baf207f29e3fcd1e1d6a567602f7e3dcb0615d 100644 --- a/ets2panda/ir/expressions/unaryExpression.h +++ b/ets2panda/ir/expressions/unaryExpression.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 - 2024 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 @@ -65,7 +65,7 @@ public: [[nodiscard]] UnaryExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/expressions/updateExpression.cpp b/ets2panda/ir/expressions/updateExpression.cpp index 68a08f29953155034c40c67cd34e88dc9cc062b4..580d4f0203656a9b9debd620ff3af2bbdeee53cf 100644 --- a/ets2panda/ir/expressions/updateExpression.cpp +++ b/ets2panda/ir/expressions/updateExpression.cpp @@ -26,14 +26,14 @@ #include "ir/astDump.h" #include "ir/srcDump.h" #include "ir/expressions/unaryExpression.h" -#include "ir/ts/tsAsExpression.h" -#include "ir/expressions/identifier.h" -#include "ir/expressions/memberExpression.h" namespace ark::es2panda::ir { -void UpdateExpression::TransformChildren(const NodeTransformer &cb) +void UpdateExpression::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { - argument_ = cb(argument_)->AsExpression(); + if (auto *transformedNode = cb(argument_); argument_ != transformedNode) { + argument_->SetTransformedNode(transformationName, transformedNode); + argument_ = transformedNode->AsExpression(); + } } void UpdateExpression::Iterate(const NodeTraverser &cb) const diff --git a/ets2panda/ir/expressions/updateExpression.h b/ets2panda/ir/expressions/updateExpression.h index 510ad313dfbb861577a7c2afd9d87c741a21c161..3d1c641ad3efe2b7cc84f64d0bffc8605654a3ed 100644 --- a/ets2panda/ir/expressions/updateExpression.h +++ b/ets2panda/ir/expressions/updateExpression.h @@ -64,7 +64,7 @@ public: [[nodiscard]] UpdateExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/expressions/yieldExpression.cpp b/ets2panda/ir/expressions/yieldExpression.cpp index 1d435c224c93c9c31c756af3dbd653b51b738d7e..37cc476a5f8239c705a2312e696b6f23e5065967 100644 --- a/ets2panda/ir/expressions/yieldExpression.cpp +++ b/ets2panda/ir/expressions/yieldExpression.cpp @@ -23,10 +23,13 @@ #include "ir/srcDump.h" namespace ark::es2panda::ir { -void YieldExpression::TransformChildren(const NodeTransformer &cb) +void YieldExpression::TransformChildren(const NodeTransformer &cb, std::string_view const transformationName) { if (argument_ != nullptr) { - argument_ = cb(argument_)->AsExpression(); + if (auto *transformedNode = cb(argument_); argument_ != transformedNode) { + argument_->SetTransformedNode(transformationName, transformedNode); + argument_ = transformedNode->AsExpression(); + } } } diff --git a/ets2panda/ir/expressions/yieldExpression.h b/ets2panda/ir/expressions/yieldExpression.h index d097a488f31e51ee177629563a15a10d59d194d5..171d68607e23b8c2af4448cac011e824897192d4 100644 --- a/ets2panda/ir/expressions/yieldExpression.h +++ b/ets2panda/ir/expressions/yieldExpression.h @@ -48,7 +48,7 @@ public: [[nodiscard]] YieldExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/module/exportAllDeclaration.cpp b/ets2panda/ir/module/exportAllDeclaration.cpp index a2c5cf1fb0f8a73a093e4e9b7e3787cdd6479bef..2ea23fa2bb289624e74bd6847f326d9cdc8a9a98 100644 --- a/ets2panda/ir/module/exportAllDeclaration.cpp +++ b/ets2panda/ir/module/exportAllDeclaration.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021-2022 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 @@ -22,12 +22,18 @@ #include "ir/srcDump.h" namespace ark::es2panda::ir { -void ExportAllDeclaration::TransformChildren(const NodeTransformer &cb) +void ExportAllDeclaration::TransformChildren(const NodeTransformer &cb, std::string_view const transformationName) { - source_ = cb(source_)->AsStringLiteral(); + if (auto *transformedNode = cb(source_); source_ != transformedNode) { + source_->SetTransformedNode(transformationName, transformedNode); + source_ = transformedNode->AsStringLiteral(); + } if (exported_ != nullptr) { - exported_ = cb(exported_)->AsIdentifier(); + if (auto *transformedNode = cb(exported_); exported_ != transformedNode) { + exported_->SetTransformedNode(transformationName, transformedNode); + exported_ = transformedNode->AsIdentifier(); + } } } diff --git a/ets2panda/ir/module/exportAllDeclaration.h b/ets2panda/ir/module/exportAllDeclaration.h index 4321911490001a7bf4a5a968557148e07d75ea3d..b718a56ee799ad2fb8d83bd461862124cb96781d 100644 --- a/ets2panda/ir/module/exportAllDeclaration.h +++ b/ets2panda/ir/module/exportAllDeclaration.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 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 @@ -39,7 +39,7 @@ public: return exported_; } - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/module/exportDefaultDeclaration.cpp b/ets2panda/ir/module/exportDefaultDeclaration.cpp index 168c4db7457f0115f902fa560edf3d29877d75c5..fffdde9341678fd550133f72728bbbb3a3a8f492 100644 --- a/ets2panda/ir/module/exportDefaultDeclaration.cpp +++ b/ets2panda/ir/module/exportDefaultDeclaration.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021-2022 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 @@ -22,9 +22,12 @@ #include "ir/srcDump.h" namespace ark::es2panda::ir { -void ExportDefaultDeclaration::TransformChildren(const NodeTransformer &cb) +void ExportDefaultDeclaration::TransformChildren(const NodeTransformer &cb, std::string_view const transformationName) { - decl_ = cb(decl_); + if (auto *transformedNode = cb(decl_); decl_ != transformedNode) { + decl_->SetTransformedNode(transformationName, transformedNode); + decl_ = transformedNode; + } } void ExportDefaultDeclaration::Iterate(const NodeTraverser &cb) const diff --git a/ets2panda/ir/module/exportDefaultDeclaration.h b/ets2panda/ir/module/exportDefaultDeclaration.h index 302e2c549dcafe9bc3d8f868aba44746f1d09da9..0e4595b6eec4e7ce574fe62b2fc5dbb127c98fa9 100644 --- a/ets2panda/ir/module/exportDefaultDeclaration.h +++ b/ets2panda/ir/module/exportDefaultDeclaration.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 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 @@ -41,7 +41,7 @@ public: return exportEquals_; } - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/module/exportNamedDeclaration.cpp b/ets2panda/ir/module/exportNamedDeclaration.cpp index 07de0d2e241e41df5a093741fa70fa33eb49b094..77f1df112165726b46a32dd4e6a21784492fc9a3 100644 --- a/ets2panda/ir/module/exportNamedDeclaration.cpp +++ b/ets2panda/ir/module/exportNamedDeclaration.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 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 @@ -22,21 +22,33 @@ #include "ir/srcDump.h" namespace ark::es2panda::ir { -void ExportNamedDeclaration::TransformChildren(const NodeTransformer &cb) +void ExportNamedDeclaration::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { for (auto *&it : decorators_) { - it = cb(it)->AsDecorator(); + if (auto *transformedNode = cb(it); it != transformedNode) { + it->SetTransformedNode(transformationName, transformedNode); + it = transformedNode->AsDecorator(); + } } if (decl_ != nullptr) { - decl_ = cb(decl_); + if (auto *transformedNode = cb(decl_); decl_ != transformedNode) { + decl_->SetTransformedNode(transformationName, transformedNode); + decl_ = transformedNode; + } } else { if (source_ != nullptr) { - source_ = cb(source_)->AsStringLiteral(); + if (auto *transformedNode = cb(source_); source_ != transformedNode) { + source_->SetTransformedNode(transformationName, transformedNode); + source_ = transformedNode->AsStringLiteral(); + } } for (auto *&it : specifiers_) { - it = cb(it)->AsExportSpecifier(); + if (auto *transformedNode = cb(it); it != transformedNode) { + it->SetTransformedNode(transformationName, transformedNode); + it = transformedNode->AsExportSpecifier(); + } } } } diff --git a/ets2panda/ir/module/exportNamedDeclaration.h b/ets2panda/ir/module/exportNamedDeclaration.h index fa661a7f9a8e9a2047250b69389b933171110429..57c0fc2f577c7e3f517e7564667e2c5fbb1233e3 100644 --- a/ets2panda/ir/module/exportNamedDeclaration.h +++ b/ets2panda/ir/module/exportNamedDeclaration.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 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 @@ -75,7 +75,7 @@ public: return !inTs && (source_ == nullptr); } - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/module/exportSpecifier.cpp b/ets2panda/ir/module/exportSpecifier.cpp index cbb0e2d168617671d5f88c7f9ce3365faaf187b1..a162f55330aa3eb67171eec4189281bdf3eb2ca5 100644 --- a/ets2panda/ir/module/exportSpecifier.cpp +++ b/ets2panda/ir/module/exportSpecifier.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 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 @@ -22,10 +22,17 @@ #include "ir/srcDump.h" namespace ark::es2panda::ir { -void ExportSpecifier::TransformChildren(const NodeTransformer &cb) +void ExportSpecifier::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { - local_ = cb(local_)->AsIdentifier(); - exported_ = cb(exported_)->AsIdentifier(); + if (auto *transformedNode = cb(local_); local_ != transformedNode) { + local_->SetTransformedNode(transformationName, transformedNode); + local_ = transformedNode->AsIdentifier(); + } + + if (auto *transformedNode = cb(exported_); exported_ != transformedNode) { + exported_->SetTransformedNode(transformationName, transformedNode); + exported_ = transformedNode->AsIdentifier(); + } } void ExportSpecifier::Iterate(const NodeTraverser &cb) const diff --git a/ets2panda/ir/module/exportSpecifier.h b/ets2panda/ir/module/exportSpecifier.h index f001816fc15c75cf974ccadcd6668af15d3f0b04..a58e5deb371be00fb4ccacbc27c064c948699198 100644 --- a/ets2panda/ir/module/exportSpecifier.h +++ b/ets2panda/ir/module/exportSpecifier.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 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 @@ -38,7 +38,7 @@ public: return exported_; } - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/module/importDeclaration.cpp b/ets2panda/ir/module/importDeclaration.cpp index 5db4eb5c1625d06298e762957abb2798836880a9..aa25c7a4f7633b879d07a939275e0577632f7940 100644 --- a/ets2panda/ir/module/importDeclaration.cpp +++ b/ets2panda/ir/module/importDeclaration.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021-2022 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 @@ -22,12 +22,18 @@ #include "ir/srcDump.h" namespace ark::es2panda::ir { -void ImportDeclaration::TransformChildren(const NodeTransformer &cb) +void ImportDeclaration::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { - source_ = cb(source_)->AsStringLiteral(); + if (auto *transformedNode = cb(source_); source_ != transformedNode) { + source_->SetTransformedNode(transformationName, transformedNode); + source_ = transformedNode->AsStringLiteral(); + } for (auto *&it : specifiers_) { - it = cb(it); + if (auto *transformedNode = cb(it); it != transformedNode) { + it->SetTransformedNode(transformationName, transformedNode); + it = transformedNode; + } } } diff --git a/ets2panda/ir/module/importDeclaration.h b/ets2panda/ir/module/importDeclaration.h index f81e53f1ba452b3034a9005e044eb3a19f2a1799..792493562f957db27a437d8ce9d8a22fb0a50fde 100644 --- a/ets2panda/ir/module/importDeclaration.h +++ b/ets2panda/ir/module/importDeclaration.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 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 @@ -44,7 +44,7 @@ public: return specifiers_; } - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/module/importDefaultSpecifier.cpp b/ets2panda/ir/module/importDefaultSpecifier.cpp index 524b961622bba720e1ea9030b87f48425da4db6a..1305070d8cf302ac78298f9dbde6f62d3221d5b5 100644 --- a/ets2panda/ir/module/importDefaultSpecifier.cpp +++ b/ets2panda/ir/module/importDefaultSpecifier.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021-2022 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 @@ -22,9 +22,12 @@ #include "ir/srcDump.h" namespace ark::es2panda::ir { -void ImportDefaultSpecifier::TransformChildren(const NodeTransformer &cb) +void ImportDefaultSpecifier::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { - local_ = cb(local_)->AsIdentifier(); + if (auto *transformedNode = cb(local_); local_ != transformedNode) { + local_->SetTransformedNode(transformationName, transformedNode); + local_ = transformedNode->AsIdentifier(); + } } void ImportDefaultSpecifier::Iterate(const NodeTraverser &cb) const diff --git a/ets2panda/ir/module/importDefaultSpecifier.h b/ets2panda/ir/module/importDefaultSpecifier.h index ed47e4857b8d54dfbaedc6f6611422fc5b03c9ff..5d42bd6933e3c4e3205776b965395bab215063d5 100644 --- a/ets2panda/ir/module/importDefaultSpecifier.h +++ b/ets2panda/ir/module/importDefaultSpecifier.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 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 @@ -32,7 +32,7 @@ public: return local_; } - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/module/importNamespaceSpecifier.cpp b/ets2panda/ir/module/importNamespaceSpecifier.cpp index e39a5254a50c7b1018a483a1553cff496d53eaa6..66af4afaa20fe004d80a54d20d820da384295f18 100644 --- a/ets2panda/ir/module/importNamespaceSpecifier.cpp +++ b/ets2panda/ir/module/importNamespaceSpecifier.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021-2022 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 @@ -15,7 +15,6 @@ #include "importNamespaceSpecifier.h" -#include "varbinder/ETSBinder.h" #include "checker/TSchecker.h" #include "compiler/core/ETSGen.h" #include "compiler/core/pandagen.h" @@ -23,9 +22,12 @@ #include "ir/srcDump.h" namespace ark::es2panda::ir { -void ImportNamespaceSpecifier::TransformChildren(const NodeTransformer &cb) +void ImportNamespaceSpecifier::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { - local_ = cb(local_)->AsIdentifier(); + if (auto *transformedNode = cb(local_); local_ != transformedNode) { + local_->SetTransformedNode(transformationName, transformedNode); + local_ = transformedNode->AsIdentifier(); + } } void ImportNamespaceSpecifier::Iterate(const NodeTraverser &cb) const diff --git a/ets2panda/ir/module/importNamespaceSpecifier.h b/ets2panda/ir/module/importNamespaceSpecifier.h index 8bd07cfe8acc71bff401f99a2d12f5e9352cc26a..baabf731f004ba7b99d42614c688951a78c95810 100644 --- a/ets2panda/ir/module/importNamespaceSpecifier.h +++ b/ets2panda/ir/module/importNamespaceSpecifier.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 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 @@ -38,7 +38,7 @@ public: return local_; } - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/module/importSpecifier.cpp b/ets2panda/ir/module/importSpecifier.cpp index b408f75183231e2d207859e67f7dd4733ff67081..7e080cf1a5b3eb2053fc99463aae940334c77c5d 100644 --- a/ets2panda/ir/module/importSpecifier.cpp +++ b/ets2panda/ir/module/importSpecifier.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 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 @@ -22,12 +22,19 @@ #include "ir/srcDump.h" namespace ark::es2panda::ir { -void ImportSpecifier::TransformChildren(const NodeTransformer &cb) +void ImportSpecifier::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { if (local_ != nullptr) { - local_ = cb(local_)->AsIdentifier(); + if (auto *transformedNode = cb(local_); local_ != transformedNode) { + local_->SetTransformedNode(transformationName, transformedNode); + local_ = transformedNode->AsIdentifier(); + } + } + + if (auto *transformedNode = cb(imported_); imported_ != transformedNode) { + imported_->SetTransformedNode(transformationName, transformedNode); + imported_ = transformedNode->AsIdentifier(); } - imported_ = cb(imported_)->AsIdentifier(); } void ImportSpecifier::Iterate(const NodeTraverser &cb) const diff --git a/ets2panda/ir/module/importSpecifier.h b/ets2panda/ir/module/importSpecifier.h index d9eed5901eab043aa2fc7808baa06d54963e256b..4375bfb7650f648ed28e53d6817d7a7c574c88bc 100644 --- a/ets2panda/ir/module/importSpecifier.h +++ b/ets2panda/ir/module/importSpecifier.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 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 @@ -48,7 +48,7 @@ public: return local_; } - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/opaqueTypeNode.cpp b/ets2panda/ir/opaqueTypeNode.cpp index 31ac46a1dc5dfadb1992a2d32cdf1f6016387992..dc1795205569563cf2eaac470ae712a2b9e447e3 100644 --- a/ets2panda/ir/opaqueTypeNode.cpp +++ b/ets2panda/ir/opaqueTypeNode.cpp @@ -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 @@ -22,7 +22,11 @@ namespace ark::es2panda::ir { -void OpaqueTypeNode::TransformChildren([[maybe_unused]] const NodeTransformer &cb) {} +void OpaqueTypeNode::TransformChildren([[maybe_unused]] const NodeTransformer &cb, + [[maybe_unused]] std::string_view transformationName) +{ +} + void OpaqueTypeNode::Iterate([[maybe_unused]] const NodeTraverser &cb) const {} void OpaqueTypeNode::Dump(ir::AstDumper *dumper) const diff --git a/ets2panda/ir/opaqueTypeNode.h b/ets2panda/ir/opaqueTypeNode.h index 02c80d7ad00b415e2130eac5d1d5e225f9e75556..858de74ce9783addf1c2f401c3ab419aaac924ec 100644 --- a/ets2panda/ir/opaqueTypeNode.h +++ b/ets2panda/ir/opaqueTypeNode.h @@ -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 @@ -36,7 +36,7 @@ public: SetTsType(type); } - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/statements/assertStatement.cpp b/ets2panda/ir/statements/assertStatement.cpp index 055b64e4719a37f00cb93a5e82669ced3e5df49b..4c6a2b1c870afc59c78e3e3f2f12a801c6104ff9 100644 --- a/ets2panda/ir/statements/assertStatement.cpp +++ b/ets2panda/ir/statements/assertStatement.cpp @@ -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 @@ -26,12 +26,18 @@ #include "ir/expression.h" namespace ark::es2panda::ir { -void AssertStatement::TransformChildren(const NodeTransformer &cb) +void AssertStatement::TransformChildren(const NodeTransformer &cb, std::string_view const transformationName) { - test_ = cb(test_)->AsExpression(); + if (auto *transformedNode = cb(test_); test_ != transformedNode) { + test_->SetTransformedNode(transformationName, transformedNode); + test_ = transformedNode->AsExpression(); + } if (second_ != nullptr) { - second_ = cb(second_)->AsExpression(); + if (auto *transformedNode = cb(second_); second_ != transformedNode) { + second_->SetTransformedNode(transformationName, transformedNode); + second_ = transformedNode->AsExpression(); + } } } diff --git a/ets2panda/ir/statements/assertStatement.h b/ets2panda/ir/statements/assertStatement.h index 85f171d9709f7fab7f9bfe395293c61cef38bd69..02b60f3f4607ea566dc328eaad59dc22f36a7291 100644 --- a/ets2panda/ir/statements/assertStatement.h +++ b/ets2panda/ir/statements/assertStatement.h @@ -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 @@ -44,7 +44,7 @@ public: return second_; } - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/statements/blockStatement.cpp b/ets2panda/ir/statements/blockStatement.cpp index db63e4079c40d5566a61796572202452fea81bb9..5461bb236312c46068f028c29ac2de40a2ebf739 100644 --- a/ets2panda/ir/statements/blockStatement.cpp +++ b/ets2panda/ir/statements/blockStatement.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 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 @@ -15,7 +15,6 @@ #include "blockStatement.h" -#include "varbinder/scope.h" #include "compiler/core/pandagen.h" #include "compiler/core/regScope.h" #include "compiler/core/ETSGen.h" @@ -25,10 +24,13 @@ #include "ir/srcDump.h" namespace ark::es2panda::ir { -void BlockStatement::TransformChildren(const NodeTransformer &cb) +void BlockStatement::TransformChildren(const NodeTransformer &cb, std::string_view const transformationName) { for (auto *&it : statements_) { - it = cb(it)->AsStatement(); + if (auto *transformedNode = cb(it); it != transformedNode) { + it->SetTransformedNode(transformationName, transformedNode); + it = transformedNode->AsStatement(); + } } } diff --git a/ets2panda/ir/statements/blockStatement.h b/ets2panda/ir/statements/blockStatement.h index 5d2548470491b2909e6140520b32f056bb149cea..277f4ef156a1dc19d6b34b4c1f34ca1973ea91fd 100644 --- a/ets2panda/ir/statements/blockStatement.h +++ b/ets2panda/ir/statements/blockStatement.h @@ -35,17 +35,17 @@ public: // NOTE (somas): this friend relationship can be removed once there are getters for private fields friend class checker::ETSAnalyzer; - bool IsScopeBearer() const override + [[nodiscard]] bool IsScopeBearer() const noexcept override { return true; } - varbinder::Scope *Scope() const override + [[nodiscard]] varbinder::Scope *Scope() const noexcept override { return scope_; } - void SetScope(varbinder::Scope *scope) + void SetScope(varbinder::Scope *scope) noexcept { scope_ = scope; } @@ -65,7 +65,7 @@ public: trailingBlocks_.emplace(stmt, trailingBlock); } - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; diff --git a/ets2panda/ir/statements/breakStatement.cpp b/ets2panda/ir/statements/breakStatement.cpp index 104200716bbfef03bf0845db89c0367bbdb755a2..dbb225c75e46edc4f9273b5d33dee27641a725ec 100644 --- a/ets2panda/ir/statements/breakStatement.cpp +++ b/ets2panda/ir/statements/breakStatement.cpp @@ -23,10 +23,13 @@ #include "checker/ETSchecker.h" namespace ark::es2panda::ir { -void BreakStatement::TransformChildren(const NodeTransformer &cb) +void BreakStatement::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { if (ident_ != nullptr) { - ident_ = cb(ident_)->AsIdentifier(); + if (auto *transformedNode = cb(ident_); ident_ != transformedNode) { + ident_->SetTransformedNode(transformationName, transformedNode); + ident_ = transformedNode->AsIdentifier(); + } } } diff --git a/ets2panda/ir/statements/breakStatement.h b/ets2panda/ir/statements/breakStatement.h index 846235f277064795e584ee8b9c850b5c09faa569..f81c16a64dde997f448af7150ba686c4ed765ce9 100644 --- a/ets2panda/ir/statements/breakStatement.h +++ b/ets2panda/ir/statements/breakStatement.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 - 2024 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 @@ -54,7 +54,7 @@ public: target_ = target; } - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/statements/classDeclaration.cpp b/ets2panda/ir/statements/classDeclaration.cpp index 11557572dc64e7e837f3598277f9118ec09b445c..7a41c3ea61c61629686ad625aac6a27f3117e6e1 100644 --- a/ets2panda/ir/statements/classDeclaration.cpp +++ b/ets2panda/ir/statements/classDeclaration.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 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 @@ -22,13 +22,19 @@ #include "ir/srcDump.h" namespace ark::es2panda::ir { -void ClassDeclaration::TransformChildren(const NodeTransformer &cb) +void ClassDeclaration::TransformChildren(const NodeTransformer &cb, std::string_view const transformationName) { for (auto *&it : decorators_) { - it = cb(it)->AsDecorator(); + if (auto *transformedNode = cb(it); it != transformedNode) { + it->SetTransformedNode(transformationName, transformedNode); + it = transformedNode->AsDecorator(); + } } - def_ = cb(def_)->AsClassDefinition(); + if (auto *transformedNode = cb(def_); def_ != transformedNode) { + def_->SetTransformedNode(transformationName, transformedNode); + def_ = transformedNode->AsClassDefinition(); + } } void ClassDeclaration::Iterate(const NodeTraverser &cb) const diff --git a/ets2panda/ir/statements/classDeclaration.h b/ets2panda/ir/statements/classDeclaration.h index 1eeb2de6a05f6068ab68fd37a71fd7ac0c3af961..e1ebedd7b0f1c21cf4ca90191eff919cbc4bf5a0 100644 --- a/ets2panda/ir/statements/classDeclaration.h +++ b/ets2panda/ir/statements/classDeclaration.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 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 @@ -56,7 +56,7 @@ public: return true; } - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/statements/continueStatement.cpp b/ets2panda/ir/statements/continueStatement.cpp index d952b40801b62669a55bc178dd21407a62927fa1..cbe02eac679d728749a6e43c0013786cedbe74ec 100644 --- a/ets2panda/ir/statements/continueStatement.cpp +++ b/ets2panda/ir/statements/continueStatement.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021-2022 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 @@ -22,10 +22,13 @@ #include "ir/srcDump.h" namespace ark::es2panda::ir { -void ContinueStatement::TransformChildren(const NodeTransformer &cb) +void ContinueStatement::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { if (ident_ != nullptr) { - ident_ = cb(ident_)->AsIdentifier(); + if (auto *transformedNode = cb(ident_); ident_ != transformedNode) { + ident_->SetTransformedNode(transformationName, transformedNode); + ident_ = transformedNode->AsIdentifier(); + } } } diff --git a/ets2panda/ir/statements/continueStatement.h b/ets2panda/ir/statements/continueStatement.h index 8dbbc258f6db989aba690d45be01f29282fd6e91..c85725e0bb657ce55e7910e0723f142e5f4a3dda 100644 --- a/ets2panda/ir/statements/continueStatement.h +++ b/ets2panda/ir/statements/continueStatement.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 - 2024 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 @@ -53,7 +53,7 @@ public: target_ = target; } - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/statements/debuggerStatement.cpp b/ets2panda/ir/statements/debuggerStatement.cpp index f22e879c911921cf83d18df6396a179777def7b8..abe5372f5598acdf1d81b57bc3227be9951b8250 100644 --- a/ets2panda/ir/statements/debuggerStatement.cpp +++ b/ets2panda/ir/statements/debuggerStatement.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021-2022 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 @@ -22,7 +22,11 @@ #include "ir/srcDump.h" namespace ark::es2panda::ir { -void DebuggerStatement::TransformChildren([[maybe_unused]] const NodeTransformer &cb) {} +void DebuggerStatement::TransformChildren([[maybe_unused]] const NodeTransformer &cb, + [[maybe_unused]] std::string_view const transformationName) +{ +} + void DebuggerStatement::Iterate([[maybe_unused]] const NodeTraverser &cb) const {} void DebuggerStatement::Dump(ir::AstDumper *dumper) const diff --git a/ets2panda/ir/statements/debuggerStatement.h b/ets2panda/ir/statements/debuggerStatement.h index 949f6d6b7a99efc8cb92acbec89ef791e04f1627..bbdc227d77c85adfea02727e650ba7a5df8c6047 100644 --- a/ets2panda/ir/statements/debuggerStatement.h +++ b/ets2panda/ir/statements/debuggerStatement.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 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 @@ -23,7 +23,7 @@ class DebuggerStatement : public Statement { public: explicit DebuggerStatement() : Statement(AstNodeType::DEBUGGER_STATEMENT) {} - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/statements/doWhileStatement.cpp b/ets2panda/ir/statements/doWhileStatement.cpp index 334db9ac59c59633c6e9c592a92ebff4e32933ff..064ad9cff797c2692bf06da7748a1cbe7a177563 100644 --- a/ets2panda/ir/statements/doWhileStatement.cpp +++ b/ets2panda/ir/statements/doWhileStatement.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 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 @@ -26,10 +26,17 @@ #include "ir/srcDump.h" namespace ark::es2panda::ir { -void DoWhileStatement::TransformChildren(const NodeTransformer &cb) +void DoWhileStatement::TransformChildren(const NodeTransformer &cb, std::string_view const transformationName) { - body_ = cb(body_)->AsStatement(); - test_ = cb(test_)->AsExpression(); + if (auto *transformedNode = cb(body_); body_ != transformedNode) { + body_->SetTransformedNode(transformationName, transformedNode); + body_ = transformedNode->AsStatement(); + } + + if (auto *transformedNode = cb(test_); test_ != transformedNode) { + test_->SetTransformedNode(transformationName, transformedNode); + test_ = transformedNode->AsExpression(); + } } void DoWhileStatement::Iterate(const NodeTraverser &cb) const diff --git a/ets2panda/ir/statements/doWhileStatement.h b/ets2panda/ir/statements/doWhileStatement.h index 734fa981605b818681ff270044abf05e36d0ba63..e8dd4f6e07849a25839d97898936c2bfc5805394 100644 --- a/ets2panda/ir/statements/doWhileStatement.h +++ b/ets2panda/ir/statements/doWhileStatement.h @@ -52,7 +52,7 @@ public: return test_; } - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; diff --git a/ets2panda/ir/statements/emptyStatement.cpp b/ets2panda/ir/statements/emptyStatement.cpp index 59b3fb1722f3f9bb8af9b53b637c1b25a77cbf79..8337d9f4e8933bd53102d7e2379ded31a8e4ab4a 100644 --- a/ets2panda/ir/statements/emptyStatement.cpp +++ b/ets2panda/ir/statements/emptyStatement.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021-2022 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 @@ -22,7 +22,11 @@ #include "ir/srcDump.h" namespace ark::es2panda::ir { -void EmptyStatement::TransformChildren([[maybe_unused]] const NodeTransformer &cb) {} +void EmptyStatement::TransformChildren([[maybe_unused]] const NodeTransformer &c, + [[maybe_unused]] std::string_view const transformationName) +{ +} + void EmptyStatement::Iterate([[maybe_unused]] const NodeTraverser &cb) const {} void EmptyStatement::Dump(ir::AstDumper *dumper) const diff --git a/ets2panda/ir/statements/emptyStatement.h b/ets2panda/ir/statements/emptyStatement.h index 9a03cd73d6d6474e9ce5148e5054849dd0b5a13b..eff201b6f7e001e04531711476bc31ccacfdacb8 100644 --- a/ets2panda/ir/statements/emptyStatement.h +++ b/ets2panda/ir/statements/emptyStatement.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 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 @@ -23,7 +23,7 @@ class EmptyStatement : public Statement { public: explicit EmptyStatement() : Statement(AstNodeType::EMPTY_STATEMENT) {} - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/statements/expressionStatement.cpp b/ets2panda/ir/statements/expressionStatement.cpp index 717496b46fbf66a14402b91376fe50f4aa502e78..2ed2cac55561e29e5796a60e2964a87d0963bb27 100644 --- a/ets2panda/ir/statements/expressionStatement.cpp +++ b/ets2panda/ir/statements/expressionStatement.cpp @@ -22,9 +22,12 @@ #include "ir/srcDump.h" namespace ark::es2panda::ir { -void ExpressionStatement::TransformChildren(const NodeTransformer &cb) +void ExpressionStatement::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { - expression_ = cb(expression_)->AsExpression(); + if (auto *transformedNode = cb(expression_); expression_ != transformedNode) { + expression_->SetTransformedNode(transformationName, transformedNode); + expression_ = transformedNode->AsExpression(); + } } void ExpressionStatement::Iterate(const NodeTraverser &cb) const diff --git a/ets2panda/ir/statements/expressionStatement.h b/ets2panda/ir/statements/expressionStatement.h index 2b02cf943b898b1dc2982576fd7e70c6187a9fe8..1b9bb877c10b88ad6b36e32b8bc5ab9cf23715ae 100644 --- a/ets2panda/ir/statements/expressionStatement.h +++ b/ets2panda/ir/statements/expressionStatement.h @@ -35,7 +35,7 @@ public: return expression_; } - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/statements/forInStatement.cpp b/ets2panda/ir/statements/forInStatement.cpp index ec0a69f711d7d6de20bd696ed3ad35370448288e..b407148194306c6f0d3a0d41349d8ca2192f32aa 100644 --- a/ets2panda/ir/statements/forInStatement.cpp +++ b/ets2panda/ir/statements/forInStatement.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 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 @@ -25,11 +25,22 @@ #include "ir/srcDump.h" namespace ark::es2panda::ir { -void ForInStatement::TransformChildren(const NodeTransformer &cb) +void ForInStatement::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { - left_ = cb(left_); - right_ = cb(right_)->AsExpression(); - body_ = cb(body_)->AsStatement(); + if (auto *transformedNode = cb(left_); left_ != transformedNode) { + left_->SetTransformedNode(transformationName, transformedNode); + left_ = transformedNode; + } + + if (auto *transformedNode = cb(right_); right_ != transformedNode) { + right_->SetTransformedNode(transformationName, transformedNode); + right_ = transformedNode->AsExpression(); + } + + if (auto *transformedNode = cb(body_); body_ != transformedNode) { + body_->SetTransformedNode(transformationName, transformedNode); + body_ = transformedNode->AsStatement(); + } } void ForInStatement::Iterate(const NodeTraverser &cb) const diff --git a/ets2panda/ir/statements/forInStatement.h b/ets2panda/ir/statements/forInStatement.h index 66dc9ef3743667149af9d9d93ded914386325137..f7df698a01fd6a52ed037f358e8055a92b8915d6 100644 --- a/ets2panda/ir/statements/forInStatement.h +++ b/ets2panda/ir/statements/forInStatement.h @@ -62,7 +62,7 @@ public: return body_; } - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; diff --git a/ets2panda/ir/statements/forOfStatement.cpp b/ets2panda/ir/statements/forOfStatement.cpp index a2126705e4c5407f28ac6fda4f88887f3fb736be..ad2de57506821a7a5f04040dd501cabed2b81e05 100644 --- a/ets2panda/ir/statements/forOfStatement.cpp +++ b/ets2panda/ir/statements/forOfStatement.cpp @@ -22,11 +22,22 @@ #include "ir/srcDump.h" namespace ark::es2panda::ir { -void ForOfStatement::TransformChildren(const NodeTransformer &cb) +void ForOfStatement::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { - left_ = cb(left_); - right_ = cb(right_)->AsExpression(); - body_ = cb(body_)->AsStatement(); + if (auto *transformedNode = cb(left_); left_ != transformedNode) { + left_->SetTransformedNode(transformationName, transformedNode); + left_ = transformedNode; + } + + if (auto *transformedNode = cb(right_); right_ != transformedNode) { + right_->SetTransformedNode(transformationName, transformedNode); + right_ = transformedNode->AsExpression(); + } + + if (auto *transformedNode = cb(body_); body_ != transformedNode) { + body_->SetTransformedNode(transformationName, transformedNode); + body_ = transformedNode->AsStatement(); + } } void ForOfStatement::Iterate(const NodeTraverser &cb) const diff --git a/ets2panda/ir/statements/forOfStatement.h b/ets2panda/ir/statements/forOfStatement.h index 9a85af45df0e272036165c8a2731e5b40425b3f7..4b3cc0af294369328c611cf6ec4c1903da1e1fef 100644 --- a/ets2panda/ir/statements/forOfStatement.h +++ b/ets2panda/ir/statements/forOfStatement.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 - 2024 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 @@ -88,7 +88,7 @@ public: [[nodiscard]] ForOfStatement *Clone(ArenaAllocator *allocator, AstNode *parent) override; - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; diff --git a/ets2panda/ir/statements/forUpdateStatement.cpp b/ets2panda/ir/statements/forUpdateStatement.cpp index 694da618e77d437ab410537cda645e1d8bdea29c..1a00dc8c940eff2288afea18bdb7266b4fa139f2 100644 --- a/ets2panda/ir/statements/forUpdateStatement.cpp +++ b/ets2panda/ir/statements/forUpdateStatement.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 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 @@ -14,35 +14,44 @@ */ #include "forUpdateStatement.h" -#include -#include "varbinder/scope.h" #include "compiler/base/condition.h" #include "compiler/base/lreference.h" #include "compiler/core/labelTarget.h" #include "compiler/core/pandagen.h" #include "compiler/core/ETSGen.h" -#include "compiler/core/dynamicContext.h" #include "checker/TSchecker.h" #include "ir/astDump.h" #include "ir/srcDump.h" namespace ark::es2panda::ir { -void ForUpdateStatement::TransformChildren(const NodeTransformer &cb) +void ForUpdateStatement::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { if (init_ != nullptr) { - init_ = cb(init_); + if (auto *transformedNode = cb(init_); init_ != transformedNode) { + init_->SetTransformedNode(transformationName, transformedNode); + init_ = transformedNode; + } } if (test_ != nullptr) { - test_ = cb(test_)->AsExpression(); + if (auto *transformedNode = cb(test_); test_ != transformedNode) { + test_->SetTransformedNode(transformationName, transformedNode); + test_ = transformedNode->AsExpression(); + } } if (update_ != nullptr) { - update_ = cb(update_)->AsExpression(); + if (auto *transformedNode = cb(update_); update_ != transformedNode) { + update_->SetTransformedNode(transformationName, transformedNode); + update_ = transformedNode->AsExpression(); + } } - body_ = cb(body_)->AsStatement(); + if (auto *transformedNode = cb(body_); body_ != transformedNode) { + body_->SetTransformedNode(transformationName, transformedNode); + body_ = transformedNode->AsStatement(); + } } void ForUpdateStatement::Iterate(const NodeTraverser &cb) const diff --git a/ets2panda/ir/statements/forUpdateStatement.h b/ets2panda/ir/statements/forUpdateStatement.h index 7477d9252ac62791fe22f623a966f24b29a70cb3..a9be720c25d6cee86ce87c3102ff3ac385a33e37 100644 --- a/ets2panda/ir/statements/forUpdateStatement.h +++ b/ets2panda/ir/statements/forUpdateStatement.h @@ -72,7 +72,7 @@ public: return body_; } - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; diff --git a/ets2panda/ir/statements/functionDeclaration.cpp b/ets2panda/ir/statements/functionDeclaration.cpp index 69ada915841eb6f65f4b61249c57f28efaf3e5bb..aba513ca81b16ca0e3fc47d2f84d72e7ca579421 100644 --- a/ets2panda/ir/statements/functionDeclaration.cpp +++ b/ets2panda/ir/statements/functionDeclaration.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 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 @@ -16,7 +16,6 @@ #include "functionDeclaration.h" #include "varbinder/variable.h" -#include "varbinder/scope.h" #include "compiler/core/ETSGen.h" #include "checker/TSchecker.h" #include "ir/astDump.h" @@ -24,13 +23,19 @@ #include "compiler/core/pandagen.h" namespace ark::es2panda::ir { -void FunctionDeclaration::TransformChildren(const NodeTransformer &cb) +void FunctionDeclaration::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { for (auto *&it : decorators_) { - it = cb(it)->AsDecorator(); + if (auto *transformedNode = cb(it); it != transformedNode) { + it->SetTransformedNode(transformationName, transformedNode); + it = transformedNode->AsDecorator(); + } } - func_ = cb(func_)->AsScriptFunction(); + if (auto *transformedNode = cb(func_); func_ != transformedNode) { + func_->SetTransformedNode(transformationName, transformedNode); + func_ = transformedNode->AsScriptFunction(); + } } void FunctionDeclaration::Iterate(const NodeTraverser &cb) const diff --git a/ets2panda/ir/statements/functionDeclaration.h b/ets2panda/ir/statements/functionDeclaration.h index 05a5c0f7b4d2647d657afa80549bc6527ec32359..3915d852611b56fff976da5341667d66d147e02b 100644 --- a/ets2panda/ir/statements/functionDeclaration.h +++ b/ets2panda/ir/statements/functionDeclaration.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 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 @@ -56,7 +56,7 @@ public: return !inTs; } - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/statements/ifStatement.cpp b/ets2panda/ir/statements/ifStatement.cpp index c82bae2e519a092562e0ee0d67d67e1be5ae453a..b1b40c00586a743d5b124c0bd554b835fd635882 100644 --- a/ets2panda/ir/statements/ifStatement.cpp +++ b/ets2panda/ir/statements/ifStatement.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 - 2024 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 @@ -22,13 +22,23 @@ #include "ir/srcDump.h" namespace ark::es2panda::ir { -void IfStatement::TransformChildren(const NodeTransformer &cb) +void IfStatement::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { - test_ = cb(test_)->AsExpression(); - consequent_ = cb(consequent_)->AsStatement(); + if (auto *transformedNode = cb(test_); test_ != transformedNode) { + test_->SetTransformedNode(transformationName, transformedNode); + test_ = transformedNode->AsExpression(); + } + + if (auto *transformedNode = cb(consequent_); consequent_ != transformedNode) { + consequent_->SetTransformedNode(transformationName, transformedNode); + consequent_ = transformedNode->AsStatement(); + } if (alternate_ != nullptr) { - alternate_ = cb(alternate_)->AsStatement(); + if (auto *transformedNode = cb(alternate_); alternate_ != transformedNode) { + alternate_->SetTransformedNode(transformationName, transformedNode); + alternate_ = transformedNode->AsStatement(); + } } } diff --git a/ets2panda/ir/statements/ifStatement.h b/ets2panda/ir/statements/ifStatement.h index 5552fe80a0632dc0dc59300548c726234c7fb19c..75da2299a9555b24a46684f0965eb564209be8e7 100644 --- a/ets2panda/ir/statements/ifStatement.h +++ b/ets2panda/ir/statements/ifStatement.h @@ -69,7 +69,7 @@ public: return alternate_; } - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; diff --git a/ets2panda/ir/statements/labelledStatement.cpp b/ets2panda/ir/statements/labelledStatement.cpp index f0d65e3417f92bb5a56ea2e49d477fe696caca05..cee0655b7dd693a1fc71c4fe9162688025210556 100644 --- a/ets2panda/ir/statements/labelledStatement.cpp +++ b/ets2panda/ir/statements/labelledStatement.cpp @@ -22,10 +22,17 @@ #include "ir/srcDump.h" namespace ark::es2panda::ir { -void LabelledStatement::TransformChildren(const NodeTransformer &cb) +void LabelledStatement::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { - ident_ = cb(ident_)->AsIdentifier(); - body_ = cb(body_)->AsStatement(); + if (auto *transformedNode = cb(ident_); ident_ != transformedNode) { + ident_->SetTransformedNode(transformationName, transformedNode); + ident_ = transformedNode->AsIdentifier(); + } + + if (auto *transformedNode = cb(body_); body_ != transformedNode) { + body_->SetTransformedNode(transformationName, transformedNode); + body_ = transformedNode->AsStatement(); + } } void LabelledStatement::Iterate(const NodeTraverser &cb) const diff --git a/ets2panda/ir/statements/labelledStatement.h b/ets2panda/ir/statements/labelledStatement.h index be415785939c6690f7ae38f23f42cbf8a2e03562..e62d9a28ed3342987273409eb63a8d1ff7bbdc7e 100644 --- a/ets2panda/ir/statements/labelledStatement.h +++ b/ets2panda/ir/statements/labelledStatement.h @@ -48,7 +48,7 @@ public: const ir::AstNode *GetReferencedStatement() const; - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; diff --git a/ets2panda/ir/statements/loopStatement.h b/ets2panda/ir/statements/loopStatement.h index c86db2560136e40fc28bfc7d9ebfac19ecee1d0f..7d996280d0aa868cc28af6716bb7469ce04ef930 100644 --- a/ets2panda/ir/statements/loopStatement.h +++ b/ets2panda/ir/statements/loopStatement.h @@ -28,25 +28,28 @@ public: NO_COPY_SEMANTIC(LoopStatement); NO_MOVE_SEMANTIC(LoopStatement); - bool IsScopeBearer() const override + [[nodiscard]] bool IsScopeBearer() const noexcept override { return true; } - varbinder::LoopScope *Scope() const override + [[nodiscard]] varbinder::LoopScope *Scope() const noexcept final { return scope_; } void SetScope(varbinder::LoopScope *scope) { + ASSERT(scope_ == nullptr); scope_ = scope; } - void TransformChildren([[maybe_unused]] const NodeTransformer &cb) override + void TransformChildren([[maybe_unused]] const NodeTransformer &cb, + [[maybe_unused]] std::string_view const transformationName) override { UNREACHABLE(); } + void Iterate([[maybe_unused]] const NodeTraverser &cb) const override { UNREACHABLE(); diff --git a/ets2panda/ir/statements/returnStatement.cpp b/ets2panda/ir/statements/returnStatement.cpp index d637554d08254cee1df8c065b32c29807e38a9f8..8e5479d317d41dfe540946406002743b388dd2d4 100644 --- a/ets2panda/ir/statements/returnStatement.cpp +++ b/ets2panda/ir/statements/returnStatement.cpp @@ -22,10 +22,13 @@ #include "ir/srcDump.h" namespace ark::es2panda::ir { -void ReturnStatement::TransformChildren(const NodeTransformer &cb) +void ReturnStatement::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { if (argument_ != nullptr) { - argument_ = cb(argument_)->AsExpression(); + if (auto *transformedNode = cb(argument_); argument_ != transformedNode) { + argument_->SetTransformedNode(transformationName, transformedNode); + argument_ = transformedNode->AsExpression(); + } } } diff --git a/ets2panda/ir/statements/returnStatement.h b/ets2panda/ir/statements/returnStatement.h index 2b4499b213e6cba5703e621cad0a4bc9e04d2f72..b3586881a71f2b7ac7db1a1637b6ac02cf2308a9 100644 --- a/ets2panda/ir/statements/returnStatement.h +++ b/ets2panda/ir/statements/returnStatement.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 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 @@ -61,7 +61,7 @@ public: return returnType_; } - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void SetReturnType(checker::ETSChecker *checker, checker::Type *type) override; void SetArgument(Expression *arg); diff --git a/ets2panda/ir/statements/switchCaseStatement.cpp b/ets2panda/ir/statements/switchCaseStatement.cpp index 6c8a8999fcc25aaa8f03c7f028e5c6fbcb444d6f..49d1340b2fd3d432ae264c7527675e388afb92fb 100644 --- a/ets2panda/ir/statements/switchCaseStatement.cpp +++ b/ets2panda/ir/statements/switchCaseStatement.cpp @@ -23,14 +23,20 @@ #include "ir/srcDump.h" namespace ark::es2panda::ir { -void SwitchCaseStatement::TransformChildren(const NodeTransformer &cb) +void SwitchCaseStatement::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { if (test_ != nullptr) { - test_ = cb(test_)->AsExpression(); + if (auto *transformedNode = cb(test_); test_ != transformedNode) { + test_->SetTransformedNode(transformationName, transformedNode); + test_ = transformedNode->AsExpression(); + } } for (auto *&it : consequent_) { - it = cb(it)->AsStatement(); + if (auto *transformedNode = cb(it); it != transformedNode) { + it->SetTransformedNode(transformationName, transformedNode); + it = transformedNode->AsStatement(); + } } } diff --git a/ets2panda/ir/statements/switchCaseStatement.h b/ets2panda/ir/statements/switchCaseStatement.h index 0c47131c72362bde4bf2751c6d8c4e7f61f03418..39911b7bd765dce32f772478be3bdfaef7d22df8 100644 --- a/ets2panda/ir/statements/switchCaseStatement.h +++ b/ets2panda/ir/statements/switchCaseStatement.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 - 2024 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 @@ -49,7 +49,7 @@ public: return consequent_; } - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; diff --git a/ets2panda/ir/statements/switchStatement.cpp b/ets2panda/ir/statements/switchStatement.cpp index b1e59002144f11dc461d3df3b219b612b7d9e2f9..841174d6e3d1e2d2578fb6443e8a4ec2b3a9d38d 100644 --- a/ets2panda/ir/statements/switchStatement.cpp +++ b/ets2panda/ir/statements/switchStatement.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 - 2024 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 @@ -22,12 +22,18 @@ #include "ir/srcDump.h" namespace ark::es2panda::ir { -void SwitchStatement::TransformChildren(const NodeTransformer &cb) +void SwitchStatement::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { - discriminant_ = cb(discriminant_)->AsExpression(); + if (auto *transformedNode = cb(discriminant_); discriminant_ != transformedNode) { + discriminant_->SetTransformedNode(transformationName, transformedNode); + discriminant_ = transformedNode->AsExpression(); + } for (auto *&it : cases_) { - it = cb(it)->AsSwitchCaseStatement(); + if (auto *transformedNode = cb(it); it != transformedNode) { + it->SetTransformedNode(transformationName, transformedNode); + it = transformedNode->AsSwitchCaseStatement(); + } } } diff --git a/ets2panda/ir/statements/switchStatement.h b/ets2panda/ir/statements/switchStatement.h index 909384c281d38e5ea3b89e3d1c8cb0772eb36ace..2785d038485aa4d6a3e660b55f94f87c1196cac4 100644 --- a/ets2panda/ir/statements/switchStatement.h +++ b/ets2panda/ir/statements/switchStatement.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 - 2024 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 @@ -61,22 +61,23 @@ public: return cases_; } - bool IsScopeBearer() const override + [[nodiscard]] bool IsScopeBearer() const noexcept override { return true; } - varbinder::LocalScope *Scope() const override + [[nodiscard]] varbinder::LocalScope *Scope() const noexcept override { return scope_; } void SetScope(varbinder::LocalScope *scope) noexcept { + ASSERT(scope_ == nullptr); scope_ = scope; } - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; diff --git a/ets2panda/ir/statements/throwStatement.cpp b/ets2panda/ir/statements/throwStatement.cpp index f9af062a550349766fbbfe147ae431b1af14423f..3c885f2abd26a7e43384a35b5eecd56ee5c321dd 100644 --- a/ets2panda/ir/statements/throwStatement.cpp +++ b/ets2panda/ir/statements/throwStatement.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021-2022 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 @@ -23,9 +23,12 @@ #include "ir/expression.h" namespace ark::es2panda::ir { -void ThrowStatement::TransformChildren(const NodeTransformer &cb) +void ThrowStatement::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { - argument_ = cb(argument_)->AsExpression(); + if (auto *transformedNode = cb(argument_); argument_ != transformedNode) { + argument_->SetTransformedNode(transformationName, transformedNode); + argument_ = transformedNode->AsExpression(); + } } void ThrowStatement::Iterate(const NodeTraverser &cb) const diff --git a/ets2panda/ir/statements/throwStatement.h b/ets2panda/ir/statements/throwStatement.h index 1044a2c236ccf93f564ad6e54bec859b29b438f7..0aebe78e29e4d1039dacbe45c4798fbe52354770 100644 --- a/ets2panda/ir/statements/throwStatement.h +++ b/ets2panda/ir/statements/throwStatement.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 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 @@ -36,7 +36,7 @@ public: friend class checker::ETSAnalyzer; - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/statements/tryStatement.cpp b/ets2panda/ir/statements/tryStatement.cpp index 05e79264d67a47b271354e44c1ca030f41932f9a..c9497dfb63cbb13c84eff98dd0924f2bc82c08e0 100644 --- a/ets2panda/ir/statements/tryStatement.cpp +++ b/ets2panda/ir/statements/tryStatement.cpp @@ -26,16 +26,25 @@ #include "ir/statements/blockStatement.h" namespace ark::es2panda::ir { -void TryStatement::TransformChildren(const NodeTransformer &cb) +void TryStatement::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { - block_ = cb(block_)->AsBlockStatement(); + if (auto *transformedNode = cb(block_); block_ != transformedNode) { + block_->SetTransformedNode(transformationName, transformedNode); + block_ = transformedNode->AsBlockStatement(); + } for (auto *&it : catchClauses_) { - it = cb(it)->AsCatchClause(); + if (auto *transformedNode = cb(it); it != transformedNode) { + it->SetTransformedNode(transformationName, transformedNode); + it = transformedNode->AsCatchClause(); + } } if (finalizer_ != nullptr) { - finalizer_ = cb(finalizer_)->AsBlockStatement(); + if (auto *transformedNode = cb(finalizer_); finalizer_ != transformedNode) { + finalizer_->SetTransformedNode(transformationName, transformedNode); + finalizer_ = transformedNode->AsBlockStatement(); + } } } diff --git a/ets2panda/ir/statements/tryStatement.h b/ets2panda/ir/statements/tryStatement.h index cceb03517f554681cb0b87f5e6b1002e5b2cd2fb..3c46ebcf598c28b41e804b43908eb3ec9fe77d71 100644 --- a/ets2panda/ir/statements/tryStatement.h +++ b/ets2panda/ir/statements/tryStatement.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 - 2024 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 @@ -82,7 +82,7 @@ public: return catchClauses_; } - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; diff --git a/ets2panda/ir/statements/variableDeclaration.cpp b/ets2panda/ir/statements/variableDeclaration.cpp index 87b5ee8fcabcd4e92bdfdc1d606c37e3c45b2ec0..e7080c19ab6c132d7b6ffa0905b9ebae6f590cf2 100644 --- a/ets2panda/ir/statements/variableDeclaration.cpp +++ b/ets2panda/ir/statements/variableDeclaration.cpp @@ -16,7 +16,6 @@ #include "variableDeclaration.h" #include "macros.h" -#include "varbinder/scope.h" #include "varbinder/variable.h" #include "checker/TSchecker.h" #include "checker/ETSchecker.h" @@ -25,20 +24,23 @@ #include "ir/astDump.h" #include "ir/srcDump.h" #include "ir/base/decorator.h" -#include "ir/expressions/arrayExpression.h" -#include "ir/expressions/identifier.h" -#include "ir/expressions/objectExpression.h" #include "ir/statements/variableDeclarator.h" namespace ark::es2panda::ir { -void VariableDeclaration::TransformChildren(const NodeTransformer &cb) +void VariableDeclaration::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { for (auto *&it : decorators_) { - it = cb(it)->AsDecorator(); + if (auto *transformedNode = cb(it); it != transformedNode) { + it->SetTransformedNode(transformationName, transformedNode); + it = transformedNode->AsDecorator(); + } } for (auto *&it : declarators_) { - it = cb(it)->AsVariableDeclarator(); + if (auto *transformedNode = cb(it); it != transformedNode) { + it->SetTransformedNode(transformationName, transformedNode); + it = transformedNode->AsVariableDeclarator(); + } } } diff --git a/ets2panda/ir/statements/variableDeclaration.h b/ets2panda/ir/statements/variableDeclaration.h index ff0f3cf873536aa6430e84f42fca2eddce36630e..cbafb4202993f05631ed1e44879a468543fbec7e 100644 --- a/ets2panda/ir/statements/variableDeclaration.h +++ b/ets2panda/ir/statements/variableDeclaration.h @@ -75,7 +75,7 @@ public: return true; } - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/statements/variableDeclarator.cpp b/ets2panda/ir/statements/variableDeclarator.cpp index 87d8ca321a71844af95fcb168673185ee06c014f..665995fc626345cf984d13df9381301a4386f58b 100644 --- a/ets2panda/ir/statements/variableDeclarator.cpp +++ b/ets2panda/ir/statements/variableDeclarator.cpp @@ -15,7 +15,6 @@ #include "variableDeclarator.h" -#include "varbinder/variableFlags.h" #include "compiler/base/lreference.h" #include "compiler/core/pandagen.h" #include "compiler/core/ETSGen.h" @@ -25,21 +24,24 @@ #include "ir/typeNode.h" #include "ir/expression.h" #include "ir/statements/variableDeclaration.h" -#include "ir/expressions/arrayExpression.h" -#include "ir/expressions/objectExpression.h" -#include "ir/expressions/identifier.h" #include "checker/TSchecker.h" #include "checker/ETSchecker.h" #include "checker/ts/destructuringContext.h" namespace ark::es2panda::ir { -void VariableDeclarator::TransformChildren(const NodeTransformer &cb) +void VariableDeclarator::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { - id_ = cb(id_)->AsExpression(); + if (auto *transformedNode = cb(id_); id_ != transformedNode) { + id_->SetTransformedNode(transformationName, transformedNode); + id_ = transformedNode->AsExpression(); + } if (init_ != nullptr) { - init_ = cb(init_)->AsExpression(); + if (auto *transformedNode = cb(init_); init_ != transformedNode) { + init_->SetTransformedNode(transformationName, transformedNode); + init_ = transformedNode->AsExpression(); + } } } diff --git a/ets2panda/ir/statements/variableDeclarator.h b/ets2panda/ir/statements/variableDeclarator.h index 17ed8554e79c491322b68d9261437e5e8b11419e..cf9a1e6da615cd88622555701784ae5efd53cb65 100644 --- a/ets2panda/ir/statements/variableDeclarator.h +++ b/ets2panda/ir/statements/variableDeclarator.h @@ -77,7 +77,7 @@ public: return flag_; } - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/statements/whileStatement.cpp b/ets2panda/ir/statements/whileStatement.cpp index 0eb2273be565897384da535d388394ec0331064b..f193b12c0f98dbabfff872f2db635b89cddb1c59 100644 --- a/ets2panda/ir/statements/whileStatement.cpp +++ b/ets2panda/ir/statements/whileStatement.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 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 @@ -15,7 +15,6 @@ #include "whileStatement.h" -#include "varbinder/scope.h" #include "compiler/base/condition.h" #include "compiler/core/labelTarget.h" #include "compiler/core/pandagen.h" @@ -27,10 +26,17 @@ #include "ir/expression.h" namespace ark::es2panda::ir { -void WhileStatement::TransformChildren(const NodeTransformer &cb) +void WhileStatement::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { - test_ = cb(test_)->AsExpression(); - body_ = cb(body_)->AsStatement(); + if (auto *transformedNode = cb(test_); test_ != transformedNode) { + test_->SetTransformedNode(transformationName, transformedNode); + test_ = transformedNode->AsExpression(); + } + + if (auto *transformedNode = cb(body_); body_ != transformedNode) { + body_->SetTransformedNode(transformationName, transformedNode); + body_ = transformedNode->AsStatement(); + } } void WhileStatement::Iterate(const NodeTraverser &cb) const diff --git a/ets2panda/ir/statements/whileStatement.h b/ets2panda/ir/statements/whileStatement.h index ddac1e4ea7e7e05ac620f1568aa416e94fce46c5..94813cb38a85dd56fc433d9502f7bcc996322ab7 100644 --- a/ets2panda/ir/statements/whileStatement.h +++ b/ets2panda/ir/statements/whileStatement.h @@ -52,7 +52,7 @@ public: return body_; } - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; diff --git a/ets2panda/ir/ts/tsAnyKeyword.cpp b/ets2panda/ir/ts/tsAnyKeyword.cpp index 4db1e94f534cc52ceef5d083c4c8215fb0fa42ec..a58a7f3dcacc3c5f3f470c179ad843910624175a 100644 --- a/ets2panda/ir/ts/tsAnyKeyword.cpp +++ b/ets2panda/ir/ts/tsAnyKeyword.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021-2022 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 @@ -22,7 +22,11 @@ #include "ir/srcDump.h" namespace ark::es2panda::ir { -void TSAnyKeyword::TransformChildren([[maybe_unused]] const NodeTransformer &cb) {} +void TSAnyKeyword::TransformChildren([[maybe_unused]] const NodeTransformer &cb, + [[maybe_unused]] std::string_view const transformationName) +{ +} + void TSAnyKeyword::Iterate([[maybe_unused]] const NodeTraverser &cb) const {} void TSAnyKeyword::Dump(ir::AstDumper *dumper) const diff --git a/ets2panda/ir/ts/tsAnyKeyword.h b/ets2panda/ir/ts/tsAnyKeyword.h index aceb081286e09012310ab922e8c59368b3b1c9a6..a425629950dba340f11a8474f92c669587955cbf 100644 --- a/ets2panda/ir/ts/tsAnyKeyword.h +++ b/ets2panda/ir/ts/tsAnyKeyword.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021-2022 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 @@ -23,7 +23,7 @@ class TSAnyKeyword : public TypeNode { public: explicit TSAnyKeyword() : TypeNode(AstNodeType::TS_ANY_KEYWORD) {} - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/ts/tsArrayType.cpp b/ets2panda/ir/ts/tsArrayType.cpp index 5d663e05bae7fb79a82bcfc7f97a42436607c708..906181b451377b96fab5b637db0eb909eae53c9a 100644 --- a/ets2panda/ir/ts/tsArrayType.cpp +++ b/ets2panda/ir/ts/tsArrayType.cpp @@ -24,9 +24,12 @@ #include "macros.h" namespace ark::es2panda::ir { -void TSArrayType::TransformChildren(const NodeTransformer &cb) +void TSArrayType::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { - elementType_ = static_cast(cb(elementType_)); + if (auto *transformedNode = cb(elementType_); elementType_ != transformedNode) { + elementType_->SetTransformedNode(transformationName, transformedNode); + elementType_ = static_cast(transformedNode); + } } void TSArrayType::Iterate(const NodeTraverser &cb) const diff --git a/ets2panda/ir/ts/tsArrayType.h b/ets2panda/ir/ts/tsArrayType.h index 7c6150a851e91e64b344ff64e70d020fbc5df0ab..0d0b3167edc4ba7c96be1ee7b6f0282575a679f9 100644 --- a/ets2panda/ir/ts/tsArrayType.h +++ b/ets2panda/ir/ts/tsArrayType.h @@ -37,7 +37,7 @@ public: friend class checker::TSAnalyzer; friend class checker::ETSAnalyzer; - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/ts/tsAsExpression.cpp b/ets2panda/ir/ts/tsAsExpression.cpp index 4c0b13c158814e01bf6cce4317e78b2a8ff73586..03f6a92d21a5098338141b84d0892ee0bc95434b 100644 --- a/ets2panda/ir/ts/tsAsExpression.cpp +++ b/ets2panda/ir/ts/tsAsExpression.cpp @@ -35,10 +35,19 @@ void TSAsExpression::SetExpr(Expression *expr) noexcept } } -void TSAsExpression::TransformChildren(const NodeTransformer &cb) +void TSAsExpression::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { - expression_ = cb(expression_)->AsExpression(); - SetTsTypeAnnotation(static_cast(cb(TypeAnnotation()))); + if (auto *transformedNode = cb(expression_); expression_ != transformedNode) { + expression_->SetTransformedNode(transformationName, transformedNode); + expression_ = transformedNode->AsExpression(); + } + + if (auto *typeAnnotation = TypeAnnotation(); typeAnnotation != nullptr) { + if (auto *transformedNode = cb(typeAnnotation); typeAnnotation != transformedNode) { + typeAnnotation->SetTransformedNode(transformationName, transformedNode); + SetTsTypeAnnotation(static_cast(transformedNode)); + } + } } void TSAsExpression::Iterate(const NodeTraverser &cb) const diff --git a/ets2panda/ir/ts/tsAsExpression.h b/ets2panda/ir/ts/tsAsExpression.h index 69688f971e11cfb9c0a12ec592d86aa0c1c580aa..93c570758a69ef6361a26f1501e77ef1b96cbfdd 100644 --- a/ets2panda/ir/ts/tsAsExpression.h +++ b/ets2panda/ir/ts/tsAsExpression.h @@ -63,7 +63,7 @@ public: isUncheckedCast_ = isUncheckedCast; } - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/ts/tsBigintKeyword.cpp b/ets2panda/ir/ts/tsBigintKeyword.cpp index d11abdb28ea85befeb47397ebb9f048cf5545624..c175977ebd44e88838f948510de89663fb9b4cb5 100644 --- a/ets2panda/ir/ts/tsBigintKeyword.cpp +++ b/ets2panda/ir/ts/tsBigintKeyword.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021-2022 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 @@ -23,7 +23,11 @@ #include "checker/TSchecker.h" namespace ark::es2panda::ir { -void TSBigintKeyword::TransformChildren([[maybe_unused]] const NodeTransformer &cb) {} +void TSBigintKeyword::TransformChildren([[maybe_unused]] const NodeTransformer &cb, + [[maybe_unused]] std::string_view const transformationName) +{ +} + void TSBigintKeyword::Iterate([[maybe_unused]] const NodeTraverser &cb) const {} void TSBigintKeyword::Dump(ir::AstDumper *dumper) const diff --git a/ets2panda/ir/ts/tsBigintKeyword.h b/ets2panda/ir/ts/tsBigintKeyword.h index 5d6bdad1db906efc1a59cfa1a5a7cbdbf8c8bed9..c502a7ceea575be7fbbfd7273787afaa9d75cedc 100644 --- a/ets2panda/ir/ts/tsBigintKeyword.h +++ b/ets2panda/ir/ts/tsBigintKeyword.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 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 @@ -23,7 +23,7 @@ class TSBigintKeyword : public TypeNode { public: explicit TSBigintKeyword() : TypeNode(AstNodeType::TS_BIGINT_KEYWORD) {} - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/ts/tsBooleanKeyword.cpp b/ets2panda/ir/ts/tsBooleanKeyword.cpp index 520631ba562429ae37cf8e749f29d7c7a4d4714d..96f2c3002237296f01d1d3dee0444df65c028123 100644 --- a/ets2panda/ir/ts/tsBooleanKeyword.cpp +++ b/ets2panda/ir/ts/tsBooleanKeyword.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021-2022 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 @@ -22,7 +22,11 @@ #include "ir/srcDump.h" namespace ark::es2panda::ir { -void TSBooleanKeyword::TransformChildren([[maybe_unused]] const NodeTransformer &cb) {} +void TSBooleanKeyword::TransformChildren([[maybe_unused]] const NodeTransformer &cb, + [[maybe_unused]] std::string_view const transformationName) +{ +} + void TSBooleanKeyword::Iterate([[maybe_unused]] const NodeTraverser &cb) const {} void TSBooleanKeyword::Dump(ir::AstDumper *dumper) const diff --git a/ets2panda/ir/ts/tsBooleanKeyword.h b/ets2panda/ir/ts/tsBooleanKeyword.h index 5e31aa4e489f67f1eaede9daada4998c1de35fe7..327ca6254d9184ebb639c7e4ca68cdbfd9500f94 100644 --- a/ets2panda/ir/ts/tsBooleanKeyword.h +++ b/ets2panda/ir/ts/tsBooleanKeyword.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 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 @@ -23,7 +23,7 @@ class TSBooleanKeyword : public TypeNode { public: explicit TSBooleanKeyword() : TypeNode(AstNodeType::TS_BOOLEAN_KEYWORD) {} - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/ts/tsClassImplements.cpp b/ets2panda/ir/ts/tsClassImplements.cpp index cf5510794a6b836d689824f7f2ed35436ca8f7d0..3fb69b2db260be8be462bf2273ff1d459c3ef598 100644 --- a/ets2panda/ir/ts/tsClassImplements.cpp +++ b/ets2panda/ir/ts/tsClassImplements.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 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 @@ -24,9 +24,12 @@ #include "ir/ts/tsTypeParameterInstantiation.h" namespace ark::es2panda::ir { -void TSClassImplements::TransformChildren(const NodeTransformer &cb) +void TSClassImplements::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { - expression_ = cb(expression_)->AsExpression(); + if (auto *transformedNode = cb(expression_); expression_ != transformedNode) { + expression_->SetTransformedNode(transformationName, transformedNode); + expression_ = transformedNode->AsExpression(); + } } void TSClassImplements::Iterate(const NodeTraverser &cb) const diff --git a/ets2panda/ir/ts/tsClassImplements.h b/ets2panda/ir/ts/tsClassImplements.h index 53bf75cbecd8402401c4e38b13c33bfdc2e8ff36..042c2fda32cbb56d98c0b11efe4cf7c3c6843fa9 100644 --- a/ets2panda/ir/ts/tsClassImplements.h +++ b/ets2panda/ir/ts/tsClassImplements.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 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 @@ -48,7 +48,7 @@ public: return typeParameters_; } - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/ts/tsConditionalType.cpp b/ets2panda/ir/ts/tsConditionalType.cpp index 8b0337e968fdef0385222ac02dab3b915cb31f26..2020f93f569fe1315aab5586e7d4217a835fe996 100644 --- a/ets2panda/ir/ts/tsConditionalType.cpp +++ b/ets2panda/ir/ts/tsConditionalType.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 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 @@ -22,12 +22,27 @@ #include "ir/srcDump.h" namespace ark::es2panda::ir { -void TSConditionalType::TransformChildren(const NodeTransformer &cb) +void TSConditionalType::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { - checkType_ = cb(checkType_)->AsExpression(); - extendsType_ = cb(extendsType_)->AsExpression(); - trueType_ = cb(trueType_)->AsExpression(); - falseType_ = cb(falseType_)->AsExpression(); + if (auto *transformedNode = cb(checkType_); checkType_ != transformedNode) { + checkType_->SetTransformedNode(transformationName, transformedNode); + checkType_ = transformedNode->AsExpression(); + } + + if (auto *transformedNode = cb(extendsType_); extendsType_ != transformedNode) { + extendsType_->SetTransformedNode(transformationName, transformedNode); + extendsType_ = transformedNode->AsExpression(); + } + + if (auto *transformedNode = cb(trueType_); trueType_ != transformedNode) { + trueType_->SetTransformedNode(transformationName, transformedNode); + trueType_ = transformedNode->AsExpression(); + } + + if (auto *transformedNode = cb(falseType_); falseType_ != transformedNode) { + falseType_->SetTransformedNode(transformationName, transformedNode); + falseType_ = transformedNode->AsExpression(); + } } void TSConditionalType::Iterate(const NodeTraverser &cb) const diff --git a/ets2panda/ir/ts/tsConditionalType.h b/ets2panda/ir/ts/tsConditionalType.h index ef39b6e608179e0748c15933b0ee2802d9c7aabe..81c549ff0a375278a6af9973b7eb7a27626fb660 100644 --- a/ets2panda/ir/ts/tsConditionalType.h +++ b/ets2panda/ir/ts/tsConditionalType.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 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 @@ -51,7 +51,7 @@ public: return falseType_; } - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/ts/tsConstructorType.cpp b/ets2panda/ir/ts/tsConstructorType.cpp index bc6163f778a94056887dd6d097c554e484e3aa72..161309c8ccecdc709ea926abbf71a9cc73168a77 100644 --- a/ets2panda/ir/ts/tsConstructorType.cpp +++ b/ets2panda/ir/ts/tsConstructorType.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 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 @@ -15,20 +15,17 @@ #include "tsConstructorType.h" -#include "varbinder/scope.h" #include "checker/TSchecker.h" #include "checker/types/signature.h" #include "compiler/core/ETSGen.h" #include "compiler/core/pandagen.h" #include "ir/astDump.h" #include "ir/srcDump.h" -#include "ir/ts/tsTypeParameter.h" -#include "ir/ts/tsTypeParameterDeclaration.h" namespace ark::es2panda::ir { -void TSConstructorType::TransformChildren(const NodeTransformer &cb) +void TSConstructorType::TransformChildren(const NodeTransformer &cb, std::string_view const transformationName) { - signature_.TransformChildren(cb); + signature_.TransformChildren(cb, transformationName); } void TSConstructorType::Iterate(const NodeTraverser &cb) const diff --git a/ets2panda/ir/ts/tsConstructorType.h b/ets2panda/ir/ts/tsConstructorType.h index 7e7a51a9b71819105ce7bd6f39edf6a12f98ddc3..3cddadfd8ffd73b4d888ac03b1e83bb3be7f5c1b 100644 --- a/ets2panda/ir/ts/tsConstructorType.h +++ b/ets2panda/ir/ts/tsConstructorType.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 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 @@ -36,18 +36,19 @@ public: // NOTE (vivienvoros): these friend relationships can be removed once there are getters for private fields friend class checker::TSAnalyzer; - bool IsScopeBearer() const override + [[nodiscard]] bool IsScopeBearer() const noexcept override { return true; } - varbinder::Scope *Scope() const override + [[nodiscard]] varbinder::Scope *Scope() const noexcept override { return scope_; } void SetScope(varbinder::Scope *scope) { + ASSERT(scope_ == nullptr); scope_ = scope; } @@ -80,7 +81,7 @@ public: return abstract_; } - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/ts/tsEnumDeclaration.cpp b/ets2panda/ir/ts/tsEnumDeclaration.cpp index 9c20dc35e97b4d5929524f216b8927eb977961ed..b2eb18d9218a54c20b9ce0f9759e2ed07620f567 100644 --- a/ets2panda/ir/ts/tsEnumDeclaration.cpp +++ b/ets2panda/ir/ts/tsEnumDeclaration.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 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 @@ -18,22 +18,30 @@ #include "checker/TSchecker.h" #include "compiler/core/ETSGen.h" #include "compiler/core/pandagen.h" -#include "varbinder/scope.h" #include "util/helpers.h" #include "ir/astDump.h" #include "ir/srcDump.h" namespace ark::es2panda::ir { -void TSEnumDeclaration::TransformChildren(const NodeTransformer &cb) +void TSEnumDeclaration::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { for (auto *&it : decorators_) { - it = cb(it)->AsDecorator(); + if (auto *transformedNode = cb(it); it != transformedNode) { + it->SetTransformedNode(transformationName, transformedNode); + it = transformedNode->AsDecorator(); + } } - key_ = cb(key_)->AsIdentifier(); + if (auto *transformedNode = cb(key_); key_ != transformedNode) { + key_->SetTransformedNode(transformationName, transformedNode); + key_ = transformedNode->AsIdentifier(); + } for (auto *&it : members_) { - it = cb(it); + if (auto *transformedNode = cb(it); it != transformedNode) { + it->SetTransformedNode(transformationName, transformedNode); + it = transformedNode; + } } } diff --git a/ets2panda/ir/ts/tsEnumDeclaration.h b/ets2panda/ir/ts/tsEnumDeclaration.h index ff3a4d584ca52dfad674306f78bda8de3a5686d8..d414546a538503fc9068691d32b1e5ca0c1739a9 100644 --- a/ets2panda/ir/ts/tsEnumDeclaration.h +++ b/ets2panda/ir/ts/tsEnumDeclaration.h @@ -47,18 +47,19 @@ public: } } - bool IsScopeBearer() const override + [[nodiscard]] bool IsScopeBearer() const noexcept override { return true; } - varbinder::LocalScope *Scope() const override + [[nodiscard]] varbinder::LocalScope *Scope() const noexcept override { return scope_; } void SetScope(varbinder::LocalScope *scope) { + ASSERT(scope_ == nullptr); scope_ = scope; } @@ -119,7 +120,7 @@ public: static varbinder::EnumMemberResult EvaluateEnumMember(checker::TSChecker *checker, varbinder::EnumVariable *enumVar, const ir::AstNode *expr); - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/ts/tsEnumMember.cpp b/ets2panda/ir/ts/tsEnumMember.cpp index 8678dd2653074ad457f646d3de2f22483477fc5a..cb38c61b1a7e91c21ab9adc51e483d9472143f28 100644 --- a/ets2panda/ir/ts/tsEnumMember.cpp +++ b/ets2panda/ir/ts/tsEnumMember.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021-2022 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 @@ -22,12 +22,18 @@ #include "ir/srcDump.h" namespace ark::es2panda::ir { -void TSEnumMember::TransformChildren(const NodeTransformer &cb) +void TSEnumMember::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { - key_ = cb(key_)->AsExpression(); + if (auto *transformedNode = cb(key_); key_ != transformedNode) { + key_->SetTransformedNode(transformationName, transformedNode); + key_ = transformedNode->AsExpression(); + } if (init_ != nullptr) { - init_ = cb(init_)->AsExpression(); + if (auto *transformedNode = cb(init_); init_ != transformedNode) { + init_->SetTransformedNode(transformationName, transformedNode); + init_ = transformedNode->AsExpression(); + } } } diff --git a/ets2panda/ir/ts/tsEnumMember.h b/ets2panda/ir/ts/tsEnumMember.h index 20abe1528582af5118298179a8182e01415c33b1..6afde57fb09bcb3a7358b604385cc8ec13802378 100644 --- a/ets2panda/ir/ts/tsEnumMember.h +++ b/ets2panda/ir/ts/tsEnumMember.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021-2022 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 @@ -45,7 +45,7 @@ public: [[nodiscard]] util::StringView Name() const; - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/ts/tsExternalModuleReference.cpp b/ets2panda/ir/ts/tsExternalModuleReference.cpp index 8148b7b7362c575adc29cf78c93c1c157d758bc4..39f0edf39257a604ae534f70101b8bd20e05bb25 100644 --- a/ets2panda/ir/ts/tsExternalModuleReference.cpp +++ b/ets2panda/ir/ts/tsExternalModuleReference.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021-2022 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 @@ -22,9 +22,12 @@ #include "ir/srcDump.h" namespace ark::es2panda::ir { -void TSExternalModuleReference::TransformChildren(const NodeTransformer &cb) +void TSExternalModuleReference::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { - expr_ = cb(expr_)->AsExpression(); + if (auto *transformedNode = cb(expr_); expr_ != transformedNode) { + expr_->SetTransformedNode(transformationName, transformedNode); + expr_ = transformedNode->AsExpression(); + } } void TSExternalModuleReference::Iterate(const NodeTraverser &cb) const diff --git a/ets2panda/ir/ts/tsExternalModuleReference.h b/ets2panda/ir/ts/tsExternalModuleReference.h index a3855e69156d43edebc7db1450418f839db844da..f96354341441dbbabe313e51295a66fcd345ed12 100644 --- a/ets2panda/ir/ts/tsExternalModuleReference.h +++ b/ets2panda/ir/ts/tsExternalModuleReference.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 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 @@ -31,7 +31,7 @@ public: return expr_; } - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/ts/tsFunctionType.cpp b/ets2panda/ir/ts/tsFunctionType.cpp index caafc799d9d34519805b4de2ca7bea1144dad8ba..daf1837cf1ff5b3e298dd93001de93164088bb26 100644 --- a/ets2panda/ir/ts/tsFunctionType.cpp +++ b/ets2panda/ir/ts/tsFunctionType.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 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 @@ -15,7 +15,6 @@ #include "tsFunctionType.h" -#include "varbinder/scope.h" #include "checker/TSchecker.h" #include "checker/ETSchecker.h" #include "checker/types/signature.h" @@ -23,15 +22,11 @@ #include "compiler/core/pandagen.h" #include "ir/astDump.h" #include "ir/srcDump.h" -#include "ir/base/spreadElement.h" -#include "ir/expressions/identifier.h" -#include "ir/ts/tsTypeParameter.h" -#include "ir/ts/tsTypeParameterDeclaration.h" namespace ark::es2panda::ir { -void TSFunctionType::TransformChildren(const NodeTransformer &cb) +void TSFunctionType::TransformChildren(const NodeTransformer &cb, std::string_view const transformationName) { - signature_.TransformChildren(cb); + signature_.TransformChildren(cb, transformationName); } void TSFunctionType::Iterate(const NodeTraverser &cb) const diff --git a/ets2panda/ir/ts/tsFunctionType.h b/ets2panda/ir/ts/tsFunctionType.h index cc0f35fb15181449e0482dd1ffaec3f18a3d9652..b81678b8b5c84952744b0ef804aa413733486bdc 100644 --- a/ets2panda/ir/ts/tsFunctionType.h +++ b/ets2panda/ir/ts/tsFunctionType.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 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 @@ -34,18 +34,19 @@ public: // NOTE (vivienvoros): these friend relationships can be removed once there are getters for private fields friend class checker::TSAnalyzer; - bool IsScopeBearer() const override + [[nodiscard]] bool IsScopeBearer() const noexcept override { return true; } - varbinder::Scope *Scope() const override + [[nodiscard]] varbinder::Scope *Scope() const noexcept override { return scope_; } void SetScope(varbinder::Scope *scope) { + ASSERT(scope_ == nullptr); scope_ = scope; } @@ -78,7 +79,7 @@ public: nullable_ = nullable; } - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/ts/tsImportEqualsDeclaration.cpp b/ets2panda/ir/ts/tsImportEqualsDeclaration.cpp index 663917cccde5208e0e1c3cdcaf5fa00d95ad94bf..864e7c200e00d637fb6582905fd7014b5a59397b 100644 --- a/ets2panda/ir/ts/tsImportEqualsDeclaration.cpp +++ b/ets2panda/ir/ts/tsImportEqualsDeclaration.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 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 @@ -24,10 +24,17 @@ #include "ir/expressions/identifier.h" namespace ark::es2panda::ir { -void TSImportEqualsDeclaration::TransformChildren(const NodeTransformer &cb) +void TSImportEqualsDeclaration::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { - id_ = cb(id_)->AsIdentifier(); - moduleReference_ = cb(moduleReference_)->AsExpression(); + if (auto *transformedNode = cb(id_); id_ != transformedNode) { + id_->SetTransformedNode(transformationName, transformedNode); + id_ = transformedNode->AsIdentifier(); + } + + if (auto *transformedNode = cb(moduleReference_); moduleReference_ != transformedNode) { + moduleReference_->SetTransformedNode(transformationName, transformedNode); + moduleReference_ = transformedNode->AsExpression(); + } } void TSImportEqualsDeclaration::Iterate(const NodeTraverser &cb) const diff --git a/ets2panda/ir/ts/tsImportEqualsDeclaration.h b/ets2panda/ir/ts/tsImportEqualsDeclaration.h index c63b13a09f28cdfc04fcb69037dcf05120d1d67c..e1adb15ffef8d22e0ec469541d65725474fa7ac2 100644 --- a/ets2panda/ir/ts/tsImportEqualsDeclaration.h +++ b/ets2panda/ir/ts/tsImportEqualsDeclaration.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 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 @@ -46,7 +46,7 @@ public: return isExport_; } - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/ts/tsImportType.cpp b/ets2panda/ir/ts/tsImportType.cpp index c0e1c5150e525819d51659b99076a5d368394f02..ff8e7d99134e435106903d72462a5e3af1206b76 100644 --- a/ets2panda/ir/ts/tsImportType.cpp +++ b/ets2panda/ir/ts/tsImportType.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 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 @@ -24,16 +24,25 @@ #include "ir/ts/tsTypeParameterInstantiation.h" namespace ark::es2panda::ir { -void TSImportType::TransformChildren(const NodeTransformer &cb) +void TSImportType::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { - param_ = cb(param_)->AsExpression(); + if (auto *transformedNode = cb(param_); param_ != transformedNode) { + param_->SetTransformedNode(transformationName, transformedNode); + param_ = transformedNode->AsExpression(); + } if (typeParams_ != nullptr) { - typeParams_ = cb(typeParams_)->AsTSTypeParameterInstantiation(); + if (auto *transformedNode = cb(typeParams_); typeParams_ != transformedNode) { + typeParams_->SetTransformedNode(transformationName, transformedNode); + typeParams_ = transformedNode->AsTSTypeParameterInstantiation(); + } } if (qualifier_ != nullptr) { - qualifier_ = cb(qualifier_)->AsExpression(); + if (auto *transformedNode = cb(qualifier_); qualifier_ != transformedNode) { + qualifier_->SetTransformedNode(transformationName, transformedNode); + qualifier_ = transformedNode->AsExpression(); + } } } diff --git a/ets2panda/ir/ts/tsImportType.h b/ets2panda/ir/ts/tsImportType.h index c2f742cb004bfa57d9443fb9ab2966ffc40ab4e1..780037bcab0ecb8790e4dc125c3b19545b3c7f5d 100644 --- a/ets2panda/ir/ts/tsImportType.h +++ b/ets2panda/ir/ts/tsImportType.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 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 @@ -53,7 +53,7 @@ public: return isTypeof_; } - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/ts/tsIndexedAccessType.cpp b/ets2panda/ir/ts/tsIndexedAccessType.cpp index d7699fed1a4c7ac9bb1a4dfb20200e8f418b871e..929a2e9f4ca7deb779d2f6435c7012e468575acf 100644 --- a/ets2panda/ir/ts/tsIndexedAccessType.cpp +++ b/ets2panda/ir/ts/tsIndexedAccessType.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 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 @@ -23,10 +23,17 @@ #include "checker/TSchecker.h" namespace ark::es2panda::ir { -void TSIndexedAccessType::TransformChildren(const NodeTransformer &cb) +void TSIndexedAccessType::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { - objectType_ = static_cast(cb(objectType_)); - indexType_ = static_cast(cb(indexType_)); + if (auto *transformedNode = cb(objectType_); objectType_ != transformedNode) { + objectType_->SetTransformedNode(transformationName, transformedNode); + objectType_ = static_cast(transformedNode); + } + + if (auto *transformedNode = cb(indexType_); indexType_ != transformedNode) { + indexType_->SetTransformedNode(transformationName, transformedNode); + indexType_ = static_cast(transformedNode); + } } void TSIndexedAccessType::Iterate(const NodeTraverser &cb) const diff --git a/ets2panda/ir/ts/tsIndexedAccessType.h b/ets2panda/ir/ts/tsIndexedAccessType.h index 8d2db0eafd6490e360944029845aa0c9383a3f5b..7093f31b732dc4b757f59aadbcab33b9be2807f3 100644 --- a/ets2panda/ir/ts/tsIndexedAccessType.h +++ b/ets2panda/ir/ts/tsIndexedAccessType.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 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 @@ -42,7 +42,7 @@ public: return indexType_; } - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/ts/tsInferType.cpp b/ets2panda/ir/ts/tsInferType.cpp index f2f75161b4004c8e1d80165541dc9b97ce5b28bf..a4d8a960db13fda45edc4f1722a15b9cbf2121fa 100644 --- a/ets2panda/ir/ts/tsInferType.cpp +++ b/ets2panda/ir/ts/tsInferType.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021-2022 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 @@ -23,9 +23,12 @@ #include "ir/ts/tsTypeParameter.h" namespace ark::es2panda::ir { -void TSInferType::TransformChildren(const NodeTransformer &cb) +void TSInferType::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { - typeParam_ = cb(typeParam_)->AsTSTypeParameter(); + if (auto *transformedNode = cb(typeParam_); typeParam_ != transformedNode) { + typeParam_->SetTransformedNode(transformationName, transformedNode); + typeParam_ = transformedNode->AsTSTypeParameter(); + } } void TSInferType::Iterate(const NodeTraverser &cb) const diff --git a/ets2panda/ir/ts/tsInferType.h b/ets2panda/ir/ts/tsInferType.h index 5561aae567dbb8f3a3296771796b7a43c29300e0..5f60bb34b143c07730ed294072fb8581431ff304 100644 --- a/ets2panda/ir/ts/tsInferType.h +++ b/ets2panda/ir/ts/tsInferType.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 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 @@ -30,7 +30,7 @@ public: return typeParam_; } - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/ts/tsInterfaceBody.cpp b/ets2panda/ir/ts/tsInterfaceBody.cpp index 00646e2b175c1d252d17a6d9827e45d6019b6f6e..ebfe04ed84b710d004f434569a208e4ca1e74089 100644 --- a/ets2panda/ir/ts/tsInterfaceBody.cpp +++ b/ets2panda/ir/ts/tsInterfaceBody.cpp @@ -22,10 +22,13 @@ #include "ir/srcDump.h" namespace ark::es2panda::ir { -void TSInterfaceBody::TransformChildren(const NodeTransformer &cb) +void TSInterfaceBody::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { for (auto *&it : body_) { - it = cb(it); + if (auto *transformedNode = cb(it); it != transformedNode) { + it->SetTransformedNode(transformationName, transformedNode); + it = transformedNode; + } } } diff --git a/ets2panda/ir/ts/tsInterfaceBody.h b/ets2panda/ir/ts/tsInterfaceBody.h index 96ce8e49981157ace2e6a86d482eabb0ae8801f8..d603bae0df3494df2924ce176aabe71d2987d0d2 100644 --- a/ets2panda/ir/ts/tsInterfaceBody.h +++ b/ets2panda/ir/ts/tsInterfaceBody.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 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 @@ -41,7 +41,7 @@ public: return body_; } - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/ts/tsInterfaceDeclaration.cpp b/ets2panda/ir/ts/tsInterfaceDeclaration.cpp index ceb66692cba7ad71fb0d8aff18083eb9a0cedf2a..9bae733c0b96edb530c5a2e9e2a52877ecd28fd5 100644 --- a/ets2panda/ir/ts/tsInterfaceDeclaration.cpp +++ b/ets2panda/ir/ts/tsInterfaceDeclaration.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 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 @@ -17,7 +17,6 @@ #include "macros.h" #include "varbinder/declaration.h" -#include "varbinder/scope.h" #include "varbinder/variable.h" #include "checker/TSchecker.h" #include "checker/ETSchecker.h" @@ -33,23 +32,38 @@ #include "ir/ts/tsTypeParameterDeclaration.h" namespace ark::es2panda::ir { -void TSInterfaceDeclaration::TransformChildren(const NodeTransformer &cb) +void TSInterfaceDeclaration::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { for (auto *&it : decorators_) { - it = cb(it)->AsDecorator(); + if (auto *transformedNode = cb(it); it != transformedNode) { + it->SetTransformedNode(transformationName, transformedNode); + it = transformedNode->AsDecorator(); + } } - id_ = cb(id_)->AsIdentifier(); + if (auto *transformedNode = cb(id_); id_ != transformedNode) { + id_->SetTransformedNode(transformationName, transformedNode); + id_ = transformedNode->AsIdentifier(); + } if (typeParams_ != nullptr) { - typeParams_ = cb(typeParams_)->AsTSTypeParameterDeclaration(); + if (auto *transformedNode = cb(typeParams_); typeParams_ != transformedNode) { + typeParams_->SetTransformedNode(transformationName, transformedNode); + typeParams_ = transformedNode->AsTSTypeParameterDeclaration(); + } } for (auto *&it : extends_) { - it = cb(it)->AsTSInterfaceHeritage(); + if (auto *transformedNode = cb(it); it != transformedNode) { + it->SetTransformedNode(transformationName, transformedNode); + it = transformedNode->AsTSInterfaceHeritage(); + } } - body_ = cb(body_)->AsTSInterfaceBody(); + if (auto *transformedNode = cb(body_); body_ != transformedNode) { + body_->SetTransformedNode(transformationName, transformedNode); + body_ = transformedNode->AsTSInterfaceBody(); + } } void TSInterfaceDeclaration::Iterate(const NodeTraverser &cb) const diff --git a/ets2panda/ir/ts/tsInterfaceDeclaration.h b/ets2panda/ir/ts/tsInterfaceDeclaration.h index 591f65878e48b1d4bd04b03ca8db42a1a4fc0948..d1c876b069ed7e083d20a0e6f5073134b96fb794 100644 --- a/ets2panda/ir/ts/tsInterfaceDeclaration.h +++ b/ets2panda/ir/ts/tsInterfaceDeclaration.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 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 @@ -50,18 +50,19 @@ public: } } - bool IsScopeBearer() const override + [[nodiscard]] bool IsScopeBearer() const noexcept override { return true; } - varbinder::LocalScope *Scope() const override + [[nodiscard]] varbinder::LocalScope *Scope() const noexcept override { return scope_; } void SetScope(varbinder::LocalScope *scope) { + ASSERT(scope_ == nullptr); scope_ = scope; } @@ -145,7 +146,7 @@ public: return !inTs; } - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; es2panda::Language Language() const { diff --git a/ets2panda/ir/ts/tsInterfaceHeritage.cpp b/ets2panda/ir/ts/tsInterfaceHeritage.cpp index 27463d778fc461f50d30be4e41f0140e57b6ba83..e34cad8eff9a28c1f474b5b8f71b3baaabc6b43b 100644 --- a/ets2panda/ir/ts/tsInterfaceHeritage.cpp +++ b/ets2panda/ir/ts/tsInterfaceHeritage.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 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 @@ -14,23 +14,20 @@ */ #include "tsInterfaceHeritage.h" -#include -#include "varbinder/scope.h" #include "checker/TSchecker.h" -#include "compiler/core/ETSCompiler.h" #include "compiler/core/ETSGen.h" #include "compiler/core/pandagen.h" #include "ir/astDump.h" #include "ir/srcDump.h" -#include "ir/expressions/identifier.h" -#include "ir/ts/tsTypeParameterInstantiation.h" -#include "ir/ts/tsTypeReference.h" namespace ark::es2panda::ir { -void TSInterfaceHeritage::TransformChildren(const NodeTransformer &cb) +void TSInterfaceHeritage::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { - expr_ = static_cast(cb(expr_)); + if (auto *transformedNode = cb(expr_); expr_ != transformedNode) { + expr_->SetTransformedNode(transformationName, transformedNode); + expr_ = static_cast(transformedNode); + } } void TSInterfaceHeritage::Iterate(const NodeTraverser &cb) const diff --git a/ets2panda/ir/ts/tsInterfaceHeritage.h b/ets2panda/ir/ts/tsInterfaceHeritage.h index b3d86aa0aa5aa3ed4ee68c254d191a25bc0797d8..dec94e57d4da7ac9b99638f5ffc7feb4e0fab4bd 100644 --- a/ets2panda/ir/ts/tsInterfaceHeritage.h +++ b/ets2panda/ir/ts/tsInterfaceHeritage.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 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 @@ -36,7 +36,7 @@ public: return expr_; } - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/ts/tsIntersectionType.cpp b/ets2panda/ir/ts/tsIntersectionType.cpp index d6f95e200cfcfe89881b4986de23f70ce54100e1..1642cd0870d66ba44436ee44c787c85540352770 100644 --- a/ets2panda/ir/ts/tsIntersectionType.cpp +++ b/ets2panda/ir/ts/tsIntersectionType.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021-2022 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 @@ -23,10 +23,13 @@ #include "checker/ETSchecker.h" namespace ark::es2panda::ir { -void TSIntersectionType::TransformChildren(const NodeTransformer &cb) +void TSIntersectionType::TransformChildren(const NodeTransformer &cb, std::string_view const transformationName) { for (auto *&it : types_) { - it = cb(it)->AsExpression(); + if (auto *transformedNode = cb(it); it != transformedNode) { + it->SetTransformedNode(transformationName, transformedNode); + it = transformedNode->AsExpression(); + } } } diff --git a/ets2panda/ir/ts/tsIntersectionType.h b/ets2panda/ir/ts/tsIntersectionType.h index ff36f928ad45674ece9ea5e02ea8405a6086a1d8..665855f1b2e8118aa2d764eb6ec05cfc71cad804 100644 --- a/ets2panda/ir/ts/tsIntersectionType.h +++ b/ets2panda/ir/ts/tsIntersectionType.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 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 @@ -31,7 +31,7 @@ public: return types_; } - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/ts/tsLiteralType.cpp b/ets2panda/ir/ts/tsLiteralType.cpp index 05a3dc156d8b03f9d4829fcf3420471233f044ab..6a780dc5d250b4d5aef64b8e3a7b9449a73c1717 100644 --- a/ets2panda/ir/ts/tsLiteralType.cpp +++ b/ets2panda/ir/ts/tsLiteralType.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021-2022 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 @@ -22,9 +22,12 @@ #include "checker/TSchecker.h" namespace ark::es2panda::ir { -void TSLiteralType::TransformChildren(const NodeTransformer &cb) +void TSLiteralType::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { - literal_ = cb(literal_)->AsExpression(); + if (auto *transformedNode = cb(literal_); literal_ != transformedNode) { + literal_->SetTransformedNode(transformationName, transformedNode); + literal_ = transformedNode->AsExpression(); + } } void TSLiteralType::Iterate(const NodeTraverser &cb) const diff --git a/ets2panda/ir/ts/tsLiteralType.h b/ets2panda/ir/ts/tsLiteralType.h index 7f57ee53e4f4543b28a44b8357b800329fb124e6..14c2f2ab18789bd9ad48816148de4c2c81ef339d 100644 --- a/ets2panda/ir/ts/tsLiteralType.h +++ b/ets2panda/ir/ts/tsLiteralType.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 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 @@ -28,7 +28,7 @@ public: return literal_; } - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/ts/tsMappedType.cpp b/ets2panda/ir/ts/tsMappedType.cpp index 8cd0dcdd75bd68847608973193875c4651e1c1c9..56b85355c93718d12919ff7424c89b81c1036f75 100644 --- a/ets2panda/ir/ts/tsMappedType.cpp +++ b/ets2panda/ir/ts/tsMappedType.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021-2022 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 @@ -24,11 +24,18 @@ #include "ir/ts/tsTypeParameter.h" namespace ark::es2panda::ir { -void TSMappedType::TransformChildren(const NodeTransformer &cb) +void TSMappedType::TransformChildren(const NodeTransformer &cb, std::string_view const transformationName) { - typeParameter_ = cb(typeParameter_)->AsTSTypeParameter(); + if (auto *transformedNode = cb(typeParameter_); typeParameter_ != transformedNode) { + typeParameter_->SetTransformedNode(transformationName, transformedNode); + typeParameter_ = transformedNode->AsTSTypeParameter(); + } + if (typeAnnotation_ != nullptr) { - typeAnnotation_ = static_cast(cb(typeAnnotation_)); + if (auto *transformedNode = cb(typeAnnotation_); typeAnnotation_ != transformedNode) { + typeAnnotation_->SetTransformedNode(transformationName, transformedNode); + typeAnnotation_ = static_cast(transformedNode); + } } } diff --git a/ets2panda/ir/ts/tsMappedType.h b/ets2panda/ir/ts/tsMappedType.h index 48871c081d8e6ede8da1665ad28ef1285f07cf3a..2d9469a8895f1b72bc5fd43146349c81197c2387 100644 --- a/ets2panda/ir/ts/tsMappedType.h +++ b/ets2panda/ir/ts/tsMappedType.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 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 @@ -52,7 +52,7 @@ public: return optional_; } - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/ts/tsModuleBlock.cpp b/ets2panda/ir/ts/tsModuleBlock.cpp index f16627aef13b92bf225872179a2771900916e87e..3b3ba03f288aa0c012a4ea9ffbe9934fa33f44d2 100644 --- a/ets2panda/ir/ts/tsModuleBlock.cpp +++ b/ets2panda/ir/ts/tsModuleBlock.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021-2022 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 @@ -15,7 +15,6 @@ #include "tsModuleBlock.h" -#include "varbinder/scope.h" #include "checker/TSchecker.h" #include "compiler/core/ETSGen.h" #include "compiler/core/pandagen.h" @@ -23,10 +22,13 @@ #include "ir/srcDump.h" namespace ark::es2panda::ir { -void TSModuleBlock::TransformChildren(const NodeTransformer &cb) +void TSModuleBlock::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { for (auto *&it : statements_) { - it = cb(it)->AsStatement(); + if (auto *transformedNode = cb(it); it != transformedNode) { + it->SetTransformedNode(transformationName, transformedNode); + it = transformedNode->AsStatement(); + } } } diff --git a/ets2panda/ir/ts/tsModuleBlock.h b/ets2panda/ir/ts/tsModuleBlock.h index f9ca0a3bc1fb100178efe3f1a7885b6bd09cd1ab..877eae789e594e312e8b2d6f248e8f0398b7148f 100644 --- a/ets2panda/ir/ts/tsModuleBlock.h +++ b/ets2panda/ir/ts/tsModuleBlock.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 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 @@ -27,18 +27,19 @@ public: { } - bool IsScopeBearer() const override + [[nodiscard]] bool IsScopeBearer() const noexcept override { return true; } - varbinder::Scope *Scope() const override + [[nodiscard]] varbinder::Scope *Scope() const noexcept override { return scope_; } void SetScope(varbinder::LocalScope *scope) { + ASSERT(scope_ == nullptr); scope_ = scope; } @@ -47,7 +48,7 @@ public: return statements_; } - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/ts/tsModuleDeclaration.cpp b/ets2panda/ir/ts/tsModuleDeclaration.cpp index 7ddaae46c9197f0514b42e0b3fb3a3d7f182a1b0..abc38e6c02aa9c80a272efdefd4c946da03cbe0f 100644 --- a/ets2panda/ir/ts/tsModuleDeclaration.cpp +++ b/ets2panda/ir/ts/tsModuleDeclaration.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021-2022 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 @@ -15,26 +15,33 @@ #include "tsModuleDeclaration.h" -#include "varbinder/scope.h" #include "checker/TSchecker.h" #include "compiler/core/ETSGen.h" #include "compiler/core/pandagen.h" #include "ir/astDump.h" #include "ir/srcDump.h" #include "ir/base/decorator.h" -#include "ir/expression.h" namespace ark::es2panda::ir { -void TSModuleDeclaration::TransformChildren(const NodeTransformer &cb) +void TSModuleDeclaration::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { for (auto *&it : decorators_) { - it = cb(it)->AsDecorator(); + if (auto *transformedNode = cb(it); it != transformedNode) { + it->SetTransformedNode(transformationName, transformedNode); + it = transformedNode->AsDecorator(); + } } - name_ = cb(name_)->AsExpression(); + if (auto *transformedNode = cb(name_); name_ != transformedNode) { + name_->SetTransformedNode(transformationName, transformedNode); + name_ = transformedNode->AsExpression(); + } if (body_ != nullptr) { - body_ = cb(body_)->AsStatement(); + if (auto *transformedNode = cb(body_); body_ != transformedNode) { + body_->SetTransformedNode(transformationName, transformedNode); + body_ = transformedNode->AsStatement(); + } } } diff --git a/ets2panda/ir/ts/tsModuleDeclaration.h b/ets2panda/ir/ts/tsModuleDeclaration.h index 35d3f8d43f5383f4c6f1b92f4368c8722c31af55..304c38fac6295637518f51d3cb39de31ef592a4b 100644 --- a/ets2panda/ir/ts/tsModuleDeclaration.h +++ b/ets2panda/ir/ts/tsModuleDeclaration.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 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 @@ -36,18 +36,19 @@ public: { } - bool IsScopeBearer() const override + [[nodiscard]] bool IsScopeBearer() const noexcept override { return true; } - varbinder::LocalScope *Scope() const override + [[nodiscard]] varbinder::LocalScope *Scope() const noexcept override { return scope_; } void SetScope(varbinder::LocalScope *scope) { + ASSERT(scope_ == nullptr); scope_ = scope; } @@ -86,7 +87,7 @@ public: return !inTs; } - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/ts/tsNamedTupleMember.cpp b/ets2panda/ir/ts/tsNamedTupleMember.cpp index 415543fc213fa4b5673895e54c21f628ee28c1cb..ab541e8cae6b08abca48ce7479ac6b059de59697 100644 --- a/ets2panda/ir/ts/tsNamedTupleMember.cpp +++ b/ets2panda/ir/ts/tsNamedTupleMember.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 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 @@ -23,10 +23,17 @@ #include "ir/srcDump.h" namespace ark::es2panda::ir { -void TSNamedTupleMember::TransformChildren(const NodeTransformer &cb) +void TSNamedTupleMember::TransformChildren(const NodeTransformer &cb, std::string_view const transformationName) { - label_ = cb(label_)->AsExpression(); - elementType_ = static_cast(cb(elementType_)); + if (auto *transformedNode = cb(label_); label_ != transformedNode) { + label_->SetTransformedNode(transformationName, transformedNode); + label_ = transformedNode->AsExpression(); + } + + if (auto *transformedNode = cb(elementType_); elementType_ != transformedNode) { + elementType_->SetTransformedNode(transformationName, transformedNode); + elementType_ = static_cast(transformedNode); + } } void TSNamedTupleMember::Iterate(const NodeTraverser &cb) const diff --git a/ets2panda/ir/ts/tsNamedTupleMember.h b/ets2panda/ir/ts/tsNamedTupleMember.h index aec8f37516b36d49f1485ebce8205e0c8898f85b..8f399628cd781275e04e89c354defe527efa894b 100644 --- a/ets2panda/ir/ts/tsNamedTupleMember.h +++ b/ets2panda/ir/ts/tsNamedTupleMember.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 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 @@ -46,7 +46,7 @@ public: return optional_; } - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/ts/tsNeverKeyword.cpp b/ets2panda/ir/ts/tsNeverKeyword.cpp index 4ced6f0cd237a072005e4995576dc872a9a1d9f1..0dde19e4a1ec70d71bf7c00470f5c3ab17729ac1 100644 --- a/ets2panda/ir/ts/tsNeverKeyword.cpp +++ b/ets2panda/ir/ts/tsNeverKeyword.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021-2022 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 @@ -22,7 +22,11 @@ #include "checker/TSchecker.h" namespace ark::es2panda::ir { -void TSNeverKeyword::TransformChildren([[maybe_unused]] const NodeTransformer &cb) {} +void TSNeverKeyword::TransformChildren([[maybe_unused]] const NodeTransformer &cb, + [[maybe_unused]] std::string_view const transformationName) +{ +} + void TSNeverKeyword::Iterate([[maybe_unused]] const NodeTraverser &cb) const {} void TSNeverKeyword::Dump(ir::AstDumper *dumper) const diff --git a/ets2panda/ir/ts/tsNeverKeyword.h b/ets2panda/ir/ts/tsNeverKeyword.h index 7e490832874eb7035141fabea1a27dd74e65cc79..9a58112e34e560f4cd6903b3a5976782a6c4c088 100644 --- a/ets2panda/ir/ts/tsNeverKeyword.h +++ b/ets2panda/ir/ts/tsNeverKeyword.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 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 @@ -23,7 +23,7 @@ class TSNeverKeyword : public TypeNode { public: explicit TSNeverKeyword() : TypeNode(AstNodeType::TS_NEVER_KEYWORD) {} - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/ts/tsNonNullExpression.cpp b/ets2panda/ir/ts/tsNonNullExpression.cpp index c2513e7f30107e0caa0ab820f3e6080ce0a928e1..d6b82084163c5538bb523329da51fb1e4284e9d7 100644 --- a/ets2panda/ir/ts/tsNonNullExpression.cpp +++ b/ets2panda/ir/ts/tsNonNullExpression.cpp @@ -23,9 +23,12 @@ #include "ir/srcDump.h" namespace ark::es2panda::ir { -void TSNonNullExpression::TransformChildren(const NodeTransformer &cb) +void TSNonNullExpression::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { - expr_ = cb(expr_)->AsExpression(); + if (auto *transformedNode = cb(expr_); expr_ != transformedNode) { + expr_->SetTransformedNode(transformationName, transformedNode); + expr_ = transformedNode->AsExpression(); + } } void TSNonNullExpression::Iterate(const NodeTraverser &cb) const diff --git a/ets2panda/ir/ts/tsNonNullExpression.h b/ets2panda/ir/ts/tsNonNullExpression.h index 2e772bf542ab7dd44a2850b496951335d96e1164..316707a143a03bc09b6ba9a9b73286032d88efd9 100644 --- a/ets2panda/ir/ts/tsNonNullExpression.h +++ b/ets2panda/ir/ts/tsNonNullExpression.h @@ -44,7 +44,17 @@ public: expr_ = expr; } - void TransformChildren(const NodeTransformer &cb) override; + checker::Type *OriginalType() const noexcept + { + return originalType_; + } + + void SetOriginalType(checker::Type *type) noexcept + { + originalType_ = type; + } + + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; @@ -62,6 +72,7 @@ public: private: Expression *expr_; + checker::Type *originalType_ = nullptr; }; } // namespace ark::es2panda::ir diff --git a/ets2panda/ir/ts/tsNullKeyword.cpp b/ets2panda/ir/ts/tsNullKeyword.cpp index 43c7ac60be7debe154b3d121fde1e933530859f3..cada8cf2fb2631df51111dc9d2c21c5d36d640ab 100644 --- a/ets2panda/ir/ts/tsNullKeyword.cpp +++ b/ets2panda/ir/ts/tsNullKeyword.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021-2022 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 @@ -22,7 +22,11 @@ #include "checker/TSchecker.h" namespace ark::es2panda::ir { -void TSNullKeyword::TransformChildren([[maybe_unused]] const NodeTransformer &cb) {} +void TSNullKeyword::TransformChildren([[maybe_unused]] const NodeTransformer &cb, + [[maybe_unused]] std::string_view const transformationName) +{ +} + void TSNullKeyword::Iterate([[maybe_unused]] const NodeTraverser &cb) const {} void TSNullKeyword::Dump(ir::AstDumper *dumper) const diff --git a/ets2panda/ir/ts/tsNullKeyword.h b/ets2panda/ir/ts/tsNullKeyword.h index 0f79d2e40ee70473a4997b84ca7d67139610572d..e50c99c1f40dd23252456502585e5e87e20ca8b7 100644 --- a/ets2panda/ir/ts/tsNullKeyword.h +++ b/ets2panda/ir/ts/tsNullKeyword.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021-2022 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 @@ -23,7 +23,7 @@ class TSNullKeyword : public TypeNode { public: explicit TSNullKeyword() : TypeNode(AstNodeType::TS_NULL_KEYWORD) {} - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/ts/tsNumberKeyword.cpp b/ets2panda/ir/ts/tsNumberKeyword.cpp index 94285d57985eee08d2f5e9030b8bd3f296c2b01b..0a89cfa4a55cb24350be277066fe0741dbd0e33e 100644 --- a/ets2panda/ir/ts/tsNumberKeyword.cpp +++ b/ets2panda/ir/ts/tsNumberKeyword.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021-2022 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 @@ -22,7 +22,11 @@ #include "ir/srcDump.h" namespace ark::es2panda::ir { -void TSNumberKeyword::TransformChildren([[maybe_unused]] const NodeTransformer &cb) {} +void TSNumberKeyword::TransformChildren([[maybe_unused]] const NodeTransformer &cb, + [[maybe_unused]] std::string_view const transformationName) +{ +} + void TSNumberKeyword::Iterate([[maybe_unused]] const NodeTraverser &cb) const {} void TSNumberKeyword::Dump(ir::AstDumper *dumper) const diff --git a/ets2panda/ir/ts/tsNumberKeyword.h b/ets2panda/ir/ts/tsNumberKeyword.h index bbfd40afab53af8cc955be703d42cca941c13a9c..beb982c1dc00b1cc690c7ee14d062f203d519648 100644 --- a/ets2panda/ir/ts/tsNumberKeyword.h +++ b/ets2panda/ir/ts/tsNumberKeyword.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 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 @@ -23,7 +23,7 @@ class TSNumberKeyword : public TypeNode { public: explicit TSNumberKeyword() : TypeNode(AstNodeType::TS_NUMBER_KEYWORD) {} - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/ts/tsObjectKeyword.cpp b/ets2panda/ir/ts/tsObjectKeyword.cpp index 88d0e1d6be3643c7445865e564dff970bc09c93b..2ccd2ab4b9057148a128adf4c0be52d26e04bb28 100644 --- a/ets2panda/ir/ts/tsObjectKeyword.cpp +++ b/ets2panda/ir/ts/tsObjectKeyword.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021-2022 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 @@ -22,7 +22,11 @@ #include "ir/srcDump.h" namespace ark::es2panda::ir { -void TSObjectKeyword::TransformChildren([[maybe_unused]] const NodeTransformer &cb) {} +void TSObjectKeyword::TransformChildren([[maybe_unused]] const NodeTransformer &cb, + [[maybe_unused]] std::string_view const transformationName) +{ +} + void TSObjectKeyword::Iterate([[maybe_unused]] const NodeTraverser &cb) const {} void TSObjectKeyword::Dump(ir::AstDumper *dumper) const diff --git a/ets2panda/ir/ts/tsObjectKeyword.h b/ets2panda/ir/ts/tsObjectKeyword.h index 6060105d2ee39aecb38c63a3bdf939f7f4ada5c1..cf18f5de55d90ef8e1c03c016bf01981e19e8fc0 100644 --- a/ets2panda/ir/ts/tsObjectKeyword.h +++ b/ets2panda/ir/ts/tsObjectKeyword.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 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 @@ -23,7 +23,7 @@ class TSObjectKeyword : public TypeNode { public: explicit TSObjectKeyword() : TypeNode(AstNodeType::TS_OBJECT_KEYWORD) {} - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/ts/tsParameterProperty.cpp b/ets2panda/ir/ts/tsParameterProperty.cpp index 26020731ae01aa9b882e3c8faf370a887113dda9..e2adb0787fadfdbdf1a8812b8cf0f82f00a55caf 100644 --- a/ets2panda/ir/ts/tsParameterProperty.cpp +++ b/ets2panda/ir/ts/tsParameterProperty.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021-2022 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 @@ -23,9 +23,12 @@ #include "ir/expression.h" namespace ark::es2panda::ir { -void TSParameterProperty::TransformChildren(const NodeTransformer &cb) +void TSParameterProperty::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { - parameter_ = cb(parameter_)->AsExpression(); + if (auto *transformedNode = cb(parameter_); parameter_ != transformedNode) { + parameter_->SetTransformedNode(transformationName, transformedNode); + parameter_ = transformedNode->AsExpression(); + } } void TSParameterProperty::Iterate(const NodeTraverser &cb) const diff --git a/ets2panda/ir/ts/tsParameterProperty.h b/ets2panda/ir/ts/tsParameterProperty.h index e1da3e8dcddf92b855a2b0ef8a3a01dec0757141..9ebb86812f8e9cdc1558f1f19e481043d7c9c95b 100644 --- a/ets2panda/ir/ts/tsParameterProperty.h +++ b/ets2panda/ir/ts/tsParameterProperty.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 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 @@ -60,7 +60,7 @@ public: return parameter_; } - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/ts/tsParenthesizedType.cpp b/ets2panda/ir/ts/tsParenthesizedType.cpp index b845de55822ad4d4b624b949adf0f13086a16052..62a336d6151a31bef798ac17643ba7dd67253ee8 100644 --- a/ets2panda/ir/ts/tsParenthesizedType.cpp +++ b/ets2panda/ir/ts/tsParenthesizedType.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021-2022 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 @@ -22,9 +22,12 @@ #include "checker/TSchecker.h" namespace ark::es2panda::ir { -void TSParenthesizedType::TransformChildren(const NodeTransformer &cb) +void TSParenthesizedType::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { - type_ = static_cast(cb(type_)); + if (auto *transformedNode = cb(type_); type_ != transformedNode) { + type_->SetTransformedNode(transformationName, transformedNode); + type_ = static_cast(transformedNode); + } } void TSParenthesizedType::Iterate(const NodeTraverser &cb) const diff --git a/ets2panda/ir/ts/tsParenthesizedType.h b/ets2panda/ir/ts/tsParenthesizedType.h index 7faec68308aa4acf17d78c76584ac672bbdbb606..dce7eabe38e67c43cf96d6d33f1cf9204c001112 100644 --- a/ets2panda/ir/ts/tsParenthesizedType.h +++ b/ets2panda/ir/ts/tsParenthesizedType.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 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 @@ -33,7 +33,7 @@ public: return type_; } - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/ts/tsQualifiedName.cpp b/ets2panda/ir/ts/tsQualifiedName.cpp index 4eaac0b13933433e794a8e12e1f7bdb65dd79cf9..bb1e3992d26eaa1baf9d49c00f47ed0e10f93ca5 100644 --- a/ets2panda/ir/ts/tsQualifiedName.cpp +++ b/ets2panda/ir/ts/tsQualifiedName.cpp @@ -38,10 +38,17 @@ void TSQualifiedName::Iterate(const NodeTraverser &cb) const cb(right_); } -void TSQualifiedName::TransformChildren(const NodeTransformer &cb) +void TSQualifiedName::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { - left_ = cb(left_)->AsExpression(); - right_ = cb(right_)->AsIdentifier(); + if (auto *transformedNode = cb(left_); left_ != transformedNode) { + left_->SetTransformedNode(transformationName, transformedNode); + left_ = transformedNode->AsExpression(); + } + + if (auto *transformedNode = cb(right_); right_ != transformedNode) { + right_->SetTransformedNode(transformationName, transformedNode); + right_ = transformedNode->AsIdentifier(); + } } void TSQualifiedName::Dump(ir::AstDumper *dumper) const diff --git a/ets2panda/ir/ts/tsQualifiedName.h b/ets2panda/ir/ts/tsQualifiedName.h index 1bf699b6cd8204e86f947a8b6bbdf494749f351b..ef7bbddccd6082d6866d2006557c438967de67ce 100644 --- a/ets2panda/ir/ts/tsQualifiedName.h +++ b/ets2panda/ir/ts/tsQualifiedName.h @@ -63,7 +63,7 @@ public: [[nodiscard]] TSQualifiedName *Clone(ArenaAllocator *allocator, AstNode *parent) override; - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/ts/tsStringKeyword.cpp b/ets2panda/ir/ts/tsStringKeyword.cpp index 1a0a403ab3164f2b80b36def71e29d8430a2ff8d..3d63e2a02770cd158fb600dc0de69770cd895c05 100644 --- a/ets2panda/ir/ts/tsStringKeyword.cpp +++ b/ets2panda/ir/ts/tsStringKeyword.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021-2022 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 @@ -22,7 +22,11 @@ #include "ir/srcDump.h" namespace ark::es2panda::ir { -void TSStringKeyword::TransformChildren([[maybe_unused]] const NodeTransformer &cb) {} +void TSStringKeyword::TransformChildren([[maybe_unused]] const NodeTransformer &cb, + [[maybe_unused]] std::string_view const transformationName) +{ +} + void TSStringKeyword::Iterate([[maybe_unused]] const NodeTraverser &cb) const {} void TSStringKeyword::Dump(ir::AstDumper *dumper) const diff --git a/ets2panda/ir/ts/tsStringKeyword.h b/ets2panda/ir/ts/tsStringKeyword.h index 34825e8eb2d9b70fd6e3dee444a937e3ac572529..91739d3767306f48b3f5056cb3a7a5ecb710d020 100644 --- a/ets2panda/ir/ts/tsStringKeyword.h +++ b/ets2panda/ir/ts/tsStringKeyword.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 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 @@ -23,7 +23,7 @@ class TSStringKeyword : public TypeNode { public: explicit TSStringKeyword() : TypeNode(AstNodeType::TS_STRING_KEYWORD) {} - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/ts/tsThisType.cpp b/ets2panda/ir/ts/tsThisType.cpp index 802a8ad4039449fb188c79e66ecd4d9cf3101275..d317d7253c28c26c19cf0f24e0c827d31d2bcf43 100644 --- a/ets2panda/ir/ts/tsThisType.cpp +++ b/ets2panda/ir/ts/tsThisType.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021-2022 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 @@ -23,7 +23,11 @@ #include "ir/srcDump.h" namespace ark::es2panda::ir { -void TSThisType::TransformChildren([[maybe_unused]] const NodeTransformer &cb) {} +void TSThisType::TransformChildren([[maybe_unused]] const NodeTransformer &cb, + [[maybe_unused]] std::string_view const transformationName) +{ +} + void TSThisType::Iterate([[maybe_unused]] const NodeTraverser &cb) const {} void TSThisType::Dump(ir::AstDumper *dumper) const diff --git a/ets2panda/ir/ts/tsThisType.h b/ets2panda/ir/ts/tsThisType.h index e102d1e5e3b45ba1298633ce99c397f94d0cca2a..23b24d26dc25108e9348572814f266b8a27e8be8 100644 --- a/ets2panda/ir/ts/tsThisType.h +++ b/ets2panda/ir/ts/tsThisType.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021-2022 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 @@ -23,7 +23,7 @@ class TSThisType : public TypeNode { public: explicit TSThisType() : TypeNode(AstNodeType::TS_THIS_TYPE) {} - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/ts/tsTupleType.cpp b/ets2panda/ir/ts/tsTupleType.cpp index f531aef829490aa96c88d9d8eeda4434112fc9a9..dcd05ea63b4a19adb4077af78242ca1d6b767a36 100644 --- a/ets2panda/ir/ts/tsTupleType.cpp +++ b/ets2panda/ir/ts/tsTupleType.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 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 @@ -27,10 +27,13 @@ #include "ir/ts/tsNamedTupleMember.h" namespace ark::es2panda::ir { -void TSTupleType::TransformChildren(const NodeTransformer &cb) +void TSTupleType::TransformChildren(const NodeTransformer &cb, std::string_view const transformationName) { for (auto *&it : elementTypes_) { - it = static_cast(cb(it)); + if (auto *transformedNode = cb(it); it != transformedNode) { + it->SetTransformedNode(transformationName, transformedNode); + it = static_cast(transformedNode); + } } } diff --git a/ets2panda/ir/ts/tsTupleType.h b/ets2panda/ir/ts/tsTupleType.h index 0cf625a17c90c86399cc18a812d249d69c122715..d482d934db8e0987c887ff6e34bbb62b039bcb0c 100644 --- a/ets2panda/ir/ts/tsTupleType.h +++ b/ets2panda/ir/ts/tsTupleType.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 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 @@ -33,7 +33,7 @@ public: return elementTypes_; } - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/ts/tsTypeAliasDeclaration.cpp b/ets2panda/ir/ts/tsTypeAliasDeclaration.cpp index f353a26f46b8c09184cbfd19caed690440fa1fbd..bfc882b896ca532b73f9bc5d97738d53ee15f4ea 100644 --- a/ets2panda/ir/ts/tsTypeAliasDeclaration.cpp +++ b/ets2panda/ir/ts/tsTypeAliasDeclaration.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 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 @@ -14,10 +14,7 @@ */ #include "tsTypeAliasDeclaration.h" -#include -#include "macros.h" -#include "varbinder/scope.h" #include "checker/TSchecker.h" #include "compiler/core/ETSGen.h" #include "compiler/core/pandagen.h" @@ -30,20 +27,32 @@ #include "ir/ts/tsTypeParameterDeclaration.h" namespace ark::es2panda::ir { -void TSTypeAliasDeclaration::TransformChildren(const NodeTransformer &cb) +void TSTypeAliasDeclaration::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { for (auto *&it : decorators_) { - it = cb(it)->AsDecorator(); + if (auto *transformedNode = cb(it); it != transformedNode) { + it->SetTransformedNode(transformationName, transformedNode); + it = transformedNode->AsDecorator(); + } } - id_ = cb(id_)->AsIdentifier(); + if (auto *transformedNode = cb(id_); id_ != transformedNode) { + id_->SetTransformedNode(transformationName, transformedNode); + id_ = transformedNode->AsIdentifier(); + } if (typeParams_ != nullptr) { - typeParams_ = cb(typeParams_)->AsTSTypeParameterDeclaration(); + if (auto *transformedNode = cb(typeParams_); typeParams_ != transformedNode) { + typeParams_->SetTransformedNode(transformationName, transformedNode); + typeParams_ = transformedNode->AsTSTypeParameterDeclaration(); + } } - if (TypeAnnotation() != nullptr) { - SetTsTypeAnnotation(static_cast(cb(TypeAnnotation()))); + if (auto *typeAnnotation = TypeAnnotation(); typeAnnotation != nullptr) { + if (auto *transformedNode = cb(typeAnnotation); typeAnnotation != transformedNode) { + typeAnnotation->SetTransformedNode(transformationName, transformedNode); + SetTsTypeAnnotation(static_cast(transformedNode)); + } } } diff --git a/ets2panda/ir/ts/tsTypeAliasDeclaration.h b/ets2panda/ir/ts/tsTypeAliasDeclaration.h index 4aefa921a357159998e475d46a243c4dad1cff2e..f00e94e3f1cb138ce96c13ed8015f99e9b4d379b 100644 --- a/ets2panda/ir/ts/tsTypeAliasDeclaration.h +++ b/ets2panda/ir/ts/tsTypeAliasDeclaration.h @@ -104,7 +104,7 @@ public: return typeParamTypes_; } - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/ts/tsTypeAssertion.cpp b/ets2panda/ir/ts/tsTypeAssertion.cpp index 0ec57656c78267569941cba8f13363be837cbb02..b939c1c5b3aff7a189af38c5bd73ea76562595b8 100644 --- a/ets2panda/ir/ts/tsTypeAssertion.cpp +++ b/ets2panda/ir/ts/tsTypeAssertion.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021-2022 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 @@ -23,10 +23,19 @@ #include "ir/typeNode.h" namespace ark::es2panda::ir { -void TSTypeAssertion::TransformChildren(const NodeTransformer &cb) +void TSTypeAssertion::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { - SetTsTypeAnnotation(static_cast(cb(TypeAnnotation()))); - expression_ = cb(expression_)->AsExpression(); + if (auto *typeAnnotation = TypeAnnotation(); typeAnnotation != nullptr) { + if (auto *transformedNode = cb(typeAnnotation); typeAnnotation != transformedNode) { + typeAnnotation->SetTransformedNode(transformationName, transformedNode); + SetTsTypeAnnotation(static_cast(transformedNode)); + } + } + + if (auto *transformedNode = cb(expression_); expression_ != transformedNode) { + expression_->SetTransformedNode(transformationName, transformedNode); + expression_ = transformedNode->AsExpression(); + } } void TSTypeAssertion::Iterate(const NodeTraverser &cb) const diff --git a/ets2panda/ir/ts/tsTypeAssertion.h b/ets2panda/ir/ts/tsTypeAssertion.h index bf5dc1105a235b2283b3f26a15b4c1f8f2138c62..6da2c817cd7e8da1a40332fe85280a5cefbfbd66 100644 --- a/ets2panda/ir/ts/tsTypeAssertion.h +++ b/ets2panda/ir/ts/tsTypeAssertion.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 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 @@ -31,7 +31,7 @@ public: return expression_; } - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/ts/tsTypeLiteral.cpp b/ets2panda/ir/ts/tsTypeLiteral.cpp index ed44400d2987a6dfd0e7ae16c3555e098a312a85..f4607ef7cad0059909c204d955f361bc161fe6de 100644 --- a/ets2panda/ir/ts/tsTypeLiteral.cpp +++ b/ets2panda/ir/ts/tsTypeLiteral.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 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 @@ -26,10 +26,13 @@ #include "checker/types/signature.h" namespace ark::es2panda::ir { -void TSTypeLiteral::TransformChildren(const NodeTransformer &cb) +void TSTypeLiteral::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { for (auto *&it : members_) { - it = cb(it); + if (auto *transformedNode = cb(it); it != transformedNode) { + it->SetTransformedNode(transformationName, transformedNode); + it = transformedNode; + } } } diff --git a/ets2panda/ir/ts/tsTypeLiteral.h b/ets2panda/ir/ts/tsTypeLiteral.h index 26a6988ccaa53eb286ce728d17586f2dfd465381..a881ba162eb95f1c2d37b9943902883537a7960b 100644 --- a/ets2panda/ir/ts/tsTypeLiteral.h +++ b/ets2panda/ir/ts/tsTypeLiteral.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 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 @@ -31,7 +31,7 @@ public: return members_; } - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/ts/tsTypeOperator.cpp b/ets2panda/ir/ts/tsTypeOperator.cpp index 0a51fd7b69db1b6649bd44324efa9de8bc5c57d8..2fae5deee9d4428152767cbe7b4cb3bf7c0543c5 100644 --- a/ets2panda/ir/ts/tsTypeOperator.cpp +++ b/ets2panda/ir/ts/tsTypeOperator.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021-2022 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 @@ -22,9 +22,12 @@ #include "ir/srcDump.h" namespace ark::es2panda::ir { -void TSTypeOperator::TransformChildren(const NodeTransformer &cb) +void TSTypeOperator::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { - type_ = static_cast(cb(type_)); + if (auto *transformedNode = cb(type_); type_ != transformedNode) { + type_->SetTransformedNode(transformationName, transformedNode); + type_ = static_cast(transformedNode); + } } void TSTypeOperator::Iterate(const NodeTraverser &cb) const diff --git a/ets2panda/ir/ts/tsTypeOperator.h b/ets2panda/ir/ts/tsTypeOperator.h index 8444613981e640003df8a605ac6f5809267c618d..450f014c6b2c19209092b8399e4fd32dcc629922 100644 --- a/ets2panda/ir/ts/tsTypeOperator.h +++ b/ets2panda/ir/ts/tsTypeOperator.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 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 @@ -46,7 +46,7 @@ public: return operatorType_ == TSOperatorType::UNIQUE; } - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/ts/tsTypeParameter.cpp b/ets2panda/ir/ts/tsTypeParameter.cpp index cbdd3759b6fb1995bd3a9d01df7389a9bd6ff3b0..7e5ddd4d24937126e2cf226d6a1d82241afb1af1 100644 --- a/ets2panda/ir/ts/tsTypeParameter.cpp +++ b/ets2panda/ir/ts/tsTypeParameter.cpp @@ -1,5 +1,5 @@ -/** - * Copyright (c) 2021 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 @@ -24,16 +24,25 @@ #include "ir/expressions/identifier.h" namespace ark::es2panda::ir { -void TSTypeParameter::TransformChildren(const NodeTransformer &cb) +void TSTypeParameter::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { - name_ = cb(name_)->AsIdentifier(); + if (auto *transformedNode = cb(name_); name_ != transformedNode) { + name_->SetTransformedNode(transformationName, transformedNode); + name_ = transformedNode->AsIdentifier(); + } if (constraint_ != nullptr) { - constraint_ = static_cast(cb(constraint_)); + if (auto *transformedNode = cb(constraint_); constraint_ != transformedNode) { + constraint_->SetTransformedNode(transformationName, transformedNode); + constraint_ = static_cast(transformedNode); + } } if (defaultType_ != nullptr) { - defaultType_ = static_cast(cb(defaultType_)); + if (auto *transformedNode = cb(defaultType_); defaultType_ != transformedNode) { + defaultType_->SetTransformedNode(transformationName, transformedNode); + defaultType_ = static_cast(transformedNode); + } } } diff --git a/ets2panda/ir/ts/tsTypeParameter.h b/ets2panda/ir/ts/tsTypeParameter.h index bf5e210180768875431e3be9979ebb82c1d79db6..82b956e6d9499ed1e2692ea860ad595af4201747 100644 --- a/ets2panda/ir/ts/tsTypeParameter.h +++ b/ets2panda/ir/ts/tsTypeParameter.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 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 @@ -62,7 +62,7 @@ public: return defaultType_; } - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/ts/tsTypeParameterDeclaration.cpp b/ets2panda/ir/ts/tsTypeParameterDeclaration.cpp index 11b790500e6c8aec87527bf3cbd9151b25c1e475..a72da5b885f9e0c6baa38f0b043b9d1bc4386621 100644 --- a/ets2panda/ir/ts/tsTypeParameterDeclaration.cpp +++ b/ets2panda/ir/ts/tsTypeParameterDeclaration.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021-2022 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 @@ -15,7 +15,6 @@ #include "tsTypeParameterDeclaration.h" -#include "varbinder/scope.h" #include "checker/TSchecker.h" #include "compiler/core/ETSGen.h" #include "compiler/core/pandagen.h" @@ -24,10 +23,13 @@ #include "ir/ts/tsTypeParameter.h" namespace ark::es2panda::ir { -void TSTypeParameterDeclaration::TransformChildren(const NodeTransformer &cb) +void TSTypeParameterDeclaration::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { for (auto *&it : params_) { - cb(it)->AsTSTypeParameter(); + if (auto *transformedNode = cb(it); it != transformedNode) { + it->SetTransformedNode(transformationName, transformedNode); + it = transformedNode->AsTSTypeParameter(); + } } } diff --git a/ets2panda/ir/ts/tsTypeParameterDeclaration.h b/ets2panda/ir/ts/tsTypeParameterDeclaration.h index da78d320c5a677008db6f126519cb503d317e876..a145e0dcec89c884645787bb849958aeb3b075ff 100644 --- a/ets2panda/ir/ts/tsTypeParameterDeclaration.h +++ b/ets2panda/ir/ts/tsTypeParameterDeclaration.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 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 @@ -31,18 +31,19 @@ public: { } - bool IsScopeBearer() const override + [[nodiscard]] bool IsScopeBearer() const noexcept override { return true; } - varbinder::LocalScope *Scope() const override + [[nodiscard]] varbinder::LocalScope *Scope() const noexcept override { return scope_; } void SetScope(varbinder::LocalScope *scope) { + ASSERT(scope_ == nullptr); scope_ = scope; } @@ -64,7 +65,7 @@ public: return requiredParams_; } - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/ts/tsTypeParameterInstantiation.cpp b/ets2panda/ir/ts/tsTypeParameterInstantiation.cpp index 972bf398f1f9fa80c7ff65a1bc686b2635a613bb..22ac939a19f92dfd635ad9bc0951f80c0de47cc6 100644 --- a/ets2panda/ir/ts/tsTypeParameterInstantiation.cpp +++ b/ets2panda/ir/ts/tsTypeParameterInstantiation.cpp @@ -47,10 +47,13 @@ TSTypeParameterInstantiation *TSTypeParameterInstantiation::Clone(ArenaAllocator throw Error(ErrorType::GENERIC, "", CLONE_ALLOCATION_ERROR); } -void TSTypeParameterInstantiation::TransformChildren(const NodeTransformer &cb) +void TSTypeParameterInstantiation::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { for (auto *&it : params_) { - it = static_cast(cb(it)); + if (auto *transformedNode = cb(it); it != transformedNode) { + it->SetTransformedNode(transformationName, transformedNode); + it = static_cast(transformedNode); + } } } diff --git a/ets2panda/ir/ts/tsTypeParameterInstantiation.h b/ets2panda/ir/ts/tsTypeParameterInstantiation.h index 84c8fb67218c79d2243838a0e1083a3338e0c2b7..f251f6730c24f50d75dbced36579025f60cd9d89 100644 --- a/ets2panda/ir/ts/tsTypeParameterInstantiation.h +++ b/ets2panda/ir/ts/tsTypeParameterInstantiation.h @@ -44,7 +44,7 @@ public: [[nodiscard]] TSTypeParameterInstantiation *Clone(ArenaAllocator *allocator, AstNode *parent) override; - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/ts/tsTypePredicate.cpp b/ets2panda/ir/ts/tsTypePredicate.cpp index 956b6698723900b9d7e22cc7e9fce80a52ef9bdf..6576719979dbf5bcf38b620321581a090f2148e6 100644 --- a/ets2panda/ir/ts/tsTypePredicate.cpp +++ b/ets2panda/ir/ts/tsTypePredicate.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 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 @@ -24,11 +24,18 @@ #include "ir/expression.h" namespace ark::es2panda::ir { -void TSTypePredicate::TransformChildren(const NodeTransformer &cb) +void TSTypePredicate::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { - parameterName_ = cb(parameterName_)->AsExpression(); + if (auto *transformedNode = cb(parameterName_); parameterName_ != transformedNode) { + parameterName_->SetTransformedNode(transformationName, transformedNode); + parameterName_ = transformedNode->AsExpression(); + } + if (typeAnnotation_ != nullptr) { - typeAnnotation_ = static_cast(cb(typeAnnotation_)); + if (auto *transformedNode = cb(typeAnnotation_); typeAnnotation_ != transformedNode) { + typeAnnotation_->SetTransformedNode(transformationName, transformedNode); + typeAnnotation_ = static_cast(transformedNode); + } } } diff --git a/ets2panda/ir/ts/tsTypePredicate.h b/ets2panda/ir/ts/tsTypePredicate.h index 40695a9eeff139c890fe41ece383eefee4aaf665..49f775ced3a723f05afe0e0f552e2d48bcb3e6ce 100644 --- a/ets2panda/ir/ts/tsTypePredicate.h +++ b/ets2panda/ir/ts/tsTypePredicate.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 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 @@ -44,7 +44,7 @@ public: return asserts_; } - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/ts/tsTypeQuery.cpp b/ets2panda/ir/ts/tsTypeQuery.cpp index d9b0ae7624ef9284e5399b1f1cb3dd9f13ca1f53..e366fddbef1903605a9e0d4503b241a930319c7b 100644 --- a/ets2panda/ir/ts/tsTypeQuery.cpp +++ b/ets2panda/ir/ts/tsTypeQuery.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021-2022 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 @@ -23,9 +23,12 @@ #include "checker/TSchecker.h" namespace ark::es2panda::ir { -void TSTypeQuery::TransformChildren(const NodeTransformer &cb) +void TSTypeQuery::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { - exprName_ = cb(exprName_)->AsExpression(); + if (auto *transformedNode = cb(exprName_); exprName_ != transformedNode) { + exprName_->SetTransformedNode(transformationName, transformedNode); + exprName_ = transformedNode->AsExpression(); + } } void TSTypeQuery::Iterate(const NodeTraverser &cb) const diff --git a/ets2panda/ir/ts/tsTypeQuery.h b/ets2panda/ir/ts/tsTypeQuery.h index b6b3f1c17fd5c73cc1aa34f19e5277b47861db88..2bdce5f2aa271076cb0b83e91a06d419c57b43f1 100644 --- a/ets2panda/ir/ts/tsTypeQuery.h +++ b/ets2panda/ir/ts/tsTypeQuery.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 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 @@ -32,7 +32,7 @@ public: return exprName_; } - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/ts/tsTypeReference.cpp b/ets2panda/ir/ts/tsTypeReference.cpp index 828bc2fafd4f32f1de67bf52c207fde18532591a..77237b56c39ef3cf641873197858032af553a354 100644 --- a/ets2panda/ir/ts/tsTypeReference.cpp +++ b/ets2panda/ir/ts/tsTypeReference.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 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 @@ -31,13 +31,19 @@ #include "ir/ts/tsQualifiedName.h" namespace ark::es2panda::ir { -void TSTypeReference::TransformChildren(const NodeTransformer &cb) +void TSTypeReference::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { if (typeParams_ != nullptr) { - typeParams_ = cb(typeParams_)->AsTSTypeParameterInstantiation(); + if (auto *transformedNode = cb(typeParams_); typeParams_ != transformedNode) { + typeParams_->SetTransformedNode(transformationName, transformedNode); + typeParams_ = transformedNode->AsTSTypeParameterInstantiation(); + } } - typeName_ = cb(typeName_)->AsExpression(); + if (auto *transformedNode = cb(typeName_); typeName_ != transformedNode) { + typeName_->SetTransformedNode(transformationName, transformedNode); + typeName_ = transformedNode->AsExpression(); + } } void TSTypeReference::Iterate(const NodeTraverser &cb) const diff --git a/ets2panda/ir/ts/tsTypeReference.h b/ets2panda/ir/ts/tsTypeReference.h index 062ccc9ad5f1bce8224acc6204cf42be9bebb429..fdd099bcab0b07ca24686b7f5012a745468b7783 100644 --- a/ets2panda/ir/ts/tsTypeReference.h +++ b/ets2panda/ir/ts/tsTypeReference.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 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 @@ -44,7 +44,7 @@ public: ir::Identifier *BaseName() const; - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/ts/tsUndefinedKeyword.cpp b/ets2panda/ir/ts/tsUndefinedKeyword.cpp index cde8ff8680a242abba80ba78505685ffbc6b2ee0..d3caacd06ee65f69e400f5694e3f66377748d8fd 100644 --- a/ets2panda/ir/ts/tsUndefinedKeyword.cpp +++ b/ets2panda/ir/ts/tsUndefinedKeyword.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021-2022 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 @@ -22,7 +22,11 @@ #include "ir/srcDump.h" namespace ark::es2panda::ir { -void TSUndefinedKeyword::TransformChildren([[maybe_unused]] const NodeTransformer &cb) {} +void TSUndefinedKeyword::TransformChildren([[maybe_unused]] const NodeTransformer &cb, + [[maybe_unused]] std::string_view const transformationName) +{ +} + void TSUndefinedKeyword::Iterate([[maybe_unused]] const NodeTraverser &cb) const {} void TSUndefinedKeyword::Dump(ir::AstDumper *dumper) const diff --git a/ets2panda/ir/ts/tsUndefinedKeyword.h b/ets2panda/ir/ts/tsUndefinedKeyword.h index 141b1f45ab925b3d0668136c93b71b986a655e8e..e4b8d1fe7009d4fa7d2a1a6e54f27bc151264cf8 100644 --- a/ets2panda/ir/ts/tsUndefinedKeyword.h +++ b/ets2panda/ir/ts/tsUndefinedKeyword.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 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 @@ -23,7 +23,7 @@ class TSUndefinedKeyword : public TypeNode { public: explicit TSUndefinedKeyword() : TypeNode(AstNodeType::TS_UNDEFINED_KEYWORD) {} - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/ts/tsUnionType.cpp b/ets2panda/ir/ts/tsUnionType.cpp index b60abf3d32c4524c509b44682844fc3099ec9867..de6f040945ed7199fbd18685dfd5a09678659aca 100644 --- a/ets2panda/ir/ts/tsUnionType.cpp +++ b/ets2panda/ir/ts/tsUnionType.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021-2022 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 @@ -22,10 +22,13 @@ #include "ir/srcDump.h" namespace ark::es2panda::ir { -void TSUnionType::TransformChildren(const NodeTransformer &cb) +void TSUnionType::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { for (auto *&it : types_) { - it = static_cast(cb(it)); + if (auto *transformedNode = cb(it); it != transformedNode) { + it->SetTransformedNode(transformationName, transformedNode); + it = static_cast(transformedNode); + } } } diff --git a/ets2panda/ir/ts/tsUnionType.h b/ets2panda/ir/ts/tsUnionType.h index b75aa570a5f87d33d739fda156e5e100eae2cfa4..262c61686ccf571835e30142fd5449fd1eeddcf7 100644 --- a/ets2panda/ir/ts/tsUnionType.h +++ b/ets2panda/ir/ts/tsUnionType.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 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 @@ -31,7 +31,7 @@ public: return types_; } - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/ts/tsUnknownKeyword.cpp b/ets2panda/ir/ts/tsUnknownKeyword.cpp index 465fde7be4e48057407a4174cdd566cb5a28269c..5cddd04fc02d30bddf71fce61162c23e229cd73a 100644 --- a/ets2panda/ir/ts/tsUnknownKeyword.cpp +++ b/ets2panda/ir/ts/tsUnknownKeyword.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021-2022 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 @@ -22,7 +22,11 @@ #include "ir/srcDump.h" namespace ark::es2panda::ir { -void TSUnknownKeyword::TransformChildren([[maybe_unused]] const NodeTransformer &cb) {} +void TSUnknownKeyword::TransformChildren([[maybe_unused]] const NodeTransformer &cb, + [[maybe_unused]] std::string_view const transformationName) +{ +} + void TSUnknownKeyword::Iterate([[maybe_unused]] const NodeTraverser &cb) const {} void TSUnknownKeyword::Dump(ir::AstDumper *dumper) const diff --git a/ets2panda/ir/ts/tsUnknownKeyword.h b/ets2panda/ir/ts/tsUnknownKeyword.h index 28452a9ccb283ad2444434d4eb2ac01e280a4096..90bff7dbecd4bae1af726b4fdccb28db7ea3f874 100644 --- a/ets2panda/ir/ts/tsUnknownKeyword.h +++ b/ets2panda/ir/ts/tsUnknownKeyword.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 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 @@ -23,7 +23,7 @@ class TSUnknownKeyword : public TypeNode { public: explicit TSUnknownKeyword() : TypeNode(AstNodeType::TS_UNKNOWN_KEYWORD) {} - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/ir/ts/tsVoidKeyword.cpp b/ets2panda/ir/ts/tsVoidKeyword.cpp index ca4286ed5a0c2a87e53ba938f11706fb0959d764..b6843269c1781043d80e8bc0131b092c9f677edf 100644 --- a/ets2panda/ir/ts/tsVoidKeyword.cpp +++ b/ets2panda/ir/ts/tsVoidKeyword.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021-2022 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 @@ -22,7 +22,11 @@ #include "ir/srcDump.h" namespace ark::es2panda::ir { -void TSVoidKeyword::TransformChildren([[maybe_unused]] const NodeTransformer &cb) {} +void TSVoidKeyword::TransformChildren([[maybe_unused]] const NodeTransformer &cb, + [[maybe_unused]] std::string_view const transformationName) +{ +} + void TSVoidKeyword::Iterate([[maybe_unused]] const NodeTraverser &cb) const {} void TSVoidKeyword::Dump(ir::AstDumper *dumper) const diff --git a/ets2panda/ir/ts/tsVoidKeyword.h b/ets2panda/ir/ts/tsVoidKeyword.h index 027e032832e23b3cb99d3975ccccbdad30f85bcf..160a31f858f44b7e6d2621c6af22f425bcbab75f 100644 --- a/ets2panda/ir/ts/tsVoidKeyword.h +++ b/ets2panda/ir/ts/tsVoidKeyword.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021-2022 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 @@ -23,7 +23,7 @@ class TSVoidKeyword : public TypeNode { public: explicit TSVoidKeyword() : TypeNode(AstNodeType::TS_VOID_KEYWORD) {} - void TransformChildren(const NodeTransformer &cb) override; + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/test/parser/ets/getterOverrideGen_n-expected.txt b/ets2panda/test/parser/ets/getterOverrideGen_n-expected.txt index 6330f802e575fd08e280902b51423aa5d7b48a5c..d2a3cc23eba6b4f01535177d0869ba233bb64aec 100644 --- a/ets2panda/test/parser/ets/getterOverrideGen_n-expected.txt +++ b/ets2panda/test/parser/ets/getterOverrideGen_n-expected.txt @@ -11,56 +11,15 @@ "key": { "type": "Identifier", "name": "prop2", - "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "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 - } - } - }, "decorators": [], "loc": { "start": { - "line": 17, - "column": 3 + "line": 1, + "column": 1 }, "end": { - "line": 17, - "column": 8 + "line": 1, + "column": 1 } } }, @@ -76,56 +35,15 @@ "id": { "type": "Identifier", "name": "prop2", - "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "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 - } - } - }, "decorators": [], "loc": { "start": { - "line": 17, - "column": 3 + "line": 1, + "column": 1 }, "end": { - "line": 17, - "column": 8 + "line": 1, + "column": 1 } } }, @@ -203,56 +121,15 @@ "key": { "type": "Identifier", "name": "prop2", - "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "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 - } - } - }, "decorators": [], "loc": { "start": { - "line": 17, - "column": 3 + "line": 1, + "column": 1 }, "end": { - "line": 17, - "column": 8 + "line": 1, + "column": 1 } } }, @@ -268,56 +145,15 @@ "id": { "type": "Identifier", "name": "prop2", - "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "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 - } - } - }, "decorators": [], "loc": { "start": { - "line": 17, - "column": 3 + "line": 1, + "column": 1 }, "end": { - "line": 17, - "column": 8 + "line": 1, + "column": 1 } } }, @@ -449,56 +285,15 @@ "key": { "type": "Identifier", "name": "prop2", - "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "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 - } - } - }, "decorators": [], "loc": { "start": { - "line": 17, - "column": 3 + "line": 1, + "column": 1 }, "end": { - "line": 17, - "column": 8 + "line": 1, + "column": 1 } } }, @@ -514,56 +309,15 @@ "id": { "type": "Identifier", "name": "prop2", - "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "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 - } - } - }, "decorators": [], "loc": { "start": { - "line": 17, - "column": 3 + "line": 1, + "column": 1 }, "end": { - "line": 17, - "column": 8 + "line": 1, + "column": 1 } } }, diff --git a/ets2panda/test/parser/ets/import_tests/internals-expected.txt b/ets2panda/test/parser/ets/import_tests/internals-expected.txt index 705d3fe8a7f7738a8f9988a630a1657b286ef79f..00d86140b39059cc3a1d719cd2122f39f4129b99 100644 --- a/ets2panda/test/parser/ets/import_tests/internals-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/internals-expected.txt @@ -149,56 +149,15 @@ "key": { "type": "Identifier", "name": "name", - "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "string", - "decorators": [], - "loc": { - "start": { - "line": 20, - "column": 12 - }, - "end": { - "line": 20, - "column": 18 - } - } - }, - "loc": { - "start": { - "line": 20, - "column": 12 - }, - "end": { - "line": 20, - "column": 19 - } - } - }, - "loc": { - "start": { - "line": 20, - "column": 12 - }, - "end": { - "line": 20, - "column": 19 - } - } - }, "decorators": [], "loc": { "start": { - "line": 20, - "column": 5 + "line": 1, + "column": 1 }, "end": { - "line": 20, - "column": 9 + "line": 1, + "column": 1 } } }, @@ -214,56 +173,15 @@ "id": { "type": "Identifier", "name": "name", - "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "string", - "decorators": [], - "loc": { - "start": { - "line": 20, - "column": 12 - }, - "end": { - "line": 20, - "column": 18 - } - } - }, - "loc": { - "start": { - "line": 20, - "column": 12 - }, - "end": { - "line": 20, - "column": 19 - } - } - }, - "loc": { - "start": { - "line": 20, - "column": 12 - }, - "end": { - "line": 20, - "column": 19 - } - } - }, "decorators": [], "loc": { "start": { - "line": 20, - "column": 5 + "line": 1, + "column": 1 }, "end": { - "line": 20, - "column": 9 + "line": 1, + "column": 1 } } }, @@ -341,56 +259,15 @@ "key": { "type": "Identifier", "name": "name", - "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "string", - "decorators": [], - "loc": { - "start": { - "line": 20, - "column": 12 - }, - "end": { - "line": 20, - "column": 18 - } - } - }, - "loc": { - "start": { - "line": 20, - "column": 12 - }, - "end": { - "line": 20, - "column": 19 - } - } - }, - "loc": { - "start": { - "line": 20, - "column": 12 - }, - "end": { - "line": 20, - "column": 19 - } - } - }, "decorators": [], "loc": { "start": { - "line": 20, - "column": 5 + "line": 1, + "column": 1 }, "end": { - "line": 20, - "column": 9 + "line": 1, + "column": 1 } } }, @@ -406,56 +283,15 @@ "id": { "type": "Identifier", "name": "name", - "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "string", - "decorators": [], - "loc": { - "start": { - "line": 20, - "column": 12 - }, - "end": { - "line": 20, - "column": 18 - } - } - }, - "loc": { - "start": { - "line": 20, - "column": 12 - }, - "end": { - "line": 20, - "column": 19 - } - } - }, - "loc": { - "start": { - "line": 20, - "column": 12 - }, - "end": { - "line": 20, - "column": 19 - } - } - }, "decorators": [], "loc": { "start": { - "line": 20, - "column": 5 + "line": 1, + "column": 1 }, "end": { - "line": 20, - "column": 9 + "line": 1, + "column": 1 } } }, @@ -587,56 +423,15 @@ "key": { "type": "Identifier", "name": "name", - "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "string", - "decorators": [], - "loc": { - "start": { - "line": 20, - "column": 12 - }, - "end": { - "line": 20, - "column": 18 - } - } - }, - "loc": { - "start": { - "line": 20, - "column": 12 - }, - "end": { - "line": 20, - "column": 19 - } - } - }, - "loc": { - "start": { - "line": 20, - "column": 12 - }, - "end": { - "line": 20, - "column": 19 - } - } - }, "decorators": [], "loc": { "start": { - "line": 20, - "column": 5 + "line": 1, + "column": 1 }, "end": { - "line": 20, - "column": 9 + "line": 1, + "column": 1 } } }, @@ -652,56 +447,15 @@ "id": { "type": "Identifier", "name": "name", - "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "string", - "decorators": [], - "loc": { - "start": { - "line": 20, - "column": 12 - }, - "end": { - "line": 20, - "column": 18 - } - } - }, - "loc": { - "start": { - "line": 20, - "column": 12 - }, - "end": { - "line": 20, - "column": 19 - } - } - }, - "loc": { - "start": { - "line": 20, - "column": 12 - }, - "end": { - "line": 20, - "column": 19 - } - } - }, "decorators": [], "loc": { "start": { - "line": 20, - "column": 5 + "line": 1, + "column": 1 }, "end": { - "line": 20, - "column": 9 + "line": 1, + "column": 1 } } }, diff --git a/ets2panda/test/parser/ets/import_tests/repeat-expected.txt b/ets2panda/test/parser/ets/import_tests/repeat-expected.txt index 5df8d660a1c55f0775793907b466c64a17e096bb..2f8158d29d23f1f32fcd841f587b907445416a1b 100644 --- a/ets2panda/test/parser/ets/import_tests/repeat-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/repeat-expected.txt @@ -155,56 +155,15 @@ "key": { "type": "Identifier", "name": "name", - "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "string", - "decorators": [], - "loc": { - "start": { - "line": 20, - "column": 12 - }, - "end": { - "line": 20, - "column": 18 - } - } - }, - "loc": { - "start": { - "line": 20, - "column": 12 - }, - "end": { - "line": 20, - "column": 19 - } - } - }, - "loc": { - "start": { - "line": 20, - "column": 12 - }, - "end": { - "line": 20, - "column": 19 - } - } - }, "decorators": [], "loc": { "start": { - "line": 20, - "column": 5 + "line": 1, + "column": 1 }, "end": { - "line": 20, - "column": 9 + "line": 1, + "column": 1 } } }, @@ -220,56 +179,15 @@ "id": { "type": "Identifier", "name": "name", - "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "string", - "decorators": [], - "loc": { - "start": { - "line": 20, - "column": 12 - }, - "end": { - "line": 20, - "column": 18 - } - } - }, - "loc": { - "start": { - "line": 20, - "column": 12 - }, - "end": { - "line": 20, - "column": 19 - } - } - }, - "loc": { - "start": { - "line": 20, - "column": 12 - }, - "end": { - "line": 20, - "column": 19 - } - } - }, "decorators": [], "loc": { "start": { - "line": 20, - "column": 5 + "line": 1, + "column": 1 }, "end": { - "line": 20, - "column": 9 + "line": 1, + "column": 1 } } }, @@ -347,56 +265,15 @@ "key": { "type": "Identifier", "name": "name", - "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "string", - "decorators": [], - "loc": { - "start": { - "line": 20, - "column": 12 - }, - "end": { - "line": 20, - "column": 18 - } - } - }, - "loc": { - "start": { - "line": 20, - "column": 12 - }, - "end": { - "line": 20, - "column": 19 - } - } - }, - "loc": { - "start": { - "line": 20, - "column": 12 - }, - "end": { - "line": 20, - "column": 19 - } - } - }, "decorators": [], "loc": { "start": { - "line": 20, - "column": 5 + "line": 1, + "column": 1 }, "end": { - "line": 20, - "column": 9 + "line": 1, + "column": 1 } } }, @@ -412,56 +289,15 @@ "id": { "type": "Identifier", "name": "name", - "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "string", - "decorators": [], - "loc": { - "start": { - "line": 20, - "column": 12 - }, - "end": { - "line": 20, - "column": 18 - } - } - }, - "loc": { - "start": { - "line": 20, - "column": 12 - }, - "end": { - "line": 20, - "column": 19 - } - } - }, - "loc": { - "start": { - "line": 20, - "column": 12 - }, - "end": { - "line": 20, - "column": 19 - } - } - }, "decorators": [], "loc": { "start": { - "line": 20, - "column": 5 + "line": 1, + "column": 1 }, "end": { - "line": 20, - "column": 9 + "line": 1, + "column": 1 } } }, @@ -593,56 +429,15 @@ "key": { "type": "Identifier", "name": "name", - "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "string", - "decorators": [], - "loc": { - "start": { - "line": 20, - "column": 12 - }, - "end": { - "line": 20, - "column": 18 - } - } - }, - "loc": { - "start": { - "line": 20, - "column": 12 - }, - "end": { - "line": 20, - "column": 19 - } - } - }, - "loc": { - "start": { - "line": 20, - "column": 12 - }, - "end": { - "line": 20, - "column": 19 - } - } - }, "decorators": [], "loc": { "start": { - "line": 20, - "column": 5 + "line": 1, + "column": 1 }, "end": { - "line": 20, - "column": 9 + "line": 1, + "column": 1 } } }, @@ -658,56 +453,15 @@ "id": { "type": "Identifier", "name": "name", - "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "string", - "decorators": [], - "loc": { - "start": { - "line": 20, - "column": 12 - }, - "end": { - "line": 20, - "column": 18 - } - } - }, - "loc": { - "start": { - "line": 20, - "column": 12 - }, - "end": { - "line": 20, - "column": 19 - } - } - }, - "loc": { - "start": { - "line": 20, - "column": 12 - }, - "end": { - "line": 20, - "column": 19 - } - } - }, "decorators": [], "loc": { "start": { - "line": 20, - "column": 5 + "line": 1, + "column": 1 }, "end": { - "line": 20, - "column": 9 + "line": 1, + "column": 1 } } }, diff --git a/ets2panda/test/parser/ets/nonPublicInterfaceProp-expected.txt b/ets2panda/test/parser/ets/nonPublicInterfaceProp-expected.txt index dcfc03b1addc9069f3776b6b1309771ed7f38db2..f385c0728dfe39c697469144790cc4b501e97969 100644 --- a/ets2panda/test/parser/ets/nonPublicInterfaceProp-expected.txt +++ b/ets2panda/test/parser/ets/nonPublicInterfaceProp-expected.txt @@ -11,28 +11,15 @@ "key": { "type": "Identifier", "name": "field", - "typeAnnotation": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 18, - "column": 12 - }, - "end": { - "line": 18, - "column": 15 - } - } - }, "decorators": [], "loc": { "start": { - "line": 18, - "column": 5 + "line": 1, + "column": 1 }, "end": { - "line": 18, - "column": 10 + "line": 1, + "column": 1 } } }, @@ -48,28 +35,15 @@ "id": { "type": "Identifier", "name": "field", - "typeAnnotation": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 18, - "column": 12 - }, - "end": { - "line": 18, - "column": 15 - } - } - }, "decorators": [], "loc": { "start": { - "line": 18, - "column": 5 + "line": 1, + "column": 1 }, "end": { - "line": 18, - "column": 10 + "line": 1, + "column": 1 } } }, @@ -119,28 +93,15 @@ "key": { "type": "Identifier", "name": "field", - "typeAnnotation": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 18, - "column": 12 - }, - "end": { - "line": 18, - "column": 15 - } - } - }, "decorators": [], "loc": { "start": { - "line": 18, - "column": 5 + "line": 1, + "column": 1 }, "end": { - "line": 18, - "column": 10 + "line": 1, + "column": 1 } } }, @@ -156,28 +117,15 @@ "id": { "type": "Identifier", "name": "field", - "typeAnnotation": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 18, - "column": 12 - }, - "end": { - "line": 18, - "column": 15 - } - } - }, "decorators": [], "loc": { "start": { - "line": 18, - "column": 5 + "line": 1, + "column": 1 }, "end": { - "line": 18, - "column": 10 + "line": 1, + "column": 1 } } }, @@ -281,28 +229,15 @@ "key": { "type": "Identifier", "name": "field", - "typeAnnotation": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 18, - "column": 12 - }, - "end": { - "line": 18, - "column": 15 - } - } - }, "decorators": [], "loc": { "start": { - "line": 18, - "column": 5 + "line": 1, + "column": 1 }, "end": { - "line": 18, - "column": 10 + "line": 1, + "column": 1 } } }, @@ -318,28 +253,15 @@ "id": { "type": "Identifier", "name": "field", - "typeAnnotation": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 18, - "column": 12 - }, - "end": { - "line": 18, - "column": 15 - } - } - }, "decorators": [], "loc": { "start": { - "line": 18, - "column": 5 + "line": 1, + "column": 1 }, "end": { - "line": 18, - "column": 10 + "line": 1, + "column": 1 } } }, diff --git a/ets2panda/test/parser/ets/optional_field_interface-expected.txt b/ets2panda/test/parser/ets/optional_field_interface-expected.txt index bf45bd24345697c1d90e80f7d762f663f37db81b..199212264ad0731e46cca484dd978a07f9279cf3 100644 --- a/ets2panda/test/parser/ets/optional_field_interface-expected.txt +++ b/ets2panda/test/parser/ets/optional_field_interface-expected.txt @@ -11,56 +11,15 @@ "key": { "type": "Identifier", "name": "field", - "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 13 - }, - "end": { - "line": 18, - "column": 19 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 13 - }, - "end": { - "line": 18, - "column": 20 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 13 - }, - "end": { - "line": 18, - "column": 20 - } - } - }, "decorators": [], "loc": { "start": { - "line": 18, - "column": 4 + "line": 1, + "column": 1 }, "end": { - "line": 18, - "column": 9 + "line": 1, + "column": 1 } } }, @@ -76,56 +35,15 @@ "id": { "type": "Identifier", "name": "field", - "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 13 - }, - "end": { - "line": 18, - "column": 19 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 13 - }, - "end": { - "line": 18, - "column": 20 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 13 - }, - "end": { - "line": 18, - "column": 20 - } - } - }, "decorators": [], "loc": { "start": { - "line": 18, - "column": 4 + "line": 1, + "column": 1 }, "end": { - "line": 18, - "column": 9 + "line": 1, + "column": 1 } } }, @@ -231,56 +149,15 @@ "key": { "type": "Identifier", "name": "field", - "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 13 - }, - "end": { - "line": 18, - "column": 19 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 13 - }, - "end": { - "line": 18, - "column": 20 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 13 - }, - "end": { - "line": 18, - "column": 20 - } - } - }, "decorators": [], "loc": { "start": { - "line": 18, - "column": 4 + "line": 1, + "column": 1 }, "end": { - "line": 18, - "column": 9 + "line": 1, + "column": 1 } } }, @@ -296,56 +173,15 @@ "id": { "type": "Identifier", "name": "field", - "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 13 - }, - "end": { - "line": 18, - "column": 19 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 13 - }, - "end": { - "line": 18, - "column": 20 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 13 - }, - "end": { - "line": 18, - "column": 20 - } - } - }, "decorators": [], "loc": { "start": { - "line": 18, - "column": 4 + "line": 1, + "column": 1 }, "end": { - "line": 18, - "column": 9 + "line": 1, + "column": 1 } } }, @@ -505,56 +341,15 @@ "key": { "type": "Identifier", "name": "field", - "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 13 - }, - "end": { - "line": 18, - "column": 19 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 13 - }, - "end": { - "line": 18, - "column": 20 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 13 - }, - "end": { - "line": 18, - "column": 20 - } - } - }, "decorators": [], "loc": { "start": { - "line": 18, - "column": 4 + "line": 1, + "column": 1 }, "end": { - "line": 18, - "column": 9 + "line": 1, + "column": 1 } } }, @@ -570,56 +365,15 @@ "id": { "type": "Identifier", "name": "field", - "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 13 - }, - "end": { - "line": 18, - "column": 19 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 13 - }, - "end": { - "line": 18, - "column": 20 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 13 - }, - "end": { - "line": 18, - "column": 20 - } - } - }, "decorators": [], "loc": { "start": { - "line": 18, - "column": 4 + "line": 1, + "column": 1 }, "end": { - "line": 18, - "column": 9 + "line": 1, + "column": 1 } } }, diff --git a/ets2panda/test/parser/ets/optional_field_interfaceUnion-expected.txt b/ets2panda/test/parser/ets/optional_field_interfaceUnion-expected.txt index 43a486273ab75722bcc0d889a03162812da699d8..d0f673a68a7bc06aa370ee76d8290fcb41530724 100644 --- a/ets2panda/test/parser/ets/optional_field_interfaceUnion-expected.txt +++ b/ets2panda/test/parser/ets/optional_field_interfaceUnion-expected.txt @@ -11,153 +11,15 @@ "key": { "type": "Identifier", "name": "field", - "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 13 - }, - "end": { - "line": 18, - "column": 19 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 13 - }, - "end": { - "line": 18, - "column": 21 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 13 - }, - "end": { - "line": 18, - "column": 21 - } - } - }, - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "String", - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 22 - }, - "end": { - "line": 18, - "column": 28 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 22 - }, - "end": { - "line": 18, - "column": 30 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 22 - }, - "end": { - "line": 18, - "column": 30 - } - } - }, - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Number", - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 31 - }, - "end": { - "line": 18, - "column": 37 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 31 - }, - "end": { - "line": 18, - "column": 38 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 31 - }, - "end": { - "line": 18, - "column": 38 - } - } - } - ], - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, "decorators": [], "loc": { "start": { - "line": 18, - "column": 4 + "line": 1, + "column": 1 }, "end": { - "line": 18, - "column": 9 + "line": 1, + "column": 1 } } }, @@ -173,153 +35,15 @@ "id": { "type": "Identifier", "name": "field", - "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 13 - }, - "end": { - "line": 18, - "column": 19 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 13 - }, - "end": { - "line": 18, - "column": 21 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 13 - }, - "end": { - "line": 18, - "column": 21 - } - } - }, - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "String", - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 22 - }, - "end": { - "line": 18, - "column": 28 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 22 - }, - "end": { - "line": 18, - "column": 30 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 22 - }, - "end": { - "line": 18, - "column": 30 - } - } - }, - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Number", - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 31 - }, - "end": { - "line": 18, - "column": 37 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 31 - }, - "end": { - "line": 18, - "column": 38 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 31 - }, - "end": { - "line": 18, - "column": 38 - } - } - } - ], - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, "decorators": [], "loc": { "start": { - "line": 18, - "column": 4 + "line": 1, + "column": 1 }, "end": { - "line": 18, - "column": 9 + "line": 1, + "column": 1 } } }, @@ -513,324 +237,48 @@ "end": { "line": 18, "column": 38 - } - } - }, - "overloads": [ - { - "type": "MethodDefinition", - "key": { - "type": "Identifier", - "name": "field", - "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 13 - }, - "end": { - "line": 18, - "column": 19 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 13 - }, - "end": { - "line": 18, - "column": 21 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 13 - }, - "end": { - "line": 18, - "column": 21 - } - } - }, - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "String", - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 22 - }, - "end": { - "line": 18, - "column": 28 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 22 - }, - "end": { - "line": 18, - "column": 30 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 22 - }, - "end": { - "line": 18, - "column": 30 - } - } - }, - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Number", - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 31 - }, - "end": { - "line": 18, - "column": 37 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 31 - }, - "end": { - "line": 18, - "column": 38 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 31 - }, - "end": { - "line": 18, - "column": 38 - } - } - } - ], - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 4 - }, - "end": { - "line": 18, - "column": 9 - } - } - }, - "kind": "method", - "accessibility": "public", - "static": false, - "optional": false, - "computed": false, - "value": { - "type": "FunctionExpression", - "function": { - "type": "ScriptFunction", - "id": { - "type": "Identifier", - "name": "field", - "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 13 - }, - "end": { - "line": 18, - "column": 19 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 13 - }, - "end": { - "line": 18, - "column": 21 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 13 - }, - "end": { - "line": 18, - "column": 21 - } - } - }, - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "String", - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 22 - }, - "end": { - "line": 18, - "column": 28 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 22 - }, - "end": { - "line": 18, - "column": 30 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 22 - }, - "end": { - "line": 18, - "column": 30 - } - } - }, - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Number", - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 31 - }, - "end": { - "line": 18, - "column": 37 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 31 - }, - "end": { - "line": 18, - "column": 38 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 31 - }, - "end": { - "line": 18, - "column": 38 - } - } - } - ], - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, + } + } + }, + "overloads": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "field", + "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": "field", "decorators": [], "loc": { "start": { - "line": 18, - "column": 4 + "line": 1, + "column": 1 }, "end": { - "line": 18, - "column": 9 + "line": 1, + "column": 1 } } }, @@ -1087,153 +535,15 @@ "key": { "type": "Identifier", "name": "field", - "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 13 - }, - "end": { - "line": 18, - "column": 19 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 13 - }, - "end": { - "line": 18, - "column": 21 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 13 - }, - "end": { - "line": 18, - "column": 21 - } - } - }, - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "String", - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 22 - }, - "end": { - "line": 18, - "column": 28 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 22 - }, - "end": { - "line": 18, - "column": 30 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 22 - }, - "end": { - "line": 18, - "column": 30 - } - } - }, - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Number", - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 31 - }, - "end": { - "line": 18, - "column": 37 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 31 - }, - "end": { - "line": 18, - "column": 38 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 31 - }, - "end": { - "line": 18, - "column": 38 - } - } - } - ], - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, "decorators": [], "loc": { "start": { - "line": 18, - "column": 4 + "line": 1, + "column": 1 }, "end": { - "line": 18, - "column": 9 + "line": 1, + "column": 1 } } }, @@ -1249,153 +559,15 @@ "id": { "type": "Identifier", "name": "field", - "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 13 - }, - "end": { - "line": 18, - "column": 19 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 13 - }, - "end": { - "line": 18, - "column": 21 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 13 - }, - "end": { - "line": 18, - "column": 21 - } - } - }, - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "String", - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 22 - }, - "end": { - "line": 18, - "column": 28 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 22 - }, - "end": { - "line": 18, - "column": 30 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 22 - }, - "end": { - "line": 18, - "column": 30 - } - } - }, - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Number", - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 31 - }, - "end": { - "line": 18, - "column": 37 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 31 - }, - "end": { - "line": 18, - "column": 38 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 31 - }, - "end": { - "line": 18, - "column": 38 - } - } - } - ], - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, "decorators": [], "loc": { "start": { - "line": 18, - "column": 4 + "line": 1, + "column": 1 }, "end": { - "line": 18, - "column": 9 + "line": 1, + "column": 1 } } }, diff --git a/ets2panda/test/parser/ets/optional_field_interfaceUnionNotCompatible-expected.txt b/ets2panda/test/parser/ets/optional_field_interfaceUnionNotCompatible-expected.txt index 40779d5b498b0573dccd5dc6fe00b93c828e3305..e7431b983638f655eb04fc60fbeba458b58ef1b4 100644 --- a/ets2panda/test/parser/ets/optional_field_interfaceUnionNotCompatible-expected.txt +++ b/ets2panda/test/parser/ets/optional_field_interfaceUnionNotCompatible-expected.txt @@ -11,112 +11,15 @@ "key": { "type": "Identifier", "name": "field", - "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "String", - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 13 - }, - "end": { - "line": 18, - "column": 19 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 13 - }, - "end": { - "line": 18, - "column": 21 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 13 - }, - "end": { - "line": 18, - "column": 21 - } - } - }, - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Number", - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 22 - }, - "end": { - "line": 18, - "column": 28 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 22 - }, - "end": { - "line": 18, - "column": 29 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 22 - }, - "end": { - "line": 18, - "column": 29 - } - } - } - ], - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, "decorators": [], "loc": { "start": { - "line": 18, - "column": 4 + "line": 1, + "column": 1 }, "end": { - "line": 18, - "column": 9 + "line": 1, + "column": 1 } } }, @@ -132,112 +35,15 @@ "id": { "type": "Identifier", "name": "field", - "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "String", - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 13 - }, - "end": { - "line": 18, - "column": 19 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 13 - }, - "end": { - "line": 18, - "column": 21 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 13 - }, - "end": { - "line": 18, - "column": 21 - } - } - }, - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Number", - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 22 - }, - "end": { - "line": 18, - "column": 28 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 22 - }, - "end": { - "line": 18, - "column": 29 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 22 - }, - "end": { - "line": 18, - "column": 29 - } - } - } - ], - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, "decorators": [], "loc": { "start": { - "line": 18, - "column": 4 + "line": 1, + "column": 1 }, "end": { - "line": 18, - "column": 9 + "line": 1, + "column": 1 } } }, @@ -399,112 +205,15 @@ "key": { "type": "Identifier", "name": "field", - "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "String", - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 13 - }, - "end": { - "line": 18, - "column": 19 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 13 - }, - "end": { - "line": 18, - "column": 21 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 13 - }, - "end": { - "line": 18, - "column": 21 - } - } - }, - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Number", - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 22 - }, - "end": { - "line": 18, - "column": 28 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 22 - }, - "end": { - "line": 18, - "column": 29 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 22 - }, - "end": { - "line": 18, - "column": 29 - } - } - } - ], - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, "decorators": [], "loc": { "start": { - "line": 18, - "column": 4 + "line": 1, + "column": 1 }, "end": { - "line": 18, - "column": 9 + "line": 1, + "column": 1 } } }, @@ -520,112 +229,15 @@ "id": { "type": "Identifier", "name": "field", - "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "String", - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 13 - }, - "end": { - "line": 18, - "column": 19 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 13 - }, - "end": { - "line": 18, - "column": 21 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 13 - }, - "end": { - "line": 18, - "column": 21 - } - } - }, - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Number", - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 22 - }, - "end": { - "line": 18, - "column": 28 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 22 - }, - "end": { - "line": 18, - "column": 29 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 22 - }, - "end": { - "line": 18, - "column": 29 - } - } - } - ], - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, "decorators": [], "loc": { "start": { - "line": 18, - "column": 4 + "line": 1, + "column": 1 }, "end": { - "line": 18, - "column": 9 + "line": 1, + "column": 1 } } }, @@ -841,112 +453,15 @@ "key": { "type": "Identifier", "name": "field", - "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "String", - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 13 - }, - "end": { - "line": 18, - "column": 19 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 13 - }, - "end": { - "line": 18, - "column": 21 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 13 - }, - "end": { - "line": 18, - "column": 21 - } - } - }, - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Number", - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 22 - }, - "end": { - "line": 18, - "column": 28 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 22 - }, - "end": { - "line": 18, - "column": 29 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 22 - }, - "end": { - "line": 18, - "column": 29 - } - } - } - ], - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, "decorators": [], "loc": { "start": { - "line": 18, - "column": 4 + "line": 1, + "column": 1 }, "end": { - "line": 18, - "column": 9 + "line": 1, + "column": 1 } } }, @@ -962,112 +477,15 @@ "id": { "type": "Identifier", "name": "field", - "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "String", - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 13 - }, - "end": { - "line": 18, - "column": 19 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 13 - }, - "end": { - "line": 18, - "column": 21 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 13 - }, - "end": { - "line": 18, - "column": 21 - } - } - }, - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Number", - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 22 - }, - "end": { - "line": 18, - "column": 28 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 22 - }, - "end": { - "line": 18, - "column": 29 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 22 - }, - "end": { - "line": 18, - "column": 29 - } - } - } - ], - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, "decorators": [], "loc": { "start": { - "line": 18, - "column": 4 + "line": 1, + "column": 1 }, "end": { - "line": 18, - "column": 9 + "line": 1, + "column": 1 } } }, diff --git a/ets2panda/test/parser/ets/privateSuperConstructorCall-expected.txt b/ets2panda/test/parser/ets/privateSuperConstructorCall-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..11ba48c3c1060e4f6c382de9d28d69da27de6e37 --- /dev/null +++ b/ets2panda/test/parser/ets/privateSuperConstructorCall-expected.txt @@ -0,0 +1,1039 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "Alma", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 7 + }, + "end": { + "line": 16, + "column": 11 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "x", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 10 + }, + "end": { + "line": 17, + "column": 11 + } + } + }, + "accessibility": "public", + "static": false, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 17, + "column": 13 + }, + "end": { + "line": 17, + "column": 16 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 10 + }, + "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": "private", + "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": "alma", + "typeAnnotation": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 18, + "column": 29 + }, + "end": { + "line": 18, + "column": 32 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 23 + }, + "end": { + "line": 18, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 23 + }, + "end": { + "line": 18, + "column": 32 + } + } + } + ], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "MemberExpression", + "object": { + "type": "ThisExpression", + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 9 + } + } + }, + "property": { + "type": "Identifier", + "name": "x", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 10 + }, + "end": { + "line": 19, + "column": 11 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 11 + } + } + }, + "right": { + "type": "Identifier", + "name": "alma", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 14 + }, + "end": { + "line": 19, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 19 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 34 + }, + "end": { + "line": 20, + "column": 4 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 22 + }, + "end": { + "line": 20, + "column": 4 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 22 + }, + "end": { + "line": 20, + "column": 4 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 3 + }, + "end": { + "line": 20, + "column": 4 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 12 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "Banana", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 7 + }, + "end": { + "line": 23, + "column": 13 + } + } + }, + "superClass": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Alma", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 22 + }, + "end": { + "line": 23, + "column": 26 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 22 + }, + "end": { + "line": 23, + "column": 28 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 22 + }, + "end": { + "line": 23, + "column": 28 + } + } + }, + "implements": [], + "body": [ + { + "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": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "Super", + "loc": { + "start": { + "line": 25, + "column": 5 + }, + "end": { + "line": 25, + "column": 10 + } + } + }, + "arguments": [ + { + "type": "NumberLiteral", + "value": 5, + "loc": { + "start": { + "line": 25, + "column": 11 + }, + "end": { + "line": 25, + "column": 12 + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 25, + "column": 5 + }, + "end": { + "line": 25, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 25, + "column": 5 + }, + "end": { + "line": 25, + "column": 14 + } + } + } + ], + "loc": { + "start": { + "line": 24, + "column": 24 + }, + "end": { + "line": 26, + "column": 4 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 21 + }, + "end": { + "line": 26, + "column": 4 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 21 + }, + "end": { + "line": 26, + "column": 4 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 3 + }, + "end": { + "line": 26, + "column": 4 + } + } + } + ], + "loc": { + "start": { + "line": 23, + "column": 27 + }, + "end": { + "line": 27, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 1 + }, + "end": { + "line": 27, + "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": 29, + "column": 10 + }, + "end": { + "line": 29, + "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": 29, + "column": 10 + }, + "end": { + "line": 29, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 29, + "column": 18 + }, + "end": { + "line": 29, + "column": 22 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "instance", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Banana", + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 17 + }, + "end": { + "line": 30, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 17 + }, + "end": { + "line": 30, + "column": 25 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 17 + }, + "end": { + "line": 30, + "column": 25 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 7 + }, + "end": { + "line": 30, + "column": 15 + } + } + }, + "init": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Banana", + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 30 + }, + "end": { + "line": 30, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 30 + }, + "end": { + "line": 30, + "column": 37 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 30 + }, + "end": { + "line": 30, + "column": 37 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 30, + "column": 26 + }, + "end": { + "line": 30, + "column": 39 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 7 + }, + "end": { + "line": 30, + "column": 39 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 30, + "column": 3 + }, + "end": { + "line": 30, + "column": 39 + } + } + }, + { + "type": "AssertStatement", + "test": { + "type": "BinaryExpression", + "operator": "==", + "left": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "instance", + "decorators": [], + "loc": { + "start": { + "line": 31, + "column": 10 + }, + "end": { + "line": 31, + "column": 18 + } + } + }, + "property": { + "type": "Identifier", + "name": "x", + "decorators": [], + "loc": { + "start": { + "line": 31, + "column": 19 + }, + "end": { + "line": 31, + "column": 20 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 31, + "column": 10 + }, + "end": { + "line": 31, + "column": 20 + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 5, + "loc": { + "start": { + "line": 31, + "column": 24 + }, + "end": { + "line": 31, + "column": 25 + } + } + }, + "loc": { + "start": { + "line": 31, + "column": 10 + }, + "end": { + "line": 31, + "column": 25 + } + } + }, + "second": null, + "loc": { + "start": { + "line": 31, + "column": 3 + }, + "end": { + "line": 31, + "column": 26 + } + } + } + ], + "loc": { + "start": { + "line": 29, + "column": 23 + }, + "end": { + "line": 32, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 14 + }, + "end": { + "line": 32, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 14 + }, + "end": { + "line": 32, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 1 + }, + "end": { + "line": 32, + "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": 33, + "column": 1 + } + } +} +TypeError: Signature constructor(alma: int): void is not visible here. [privateSuperConstructorCall.ets:25:5] diff --git a/ets2panda/test/parser/ets/privateSuperConstructorCall.ets b/ets2panda/test/parser/ets/privateSuperConstructorCall.ets new file mode 100644 index 0000000000000000000000000000000000000000..da70db7663b4ecd38296355fdebc8f5e81684a83 --- /dev/null +++ b/ets2panda/test/parser/ets/privateSuperConstructorCall.ets @@ -0,0 +1,32 @@ +/* + * 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 Alma { + public x: int; + private constructor(alma: int) { + this.x = alma; + } +} + +class Banana extends Alma { + public constructor() { + super(5); + } +} + +function main(): void { + let instance: Banana = new Banana(); + assert instance.x == 5; +} diff --git a/ets2panda/test/parser/ets/re_export/diamond/A-expected.txt b/ets2panda/test/parser/ets/re_export/diamond/A-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..5c1d2aa74e7dd53a864e85fb6a753ae2abebc32c --- /dev/null +++ b/ets2panda/test/parser/ets/re_export/diamond/A-expected.txt @@ -0,0 +1,287 @@ +{ + "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": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 12 + }, + "end": { + "line": 16, + "column": 15 + } + } + }, + "right": { + "type": "StringLiteral", + "value": "AAA", + "loc": { + "start": { + "line": 16, + "column": 26 + }, + "end": { + "line": 16, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 12 + }, + "end": { + "line": 16, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 12 + }, + "end": { + "line": 16, + "column": 31 + } + } + } + ], + "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": "foo", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 12 + }, + "end": { + "line": 16, + "column": 15 + } + } + }, + "accessibility": "public", + "static": true, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 17 + }, + "end": { + "line": 16, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 17 + }, + "end": { + "line": 16, + "column": 25 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 17 + }, + "end": { + "line": 16, + "column": 25 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 12 + }, + "end": { + "line": 16, + "column": 31 + } + } + } + ], + "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/diamond/A.ets b/ets2panda/test/parser/ets/re_export/diamond/A.ets new file mode 100644 index 0000000000000000000000000000000000000000..eb3c9b72439a19456f29a35fc03a8f064d2092f2 --- /dev/null +++ b/ets2panda/test/parser/ets/re_export/diamond/A.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 let foo: string = "AAA" diff --git a/ets2panda/test/parser/ets/re_export/diamond/B-expected.txt b/ets2panda/test/parser/ets/re_export/diamond/B-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..75bfb3625e97f0c8034935a5238f9dc7f447aea3 --- /dev/null +++ b/ets2panda/test/parser/ets/re_export/diamond/B-expected.txt @@ -0,0 +1,238 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ETSReExportDeclaration", + "ets_import_declarations": { + "type": "ImportDeclaration", + "source": { + "type": "StringLiteral", + "value": "./A", + "loc": { + "start": { + "line": 16, + "column": 26 + }, + "end": { + "line": 16, + "column": 31 + } + } + }, + "specifiers": [ + { + "type": "ImportSpecifier", + "local": { + "type": "Identifier", + "name": "boo", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 16 + }, + "end": { + "line": 16, + "column": 19 + } + } + }, + "imported": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 12 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 19 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 16, + "column": 31 + } + } + }, + "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": 17, + "column": 1 + } + } +} diff --git a/ets2panda/test/parser/ets/re_export/diamond/B.ets b/ets2panda/test/parser/ets/re_export/diamond/B.ets new file mode 100644 index 0000000000000000000000000000000000000000..4ca9b2e2a63e859a3dfe8aa1772a2f4da74b5613 --- /dev/null +++ b/ets2panda/test/parser/ets/re_export/diamond/B.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 {foo as boo} from "./A" diff --git a/ets2panda/test/parser/ets/re_export/diamond/B2-expected.txt b/ets2panda/test/parser/ets/re_export/diamond/B2-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..12883a6851e4c2f4f4229756964d72a579f518ee --- /dev/null +++ b/ets2panda/test/parser/ets/re_export/diamond/B2-expected.txt @@ -0,0 +1,238 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ETSReExportDeclaration", + "ets_import_declarations": { + "type": "ImportDeclaration", + "source": { + "type": "StringLiteral", + "value": "./B", + "loc": { + "start": { + "line": 16, + "column": 26 + }, + "end": { + "line": 16, + "column": 31 + } + } + }, + "specifiers": [ + { + "type": "ImportSpecifier", + "local": { + "type": "Identifier", + "name": "BOO", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 16 + }, + "end": { + "line": 16, + "column": 19 + } + } + }, + "imported": { + "type": "Identifier", + "name": "boo", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 12 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 19 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 16, + "column": 31 + } + } + }, + "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": 17, + "column": 1 + } + } +} diff --git a/ets2panda/test/parser/ets/re_export/diamond/B2.ets b/ets2panda/test/parser/ets/re_export/diamond/B2.ets new file mode 100644 index 0000000000000000000000000000000000000000..6b9860e9ceb1d1d8e6e99f4f66b6b40755f63b71 --- /dev/null +++ b/ets2panda/test/parser/ets/re_export/diamond/B2.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 {boo as BOO} from "./B" diff --git a/ets2panda/test/parser/ets/re_export/diamond/C-expected.txt b/ets2panda/test/parser/ets/re_export/diamond/C-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..730c5bba5f0ea4cc1de7579106d6412966a0d7bd --- /dev/null +++ b/ets2panda/test/parser/ets/re_export/diamond/C-expected.txt @@ -0,0 +1,238 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ETSReExportDeclaration", + "ets_import_declarations": { + "type": "ImportDeclaration", + "source": { + "type": "StringLiteral", + "value": "./A", + "loc": { + "start": { + "line": 16, + "column": 26 + }, + "end": { + "line": 16, + "column": 31 + } + } + }, + "specifiers": [ + { + "type": "ImportSpecifier", + "local": { + "type": "Identifier", + "name": "coo", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 16 + }, + "end": { + "line": 16, + "column": 19 + } + } + }, + "imported": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 12 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 19 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 16, + "column": 31 + } + } + }, + "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": 17, + "column": 1 + } + } +} diff --git a/ets2panda/test/parser/ets/re_export/diamond/C.ets b/ets2panda/test/parser/ets/re_export/diamond/C.ets new file mode 100644 index 0000000000000000000000000000000000000000..fccf01e30c70b972051b8ecab592f1743687542f --- /dev/null +++ b/ets2panda/test/parser/ets/re_export/diamond/C.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 {foo as coo} from "./A" diff --git a/ets2panda/test/parser/ets/re_export/diamond/C2-expected.txt b/ets2panda/test/parser/ets/re_export/diamond/C2-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..11dda3ff2a637dc27f506c5918d8a469296c15d0 --- /dev/null +++ b/ets2panda/test/parser/ets/re_export/diamond/C2-expected.txt @@ -0,0 +1,238 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ETSReExportDeclaration", + "ets_import_declarations": { + "type": "ImportDeclaration", + "source": { + "type": "StringLiteral", + "value": "./C", + "loc": { + "start": { + "line": 16, + "column": 26 + }, + "end": { + "line": 16, + "column": 31 + } + } + }, + "specifiers": [ + { + "type": "ImportSpecifier", + "local": { + "type": "Identifier", + "name": "COO", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 16 + }, + "end": { + "line": 16, + "column": 19 + } + } + }, + "imported": { + "type": "Identifier", + "name": "coo", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 12 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 19 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 16, + "column": 31 + } + } + }, + "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": 17, + "column": 1 + } + } +} diff --git a/ets2panda/test/parser/ets/re_export/diamond/C2.ets b/ets2panda/test/parser/ets/re_export/diamond/C2.ets new file mode 100644 index 0000000000000000000000000000000000000000..8a1afee54fdaa66d3c1b7b557ab28da717b84427 --- /dev/null +++ b/ets2panda/test/parser/ets/re_export/diamond/C2.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 {coo as COO} from "./C" diff --git a/ets2panda/test/parser/ets/re_export/diamond/D-expected.txt b/ets2panda/test/parser/ets/re_export/diamond/D-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..e50334a1060ae8dbfd2c5ea9cf3b8b569ee9c01b --- /dev/null +++ b/ets2panda/test/parser/ets/re_export/diamond/D-expected.txt @@ -0,0 +1,600 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ImportDeclaration", + "source": { + "type": "StringLiteral", + "value": "./B", + "loc": { + "start": { + "line": 22, + "column": 21 + }, + "end": { + "line": 22, + "column": 26 + } + } + }, + "specifiers": [ + { + "type": "ImportNamespaceSpecifier", + "local": { + "type": "Identifier", + "name": "BB", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 13 + }, + "end": { + "line": 22, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 8 + }, + "end": { + "line": 22, + "column": 15 + } + } + } + ], + "loc": { + "start": { + "line": 22, + "column": 1 + }, + "end": { + "line": 22, + "column": 26 + } + } + }, + { + "type": "ImportDeclaration", + "source": { + "type": "StringLiteral", + "value": "./C", + "loc": { + "start": { + "line": 23, + "column": 21 + }, + "end": { + "line": 23, + "column": 26 + } + } + }, + "specifiers": [ + { + "type": "ImportNamespaceSpecifier", + "local": { + "type": "Identifier", + "name": "CC", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 13 + }, + "end": { + "line": 23, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 8 + }, + "end": { + "line": 23, + "column": 15 + } + } + } + ], + "loc": { + "start": { + "line": 23, + "column": 1 + }, + "end": { + "line": 23, + "column": 26 + } + } + }, + { + "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": 25, + "column": 10 + }, + "end": { + "line": 25, + "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": 25, + "column": 10 + }, + "end": { + "line": 25, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "console", + "decorators": [], + "loc": { + "start": { + "line": 26, + "column": 3 + }, + "end": { + "line": 26, + "column": 10 + } + } + }, + "property": { + "type": "Identifier", + "name": "log", + "decorators": [], + "loc": { + "start": { + "line": 26, + "column": 11 + }, + "end": { + "line": 26, + "column": 14 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 26, + "column": 3 + }, + "end": { + "line": 26, + "column": 14 + } + } + }, + "arguments": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "CC", + "decorators": [], + "loc": { + "start": { + "line": 26, + "column": 15 + }, + "end": { + "line": 26, + "column": 17 + } + } + }, + "property": { + "type": "Identifier", + "name": "coo", + "decorators": [], + "loc": { + "start": { + "line": 26, + "column": 18 + }, + "end": { + "line": 26, + "column": 21 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 26, + "column": 15 + }, + "end": { + "line": 26, + "column": 21 + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 26, + "column": 3 + }, + "end": { + "line": 26, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 3 + }, + "end": { + "line": 26, + "column": 23 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "console", + "decorators": [], + "loc": { + "start": { + "line": 27, + "column": 3 + }, + "end": { + "line": 27, + "column": 10 + } + } + }, + "property": { + "type": "Identifier", + "name": "log", + "decorators": [], + "loc": { + "start": { + "line": 27, + "column": 11 + }, + "end": { + "line": 27, + "column": 14 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 27, + "column": 3 + }, + "end": { + "line": 27, + "column": 14 + } + } + }, + "arguments": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "BB", + "decorators": [], + "loc": { + "start": { + "line": 27, + "column": 15 + }, + "end": { + "line": 27, + "column": 17 + } + } + }, + "property": { + "type": "Identifier", + "name": "boo", + "decorators": [], + "loc": { + "start": { + "line": 27, + "column": 18 + }, + "end": { + "line": 27, + "column": 21 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 27, + "column": 15 + }, + "end": { + "line": 27, + "column": 21 + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 27, + "column": 3 + }, + "end": { + "line": 27, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 27, + "column": 3 + }, + "end": { + "line": 27, + "column": 23 + } + } + } + ], + "loc": { + "start": { + "line": 25, + "column": 17 + }, + "end": { + "line": 28, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 25, + "column": 14 + }, + "end": { + "line": 28, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 25, + "column": 14 + }, + "end": { + "line": 28, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 25, + "column": 1 + }, + "end": { + "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 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 29, + "column": 1 + } + } +} diff --git a/ets2panda/test/parser/ets/re_export/diamond/D.ets b/ets2panda/test/parser/ets/re_export/diamond/D.ets new file mode 100644 index 0000000000000000000000000000000000000000..e9f2897d28c08f92ec2f0f9d5d4d58126e0711a4 --- /dev/null +++ b/ets2panda/test/parser/ets/re_export/diamond/D.ets @@ -0,0 +1,28 @@ +/* + * 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. + */ + +/* A + / \ + B C + \ / + D */ + +import * as BB from "./B" +import * as CC from "./C" + +function main() { + console.log(CC.coo); + console.log(BB.boo); +} diff --git a/ets2panda/test/parser/ets/re_export/diamond/D2-expected.txt b/ets2panda/test/parser/ets/re_export/diamond/D2-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..d7aa2fa4438143f8ded241351407e11ca84754fd --- /dev/null +++ b/ets2panda/test/parser/ets/re_export/diamond/D2-expected.txt @@ -0,0 +1,600 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ImportDeclaration", + "source": { + "type": "StringLiteral", + "value": "./B2", + "loc": { + "start": { + "line": 24, + "column": 21 + }, + "end": { + "line": 24, + "column": 27 + } + } + }, + "specifiers": [ + { + "type": "ImportNamespaceSpecifier", + "local": { + "type": "Identifier", + "name": "BB", + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 13 + }, + "end": { + "line": 24, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 8 + }, + "end": { + "line": 24, + "column": 15 + } + } + } + ], + "loc": { + "start": { + "line": 24, + "column": 1 + }, + "end": { + "line": 24, + "column": 27 + } + } + }, + { + "type": "ImportDeclaration", + "source": { + "type": "StringLiteral", + "value": "./C2", + "loc": { + "start": { + "line": 25, + "column": 21 + }, + "end": { + "line": 25, + "column": 27 + } + } + }, + "specifiers": [ + { + "type": "ImportNamespaceSpecifier", + "local": { + "type": "Identifier", + "name": "CC", + "decorators": [], + "loc": { + "start": { + "line": 25, + "column": 13 + }, + "end": { + "line": 25, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 25, + "column": 8 + }, + "end": { + "line": 25, + "column": 15 + } + } + } + ], + "loc": { + "start": { + "line": 25, + "column": 1 + }, + "end": { + "line": 25, + "column": 27 + } + } + }, + { + "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": 27, + "column": 10 + }, + "end": { + "line": 27, + "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": 27, + "column": 10 + }, + "end": { + "line": 27, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "console", + "decorators": [], + "loc": { + "start": { + "line": 28, + "column": 3 + }, + "end": { + "line": 28, + "column": 10 + } + } + }, + "property": { + "type": "Identifier", + "name": "log", + "decorators": [], + "loc": { + "start": { + "line": 28, + "column": 11 + }, + "end": { + "line": 28, + "column": 14 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 28, + "column": 3 + }, + "end": { + "line": 28, + "column": 14 + } + } + }, + "arguments": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "CC", + "decorators": [], + "loc": { + "start": { + "line": 28, + "column": 15 + }, + "end": { + "line": 28, + "column": 17 + } + } + }, + "property": { + "type": "Identifier", + "name": "COO", + "decorators": [], + "loc": { + "start": { + "line": 28, + "column": 18 + }, + "end": { + "line": 28, + "column": 21 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 28, + "column": 15 + }, + "end": { + "line": 28, + "column": 21 + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 28, + "column": 3 + }, + "end": { + "line": 28, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 28, + "column": 3 + }, + "end": { + "line": 28, + "column": 23 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "console", + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 3 + }, + "end": { + "line": 29, + "column": 10 + } + } + }, + "property": { + "type": "Identifier", + "name": "log", + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 11 + }, + "end": { + "line": 29, + "column": 14 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 29, + "column": 3 + }, + "end": { + "line": 29, + "column": 14 + } + } + }, + "arguments": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "BB", + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 15 + }, + "end": { + "line": 29, + "column": 17 + } + } + }, + "property": { + "type": "Identifier", + "name": "BOO", + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 18 + }, + "end": { + "line": 29, + "column": 21 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 29, + "column": 15 + }, + "end": { + "line": 29, + "column": 21 + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 29, + "column": 3 + }, + "end": { + "line": 29, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 3 + }, + "end": { + "line": 29, + "column": 23 + } + } + } + ], + "loc": { + "start": { + "line": 27, + "column": 17 + }, + "end": { + "line": 30, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 27, + "column": 14 + }, + "end": { + "line": 30, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 27, + "column": 14 + }, + "end": { + "line": 30, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 27, + "column": 1 + }, + "end": { + "line": 30, + "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": 31, + "column": 1 + } + } +} diff --git a/ets2panda/test/parser/ets/re_export/diamond/D2.ets b/ets2panda/test/parser/ets/re_export/diamond/D2.ets new file mode 100644 index 0000000000000000000000000000000000000000..b2f16bb816f7fdc7fda62644a2b37ee81e74ffea --- /dev/null +++ b/ets2panda/test/parser/ets/re_export/diamond/D2.ets @@ -0,0 +1,30 @@ +/* + * 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. + */ + +/* A + / \ + B C + | | + B2 C2 + \ / + D2 */ + +import * as BB from "./B2" +import * as CC from "./C2" + +function main() { + console.log(CC.COO); + console.log(BB.BOO); +} diff --git a/ets2panda/test/parser/ets/re_export/import_13-expected.txt b/ets2panda/test/parser/ets/re_export/import_13-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..93b4d5684de808ddb209d7999fe1974f85e18698 --- /dev/null +++ b/ets2panda/test/parser/ets/re_export/import_13-expected.txt @@ -0,0 +1,391 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ImportDeclaration", + "source": { + "type": "StringLiteral", + "value": "./re_export_8", + "loc": { + "start": { + "line": 16, + "column": 20 + }, + "end": { + "line": 16, + "column": 35 + } + } + }, + "specifiers": [ + { + "type": "ImportNamespaceSpecifier", + "local": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 13 + }, + "end": { + "line": 16, + "column": 14 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 16, + "column": 14 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 16, + "column": 35 + } + } + }, + { + "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": 19 + }, + "end": { + "line": 18, + "column": 23 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 6 + } + } + }, + "property": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 7 + }, + "end": { + "line": 20, + "column": 10 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 10 + } + } + }, + "arguments": [], + "optional": false, + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 12 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 13 + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 1 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 21, + "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": 22, + "column": 1 + } + } +} diff --git a/ets2panda/test/parser/ets/re_export/import_13.ets b/ets2panda/test/parser/ets/re_export/import_13.ets new file mode 100644 index 0000000000000000000000000000000000000000..9b7fc3dcfb817c13171982e3efeecd90711f302c --- /dev/null +++ b/ets2panda/test/parser/ets/re_export/import_13.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 * as A from "./re_export_8" + +function main() : void +{ + A.foo(); +} diff --git a/ets2panda/test/parser/ets/re_export/import_14-expected.txt b/ets2panda/test/parser/ets/re_export/import_14-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..0626011c040b97914d040b2fa434368b55146936 --- /dev/null +++ b/ets2panda/test/parser/ets/re_export/import_14-expected.txt @@ -0,0 +1,391 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ImportDeclaration", + "source": { + "type": "StringLiteral", + "value": "./re_export_9", + "loc": { + "start": { + "line": 16, + "column": 20 + }, + "end": { + "line": 16, + "column": 35 + } + } + }, + "specifiers": [ + { + "type": "ImportNamespaceSpecifier", + "local": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 13 + }, + "end": { + "line": 16, + "column": 14 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 16, + "column": 14 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 16, + "column": 35 + } + } + }, + { + "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": 19 + }, + "end": { + "line": 18, + "column": 23 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 6 + } + } + }, + "property": { + "type": "Identifier", + "name": "fooAlias", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 7 + }, + "end": { + "line": 20, + "column": 15 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 15 + } + } + }, + "arguments": [], + "optional": false, + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 17 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 18 + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 1 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 21, + "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": 22, + "column": 1 + } + } +} diff --git a/ets2panda/test/parser/ets/re_export/import_14.ets b/ets2panda/test/parser/ets/re_export/import_14.ets new file mode 100644 index 0000000000000000000000000000000000000000..2748599756591bd1c7813772744606d9efb01455 --- /dev/null +++ b/ets2panda/test/parser/ets/re_export/import_14.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 * as A from "./re_export_9" + +function main() : void +{ + A.fooAlias(); +} diff --git a/ets2panda/test/parser/ets/re_export/import_15-expected.txt b/ets2panda/test/parser/ets/re_export/import_15-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..236d597b09d714309c0f6f0dd81efbb01097b6e7 --- /dev/null +++ b/ets2panda/test/parser/ets/re_export/import_15-expected.txt @@ -0,0 +1,391 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ImportDeclaration", + "source": { + "type": "StringLiteral", + "value": "./re_export_10", + "loc": { + "start": { + "line": 16, + "column": 20 + }, + "end": { + "line": 16, + "column": 36 + } + } + }, + "specifiers": [ + { + "type": "ImportNamespaceSpecifier", + "local": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 13 + }, + "end": { + "line": 16, + "column": 14 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 16, + "column": 14 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 16, + "column": 36 + } + } + }, + { + "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": 19 + }, + "end": { + "line": 18, + "column": 23 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 6 + } + } + }, + "property": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 7 + }, + "end": { + "line": 20, + "column": 10 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 10 + } + } + }, + "arguments": [], + "optional": false, + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 12 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 13 + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 1 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 21, + "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": 22, + "column": 1 + } + } +} diff --git a/ets2panda/test/parser/ets/re_export/import_15.ets b/ets2panda/test/parser/ets/re_export/import_15.ets new file mode 100644 index 0000000000000000000000000000000000000000..91d3c71f02bc2f57b7b43d264a3c914905cf8a99 --- /dev/null +++ b/ets2panda/test/parser/ets/re_export/import_15.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 * as A from "./re_export_10" + +function main() : void +{ + A.foo(); +} diff --git a/ets2panda/test/parser/ets/re_export/import_7-expected.txt b/ets2panda/test/parser/ets/re_export/import_7-expected.txt index 06508df53454bf9e968586a1f6be8d4a21cb517b..2cb3020a50a6e84253201135f5666d8f6535548c 100644 --- a/ets2panda/test/parser/ets/re_export/import_7-expected.txt +++ b/ets2panda/test/parser/ets/re_export/import_7-expected.txt @@ -389,4 +389,3 @@ } } } -TypeError: Property 'foo' does not exist on type 're_export' [import_7.ets:20:7] diff --git a/ets2panda/test/parser/ets/re_export/re_export_10-expected.txt b/ets2panda/test/parser/ets/re_export/re_export_10-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..748856996c768aa260013f339180f33bb8c38aeb --- /dev/null +++ b/ets2panda/test/parser/ets/re_export/re_export_10-expected.txt @@ -0,0 +1,223 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ETSReExportDeclaration", + "ets_import_declarations": { + "type": "ImportDeclaration", + "source": { + "type": "StringLiteral", + "value": "./re_export", + "loc": { + "start": { + "line": 16, + "column": 15 + }, + "end": { + "line": 16, + "column": 28 + } + } + }, + "specifiers": [ + { + "type": "ImportNamespaceSpecifier", + "local": { + "type": "Identifier", + "name": "", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 16, + "column": 14 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 16, + "column": 28 + } + } + }, + "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/re_export_10.ets b/ets2panda/test/parser/ets/re_export/re_export_10.ets new file mode 100644 index 0000000000000000000000000000000000000000..15868fdd7bb5d4f9563e1881a727603631eb260b --- /dev/null +++ b/ets2panda/test/parser/ets/re_export/re_export_10.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 * from "./re_export" + diff --git a/ets2panda/test/parser/ets/re_export/re_export_8-expected.txt b/ets2panda/test/parser/ets/re_export/re_export_8-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..18e18255efc748f2bcbd61ab11ad694ac17c4575 --- /dev/null +++ b/ets2panda/test/parser/ets/re_export/re_export_8-expected.txt @@ -0,0 +1,238 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ETSReExportDeclaration", + "ets_import_declarations": { + "type": "ImportDeclaration", + "source": { + "type": "StringLiteral", + "value": "./export", + "loc": { + "start": { + "line": 16, + "column": 19 + }, + "end": { + "line": 16, + "column": 29 + } + } + }, + "specifiers": [ + { + "type": "ImportSpecifier", + "local": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 12 + } + } + }, + "imported": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 12 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 12 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 16, + "column": 29 + } + } + }, + "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/re_export_8.ets b/ets2panda/test/parser/ets/re_export/re_export_8.ets new file mode 100644 index 0000000000000000000000000000000000000000..60011e734e16e422c7afb9d74d8ab941dde25de7 --- /dev/null +++ b/ets2panda/test/parser/ets/re_export/re_export_8.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 {foo} from "./export" + diff --git a/ets2panda/test/parser/ets/re_export/re_export_9-expected.txt b/ets2panda/test/parser/ets/re_export/re_export_9-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..addfea23e0ce3f3d5e3eee832cd805b5c145a48b --- /dev/null +++ b/ets2panda/test/parser/ets/re_export/re_export_9-expected.txt @@ -0,0 +1,238 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ETSReExportDeclaration", + "ets_import_declarations": { + "type": "ImportDeclaration", + "source": { + "type": "StringLiteral", + "value": "./export", + "loc": { + "start": { + "line": 16, + "column": 31 + }, + "end": { + "line": 16, + "column": 41 + } + } + }, + "specifiers": [ + { + "type": "ImportSpecifier", + "local": { + "type": "Identifier", + "name": "fooAlias", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 16 + }, + "end": { + "line": 16, + "column": 24 + } + } + }, + "imported": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 12 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 24 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 16, + "column": 41 + } + } + }, + "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/re_export_9.ets b/ets2panda/test/parser/ets/re_export/re_export_9.ets new file mode 100644 index 0000000000000000000000000000000000000000..2ca1a91495b670f3872fc4d6855ab88045857cc1 --- /dev/null +++ b/ets2panda/test/parser/ets/re_export/re_export_9.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 {foo as fooAlias} from "./export" + diff --git a/ets2panda/test/runtime/ets/assert_not_nullish_expression.ets b/ets2panda/test/runtime/ets/assert_not_nullish_expression.ets new file mode 100644 index 0000000000000000000000000000000000000000..89ef200bae7e9e180194ea9390b2191ebd06d3aa --- /dev/null +++ b/ets2panda/test/runtime/ets/assert_not_nullish_expression.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. + */ + +function main():void{ + let a = (): Int|undefined => {return 3; }(); + assert a!; + foo(5); +} + +function foo(i: Int|undefined): void { +assert i!; +} diff --git a/ets2panda/test/runtime/ets/conversionFloatIntLong.ets b/ets2panda/test/runtime/ets/conversionFloatIntLong.ets new file mode 100644 index 0000000000000000000000000000000000000000..768241b8e8c36d30ead392b94b06c9e63e515bef --- /dev/null +++ b/ets2panda/test/runtime/ets/conversionFloatIntLong.ets @@ -0,0 +1,59 @@ +/* + * 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 { + + let f: float = 1000000001.044 + let f_i = f as int + let f_l = f as long + assert(f_l == 1000000000) + assert(f_i == 1000000000) + + let d: double = 1000000001.044 + let d_i = d as int + let d_l = d as long + assert(d_l == 1000000001) + assert(d_i == 1000000001) + + let f2: float= 10001.044 + let f_i2 = f2 as int + let f_l2 = f2 as long + assert(f_l2 == 10001) + assert(f_i2 == 10001) + + let i: int = 2147483647 + let i_f = i as float + let i_d = i as double + assert(i_f == 2147483600) + assert(i_d == 2147483647) + + let i2: int = 1073741824 + let i_f2 = i2 as float + let i_d2 = i2 as double + assert(i_f2 == 1073741824) + assert(i_d2 == 1073741824) + + let l: long= 1073741824 + let l_f = l as float + let d_f = l as double + assert(l_f == 1073741824) + assert(d_f == 1073741824) + + let l2: int = 2147483647 + let l_f2 = l2 as float + let d_f2 = l2 as double + assert(l_f2 == 2147483600) + assert(d_f2 == 2147483647) +} diff --git a/ets2panda/test/runtime/ets/conversionFromInfinity.ets b/ets2panda/test/runtime/ets/conversionFromInfinity.ets new file mode 100644 index 0000000000000000000000000000000000000000..812df0fe9e9b1d94183042ad02a60e76755c5a1b --- /dev/null +++ b/ets2panda/test/runtime/ets/conversionFromInfinity.ets @@ -0,0 +1,85 @@ +/* + * 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 { + +let nan_byte = Infinity * 0 as byte +let nan_short = Infinity * 0 as short +let nan_long = Infinity * 0 as long +let nan_char = Infinity * 0 as char +let nan_int = Infinity * 0 as int +let nan_float = Infinity * 0 as float +let nan_double = Infinity * 0 as double +let nan_byte2 = Infinity * 0 as byte + +assert(nan_byte == 0) +assert(nan_int == 0) +assert(nan_short == 0) +assert(nan_long == 0) +assert(nan_char == 0) +assert(isNaN(nan_float)) +assert(isNaN(nan_double)) +assert(nan_byte2 == 0) + +let b1 = Infinity as byte // converted at compile time, as 'Infinity' is constant +let b2: double = Infinity +let b3 = b2 as byte // converted in runtime, as b2 isn't constant + +assert(b1 == -1) +assert(b3 == -1) + +let l1 = Infinity as long +let l2: double = Infinity +let l3 = l2 as long + +assert(l1 == 9223372036854775807) +assert(l3 == 9223372036854775807) + +let i1 = Infinity as int +let i2: double = Infinity +let i3 = i2 as int + +assert(i1 == 2147483647) +assert(i3 == 2147483647) + +let s1 = Infinity as short +let s2: double = Infinity +let s3 = s2 as short + +assert(s1 == -1) +assert(s3 == -1) + +let c1 = Infinity as char +let c2: double = Infinity +let c3 = c2 as char + +assert(c1 == 65535) +assert(c3 == 65535) + +let f1 = Infinity as float +let f2: double = Infinity +let f3 = f2 as float + +assert(f1 == Infinity) +assert(f3 == Infinity) + +let d1 = Infinity as double +let d2: double = Infinity +let d3 = d2 as double + +assert(d1 == Infinity) +assert(d3 == Infinity) +} diff --git a/ets2panda/varbinder/ETSBinder.cpp b/ets2panda/varbinder/ETSBinder.cpp index 864490810cadb9a6975314d9566627f2ad877572..8fcb6880885515efaff4d468c981734510167d3c 100644 --- a/ets2panda/varbinder/ETSBinder.cpp +++ b/ets2panda/varbinder/ETSBinder.cpp @@ -513,7 +513,6 @@ bool ETSBinder::AddImportNamespaceSpecifiersToTopBindings(ir::AstNode *const spe for (auto it : item->GetETSImportDeclarations()->Specifiers()) { if (it->IsImportNamespaceSpecifier() && !specifier->AsImportNamespaceSpecifier()->Local()->Name().Empty()) { - std::cerr << "Warning: import with alias cannot be used with re-export\n"; continue; } @@ -619,7 +618,14 @@ bool ETSBinder::AddImportSpecifiersToTopBindings(ir::AstNode *const specifier, return true; } - const auto &imported = importSpecifier->Imported()->AsIdentifier()->Name(); + auto imported = importSpecifier->Imported()->Name(); + + for (auto const item : import->Specifiers()) { + if (item->IsImportSpecifier() && item->AsImportSpecifier()->Local()->Name().Is(imported.Mutf8()) && + !item->AsImportSpecifier()->Local()->Name().Is(item->AsImportSpecifier()->Imported()->Name().Mutf8())) { + imported = item->AsImportSpecifier()->Imported()->Name(); + } + } auto *const var = FindImportSpecifiersVariable(imported, globalBindings, recordRes); diff --git a/ets2panda/varbinder/variable.h b/ets2panda/varbinder/variable.h index 41e1484ebc157cb70d952c6ff208359f5b1ea698..71416a738a5455a1d6c29f5d5c7edc8498d18a3f 100644 --- a/ets2panda/varbinder/variable.h +++ b/ets2panda/varbinder/variable.h @@ -66,68 +66,68 @@ public: VARIABLE_TYPES(DECLARE_CHECKS_CASTS) #undef DECLARE_CHECKS_CASTS - const Decl *Declaration() const + [[nodiscard]] const Decl *Declaration() const noexcept { return decl_; } - Decl *Declaration() + [[nodiscard]] Decl *Declaration() noexcept { return decl_; } - VariableFlags Flags() const + [[nodiscard]] VariableFlags Flags() const noexcept { return flags_; } - checker::Type *TsType() const + [[nodiscard]] checker::Type *TsType() const noexcept { return tsType_; } - Scope *GetScope() const + [[nodiscard]] Scope *GetScope() const noexcept { return scope_; } - void SetTsType(checker::Type *tsType) + void SetTsType(checker::Type *tsType) noexcept { tsType_ = tsType; } - void SetScope(varbinder::Scope *scope) + void SetScope(varbinder::Scope *scope) noexcept { scope_ = scope; } - void AddFlag(VariableFlags flag) + void AddFlag(VariableFlags flag) noexcept { flags_ |= flag; } - bool HasFlag(VariableFlags flag) const + [[nodiscard]] bool HasFlag(VariableFlags flag) const noexcept { return (flags_ & flag) != 0; } - void RemoveFlag(VariableFlags flag) + void RemoveFlag(VariableFlags flag) noexcept { flags_ &= ~flag; } - void Reset(Decl *decl, VariableFlags flags) + void Reset(Decl *decl, VariableFlags flags) noexcept { decl_ = decl; flags_ = flags; } - bool LexicalBound() const + [[nodiscard]] bool LexicalBound() const noexcept { return HasFlag(VariableFlags::LEXICAL_BOUND); } - const util::StringView &Name() const; + [[nodiscard]] const util::StringView &Name() const; virtual void SetLexical(Scope *scope) = 0; protected: @@ -137,9 +137,11 @@ protected: // NOLINTBEGIN(misc-non-private-member-variables-in-classes) Decl *decl_ {}; VariableFlags flags_ {}; + // NOLINTEND(misc-non-private-member-variables-in-classes) + +private: checker::Type *tsType_ {}; Scope *scope_ {}; - // NOLINTEND(misc-non-private-member-variables-in-classes) }; class LocalVariable : public Variable {