• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2021-2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "decorator.h"
17 
18 #include "checker/ETSchecker.h"
19 #include "checker/TSchecker.h"
20 #include "compiler/core/ETSGen.h"
21 #include "compiler/core/pandagen.h"
22 
23 namespace ark::es2panda::ir {
TransformChildren(const NodeTransformer & cb,std::string_view transformationName)24 void Decorator::TransformChildren(const NodeTransformer &cb, std::string_view transformationName)
25 {
26     if (auto *transformedNode = cb(expr_); expr_ != transformedNode) {
27         expr_->SetTransformedNode(transformationName, transformedNode);
28         expr_ = transformedNode->AsExpression();
29     }
30 }
31 
Iterate(const NodeTraverser & cb) const32 void Decorator::Iterate(const NodeTraverser &cb) const
33 {
34     cb(expr_);
35 }
36 
Dump(ir::AstDumper * dumper) const37 void Decorator::Dump(ir::AstDumper *dumper) const
38 {
39     dumper->Add({{"type", "Decorator"}, {"expression", expr_}});
40 }
41 
Dump(ir::SrcDumper * dumper) const42 void Decorator::Dump(ir::SrcDumper *dumper) const
43 {
44     dumper->Add("Decorator");
45 }
46 
Compile(compiler::PandaGen * pg) const47 void Decorator::Compile(compiler::PandaGen *pg) const
48 {
49     pg->GetAstCompiler()->Compile(this);
50 }
51 
Compile(compiler::ETSGen * etsg) const52 void Decorator::Compile(compiler::ETSGen *etsg) const
53 {
54     etsg->GetAstCompiler()->Compile(this);
55 }
56 
Check(checker::TSChecker * checker)57 checker::Type *Decorator::Check(checker::TSChecker *checker)
58 {
59     return checker->GetAnalyzer()->Check(this);
60 }
61 
Check(checker::ETSChecker * checker)62 checker::VerifiedType Decorator::Check(checker::ETSChecker *checker)
63 {
64     return {this, checker->GetAnalyzer()->Check(this)};
65 }
66 
Clone(ArenaAllocator * const allocator,AstNode * const parent)67 Decorator *Decorator::Clone(ArenaAllocator *const allocator, AstNode *const parent)
68 {
69     auto *const expr = expr_ != nullptr ? expr_->Clone(allocator, nullptr)->AsExpression() : nullptr;
70     auto *const clone = allocator->New<Decorator>(expr);
71     ES2PANDA_ASSERT(clone != nullptr);
72     if (expr != nullptr) {
73         expr->SetParent(clone);
74     }
75     if (parent != nullptr) {
76         clone->SetParent(parent);
77     }
78     return clone;
79 }
80 }  // namespace ark::es2panda::ir
81