source: azure_iot_hub/trunk/asp3_dcre/tecsgen/tecslib/core/types.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: 43.3 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#= 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, -128
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 when -128
728 str = "#{str}long double"
729 end
730 return str
731 end
732
733 def get_type_str_post
734 ""
735 end
736
737 def get_bit_size
738 @bit_size
739 end
740
741 def show_tree( indent )
742 indent.times { print " " }
743 puts "FloatType bit_size=#{@bit_size} qualifier=#{@qualifier} #{locale_str}"
744 super( indent + 1 )
745 end
746end
747
748class EnumType < Type # mikan
749# @bit_size:: -1: enum
750# 8, 16, 32, 64, 128
751# @element:: []
752# @element_val:: []
753
754 def initialize( bit_size )
755 super()
756 @bit_size = bit_size
757 end
758
759 def check
760 # mikan enum check
761 end
762
763 def show_tree( indent )
764 indent.times { print " " }
765 puts "EnumType bit_size=#{@bit_size} qualifier=#{@qualifier} #{locale_str}"
766 super( indent + 1 )
767 # mikan element
768 end
769end
770
771class StructType < Type
772# @tag::
773# @b_define:: true if define, false if refer
774# @members_decl:: NamedList
775# @definition:: StructType
776# @b_has_pointer_member:: bool : メンバにポインタ型がある
777# @b_has_sized_pointer_member:: bool : メンバにポインタ型がある
778# @b_has_unsized_string_member:: bool : メンバにポインタ型がある
779# @b_hasTag:: bool : タグがある
780# @member_types_symbol:: Symbol : tag が無い時のみ設定 (それ以外では nil)
781
782 @@structtype_current_stack = []
783 @@structtype_current_sp = -1
784
785 # tag なし struct
786 @@no_struct_tag_num = 0
787 @@no_tag_struct_list = {}
788
789 def initialize( tag = nil )
790 super()
791 @tag = tag
792 if tag then
793 @b_hasTag = true
794 else
795 @b_hasTag = false
796 end
797 @@structtype_current_sp += 1
798 @@structtype_current_stack[@@structtype_current_sp] = self
799 @b_has_pointer_member = false
800 @b_has_sized_pointer_member = false
801 @b_has_unsized_string_member = false
802 @member_types_symbol = nil
803 end
804
805 def self.set_define( b_define )
806 @@structtype_current_stack[@@structtype_current_sp].set_define( b_define )
807 end
808
809 def set_define( b_define )
810 @b_define = b_define
811 if @b_define then
812 @members_decl = NamedList.new( nil, "in struct #{@tag}" )
813 # if @tag then 登録タイミングを終わりに変更 V1.0.2.19
814 # Namespace.new_structtype( self )
815 # end
816 else
817 @definition = Namespace.find_tag( @tag )
818 # check_struct_tag に移す V1.0.2.19
819 # if @definition == nil then
820 # cdl_error( "T1021 \'$1\': struct not defined" , @tag )
821 # end
822 end
823 end
824
825 def self.new_member( member_decl )
826 @@structtype_current_stack[@@structtype_current_sp].new_member( member_decl )
827 end
828
829 def new_member( member_decl )
830 member_decl.set_owner self # Decl (StructType)
831 @members_decl.add_item( member_decl )
832 if member_decl.get_type.has_pointer?
833 @b_has_pointer_member = true
834 end
835 if member_decl.get_type.has_sized_pointer?
836 @b_has_sized_pointer_member = true
837 end
838 if member_decl.get_type.has_unsized_string?
839 @b_has_unsized_string_member = true
840 end
841 end
842
843 def check # 意味的誤りがあれば、文字列を返す
844 nil
845 end
846
847 #=== 構造体のタグをチェック
848 # declarator の時点でチェックする
849 #kind:: Decl の @kind を参ç…
850§
851 def check_struct_tag kind
852 if @tag == nil
853 return
854 end
855
856 st = Namespace.find_tag( @tag )
857 if st == nil then
858 cdl_error( "T1022 struct $1: not defined" , @tag )
859 end
860 end
861
862 # mikan Float 型の C_EXP 対応 (generate.rb にも変更必
863要)
864 def check_init( locale, ident, initializer, kind, attribute = nil )
865
866 st = Namespace.find_tag( @tag )
867 if st == nil then
868 cdl_error2( locale, "T1023 struct $1: not defined" , @tag )
869 return
870 end
871
872 # 初期化子が式の場合、型(タグ)が一致するかチェック
873 if initializer.instance_of?( Expression ) then
874 t = initializer.get_type( attribute )
875 # print "Check init #{t.class} #{t.get_name}\n"
876 if ! t.kind_of?( StructType ) then
877 if t then
878 str = t.get_type_str
879 else
880 str = "unknown"
881 end
882 cdl_error2( locale, "T1038 $1: initializer type mismatch. '$2' & '$3'" , ident, get_type_str, str )
883 elsif @tag != t.get_name then
884 cdl_error2( locale, "T1039 $1: struct tag mismatch $2 and $3" , ident, @tag, t.get_name )
885 end
886 initializer = initializer.eval_const( attribute )
887 end
888
889 if initializer.instance_of?( Array ) then
890 i = 0
891 st.get_members_decl.get_items.each { |d|
892 if initializer[i] then
893 d.get_type.check_init( locale, "#{ident}.#{d.get_identifier}", initializer[i], kind )
894 end
895 i += 1
896 }
897 else
898 cdl_error2( locale, "T1024 $1: unsuitable initializer for struct" , ident )
899 end
900 end
901
902 def self.end_of_parse()
903 @@structtype_current_stack[@@structtype_current_sp].end_of_parse
904 @@structtype_current_sp -= 1
905 end
906
907 def end_of_parse()
908 if @members_decl == nil # @b_define = false またはメンバーのない構造体(エラー)
909 return
910 end
911 @members_decl.get_items.each{ |md|
912 size = md.get_size_is
913 if size then
914 val = size.eval_const( @members_decl )
915 if val == nil then
916 type = size.get_type( @members_decl )
917 if ! type.kind_of?( IntType ) then
918 cdl_error( "T1025 size_is argument is not integer type" )
919 end
920 end
921 end
922 count = md.get_count_is
923 if count then
924 val = count.eval_const( @members_decl )
925 if val == nil then
926 type = count.get_type( @members_decl )
927 if ! type.kind_of?( IntType ) then
928 cdl_error( "T1026 count_is argument is not integer type" )
929 end
930 end
931 end
932 string = md.get_string
933 if string == -1 then
934 # 長さ指定なし
935 elsif string then
936 val = string.eval_const( @members_decl )
937 if val == nil then
938 type = string.get_type( @members_decl )
939 if ! type.kind_of?( IntType ) then
940 cdl_error( "T1027 string argument is not integer type" )
941 end
942 end
943 end
944 }
945
946 if @tag == nil then
947 @member_types_symbol = get_member_types_symbol
948 # print "member_types_symbol = #{get_member_types_symbol}\n"
949 if @@no_tag_struct_list[ @member_types_symbol ] then
950 @tag = @@no_tag_struct_list[ @member_types_symbol ]
951 else
952 @tag = :"TAG_#{@@no_struct_tag_num}_TECS_internal__"
953 @@no_struct_tag_num += 1
954 @@no_tag_struct_list[ @member_types_symbol ] = @tag
955 Namespace.new_structtype( self )
956 end
957 else
958 if @b_define then
959 Namespace.new_structtype( self )
960 end
961 end
962 end
963
964 def get_name
965 @tag
966 end
967
968 def get_type_str # mikan struct get_type_str
969 str = super
970
971 if @b_hasTag then
972 # typedef struct tag StructType; の形式の場合
973 # struct の本体は、別に生成される
974 return "#{str}struct #{@tag}"
975
976 else
977 # typedef struct { int a; } StructType; の形式の場合
978 str += "struct {"
979 @members_decl.get_items.each{ |i|
980 str += sprintf( "%s %s%s;", "#{i.get_type.get_type_str}", "#{i.get_name}", "#{i.get_type.get_type_str_post}" )
981 }
982 str += "} "
983
984 return str
985
986 end
987 end
988
989 def get_type_str_post
990 ""
991 end
992
993 def get_members_decl
994 return @members_decl if @members_decl
995
996 st = Namespace.find_tag( @tag )
997 if st then
998 return st.get_members_decl
999 end
1000
1001 return nil
1002 end
1003
1004 def has_pointer?
1005 if @definition
1006 return @definition.has_pointer?
1007 else
1008 return @b_has_pointer_member
1009 end
1010 end
1011
1012 def has_sized_pointer?
1013 if @definition
1014 return @definition.has_sized_pointer?
1015 else
1016 return @b_has_sized_pointer_member
1017 end
1018 end
1019
1020 def has_unsized_string?
1021 if @definition
1022 return @definition.has_unsized_string?
1023 else
1024 return @b_has_unsized_string_member
1025 end
1026 end
1027
1028 #=== 同じ構造体かどうかチェックする
1029 # tag のチェックは行わない
1030 # すべてのメンバの名前と型が一致することを確認する
1031 def same? another
1032 md = another.get_members_decl
1033 if @members_decl == nil || md == nil
1034 return false
1035 end
1036
1037 md1 = @members_decl.get_items
1038 md2 = md.get_items
1039 if( md1.length != md2.length )
1040 return false
1041 end
1042
1043 i = 0
1044 while i < md1.length
1045 if md1[i].get_name != md2[i].get_name ||
1046 md1[i].get_type.get_type_str != md2[i].get_type.get_type_str ||
1047 md1[i].get_type.get_type_str_post != md2[i].get_type.get_type_str_post
1048 return false
1049 end
1050 i += 1
1051 end
1052
1053 return true
1054 end
1055
1056 def get_member_types_symbol
1057 mts = ''
1058 @members_decl.get_items.each { |member|
1059 mts += member.get_type.get_type_str + member.get_type.get_type_str_post + ';'
1060 }
1061 return mts.to_sym
1062 end
1063
1064 def show_tree( indent )
1065 indent.times { print " " }
1066 puts "StructType tag: #{@tag} qualifier=#{@qualifier} has_pointer=#{@b_has_pointer_member} #{locale_str}"
1067 super( indent + 1 )
1068 if @b_define then
1069 @members_decl.show_tree( indent + 1 )
1070 end
1071 end
1072end
1073
1074class FuncType < Type
1075# @paramlist:: ParamList
1076# @type:: return type : PtrType, ArrayType, FuncType, IntType, FloatType, ...
1077# @b_oneway:: bool: true, false
1078# @has_in:: bool : has [in] parameter
1079# @has_inout:: bool : has [inout] parameter
1080# @has_out:: bool : has [out] parameter
1081# @has_send:: bool : has [send] parameter
1082# @has_receive:: bool : has [receive] parameter
1083
1084 def initialize( paramlist = nil )
1085 super()
1086
1087 @has_in = false
1088 @has_inout = false
1089 @has_out = false
1090 @has_send = false
1091 @has_receive = false
1092
1093 @paramlist = paramlist
1094 @b_oneway = false
1095 if paramlist then
1096 paramlist.check_param
1097 else
1098 @paramlist = ParamList.new( nil )
1099 end
1100 @paramlist.set_owner self # ParamList
1101 @paramlist.get_items.each{ |p|
1102 case p.get_direction
1103 when :IN
1104 @has_in = true
1105 when :INOUT
1106 @has_inout = true
1107 when :OUT
1108 @has_out = true
1109 when :SEND
1110 @has_send = true
1111 when :RECEIVE
1112 @has_receive = true
1113 else
1114 raise "unkown direction"
1115 end
1116 }
1117
1118 end
1119
1120 def check # 意味的誤りがあれば、文字列を返す
1121 if @type.class == ArrayType then # é…
1122åˆ—を返す関数
1123 return "function returning array"
1124 elsif @type.class == FuncType then # 関数を返す関数
1125 return "function returning function"
1126 end
1127 return @type.check # 関数の return する型のチェック
1128
1129 # パラメータの型のチェックは ParamList#check_param で行う
1130 end
1131
1132 def check_struct_tag kind
1133 @type.check_struct_tag kind
1134 # ParamDecl でもチェックされるので、ここではチェックしない
1135 # @paramlist.check_struct_tag kind
1136 end
1137
1138 def check_init( locale, ident, initializer, kind, attribute = nil )
1139 cdl_error2( locale, "T1028 $1: cannot initialize function pointer" , ident )
1140 return
1141 end
1142
1143 def set_type( type )
1144 unless @type then
1145 @type = type
1146 else
1147 @type.set_type( type )
1148 end
1149 end
1150
1151 #=== return type を返す
1152 #
1153 # return type を返す
1154 # get_return_type とすべきだった
1155 def get_type
1156 @type
1157 end
1158
1159 def get_type_str
1160 return @type.get_type_str
1161 end
1162
1163 def get_type_str_post
1164 # 型だけを返す (仮引数の名前を含めない)
1165 @paramlist.to_str( false )
1166 end
1167
1168 def get_paramlist
1169 @paramlist
1170 end
1171
1172 def set_oneway( b_oneway )
1173 @b_oneway = b_oneway
1174
1175 if ( ( @type.get_type_str != "ER" && @type.get_type_str != "void" ) || @type.get_type_str_post != "" ) then
1176 cdl_error( "T1029 oneway function cannot return type \'$1$2\', \'void\' or \'ER\' is permitted" , @type.get_type_str, @type.get_type_str_post )
1177 end
1178
1179 if @paramlist then
1180 @paramlist.get_items.each{ |p|
1181 if p.get_direction != :IN && p.get_direction != :SEND then
1182 cdl_error( "T1030 oneway function cannot have $1 parameter for \'$2\'" , p.get_direction, p.get_name )
1183 end
1184 }
1185 end
1186 end
1187
1188 def is_oneway?
1189 @b_oneway
1190 end
1191
1192 #=== Push Pop Allocator が必
1193要か?
1194 # Transparent RPC の場合 oneway かつ in のé…
1195åˆ—(size_is, count_is, string のいずれかで修飾)がある
1196 def need_PPAllocator?( b_opaque = false )
1197 if @b_oneway || b_opaque then
1198 return @paramlist.need_PPAllocator?( b_opaque )
1199 else
1200 return false
1201 end
1202 end
1203
1204 #=== パラメータが in, inout, out, send, receive を持つか
1205 def has_in?
1206 @has_in
1207 end
1208 def has_inout?
1209 @has_inout
1210 end
1211 def has_out?
1212 @has_out
1213 end
1214 def has_send?
1215 @has_send
1216 end
1217 def has_receive?
1218 @has_receive
1219 end
1220
1221 #=== å…
1222¥åŠ›æ–¹å‘のパラメータを持つか
1223 def has_inward?
1224 @has_in || @has_inout || @has_send
1225 end
1226 #=== 出力方向のパラメータを持つか
1227 def has_outward?
1228 @has_inout || @has_out || @has_receive
1229 end
1230
1231 def show_tree( indent )
1232 indent.times { print " " }
1233 if @b_oneway then
1234 puts "FunctType: oneway=true #{locale_str}"
1235 else
1236 puts "FunctType: oneway=false #{locale_str}"
1237 end
1238 super( indent + 1 )
1239 if @paramlist then
1240 @paramlist.show_tree( indent + 1 )
1241 end
1242 (indent+1).times { print " " }
1243 puts "return type:"
1244 @type.show_tree( indent + 2 )
1245 end
1246end
1247
1248class ArrayType < Type
1249# @type:: element type : ArrayType, FuncType, IntType, FloatType, ...
1250# @subscript:: Expression, nil if '[]'
1251
1252 include HasType
1253
1254 def initialize( subscript = nil )
1255 super()
1256 @subscript = subscript
1257 initHasType
1258 end
1259
1260 def set_type( type )
1261 unless @type then
1262 @type = type
1263 else
1264 @type.set_type( type )
1265 end
1266 end
1267
1268 #=== Array#qualifier(const, volatile) の設定
1269 def set_qualifier( qualifier )
1270 clone_type
1271 @type.set_qualifier( qualifier )
1272 super
1273 end
1274
1275 # é…
1276åˆ—要素が const なら const
1277 def is_const?
1278 @type.is_const?
1279 end
1280
1281 # é…
1282åˆ—要素が volatile なら volatile
1283 def is_volatile?
1284 @type.is_volatile?
1285 end
1286
1287 def get_type
1288 @type
1289 end
1290
1291 def get_subscript
1292 @subscript
1293 end
1294
1295 def get_type_str
1296 return "#{@type.get_type_str}"
1297 end
1298
1299 def get_type_str_post
1300 if @subscript
1301 "[#{@subscript.eval_const(nil)}]#{@type.get_type_str_post}"
1302 else
1303 "[]#{@type.get_type_str_post}"
1304 end
1305 # "[#{@subscript.to_s}]#{@type.get_type_str_post}"
1306 end
1307
1308 def check # 意味的誤りがあれば、文字列を返す
1309 if @type.class == FuncType then # 関数のé…
1310åˆ—
1311 return "array of function"
1312 elsif @type.class == ArrayType then # 添数なしé…
1313åˆ—のé…
1314åˆ—
1315 unless @type.get_subscript then
1316 return "subscript not specified"
1317 end
1318 end
1319
1320 return @type.check # é…
1321åˆ—要素の型をチェック
1322 end
1323
1324 def check_struct_tag kind
1325 @type.check_struct_tag kind
1326 end
1327
1328 def check_init( locale, ident, initializer, kind, attribute = nil )
1329 if ( initializer.instance_of?( Array ) ) then
1330 # 要素数が指定されている場合、初期化要素数をチェック
1331 if @subscript then
1332 n_sub = @subscript.eval_const( nil )
1333 if n_sub then
1334 if initializer.length > n_sub then
1335 cdl_error2( locale, "T9999 $1: too many initializer, $2 for $3" , ident, initializer.length, n_sub )
1336 end
1337 end
1338 end
1339 index = 0
1340 initializer.each{ |i|
1341 @type.check_init( locale, "#{ident}[#{index}]", i, kind, attribute = nil )
1342 index += 1
1343 }
1344 else
1345 cdl_error2( locale, "T1031 $1: unsuitable initializer for array" , ident )
1346 end
1347 end
1348
1349 def has_pointer?
1350 @type.has_pointer?
1351 end
1352
1353 def has_sized_pointer?
1354 @type.has_sized_pointer?
1355 end
1356
1357 def has_unsized_string?
1358 @type.has_unsized_string?
1359 end
1360
1361 def show_tree( indent )
1362 indent.times { print " " }
1363 puts "ArrayType: #{locale_str}"
1364 super( indent + 1 )
1365 (indent+1).times { print " " }
1366 puts "type:"
1367 @type.show_tree( indent + 2 )
1368 (indent+1).times { print " " }
1369 puts "subscript:"
1370 if @subscript then
1371 @subscript.show_tree( indent + 2 )
1372 else
1373 (indent+2).times { print " " }
1374 puts "no subscript"
1375 end
1376 end
1377end
1378
1379class PtrType < Type
1380# @type:: refer to : PtrType, FuncType, ArrayType, IntType, FloatType, ...
1381# @size:: Expr, or nil if not specified
1382# @count:: Expr, or nil if not specified
1383# @string:: Expr or -1(if size not specified) (string 引数), or nil if not specified
1384
1385 include HasType
1386
1387 def initialize( referto = nil )
1388 super()
1389 @type = referto
1390 @size = nil
1391 @count = nil
1392 @string = nil
1393 initHasType
1394 end
1395
1396 def set_type( type )
1397 unless @type then
1398 @type = type
1399 else
1400 @type.set_type( type ) # 枝å…
1401ˆã® type を設定
1402 end
1403 end
1404
1405 def get_type_str
1406 if @type.kind_of?( ArrayType ) || @type.kind_of?( FuncType ) then
1407 parenthes = "("
1408 else
1409 parenthes = ""
1410 end
1411 return "#{@type.get_type_str}#{parenthes}*"
1412 end
1413
1414 def get_type_str_post
1415 if @type.kind_of?( ArrayType ) || @type.kind_of?( FuncType ) then
1416 parenthes = ")"
1417 else
1418 parenthes = ""
1419 end
1420 "#{parenthes}#{@type.get_type_str_post}"
1421 end
1422
1423 def check # 意味的誤りがあれば、文字列を返す
1424 return nil if @type == nil
1425 @type.check
1426 end
1427
1428 def check_struct_tag kind
1429 if kind != :MEMBER # 構造体メンバーの場合、ポインタのå…
1430ˆã®æ§‹é€ ä½“タグをチェックしない
1431 @type.check_struct_tag kind
1432 end
1433 end
1434
1435 def check_init( locale, ident, initializer, kind, attribute = nil )
1436 if ( initializer.instance_of?( Expression ) ) then
1437 val = initializer.eval_const2( nil, attribute )
1438 if val.kind_of? PointerVal then
1439 type = val.get_type # PtrType
1440 t1 = self
1441 t2 = type
1442 while( t1.kind_of?( PtrType ) && t2.kind_of?( PtrType ) )
1443 t1 = t1.get_type
1444 t2 = t2.get_type
1445 if ( t1.class == t2.class ) && ( t1.get_bit_size == t2.get_bit_size ) then
1446 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
1447 # int8_t などが、一方は .h に定義されているケース
1448 else
1449 cdl_error2( locale, "T1032 $1: incompatible pointer type" , ident )
1450 break
1451 end
1452 end
1453 elsif val.kind_of? IntegerVal then
1454 if val.to_i != 0 then
1455 cdl_error2( locale, "T1033 $1: need cast to assign integer to pointer" , ident )
1456 end
1457 elsif val.kind_of? StringVal then
1458 # 文字列定数
1459 # mikan L"wide string"
1460 if @type.get_bit_size != -1 && @type.get_bit_size != -11 then # -1: char_t
1461 cdl_error2( locale, "T1034 $1: unsuitable string constant" , ident )
1462 end
1463 elsif ( val.instance_of?( Array ) ) then
1464 i = 0
1465 val.each { |ini|
1466 @type.check_init( locale, "#{ident}[#{i}]", ini, kind, attribute = nil )
1467 i += 1
1468 }
1469 elsif val.instance_of?( C_EXP ) then
1470
1471 else
1472 cdl_error2( locale, "T1035 $1: unsuitable initializer for pointer" , ident )
1473 end
1474 elsif ( initializer.instance_of?( Array ) ) then
1475 if @size == nil && @count == nil then
1476 cdl_error2( locale, "T9999 $1: non-size_is pointer cannot have array initializer", ident )
1477 end
1478
1479 i = 0
1480 initializer.each { |ini|
1481 @type.check_init( locale, "#{ident}[#{i}]", ini, kind, attribute = nil )
1482 i += 1
1483 }
1484 elsif( initializer.instance_of?( C_EXP ) ) then
1485
1486 else
1487 cdl_error2( locale, "T1036 $1: unsuitable initializer for pointer" , ident )
1488 end
1489 end
1490
1491 def get_referto
1492 clone_type
1493 @type
1494 end
1495
1496 def set_scs( size, count, string, max, b_nullable )
1497 @size = size
1498 @count = count
1499 @max = max
1500 @b_nullable = b_nullable
1501
1502 # string は最も左側の ptr に作用する
1503 if @type.kind_of?( PtrType ) then
1504 # ptr_level が 2 以上であることは ParamDecl#initializer でチェックされる
1505 clone_type
1506 @type.set_scs( nil, nil, string, nil, false )
1507 elsif @type.kind_of?( VoidType ) && ( size || count || string ) then
1508 str = ""
1509 if size then
1510 str = "size_is"
1511 end
1512 if count then
1513 if str then
1514 str += ", "
1515 end
1516 str += "count_is"
1517 end
1518 if string then
1519 if str then
1520 str += ", "
1521 end
1522 str += "string"
1523 end
1524
1525 cdl_error( "T1040 $1 specified for void pointer type", str )
1526 else
1527 @string = string
1528 end
1529
1530 if (@size != nil) && (@b_nullable != false) then
1531 cdl_error( "T9999 size_is & nullable cannot be specified simultaneously. If size is zero, pointer must be null")
1532 end
1533 end
1534
1535 def clear_max
1536 @max = nil
1537 end
1538
1539 def get_size
1540 @size
1541 end
1542
1543 def get_count
1544 @count
1545 end
1546
1547 def get_string
1548 @string
1549 end
1550
1551 #=== PtrType# size_is の最大値
1552 def get_max
1553 @max
1554 end
1555
1556 def is_nullable?
1557 return @b_nullable
1558 end
1559
1560 def get_type
1561 clone_type
1562 @type
1563 end
1564
1565 def has_pointer?
1566 true
1567 end
1568
1569 def has_sized_pointer?
1570 @size != nil || @count != nil || @string.instance_of?( Expression ) || @type.has_sized_pointer?
1571 end
1572
1573 def has_unsized_string?
1574 @string == -1 || @type.has_unsized_string?
1575 end
1576
1577 def show_tree( indent )
1578 indent.times { print " " }
1579 puts "PtrType: qualifier=#{@qualifier}, nullable=#{@b_nullable} #{locale_str}"
1580 super( indent + 1 )
1581 (indent+1).times { print " " }
1582 if @size then
1583 print "size=#{@size.to_s}, "
1584 else
1585 print "size=nil, "
1586 end
1587 if @max then
1588 print "max=#{@size.to_s}, "
1589 else
1590 print "max=nil, "
1591 end
1592 if @count then
1593 print "count=#{@count.to_s}, "
1594 else
1595 print "count=nil, "
1596 end
1597 if @string then
1598 if @string.instance_of?( Expression ) then
1599 print "string=#{@string.to_s}\n"
1600 else
1601 print "string=yes\n"
1602 end
1603 else
1604 print "string=nil\n"
1605 end
1606
1607 (indent+1).times { print " " }
1608 puts "type:"
1609 @type.show_tree( indent + 2 )
1610 end
1611
1612end
1613
1614#== DescriptorType クラス
1615# 動的結合で渡すデスクリプタ型
1616class DescriptorType < Type
1617 # @sinagure_nsp::NamespacePath
1618
1619 @@descriptors = {}
1620
1621 def initialize( signature_nsp )
1622 @signature_nsp = signature_nsp
1623 # check_signature ##
1624 @@descriptors[ self ] = false
1625 end
1626
1627 def get_type_str
1628 "Descriptor( #{@signature_nsp.get_global_name} )"
1629 end
1630
1631 def get_type_str_post
1632 ""
1633 end
1634
1635 def set_qualifier( qualifier )
1636 cdl_error( "T9999 '$1' cannot be specified for Descriptor", qualfier.to_s )
1637 end
1638
1639 def check
1640 end
1641
1642 def check_init( locale, ident, initializer, kind, attribute = nil )
1643 case kind
1644 when :PARAMETER
1645 # 引数は初期化できない
1646 else
1647 cdl_error2( locale, "T9999 Descriptor cannot be used for $1", kind)
1648 end
1649 end
1650
1651 def self.check_signature
1652 @@descriptors.each{ |desc, val|
1653 if val != true then
1654 desc.check_signature
1655 @@descriptors[ desc ] = true
1656 end
1657 }
1658 end
1659
1660 def check_signature
1661 # p "Desc #{@signature_nsp.to_s}"
1662 obj = Namespace.find @signature_nsp
1663 if ! obj.kind_of? Signature then
1664 cdl_error( "T9999 '$1': not signature or not found", @signature_nsp.to_s )
1665 else
1666 if obj.has_descriptor? then
1667 # cdl_error( "T9999 '$1': has Descriptor in function parameter", @signature_nsp.to_s )
1668 end
1669 # @signature_nsp = obj.get_namespace_path
1670 end
1671 end
1672
1673 #== DescriptorType#
1674 def get_signature
1675 Namespace.find @signature_nsp
1676 end
1677end
1678
1679# 以下単体テストコード
1680if $unit_test then
1681 puts( "===== Unit Test: IntType ===== (types.rb)")
1682 sizes = [ 8, 16, 32, 64 ]
1683 sizes.each{ |n|
1684 int = IntType.new n
1685 printf( "%8s max: %d min:%d\n", "int#{n}_t", int.get_max, int.get_min )
1686 }
1687 puts ""
1688end
Note: See TracBrowser for help on using the repository browser.