source: EcnlProtoTool/trunk/asp3_dcre/tecsgen/tecslib/core/gen_xml.rb@ 270

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

mruby版ECNLプロトタイピング・ツールを追加

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-ruby
File size: 10.6 KB
Line 
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# 上記著作権者
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: gen_xml.rb 1011 2016-07-11 02:20:01Z coas-nagasima $
53#++
54
55XML_INDENT = " "
56
57class Namespace
58 def self.gen_XML root_namespace
59 begin
60 file_name = $gen_base + "/" + $target + ".xml"
61 dbgPrint "generating XML file:#{file_name}\n"
62 file = AppFile.open( file_name )
63
64 file.print <<EOT
65<?xml version="1.0" encoding="UTF-8"?>
66<GUI_Tool xmlns="http://www.toppers.jp/tecs.html">
67EOT
68 root_namespace.gen_XML file, 1
69
70 file.print <<EOT
71</GUI_Tool>
72EOT
73
74 file.close
75 rescue => evar
76 Generator.error( "T2001 fail to create XML file $1", file_name)
77 print_exception( evar )
78 end
79 end
80
81 def gen_XML( file, nest )
82 # signature のコードを生成
83 @signature_list.each { |s|
84 s.gen_XML file, nest
85 }
86
87 # celltype のコードを生成
88 @celltype_list.each { |t|
89 t.gen_XML( file, nest )
90 }
91
92 # composite のコードを生成
93 @compositecelltype_list.each { |t|
94 t.gen_XML( file, nest )
95 }
96
97 # cell のコードを生成
98 @cell_list.each { |t|
99 t.gen_XML( file, nest )
100 }
101
102 # サブネームスペースのコードを生成
103 @namespace_list.each { |n|
104 kind = n.instance_of?( Namespace ) ? "namespace" : "region"
105 file.print <<EOT
106#{XML_INDENT * nest}<#{kind}>
107#{XML_INDENT * (nest+1)}<name> #{n.get_name} </name>
108EOT
109 n.gen_XML( file, nest + 1 )
110 file.print <<EOT
111#{XML_INDENT * nest}</#{kind}>
112EOT
113 }
114 end
115end
116
117class Signature
118 def gen_XML file, nest
119 indent = XML_INDENT * nest
120 if is_imported? then
121 file.print <<EOT
122#{indent}<import path='#{@import.get_cdl_name}'>
123EOT
124 nest += 1
125 indent = XML_INDENT * nest
126 end
127
128 file.print <<EOT
129#{indent}<signature>
130#{indent}#{XML_INDENT}<name> #{@name} </name>
131EOT
132 @function_head_list.get_items.each{ |fh|
133 file.print <<EOT
134#{indent}#{XML_INDENT}<func>
135#{indent}#{XML_INDENT}#{XML_INDENT}<name> #{fh.get_name} </name>
136#{indent}#{XML_INDENT}#{XML_INDENT}<rettype> #{fh.get_return_type.get_type_str}#{fh.get_return_type.get_type_str_post} </rettype>
137EOT
138 fh.get_paramlist.get_items.each{ |pd|
139 file.print <<EOT
140#{indent}#{XML_INDENT}#{XML_INDENT}<param>
141#{indent}#{XML_INDENT}#{XML_INDENT}#{XML_INDENT}<name> #{pd.get_name} </name>
142#{indent}#{XML_INDENT}#{XML_INDENT}#{XML_INDENT}<type> #{pd.get_type.get_type_str}#{pd.get_type.get_type_str_post} </type>
143#{indent}#{XML_INDENT}#{XML_INDENT}</param>
144EOT
145 }
146 file.print <<EOT
147#{indent}#{XML_INDENT}</func>
148EOT
149 }
150 file.print <<EOT
151#{indent}</signature>
152EOT
153 if is_imported? then
154 nest -= 1
155 indent = XML_INDENT * nest
156 file.print <<EOT
157#{indent}</import>
158EOT
159 end
160 end
161end
162
163class Celltype
164 def gen_XML file, nest
165 indent = XML_INDENT * nest
166 if is_imported? then
167 file.print <<EOT
168#{indent}<import path='#{@import.get_cdl_name}'>
169EOT
170 nest += 1
171 indent = XML_INDENT * nest
172 end
173
174 file.print <<EOT
175#{indent}<celltype>
176#{indent}#{XML_INDENT}<name> #{@name} </name>
177EOT
178 if @active then
179 file.print <<EOT
180#{indent}#{XML_INDENT}<active />
181EOT
182 end
183 if @singleton then
184 file.print <<EOT
185#{indent}#{XML_INDENT}<singleton />
186EOT
187 end
188
189 @attribute.each{ |attr|
190 file.print <<EOT
191#{indent}#{XML_INDENT}<attr>
192#{indent}#{XML_INDENT}#{XML_INDENT}<name> #{attr.get_name} </name>
193#{indent}#{XML_INDENT}#{XML_INDENT}<type> #{attr.get_type.get_type_str}#{attr.get_type.get_type_str_post} </type>
194EOT
195 if attr.get_initializer then
196 file.print <<EOT
197#{indent}#{XML_INDENT}#{XML_INDENT}<initializer> #{attr.get_initializer.to_CDL_str} </initializer>
198EOT
199 end
200
201 if attr.get_choice_list then
202 file.print <<EOT
203#{indent}#{XML_INDENT}#{XML_INDENT}<choice>
204EOT
205
206 attr.get_choice_list.each { |choiceElement|
207 file.print <<EOT
208#{indent}#{XML_INDENT}#{XML_INDENT}#{XML_INDENT}<choiceElement>#{choiceElement}</choiceElement>
209EOT
210 }
211
212 file.print <<EOT
213#{indent}#{XML_INDENT}#{XML_INDENT}</choice>
214EOT
215 end
216
217 file.print <<EOT
218#{indent}#{XML_INDENT}</attr>
219EOT
220 }
221 @port.each{ |port|
222 port_type = port.get_port_type == :CALL ? "call" : "entry"
223 file.print <<EOT
224#{indent}#{XML_INDENT}<#{port_type}>
225#{indent}#{XML_INDENT}#{XML_INDENT}<name> #{port.get_name} </name>
226#{indent}#{XML_INDENT}#{XML_INDENT}<signame> #{port.get_signature.get_name} </signame>
227EOT
228 if port.get_array_size then
229 file.print <<EOT
230#{indent}#{XML_INDENT}#{XML_INDENT}<subscript> #{port.get_array_size} </subscript>
231EOT
232 end
233 file.print <<EOT
234#{indent}#{XML_INDENT}</#{port_type}>
235EOT
236 }
237 file.print <<EOT
238#{indent}</celltype>
239EOT
240 if is_imported? then
241 nest -= 1
242 indent = XML_INDENT * nest
243 file.print <<EOT
244#{indent}</import>
245EOT
246 end
247 end
248
249end
250
251#
252# Celltype とå…
253±ç”¨å¯èƒ½ãªã¯ãšã ãŒã€ä»¥ä¸‹ã®ç‚¹ã®å¤‰æ›´ãŒå¿…
254要
255# @active ⇒ @b_active
256# @singleton ⇒ @b_singleton
257# @attribute ⇒ @name_list (Decl)
258# @port ⇒ @name_list (Port)
259class CompositeCelltype
260 def gen_XML file, nest
261 indent = XML_INDENT * nest
262 if is_imported? then
263 file.print <<EOT
264#{indent}<import path='#{@import.get_cdl_name}'>
265EOT
266 nest += 1
267 indent = XML_INDENT * nest
268 end
269
270 file.print <<EOT
271#{indent}<celltype>
272#{indent}#{XML_INDENT}<name> #{@name} </name>
273EOT
274 file.print <<EOT
275#{indent}#{XML_INDENT}<composite />
276EOT
277
278 if @b_active then
279 file.print <<EOT
280#{indent}#{XML_INDENT}<active />
281EOT
282 end
283 if @b_singleton then
284 file.print <<EOT
285#{indent}#{XML_INDENT}<singleton />
286EOT
287 end
288
289 @name_list.get_items.each{ |attr|
290 if ! attr.instance_of? Decl then
291 next
292 end
293 file.print <<EOT
294#{indent}#{XML_INDENT}<attr>
295#{indent}#{XML_INDENT}#{XML_INDENT}<name> #{attr.get_name} </name>
296#{indent}#{XML_INDENT}#{XML_INDENT}<type> #{attr.get_type.get_type_str}#{attr.get_type.get_type_str_post} </type>
297EOT
298 if attr.get_initializer then
299 file.print <<EOT
300#{indent}#{XML_INDENT}#{XML_INDENT}<initializer> #{attr.get_initializer.to_CDL_str} </initializer>
301EOT
302 end
303 file.print <<EOT
304#{indent}#{XML_INDENT}</attr>
305EOT
306 }
307 @name_list.get_items.each{ |port|
308 if ! port.instance_of? Port then
309 next
310 end
311 port_type = port.get_port_type == :CALL ? "call" : "entry"
312 file.print <<EOT
313#{indent}#{XML_INDENT}<#{port_type}>
314#{indent}#{XML_INDENT}#{XML_INDENT}<name> #{port.get_name} </name>
315#{indent}#{XML_INDENT}#{XML_INDENT}<signame> #{port.get_signature.get_name} </signame>
316EOT
317 if port.get_array_size then
318 file.print <<EOT
319#{indent}#{XML_INDENT}#{XML_INDENT}<subscript> #{port.get_array_size} </subscript>
320EOT
321 end
322 file.print <<EOT
323#{indent}#{XML_INDENT}</#{port_type}>
324EOT
325 }
326 file.print <<EOT
327#{indent}</celltype>
328EOT
329 if is_imported? then
330 nest -= 1
331 indent = XML_INDENT * nest
332 file.print <<EOT
333#{indent}</import>
334EOT
335 end
336 end
337
338end
339
340class Cell
341 def gen_XML file, nest
342 indent = XML_INDENT * nest
343
344 if is_imported? then
345 file.print <<EOT
346#{indent}<import path='#{@import.get_cdl_name}'>
347EOT
348 nest += 1
349 indent = XML_INDENT * nest
350 end
351
352 file.print <<EOT
353#{indent}<cell>
354#{indent}#{XML_INDENT}<name> #{@name} </name>
355EOT
356 @join_list.get_items.each{ |join|
357 if join.get_definition.kind_of? Port then
358 kind = "call_join"
359 elsif join.get_definition.kind_of? Decl then
360 kind = "attr_join"
361 else
362 raise "Unknown"
363 end
364 if join.get_array_member2 then
365 join.get_array_member2.each { |j2|
366 file.print <<EOT
367#{indent}#{XML_INDENT}<#{kind}>
368#{indent}#{XML_INDENT}#{XML_INDENT}<name> #{join.get_name} </name>
369#{indent}#{XML_INDENT}#{XML_INDENT}<subscript> #{join.get_subscript} </subscript>
370#{indent}#{XML_INDENT}#{XML_INDENT}<rhs> #{join.get_rhs.to_CDL_str} </rhs>
371#{indent}#{XML_INDENT}</#{kind}>
372EOT
373 }
374 else
375 file.print <<EOT
376#{indent}#{XML_INDENT}<#{kind}>
377#{indent}#{XML_INDENT}#{XML_INDENT}<name> #{join.get_name} </name>
378#{indent}#{XML_INDENT}#{XML_INDENT}<rhs> #{join.get_rhs.to_CDL_str} </rhs>
379#{indent}#{XML_INDENT}</#{kind}>
380EOT
381 end
382 }
383 file.print <<EOT
384#{indent}</cell>
385EOT
386 if is_imported? then
387 nest -= 1
388 indent = XML_INDENT * nest
389 file.print <<EOT
390#{indent}</import>
391EOT
392 end
393 end
394end
Note: See TracBrowser for help on using the repository browser.