diff --git a/.gitignore b/.gitignore index d0f42167dbd53b4bedadc0a8988e4646e9fb2972..2a23da7872b255928df7d4d3d547cc6a41e8326f 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,4 @@ ets2panda/linter*/test_rules/**/results ets2panda/linter*/**/package-lock.json **/compile_commands.json .cache +.vscode diff --git a/ets2panda/checker/ETSAnalyzer.cpp b/ets2panda/checker/ETSAnalyzer.cpp index ec729cf22942eacc61d2ca5a674062973d981b88..ddc11feb4981fe4f87ffbbcb06d65b3f902fa469 100644 --- a/ets2panda/checker/ETSAnalyzer.cpp +++ b/ets2panda/checker/ETSAnalyzer.cpp @@ -82,7 +82,7 @@ checker::Type *ETSAnalyzer::Check(ir::ClassDefinition *node) const checker::Type *ETSAnalyzer::Check(ir::ClassProperty *st) const { - ASSERT(st->Key()->IsIdentifier()); + ASSERT(st->Id() != nullptr); ETSChecker *checker = GetETSChecker(); if (st->TsType() != nullptr) { @@ -97,8 +97,7 @@ checker::Type *ETSAnalyzer::Check(ir::ClassProperty *st) const checker->AddStatus(checker::CheckerStatus::IN_STATIC_CONTEXT); } - st->SetTsType( - checker->CheckVariableDeclaration(st->Key()->AsIdentifier(), st->TypeAnnotation(), st->Value(), st->flags_)); + st->SetTsType(checker->CheckVariableDeclaration(st->Id(), st->TypeAnnotation(), st->Value(), st->Modifiers())); return st->TsType(); } diff --git a/ets2panda/ir/astNode.cpp b/ets2panda/ir/astNode.cpp index bceb87943b488f79aa83938d004a22ee54d1d161..4db50cff077bed7228d0102d09035f34df1efb3d 100644 --- a/ets2panda/ir/astNode.cpp +++ b/ets2panda/ir/astNode.cpp @@ -92,7 +92,7 @@ bool AstNode::IsAnyChild(const NodePredicate &cb) const void AnnotatedAstNode::CloneTypeAnnotation(ArenaAllocator *const allocator) { if (auto *annotation = const_cast(TypeAnnotation()); annotation != nullptr) { - SetTsTypeAnnotation(annotation->Clone(allocator, this)->AsTypeNode()); + SetTsTypeAnnotation(annotation->Clone(allocator, this)); } } diff --git a/ets2panda/ir/astNode.h b/ets2panda/ir/astNode.h index 950d346f6f7cd740eed5cb85242a15b16da29324..f164f1660c7d4bd4ae7438d7244faf93d3032686 100644 --- a/ets2panda/ir/astNode.h +++ b/ets2panda/ir/astNode.h @@ -448,6 +448,13 @@ public: [[nodiscard]] ir::BlockStatement *GetTopStatement(); [[nodiscard]] const ir::BlockStatement *GetTopStatement() const; + // NOLINTNEXTLINE(google-default-arguments) + [[nodiscard]] virtual AstNode *Clone([[maybe_unused]] ArenaAllocator *const allocator, + [[maybe_unused]] AstNode *const parent = nullptr) + { + UNREACHABLE(); + } + virtual void TransformChildren(const NodeTransformer &cb) = 0; virtual void Iterate(const NodeTraverser &cb) const = 0; void TransformChildrenRecursively(const NodeTransformer &cb); diff --git a/ets2panda/ir/base/classDefinition.cpp b/ets2panda/ir/base/classDefinition.cpp index 12e57a0dbcb10ad54bb56bc9a9365d5a8a68fb37..31520c1ffd1097eb9e0e568d5258279d52443180 100644 --- a/ets2panda/ir/base/classDefinition.cpp +++ b/ets2panda/ir/base/classDefinition.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021 - 2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/ets2panda/ir/base/classDefinition.h b/ets2panda/ir/base/classDefinition.h index 7341aab83e5a2787b52579e2eb10a6256299f4bf..b952989226c9e1f4d630395d56959aa89b51acef 100644 --- a/ets2panda/ir/base/classDefinition.h +++ b/ets2panda/ir/base/classDefinition.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021 - 2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.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,6 +50,12 @@ DEFINE_BITOPS(ClassDefinitionModifiers) class ClassDefinition : public TypedAstNode { public: + ClassDefinition() = delete; + ~ClassDefinition() override = default; + + NO_COPY_SEMANTIC(ClassDefinition); + NO_MOVE_SEMANTIC(ClassDefinition); + explicit ClassDefinition(varbinder::LocalScope *scope, const util::StringView &private_id, Identifier *ident, TSTypeParameterDeclaration *type_params, TSTypeParameterInstantiation *super_type_params, ArenaVector &&implements, MethodDefinition *ctor, @@ -104,82 +110,82 @@ public: return scope_; } - const Identifier *Ident() const + [[nodiscard]] const Identifier *Ident() const noexcept { return ident_; } - Identifier *Ident() + [[nodiscard]] Identifier *Ident() noexcept { return ident_; } - void SetIdent(ir::Identifier *ident) + void SetIdent(ir::Identifier *ident) noexcept { ident_ = ident; } - const util::StringView &PrivateId() const + [[nodiscard]] const util::StringView &PrivateId() const noexcept { return private_id_; } - const util::StringView &InternalName() const + [[nodiscard]] const util::StringView &InternalName() const noexcept { return private_id_; } - void SetInternalName(util::StringView internal_name) + void SetInternalName(util::StringView internal_name) noexcept { private_id_ = internal_name; } - Expression *Super() + [[nodiscard]] Expression *Super() noexcept { return super_class_; } - const Expression *Super() const + [[nodiscard]] const Expression *Super() const noexcept { return super_class_; } - bool IsGlobal() const + [[nodiscard]] bool IsGlobal() const noexcept { return (modifiers_ & ClassDefinitionModifiers::GLOBAL) != 0; } - bool IsExtern() const + [[nodiscard]] bool IsExtern() const noexcept { return (modifiers_ & ClassDefinitionModifiers::EXTERN) != 0; } - bool IsInner() const + [[nodiscard]] bool IsInner() const noexcept { return (modifiers_ & ClassDefinitionModifiers::INNER) != 0; } - bool IsGlobalInitialized() const + [[nodiscard]] bool IsGlobalInitialized() const noexcept { return (modifiers_ & ClassDefinitionModifiers::GLOBAL_INITIALIZED) != 0; } - es2panda::Language Language() const + [[nodiscard]] es2panda::Language Language() const noexcept { return lang_; } - void SetGlobalInitialized() + void SetGlobalInitialized() noexcept { modifiers_ |= ClassDefinitionModifiers::GLOBAL_INITIALIZED; } - void SetInnerModifier() + void SetInnerModifier() noexcept { modifiers_ |= ClassDefinitionModifiers::INNER; } - ClassDefinitionModifiers Modifiers() const + [[nodiscard]] ClassDefinitionModifiers Modifiers() const noexcept { return modifiers_; } @@ -193,37 +199,37 @@ public: body_.insert(body_.end(), body.begin(), body.end()); } - ArenaVector &Body() + [[nodiscard]] ArenaVector &Body() noexcept { return body_; } - const ArenaVector &Body() const + [[nodiscard]] const ArenaVector &Body() const noexcept { return body_; } - MethodDefinition *Ctor() + [[nodiscard]] MethodDefinition *Ctor() noexcept { return ctor_; } - ArenaVector &Implements() + [[nodiscard]] ArenaVector &Implements() noexcept { return implements_; } - const ArenaVector &Implements() const + [[nodiscard]] const ArenaVector &Implements() const noexcept { return implements_; } - const ir::TSTypeParameterDeclaration *TypeParams() const + [[nodiscard]] const ir::TSTypeParameterDeclaration *TypeParams() const noexcept { return type_params_; } - ir::TSTypeParameterDeclaration *TypeParams() + [[nodiscard]] ir::TSTypeParameterDeclaration *TypeParams() noexcept { return type_params_; } @@ -235,7 +241,9 @@ public: void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; + void Dump(ir::AstDumper *dumper) const override; + void Compile(compiler::PandaGen *pg) const override; void Compile(compiler::ETSGen *etsg) const override; checker::Type *Check(checker::TSChecker *checker) override; diff --git a/ets2panda/ir/base/classElement.cpp b/ets2panda/ir/base/classElement.cpp index 192aecf3038e85c9818b50e6e3161d8c24b5efe7..62b0ebb1003ff02519fe98bdc74c1bd7df759be1 100644 --- a/ets2panda/ir/base/classElement.cpp +++ b/ets2panda/ir/base/classElement.cpp @@ -20,17 +20,17 @@ namespace panda::es2panda::ir { -Identifier *ClassElement::Id() +Identifier *ClassElement::Id() noexcept { - return key_->AsIdentifier(); + return key_->IsIdentifier() ? key_->AsIdentifier() : nullptr; } -const Identifier *ClassElement::Id() const +const Identifier *ClassElement::Id() const noexcept { - return key_->AsIdentifier(); + return key_->IsIdentifier() ? key_->AsIdentifier() : nullptr; } -bool ClassElement::IsPrivateElement() const +bool ClassElement::IsPrivateElement() const noexcept { if (IsClassStaticBlock()) { return false; diff --git a/ets2panda/ir/base/classElement.h b/ets2panda/ir/base/classElement.h index ea99fb156653d56d229f50c4ff6972157bae7382..034f63036d56192ade204dce831d29fc520626be 100644 --- a/ets2panda/ir/base/classElement.h +++ b/ets2panda/ir/base/classElement.h @@ -23,8 +23,14 @@ class Expression; class ClassElement : public TypedStatement { public: - explicit ClassElement(AstNodeType element_type, Expression *key, Expression *value, ModifierFlags modifiers, - ArenaAllocator *allocator, bool is_computed) + ClassElement() = delete; + ~ClassElement() override = default; + + NO_COPY_SEMANTIC(ClassElement); + NO_MOVE_SEMANTIC(ClassElement); + + explicit ClassElement(AstNodeType const element_type, Expression *const key, Expression *const value, + ModifierFlags const modifiers, ArenaAllocator *const allocator, bool const is_computed) : TypedStatement(element_type, modifiers), key_(key), value_(value), @@ -33,37 +39,38 @@ public: { } - Identifier *Id(); - const Identifier *Id() const; + [[nodiscard]] Identifier *Id() noexcept; + + [[nodiscard]] const Identifier *Id() const noexcept; - Expression *Key() + [[nodiscard]] Expression *Key() noexcept { return key_; } - const Expression *Key() const + [[nodiscard]] const Expression *Key() const noexcept { return key_; } - Expression *Value() + [[nodiscard]] Expression *Value() noexcept { return value_; } - const Expression *Value() const + [[nodiscard]] const Expression *Value() const noexcept { return value_; } - bool IsPrivateElement() const; + [[nodiscard]] bool IsPrivateElement() const noexcept; - const ArenaVector &Decorators() const + [[nodiscard]] const ArenaVector &Decorators() const noexcept { return decorators_; } - bool IsComputed() const + [[nodiscard]] bool IsComputed() const noexcept { return is_computed_; } @@ -73,7 +80,14 @@ public: decorators_ = std::move(decorators); } - virtual PrivateFieldKind ToPrivateFieldKind(bool is_static) const = 0; + void AddDecorator(ir::Decorator *const decorator) + { + if (decorator != nullptr) { + decorators_.emplace_back(decorator); + } + } + + [[nodiscard]] virtual PrivateFieldKind ToPrivateFieldKind(bool is_static) const = 0; protected: // NOLINTBEGIN(misc-non-private-member-variables-in-classes) diff --git a/ets2panda/ir/base/classProperty.cpp b/ets2panda/ir/base/classProperty.cpp index 24bfd844c1b8dad6d7ee340955a11133a97a32bb..081a992abfc21948efc67dd5bda7052c2deb1e4d 100644 --- a/ets2panda/ir/base/classProperty.cpp +++ b/ets2panda/ir/base/classProperty.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021 - 2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.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,9 +26,6 @@ #include "ir/expression.h" #include "ir/expressions/identifier.h" -#include -#include - namespace panda::es2panda::ir { void ClassProperty::TransformChildren(const NodeTransformer &cb) { @@ -100,4 +97,31 @@ checker::Type *ClassProperty::Check(checker::ETSChecker *checker) { return checker->GetAnalyzer()->Check(this); } + +// NOLINTNEXTLINE(google-default-arguments) +ClassProperty *ClassProperty::Clone(ArenaAllocator *const allocator, AstNode *const parent) +{ + auto *const key = key_->Clone(allocator)->AsExpression(); + auto *const value = value_->Clone(allocator)->AsExpression(); + auto *const type_annotation = type_annotation_->Clone(allocator, this); + + if (auto *const clone = allocator->New(key, value, type_annotation, flags_, allocator, is_computed_); + clone != nullptr) { + if (parent != nullptr) { + clone->SetParent(parent); + } + + key->SetParent(clone); + value->SetParent(clone); + type_annotation->SetParent(clone); + + for (auto *const decorator : decorators_) { + clone->AddDecorator(decorator->Clone(allocator, clone)); + } + + return clone; + } + + throw Error(ErrorType::GENERIC, "", CLONE_ALLOCATION_ERROR); +} } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/base/classProperty.h b/ets2panda/ir/base/classProperty.h index 82738acdab8b41e04f7d507aeed1a87b0bf62344..fc9773fc0f74a130cd2e1ae1dc09b92f07268081 100644 --- a/ets2panda/ir/base/classProperty.h +++ b/ets2panda/ir/base/classProperty.h @@ -28,28 +28,37 @@ class TypeNode; class ClassProperty : public ClassElement { public: - explicit ClassProperty(Expression *key, Expression *value, TypeNode *type_annotation, ModifierFlags modifiers, - ArenaAllocator *allocator, bool is_computed) + ClassProperty() = delete; + ~ClassProperty() override = default; + + NO_COPY_SEMANTIC(ClassProperty); + NO_MOVE_SEMANTIC(ClassProperty); + + explicit ClassProperty(Expression *const key, Expression *const value, TypeNode *const type_annotation, + ModifierFlags const modifiers, ArenaAllocator *const allocator, bool const is_computed) : ClassElement(AstNodeType::CLASS_PROPERTY, key, value, modifiers, allocator, is_computed), type_annotation_(type_annotation) { } - // NOTE: csabahurton. friend relationship can be removed once there are getters for private fields - friend class checker::ETSAnalyzer; - TypeNode *TypeAnnotation() const + [[nodiscard]] TypeNode *TypeAnnotation() const noexcept { return type_annotation_; } - PrivateFieldKind ToPrivateFieldKind(bool is_static) const override + [[nodiscard]] PrivateFieldKind ToPrivateFieldKind(bool const is_static) const override { return is_static ? PrivateFieldKind::STATIC_FIELD : PrivateFieldKind::FIELD; } + // NOLINTNEXTLINE(google-default-arguments) + [[nodiscard]] ClassProperty *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; + void Dump(ir::AstDumper *dumper) const override; + void Compile(compiler::PandaGen *pg) const override; void Compile(compiler::ETSGen *etsg) const override; checker::Type *Check(checker::TSChecker *checker) override; diff --git a/ets2panda/ir/base/decorator.cpp b/ets2panda/ir/base/decorator.cpp index 3b9e5c419b8f49dbde292e01e9850584245f5ac7..beb884f79b09a942806568245b84a242d24ee780 100644 --- a/ets2panda/ir/base/decorator.cpp +++ b/ets2panda/ir/base/decorator.cpp @@ -60,9 +60,9 @@ checker::Type *Decorator::Check(checker::ETSChecker *checker) } // NOLINTNEXTLINE(google-default-arguments) -Statement *Decorator::Clone(ArenaAllocator *const allocator, AstNode *const parent) +Decorator *Decorator::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const expr = expr_ != nullptr ? expr_->Clone(allocator) : nullptr; + auto *const expr = expr_ != nullptr ? expr_->Clone(allocator)->AsExpression() : nullptr; if (auto *const clone = allocator->New(expr); clone != nullptr) { if (expr != nullptr) { diff --git a/ets2panda/ir/base/decorator.h b/ets2panda/ir/base/decorator.h index aadfb87af2223e923ce9840dd9e4690d50bea5ef..e85858d4b34eb4a7533e340431a087bf6e8908a1 100644 --- a/ets2panda/ir/base/decorator.h +++ b/ets2panda/ir/base/decorator.h @@ -37,7 +37,7 @@ public: } // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Statement *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] Decorator *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/base/metaProperty.cpp b/ets2panda/ir/base/metaProperty.cpp index f88b13cc03b88649618baabbb677af035f4dce63..cba2f3402a8fd1a3056cad35eac9483ef0f0b16b 100644 --- a/ets2panda/ir/base/metaProperty.cpp +++ b/ets2panda/ir/base/metaProperty.cpp @@ -70,7 +70,7 @@ checker::Type *MetaProperty::Check([[maybe_unused]] checker::ETSChecker *checker } // NOLINTNEXTLINE(google-default-arguments) -Expression *MetaProperty::Clone(ArenaAllocator *const allocator, AstNode *const parent) +MetaProperty *MetaProperty::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(kind_); clone != nullptr) { if (parent != nullptr) { diff --git a/ets2panda/ir/base/metaProperty.h b/ets2panda/ir/base/metaProperty.h index 7a3d4e7f1736685ee21cd162a22f70506a014073..6ba62e83febb2ffcf6559b76177548687aaf8211 100644 --- a/ets2panda/ir/base/metaProperty.h +++ b/ets2panda/ir/base/metaProperty.h @@ -44,7 +44,7 @@ public: void TransformChildren(const NodeTransformer &cb) override; // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] MetaProperty *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; diff --git a/ets2panda/ir/base/methodDefinition.cpp b/ets2panda/ir/base/methodDefinition.cpp index cff3cf3c6bd661e08997ecfc465c3c3b6208bd3c..0f59befb68dd5e66ff518f8ae710525023f43ef3 100644 --- a/ets2panda/ir/base/methodDefinition.cpp +++ b/ets2panda/ir/base/methodDefinition.cpp @@ -33,17 +33,17 @@ namespace panda::es2panda::ir { -ScriptFunction *MethodDefinition::Function() +ScriptFunction *MethodDefinition::Function() noexcept { - return value_->AsFunctionExpression()->Function(); + return value_->IsFunctionExpression() ? value_->AsFunctionExpression()->Function() : nullptr; } -const ScriptFunction *MethodDefinition::Function() const +const ScriptFunction *MethodDefinition::Function() const noexcept { - return value_->AsFunctionExpression()->Function(); + return value_->IsFunctionExpression() ? value_->AsFunctionExpression()->Function() : nullptr; } -PrivateFieldKind MethodDefinition::ToPrivateFieldKind(bool is_static) const +PrivateFieldKind MethodDefinition::ToPrivateFieldKind(bool const is_static) const { switch (kind_) { case MethodDefinitionKind::METHOD: { @@ -331,4 +331,38 @@ void MethodDefinition::CheckMethodModifiers(checker::ETSChecker *checker) "Invalid method modifier(s): a static method can't have abstract, final or override modifier.", Start()); } } + +// NOLINTNEXTLINE(google-default-arguments) +MethodDefinition *MethodDefinition::Clone(ArenaAllocator *const allocator, AstNode *const parent) +{ + auto *const key = key_ != nullptr ? key_->Clone(allocator)->AsExpression() : nullptr; + auto *const value = value_ != nullptr ? value_->Clone(allocator)->AsExpression() : nullptr; + + if (auto *const clone = allocator->New(kind_, key, value, flags_, allocator, is_computed_); + clone != nullptr) { + if (parent != nullptr) { + clone->SetParent(parent); + } + + if (key != nullptr) { + key->SetParent(clone); + } + + if (value != nullptr) { + value->SetParent(clone); + } + + for (auto *const decorator : decorators_) { + clone->AddDecorator(decorator->Clone(allocator, clone)); + } + + for (auto *const overloads : overloads_) { + clone->AddOverload(overloads->Clone(allocator, clone)); + } + + return clone; + } + + throw Error(ErrorType::GENERIC, "", CLONE_ALLOCATION_ERROR); +} } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/base/methodDefinition.h b/ets2panda/ir/base/methodDefinition.h index 079bddf66cfa20019c67274a2b4b1579b4c0af61..3040a05bd0e94079be6ef6e9eaa3255b413aa834 100644 --- a/ets2panda/ir/base/methodDefinition.h +++ b/ets2panda/ir/base/methodDefinition.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021 - 2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.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,41 +16,54 @@ #ifndef ES2PANDA_PARSER_INCLUDE_AST_METHOD_DEFINITION_H #define ES2PANDA_PARSER_INCLUDE_AST_METHOD_DEFINITION_H -#include "checker/types/ets/etsObjectType.h" -#include "checker/types/signature.h" #include "ir/base/classElement.h" +namespace panda::es2panda::checker { + +class ETSObjectType; +class Signature; + +} // namespace panda::es2panda::checker + namespace panda::es2panda::ir { + class Expression; +class ScriptFunction; enum class MethodDefinitionKind { NONE, CONSTRUCTOR, METHOD, EXTENSION_METHOD, GET, SET }; class MethodDefinition : public ClassElement { public: - explicit MethodDefinition(MethodDefinitionKind kind, Expression *key, Expression *value, ModifierFlags modifiers, - ArenaAllocator *allocator, bool is_computed) + MethodDefinition() = delete; + ~MethodDefinition() override = default; + + NO_COPY_SEMANTIC(MethodDefinition); + NO_MOVE_SEMANTIC(MethodDefinition); + + explicit MethodDefinition(MethodDefinitionKind const kind, Expression *const key, Expression *const value, + ModifierFlags const modifiers, ArenaAllocator *const allocator, bool const is_computed) : ClassElement(AstNodeType::METHOD_DEFINITION, key, value, modifiers, allocator, is_computed), kind_(kind), overloads_(allocator->Adapter()) { } - MethodDefinitionKind Kind() const + [[nodiscard]] MethodDefinitionKind Kind() const noexcept { return kind_; } - bool IsConstructor() const + [[nodiscard]] bool IsConstructor() const noexcept { return kind_ == MethodDefinitionKind::CONSTRUCTOR; } - bool IsExtensionMethod() const + [[nodiscard]] bool IsExtensionMethod() const noexcept { return kind_ == MethodDefinitionKind::EXTENSION_METHOD; } - const ArenaVector &Overloads() const + [[nodiscard]] const ArenaVector &Overloads() const noexcept { return overloads_; } @@ -60,19 +73,21 @@ public: overloads_ = std::move(overloads); } - void AddOverload(MethodDefinition *overload) + void AddOverload(MethodDefinition *const overload) { - overloads_.push_back(overload); + overloads_.emplace_back(overload); } - bool HasOverload(MethodDefinition *overload) + [[nodiscard]] bool HasOverload(MethodDefinition *overload) noexcept { return std::find(overloads_.begin(), overloads_.end(), overload) != overloads_.end(); } - ScriptFunction *Function(); - const ScriptFunction *Function() const; - PrivateFieldKind ToPrivateFieldKind(bool is_static) const override; + [[nodiscard]] ScriptFunction *Function() noexcept; + [[nodiscard]] const ScriptFunction *Function() const noexcept; + + [[nodiscard]] PrivateFieldKind ToPrivateFieldKind(bool is_static) const override; + void CheckMethodModifiers(checker::ETSChecker *checker); void CheckExtensionMethod(checker::ETSChecker *checker, ScriptFunction *extension_func); void CheckExtensionIsShadowedByMethod(checker::ETSChecker *checker, checker::ETSObjectType *obj_type, @@ -82,9 +97,14 @@ public: ScriptFunction *extension_func, checker::Signature *sigature); + // NOLINTNEXTLINE(google-default-arguments) + [[nodiscard]] MethodDefinition *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; + void Dump(ir::AstDumper *dumper) const override; + void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; void Compile([[maybe_unused]] compiler::ETSGen *etsg) const override; checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; diff --git a/ets2panda/ir/base/property.cpp b/ets2panda/ir/base/property.cpp index f607be57b12bc097976ea5ea62d080cc8809aac4..bc0c8e754ec5beaf68ae707944a2292e8f52f49c 100644 --- a/ets2panda/ir/base/property.cpp +++ b/ets2panda/ir/base/property.cpp @@ -33,10 +33,10 @@ Property::Property([[maybe_unused]] Tag const tag, Expression *const key, Expres } // NOLINTNEXTLINE(google-default-arguments) -Expression *Property::Clone(ArenaAllocator *const allocator, AstNode *const parent) +Property *Property::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const key = key_ != nullptr ? key_->Clone(allocator) : nullptr; - auto *const value = value_ != nullptr ? value_->Clone(allocator) : nullptr; + auto *const key = key_ != nullptr ? key_->Clone(allocator)->AsExpression() : nullptr; + auto *const value = value_ != nullptr ? value_->Clone(allocator)->AsExpression() : nullptr; if (auto *const clone = allocator->New(Tag {}, key, value); clone != nullptr) { if (key != nullptr) { diff --git a/ets2panda/ir/base/property.h b/ets2panda/ir/base/property.h index 91d91512c44d69921b94b4698ef2043ae9be9982..1d40da12463995cbc50b7b23778161c08dd46731 100644 --- a/ets2panda/ir/base/property.h +++ b/ets2panda/ir/base/property.h @@ -103,7 +103,7 @@ public: } // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] Property *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; bool ConvertibleToPatternProperty(); ValidationInfo ValidateExpression(); diff --git a/ets2panda/ir/base/scriptFunction.cpp b/ets2panda/ir/base/scriptFunction.cpp index d7477e92b5b7cd519c9d50af95313d86ef5ba972..bebc4021c33b3f1890fcb03064634d0d349bfe31 100644 --- a/ets2panda/ir/base/scriptFunction.cpp +++ b/ets2panda/ir/base/scriptFunction.cpp @@ -26,26 +26,17 @@ #include "ir/ts/tsTypeParameterDeclaration.h" namespace panda::es2panda::ir { -bool ScriptFunction::HasBody() const -{ - return body_ != nullptr; -} - -ir::ScriptFunctionFlags ScriptFunction::Flags() const -{ - return func_flags_; -} -size_t ScriptFunction::FormalParamsLength() const +std::size_t ScriptFunction::FormalParamsLength() const noexcept { - size_t length = 0; + std::size_t length = 0U; for (const auto *param : params_) { if (param->IsRestElement() || param->IsAssignmentPattern()) { break; } - length++; + ++length; } return length; diff --git a/ets2panda/ir/base/scriptFunction.h b/ets2panda/ir/base/scriptFunction.h index 93e134422716eda3f0635a8ab6982427df2d6bea..94fb4d61845dcc4ff3a8a7c71d4cbfea16e8e7bc 100644 --- a/ets2panda/ir/base/scriptFunction.h +++ b/ets2panda/ir/base/scriptFunction.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021 - 2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.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,14 @@ class TSTypeParameterDeclaration; class TypeNode; class ScriptFunction : public AstNode { +private: public: + ScriptFunction() = delete; + ~ScriptFunction() override = default; + + NO_COPY_SEMANTIC(ScriptFunction); + NO_MOVE_SEMANTIC(ScriptFunction); + explicit ScriptFunction(varbinder::FunctionScope *scope, ArenaVector &¶ms, TSTypeParameterDeclaration *type_params, AstNode *body, TypeNode *return_type_annotation, ir::ScriptFunctionFlags func_flags, bool declare, Language lang) @@ -61,164 +68,167 @@ public: { } - const Identifier *Id() const + [[nodiscard]] const Identifier *Id() const noexcept { return id_; } - Identifier *Id() + [[nodiscard]] Identifier *Id() noexcept { return id_; } - const checker::Signature *Signature() const + [[nodiscard]] const checker::Signature *Signature() const noexcept { return signature_; } - checker::Signature *Signature() + [[nodiscard]] checker::Signature *Signature() noexcept { return signature_; } - const ArenaVector &Params() const + [[nodiscard]] const ArenaVector &Params() const noexcept { return params_; } - ArenaVector &Params() + [[nodiscard]] ArenaVector &Params() noexcept { return params_; } - const TSTypeParameterDeclaration *TypeParams() const + [[nodiscard]] const TSTypeParameterDeclaration *TypeParams() const noexcept { return type_params_; } - TSTypeParameterDeclaration *TypeParams() + [[nodiscard]] TSTypeParameterDeclaration *TypeParams() noexcept { return type_params_; } - const AstNode *Body() const + [[nodiscard]] const AstNode *Body() const noexcept { return body_; } - AstNode *Body() + [[nodiscard]] AstNode *Body() noexcept { return body_; } - void SetBody(AstNode *body) + void SetBody(AstNode *body) noexcept { body_ = body; } - const TypeNode *ReturnTypeAnnotation() const + [[nodiscard]] const TypeNode *ReturnTypeAnnotation() const noexcept { return return_type_annotation_; } - TypeNode *ReturnTypeAnnotation() + [[nodiscard]] TypeNode *ReturnTypeAnnotation() noexcept { return return_type_annotation_; } - void SetReturnTypeAnnotation(TypeNode *node) + void SetReturnTypeAnnotation(TypeNode *node) noexcept { return_type_annotation_ = node; } - bool IsEntryPoint() const + [[nodiscard]] bool IsEntryPoint() const noexcept { return (func_flags_ & ir::ScriptFunctionFlags::ENTRY_POINT) != 0; } - bool IsGenerator() const + [[nodiscard]] bool IsGenerator() const noexcept { return (func_flags_ & ir::ScriptFunctionFlags::GENERATOR) != 0; } - bool IsAsyncFunc() const + [[nodiscard]] bool IsAsyncFunc() const noexcept { return (func_flags_ & ir::ScriptFunctionFlags::ASYNC) != 0; } - bool IsArrow() const + [[nodiscard]] bool IsArrow() const noexcept { return (func_flags_ & ir::ScriptFunctionFlags::ARROW) != 0; } - bool IsOverload() const + [[nodiscard]] bool IsOverload() const noexcept { return (func_flags_ & ir::ScriptFunctionFlags::OVERLOAD) != 0; } - bool IsConstructor() const + [[nodiscard]] bool IsConstructor() const noexcept { return (func_flags_ & ir::ScriptFunctionFlags::CONSTRUCTOR) != 0; } - bool IsGetter() const + [[nodiscard]] bool IsGetter() const noexcept { return (func_flags_ & ir::ScriptFunctionFlags::GETTER) != 0; } - bool IsSetter() const + [[nodiscard]] bool IsSetter() const noexcept { return (func_flags_ & ir::ScriptFunctionFlags::SETTER) != 0; } - bool IsMethod() const + [[nodiscard]] bool IsMethod() const noexcept { return (func_flags_ & ir::ScriptFunctionFlags::METHOD) != 0; } - bool IsProxy() const + [[nodiscard]] bool IsProxy() const noexcept { return (func_flags_ & ir::ScriptFunctionFlags::PROXY) != 0; } - bool IsStaticBlock() const + [[nodiscard]] bool IsStaticBlock() const noexcept { return (func_flags_ & ir::ScriptFunctionFlags::STATIC_BLOCK) != 0; } - bool IsEnum() const + [[nodiscard]] bool IsEnum() const noexcept { return (func_flags_ & ir::ScriptFunctionFlags::ENUM) != 0; } - bool IsHidden() const + [[nodiscard]] bool IsHidden() const noexcept { return (func_flags_ & ir::ScriptFunctionFlags::HIDDEN) != 0; } - bool IsExternal() const + [[nodiscard]] bool IsExternal() const noexcept { return (func_flags_ & ir::ScriptFunctionFlags::EXTERNAL) != 0; } - bool IsImplicitSuperCallNeeded() const + [[nodiscard]] bool IsImplicitSuperCallNeeded() const noexcept { return (func_flags_ & ir::ScriptFunctionFlags::IMPLICIT_SUPER_CALL_NEEDED) != 0; } - bool HasBody() const; + [[nodiscard]] bool HasBody() const noexcept + { + return body_ != nullptr; + } - bool IsThrowing() const + [[nodiscard]] bool IsThrowing() const noexcept { return (func_flags_ & ir::ScriptFunctionFlags::THROWS) != 0; } - bool IsRethrowing() const + [[nodiscard]] bool IsRethrowing() const noexcept { return (func_flags_ & ir::ScriptFunctionFlags::RETHROWS) != 0; } - bool IsDefaultParamProxy() const noexcept + [[nodiscard]] bool IsDefaultParamProxy() const noexcept { return (func_flags_ & ir::ScriptFunctionFlags::DEFAULT_PARAM_PROXY) != 0; } @@ -228,44 +238,47 @@ public: AddFlag(ir::ScriptFunctionFlags::DEFAULT_PARAM_PROXY); } - bool IsDynamic() const + [[nodiscard]] bool IsDynamic() const noexcept { return lang_.IsDynamic(); } - bool IsExtensionMethod() const + [[nodiscard]] bool IsExtensionMethod() const noexcept { return (func_flags_ & ir::ScriptFunctionFlags::INSTANCE_EXTENSION_METHOD) != 0; } - bool Declare() const + [[nodiscard]] bool Declare() const noexcept { return declare_; } - ir::ScriptFunctionFlags Flags() const; + [[nodiscard]] ir::ScriptFunctionFlags Flags() const noexcept + { + return func_flags_; + } - void SetIdent(Identifier *id) + void SetIdent(Identifier *id) noexcept { id_ = id; } - void SetSignature(checker::Signature *signature) + void SetSignature(checker::Signature *signature) noexcept { signature_ = signature; } - void AddFlag(ir::ScriptFunctionFlags flags) + void AddFlag(ir::ScriptFunctionFlags flags) noexcept { func_flags_ |= flags; } - void AddModifier(ir::ModifierFlags flags) + void AddModifier(ir::ModifierFlags flags) noexcept { flags_ |= flags; } - size_t FormalParamsLength() const; + [[nodiscard]] std::size_t FormalParamsLength() const noexcept; bool IsScopeBearer() const override { @@ -277,15 +290,16 @@ public: return scope_; } - void TransformChildren(const NodeTransformer &cb) override; - - es2panda::Language Language() const + [[nodiscard]] es2panda::Language Language() const { return lang_; } + void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; + void Dump(ir::AstDumper *dumper) const override; + void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; void Compile([[maybe_unused]] compiler::ETSGen *etsg) const override; checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; diff --git a/ets2panda/ir/base/spreadElement.cpp b/ets2panda/ir/base/spreadElement.cpp index 1f995a1f1160a8f03d86f2b8c0199817629b6394..e7ff3e06229faacd354b5dd91279d5cbc2e63c54 100644 --- a/ets2panda/ir/base/spreadElement.cpp +++ b/ets2panda/ir/base/spreadElement.cpp @@ -31,16 +31,16 @@ SpreadElement::SpreadElement([[maybe_unused]] Tag const tag, SpreadElement const optional_ = other.optional_; if (other.argument_ != nullptr) { - argument_ = other.argument_->Clone(allocator, this); + argument_ = other.argument_->Clone(allocator, this)->AsExpression(); } for (auto *decorator : other.decorators_) { - decorators_.emplace_back(decorator->Clone(allocator, this)->AsDecorator()); + decorators_.emplace_back(decorator->Clone(allocator, this)); } } // NOLINTNEXTLINE(google-default-arguments) -Expression *SpreadElement::Clone(ArenaAllocator *const allocator, AstNode *const parent) +SpreadElement *SpreadElement::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(Tag {}, *this, allocator); clone != nullptr) { if (parent != nullptr) { diff --git a/ets2panda/ir/base/spreadElement.h b/ets2panda/ir/base/spreadElement.h index 037cc59ca40d90174d64c54e4380f659c96ae2b5..11ef4991fb60be00ec832be185f5c5a30244eedd 100644 --- a/ets2panda/ir/base/spreadElement.h +++ b/ets2panda/ir/base/spreadElement.h @@ -69,7 +69,7 @@ public: } // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] SpreadElement *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; ValidationInfo ValidateExpression(); [[nodiscard]] bool ConvertibleToRest(bool is_declaration, bool allow_pattern = true); diff --git a/ets2panda/ir/base/templateElement.cpp b/ets2panda/ir/base/templateElement.cpp index 8a0e7d317ee2ca4c6cdd02508ea2490ef5eb7ca5..d48fe642795a24e28ecfb2d963dca5a36511e7c4 100644 --- a/ets2panda/ir/base/templateElement.cpp +++ b/ets2panda/ir/base/templateElement.cpp @@ -51,7 +51,7 @@ checker::Type *TemplateElement::Check([[maybe_unused]] checker::ETSChecker *chec } // NOLINTNEXTLINE(google-default-arguments) -Expression *TemplateElement::Clone(ArenaAllocator *const allocator, AstNode *const parent) +TemplateElement *TemplateElement::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(raw_, cooked_); clone != nullptr) { if (parent != nullptr) { diff --git a/ets2panda/ir/base/templateElement.h b/ets2panda/ir/base/templateElement.h index b373d7aff8cc660a598824361c10e65c2e93ef3c..55280eb77bb58c126cdd8427f0de93c62bcf171b 100644 --- a/ets2panda/ir/base/templateElement.h +++ b/ets2panda/ir/base/templateElement.h @@ -45,7 +45,7 @@ public: } // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] TemplateElement *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/base/tsIndexSignature.cpp b/ets2panda/ir/base/tsIndexSignature.cpp index 09598d5b2488039e1ebf0c31c6900265cb77e31a..1297bd78f327da31c9ed5a0d2e53502deae90bcf 100644 --- a/ets2panda/ir/base/tsIndexSignature.cpp +++ b/ets2panda/ir/base/tsIndexSignature.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021 - 2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.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,13 +16,12 @@ #include "tsIndexSignature.h" #include "ir/astDump.h" -#include "ir/typeNode.h" #include "ir/expressions/identifier.h" #include "checker/TSchecker.h" namespace panda::es2panda::ir { -TSIndexSignature::TSIndexSignatureKind TSIndexSignature::Kind() const +TSIndexSignature::TSIndexSignatureKind TSIndexSignature::Kind() const noexcept { return param_->AsIdentifier()->TypeAnnotation()->IsTSNumberKeyword() ? TSIndexSignatureKind::NUMBER : TSIndexSignatureKind::STRING; @@ -78,4 +77,24 @@ checker::Type *TSIndexSignature::Check([[maybe_unused]] checker::ETSChecker *che { return nullptr; } + +// NOLINTNEXTLINE(google-default-arguments) +TSIndexSignature *TSIndexSignature::Clone(ArenaAllocator *const allocator, AstNode *const parent) +{ + auto *const param = param_ != nullptr ? param_->Clone(allocator)->AsExpression() : nullptr; + auto *const type_annotation = type_annotation_->Clone(allocator); + + if (auto *const clone = allocator->New(param, type_annotation, readonly_); clone != nullptr) { + if (parent != nullptr) { + clone->SetParent(parent); + } + if (param != nullptr) { + param->SetParent(clone); + } + type_annotation->SetParent(clone); + return clone; + } + + throw Error(ErrorType::GENERIC, "", CLONE_ALLOCATION_ERROR); +} } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/base/tsIndexSignature.h b/ets2panda/ir/base/tsIndexSignature.h index db29746c9150d9f768b760e68477280096771d64..ed9bc3d8c1bae63c7030e97e8a5788b8318f4cca 100644 --- a/ets2panda/ir/base/tsIndexSignature.h +++ b/ets2panda/ir/base/tsIndexSignature.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021 - 2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.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,14 +16,20 @@ #ifndef ES2PANDA_PARSER_INCLUDE_AST_TS_INDEX_SIGNATURE_H #define ES2PANDA_PARSER_INCLUDE_AST_TS_INDEX_SIGNATURE_H -#include "ir/statement.h" +#include "ir/typeNode.h" namespace panda::es2panda::ir { class TSIndexSignature : public TypedAstNode { public: enum class TSIndexSignatureKind { NUMBER, STRING }; - explicit TSIndexSignature(Expression *param, TypeNode *type_annotation, bool readonly) + TSIndexSignature() = delete; + ~TSIndexSignature() override = default; + + NO_COPY_SEMANTIC(TSIndexSignature); + NO_MOVE_SEMANTIC(TSIndexSignature); + + explicit TSIndexSignature(Expression *const param, TypeNode *const type_annotation, bool const readonly) : TypedAstNode(AstNodeType::TS_INDEX_SIGNATURE), param_(param), type_annotation_(type_annotation), @@ -31,26 +37,31 @@ public: { } - const Expression *Param() const + [[nodiscard]] const Expression *Param() const noexcept { return param_; } - const TypeNode *TypeAnnotation() const + [[nodiscard]] const TypeNode *TypeAnnotation() const noexcept { return type_annotation_; } - bool Readonly() const + [[nodiscard]] bool Readonly() const noexcept { return readonly_; } - TSIndexSignatureKind Kind() const; + [[nodiscard]] TSIndexSignatureKind Kind() const noexcept; + + // NOLINTNEXTLINE(google-default-arguments) + [[nodiscard]] TSIndexSignature *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; + void Dump(ir::AstDumper *dumper) const override; + void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; diff --git a/ets2panda/ir/base/tsMethodSignature.cpp b/ets2panda/ir/base/tsMethodSignature.cpp index c6f203b24b91e353de82a43c3fc37a2cd96349f9..4e09c0dd5b2eee323e555faf1137a587d48cb5f9 100644 --- a/ets2panda/ir/base/tsMethodSignature.cpp +++ b/ets2panda/ir/base/tsMethodSignature.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021 - 2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.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 "varbinder/scope.h" #include "ir/astDump.h" -#include "ir/typeNode.h" #include "ir/ts/tsTypeParameter.h" #include "ir/ts/tsTypeParameterDeclaration.h" diff --git a/ets2panda/ir/base/tsMethodSignature.h b/ets2panda/ir/base/tsMethodSignature.h index ffa4dca38709fca21aa9ff37fc4382ca0e2e69cd..849f463aa4e74df9f2ca22e0ab834866ce511f07 100644 --- a/ets2panda/ir/base/tsMethodSignature.h +++ b/ets2panda/ir/base/tsMethodSignature.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021 - 2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.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,13 +16,19 @@ #ifndef ES2PANDA_PARSER_INCLUDE_AST_TS_METHOD_SIGNATURE_H #define ES2PANDA_PARSER_INCLUDE_AST_TS_METHOD_SIGNATURE_H -#include "ir/statement.h" +#include "ir/typeNode.h" namespace panda::es2panda::ir { class TSTypeParameterDeclaration; class TSMethodSignature : public AstNode { public: + TSMethodSignature() = delete; + ~TSMethodSignature() override = default; + + NO_COPY_SEMANTIC(TSMethodSignature); + NO_MOVE_SEMANTIC(TSMethodSignature); + explicit TSMethodSignature(varbinder::Scope *scope, Expression *key, TSTypeParameterDeclaration *type_params, ArenaVector &¶ms, TypeNode *return_type_annotation, bool computed, bool optional) @@ -47,44 +53,46 @@ public: return scope_; } - const Expression *Key() const + [[nodiscard]] const Expression *Key() const noexcept { return key_; } - Expression *Key() + [[nodiscard]] Expression *Key() noexcept { return key_; } - const TSTypeParameterDeclaration *TypeParams() const + [[nodiscard]] const TSTypeParameterDeclaration *TypeParams() const noexcept { return type_params_; } - const ArenaVector &Params() const + [[nodiscard]] const ArenaVector &Params() const noexcept { return params_; } - const TypeNode *ReturnTypeAnnotation() const + [[nodiscard]] const TypeNode *ReturnTypeAnnotation() const noexcept { return return_type_annotation_; } - bool Computed() const + [[nodiscard]] bool Computed() const noexcept { return computed_; } - bool Optional() const + [[nodiscard]] bool Optional() const noexcept { return optional_; } void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; + void Dump(ir::AstDumper *dumper) const override; + void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; diff --git a/ets2panda/ir/base/tsPropertySignature.cpp b/ets2panda/ir/base/tsPropertySignature.cpp index 3cfddf1f7fa1cb06cf888cd07f5a517fa545388e..8c5312bdc4a35a6c7f6542d8644ddd61a5b411b8 100644 --- a/ets2panda/ir/base/tsPropertySignature.cpp +++ b/ets2panda/ir/base/tsPropertySignature.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021 - 2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -74,4 +74,25 @@ checker::Type *TSPropertySignature::Check([[maybe_unused]] checker::ETSChecker * { return nullptr; } + +// NOLINTNEXTLINE(google-default-arguments) +TSPropertySignature *TSPropertySignature::Clone(ArenaAllocator *const allocator, AstNode *const parent) +{ + auto *const key = key_ != nullptr ? key_->Clone(allocator)->AsExpression() : nullptr; + auto *const type_annotation = TypeAnnotation()->Clone(allocator); + + if (auto *const clone = allocator->New(key, type_annotation, computed_, optional_, readonly_); + clone != nullptr) { + if (parent != nullptr) { + clone->SetParent(parent); + } + if (key != nullptr) { + key->SetParent(clone); + } + type_annotation->SetParent(clone); + return clone; + } + + throw Error(ErrorType::GENERIC, "", CLONE_ALLOCATION_ERROR); +} } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/base/tsPropertySignature.h b/ets2panda/ir/base/tsPropertySignature.h index b39ebfdd0dc38b3e327f4905f11ab52012768d2f..c9ba0b1fb51b7aeb9d934f495fa28c9694bcc533 100644 --- a/ets2panda/ir/base/tsPropertySignature.h +++ b/ets2panda/ir/base/tsPropertySignature.h @@ -23,6 +23,12 @@ class TypeNode; class TSPropertySignature : public AnnotatedAstNode { public: + TSPropertySignature() = delete; + ~TSPropertySignature() override = default; + + NO_COPY_SEMANTIC(TSPropertySignature); + NO_MOVE_SEMANTIC(TSPropertySignature); + explicit TSPropertySignature(Expression *key, TypeNode *type_annotation, bool computed, bool optional, bool readonly) : AnnotatedAstNode(AstNodeType::TS_PROPERTY_SIGNATURE, type_annotation), @@ -33,34 +39,39 @@ public: { } - const Expression *Key() const + [[nodiscard]] const Expression *Key() const noexcept { return key_; } - Expression *Key() + [[nodiscard]] Expression *Key() noexcept { return key_; } - bool Computed() const + [[nodiscard]] bool Computed() const noexcept { return computed_; } - bool Optional() const + [[nodiscard]] bool Optional() const noexcept { return optional_; } - bool Readonly() const + [[nodiscard]] bool Readonly() const noexcept { return readonly_; } + // NOLINTNEXTLINE(google-default-arguments) + [[nodiscard]] TSPropertySignature *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; + void Dump(ir::AstDumper *dumper) const override; + void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; diff --git a/ets2panda/ir/base/tsSignatureDeclaration.cpp b/ets2panda/ir/base/tsSignatureDeclaration.cpp index 734c4613f9cdd7b80be713cadb2c229dd837689d..a36cf714a6a1d619871eb8b804e8240d92575d13 100644 --- a/ets2panda/ir/base/tsSignatureDeclaration.cpp +++ b/ets2panda/ir/base/tsSignatureDeclaration.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021 - 2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/ets2panda/ir/base/tsSignatureDeclaration.h b/ets2panda/ir/base/tsSignatureDeclaration.h index bd89af7fa3b833cc3542d3b60d05ae871697f8e6..20028f3aa848702267ad4baf9d862a158343e16d 100644 --- a/ets2panda/ir/base/tsSignatureDeclaration.h +++ b/ets2panda/ir/base/tsSignatureDeclaration.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021 - 2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.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,7 @@ #ifndef ES2PANDA_PARSER_INCLUDE_AST_TS_SIGNATURE_DECLARATION_H #define ES2PANDA_PARSER_INCLUDE_AST_TS_SIGNATURE_DECLARATION_H -#include "ir/statement.h" +#include "ir/astNode.h" namespace panda::es2panda::ir { class TSTypeParameterDeclaration; @@ -25,9 +25,15 @@ class TSSignatureDeclaration : public TypedAstNode { public: enum class TSSignatureDeclarationKind { CALL_SIGNATURE, CONSTRUCT_SIGNATURE }; - explicit TSSignatureDeclaration(varbinder::Scope *scope, TSSignatureDeclarationKind kind, - TSTypeParameterDeclaration *type_params, ArenaVector &¶ms, - TypeNode *return_type_annotation) + TSSignatureDeclaration() = delete; + ~TSSignatureDeclaration() override = default; + + NO_COPY_SEMANTIC(TSSignatureDeclaration); + NO_MOVE_SEMANTIC(TSSignatureDeclaration); + + explicit TSSignatureDeclaration(varbinder::Scope *const scope, TSSignatureDeclarationKind const kind, + TSTypeParameterDeclaration *const type_params, ArenaVector &¶ms, + TypeNode *const return_type_annotation) : TypedAstNode(AstNodeType::TS_SIGNATURE_DECLARATION), scope_(scope), kind_(kind), @@ -47,29 +53,31 @@ public: return scope_; } - const TSTypeParameterDeclaration *TypeParams() const + [[nodiscard]] const TSTypeParameterDeclaration *TypeParams() const noexcept { return type_params_; } - const ArenaVector &Params() const + [[nodiscard]] const ArenaVector &Params() const noexcept { return params_; } - const TypeNode *ReturnTypeAnnotation() const + [[nodiscard]] const TypeNode *ReturnTypeAnnotation() const noexcept { return return_type_annotation_; } - TSSignatureDeclarationKind Kind() const + [[nodiscard]] TSSignatureDeclarationKind Kind() const noexcept { return kind_; } void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; + void Dump(ir::AstDumper *dumper) const override; + void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; diff --git a/ets2panda/ir/ets/etsClassLiteral.cpp b/ets2panda/ir/ets/etsClassLiteral.cpp index 79c11f531ecd7fc26d5fb88e412abc91c73b012b..9d461309a1ecac09ea49b28c67e735499e41a92d 100644 --- a/ets2panda/ir/ets/etsClassLiteral.cpp +++ b/ets2panda/ir/ets/etsClassLiteral.cpp @@ -77,9 +77,9 @@ checker::Type *ETSClassLiteral::Check([[maybe_unused]] checker::ETSChecker *chec } // NOLINTNEXTLINE(google-default-arguments) -Expression *ETSClassLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) +ETSClassLiteral *ETSClassLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const expr = expr_ != nullptr ? expr_->Clone(allocator)->AsTypeNode() : nullptr; + auto *const expr = expr_ != nullptr ? expr_->Clone(allocator) : nullptr; if (auto *const clone = allocator->New(expr); clone != nullptr) { if (expr != nullptr) { diff --git a/ets2panda/ir/ets/etsClassLiteral.h b/ets2panda/ir/ets/etsClassLiteral.h index 64dadfd65bbfb304b5a993444ee73cbba8bbe36f..44fbf9c8ba0179b0caf85783579f81727f302c11 100644 --- a/ets2panda/ir/ets/etsClassLiteral.h +++ b/ets2panda/ir/ets/etsClassLiteral.h @@ -31,7 +31,7 @@ public: explicit ETSClassLiteral(ir::TypeNode *const expr) : Expression(AstNodeType::ETS_CLASS_LITERAL), expr_(expr) {} // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ETSClassLiteral *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/ets/etsLaunchExpression.cpp b/ets2panda/ir/ets/etsLaunchExpression.cpp index f5d880a47f87fba81be68b8bcdd7c9ea5d3983b0..280a1f05e2531d5bc58e42805d5a69a6ae531f7b 100644 --- a/ets2panda/ir/ets/etsLaunchExpression.cpp +++ b/ets2panda/ir/ets/etsLaunchExpression.cpp @@ -117,9 +117,9 @@ bool ETSLaunchExpression::IsStaticCall() const } // NOLINTNEXTLINE(google-default-arguments) -Expression *ETSLaunchExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) +ETSLaunchExpression *ETSLaunchExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const expr = expr_ != nullptr ? expr_->Clone(allocator)->AsCallExpression() : nullptr; + auto *const expr = expr_ != nullptr ? expr_->Clone(allocator) : nullptr; if (auto *const clone = allocator->New(expr); clone != nullptr) { if (expr != nullptr) { diff --git a/ets2panda/ir/ets/etsLaunchExpression.h b/ets2panda/ir/ets/etsLaunchExpression.h index db99d9e6a58b6fd1a65e0be5066bdb06cb764bed..2863db9948045ae9f94f5adba6606e7e2333e716 100644 --- a/ets2panda/ir/ets/etsLaunchExpression.h +++ b/ets2panda/ir/ets/etsLaunchExpression.h @@ -33,7 +33,7 @@ public: explicit ETSLaunchExpression(CallExpression *expr); // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ETSLaunchExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/ets/etsNewArrayInstanceExpression.cpp b/ets2panda/ir/ets/etsNewArrayInstanceExpression.cpp index bf3d63aafe6f8230f4e2f8cb39ebd7dc9b536ce3..b56d07341e770bf2117b4091904345c98e01cbfa 100644 --- a/ets2panda/ir/ets/etsNewArrayInstanceExpression.cpp +++ b/ets2panda/ir/ets/etsNewArrayInstanceExpression.cpp @@ -71,10 +71,11 @@ checker::Type *ETSNewArrayInstanceExpression::Check([[maybe_unused]] checker::ET } // NOLINTNEXTLINE(google-default-arguments) -Expression *ETSNewArrayInstanceExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) +ETSNewArrayInstanceExpression *ETSNewArrayInstanceExpression::Clone(ArenaAllocator *const allocator, + AstNode *const parent) { - auto *const type_ref = type_reference_ != nullptr ? type_reference_->Clone(allocator)->AsTypeNode() : nullptr; - auto *const dimension = dimension_ != nullptr ? dimension_->Clone(allocator) : nullptr; + auto *const type_ref = type_reference_ != nullptr ? type_reference_->Clone(allocator) : nullptr; + auto *const dimension = dimension_ != nullptr ? dimension_->Clone(allocator)->AsExpression() : nullptr; if (auto *const clone = allocator->New(type_ref, dimension); clone != nullptr) { if (type_ref != nullptr) { diff --git a/ets2panda/ir/ets/etsNewArrayInstanceExpression.h b/ets2panda/ir/ets/etsNewArrayInstanceExpression.h index 553bb75120377bf84d5ead2276bf5323fbf855b6..9cafcc56e83cd9a827e29f86a5ff96b4be39be7a 100644 --- a/ets2panda/ir/ets/etsNewArrayInstanceExpression.h +++ b/ets2panda/ir/ets/etsNewArrayInstanceExpression.h @@ -36,7 +36,7 @@ public: } // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ETSNewArrayInstanceExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/ets/etsNewClassInstanceExpression.cpp b/ets2panda/ir/ets/etsNewClassInstanceExpression.cpp index 0e55a8ac981c704ab2e0c4719cf31b7094de37d2..e0a0ce1b2db3d3c27225f514e5e99143699d9d2f 100644 --- a/ets2panda/ir/ets/etsNewClassInstanceExpression.cpp +++ b/ets2panda/ir/ets/etsNewClassInstanceExpression.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 - 2023 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.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,4 +184,30 @@ checker::Type *ETSNewClassInstanceExpression::Check([[maybe_unused]] checker::ET return TsType(); } + +ETSNewClassInstanceExpression::ETSNewClassInstanceExpression(ETSNewClassInstanceExpression const &other, + ArenaAllocator *const allocator) + : Expression(static_cast(other)), arguments_(allocator->Adapter()), signature_(other.signature_) +{ + type_reference_ = other.type_reference_->Clone(allocator, this)->AsExpression(); + class_def_ = other.class_def_->Clone(allocator, this)->AsClassDefinition(); + + for (auto *const argument : other.arguments_) { + arguments_.emplace_back(argument->Clone(allocator, this)->AsExpression()); + } +} + +// NOLINTNEXTLINE(google-default-arguments) +ETSNewClassInstanceExpression *ETSNewClassInstanceExpression::Clone(ArenaAllocator *const allocator, + AstNode *const parent) +{ + if (auto *const clone = allocator->New(*this, allocator); clone != nullptr) { + if (parent != nullptr) { + clone->SetParent(parent); + } + return clone; + } + + throw Error(ErrorType::GENERIC, "", CLONE_ALLOCATION_ERROR); +} } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/ets/etsNewClassInstanceExpression.h b/ets2panda/ir/ets/etsNewClassInstanceExpression.h index ffed6e65cdd9747a1bde4c1841d2ce62757f987f..25cd7607ff939b0d2b1de559525514646d09be1c 100644 --- a/ets2panda/ir/ets/etsNewClassInstanceExpression.h +++ b/ets2panda/ir/ets/etsNewClassInstanceExpression.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 - 2023 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -29,8 +29,15 @@ class ClassDefinition; class ETSNewClassInstanceExpression : public Expression { public: - explicit ETSNewClassInstanceExpression(ir::Expression *type_reference, ArenaVector &&arguments, - ir::ClassDefinition *class_definition) + ETSNewClassInstanceExpression() = delete; + ~ETSNewClassInstanceExpression() override = default; + + NO_COPY_SEMANTIC(ETSNewClassInstanceExpression); + NO_MOVE_SEMANTIC(ETSNewClassInstanceExpression); + + explicit ETSNewClassInstanceExpression(ir::Expression *const type_reference, + ArenaVector &&arguments, + ir::ClassDefinition *const class_definition) : Expression(AstNodeType::ETS_NEW_CLASS_INSTANCE_EXPRESSION), type_reference_(type_reference), arguments_(std::move(arguments)), @@ -38,22 +45,24 @@ public: { } - ir::ClassDefinition *ClassDefinition() + explicit ETSNewClassInstanceExpression(ETSNewClassInstanceExpression const &other, ArenaAllocator *allocator); + + [[nodiscard]] ir::ClassDefinition *ClassDefinition() noexcept { return class_def_; } - const ir::ClassDefinition *ClassDefinition() const + [[nodiscard]] const ir::ClassDefinition *ClassDefinition() const noexcept { return class_def_; } - ir::Expression *GetTypeRef() const + [[nodiscard]] ir::Expression *GetTypeRef() const noexcept { return type_reference_; } - ArenaVector GetArguments() const + [[nodiscard]] ArenaVector GetArguments() const noexcept { return arguments_; } @@ -67,9 +76,14 @@ public: ir::Expression *name, checker::Signature *signature, const ArenaVector &arguments); + // NOLINTNEXTLINE(google-default-arguments) + [[nodiscard]] ETSNewClassInstanceExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; + void Dump(ir::AstDumper *dumper) const override; + void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; void Compile([[maybe_unused]] compiler::ETSGen *etsg) const override; checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; diff --git a/ets2panda/ir/ets/etsNewMultiDimArrayInstanceExpression.cpp b/ets2panda/ir/ets/etsNewMultiDimArrayInstanceExpression.cpp index 3671c96b28d60c2b1e9c1f9b1465aea951eb4738..73a9fafa1f10cac753fe217a3b28092a44d9a4c7 100644 --- a/ets2panda/ir/ets/etsNewMultiDimArrayInstanceExpression.cpp +++ b/ets2panda/ir/ets/etsNewMultiDimArrayInstanceExpression.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 - 2023 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -71,4 +71,31 @@ checker::Type *ETSNewMultiDimArrayInstanceExpression::Check([[maybe_unused]] che signature_ = checker->CreateBuiltinArraySignature(element_type->AsETSArrayType(), dimensions_.size()); return TsType(); } + +ETSNewMultiDimArrayInstanceExpression::ETSNewMultiDimArrayInstanceExpression( + ETSNewMultiDimArrayInstanceExpression const &other, ArenaAllocator *const allocator) + : Expression(static_cast(other)), + dimensions_(allocator->Adapter()), + signature_(other.signature_) +{ + type_reference_ = other.type_reference_->Clone(allocator, this); + + for (auto *const dimension : other.dimensions_) { + dimensions_.emplace_back(dimension->Clone(allocator, this)->AsExpression()); + } +} + +// NOLINTNEXTLINE(google-default-arguments) +ETSNewMultiDimArrayInstanceExpression *ETSNewMultiDimArrayInstanceExpression::Clone(ArenaAllocator *const allocator, + AstNode *const parent) +{ + if (auto *const clone = allocator->New(*this, allocator); clone != nullptr) { + if (parent != nullptr) { + clone->SetParent(parent); + } + return clone; + } + + throw Error(ErrorType::GENERIC, "", CLONE_ALLOCATION_ERROR); +} } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/ets/etsNewMultiDimArrayInstanceExpression.h b/ets2panda/ir/ets/etsNewMultiDimArrayInstanceExpression.h index 1cf38efa643435cccf347872aed8957b3912a35d..2ee2a3d4d4c5b1a458c446d808ff5694d67417a3 100644 --- a/ets2panda/ir/ets/etsNewMultiDimArrayInstanceExpression.h +++ b/ets2panda/ir/ets/etsNewMultiDimArrayInstanceExpression.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.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,7 +26,13 @@ namespace panda::es2panda::ir { class ETSNewMultiDimArrayInstanceExpression : public Expression { public: - explicit ETSNewMultiDimArrayInstanceExpression(ir::TypeNode *type_reference, + ETSNewMultiDimArrayInstanceExpression() = delete; + ~ETSNewMultiDimArrayInstanceExpression() override = default; + + NO_COPY_SEMANTIC(ETSNewMultiDimArrayInstanceExpression); + NO_MOVE_SEMANTIC(ETSNewMultiDimArrayInstanceExpression); + + explicit ETSNewMultiDimArrayInstanceExpression(ir::TypeNode *const type_reference, ArenaVector &&dimensions) : Expression(AstNodeType::ETS_NEW_MULTI_DIM_ARRAY_INSTANCE_EXPRESSION), type_reference_(type_reference), @@ -34,19 +40,28 @@ public: { } - checker::Signature *Signature() + explicit ETSNewMultiDimArrayInstanceExpression(ETSNewMultiDimArrayInstanceExpression const &other, + ArenaAllocator *allocator); + + [[nodiscard]] checker::Signature *Signature() noexcept { return signature_; } - const checker::Signature *Signature() const + [[nodiscard]] const checker::Signature *Signature() const noexcept { return signature_; } + // NOLINTNEXTLINE(google-default-arguments) + [[nodiscard]] ETSNewMultiDimArrayInstanceExpression *Clone(ArenaAllocator *allocator, + AstNode *parent = nullptr) override; + void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; + void Dump(ir::AstDumper *dumper) const override; + void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; void Compile([[maybe_unused]] compiler::ETSGen *etsg) const override; checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; diff --git a/ets2panda/ir/ets/etsPackageDeclaration.cpp b/ets2panda/ir/ets/etsPackageDeclaration.cpp index b31ed8e71ba451b99890227ca2d99567b4091c56..d78bc70007436b6924d85215c7adc11893d39c97 100644 --- a/ets2panda/ir/ets/etsPackageDeclaration.cpp +++ b/ets2panda/ir/ets/etsPackageDeclaration.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 - 2023 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.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,4 +50,21 @@ checker::Type *ETSPackageDeclaration::Check([[maybe_unused]] checker::ETSChecker { return nullptr; } + +// NOLINTNEXTLINE(google-default-arguments) +ETSPackageDeclaration *ETSPackageDeclaration::Clone(ArenaAllocator *const allocator, AstNode *const parent) +{ + auto const name = name_ != nullptr ? name_->Clone(allocator, this)->AsExpression() : nullptr; + if (auto *const clone = allocator->New(name); clone != nullptr) { + if (name != nullptr) { + name->SetParent(clone); + } + if (parent != nullptr) { + clone->SetParent(parent); + } + return clone; + } + + throw Error(ErrorType::GENERIC, "", CLONE_ALLOCATION_ERROR); +} } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/ets/etsPackageDeclaration.h b/ets2panda/ir/ets/etsPackageDeclaration.h index 8ca20442d3d93240c979767e8aae6325cd873180..50249d8c681dcf6dad4c8d05bda130833c8b1a85 100644 --- a/ets2panda/ir/ets/etsPackageDeclaration.h +++ b/ets2panda/ir/ets/etsPackageDeclaration.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 - 2023 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.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,25 @@ namespace panda::es2panda::ir { class ETSPackageDeclaration : public Statement { public: - explicit ETSPackageDeclaration(ir::Expression *name) : Statement(AstNodeType::ETS_PACKAGE_DECLARATION), name_(name) + ETSPackageDeclaration() = delete; + ~ETSPackageDeclaration() override = default; + + NO_COPY_SEMANTIC(ETSPackageDeclaration); + NO_MOVE_SEMANTIC(ETSPackageDeclaration); + + explicit ETSPackageDeclaration(ir::Expression *const name) + : Statement(AstNodeType::ETS_PACKAGE_DECLARATION), name_(name) { } + // NOLINTNEXTLINE(google-default-arguments) + [[nodiscard]] ETSPackageDeclaration *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; + void Dump(ir::AstDumper *dumper) const override; + void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; void Compile([[maybe_unused]] compiler::ETSGen *etsg) const override; checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; diff --git a/ets2panda/ir/ets/etsParameterExpression.cpp b/ets2panda/ir/ets/etsParameterExpression.cpp index bb0172b423fb8709b45b962774c37a9c49063fb6..3d00268107796fc5b6a597b7f68a6067443080a1 100644 --- a/ets2panda/ir/ets/etsParameterExpression.cpp +++ b/ets2panda/ir/ets/etsParameterExpression.cpp @@ -163,11 +163,11 @@ checker::Type *ETSParameterExpression::Check(checker::ETSChecker *const checker) } // NOLINTNEXTLINE(google-default-arguments) -Expression *ETSParameterExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) +ETSParameterExpression *ETSParameterExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { auto *const ident_or_spread = spread_ != nullptr ? spread_->Clone(allocator)->AsAnnotatedExpression() : ident_->Clone(allocator)->AsAnnotatedExpression(); - auto *const initializer = initializer_ != nullptr ? initializer_->Clone(allocator) : nullptr; + auto *const initializer = initializer_ != nullptr ? initializer_->Clone(allocator)->AsExpression() : nullptr; if (auto *const clone = allocator->New(ident_or_spread, initializer); clone != nullptr) { ident_or_spread->SetParent(clone); diff --git a/ets2panda/ir/ets/etsParameterExpression.h b/ets2panda/ir/ets/etsParameterExpression.h index 4ea4ed1e32ad11db3db905048e24868de9c89732..7786d77fc3080a6e8cbb0e956982ba3ae1423283 100644 --- a/ets2panda/ir/ets/etsParameterExpression.h +++ b/ets2panda/ir/ets/etsParameterExpression.h @@ -65,7 +65,7 @@ public: } // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ETSParameterExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void Iterate(const NodeTraverser &cb) const override; void TransformChildren(const NodeTransformer &cb) override; diff --git a/ets2panda/ir/ets/etsStructDeclaration.cpp b/ets2panda/ir/ets/etsStructDeclaration.cpp index 8bd7ed765a9957726b5a8c9f231372d41af095e9..14f7101ad09c6d056deac938079fd3ada3aa2508 100644 --- a/ets2panda/ir/ets/etsStructDeclaration.cpp +++ b/ets2panda/ir/ets/etsStructDeclaration.cpp @@ -68,4 +68,27 @@ checker::Type *ETSStructDeclaration::Check(checker::ETSChecker *checker) { return checker->GetAnalyzer()->Check(this); } + +// NOLINTNEXTLINE(google-default-arguments) +ETSStructDeclaration *ETSStructDeclaration::Clone(ArenaAllocator *const allocator, AstNode *const parent) +{ + auto *const def = def_ != nullptr ? def_->Clone(allocator, this)->AsClassDefinition() : nullptr; + + if (auto *const clone = allocator->New(def, allocator); clone != nullptr) { + for (auto *const decorator : decorators_) { + clone->AddDecorator(decorator->Clone(allocator, clone)); + } + + if (def != nullptr) { + def->SetParent(clone); + } + + if (parent != nullptr) { + clone->SetParent(parent); + } + return clone; + } + + throw Error(ErrorType::GENERIC, "", CLONE_ALLOCATION_ERROR); +} } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/ets/etsStructDeclaration.h b/ets2panda/ir/ets/etsStructDeclaration.h index 90a448f581dfdf1ad83d074484be39a8ffb47acb..2368350de75f494537b0767da3b728a9acd2e84f 100644 --- a/ets2panda/ir/ets/etsStructDeclaration.h +++ b/ets2panda/ir/ets/etsStructDeclaration.h @@ -21,22 +21,28 @@ namespace panda::es2panda::ir { class ETSStructDeclaration : public Statement { public: - explicit ETSStructDeclaration(ClassDefinition *def, ArenaAllocator *allocator) + ETSStructDeclaration() = delete; + ~ETSStructDeclaration() override = default; + + NO_COPY_SEMANTIC(ETSStructDeclaration); + NO_MOVE_SEMANTIC(ETSStructDeclaration); + + explicit ETSStructDeclaration(ClassDefinition *const def, ArenaAllocator *const allocator) : Statement(AstNodeType::STRUCT_DECLARATION), def_(def), decorators_(allocator->Adapter()) { } - ClassDefinition *Definition() + [[nodiscard]] ClassDefinition *Definition() noexcept { return def_; } - const ClassDefinition *Definition() const + [[nodiscard]] const ClassDefinition *Definition() const noexcept { return def_; } - const ArenaVector &Decorators() const + [[nodiscard]] const ArenaVector &Decorators() const noexcept { return decorators_; } @@ -46,14 +52,24 @@ public: decorators_ = std::move(decorators); } + void AddDecorator(Decorator *const decorator) + { + decorators_.emplace_back(decorator); + } + bool CanHaveDecorator([[maybe_unused]] bool in_ts) const override { return true; } + // NOLINTNEXTLINE(google-default-arguments) + [[nodiscard]] ETSStructDeclaration *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; + void Dump(ir::AstDumper *dumper) const override; + void Compile(compiler::PandaGen *pg) const override; void Compile(compiler::ETSGen *etsg) const override; diff --git a/ets2panda/ir/expression.cpp b/ets2panda/ir/expression.cpp index 6d117c469e9c17a316e203beb5ab5dbcd4c70df4..6415d5e1726f58ee8e492c07629383dc60bf3c87 100644 --- a/ets2panda/ir/expression.cpp +++ b/ets2panda/ir/expression.cpp @@ -21,7 +21,7 @@ namespace panda::es2panda::ir { void AnnotatedExpression::CloneTypeAnnotation(ArenaAllocator *const allocator) { if (auto *annotation = const_cast(TypeAnnotation()); annotation != nullptr) { - SetTsTypeAnnotation(annotation->Clone(allocator, this)->AsTypeNode()); + SetTsTypeAnnotation(annotation->Clone(allocator, this)); } } diff --git a/ets2panda/ir/expression.h b/ets2panda/ir/expression.h index 833fa1589022a98d75abb71694b7a8f4066b86fe..5b5479c3d62b939468e87b32b872f5c3b26cc9bd 100644 --- a/ets2panda/ir/expression.h +++ b/ets2panda/ir/expression.h @@ -97,14 +97,6 @@ public: return reinterpret_cast(this); } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] virtual Expression *Clone([[maybe_unused]] ArenaAllocator *const allocator, - [[maybe_unused]] AstNode *const parent = nullptr) - { - UNREACHABLE(); - return nullptr; - } - protected: explicit Expression(AstNodeType const type) : TypedAstNode(type) {} explicit Expression(AstNodeType const type, ModifierFlags const flags) : TypedAstNode(type, flags) {} diff --git a/ets2panda/ir/expressions/arrayExpression.cpp b/ets2panda/ir/expressions/arrayExpression.cpp index c3c36bef08d178a73a9bc23e6ce871535cb73f3e..6b46553a1db6a6056dc7b3861fd1441f719e0535 100644 --- a/ets2panda/ir/expressions/arrayExpression.cpp +++ b/ets2panda/ir/expressions/arrayExpression.cpp @@ -46,16 +46,16 @@ ArrayExpression::ArrayExpression([[maybe_unused]] Tag const tag, ArrayExpression optional_ = other.optional_; for (auto *element : other.elements_) { - elements_.emplace_back(element->Clone(allocator, this)); + elements_.emplace_back(element->Clone(allocator, this)->AsExpression()); } for (auto *decorator : other.decorators_) { - decorators_.emplace_back(decorator->Clone(allocator, this)->AsDecorator()); + decorators_.emplace_back(decorator->Clone(allocator, this)); } } // NOLINTNEXTLINE(google-default-arguments) -Expression *ArrayExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) +ArrayExpression *ArrayExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(Tag {}, *this, allocator); clone != nullptr) { if (parent != nullptr) { diff --git a/ets2panda/ir/expressions/arrayExpression.h b/ets2panda/ir/expressions/arrayExpression.h index 5848b480b54f641968a51e5abaddad04fa2a09ed..bbe3c830fd3821c261f45761942007d95714d70e 100644 --- a/ets2panda/ir/expressions/arrayExpression.h +++ b/ets2panda/ir/expressions/arrayExpression.h @@ -99,7 +99,7 @@ public: } // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ArrayExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; [[nodiscard]] bool ConvertibleToArrayPattern(); [[nodiscard]] ValidationInfo ValidateExpression(); diff --git a/ets2panda/ir/expressions/arrowFunctionExpression.cpp b/ets2panda/ir/expressions/arrowFunctionExpression.cpp index 0cb1b3b65fda36d2382bd984c471d1ff3110e718..c07a110c37a3952c267fa4028396b2a7cf2ff257 100644 --- a/ets2panda/ir/expressions/arrowFunctionExpression.cpp +++ b/ets2panda/ir/expressions/arrowFunctionExpression.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021 - 2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.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,4 +61,33 @@ checker::Type *ArrowFunctionExpression::Check(checker::ETSChecker *checker) { return checker->GetAnalyzer()->Check(this); } + +ArrowFunctionExpression::ArrowFunctionExpression(ArrowFunctionExpression const &other, ArenaAllocator *const allocator) + : Expression(static_cast(other)), + captured_vars_(allocator->Adapter()), + propagate_this_(other.propagate_this_) +{ + func_ = other.func_->Clone(allocator, this)->AsScriptFunction(); + + for (auto *const variable : other.captured_vars_) { + captured_vars_.emplace_back(variable); + } + + if (other.resolved_lambda_ != nullptr) { + resolved_lambda_ = other.resolved_lambda_->Clone(allocator, this)->AsClassDefinition(); + } +} + +// NOLINTNEXTLINE(google-default-arguments) +ArrowFunctionExpression *ArrowFunctionExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) +{ + if (auto *const clone = allocator->New(*this, allocator); clone != nullptr) { + if (parent != nullptr) { + clone->SetParent(parent); + } + return clone; + } + + throw Error(ErrorType::GENERIC, "", CLONE_ALLOCATION_ERROR); +} } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/expressions/arrowFunctionExpression.h b/ets2panda/ir/expressions/arrowFunctionExpression.h index 2d78a104125f5e3f2f1d7ff3e10f53e32ae864f9..0cc830afadcb529bd436b6ec84c39eb381f6bd05 100644 --- a/ets2panda/ir/expressions/arrowFunctionExpression.h +++ b/ets2panda/ir/expressions/arrowFunctionExpression.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021 - 2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.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,53 +27,65 @@ class ScriptFunction; class ArrowFunctionExpression : public Expression { public: - explicit ArrowFunctionExpression(ArenaAllocator *allocator, ScriptFunction *func) + ArrowFunctionExpression() = delete; + ~ArrowFunctionExpression() override = default; + + NO_COPY_SEMANTIC(ArrowFunctionExpression); + NO_MOVE_SEMANTIC(ArrowFunctionExpression); + + explicit ArrowFunctionExpression(ArenaAllocator *const allocator, ScriptFunction *const func) : Expression(AstNodeType::ARROW_FUNCTION_EXPRESSION), func_(func), captured_vars_(allocator->Adapter()) { } + + explicit ArrowFunctionExpression(ArrowFunctionExpression const &other, ArenaAllocator *allocator); + // NOTE (csabahurton): friend relationship can be removed once there are getters for private fields friend class compiler::ETSCompiler; - const ScriptFunction *Function() const + [[nodiscard]] const ScriptFunction *Function() const noexcept { return func_; } - ScriptFunction *Function() + [[nodiscard]] ScriptFunction *Function() noexcept { return func_; } - const ClassDefinition *ResolvedLambda() const + [[nodiscard]] const ClassDefinition *ResolvedLambda() const noexcept { return resolved_lambda_; } - ClassDefinition *ResolvedLambda() + [[nodiscard]] ClassDefinition *ResolvedLambda() noexcept { return resolved_lambda_; } - ArenaVector &CapturedVars() + [[nodiscard]] ArenaVector &CapturedVars() noexcept { return captured_vars_; } - const ArenaVector &CapturedVars() const + [[nodiscard]] const ArenaVector &CapturedVars() const noexcept { return captured_vars_; } - void SetResolvedLambda(ClassDefinition *lambda) + void SetResolvedLambda(ClassDefinition *const lambda) noexcept { resolved_lambda_ = lambda; } - void SetPropagateThis() + void SetPropagateThis() noexcept { propagate_this_ = true; } + // NOLINTNEXTLINE(google-default-arguments) + [[nodiscard]] ArrowFunctionExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; diff --git a/ets2panda/ir/expressions/assignmentExpression.cpp b/ets2panda/ir/expressions/assignmentExpression.cpp index a6ba7d6ee0528ee4b948d9be668fe3a275f21027..4c3d14510fcfa13de7075c78b778596fc9d5fa17 100644 --- a/ets2panda/ir/expressions/assignmentExpression.cpp +++ b/ets2panda/ir/expressions/assignmentExpression.cpp @@ -322,10 +322,10 @@ AssignmentExpression::AssignmentExpression([[maybe_unused]] Tag const tag, Assig } // NOLINTNEXTLINE(google-default-arguments) -Expression *AssignmentExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) +AssignmentExpression *AssignmentExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const left = left_ != nullptr ? left_->Clone(allocator) : nullptr; - auto *const right = right_ != nullptr ? right_->Clone(allocator) : nullptr; + auto *const left = left_ != nullptr ? left_->Clone(allocator)->AsExpression() : nullptr; + auto *const right = right_ != nullptr ? right_->Clone(allocator)->AsExpression() : nullptr; if (auto *const clone = allocator->New(Tag {}, *this, left, right); clone != nullptr) { if (parent != nullptr) { diff --git a/ets2panda/ir/expressions/assignmentExpression.h b/ets2panda/ir/expressions/assignmentExpression.h index 5f14a1c1cff1321beae8fb22326bc89d9c25353a..bebc40be2a0bd06dea49ac23f2057a4a317de1b1 100644 --- a/ets2panda/ir/expressions/assignmentExpression.h +++ b/ets2panda/ir/expressions/assignmentExpression.h @@ -108,7 +108,7 @@ public: } // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] AssignmentExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; [[nodiscard]] bool ConvertibleToAssignmentPattern(bool must_be_pattern = true); diff --git a/ets2panda/ir/expressions/awaitExpression.cpp b/ets2panda/ir/expressions/awaitExpression.cpp index 636a7e5bc25ab705db10bbefabee403e2d0fc139..f14a8676b0d929a0730876fc5657105e7799fc28 100644 --- a/ets2panda/ir/expressions/awaitExpression.cpp +++ b/ets2panda/ir/expressions/awaitExpression.cpp @@ -94,9 +94,9 @@ checker::Type *AwaitExpression::Check(checker::ETSChecker *checker) } // NOLINTNEXTLINE(google-default-arguments) -Expression *AwaitExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) +AwaitExpression *AwaitExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const argument = argument_ != nullptr ? argument_->Clone(allocator) : nullptr; + auto *const argument = argument_ != nullptr ? argument_->Clone(allocator)->AsExpression() : nullptr; if (auto *const clone = allocator->New(argument); clone != nullptr) { if (argument != nullptr) { diff --git a/ets2panda/ir/expressions/awaitExpression.h b/ets2panda/ir/expressions/awaitExpression.h index 17240df98c3efcdf6ca7e22e01545aa4a293e8f9..e90a808132361bcd20138be0d00f8811210a6c12 100644 --- a/ets2panda/ir/expressions/awaitExpression.h +++ b/ets2panda/ir/expressions/awaitExpression.h @@ -35,7 +35,7 @@ public: } // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] AwaitExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/binaryExpression.cpp b/ets2panda/ir/expressions/binaryExpression.cpp index 440afa17f2d760db3d417e9bc88304214c0a7f85..641dfd9d0e5de569bfab0a889068b5d46856bbf0 100644 --- a/ets2panda/ir/expressions/binaryExpression.cpp +++ b/ets2panda/ir/expressions/binaryExpression.cpp @@ -296,10 +296,10 @@ checker::Type *BinaryExpression::Check(checker::ETSChecker *checker) } // NOLINTNEXTLINE(google-default-arguments) -Expression *BinaryExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) +BinaryExpression *BinaryExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const left = left_ != nullptr ? left_->Clone(allocator) : nullptr; - auto *const right = right_ != nullptr ? right_->Clone(allocator) : nullptr; + auto *const left = left_ != nullptr ? left_->Clone(allocator)->AsExpression() : nullptr; + auto *const right = right_ != nullptr ? right_->Clone(allocator)->AsExpression() : nullptr; if (auto *const clone = allocator->New(left, right, operator_); clone != nullptr) { if (operation_type_ != nullptr) { diff --git a/ets2panda/ir/expressions/binaryExpression.h b/ets2panda/ir/expressions/binaryExpression.h index c2a1a47bbbc2943a56b1b2822cfa2227ecd71963..b2eb6bf8232c993603fc175db85d517c26680d7c 100644 --- a/ets2panda/ir/expressions/binaryExpression.h +++ b/ets2panda/ir/expressions/binaryExpression.h @@ -113,7 +113,7 @@ public: } // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] BinaryExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/callExpression.cpp b/ets2panda/ir/expressions/callExpression.cpp index b74f16794da9ce5f8877d48db9208e8a2afb4f3b..ef2e51225fb0f2ae5c3951fdd886dd392ccd2c35 100644 --- a/ets2panda/ir/expressions/callExpression.cpp +++ b/ets2panda/ir/expressions/callExpression.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021 - 2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -533,4 +533,36 @@ checker::Type *CallExpression::InitAnonymousLambdaCallee(checker::ETSChecker *ch checker->Relation()->IsAssignableTo(callee_type, func_iface); return func_iface; } + +CallExpression::CallExpression(CallExpression const &other, ArenaAllocator *const allocator) + : MaybeOptionalExpression(static_cast(other)), + arguments_(allocator->Adapter()), + signature_(other.signature_), + trailing_comma_(other.trailing_comma_), + is_trailing_block_in_new_line_(other.is_trailing_block_in_new_line_) +{ + callee_ = other.callee_->Clone(allocator, this)->AsExpression(); + type_params_ = other.type_params_->Clone(allocator, this); + + for (auto *const argument : other.arguments_) { + arguments_.emplace_back(argument->Clone(allocator, this)->AsExpression()); + } + + if (other.trailing_block_ != nullptr) { + trailing_block_ = other.trailing_block_->Clone(allocator, this)->AsBlockStatement(); + } +} + +// NOLINTNEXTLINE(google-default-arguments) +CallExpression *CallExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) +{ + if (auto *const clone = allocator->New(*this, allocator); clone != nullptr) { + if (parent != nullptr) { + clone->SetParent(parent); + } + return clone; + } + + throw Error(ErrorType::GENERIC, "", CLONE_ALLOCATION_ERROR); +} } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/expressions/callExpression.h b/ets2panda/ir/expressions/callExpression.h index d68ca9daca725252c798de103c0eac2180193eca..a89e9b45da40e927b207da09ae115f8a76808756 100644 --- a/ets2panda/ir/expressions/callExpression.h +++ b/ets2panda/ir/expressions/callExpression.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021 - 2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -29,8 +29,15 @@ class TSTypeParameterInstantiation; class CallExpression : public MaybeOptionalExpression { public: - explicit CallExpression(Expression *callee, ArenaVector &&arguments, - TSTypeParameterInstantiation *type_params, bool optional, bool trailing_comma = false) + CallExpression() = delete; + ~CallExpression() override = default; + + NO_COPY_SEMANTIC(CallExpression); + NO_MOVE_SEMANTIC(CallExpression); + + explicit CallExpression(Expression *const callee, ArenaVector &&arguments, + TSTypeParameterInstantiation *const type_params, bool const optional, + bool const trailing_comma = false) : MaybeOptionalExpression(AstNodeType::CALL_EXPRESSION, optional), callee_(callee), arguments_(std::move(arguments)), @@ -39,93 +46,101 @@ public: { } - const Expression *Callee() const + explicit CallExpression(CallExpression const &other, ArenaAllocator *allocator); + + [[nodiscard]] const Expression *Callee() const noexcept { return callee_; } - Expression *Callee() + [[nodiscard]] Expression *Callee() noexcept { return callee_; } - void SetCallee(Expression *callee) + void SetCallee(Expression *callee) noexcept { callee_ = callee; } - const TSTypeParameterInstantiation *TypeParams() const + [[nodiscard]] const TSTypeParameterInstantiation *TypeParams() const noexcept { return type_params_; } - TSTypeParameterInstantiation *TypeParams() + [[nodiscard]] TSTypeParameterInstantiation *TypeParams() noexcept { return type_params_; } - const ArenaVector &Arguments() const + [[nodiscard]] const ArenaVector &Arguments() const noexcept { return arguments_; } - ArenaVector &Arguments() + [[nodiscard]] ArenaVector &Arguments() noexcept { return arguments_; } - bool HasTrailingComma() const + [[nodiscard]] bool HasTrailingComma() const noexcept { return trailing_comma_; } - checker::Signature *Signature() + [[nodiscard]] checker::Signature *Signature() noexcept { return signature_; } - checker::Signature *Signature() const + [[nodiscard]] checker::Signature *Signature() const noexcept { return signature_; } - void SetSignature(checker::Signature *signature) + void SetSignature(checker::Signature *const signature) noexcept { signature_ = signature; } - void SetTypeParams(TSTypeParameterInstantiation *type_params) + void SetTypeParams(TSTypeParameterInstantiation *const type_params) noexcept { type_params_ = type_params; } - void SetTrailingBlock(ir::BlockStatement *block) + void SetTrailingBlock(ir::BlockStatement *const block) noexcept { trailing_block_ = block; } - ir::BlockStatement *TrailingBlock() const + [[nodiscard]] ir::BlockStatement *TrailingBlock() const noexcept { return trailing_block_; } - void SetIsTrailingBlockInNewLine(bool is_new_line) + void SetIsTrailingBlockInNewLine(bool const is_new_line) noexcept { is_trailing_block_in_new_line_ = is_new_line; } - bool IsTrailingBlockInNewLine() const + [[nodiscard]] bool IsTrailingBlockInNewLine() const noexcept { return is_trailing_block_in_new_line_; } + // NOLINTNEXTLINE(google-default-arguments) + [[nodiscard]] CallExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; + void Dump(ir::AstDumper *dumper) const override; + void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; void Compile([[maybe_unused]] compiler::ETSGen *etsg) const override; checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + checker::Signature *ResolveCallExtensionFunction(checker::ETSFunctionType *function_type, checker::ETSChecker *checker); checker::Signature *ResolveCallForETSExtensionFuncHelperType(checker::ETSExtensionFuncHelperType *type, diff --git a/ets2panda/ir/expressions/chainExpression.cpp b/ets2panda/ir/expressions/chainExpression.cpp index ce71eac838816b664bcb6cbfc04018e05cfb1b23..40de7dc72155f04c764f9fd3c80ae1ffb53ba65c 100644 --- a/ets2panda/ir/expressions/chainExpression.cpp +++ b/ets2panda/ir/expressions/chainExpression.cpp @@ -68,9 +68,9 @@ checker::Type *ChainExpression::Check([[maybe_unused]] checker::ETSChecker *chec } // NOLINTNEXTLINE(google-default-arguments) -Expression *ChainExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) +ChainExpression *ChainExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const expression = expression_ != nullptr ? expression_->Clone(allocator) : nullptr; + auto *const expression = expression_ != nullptr ? expression_->Clone(allocator)->AsExpression() : nullptr; if (auto *const clone = allocator->New(expression); clone != nullptr) { if (expression != nullptr) { diff --git a/ets2panda/ir/expressions/chainExpression.h b/ets2panda/ir/expressions/chainExpression.h index 252ece9500b899c32839e359942a82ab5d196360..03eafe1ac9adb50618247608cfda84c986748bd0 100644 --- a/ets2panda/ir/expressions/chainExpression.h +++ b/ets2panda/ir/expressions/chainExpression.h @@ -39,7 +39,7 @@ public: } // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ChainExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/classExpression.cpp b/ets2panda/ir/expressions/classExpression.cpp index ecefc3a8faa98819a7af97b4a76a6d32be7280c2..e8f268a97177891fa0dab39888c3fe8765e4c961 100644 --- a/ets2panda/ir/expressions/classExpression.cpp +++ b/ets2panda/ir/expressions/classExpression.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.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,4 +48,22 @@ checker::Type *ClassExpression::Check([[maybe_unused]] checker::ETSChecker *chec { return nullptr; } + +// NOLINTNEXTLINE(google-default-arguments) +ClassExpression *ClassExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) +{ + auto *const def = def_ != nullptr ? def_->Clone(allocator)->AsClassDefinition() : nullptr; + + if (auto *const clone = allocator->New(def); clone != nullptr) { + if (parent != nullptr) { + clone->SetParent(parent); + } + if (def != nullptr) { + def->SetParent(clone); + } + return clone; + } + + throw Error(ErrorType::GENERIC, "", CLONE_ALLOCATION_ERROR); +} } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/expressions/classExpression.h b/ets2panda/ir/expressions/classExpression.h index 1ab8e4a09cef41e69b7982dadee50bf1f4d269bb..df7b06021f8e04bae0e0384312f2a81fcf68440c 100644 --- a/ets2panda/ir/expressions/classExpression.h +++ b/ets2panda/ir/expressions/classExpression.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021 - 2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.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,17 +23,28 @@ class ClassDefinition; class ClassExpression : public Expression { public: - explicit ClassExpression(ClassDefinition *def) : Expression(AstNodeType::CLASS_EXPRESSION), def_(def) {} + ClassExpression() = delete; + ~ClassExpression() override = default; - const ClassDefinition *Definition() const + NO_COPY_SEMANTIC(ClassExpression); + NO_MOVE_SEMANTIC(ClassExpression); + + explicit ClassExpression(ClassDefinition *const def) : Expression(AstNodeType::CLASS_EXPRESSION), def_(def) {} + + [[nodiscard]] const ClassDefinition *Definition() const noexcept { return def_; } + // NOLINTNEXTLINE(google-default-arguments) + [[nodiscard]] ClassExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; + void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; + checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; diff --git a/ets2panda/ir/expressions/conditionalExpression.cpp b/ets2panda/ir/expressions/conditionalExpression.cpp index b60d48679a534d877a6043bcf2a4da23c1f8b8d2..2d8a66e5a5d736f246883281493ceab19a15cb2a 100644 --- a/ets2panda/ir/expressions/conditionalExpression.cpp +++ b/ets2panda/ir/expressions/conditionalExpression.cpp @@ -150,11 +150,11 @@ checker::Type *ConditionalExpression::Check(checker::ETSChecker *checker) } // NOLINTNEXTLINE(google-default-arguments) -Expression *ConditionalExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) +ConditionalExpression *ConditionalExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const test = test_ != nullptr ? test_->Clone(allocator) : nullptr; - auto *const consequent = consequent_ != nullptr ? consequent_->Clone(allocator) : nullptr; - auto *const alternate = alternate_ != nullptr ? alternate_->Clone(allocator) : nullptr; + auto *const test = test_ != nullptr ? test_->Clone(allocator)->AsExpression() : nullptr; + auto *const consequent = consequent_ != nullptr ? consequent_->Clone(allocator)->AsExpression() : nullptr; + auto *const alternate = alternate_ != nullptr ? alternate_->Clone(allocator)->AsExpression() : nullptr; if (auto *const clone = allocator->New(test, consequent, alternate); clone != nullptr) { if (test != nullptr) { diff --git a/ets2panda/ir/expressions/conditionalExpression.h b/ets2panda/ir/expressions/conditionalExpression.h index 8e0e7a10d8f05320189fb05223dedd18f2d73dea..6ee5774d7be93d42754b66b1f8ae3965bd9e93b1 100644 --- a/ets2panda/ir/expressions/conditionalExpression.h +++ b/ets2panda/ir/expressions/conditionalExpression.h @@ -58,7 +58,7 @@ public: } // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ConditionalExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/functionExpression.cpp b/ets2panda/ir/expressions/functionExpression.cpp index 7f9c194231c0aed7c6c2b7a3d46b99df5c074fff..4620b5a322a02c5c8749e700dce2fd8adecf084f 100644 --- a/ets2panda/ir/expressions/functionExpression.cpp +++ b/ets2panda/ir/expressions/functionExpression.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021 - 2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.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,4 +82,20 @@ checker::Type *FunctionExpression::Check([[maybe_unused]] checker::ETSChecker *c { return nullptr; } + +// NOLINTNEXTLINE(google-default-arguments) +FunctionExpression *FunctionExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) +{ + auto *const func = func_->Clone(allocator)->AsScriptFunction(); + + if (auto *const clone = allocator->New(func); clone != nullptr) { + func->SetParent(clone); + if (parent != nullptr) { + clone->SetParent(parent); + } + return clone; + } + + throw Error(ErrorType::GENERIC, "", CLONE_ALLOCATION_ERROR); +} } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/expressions/functionExpression.h b/ets2panda/ir/expressions/functionExpression.h index 4b2191857876d40e841c41400d5ce63f5f3de283..a5565fcf499a32db19f9737269c7730597af9a62 100644 --- a/ets2panda/ir/expressions/functionExpression.h +++ b/ets2panda/ir/expressions/functionExpression.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.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,23 +23,37 @@ class ScriptFunction; class FunctionExpression : public Expression { public: - explicit FunctionExpression(ScriptFunction *func) : Expression(AstNodeType::FUNCTION_EXPRESSION), func_(func) {} + FunctionExpression() = delete; + ~FunctionExpression() override = default; - const ScriptFunction *Function() const + NO_COPY_SEMANTIC(FunctionExpression); + NO_MOVE_SEMANTIC(FunctionExpression); + + explicit FunctionExpression(ScriptFunction *const func) : Expression(AstNodeType::FUNCTION_EXPRESSION), func_(func) + { + } + + [[nodiscard]] const ScriptFunction *Function() const noexcept { return func_; } - ScriptFunction *Function() + [[nodiscard]] ScriptFunction *Function() noexcept { return func_; } + // NOLINTNEXTLINE(google-default-arguments) + [[nodiscard]] FunctionExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; + void Dump(ir::AstDumper *dumper) const override; + void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; diff --git a/ets2panda/ir/expressions/identifier.cpp b/ets2panda/ir/expressions/identifier.cpp index e1f2b3cd2a574197000bf42a07baec92d04bfec7..1ff485d89490f0b56436f3e1936399fd242f3099 100644 --- a/ets2panda/ir/expressions/identifier.cpp +++ b/ets2panda/ir/expressions/identifier.cpp @@ -35,12 +35,12 @@ Identifier::Identifier([[maybe_unused]] Tag const tag, Identifier const &other, variable_ = other.variable_; for (auto *decorator : other.decorators_) { - decorators_.emplace_back(decorator->Clone(allocator, this)->AsDecorator()); + decorators_.emplace_back(decorator->Clone(allocator, this)); } } // NOLINTNEXTLINE(google-default-arguments) -Expression *Identifier::Clone(ArenaAllocator *const allocator, AstNode *const parent) +Identifier *Identifier::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(Tag {}, *this, allocator); clone != nullptr) { if (parent != nullptr) { diff --git a/ets2panda/ir/expressions/identifier.h b/ets2panda/ir/expressions/identifier.h index a6ee3dd78ef7aaa4e9400a3bb702c9cd6a3ddc0b..5cfa53c9c227544e6c4d8fe7a85d844206f5cae7 100644 --- a/ets2panda/ir/expressions/identifier.h +++ b/ets2panda/ir/expressions/identifier.h @@ -186,7 +186,7 @@ public: } // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] Identifier *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; [[nodiscard]] ValidationInfo ValidateExpression(); diff --git a/ets2panda/ir/expressions/importExpression.cpp b/ets2panda/ir/expressions/importExpression.cpp index e812123c13e5fbc49ccd6910fa2868d0bbde7c13..d9b39dcd391d6028b91e9e4243710f49e5bce488 100644 --- a/ets2panda/ir/expressions/importExpression.cpp +++ b/ets2panda/ir/expressions/importExpression.cpp @@ -50,9 +50,9 @@ checker::Type *ImportExpression::Check([[maybe_unused]] checker::ETSChecker *che } // NOLINTNEXTLINE(google-default-arguments) -Expression *ImportExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) +ImportExpression *ImportExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const source = source_ != nullptr ? source_->Clone(allocator) : nullptr; + auto *const source = source_ != nullptr ? source_->Clone(allocator)->AsExpression() : nullptr; if (auto *const clone = allocator->New(source); clone != nullptr) { if (source != nullptr) { diff --git a/ets2panda/ir/expressions/importExpression.h b/ets2panda/ir/expressions/importExpression.h index d275dd9a9a4e87384f2455bf2f8a0fa934ec7ca4..884e3dbc294eb82c14fe0166cbe67d9f667af18c 100644 --- a/ets2panda/ir/expressions/importExpression.h +++ b/ets2panda/ir/expressions/importExpression.h @@ -30,7 +30,7 @@ public: explicit ImportExpression(Expression *source) : Expression(AstNodeType::IMPORT_EXPRESSION), source_(source) {} // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ImportExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/literals/bigIntLiteral.cpp b/ets2panda/ir/expressions/literals/bigIntLiteral.cpp index b59d2f83c9ae771c68c70ca915af97c031505b6d..5887c20cd73cb0fc8aebd1a34de9e631d1e5d146 100644 --- a/ets2panda/ir/expressions/literals/bigIntLiteral.cpp +++ b/ets2panda/ir/expressions/literals/bigIntLiteral.cpp @@ -51,7 +51,7 @@ checker::Type *BigIntLiteral::Check([[maybe_unused]] checker::ETSChecker *checke } // NOLINTNEXTLINE(google-default-arguments) -Expression *BigIntLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) +BigIntLiteral *BigIntLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(src_); clone != nullptr) { if (parent != nullptr) { diff --git a/ets2panda/ir/expressions/literals/bigIntLiteral.h b/ets2panda/ir/expressions/literals/bigIntLiteral.h index a017c4912ac80e3d975aa02b7b965edbae1793a1..32d4c40d30351f22165c52ebadbaa4c55e770d4e 100644 --- a/ets2panda/ir/expressions/literals/bigIntLiteral.h +++ b/ets2panda/ir/expressions/literals/bigIntLiteral.h @@ -36,7 +36,7 @@ public: } // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] BigIntLiteral *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/literals/booleanLiteral.cpp b/ets2panda/ir/expressions/literals/booleanLiteral.cpp index 81fc1cb14718f2c6e99534c32beca2b02f6e38fb..d73eed1c05f8c58868b7de42bc5e2e452b273e1e 100644 --- a/ets2panda/ir/expressions/literals/booleanLiteral.cpp +++ b/ets2panda/ir/expressions/literals/booleanLiteral.cpp @@ -54,7 +54,7 @@ checker::Type *BooleanLiteral::Check([[maybe_unused]] checker::ETSChecker *check } // NOLINTNEXTLINE(google-default-arguments) -Expression *BooleanLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) +BooleanLiteral *BooleanLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(boolean_); clone != nullptr) { if (parent != nullptr) { diff --git a/ets2panda/ir/expressions/literals/booleanLiteral.h b/ets2panda/ir/expressions/literals/booleanLiteral.h index 8643f5b573c262cff61edab9c12c9e406e5c1fb7..e2a69e617e72b01de88b1323c0ae24dea309540c 100644 --- a/ets2panda/ir/expressions/literals/booleanLiteral.h +++ b/ets2panda/ir/expressions/literals/booleanLiteral.h @@ -35,7 +35,7 @@ public: } // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] BooleanLiteral *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/literals/charLiteral.cpp b/ets2panda/ir/expressions/literals/charLiteral.cpp index 6596de257711f061e06f4395377b7ac1fea59ac0..4f333ee45fda52941941b61b3ec75a9600bee506 100644 --- a/ets2panda/ir/expressions/literals/charLiteral.cpp +++ b/ets2panda/ir/expressions/literals/charLiteral.cpp @@ -52,7 +52,7 @@ checker::Type *CharLiteral::Check([[maybe_unused]] checker::ETSChecker *checker) } // NOLINTNEXTLINE(google-default-arguments) -Expression *CharLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) +CharLiteral *CharLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(char_); clone != nullptr) { if (parent != nullptr) { diff --git a/ets2panda/ir/expressions/literals/charLiteral.h b/ets2panda/ir/expressions/literals/charLiteral.h index 048d73884fd2e5dad47d59ef47e11306d7af5867..f1bf1e8f105e8268c35cb28b040c8fe46dadc36d 100644 --- a/ets2panda/ir/expressions/literals/charLiteral.h +++ b/ets2panda/ir/expressions/literals/charLiteral.h @@ -41,7 +41,7 @@ public: } // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] CharLiteral *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/literals/nullLiteral.cpp b/ets2panda/ir/expressions/literals/nullLiteral.cpp index 10868ce8325bb18e32378cdc0cce05e2578a7ede..8074c1471e6a677de01031effed60f629ab2d550 100644 --- a/ets2panda/ir/expressions/literals/nullLiteral.cpp +++ b/ets2panda/ir/expressions/literals/nullLiteral.cpp @@ -54,7 +54,7 @@ checker::Type *NullLiteral::Check([[maybe_unused]] checker::ETSChecker *checker) } // NOLINTNEXTLINE(google-default-arguments) -Expression *NullLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) +NullLiteral *NullLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(); clone != nullptr) { if (parent != nullptr) { diff --git a/ets2panda/ir/expressions/literals/nullLiteral.h b/ets2panda/ir/expressions/literals/nullLiteral.h index 1fa60a74f0fa783d1d44d8106f99a51ea01d32c5..a89a07b58b8277bf8b5f9b86b48802926ddf9f51 100644 --- a/ets2panda/ir/expressions/literals/nullLiteral.h +++ b/ets2panda/ir/expressions/literals/nullLiteral.h @@ -29,7 +29,7 @@ public: explicit NullLiteral() : Literal(AstNodeType::NULL_LITERAL) {} // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] NullLiteral *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/literals/numberLiteral.cpp b/ets2panda/ir/expressions/literals/numberLiteral.cpp index d411de92385590e1760a15ad0e1145ef357cb244..c2e40f432010a1c30e5575341e292aad297eed5b 100644 --- a/ets2panda/ir/expressions/literals/numberLiteral.cpp +++ b/ets2panda/ir/expressions/literals/numberLiteral.cpp @@ -111,7 +111,7 @@ checker::Type *NumberLiteral::Check([[maybe_unused]] checker::ETSChecker *checke } // NOLINTNEXTLINE(google-default-arguments) -Expression *NumberLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) +NumberLiteral *NumberLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(number_); clone != nullptr) { if (parent != nullptr) { diff --git a/ets2panda/ir/expressions/literals/numberLiteral.h b/ets2panda/ir/expressions/literals/numberLiteral.h index e7391b8e40398b77f86ecd401c3e64d6517acdfa..da244592eed4f5cbe947cd1e6721f3972e4c840b 100644 --- a/ets2panda/ir/expressions/literals/numberLiteral.h +++ b/ets2panda/ir/expressions/literals/numberLiteral.h @@ -50,7 +50,7 @@ public: [[nodiscard]] bool HasFloatingPoint() const; // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] NumberLiteral *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/literals/regExpLiteral.cpp b/ets2panda/ir/expressions/literals/regExpLiteral.cpp index d278513f9fe09ca26e43472a2f48dc2ec46a2fbd..6409bc62edacec50c4ba1fd74863c4b5bf010b5f 100644 --- a/ets2panda/ir/expressions/literals/regExpLiteral.cpp +++ b/ets2panda/ir/expressions/literals/regExpLiteral.cpp @@ -46,7 +46,7 @@ checker::Type *RegExpLiteral::Check([[maybe_unused]] checker::ETSChecker *checke } // NOLINTNEXTLINE(google-default-arguments) -Expression *RegExpLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) +RegExpLiteral *RegExpLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(pattern_, flags_, flags_str_); clone != nullptr) { if (parent != nullptr) { diff --git a/ets2panda/ir/expressions/literals/regExpLiteral.h b/ets2panda/ir/expressions/literals/regExpLiteral.h index 8ee1c453e535964d0a1c483a91f7f276a99d7e85..8eff4811abbea4e4ffe715d7e56fceb354138b23 100644 --- a/ets2panda/ir/expressions/literals/regExpLiteral.h +++ b/ets2panda/ir/expressions/literals/regExpLiteral.h @@ -45,7 +45,7 @@ public: } // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] RegExpLiteral *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/literals/stringLiteral.cpp b/ets2panda/ir/expressions/literals/stringLiteral.cpp index 2c45cb252ecda5adb8c4d5b410bef4345cf508af..f07aa1b456a9df11616ec85eec27c4ae7c6ad9df 100644 --- a/ets2panda/ir/expressions/literals/stringLiteral.cpp +++ b/ets2panda/ir/expressions/literals/stringLiteral.cpp @@ -63,7 +63,7 @@ checker::Type *StringLiteral::Check([[maybe_unused]] checker::ETSChecker *checke } // NOLINTNEXTLINE(google-default-arguments) -Expression *StringLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) +StringLiteral *StringLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(str_); clone != nullptr) { if (parent != nullptr) { diff --git a/ets2panda/ir/expressions/literals/stringLiteral.h b/ets2panda/ir/expressions/literals/stringLiteral.h index da7f22fdadbab4187e7988f6e37c7e7fcf8041fb..9efadad219105cca701395f2fe46b6b677feda1b 100644 --- a/ets2panda/ir/expressions/literals/stringLiteral.h +++ b/ets2panda/ir/expressions/literals/stringLiteral.h @@ -42,7 +42,7 @@ public: } // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] StringLiteral *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/memberExpression.cpp b/ets2panda/ir/expressions/memberExpression.cpp index 44936411def8039ca48d27983c70f5b50f85269e..253697f0753fde1ce2262cc81bc23de8b6e62b3d 100644 --- a/ets2panda/ir/expressions/memberExpression.cpp +++ b/ets2panda/ir/expressions/memberExpression.cpp @@ -469,10 +469,10 @@ checker::Type *MemberExpression::Check(checker::ETSChecker *checker) } // NOLINTNEXTLINE(google-default-arguments) -Expression *MemberExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) +MemberExpression *MemberExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const object = object_ != nullptr ? object_->Clone(allocator) : nullptr; - auto *const property = property_ != nullptr ? property_->Clone(allocator) : nullptr; + auto *const object = object_ != nullptr ? object_->Clone(allocator)->AsExpression() : nullptr; + auto *const property = property_ != nullptr ? property_->Clone(allocator)->AsExpression() : nullptr; if (auto *const clone = allocator->New(Tag {}, object, property); clone != nullptr) { if (parent != nullptr) { diff --git a/ets2panda/ir/expressions/memberExpression.h b/ets2panda/ir/expressions/memberExpression.h index 47c172e843045b4e1361a60898a1fbd5630f39b7..a47b12398f7e16830461689ede1e75a10a3d7d86 100644 --- a/ets2panda/ir/expressions/memberExpression.h +++ b/ets2panda/ir/expressions/memberExpression.h @@ -142,7 +142,7 @@ public: [[nodiscard]] bool IsPrivateReference() const noexcept; // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] MemberExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/newExpression.cpp b/ets2panda/ir/expressions/newExpression.cpp index 565ba8caa42aac382506643a66d32de7706a6e23..ada998946446ca1934c1292feb440c4929caadf4 100644 --- a/ets2panda/ir/expressions/newExpression.cpp +++ b/ets2panda/ir/expressions/newExpression.cpp @@ -28,16 +28,16 @@ NewExpression::NewExpression([[maybe_unused]] Tag const tag, NewExpression const : Expression(static_cast(other)), arguments_(allocator->Adapter()) { if (other.callee_ != nullptr) { - callee_ = other.callee_->Clone(allocator, this); + callee_ = other.callee_->Clone(allocator, this)->AsExpression(); } for (auto *argument : other.arguments_) { - arguments_.emplace_back(argument->Clone(allocator, this)); + arguments_.emplace_back(argument->Clone(allocator, this)->AsExpression()); } } // NOLINTNEXTLINE(google-default-arguments) -Expression *NewExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) +NewExpression *NewExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(Tag {}, *this, allocator); clone != nullptr) { if (parent != nullptr) { diff --git a/ets2panda/ir/expressions/newExpression.h b/ets2panda/ir/expressions/newExpression.h index 2cefd3ce6d746341f26e6e2d26aca857bb0219c0..6fc447c38150639e107c1602e038233d3b586182 100644 --- a/ets2panda/ir/expressions/newExpression.h +++ b/ets2panda/ir/expressions/newExpression.h @@ -48,7 +48,7 @@ public: } // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] NewExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/objectExpression.cpp b/ets2panda/ir/expressions/objectExpression.cpp index f3b4b4ebff09da14eb37d8fd2e2cedca2209ae1e..c5e6218895dade1202d23708083679ab2fe8fb6d 100644 --- a/ets2panda/ir/expressions/objectExpression.cpp +++ b/ets2panda/ir/expressions/objectExpression.cpp @@ -58,16 +58,16 @@ ObjectExpression::ObjectExpression([[maybe_unused]] Tag const tag, ObjectExpress optional_ = other.optional_; for (auto *property : other.properties_) { - properties_.emplace_back(property->Clone(allocator, this)); + properties_.emplace_back(property->Clone(allocator, this)->AsExpression()); } for (auto *decorator : other.decorators_) { - decorators_.emplace_back(decorator->Clone(allocator, this)->AsDecorator()); + decorators_.emplace_back(decorator->Clone(allocator, this)); } } // NOLINTNEXTLINE(google-default-arguments) -Expression *ObjectExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) +ObjectExpression *ObjectExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(Tag {}, *this, allocator); clone != nullptr) { if (parent != nullptr) { diff --git a/ets2panda/ir/expressions/objectExpression.h b/ets2panda/ir/expressions/objectExpression.h index b258313d0b93de38a1d3b55eab3cae03dfbc5123..70121771fe53fdf4d2754e6b786fdf7e0ff429c5 100644 --- a/ets2panda/ir/expressions/objectExpression.h +++ b/ets2panda/ir/expressions/objectExpression.h @@ -83,7 +83,7 @@ public: } // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ObjectExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; [[nodiscard]] ValidationInfo ValidateExpression(); [[nodiscard]] bool ConvertibleToObjectPattern(); diff --git a/ets2panda/ir/expressions/omittedExpression.cpp b/ets2panda/ir/expressions/omittedExpression.cpp index b24ea45bebab63c11dc55a32528f0a71ea030e1e..ab2a356ac6b9b8ee39d989fc697c0cf6c348091b 100644 --- a/ets2panda/ir/expressions/omittedExpression.cpp +++ b/ets2panda/ir/expressions/omittedExpression.cpp @@ -40,7 +40,7 @@ checker::Type *OmittedExpression::Check([[maybe_unused]] checker::ETSChecker *ch } // NOLINTNEXTLINE(google-default-arguments) -Expression *OmittedExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) +OmittedExpression *OmittedExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(); clone != nullptr) { if (parent != nullptr) { diff --git a/ets2panda/ir/expressions/omittedExpression.h b/ets2panda/ir/expressions/omittedExpression.h index ee722bf0c336ee9e36d8d58fc9d017e7f02ca9db..20f7f5ead9e959abb84db7903320aebd3a0c81c7 100644 --- a/ets2panda/ir/expressions/omittedExpression.h +++ b/ets2panda/ir/expressions/omittedExpression.h @@ -31,7 +31,7 @@ public: void TransformChildren(const NodeTransformer &cb) override; // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] OmittedExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; diff --git a/ets2panda/ir/expressions/sequenceExpression.cpp b/ets2panda/ir/expressions/sequenceExpression.cpp index cde77a042f784b3d3574295e4c64f03e31ef02f6..f855c5826d318cf7049e68b19dce7948dc290a28 100644 --- a/ets2panda/ir/expressions/sequenceExpression.cpp +++ b/ets2panda/ir/expressions/sequenceExpression.cpp @@ -24,12 +24,12 @@ SequenceExpression::SequenceExpression([[maybe_unused]] Tag const tag, SequenceE : Expression(static_cast(other)), sequence_(allocator->Adapter()) { for (auto *sequence : other.sequence_) { - sequence_.emplace_back(sequence->Clone(allocator, this)); + sequence_.emplace_back(sequence->Clone(allocator, this)->AsExpression()); } } // NOLINTNEXTLINE(google-default-arguments) -Expression *SequenceExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) +SequenceExpression *SequenceExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(Tag {}, *this, allocator); clone != nullptr) { if (parent != nullptr) { diff --git a/ets2panda/ir/expressions/sequenceExpression.h b/ets2panda/ir/expressions/sequenceExpression.h index 29a1fd2aec43f64f48f98152123afb97c7f8a0d6..79e9974db8d061a6b10ca30193b9eea37c4cf63a 100644 --- a/ets2panda/ir/expressions/sequenceExpression.h +++ b/ets2panda/ir/expressions/sequenceExpression.h @@ -48,7 +48,7 @@ public: } // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] SequenceExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/superExpression.cpp b/ets2panda/ir/expressions/superExpression.cpp index 8858bffbc9e4ff10e2b72a72c26d99b24b8b8f17..b7d291a57f39b93f74a0cd3b4f45b3c238fd4904 100644 --- a/ets2panda/ir/expressions/superExpression.cpp +++ b/ets2panda/ir/expressions/superExpression.cpp @@ -65,7 +65,7 @@ checker::Type *SuperExpression::Check([[maybe_unused]] checker::ETSChecker *chec } // NOLINTNEXTLINE(google-default-arguments) -Expression *SuperExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) +SuperExpression *SuperExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(); clone != nullptr) { if (parent != nullptr) { diff --git a/ets2panda/ir/expressions/superExpression.h b/ets2panda/ir/expressions/superExpression.h index 31b2835975906406105493339f80923749dc2e28..27d45416083710a98f04330679c5a7f43f2bcb7b 100644 --- a/ets2panda/ir/expressions/superExpression.h +++ b/ets2panda/ir/expressions/superExpression.h @@ -29,7 +29,7 @@ public: explicit SuperExpression() : Expression(AstNodeType::SUPER_EXPRESSION) {} // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] SuperExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/taggedTemplateExpression.cpp b/ets2panda/ir/expressions/taggedTemplateExpression.cpp index 3960c0d1c3ee7c915b032ecb59f765e754cdf4d2..b68a413ab31afb6b1ea12d6e08e51467ae94f2bf 100644 --- a/ets2panda/ir/expressions/taggedTemplateExpression.cpp +++ b/ets2panda/ir/expressions/taggedTemplateExpression.cpp @@ -83,12 +83,11 @@ checker::Type *TaggedTemplateExpression::Check([[maybe_unused]] checker::ETSChec } // NOLINTNEXTLINE(google-default-arguments) -Expression *TaggedTemplateExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) +TaggedTemplateExpression *TaggedTemplateExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const tag = tag_ != nullptr ? tag_->Clone(allocator) : nullptr; - auto *const quasi = quasi_ != nullptr ? quasi_->Clone(allocator)->AsTemplateLiteral() : nullptr; - auto *const type_params = - type_params_ != nullptr ? type_params_->Clone(allocator)->AsTSTypeParameterInstantiation() : nullptr; + auto *const tag = tag_ != nullptr ? tag_->Clone(allocator)->AsExpression() : nullptr; + auto *const quasi = quasi_ != nullptr ? quasi_->Clone(allocator) : nullptr; + auto *const type_params = type_params_ != nullptr ? type_params_->Clone(allocator) : nullptr; if (auto *const clone = allocator->New(tag, quasi, type_params); clone != nullptr) { if (tag != nullptr) { diff --git a/ets2panda/ir/expressions/taggedTemplateExpression.h b/ets2panda/ir/expressions/taggedTemplateExpression.h index 194571cf79c12eda61595a57a64efd753b6d948c..6aeabf80f7bcebc9d807cfe829c990ec7c1e40d2 100644 --- a/ets2panda/ir/expressions/taggedTemplateExpression.h +++ b/ets2panda/ir/expressions/taggedTemplateExpression.h @@ -52,7 +52,7 @@ public: } // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] TaggedTemplateExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/templateLiteral.cpp b/ets2panda/ir/expressions/templateLiteral.cpp index 82a52458f67c586989cd81b76cccedc736d56c51..61c58acd1ee21815bdafb39788b142d871287703 100644 --- a/ets2panda/ir/expressions/templateLiteral.cpp +++ b/ets2panda/ir/expressions/templateLiteral.cpp @@ -30,16 +30,16 @@ TemplateLiteral::TemplateLiteral([[maybe_unused]] Tag const tag, TemplateLiteral expressions_(allocator->Adapter()) { for (auto *quasy : other.quasis_) { - quasis_.emplace_back(quasy->Clone(allocator, this)->AsTemplateElement()); + quasis_.emplace_back(quasy->Clone(allocator, this)); } for (auto *expression : other.expressions_) { - expressions_.emplace_back(expression->Clone(allocator, this)); + expressions_.emplace_back(expression->Clone(allocator, this)->AsExpression()); } } // NOLINTNEXTLINE(google-default-arguments) -Expression *TemplateLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) +TemplateLiteral *TemplateLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(Tag {}, *this, allocator); clone != nullptr) { if (parent != nullptr) { diff --git a/ets2panda/ir/expressions/templateLiteral.h b/ets2panda/ir/expressions/templateLiteral.h index 3ec24e8007cc43548ee7074e6060b0ff1d30bc3c..bc2d31666dcfc2116ad025c3b5c2a9af7b73d47f 100644 --- a/ets2panda/ir/expressions/templateLiteral.h +++ b/ets2panda/ir/expressions/templateLiteral.h @@ -49,7 +49,7 @@ public: } // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] TemplateLiteral *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/thisExpression.cpp b/ets2panda/ir/expressions/thisExpression.cpp index 4bfd27544111932efed650ee506898500715312c..0c91e916486119c26058cbf27f381ee4c87ace5a 100644 --- a/ets2panda/ir/expressions/thisExpression.cpp +++ b/ets2panda/ir/expressions/thisExpression.cpp @@ -109,7 +109,7 @@ checker::Type *ThisExpression::Check(checker::ETSChecker *checker) } // NOLINTNEXTLINE(google-default-arguments) -Expression *ThisExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) +ThisExpression *ThisExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(); clone != nullptr) { if (parent != nullptr) { diff --git a/ets2panda/ir/expressions/thisExpression.h b/ets2panda/ir/expressions/thisExpression.h index a98f7f39df074533882dbf48b0053b24524724f1..6ffa359d07232aedc724f3e53b009f4f6d9fe493 100644 --- a/ets2panda/ir/expressions/thisExpression.h +++ b/ets2panda/ir/expressions/thisExpression.h @@ -29,7 +29,7 @@ public: explicit ThisExpression() : Expression(AstNodeType::THIS_EXPRESSION) {} // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ThisExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/unaryExpression.cpp b/ets2panda/ir/expressions/unaryExpression.cpp index 2f6ced1150f5be10b5062bbd0193e929d5722955..a73cbef0771f745f05549cd07d211661f5374add 100644 --- a/ets2panda/ir/expressions/unaryExpression.cpp +++ b/ets2panda/ir/expressions/unaryExpression.cpp @@ -305,9 +305,9 @@ checker::Type *UnaryExpression::Check(checker::ETSChecker *checker) } // NOLINTNEXTLINE(google-default-arguments) -Expression *UnaryExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) +UnaryExpression *UnaryExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const argument = argument_ != nullptr ? argument_->Clone(allocator) : nullptr; + auto *const argument = argument_ != nullptr ? argument_->Clone(allocator)->AsExpression() : nullptr; if (auto *const clone = allocator->New(argument, operator_); clone != nullptr) { if (argument != nullptr) { diff --git a/ets2panda/ir/expressions/unaryExpression.h b/ets2panda/ir/expressions/unaryExpression.h index 1e2fb24c0b3e260332e46efe3022f22b27dd2987..ade78126852b73f78907de3db4bc4954627ca53e 100644 --- a/ets2panda/ir/expressions/unaryExpression.h +++ b/ets2panda/ir/expressions/unaryExpression.h @@ -54,7 +54,7 @@ public: } // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] UnaryExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/updateExpression.cpp b/ets2panda/ir/expressions/updateExpression.cpp index e72ca193e8daeafe42af10f01d419cdbdc17b9f4..ae49e98ae65b35975ade9f7f3a03571012e813f3 100644 --- a/ets2panda/ir/expressions/updateExpression.cpp +++ b/ets2panda/ir/expressions/updateExpression.cpp @@ -149,9 +149,9 @@ checker::Type *UpdateExpression::Check(checker::ETSChecker *checker) } // NOLINTNEXTLINE(google-default-arguments) -Expression *UpdateExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) +UpdateExpression *UpdateExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const argument = argument_ != nullptr ? argument_->Clone(allocator) : nullptr; + auto *const argument = argument_ != nullptr ? argument_->Clone(allocator)->AsExpression() : nullptr; if (auto *const clone = allocator->New(argument, operator_, prefix_); clone != nullptr) { if (argument != nullptr) { diff --git a/ets2panda/ir/expressions/updateExpression.h b/ets2panda/ir/expressions/updateExpression.h index 34901b1845bbf46306de88a9c286b86845db85dd..494fbaf2981e13e3c443338068176a4fb929d465 100644 --- a/ets2panda/ir/expressions/updateExpression.h +++ b/ets2panda/ir/expressions/updateExpression.h @@ -54,7 +54,7 @@ public: } // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] UpdateExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/yieldExpression.cpp b/ets2panda/ir/expressions/yieldExpression.cpp index 4aadc7a54582364feea1d450fdf0c06c3361bad6..465498c428b001ee02f60fd2e9cabb698570705b 100644 --- a/ets2panda/ir/expressions/yieldExpression.cpp +++ b/ets2panda/ir/expressions/yieldExpression.cpp @@ -70,9 +70,9 @@ checker::Type *YieldExpression::Check([[maybe_unused]] checker::ETSChecker *chec } // NOLINTNEXTLINE(google-default-arguments) -Expression *YieldExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) +YieldExpression *YieldExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const argument = argument_ != nullptr ? argument_->Clone(allocator) : nullptr; + auto *const argument = argument_ != nullptr ? argument_->Clone(allocator)->AsExpression() : nullptr; if (auto *const clone = allocator->New(argument, delegate_); clone != nullptr) { if (argument != nullptr) { diff --git a/ets2panda/ir/expressions/yieldExpression.h b/ets2panda/ir/expressions/yieldExpression.h index 9e8e85608b77f19cfcdf8a788394cb66af1fa9de..3c2f5282e2fc6549926d84443e13f0e9a8e1fc23 100644 --- a/ets2panda/ir/expressions/yieldExpression.h +++ b/ets2panda/ir/expressions/yieldExpression.h @@ -47,7 +47,7 @@ public: } // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] YieldExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/statement.cpp b/ets2panda/ir/statement.cpp index 8eb886a24eab5ca13ccc2fd3120d1c20620b2d7c..4bec7797487312b9b7890b59b00376ff685e0095 100644 --- a/ets2panda/ir/statement.cpp +++ b/ets2panda/ir/statement.cpp @@ -20,7 +20,7 @@ namespace panda::es2panda::ir { void AnnotatedStatement::CloneTypeAnnotation(ArenaAllocator *const allocator) { if (auto *annotation = const_cast(TypeAnnotation()); annotation != nullptr) { - SetTsTypeAnnotation(annotation->Clone(allocator, this)->AsTypeNode()); + SetTsTypeAnnotation(annotation->Clone(allocator, this)); } } diff --git a/ets2panda/ir/statement.h b/ets2panda/ir/statement.h index 76e05d1d4bf3c4b6365e58329741e29455b92e6a..c1004f771cfe403cbaa9616532c0e3ff1630f3bd 100644 --- a/ets2panda/ir/statement.h +++ b/ets2panda/ir/statement.h @@ -36,14 +36,6 @@ public: virtual void SetReturnType([[maybe_unused]] checker::ETSChecker *checker, [[maybe_unused]] checker::Type *type) {} - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] virtual Statement *Clone([[maybe_unused]] ArenaAllocator *const allocator, - [[maybe_unused]] AstNode *const parent = nullptr) - { - UNREACHABLE(); - return nullptr; - } - protected: explicit Statement(AstNodeType type) : AstNode(type) {} explicit Statement(AstNodeType type, ModifierFlags flags) : AstNode(type, flags) {} diff --git a/ets2panda/ir/ts/tsTypeParameterInstantiation.cpp b/ets2panda/ir/ts/tsTypeParameterInstantiation.cpp index 614e9798df1fab0d259a248af6eb144a817379d9..f9906355134f706cc9f02bc68efa1eebce3c9ef6 100644 --- a/ets2panda/ir/ts/tsTypeParameterInstantiation.cpp +++ b/ets2panda/ir/ts/tsTypeParameterInstantiation.cpp @@ -27,12 +27,13 @@ TSTypeParameterInstantiation::TSTypeParameterInstantiation([[maybe_unused]] Tag : Expression(static_cast(other)), params_(allocator->Adapter()) { for (auto *param : other.params_) { - params_.emplace_back(param->Clone(allocator, this)->AsTypeNode()); + params_.emplace_back(param->Clone(allocator, this)); } } // NOLINTNEXTLINE(google-default-arguments) -Expression *TSTypeParameterInstantiation::Clone(ArenaAllocator *const allocator, AstNode *const parent) +TSTypeParameterInstantiation *TSTypeParameterInstantiation::Clone(ArenaAllocator *const allocator, + AstNode *const parent) { if (auto *const clone = allocator->New(Tag {}, *this, allocator); clone != nullptr) { if (parent != nullptr) { diff --git a/ets2panda/ir/ts/tsTypeParameterInstantiation.h b/ets2panda/ir/ts/tsTypeParameterInstantiation.h index 727e08911e51a4b2b7e2b7195e298efe543c6f08..09db9a4b1df80ee993004e47adeab28c5347e851 100644 --- a/ets2panda/ir/ts/tsTypeParameterInstantiation.h +++ b/ets2panda/ir/ts/tsTypeParameterInstantiation.h @@ -43,7 +43,7 @@ public: } // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] TSTypeParameterInstantiation *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/typeNode.cpp b/ets2panda/ir/typeNode.cpp index 991f0a7d9549324e03af7194c032c78265f17765..be22e10ee704a4131e7b904c37bcbe46245b34a3 100644 --- a/ets2panda/ir/typeNode.cpp +++ b/ets2panda/ir/typeNode.cpp @@ -14,13 +14,14 @@ */ #include "typeNode.h" +#include "astNode.h" #include "opaqueTypeNode.h" #include "es2panda.h" namespace panda::es2panda::ir { // NOLINTNEXTLINE(google-default-arguments) -Expression *TypeNode::Clone(ArenaAllocator *const allocator, AstNode *const parent) +TypeNode *TypeNode::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const type = TsType(); type != nullptr) { if (auto *const clone = allocator->New(type); clone != nullptr) { diff --git a/ets2panda/ir/typeNode.h b/ets2panda/ir/typeNode.h index c92340a3a1fb3512ce77ef4a6f345f4a901154e4..7933f9b5e407daaa0898bc2b39b20c5107b542c4 100644 --- a/ets2panda/ir/typeNode.h +++ b/ets2panda/ir/typeNode.h @@ -48,7 +48,7 @@ public: } // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] TypeNode *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; protected: explicit TypeNode(AstNodeType const type) : Expression(type) {}