/** * Copyright (c) 2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef ES2PANDA_AOT_DEPEND_RELATION_H #define ES2PANDA_AOT_DEPEND_RELATION_H #include #include #include #include #include #include #include #include namespace panda::es2panda::aot { class DepsRelationResolver { public: explicit DepsRelationResolver(const std::map &progsInfo, const std::unique_ptr &options, std::map> &resolvedDepsRelation) : progsInfo_(progsInfo), resolvedDepsRelation_(resolvedDepsRelation), compileContextInfo_(options->CompilerOptions().compileContextInfo), dumpDepsInfo_(options->CompilerOptions().dumpDepsInfo) { } ~DepsRelationResolver() = default; void CollectStaticImportDepsRelation(const panda::pandasm::Program &program, const std::string &recordName); void CollectDynamicImportDepsRelation(const panda::pandasm::Program &program, const std::string &recordName); bool Resolve(); private: void FillRecord2ProgramMap(std::unordered_map &record2ProgramMap); bool CollectCommonjsRecords(const std::vector &fieldList, const std::string &progKey, const std::string &recordName); void CollectDepsIfNeeded(const std::string &ohmurl); void DumpDepsRelations(); const std::map &progsInfo_; std::map> &resolvedDepsRelation_; CompileContextInfo &compileContextInfo_; std::queue depsToBeResolved_ {}; std::unordered_set resolvedRecords_ {}; bool dumpDepsInfo_ {false}; }; } // namespace panda::es2panda::aot #endif