Class: MrubyInfoBridgeSignaturePlugin
- Inherits:
-
SignaturePlugin
- Object
- Node
- Plugin
- SignaturePlugin
- MrubyInfoBridgeSignaturePlugin
- Includes:
- MrubyBridgeSignaturePluginModule
- Defined in:
- lib/tecsgen/plugin/MrubyInfoBridgeSignaturePlugin.rb
Overview
mruby => TECS bridge
Copyright (C) 2008-2017 by TOPPERS Project
上記著作権者は,以下の(1)〜(4)の条件を満たす場合に限り,本ソフトウェ
ア(本ソフトウェアを改変したものを含む.以下同じ)を使用・複製・改
変・再配布(以下,利用と呼ぶ)することを無償で許諾する.
(1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
権表示,この利用条件および下記の無保証規定が,そのままの形でソー
スコード中に含まれていること.
(2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
用できる形で再配布する場合には,再配布に伴うドキュメント(利用
者マニュアルなど)に,上記の著作権表示,この利用条件および下記
の無保証規定を掲載すること.
(3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
用できない形で再配布する場合には,次のいずれかの条件を満たすこ
と.
(a) 再配布に伴うドキュメント(利用者マニュアルなど)に,上記の著
作権表示,この利用条件および下記の無保証規定を掲載すること.
(b) 再配布の形態を,別に定める方法によって,TOPPERSプロジェクトに
報告すること.
(4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
害からも,上記著作権者およびTOPPERSプロジェクトを免責すること.
また,本ソフトウェアのユーザまたはエンドユーザからのいかなる理
由に基づく請求からも,上記著作権者およびTOPPERSプロジェクトを
免責すること.
本ソフトウェアは,無保証で提供されているものである.上記著作権者お
よびTOPPERSプロジェクトは,本ソフトウェアに関して,特定の使用目的
に対する適合性も含めて,いかなる保証も行わない.また,本ソフトウェ
アの利用により直接的または間接的に生じたいかなる損害に関しても,そ
の責任を負わない.
$Id: MrubyInfoBridgeSignaturePlugin.rb 3050 2019-02-26 14:35:29Z okuma-top $
Constant Summary collapse
false
- @@b_gen_post_code_by_dependent =
true if gen_post_code is called by MrubyBridgeCellPlugin
false
Constants included from MrubyBridgeSignaturePluginModule
MrubyBridgeSignaturePluginModule::MrubyBridgePluginArgProc
Constants inherited from Plugin
Class Method Summary collapse
-
.gen_post_code(file) ⇒ Object
プラグインが CDL の POST コードを生成 tmp_plugin_post_code.cdl への出力.
- .gen_post_code_body(file) ⇒ Object
-
.set_gen_post_code_by_dependent ⇒ Object
by MrubyBriddeCellPlugin.
Instance Method Summary collapse
-
#check_name_and_return_type(func_head_array) ⇒ Object
check function name & return type.
-
#check_parameter_type(func_head_array) ⇒ Object
check paramter type.
-
#check_struct_member(struct_type, fh) ⇒ Object
構造体のメンバーの型のチェック.
-
#gen_cdl_file(file) ⇒ Object
CDL ファイルの生成 typedef, signature, celltype, cell コードを生成 file:: FILE 生成するファイル.
-
#gen_ep_func_body(file, b_singleton, ct_name, global_ct_name, sig_name, ep_name, func_name, func_global_name, func_type, params) ⇒ Object
受け口関数の本体コードを生成(頭部と末尾は別途出力) ct_name:: Symbol (プラグインで生成された) セルタイプ名 .Symbol として送られてくる.
- #gen_ep_func_body_bridge(file, b_singleton, ct_name, global_ct_name, sig_name, ep_name, func_name, func_global_name, func_type, params) ⇒ Object
- #gen_ep_func_body_bridge_init(file, b_singleton, ct_name, global_ct_name, sig_name, ep_name, func_name, func_global_name, func_type, params) ⇒ Object
-
#gen_preamble(file, b_singleton, ct_name, global_ct_name) ⇒ Object
受け口関数の preamble (C言語)を生成する 必要なら preamble 部に出力する file:: FILE 出力先ファイル b_singleton:: bool true if singleton ct_name:: Symbol global_ct_name:: string.
- #gen_preamble_bridge_func(file, b_singleton, ct_name, global_ct_name) ⇒ Object
- #gen_preamble_instance(file, b_singleton, ct_name, global_ct_name) ⇒ Object
- #gen_preamble_instance_initialize(file, b_singleton, ct_name, global_ct_name) ⇒ Object
- #gen_preamble_instance_proto(file, b_singleton, ct_name, global_ct_name) ⇒ Object
- #gen_preamble_mruby(file, b_singleton, ct_name, global_ct_name) ⇒ Object
- #get_type_map_ent(ttype) ⇒ Object
-
#initialize(signature, option) ⇒ MrubyInfoBridgeSignaturePlugin
constructor
プラグインインスタンスの初期化 戻り値、引数の型が使用可能なものかチェックする.
-
#new_cell(cell) ⇒ Object
gen_cdl_file で定義したセルタイプに 新しいセルが定義された cell のセルタイプの名前は @celltype_name.
- #register_ptr_type(ttype, fh) ⇒ Object
Methods included from MrubyBridgeSignaturePluginModule
#gen_ep_func_body_ptr, #gen_ep_func_body_struct, #gen_preamble_ptr, #gen_preamble_struct, #get_celltype_name, #ptrMrb2C, #set_auto_exclude, #set_exclude, #set_ignoreUnsigned, #set_include
Methods inherited from Plugin
#cdl_error, #check_plugin_arg, #gen_ep_func?, #gen_postamble, #parse_plugin_arg, #print_msg, #set_locale, #set_silent
Methods inherited from Node
#cdl_error, #cdl_error2, #cdl_error3, #cdl_info, #cdl_info2, #cdl_warning, #cdl_warning2, #get_locale, #locale_str, #set_locale
Constructor Details
#initialize(signature, option) ⇒ MrubyInfoBridgeSignaturePlugin
プラグインインスタンスの初期化
戻り値、引数の型が使用可能なものかチェックする
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/tecsgen/plugin/MrubyInfoBridgeSignaturePlugin.rb', line 62 def initialize( signature, option ) super if ! @@b_no_banner STDERR << "MrubyInfoBridgeSignaturePlugin: version 1.3.0 (Suitable for mruby ver 1.3.0 & ver 1.2.0). \n" @@b_no_banner = true end @b_ignoreUnsigned = false @includes = [] @excludes = [] @struct_list = { } @ptr_list = { } @auto_exclude_list = {} @b_auto_exclude = true # auto_exclude = true by default @plugin_arg_check_proc_tab = MrubyBridgePluginArgProc parse_plugin_arg @celltype_name = :"t#{@signature.get_global_name}" @init_celltype_name = :"#{@celltype_name}_Initializer" # this variable is sometimes not used. rhs coded directry. @class_name = :"T#{@signature.get_global_name}" @func_head_array = [] fh_array = [] if @includes.length > 0 && @excludes.length > 0 then cdl_error( "MRB1011 both include && exclude are specified" ) end if signature.get_function_head_array == nil then return # 以前に文法エラー発生 end signature.get_function_head_array.each{ |func_head| if @includes.length > 0 then if @includes.index func_head.get_name then dbgPrint "MrubyBridgePlugin: #{func_head.get_name} INCLUDED\n" fh_array << func_head else dbgPrint "MrubyBridgePlugin: #{func_head.get_name} NOT included\n" end elsif @excludes.length > 0 then if @excludes.index( func_head.get_name ) == nil then dbgPrint "MrubyBridgePlugin: #{func_head.get_name} NOT excluded\n" fh_array << func_head else dbgPrint "MrubyBridgePlugin: #{func_head.get_name} EXCLUDED\n" end else fh_array << func_head end } check_name_and_return_type fh_array check_parameter_type fh_array fh_array.each{ |fh| if @auto_exclude_list[ fh.get_name ] == nil then @func_head_array << fh else dbgPrint "MrubyBridgePlugin: auto_exclude #{fh.get_name}\n" end } if @func_head_array.length == 0 then cdl_error( "MRB1012 '$1' no function remained by exclude", @signature.get_name ) end end |
Class Method Details
.gen_post_code(file) ⇒ Object
プラグインが CDL の POST コードを生成
tmp_plugin_post_code.cdl への出力
468 469 470 471 472 473 |
# File 'lib/tecsgen/plugin/MrubyInfoBridgeSignaturePlugin.rb', line 468 def self.gen_post_code file dbgPrint "#{self.name}: gen_post_code\n" if ! @@b_gen_post_code_by_dependent then gen_post_code_body file end end |
.gen_post_code_body(file) ⇒ Object
480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 |
# File 'lib/tecsgen/plugin/MrubyInfoBridgeSignaturePlugin.rb', line 480 def self.gen_post_code_body file dbgPrint "#{self.name}: gen_post_code_body\n" file.print "\n // MrubyBridgeSignaturePlugin: MBP601\n" @@VM_celltypes.each{ |vm_name, instance_list| instance_list.each { |celltype_name, array| cell = array[0] if cell.get_celltype then ct_name = cell.get_celltype.get_name file.print <<EOT cell nMrubyInfo::#{ct_name}_Initializer #{vm_name}_#{ct_name}_Initializer{ }; EOT end } } file.print " // MBP602\n" @@ptr_list.each{ |name,tment| file.print <<EOT cell nMruby::#{name} C#{name} { }; EOT } file.print " // MBP603\n" @@struct_list.each{ |name,sttype| file.print <<EOT cell nMruby::#{name} C#{name} { }; EOT } if @@VM_celltypes == nil raise "MrubyBridgeSignaturePlugin: are0" end @@VM_celltypes.each{ |vm_name, instance_list| file.print " /* === VM name is '#{vm_name}' === (MBP610) */\n" init_cell_name = "#{vm_name}_TECSInitializer" file.print " cell nMruby::tTECSInitializer #{init_cell_name} {\n" instance_list.each { |celltype_name, array| ct_name = celltype_name file.print " cInitialize[] = #{vm_name}_#{ct_name}_Initializer.eInitialize;\n" } if @@VM_ptr_list[vm_name] then @@VM_ptr_list[vm_name].each{ |name, tment| file.print " cInitialize[] = C#{name}.eInitialize;\n" } end if @@VM_struct_list[vm_name] then @@VM_struct_list[vm_name].each{ |name, sttype| file.print " cInitialize[] = C#{name}.eInitialize;\n" } end file.print " };" } end |
.set_gen_post_code_by_dependent ⇒ Object
by MrubyBriddeCellPlugin
475 476 477 478 |
# File 'lib/tecsgen/plugin/MrubyInfoBridgeSignaturePlugin.rb', line 475 def self.set_gen_post_code_by_dependent # by MrubyBriddeCellPlugin dbgPrint "#{self.name}: set_gen_post_code_by_dependent\n" @@b_gen_post_code_by_dependent = true end |
Instance Method Details
#check_name_and_return_type(func_head_array) ⇒ Object
check function name & return type
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/tecsgen/plugin/MrubyInfoBridgeSignaturePlugin.rb', line 133 def check_name_and_return_type func_head_array b_init = false; b_init_cell = false func_head_array.each{ |func_head| if( func_head.get_name == :initialize )then cdl_warning( "MRW2001 initialize: internally defined. change to initialize_cell in ruby" ) b_init = true elsif( func_head.get_name == :initialize_cell )then b_init_cell = true end rtype = func_head.get_return_type.get_original_type case rtype when BoolType, IntType, FloatType, VoidType else if @b_auto_exclude then cdl_info( "MRI0001 cannot return type $1, $2 automatcally excluded", rtype.get_type_str, func_head.get_name ) @auto_exclude_list[ func_head.get_name ] = func_head else cdl_error( "MRB1001 cannot return type $1", rtype.get_type_str ) end end } if( b_init && b_init_cell )then cdl_warning( "MRB1002 initialize: internally defined. change to initialize_cell in ruby" ) end end |
#check_parameter_type(func_head_array) ⇒ Object
check paramter type
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
# File 'lib/tecsgen/plugin/MrubyInfoBridgeSignaturePlugin.rb', line 160 def check_parameter_type func_head_array # check type of parameters func_head_array.each{ |fh| fh.get_paramlist.get_items.each{ |param_decl| case param_decl.get_direction when :SEND, :RECEIVE if @b_auto_exclude then cdl_info( "MRI0002 $1: $2 parameter cannot be used in mruby Bridge, $3 automatcally excluded", param_decl.get_name, param_decl.get_direction.to_s.downcase, fh.get_name ) @auto_exclude_list[ fh.get_name ] = fh else cdl_error( "MRB1003 $1: $2 parameter cannot be used in mruby Bridge", param_decl.get_name, param_decl.get_direction.to_s.downcase ) end end type = param_decl.get_type type_org = type.get_original_type type_str = type.get_type_str + type.get_type_str_post b_ng = false case type_org when IntType case type_org.get_bit_size when 8, 16, 32, 64 when -1, -2, -3, -4, -11 else b_ng = true end when BoolType when FloatType when PtrType ttype_org = type_org.get_type # ポインタの指している先の型 ttype = ttype_org.get_original_type # 上記の typedef されている場合、元の型 register_ptr_type ttype_org, fh if( type_org.get_string.to_s == "-1" ) then case param_decl.get_direction when :OUT, :INOUT if @b_auto_exclude then cdl_info( "MRB9999 string specifier without length cannot be used for out & inout parameter, $1 automatcally excluded", fh.get_name ) @auto_exclude_list[ fh.get_name ] = fh else cdl_error( "MRB9999 string specifier without length cannot be used for out & inout parameter") end end end case ttype when IntType bit_size = ttype.get_bit_size # if bit_size < 0 && bit_size != -1 then # b_ng = true # end when FloatType when BoolType when StructType if( type_org.get_size || type_org.get_string || type_org.get_count ) then if @b_auto_exclude then cdl_info( "MRI9999 $1: size_is, count_is, string cannot be specified for struct pointer, $2 automatcally excluded", param_decl.get_name, fh.get_name ) @auto_exclude_list[ fh.get_name ] = fh else cdl_error( "MRB1004 $1: size_is, count_is, string cannot be specified for struct pointer", param_decl.get_name ) end end check_struct_member ttype_org, fh else b_ng = true end when StructType check_struct_member type_org, fh else # ArrayType, FuncType, EnumType, VoidType b_ng = true end if b_ng then if @b_auto_exclude then cdl_info( "MRI9999 $1: type $2 cannot be used in mruby Bridge, $3 automatcally excluded", param_decl.get_name, type_str, fh.get_name ) @auto_exclude_list[ fh.get_name ] = fh else cdl_error( "MRB1005 $1: type $2 cannot be used in mruby Bridge", param_decl.get_name, type_str ) end end } } end |
#check_struct_member(struct_type, fh) ⇒ Object
構造体のメンバーの型のチェック
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 |
# File 'lib/tecsgen/plugin/MrubyInfoBridgeSignaturePlugin.rb', line 248 def check_struct_member struct_type, fh #p "tag name:#{struct_type.get_name}" # sttype = Namespace.find_tag( struct_type.get_name ) sttype = struct_type.get_original_type if sttype.get_name == nil then if @b_auto_exclude then cdl_info( "MRI9999 tagless-struct cannot be handled, $1 automatcally excluded", fh.get_name ) @auto_exclude_list[ fh.get_name ] = fh return # 登録しないように打ち切る else cdl_error( "MRB10007 tagless-struct cannot be handled") end end sttype.get_members_decl.get_items.each { |d| t = d.get_type.get_original_type case t when IntType, FloatType, BoolType else if @b_auto_exclude then cdl_info( "MRI9999 $1: type $2 not allowed for struct member, $3 automatcally excluded", d.get_name, d.get_type.get_type_str + d.get_type.get_type_str_post, fh.get_name ) @auto_exclude_list[ fh.get_name ] = fh return # 登録しないように打ち切る else cdl_error( "MRB1006 $1: type $2 not allowed for struct member", d.get_name, d.get_type.get_type_str + d.get_type.get_type_str_post ) end end } st_name = :"t{}" if @struct_list[ sttype.get_name ] == nil then # print_msg " MrubyBridgePlugin: [struct] #{struct_type.get_type_str} => class TECS::Struct#{sttype.get_name}\n" print " MrubyBridgePlugin: [struct] #{struct_type.get_type_str} => class TECS::Struct#{sttype.get_name}\n" @struct_list[ sttype.get_name ] = sttype end end |
#gen_cdl_file(file) ⇒ Object
CDL ファイルの生成
typedef, signature, celltype, cell コードを生成
- file
-
FILE 生成するファイル
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 |
# File 'lib/tecsgen/plugin/MrubyInfoBridgeSignaturePlugin.rb', line 320 def gen_cdl_file(file) # ブリッジセルタイプの生成 if @@celltypes[ @celltype_name ] == nil then @@celltypes[ @celltype_name ] = [ self ] @@init_celltypes[ @init_celltype_name ] = true print_msg <<EOT MrubyBridgePlugin: [signature] #{@signature.get_namespace_path} => [celltype] nMrubyInfo::#{@celltype_name} => [class] TECS::#{@class_name} EOT file.print <<EOT /* * MrubyBridgeSignaturePlugin: * signature=#{@signature.get_namespace_path} * * => celltype=nMrubyInfo::#{@celltype_name} * (bridge cell 's celltype; generated in this file) * cell nMrubyInfo::#{@celltype_name} BridgeCellName { cTECS = CellName.eEntry; }; * where eEntry's signature must be #{@signature.get_namespace_path}. * => class=TECS::#{@class_name} * (mruby’s class; accessible from your script) * bridge = TECS::#{@class_name}.new("BridgeCellName") */ import( <mruby.cdl> ); /**** Ruby => TECS Bridge Celltype (MBP500) ****/ namespace nMrubyInfo{ // bridge celltype [singleton, idx_is_id,active] // not actually active, to avoid warning W1002, W1007 celltype #{@celltype_name} { [dynamic,optional] call #{@signature.get_namespace_path.to_s} cTECS; call nTECSInfo::sTECSInfo cTECSInfo; [dynamic,optional] call nTECSInfo::sEntryInfo cEntryInfo; [dynamic,optional] call nTECSInfo::sSignatureInfo cSignatureInfo; [dynamic,optional] call nTECSInfo::sRawEntryDescriptorInfo cRawEntryDescriptorInfo; attr { [omit] char_t *VMname = "VM"; [omit] char_t *bridgeName = C_EXP( "$cell$" ); }; }; // bridge initializer celltype celltype #{@init_celltype_name} { entry nMruby::sInitializeTECSBridge eInitialize; }; }; // Bridge Cell cell nMrubyInfo::t#{@signature.get_global_name} MrubyInfoBridge_#{@signature.get_global_name} { // cTECS = Sample.eEnt; cTECSInfo = TECSInfo.eTECSInfo; // bridgeName = "Simple"; }; EOT # 構造体セルタイプの生成 @struct_list.each{ |name, sttype| if @@struct_list[ name ] == nil then file.print <<EOT namespace nMrubyInfo{ [singleton] celltype #{name} { entry sInitializeTECSBridge eInitialize; }; }; EOT @@struct_list[ name ] = sttype end } else cdl_info( "MRBW001 MrubyBridgePlugin: signature '$1' duplicate. ignored current one", @signature.get_namespace_path ) @@celltypes[ @celltype_name ] << self end end |
#gen_ep_func_body(file, b_singleton, ct_name, global_ct_name, sig_name, ep_name, func_name, func_global_name, func_type, params) ⇒ Object
受け口関数の本体コードを生成(頭部と末尾は別途出力)
- ct_name
-
Symbol (プラグインで生成された) セルタイプ名 .Symbol として送られてくる
542 543 544 545 546 547 548 549 550 551 552 553 554 |
# File 'lib/tecsgen/plugin/MrubyInfoBridgeSignaturePlugin.rb', line 542 def gen_ep_func_body( file, b_singleton, ct_name, global_ct_name, sig_name, ep_name, func_name, func_global_name, func_type, params ) if @@celltypes[ ct_name ] then gen_ep_func_body_bridge( file, b_singleton, ct_name, global_ct_name, sig_name, ep_name, func_name, func_global_name, func_type, params ) elsif @@init_celltypes[ ct_name ] then gen_ep_func_body_bridge_init( file, b_singleton, ct_name, global_ct_name, sig_name, ep_name, func_name, func_global_name, func_type, params ) elsif @@ptr_list[ ct_name ] then gen_ep_func_body_ptr( file, b_singleton, ct_name, global_ct_name, sig_name, ep_name, func_name, func_global_name, func_type, params ) elsif @@struct_list[ ct_name ] then gen_ep_func_body_struct( file, b_singleton, ct_name, global_ct_name, sig_name, ep_name, func_name, func_global_name, func_type, params ) else raise "MrubyBridgeSignaturePlugin: Unknown #{ct_name}" end end |
#gen_ep_func_body_bridge(file, b_singleton, ct_name, global_ct_name, sig_name, ep_name, func_name, func_global_name, func_type, params) ⇒ Object
556 557 558 |
# File 'lib/tecsgen/plugin/MrubyInfoBridgeSignaturePlugin.rb', line 556 def gen_ep_func_body_bridge( file, b_singleton, ct_name, global_ct_name, sig_name, ep_name, func_name, func_global_name, func_type, params ) raise "MrubyBridgeSignaturePlugin: unexpected " end |
#gen_ep_func_body_bridge_init(file, b_singleton, ct_name, global_ct_name, sig_name, ep_name, func_name, func_global_name, func_type, params) ⇒ Object
560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 |
# File 'lib/tecsgen/plugin/MrubyInfoBridgeSignaturePlugin.rb', line 560 def gen_ep_func_body_bridge_init( file, b_singleton, ct_name, global_ct_name, sig_name, ep_name, func_name, func_global_name, func_type, params ) file.print <<EOT // CELLCB *p_cellcb = GET_CELLCB( idx ); /* no error check */ /* MBP700 */ struct RClass *rc; rc = mrb_define_class_under( mrb, TECS, \"#{@class_name}\", mrb->object_class ); mrb_define_method( mrb, rc, "initialize", MrubyBridge_#{@celltype_name}_initialize, MRB_ARGS_REQ(1) ); MRB_SET_INSTANCE_TT(rc, MRB_TT_DATA); EOT @func_head_array.each{ |f| if ! f.is_function? then next end if f.get_name != :initialize then func_name = f.get_name else func_name = :initialize_cell end ret_type = f.get_return_type n_param = 0 f.get_paramlist.get_items.each{ |param| case param.get_direction when :IN, :INOUT, :OUT n_param += 1 when :SEND, :RECEIVE raise "MrubyBridgeSignaturePlugin: send, receive" end } if n_param > 0 then p_str = "MRB_ARGS_REQ( #{n_param} )" else p_str = "MRB_ARGS_NONE()" end file.print <<EOT mrb_define_method( mrb, rc, "#{func_name}", MrubyBridge_#{@celltype_name}_#{func_name}, #{p_str} ); EOT } end |
#gen_preamble(file, b_singleton, ct_name, global_ct_name) ⇒ Object
受け口関数の preamble (C言語)を生成する
必要なら preamble 部に出力する
- file
-
FILE 出力先ファイル
- b_singleton
-
bool true if singleton
- ct_name
-
Symbol
- global_ct_name
-
string
607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 |
# File 'lib/tecsgen/plugin/MrubyInfoBridgeSignaturePlugin.rb', line 607 def gen_preamble( file, b_singleton, ct_name, global_ct_name ) if @@celltypes[ ct_name ] then gen_preamble_mruby( file, b_singleton, ct_name, global_ct_name ) gen_preamble_instance( file, b_singleton, ct_name, global_ct_name ) gen_preamble_instance_initialize( file, b_singleton, ct_name, global_ct_name ) gen_preamble_bridge_func( file, b_singleton, ct_name, global_ct_name ) elsif @@init_celltypes[ ct_name ] then gen_preamble_mruby( file, b_singleton, ct_name, global_ct_name ) gen_preamble_instance_proto( file, b_singleton, ct_name, global_ct_name ) elsif @@ptr_list[ ct_name ] then gen_preamble_ptr( file, b_singleton, ct_name, global_ct_name ) elsif @@struct_list[ ct_name ] then gen_preamble_struct( file, b_singleton, ct_name, global_ct_name ) else raise "MrubyBridgeSignaturePlugin: MrubyBridgeSignaturePlugin: Unknown #{ct_name}" end end |
#gen_preamble_bridge_func(file, b_singleton, ct_name, global_ct_name) ⇒ Object
783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 |
# File 'lib/tecsgen/plugin/MrubyInfoBridgeSignaturePlugin.rb', line 783 def gen_preamble_bridge_func( file, b_singleton, ct_name, global_ct_name ) @func_head_array.each{ |f| if ! f.is_function? then next end if f.get_name != :initialize then func_name = f.get_name else func_name = :initialize_cell end ret_type = f.get_return_type ret_type0 = f.get_return_type.get_original_type b_void = ret_type0.is_void? plist = f.get_paramlist.get_items file.print <<EOT /* bridge function (MBP101) */ mrb_value MrubyBridge_#{ct_name}_#{func_name}( mrb_state *mrb, mrb_value self ) { /* cellcbp (MBP105) */ // CELLCB *p_cellcb = ((struct tecs_#{@celltype_name} *)DATA_PTR(self))->cbp; EOT file.print " /* variables for return & parameter (MBP110) */\n" if ! b_void then file.print " ", ret_type.get_type_str, "\tret_val", ret_type.get_type_str_post, ";\n" end arg_str = "" n_param = 0 n_scalar = 0 n_ptr = 0 n_struct = 0 plist.each{ |param| case param.get_direction when :IN, :INOUT, :OUT type = param.get_type.get_original_type case type when IntType file.print " mrb_int mrb_", param.get_name, ";\n" file.print " #{param.get_type.get_type_str} #{param.get_name}#{param.get_type.get_type_str_post};\n" arg_str += "i" n_param += 1 n_scalar += 1 when FloatType file.print " mrb_float mrb_", param.get_name, ";\n" file.print " #{param.get_type.get_type_str} #{param.get_name}#{param.get_type.get_type_str_post};\n" arg_str += "f" n_param += 1 n_scalar += 1 when BoolType file.print " mrb_value mrb_", param.get_name, ";\n" file.print " #{param.get_type.get_type_str} #{param.get_name}#{param.get_type.get_type_str_post};\n" arg_str += "o" n_param += 1 n_scalar += 1 when PtrType file.print " mrb_value mrb_", param.get_name, ";\n" file.print " #{param.get_type.get_type_str} #{param.get_name}#{param.get_type.get_type_str_post};\n" arg_str += "o" n_param += 1 n_ptr += 1 when StructType file.print " mrb_value mrb_", param.get_name, ";\n" file.print " #{param.get_type.get_type_str} *#{param.get_name}#{param.get_type.get_type_str_post};\n" arg_str += "o" n_param += 1 n_struct += 1 else raise "MrubyBridgeSignaturePlugin: Unknown type" end end } if n_param > 0 then file.print " /* retrieve arguments (MBP111) */\n" file.print " mrb_get_args(mrb, \"#{arg_str}\"" plist.each{ |param| case param.get_direction when :IN, :INOUT, :OUT type = param.get_type.get_original_type case type when IntType file.print ", &mrb_", param.get_name when FloatType file.print ", &mrb_", param.get_name when BoolType file.print ", &mrb_", param.get_name when PtrType file.print ", &mrb_", param.get_name when StructType file.print ", &mrb_", param.get_name else raise "MrubyBridgeSignaturePlugin: Unknown type" end end } file.print " );\n" if n_scalar > 0 || n_struct > 0 then file.print " /* convert mrb to C (MBP112) */\n" end plist.each{ |param| case param.get_direction when :IN, :INOUT, :OUT type = param.get_type.get_original_type case type when IntType ttype = type.get_original_type tment = get_type_map_ent ttype file.print " VALCHECK_#{tment[1]}( mrb, mrb_#{param.get_name} );\n" file.print " #{param.get_name} = (#{param.get_type.get_type_str})mrb_#{param.get_name};\n" when FloatType file.print " #{param.get_name} = (#{param.get_type.get_type_str})mrb_#{param.get_name};\n" when BoolType file.print " #{param.get_name} = mrb_test( mrb_#{param.get_name} );\n" when PtrType ttype = type.get_type.get_original_type case ttype when StructType file.print " CHECK_STRUCT( #{ttype.get_name}, mrb_#{param.get_name} );\n" file.print " #{param.get_name} = (struct #{ttype.get_name}*)DATA_PTR(mrb_#{param.get_name});\n" when IntType when FloatType when BoolType else raise "MrubyBridgeSignaturePlugin: cannot handle type" end when StructType file.print " CHECK_STRUCT( #{type.get_name}, mrb_#{param.get_name} );\n" file.print " #{param.get_name} = (struct #{type.get_name}*)DATA_PTR(mrb_#{param.get_name});\n" else raise( "MrubyBridgeSignaturePlugin: canot treat class" ) end end } if n_ptr > 0 then file.print " /* convert mrb to C for pointer types (MBP113) */\n" end plist.each{ |param| case param.get_direction when :IN, :INOUT, :OUT type = param.get_type.get_original_type case type when IntType when FloatType when BoolType when PtrType case type.get_type.get_original_type when StructType when IntType ptrMrb2C file, type, param when FloatType ptrMrb2C file, type, param when BoolType ptrMrb2C file, type, param else raise "MrubyBridgeSignaturePlugin: cannot handle type" end when StructType else raise( "MrubyBridgeSignaturePlugin: canot treat class" ) end end } end file.print <<EOT /* calling target (MBP120) */ cTECS_set_descriptor( ((struct tecs_tsSample *)DATA_PTR(self))->desc ); EOT if ! b_void then file.print " ret_val = " else file.print " " end delim = "" file.print "cTECS_", f.get_name, "( " plist.each{ |param| if param.get_type.get_original_type.kind_of? StructType then aster = "*" else aster = "" end file.print delim, aster, param.get_name delim = ", " } file.print " );\n" file.print " /* return (MBP130) */\n" case ret_type0 when BoolType file.print " return ret_val ? mrb_true_value() : mrb_false_value();\n" when IntType file.print " return mrb_fixnum_value( ret_val );\n" when FloatType file.print " return mrb_float_value( mrb, ret_val );\n" when VoidType file.print " return mrb_nil_value();\n" else raise "MrubyBridgeSignaturePlugin: unknown type" end file.print "}\n" } end |
#gen_preamble_instance(file, b_singleton, ct_name, global_ct_name) ⇒ Object
648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 |
# File 'lib/tecsgen/plugin/MrubyInfoBridgeSignaturePlugin.rb', line 648 def gen_preamble_instance( file, b_singleton, ct_name, global_ct_name ) # 「#1005 MrubyBridgePlugin-test のビルドに失敗」にて追加 # 「#1004 idx_is_id が true の場合(domain の場合は未指定でも true) の CBP のプロトタイプ宣言」にて不要になる見込み nsp = NamespacePath.new( :nMrubyInfo, true ) nsp.append! ct_name ct = Namespace.find nsp if ct.idx_is_id_act? then if ct.has_CB? then inib_cb = "CB" elsif ct.has_INIB? then inib_cb = "INIB" else inib_cb = nil end if inib_cb then ct.get_cell_list.each{ |cell| if cell.is_generate? then name_array = ct.get_name_array( cell ) file.print "extern #{ct.get_global_name}_CB #{cell.get_global_name}_#{inib_cb};\n" end } end end file.print <<EOT /* RData MBP001 */ static void #{@celltype_name}_free( mrb_state *mrb, void *p ) { if( p ) (void)mrb_free( mrb, p ); } /* RData MBP002 */ struct mrb_data_type data_type_#{@celltype_name} = { "#{@celltype_name}", #{@celltype_name}_free }; /* RData MBP003 */ struct tecs_#{@celltype_name} { Descriptor( #{@signature.get_global_name} ) desc; }; #ifndef MRUBYINFOBRIDGE_NAME_LEN #define MRUBYINFOBRIDGE_NAME_LEN 256 #endif EOT end |
#gen_preamble_instance_initialize(file, b_singleton, ct_name, global_ct_name) ⇒ Object
727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 |
# File 'lib/tecsgen/plugin/MrubyInfoBridgeSignaturePlugin.rb', line 727 def gen_preamble_instance_initialize( file, b_singleton, ct_name, global_ct_name ) file.print <<EOT /* MBP100 */ mrb_value MrubyBridge_#{@celltype_name}_initialize( mrb_state *mrb, mrb_value self) { mrb_value name; struct tecs_#{@celltype_name} *tecs_desc; Descriptor( nTECSInfo_sRawEntryDescriptorInfo ) rawEntryDescDesc; Descriptor( nTECSInfo_sEntryInfo ) entryDesc; Descriptor( nTECSInfo_sSignatureInfo ) signatureDesc; Descriptor( #{@signature.get_global_name} ) cellEntryDesc; char_t tecs_name[ MRUBYINFOBRIDGE_NAME_LEN ]; void *rawDesc; /* set DATA_TYPE earlier to avoid SEGV */ DATA_TYPE( self ) = &data_type_#{@celltype_name}; mrb_get_args(mrb, "o", &name ); if( mrb_type( name ) != MRB_TT_STRING ){ mrb_raise(mrb, E_NAME_ERROR, "cell name not string"); } if( cTECSInfo_findRawEntryDescriptor( RSTRING_PTR( name ), 0, &rawEntryDescDesc, &entryDesc ) != E_OK ){ mrb_raise( mrb, E_ARGUMENT_ERROR, "MrubyInfoBridgeSignaturePlugin: path not found" ); } else{ syslog( LOG_NOTICE, "MrubyInfoBridgePlugin: %s: found", RSTRING_PTR( name ) ); } // retrieve Signature Name from EntryInfo to check cEntryInfo_set_descriptor( entryDesc ); cEntryInfo_getSignatureInfo( &signatureDesc ); cSignatureInfo_set_descriptor( signatureDesc ); cSignatureInfo_getName( tecs_name, MRUBYINFOBRIDGE_NAME_LEN ); if( strncmp( tecs_name, "#{@signature.get_name}", MRUBYINFOBRIDGE_NAME_LEN ) != 0 ){ mrb_raise( mrb, E_ARGUMENT_ERROR, "MrubyInfoBridgeSignaturePlugin: signature name mismatch" ); } else{ syslog( LOG_NOTICE, "MrubyInfoBridgePlugin: signature name matched: %s", "#{@signature.get_name}" ); } // retrieve Cell's Entry Descriptor cRawEntryDescriptorInfo_set_descriptor( rawEntryDescDesc ); cRawEntryDescriptorInfo_getRawDescriptor( 0, &rawDesc ); cellEntryDesc.vdes = (struct tag_#{@signature.get_global_name}_VDES *)rawDesc; tecs_desc = (struct tecs_#{@celltype_name} *)mrb_malloc(mrb, sizeof(struct tecs_#{@celltype_name}) ); tecs_desc->desc = cellEntryDesc; DATA_PTR( self ) = (void *)tecs_desc; return self; } EOT end |
#gen_preamble_instance_proto(file, b_singleton, ct_name, global_ct_name) ⇒ Object
700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 |
# File 'lib/tecsgen/plugin/MrubyInfoBridgeSignaturePlugin.rb', line 700 def gen_preamble_instance_proto( file, b_singleton, ct_name, global_ct_name ) file.print <<EOT // Prototype MBP400 mrb_value MrubyBridge_#{@celltype_name}_initialize( mrb_state *mrb, mrb_value self); EOT @func_head_array.each{ |f| if ! f.is_function? then next end if f.get_name != :initialize then func_name = f.get_name else func_name = :initialize_cell end ret_type = f.get_return_type ret_type0 = f.get_return_type.get_original_type b_void = ret_type0.is_void? plist = f.get_paramlist.get_items file.print <<EOT mrb_value MrubyBridge_#{@celltype_name}_#{func_name}( mrb_state *mrb, mrb_value self ); EOT } end |
#gen_preamble_mruby(file, b_singleton, ct_name, global_ct_name) ⇒ Object
625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 |
# File 'lib/tecsgen/plugin/MrubyInfoBridgeSignaturePlugin.rb', line 625 def gen_preamble_mruby( file, b_singleton, ct_name, global_ct_name ) file.print <<EOT /* MBP: MrubyBridgePlugin: MBP000 */ #include "mruby.h" #include "mruby/class.h" #include "mruby/data.h" #include "mruby/string.h" #include "TECSPointer.h" #include "TECSStruct.h" #include "t_syslog.h" #if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) #define DLLEXPORT __declspec(dllexport) #else #define DLLEXPORT #endif #ifndef NULL #define NULL 0 #endif EOT end |
#get_type_map_ent(ttype) ⇒ Object
302 303 304 305 306 307 308 309 310 311 312 313 314 315 |
# File 'lib/tecsgen/plugin/MrubyInfoBridgeSignaturePlugin.rb', line 302 def get_type_map_ent ttype # structure type is registerd in check_struct_member if ttype.kind_of? StructType return end tstr = ttype.get_type_str.sub( /const /, "" ) # const は無視 tstr = tstr.sub( /volatile /, "" ) # volatile も無視 if @b_ignoreUnsigned then tstr = tstr.sub( /unsigned /, "" ) # volatile も無視 tstr = tstr.sub( /uint/, "int" ) # volatile も無視 tstr = tstr.sub( /[cs]char/, "char" ) # volatile も無視 end return @@TYPE_MAP[ tstr.to_sym ] end |
#new_cell(cell) ⇒ Object
gen_cdl_file で定義したセルタイプに 新しいセルが定義された
cell のセルタイプの名前は @celltype_name
403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 |
# File 'lib/tecsgen/plugin/MrubyInfoBridgeSignaturePlugin.rb', line 403 def new_cell cell if cell.get_celltype.get_name != @celltype_name then return end join = cell.get_join_list.get_item :VMname if join then vm_name = CDLString.remove_dquote(join.get_rhs.to_s).to_sym else vm_name = :"VM" end if @@VM_list[ vm_name ] == nil then @@VM_list[ vm_name ] = true initializer_celltype_cdl = "#{$gen}/#{cell.get_name}Initializer.cdl" file = CFile.open( initializer_celltype_cdl, "w" ) # TECS 初期化セル(プロトタイプ宣言) print_msg " MrubyBridgePlugin: join your VM's cInitialize to #{vm_name}_TECSInitializer.eInitialize\n" file.print <<EOT // prototype of TECSInitializer (MBP510) cell nMruby::tTECSInitializer #{vm_name}_TECSInitializer; EOT file.close Generator.parse( initializer_celltype_cdl, self ) end if @@VM_celltypes[ vm_name ] then vma = @@VM_celltypes[ vm_name ] if vma[ @celltype_name ] then vma[ @celltype_name ] << cell else vma[ @celltype_name ] = [cell] @@VM_celltypes[ vm_name ] = vma end else vma = { } vma[ @celltype_name ] = [cell] @@VM_celltypes[ vm_name ] = vma end @struct_list.each{ |stname, sttype| if @@VM_struct_list[ vm_name ] then @@VM_struct_list[ vm_name ][ sttype.get_name ] = sttype else @@VM_struct_list[ vm_name ] = { sttype.get_name => sttype } end } @ptr_list.each{ |ptr_celltype_name, tment| if @@VM_ptr_list[ vm_name ] then @@VM_ptr_list[ vm_name ][ ptr_celltype_name ] = tment else @@VM_ptr_list[ vm_name ] = { ptr_celltype_name => tment } end } end |
#register_ptr_type(ttype, fh) ⇒ Object
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 |
# File 'lib/tecsgen/plugin/MrubyInfoBridgeSignaturePlugin.rb', line 284 def register_ptr_type ttype, fh t_org = ttype.get_original_type tment = get_type_map_ent t_org if tment == nil then return # cdl_error( "MRB1008 unknown pointer type '$1'", ttype.get_type_str ) end ptr_celltype_name = :"t#{tment[1]}Pointer" if @@ptr_list[ ptr_celltype_name ] == nil then # print_msg " MrubyBridgePlugin: [pointer] #{ttype.get_type_str}* => class TECS::#{tment[1]}Pointer\n" print " MrubyBridgePlugin: [pointer] #{ttype.get_type_str}* => class TECS::#{tment[1]}Pointer\n" @@ptr_list[ ptr_celltype_name ] = tment end if @ptr_list[ ptr_celltype_name ] == nil then @ptr_list[ ptr_celltype_name ] = tment end end |