Class: MrubyBridgeSignaturePlugin
- Inherits:
-
SignaturePlugin
- Object
- Node
- Plugin
- SignaturePlugin
- MrubyBridgeSignaturePlugin
- Defined in:
- lib/tecsgen/plugin/MrubyBridgeSignaturePlugin.rb
Overview
Todo: 生成するもの
gen_cdl_file
ブリッジ初期化セルタイプ (シグニチャごと)
@@init_celltypes に記録
ブリッジセルタイプ (シグニチャごと)
@@celltypes に記録
構造体セルタイプ
@@struct_list に記録
new_cell
TECS 初期化セル(プロトタイプ宣言)
@@VM_init_cells に記録
@@VM_struct_list に記録
@@VM_ptr_list に記録
gen_post_code
構造体初期化セル
ポインタ初期化セル
TECS 初期化セル
ep_func の作成
signature, ポインタ、構造体 … 初期化受け口=mruby VM への登録
ポインタ
preamble の作成
ポインタ、構造体 … アクセス用コードの生成
signature … ブリッジ関数のプロトタイプ宣言
postamble の作成
signature … ブリッジ関数の定義
Constant Summary collapse
- MrubyBridgePluginArgProc =
プラグイン引数名 => Proc
{ "ignoreUnsigned" => Proc.new {|obj, rhs| obj.set_ignoreUnsigned rhs }, "include" => Proc.new {|obj, rhs| obj.set_include rhs }, "exclude" => Proc.new {|obj, rhs| obj.set_exclude rhs }, "auto_exclude" => Proc.new {|obj, rhs| obj.set_auto_exclude rhs }, }
false
- @@b_gen_post_code_by_dependent =
true if gen_post_code is called by MrubyBridgeCellPlugin
false
- @@celltypes =
{celltype_name => [ BridgePlugin のインスタンスの配列 }
{ }
- @@init_celltypes =
{celltype_name => [ BridgePlugin のインスタンスの配列 }
{ }
- @@struct_list =
struct_name=>StructType
{ }
- @@ptr_list =
@@TYPE_MAP の対応するもの
{ }
- @@VM_list =
VM_name => true
{ }
- @@VM_celltypes =
VM_name => { @celltype_name => セルの配列 }
{ }
- @@VM_struct_list =
name=>StructType
{ }
- @@VM_ptr_list =
{ VM_name => @@TYPE_MAP の対応するもの }
{ }
- @@TYPE_MAP =
type_str class GET_SET
{ # type_str class GET_SET :char_t => [:char_t, "Char", :Char, :INT], :uchar_t => [:uchar_t, "UChar", :Char, :INT], :schar_t => [:schar_t, "SChar", :Char, :INT], :bool_t => [:bool_t, "Bool", :Bool, :BOOL], :int8_t => [:int8_t, "Int8", :Int, :INT], :int16_t => [:int16_t, "Int16", :Int, :INT], :int32_t => [:int32_t, "Int32", :Int, :INT], :int64_t => [:int64_t, "Int64", :Int, :INT], :uint8_t => [:uint8_t, "UInt8", :Int, :INT], :uint16_t => [:uint16_t, "UInt16", :Int, :INT], :uint32_t => [:uint32_t, "UInt32", :Int, :INT], :uint64_t => [:uint64_t, "UInt64", :Int, :INT], :int => [:int, "Int", :Int, :INT], :char => [:char, "Char", :Char, :INT], # char は char_t として扱う :short => [:short, "Short", :Int, :INT], :long => [:long, "Long", :Int, :INT], :"unsigned char" => [:uchar_t, "UChar", :Char, :INT], :"unsigned int" => [:"unsigned int", "UInt", :Int, :INT], :"unsigned short" => [:"unsigned short", "UShort", :Int, :INT], :"unsigned long" => [:"unsigned long", "ULong", :Int, :INT], :"signed char" => [:schar_t, "SChar", :Char, :INT], :"signed int" => [:int, "Int", :Int, :INT], :"signed short" => [:short, "Short", :Int, :INT], :"signed long" => [:long, "Long", :Int, :INT], :float32_t => [:float32_t, "Float32", :Float, :FLOAT], :double64_t => [:double64_t, "Double64", :Float, :FLOAT], :float => [:float, "Float32", :Float, :FLOAT], :double => [:double, "Double64", :Float, :FLOAT] }
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_ep_func_body_ptr(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_struct(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
- #gen_preamble_ptr(file, b_singleton, ct_name, global_ct_name) ⇒ Object
- #gen_preamble_struct(file, b_singleton, ct_name, global_ct_name) ⇒ Object
- #get_celltype_name ⇒ Object
- #get_type_map_ent(ttype) ⇒ Object
-
#initialize(signature, option) ⇒ MrubyBridgeSignaturePlugin
constructor
プラグインインスタンスの初期化 戻り値、引数の型が使用可能なものかチェックする.
-
#new_cell(cell) ⇒ Object
gen_cdl_file で定義したセルタイプに 新しいセルが定義された cell のセルタイプの名前は @celltype_name.
- #ptrMrb2C(file, type, param) ⇒ Object
- #register_ptr_type(ttype, fh) ⇒ Object
-
#set_auto_exclude(rhs) ⇒ Object
プラグイン引数 auto_exclude.
-
#set_exclude(rhs) ⇒ Object
プラグイン引数 exclude.
-
#set_ignoreUnsigned(rhs) ⇒ Object
プラグイン引数 ignoreUnsigned.
-
#set_include(rhs) ⇒ Object
プラグイン引数 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) ⇒ MrubyBridgeSignaturePlugin
プラグインインスタンスの初期化
戻り値、引数の型が使用可能なものかチェックする
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 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 |
# File 'lib/tecsgen/plugin/MrubyBridgeSignaturePlugin.rb', line 135 def initialize(signature, option) super if !@@b_no_banner STDERR << "MrubyBridgePlugin: 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 cdl_error("MRB1011 both include && exclude are specified") end if signature.get_function_head_array.nil? return # 以前に文法エラー発生 end signature.get_function_head_array.each{|func_head| if @includes.length > 0 if @includes.index func_head.get_name 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 if @excludes.index(func_head.get_name).nil? 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? @func_head_array << fh else dbgPrint "MrubyBridgePlugin: auto_exclude #{fh.get_name}\n" end } if @func_head_array.length == 0 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 への出力
525 526 527 528 529 530 |
# File 'lib/tecsgen/plugin/MrubyBridgeSignaturePlugin.rb', line 525 def self.gen_post_code(file) dbgPrint "#{self.name}: gen_post_code\n" if !@@b_gen_post_code_by_dependent gen_post_code_body file end end |
.gen_post_code_body(file) ⇒ Object
537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 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 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 |
# File 'lib/tecsgen/plugin/MrubyBridgeSignaturePlugin.rb', line 537 def self.gen_post_code_body(file) dbgPrint "#{self.name}: gen_post_code_body\n" # file.print <<EOT # namespace nMruby { # EOT # # @@ptr_list.each{ |name,tment| # file.print <<EOT # # // MBP600 # [singleton] # celltype #{name} { # entry sInitializeTECSBridge eInitialize; # }; # EOT # } # # file.print <<EOT # }; # EOT # gen_post_code で生成した celltype は gen_ep_func が呼び出されない #847 # @@struct_list.each{ |name,sttype| # file.print <<EOT # # [singleton] # celltype #{name} { # entry sInitializeTECSBridge eInitialize; # }; # EOT # } 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 ct_name = cell.get_celltype.get_name file.print <<EOT cell nMruby::#{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| # array.each{ |cell| # ct_name = cell.get_celltype.get_name ct_name = celltype_name file.print " cInitialize[] = #{vm_name}_#{ct_name}_Initializer.eInitialize;\n" # } } if @@VM_ptr_list[vm_name] @@VM_ptr_list[vm_name].each{|name, tment| file.print " cInitialize[] = C#{name}.eInitialize;\n" } end if @@VM_struct_list[vm_name] @@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
532 533 534 535 |
# File 'lib/tecsgen/plugin/MrubyBridgeSignaturePlugin.rb', line 532 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
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 |
# File 'lib/tecsgen/plugin/MrubyBridgeSignaturePlugin.rb', line 206 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 cdl_warning("MRW2001 initialize: internally defined. change to initialize_cell in ruby") b_init = true elsif func_head.get_name == :initialize_cell 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 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 cdl_warning("MRB1002 initialize: internally defined. change to initialize_cell in ruby") end end |
#check_parameter_type(func_head_array) ⇒ Object
check paramter type
234 235 236 237 238 239 240 241 242 243 244 245 246 247 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 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 |
# File 'lib/tecsgen/plugin/MrubyBridgeSignaturePlugin.rb', line 234 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 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" case param_decl.get_direction when :OUT, :INOUT if @b_auto_exclude 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 if @b_auto_exclude 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 if @b_auto_exclude 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
構造体のメンバーの型のチェック
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 |
# File 'lib/tecsgen/plugin/MrubyBridgeSignaturePlugin.rb', line 322 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? if @b_auto_exclude 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 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? # 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 生成するファイル
394 395 396 397 398 399 400 401 402 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 |
# File 'lib/tecsgen/plugin/MrubyBridgeSignaturePlugin.rb', line 394 def gen_cdl_file(file) # ブリッジセルタイプの生成 if @@celltypes[@celltype_name].nil? @@celltypes[@celltype_name] = [self] @@init_celltypes[@init_celltype_name] = true print_msg <<EOT MrubyBridgePlugin: [signature] #{@signature.get_namespace_path} => [celltype] nMruby::#{@celltype_name} => [class] TECS::#{@class_name} EOT file.print <<EOT /* * MrubyBridgeSignaturePlugin: * signature=#{@signature.get_namespace_path} * * => celltype=nMruby::#{@celltype_name} * (bridge cell's celltype; generated in this file) * cell nMruby::#{@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 nMruby{ // bridge celltype [idx_is_id,active] // not actually active, to avoid warning W1002, W1007 celltype #{@celltype_name} { call #{@signature.get_namespace_path} cTECS; attr { [omit] char_t *VMname = "VM"; [omit] char_t *bridgeName = C_EXP( "$cell$" ); }; }; // bridge initializer celltype celltype #{@init_celltype_name} { entry sInitializeTECSBridge eInitialize; }; }; EOT # 構造体セルタイプの生成 @struct_list.each{|name, sttype| if @@struct_list[name].nil? file.print <<EOT namespace nMruby{ [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 として送られてくる
631 632 633 634 635 636 637 638 639 640 641 642 643 |
# File 'lib/tecsgen/plugin/MrubyBridgeSignaturePlugin.rb', line 631 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] 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] 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] 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] 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
645 646 647 |
# File 'lib/tecsgen/plugin/MrubyBridgeSignaturePlugin.rb', line 645 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
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 |
# File 'lib/tecsgen/plugin/MrubyBridgeSignaturePlugin.rb', line 649 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? next end if f.get_name != :initialize 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 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_ep_func_body_ptr(file, b_singleton, ct_name, global_ct_name, sig_name, ep_name, func_name, func_global_name, func_type, params) ⇒ Object
690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 |
# File 'lib/tecsgen/plugin/MrubyBridgeSignaturePlugin.rb', line 690 def 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) t = @@ptr_list[ct_name] type = t[1] file.print <<EOT struct RClass *a; /* MBP710 */ a = mrb_define_class_under(mrb, TECS, "#{type}Pointer", mrb->object_class); MRB_SET_INSTANCE_TT(a, MRB_TT_DATA); mrb_define_method(mrb, a, "initialize", #{type}Pointer_initialize, MRB_ARGS_REQ(1)); mrb_define_method(mrb, a, "[]", #{type}Pointer_aget, MRB_ARGS_REQ(1)); mrb_define_method(mrb, a, "value", #{type}Pointer_get_val, MRB_ARGS_NONE()); mrb_define_method(mrb, a, "[]=", #{type}Pointer_aset, MRB_ARGS_REQ(2)); mrb_define_method(mrb, a, "value=", #{type}Pointer_set_val, MRB_ARGS_REQ(1)); mrb_define_method(mrb, a, "size", #{type}Pointer_size, MRB_ARGS_NONE()); mrb_define_method(mrb, a, "length", #{type}Pointer_size, MRB_ARGS_NONE()); EOT if t[2] == :Char file.print <<EOT mrb_define_method(mrb, a, "to_s", CharPointer_to_s, MRB_ARGS_NONE()); mrb_define_method(mrb, a, "from_s", CharPointer_from_s, MRB_ARGS_REQ(1)); EOT end end |
#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) ⇒ Object
716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 |
# File 'lib/tecsgen/plugin/MrubyBridgeSignaturePlugin.rb', line 716 def 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) tag = ct_name structType = @@struct_list[tag] file.print <<EOT struct RClass *a; /* MBP720 */ a = mrb_define_class_under(mrb, TECS, "Struct#{tag}", mrb->object_class); MRB_SET_INSTANCE_TT(a, MRB_TT_DATA); mrb_define_method(mrb, a, "initialize", Struct_#{tag}_initialize, MRB_ARGS_NONE()); EOT structType.get_members_decl.get_items.each{|d| file.print " STRUCT_INIT_MEMBER( #{tag}, #{d.get_name} )\n" } 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
739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 |
# File 'lib/tecsgen/plugin/MrubyBridgeSignaturePlugin.rb', line 739 def gen_preamble(file, b_singleton, ct_name, global_ct_name) if @@celltypes[ct_name] 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] 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] gen_preamble_ptr(file, b_singleton, ct_name, global_ct_name) elsif @@struct_list[ct_name] 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
974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 |
# File 'lib/tecsgen/plugin/MrubyBridgeSignaturePlugin.rb', line 974 def gen_preamble_bridge_func(file, b_singleton, ct_name, global_ct_name) @func_head_array.each{|f| if !f.is_function? next end if f.get_name != :initialize 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 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 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 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 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 " /* calling target (MBP120) */\n" if !b_void 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.is_a? StructType 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
779 780 781 782 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 |
# File 'lib/tecsgen/plugin/MrubyBridgeSignaturePlugin.rb', line 779 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(:nMruby, true) nsp.append! ct_name ct = Namespace.find nsp if ct.idx_is_id_act? if ct.has_CB? inib_cb = "CB" elsif ct.has_INIB? inib_cb = "INIB" else inib_cb = nil end if inib_cb ct.get_cell_list.each{|cell| if cell.is_generate? 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} { CELLCB *cbp; }; /* name_to_cbp MBP010 */ const struct name_to_cbp_#{@celltype_name} { char *name; /* Cell Name */ CELLCB *cbp; } Name_to_cbp_#{@celltype_name}[] = { EOT nsp = NamespacePath.new(:nMruby, true) nsp.append! ct_name ct = Namespace.find nsp ct.get_cell_list.each{|cell| if cell.is_generate? join_list = cell.get_join_list join = join_list.get_item(:bridgeName) if join.nil? name = "\"#{cell.get_name}\"" else rhs = join.get_rhs attr_list = cell.get_celltype.get_attribute_list name = rhs.eval_const join_list, attr_list end name_array = ct.get_name_array(cell) file.print "\t{ #{name}, #{name_array[8]} },\n" end } file.print <<EOT \t{ 0, 0 }, }; EOT end |
#gen_preamble_instance_initialize(file, b_singleton, ct_name, global_ct_name) ⇒ Object
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 |
# File 'lib/tecsgen/plugin/MrubyBridgeSignaturePlugin.rb', line 940 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_cb; const struct name_to_cbp_#{@celltype_name} *ntc; /* 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"); } for( ntc = &Name_to_cbp_#{@celltype_name}[0]; ntc->name != NULL; ntc++ ){ if( strcmp( ntc->name, RSTRING_PTR( name ) ) == 0 ) break; } if( ntc->name == 0 ){ mrb_raise(mrb, E_ARGUMENT_ERROR, "cell not found"); } tecs_cb = (struct tecs_#{@celltype_name} *)mrb_malloc(mrb, sizeof(struct tecs_#{@celltype_name}) ); tecs_cb->cbp = ntc->cbp; DATA_PTR( self ) = (void *)tecs_cb; return self; } EOT end |
#gen_preamble_instance_proto(file, b_singleton, ct_name, global_ct_name) ⇒ Object
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 |
# File 'lib/tecsgen/plugin/MrubyBridgeSignaturePlugin.rb', line 913 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? next end if f.get_name != :initialize 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
757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 |
# File 'lib/tecsgen/plugin/MrubyBridgeSignaturePlugin.rb', line 757 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" #if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) #define DLLEXPORT __declspec(dllexport) #else #define DLLEXPORT #endif #ifndef NULL #define NULL 0 #endif EOT end |
#gen_preamble_ptr(file, b_singleton, ct_name, global_ct_name) ⇒ Object
860 861 862 863 864 865 866 867 |
# File 'lib/tecsgen/plugin/MrubyBridgeSignaturePlugin.rb', line 860 def gen_preamble_ptr(file, b_singleton, ct_name, global_ct_name) tment = @@ptr_list[ct_name] file.print <<EOT GET_SET_#{tment[3]}( #{tment[1]}, #{tment[0]} ) POINTER_CLASS( #{tment[1]}, #{tment[0]} ) EOT end |
#gen_preamble_struct(file, b_singleton, ct_name, global_ct_name) ⇒ Object
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 |
# File 'lib/tecsgen/plugin/MrubyBridgeSignaturePlugin.rb', line 869 def gen_preamble_struct(file, b_singleton, ct_name, global_ct_name) tag = ct_name structType = @@struct_list[tag] file.print <<EOT /* struct #{tag} */ STRUCT_CLASS( #{tag} ) EOT structType.get_members_decl.get_items.each{|d| type = d.get_type.get_original_type case type when IntType, CIntType bit_size = type.get_bit_size case bit_size when -11, -1 tType = "Char" ttype = "char" when -2 tType = "Short" ttype = "short" when -3 tType = "Int" ttype = "int" when -4 tType = "Long" ttype = "long" when -5 tType = "IntPtr" ttype = "intptr" when 8, 16, 32, 64 tType = "Int#{bit_size}" ttype = "int#{bit_size}" else raise "MrubyBridgeSignaturePlugin: MrubyBridgeSignaturePlugin: cannot handle bit_size #{bit_size}" end file.print "MEMBER_GET_SET_INT( #{tag}, #{d.get_name}, #{tType}, #{ttype} )\n" when FloatType, CFloatType file.print "MEMBER_GET_SET_FLOAT( #{tag}, #{d.get_name} )\n" else raise "MrubyBridgeSignaturePlugin: MrubyBridgeSignaturePlugin: cannot handle type" end } end |
#get_celltype_name ⇒ Object
1253 1254 1255 |
# File 'lib/tecsgen/plugin/MrubyBridgeSignaturePlugin.rb', line 1253 def get_celltype_name @celltype_name end |
#get_type_map_ent(ttype) ⇒ Object
376 377 378 379 380 381 382 383 384 385 386 387 388 389 |
# File 'lib/tecsgen/plugin/MrubyBridgeSignaturePlugin.rb', line 376 def get_type_map_ent(ttype) # structure type is registerd in check_struct_member if ttype.is_a? StructType return end tstr = ttype.get_type_str.sub(/const /, "") # const は無視 tstr = tstr.sub(/volatile /, "") # volatile も無視 if @b_ignoreUnsigned 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
461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 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 |
# File 'lib/tecsgen/plugin/MrubyBridgeSignaturePlugin.rb', line 461 def new_cell(cell) if cell.get_celltype.get_name != @celltype_name return end join = cell.get_join_list.get_item :VMname if join vm_name = CDLString.remove_dquote(join.get_rhs.to_s).to_sym else vm_name = :VM end if @@VM_list[vm_name].nil? @@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] vma = @@VM_celltypes[vm_name] if vma[@celltype_name] 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] @@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] @@VM_ptr_list[vm_name][ ptr_celltype_name ] = tment else @@VM_ptr_list[vm_name] = { ptr_celltype_name => tment } end } end |
#ptrMrb2C(file, type, param) ⇒ Object
1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 |
# File 'lib/tecsgen/plugin/MrubyBridgeSignaturePlugin.rb', line 1182 def ptrMrb2C(file, type, param) ttype = type.get_type.get_original_type tment = get_type_map_ent ttype tstr = tment[1] =begin case ttype when IntType bit_size = ttype.get_bit_size case bit_size when -1, -11 tstr = "Char" when 8, 16, 32, 64 tstr = "Int#{bit_size}" when -2 tstr = "Short" when -3 tstr = "Int" when -4 tstr = "Long" when -5 tstr = "IntPtr" else raise "MrubyBridgeSignaturePlugin: not handle type" end when FloatType if ttype.get_bit_size == 32 then tstr = "Float32" else tstr = "Double64" end when BoolType tstr = "Bool" when StructType raise "MrubyBridgeSignaturePlugin: not handle type 2 #{ttype}" else raise "MrubyBridgeSignaturePlugin: not handle type 2 #{ttype}" end =end if param.get_size sz_str = param.get_size.to_s elsif param.get_string # mikan とりあえず size_is と string の同時指定 (二重ポインタ) はなし sz_str = param.get_string.to_s else sz_str = "1" end # unsigned 型の場合には cast が必要 if ttype.get_original_type.get_type_str != param.get_type.get_type.get_type_str cast_str = "(#{param.get_type.get_type_str})" else cast_str = "" end modify = "" case param.get_direction when :OUT, :INOUT case tstr when "Char", "SChar", "UChar" modify = "Mod" end end if param.is_nullable? nullable = "Nullable" else nullable = "" end # file.print " CHECK_POINTER( #{tstr}, mrb_#{param.get_name}, #{sz_str} );\n" # file.print " #{param.get_name} = #{cast_str}((struct #{tstr}PointerBody*)(DATA_PTR(mrb_#{param.get_name})))->buf;\n" file.print " #{param.get_name} = CheckAndGet#{tstr}Pointer#{modify}#{nullable}( mrb, mrb_#{param.get_name}, #{sz_str} );\n" end |
#register_ptr_type(ttype, fh) ⇒ Object
358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 |
# File 'lib/tecsgen/plugin/MrubyBridgeSignaturePlugin.rb', line 358 def register_ptr_type(ttype, fh) t_org = ttype.get_original_type tment = get_type_map_ent t_org if tment.nil? 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? # 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? @ptr_list[ptr_celltype_name] = tment end end |
#set_auto_exclude(rhs) ⇒ Object
プラグイン引数 auto_exclude
1298 1299 1300 1301 1302 1303 1304 1305 1306 |
# File 'lib/tecsgen/plugin/MrubyBridgeSignaturePlugin.rb', line 1298 def set_auto_exclude(rhs) if rhs == "false" @b_auto_exclude = false elsif rhs == "true" @b_auto_exclude = true # auto_exclude = true by default else cdl_warning("MRB9999 auto_exclude: unknown rhs value ignored. specify true or false") end end |
#set_exclude(rhs) ⇒ Object
プラグイン引数 exclude
1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 |
# File 'lib/tecsgen/plugin/MrubyBridgeSignaturePlugin.rb', line 1284 def set_exclude(rhs) funcs = rhs.split "," funcs.each{|rhs_func| rhs_func.gsub!(/\s/, "") func_head = @signature.get_function_head rhs_func.to_sym if func_head == false cdl_error("MRB1010 exclude function '$1' not found in signagture '$2", rhs, @signature.get_name) else @excludes << rhs_func.to_sym end } end |
#set_ignoreUnsigned(rhs) ⇒ Object
プラグイン引数 ignoreUnsigned
1258 1259 1260 1261 1262 |
# File 'lib/tecsgen/plugin/MrubyBridgeSignaturePlugin.rb', line 1258 def set_ignoreUnsigned(rhs) if rhs == "true" || rhs.nil? @b_ignoreUnsigned = true end end |
#set_include(rhs) ⇒ Object
プラグイン引数 include
1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 |
# File 'lib/tecsgen/plugin/MrubyBridgeSignaturePlugin.rb', line 1265 def set_include(rhs) funcs = rhs.split "," funcs.each{|rhs_func| found = false rhs_func.gsub!(/\s/, "") @signature.get_function_head_array.each{|a| if rhs_func.to_sym == a.get_name found = true end } if found == false cdl_error("MRB1009 include function '$1' not found in signagture '$2'", rhs, @signature.get_name) else @includes << rhs_func.to_sym end } end |