source: EcnlProtoTool/trunk/asp3_dcre/tecsgen/tecslib/core/types.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: 42.5 KB
Line 
1# -*- coding: utf-8 -*-
2#
3# TECS Generator
4# Generator for TOPPERS Embedded Component System
5#
6# Copyright (C) 2008-2015 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: types.rb 1011 2016-07-11 02:20:01Z coas-nagasima $
53#++
54
55#= HasType: @type を内
56部に持つ型のためのモジュール
57# @b_cloned::Bool : true if @type is cloned
58#
59# このモジュールは DefinedType, PtrType, ArrayType に include される
60# 本当は typedef された時の Decl の要素のみ clone すればよいのだが、get_type, get_original_type で
61# 取り出されたとき、set_scs, set_qualifier されたときに無条件で clone する (無駄にメモリを使用する)
62# ただし、clone するのは一回のみである (二回 clone すると別の型を参ç…
63§ã—てしまう)
64#
65# initialize で clone しても、å…
66±æœ‰ã•ã‚Œã¦ã„るときに clone されない
67#
68module HasType
69 def initHasType
70 @b_cloned = false
71 end
72
73 #=== HasType# @type をクローンする
74 def clone_type
75# if @b_cloned == false then
76 @type = @type.clone
77 @b_cloned = true
78# end
79 end
80end
81
82class Type < Node
83# @b_const : bool
84# @b_volatile : bool
85
86 def initialize
87 super
88 end
89
90 def set_qualifier( qualifier )
91 case qualifier
92 when :CONST
93# if @b_const then
94# cdl_error( "T1001 const duplicate" )
95# end
96 @b_const = true
97 when :VOLATILE
98# if @b_volatile then
99# cdl_error( "T1002 volatile duplicate" )
100# end
101 @b_volatile = true
102 else
103 raise "Unknown qualifier #{qualifier}"
104 end
105 end
106
107 def is_const?
108 if @b_const then
109 return true
110 else
111 return false
112 end
113 end
114
115 def is_volatile?
116 if @b_volatile then
117 return true
118 else
119 return false
120 end
121 end
122
123 def is_void?
124 if self.kind_of? DefinedType then
125 return @type.is_void?
126 elsif self.kind_of? VoidType then
127 return true
128 else
129 return false
130 end
131 end
132
133 #=== size_is, count_is, string を設定
134 # 派生クラスでオーバーライドする(デフォルトではエラー)
135 def set_scs( size, count, string, max = nil, b_nullable = false )
136 str = ""
137 delim = ""
138 if size then
139 str = "size_is"
140 delim = ", "
141 end
142 if count then
143 str = "#{str}#{delim}count_is"
144 delim = ", "
145 end
146 if string then
147 str = "#{str}#{delim}string"
148 delim = ", "
149 end
150 if b_nullable then
151 str = "#{str}#{delim}nullable"
152 delim = ", "
153 end
154 cdl_error( "T1003 $1: unsuitable specifier for $2" , str, self.class )
155 end
156
157 def clear_max
158 raise "clear_max called: #{self.class}"
159 end
160
161 def get_type_str
162 str = ""
163 if @b_const then
164 str = "#{str}const "
165 end
166 if @b_volatile then
167 str = "#{str}volatile "
168 end
169 return str
170 end
171
172 #=== 型をチェック
173 # 正当な型定義かどうか、チェックする
174 def check
175 # 型に誤りがあれば、エラー文字列を返す
176 end
177
178 #=== struct の tag をチェック
179 # 正当な型定義かどうか、チェックする
180 #kind:: Decl の @kind を参ç…
181§
182 def check_struct_tag kind
183 # tag が存在しなければエラーを出力する
184 # é…
185åˆ—型では、要素の型を再帰的にチェック
186 # ポインタ型では、指すå…
187ˆã® tag チェックはしない
188 # 関数型ではパラメータリストのすべてについて行う
189 end
190
191 #=== 初期化可能かチェック
192 # attribute など初期化可能かチェックする(型に対し正当な初期化子が与えられているか)
193 #ident:: string 被代å…
194¥å¤‰æ•°å‘½
195 #initialize:: Expression, Array of initializer or C_EXP
196 # 代å…
197¥å€¤ã€C_EXP が与えられるのは IntType の場合のみ
198 #kind:: symbol (:ATTRIBUTE, :VAR, :CONSTNAT )
199 #attribute:: NameList kind == :VAR のとき参ç…
200§ã§ãã‚‹ attribute
201 #
202 # locale を第一引数として取るのは、以下の理由による。
203 # このメソッドは、変数への代å…
204¥ãŒè¡Œã‚ã‚Œã‚‹ã€Œè¡Œã€ã«å¯¾ã—て呼び出されるが、
205 # Type クラスのインスタンスは、変数が定義された「行」を記憶している。
206 #
207 # STAGE: S
208 def check_init( locale, ident, initializer, kind, attribute = nil )
209 #
210 end
211
212 #=== const_val を指定の型にキャストする
213 # 派生クラスでオーバーライドしていないとエラー
214 def cast( const_val )
215 cdl_error( "T1004 cannot cast to $1" , self.class )
216 end
217
218 #=== 型が一致するかのチェック
219 # 型名の字面でチェック.
220 # typedef された型も字面で一致を見るため、å…
221ƒã®åž‹ãŒåŒã˜ã§ã‚‚型名が異なれば不一致となる
222 def equal? type2
223 return ( get_type_str == type2.get_type_str ) && ( get_type_str_post == type2.get_type_str_post )
224 end
225
226 #=== bit size を得る
227 # IntType, FloatType 以外は0
228 def get_bit_size
229 return 0
230 end
231
232 #=== å…
233ƒã®åž‹ã‚’å¾—ã‚‹
234 # typedef された型の場合、そのå…
235ƒã®åž‹ã‚’返す.
236 # それ以外は、自分自身を返す.
237 # (DefinedType では本メソッドがオーバーライドされる)
238 def get_original_type
239 return self
240 end
241
242 #=== 内
243部にポインタ型を持つ
244 # ポインタ型、またはポインタ型メンバを持つ構造体、または要素がポインタ型を持つé…
245åˆ—
246 def has_pointer?
247 false
248 end
249
250 #=== size_is, count_is, string 指定されたポインタを持つか
251 # size_is, count_is, string 指定されたポインタ型、またはそれをメンバに持つ構造体、またはそれをを要素に持つé…
252åˆ—
253 def has_sized_pointer?
254 false
255 end
256
257 #=== 長さ指定のない string を持つ
258 # なさ指定のない string 指定されたポインタ型、またはそれをメンバに持つ構造体、またはそれを要素に持つé…
259åˆ—
260 def has_unsized_string?
261 false
262 end
263
264 def show_tree indent
265 indent.times { print " " }
266 puts "const=#{@b_const} volatile=#{@b_volatile} #{locale_str}"
267 indent.times { print " " }
268 puts "has_pointer=#{has_pointer?} has_sized_pointer=#{has_sized_pointer?} has_unsized_string=#{has_unsized_string?}"
269 end
270end
271
272class DefinedType < Type
273# @type_name::string
274# @typedef::Typedef
275# @type:: kind_of Type
276
277 include HasType
278
279 def initialize( type_name )
280 super()
281 @type_name = type_name
282
283 # mikan type_name が path になっていないため暫定
284 @typedef = Namespace.find( [ type_name ] ) #1
285
286# if @type.class != Typedef then
287# raise NotTypedef
288 # end
289 if @typedef == nil then
290 cdl_error( "T1005 \'$1\' not defined" , type_name )
291 elsif @typedef.class != Typedef then
292 cdl_error( "T1006 \'$1\' not type name. expecting type name here" , type_name )
293 end
294 @type = @typedef.get_declarator.get_type
295 initHasType
296 end
297
298 def get_type
299 clone_type
300 return @type
301 end
302
303 def get_type_str
304 "#{super}#{@type_name}"
305 end
306
307 def get_type_str_post
308 ""
309 end
310
311 def get_size
312 return @type.get_size
313 end
314
315 def is_nullable?
316 return @type.is_nullable?
317 end
318
319 #=== qualifier(const, volatile) の設定
320 def set_qualifier( qualifier )
321 clone_type
322 @type.set_qualifier( qualifier )
323 super
324 end
325
326 def set_scs( size, count, string, max = nil, b_nullable = false )
327 clone_type
328 @type.set_scs( size, count, string, max, b_nullable )
329 end
330
331 def clear_max
332 @type.clear_max
333 end
334
335 def get_original_type
336 clone_type
337 return @type.get_original_type
338 end
339
340 def check # 意味的誤りがあれば、文字列を返す
341 nil # typedef の段階で意味チェックされている
342 end
343
344 def check_init( locale, ident, initializer, kind, attribute = nil )
345 get_type.check_init( locale, ident, initializer, kind, attribute )
346 end
347
348 #=== 内
349部にポインタ型を持つ
350 # ポインタ型、またはポインタ型メンバを持つ構造体、または要素がポインタ型を持つé…
351åˆ—
352 def has_pointer?
353 @type.has_pointer?
354 end
355
356 #=== size_is, count_is, string 指定されたポインタを持つか
357 # size_is, count_is, string 指定されたポインタ型、またはそれをメンバに持つ構造体、またはそれをを要素に持つé…
358åˆ—
359 def has_sized_pointer?
360 @type.has_sized_pointer?
361 end
362
363 #=== 長さ指定のない string を持つ
364 # なさ指定のない string 指定されたポインタ型、またはそれをメンバに持つ構造体、またはそれを要素に持つé…
365åˆ—
366 def has_unsized_string?
367 @type.has_unsized_string?
368 end
369
370 def show_tree( indent )
371 indent.times { print " " }
372 if @typedef == nil then
373 puts "DefinedType: #{@type_name} is missing, const=#{@b_const} volatile=#{@b_volatile} #{locale_str}"
374 else
375 puts "DefinedType: #{@type_name}, const=#{@b_const} volatile=#{@b_volatile}"
376 end
377 super( indent + 1 )
378 @typedef.show_tree( indent + 1 )
379 @type.show_tree( indent + 1 )
380 end
381end
382
383class VoidType < Type
384
385 def check # 意味的誤りがあれば、文字列を返す
386 nil
387 end
388
389 def check_init( locale, ident, initializer, kind, attribute = nil )
390 cdl_error2( locale, "T1007 $1: void type variable cannot have initializer" , ident )
391 end
392
393 def get_type_str
394 "#{super}void"
395 end
396
397 def get_type_str_post
398 ""
399 end
400
401 def show_tree( indent )
402 indent.times { print " " }
403 puts "VoidType #{locale_str}"
404 super( indent + 1 )
405 end
406end
407
408class BoolType < Type
409
410 def check # 意味的誤りがあれば、文字列を返す
411 nil
412 end
413
414 def get_type_str
415 "#{super}bool_t"
416 end
417
418 def get_type_str_post
419 ""
420 end
421
422 def show_tree( indent )
423 indent.times { print " " }
424 puts "BoolType #{locale_str}"
425 super( indent + 1 )
426 end
427end
428
429class IntType < Type
430# @bit_size:: -11: char, -1: char_t, -2: short, -3: int, -4: long, -5: long long
431# 8, 16, 32, 64, 128
432# @sign:: :SIGNED, :UNSIGNED, nil
433
434 def initialize( bit_size )
435 super()
436 @bit_size = bit_size
437 @sign = nil
438 end
439
440 def set_sign( sign, b_uint = false )
441 if @sign then
442 if @sign != sign then
443 cdl_error( "T1008 ambigous signed or unsigned" )
444 end
445 elsif b_uint == false && @bit_size > 0 then
446 if sign == :SIGNED then
447 cdl_warning( "W2001 signed int$1_t: obsolete. use int$2_t" , @bit_size, @bit_size )
448 else
449 cdl_warning( "W2002 unsinged int$1_t: obsolete. use uint$2_t" , @bit_size, @bit_size )
450 end
451 end
452
453 @sign = sign
454
455 if @sign != :SIGNED && @sign != :UNSIGNED then
456 raise "set_sign: unknown sign: #{@sign}"
457 end
458 end
459
460 def check # 意味的誤りがあれば、文字列を返す
461 nil
462 end
463
464 def check_init( locale, ident, initializer, kind, attribute = nil )
465 val = initializer # C_EXP, Array
466 if val.instance_of?( Expression ) then
467 val = val.eval_const2( nil, attribute )
468 # 評価の結果 C_EXP や Array となる可能性がある
469 end
470
471 if val.instance_of? Token then # StringVal 導å…
472¥ã«ã‚ˆã‚Šã€ã‚‚はや Token は来ないはず
473 # val が Token の場合 == の右辺が String だとエラーを起こす (#198)
474 cdl_error2( locale, "T1009 $1: $2: not integer" , ident, val )
475 return
476 elsif val.is_a? C_EXP then
477 # #192 var が attribute を参ç…
478§ã—、attribute の右辺が C_EXP の場合
479 # const の右辺が C_EXP の場合も
480 return
481 elsif val.kind_of? FloatVal then
482 cdl_error2( locale, "T1011 $1: need cast to assign float to integer" , ident )
483 return
484 elsif val.instance_of? Array then
485 cdl_error2( locale, "T1017 $1: unsuitable initializer for scalar type" , ident )
486 return
487 elsif val == nil then
488 cdl_error2( locale, "T1010 $1: initializer is not constant" , ident )
489 return
490 end
491
492 if ! val.kind_of? IntegerVal then
493 cdl_error2( locale, "T1012 $1: $2: not integer" , ident, val )
494 return
495 end
496
497 val = val.to_i
498 max = get_max
499 min = get_min
500 dbgPrint "sign=#{@sign} ident=#{ident} val=#{val} max=#{max} min=#{min}\n"
501
502 if max != nil then
503 if val > max then
504 if @sign == :SIGNED || @sign == nil then
505 cdl_error2( locale, "T1013 $1: too large (max=$2)" , ident, max )
506 else
507 cdl_error2( locale, "T1016 $1: too large (max=$2)" , ident, max )
508 end
509 end
510 end
511
512 if min != nil then
513 if val < min
514 if @sign == :SIGNED || @sign == nil then
515 cdl_error2( locale, "T1014 $1: too large negative value (min=$2)" , ident, min )
516 else
517 cdl_error2( locale, "T1015 $1: negative value for unsigned" , ident )
518 end
519 end
520 end
521 end
522
523 #=== IntType# 最大値、最小値をチェックしてクリップする
524 # キャスト演算を行う
525 #in_val:: IntegerVal, FloatVal: この型にキャストする値
526 #from_type:: Symbol: :IntType, :FloatType IntType の場合はビット数でクリップ、FloatType の場合は最大値でクリップ
527 def check_and_clip( in_val, from_type = :IntType )
528 bit_size = get_bit_size
529 if bit_size == -1 then
530 bit_size = 8
531 end
532 val = in_val.to_i
533 if get_max && val > get_max then
534 if from_type == :IntType then
535 rval = ((1 << bit_size)-1) & val # bit 数でクリップ
536 else
537 rval = get_max # 最大値でクリップ (FloatType)
538 end
539 cdl_warning( "W2003 $1: too large to cast to $2, clipped($3)" , in_val, get_type_str, rval )
540 elsif get_min && val < get_min then
541 if from_type == :IntType then
542 rval = ((1 << bit_size)-1) & val
543 else
544 rval = get_min
545 end
546 if @sign == :SIGNED || @sign == nil then
547 cdl_warning( "W2004 $1: too small to cast to $2, clipped($3)" , in_val, get_type_str, rval )
548 else # @sign == :UNSIGNED || @sign == nil (char の場合)
549 cdl_warning( "W2005 $1: negative value for unsigned: convert to $2" , in_val, rval )
550 end
551 else
552 rval = val
553 end
554 return rval
555 end
556
557 def get_min
558 if @sign == :SIGNED || @sign == nil then
559 if @bit_size == -1 then
560 bit_sz = 8 # char_t は、有符号に扱う
561 else
562 bit_sz = @bit_size
563 end
564 case bit_sz
565 when 8, 16, 32, 64, 128
566 return - ( 1 << ( bit_sz - 1 ))
567 else # -1, -2, -3, -4, -5, -11
568 return nil
569 end
570 else # @sign == :UNSIGNED
571 return 0
572 end
573 end
574
575 def get_max
576 if @bit_size == -1 then
577 if @sign == nil then
578 return 255 # char_t は、無符号に扱う
579 else
580 bit_sz = 8
581 end
582 else
583 bit_sz = @bit_size
584 end
585 if @sign == :SIGNED || @sign == nil then
586 case bit_sz
587 when 8, 16, 32, 64, 128
588 return ( 1 << ( bit_sz - 1 )) -1
589 else # -1, -2, -3, -4, -5, -11
590 return nil
591 end
592 else # @sign == :UNSIGNED
593 case bit_sz
594 when 8, 16, 32, 64, 128
595 return ( 1 << bit_sz ) - 1
596 else # -2, -3, -4, -5, -11
597 return nil
598 end
599 end
600 end
601
602 #=== IntType# C 言語における型名(修飾子付き)
603 def get_type_str
604 str = super
605
606 # NEW_MODE
607 case @sign
608 when :SIGNED
609 sign = ""
610 signL = "signed "
611 when :UNSIGNED
612 sign = "u"
613 signL = "unsigned "
614 else
615 sign = ""
616 signL = ""
617 end
618
619 # p "get_type_str: sign:#{@sign} signL=#{signL}"
620
621 case @bit_size
622 when -1 # char_t 型
623 if @sign == :SIGNED then
624 sign = "s"
625 end
626 str = "#{str}#{sign}char_t"
627 when -11 # char 型(obsolete)
628 str = "#{str}#{signL}char"
629 when -2 # short 型
630 str = "#{str}#{signL}short"
631 when -3 # int 型
632 str = "#{str}#{signL}int"
633 when -4 # long 型
634 str = "#{str}#{signL}long"
635 when -5 # long long 型
636 str = "#{str}#{signL}long long"
637 when 8, 16, 32, 64, 128 # int16, int32, int64, int128 型
638 str = "#{str}#{sign}int#{@bit_size}_t"
639 end
640
641 return str
642 end
643
644 #=== IntType# C 言語における型名(後置文字列)
645 def get_type_str_post
646 ""
647 end
648
649 #=== IntType#bit_size を得る
650 # 返される値は @bit_size の仕様を参ç…
651§
652 def get_bit_size
653 return @bit_size
654 end
655
656 #=== IntType# sign を得る
657 # @sign の説明を参ç…
658§
659 def get_sign
660 @sign
661 end
662
663 def show_tree( indent )
664 indent.times { print " " }
665 puts "IntType bit_size=#{@bit_size} sign=#{@sign} const=#{@b_const} volatile=#{@b_volatile} #{locale_str}"
666 super( indent + 1 )
667 end
668end
669
670class FloatType < Type
671# @bit_size:: 32, 64, (80), -32, -64
672
673 def initialize( bit_size )
674 super()
675 @bit_size = bit_size
676 end
677
678 def check # 意味的誤りがあれば、文字列を返す
679 nil
680 end
681
682 # mikan Float 型の C_EXP 対応 (generate.rb にも変更必
683要)
684 def check_init( locale, ident, initializer, kind, attribute = nil )
685 # 型に対する初期値に誤りがあれば、エラー文字列を返す
686 val = initializer
687 if val.instance_of?( Expression ) then
688 val = val.eval_const2( nil, attribute )
689 # 評価の結果 C_EXP や Array となる可能性がある
690 end
691
692 if val.instance_of? Token then
693 # val が Token の場合 == の右辺が String だとエラーを起こす
694 cdl_error2( locale, "T1018 $1: $2: not number" , ident, val )
695 return
696 elsif val.instance_of? Array then
697 cdl_error2( locale, "T1020 $1: unsuitable initializer for scalar type" , ident )
698 return
699 elsif val.instance_of? C_EXP then
700 return
701 elsif val == nil then
702 cdl_error2( locale, "T1019 $1: initializer is not constant" , ident )
703 return
704 elsif ! val.kind_of?( IntegerVal ) && ! val.kind_of?( FloatVal ) then
705 cdl_error2( locale, "T1037 $1: not number" , ident )
706 return
707 end
708 # else
709 # cdl_error2( locale, "T1020 $1: unsuitable initializer for scalar type" , ident )
710 # return
711 # end
712 return
713 end
714
715 def get_type_str
716 str = super
717
718 case @bit_size
719 when 32
720 str = "#{str}float32_t"
721 when 64
722 str = "#{str}double64_t"
723 when -32
724 str = "#{str}float"
725 when -64
726 str = "#{str}double"
727 end
728 return str
729 end
730
731 def get_type_str_post
732 ""
733 end
734
735 def get_bit_size
736 @bit_size
737 end
738
739 def show_tree( indent )
740 indent.times { print " " }
741 puts "FloatType bit_size=#{@bit_size} qualifier=#{@qualifier} #{locale_str}"
742 super( indent + 1 )
743 end
744end
745
746class EnumType < Type # mikan
747# @bit_size:: -1: enum
748# 8, 16, 32, 64, 128
749# @element:: []
750# @element_val:: []
751
752 def initialize( bit_size )
753 super()
754 @bit_size = bit_size
755 end
756
757 def check
758 # mikan enum check
759 end
760
761 def show_tree( indent )
762 indent.times { print " " }
763 puts "EnumType bit_size=#{@bit_size} qualifier=#{@qualifier} #{locale_str}"
764 super( indent + 1 )
765 # mikan element
766 end
767end
768
769class StructType < Type
770# @tag::
771# @b_define:: true if define, false if refer
772# @members_decl:: NamedList
773# @definition:: StructType
774# @b_has_pointer_member:: bool : メンバにポインタ型がある
775# @b_has_sized_pointer_member:: bool : メンバにポインタ型がある
776# @b_has_unsized_string_member:: bool : メンバにポインタ型がある
777# @member_types_symbol:: Symbol : tag が無い時のみ設定 (それ以外では nil)
778
779 @@structtype_current_stack = []
780 @@structtype_current_sp = -1
781
782 # tag なし struct
783 @@no_struct_tag_num = 0
784 @@no_tag_struct_list = {}
785
786 def initialize( tag = nil )
787 super()
788 @tag = tag
789 @@structtype_current_sp += 1
790 @@structtype_current_stack[@@structtype_current_sp] = self
791 @b_has_pointer_member = false
792 @b_has_sized_pointer_member = false
793 @b_has_unsized_string_member = false
794 @member_types_symbol = nil
795 end
796
797 def self.set_define( b_define )
798 @@structtype_current_stack[@@structtype_current_sp].set_define( b_define )
799 end
800
801 def set_define( b_define )
802 @b_define = b_define
803 if @b_define then
804 @members_decl = NamedList.new( nil, "in struct #{@tag}" )
805 # if @tag then 登録タイミングを終わりに変更 V1.0.2.19
806 # Namespace.new_structtype( self )
807 # end
808 else
809 @definition = Namespace.find_tag( @tag )
810 # check_struct_tag に移す V1.0.2.19
811 # if @definition == nil then
812 # cdl_error( "T1021 \'$1\': struct not defined" , @tag )
813 # end
814 end
815 end
816
817 def self.new_member( member_decl )
818 @@structtype_current_stack[@@structtype_current_sp].new_member( member_decl )
819 end
820
821 def new_member( member_decl )
822 member_decl.set_owner self # Decl (StructType)
823 @members_decl.add_item( member_decl )
824 if member_decl.get_type.has_pointer?
825 @b_has_pointer_member = true
826 end
827 if member_decl.get_type.has_sized_pointer?
828 @b_has_sized_pointer_member = true
829 end
830 if member_decl.get_type.has_unsized_string?
831 @b_has_unsized_string_member = true
832 end
833 end
834
835 def check # 意味的誤りがあれば、文字列を返す
836 nil
837 end
838
839 #=== 構造体のタグをチェック
840 # declarator の時点でチェックする
841 #kind:: Decl の @kind を参ç…
842§
843 def check_struct_tag kind
844 if @tag == nil
845 return
846 end
847
848 st = Namespace.find_tag( @tag )
849 if st == nil then
850 cdl_error( "T1022 struct $1: not defined" , @tag )
851 end
852 end
853
854 # mikan Float 型の C_EXP 対応 (generate.rb にも変更必
855要)
856 def check_init( locale, ident, initializer, kind, attribute = nil )
857
858 st = Namespace.find_tag( @tag )
859 if st == nil then
860 cdl_error2( locale, "T1023 struct $1: not defined" , @tag )
861 return
862 end
863
864 # 初期化子が式の場合、型(タグ)が一致するかチェック
865 if initializer.instance_of?( Expression ) then
866 t = initializer.get_type( attribute )
867 # print "Check init #{t.class} #{t.get_name}\n"
868 if ! t.kind_of?( StructType ) then
869 if t then
870 str = t.get_type_str
871 else
872 str = "unknown"
873 end
874 cdl_error2( locale, "T1038 $1: initializer type mismatch. '$2' & '$3'" , ident, get_type_str, str )
875 elsif @tag != t.get_name then
876 cdl_error2( locale, "T1039 $1: struct tag mismatch $2 and $3" , ident, @tag, t.get_name )
877 end
878 initializer = initializer.eval_const( attribute )
879 end
880
881 if initializer.instance_of?( Array ) then
882 i = 0
883 st.get_members_decl.get_items.each { |d|
884 if initializer[i] then
885 d.get_type.check_init( locale, "#{ident}.#{d.get_identifier}", initializer[i], kind )
886 end
887 i += 1
888 }
889 else
890 cdl_error2( locale, "T1024 $1: unsuitable initializer for struct" , ident )
891 end
892 end
893
894 def self.end_of_parse()
895 @@structtype_current_stack[@@structtype_current_sp].end_of_parse
896 @@structtype_current_sp -= 1
897 end
898
899 def end_of_parse()
900 if @members_decl == nil # @b_define = false またはメンバーのない構造体(エラー)
901 return
902 end
903 @members_decl.get_items.each{ |md|
904 size = md.get_size_is
905 if size then
906 val = size.eval_const( @members_decl )
907 if val == nil then
908 type = size.get_type( @members_decl )
909 if ! type.kind_of?( IntType ) then
910 cdl_error( "T1025 size_is argument is not integer type" )
911 end
912 end
913 end
914 count = md.get_count_is
915 if count then
916 val = count.eval_const( @members_decl )
917 if val == nil then
918 type = count.get_type( @members_decl )
919 if ! type.kind_of?( IntType ) then
920 cdl_error( "T1026 count_is argument is not integer type" )
921 end
922 end
923 end
924 string = md.get_string
925 if string == -1 then
926 # 長さ指定なし
927 elsif string then
928 val = string.eval_const( @members_decl )
929 if val == nil then
930 type = string.get_type( @members_decl )
931 if ! type.kind_of?( IntType ) then
932 cdl_error( "T1027 string argument is not integer type" )
933 end
934 end
935 end
936 }
937
938 if @tag == nil then
939 @member_types_symbol = get_member_types_symbol
940 # print "member_types_symbol = #{get_member_types_symbol}\n"
941 if @@no_tag_struct_list[ @member_types_symbol ] then
942 @tag = @@no_tag_struct_list[ @member_types_symbol ]
943 else
944 @tag = :"TAG_#{@@no_struct_tag_num}_TECS_internal__"
945 @@no_struct_tag_num += 1
946 @@no_tag_struct_list[ @member_types_symbol ] = @tag
947 Namespace.new_structtype( self )
948 end
949 else
950 if @b_define then
951 Namespace.new_structtype( self )
952 end
953 end
954 end
955
956 def get_name
957 @tag
958 end
959
960 def get_type_str # mikan struct get_type_str
961 str = super
962
963 if @tag then
964 # typedef struct tag StructType; の形式の場合
965 # struct の本体は、別に生成される
966 return "#{str}struct #{@tag} "
967
968 else
969 # typedef struct { int a; } StructType; の形式の場合
970 str += "struct {\n"
971 @members_decl.get_items.each{ |i|
972 str += sprintf( " %-8s %s%s;\n", "#{i.get_type.get_type_str}", "#{i.get_name}", "#{i.get_type.get_type_str_post}" )
973 }
974 str += "} "
975
976 return str
977
978 end
979 end
980
981 def get_type_str_post
982 ""
983 end
984
985 def get_members_decl
986 return @members_decl if @members_decl
987
988 st = Namespace.find_tag( @tag )
989 if st then
990 return st.get_members_decl
991 end
992
993 return nil
994 end
995
996 def has_pointer?
997 if @definition
998 return @definition.has_pointer?
999 else
1000 return @b_has_pointer_member
1001 end
1002 end
1003
1004 def has_sized_pointer?
1005 if @definition
1006 return @definition.has_sized_pointer?
1007 else
1008 return @b_has_sized_pointer_member
1009 end
1010 end
1011
1012 def has_unsized_string?
1013 if @definition
1014 return @definition.has_unsized_string?
1015 else
1016 return @b_has_unsized_string_member
1017 end
1018 end
1019
1020 #=== 同じ構造体かどうかチェックする
1021 # tag のチェックは行わない
1022 # すべてのメンバの名前と型が一致することを確認する
1023 def same? another
1024 md = another.get_members_decl
1025 if @members_decl == nil || md == nil
1026 return false
1027 end
1028
1029 md1 = @members_decl.get_items
1030 md2 = md.get_items
1031 if( md1.length != md2.length )
1032 return false
1033 end
1034
1035 i = 0
1036 while i < md1.length
1037 if md1[i].get_name != md2[i].get_name ||
1038 md1[i].get_type.get_type_str != md2[i].get_type.get_type_str ||
1039 md1[i].get_type.get_type_str_post != md2[i].get_type.get_type_str_post
1040 return false
1041 end
1042 i += 1
1043 end
1044
1045 return true
1046 end
1047
1048 def get_member_types_symbol
1049 mts = ''
1050 @members_decl.get_items.each { |member|
1051 mts += member.get_type.get_type_str + member.get_type.get_type_str_post + ';'
1052 }
1053 return mts.to_sym
1054 end
1055
1056 def show_tree( indent )
1057 indent.times { print " " }
1058 puts "StructType tag: #{@tag} qualifier=#{@qualifier} has_pointer=#{@b_has_pointer_member} #{locale_str}"
1059 super( indent + 1 )
1060 if @b_define then
1061 @members_decl.show_tree( indent + 1 )
1062 end
1063 end
1064end
1065
1066class FuncType < Type
1067# @paramlist:: ParamList
1068# @type:: return type : PtrType, ArrayType, FuncType, IntType, FloatType, ...
1069# @b_oneway:: bool: true, false
1070# @has_in:: bool : has [in] parameter
1071# @has_inout:: bool : has [inout] parameter
1072# @has_out:: bool : has [out] parameter
1073# @has_send:: bool : has [send] parameter
1074# @has_receive:: bool : has [receive] parameter
1075
1076 def initialize( paramlist = nil )
1077 super()
1078
1079 @has_in = false
1080 @has_inout = false
1081 @has_out = false
1082 @has_send = false
1083 @has_receive = false
1084
1085 @paramlist = paramlist
1086 @b_oneway = false
1087 if paramlist then
1088 paramlist.check_param
1089 else
1090 @paramlist = ParamList.new( nil )
1091 end
1092 @paramlist.set_owner self # ParamList
1093 @paramlist.get_items.each{ |p|
1094 case p.get_direction
1095 when :IN
1096 @has_in = true
1097 when :INOUT
1098 @has_inout = true
1099 when :OUT
1100 @has_out = true
1101 when :SEND
1102 @has_send = true
1103 when :RECEIVE
1104 @has_receive = true
1105 else
1106 raise "unkown direction"
1107 end
1108 }
1109
1110 end
1111
1112 def check # 意味的誤りがあれば、文字列を返す
1113 if @type.class == ArrayType then # é…
1114åˆ—を返す関数
1115 return "function returning array"
1116 elsif @type.class == FuncType then # 関数を返す関数
1117 return "function returning function"
1118 end
1119 return @type.check # 関数の return する型のチェック
1120
1121 # パラメータの型のチェックは ParamList#check_param で行う
1122 end
1123
1124 def check_struct_tag kind
1125 @type.check_struct_tag kind
1126 # ParamDecl でもチェックされるので、ここではチェックしない
1127 # @paramlist.check_struct_tag kind
1128 end
1129
1130 def check_init( locale, ident, initializer, kind, attribute = nil )
1131 cdl_error2( locale, "T1028 $1: cannot initialize function pointer" , ident )
1132 return
1133 end
1134
1135 def set_type( type )
1136 unless @type then
1137 @type = type
1138 else
1139 @type.set_type( type )
1140 end
1141 end
1142
1143 #=== return type を返す
1144 #
1145 # return type を返す
1146 # get_return_type とすべきだった
1147 def get_type
1148 @type
1149 end
1150
1151 def get_type_str
1152 return @type.get_type_str
1153 end
1154
1155 def get_type_str_post
1156 # 型だけを返す (仮引数の名前を含めない)
1157 @paramlist.to_str( false )
1158 end
1159
1160 def get_paramlist
1161 @paramlist
1162 end
1163
1164 def set_oneway( b_oneway )
1165 @b_oneway = b_oneway
1166
1167 if ( ( @type.get_type_str != "ER" && @type.get_type_str != "void" ) || @type.get_type_str_post != "" ) then
1168 cdl_error( "T1029 oneway function cannot return type \'$1$2\', \'void\' or \'ER\' is permitted" , @type.get_type_str, @type.get_type_str_post )
1169 end
1170
1171 if @paramlist then
1172 @paramlist.get_items.each{ |p|
1173 if p.get_direction != :IN && p.get_direction != :SEND then
1174 cdl_error( "T1030 oneway function cannot have $1 parameter for \'$2\'" , p.get_direction, p.get_name )
1175 end
1176 }
1177 end
1178 end
1179
1180 def is_oneway?
1181 @b_oneway
1182 end
1183
1184 #=== Push Pop Allocator が必
1185要か?
1186 # Transparent RPC の場合 oneway かつ in のé…
1187åˆ—(size_is, count_is, string のいずれかで修飾)がある
1188 def need_PPAllocator?( b_opaque = false )
1189 if @b_oneway || b_opaque then
1190 return @paramlist.need_PPAllocator?( b_opaque )
1191 else
1192 return false
1193 end
1194 end
1195
1196 #=== パラメータが in, inout, out, send, receive を持つか
1197 def has_in?
1198 @has_in
1199 end
1200 def has_inout?
1201 @has_inout
1202 end
1203 def has_out?
1204 @has_out
1205 end
1206 def has_send?
1207 @has_send
1208 end
1209 def has_receive?
1210 @has_receive
1211 end
1212
1213 #=== å…
1214¥åŠ›æ–¹å‘のパラメータを持つか
1215 def has_inward?
1216 @has_in || @has_inout || @has_send
1217 end
1218 #=== 出力方向のパラメータを持つか
1219 def has_outward?
1220 @has_inout || @has_out || @has_receive
1221 end
1222
1223 def show_tree( indent )
1224 indent.times { print " " }
1225 if @b_oneway then
1226 puts "FunctType: oneway=true #{locale_str}"
1227 else
1228 puts "FunctType: oneway=false #{locale_str}"
1229 end
1230 super( indent + 1 )
1231 if @paramlist then
1232 @paramlist.show_tree( indent + 1 )
1233 end
1234 (indent+1).times { print " " }
1235 puts "return type:"
1236 @type.show_tree( indent + 2 )
1237 end
1238end
1239
1240class ArrayType < Type
1241# @type:: element type : ArrayType, FuncType, IntType, FloatType, ...
1242# @subscript:: Expression, nil if '[]'
1243
1244 include HasType
1245
1246 def initialize( subscript = nil )
1247 super()
1248 @subscript = subscript
1249 initHasType
1250 end
1251
1252 def set_type( type )
1253 unless @type then
1254 @type = type
1255 else
1256 @type.set_type( type )
1257 end
1258 end
1259
1260 #=== Array#qualifier(const, volatile) の設定
1261 def set_qualifier( qualifier )
1262 clone_type
1263 @type.set_qualifier( qualifier )
1264 super
1265 end
1266
1267 # é…
1268åˆ—要素が const なら const
1269 def is_const?
1270 @type.is_const?
1271 end
1272
1273 # é…
1274åˆ—要素が volatile なら volatile
1275 def is_volatile?
1276 @type.is_volatile?
1277 end
1278
1279 def get_type
1280 @type
1281 end
1282
1283 def get_subscript
1284 @subscript
1285 end
1286
1287 def get_type_str
1288 return "#{@type.get_type_str}"
1289 end
1290
1291 def get_type_str_post
1292 if @subscript
1293 "[#{@subscript.eval_const(nil)}]#{@type.get_type_str_post}"
1294 else
1295 "[]#{@type.get_type_str_post}"
1296 end
1297 # "[#{@subscript.to_s}]#{@type.get_type_str_post}"
1298 end
1299
1300 def check # 意味的誤りがあれば、文字列を返す
1301 if @type.class == FuncType then # 関数のé…
1302åˆ—
1303 return "array of function"
1304 elsif @type.class == ArrayType then # 添数なしé…
1305åˆ—のé…
1306åˆ—
1307 unless @type.get_subscript then
1308 return "subscript not specified"
1309 end
1310 end
1311
1312 return @type.check # é…
1313åˆ—要素の型をチェック
1314 end
1315
1316 def check_struct_tag kind
1317 @type.check_struct_tag kind
1318 end
1319
1320 def check_init( locale, ident, initializer, kind, attribute = nil )
1321 if ( initializer.instance_of?( Array ) ) then
1322 index = 0
1323 initializer.each{ |i|
1324 @type.check_init( locale, "#{ident}[#{index}]", i, kind, attribute = nil )
1325 index += 1
1326 }
1327 else
1328 cdl_error2( locale, "T1031 $1: unsuitable initializer for array" , ident )
1329 end
1330 end
1331
1332 def has_pointer?
1333 @type.has_pointer?
1334 end
1335
1336 def has_sized_pointer?
1337 @type.has_sized_pointer?
1338 end
1339
1340 def has_unsized_string?
1341 @type.has_unsized_string?
1342 end
1343
1344 def show_tree( indent )
1345 indent.times { print " " }
1346 puts "ArrayType: #{locale_str}"
1347 super( indent + 1 )
1348 (indent+1).times { print " " }
1349 puts "type:"
1350 @type.show_tree( indent + 2 )
1351 (indent+1).times { print " " }
1352 puts "subscript:"
1353 if @subscript then
1354 @subscript.show_tree( indent + 2 )
1355 else
1356 (indent+2).times { print " " }
1357 puts "no subscript"
1358 end
1359 end
1360end
1361
1362class PtrType < Type
1363# @type:: refer to : PtrType, FuncType, ArrayType, IntType, FloatType, ...
1364# @size:: Expr, or nil if not specified
1365# @count:: Expr, or nil if not specified
1366# @string:: Expr or -1(if size not specified) (string 引数), or nil if not specified
1367
1368 include HasType
1369
1370 def initialize( referto = nil )
1371 super()
1372 @type = referto
1373 @size = nil
1374 @count = nil
1375 @string = nil
1376 initHasType
1377 end
1378
1379 def set_type( type )
1380 unless @type then
1381 @type = type
1382 else
1383 @type.set_type( type ) # 枝å…
1384ˆã® type を設定
1385 end
1386 end
1387
1388 def get_type_str
1389 if @type.kind_of?( ArrayType ) || @type.kind_of?( FuncType ) then
1390 parenthes = "("
1391 else
1392 parenthes = ""
1393 end
1394 return "#{@type.get_type_str}#{parenthes}*"
1395 end
1396
1397 def get_type_str_post
1398 if @type.kind_of?( ArrayType ) || @type.kind_of?( FuncType ) then
1399 parenthes = ")"
1400 else
1401 parenthes = ""
1402 end
1403 "#{parenthes}#{@type.get_type_str_post}"
1404 end
1405
1406 def check # 意味的誤りがあれば、文字列を返す
1407 return nil if @type == nil
1408 @type.check
1409 end
1410
1411 def check_struct_tag kind
1412 if kind != :MEMBER # 構造体メンバーの場合、ポインタのå…
1413ˆã®æ§‹é€ ä½“タグをチェックしない
1414 @type.check_struct_tag kind
1415 end
1416 end
1417
1418 def check_init( locale, ident, initializer, kind, attribute = nil )
1419 if ( initializer.instance_of?( Expression ) ) then
1420 val = initializer.eval_const2( nil, attribute )
1421 if val.kind_of? PointerVal then
1422 type = val.get_type # PtrType
1423 t1 = self
1424 t2 = type
1425 while( t1.kind_of?( PtrType ) && t2.kind_of?( PtrType ) )
1426 t1 = t1.get_type
1427 t2 = t2.get_type
1428 if ( t1.class == t2.class ) && ( t1.get_bit_size == t2.get_bit_size ) then
1429 elsif ( t1.kind_of?( CDefinedType) || t2.kind_of?( CDefinedType ) )&& t1.get_type_str == t2.get_type_str && t1.get_type_str_post && t2.get_type_str_post then
1430 # int8_t などが、一方は .h に定義されているケース
1431 else
1432 cdl_error2( locale, "T1032 $1: incompatible pointer type" , ident )
1433 break
1434 end
1435 end
1436 elsif val.kind_of? IntegerVal then
1437 if val.to_i != 0 then
1438 cdl_error2( locale, "T1033 $1: need cast to assign integer to pointer" , ident )
1439 end
1440 elsif val.kind_of? StringVal then
1441 # 文字列定数
1442 # mikan L"wide string"
1443 if @type.get_bit_size != -1 && @type.get_bit_size != -11 then # -1: char_t
1444 cdl_error2( locale, "T1034 $1: unsuitable string constant" , ident )
1445 end
1446 elsif ( val.instance_of?( Array ) ) then
1447 i = 0
1448 val.each { |ini|
1449 @type.check_init( locale, "#{ident}[#{i}]", ini, kind, attribute = nil )
1450 i += 1
1451 }
1452 elsif val.instance_of?( C_EXP ) then
1453
1454 else
1455 cdl_error2( locale, "T1035 $1: unsuitable initializer for pointer" , ident )
1456 end
1457 elsif ( initializer.instance_of?( Array ) ) then
1458 if @size == nil && @count == nil then
1459 cdl_error2( locale, "T9999 $1: non-size_is pointer cannot have array initializer", ident )
1460 end
1461
1462 i = 0
1463 initializer.each { |ini|
1464 @type.check_init( locale, "#{ident}[#{i}]", ini, kind, attribute = nil )
1465 i += 1
1466 }
1467 elsif( initializer.instance_of?( C_EXP ) ) then
1468
1469 else
1470 cdl_error2( locale, "T1036 $1: unsuitable initializer for pointer" , ident )
1471 end
1472 end
1473
1474 def get_referto
1475 clone_type
1476 @type
1477 end
1478
1479 def set_scs( size, count, string, max, b_nullable )
1480 @size = size
1481 @count = count
1482 @max = max
1483 @b_nullable = b_nullable
1484
1485 # string は最も左側の ptr に作用する
1486 if @type.kind_of?( PtrType ) then
1487 # ptr_level が 2 以上であることは ParamDecl#initializer でチェックされる
1488 clone_type
1489 @type.set_scs( nil, nil, string, nil, false )
1490 elsif @type.kind_of?( VoidType ) && ( size || count || string ) then
1491 str = ""
1492 if size then
1493 str = "size_is"
1494 end
1495 if count then
1496 if str then
1497 str += ", "
1498 end
1499 str += "count_is"
1500 end
1501 if string then
1502 if str then
1503 str += ", "
1504 end
1505 str += "string"
1506 end
1507
1508 cdl_error( "T1040 $1 specified for void pointer type", str )
1509 else
1510 @string = string
1511 end
1512
1513 if (@size != nil) && (@b_nullable != false) then
1514 cdl_error( "T9999 size_is & nullable cannot be specified simultaneously. If size is zero, pointer must be null")
1515 end
1516 end
1517
1518 def clear_max
1519 @max = nil
1520 end
1521
1522 def get_size
1523 @size
1524 end
1525
1526 def get_count
1527 @count
1528 end
1529
1530 def get_string
1531 @string
1532 end
1533
1534 #=== PtrType# size_is の最大値
1535 def get_max
1536 @max
1537 end
1538
1539 def is_nullable?
1540 return @b_nullable
1541 end
1542
1543 def get_type
1544 clone_type
1545 @type
1546 end
1547
1548 def has_pointer?
1549 true
1550 end
1551
1552 def has_sized_pointer?
1553 @size != nil || @count != nil || @string.instance_of?( Expression ) || @type.has_sized_pointer?
1554 end
1555
1556 def has_unsized_string?
1557 @string == -1 || @type.has_unsized_string?
1558 end
1559
1560 def show_tree( indent )
1561 indent.times { print " " }
1562 puts "PtrType: qualifier=#{@qualifier}, nullable=#{@b_nullable} #{locale_str}"
1563 super( indent + 1 )
1564 (indent+1).times { print " " }
1565 if @size then
1566 print "size=#{@size.to_s}, "
1567 else
1568 print "size=nil, "
1569 end
1570 if @max then
1571 print "max=#{@size.to_s}, "
1572 else
1573 print "max=nil, "
1574 end
1575 if @count then
1576 print "count=#{@count.to_s}, "
1577 else
1578 print "count=nil, "
1579 end
1580 if @string then
1581 if @string.instance_of?( Expression ) then
1582 print "string=#{@string.to_s}\n"
1583 else
1584 print "string=yes\n"
1585 end
1586 else
1587 print "string=nil\n"
1588 end
1589
1590 (indent+1).times { print " " }
1591 puts "type:"
1592 @type.show_tree( indent + 2 )
1593 end
1594
1595end
1596
1597#== DescriptorType クラス
1598# 動的結合で渡すデスクリプタ型
1599class DescriptorType < Type
1600# @sinagure_nsp::NamespacePath
1601
1602 def initialize( signature_nsp )
1603 @signature_nsp = signature_nsp
1604 obj = Namespace.find signature_nsp
1605 if ! obj.kind_of? Signature then
1606 cdl_error( "T9999 '$1': not signature or not found", signature_nsp.to_s )
1607 else
1608 if obj.has_descriptor? then
1609 cdl_error( "T9999 '$1': has Desicrptor in function parameter", signature_nsp.to_s )
1610 end
1611 end
1612 end
1613
1614 def get_type_str
1615 "Descriptor( #{@signature_nsp.to_s} )"
1616 end
1617
1618 def get_type_str_post
1619 ""
1620 end
1621
1622 def set_qualifier( qualifier )
1623 cdl_error( "T9999 '$1' cannot be specified for Descriptor", qualfier.to_s )
1624 end
1625
1626 def check
1627 end
1628
1629 def check_init( locale, ident, initializer, kind, attribute = nil )
1630 case kind
1631 when :PARAMETER
1632 # 引数は初期化できない
1633 else
1634 cdl_error2( locale, "T9999 Descriptor cannot be used for $1", kind)
1635 end
1636 end
1637
1638 #== DescriptorType#
1639 # 意味解析段階では nil が返される可能性に注意
1640 def get_signature
1641 Namespace.find @signature_nsp
1642 end
1643end
1644
1645# 以下単体テストコード
1646if $unit_test then
1647 puts( "===== Unit Test: IntType ===== (types.rb)")
1648 sizes = [ 8, 16, 32, 64 ]
1649 sizes.each{ |n|
1650 int = IntType.new n
1651 printf( "%8s max: %d min:%d\n", "int#{n}_t", int.get_max, int.get_min )
1652 }
1653 puts ""
1654end
Note: See TracBrowser for help on using the repository browser.