1/*
2 * Copyright (c) 2021-2024 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 "classStaticBlock.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#include "ir/astDump.h"
23#include "ir/srcDump.h"
24#include "ir/base/decorator.h"
25#include "ir/base/scriptFunction.h"
26#include "ir/expression.h"
27#include "ir/expressions/identifier.h"
28#include "ir/expressions/functionExpression.h"
29
30namespace ark::es2panda::ir {
31void ClassStaticBlock::TransformChildren(const NodeTransformer &cb, std::string_view transformationName)
32{
33    if (auto *transformedNode = cb(value_); value_ != transformedNode) {
34        value_->SetTransformedNode(transformationName, transformedNode);
35        value_ = transformedNode->AsExpression();
36    }
37}
38
39void ClassStaticBlock::Iterate(const NodeTraverser &cb) const
40{
41    cb(value_);
42}
43
44void ClassStaticBlock::Dump(ir::AstDumper *dumper) const
45{
46    dumper->Add({{"type", "ClassStaticBlock"}, {"value", value_}});
47}
48
49void ClassStaticBlock::Dump([[maybe_unused]] ir::SrcDumper *dumper) const
50{
51    // NOTE(nsizov): we don't want to show this node
52}
53
54void ClassStaticBlock::Compile(compiler::PandaGen *pg) const
55{
56    pg->GetAstCompiler()->Compile(this);
57}
58
59void ClassStaticBlock::Compile(compiler::ETSGen *etsg) const
60{
61    etsg->GetAstCompiler()->Compile(this);
62}
63
64checker::Type *ClassStaticBlock::Check(checker::TSChecker *checker)
65{
66    return checker->GetAnalyzer()->Check(this);
67}
68
69checker::Type *ClassStaticBlock::Check(checker::ETSChecker *checker)
70{
71    return checker->GetAnalyzer()->Check(this);
72}
73
74ir::ScriptFunction *ClassStaticBlock::Function()
75{
76    return value_->AsFunctionExpression()->Function();
77}
78
79const ir::ScriptFunction *ClassStaticBlock::Function() const
80{
81    return value_->AsFunctionExpression()->Function();
82}
83
84const util::StringView &ClassStaticBlock::Name() const
85{
86    return Function()->Id()->Name();
87}
88
89}  // namespace ark::es2panda::ir
90