1 /* 2 * Copyright (c) 2023 - 2024 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 "compiler/lowering/ets/topLevelStmts/topLevelStmts.h" 17 18 #include "compiler/lowering/ets/topLevelStmts/globalClassHandler.h" 19 20 namespace ark::es2panda::compiler { 21 Perform(public_lib::Context * ctx,parser::Program * program)22bool TopLevelStatements::Perform(public_lib::Context *ctx, parser::Program *program) 23 { 24 GlobalClassHandler globalClass(program->Allocator()); 25 auto imports = ImportExportDecls(program->VarBinder()->AsETSBinder(), ctx->parser->AsETSParser()); 26 imports.ParseDefaultSources(); 27 auto extSrcs = program->ExternalSources(); 28 for (auto &[_, ext_programs] : extSrcs) { 29 (void)_; 30 imports.HandleGlobalStmts(ext_programs); 31 globalClass.InitGlobalClass(ext_programs); 32 } 33 ArenaVector<parser::Program *> mainModule(program->Allocator()->Adapter()); 34 mainModule.emplace_back(program); 35 imports.HandleGlobalStmts(mainModule); 36 globalClass.InitGlobalClass(mainModule); 37 return true; 38 } 39 40 } // namespace ark::es2panda::compiler