source: azure_iot_hub/trunk/asp3_dcre/tecsgen/tecslib/core/tool_info.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.7 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# 上記著作権者
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#= TOOL_INFO class
56# The syntax of the contents of __tool_info__ is same as JSON.
57# Home made schema is used to validate the contents of __tool_info__.
58# the schema is not defiened well. see saveload.rb for example of the schema.
59#
60class TOOL_INFO
61
62 # tool_info
63 @@tool_info = { }
64
65 # tool_info schema for tecsgen
66 @@TECSGEN_schema = {
67 :tecsgen => { # require
68 :base_dir => [ :string ], # dir where the cde created initially
69 :direct_import => [ :string ], # .cdl (sometimes .cde) specified in argments
70 :import_path => [ :string ], # -I of tecsgen
71 :define_macro => [ :string ], # -D of tecsgen
72 :tecscde_version=> :string, # TECSCDE version
73 :cde_format_version=> :string, # CDE format version
74 :save_date => :string, # last save date & time
75 },
76 :__tecsgen => { # optioanl
77 :cpp => :string # -c or TECS_CPP environment variable
78 }
79 }
80
81 def initialize( name, val )
82 @@tool_info[name] = val
83
84 # __tool_info__( "tecsgen" ): validate & reflect immediately
85 p "tool_info: tecsgen #{name}"
86 if name == :tecsgen then
87 set_tecsgen_tool_info
88 end
89 end
90
91 def self.get_tool_info name
92 @@tool_info[ name ]
93 end
94
95 #=== TOOL_INFO#set_tecsgen_tool_info
96 # __tool_info__( "tecsgen" )
97 def set_tecsgen_tool_info
98 validator = TOOL_INFO::VALIDATOR.new( :tecsgen, @@TECSGEN_schema )
99 if validator.validate || $b_force_apply_tool_info
100 info = TOOL_INFO.get_tool_info( :tecsgen )
101 (info[ :base_dir ]).each{ |bd|
102 if ! $base_dir.include? bd
103 $base_dir[ bd ] = true
104 end
105 }
106
107 info[ :import_path ].each{ |path|
108 if ! $import_path.include?( path )
109 $import_path << path
110 end
111 }
112
113 info[ :define_macro ].each{ |define|
114 if ! $define.include?( define )
115 $define << define
116 end
117 }
118 if info[ :cpp ]
119 if ! $b_cpp_specified
120 $cpp = info[ :cpp ]
121 $b_cpp_specified = true
122 end
123 end
124
125 info[ :direct_import ] && info[ :direct_import ].each{ |import|
126 Import.new( import, false, false )
127 }
128 end
129 end
130
131 #== simple JSON validator
132 # this validator use simple schema.
133 # array length cannot be checked.
134 # you have to check array length in your code, if necessary.
135 class VALIDATOR
136
137 #@b_ok::Bool
138
139 def error( msg )
140 STDERR.print( "__tool_info__: " + msg )
141 @b_ok = false
142 end
143
144 def initialize name, schema
145 @name = name
146 @schema = schema
147 @b_ok = true
148 end
149
150 #=== VALIDATOR#validate
151 def validate
152 info = TOOL_INFO.get_tool_info @name
153 if info == nil
154 error( "\"#{@name}\" not found\n" )
155 return @b_ok
156 end
157 validate_object info, @name, @name
158 return @b_ok
159 end
160
161 def validate_object( object, require_type, path )
162 obj_type = @schema[ require_type ]
163 dbgPrint "validate_object: #{path} object=#{obj_type[ :type ]} required=#{object[:type]}\n"
164
165 obj_type.each{ |name, val_type|
166 val = object[name]
167 path2 = path.to_s + "." + name.to_s
168 if val == nil
169 error( "#{path}: required property not found '#{name}'\n" )
170 next
171 end
172 if val_type.kind_of? Array
173 validate_array_member val, val_type, path2
174 else
175 validate_types val, val_type, path2
176 end
177 }
178
179 optional = @schema[ ("__" + require_type.to_s).to_sym ]
180 if optional
181 dbgPrint "#{require_type.to_s} has optional\n"
182
183 optional.each{ |name, val_type|
184 val = object[name]
185 path2 = path.to_s + "." + name.to_s
186 if val == nil
187 # no need to occur error
188 # error( "#{path}: required property not found '#{name}'\n" )
189 next
190 end
191 if val_type.kind_of? Array
192 validate_array_member val, val_type, path2
193 else
194 validate_types val, val_type, path2
195 end
196 }
197 end
198
199 end
200
201 def validate_array_member array, val_types, path
202 if ! array.kind_of? Array
203 error( "#{path2}: array required as value\n" )
204 return
205 end
206 index=0
207 array.each{ |member|
208 type = get_object_type member
209 i = val_types.find_index type
210 if i == nil
211 if type == :integer
212 i = val_types.find_index :number
213 end
214 end
215 if i == nil
216 error( "#{path}: array member type mismatch, #{type} for #{val_types}\n" )
217 next
218 end
219 val_type = val_types[ i ]
220 validate_types member, val_type, (path.to_s + '[' + index.to_s + '].')
221 index += 1
222 }
223 end
224
225 #=== TOOL_INFO::VALIDATOR#validate_types
226 #obj::Object (Integer, Floating, String, Hash)
227 #val_type::Symbol : required object type
228 def validate_types obj, val_type, path
229 type = get_object_type obj
230 case val_type
231 when :integer
232 if type == :integer
233 return
234 end
235 when :number
236 if type == :integer || type == :number
237 return
238 end
239 when :string
240 if type == :string
241 return
242 end
243 # when :nil # mikan
244 # when :bool # mikan
245 else # object or fixed string
246 if val_type.kind_of? String
247 # val is specified by String
248 if type == :string
249 if obj == val_type
250 return
251 end
252 end
253 else
254 if type.to_sym == val_type
255 validate_object( obj, val_type, path + val_type.to_s )
256 return
257 end
258 end
259 end
260 error( "#{path}: type mismatch, #{type} for #{val_type}\n" )
261 end
262
263 def get_object_type obj
264# p "#{obj.class} #{obj.to_s}"
265 if obj.kind_of? Integer
266 return :integer
267 elsif obj.kind_of? Float
268 return :number
269 elsif obj.kind_of? String
270 return :string
271 elsif obj.kind_of? Hash
272 return obj[ :type ].to_sym
273 end
274 return nil
275 end
276 end
277
278end
279
280
281#---------- obsolete -------#
282
283#--- TOOL_INFO replaced location information ---#
284
285class TECSGEN
286
287 #------ manupulate location information --------#
288 def self.new_cell_location cell_location
289 @@current_tecsgen.new_cell_location cell_location
290 end
291 def new_cell_location cell_location
292 @cell_location_list << cell_location
293 end
294 def get_cell_location_list
295 @cell_location_list
296 end
297
298 def self.new_join_location join_location
299 @@current_tecsgen.new_join_location join_location
300 end
301 def new_join_location join_location
302 @join_location_list << join_location
303 end
304 def get_join_location_list
305 @join_location_list
306 end
307
308#== Cell_location
309 # tecscde の位置情
310å ±
311 class Cell_location
312
313 #=== Join_location#initialize
314 #cell_nspath::NamespacePath
315 #x,y,w,h::Expression
316 #port_location_list::[ [Symbol(ep_or_cp_name), Symbol(edge_name), Expression(offset)], ... ]
317 #ep_name::Symbol
318 def initialize( cell_nspath, x, y, w, h, port_location_list )
319 # p "Cell_location: #{cell_nspath}, #{x}, #{y}, #{w}, #{h}, #{port_location_list}"
320 @cell_nspath = cell_nspath
321 @x = x.eval_const nil
322 @y = y.eval_const nil
323 @w = w.eval_const nil
324 @h = h.eval_const nil
325 @port_location_list = port_location_list
326
327 TECSGEN.new_cell_location self
328 end
329
330 def get_location
331 [ @cell_nspath, @x, @y, @w, @h, @port_location_list ]
332 end
333
334 end # Cell_location
335
336 #== Join_location
337 # tecscde の位置情
338å ±
339 class Join_location
340 @@join_location_list = []
341
342 #=== Join_location#initialize
343 #cp_cell_nspath::NamespacePath
344 #cp_name::Symbol
345 #ep_cell_nspath::NamespacePath
346 #ep_name::Symbol
347 #bar_list::[[Symbol (VBar or HBar), Expression(position mm)], ....]
348 def initialize( cp_cell_nspath, cp_name, ep_cell_path, ep_name, bar_list )
349 # p "Join_location #{cp_cell_nspath}, #{cp_name}, #{ep_cell_path}, #{ep_name} #{bar_list}"
350 @cp_cell_nspath = cp_cell_nspath
351 @cp_name = cp_name
352 @ep_cell_path = ep_cell_path
353 @ep_name = ep_name
354 @bar_list = bar_list
355
356 TECSGEN.new_join_location self
357 end
358
359 def get_location
360 [@cp_cell_nspath, @cp_name, @ep_cell_path, @ep_name, @bar_list]
361 end
362
363 end # Join_location
364
365end # TECSGEN
Note: See TracBrowser for help on using the repository browser.