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 "loopStatement.h"
17
18 #include "ir/statements/blockStatement.h"
19
20 namespace panda::es2panda::ir {
21
UpdateChildStatement(const NodeUpdater & cb,const binder::Binder * binder,Statement * statement) const22 Statement *LoopStatement::UpdateChildStatement(const NodeUpdater &cb,
23 const binder::Binder *binder,
24 Statement *statement) const
25 {
26 auto newStatement = cb(statement);
27 if (std::holds_alternative<ir::AstNode *>(newStatement)) {
28 return std::get<ir::AstNode *>(newStatement)->AsStatement();
29 }
30
31 ASSERT(std::holds_alternative<std::vector<ir::AstNode *>>(newStatement));
32 ArenaVector<ir::Statement *> statements(binder->Allocator()->Adapter());
33 auto newStatements = std::get<std::vector<ir::AstNode *>>(newStatement);
34 for (auto *it : newStatements) {
35 statements.push_back(it->AsStatement());
36 }
37 return binder->Allocator()->New<ir::BlockStatement>(nullptr, std::move(statements));
38 }
39
40 } // namespace panda::es2panda::ir
41