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 | #
|
---|
68 | module 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
|
---|
80 | end
|
---|
81 |
|
---|
82 | class 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
|
---|
270 | end
|
---|
271 |
|
---|
272 | class 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
|
---|
381 | end
|
---|
382 |
|
---|
383 | class 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
|
---|
406 | end
|
---|
407 |
|
---|
408 | class 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
|
---|
427 | end
|
---|
428 |
|
---|
429 | class 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
|
---|
668 | end
|
---|
669 |
|
---|
670 | class 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
|
---|
744 | end
|
---|
745 |
|
---|
746 | class 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
|
---|
767 | end
|
---|
768 |
|
---|
769 | class 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
|
---|
1064 | end
|
---|
1065 |
|
---|
1066 | class 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
|
---|
1238 | end
|
---|
1239 |
|
---|
1240 | class 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
|
---|
1360 | end
|
---|
1361 |
|
---|
1362 | class 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 |
|
---|
1595 | end
|
---|
1596 |
|
---|
1597 | #== DescriptorType ã¯ã©ã¹
|
---|
1598 | # åççµåã§æ¸¡ããã¹ã¯ãªãã¿å
|
---|
1599 | class 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
|
---|
1643 | end
|
---|
1644 |
|
---|
1645 | # 以ä¸åä½ãã¹ãã³ã¼ã
|
---|
1646 | if $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 ""
|
---|
1654 | end
|
---|