source: azure_iot_hub/trunk/asp3_dcre/tecsgen/tecslib/plugin/lib/MrubyBridgeCelltypePluginModule.rb@ 388

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

Azure IoT Hub Device C SDK を使ったサンプルの追加

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-ruby
File size: 10.9 KB
Line 
1# -*- coding: utf-8 -*-
2#
3# TECS Generator
4# Generator for TOPPERS Embedded Component System
5#
6# Copyright (C) 2008-2011 by TOPPERS Project
7#--
8# 上記著作権者
9は,以下の(1)~(4)の条件を満たす場合に限り,本ソフトウェ
10# ア(本ソフトウェアを改変したものを含む.以下同じ)を使用・複製・改
11# 変・再é…
12å¸ƒï¼ˆä»¥ä¸‹ï¼Œåˆ©ç”¨ã¨å‘¼ã¶ï¼‰ã™ã‚‹ã“とを無償で許諾する.
13# (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
14# 権表示,この利用条件および下記の無保証規定が,そのままの形でソー
15# スコード中に含まれていること.
16# (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
17# 用できる形で再é…
18å¸ƒã™ã‚‹å ´åˆã«ã¯ï¼Œå†é…
19å¸ƒã«ä¼´ã†ãƒ‰ã‚­ãƒ¥ãƒ¡ãƒ³ãƒˆï¼ˆåˆ©ç”¨
20# 者
21マニュアルなど)に,上記の著作権表示,この利用条件および下記
22# の無保証規定を掲載すること.
23# (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
24# 用できない形で再é…
25å¸ƒã™ã‚‹å ´åˆã«ã¯ï¼Œæ¬¡ã®ã„ずれかの条件を満たすこ
26# と.
27# (a) 再é…
28å¸ƒã«ä¼´ã†ãƒ‰ã‚­ãƒ¥ãƒ¡ãƒ³ãƒˆï¼ˆåˆ©ç”¨è€…
29マニュアルなど)に,上記の著
30# 作権表示,この利用条件および下記の無保証規定を掲載すること.
31# (b) 再é…
32å¸ƒã®å½¢æ…
33‹ã‚’,別に定める方法によって,TOPPERSプロジェクトに
34# 報告すること.
35# (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
36# 害からも,上記著作権者
37およびTOPPERSプロジェクトをå…
38è²¬ã™ã‚‹ã“と.
39# また,本ソフトウェアのユーザまたはエンドユーザからのいかなる理
40# 由に基づく請求からも,上記著作権者
41およびTOPPERSプロジェクトを
42# å…
43è²¬ã™ã‚‹ã“と.
44#
45# 本ソフトウェアは,無保証で提供されているものである.上記著作権者
46お
47# よびTOPPERSプロジェクトは,本ソフトウェアに関して,特定の使用目的
48# に対する適合性も含めて,いかなる保証も行わない.また,本ソフトウェ
49# アの利用により直接的または間接的に生じたいかなる損害に関しても,そ
50# の責任を負わない.
51#
52# $Id$
53#++
54
55#== celltype プラグインのå…
56±é€šã®è¦ªã‚¯ãƒ©ã‚¹
57module MrubyBridgeCelltypePluginModule
58
59 # プラグイン引数名 => Proc
60 MrubyBridgePluginArgProc = {
61 "ignoreUnsigned" => Proc.new { |obj,rhs| obj.set_ignoreUnsigned rhs },
62 "include_inner_cell" => Proc.new { |obj,rhs| obj.set_include_inner_cell rhs },
63 "exclude_cell" => Proc.new { |obj,rhs| obj.set_exclude_cell rhs },
64 "exclude_port" => Proc.new { |obj,rhs| obj.set_exclude_port rhs },
65 "exclude_port_func" => Proc.new { |obj,rhs| obj.set_exclude_port_func rhs },
66 "auto_exclude" => Proc.new { |obj,rhs| obj.set_auto_exclude rhs },
67 }
68
69 require_tecsgen_lib( "MrubyBridgeCellPlugin.rb" )
70 @@plugin_list = []
71 @@count = 1
72
73 #celltype:: Celltype セルタイプ(インスタンス)
74 def initialize( celltype, option )
75 dbgPrint "#{self.class.name}: initialzie: #{celltype.get_name}\n"
76
77 super
78 @celltype = celltype
79 @cell_list = []
80 @include_inner_cell = false
81 @exclude_cells = []
82 @exclude_port = []
83 @exclude_port_func = {}
84 @b_ignoreUnsigned = false
85 @b_auto_exclude = true # auto_exclude = true by default
86 @@plugin_list << self
87
88 @plugin_arg_check_proc_tab = MrubyBridgePluginArgProc
89 @plugin_arg_str = CDLString.remove_dquote option
90 parse_plugin_arg
91
92 MrubyBridgeCellPlugin.set_gen_post_code_by_dependent
93 end
94
95 #=== 新しいセル
96 #cell:: Cell セル
97 #
98 # celltype プラグインを指定されたセルタイプのセルが生成された
99 # セルタイププラグインに対する新しいセルの報告
100 # generate 文により呼び出された場合、それまでに定義された cell については、initialize のタイミングで呼び出される
101 def new_cell( cell )
102 dbgPrint "MrubyBridgeCelltypePluginModule: new_cell: #{cell.get_name}\n"
103
104 return if @cell_list.include? cell # この行は、本来不要のはず
105 if TECSGEN.post_coded? # post_code 以降のセルは対象から外す
106 cdl_info( "I9999 MrubyBridgeCelltypePlugin: $1 is excluded because cell generated after post_coded", cell.get_name )
107 return
108 end
109
110 # include_inner_cell option
111 if cell.is_cloned? && @include_inner_cell == false then
112 # p "#{cell.get_name} excluded"
113 cdl_info( "I9999 MrubyBridgeCelltypePlugin: inner cell $1 is excluded", cell.get_name )
114 return
115 # else
116 # p "#{cell.get_name} included"
117 end
118
119 # exclude_cell option
120 if @exclude_cells.include?( cell.get_name ) then
121 return
122 end
123
124 opt_str = "ignoreUnsigned=#{@b_ignoreUnsigned}, auto_exclude=#{@b_auto_exclude}"
125 @exclude_port.each{ |port|
126 opt_str += ",exclude_port=#{port}"
127 }
128 @exclude_port_func.each{ |port, funcs|
129 funcs.each{ |func|
130 opt_str += ",exclude_port_func=#{port}.#{func}"
131 }
132 }
133
134 # p "MrubyBridgeCelltypePlugin: opt_str=#{opt_str}"
135
136 fn2 = "#{$gen}/tmp_MrubyBridgeCelltypePluginModule_#{@celltype.get_name}_#{@@count}.cdl"
137 f2 = File.open( fn2, "w" )
138 f2.print <<EOT
139/* MrubyBridgeCelltypePluginModule: celltype=#{@celltype.get_name} */
140generate( MrubyBridgeCellPlugin, #{cell.get_namespace_path}, "#{opt_str}" );
141EOT
142 f2.close
143 dbgPrint "MrubyBridgeCelltypePluginModule new_cell: Import #{fn2}\n"
144 Import.new "#{fn2}"
145 @@count += 1
146 end
147
148### 意味解析段階で呼び出されるメソッド ###
149 #=== CDL ファイルの生成
150 # typedef, signature, celltype, cell のコードを生成
151 # 重複して生成してはならない
152 # すでに生成されている場合は出力しないこと。
153 # もしくは同名の import により、重複を避けること。
154 #file:: FILE 生成するファイル
155 def gen_cdl_file file
156# この段階で呼びだすと generate 文が呼び出される前のセルのみの出力となる
157
158# dbgPrint "MrubyBridgeCelltypePlugin: gen_cdl_file: #{@celltype.get_name}\n"
159# file.print <<EOT
160#/* MrubyBridgeCelltypePlugin: celltype=#{@celltype.get_name}
161# *
162# * cell's generate before celltype's generate
163# */
164#
165#EOT
166# @celltype.get_cell_list.each { |cell|
167# @cell_list << cell
168# # mikan option, region
169# dbgPrint "MrubyBridgeCelltypePlugin: cell=#{cell.get_name}\n"
170# file.print <<EOT
171#generate( MrubyBridgeCellPlugin, #{cell.get_namespace_path}, "" );
172#EOT
173# }
174
175 end
176
177 #=== tCelltype_factory.h に挿å…
178¥ã™ã‚‹ã‚³ãƒ¼ãƒ‰ã‚’生成する
179 # file 以外の他のファイルにファクトリコードを生成してもよい
180 # セルタイププラグインが指定されたセルタイプのみ呼び出される
181 def gen_factory file
182 end
183
184 def get_celltype
185 @celltype
186 end
187
188 @@b_gen_post_code_called = false
189 #=== 後ろの CDL コードを生成
190 #プラグインの後ろの CDL コードを生成
191 #file:: File:
192 def self.gen_post_code( file )
193 dbgPrint "#{self.name}: gen_post_code_body\n"
194
195 if @@b_gen_post_code_called == false then
196 @@b_gen_post_code_called = true
197 MrubyBridgeCellPlugin.gen_post_code_body file
198 end
199
200# この段階で生成すると、同じポストコードで出力される mruby の初期化コードに反映されない
201
202# # MrubyBridgeCelltypePlugin の生成する generate 文は、
203# fn2 = "#{$gen}/tmp_MrubyBridgeCelltypePlugin_post.cdl"
204# f2 = File.open( fn2, "w" )
205# # 複数のプラグインの post_code が一つのファイルに含まれるため、以下のような見出しをつけること
206# dbgPrint "MrubyBridgeCelltypePlugin: gen_post_code\n"
207# f2.print "/* '#{self.name}' post code */\n"
208# @@plugin_list.each{ |plugin|
209# plugin.get_celltype.get_cell_list.each{ |cell|
210# # mikan option, region
211# f2.print <<EOT
212#generate( MrubyBridgeCellPlugin, #{cell.get_namespace_path}, "" );
213#EOT
214# }
215# }
216# f2.close
217# p Import
218# Import.new "#{fn2}"
219 end
220
221 #=== プラグイン引数
222
223 #=== プラグイン引数 ignoreUnsigned
224 def set_ignoreUnsigned rhs
225 if rhs == "true" || rhs == nil then
226 @b_ignoreUnsigned = true
227 end
228 end
229
230 def set_include_inner_cell rhs
231 if rhs == "true" || rhs == nil then
232 @include_inner_cell = true
233 end
234 end
235
236 def set_exclude_cell rhs
237 cells = rhs.split ','
238 cells.each{ |rhs_cell|
239 rhs_cell.gsub!( /\s/, "" )
240 @exclude_cells << rhs_cell.to_sym
241 }
242 end
243 def set_exclude_port rhs
244 ports = rhs.split ','
245 ct = @cell.get_celltype
246 return if ct == nil # error case
247 ports.each{ |rhs_port|
248 obj = ct.find( rhs_port.to_sym )
249 if( ( ! obj.instance_of? Port ) || obj.get_port_type != :ENTRY ) then
250 cdl_error( "MRB9999 exclude_port '$1' not found or not entry in celltype '$2'", rhs_port, ct.get_name )
251 else
252 # print "MRBBridgeCellPlugin: exclude #{rhs_port}\n"
253 @exclude_port << rhs_port
254 end
255 }
256 end
257
258 #=== プラグイン引数 exclude_port_func
259 def set_exclude_port_func rhs
260 port_funcs = rhs.split ','
261 ct = @celltype
262 return if ct == nil # error case
263 port_funcs.each{ |rhs_port_func|
264 port_func = rhs_port_func.split( '.' )
265 if port_func.length != 2 then
266 cdl_error( "MRB9999 exclude_port_func: '$1' not in 'port.func' form", rhs_port_func )
267 end
268 obj = ct.find( port_func[0].to_sym )
269 if( ( ! obj.instance_of? Port ) || obj.get_port_type != :ENTRY ) then
270 cdl_error( "MRB9999 exclude_port_func: port '$1' not found in celltype '$2'", rhs_port_func, ct.get_name )
271 else
272 signature = obj.get_signature
273 next if signature == nil # error case
274 if signature.get_function_head port_func[1].to_sym
275 # print "MRBBridgeCellPlugin: #{port_func[0]}.#{port_func[1]} exclude\n"
276 if @exclude_port_func[ port_func[0] ] then
277 @exclude_port_func[ port_func[0] ] << port_func[1]
278 else
279 @exclude_port_func[ port_func[0] ] = [ port_func[1] ]
280 end
281 else
282 cdl_error( "MRB9999 include_port_func: func '$1' not found in port '$2' celltype $3",
283 port_func[1], port_func[0], ct.get_name )
284 end
285 end
286 }
287 end
288
289 #=== プラグイン引数 auto_exclude
290 def set_auto_exclude rhs
291 # print "MrubyBridgeCellPlugin: auto_exclude=#{rhs}\n"
292 if rhs == "false" then
293 @b_auto_exclude = false
294 elsif rhs == "true" then
295 @b_auto_exclude = true # auto_exclude = true by default
296 else
297 cdl_warning( "MRB9999 auto_exclude: unknown rhs value ignored. specify true or false" )
298 end
299 end
300end
301
Note: See TracBrowser for help on using the repository browser.