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 "classExpression.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 ClassExpression::TransformChildren(const NodeTransformer &cb)
26 {
27 def_ = cb(def_)->AsClassDefinition();
28 }
29
Iterate(const NodeTraverser & cb) const30 void ClassExpression::Iterate(const NodeTraverser &cb) const
31 {
32 cb(def_);
33 }
34
Dump(ir::AstDumper * dumper) const35 void ClassExpression::Dump(ir::AstDumper *dumper) const
36 {
37 dumper->Add({{"type", "ClassExpression"}, {"definition", def_}});
38 }
39
Dump(ir::SrcDumper * dumper) const40 void ClassExpression::Dump(ir::SrcDumper *dumper) const
41 {
42 dumper->Add("ClassExpression");
43 }
44
Compile(compiler::PandaGen * pg) const45 void ClassExpression::Compile(compiler::PandaGen *pg) const
46 {
47 pg->GetAstCompiler()->Compile(this);
48 }
49
Compile(compiler::ETSGen * etsg) const50 void ClassExpression::Compile(compiler::ETSGen *etsg) const
51 {
52 etsg->GetAstCompiler()->Compile(this);
53 }
54
Check(checker::TSChecker * checker)55 checker::Type *ClassExpression::Check(checker::TSChecker *checker)
56 {
57 return checker->GetAnalyzer()->Check(this);
58 }
59
Check(checker::ETSChecker * checker)60 checker::Type *ClassExpression::Check(checker::ETSChecker *checker)
61 {
62 return checker->GetAnalyzer()->Check(this);
63 }
64
65 // NOLINTNEXTLINE(google-default-arguments)
Clone(ArenaAllocator * const allocator,AstNode * const parent)66 ClassExpression *ClassExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent)
67 {
68 auto *const def = def_ != nullptr ? def_->Clone(allocator)->AsClassDefinition() : nullptr;
69
70 if (auto *const clone = allocator->New<ClassExpression>(def); clone != nullptr) {
71 if (parent != nullptr) {
72 clone->SetParent(parent);
73 }
74 if (def != nullptr) {
75 def->SetParent(clone);
76 }
77 return clone;
78 }
79
80 throw Error(ErrorType::GENERIC, "", CLONE_ALLOCATION_ERROR);
81 }
82 } // namespace panda::es2panda::ir
83