13af6ab5fSopenharmony_ci/** 23af6ab5fSopenharmony_ci * Copyright (c) 2021-2024 Huawei Device Co., Ltd. 33af6ab5fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 43af6ab5fSopenharmony_ci * you may not use this file except in compliance with the License. 53af6ab5fSopenharmony_ci * You may obtain a copy of the License at 63af6ab5fSopenharmony_ci * 73af6ab5fSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 83af6ab5fSopenharmony_ci * 93af6ab5fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 103af6ab5fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 113af6ab5fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 123af6ab5fSopenharmony_ci * See the License for the specific language governing permissions and 133af6ab5fSopenharmony_ci * limitations under the License. 143af6ab5fSopenharmony_ci */ 153af6ab5fSopenharmony_ci 163af6ab5fSopenharmony_ci// Autogenerated file -- DO NOT EDIT! 173af6ab5fSopenharmony_ci 183af6ab5fSopenharmony_ci#ifndef ES2PANDA_COMPILER_GEN_SIGNATURES_H 193af6ab5fSopenharmony_ci#define ES2PANDA_COMPILER_GEN_SIGNATURES_H 203af6ab5fSopenharmony_ci 213af6ab5fSopenharmony_ci#include "util/ustring.h" 223af6ab5fSopenharmony_ci#include "util/language.h" 233af6ab5fSopenharmony_ci 243af6ab5fSopenharmony_ci#include <optional> 253af6ab5fSopenharmony_ci 263af6ab5fSopenharmony_cinamespace ark::es2panda::compiler { 273af6ab5fSopenharmony_ciclass Signatures { 283af6ab5fSopenharmony_cipublic: 293af6ab5fSopenharmony_ci explicit Signatures() = delete; 303af6ab5fSopenharmony_ci 313af6ab5fSopenharmony_ci // Defines 323af6ab5fSopenharmony_ci% Signatures::DEFINES.each do |ref, define| 333af6ab5fSopenharmony_ci% if define.comment 343af6ab5fSopenharmony_ci static constexpr std::string_view <%= ref %> = "<%= define.name %>"; // <%= define.comment %> 353af6ab5fSopenharmony_ci% else 363af6ab5fSopenharmony_ci static constexpr std::string_view <%= ref %> = "<%= define.name %>"; 373af6ab5fSopenharmony_ci% end 383af6ab5fSopenharmony_ci% end 393af6ab5fSopenharmony_ci 403af6ab5fSopenharmony_ci // Primitive types 413af6ab5fSopenharmony_ci% Signatures::PRIMITIVES.each do |ref, name| 423af6ab5fSopenharmony_ci static constexpr std::string_view <%= ref %> = "<%= name %>"; 433af6ab5fSopenharmony_ci% end 443af6ab5fSopenharmony_ci 453af6ab5fSopenharmony_ci // TypeDescriptor primitives 463af6ab5fSopenharmony_ci% Signatures::TYPEDESCRIPTORS.each do |ref, name| 473af6ab5fSopenharmony_ci static constexpr std::string_view <%= ref %> = "<%= name %>"; 483af6ab5fSopenharmony_ci% end 493af6ab5fSopenharmony_ci 503af6ab5fSopenharmony_ci // Builtin classes 513af6ab5fSopenharmony_ci% Signatures::BUILTINS.each do |ref, desc| 523af6ab5fSopenharmony_ci static constexpr std::string_view <%= ref %>_CLASS = "<%= desc[1] %>"; 533af6ab5fSopenharmony_ci% end 543af6ab5fSopenharmony_ci 553af6ab5fSopenharmony_ci // Builtins 563af6ab5fSopenharmony_ci% Signatures::BUILTINS.each do |ref, desc| 573af6ab5fSopenharmony_ci static constexpr std::string_view <%= ref %> = "<%= desc[0] %>"; 583af6ab5fSopenharmony_ci% end 593af6ab5fSopenharmony_ci 603af6ab5fSopenharmony_ci // Builtin signatures 613af6ab5fSopenharmony_ci% Signatures::SIGNATURES.each do |ref, name| 623af6ab5fSopenharmony_ci static constexpr std::string_view <%= ref %> = "<%= name %>"; 633af6ab5fSopenharmony_ci% end 643af6ab5fSopenharmony_ci 653af6ab5fSopenharmony_ci class Dynamic { 663af6ab5fSopenharmony_ci public: 673af6ab5fSopenharmony_ci static bool IsSupported([[maybe_unused]] Language lang) 683af6ab5fSopenharmony_ci { 693af6ab5fSopenharmony_ci% Signatures::DYNAMIC.each do |lang, data| 703af6ab5fSopenharmony_ci if (lang.GetId() == Language::Id::<%= lang.upcase %>) { 713af6ab5fSopenharmony_ci return true; // NOLINT(readability-simplify-boolean-expr) 723af6ab5fSopenharmony_ci } 733af6ab5fSopenharmony_ci% end 743af6ab5fSopenharmony_ci return false; 753af6ab5fSopenharmony_ci } 763af6ab5fSopenharmony_ci 773af6ab5fSopenharmony_ci static std::string_view Type(Language lang) 783af6ab5fSopenharmony_ci { 793af6ab5fSopenharmony_ci ASSERT(IsSupported(lang)); 803af6ab5fSopenharmony_ci% Signatures::DYNAMIC.each do |lang, data| 813af6ab5fSopenharmony_ci if (lang.GetId() == Language::Id::<%= lang.upcase %>) { 823af6ab5fSopenharmony_ci return <%= data.dynamic_class %>; 833af6ab5fSopenharmony_ci } 843af6ab5fSopenharmony_ci% end 853af6ab5fSopenharmony_ci UNREACHABLE(); 863af6ab5fSopenharmony_ci } 873af6ab5fSopenharmony_ci 883af6ab5fSopenharmony_ci static std::string_view CallClass(Language lang) 893af6ab5fSopenharmony_ci { 903af6ab5fSopenharmony_ci ASSERT(IsSupported(lang)); 913af6ab5fSopenharmony_ci% Signatures::DYNAMIC.each do |lang, data| 923af6ab5fSopenharmony_ci if (lang.GetId() == Language::Id::<%= lang.upcase %>) { 933af6ab5fSopenharmony_ci return <%= data.call_class.name %>; 943af6ab5fSopenharmony_ci } 953af6ab5fSopenharmony_ci% end 963af6ab5fSopenharmony_ci UNREACHABLE(); 973af6ab5fSopenharmony_ci } 983af6ab5fSopenharmony_ci 993af6ab5fSopenharmony_ci static std::string_view InitCallClassBuiltin(Language lang) 1003af6ab5fSopenharmony_ci { 1013af6ab5fSopenharmony_ci ASSERT(IsSupported(lang)); 1023af6ab5fSopenharmony_ci% Signatures::DYNAMIC.each do |lang, data| 1033af6ab5fSopenharmony_ci if (lang.GetId() == Language::Id::<%= lang.upcase %>) { 1043af6ab5fSopenharmony_ci return <%= data.call_class.init_builtin %>; 1053af6ab5fSopenharmony_ci } 1063af6ab5fSopenharmony_ci% end 1073af6ab5fSopenharmony_ci UNREACHABLE(); 1083af6ab5fSopenharmony_ci } 1093af6ab5fSopenharmony_ci 1103af6ab5fSopenharmony_ci static std::string_view NewClass(Language lang) 1113af6ab5fSopenharmony_ci { 1123af6ab5fSopenharmony_ci ASSERT(IsSupported(lang)); 1133af6ab5fSopenharmony_ci% Signatures::DYNAMIC.each do |lang, data| 1143af6ab5fSopenharmony_ci if (lang.GetId() == Language::Id::<%= lang.upcase %>) { 1153af6ab5fSopenharmony_ci return <%= data.new_class.name %>; 1163af6ab5fSopenharmony_ci } 1173af6ab5fSopenharmony_ci% end 1183af6ab5fSopenharmony_ci UNREACHABLE(); 1193af6ab5fSopenharmony_ci } 1203af6ab5fSopenharmony_ci 1213af6ab5fSopenharmony_ci static std::string_view InitNewClassBuiltin(Language lang) 1223af6ab5fSopenharmony_ci { 1233af6ab5fSopenharmony_ci ASSERT(IsSupported(lang)); 1243af6ab5fSopenharmony_ci% Signatures::DYNAMIC.each do |lang, data| 1253af6ab5fSopenharmony_ci if (lang.GetId() == Language::Id::<%= lang.upcase %>) { 1263af6ab5fSopenharmony_ci return <%= data.new_class.init_builtin %>; 1273af6ab5fSopenharmony_ci } 1283af6ab5fSopenharmony_ci% end 1293af6ab5fSopenharmony_ci UNREACHABLE(); 1303af6ab5fSopenharmony_ci } 1313af6ab5fSopenharmony_ci 1323af6ab5fSopenharmony_ci static std::string_view LoadModuleBuiltin(Language lang) 1333af6ab5fSopenharmony_ci { 1343af6ab5fSopenharmony_ci ASSERT(IsSupported(lang)); 1353af6ab5fSopenharmony_ci% Signatures::DYNAMIC.each do |lang, data| 1363af6ab5fSopenharmony_ci if (lang.GetId() == Language::Id::<%= lang.upcase %>) { 1373af6ab5fSopenharmony_ci return <%= data.module_class.load_builtin %>; 1383af6ab5fSopenharmony_ci } 1393af6ab5fSopenharmony_ci% end 1403af6ab5fSopenharmony_ci UNREACHABLE(); 1413af6ab5fSopenharmony_ci } 1423af6ab5fSopenharmony_ci 1433af6ab5fSopenharmony_ci static std::optional<Language> LanguageFromType(std::string_view assemblerName) 1443af6ab5fSopenharmony_ci { 1453af6ab5fSopenharmony_ci% Signatures::DYNAMIC.each do |lang, data| 1463af6ab5fSopenharmony_ci if (assemblerName == <%= data.dynamic_class %>) { 1473af6ab5fSopenharmony_ci return Language(Language::Id::<%= lang.upcase %>); 1483af6ab5fSopenharmony_ci } 1493af6ab5fSopenharmony_ci% end 1503af6ab5fSopenharmony_ci return {}; 1513af6ab5fSopenharmony_ci } 1523af6ab5fSopenharmony_ci 1533af6ab5fSopenharmony_ci static std::string_view GetUndefinedBuiltin(Language lang) 1543af6ab5fSopenharmony_ci { 1553af6ab5fSopenharmony_ci ASSERT(IsSupported(lang)); 1563af6ab5fSopenharmony_ci% Signatures::DYNAMIC.each do |lang, data| 1573af6ab5fSopenharmony_ci if (lang.GetId() == Language::Id::<%= lang.upcase %>) { 1583af6ab5fSopenharmony_ci return <%= data.builtins.get_undefined %>; 1593af6ab5fSopenharmony_ci } 1603af6ab5fSopenharmony_ci% end 1613af6ab5fSopenharmony_ci UNREACHABLE(); 1623af6ab5fSopenharmony_ci } 1633af6ab5fSopenharmony_ci 1643af6ab5fSopenharmony_ci% def generate(attr, pref) 1653af6ab5fSopenharmony_ci% builtins = Hash.new() 1663af6ab5fSopenharmony_ci% Signatures::DYNAMIC.each do |lang, data| 1673af6ab5fSopenharmony_ci% data.builtins[attr].each do |builtin_data| 1683af6ab5fSopenharmony_ci% builtins[builtin_data.type] = [] unless builtins.key?(builtin_data.type) 1693af6ab5fSopenharmony_ci% builtins[builtin_data.type].append([lang, builtin_data.builtin]) 1703af6ab5fSopenharmony_ci% end 1713af6ab5fSopenharmony_ci% end 1723af6ab5fSopenharmony_ci% res = '' 1733af6ab5fSopenharmony_ci% builtins.each do |type, data| 1743af6ab5fSopenharmony_ci% res += "\n" 1753af6ab5fSopenharmony_ci% res += " static std::string_view #{pref}#{type.capitalize}Builtin(Language lang)\n" 1763af6ab5fSopenharmony_ci% res += " {\n" 1773af6ab5fSopenharmony_ci% data.each do |builtin_data| 1783af6ab5fSopenharmony_ci% (lang, builtin) = builtin_data 1793af6ab5fSopenharmony_ci% res += " if (lang.GetId() == Language::Id::#{lang.upcase}) {\n" 1803af6ab5fSopenharmony_ci% res += " return #{builtin};\n" 1813af6ab5fSopenharmony_ci% res += " }\n" 1823af6ab5fSopenharmony_ci% end 1833af6ab5fSopenharmony_ci% res += " UNREACHABLE();\n" 1843af6ab5fSopenharmony_ci% res += " }" 1853af6ab5fSopenharmony_ci% end 1863af6ab5fSopenharmony_ci% res 1873af6ab5fSopenharmony_ci% end 1883af6ab5fSopenharmony_ci<%= generate(:new, 'New') %> 1893af6ab5fSopenharmony_ci<%= generate(:get_value, 'Get') %> 1903af6ab5fSopenharmony_ci<%= generate(:get_property, 'GetProperty') %> 1913af6ab5fSopenharmony_ci<%= generate(:set_property, 'SetProperty') %> 1923af6ab5fSopenharmony_ci<%= generate(:get_element, 'GetElement') %> 1933af6ab5fSopenharmony_ci<%= generate(:set_element, 'SetElement') %> 1943af6ab5fSopenharmony_ci 1953af6ab5fSopenharmony_ci }; 1963af6ab5fSopenharmony_ci}; 1973af6ab5fSopenharmony_ci} // namespace ark::es2panda::compiler 1983af6ab5fSopenharmony_ci 1993af6ab5fSopenharmony_ci#endif 200