1 /** 2 * Copyright (c) 2021-2022 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 "statement.h" 17 18 namespace panda::es2panda::ir { UpdateForMultipleTransformedStatements(const NodeUpdater & cb,ArenaVector<Statement * > & originStatements)19void Statement::UpdateForMultipleTransformedStatements(const NodeUpdater &cb, 20 ArenaVector<Statement *> &originStatements) 21 { 22 for (auto iter = originStatements.begin(); iter != originStatements.end();) { 23 auto newStatements = cb(*iter); 24 if (std::holds_alternative<ir::AstNode *>(newStatements)) { 25 auto statement = std::get<ir::AstNode *>(newStatements); 26 if (statement == *iter) { 27 iter++; 28 } else if (statement == nullptr) { 29 iter = originStatements.erase(iter); 30 } else { 31 *iter = statement->AsStatement(); 32 iter++; 33 } 34 } else { 35 auto statements = std::get<std::vector<ir::AstNode *>>(newStatements); 36 for (auto *it : statements) { 37 iter = originStatements.insert(iter, it->AsStatement()); 38 iter++; 39 } 40 iter = originStatements.erase(iter); 41 } 42 } 43 } 44 } // namespace panda::es2panda::ir 45