• 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
16bool IsDynamicLanguage([[maybe_unused]] panda::panda_file::SourceLang lang)
17{
18% Common::plugins.each_value do |plugin_opts|
19% next unless plugin_opts["language_config"]
20% next unless plugin_opts["language_config"]["lang_type"]
21    if (lang == <%= plugin_opts["lang_enum"] %>) {
22        return <%= plugin_opts["language_config"]["lang_type"] == "dynamic" %>; //NOLINT(readability-simplify-boolean-expr)
23    }
24% end
25
26    return false;
27}
28
29std::optional<panda::panda_file::SourceLang> LanguageFromString([[maybe_unused]] std::string_view lang)
30{
31%   Common::plugins.each_value do |plugin_opts|
32%     next unless plugin_opts["directive_name"]
33    if (lang == "<%= plugin_opts["directive_name"] %>") {
34        return <%= plugin_opts["lang_enum"] %>;
35    }
36%   end
37
38    if (lang == "PandaAssembly") {
39        return panda::panda_file::SourceLang::PANDA_ASSEMBLY;
40    }
41
42    return {};
43}
44
45const char *LanguageToString([[maybe_unused]] panda::panda_file::SourceLang lang)
46{
47%   Common::plugins.each_value do |plugin_opts|
48%     next unless plugin_opts["directive_name"]
49    if (lang == <%= plugin_opts["lang_enum"] %>) {
50        return "<%= plugin_opts["directive_name"] %>";
51    }
52%   end
53
54    return "PandaAssembly";
55}
56
57const char *GetCtorName([[maybe_unused]] panda::panda_file::SourceLang lang)
58{
59%   Common::plugins.each_value do |plugin_opts|
60%     next unless plugin_opts["ctor_name"]
61    if (lang == <%= plugin_opts["lang_enum"] %>) {
62        return "<%= plugin_opts["ctor_name"] %>";
63    }
64%   end
65
66    return ".ctor";
67}
68
69const char *GetCctorName([[maybe_unused]] panda::panda_file::SourceLang lang)
70{
71%   Common::plugins.each_value do |plugin_opts|
72%     next unless plugin_opts["cctor_name"]
73    if (lang == <%= plugin_opts["lang_enum"] %>) {
74        return "<%= plugin_opts["cctor_name"] %>";
75    }
76%   end
77
78    return ".cctor";
79}
80
81const char *GetStringClassDescriptor([[maybe_unused]] panda::panda_file::SourceLang lang)
82{
83%   Common::plugins.each do |plugin_lang, plugin_opts|
84%     next unless plugin_opts["string_class_descriptor"]
85    if (lang == <%= plugin_opts["lang_enum"] %>) {
86        return "<%= plugin_opts["string_class_descriptor"] %>";
87    }
88%   end
89
90    return "Lpanda/String;";
91}
92