• 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};
29
30constexpr uint8_t LANG_COUNT = <%= Common::plugins.length + 1 %>;
31
32constexpr std::array<SourceLang, panda::panda_file::LANG_COUNT> LANG_ITERATOR = {
33% Common::plugins.each do |plugin_lang, plugin_opts|
34    <%= plugin_opts["lang_enum"] %>,
35% end
36    panda::panda_file::SourceLang::PANDA_ASSEMBLY
37};
38
39static constexpr size_t GetLangArrIndex(panda_file::SourceLang lang)
40{
41    for (size_t index = 0; index < panda::panda_file::LANG_ITERATOR.size(); ++index) {
42        if (panda::panda_file::LANG_ITERATOR[index] == lang) {
43            return index;
44        }
45    }
46
47    UNREACHABLE();
48    return 0;
49}
50
51inline std::ostream &operator<<(std::ostream &stream, SourceLang lang)
52{
53    switch (lang) {
54% Common::plugins.each do |plugin_lang, plugin_opts|
55        case <%= plugin_opts["lang_enum"] %>:
56%   name = case plugin_lang
57%     when "ECMASCRIPT" then "ECMAScript"
58%     when "JAVA" then "Java 8"
59%     else plugin_lang.gsub(/_/, " ").capitalize
60%   end
61            stream << "<%= name %>";
62            break;
63% end
64        case panda::panda_file::SourceLang::PANDA_ASSEMBLY:
65            stream << "Panda Assembly";
66            break;
67        default:
68            UNREACHABLE();
69    }
70    return stream;
71}
72
73// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
74#define LANG_ENUM_LIST   \
75% Common::plugins.each_value do |plugin_opts|
76    <%= plugin_opts["lang_enum"] %>, \
77% end
78    panda::panda_file::SourceLang::PANDA_ASSEMBLY
79
80}  // namespace panda::panda_file
81
82#endif  // LIBPANDAFILE_SOURCE_LANG_ENUM_H
83