1 | #!ruby -Ku
|
---|
2 | #
|
---|
3 | # TOPPERS Configurator by Ruby
|
---|
4 | #
|
---|
5 | # Copyright (C) 2015,2016 by Embedded and Real-Time Systems Laboratory
|
---|
6 | # Graduate School of Information Science, Nagoya Univ., JAPAN
|
---|
7 | # Copyright (C) 2015 by FUJI SOFT INCORPORATED, JAPAN
|
---|
8 | #
|
---|
9 | # ä¸è¨èä½æ¨©è
|
---|
10 | ã¯ï¼ä»¥ä¸ã®(1)ã(4)ã®æ¡ä»¶ãæºããå ´åã«éãï¼æ¬ã½ããã¦ã§
|
---|
11 | # ã¢ï¼æ¬ã½ããã¦ã§ã¢ãæ¹å¤ãããã®ãå«ãï¼ä»¥ä¸åãï¼ã使ç¨ã»è¤è£½ã»æ¹
|
---|
12 | # å¤ã»åé
|
---|
13 | å¸ï¼ä»¥ä¸ï¼å©ç¨ã¨å¼ã¶ï¼ãããã¨ãç¡åã§è¨±è«¾ããï¼
|
---|
14 | # (1) æ¬ã½ããã¦ã§ã¢ãã½ã¼ã¹ã³ã¼ãã®å½¢ã§å©ç¨ããå ´åã«ã¯ï¼ä¸è¨ã®èä½
|
---|
15 | # 権表示ï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãï¼ãã®ã¾ã¾ã®å½¢ã§ã½ã¼
|
---|
16 | # ã¹ã³ã¼ãä¸ã«å«ã¾ãã¦ãããã¨ï¼
|
---|
17 | # (2) æ¬ã½ããã¦ã§ã¢ãï¼ã©ã¤ãã©ãªå½¢å¼ãªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
18 | # ç¨ã§ããå½¢ã§åé
|
---|
19 | å¸ããå ´åã«ã¯ï¼åé
|
---|
20 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨
|
---|
21 | # è
|
---|
22 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®èä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨
|
---|
23 | # ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
24 | # (3) æ¬ã½ããã¦ã§ã¢ãï¼æ©å¨ã«çµã¿è¾¼ããªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
25 | # ç¨ã§ããªãå½¢ã§åé
|
---|
26 | å¸ããå ´åã«ã¯ï¼æ¬¡ã®ããããã®æ¡ä»¶ãæºããã
|
---|
27 | # ã¨ï¼
|
---|
28 | # (a) åé
|
---|
29 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨è
|
---|
30 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®è
|
---|
31 | # ä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
32 | # (b) åé
|
---|
33 | å¸ã®å½¢æ
|
---|
34 | ãï¼å¥ã«å®ããæ¹æ³ã«ãã£ã¦ï¼TOPPERSããã¸ã§ã¯ãã«
|
---|
35 | # å ±åãããã¨ï¼
|
---|
36 | # (4) æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæ
|
---|
37 | # 害ãããï¼ä¸è¨èä½æ¨©è
|
---|
38 | ããã³TOPPERSããã¸ã§ã¯ããå
|
---|
39 | 責ãããã¨ï¼
|
---|
40 | # ã¾ãï¼æ¬ã½ããã¦ã§ã¢ã®ã¦ã¼ã¶ã¾ãã¯ã¨ã³ãã¦ã¼ã¶ããã®ãããªãç
|
---|
41 | # ç±ã«åºã¥ãè«æ±ãããï¼ä¸è¨èä½æ¨©è
|
---|
42 | ããã³TOPPERSããã¸ã§ã¯ãã
|
---|
43 | # å
|
---|
44 | 責ãããã¨ï¼
|
---|
45 | #
|
---|
46 | # æ¬ã½ããã¦ã§ã¢ã¯ï¼ç¡ä¿è¨¼ã§æä¾ããã¦ãããã®ã§ããï¼ä¸è¨èä½æ¨©è
|
---|
47 | ã
|
---|
48 | # ãã³TOPPERSããã¸ã§ã¯ãã¯ï¼æ¬ã½ããã¦ã§ã¢ã«é¢ãã¦ï¼ç¹å®ã®ä½¿ç¨ç®ç
|
---|
49 | # ã«å¯¾ããé©åæ§ãå«ãã¦ï¼ãããªãä¿è¨¼ãè¡ããªãï¼ã¾ãï¼æ¬ã½ããã¦ã§
|
---|
50 | # ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæ害ã«é¢ãã¦ãï¼ã
|
---|
51 | # ã®è²¬ä»»ãè² ããªãï¼
|
---|
52 | #
|
---|
53 | # $Id: StrVal.rb 25 2016-01-29 16:48:00Z ertl-hiro $
|
---|
54 | #
|
---|
55 |
|
---|
56 | ######################################################################
|
---|
57 | # æååï¼æ°å¤ã¯ã©ã¹å®ç¾©
|
---|
58 | ######################################################################
|
---|
59 | class StrVal < String
|
---|
60 | def initialize(sStr, nVal = (sStr =~ /^[0-9]+$/) ? sStr.to_i() : nil)
|
---|
61 | @nVal = nVal
|
---|
62 | super(sStr)
|
---|
63 | end
|
---|
64 |
|
---|
65 | # æ°å¤æ
|
---|
66 | å ±ãè¿ã
|
---|
67 | def val()
|
---|
68 | return @nVal
|
---|
69 | end
|
---|
70 |
|
---|
71 | # ã¤ã¬ã®ã¥ã©ã¼ãªä½¿ç¨æã®ã¨ã©ã¼
|
---|
72 | def unexpected_use(other, sExp)
|
---|
73 | if (!@nVal.nil?)
|
---|
74 | if (other.is_a?(StrVal) && other.val.nil?)
|
---|
75 | error_exit("`#{other}' don't have value", caller[1])
|
---|
76 | else
|
---|
77 | error_exit("`#{sExp}' can't use with `#{other.class}'", caller[1])
|
---|
78 | end
|
---|
79 | else
|
---|
80 | error_exit("`#{self}' don't have value", caller[1])
|
---|
81 | end
|
---|
82 | end
|
---|
83 |
|
---|
84 | # æ¼ç®åãªã¼ãã¼ã©ã¤ã(tfã¨åçã®æ©è½ãå®ç¾)
|
---|
85 | alias_method :plus, :+
|
---|
86 | alias_method :asterisk, :*
|
---|
87 | alias_method :gt, :>
|
---|
88 | alias_method :lt, :<
|
---|
89 | alias_method :ge, :>=
|
---|
90 | alias_method :le, :<=
|
---|
91 | alias_method :eq, :==
|
---|
92 | alias_method :ne, :!=
|
---|
93 | alias_method :ls, :<<
|
---|
94 | def +(other)
|
---|
95 | if (!@nVal.nil? && other.is_a?(Integer))
|
---|
96 | @nVal + other
|
---|
97 | elsif (!@nVal.nil? && other.is_a?(StrVal) && !other.val.nil?)
|
---|
98 | @nVal + other.val
|
---|
99 | else
|
---|
100 | plus(other)
|
---|
101 | end
|
---|
102 | end
|
---|
103 | def -(other)
|
---|
104 | if (!@nVal.nil? && other.is_a?(Integer))
|
---|
105 | @nVal - other
|
---|
106 | elsif (!@nVal.nil? && other.is_a?(StrVal) && !other.val.nil?)
|
---|
107 | @nVal - other.val
|
---|
108 | else
|
---|
109 | unexpected_use(other, "-")
|
---|
110 | end
|
---|
111 | end
|
---|
112 | def *(other)
|
---|
113 | if (!@nVal.nil? && other.is_a?(Integer))
|
---|
114 | @nVal * other
|
---|
115 | elsif (!@nVal.nil? && other.is_a?(StrVal) && !other.val.nil?)
|
---|
116 | @nVal * other.val
|
---|
117 | else
|
---|
118 | asterisk(other)
|
---|
119 | end
|
---|
120 | end
|
---|
121 | def /(other)
|
---|
122 | if (!@nVal.nil? && other.is_a?(Integer))
|
---|
123 | @nVal / other
|
---|
124 | elsif (!@nVal.nil? && other.is_a?(StrVal) && !other.val.nil?)
|
---|
125 | @nVal / other.val
|
---|
126 | else
|
---|
127 | unexpected_use(other, "/")
|
---|
128 | end
|
---|
129 | end
|
---|
130 | def &(other)
|
---|
131 | if (!@nVal.nil? && other.is_a?(Integer))
|
---|
132 | @nVal & other
|
---|
133 | elsif (!@nVal.nil? && other.is_a?(StrVal) && !other.val.nil?)
|
---|
134 | @nVal & other.val
|
---|
135 | else
|
---|
136 | unexpected_use(other, "&")
|
---|
137 | end
|
---|
138 | end
|
---|
139 | def |(other)
|
---|
140 | if (!@nVal.nil? && other.is_a?(Integer))
|
---|
141 | @nVal | other
|
---|
142 | elsif (!@nVal.nil? && other.is_a?(StrVal) && !other.val.nil?)
|
---|
143 | @nVal | other.val
|
---|
144 | else
|
---|
145 | unexpected_use(other, "|")
|
---|
146 | end
|
---|
147 | end
|
---|
148 | def >(other)
|
---|
149 | if (!@nVal.nil? && other.is_a?(Integer))
|
---|
150 | @nVal > other
|
---|
151 | elsif (!@nVal.nil? && other.is_a?(StrVal) && !other.val.nil?)
|
---|
152 | @nVal > other.val
|
---|
153 | else
|
---|
154 | gt(other)
|
---|
155 | end
|
---|
156 | end
|
---|
157 | def <(other)
|
---|
158 | if (!@nVal.nil? && other.is_a?(Integer))
|
---|
159 | @nVal < other
|
---|
160 | elsif (!@nVal.nil? && other.is_a?(StrVal) && !other.val.nil?)
|
---|
161 | @nVal < other.val
|
---|
162 | else
|
---|
163 | lt(other)
|
---|
164 | end
|
---|
165 | end
|
---|
166 | def >=(other)
|
---|
167 | if (!@nVal.nil? && other.is_a?(Integer))
|
---|
168 | @nVal >= other
|
---|
169 | elsif (!@nVal.nil? && other.is_a?(StrVal) && !other.val.nil?)
|
---|
170 | @nVal >= other.val
|
---|
171 | else
|
---|
172 | ge(other)
|
---|
173 | end
|
---|
174 | end
|
---|
175 | def <=(other)
|
---|
176 | if (!@nVal.nil? && other.is_a?(Integer))
|
---|
177 | @nVal <= other
|
---|
178 | elsif (!@nVal.nil? && other.is_a?(StrVal) && !other.val.nil?)
|
---|
179 | @nVal <= other.val
|
---|
180 | else
|
---|
181 | le(other)
|
---|
182 | end
|
---|
183 | end
|
---|
184 | def ==(other)
|
---|
185 | if (!@nVal.nil? && other.is_a?(Integer))
|
---|
186 | @nVal == other
|
---|
187 | elsif (!@nVal.nil? && other.is_a?(StrVal) && !other.val.nil?)
|
---|
188 | @nVal == other.val
|
---|
189 | else
|
---|
190 | eq(other)
|
---|
191 | end
|
---|
192 | end
|
---|
193 | def !=(other)
|
---|
194 | if (!@nVal.nil? && other.is_a?(Integer))
|
---|
195 | @nVal != other
|
---|
196 | elsif (!@nVal.nil? && other.is_a?(StrVal) && !other.val.nil?)
|
---|
197 | @nVal != other.val
|
---|
198 | else
|
---|
199 | ne(other)
|
---|
200 | end
|
---|
201 | end
|
---|
202 | def >>(other)
|
---|
203 | if (!@nVal.nil? && other.is_a?(Integer))
|
---|
204 | @nVal >> other
|
---|
205 | elsif (!@nVal.nil? && other.is_a?(StrVal) && !other.val.nil?)
|
---|
206 | @nVal >> other.val
|
---|
207 | else
|
---|
208 | unexpected_use(other, ">>")
|
---|
209 | end
|
---|
210 | end
|
---|
211 | def <<(other)
|
---|
212 | if (!@nVal.nil? && other.is_a?(Integer))
|
---|
213 | @nVal << other
|
---|
214 | elsif (!@nVal.nil? && other.is_a?(StrVal) && !other.val.nil?)
|
---|
215 | @nVal << other.val
|
---|
216 | else
|
---|
217 | ls(other)
|
---|
218 | end
|
---|
219 | end
|
---|
220 | def ~@
|
---|
221 | if (!@nVal.nil?)
|
---|
222 | ~@nVal
|
---|
223 | else
|
---|
224 | unexpected_use(nil, "~")
|
---|
225 | end
|
---|
226 | end
|
---|
227 |
|
---|
228 | # ppãããã°æã®è¡¨ç¤ºæ¹å
|
---|
229 | def pretty_print(q)
|
---|
230 | if (!@nVal.nil?)
|
---|
231 | q.text("#{self}{#{@nVal}(#{sprintf("0x%x",@nVal)})}")
|
---|
232 | else
|
---|
233 | q.text("#{self}{-}")
|
---|
234 | end
|
---|
235 | end
|
---|
236 | end
|
---|
237 |
|
---|
238 | ######################################################################
|
---|
239 | # æ´æ°ã¯ã©ã¹ã®æ¼ç®åãªã¼ãã¼ã©ã¤ã(tfã¨åçã®æ©è½ãå®ç¾)
|
---|
240 | ######################################################################
|
---|
241 | class Fixnum
|
---|
242 | alias_method :plus, :+
|
---|
243 | alias_method :minus, :-
|
---|
244 | alias_method :asterisk, :*
|
---|
245 | alias_method :slash, :/
|
---|
246 | alias_method :ampersand, :&
|
---|
247 | alias_method :pipe, :|
|
---|
248 | alias_method :gt, :>
|
---|
249 | alias_method :lt, :<
|
---|
250 | alias_method :ge, :>=
|
---|
251 | alias_method :le, :<=
|
---|
252 | alias_method :eq, :==
|
---|
253 | alias_method :ne, :!=
|
---|
254 | alias_method :rs, :>>
|
---|
255 | alias_method :ls, :<<
|
---|
256 | def +(other)
|
---|
257 | other.is_a?(StrVal) ? plus(other.val) : plus(other)
|
---|
258 | end
|
---|
259 | def -(other)
|
---|
260 | other.is_a?(StrVal) ? minus(other.val) : minus(other)
|
---|
261 | end
|
---|
262 | def *(other)
|
---|
263 | other.is_a?(StrVal) ? asterisk(other.val) : asterisk(other)
|
---|
264 | end
|
---|
265 | def /(other)
|
---|
266 | other.is_a?(StrVal) ? slash(other.val) : slash(other)
|
---|
267 | end
|
---|
268 | def &(other)
|
---|
269 | other.is_a?(StrVal) ? ampersand(other.val) : ampersand(other)
|
---|
270 | end
|
---|
271 | def |(other)
|
---|
272 | other.is_a?(StrVal) ? pipe(other.val) : pipe(other)
|
---|
273 | end
|
---|
274 | def >(other)
|
---|
275 | other.is_a?(StrVal) ? gt(other.val) : gt(other)
|
---|
276 | end
|
---|
277 | def <(other)
|
---|
278 | other.is_a?(StrVal) ? lt(other.val) : lt(other)
|
---|
279 | end
|
---|
280 | def >=(other)
|
---|
281 | other.is_a?(StrVal) ? ge(other.val) : ge(other)
|
---|
282 | end
|
---|
283 | def <=(other)
|
---|
284 | other.is_a?(StrVal) ? le(other.val) : le(other)
|
---|
285 | end
|
---|
286 | def ==(other)
|
---|
287 | other.is_a?(StrVal) ? eq(other.val) : eq(other)
|
---|
288 | end
|
---|
289 | def !=(other)
|
---|
290 | other.is_a?(StrVal) ? ne(other.val) : ne(other)
|
---|
291 | end
|
---|
292 | def >>(other)
|
---|
293 | other.is_a?(StrVal) ? rs(other.val) : rs(other)
|
---|
294 | end
|
---|
295 | def <<(other)
|
---|
296 | other.is_a?(StrVal) ? ls(other.val) : ls(other)
|
---|
297 | end
|
---|
298 | end
|
---|
299 |
|
---|
300 | class Bignum
|
---|
301 | alias_method :plus, :+
|
---|
302 | alias_method :minus, :-
|
---|
303 | alias_method :asterisk, :*
|
---|
304 | alias_method :slash, :/
|
---|
305 | alias_method :ampersand, :&
|
---|
306 | alias_method :pipe, :|
|
---|
307 | alias_method :gt, :>
|
---|
308 | alias_method :lt, :<
|
---|
309 | alias_method :ge, :>=
|
---|
310 | alias_method :le, :<=
|
---|
311 | alias_method :eq, :==
|
---|
312 | alias_method :ne, :!=
|
---|
313 | alias_method :rs, :>>
|
---|
314 | alias_method :ls, :<<
|
---|
315 | def +(other)
|
---|
316 | other.is_a?(StrVal) ? plus(other.val) : plus(other)
|
---|
317 | end
|
---|
318 | def -(other)
|
---|
319 | other.is_a?(StrVal) ? minus(other.val) : minus(other)
|
---|
320 | end
|
---|
321 | def *(other)
|
---|
322 | other.is_a?(StrVal) ? asterisk(other.val) : asterisk(other)
|
---|
323 | end
|
---|
324 | def /(other)
|
---|
325 | other.is_a?(StrVal) ? slash(other.val) : slash(other)
|
---|
326 | end
|
---|
327 | def &(other)
|
---|
328 | other.is_a?(StrVal) ? ampersand(other.val) : ampersand(other)
|
---|
329 | end
|
---|
330 | def |(other)
|
---|
331 | other.is_a?(StrVal) ? pipe(other.val) : pipe(other)
|
---|
332 | end
|
---|
333 | def >(other)
|
---|
334 | other.is_a?(StrVal) ? gt(other.val) : gt(other)
|
---|
335 | end
|
---|
336 | def <(other)
|
---|
337 | other.is_a?(StrVal) ? lt(other.val) : lt(other)
|
---|
338 | end
|
---|
339 | def >=(other)
|
---|
340 | other.is_a?(StrVal) ? ge(other.val) : ge(other)
|
---|
341 | end
|
---|
342 | def <=(other)
|
---|
343 | other.is_a?(StrVal) ? le(other.val) : le(other)
|
---|
344 | end
|
---|
345 | def ==(other)
|
---|
346 | other.is_a?(StrVal) ? eq(other.val) : eq(other)
|
---|
347 | end
|
---|
348 | def !=(other)
|
---|
349 | other.is_a?(StrVal) ? ne(other.val) : ne(other)
|
---|
350 | end
|
---|
351 | def >>(other)
|
---|
352 | other.is_a?(StrVal) ? rs(other.val) : rs(other)
|
---|
353 | end
|
---|
354 | def <<(other)
|
---|
355 | other.is_a?(StrVal) ? ls(other.val) : ls(other)
|
---|
356 | end
|
---|
357 | end
|
---|