• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "etsClassLiteral.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 ETSClassLiteral::TransformChildren(const NodeTransformer &cb)
26 {
27     expr_ = static_cast<TypeNode *>(cb(expr_));
28 }
29 
Iterate(const NodeTraverser & cb) const30 void ETSClassLiteral::Iterate([[maybe_unused]] const NodeTraverser &cb) const
31 {
32     cb(expr_);
33 }
34 
Dump(ir::AstDumper * dumper) const35 void ETSClassLiteral::Dump(ir::AstDumper *dumper) const
36 {
37     dumper->Add({{"type", "ETSClassLiteral"}});
38 }
39 
Dump(ir::SrcDumper * dumper) const40 void ETSClassLiteral::Dump(ir::SrcDumper *dumper) const
41 {
42     dumper->Add("ETSClassLiteral");
43 }
44 
Compile(compiler::PandaGen * pg) const45 void ETSClassLiteral::Compile(compiler::PandaGen *pg) const
46 {
47     pg->GetAstCompiler()->Compile(this);
48 }
49 
Compile(compiler::ETSGen * etsg) const50 void ETSClassLiteral::Compile(compiler::ETSGen *etsg) const
51 {
52     etsg->GetAstCompiler()->Compile(this);
53 }
54 
Check(checker::TSChecker * checker)55 checker::Type *ETSClassLiteral::Check(checker::TSChecker *checker)
56 {
57     return checker->GetAnalyzer()->Check(this);
58 }
59 
Check(checker::ETSChecker * checker)60 checker::Type *ETSClassLiteral::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 ETSClassLiteral *ETSClassLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent)
67 {
68     auto *const expr = expr_ != nullptr ? expr_->Clone(allocator) : nullptr;
69 
70     if (auto *const clone = allocator->New<ETSClassLiteral>(expr); clone != nullptr) {
71         if (expr != nullptr) {
72             expr->SetParent(clone);
73         }
74         if (parent != nullptr) {
75             clone->SetParent(parent);
76         }
77         return clone;
78     }
79 
80     throw Error(ErrorType::GENERIC, "", CLONE_ALLOCATION_ERROR);
81 }
82 }  // namespace panda::es2panda::ir
83