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 | #
|
---|
37 | # $Id$
|
---|
38 | #++
|
---|
39 |
|
---|
40 | XML_INDENT = " "
|
---|
41 |
|
---|
42 | class Namespace
|
---|
43 | def self.gen_XML root_namespace
|
---|
44 | begin
|
---|
45 | file_name = $gen_base + "/" + $target + ".xml"
|
---|
46 | dbgPrint "generating XML file:#{file_name}\n"
|
---|
47 | file = AppFile.open( file_name )
|
---|
48 |
|
---|
49 | file.print <<EOT
|
---|
50 | <?xml version="1.0" encoding="UTF-8"?>
|
---|
51 | <GUI_Tool xmlns="http://www.toppers.jp/tecs.html">
|
---|
52 | EOT
|
---|
53 | root_namespace.gen_XML file, 1
|
---|
54 |
|
---|
55 | file.print <<EOT
|
---|
56 | </GUI_Tool>
|
---|
57 | EOT
|
---|
58 |
|
---|
59 | file.close
|
---|
60 | rescue => evar
|
---|
61 | Generator.error( "T2001 fail to create XML file $1", file_name)
|
---|
62 | print_exception( evar )
|
---|
63 | end
|
---|
64 | end
|
---|
65 |
|
---|
66 | def gen_XML( file, nest )
|
---|
67 | # signature のコードを生成
|
---|
68 | @signature_list.each { |s|
|
---|
69 | s.gen_XML file, nest
|
---|
70 | }
|
---|
71 |
|
---|
72 | # celltype のコードを生成
|
---|
73 | @celltype_list.each { |t|
|
---|
74 | t.gen_XML( file, nest )
|
---|
75 | }
|
---|
76 |
|
---|
77 | # composite のコードを生成
|
---|
78 | @compositecelltype_list.each { |t|
|
---|
79 | t.gen_XML( file, nest )
|
---|
80 | }
|
---|
81 |
|
---|
82 | # cell のコードを生成
|
---|
83 | @cell_list.each { |t|
|
---|
84 | t.gen_XML( file, nest )
|
---|
85 | }
|
---|
86 |
|
---|
87 | # サブネームスペースのコードを生成
|
---|
88 | @namespace_list.each { |n|
|
---|
89 | kind = n.instance_of?( Namespace ) ? "namespace" : "region"
|
---|
90 | file.print <<EOT
|
---|
91 | #{XML_INDENT * nest}<#{kind}>
|
---|
92 | #{XML_INDENT * (nest+1)}<name> #{n.get_name} </name>
|
---|
93 | EOT
|
---|
94 | n.gen_XML( file, nest + 1 )
|
---|
95 | file.print <<EOT
|
---|
96 | #{XML_INDENT * nest}</#{kind}>
|
---|
97 | EOT
|
---|
98 | }
|
---|
99 | end
|
---|
100 | end
|
---|
101 |
|
---|
102 | class Signature
|
---|
103 | def gen_XML file, nest
|
---|
104 | indent = XML_INDENT * nest
|
---|
105 | if is_imported? then
|
---|
106 | file.print <<EOT
|
---|
107 | #{indent}<import path='#{@import.get_cdl_name}'>
|
---|
108 | EOT
|
---|
109 | nest += 1
|
---|
110 | indent = XML_INDENT * nest
|
---|
111 | end
|
---|
112 |
|
---|
113 | file.print <<EOT
|
---|
114 | #{indent}<signature>
|
---|
115 | #{indent}#{XML_INDENT}<name> #{@name} </name>
|
---|
116 | EOT
|
---|
117 | @function_head_list.get_items.each{ |fh|
|
---|
118 | file.print <<EOT
|
---|
119 | #{indent}#{XML_INDENT}<func>
|
---|
120 | #{indent}#{XML_INDENT}#{XML_INDENT}<name> #{fh.get_name} </name>
|
---|
121 | #{indent}#{XML_INDENT}#{XML_INDENT}<rettype> #{fh.get_return_type.get_type_str}#{fh.get_return_type.get_type_str_post} </rettype>
|
---|
122 | EOT
|
---|
123 | fh.get_paramlist.get_items.each{ |pd|
|
---|
124 | file.print <<EOT
|
---|
125 | #{indent}#{XML_INDENT}#{XML_INDENT}<param>
|
---|
126 | #{indent}#{XML_INDENT}#{XML_INDENT}#{XML_INDENT}<name> #{pd.get_name} </name>
|
---|
127 | #{indent}#{XML_INDENT}#{XML_INDENT}#{XML_INDENT}<type> #{pd.get_type.get_type_str}#{pd.get_type.get_type_str_post} </type>
|
---|
128 | #{indent}#{XML_INDENT}#{XML_INDENT}</param>
|
---|
129 | EOT
|
---|
130 | }
|
---|
131 | file.print <<EOT
|
---|
132 | #{indent}#{XML_INDENT}</func>
|
---|
133 | EOT
|
---|
134 | }
|
---|
135 | file.print <<EOT
|
---|
136 | #{indent}</signature>
|
---|
137 | EOT
|
---|
138 | if is_imported? then
|
---|
139 | nest -= 1
|
---|
140 | indent = XML_INDENT * nest
|
---|
141 | file.print <<EOT
|
---|
142 | #{indent}</import>
|
---|
143 | EOT
|
---|
144 | end
|
---|
145 | end
|
---|
146 | end
|
---|
147 |
|
---|
148 | class Celltype
|
---|
149 | def gen_XML file, nest
|
---|
150 | indent = XML_INDENT * nest
|
---|
151 | if is_imported? then
|
---|
152 | file.print <<EOT
|
---|
153 | #{indent}<import path='#{@import.get_cdl_name}'>
|
---|
154 | EOT
|
---|
155 | nest += 1
|
---|
156 | indent = XML_INDENT * nest
|
---|
157 | end
|
---|
158 |
|
---|
159 | file.print <<EOT
|
---|
160 | #{indent}<celltype>
|
---|
161 | #{indent}#{XML_INDENT}<name> #{@name} </name>
|
---|
162 | EOT
|
---|
163 | if @active then
|
---|
164 | file.print <<EOT
|
---|
165 | #{indent}#{XML_INDENT}<active />
|
---|
166 | EOT
|
---|
167 | end
|
---|
168 | if @singleton then
|
---|
169 | file.print <<EOT
|
---|
170 | #{indent}#{XML_INDENT}<singleton />
|
---|
171 | EOT
|
---|
172 | end
|
---|
173 |
|
---|
174 | @attribute.each{ |attr|
|
---|
175 | file.print <<EOT
|
---|
176 | #{indent}#{XML_INDENT}<attr>
|
---|
177 | #{indent}#{XML_INDENT}#{XML_INDENT}<name> #{attr.get_name} </name>
|
---|
178 | #{indent}#{XML_INDENT}#{XML_INDENT}<type> #{attr.get_type.get_type_str}#{attr.get_type.get_type_str_post} </type>
|
---|
179 | EOT
|
---|
180 | if attr.get_initializer then
|
---|
181 | file.print <<EOT
|
---|
182 | #{indent}#{XML_INDENT}#{XML_INDENT}<initializer> #{attr.get_initializer.to_CDL_str} </initializer>
|
---|
183 | EOT
|
---|
184 | end
|
---|
185 |
|
---|
186 | if attr.get_choice_list then
|
---|
187 | file.print <<EOT
|
---|
188 | #{indent}#{XML_INDENT}#{XML_INDENT}<choice>
|
---|
189 | EOT
|
---|
190 |
|
---|
191 | attr.get_choice_list.each { |choiceElement|
|
---|
192 | file.print <<EOT
|
---|
193 | #{indent}#{XML_INDENT}#{XML_INDENT}#{XML_INDENT}<choiceElement>#{choiceElement}</choiceElement>
|
---|
194 | EOT
|
---|
195 | }
|
---|
196 |
|
---|
197 | file.print <<EOT
|
---|
198 | #{indent}#{XML_INDENT}#{XML_INDENT}</choice>
|
---|
199 | EOT
|
---|
200 | end
|
---|
201 |
|
---|
202 | file.print <<EOT
|
---|
203 | #{indent}#{XML_INDENT}</attr>
|
---|
204 | EOT
|
---|
205 | }
|
---|
206 | @port.each{ |port|
|
---|
207 | port_type = port.get_port_type == :CALL ? "call" : "entry"
|
---|
208 | file.print <<EOT
|
---|
209 | #{indent}#{XML_INDENT}<#{port_type}>
|
---|
210 | #{indent}#{XML_INDENT}#{XML_INDENT}<name> #{port.get_name} </name>
|
---|
211 | #{indent}#{XML_INDENT}#{XML_INDENT}<signame> #{port.get_signature.get_name} </signame>
|
---|
212 | EOT
|
---|
213 | if port.get_array_size then
|
---|
214 | file.print <<EOT
|
---|
215 | #{indent}#{XML_INDENT}#{XML_INDENT}<subscript> #{port.get_array_size} </subscript>
|
---|
216 | EOT
|
---|
217 | end
|
---|
218 | file.print <<EOT
|
---|
219 | #{indent}#{XML_INDENT}</#{port_type}>
|
---|
220 | EOT
|
---|
221 | }
|
---|
222 | file.print <<EOT
|
---|
223 | #{indent}</celltype>
|
---|
224 | EOT
|
---|
225 | if is_imported? then
|
---|
226 | nest -= 1
|
---|
227 | indent = XML_INDENT * nest
|
---|
228 | file.print <<EOT
|
---|
229 | #{indent}</import>
|
---|
230 | EOT
|
---|
231 | end
|
---|
232 | end
|
---|
233 |
|
---|
234 | end
|
---|
235 |
|
---|
236 | #
|
---|
237 | # Celltype と共用可能なはずだが、以下の点の変更が必要
|
---|
238 | # @active ⇒ @b_active
|
---|
239 | # @singleton ⇒ @b_singleton
|
---|
240 | # @attribute ⇒ @name_list (Decl)
|
---|
241 | # @port ⇒ @name_list (Port)
|
---|
242 | class CompositeCelltype
|
---|
243 | def gen_XML file, nest
|
---|
244 | indent = XML_INDENT * nest
|
---|
245 | if is_imported? then
|
---|
246 | file.print <<EOT
|
---|
247 | #{indent}<import path='#{@import.get_cdl_name}'>
|
---|
248 | EOT
|
---|
249 | nest += 1
|
---|
250 | indent = XML_INDENT * nest
|
---|
251 | end
|
---|
252 |
|
---|
253 | file.print <<EOT
|
---|
254 | #{indent}<celltype>
|
---|
255 | #{indent}#{XML_INDENT}<name> #{@name} </name>
|
---|
256 | EOT
|
---|
257 | file.print <<EOT
|
---|
258 | #{indent}#{XML_INDENT}<composite />
|
---|
259 | EOT
|
---|
260 |
|
---|
261 | if @b_active then
|
---|
262 | file.print <<EOT
|
---|
263 | #{indent}#{XML_INDENT}<active />
|
---|
264 | EOT
|
---|
265 | end
|
---|
266 | if @b_singleton then
|
---|
267 | file.print <<EOT
|
---|
268 | #{indent}#{XML_INDENT}<singleton />
|
---|
269 | EOT
|
---|
270 | end
|
---|
271 |
|
---|
272 | @name_list.get_items.each{ |attr|
|
---|
273 | if ! attr.instance_of? Decl then
|
---|
274 | next
|
---|
275 | end
|
---|
276 | file.print <<EOT
|
---|
277 | #{indent}#{XML_INDENT}<attr>
|
---|
278 | #{indent}#{XML_INDENT}#{XML_INDENT}<name> #{attr.get_name} </name>
|
---|
279 | #{indent}#{XML_INDENT}#{XML_INDENT}<type> #{attr.get_type.get_type_str}#{attr.get_type.get_type_str_post} </type>
|
---|
280 | EOT
|
---|
281 | if attr.get_initializer then
|
---|
282 | file.print <<EOT
|
---|
283 | #{indent}#{XML_INDENT}#{XML_INDENT}<initializer> #{attr.get_initializer.to_CDL_str} </initializer>
|
---|
284 | EOT
|
---|
285 | end
|
---|
286 | file.print <<EOT
|
---|
287 | #{indent}#{XML_INDENT}</attr>
|
---|
288 | EOT
|
---|
289 | }
|
---|
290 | @name_list.get_items.each{ |port|
|
---|
291 | if ! port.instance_of? Port then
|
---|
292 | next
|
---|
293 | end
|
---|
294 | port_type = port.get_port_type == :CALL ? "call" : "entry"
|
---|
295 | file.print <<EOT
|
---|
296 | #{indent}#{XML_INDENT}<#{port_type}>
|
---|
297 | #{indent}#{XML_INDENT}#{XML_INDENT}<name> #{port.get_name} </name>
|
---|
298 | #{indent}#{XML_INDENT}#{XML_INDENT}<signame> #{port.get_signature.get_name} </signame>
|
---|
299 | EOT
|
---|
300 | if port.get_array_size then
|
---|
301 | file.print <<EOT
|
---|
302 | #{indent}#{XML_INDENT}#{XML_INDENT}<subscript> #{port.get_array_size} </subscript>
|
---|
303 | EOT
|
---|
304 | end
|
---|
305 | file.print <<EOT
|
---|
306 | #{indent}#{XML_INDENT}</#{port_type}>
|
---|
307 | EOT
|
---|
308 | }
|
---|
309 | file.print <<EOT
|
---|
310 | #{indent}</celltype>
|
---|
311 | EOT
|
---|
312 | if is_imported? then
|
---|
313 | nest -= 1
|
---|
314 | indent = XML_INDENT * nest
|
---|
315 | file.print <<EOT
|
---|
316 | #{indent}</import>
|
---|
317 | EOT
|
---|
318 | end
|
---|
319 | end
|
---|
320 |
|
---|
321 | end
|
---|
322 |
|
---|
323 | class Cell
|
---|
324 | def gen_XML file, nest
|
---|
325 | indent = XML_INDENT * nest
|
---|
326 |
|
---|
327 | if is_imported? then
|
---|
328 | file.print <<EOT
|
---|
329 | #{indent}<import path='#{@import.get_cdl_name}'>
|
---|
330 | EOT
|
---|
331 | nest += 1
|
---|
332 | indent = XML_INDENT * nest
|
---|
333 | end
|
---|
334 |
|
---|
335 | file.print <<EOT
|
---|
336 | #{indent}<cell>
|
---|
337 | #{indent}#{XML_INDENT}<name> #{@name} </name>
|
---|
338 | EOT
|
---|
339 | @join_list.get_items.each{ |join|
|
---|
340 | if join.get_definition.kind_of? Port then
|
---|
341 | kind = "call_join"
|
---|
342 | elsif join.get_definition.kind_of? Decl then
|
---|
343 | kind = "attr_join"
|
---|
344 | else
|
---|
345 | raise "Unknown"
|
---|
346 | end
|
---|
347 | if join.get_array_member2 then
|
---|
348 | join.get_array_member2.each { |j2|
|
---|
349 | file.print <<EOT
|
---|
350 | #{indent}#{XML_INDENT}<#{kind}>
|
---|
351 | #{indent}#{XML_INDENT}#{XML_INDENT}<name> #{join.get_name} </name>
|
---|
352 | #{indent}#{XML_INDENT}#{XML_INDENT}<subscript> #{join.get_subscript} </subscript>
|
---|
353 | #{indent}#{XML_INDENT}#{XML_INDENT}<rhs> #{join.get_rhs.to_CDL_str} </rhs>
|
---|
354 | #{indent}#{XML_INDENT}</#{kind}>
|
---|
355 | EOT
|
---|
356 | }
|
---|
357 | else
|
---|
358 | file.print <<EOT
|
---|
359 | #{indent}#{XML_INDENT}<#{kind}>
|
---|
360 | #{indent}#{XML_INDENT}#{XML_INDENT}<name> #{join.get_name} </name>
|
---|
361 | #{indent}#{XML_INDENT}#{XML_INDENT}<rhs> #{join.get_rhs.to_CDL_str} </rhs>
|
---|
362 | #{indent}#{XML_INDENT}</#{kind}>
|
---|
363 | EOT
|
---|
364 | end
|
---|
365 | }
|
---|
366 | file.print <<EOT
|
---|
367 | #{indent}</cell>
|
---|
368 | EOT
|
---|
369 | if is_imported? then
|
---|
370 | nest -= 1
|
---|
371 | indent = XML_INDENT * nest
|
---|
372 | file.print <<EOT
|
---|
373 | #{indent}</import>
|
---|
374 | EOT
|
---|
375 | end
|
---|
376 | end
|
---|
377 | end
|
---|