source: azure_iot_hub/trunk/asp3_dcre/tecsgen/tecslib/plugin/MrubyBridgeCelltypePlugin.rb@ 389

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

ビルドが通るよう更新

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-ruby;charset=UTF-8
File size: 11.3 KB
Line 
1# -*- coding: utf-8 -*-
2#
3# TECS Generator
4# Generator for TOPPERS Embedded Component System
5#
6# Copyright (C) 2008-2017 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#
37# $Id$
38#++
39
40require_tecsgen_lib 'tecslib/plugin/lib/MrubyBridgeCelltypePluginModule.rb'
41
42#== MrubyBridgeCompositePlugin
43class MrubyBridgeCelltypePlugin < CompositePlugin
44 dbgPrint "MrubyBridgeCelltypePlugin loaded\n"
45 include MrubyBridgeCelltypePluginModule
46
47 def self.gen_post_code( file )
48 MrubyBridgeCelltypePluginModule.gen_post_code file
49 end
50end
51
52
53#
54##== celltype プラグインの共通の親クラス
55#class MrubyBridgeCelltypePlugin < CelltypePlugin
56#
57# # プラグイン引数名 => Proc
58# MrubyBridgePluginArgProc = {
59# "ignoreUnsigned" => Proc.new { |obj,rhs| obj.set_ignoreUnsigned rhs },
60# "include_inner_cell" => Proc.new { |obj,rhs| obj.set_include_inner_cell rhs },
61# "exclude_cell" => Proc.new { |obj,rhs| obj.set_exclude_cell rhs },
62# "exclude_port" => Proc.new { |obj,rhs| obj.set_exclude_port rhs },
63# "exclude_port_func" => Proc.new { |obj,rhs| obj.set_exclude_port_func rhs },
64# "auto_exclude" => Proc.new { |obj,rhs| obj.set_auto_exclude rhs },
65# }
66#
67# require_tecsgen_lib( "MrubyBridgeCellPlugin.rb" )
68# @@plugin_list = []
69# @@count = 1
70#
71# #celltype:: Celltype セルタイプ(インスタンス)
72# def initialize( celltype, option )
73# dbgPrint "#{self.class.name}: initialzie: #{celltype.get_name}\n"
74#
75# super
76# @celltype = celltype
77# @cell_list = []
78# @include_inner_cell = false
79# @exclude_cells = []
80# @exclude_port = []
81# @exclude_port_func = {}
82# @b_ignoreUnsigned = false
83# @b_auto_exclude = true # auto_exclude = true by default
84# @@plugin_list << self
85#
86# @plugin_arg_check_proc_tab = MrubyBridgePluginArgProc
87# @plugin_arg_str = CDLString.remove_dquote option
88# parse_plugin_arg
89#
90# MrubyBridgeCellPlugin.set_gen_post_code_by_dependent
91# end
92#
93# #=== 新しいセル
94# #cell:: Cell セル
95# #
96# # celltype プラグインを指定されたセルタイプのセルが生成された
97# # セルタイププラグインに対する新しいセルの報告
98# # generate 文により呼び出された場合、それまでに定義された cell については、initialize のタイミングで呼び出される
99# def new_cell( cell )
100# dbgPrint "MrubyBridgeCelltypePlugin: new_cell: #{cell.get_name}\n"
101#
102# return if @cell_list.include? cell # この行は、本来不要のはず
103# if TECSGEN.post_coded? # post_code 以降のセルは対象から外す
104# cdl_info( "I9999 MrubyBridgeCelltypePlugin: $1 is excluded because cell generated after post_coded", cell.get_name )
105# return
106# end
107#
108# # include_inner_cell option
109# if cell.is_cloned? && @include_inner_cell == false then
110# # p "#{cell.get_name} excluded"
111# cdl_info( "I9999 MrubyBridgeCelltypePlugin: inner cell $1 is excluded", cell.get_name )
112# return
113# # else
114# # p "#{cell.get_name} included"
115# end
116#
117# # exclude_cell option
118# if @exclude_cells.include?( cell.get_name ) then
119# return
120# end
121#
122# opt_str = "ignoreUnsigned=#{@b_ignoreUnsigned}, auto_exclude=#{@b_auto_exclude}"
123# @exclude_port.each{ |port|
124# opt_str += ",exclude_port=#{port}"
125# }
126# @exclude_port_func.each{ |port, funcs|
127# funcs.each{ |func|
128# opt_str += ",exclude_port_func=#{port}.#{func}"
129# }
130# }
131#
132# # p "MrubyBridgeCelltypePlugin: opt_str=#{opt_str}"
133#
134# # mikan option, region
135# fn2 = "#{$gen}/tmp_MrubyBridgeCelltypePlugin_#{@celltype.get_name}_#{@@count}.cdl"
136# f2 = File.open( fn2, "w" )
137# f2.print <<EOT
138#/* MrubyBridgeCelltypePlugin: celltype=#{@celltype.get_name} */
139#generate( MrubyBridgeCellPlugin, #{cell.get_namespace_path}, "#{opt_str}" );
140#EOT
141# f2.close
142# Import.new "#{fn2}"
143# @@count += 1
144# end
145#
146#### 意味解析段階で呼び出されるメソッド ###
147# #=== CDL ファイルの生成
148# # typedef, signature, celltype, cell のコードを生成
149# # 重複して生成してはならない
150# # すでに生成されている場合は出力しないこと。
151# # もしくは同名の import により、重複を避けること。
152# #file:: FILE 生成するファイル
153# def gen_cdl_file file
154## この段階で呼びだすと generate 文が呼び出される前のセルのみの出力となる
155#
156## dbgPrint "MrubyBridgeCelltypePlugin: gen_cdl_file: #{@celltype.get_name}\n"
157## file.print <<EOT
158##/* MrubyBridgeCelltypePlugin: celltype=#{@celltype.get_name}
159## *
160## * cell's generate before celltype's generate
161## */
162##
163##EOT
164## @celltype.get_cell_list.each { |cell|
165## @cell_list << cell
166## # mikan option, region
167## dbgPrint "MrubyBridgeCelltypePlugin: cell=#{cell.get_name}\n"
168## file.print <<EOT
169##generate( MrubyBridgeCellPlugin, #{cell.get_namespace_path}, "" );
170##EOT
171## }
172#
173# end
174#
175# #=== tCelltype_factory.h に挿入するコードを生成する
176# # file 以外の他のファイルにファクトリコードを生成してもよい
177# # セルタイププラグインが指定されたセルタイプのみ呼び出される
178# def gen_factory file
179# end
180#
181# def get_celltype
182# @celltype
183# end
184#
185# #=== 後ろの CDL コードを生成
186# #プラグインの後ろの CDL コードを生成
187# #file:: File:
188# def self.gen_post_code( file )
189# dbgPrint "#{self.name}: gen_post_code_body\n"
190# print "#{self.name}: gen_post_code_body\n"
191## この段階で生成すると、同じポストコードで出力される mruby の初期化コードに反映されない
192#
193## # MrubyBridgeCelltypePlugin の生成する generate 文は、
194## fn2 = "#{$gen}/tmp_MrubyBridgeCelltypePlugin_post.cdl"
195## f2 = File.open( fn2, "w" )
196## # 複数のプラグインの post_code が一つのファイルに含まれるため、以下のような見出しをつけること
197## dbgPrint "MrubyBridgeCelltypePlugin: gen_post_code\n"
198## f2.print "/* '#{self.name}' post code */\n"
199## @@plugin_list.each{ |plugin|
200## plugin.get_celltype.get_cell_list.each{ |cell|
201## # mikan option, region
202## f2.print <<EOT
203##generate( MrubyBridgeCellPlugin, #{cell.get_namespace_path}, "" );
204##EOT
205## }
206## }
207## f2.close
208## p Import
209## Import.new "#{fn2}"
210#
211# MrubyBridgeCellPlugin.gen_post_code_body file
212# end
213#
214# #=== プラグイン引数
215#
216# #=== プラグイン引数 ignoreUnsigned
217# def set_ignoreUnsigned rhs
218# if rhs == "true" || rhs == nil then
219# @b_ignoreUnsigned = true
220# end
221# end
222#
223# def set_include_inner_cell rhs
224# if rhs == "true" || rhs == nil then
225# @include_inner_cell = true
226# end
227# end
228#
229# def set_exclude_cell rhs
230# cells = rhs.split ','
231# cells.each{ |rhs_cell|
232# rhs_cell.gsub!( /\s/, "" )
233# @exclude_cells << rhs_cell.to_sym
234# }
235# end
236# def set_exclude_port rhs
237# ports = rhs.split ','
238# ct = @cell.get_celltype
239# return if ct == nil # error case
240# ports.each{ |rhs_port|
241# obj = ct.find( rhs_port.to_sym )
242# if( ( ! obj.instance_of? Port ) || obj.get_port_type != :ENTRY ) then
243# cdl_error( "MRB9999 exclude_port '$1' not found or not entry in celltype '$2'", rhs_port, ct.get_name )
244# else
245# # print "MRBBridgeCellPlugin: exclude #{rhs_port}\n"
246# @exclude_port << rhs_port
247# end
248# }
249# end
250#
251# #=== プラグイン引数 exclude_port_func
252# def set_exclude_port_func rhs
253# port_funcs = rhs.split ','
254# ct = @celltype
255# return if ct == nil # error case
256# port_funcs.each{ |rhs_port_func|
257# port_func = rhs_port_func.split( '.' )
258# if port_func.length != 2 then
259# cdl_error( "MRB9999 exclude_port_func: '$1' not in 'port.func' form", rhs_port_func )
260# end
261# obj = ct.find( port_func[0].to_sym )
262# if( ( ! obj.instance_of? Port ) || obj.get_port_type != :ENTRY ) then
263# cdl_error( "MRB9999 exclude_port_func: port '$1' not found in celltype '$2'", rhs_port_func, ct.get_name )
264# else
265# signature = obj.get_signature
266# next if signature == nil # error case
267# if signature.get_function_head port_func[1].to_sym
268# # print "MRBBridgeCellPlugin: #{port_func[0]}.#{port_func[1]} exclude\n"
269# if @exclude_port_func[ port_func[0] ] then
270# @exclude_port_func[ port_func[0] ] << port_func[1]
271# else
272# @exclude_port_func[ port_func[0] ] = [ port_func[1] ]
273# end
274# else
275# cdl_error( "MRB9999 include_port_func: func '$1' not found in port '$2' celltype $3",
276# port_func[1], port_func[0], ct.get_name )
277# end
278# end
279# }
280# end
281#
282# #=== プラグイン引数 auto_exclude
283# def set_auto_exclude rhs
284# # print "MrubyBridgeCellPlugin: auto_exclude=#{rhs}\n"
285# if rhs == "false" then
286# @b_auto_exclude = false
287# elsif rhs == "true" then
288# @b_auto_exclude = true # auto_exclude = true by default
289# else
290# cdl_warning( "MRB9999 auto_exclude: unknown rhs value ignored. specify true or false" )
291# end
292# end
293#end
294#
Note: See TracBrowser for help on using the repository browser.