1 /**
2 * Copyright (c) 2021 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 "classDeclaration.h"
17
18 #include "checker/TSchecker.h"
19 #include "compiler/core/ETSGen.h"
20 #include "compiler/core/pandagen.h"
21 #include "ir/astDump.h"
22 #include "ir/srcDump.h"
23
24 namespace panda::es2panda::ir {
TransformChildren(const NodeTransformer & cb)25 void ClassDeclaration::TransformChildren(const NodeTransformer &cb)
26 {
27 for (auto *&it : decorators_) {
28 it = cb(it)->AsDecorator();
29 }
30
31 def_ = cb(def_)->AsClassDefinition();
32 }
33
Iterate(const NodeTraverser & cb) const34 void ClassDeclaration::Iterate(const NodeTraverser &cb) const
35 {
36 for (auto *it : decorators_) {
37 cb(it);
38 }
39
40 cb(def_);
41 }
42
Dump(ir::AstDumper * dumper) const43 void ClassDeclaration::Dump(ir::AstDumper *dumper) const
44 {
45 dumper->Add({{"type", "ClassDeclaration"}, {"definition", def_}, {"decorators", AstDumper::Optional(decorators_)}});
46 }
47
Dump(ir::SrcDumper * dumper) const48 void ClassDeclaration::Dump(ir::SrcDumper *dumper) const
49 {
50 if (def_ != nullptr) {
51 def_->Dump(dumper);
52 }
53 // NOTE(nsizov): support decorators when supported in ArkTS
54 ASSERT(decorators_.empty());
55 }
56
Compile(compiler::PandaGen * pg) const57 void ClassDeclaration::Compile(compiler::PandaGen *pg) const
58 {
59 pg->GetAstCompiler()->Compile(this);
60 }
61
Compile(compiler::ETSGen * etsg) const62 void ClassDeclaration::Compile(compiler::ETSGen *etsg) const
63 {
64 etsg->GetAstCompiler()->Compile(this);
65 }
66
Check(checker::TSChecker * checker)67 checker::Type *ClassDeclaration::Check(checker::TSChecker *checker)
68 {
69 return checker->GetAnalyzer()->Check(this);
70 }
71
Check(checker::ETSChecker * checker)72 checker::Type *ClassDeclaration::Check(checker::ETSChecker *checker)
73 {
74 return checker->GetAnalyzer()->Check(this);
75 }
76 } // namespace panda::es2panda::ir
77