[270] | 1 | # -*- coding: utf-8 -*-
|
---|
| 2 | #
|
---|
| 3 | # TECS Generator
|
---|
| 4 | # Generator for TOPPERS Embedded Component System
|
---|
| 5 | #
|
---|
| 6 | # Copyright (C) 2008-2014 by TOPPERS Project
|
---|
| 7 | #--
|
---|
| 8 | # 上記著作権者は,以下の(1)~(4)の条件を満たす場合に限り,本ソフトウェ
|
---|
| 9 | # ア(本ソフトウェアを改変したものを含む.以下同じ)を使用・複製・改
|
---|
| 10 | # 変・再配布(以下,利用と呼ぶ)することを無償で許諾する.
|
---|
| 11 | # (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
|
---|
| 12 | # 権表示,この利用条件および下記の無保証規定が,そのままの形でソー
|
---|
| 13 | # スコード中に含まれていること.
|
---|
| 14 | # (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
|
---|
| 15 | # 用できる形で再配布する場合には,再配布に伴うドキュメント(利用
|
---|
| 16 | # 者マニュアルなど)に,上記の著作権表示,この利用条件および下記
|
---|
| 17 | # の無保証規定を掲載すること.
|
---|
| 18 | # (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
|
---|
| 19 | # 用できない形で再配布する場合には,次のいずれかの条件を満たすこ
|
---|
| 20 | # と.
|
---|
| 21 | # (a) 再配布に伴うドキュメント(利用者マニュアルなど)に,上記の著
|
---|
| 22 | # 作権表示,この利用条件および下記の無保証規定を掲載すること.
|
---|
| 23 | # (b) 再配布の形態を,別に定める方法によって,TOPPERSプロジェクトに
|
---|
| 24 | # 報告すること.
|
---|
| 25 | # (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
|
---|
| 26 | # 害からも,上記著作権者およびTOPPERSプロジェクトを免責すること.
|
---|
| 27 | # また,本ソフトウェアのユーザまたはエンドユーザからのいかなる理
|
---|
| 28 | # 由に基づく請求からも,上記著作権者およびTOPPERSプロジェクトを
|
---|
| 29 | # 免責すること.
|
---|
| 30 | #
|
---|
| 31 | # 本ソフトウェアは,無保証で提供されているものである.上記著作権者お
|
---|
| 32 | # よびTOPPERSプロジェクトは,本ソフトウェアに関して,特定の使用目的
|
---|
| 33 | # に対する適合性も含めて,いかなる保証も行わない.また,本ソフトウェ
|
---|
| 34 | # アの利用により直接的または間接的に生じたいかなる損害に関しても,そ
|
---|
| 35 | # の責任を負わない.
|
---|
| 36 | #
|
---|
[321] | 37 | # $Id$
|
---|
[270] | 38 | #++
|
---|
| 39 |
|
---|
| 40 | #プラグインオプション用変数
|
---|
| 41 | #@task_priority:: Integer
|
---|
| 42 | #@channelCelltype:: String
|
---|
| 43 | #@channelCellName:: String
|
---|
| 44 | #@PPAllocatorSize:: Integer
|
---|
| 45 | module GenTransparentMarshaler
|
---|
| 46 |
|
---|
| 47 | # プラグイン引数名と Proc
|
---|
| 48 | RPCPluginArgProc = {
|
---|
| 49 | "taskPriority" => Proc.new { |obj,rhs| obj.set_taskPriority rhs },
|
---|
| 50 | "channelCelltype" => Proc.new { |obj,rhs| obj.set_channelCelltype rhs },
|
---|
| 51 | "TDRCelltype" => Proc.new { |obj,rhs| obj.set_TDRCelltype rhs },
|
---|
| 52 | "channelCell" => Proc.new { |obj,rhs| obj.set_channelCellName rhs },
|
---|
| 53 | "PPAllocatorSize" => Proc.new { |obj,rhs| obj.set_PPAllocatorSize rhs },
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | #=== プラグイン引数 taskPriority のチェック
|
---|
| 57 | def set_taskPriority( rhs )
|
---|
| 58 | @task_priority = rhs
|
---|
| 59 | end
|
---|
| 60 |
|
---|
| 61 | #=== プラグイン引数 channelCelltype のチェック
|
---|
| 62 | def set_channelCelltype( rhs )
|
---|
| 63 | @channelCelltype = rhs.to_sym
|
---|
| 64 | # path = [ "::", @channelCelltype ]
|
---|
| 65 | # obj = Namespace.find( path )
|
---|
| 66 | nsp = NamespacePath.analyze( @channelCelltype.to_s )
|
---|
| 67 | obj = Namespace.find( nsp )
|
---|
| 68 | if ! obj.instance_of?( Celltype ) && ! obj.instance_of?( CompositeCelltype ) then
|
---|
| 69 | cdl_error( "RPCPlugin: channeclCelltype '#{rhs}' not celltype or not found" )
|
---|
| 70 | end
|
---|
| 71 | end
|
---|
| 72 |
|
---|
| 73 | #=== プラグイン引数 TDRCelltype のチェック
|
---|
| 74 | def set_TDRCelltype( rhs )
|
---|
| 75 | @TDRCelltype = rhs.to_sym
|
---|
| 76 | # path = [ "::", @TDRCelltype ]
|
---|
| 77 | # obj = Namespace.find( path )
|
---|
| 78 | nsp = NamespacePath.analyze( @TDRCelltype.to_s )
|
---|
| 79 | obj = Namespace.find( nsp )
|
---|
| 80 | if ! obj.instance_of?( Celltype ) && ! obj.instance_of?( CompositeCelltype ) then
|
---|
| 81 | cdl_error( "RPCPlugin: TDRCelltype '#{rhs}' not celltype or not found" )
|
---|
| 82 | end
|
---|
| 83 | end
|
---|
| 84 |
|
---|
| 85 | #=== プラグイン引数 channelCellName のチェック
|
---|
| 86 | def set_channelCellName( rhs )
|
---|
| 87 | @channelCellName = rhs
|
---|
| 88 | if @channelCellName =~ /\A[a-zA-Z_]\w*/ then
|
---|
| 89 | # OK
|
---|
| 90 | else
|
---|
| 91 | cdl_error( "RPCPlugin: channeclCellName '#{rhs}' unsuitable for identifier" )
|
---|
| 92 | end
|
---|
| 93 | end
|
---|
| 94 |
|
---|
| 95 | #=== プラグイン引数 PPAllocatorSize のチェック
|
---|
| 96 | def set_PPAllocatorSize( rhs )
|
---|
| 97 | @PPAllocatorSize = rhs
|
---|
| 98 | end
|
---|
| 99 |
|
---|
| 100 | #=== marshaler のセルタイプ名を設定する
|
---|
| 101 | def initialize_transparent_marshaler cell_name
|
---|
| 102 | @task_priority = 8
|
---|
| 103 | @channelCelltype = "tDataqueueOWChannel"
|
---|
| 104 | @TDRCelltype = "tTDR"
|
---|
| 105 | @channelCellName = "#{cell_name}_Channel"
|
---|
| 106 | @PPAllocatorSize = nil
|
---|
| 107 |
|
---|
| 108 | @marshaler_celltype_name = "tMarshaler_#{@signature.get_global_name}"
|
---|
| 109 | @unmarshaler_celltype_name = "tUnmarshaler_#{@signature.get_global_name}"
|
---|
| 110 | @marshaler_celltype_file_name = "#{$gen}/#{@marshaler_celltype_name}.cdl"
|
---|
| 111 | end
|
---|
| 112 |
|
---|
| 113 | def gen_marshaler_celltype
|
---|
| 114 |
|
---|
| 115 | if @PPAllocatorSize then
|
---|
| 116 | alloc_call_port = " call sPPAllocator cPPAllocator;\n"
|
---|
| 117 | else
|
---|
| 118 | alloc_call_port = ""
|
---|
| 119 | end
|
---|
| 120 |
|
---|
| 121 | f = CFile.open( @marshaler_celltype_file_name, "w" )
|
---|
| 122 | # 同じ内容を二度書く可能性あり (AppFile は不可)
|
---|
| 123 |
|
---|
| 124 | f.print <<EOT
|
---|
| 125 |
|
---|
| 126 | celltype #{@marshaler_celltype_name} {
|
---|
| 127 | entry #{@signature.get_namespace_path} eClientEntry;
|
---|
| 128 | call sTDR cTDR;
|
---|
| 129 | call sEventflag cEventflag;
|
---|
| 130 | [optional]
|
---|
| 131 | call sSemaphore cLockChannel; // this port is eliminated by optimize
|
---|
| 132 | };
|
---|
| 133 | celltype #{@unmarshaler_celltype_name} {
|
---|
| 134 | call #{@signature.get_namespace_path} cServerCall;
|
---|
| 135 | call sTDR cTDR;
|
---|
| 136 | call sEventflag cEventflag;
|
---|
| 137 | entry sUnmarshalerMain eUnmarshalAndCallFunction;
|
---|
| 138 | #{alloc_call_port}};
|
---|
| 139 | EOT
|
---|
| 140 | f.close
|
---|
| 141 | end
|
---|
| 142 |
|
---|
| 143 | #=== 受け口関数の本体コードを生成(頭部と末尾は別途出力)
|
---|
| 144 | #ct_name:: Symbol (through プラグインで生成された) セルタイプ名 .Symbol として送られてくる(らしい)
|
---|
| 145 | 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 )
|
---|
| 146 |
|
---|
| 147 | # unmarshaler クラスか?
|
---|
| 148 | if ct_name == @unmarshaler_celltype_name.to_sym then
|
---|
| 149 | gen_ep_func_body_unmarshal( file, b_singleton, ct_name, global_ct_name, sig_name, ep_name, func_name, func_global_name, func_type, params )
|
---|
| 150 | else
|
---|
| 151 | gen_ep_func_body_marshal( file, b_singleton, ct_name, global_ct_name, sig_name, ep_name, func_name, func_global_name, func_type, params )
|
---|
| 152 | end
|
---|
| 153 | end
|
---|
| 154 |
|
---|
| 155 | #=== marshal コードの生成
|
---|
| 156 | def gen_ep_func_body_marshal( file, b_singleton, ct_name, global_ct_name, sig_name, ep_name, func_name, func_global_name, func_type, params )
|
---|
| 157 |
|
---|
| 158 | b_void = false
|
---|
| 159 | b_ret_er = false
|
---|
| 160 |
|
---|
| 161 | # 関数の戻り値の元の型を得る(typedef されている場合)
|
---|
| 162 | type = func_type.get_type.get_original_type
|
---|
| 163 |
|
---|
| 164 | # 戻り値記憶用の変数を出力(void 型の関数では出力しない)
|
---|
| 165 | if ! type.is_void? then
|
---|
| 166 | if func_type.get_type.kind_of?( DefinedType ) && ( func_type.get_type.get_type_str == "ER" || func_type.get_type.get_type_str == "ER_INT" ) then
|
---|
| 167 | file.print( " #{func_type.get_type.get_type_str} retval_ = E_OK;\n" )
|
---|
| 168 | b_ret_er = true
|
---|
| 169 | else
|
---|
| 170 | file.print( " #{func_type.get_type.get_type_str} retval_;\n" )
|
---|
| 171 | end
|
---|
| 172 | else
|
---|
| 173 | b_void = true
|
---|
| 174 | end
|
---|
| 175 |
|
---|
| 176 | file.print( " ER ercd_;\n" )
|
---|
| 177 | file.print( " FLGPTN flgptn;\n" )
|
---|
| 178 |
|
---|
| 179 | # 呼び先の signature を取り出す
|
---|
| 180 | signature = @signature
|
---|
| 181 |
|
---|
| 182 | # 関数 ID (整数値)
|
---|
| 183 | func_id = signature.get_id_from_func_name( func_name )
|
---|
| 184 | file.print( " int16_t func_id_ = #{func_id}; /* id of #{func_name}: #{func_id} */\n" )
|
---|
| 185 |
|
---|
| 186 | # シングルトンでないか?
|
---|
| 187 | if ! b_singleton then
|
---|
| 188 |
|
---|
| 189 | # singleton でなければ p_cellcb 取得コードを出力
|
---|
| 190 | file.print <<EOT
|
---|
| 191 | #{ct_name}_CB *p_cellcb;
|
---|
| 192 |
|
---|
| 193 | if( VALID_IDX( idx ) ){
|
---|
| 194 | p_cellcb = GET_CELLCB(idx);
|
---|
| 195 | EOT
|
---|
| 196 |
|
---|
| 197 | # エラーを返すか?
|
---|
| 198 | if b_ret_er then
|
---|
| 199 | file.print <<EOT
|
---|
| 200 | }else{
|
---|
| 201 | return ERCD( E_RPC, E_ID );
|
---|
| 202 | }
|
---|
| 203 | EOT
|
---|
| 204 | else
|
---|
| 205 | file.print <<EOT
|
---|
| 206 | }else{
|
---|
| 207 | /* エラー処理コードをここに記述 */
|
---|
| 208 | }
|
---|
| 209 | EOT
|
---|
| 210 | end
|
---|
| 211 | end
|
---|
| 212 |
|
---|
| 213 | # channel lock コード
|
---|
| 214 | file.print <<EOT
|
---|
| 215 | /* Channel Lock */
|
---|
| 216 | if( is_cLockChannel_joined() )
|
---|
| 217 | cLockChannel_wait();
|
---|
| 218 |
|
---|
| 219 | EOT
|
---|
| 220 |
|
---|
| 221 | # SOP を送信
|
---|
| 222 | file.print " /* SOPの送出 */\n"
|
---|
| 223 | file.print " if( ( ercd_ = cTDR_sendSOP( true ) ) != E_OK )\n"
|
---|
| 224 | file.print " goto error_reset;\n"
|
---|
| 225 |
|
---|
| 226 | # func_id を送信
|
---|
| 227 | file.print " /* 関数 id の送出 */\n"
|
---|
| 228 | file.print " if( ( ercd_ = cTDR_putInt16( func_id_ ) ) != E_OK )\n"
|
---|
| 229 | file.print " goto error_reset;\n"
|
---|
| 230 |
|
---|
| 231 | # p "celltype_name, sig_name, func_name, func_global_name"
|
---|
| 232 | # p "#{ct_name}, #{sig_name}, #{func_name}, #{func_global_name}"
|
---|
| 233 |
|
---|
| 234 | b_get = false # marshal なら put
|
---|
| 235 | b_marshal = true # marshal
|
---|
| 236 |
|
---|
| 237 | # in 方向の入出力を出力
|
---|
| 238 | file.print " /* 入力引数送出 */\n"
|
---|
| 239 | print_params( params, file, 1, b_marshal, b_get, true, func_type.is_oneway? )
|
---|
| 240 | print_params( params, file, 1, b_marshal, b_get, false, func_type.is_oneway? )
|
---|
| 241 | if ! b_void && ! func_type.is_oneway? then
|
---|
| 242 | ret_ptr_type = PtrType.new( func_type.get_type )
|
---|
| 243 | print_param_nc( "retval_", ret_ptr_type, file, 1, :RETURN, "&", nil, b_get )
|
---|
| 244 | end
|
---|
| 245 |
|
---|
| 246 | file.print " /* EOPの送出(パケットの掃きだし) */\n"
|
---|
| 247 | if ! func_type.is_oneway? then
|
---|
| 248 | b_continue = "true"
|
---|
| 249 | else
|
---|
| 250 | b_continue = "false"
|
---|
| 251 | end
|
---|
| 252 | file.print " if( (ercd_=cTDR_sendEOP(#{b_continue})) != E_OK )\n"
|
---|
| 253 | file.print " goto error_reset;\n\n"
|
---|
| 254 |
|
---|
| 255 | if ! func_type.is_oneway? then
|
---|
| 256 | file.print <<EOT
|
---|
| 257 | if( (ercd_=cEventflag_wait( 0x01, TWF_ANDW, &flgptn )) != E_OK ){
|
---|
| 258 | ercd_ = ERCD(E_RPC,ercd_);
|
---|
| 259 | goto error_reset;
|
---|
| 260 | }
|
---|
| 261 | if( (ercd_=cEventflag_clear( 0x00 ) ) != E_OK ){
|
---|
| 262 | ercd_ = ERCD(E_RPC,ercd_);
|
---|
| 263 | goto error_reset;
|
---|
| 264 | }
|
---|
| 265 | EOT
|
---|
| 266 | end # ! func_type.is_oneway?
|
---|
| 267 |
|
---|
| 268 | file.print <<EOT
|
---|
| 269 | /* Channel Lock */
|
---|
| 270 | if( is_cLockChannel_joined() )
|
---|
| 271 | cLockChannel_signal();
|
---|
| 272 | EOT
|
---|
| 273 |
|
---|
| 274 | if( b_void == false )then
|
---|
| 275 | # 呼び元に戻り値をリターン
|
---|
| 276 | file.print( " return retval_;\n" )
|
---|
| 277 | else
|
---|
| 278 | file.print( " return;\n" )
|
---|
| 279 | end
|
---|
| 280 |
|
---|
| 281 | file.print <<EOT
|
---|
| 282 |
|
---|
| 283 | error_reset:
|
---|
| 284 | if( ercd_ != ERCD( E_RPC, E_RESET ) )
|
---|
| 285 | (void)cTDR_reset();
|
---|
| 286 | EOT
|
---|
| 287 |
|
---|
| 288 | # channel lock コード
|
---|
| 289 | file.print <<EOT
|
---|
| 290 | /* Channel Lock */
|
---|
| 291 | if( is_cLockChannel_joined() )
|
---|
| 292 | cLockChannel_signal();
|
---|
| 293 |
|
---|
| 294 | EOT
|
---|
| 295 |
|
---|
| 296 | if( b_ret_er != false )then
|
---|
| 297 | # 呼び元に戻り値をリターン
|
---|
| 298 | file.print( " return ercd_;\n" )
|
---|
| 299 | else
|
---|
| 300 | file.print( " return;\n" )
|
---|
| 301 | end
|
---|
| 302 |
|
---|
| 303 | end
|
---|
| 304 |
|
---|
| 305 | #=== unmarshal コードの生成
|
---|
| 306 | def gen_ep_func_body_unmarshal( file, b_singleton, ct_name, global_ct_name, sig_name, ep_name, func_name, func_global_name, func_type, params )
|
---|
| 307 |
|
---|
| 308 | # b_ret_er = true
|
---|
| 309 | b_ret_er = false
|
---|
| 310 |
|
---|
| 311 | # func_id を得るコードを生成
|
---|
| 312 | file.print <<EOT
|
---|
| 313 |
|
---|
| 314 | int16_t func_id_;
|
---|
| 315 | ER ercd_;
|
---|
| 316 |
|
---|
| 317 | #{ct_name}_CB *p_cellcb;
|
---|
| 318 |
|
---|
| 319 | if( VALID_IDX( idx ) ){
|
---|
| 320 | p_cellcb = GET_CELLCB(idx);
|
---|
| 321 | EOT
|
---|
| 322 |
|
---|
| 323 | if b_ret_er then
|
---|
| 324 | file.print <<EOT
|
---|
| 325 | }else{
|
---|
| 326 | return ERCD( E_RPC, E_ID );
|
---|
| 327 | }
|
---|
| 328 | EOT
|
---|
| 329 | else
|
---|
| 330 | file.print <<EOT
|
---|
| 331 | }else{
|
---|
| 332 | /* エラー処理コードをここに記述 */
|
---|
| 333 | }
|
---|
| 334 | EOT
|
---|
| 335 | end
|
---|
| 336 |
|
---|
| 337 | file.print <<EOT
|
---|
| 338 |
|
---|
| 339 | /* SOPのチェック */
|
---|
| 340 | if( (ercd_=cTDR_receiveSOP( false )) != E_OK )
|
---|
| 341 | goto error_reset;
|
---|
| 342 | /* func_id の取得 */
|
---|
| 343 | if( (ercd_=cTDR_getInt16( &func_id_ )) != E_OK )
|
---|
| 344 | goto error_reset;
|
---|
| 345 |
|
---|
| 346 | #ifdef RPC_DEBUG
|
---|
| 347 | syslog(LOG_INFO, "unmarshaler task: func_id: %d", func_id_ );
|
---|
| 348 | #endif
|
---|
| 349 | switch( func_id_ ){
|
---|
| 350 | EOT
|
---|
| 351 |
|
---|
| 352 | # 呼び先の signature を取り出す
|
---|
| 353 | # port = @celltype.find( @next_cell_port_name )
|
---|
| 354 | # signature = port.get_signature
|
---|
| 355 | signature = @signature
|
---|
| 356 |
|
---|
| 357 | # through の signature に含まれる すべての関数について
|
---|
| 358 | signature.get_function_head_array.each { |f|
|
---|
| 359 | f_name = f.get_name
|
---|
| 360 | f_type = f.get_declarator.get_type
|
---|
| 361 | id = signature.get_id_from_func_name( f_name )
|
---|
| 362 |
|
---|
| 363 | # 関数は返り値を持つか?
|
---|
| 364 | if f_type.get_type.is_void? then
|
---|
| 365 | b_void = true
|
---|
| 366 | else
|
---|
| 367 | b_void = false
|
---|
| 368 | end
|
---|
| 369 |
|
---|
| 370 | # パケットの終わりをチェック(未受け取りのデータが残っていないかチェック)
|
---|
| 371 | file.print " case #{id}: /*** #{f_name} ***/ \n"
|
---|
| 372 | file.print " if( tTransparentUnmarshaler_#{@signature.get_global_name}_#{f_name}() != E_OK )\n"
|
---|
| 373 | file.print " goto error_reset;\n"
|
---|
| 374 | file.print " break;\n"
|
---|
| 375 |
|
---|
| 376 | } #
|
---|
| 377 |
|
---|
| 378 | if @PPAllocatorSize then
|
---|
| 379 | ppallocator_dealloc_str = " /* PPAllocator のすべてを解放 */\n cPPAllocator_dealloc_all();"
|
---|
| 380 | else
|
---|
| 381 | ppallocator_dealloc_str = ""
|
---|
| 382 | end
|
---|
| 383 |
|
---|
| 384 |
|
---|
| 385 | file.print <<EOT
|
---|
| 386 | default:
|
---|
| 387 | syslog(LOG_INFO, "unmarshaler task: ERROR: unknown func_id: %d", func_id_ );
|
---|
| 388 | };
|
---|
| 389 | #{ppallocator_dealloc_str}
|
---|
[429] | 390 | return E_OK;
|
---|
[270] | 391 |
|
---|
| 392 | error_reset:
|
---|
| 393 | if( ercd_ != ERCD( E_RPC, E_RESET ) )
|
---|
| 394 | (void)cTDR_reset();
|
---|
| 395 | #{ppallocator_dealloc_str}
|
---|
[429] | 396 | return E_OK;
|
---|
[270] | 397 | EOT
|
---|
| 398 |
|
---|
| 399 | end
|
---|
| 400 |
|
---|
| 401 | # IN b_marshal, b_get
|
---|
| 402 | # b_marshal = true && b_get == false : マーシャラで入力引数送出
|
---|
| 403 | # b_marshal = true && b_get == true : マーシャラで出力引数受取
|
---|
| 404 | # b_marshal = false && b_get == true : アンマーシャラで入力引数受取
|
---|
| 405 | # b_marshal = false && b_get == get : アンマーシャラで出力引数送出
|
---|
| 406 | def print_params( params, file, nest, b_marshal, b_get, b_referenced, b_oneway = false )
|
---|
| 407 | params.each{ |param|
|
---|
| 408 | # p "#{param.get_name}: b_marshal: #{b_marshal} b_get: #{b_get}"
|
---|
| 409 | if ! ( b_referenced == param.is_referenced? ) then
|
---|
| 410 | next
|
---|
| 411 | end
|
---|
| 412 |
|
---|
| 413 | dir = param.get_direction
|
---|
| 414 | type = param.get_type
|
---|
| 415 | if b_oneway && dir == :IN && type.get_original_type.kind_of?( PtrType ) || type.get_original_type.kind_of?( ArrayType ) then
|
---|
| 416 | # oneway, in, PtrType の場合コピー
|
---|
| 417 | alloc_cp = "cPPAllocator_alloc"
|
---|
| 418 | alloc_cp_extra = nil
|
---|
| 419 | print_param( param.get_name, type, file, nest, dir, nil, nil, b_marshal, b_get, alloc_cp, alloc_cp_extra )
|
---|
| 420 | else
|
---|
| 421 | if( b_get == false && b_marshal == true || b_get == true && b_marshal == false )then
|
---|
| 422 | case dir
|
---|
| 423 | # when :IN, :INOUT, :SEND
|
---|
| 424 | when :IN, :INOUT, :OUT, :SEND, :RECEIVE
|
---|
| 425 | print_param_nc( param.get_name, type, file, nest, b_marshal, nil, nil, b_get )
|
---|
| 426 | end
|
---|
| 427 | else
|
---|
| 428 | # case dir
|
---|
| 429 | # when :OUT, :INOUT, :RECEIVE
|
---|
| 430 | # when :RECEIVE
|
---|
| 431 | # print_param_nc( param.get_name, type, file, nest, b_marshal, nil, nil, b_get )
|
---|
| 432 | # end
|
---|
| 433 | end
|
---|
| 434 | end
|
---|
| 435 | }
|
---|
| 436 | end
|
---|
| 437 |
|
---|
| 438 | #=== コピーしない引数渡しコードの出力
|
---|
| 439 | def print_param_nc( name, type, file, nest, b_marshal, outer, outer2, b_get )
|
---|
| 440 | indent = " " * ( nest + 1 )
|
---|
| 441 |
|
---|
| 442 | case type
|
---|
| 443 | when DefinedType
|
---|
| 444 | print_param_nc( name, type.get_type, file, nest, b_marshal, outer, outer2, b_get )
|
---|
| 445 | when BoolType, IntType, FloatType, PtrType, ArrayType
|
---|
| 446 | case type
|
---|
| 447 | when BoolType
|
---|
| 448 | type_str = "Int8"
|
---|
| 449 | cast_str = "int8_t"
|
---|
| 450 | when IntType
|
---|
| 451 | bit_size = type.get_bit_size
|
---|
| 452 | case type.get_sign
|
---|
| 453 | when :UNSIGNED
|
---|
| 454 | signC = "U"
|
---|
| 455 | sign = "u"
|
---|
| 456 | when :SIGNED
|
---|
| 457 | if bit_size == -1 || bit_size == -11 then
|
---|
| 458 | # signed char の場合、signed を指定する
|
---|
| 459 | signC = "S"
|
---|
| 460 | sign = "s"
|
---|
| 461 | else
|
---|
| 462 | signC = ""
|
---|
| 463 | sign = ""
|
---|
| 464 | end
|
---|
| 465 | else
|
---|
| 466 | signC = ""
|
---|
| 467 | sign = ""
|
---|
| 468 | end
|
---|
| 469 |
|
---|
| 470 | # p "pn:: #{name} #{bit_size} #{type.get_type_str}"
|
---|
| 471 | case bit_size
|
---|
| 472 | when -1, -11 # -1: char_t, -11: char
|
---|
| 473 | type_str = "#{signC}Char"
|
---|
| 474 | cast_str = "#{sign}char_t"
|
---|
| 475 | when -2
|
---|
| 476 | type_str = "#{signC}Short"
|
---|
| 477 | cast_str = "#{sign}short_t"
|
---|
| 478 | when -3
|
---|
| 479 | type_str = "#{signC}Int"
|
---|
| 480 | cast_str = "#{sign}int_t"
|
---|
| 481 | when -4
|
---|
| 482 | type_str = "#{signC}Long"
|
---|
| 483 | cast_str = "#{sign}long_t"
|
---|
| 484 | when -5
|
---|
| 485 | type_str = "Intptr"
|
---|
| 486 | cast_str = "intptr_t"
|
---|
| 487 | when 8, 16, 32, 64, 128
|
---|
| 488 | type_str = "#{signC}Int#{bit_size}"
|
---|
| 489 | cast_str = "#{sign}int#{bit_size}_t"
|
---|
| 490 | else
|
---|
| 491 | raise "unknown bit_size '#{bit_size}' for int type "
|
---|
| 492 | end
|
---|
| 493 |
|
---|
| 494 | when FloatType
|
---|
| 495 | bit_size = type.get_bit_size
|
---|
| 496 | if bit_size == 32 then
|
---|
| 497 | type_str = "Float32"
|
---|
| 498 | cast_str = "float32_t"
|
---|
| 499 | else
|
---|
| 500 | type_str = "Double64"
|
---|
| 501 | cast_str = "double64_t"
|
---|
| 502 | end
|
---|
| 503 |
|
---|
| 504 | when PtrType
|
---|
| 505 | type_str = "Intptr"
|
---|
| 506 | cast_str = "intptr_t"
|
---|
| 507 | when ArrayType
|
---|
| 508 | type_str = "Intptr"
|
---|
| 509 | cast_str = "intptr_t"
|
---|
| 510 | end
|
---|
| 511 |
|
---|
| 512 | if type.get_type_str == cast_str then
|
---|
| 513 | cast_str = ""
|
---|
| 514 | else
|
---|
| 515 | cast_str = "(" + cast_str + ")"
|
---|
| 516 | end
|
---|
| 517 |
|
---|
| 518 | if( b_get )then
|
---|
| 519 | cast_str.gsub!( /\)$/, "*)" )
|
---|
| 520 | file.print " " * nest
|
---|
| 521 | file.print "if( ( ercd_ = cTDR_get#{type_str}( #{cast_str}&(#{outer}#{name}#{outer2}) ) ) != E_OK )\n"
|
---|
| 522 | file.print " " * nest
|
---|
| 523 | file.print " goto error_reset;\n"
|
---|
| 524 | else
|
---|
| 525 | file.print " " * nest
|
---|
| 526 | file.print "if( ( ercd_ = cTDR_put#{type_str}( #{cast_str}#{outer}#{name}#{outer2} ) ) != E_OK )\n"
|
---|
| 527 | file.print " " * nest
|
---|
| 528 | file.print " goto error_reset;\n"
|
---|
| 529 | end
|
---|
| 530 |
|
---|
| 531 | when StructType
|
---|
| 532 | members_decl =type.get_members_decl
|
---|
| 533 | members_decl.get_items.each { |m|
|
---|
| 534 | if m.is_referenced? then
|
---|
| 535 | print_param_nc( m.get_name, m.get_type, file, nest, b_marshal, "#{outer}#{name}#{outer2}.", nil, b_get )
|
---|
| 536 | end
|
---|
| 537 | }
|
---|
| 538 | members_decl.get_items.each { |m|
|
---|
| 539 | if ! m.is_referenced? then
|
---|
| 540 | print_param_nc( m.get_name, m.get_type, file, nest, b_marshal, "#{outer}#{name}#{outer2}.", nil, b_get )
|
---|
| 541 | end
|
---|
| 542 | }
|
---|
| 543 |
|
---|
| 544 | when VoidType
|
---|
| 545 | when EnumType # mikan EnumType
|
---|
| 546 | when FuncType # mikan FuncType
|
---|
| 547 | end
|
---|
| 548 | end
|
---|
| 549 |
|
---|
| 550 |
|
---|
| 551 | #=== PREAMBLE 部のコード生成
|
---|
| 552 | # アンマーシャラセルタイプの場合、アンマーシャラ関数のプロトタイプ宣言を生成
|
---|
| 553 | def gen_preamble file, b_singleton, ct_name, global_name
|
---|
| 554 | if ct_name != @unmarshaler_celltype_name.to_sym then
|
---|
| 555 | return
|
---|
| 556 | end
|
---|
| 557 |
|
---|
| 558 | file.print "/* アンマーシャラ関数のプロトタイプ宣言 */\n"
|
---|
| 559 | # signature に含まれる すべての関数について
|
---|
| 560 | @signature.get_function_head_array.each { |f|
|
---|
| 561 | f_name = f.get_name
|
---|
| 562 | f_type = f.get_declarator.get_type
|
---|
| 563 | id = @signature.get_id_from_func_name( f_name )
|
---|
| 564 | file.print "static ER tTransparentUnmarshaler_#{@signature.get_global_name}_#{f_name}();\t/* func_id: #{id} */\n"
|
---|
| 565 | }
|
---|
| 566 | file.print "\n"
|
---|
| 567 | end
|
---|
| 568 |
|
---|
| 569 | #=== POSTAMBLE 部のコード生成
|
---|
| 570 | # アンマーシャラセルタイプの場合、アンマーシャラ関数の生成
|
---|
| 571 | def gen_postamble file, b_singleton, ct_name, global_name
|
---|
| 572 | if ct_name != @unmarshaler_celltype_name.to_sym then
|
---|
| 573 | return
|
---|
| 574 | end
|
---|
| 575 |
|
---|
| 576 | file.print "\n/*** アンマーシャラ関数 ***/\n\n"
|
---|
| 577 | @signature.get_function_head_array.each { |f|
|
---|
| 578 | f_name = f.get_name
|
---|
| 579 | f_type = f.get_declarator.get_type
|
---|
| 580 | id = @signature.get_id_from_func_name( f_name )
|
---|
| 581 |
|
---|
| 582 | # 関数は返り値を持つか?
|
---|
| 583 | if f_type.get_type.is_void? then
|
---|
| 584 | b_void = true
|
---|
| 585 | else
|
---|
| 586 | b_void = false
|
---|
| 587 | end
|
---|
| 588 |
|
---|
| 589 | file.print <<EOT
|
---|
| 590 | /*
|
---|
| 591 | * name: #{f_name}
|
---|
| 592 | * func_id: #{id}
|
---|
| 593 | */
|
---|
| 594 | EOT
|
---|
| 595 | file.print "static ER\n"
|
---|
| 596 | file.print "tTransparentUnmarshaler_#{@signature.get_global_name}_#{f_name}()\n"
|
---|
| 597 | file.print "{\n"
|
---|
| 598 | file.print " ER ercd_;\n"
|
---|
| 599 | file.print " CELLCB *p_cellcb;\n"
|
---|
| 600 |
|
---|
| 601 | # 引数を受取る変数の定義
|
---|
| 602 | param_list = f.get_declarator.get_type.get_paramlist.get_items
|
---|
| 603 | # FuncHead-> Decl-> FuncType->ParamList
|
---|
| 604 | param_list.each{ |par|
|
---|
| 605 | name = par.get_name
|
---|
| 606 | type = par.get_type
|
---|
| 607 | if type.kind_of? ArrayType then
|
---|
| 608 | type = type.get_type
|
---|
| 609 | aster = "(*"
|
---|
| 610 | aster2 = ")"
|
---|
| 611 | else
|
---|
| 612 | aster = ""
|
---|
| 613 | aster2 = ""
|
---|
| 614 | end
|
---|
| 615 |
|
---|
| 616 | type_str = type.get_type_str.gsub( /\bconst\b */, "" ) # "const" を外す
|
---|
| 617 |
|
---|
| 618 | file.printf( " %-12s %s%s%s%s;\n", type_str, aster, name, aster2, type.get_type_str_post )
|
---|
| 619 | }
|
---|
| 620 |
|
---|
| 621 | # 戻り値を受け取る変数の定義
|
---|
| 622 | if ! b_void then
|
---|
| 623 | if f.is_oneway? then
|
---|
| 624 | retval_ptr = "" # oneway の場合、受け取るが捨てられる
|
---|
| 625 | else
|
---|
| 626 | retval_ptr = "*"
|
---|
| 627 | end
|
---|
| 628 | file.printf( " %-12s #{retval_ptr}retval_%s;\n", f_type.get_type.get_type_str, f_type.get_type.get_type_str_post )
|
---|
| 629 | end
|
---|
| 630 |
|
---|
| 631 | # in 方向の入出力を入力
|
---|
| 632 | file.print "\n /* 入力引数受取 */\n"
|
---|
| 633 | b_get = true # unmarshal では get
|
---|
| 634 | b_marshal = false
|
---|
| 635 | print_params( param_list, file, 1, b_marshal, b_get, true, f.is_oneway? )
|
---|
| 636 | print_params( param_list, file, 1, b_marshal, b_get, false, f.is_oneway? )
|
---|
| 637 | if ! b_void && ! f.is_oneway? then
|
---|
| 638 | ret_ptr_type = PtrType.new( f_type.get_type )
|
---|
| 639 | print_param_nc( "retval_", ret_ptr_type, file, 2, :RETURN, nil, nil, b_get )
|
---|
| 640 | end
|
---|
| 641 |
|
---|
| 642 | # パケットの受信完了
|
---|
| 643 | # mikan 本当は、対象関数を呼出す後に実施したい.呼出しパケットの使用終わりを宣言する目的として
|
---|
| 644 | file.print " /* パケット終わりをチェック */\n"
|
---|
| 645 | if ! f.is_oneway? then
|
---|
| 646 | b_continue = "true"
|
---|
| 647 | else
|
---|
| 648 | b_continue = "false"
|
---|
| 649 | end
|
---|
| 650 | file.print " if( (ercd_=cTDR_receiveEOP(#{b_continue})) != E_OK )\n"
|
---|
| 651 | file.print " goto error_reset;\n\n"
|
---|
| 652 |
|
---|
| 653 | # 対象関数を呼出す
|
---|
| 654 | file.print " /* 対象関数の呼出し */\n"
|
---|
| 655 | if b_void then
|
---|
| 656 | file.print( " cServerCall_#{f_name}(" )
|
---|
| 657 | else
|
---|
| 658 | file.print( " #{retval_ptr}retval_ = cServerCall_#{f_name}(" )
|
---|
| 659 | end
|
---|
| 660 |
|
---|
| 661 | delim = " "
|
---|
| 662 | param_list.each{ |par|
|
---|
| 663 | file.print delim
|
---|
| 664 | delim = ", "
|
---|
| 665 | file.print "#{par.get_name}"
|
---|
| 666 | }
|
---|
| 667 | file.print( " );\n" )
|
---|
| 668 |
|
---|
| 669 | # 戻り値、出力引数の受取コードの生成
|
---|
| 670 |
|
---|
| 671 | # oneway の場合出力、戻り値が無く、受取を待たない(非同期な呼出し)
|
---|
| 672 | if ! f.is_oneway? then
|
---|
| 673 | file.print <<EOT
|
---|
| 674 | /* 関数処理の終了を通知 */
|
---|
| 675 | if( ( ercd_ = cEventflag_set( 0x01 ) ) != E_OK ){
|
---|
| 676 | goto error_reset;
|
---|
| 677 | }
|
---|
| 678 | EOT
|
---|
| 679 | end # ! f.is_oneway?
|
---|
| 680 | file.print <<EOT
|
---|
| 681 | return E_OK;
|
---|
| 682 | error_reset:
|
---|
| 683 | return ercd_;
|
---|
| 684 | }
|
---|
| 685 |
|
---|
| 686 | EOT
|
---|
| 687 |
|
---|
| 688 | }
|
---|
| 689 |
|
---|
| 690 | end
|
---|
| 691 |
|
---|
| 692 | end
|
---|