source: asp3_tinet_ecnl_arm/trunk/asp3_dcre/tecsgen/tecslib/plugin/MrubyBridgeSignaturePlugin.rb@ 374

Last change on this file since 374 was 374, checked in by coas-nagasima, 5 years ago

mbed関連を更新
シリアルドライバをmbedのHALを使うよう変更
ファイルディスクリプタの処理を更新

  • Property charset set to UTF-8
  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-ruby
File size: 44.7 KB
Line 
1# -*- coding: utf-8 -*-
2#
3# mruby => TECS bridge
4#
5# Copyright (C) 2008-2017 by TOPPERS Project
6#
7# 上記著作権者
8は,以下の(1)~(4)の条件を満たす場合に限り,本ソフトウェ
9# ア(本ソフトウェアを改変したものを含む.以下同じ)を使用・複製・改
10# 変・再é…
11å¸ƒï¼ˆä»¥ä¸‹ï¼Œåˆ©ç”¨ã¨å‘¼ã¶ï¼‰ã™ã‚‹ã“とを無償で許諾する.
12# (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
13# 権表示,この利用条件および下記の無保証規定が,そのままの形でソー
14# スコード中に含まれていること.
15# (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
16# 用できる形で再é…
17å¸ƒã™ã‚‹å ´åˆã«ã¯ï¼Œå†é…
18å¸ƒã«ä¼´ã†ãƒ‰ã‚­ãƒ¥ãƒ¡ãƒ³ãƒˆï¼ˆåˆ©ç”¨
19# 者
20マニュアルなど)に,上記の著作権表示,この利用条件および下記
21# の無保証規定を掲載すること.
22# (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
23# 用できない形で再é…
24å¸ƒã™ã‚‹å ´åˆã«ã¯ï¼Œæ¬¡ã®ã„ずれかの条件を満たすこ
25# と.
26# (a) 再é…
27å¸ƒã«ä¼´ã†ãƒ‰ã‚­ãƒ¥ãƒ¡ãƒ³ãƒˆï¼ˆåˆ©ç”¨è€…
28マニュアルなど)に,上記の著
29# 作権表示,この利用条件および下記の無保証規定を掲載すること.
30# (b) 再é…
31å¸ƒã®å½¢æ…
32‹ã‚’,別に定める方法によって,TOPPERSプロジェクトに
33# 報告すること.
34# (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
35# 害からも,上記著作権者
36およびTOPPERSプロジェクトをå…
37è²¬ã™ã‚‹ã“と.
38# また,本ソフトウェアのユーザまたはエンドユーザからのいかなる理
39# 由に基づく請求からも,上記著作権者
40およびTOPPERSプロジェクトを
41# å…
42è²¬ã™ã‚‹ã“と.
43#
44# 本ソフトウェアは,無保証で提供されているものである.上記著作権者
45お
46# よびTOPPERSプロジェクトは,本ソフトウェアに関して,特定の使用目的
47# に対する適合性も含めて,いかなる保証も行わない.また,本ソフトウェ
48# アの利用により直接的または間接的に生じたいかなる損害に関しても,そ
49# の責任を負わない.
50#
51# $Id$
52#
53
54# Todo:
55# 生成するもの
56# gen_cdl_file
57# ブリッジ初期化セルタイプ (シグニチャごと)
58# @@init_celltypes に記録
59# ブリッジセルタイプ (シグニチャごと)
60# @@celltypes に記録
61# 構造体セルタイプ
62# @@struct_list に記録
63# new_cell
64# TECS 初期化セル(プロトタイプ宣言)
65# @@VM_init_cells に記録
66# @@VM_struct_list に記録
67# @@VM_ptr_list に記録
68# gen_post_code
69# 構造体初期化セル
70# ポインタ初期化セル
71# TECS 初期化セル
72#
73# ep_func の作成
74# signature, ポインタ、構造体 … 初期化受け口=mruby VM への登録
75# ポインタ
76# preamble の作成
77# ポインタ、構造体 … アクセス用コードの生成
78# signature … ブリッジ関数のプロトタイプ宣言
79# postamble の作成
80# signature … ブリッジ関数の定義
81
82class MrubyBridgeSignaturePlugin < SignaturePlugin
83
84 # プラグイン引数名 => Proc
85 MrubyBridgePluginArgProc = {
86 "ignoreUnsigned" => Proc.new { |obj,rhs| obj.set_ignoreUnsigned rhs },
87 "include" => Proc.new { |obj,rhs| obj.set_include rhs },
88 "exclude" => Proc.new { |obj,rhs| obj.set_exclude rhs },
89 "auto_exclude" => Proc.new { |obj,rhs| obj.set_auto_exclude rhs },
90 }
91
92 @@b_no_banner = false #
93 @@b_gen_post_code_by_dependent = false # true if gen_post_code is called by MrubyBridgeCellPlugin
94 @@celltypes = { } # {celltype_name => [ BridgePlugin のインスタンスのé…
95åˆ— }
96 @@init_celltypes = { } # {celltype_name => [ BridgePlugin のインスタンスのé…
97åˆ— }
98 @@struct_list = { } # {struct_name=>StructType}
99 @@ptr_list = { } # {ptr_celltype_name=> @@TYPE_MAP の対応するもの}
100 @@VM_list = { } # VM_name => true
101 @@VM_celltypes = { } # VM_name => { @celltype_name => セルのé…
102åˆ— }
103 @@VM_struct_list = { } # {name=>StructType}
104 @@VM_ptr_list = { } # { VM_name => {name=> @@TYPE_MAP の対応するもの} }
105 @@TYPE_MAP = { # type_str class GET_SET
106 :char_t => [:char_t, "Char", :Char, :INT ],
107 :uchar_t => [:uchar_t, "UChar", :Char, :INT ],
108 :schar_t => [:schar_t, "SChar", :Char, :INT ],
109
110 :bool_t => [:bool_t, "Bool", :Bool, :BOOL ],
111 :int8_t => [:int8_t, "Int8", :Int, :INT ],
112 :int16_t => [:int16_t, "Int16", :Int, :INT ],
113 :int32_t => [:int32_t, "Int32", :Int, :INT ],
114 :int64_t => [:int64_t, "Int64", :Int, :INT ],
115 :uint8_t => [:uint8_t, "UInt8", :Int, :INT ],
116 :uint16_t => [:uint16_t, "UInt16", :Int, :INT ],
117 :uint32_t => [:uint32_t, "UInt32", :Int, :INT ],
118 :uint64_t => [:uint64_t, "UInt64", :Int, :INT ],
119
120 :int => [:int, "Int", :Int, :INT ],
121 :char => [:char, "Char", :Char, :INT ], # char は char_t として扱う
122 :short => [:short, "Short", :Int, :INT ],
123 :long => [:long, "Long", :Int, :INT ],
124
125 :"unsigned char" => [:uchar_t, "UChar", :Char, :INT ],
126 :"unsigned int" => [:"unsigned int", "UInt", :Int, :INT ],
127 :"unsigned short" => [:"unsigned short", "UShort", :Int, :INT ],
128 :"unsigned long" => [:"unsigned long", "ULong", :Int, :INT ],
129 :"signed char" => [:schar_t, "SChar", :Char, :INT ],
130 :"signed int" => [:int, "Int", :Int, :INT ],
131 :"signed short" => [:short, "Short", :Int, :INT ],
132 :"signed long" => [:long, "Long", :Int, :INT ],
133
134 :float32_t => [:float32_t, "Float32", :Float, :FLOAT ],
135 :double64_t => [:double64_t,"Double64", :Float, :FLOAT ],
136
137 :float => [:float, "Float32", :Float, :FLOAT ],
138 :double => [:double, "Double64", :Float, :FLOAT ]
139 }
140
141 # included or excluded functions
142
143 ### ロードされた時点で実行される ###
144
145 # -I に $(TECSPATH)/mruby を追加
146 # TECSGEN::Makefile.add_obj "$(MRUBY_MAIN_OBJ)"
147 TECSGEN::Makefile.add_ldflag "-lmruby -L$(MRUBYPATH)/lib -lm"
148 TECSGEN::Makefile.add_search_path "$(MRUBYPATH)/include"
149 TECSGEN::Makefile.add_var "MRUBYPATH", "..", "CHANGE this to suitable path"
150 # TECSGEN::Makefile.add_var "MRUBY_MAIN_OBJ", "$(_TECS_OBJ_DIR)tecs_mruby.o", "CHANGE this if your have your main"
151
152 #=== プラグインインスタンスの初期化
153 # 戻り値、引数の型が使用可能なものかチェックする
154 #
155 def initialize( signature, option )
156 super
157
158 if ! @@b_no_banner
159 STDERR << "MrubyBridgePlugin: version 1.3.0 (Suitable for mruby ver 1.3.0 & ver 1.2.0). \n"
160 @@b_no_banner = true
161 end
162
163 @b_ignoreUnsigned = false
164 @includes = []
165 @excludes = []
166 @struct_list = { }
167 @ptr_list = { }
168 @auto_exclude_list = {}
169 @b_auto_exclude = true # auto_exclude = true by default
170
171 @plugin_arg_check_proc_tab = MrubyBridgePluginArgProc
172 parse_plugin_arg
173
174 @celltype_name = :"t#{@signature.get_global_name}"
175 @init_celltype_name = :"#{@celltype_name}_Initializer"
176 # this variable is sometimes not used. rhs coded directry.
177 @class_name = :"T#{@signature.get_global_name}"
178
179 @func_head_array = []
180 fh_array = []
181 if @includes.length > 0 && @excludes.length > 0 then
182 cdl_error( "MRB1011 both include && exclude are specified" )
183 end
184
185 if signature.get_function_head_array == nil then
186 return # 以前に文法エラー発生
187 end
188
189 signature.get_function_head_array.each{ |func_head|
190 if @includes.length > 0 then
191 if @includes.index func_head.get_name then
192 dbgPrint "MrubyBridgePlugin: #{func_head.get_name} INCLUDED\n"
193 fh_array << func_head
194 else
195 dbgPrint "MrubyBridgePlugin: #{func_head.get_name} NOT included\n"
196 end
197 elsif @excludes.length > 0 then
198 if @excludes.index( func_head.get_name ) == nil then
199 dbgPrint "MrubyBridgePlugin: #{func_head.get_name} NOT excluded\n"
200 fh_array << func_head
201 else
202 dbgPrint "MrubyBridgePlugin: #{func_head.get_name} EXCLUDED\n"
203 end
204 else
205 fh_array << func_head
206 end
207 }
208
209 check_name_and_return_type fh_array
210 check_parameter_type fh_array
211
212 fh_array.each{ |fh|
213 if @auto_exclude_list[ fh.get_name ] == nil then
214 @func_head_array << fh
215 else
216 dbgPrint "MrubyBridgePlugin: auto_exclude #{fh.get_name}\n"
217 end
218 }
219
220 if @func_head_array.length == 0 then
221 cdl_error( "MRB1012 '$1' no function remained by exclude", @signature.get_name )
222 end
223 end
224
225 #=== check function name & return type
226 def check_name_and_return_type func_head_array
227 b_init = false; b_init_cell = false
228 func_head_array.each{ |func_head|
229 if( func_head.get_name == :initialize )then
230 cdl_warning( "MRW2001 initialize: internally defined. change to initialize_cell in ruby" )
231 b_init = true
232 elsif( func_head.get_name == :initialize_cell )then
233 b_init_cell = true
234 end
235 rtype = func_head.get_return_type.get_original_type
236 case rtype
237 when BoolType, IntType, FloatType, VoidType
238 else
239 if @b_auto_exclude then
240 cdl_info( "MRI0001 cannot return type $1, $2 automatcally excluded", rtype.get_type_str, func_head.get_name )
241 @auto_exclude_list[ func_head.get_name ] = func_head
242 else
243 cdl_error( "MRB1001 cannot return type $1", rtype.get_type_str )
244 end
245 end
246 }
247 if( b_init && b_init_cell )then
248 cdl_warning( "MRB1002 initialize: internally defined. change to initialize_cell in ruby" )
249 end
250 end
251
252 #=== check paramter type
253 def check_parameter_type func_head_array
254 # check type of parameters
255 func_head_array.each{ |fh|
256 fh.get_paramlist.get_items.each{ |param_decl|
257 case param_decl.get_direction
258 when :SEND, :RECEIVE
259 if @b_auto_exclude then
260 cdl_info( "MRI0002 $1: $2 parameter cannot be used in mruby Bridge, $3 automatcally excluded",
261 param_decl.get_name, param_decl.get_direction.to_s.downcase, fh.get_name )
262 @auto_exclude_list[ fh.get_name ] = fh
263 else
264 cdl_error( "MRB1003 $1: $2 parameter cannot be used in mruby Bridge", param_decl.get_name, param_decl.get_direction.to_s.downcase )
265 end
266 end
267 type = param_decl.get_type
268 type_org = type.get_original_type
269 type_str = type.get_type_str + type.get_type_str_post
270
271 b_ng = false
272 case type_org
273 when IntType
274 case type_org.get_bit_size
275 when 8, 16, 32, 64
276 when -1, -2, -3, -4, -11
277 else
278 b_ng = true
279 end
280 when BoolType
281 when FloatType
282 when PtrType
283 ttype_org = type_org.get_type # ポインタの指しているå…
284ˆã®åž‹
285 ttype = ttype_org.get_original_type # 上記の typedef されている場合、å…
286ƒã®åž‹
287 register_ptr_type ttype_org, fh
288
289 if( type_org.get_string.to_s == "-1" ) then
290 case param_decl.get_direction
291 when :OUT, :INOUT
292 if @b_auto_exclude then
293 cdl_info( "MRB9999 string specifier without length cannot be used for out & inout parameter, $1 automatcally excluded",
294 fh.get_name )
295 @auto_exclude_list[ fh.get_name ] = fh
296 else
297 cdl_error( "MRB9999 string specifier without length cannot be used for out & inout parameter")
298 end
299 end
300 end
301
302 case ttype
303 when IntType
304 bit_size = ttype.get_bit_size
305 # if bit_size < 0 && bit_size != -1 then
306 # b_ng = true
307 # end
308 when FloatType
309 when BoolType
310 when StructType
311 if( type_org.get_size || type_org.get_string || type_org.get_count ) then
312 if @b_auto_exclude then
313 cdl_info( "MRI9999 $1: size_is, count_is, string cannot be specified for struct pointer, $2 automatcally excluded",
314 param_decl.get_name, fh.get_name )
315 @auto_exclude_list[ fh.get_name ] = fh
316 else
317 cdl_error( "MRB1004 $1: size_is, count_is, string cannot be specified for struct pointer", param_decl.get_name )
318 end
319 end
320 check_struct_member ttype_org, fh
321 else
322 b_ng = true
323 end
324 when StructType
325 check_struct_member type_org, fh
326 else # ArrayType, FuncType, EnumType, VoidType
327 b_ng = true
328 end
329 if b_ng then
330 if @b_auto_exclude then
331 cdl_info( "MRI9999 $1: type $2 cannot be used in mruby Bridge, $3 automatcally excluded",
332 param_decl.get_name, type_str, fh.get_name )
333 @auto_exclude_list[ fh.get_name ] = fh
334 else
335 cdl_error( "MRB1005 $1: type $2 cannot be used in mruby Bridge", param_decl.get_name, type_str )
336 end
337 end
338 }
339 }
340 end
341
342 #=== 構造体のメンバーの型のチェック
343 def check_struct_member struct_type, fh
344 #p "tag name:#{struct_type.get_name}"
345 # sttype = Namespace.find_tag( struct_type.get_name )
346 sttype = struct_type.get_original_type
347 if sttype.get_name == nil then
348 if @b_auto_exclude then
349 cdl_info( "MRI9999 tagless-struct cannot be handled, $1 automatcally excluded", fh.get_name )
350 @auto_exclude_list[ fh.get_name ] = fh
351 return # 登録しないように打ち切る
352 else
353 cdl_error( "MRB10007 tagless-struct cannot be handled")
354 end
355 end
356 sttype.get_members_decl.get_items.each { |d|
357 t = d.get_type.get_original_type
358 case t
359 when IntType, FloatType, BoolType
360 else
361 if @b_auto_exclude then
362 cdl_info( "MRI9999 $1: type $2 not allowed for struct member, $3 automatcally excluded",
363 d.get_name, d.get_type.get_type_str + d.get_type.get_type_str_post, fh.get_name )
364 @auto_exclude_list[ fh.get_name ] = fh
365 return # 登録しないように打ち切る
366 else
367 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 )
368 end
369 end
370 }
371 st_name = :"t{}"
372 if @struct_list[ sttype.get_name ] == nil then
373 # print_msg " MrubyBridgePlugin: [struct] #{struct_type.get_type_str} => class TECS::Struct#{sttype.get_name}\n"
374 print " MrubyBridgePlugin: [struct] #{struct_type.get_type_str} => class TECS::Struct#{sttype.get_name}\n"
375 @struct_list[ sttype.get_name ] = sttype
376 end
377 end
378
379 def register_ptr_type ttype, fh
380 t_org = ttype.get_original_type
381 tment = get_type_map_ent t_org
382 if tment == nil then
383 return
384 # cdl_error( "MRB1008 unknown pointer type '$1'", ttype.get_type_str )
385 end
386 ptr_celltype_name = :"t#{tment[1]}Pointer"
387 if @@ptr_list[ ptr_celltype_name ] == nil then
388 # print_msg " MrubyBridgePlugin: [pointer] #{ttype.get_type_str}* => class TECS::#{tment[1]}Pointer\n"
389 print " MrubyBridgePlugin: [pointer] #{ttype.get_type_str}* => class TECS::#{tment[1]}Pointer\n"
390 @@ptr_list[ ptr_celltype_name ] = tment
391 end
392 if @ptr_list[ ptr_celltype_name ] == nil then
393 @ptr_list[ ptr_celltype_name ] = tment
394 end
395 end
396
397 def get_type_map_ent ttype
398 # structure type is registerd in check_struct_member
399 if ttype.kind_of? StructType
400 return
401 end
402 tstr = ttype.get_type_str.sub( /const /, "" ) # const は無視
403 tstr = tstr.sub( /volatile /, "" ) # volatile も無視
404 if @b_ignoreUnsigned then
405 tstr = tstr.sub( /unsigned /, "" ) # volatile も無視
406 tstr = tstr.sub( /uint/, "int" ) # volatile も無視
407 tstr = tstr.sub( /[cs]char/, "char" ) # volatile も無視
408 end
409 return @@TYPE_MAP[ tstr.to_sym ]
410 end
411
412 #=== CDL ファイルの生成
413 # typedef, signature, celltype, cell コードを生成
414 #file:: FILE 生成するファイル
415 def gen_cdl_file(file)
416
417 # ブリッジセルタイプの生成
418 if @@celltypes[ @celltype_name ] == nil then
419 @@celltypes[ @celltype_name ] = [ self ]
420 @@init_celltypes[ @init_celltype_name ] = true
421 print_msg <<EOT
422 MrubyBridgePlugin: [signature] #{@signature.get_namespace_path} => [celltype] nMruby::#{@celltype_name} => [class] TECS::#{@class_name}
423EOT
424
425 file.print <<EOT
426/*
427 * MrubyBridgeSignaturePlugin:
428 * signature=#{@signature.get_namespace_path}
429 *
430 * => celltype=nMruby::#{@celltype_name}
431 * (bridge cell's celltype; generated in this file)
432 * cell nMruby::#{@celltype_name} BridgeCellName { cTECS = CellName.eEntry; };
433 * where eEntry's signature must be #{@signature.get_namespace_path}.
434 * => class=TECS::#{@class_name}
435 * (mruby's class; accessible from your script)
436 * bridge = TECS::#{@class_name}.new("BridgeCellName")
437 */
438import( <mruby.cdl> );
439
440/**** Ruby => TECS Bridge Celltype (MBP500) ****/
441namespace nMruby{
442 // bridge celltype
443 [idx_is_id,active] // not actually active, to avoid warning W1002, W1007
444 celltype #{@celltype_name} {
445 call #{@signature.get_namespace_path.to_s} cTECS;
446 attr {
447 [omit]
448 char_t *VMname = "VM";
449 [omit]
450 char_t *bridgeName = C_EXP( "$cell$" );
451 };
452 };
453 // bridge initializer celltype
454 celltype #{@init_celltype_name} {
455 entry sInitializeTECSBridge eInitialize;
456 };
457};
458EOT
459
460 # 構造体セルタイプの生成
461 @struct_list.each{ |name, sttype|
462 if @@struct_list[ name ] == nil then
463 file.print <<EOT
464namespace nMruby{
465 [singleton]
466 celltype #{name} {
467 entry sInitializeTECSBridge eInitialize;
468 };
469};
470EOT
471 @@struct_list[ name ] = sttype
472 end
473 }
474
475 else
476 cdl_info( "MRBW001 MrubyBridgePlugin: signature '$1' duplicate. ignored current one", @signature.get_namespace_path )
477 @@celltypes[ @celltype_name ] << self
478 end
479 end
480
481 #=== gen_cdl_file で定義したセルタイプに 新しいセルが定義された
482 # cell のセルタイプの名前は @celltype_name
483 def new_cell cell
484 if cell.get_celltype.get_name != @celltype_name then
485 return
486 end
487
488 join = cell.get_join_list.get_item :VMname
489 if join then
490 vm_name = CDLString.remove_dquote(join.get_rhs.to_s).to_sym
491 else
492 vm_name = :"VM"
493 end
494
495 if @@VM_list[ vm_name ] == nil then
496 @@VM_list[ vm_name ] = true
497
498 initializer_celltype_cdl = "#{$gen}/#{cell.get_name}Initializer.cdl"
499 file = CFile.open( initializer_celltype_cdl, "w" )
500
501 # TECS 初期化セル(プロトタイプ宣言)
502 print_msg " MrubyBridgePlugin: join your VM's cInitialize to #{vm_name}_TECSInitializer.eInitialize\n"
503
504 file.print <<EOT
505
506 // prototype of TECSInitializer (MBP510)
507 cell nMruby::tTECSInitializer #{vm_name}_TECSInitializer;
508EOT
509 file.close
510
511 Generator.parse( initializer_celltype_cdl, self )
512 end
513
514 if @@VM_celltypes[ vm_name ] then
515 vma = @@VM_celltypes[ vm_name ]
516
517 if vma[ @celltype_name ] then
518 vma[ @celltype_name ] << cell
519 else
520 vma[ @celltype_name ] = [cell]
521 @@VM_celltypes[ vm_name ] = vma
522 end
523 else
524 vma = { }
525 vma[ @celltype_name ] = [cell]
526 @@VM_celltypes[ vm_name ] = vma
527 end
528
529 @struct_list.each{ |stname, sttype|
530 if @@VM_struct_list[ vm_name ] then
531 @@VM_struct_list[ vm_name ][ sttype.get_name ] = sttype
532 else
533 @@VM_struct_list[ vm_name ] = { sttype.get_name => sttype }
534 end
535 }
536 @ptr_list.each{ |ptr_celltype_name, tment|
537 if @@VM_ptr_list[ vm_name ] then
538 @@VM_ptr_list[ vm_name ][ ptr_celltype_name ] = tment
539 else
540 @@VM_ptr_list[ vm_name ] = { ptr_celltype_name => tment }
541 end
542 }
543
544 end
545
546 #=== プラグインが CDL の POST コードを生成
547 # tmp_plugin_post_code.cdl への出力
548 def self.gen_post_code file
549 dbgPrint "#{self.name}: gen_post_code\n"
550 if ! @@b_gen_post_code_by_dependent then
551 gen_post_code_body file
552 end
553 end
554
555 def self.set_gen_post_code_by_dependent # by MrubyBriddeCellPlugin
556 dbgPrint "#{self.name}: set_gen_post_code_by_dependent\n"
557 @@b_gen_post_code_by_dependent = true
558 end
559
560 def self.gen_post_code_body file
561 dbgPrint "#{self.name}: gen_post_code_body\n"
562
563# file.print <<EOT
564# namespace nMruby {
565# EOT
566#
567# @@ptr_list.each{ |name,tment|
568# file.print <<EOT
569#
570# // MBP600
571# [singleton]
572# celltype #{name} {
573# entry sInitializeTECSBridge eInitialize;
574# };
575# EOT
576# }
577#
578# file.print <<EOT
579# };
580# EOT
581
582# gen_post_code で生成した celltype は gen_ep_func が呼び出されない #847
583# @@struct_list.each{ |name,sttype|
584# file.print <<EOT
585#
586# [singleton]
587# celltype #{name} {
588# entry sInitializeTECSBridge eInitialize;
589# };
590#EOT
591# }
592
593 file.print "\n // MrubyBridgeSignaturePlugin: MBP601\n"
594 @@VM_celltypes.each{ |vm_name, instance_list|
595 instance_list.each { |celltype_name, array|
596 cell = array[0]
597 if cell.get_celltype then
598 ct_name = cell.get_celltype.get_name
599 file.print <<EOT
600 cell nMruby::#{ct_name}_Initializer #{vm_name}_#{ct_name}_Initializer{ };
601EOT
602 end
603 }
604 }
605
606 file.print " // MBP602\n"
607 @@ptr_list.each{ |name,tment|
608 file.print <<EOT
609 cell nMruby::#{name} C#{name} { };
610EOT
611 }
612
613 file.print " // MBP603\n"
614 @@struct_list.each{ |name,sttype|
615 file.print <<EOT
616 cell nMruby::#{name} C#{name} { };
617EOT
618 }
619
620 if @@VM_celltypes == nil
621 raise "MrubyBridgeSignaturePlugin: are0"
622 end
623 @@VM_celltypes.each{ |vm_name, instance_list|
624 file.print " /* === VM name is '#{vm_name}' === (MBP610) */\n"
625 init_cell_name = "#{vm_name}_TECSInitializer"
626
627 file.print " cell nMruby::tTECSInitializer #{init_cell_name} {\n"
628
629 instance_list.each { |celltype_name, array|
630# array.each{ |cell|
631# ct_name = cell.get_celltype.get_name
632 ct_name = celltype_name
633 file.print " cInitialize[] = #{vm_name}_#{ct_name}_Initializer.eInitialize;\n"
634# }
635 }
636 if @@VM_ptr_list[vm_name] then
637 @@VM_ptr_list[vm_name].each{ |name, tment|
638 file.print " cInitialize[] = C#{name}.eInitialize;\n"
639 }
640 end
641 if @@VM_struct_list[vm_name] then
642 @@VM_struct_list[vm_name].each{ |name, sttype|
643 file.print " cInitialize[] = C#{name}.eInitialize;\n"
644 }
645 end
646 file.print " };"
647 }
648
649 end
650
651 ####### 以下コード生成段階 ######
652
653 #=== 受け口関数の本体コードを生成(頭部と末尾は別途出力)
654 #ct_name:: Symbol (プラグインで生成された) セルタイプ名 .Symbol として送られてくる
655 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 )
656 if @@celltypes[ ct_name ] then
657 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 )
658 elsif @@init_celltypes[ ct_name ] then
659 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 )
660 elsif @@ptr_list[ ct_name ] then
661 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 )
662 elsif @@struct_list[ ct_name ] then
663 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 )
664 else
665 raise "MrubyBridgeSignaturePlugin: Unknown #{ct_name}"
666 end
667 end
668
669 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 )
670 raise "MrubyBridgeSignaturePlugin: unexpected "
671 end
672
673 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 )
674 file.print <<EOT
675 // CELLCB *p_cellcb = GET_CELLCB( idx ); /* no error check */ /* MBP700 */
676 struct RClass *rc;
677
678 rc = mrb_define_class_under( mrb, TECS, \"#{@class_name}\", mrb->object_class );
679 mrb_define_method( mrb, rc, "initialize", MrubyBridge_#{@celltype_name}_initialize, MRB_ARGS_REQ(1) );
680 MRB_SET_INSTANCE_TT(rc, MRB_TT_DATA);
681EOT
682
683 @func_head_array.each{ |f|
684 if ! f.is_function? then
685 next
686 end
687 if f.get_name != :initialize then
688 func_name = f.get_name
689 else
690 func_name = :initialize_cell
691 end
692
693 ret_type = f.get_return_type
694 n_param = 0
695 f.get_paramlist.get_items.each{ |param|
696 case param.get_direction
697 when :IN, :INOUT, :OUT
698 n_param += 1
699 when :SEND, :RECEIVE
700 raise "MrubyBridgeSignaturePlugin: send, receive"
701 end
702 }
703 if n_param > 0 then
704 p_str = "MRB_ARGS_REQ( #{n_param} )"
705 else
706 p_str = "MRB_ARGS_NONE()"
707 end
708 file.print <<EOT
709 mrb_define_method( mrb, rc, "#{func_name}", MrubyBridge_#{@celltype_name}_#{func_name}, #{p_str} );
710EOT
711 }
712 end
713
714 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 )
715
716 t = @@ptr_list[ct_name]
717 type = t[1]
718 file.print <<EOT
719 struct RClass *a; /* MBP710 */
720
721 a = mrb_define_class_under(mrb, TECS, "#{type}Pointer", mrb->object_class);
722 MRB_SET_INSTANCE_TT(a, MRB_TT_DATA);
723
724 mrb_define_method(mrb, a, "initialize", #{type}Pointer_initialize, MRB_ARGS_REQ(1));
725 mrb_define_method(mrb, a, "[]", #{type}Pointer_aget, MRB_ARGS_REQ(1));
726 mrb_define_method(mrb, a, "value", #{type}Pointer_get_val, MRB_ARGS_NONE());
727 mrb_define_method(mrb, a, "[]=", #{type}Pointer_aset, MRB_ARGS_REQ(2));
728 mrb_define_method(mrb, a, "value=", #{type}Pointer_set_val, MRB_ARGS_REQ(1));
729 mrb_define_method(mrb, a, "size", #{type}Pointer_size, MRB_ARGS_NONE());
730 mrb_define_method(mrb, a, "length", #{type}Pointer_size, MRB_ARGS_NONE());
731EOT
732
733 if t[2] == :Char then
734 file.print <<EOT
735 mrb_define_method(mrb, a, "to_s", CharPointer_to_s, MRB_ARGS_NONE());
736 mrb_define_method(mrb, a, "from_s", CharPointer_from_s, MRB_ARGS_REQ(1));
737EOT
738 end
739 end
740
741 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 )
742 tag = ct_name
743 structType = @@struct_list[ tag ]
744 file.print <<EOT
745 struct RClass *a; /* MBP720 */
746
747 a = mrb_define_class_under(mrb, TECS, "Struct#{tag}", mrb->object_class);
748 MRB_SET_INSTANCE_TT(a, MRB_TT_DATA);
749
750 mrb_define_method(mrb, a, "initialize", Struct_#{tag}_initialize, MRB_ARGS_NONE());
751EOT
752
753 structType.get_members_decl.get_items.each{ |d|
754 file.print " STRUCT_INIT_MEMBER( #{tag}, #{d.get_name} )\n"
755 }
756 end
757
758 #=== 受け口関数の preamble (C言語)を生成する
759 # 必
760要なら preamble 部に出力する
761 #file:: FILE 出力å…
762ˆãƒ•ã‚¡ã‚¤ãƒ«
763 #b_singleton:: bool true if singleton
764 #ct_name:: Symbol
765 #global_ct_name:: string
766 def gen_preamble( file, b_singleton, ct_name, global_ct_name )
767 if @@celltypes[ ct_name ] then
768 gen_preamble_mruby( file, b_singleton, ct_name, global_ct_name )
769 gen_preamble_instance( file, b_singleton, ct_name, global_ct_name )
770 gen_preamble_instance_initialize( file, b_singleton, ct_name, global_ct_name )
771 gen_preamble_bridge_func( file, b_singleton, ct_name, global_ct_name )
772 elsif @@init_celltypes[ ct_name ] then
773 gen_preamble_mruby( file, b_singleton, ct_name, global_ct_name )
774 gen_preamble_instance_proto( file, b_singleton, ct_name, global_ct_name )
775 elsif @@ptr_list[ ct_name ] then
776 gen_preamble_ptr( file, b_singleton, ct_name, global_ct_name )
777 elsif @@struct_list[ ct_name ] then
778 gen_preamble_struct( file, b_singleton, ct_name, global_ct_name )
779 else
780 raise "MrubyBridgeSignaturePlugin: MrubyBridgeSignaturePlugin: Unknown #{ct_name}"
781 end
782 end
783
784 def gen_preamble_mruby( file, b_singleton, ct_name, global_ct_name )
785 file.print <<EOT
786/* MBP: MrubyBridgePlugin: MBP000 */
787#include "mruby.h"
788#include "mruby/class.h"
789#include "mruby/data.h"
790#include "mruby/string.h"
791#include "TECSPointer.h"
792#include "TECSStruct.h"
793
794#if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
795#define DLLEXPORT __declspec(dllexport)
796#else
797#define DLLEXPORT
798#endif
799
800#ifndef NULL
801#define NULL 0
802#endif
803EOT
804 end
805
806 def gen_preamble_instance( file, b_singleton, ct_name, global_ct_name )
807 # 「#1005 MrubyBridgePlugin-test のビルドに失敗」にて追加
808 # 「#1004 idx_is_id が true の場合(domain の場合は未指定でも true) の CBP のプロトタイプ宣言」にて不要になる見込み
809 nsp = NamespacePath.new( :nMruby, true )
810 nsp.append! ct_name
811 ct = Namespace.find nsp
812 if ct.idx_is_id_act? then
813 if ct.has_CB? then
814 inib_cb = "CB"
815 elsif ct.has_INIB? then
816 inib_cb = "INIB"
817 else
818 inib_cb = nil
819 end
820 if inib_cb then
821 ct.get_cell_list.each{ |cell|
822 if cell.is_generate? then
823 name_array = ct.get_name_array( cell )
824 file.print "extern #{ct.get_global_name}_CB #{cell.get_global_name}_#{inib_cb};\n"
825 end
826 }
827 end
828 end
829
830 file.print <<EOT
831
832/* RData MBP001 */
833static void
834#{@celltype_name}_free( mrb_state *mrb, void *p )
835{
836 if( p )
837 (void)mrb_free( mrb, p );
838}
839
840/* RData MBP002 */
841struct mrb_data_type data_type_#{@celltype_name} =
842{
843 "#{@celltype_name}",
844 #{@celltype_name}_free
845};
846
847/* RData MBP003 */
848struct tecs_#{@celltype_name} {
849 CELLCB *cbp;
850};
851
852/* name_to_cbp MBP010 */
853const struct name_to_cbp_#{@celltype_name} {
854 char *name; /* Cell Name */
855 CELLCB *cbp;
856} Name_to_cbp_#{@celltype_name}[] = {
857EOT
858
859 nsp = NamespacePath.new( :nMruby, true )
860 nsp.append! ct_name
861 ct = Namespace.find nsp
862
863 ct.get_cell_list.each{ |cell|
864 if cell.is_generate? then
865 join_list = cell.get_join_list
866 join = join_list.get_item( :bridgeName )
867 if join == nil then
868 name = "\"#{cell.get_name}\""
869 else
870 rhs = join.get_rhs
871 attr_list = cell.get_celltype.get_attribute_list
872 name = rhs.eval_const join_list, attr_list
873 end
874
875 name_array = ct.get_name_array( cell )
876 file.print "\t{ #{name}, #{name_array[8]} },\n"
877 end
878 }
879
880 file.print <<EOT
881\t{ 0, 0 },
882};
883
884EOT
885
886 end
887
888 def gen_preamble_ptr( file, b_singleton, ct_name, global_ct_name )
889 tment = @@ptr_list[ ct_name ]
890 file.print <<EOT
891
892GET_SET_#{tment[3]}( #{tment[1]}, #{tment[0]} )
893POINTER_CLASS( #{tment[1]}, #{tment[0]} )
894EOT
895 end
896
897 def gen_preamble_struct( file, b_singleton, ct_name, global_ct_name )
898 tag = ct_name
899 structType = @@struct_list[ tag ]
900 file.print <<EOT
901/* struct #{tag} */
902STRUCT_CLASS( #{tag} )
903EOT
904
905 structType.get_members_decl.get_items.each{ |d|
906 type = d.get_type.get_original_type
907 case type
908 when IntType, CIntType
909 bit_size = type.get_bit_size
910 case bit_size
911 when -11, -1
912 tType = "Char"
913 ttype = "char"
914 when -2
915 tType = "Short"
916 ttype = "short"
917 when -3
918 tType = "Int"
919 ttype = "int"
920 when -4
921 tType = "Long"
922 ttype = "long"
923 when -5
924 tType = "IntPtr"
925 ttype = "intptr"
926 when 8, 16, 32, 64
927 tType = "Int#{bit_size}"
928 ttype = "int#{bit_size}"
929 else
930 raise "MrubyBridgeSignaturePlugin: MrubyBridgeSignaturePlugin: cannot handle bit_size #{bit_size}"
931 end
932 file.print "MEMBER_GET_SET_INT( #{tag}, #{d.get_name}, #{tType}, #{ttype} )\n"
933 when FloatType, CFloatType
934 file.print "MEMBER_GET_SET_FLOAT( #{tag}, #{d.get_name} )\n"
935 else
936 raise "MrubyBridgeSignaturePlugin: MrubyBridgeSignaturePlugin: cannot handle type"
937 end
938 }
939
940 end
941
942 def gen_preamble_instance_proto( file, b_singleton, ct_name, global_ct_name )
943 file.print <<EOT
944// Prototype MBP400
945mrb_value MrubyBridge_#{@celltype_name}_initialize( mrb_state *mrb, mrb_value self);
946EOT
947
948 @func_head_array.each{ |f|
949 if ! f.is_function? then
950 next
951 end
952 if f.get_name != :initialize then
953 func_name = f.get_name
954 else
955 func_name = :initialize_cell
956 end
957
958 ret_type = f.get_return_type
959 ret_type0 = f.get_return_type.get_original_type
960 b_void = ret_type0.is_void?
961 plist = f.get_paramlist.get_items
962
963 file.print <<EOT
964mrb_value MrubyBridge_#{@celltype_name}_#{func_name}( mrb_state *mrb, mrb_value self );
965EOT
966 }
967 end
968
969 def gen_preamble_instance_initialize( file, b_singleton, ct_name, global_ct_name )
970 file.print <<EOT
971
972/* MBP100 */
973mrb_value
974MrubyBridge_#{@celltype_name}_initialize( mrb_state *mrb, mrb_value self)
975{
976 mrb_value name;
977 struct tecs_#{@celltype_name} *tecs_cb;
978 const struct name_to_cbp_#{@celltype_name} *ntc;
979
980 /* set DATA_TYPE earlier to avoid SEGV */
981 DATA_TYPE( self ) = &data_type_#{@celltype_name};
982
983 mrb_get_args(mrb, "o", &name );
984 if( mrb_type( name ) != MRB_TT_STRING ){
985 mrb_raise(mrb, E_NAME_ERROR, "cell name not string");
986 }
987 for( ntc = &Name_to_cbp_#{@celltype_name}[0]; ntc->name != NULL; ntc++ ){
988 if( strcmp( ntc->name, RSTRING_PTR( name ) ) == 0 )
989 break;
990 }
991 if( ntc->name == 0 ){
992 mrb_raise(mrb, E_ARGUMENT_ERROR, "cell not found");
993 }
994 tecs_cb = (struct tecs_#{@celltype_name} *)mrb_malloc(mrb, sizeof(struct tecs_#{@celltype_name}) );
995 tecs_cb->cbp = ntc->cbp;
996 DATA_PTR( self ) = (void *)tecs_cb;
997
998 return self;
999}
1000EOT
1001 end
1002
1003 def gen_preamble_bridge_func( file, b_singleton, ct_name, global_ct_name )
1004
1005 @func_head_array.each{ |f|
1006 if ! f.is_function? then
1007 next
1008 end
1009 if f.get_name != :initialize then
1010 func_name = f.get_name
1011 else
1012 func_name = :initialize_cell
1013 end
1014
1015 ret_type = f.get_return_type
1016 ret_type0 = f.get_return_type.get_original_type
1017 b_void = ret_type0.is_void?
1018 plist = f.get_paramlist.get_items
1019
1020 file.print <<EOT
1021
1022/* bridge function (MBP101) */
1023mrb_value
1024MrubyBridge_#{ct_name}_#{func_name}( mrb_state *mrb, mrb_value self )
1025{
1026 /* cellcbp (MBP105) */
1027 CELLCB *p_cellcb = ((struct tecs_#{@celltype_name} *)DATA_PTR(self))->cbp;
1028EOT
1029
1030 file.print " /* variables for return & parameter (MBP110) */\n"
1031 if ! b_void then
1032 file.print " ", ret_type.get_type_str, "\tret_val", ret_type.get_type_str_post, ";\n"
1033 end
1034 arg_str = ""
1035 n_param = 0
1036 n_scalar = 0
1037 n_ptr = 0
1038 n_struct = 0
1039 plist.each{ |param|
1040 case param.get_direction
1041 when :IN, :INOUT, :OUT
1042 type = param.get_type.get_original_type
1043 case type
1044 when IntType
1045 file.print " mrb_int mrb_", param.get_name, ";\n"
1046 file.print " #{param.get_type.get_type_str} #{param.get_name}#{param.get_type.get_type_str_post};\n"
1047 arg_str += "i"
1048 n_param += 1
1049 n_scalar += 1
1050 when FloatType
1051 file.print " mrb_float mrb_", param.get_name, ";\n"
1052 file.print " #{param.get_type.get_type_str} #{param.get_name}#{param.get_type.get_type_str_post};\n"
1053 arg_str += "f"
1054 n_param += 1
1055 n_scalar += 1
1056 when BoolType
1057 file.print " mrb_value mrb_", param.get_name, ";\n"
1058 file.print " #{param.get_type.get_type_str} #{param.get_name}#{param.get_type.get_type_str_post};\n"
1059 arg_str += "o"
1060 n_param += 1
1061 n_scalar += 1
1062 when PtrType
1063 file.print " mrb_value mrb_", param.get_name, ";\n"
1064 file.print " #{param.get_type.get_type_str} #{param.get_name}#{param.get_type.get_type_str_post};\n"
1065 arg_str += "o"
1066 n_param += 1
1067 n_ptr += 1
1068 when StructType
1069 file.print " mrb_value mrb_", param.get_name, ";\n"
1070 file.print " #{param.get_type.get_type_str} *#{param.get_name}#{param.get_type.get_type_str_post};\n"
1071 arg_str += "o"
1072 n_param += 1
1073 n_struct += 1
1074 else
1075 raise "MrubyBridgeSignaturePlugin: Unknown type"
1076 end
1077 end
1078 }
1079
1080 if n_param > 0 then
1081 file.print " /* retrieve arguments (MBP111) */\n"
1082 file.print " mrb_get_args(mrb, \"#{arg_str}\""
1083 plist.each{ |param|
1084 case param.get_direction
1085 when :IN, :INOUT, :OUT
1086 type = param.get_type.get_original_type
1087 case type
1088 when IntType
1089 file.print ", &mrb_", param.get_name
1090 when FloatType
1091 file.print ", &mrb_", param.get_name
1092 when BoolType
1093 file.print ", &mrb_", param.get_name
1094 when PtrType
1095 file.print ", &mrb_", param.get_name
1096 when StructType
1097 file.print ", &mrb_", param.get_name
1098 else
1099 raise "MrubyBridgeSignaturePlugin: Unknown type"
1100 end
1101 end
1102 }
1103 file.print " );\n"
1104
1105 if n_scalar > 0 || n_struct > 0 then
1106 file.print " /* convert mrb to C (MBP112) */\n"
1107 end
1108 plist.each{ |param|
1109 case param.get_direction
1110 when :IN, :INOUT, :OUT
1111 type = param.get_type.get_original_type
1112 case type
1113 when IntType
1114 ttype = type.get_original_type
1115 tment = get_type_map_ent ttype
1116 file.print " VALCHECK_#{tment[1]}( mrb, mrb_#{param.get_name} );\n"
1117 file.print " #{param.get_name} = (#{param.get_type.get_type_str})mrb_#{param.get_name};\n"
1118 when FloatType
1119 file.print " #{param.get_name} = (#{param.get_type.get_type_str})mrb_#{param.get_name};\n"
1120 when BoolType
1121 file.print " #{param.get_name} = mrb_test( mrb_#{param.get_name} );\n"
1122 when PtrType
1123 ttype = type.get_type.get_original_type
1124 case ttype
1125 when StructType
1126 file.print " CHECK_STRUCT( #{ttype.get_name}, mrb_#{param.get_name} );\n"
1127 file.print " #{param.get_name} = (struct #{ttype.get_name}*)DATA_PTR(mrb_#{param.get_name});\n"
1128 when IntType
1129 when FloatType
1130 when BoolType
1131 else
1132 raise "MrubyBridgeSignaturePlugin: cannot handle type"
1133 end
1134 when StructType
1135 file.print " CHECK_STRUCT( #{type.get_name}, mrb_#{param.get_name} );\n"
1136 file.print " #{param.get_name} = (struct #{type.get_name}*)DATA_PTR(mrb_#{param.get_name});\n"
1137 else
1138 raise( "MrubyBridgeSignaturePlugin: canot treat class" )
1139 end
1140 end
1141 }
1142
1143 if n_ptr > 0 then
1144 file.print " /* convert mrb to C for pointer types (MBP113) */\n"
1145 end
1146 plist.each{ |param|
1147 case param.get_direction
1148 when :IN, :INOUT, :OUT
1149 type = param.get_type.get_original_type
1150 case type
1151 when IntType
1152 when FloatType
1153 when BoolType
1154 when PtrType
1155 case type.get_type.get_original_type
1156 when StructType
1157 when IntType
1158 ptrMrb2C file, type, param
1159 when FloatType
1160 ptrMrb2C file, type, param
1161 when BoolType
1162 ptrMrb2C file, type, param
1163 else
1164 raise "MrubyBridgeSignaturePlugin: cannot handle type"
1165 end
1166 when StructType
1167 else
1168 raise( "MrubyBridgeSignaturePlugin: canot treat class" )
1169 end
1170 end
1171 }
1172
1173 end
1174
1175 file.print " /* calling target (MBP120) */\n"
1176 if ! b_void then
1177 file.print " ret_val = "
1178 else
1179 file.print " "
1180 end
1181 delim = ""
1182 file.print "cTECS_", f.get_name, "( "
1183 plist.each{ |param|
1184 if param.get_type.get_original_type.kind_of? StructType then
1185 aster = "*"
1186 else
1187 aster = ""
1188 end
1189 file.print delim, aster, param.get_name
1190 delim = ", "
1191 }
1192 file.print " );\n"
1193
1194 file.print " /* return (MBP130) */\n"
1195 case ret_type0
1196 when BoolType
1197 file.print " return ret_val ? mrb_true_value() : mrb_false_value();\n"
1198 when IntType
1199 file.print " return mrb_fixnum_value( ret_val );\n"
1200 when FloatType
1201 file.print " return mrb_float_value( mrb, ret_val );\n"
1202 when VoidType
1203 file.print " return mrb_nil_value();\n"
1204 else
1205 raise "MrubyBridgeSignaturePlugin: unknown type"
1206 end
1207
1208 file.print "}\n"
1209 }
1210 end
1211
1212 def ptrMrb2C file, type, param
1213 ttype = type.get_type.get_original_type
1214 tment = get_type_map_ent ttype
1215 tstr = tment[1]
1216=begin
1217 case ttype
1218 when IntType
1219 bit_size = ttype.get_bit_size
1220 case bit_size
1221 when -1, -11
1222 tstr = "Char"
1223 when 8, 16, 32, 64
1224 tstr = "Int#{bit_size}"
1225 when -2
1226 tstr = "Short"
1227 when -3
1228 tstr = "Int"
1229 when -4
1230 tstr = "Long"
1231 when -5
1232 tstr = "IntPtr"
1233 else
1234 raise "MrubyBridgeSignaturePlugin: not handle type"
1235 end
1236 when FloatType
1237 if ttype.get_bit_size == 32 then
1238 tstr = "Float32"
1239 else
1240 tstr = "Double64"
1241 end
1242 when BoolType
1243 tstr = "Bool"
1244 when StructType
1245 raise "MrubyBridgeSignaturePlugin: not handle type 2 #{ttype}"
1246 else
1247 raise "MrubyBridgeSignaturePlugin: not handle type 2 #{ttype}"
1248 end
1249=end
1250 if( param.get_size ) then
1251 sz_str = param.get_size.to_s
1252 elsif param.get_string then # mikan とりあえず size_is と string の同時指定 (二重ポインタ) はなし
1253 sz_str = param.get_string.to_s
1254 else
1255 sz_str = "1"
1256 end
1257 # unsigned 型の場合には cast が必
1258要
1259 if ttype.get_original_type.get_type_str != param.get_type.get_type.get_type_str then
1260 cast_str = "(#{param.get_type.get_type_str})"
1261 else
1262 cast_str = ""
1263 end
1264
1265 modify = ""
1266 case param.get_direction
1267 when :OUT, :INOUT
1268 case tstr
1269 when "Char", "SChar", "UChar"
1270 modify = "Mod"
1271 end
1272 end
1273 if param.is_nullable? then
1274 nullable = "Nullable"
1275 else
1276 nullable = ""
1277 end
1278
1279 # file.print " CHECK_POINTER( #{tstr}, mrb_#{param.get_name}, #{sz_str} );\n"
1280 # file.print " #{param.get_name} = #{cast_str}((struct #{tstr}PointerBody*)(DATA_PTR(mrb_#{param.get_name})))->buf;\n"
1281 file.print " #{param.get_name} = CheckAndGet#{tstr}Pointer#{modify}#{nullable}( mrb, mrb_#{param.get_name}, #{sz_str} );\n"
1282 end
1283
1284 def get_celltype_name
1285 @celltype_name
1286 end
1287
1288 #=== プラグイン引数 ignoreUnsigned
1289 def set_ignoreUnsigned rhs
1290 if rhs == "true" || rhs == nil then
1291 @b_ignoreUnsigned = true
1292 end
1293 end
1294 #=== プラグイン引数 include
1295 def set_include rhs
1296 funcs = rhs.split ','
1297 funcs.each{ |rhs_func|
1298 found = false
1299 rhs_func.gsub!( /\s/, "" )
1300 @signature.get_function_head_array.each{ |a|
1301 if rhs_func.to_sym == a.get_name then
1302 found = true
1303 end
1304 }
1305 if found == false then
1306 cdl_error( "MRB1009 include function '$1' not found in signagture '$2'", rhs, @signature.get_name )
1307 else
1308 @includes << rhs_func.to_sym
1309 end
1310 }
1311 end
1312 #=== プラグイン引数 exclude
1313 def set_exclude rhs
1314 funcs = rhs.split ','
1315 funcs.each{ |rhs_func|
1316 rhs_func.gsub!( /\s/, "" )
1317 func_head = @signature.get_function_head rhs_func.to_sym
1318 if func_head == false then
1319 cdl_error( "MRB1010 exclude function '$1' not found in signagture '$2", rhs, @signature.get_name )
1320 else
1321 @excludes << rhs_func.to_sym
1322 end
1323 }
1324 end
1325 #=== プラグイン引数 auto_exclude
1326 def set_auto_exclude rhs
1327 if rhs == "false" then
1328 @b_auto_exclude = false
1329 elsif rhs == "true" then
1330 @b_auto_exclude = true # auto_exclude = true by default
1331 else
1332 cdl_warning( "MRB9999 auto_exclude: unknown rhs value ignored. specify true or false" )
1333 end
1334 end
1335end
1336
Note: See TracBrowser for help on using the repository browser.