• 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 "etsNewMultiDimArrayInstanceExpression.h"
17 
18 #include "varbinder/ETSBinder.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 
25 namespace panda::es2panda::ir {
TransformChildren(const NodeTransformer & cb)26 void ETSNewMultiDimArrayInstanceExpression::TransformChildren(const NodeTransformer &cb)
27 {
28     typeReference_ = static_cast<TypeNode *>(cb(typeReference_));
29     for (auto *&dim : dimensions_) {
30         dim = cb(dim)->AsExpression();
31     }
32 }
33 
Iterate(const NodeTraverser & cb) const34 void ETSNewMultiDimArrayInstanceExpression::Iterate(const NodeTraverser &cb) const
35 {
36     cb(typeReference_);
37     for (auto *dim : dimensions_) {
38         cb(dim);
39     }
40 }
41 
Dump(ir::AstDumper * dumper) const42 void ETSNewMultiDimArrayInstanceExpression::Dump(ir::AstDumper *dumper) const
43 {
44     dumper->Add({{"type", "ETSNewMultiDimArrayInstanceExpression"},
45                  {"typeReference", typeReference_},
46                  {"dimensions", dimensions_}});
47 }
48 
Dump(ir::SrcDumper * dumper) const49 void ETSNewMultiDimArrayInstanceExpression::Dump(ir::SrcDumper *dumper) const
50 {
51     dumper->Add("new ");
52     ASSERT(typeReference_);
53     typeReference_->Dump(dumper);
54     for (auto dim : dimensions_) {
55         dumper->Add("[");
56         dim->Dump(dumper);
57         dumper->Add("]");
58     }
59 }
60 
Compile(compiler::PandaGen * pg) const61 void ETSNewMultiDimArrayInstanceExpression::Compile(compiler::PandaGen *pg) const
62 {
63     pg->GetAstCompiler()->Compile(this);
64 }
Compile(compiler::ETSGen * etsg) const65 void ETSNewMultiDimArrayInstanceExpression::Compile(compiler::ETSGen *etsg) const
66 {
67     etsg->GetAstCompiler()->Compile(this);
68 }
69 
Check(checker::TSChecker * checker)70 checker::Type *ETSNewMultiDimArrayInstanceExpression::Check(checker::TSChecker *checker)
71 {
72     return checker->GetAnalyzer()->Check(this);
73 }
74 
Check(checker::ETSChecker * checker)75 checker::Type *ETSNewMultiDimArrayInstanceExpression::Check(checker::ETSChecker *checker)
76 {
77     return checker->GetAnalyzer()->Check(this);
78 }
79 
ETSNewMultiDimArrayInstanceExpression(ETSNewMultiDimArrayInstanceExpression const & other,ArenaAllocator * const allocator)80 ETSNewMultiDimArrayInstanceExpression::ETSNewMultiDimArrayInstanceExpression(
81     ETSNewMultiDimArrayInstanceExpression const &other, ArenaAllocator *const allocator)
82     : Expression(static_cast<Expression const &>(other)),
83       dimensions_(allocator->Adapter()),
84       signature_(other.signature_)
85 {
86     typeReference_ = other.typeReference_->Clone(allocator, this);
87 
88     for (auto *const dimension : other.dimensions_) {
89         dimensions_.emplace_back(dimension->Clone(allocator, this)->AsExpression());
90     }
91 }
92 
93 // NOLINTNEXTLINE(google-default-arguments)
Clone(ArenaAllocator * const allocator,AstNode * const parent)94 ETSNewMultiDimArrayInstanceExpression *ETSNewMultiDimArrayInstanceExpression::Clone(ArenaAllocator *const allocator,
95                                                                                     AstNode *const parent)
96 {
97     if (auto *const clone = allocator->New<ETSNewMultiDimArrayInstanceExpression>(*this, allocator); clone != nullptr) {
98         if (parent != nullptr) {
99             clone->SetParent(parent);
100         }
101         return clone;
102     }
103 
104     throw Error(ErrorType::GENERIC, "", CLONE_ALLOCATION_ERROR);
105 }
106 }  // namespace panda::es2panda::ir
107