• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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#ifndef LIBPANDAFILE_SOURCE_LANG_ENUM_H
17#define LIBPANDAFILE_SOURCE_LANG_ENUM_H
18
19namespace panda::panda_file {
20
21enum class SourceLang : uint8_t {
22% Common::plugins.each do |plugin_lang, plugin_opts|
23% short_plugin_lang = plugin_lang == "JAVA" ? "JAVA_8" : plugin_lang
24    <%= short_plugin_lang %> = <%= plugin_opts["lang_enum_id"] %>,
25% end
26    ECMASCRIPT = 0,
27    PANDA_ASSEMBLY = 1,
28    JAVASCRIPT = 2,
29    TYPESCRIPT = 3,
30    ARKTS = 4
31};
32
33constexpr SourceLang DEFUALT_SOURCE_LANG = SourceLang::ECMASCRIPT;
34
35constexpr uint8_t LANG_COUNT = <%= Common::plugins.length + 1 %>;
36
37constexpr std::array<SourceLang, panda::panda_file::LANG_COUNT> LANG_ITERATOR = {
38% Common::plugins.each do |plugin_lang, plugin_opts|
39    <%= plugin_opts["lang_enum"] %>,
40% end
41    panda::panda_file::SourceLang::PANDA_ASSEMBLY
42};
43
44static constexpr size_t GetLangArrIndex(panda_file::SourceLang lang)
45{
46    for (size_t index = 0; index < panda::panda_file::LANG_ITERATOR.size(); ++index) {
47        if (panda::panda_file::LANG_ITERATOR[index] == lang) {
48            return index;
49        }
50    }
51
52    UNREACHABLE();
53    return 0;
54}
55
56inline std::ostream &operator<<(std::ostream &stream, SourceLang lang)
57{
58    switch (lang) {
59% Common::plugins.each do |plugin_lang, plugin_opts|
60        case <%= plugin_opts["lang_enum"] %>:
61%   name = case plugin_lang
62%     when "ECMASCRIPT" then "ECMAScript"
63%     when "JAVA" then "Java 8"
64%     else plugin_lang.gsub(/_/, " ").capitalize
65%   end
66            stream << "<%= name %>";
67            break;
68% end
69        case panda::panda_file::SourceLang::ECMASCRIPT:
70            stream << "ECMAScript";
71            break;
72        case panda::panda_file::SourceLang::PANDA_ASSEMBLY:
73            stream << "Panda Assembly";
74            break;
75        case panda::panda_file::SourceLang::JAVASCRIPT:
76            stream << "JavaScript";
77            break;
78        case panda::panda_file::SourceLang::TYPESCRIPT:
79            stream << "TypeScript";
80            break;
81        case panda::panda_file::SourceLang::ARKTS:
82            stream << "ArkTS";
83            break;
84        default:
85            UNREACHABLE();
86    }
87    return stream;
88}
89
90// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
91#define LANG_ENUM_LIST   \
92% Common::plugins.each_value do |plugin_opts|
93    <%= plugin_opts["lang_enum"] %>, \
94% end
95    panda::panda_file::SourceLang::PANDA_ASSEMBLY
96
97}  // namespace panda::panda_file
98
99#endif  // LIBPANDAFILE_SOURCE_LANG_ENUM_H
100