1 /* 2 * Copyright (c) 2021 - 2023 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 "varbinder/scope.h" 19 #include "checker/ETSchecker.h" 20 #include "checker/TSchecker.h" 21 #include "compiler/core/ETSGen.h" 22 #include "compiler/core/pandagen.h" 23 #include "ir/astDump.h" 24 #include "ir/srcDump.h" 25 #include "ir/base/decorator.h" 26 #include "ir/base/scriptFunction.h" 27 #include "ir/expression.h" 28 #include "ir/expressions/identifier.h" 29 #include "ir/expressions/functionExpression.h" 30 31 #include <cstdint> 32 #include <string> 33 34 namespace panda::es2panda::ir { TransformChildren(const NodeTransformer & cb)35void ClassStaticBlock::TransformChildren(const NodeTransformer &cb) 36 { 37 value_ = cb(value_)->AsExpression(); 38 } 39 Iterate(const NodeTraverser & cb) const40void ClassStaticBlock::Iterate(const NodeTraverser &cb) const 41 { 42 cb(value_); 43 } 44 Dump(ir::AstDumper * dumper) const45void ClassStaticBlock::Dump(ir::AstDumper *dumper) const 46 { 47 dumper->Add({{"type", "ClassStaticBlock"}, {"value", value_}}); 48 } 49 Dump(ir::SrcDumper * dumper) const50void ClassStaticBlock::Dump([[maybe_unused]] ir::SrcDumper *dumper) const 51 { 52 // NOTE(nsizov): we don't want to show this node 53 } 54 Compile(compiler::PandaGen * pg) const55void ClassStaticBlock::Compile(compiler::PandaGen *pg) const 56 { 57 pg->GetAstCompiler()->Compile(this); 58 } 59 Compile(compiler::ETSGen * etsg) const60void ClassStaticBlock::Compile(compiler::ETSGen *etsg) const 61 { 62 etsg->GetAstCompiler()->Compile(this); 63 } 64 Check(checker::TSChecker * checker)65checker::Type *ClassStaticBlock::Check(checker::TSChecker *checker) 66 { 67 return checker->GetAnalyzer()->Check(this); 68 } 69 Check(checker::ETSChecker * checker)70checker::Type *ClassStaticBlock::Check(checker::ETSChecker *checker) 71 { 72 return checker->GetAnalyzer()->Check(this); 73 } 74 Function()75ir::ScriptFunction *ClassStaticBlock::Function() 76 { 77 return value_->AsFunctionExpression()->Function(); 78 } 79 Function() const80const ir::ScriptFunction *ClassStaticBlock::Function() const 81 { 82 return value_->AsFunctionExpression()->Function(); 83 } 84 Name() const85const util::StringView &ClassStaticBlock::Name() const 86 { 87 return Function()->Id()->Name(); 88 } 89 90 } // namespace panda::es2panda::ir 91