• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "libabckit/src/adapter_dynamic/convert.h"
17 
18 #include "libabckit/include/c/metadata_core.h"
19 #include "libabckit/src/logger.h"
20 
21 #include "abc2program/abc2program_driver.h"
22 
23 namespace libabckit::convert {
24 
ToString(AbckitTarget target)25 std::string_view ToString(AbckitTarget target)
26 {
27     switch (target) {
28         case ABCKIT_TARGET_UNKNOWN:
29             return "unknown";
30         case ABCKIT_TARGET_ARK_TS_V1:
31             return "ArkTsV1";
32         case ABCKIT_TARGET_ARK_TS_V2:
33             return "ArkTsV2";
34         case ABCKIT_TARGET_TS:
35             return "TypeScript";
36         case ABCKIT_TARGET_JS:
37             return "JavaScript";
38         case ABCKIT_TARGET_NATIVE:
39             return "native";
40     }
41     LIBABCKIT_UNREACHABLE;
42 }
43 
ToSourceLang(AbckitTarget target)44 panda::panda_file::SourceLang ToSourceLang(AbckitTarget target)
45 {
46     using SourceLang = panda::panda_file::SourceLang;
47     switch (target) {
48         case ABCKIT_TARGET_ARK_TS_V1:
49         case ABCKIT_TARGET_ARK_TS_V2:
50             return SourceLang::ARKTS;
51         case ABCKIT_TARGET_TS:
52             return SourceLang::TYPESCRIPT;
53         case ABCKIT_TARGET_JS:
54             return SourceLang::JAVASCRIPT;
55         case ABCKIT_TARGET_NATIVE:
56             LIBABCKIT_UNIMPLEMENTED;
57         case ABCKIT_TARGET_UNKNOWN:
58             LIBABCKIT_UNREACHABLE;
59         default:
60             LIBABCKIT_UNIMPLEMENTED;
61     }
62 }
63 
ToTargetDynamic(panda::panda_file::SourceLang lang)64 AbckitTarget ToTargetDynamic(panda::panda_file::SourceLang lang)
65 {
66     using SourceLang = panda::panda_file::SourceLang;
67     switch (lang) {
68         case SourceLang::ECMASCRIPT:
69         case SourceLang::JAVASCRIPT:
70         case SourceLang::TYPESCRIPT:
71             return ABCKIT_TARGET_JS;
72         case SourceLang::ARKTS:
73             return ABCKIT_TARGET_ARK_TS_V1;
74         case SourceLang::PANDA_ASSEMBLY:
75             LIBABCKIT_LOG(ERROR) << "Unexpected source lang: PandaAssembly";
76             LIBABCKIT_UNREACHABLE;
77         default:
78             LIBABCKIT_UNIMPLEMENTED;
79     }
80 }
81 
82 }  // namespace libabckit::convert
83