1 /*
2  * Copyright (c) 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 #ifndef ES2PANDA_EVALUATE_PATH_RESOLVER_H
17 #define ES2PANDA_EVALUATE_PATH_RESOLVER_H
18 
19 #include "libpandabase/utils/arena_containers.h"
20 
21 namespace ark::es2panda::evaluate {
22 
23 class DebugInfoStorage;
24 struct EntityInfo;
25 
26 class PathResolver final {
27 public:
28     NO_COPY_SEMANTIC(PathResolver);
29     NO_MOVE_SEMANTIC(PathResolver);
30 
PathResolver(DebugInfoStorage &debugInfoStorage)31     explicit PathResolver(DebugInfoStorage &debugInfoStorage) : debugInfoStorage_(debugInfoStorage) {}
32 
33     ~PathResolver() = default;
34 
35     /**
36      * @brief Returns import path on success, empty string otherwise
37      */
38     std::string_view FindNamedImportAll(std::string_view filePath, std::string_view bindingName);
39 
40     std::optional<EntityInfo> FindImportedEntity(std::string_view filePath, std::string_view entityName);
41 
42     void FindImportedFunctions(ArenaVector<EntityInfo> &overloadSet, std::string_view filePath,
43                                std::string_view entityName);
44 
45 private:
46     void FindExportedFunctions(ArenaVector<EntityInfo> &overloadSet, std::string_view filePath,
47                                std::string_view entityName);
48     std::optional<EntityInfo> FindExportedEntity(std::string_view filePath, std::string_view entityName);
49 
50 private:
51     static constexpr std::string_view STAR_IMPORT = "*";
52 
53     DebugInfoStorage &debugInfoStorage_;
54 };
55 
56 }  // namespace ark::es2panda::evaluate
57 
58 #endif  // ES2PANDA_EVALUATE_PATH_RESOLVER_H
59