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// Autogenerated file -- DO NOT EDIT! 17// NOLINTBEGIN(cppcoreguidelines-pro-bounds-pointer-arithmetic, readability-non-const-parameter) 18// NOLINTBEGIN(readability-function-size, readability-magic-numbers) 19 20% Enums::enums&.each do |name, enum| 21% if enum.flags&.length > 0 22extern "C" __attribute__((unused)) <%= enum.namespace %><%= if enum.parent_class_name then "::" + enum.parent_class_name 23end %>::<%= name %> E2pToIr<%= name %>(Es2panda<%= name %> e2pFlags) 24{ 25% if enum.type == 'unsigned' 26% if enum.flags.length <= 32 || enum.type == "int" 27 auto irFlags = (<%= enum.namespace %><%= if enum.parent_class_name then "::" + enum.parent_class_name 28end %>::<%= name %>)0U; 29% enum.flags&.each do |flag| 30 irFlags |= (e2pFlags & Es2panda<%= name %>::<%= enum.name_to_upper_snake %>_<%= flag %>) != 0 ? <%= enum.namespace %><%= 31 if enum.parent_class_name then "::" + enum.parent_class_name 32end %>::<%= name %>::<%= flag %> : (<%= enum.namespace %><%= if enum.parent_class_name then "::" + enum.parent_class_name 33end %>::<%= name %>)0U; 34% end 35% else 36 auto irFlags = (<%= enum.namespace %><%= if enum.parent_class_name then "::" + enum.parent_class_name 37end %>::<%= name %>)0U; 38% enum.flags&.each_with_index do |flag, index| 39 irFlags |= (e2pFlags & <%= if index > 0 then "(uint64_t)1U << " + 40 (index - 1).to_s + "U" else "(uint64_t)0U" end %>) != 0 ? <%= 41 enum.namespace %><%= if enum.parent_class_name then "::" + enum.parent_class_name 42end %>::<%= name %>::<%= flag %> : (<%= enum.namespace %><%= if enum.parent_class_name then "::" + enum.parent_class_name 43end %>::<%= name %>)0U; 44% end 45% end 46 return irFlags; 47% else 48 switch(e2pFlags) 49 { 50% enum.flags&.each do |flag| 51 case Es2panda<%= name %>::<%= enum.name_to_upper_snake %>_<%= flag %>: 52 return <%= enum.namespace %><%= if enum.parent_class_name then "::" + enum.parent_class_name 53end %>::<%= name %>::<%= flag %>; 54% end 55 default: 56 UNREACHABLE(); 57 } 58%end 59} 60% end 61 62%end 63 64% Enums::enums&.each do |name, enum| 65% if enum.flags&.length > 0 66extern "C" __attribute__((unused)) Es2panda<%= name %> IrToE2p<%= name %>(<%= 67enum.namespace %><%= if enum.parent_class_name then 68"::" + enum.parent_class_name end %>::<%= name %> irFlags) 69{ 70% if enum.type == 'unsigned' 71 Es2panda<%= name %> e2pFlags {(Es2panda<%= name %>)0U}; 72% if enum.flags.length <= 32 || enum.type == "int" 73% enum.flags&.each do |flag| 74 e2pFlags = static_cast<Es2panda<%= name %>>((irFlags & <%= enum.namespace %><%= if enum.parent_class_name then 75 "::" + enum.parent_class_name end %>::<%= name %>::<%= flag 76 %>) != 0 ? e2pFlags | Es2panda<%= name %>::<%= enum.name_to_upper_snake %>_<%= flag %> : e2pFlags); 77% end 78% else 79% enum.flags&.each_with_index do |flag, index| 80 e2pFlags = static_cast<Es2panda<%= name %>>((irFlags & <%= enum.namespace %><%= if enum.parent_class_name then 81 "::" + enum.parent_class_name end %>::<%= name %>::<%= flag 82 %>) != 0 ? e2pFlags | <%= if index > 0 then "(uint64_t)1U << " + (index - 1).to_s + "U" 83 else "(uint64_t)0U" end %> : e2pFlags); 84% end 85% end 86 return e2pFlags; 87% else 88 switch(irFlags) 89 { 90% enum.flags&.each do |flag| 91 case <%= enum.namespace %><%= if enum.parent_class_name then "::" + enum.parent_class_name 92end %>::<%= name %>::<%= flag %>: 93 return Es2panda<%= name %>::<%= enum.name_to_upper_snake %>_<%= flag %>; 94% end 95 default: 96 UNREACHABLE(); 97 } 98% end 99} 100%end 101 102% end 103 104// NOLINTEND(readability-function-size, readability-magic-numbers) 105 106// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) 107#define IS(public_name, e2p_name) \ 108 extern "C" bool Is##public_name(es2panda_AstNode *ast) \ 109 { \ 110 auto *node = reinterpret_cast<ir::AstNode *>(ast); \ 111 return node->Is##e2p_name(); \ 112 } 113 114% Es2pandaLibApi::ast_nodes&.each do |ast_node| 115% if ast_node != "AstNode" && ast_node != "TypeNode" 116IS(<%= ast_node %>, <%= ast_node %>) 117% end 118% end 119 120#undef IS 121 122// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) 123#define IS(public_name, e2p_name) \ 124 extern "C" bool ScopeIs##public_name(es2panda_Scope *scope) \ 125 { \ 126 auto *e2p_scope = reinterpret_cast<varbinder::Scope *>(scope); \ 127 return e2p_scope->Is##e2p_name(); \ 128 } 129 130% Es2pandaLibApi::scopes&.each do |scope| 131% if scope != "Scope" 132IS(<%= scope %>, <%= scope %>) 133% end 134% end 135 136#undef IS 137 138// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) 139#define IS(public_name, e2p_name) \ 140 extern "C" bool TypeIs##public_name(es2panda_Type *type) \ 141 { \ 142 auto *e2p_type = reinterpret_cast<checker::Type *>(type); \ 143 return e2p_type->Is##e2p_name(); \ 144 } 145 146% Es2pandaLibApi::ast_types&.each do |type| 147% if type != "Type" 148IS(<%= type %>, <%= type %>) 149% end 150% end 151 152#undef IS 153 154// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) 155#define IS(public_name, e2p_name) \ 156 extern "C" bool VariableIs##public_name(es2panda_Variable *variable) \ 157 { \ 158 auto *e2p_variable = reinterpret_cast<varbinder::Variable *>(variable); \ 159 return e2p_variable->Is##e2p_name(); \ 160 } 161 162% Es2pandaLibApi::ast_variables&.each do |variable| 163% if variable[1] != "Variable" 164IS(<%= variable[1] %>, <%= variable[1] %>) 165% end 166% end 167 168#undef IS 169 170// NOLINTNEXTLINE(readability-function-size) 171char const *AstNodeName(es2panda_AstNode *ast) 172{ 173% Es2pandaLibApi::ast_nodes&.each do |ast_node| 174% unless ["AstNode", "Expression", "Statement", "TypeNode"].include?(ast_node) 175 if(Is<%= ast_node %>(ast)) { 176 return "<%= ast_node %>"; 177 } 178% end 179% end 180 if(IsExpression(ast)) { 181 return "Expression"; 182 } 183 if(IsStatement(ast)) { 184 return "Statement"; 185 } 186 return "Unknown AstNode"; 187} 188 189// NOLINTBEGIN(performance-for-range-copy) 190% Es2pandaLibApi::classes&.each do |namespaceName, namespaceClasses| 191% namespaceClasses&.each do |className, classData| 192 193% classData.class_constructors&.each_with_index do |constructor, index| 194/* <%= constructor["raw_decl"] %> */ 195extern "C" <%= classData.constructor_type().lib_type_to_str() 196%>Create<%= className + constructor["overload"] 197%>([[maybe_unused]] es2panda_Context *context 198<%= constructor["args"]&.map { |arg| if arg.lib_args_to_str.strip() != "" then 199", " + "[[maybe_unused]] " + arg.lib_args_to_str end }&.join("") %>) 200{ 201% constructor["args"]&.each do |arg| 202 <%= arg.lib_cast["expression"] %> 203% end 204 auto *ctx = reinterpret_cast<Context *>(context); 205 auto *ctxAllocator = ctx->allocator; 206 return reinterpret_cast<<%= classData.constructor_type().lib_type_to_str() 207 %>>(<%= classData.constructor_cast["start"] 208 %><%= constructor["args"]&.map { |arg| arg.lib_cast["var_name"] }&.join(", ") %>)<%= 209 classData.constructor_cast["end"] %>; 210} 211 212% if classData.updater_allowed() 213 214/* Updater */ 215extern "C" <%= classData.constructor_type().lib_type_to_str() 216%>Update<%= className + constructor["overload"] 217%>([[maybe_unused]] es2panda_Context *context, es2panda_AstNode *original 218<%= constructor["args"]&.map { |arg| if arg.lib_args_to_str.strip() != "" then 219", " + "[[maybe_unused]] " + arg.lib_args_to_str end }&.join("") %>) 220{ 221% constructor["args"]&.each do |arg| 222 <%= arg.lib_cast["expression"] %> 223% end 224 auto *ctx = reinterpret_cast<Context *>(context); 225 auto *ctxAllocator = ctx->allocator; 226 auto newE2pNode = <%= classData.constructor_cast["start"] 227 %><%= constructor["args"]&.map { |arg| arg.lib_cast["var_name"] }&.join(", ") %><%= 228 classData.constructor_cast["end"] %>; 229 auto *e2pOriginal = reinterpret_cast<ir::AstNode *>(original); 230 newE2pNode->SetOriginalNode(e2pOriginal); 231 newE2pNode->SetParent(e2pOriginal->Parent()); 232 newE2pNode->SetRange(e2pOriginal->Range()); 233 return reinterpret_cast<<%= classData.constructor_type().lib_type_to_str() 234 %>>(newE2pNode); 235} 236 237%end # updater end 238 239% end # constructors end 240 241% classData.class_methods&.each_with_index do |method_info, index| 242/* <%= method_info["raw_decl"] %> */ 243extern "C" <%= method_info["return_type"].lib_type_to_str %><%= className + method_info["overload_name"] 244%>([[maybe_unused]] es2panda_Context *context<%= if classData.call_cast["call_var"] 245then ", " + classData.call_cast["call_var"] end %><%= 246method_info["args"]&.map { |arg| if arg.lib_args_to_str.strip() != "" then 247", " + "[[maybe_unused]] " + arg.lib_args_to_str end}&.join("") %>/*return_args:*/<%= method_info["return_arg_to_str"] %>) 248{ 249% method_info["args"]&.each do |arg| 250 <%= arg.lib_cast["expression"] %> 251% end 252 <%= method_info["return_expr"] %> 253} 254 255% end # methods end 256 257% end 258% end # classes end 259 260% Es2pandaLibApi::structs&.each do |structName, structData| 261 262% structData.struct_getters&.each_with_index do |method_info, index| 263extern "C" <%= method_info["return_type"].lib_type_to_str %><%= structName + method_info["name"] 264%>([[maybe_unused]] es2panda_Context *context<%= if structData.call_cast["call_var"] 265then structData.call_cast["call_var"] end %>/*return_args:*/<%= method_info["return_arg_to_str"] %>) 266{ 267% method_info["args"]&.each do |arg| 268 <%= arg.lib_cast["expression"] %> 269% end 270 <%= method_info["return_expr"] %> 271} 272 273% end # getters end 274 275% end # structs end 276 277 278% Es2pandaLibApi::print_stats 279// NOLINTEND(performance-for-range-copy) 280// NOLINTEND(cppcoreguidelines-pro-bounds-pointer-arithmetic, readability-non-const-parameter)