1 | # -*- coding: utf-8 -*-
|
---|
2 | #
|
---|
3 | # TECS Generator
|
---|
4 | # Generator for TOPPERS Embedded Component System
|
---|
5 | #
|
---|
6 | # Copyright (C) 2008-2018 by TOPPERS Project
|
---|
7 | #--
|
---|
8 | # 上記著作権者は,以下の(1)~(4)の条件を満たす場合に限り,本ソフトウェ
|
---|
9 | # ア(本ソフトウェアを改変したものを含む.以下同じ)を使用・複製・改
|
---|
10 | # 変・再配布(以下,利用と呼ぶ)することを無償で許諾する.
|
---|
11 | # (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
|
---|
12 | # 権表示,この利用条件および下記の無保証規定が,そのままの形でソー
|
---|
13 | # スコード中に含まれていること.
|
---|
14 | # (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
|
---|
15 | # 用できる形で再配布する場合には,再配布に伴うドキュメント(利用
|
---|
16 | # 者マニュアルなど)に,上記の著作権表示,この利用条件および下記
|
---|
17 | # の無保証規定を掲載すること.
|
---|
18 | # (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
|
---|
19 | # 用できない形で再配布する場合には,次のいずれかの条件を満たすこ
|
---|
20 | # と.
|
---|
21 | # (a) 再配布に伴うドキュメント(利用者マニュアルなど)に,上記の著
|
---|
22 | # 作権表示,この利用条件および下記の無保証規定を掲載すること.
|
---|
23 | # (b) 再配布の形態を,別に定める方法によって,TOPPERSプロジェクトに
|
---|
24 | # 報告すること.
|
---|
25 | # (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
|
---|
26 | # 害からも,上記著作権者およびTOPPERSプロジェクトを免責すること.
|
---|
27 | # また,本ソフトウェアのユーザまたはエンドユーザからのいかなる理
|
---|
28 | # 由に基づく請求からも,上記著作権者およびTOPPERSプロジェクトを
|
---|
29 | # 免責すること.
|
---|
30 | #
|
---|
31 | # 本ソフトウェアは,無保証で提供されているものである.上記著作権者お
|
---|
32 | # よびTOPPERSプロジェクトは,本ソフトウェアに関して,特定の使用目的
|
---|
33 | # に対する適合性も含めて,いかなる保証も行わない.また,本ソフトウェ
|
---|
34 | # アの利用により直接的または間接的に生じたいかなる損害に関しても,そ
|
---|
35 | # の責任を負わない.
|
---|
36 | #
|
---|
37 | # $Id$
|
---|
38 | #++
|
---|
39 |
|
---|
40 | class Generator
|
---|
41 | rule
|
---|
42 | # トップレベルの構文要素はcomponent_description
|
---|
43 | all: component_description
|
---|
44 |
|
---|
45 | # Expr
|
---|
46 | ########################## 式 ##########################
|
---|
47 | # K&Rの文法(プログラミング言語C 第2版 付録)と一部異なる
|
---|
48 | # argument_expression_list(関数引数), assignment_expression(代入)がない
|
---|
49 | # 式の result は、すべて配列で第一要素が識別シンボル、第二要素以下が引数
|
---|
50 |
|
---|
51 | primary_expression
|
---|
52 | : namespace_identifier
|
---|
53 | { result = [ :IDENTIFIER, val[0] ] } #1ok
|
---|
54 | | TRUE
|
---|
55 | { result = [ :BOOL_CONSTANT, true ] }
|
---|
56 | | FALSE
|
---|
57 | { result = [ :BOOL_CONSTANT, false ] }
|
---|
58 | | INTEGER_CONSTANT
|
---|
59 | { result = [ :INTEGER_CONSTANT, val[0] ] }
|
---|
60 | | FLOATING_CONSTANT
|
---|
61 | { result = [ :FLOATING_CONSTANT, val[0] ] }
|
---|
62 | | OCTAL_CONSTANT
|
---|
63 | { result = [ :OCTAL_CONSTANT, val[0] ] }
|
---|
64 | | HEX_CONSTANT
|
---|
65 | { result = [ :HEX_CONSTANT, val[0] ] }
|
---|
66 | | CHARACTER_LITERAL
|
---|
67 | { result = [ :CHARACTER_LITERAL, val[0] ] }
|
---|
68 | | string_literal_list
|
---|
69 | { result = [ :STRING_LITERAL_LIST, val[0] ] }
|
---|
70 | | '(' expression ')'
|
---|
71 | { result = [ :PARENTHESES, val[1].get_elements ] }
|
---|
72 |
|
---|
73 | string_literal_list
|
---|
74 | : STRING_LITERAL
|
---|
75 | | string_literal_list STRING_LITERAL
|
---|
76 | {
|
---|
77 | # 連接した文字列を1つの文字列にまとめる
|
---|
78 | str = "\"" + val[0].val.gsub( /\"(.*)\"/, "\\1" ) + val[1].val.gsub( /\"(.*)\"/, "\\1" ) + "\""
|
---|
79 | result = Token.new( str, val[0].file, val[0].lineno, val[0].col )
|
---|
80 | }
|
---|
81 |
|
---|
82 | # 関数呼び出しと後置インクリメント、デクリメント演算子がない
|
---|
83 | postfix_expression
|
---|
84 | : primary_expression
|
---|
85 | | postfix_expression '[' expression ']'
|
---|
86 | { result = [ :OP_SUBSC, val[0], val[2] ] }
|
---|
87 | | postfix_expression '.' IDENTIFIER
|
---|
88 | { result = [ :OP_DOT, val[0], val[2] ] }
|
---|
89 | | postfix_expression '->' IDENTIFIER
|
---|
90 | { result = [ :OP_REF, val[0], val[2] ] }
|
---|
91 |
|
---|
92 | # 前置インクリメント、デクリメント演算子がない
|
---|
93 | unary_expression
|
---|
94 | : postfix_expression
|
---|
95 | | unary_operator cast_expression
|
---|
96 | { result = [ val[0], val[1] ] }
|
---|
97 | | SIZEOF unary_expression
|
---|
98 | { result = [ :OP_SIZEOF_EXPR, val[1] ] }
|
---|
99 | | SIZEOF '(' type_name ')'
|
---|
100 | { result = [ :OP_SIZEOF_TYPE, val[1] ] }
|
---|
101 |
|
---|
102 | unary_operator
|
---|
103 | : '&' { result = :OP_U_AMP }
|
---|
104 | | '*' { result = :OP_U_ASTER }
|
---|
105 | | '+' { result = :OP_U_PLUS }
|
---|
106 | | '-' { result = :OP_U_MINUS }
|
---|
107 | | '~' { result = :OP_U_TILDE }
|
---|
108 | | '!' { result = :OP_U_EXCLAM }
|
---|
109 |
|
---|
110 | cast_expression
|
---|
111 | : unary_expression
|
---|
112 | | '(' type_name ')' cast_expression
|
---|
113 | { result = [ :CAST, val[1], val[3] ] }
|
---|
114 |
|
---|
115 | multiplicative_expression
|
---|
116 | : cast_expression
|
---|
117 | | multiplicative_expression '*' cast_expression
|
---|
118 | { result = [ :OP_MULT, val[0], val[2] ] }
|
---|
119 | | multiplicative_expression '/' cast_expression
|
---|
120 | { result = [ :OP_DIV, val[0], val[2] ] }
|
---|
121 | | multiplicative_expression '%' cast_expression
|
---|
122 | { result = [ :OP_REMAIN, val[0], val[2] ] }
|
---|
123 |
|
---|
124 | additive_expression
|
---|
125 | : multiplicative_expression
|
---|
126 | | additive_expression '+' multiplicative_expression
|
---|
127 | { result = [ :OP_ADD, val[0], val[2] ] }
|
---|
128 | | additive_expression '-' multiplicative_expression
|
---|
129 | { result = [ :OP_SUB, val[0], val[2] ] }
|
---|
130 |
|
---|
131 | shift_expression
|
---|
132 | : additive_expression
|
---|
133 | | shift_expression '<<' additive_expression
|
---|
134 | { result = [ :OP_LSFT, val[0], val[2] ] }
|
---|
135 | | shift_expression '>>' additive_expression
|
---|
136 | { result = [ :OP_RSFT, val[0], val[2] ] }
|
---|
137 |
|
---|
138 | relational_expression
|
---|
139 | : shift_expression
|
---|
140 | | relational_expression '<' shift_expression
|
---|
141 | { result = [ :OP_LT, val[0], val[2] ] }
|
---|
142 | | relational_expression '>' shift_expression
|
---|
143 | { result = [ :OP_GT, val[0], val[2] ] }
|
---|
144 | | relational_expression '<=' shift_expression
|
---|
145 | { result = [ :OP_LE, val[0], val[2] ] }
|
---|
146 | | relational_expression '>=' shift_expression
|
---|
147 | { result = [ :OP_GE, val[0], val[2] ] }
|
---|
148 |
|
---|
149 | equality_expression
|
---|
150 | : relational_expression
|
---|
151 | | equality_expression '==' relational_expression
|
---|
152 | { result = [ :OP_EQ, val[0], val[2] ] }
|
---|
153 | | equality_expression '!=' relational_expression
|
---|
154 | { result = [ :OP_NE, val[0], val[2] ] }
|
---|
155 |
|
---|
156 | and_expression
|
---|
157 | : equality_expression
|
---|
158 | | and_expression '&' equality_expression
|
---|
159 | { result = [ :OP_AND, val[0], val[2] ] }
|
---|
160 |
|
---|
161 | exclusive_or_expression
|
---|
162 | : and_expression
|
---|
163 | | exclusive_or_expression '^' and_expression
|
---|
164 | { result = [ :OP_EOR, val[0], val[2] ] }
|
---|
165 |
|
---|
166 | inclusive_or_expression
|
---|
167 | : exclusive_or_expression
|
---|
168 | | inclusive_or_expression '|' exclusive_or_expression
|
---|
169 | { result = [ :OP_OR, val[0], val[2] ] }
|
---|
170 |
|
---|
171 | logical_and_expression
|
---|
172 | : inclusive_or_expression
|
---|
173 | | logical_and_expression '&&' inclusive_or_expression
|
---|
174 | { result = [ :OP_LAND, val[0], val[2] ] }
|
---|
175 |
|
---|
176 | logical_or_expression
|
---|
177 | : logical_and_expression
|
---|
178 | | logical_or_expression '||' logical_and_expression
|
---|
179 | { result = [ :OP_LOR, val[0], val[2] ] }
|
---|
180 |
|
---|
181 | conditional_expression
|
---|
182 | : logical_or_expression
|
---|
183 | | logical_or_expression '?' expression ':' conditional_expression
|
---|
184 | { result = [ :OP_CEX, val[0], val[2].get_elements, val[4] ] }
|
---|
185 |
|
---|
186 |
|
---|
187 | # コンマ演算子が使えない
|
---|
188 | expression
|
---|
189 | : conditional_expression
|
---|
190 | {
|
---|
191 | result = Expression.new( val[0] )
|
---|
192 | # result.print
|
---|
193 | }
|
---|
194 |
|
---|
195 | constant_expression
|
---|
196 | : conditional_expression
|
---|
197 | {
|
---|
198 | result = Expression.new( val[0] )
|
---|
199 | # result.print
|
---|
200 |
|
---|
201 | # res = result.eval_const( nil )
|
---|
202 | # if res then
|
---|
203 | # puts "val: #{res}"
|
---|
204 | # else
|
---|
205 | # puts "val: nil"
|
---|
206 | # end
|
---|
207 | }
|
---|
208 |
|
---|
209 |
|
---|
210 |
|
---|
211 | # Types
|
---|
212 | ########################## 宣言 ##########################
|
---|
213 | # 宣言もK&Rと一部異なる
|
---|
214 |
|
---|
215 | # declarationはセルの属性で使われる
|
---|
216 | # K&Rとの違い: storage classが指定できない、型が省略できない
|
---|
217 | declaration
|
---|
218 | : type_specifier_qualifier_list init_declarator_list ';'
|
---|
219 | {
|
---|
220 | val[1].each { |i| # i: Decl
|
---|
221 | i.set_type( val[0] )
|
---|
222 | }
|
---|
223 | result = val[1]
|
---|
224 | }
|
---|
225 |
|
---|
226 | # declaration_specifiersは関数のパラメータで使われるが、
|
---|
227 | # type_specifier_qualifier_listで十分かもしれない
|
---|
228 | # Oyama
|
---|
229 | # const, volatile は単独で型にならないので変形
|
---|
230 | # const と volatile が同居することはないので、繰返し指定できないようにした
|
---|
231 | # type_specifier も繰返し指定できる必要はない (singed など単独で型にはならない)
|
---|
232 | declaration_specifiers
|
---|
233 | : type_specifier
|
---|
234 | | type_qualifier type_specifier
|
---|
235 | {
|
---|
236 | val[1].set_qualifier( val[0] )
|
---|
237 | result = val[1]
|
---|
238 | }
|
---|
239 |
|
---|
240 | init_declarator_list
|
---|
241 | : init_declarator
|
---|
242 | { result = [val[0]] }
|
---|
243 | | init_declarator_list ',' init_declarator
|
---|
244 | { result << val[2] }
|
---|
245 |
|
---|
246 | init_declarator
|
---|
247 | : declarator
|
---|
248 | | declarator '=' initializer
|
---|
249 | { val[0].set_initializer( val[2] ) }
|
---|
250 |
|
---|
251 | # INT8から下はK&Rにない
|
---|
252 | # Oyama
|
---|
253 | # signed, unsigned は単独で型にならないので、構文要素として分離
|
---|
254 | type_specifier
|
---|
255 | : VOID { result = VoidType.new }
|
---|
256 | | FLOAT32_T { result = FloatType.new(32) }
|
---|
257 | | DOUBLE64_T { result = FloatType.new(64) }
|
---|
258 | | struct_specifier
|
---|
259 | | enum_specifier
|
---|
260 | | TYPE_NAME { result = DefinedType.new( val[0].val ) }
|
---|
261 | # | IDENTIFIER { result = DefinedType.new( val[0].val ) } # reduce/reduce conflict が起こってしまう
|
---|
262 | | sign_int_type
|
---|
263 | | char_type
|
---|
264 | | BOOL_T { result = BoolType.new }
|
---|
265 | # | BOOL {
|
---|
266 | # Generator.warning( "W5001 bool: obsolete type. use bool_t" )
|
---|
267 | # result = BoolType.new
|
---|
268 | # }
|
---|
269 | | FLOAT {
|
---|
270 | Generator.warning( "W5002 float: obsolete type. use float32_t" )
|
---|
271 | result = FloatType.new(32)
|
---|
272 | }
|
---|
273 | | DOUBLE {
|
---|
274 | Generator.warning( "W5003 double: obsolete type. use double64_t" )
|
---|
275 | result = FloatType.new(64)
|
---|
276 | }
|
---|
277 | | DESCRIPTOR '(' namespace_identifier ')' { # namespace_identifier: signature name
|
---|
278 | result = DescriptorType.new( val[2] )
|
---|
279 | }
|
---|
280 |
|
---|
281 | char_type
|
---|
282 | : CHAR_T { result = IntType.new( -1 ) }
|
---|
283 | | SCHAR_T
|
---|
284 | {
|
---|
285 | result = IntType.new( -1 )
|
---|
286 | result.set_sign( :SIGNED, true )
|
---|
287 | }
|
---|
288 | | UCHAR_T
|
---|
289 | {
|
---|
290 | result = IntType.new( -1 )
|
---|
291 | result.set_sign( :UNSIGNED, true )
|
---|
292 | }
|
---|
293 |
|
---|
294 | int_type
|
---|
295 | : CHAR {
|
---|
296 | # Generator.warning( "W5004 char: obsolete type. use char_t" )
|
---|
297 | result = IntType.new( -11 )
|
---|
298 | }
|
---|
299 | | SHORT { result = IntType.new( -2 ) }
|
---|
300 | | INT { result = IntType.new( -3 ) }
|
---|
301 | | LONG { result = IntType.new( -4 ) }
|
---|
302 | # | INTPTR { result = IntType.new( -5 ) }
|
---|
303 | # | INT8 {
|
---|
304 | # Generator.warning( "W5005 int8: obsolete. use int8_t" )
|
---|
305 | # result = IntType.new( 8 )
|
---|
306 | # }
|
---|
307 | # | INT16 {
|
---|
308 | # Generator.warning( "W5006 int16: obsolete. use int16_t" )
|
---|
309 | # result = IntType.new( 16 )
|
---|
310 | # }
|
---|
311 | # | INT32 {
|
---|
312 | # Generator.warning( "W5007 int32: obsolete. use int32_t" )
|
---|
313 | # result = IntType.new( 32 )
|
---|
314 | # }
|
---|
315 | # | INT64
|
---|
316 | # {
|
---|
317 | # Generator.warning( "W5008 int64: obsolete. use int64_t" )
|
---|
318 | # result = IntType.new( 64 )
|
---|
319 | # }
|
---|
320 | # | INT128
|
---|
321 | # {
|
---|
322 | # Generator.warning( "W5009 int64: obsolete. use int64_t" )
|
---|
323 | # result = IntType.new( 128 )
|
---|
324 | # }
|
---|
325 | | INT8_T { result = IntType.new( 8 ) }
|
---|
326 | | INT16_T { result = IntType.new( 16 ) }
|
---|
327 | | INT32_T { result = IntType.new( 32 ) }
|
---|
328 | | INT64_T { result = IntType.new( 64 ) }
|
---|
329 | | INT128_T { result = IntType.new( 128 ) }
|
---|
330 | | UINT8_T
|
---|
331 | {
|
---|
332 | result = IntType.new( 8 )
|
---|
333 | result.set_sign( :UNSIGNED, true )
|
---|
334 | }
|
---|
335 | | UINT16_T
|
---|
336 | {
|
---|
337 | result = IntType.new( 16 )
|
---|
338 | result.set_sign( :UNSIGNED, true )
|
---|
339 | }
|
---|
340 | | UINT32_T
|
---|
341 | {
|
---|
342 | result = IntType.new( 32 )
|
---|
343 | result.set_sign( :UNSIGNED, true )
|
---|
344 | }
|
---|
345 | | UINT64_T
|
---|
346 | {
|
---|
347 | result = IntType.new( 64 )
|
---|
348 | result.set_sign( :UNSIGNED, true )
|
---|
349 | }
|
---|
350 | | UINT128_T
|
---|
351 | {
|
---|
352 | result = IntType.new( 128 )
|
---|
353 | result.set_sign( :UNSIGNED, true )
|
---|
354 | }
|
---|
355 |
|
---|
356 | sign # TECS では signed, unsigned 単独では型にできない
|
---|
357 | : SIGNED { result = :SIGNED }
|
---|
358 | | UNSIGNED { result = :UNSIGNED }
|
---|
359 |
|
---|
360 | # result[0] :CHAR などのトークン、result[1] :CONST, :VOLATILE など
|
---|
361 | sign_int_type
|
---|
362 | : sign int_type
|
---|
363 | {
|
---|
364 | val[1].set_sign( val[0] )
|
---|
365 | result = val[1]
|
---|
366 | }
|
---|
367 | | int_type
|
---|
368 |
|
---|
369 | # K&Rのstruct_or_union_specifierに相当するが、unionは使えない
|
---|
370 | struct_specifier # mikan
|
---|
371 | : STRUCT struct_tag '{'
|
---|
372 | { StructType.set_define( true ) }
|
---|
373 | struct_declaration_list '}'
|
---|
374 | {
|
---|
375 | StructType.end_of_parse
|
---|
376 | result = val[1]
|
---|
377 | }
|
---|
378 | | STRUCT
|
---|
379 | {
|
---|
380 | # tag が無い場合、内部名を与える
|
---|
381 | result = StructType.new( :"TAG__#{@@no_struct_tag_num}__" )
|
---|
382 | @@no_struct_tag_num += 1
|
---|
383 | StructType.set_define( true )
|
---|
384 | }
|
---|
385 | '{' struct_declaration_list '}'
|
---|
386 | {
|
---|
387 | StructType.end_of_parse
|
---|
388 | result = val[1]
|
---|
389 | }
|
---|
390 | | STRUCT struct_tag # mikan struct_tag は namespace 対応が必要
|
---|
391 | {
|
---|
392 | StructType.set_define( false )
|
---|
393 | StructType.end_of_parse
|
---|
394 | result = val[1]
|
---|
395 | }
|
---|
396 |
|
---|
397 | struct_declaration_list
|
---|
398 | : struct_declaration
|
---|
399 | | struct_declaration_list struct_declaration
|
---|
400 |
|
---|
401 | struct_tag:
|
---|
402 | IDENTIFIER
|
---|
403 | { result = StructType.new( val[0].val ) }
|
---|
404 |
|
---|
405 | # ポインタ修飾子を追加
|
---|
406 | struct_declaration
|
---|
407 | : type_specifier_qualifier_list struct_declarator_list ';'
|
---|
408 | {
|
---|
409 | val[1].each { |i| # i: Decl
|
---|
410 | i.set_type( val[0] )
|
---|
411 | i.set_kind( :MEMBER )
|
---|
412 | i.check
|
---|
413 | StructType.new_member( i )
|
---|
414 | }
|
---|
415 | result = val[1]
|
---|
416 | }
|
---|
417 | | spec_L pointer_specifier_list spec_R type_specifier_qualifier_list struct_declarator_list ';'
|
---|
418 | {
|
---|
419 | val[4].each { |i| # i: Decl
|
---|
420 | i.set_type( val[3] )
|
---|
421 | i.set_kind( :MEMBER )
|
---|
422 | i.set_specifier_list val[1]
|
---|
423 | i.check
|
---|
424 | StructType.new_member( i )
|
---|
425 | }
|
---|
426 | result = val[4]
|
---|
427 | }
|
---|
428 |
|
---|
429 | pointer_specifier_list
|
---|
430 | : pointer_specifier { result = [ val[0] ] }
|
---|
431 | | pointer_specifier_list ',' pointer_specifier { result << val[2] }
|
---|
432 |
|
---|
433 | pointer_specifier
|
---|
434 | : STRING { result = [:STRING,-1] }
|
---|
435 | | STRING '(' expression ')' { result = [:STRING,val[2]] }
|
---|
436 | | SIZE_IS '(' expression ')' { result = [:SIZE_IS,val[2]] }
|
---|
437 | | COUNT_IS '(' expression ')' { result = [:COUNT_IS,val[2]] }
|
---|
438 |
|
---|
439 |
|
---|
440 | # K&Rのspecifier_qualifier_listと同じ
|
---|
441 | # 名前がまぎらわしかったのでtype_を付けた
|
---|
442 | type_specifier_qualifier_list
|
---|
443 | # Oyama type_specifier を繰り返して指定することはなくなった (sign_int_type としたため)
|
---|
444 | # : type_specifier type_specifier_qualifier_list
|
---|
445 | : type_specifier
|
---|
446 | | type_qualifier type_specifier_qualifier_list
|
---|
447 | {
|
---|
448 | val[1].set_qualifier( val[0] )
|
---|
449 | result = val[1]
|
---|
450 | }
|
---|
451 | # mikan Oyama type_qualifier だけでは型指定にならない : 構文エラーとするより、意味エラーとした方が親切
|
---|
452 | # | type_qualifier
|
---|
453 |
|
---|
454 |
|
---|
455 | struct_declarator_list
|
---|
456 | : struct_declarator
|
---|
457 | { result = [ val[0] ] }
|
---|
458 | | struct_declarator_list ',' struct_declarator
|
---|
459 | { result << val[2] }
|
---|
460 |
|
---|
461 | # ビットフィールドは使えない
|
---|
462 | struct_declarator
|
---|
463 | : declarator
|
---|
464 |
|
---|
465 | # enumの種類を追加
|
---|
466 | enum_specifier # mikan
|
---|
467 | : enum_type '{' enumerator_list '}'
|
---|
468 | | enum_type IDENTIFIER '{' enumerator_list '}'
|
---|
469 | | enum_type IDENTIFIER
|
---|
470 |
|
---|
471 | enum_type
|
---|
472 | : ENUM { result = EnumType.new( -1 ) }
|
---|
473 | | ENUM8 { result = EnumType.new( 8 ) }
|
---|
474 | | ENUM16 { result = EnumType.new( 16 ) }
|
---|
475 | | ENUM32 { result = EnumType.new( 32 ) }
|
---|
476 | | ENUM64 { result = EnumType.new( 64 ) }
|
---|
477 | | ENUM128 { result = EnumType.new( 128 ) }
|
---|
478 |
|
---|
479 | enumerator_list
|
---|
480 | : enumerator
|
---|
481 | | enumerator_list ',' enumerator
|
---|
482 |
|
---|
483 | enumerator
|
---|
484 | : IDENTIFIER
|
---|
485 | | IDENTIFIER '=' constant_expression
|
---|
486 |
|
---|
487 | type_qualifier
|
---|
488 | : CONST { result = :CONST }
|
---|
489 | | VOLATILE { result = :VOLATILE }
|
---|
490 |
|
---|
491 | declarator
|
---|
492 | : pointer direct_declarator
|
---|
493 | {
|
---|
494 | val[1].set_type( val[0] )
|
---|
495 | result = val[1]
|
---|
496 | }
|
---|
497 | | direct_declarator
|
---|
498 |
|
---|
499 | direct_declarator # mikan
|
---|
500 | : IDENTIFIER
|
---|
501 | { result = Decl.new( val[0].val ) }
|
---|
502 | | '(' declarator ')'
|
---|
503 | { result = val[1] }
|
---|
504 | | direct_declarator '[' constant_expression ']'
|
---|
505 | {
|
---|
506 | val[0].set_type( ArrayType.new( val[2] ) )
|
---|
507 | result = val[0]
|
---|
508 | }
|
---|
509 | | direct_declarator '[' ']'
|
---|
510 | {
|
---|
511 | val[0].set_type( ArrayType.new )
|
---|
512 | result = val[0]
|
---|
513 | }
|
---|
514 | | direct_declarator '(' parameter_type_list ')'
|
---|
515 | {
|
---|
516 | val[0].set_type( FuncType.new( val[2] ) )
|
---|
517 | result = val[0]
|
---|
518 | }
|
---|
519 | # | direct_declarator '(' identifier_list ')' # これは何のために必要? 060211
|
---|
520 | | direct_declarator '(' ')'
|
---|
521 | {
|
---|
522 | Generator.warning( "W5010 need 'void' for no parameter" )
|
---|
523 | val[0].set_type( FuncType.new )
|
---|
524 | result = val[0]
|
---|
525 | }
|
---|
526 |
|
---|
527 | pointer
|
---|
528 | : '*'
|
---|
529 | { result = PtrType.new }
|
---|
530 | | '*' type_qualifier
|
---|
531 | {
|
---|
532 | result = PtrType.new
|
---|
533 | result.set_qualifier( val[1] )
|
---|
534 | }
|
---|
535 | | '*' pointer
|
---|
536 | {
|
---|
537 | val[1].set_type(PtrType.new)
|
---|
538 | result = val[1]
|
---|
539 | }
|
---|
540 | | '*' type_qualifier pointer
|
---|
541 | {
|
---|
542 | ptrtype = PtrType.new
|
---|
543 | ptrtype.set_qualifier( val[1] )
|
---|
544 | val[2].set_type( ptrtype )
|
---|
545 | result = val[2]
|
---|
546 | }
|
---|
547 |
|
---|
548 |
|
---|
549 | parameter_type_list
|
---|
550 | : parameter_list
|
---|
551 | | parameter_list ',' '...'
|
---|
552 | # mikan 可変長パラメータ
|
---|
553 |
|
---|
554 | parameter_list
|
---|
555 | : parameter_declaration
|
---|
556 | { result = ParamList.new( val[0] ) }
|
---|
557 | | parameter_list ',' parameter_declaration
|
---|
558 | {
|
---|
559 | val[0].add_param( val[2] )
|
---|
560 | # result = val[0] 不要
|
---|
561 | }
|
---|
562 |
|
---|
563 |
|
---|
564 | # パラメータ修飾子を追加
|
---|
565 | parameter_declaration
|
---|
566 | # : spec_L parameter_specifier_list spec_R declaration_specifiers declarator
|
---|
567 | : parameter_specifier_list_bracket declaration_specifiers declarator
|
---|
568 | {
|
---|
569 | val[2].set_kind( :PARAMETER )
|
---|
570 | paramdecl = ParamDecl.new( val[2], val[1], val[0] )
|
---|
571 | val[2].check
|
---|
572 | result = paramdecl
|
---|
573 | }
|
---|
574 |
|
---|
575 | # 以下はエラーとする
|
---|
576 | | declaration_specifiers declarator # parameter_specifier なしは扱わない
|
---|
577 | {
|
---|
578 | Generator.error( "G1001 need specifier for \'$1\'" , val[1].get_name )
|
---|
579 | result = nil
|
---|
580 | }
|
---|
581 | | declaration_specifiers # 仮引数なしは、とりあえず扱わない 060210
|
---|
582 | {
|
---|
583 | unless val[0].instance_of?( VoidType ) then
|
---|
584 | Generator.error( "G1002 need parameter name" )
|
---|
585 | end
|
---|
586 | result = nil
|
---|
587 | }
|
---|
588 | # | '[' parameter_specifier_list ']' declaration_specifiers # 同 060210
|
---|
589 | | parameter_specifier_list_bracket declaration_specifiers # 同 060210
|
---|
590 | {
|
---|
591 | unless val[1].instance_of?( VoidType ) then
|
---|
592 | Generator.error( "G1003 need parameter name" )
|
---|
593 | end
|
---|
594 | result = nil
|
---|
595 | }
|
---|
596 |
|
---|
597 | parameter_specifier_list_bracket
|
---|
598 | : spec_L parameter_specifier_list spec_R { result = val[1] }
|
---|
599 | # : '[' parameter_specifier_list ']' { result = val[1] }
|
---|
600 |
|
---|
601 | parameter_specifier_list
|
---|
602 | : parameter_specifier { result = val[0] }
|
---|
603 | | parameter_specifier_list ',' parameter_specifier
|
---|
604 | { result = result + val[2] }
|
---|
605 |
|
---|
606 | parameter_specifier
|
---|
607 | : IN { result = [ [:IN] ] }
|
---|
608 | | OUT { result = [ [:OUT] ] }
|
---|
609 | | INOUT { result = [ [:INOUT] ] }
|
---|
610 | | SEND '(' namespace_identifier ')' { result = [ [:SEND, val[2]] ] } #1ok allocator
|
---|
611 | | RECEIVE '(' namespace_identifier ')' { result = [ [:RECEIVE,val[2]] ] } #1ok allocator
|
---|
612 | | STRING { result = [ [:STRING,nil] ] }
|
---|
613 | | STRING '(' expression ')' { result = [ [:STRING, val[2]] ] }
|
---|
614 | | SIZE_IS '(' expression ')' { result = [ [:SIZE_IS, val[2]] ] }
|
---|
615 | | SIZE_IS '(' expression ',' constant_expression ')'
|
---|
616 | {
|
---|
617 | result = [ [:SIZE_IS,val[2]], [:MAX_IS, val[4]] ]
|
---|
618 | }
|
---|
619 | | COUNT_IS '(' expression ')' { result = [ [:COUNT_IS,val[2]] ] }
|
---|
620 | | NULLABLE { result = [ [:NULLABLE] ] }
|
---|
621 |
|
---|
622 | type_name
|
---|
623 | : type_specifier_qualifier_list
|
---|
624 | | type_specifier_qualifier_list abstract_declarator
|
---|
625 | {
|
---|
626 | if val[1] then
|
---|
627 | val[1].set_type( val[0] )
|
---|
628 | result = val[1]
|
---|
629 | else
|
---|
630 | # エラー:仮で val[0] を返す
|
---|
631 | result = val[0]
|
---|
632 | end
|
---|
633 | }
|
---|
634 | # mikan abstract_declarator が pointer 以外ではうまく動かない、とりあえず '*' CAST のみ救った
|
---|
635 |
|
---|
636 | abstract_declarator # mikan
|
---|
637 | : pointer
|
---|
638 | | direct_abstract_declarator
|
---|
639 | | pointer direct_abstract_declarator
|
---|
640 |
|
---|
641 | direct_abstract_declarator
|
---|
642 | : '(' abstract_declarator ')'
|
---|
643 | { result = val[1] } # 関数ポインタ型を救う
|
---|
644 | | '[' ']'
|
---|
645 | {
|
---|
646 | Generator.error( "G1004 impossible array type" )
|
---|
647 | result = nil
|
---|
648 | }
|
---|
649 | | '[' constant_expression ']'
|
---|
650 | {
|
---|
651 | Generator.error( "G1005 impossible array type" )
|
---|
652 | result = nil
|
---|
653 | }
|
---|
654 | | direct_abstract_declarator '[' ']'
|
---|
655 | {
|
---|
656 | Generator.error( "G1006 impossible array type" )
|
---|
657 | result = nil
|
---|
658 | }
|
---|
659 | | direct_abstract_declarator '[' constant_expression ']'
|
---|
660 | {
|
---|
661 | Generator.error( "G1007 impossible array type" )
|
---|
662 | result = nil
|
---|
663 | }
|
---|
664 | | '(' ')'
|
---|
665 | {
|
---|
666 | Generator.error( "G1008 impossible function type" )
|
---|
667 | result = nil
|
---|
668 | }
|
---|
669 | | '(' parameter_type_list ')'
|
---|
670 | | direct_abstract_declarator '(' ')'
|
---|
671 | {
|
---|
672 | Generator.warning( "W5011 need 'void' for no parameter" )
|
---|
673 | val[0].set_type( FuncType.new )
|
---|
674 | result = val[0]
|
---|
675 | }
|
---|
676 | | direct_abstract_declarator '(' parameter_type_list ')'
|
---|
677 | {
|
---|
678 | val[0].set_type( FuncType.new( val[2] ) )
|
---|
679 | result = val[0]
|
---|
680 | }
|
---|
681 |
|
---|
682 | # assignment_expressionをconstant_expressionに変更
|
---|
683 | initializer # mikan
|
---|
684 | : constant_expression
|
---|
685 | { result = val[0] }
|
---|
686 | | '{' initializer_list '}'
|
---|
687 | { result = val[1] }
|
---|
688 | | '{' initializer_list ',' '}'
|
---|
689 | { result = val[1] }
|
---|
690 | # | C_EXP '(' STRING_LITERAL ')'
|
---|
691 | | C_EXP '(' string_literal_list ')'
|
---|
692 | { result = C_EXP.new( val[2] ) }
|
---|
693 |
|
---|
694 | initializer_list
|
---|
695 | : initializer
|
---|
696 | {
|
---|
697 | result = [ val[0] ]
|
---|
698 | }
|
---|
699 | | initializer_list ',' initializer
|
---|
700 | {
|
---|
701 | val[0] << val[2]
|
---|
702 | result = val[0]
|
---|
703 | }
|
---|
704 |
|
---|
705 |
|
---|
706 | ########################## ここからはCDL独自 ##########################
|
---|
707 |
|
---|
708 | #トップレベルの構文規則
|
---|
709 | #コンポーネント記述
|
---|
710 | component_description
|
---|
711 | : component_description specified_statement
|
---|
712 | | component_description location_information
|
---|
713 | | component_description tool_info
|
---|
714 | |
|
---|
715 |
|
---|
716 | specified_statement
|
---|
717 | : statement
|
---|
718 | | spec_L statement_specifier_list spec_R statement
|
---|
719 | {
|
---|
720 | obj = val[3]
|
---|
721 | if obj.kind_of?( Cell ) || obj.kind_of?( Signature ) || obj.kind_of?( Celltype ) || obj.kind_of?( CompositeCelltype )then
|
---|
722 | # cell, signature 以外は、指定子を置けない
|
---|
723 | else
|
---|
724 | Generator.get_statement_specifier # クリア
|
---|
725 | Generator.error( "G1009 unexpected specifier" )
|
---|
726 | end
|
---|
727 | }
|
---|
728 | # これと同じ記述が composite_celltype にもある
|
---|
729 |
|
---|
730 | statement
|
---|
731 | : typedef
|
---|
732 | | const_statement
|
---|
733 | | namespace
|
---|
734 | | signature
|
---|
735 | | celltype
|
---|
736 | | cell
|
---|
737 | | composite_celltype
|
---|
738 | | enum_specifier ';'
|
---|
739 | | struct_specifier ';'
|
---|
740 | | region
|
---|
741 | | import
|
---|
742 | | import_C
|
---|
743 | | generate_statement
|
---|
744 | | error # エラー回復ポイント
|
---|
745 |
|
---|
746 |
|
---|
747 | statement_specifier_list
|
---|
748 | : statement_specifier
|
---|
749 | { Generator.add_statement_specifier val[0] }
|
---|
750 | | statement_specifier_list ',' statement_specifier
|
---|
751 | { Generator.add_statement_specifier val[2] }
|
---|
752 |
|
---|
753 | statement_specifier
|
---|
754 | : ALLOCATOR '(' alloc_list ')' # cell
|
---|
755 | { result = [ :ALLOCATOR, val[2] ] }
|
---|
756 | | CALLBACK # signature
|
---|
757 | { result = [ :CALLBACK ] }
|
---|
758 | | CONTEXT '(' string_literal_list ')' # signature
|
---|
759 | { result = [ :CONTEXT, val[2].val ] }
|
---|
760 | | DEVIATE # signature
|
---|
761 | { result = [ :DEVIATE ] }
|
---|
762 | | ID '(' constant_expression ')' # cell
|
---|
763 | { result = [ :ID, val[2] ] }
|
---|
764 | | PROTOTYPE # cell
|
---|
765 | { result = [ :PROTOTYPE ] }
|
---|
766 | | RESTRICT '(' restrict_list ')' # cell
|
---|
767 | { result = [ :RESTRICT, val[2] ] }
|
---|
768 | | SINGLETON { result = [:SINGLETON] } # celltype, composite
|
---|
769 | | IDX_IS_ID { result = [:IDX_IS_ID] } # celltype, composite (composite: no-effective)
|
---|
770 | | ACTIVE { result = [:ACTIVE] } # celltype, composite
|
---|
771 | | GENERATE '(' plugin_name ',' plugin_arg ')' # celltype, cell
|
---|
772 | { result = [:GENERATE, val[2].val, val[4].val] }
|
---|
773 |
|
---|
774 | alloc_list
|
---|
775 | : alloc { result = [ val[0] ] }
|
---|
776 | | alloc_list ',' alloc { result << val[2] }
|
---|
777 |
|
---|
778 | alloc
|
---|
779 | : IDENTIFIER '.' IDENTIFIER '.' IDENTIFIER '=' initializer
|
---|
780 | { result = [ :NORMAL_ALLOC, val[0], nil, val[2], val[4], val[6] ] }
|
---|
781 | | IDENTIFIER '[' constant_expression ']' '.' IDENTIFIER '.' IDENTIFIER '=' initializer
|
---|
782 | { result = [ :NORMAL_ALLOC, val[0], val[2], val[5], val[7], val[9] ] }
|
---|
783 | # mikan 将来的な拡張 ('*' でまとめて指定可能とする)
|
---|
784 | # | IDENTIFIER '.' IDENTIFIER '.' '*' '=' initializer
|
---|
785 | # { result = [ val[0], val[ ], val[ ], val[ ] ] }
|
---|
786 | # | IDENTIFIER '.' '*' '.' '*' '=' initializer
|
---|
787 | # { result = [ val[0], val[ ], val[ ], val[ ] ] }
|
---|
788 |
|
---|
789 | restrict_list
|
---|
790 | : restrict
|
---|
791 | { result = [val[0]] }
|
---|
792 | | restrict_list ',' restrict
|
---|
793 | { result << val[2] }
|
---|
794 |
|
---|
795 | restrict
|
---|
796 | : port_name '=' '{' region_name_list '}'
|
---|
797 | { result = [ val[0].val, nil, val[3] ] }
|
---|
798 | | port_name '.' IDENTIFIER '=' '{' region_name_list '}'
|
---|
799 | { result = [ val[0].val, val[2].val, val[5] ] }
|
---|
800 |
|
---|
801 | region_name_list
|
---|
802 | : namespace_identifier
|
---|
803 | { result = [val[0]] }
|
---|
804 | | region_name_list ',' namespace_identifier
|
---|
805 | { result << val[2] }
|
---|
806 |
|
---|
807 | const_statement
|
---|
808 | : declaration # 定数定義
|
---|
809 | {
|
---|
810 | val[0].each { |decl|
|
---|
811 | decl.set_kind( :CONSTANT )
|
---|
812 | Namespace.new_const_decl( decl )
|
---|
813 | decl.check
|
---|
814 | }
|
---|
815 | }
|
---|
816 |
|
---|
817 | import_C
|
---|
818 | : IMPORT_C '(' STRING_LITERAL ')' ';'
|
---|
819 | {
|
---|
820 | @@import_C = true
|
---|
821 | Import_C.new( val[2] )
|
---|
822 | @@import_C = false
|
---|
823 | }
|
---|
824 | | IMPORT_C '(' STRING_LITERAL ',' STRING_LITERAL ')' ';'
|
---|
825 | {
|
---|
826 | @@import_C = true
|
---|
827 | Import_C.new( val[2], val[4] )
|
---|
828 | @@import_C = false
|
---|
829 | }
|
---|
830 |
|
---|
831 | import
|
---|
832 | : IMPORT '(' STRING_LITERAL ')' ';'
|
---|
833 | { Import.new( val[2] ) }
|
---|
834 | | IMPORT '(' AB_STRING_LITERAL ')' ';'
|
---|
835 | { Import.new( val[2], true ) }
|
---|
836 |
|
---|
837 | generate_statement
|
---|
838 | # : GENERATE '(' plugin_name ',' namespace_identifier ',' STRING_LITERAL ')' ';' #1ok signature plugin
|
---|
839 | : GENERATE '(' plugin_name ',' namespace_identifier ',' plugin_arg ')' ';' #1ok signature plugin
|
---|
840 | { Generate.new( val[2].val, val[4], val[6] ) }
|
---|
841 |
|
---|
842 | typedef
|
---|
843 | : TYPEDEF type_specifier_qualifier_list declarator_list ';'
|
---|
844 | {
|
---|
845 | val[2].each{ |i| # i:Decl
|
---|
846 | i.set_kind( :TYPEDEF )
|
---|
847 | }
|
---|
848 | Typedef.new_decl_list( val[1], val[2] )
|
---|
849 | val[2].each{ |i| # i:Decl
|
---|
850 | i.check
|
---|
851 | }
|
---|
852 | }
|
---|
853 | | TYPEDEF '[' typedef_specifier ']' type_specifier_qualifier_list declarator_list ';'
|
---|
854 | {
|
---|
855 | val[5].each{ |i| # i:Decl
|
---|
856 | i.set_kind( :TYPEDEF )
|
---|
857 | }
|
---|
858 | Typedef.new_decl_list( val[4], val[5] )
|
---|
859 | val[5].each{ |i| # i:Decl
|
---|
860 | i.check
|
---|
861 | }
|
---|
862 | }
|
---|
863 | # mikan typedef_specifier 未処置
|
---|
864 |
|
---|
865 |
|
---|
866 | typedef_specifier
|
---|
867 | : STRING
|
---|
868 | | STRING '(' expression ')'
|
---|
869 |
|
---|
870 | declarator_list
|
---|
871 | : declarator
|
---|
872 | { result = [ val[0] ] }
|
---|
873 | | declarator_list ',' declarator
|
---|
874 | { result << val[2] }
|
---|
875 |
|
---|
876 | namespace
|
---|
877 | : NAMESPACE namespace_name '{' statement_list '}' ';'
|
---|
878 | {val[1].end_of_parse}
|
---|
879 |
|
---|
880 | namespace_name
|
---|
881 | : IDENTIFIER
|
---|
882 | {result = Namespace.new(val[0].val)}
|
---|
883 | # namespace インスタンスに statement を記憶させるためここで生成
|
---|
884 |
|
---|
885 | statement_list
|
---|
886 | : specified_statement
|
---|
887 | | statement_list specified_statement
|
---|
888 |
|
---|
889 | namespace_identifier
|
---|
890 | : IDENTIFIER { result = NamespacePath.new( val[0].val, false ) }
|
---|
891 | | '::' IDENTIFIER { result = NamespacePath.new( val[1].val, true ) }
|
---|
892 | | namespace_identifier '::' IDENTIFIER
|
---|
893 | { result = val[0].append!( val[2].val ) }
|
---|
894 |
|
---|
895 | #シグニチャ
|
---|
896 | signature
|
---|
897 | : SIGNATURE signature_name '{' function_head_list '}' ';'
|
---|
898 | { result = val[1].end_of_parse( val[3] ) }
|
---|
899 |
|
---|
900 | signature_name
|
---|
901 | : IDENTIFIER
|
---|
902 | {result = Signature.new( val[0].val ) }
|
---|
903 |
|
---|
904 | function_head_list # result: function_head の配列
|
---|
905 | # : function_head
|
---|
906 | # { result = NamedList.new( val[0], "function" ) }
|
---|
907 | :
|
---|
908 | { result = NamedList.new( nil, "function" ) }
|
---|
909 | | function_head_list function_head
|
---|
910 | { result = val[0].add_item( val[1] ) }
|
---|
911 |
|
---|
912 | function_head
|
---|
913 | : type_specifier_qualifier_list declarator ';'
|
---|
914 | {
|
---|
915 | # val[1]: Decl
|
---|
916 | if val[1].is_function? then
|
---|
917 | result = FuncHead.new( val[1], val[0], false )
|
---|
918 | val[1].set_kind :FUNCHEAD
|
---|
919 | val[1].check
|
---|
920 | else
|
---|
921 | # mikan 関数の配列も以下のメッセージになる
|
---|
922 | Generator.error( "G1010 Not function" )
|
---|
923 | result = nil
|
---|
924 | end
|
---|
925 | }
|
---|
926 | | spec_L ONEWAY spec_R type_specifier_qualifier_list declarator ';'
|
---|
927 | {
|
---|
928 | if val[4].is_function? then
|
---|
929 | result = FuncHead.new( val[4], val[3], true )
|
---|
930 | else
|
---|
931 | Generator.error( "G1011 Not function" )
|
---|
932 | result = nil
|
---|
933 | end
|
---|
934 | }
|
---|
935 |
|
---|
936 |
|
---|
937 | #セルタイプ
|
---|
938 | celltype
|
---|
939 | : CELLTYPE celltype_name '{' celltype_statement_list '}' ';'
|
---|
940 | {
|
---|
941 | val[1].end_of_parse
|
---|
942 | result = val[1]
|
---|
943 | }
|
---|
944 |
|
---|
945 | celltype_name
|
---|
946 | : IDENTIFIER
|
---|
947 | { result = Celltype.new(val[0].val) }
|
---|
948 |
|
---|
949 | celltype_statement_list
|
---|
950 | : specified_celltype_statement
|
---|
951 | | celltype_statement_list specified_celltype_statement
|
---|
952 |
|
---|
953 | specified_celltype_statement
|
---|
954 | : celltype_statement
|
---|
955 | {
|
---|
956 | if val[0].kind_of? Port then
|
---|
957 | Celltype.new_port( val[0] )
|
---|
958 | end
|
---|
959 | }
|
---|
960 | | spec_L celltype_statement_specifier_list spec_R celltype_statement
|
---|
961 | {
|
---|
962 | if val[3].kind_of? Port then
|
---|
963 | val[3].set_specifier val[1] # 設定順序あり
|
---|
964 | Celltype.new_port( val[3] )
|
---|
965 | else
|
---|
966 | # Port 以外では指定子はエラー
|
---|
967 | Generator.error( "G1012 $1 : cannot put specifier here" , val[1] )
|
---|
968 | end
|
---|
969 | }
|
---|
970 |
|
---|
971 | celltype_statement
|
---|
972 | : port
|
---|
973 | | attribute
|
---|
974 | | var
|
---|
975 | | require
|
---|
976 | | factory
|
---|
977 | # | error # エラー回復ポイント (#513 無限ループに陥るケースがあるので、ここでのエラー回復は取りやめ)
|
---|
978 |
|
---|
979 | celltype_statement_specifier_list
|
---|
980 | : celltype_statement_specifier
|
---|
981 | { result = [ val[0] ] }
|
---|
982 | | celltype_statement_specifier_list ',' celltype_statement_specifier
|
---|
983 | { result << val[2] }
|
---|
984 |
|
---|
985 | celltype_statement_specifier
|
---|
986 | : INLINE { result = [ :INLINE ] }
|
---|
987 | | ALLOCATOR '(' alloc_list2 ')' { result = [ :ALLOCATOR, val[2] ] }
|
---|
988 | | OPTIONAL { result = [ :OPTIONAL ] }
|
---|
989 | | REF_DESC { result = [ :REF_DESC ] }
|
---|
990 | | DYNAMIC { result = [ :DYNAMIC ] }
|
---|
991 | | OMIT { result = [ :OMIT ] }
|
---|
992 |
|
---|
993 | alloc_list2
|
---|
994 | : alloc2 { result = [ val[0] ] } # 受け口のアロケータ指定
|
---|
995 | | alloc { result = [ val[0] ] } # 内部セルのアロケータ指定
|
---|
996 | | alloc_list2 ',' alloc2 { result << val[2] }
|
---|
997 | | alloc_list2 ',' alloc { result << val[2] }
|
---|
998 |
|
---|
999 | alloc2
|
---|
1000 | : IDENTIFIER '.' IDENTIFIER '=' initializer # 内部アロケータ (デバドラ向きアロケータ)指定
|
---|
1001 | { result = [ :INTERNAL_ALLOC, val[0].val, val[2].val, val[4] ] }
|
---|
1002 | | IDENTIFIER '.' IDENTIFIER '<=' initializer # 多段リレーモデル向きアロケータ指定
|
---|
1003 | { result = [ :RELAY_ALLOC, val[0].val, val[2].val, val[4] ] }
|
---|
1004 |
|
---|
1005 |
|
---|
1006 | #呼び口、受け口
|
---|
1007 | port
|
---|
1008 | : port_type namespace_signature_name port_name ';'
|
---|
1009 | { result = Port.new( val[2].val, val[1], val[0] ) }
|
---|
1010 | | port_type namespace_signature_name port_name '[' ']' ';'
|
---|
1011 | { result = Port.new( val[2].val, val[1], val[0], "[]" ) }
|
---|
1012 | | port_type namespace_signature_name port_name '[' array_size ']' ';'
|
---|
1013 | { result = Port.new(val[2].val, val[1], val[0], val[4]) }
|
---|
1014 | | port_type namespace_signature_name port_name '<=' namespace_identifier '.' IDENTIFIER ';' #1ok reverse require
|
---|
1015 | { result = Port.new( val[2].val, val[1], val[0], nil, val[4], val[ 6 ].val ) }
|
---|
1016 |
|
---|
1017 | port_type
|
---|
1018 | : CALL { result = :CALL }
|
---|
1019 | | ENTRY { result = :ENTRY }
|
---|
1020 |
|
---|
1021 | namespace_signature_name
|
---|
1022 | : namespace_identifier #1ok
|
---|
1023 | { result = val[0] }
|
---|
1024 |
|
---|
1025 | port_name
|
---|
1026 | : IDENTIFIER
|
---|
1027 |
|
---|
1028 | array_size
|
---|
1029 | : constant_expression
|
---|
1030 |
|
---|
1031 |
|
---|
1032 | #属性
|
---|
1033 | attribute
|
---|
1034 | : ATTRIBUTE '{' attribute_declaration_list '}' ';'
|
---|
1035 | { result = nil }
|
---|
1036 |
|
---|
1037 | attribute_declaration_list
|
---|
1038 | : attribute_declaration
|
---|
1039 | { Celltype.new_attribute( val[0] ) }
|
---|
1040 | | attribute_declaration_list attribute_declaration
|
---|
1041 | { Celltype.new_attribute( val[1] ) }
|
---|
1042 |
|
---|
1043 |
|
---|
1044 | attribute_declaration
|
---|
1045 | : declaration
|
---|
1046 | {
|
---|
1047 | val[0].each{ |i| # i:Decl
|
---|
1048 | i.set_kind( :ATTRIBUTE )
|
---|
1049 | i.check
|
---|
1050 | }
|
---|
1051 | result = val[0]
|
---|
1052 | }
|
---|
1053 | | spec_L attribute_specifier spec_R declaration
|
---|
1054 | {
|
---|
1055 | val[3].each{ |i| # i:Decl
|
---|
1056 | i.set_kind( :ATTRIBUTE ) # 設定順序あり
|
---|
1057 | i.set_specifier_list( [val[1]] )
|
---|
1058 | i.check
|
---|
1059 | }
|
---|
1060 | result = val[3]
|
---|
1061 | }
|
---|
1062 |
|
---|
1063 | attribute_specifier
|
---|
1064 | : OMIT { result = [:OMIT] }
|
---|
1065 | | SIZE_IS '(' expression ')' { result = [:SIZE_IS,val[2]] }
|
---|
1066 | | CHOICE '=' '{' choice_list '}' { result = [:CHOICE,val[3]] }
|
---|
1067 |
|
---|
1068 | choice_list
|
---|
1069 | : choice_list ',' choice_element { result << val[2] }
|
---|
1070 | | choice_element { result = [ val[0] ] }
|
---|
1071 |
|
---|
1072 | choice_element
|
---|
1073 | : STRING_LITERAL
|
---|
1074 |
|
---|
1075 | #内部変数
|
---|
1076 | var
|
---|
1077 | : VAR '{' var_declaration_list '}' ';'
|
---|
1078 | { result = nil }
|
---|
1079 |
|
---|
1080 | var_declaration_list
|
---|
1081 | : var_declaration
|
---|
1082 | { Celltype.new_var( val[0] ) }
|
---|
1083 | | var_declaration_list var_declaration
|
---|
1084 | { Celltype.new_var( val[1] ) }
|
---|
1085 |
|
---|
1086 | var_declaration
|
---|
1087 | : declaration
|
---|
1088 | {
|
---|
1089 | val[0].each{ |i| # i:Decl
|
---|
1090 | i.set_kind( :VAR )
|
---|
1091 | i.check
|
---|
1092 | }
|
---|
1093 | }
|
---|
1094 | | spec_L var_specifier spec_R declaration
|
---|
1095 | {
|
---|
1096 | val[3].each{ |i| # i:Decl
|
---|
1097 | i.set_kind( :VAR ) # 設定順序あり
|
---|
1098 | i.set_specifier_list( [val[1]] )
|
---|
1099 | i.check
|
---|
1100 | }
|
---|
1101 | result = val[3]
|
---|
1102 | }
|
---|
1103 |
|
---|
1104 | var_specifier
|
---|
1105 | : SIZE_IS '(' expression ')' { result = [:SIZE_IS,val[2]] }
|
---|
1106 |
|
---|
1107 | # リクワイア
|
---|
1108 | require
|
---|
1109 | : REQUIRE namespace_identifier '.' IDENTIFIER';' # mikan namespace #1
|
---|
1110 | {
|
---|
1111 | Celltype.new_require( val[1], val[3] )
|
---|
1112 | }
|
---|
1113 | | REQUIRE IDENTIFIER '=' namespace_identifier '.' IDENTIFIER';' #1
|
---|
1114 | {
|
---|
1115 | Celltype.new_require( val[3], val[5], val[1].val )
|
---|
1116 | }
|
---|
1117 |
|
---|
1118 | #ファクトリ
|
---|
1119 | factory
|
---|
1120 | : factory_head '{' factory_function_list '}' ';'
|
---|
1121 |
|
---|
1122 | factory_head
|
---|
1123 | : FACTORY { Factory.set_f_celltype( false ) }
|
---|
1124 | | CTFACTORY { Factory.set_f_celltype( true ) }
|
---|
1125 |
|
---|
1126 | factory_function_list
|
---|
1127 | : # 空
|
---|
1128 | | factory_function_list factory_function
|
---|
1129 |
|
---|
1130 | factory_function
|
---|
1131 | : factory_function_name '(' constant_expression ',' constant_expression ')' ';'
|
---|
1132 | { Factory.new( val[0].val, val[2], val[4], nil ) }
|
---|
1133 | | factory_function_name '(' constant_expression ',' constant_expression ',' arg_list ')' ';'
|
---|
1134 | { Factory.new( val[0].val, val[2], val[4], val[6] ) }
|
---|
1135 |
|
---|
1136 | factory_function_name
|
---|
1137 | : IDENTIFIER
|
---|
1138 |
|
---|
1139 | arg_list # factory の write 関数の第三引数以降
|
---|
1140 | : IDENTIFIER
|
---|
1141 | { result = [ [ :IDENTIFIER, val[0].val ] ] }
|
---|
1142 | | arg_list ',' IDENTIFIER
|
---|
1143 | { result << [ :IDENTIFIER, val[2].val ] }
|
---|
1144 | | STRING_LITERAL
|
---|
1145 | { result = [ [ :STRING_LITERAL, val[0].val ] ] }
|
---|
1146 | | arg_list ',' STRING_LITERAL
|
---|
1147 | { result << [ :STRING_LITERAL, val[2].val ] }
|
---|
1148 |
|
---|
1149 | #セル生成
|
---|
1150 | cell
|
---|
1151 | : CELL namespace_celltype_name cell_name '{'
|
---|
1152 | { Cell.new_def }
|
---|
1153 | join_list '}' ';'
|
---|
1154 | { result = Cell.end_of_parse true }
|
---|
1155 | | CELL namespace_celltype_name cell_name ';' # oyama プロトタイプ宣言
|
---|
1156 | { result = Cell.end_of_parse false }
|
---|
1157 |
|
---|
1158 | namespace_celltype_name
|
---|
1159 | : namespace_identifier
|
---|
1160 | { result = Cell.new(val[0]) }
|
---|
1161 |
|
---|
1162 | cell_name
|
---|
1163 | : IDENTIFIER
|
---|
1164 | { result = Cell.set_name(val[0].val) }
|
---|
1165 |
|
---|
1166 | join_list
|
---|
1167 | : # 空行 061007
|
---|
1168 | | join_list specified_join
|
---|
1169 | | join_list reverse_join
|
---|
1170 |
|
---|
1171 | specified_join
|
---|
1172 | : spec_L join_specifier_list spec_R join
|
---|
1173 | { val[3].set_specifier_list( val[1] ) }
|
---|
1174 | | join
|
---|
1175 | { val[0].set_specifier_list( [] ) }
|
---|
1176 |
|
---|
1177 | join_specifier_list
|
---|
1178 | : join_specifier_list ',' join_specifier
|
---|
1179 | { result << val[2] }
|
---|
1180 | | join_specifier
|
---|
1181 | { result = [val[0]] }
|
---|
1182 |
|
---|
1183 | join_specifier
|
---|
1184 | : THROUGH '(' plugin_name ',' plugin_arg ')'
|
---|
1185 | { result = [ :THROUGH, val[2], val[4] ] }
|
---|
1186 |
|
---|
1187 | plugin_name
|
---|
1188 | : IDENTIFIER { result = val[0] }
|
---|
1189 |
|
---|
1190 | plugin_arg
|
---|
1191 | : string_literal_list
|
---|
1192 |
|
---|
1193 | join
|
---|
1194 | # : cae_name '=' expression ';'
|
---|
1195 | # {
|
---|
1196 | # result = Join.new( val[0].val, nil, val[2] )
|
---|
1197 | # Cell.new_join( result, true )
|
---|
1198 | # }
|
---|
1199 | # | cae_name '[' ']' '=' expression ';'
|
---|
1200 | : cae_name '[' ']' '=' expression ';'
|
---|
1201 | {
|
---|
1202 | result = Join.new( val[0].val, -1, val[4] )
|
---|
1203 | Cell.new_join( result, true )
|
---|
1204 | }
|
---|
1205 | | cae_name '[' array_index ']' '=' expression ';'
|
---|
1206 | {
|
---|
1207 | result = Join.new( val[0].val, val[2], val[5] )
|
---|
1208 | Cell.new_join( result, true )
|
---|
1209 | }
|
---|
1210 | | cae_name '=' initializer ';' # 初期化子: '{', '}' も可
|
---|
1211 | {
|
---|
1212 | result = Join.new( val[0].val, nil, val[2] )
|
---|
1213 | Cell.new_join( result, true )
|
---|
1214 | }
|
---|
1215 | | cae_name '=' COMPOSITE '.' IDENTIFIER ';'
|
---|
1216 | {
|
---|
1217 | result = Join.new( val[0].val, nil, [ :COMPOSITE, val[4] ] )
|
---|
1218 | Cell.new_join( result, true )
|
---|
1219 | }
|
---|
1220 |
|
---|
1221 | cae_name # cae: callport, attribute, entryport
|
---|
1222 | : IDENTIFIER
|
---|
1223 |
|
---|
1224 | reverse_join
|
---|
1225 | # non-array <= non-array
|
---|
1226 | : cae_name '<=' namespace_identifier '.' IDENTIFIER ';'
|
---|
1227 | {
|
---|
1228 | rj = ReverseJoin.new( val[0].val, nil, val[2], val[4].val )
|
---|
1229 | Cell.new_reverse_join( rj )
|
---|
1230 | }
|
---|
1231 | # non-array <= array
|
---|
1232 | | cae_name '<=' namespace_identifier '.' IDENTIFIER '[' expression ']' ';'
|
---|
1233 | {
|
---|
1234 | rj = ReverseJoin.new( val[0].val, nil, val[2], val[4].val, val[6] )
|
---|
1235 | Cell.new_reverse_join( rj )
|
---|
1236 | }
|
---|
1237 | # array <= non-array
|
---|
1238 | | cae_name '[' array_index ']' '<=' namespace_identifier '.' IDENTIFIER ';'
|
---|
1239 | {
|
---|
1240 | rj = ReverseJoin.new( val[0].val, val[2], val[5], val[7].val )
|
---|
1241 | Cell.new_reverse_join( rj )
|
---|
1242 | }
|
---|
1243 | # array <= array
|
---|
1244 | | cae_name '[' array_index ']' '<=' namespace_identifier '.' IDENTIFIER '[' expression ']' ';'
|
---|
1245 | {
|
---|
1246 | rj = ReverseJoin.new( val[0].val, val[2], val[5], val[7].val, val[9] )
|
---|
1247 | Cell.new_reverse_join( rj )
|
---|
1248 | }
|
---|
1249 |
|
---|
1250 |
|
---|
1251 | array_index
|
---|
1252 | : constant_expression
|
---|
1253 |
|
---|
1254 | #複合種
|
---|
1255 | composite_celltype
|
---|
1256 | : COMPOSITE composite_celltype_name '{' composite_celltype_statement_list '}' ';'
|
---|
1257 | {
|
---|
1258 | CompositeCelltype.end_of_parse
|
---|
1259 | result = val[1]
|
---|
1260 | }
|
---|
1261 |
|
---|
1262 | composite_celltype_name
|
---|
1263 | : IDENTIFIER
|
---|
1264 | { result = CompositeCelltype.new(val[0].val) }
|
---|
1265 |
|
---|
1266 | composite_celltype_statement_list
|
---|
1267 | : specified_composite_celltype_statement
|
---|
1268 | | composite_celltype_statement_list specified_composite_celltype_statement
|
---|
1269 |
|
---|
1270 | specified_composite_celltype_statement
|
---|
1271 | : composite_celltype_statement
|
---|
1272 | {
|
---|
1273 | if val[0].kind_of?( Port ) then
|
---|
1274 | CompositeCelltype.new_port( val[0] ) # 遅延して登録
|
---|
1275 | end
|
---|
1276 | }
|
---|
1277 | | spec_L composite_celltype_statement_specifier_list spec_R composite_celltype_statement
|
---|
1278 | {
|
---|
1279 | if val[3].kind_of?( Port ) then
|
---|
1280 | # port 以外 val[3] に有効な値が入っていないので、以下のメソッドを適用できない
|
---|
1281 | # 現状 port, cell 以外は指定子を受け付けない
|
---|
1282 | # (しかし将来他の文も指定子を受け付ける可能性があるので、この位置に記述する)
|
---|
1283 | val[3].set_specifier( Generator.get_statement_specifier )
|
---|
1284 | CompositeCelltype.new_port( val[3] ) # 遅延して登録 (set_specifier 後)
|
---|
1285 | elsif val[3].kind_of?( Cell ) then
|
---|
1286 | # Cell.end_of_parse にて設定
|
---|
1287 | else
|
---|
1288 | Generator.get_statement_specifier # クリア
|
---|
1289 | Generator.error( "G1013 unexpected specifier" )
|
---|
1290 | end
|
---|
1291 | }
|
---|
1292 |
|
---|
1293 | composite_celltype_statement
|
---|
1294 | : composite_port
|
---|
1295 | | composite_attribute
|
---|
1296 | | internal_cell
|
---|
1297 | | export_join
|
---|
1298 | # | error # エラー回復ポイント (#513 無限ループに陥るケースがあるので、ここでのエラー回復は取りやめ)
|
---|
1299 |
|
---|
1300 | composite_celltype_statement_specifier_list
|
---|
1301 | : composite_celltype_statement_specifier
|
---|
1302 | {
|
---|
1303 | Generator.add_statement_specifier val[0]
|
---|
1304 | result = [ val[0] ]
|
---|
1305 | }
|
---|
1306 | | composite_celltype_statement_specifier_list ',' composite_celltype_statement_specifier
|
---|
1307 | {
|
---|
1308 | Generator.add_statement_specifier val[2]
|
---|
1309 | result = val[0] << val[2]
|
---|
1310 | }
|
---|
1311 |
|
---|
1312 | composite_celltype_statement_specifier
|
---|
1313 | : ALLOCATOR '(' alloc_list2 ')' { result = [ :ALLOCATOR, val[2] ] }
|
---|
1314 | | OMIT { result = [ :OMIT ] }
|
---|
1315 | | OPTIONAL { result = [ :OPTIONAL ] }
|
---|
1316 | | REF_DESC { result = [ :REF_DESC ] }
|
---|
1317 | | DYNAMIC { result = [ :DYNAMIC ] }
|
---|
1318 |
|
---|
1319 | composite_port
|
---|
1320 | : port
|
---|
1321 | {
|
---|
1322 | # CompositeCelltype.new_port( val[0] )
|
---|
1323 | result = val[0]
|
---|
1324 | }
|
---|
1325 |
|
---|
1326 | #属性
|
---|
1327 | composite_attribute
|
---|
1328 | : ATTRIBUTE '{' composite_attribute_declaration_list '}' ';'
|
---|
1329 | { result = nil }
|
---|
1330 |
|
---|
1331 | composite_attribute_declaration_list
|
---|
1332 | : attribute_declaration
|
---|
1333 | { CompositeCelltype.new_attribute( val[0] ) }
|
---|
1334 | | composite_attribute_declaration_list attribute_declaration
|
---|
1335 | { CompositeCelltype.new_attribute( val[1] ) }
|
---|
1336 |
|
---|
1337 | internal_cell
|
---|
1338 | : CELL internal_namespace_celltype_name
|
---|
1339 | internal_cell_name '{'
|
---|
1340 | { Cell.new_def }
|
---|
1341 | internal_join_list '}' ';'
|
---|
1342 | { result = Cell.end_of_parse true }
|
---|
1343 | | CELL internal_namespace_celltype_name internal_cell_name ';'
|
---|
1344 | { result = Cell.end_of_parse false }
|
---|
1345 |
|
---|
1346 |
|
---|
1347 | internal_namespace_celltype_name
|
---|
1348 | : namespace_identifier
|
---|
1349 | { Cell.new(val[0],true) }
|
---|
1350 |
|
---|
1351 | internal_cell_name
|
---|
1352 | : IDENTIFIER
|
---|
1353 | { Cell.set_name(val[0].val) }
|
---|
1354 |
|
---|
1355 |
|
---|
1356 | internal_join_list
|
---|
1357 | : # 空行 061007
|
---|
1358 | | internal_join_list specified_join
|
---|
1359 | | internal_join_list external_join
|
---|
1360 | | internal_join_list reverse_join
|
---|
1361 |
|
---|
1362 | external_join # cell 内に記述する呼び口の外部結合
|
---|
1363 | : internal_cell_elem_name '=>' COMPOSITE '.' export_name ';'
|
---|
1364 | { Cell.external_join( val[0].val, val[4].val, true ) }
|
---|
1365 | | internal_cell_elem_name '=>' export_name ';'
|
---|
1366 | { Cell.external_join( val[0].val, val[2].val, false ) }
|
---|
1367 | # 以前の文法では、呼び口側も cell の外に記述していた
|
---|
1368 | # その時の実装を
|
---|
1369 |
|
---|
1370 | export_join # cell 外に記述する受け口の外部結合
|
---|
1371 | : export_name '=>' internal_ref_cell_name '.' internal_cell_elem_name ';'
|
---|
1372 | {
|
---|
1373 | CompositeCelltype.new_join( val[0].val,
|
---|
1374 | val[2].val, val[4].val, :ENTRY )
|
---|
1375 | }
|
---|
1376 | | COMPOSITE '.' export_name '=>' internal_ref_cell_name '.' internal_cell_elem_name ';'
|
---|
1377 | {
|
---|
1378 | CompositeCelltype.new_join( val[2].val,
|
---|
1379 | val[4].val, val[6].val, :ENTRY )
|
---|
1380 | }
|
---|
1381 |
|
---|
1382 | export_name
|
---|
1383 | : IDENTIFIER
|
---|
1384 |
|
---|
1385 | internal_ref_cell_name
|
---|
1386 | : IDENTIFIER
|
---|
1387 |
|
---|
1388 | internal_cell_elem_name
|
---|
1389 | : IDENTIFIER
|
---|
1390 |
|
---|
1391 | # リージョン
|
---|
1392 | region
|
---|
1393 | : spec_L region_specifier_list spec_R REGION region_name '{' region_statement '}' ';'
|
---|
1394 | { Region.end_of_parse }
|
---|
1395 | | REGION region_name '{' region_statement '}' ';'
|
---|
1396 | { Region.end_of_parse }
|
---|
1397 |
|
---|
1398 |
|
---|
1399 | region_specifier_list
|
---|
1400 | : region_specifier
|
---|
1401 | | region_specifier_list ',' region_specifier
|
---|
1402 |
|
---|
1403 | region_specifier
|
---|
1404 | : IN_THROUGH '(' plugin_name ',' plugin_arg ')'
|
---|
1405 | { Region.new_in_through( val[2].val, val[4].val ) }
|
---|
1406 | | IN_THROUGH '(' ')' # in 許可
|
---|
1407 | { Region.new_in_through }
|
---|
1408 | | OUT_THROUGH '(' plugin_name ',' plugin_arg ')'
|
---|
1409 | { Region.new_out_through( val[2].val, val[4].val ) }
|
---|
1410 | | OUT_THROUGH '(' ')' # out 許可
|
---|
1411 | { Region.new_out_through() }
|
---|
1412 | | TO_THROUGH '(' namespace_region_name ',' plugin_name ',' plugin_arg ')'
|
---|
1413 | { Region.new_to_through( val[2], val[4].val, val[6].val ) }
|
---|
1414 | | TO_THROUGH '('namespace_region_name ')' # to 許可
|
---|
1415 | { Region.new_to_through( val[2], nil, nil ) }
|
---|
1416 | | NODE
|
---|
1417 | { Region.set_type( :NODE ) }
|
---|
1418 | | LINKUNIT
|
---|
1419 | { Region.set_type( :LINKUNIT ) }
|
---|
1420 | | DOMAIN '(' IDENTIFIER ',' STRING_LITERAL ')'
|
---|
1421 | { Region.set_domain( val[2].val, val[4] ) }
|
---|
1422 | | CLASS '(' IDENTIFIER ')'
|
---|
1423 | { Region.set_type( :CLASS, val[2].val ) }
|
---|
1424 |
|
---|
1425 | region_name
|
---|
1426 | : IDENTIFIER
|
---|
1427 | { result = Region.new( val[0].val ) }
|
---|
1428 |
|
---|
1429 | region_statement
|
---|
1430 | :
|
---|
1431 | | region_statement region_cell
|
---|
1432 | | region_statement region
|
---|
1433 |
|
---|
1434 | region_cell
|
---|
1435 | : cell
|
---|
1436 | | spec_L statement_specifier_list spec_R cell
|
---|
1437 | {
|
---|
1438 | obj = val[3]
|
---|
1439 | if obj.kind_of?( Cell ) then
|
---|
1440 | else
|
---|
1441 | Generator.get_statement_specifier # クリア
|
---|
1442 | Generator.error( "G9999 unexpected specifier" )
|
---|
1443 | end
|
---|
1444 | }
|
---|
1445 | # | spec_L region_cell_specifier_list spec_R cell
|
---|
1446 |
|
---|
1447 | # region_cell_specifier_list
|
---|
1448 | # : region_cell_specifier
|
---|
1449 | # { Generator.add_statement_specifier val[0] }
|
---|
1450 | # | region_cell_specifier_list region_cell_specifier
|
---|
1451 | # { Generator.add_statement_specifier val[2] }
|
---|
1452 |
|
---|
1453 | # region_cell_specifier
|
---|
1454 | # : ALLOCATOR '(' alloc_list ')'
|
---|
1455 | # { result = [ :ALLOCATOR, val[2] ] }
|
---|
1456 |
|
---|
1457 |
|
---|
1458 | namespace_region_name
|
---|
1459 | : :IDENTIFIER
|
---|
1460 | { result = [ val[0].val ] } # mikan 配列である必要はない
|
---|
1461 | # : namespace_identifier
|
---|
1462 |
|
---|
1463 | # 指定子の括弧 (in, out などのキーワード切り替えのため分離)
|
---|
1464 | spec_L
|
---|
1465 | : '[' { set_in_specifier }
|
---|
1466 | spec_R
|
---|
1467 | : ']' { unset_in_specifier }
|
---|
1468 |
|
---|
1469 | # location information
|
---|
1470 | location_information
|
---|
1471 | : __LOCATION_INFORMATION__ '{' cell_location_join_location_list '}'
|
---|
1472 |
|
---|
1473 | cell_location_join_location_list
|
---|
1474 | : cell_location_join_location_list cell_location
|
---|
1475 | | cell_location_join_location_list join_location
|
---|
1476 | |
|
---|
1477 |
|
---|
1478 | cell_location
|
---|
1479 | : __CELL__ namespace_identifier '(' constant_expression ',' constant_expression ',' constant_expression ',' constant_expression ')' '{' port_location_list '}'
|
---|
1480 | {
|
---|
1481 | TECSGEN::Cell_location.new( val[1], val[3], val[5], val[7], val[9], val[12] )
|
---|
1482 | }
|
---|
1483 |
|
---|
1484 | port_location_list
|
---|
1485 | : port_location_list port_location
|
---|
1486 | {
|
---|
1487 | result = val[0] << val[1]
|
---|
1488 | }
|
---|
1489 | |
|
---|
1490 | { result = [] }
|
---|
1491 |
|
---|
1492 | port_location
|
---|
1493 | : IDENTIFIER '(' IDENTIFIER ',' constant_expression ')'
|
---|
1494 | { result = [ val[0], val[2], val[3] ] }
|
---|
1495 |
|
---|
1496 | join_location # mikan port array
|
---|
1497 | : __JOIN__ '(' namespace_identifier '.' IDENTIFIER '=>' namespace_identifier '.' IDENTIFIER ')' '{' bar_list '}'
|
---|
1498 | {
|
---|
1499 | TECSGEN::Join_location.new( val[2], val[4], val[6], val[8], val[11] )
|
---|
1500 | }
|
---|
1501 |
|
---|
1502 | bar_list
|
---|
1503 | : bar_list IDENTIFIER '(' constant_expression ')'
|
---|
1504 | {
|
---|
1505 | result = val[0] << [ val[1], val[3] ]
|
---|
1506 | }
|
---|
1507 | | { result = [] }
|
---|
1508 |
|
---|
1509 |
|
---|
1510 | # JSON object
|
---|
1511 | tool_info : TOOL_INFO '(' JSON_string ')' JSON_object { TOOL_INFO.new( val[2].to_sym, val[4] ) }
|
---|
1512 | JSON_object : '{' JSON_property_list '}' { result = val[1] }
|
---|
1513 | JSON_property_list : JSON_string ':' JSON_value { result = { val[0].to_sym => val[2] } }
|
---|
1514 | | JSON_property_list ',' JSON_string ':' JSON_value
|
---|
1515 | { val[0][ val[2].to_sym ] = val[4] }
|
---|
1516 | JSON_value : JSON_string | JSON_number | JSON_object | JSON_array
|
---|
1517 | | TRUE { result=val[0].val } | FALSE { result=val[0].val } # JSON_NULL # null not suppoted
|
---|
1518 | JSON_array : '[' JSON_array_list ']' { result = val[1] }
|
---|
1519 | | '[' ']' { result = [] }
|
---|
1520 | JSON_array_list : JSON_value { result = [ val[0] ] }
|
---|
1521 | | JSON_array_list ',' JSON_value { val[0] << val[2] }
|
---|
1522 | JSON_string : STRING_LITERAL { result = val[0].val.gsub!( /\"(.*)\"/, "\\1" ) }
|
---|
1523 | JSON_number : INTEGER_CONSTANT { result = val[0].val.to_i }
|
---|
1524 | | FLOATING_CONSTANT { result = val[0].val.to_f }
|
---|
1525 | | '-' INTEGER_CONSTANT { result = - val[0].val.to_i }
|
---|
1526 | | '-' FLOATING_CONSTANT { result = - val[0].val.to_f }
|
---|
1527 | | '+' INTEGER_CONSTANT { result = val[0].val.to_i }
|
---|
1528 | | '+' FLOATING_CONSTANT { result = val[0].val.to_f }
|
---|
1529 |
|
---|
1530 |
|
---|
1531 | end
|
---|
1532 |
|
---|
1533 | ---- inner
|
---|
1534 |
|
---|
1535 | RESERVED = {
|
---|
1536 | # keyword
|
---|
1537 | 'namespace' => :NAMESPACE,
|
---|
1538 | 'signature' => :SIGNATURE,
|
---|
1539 | 'celltype' => :CELLTYPE,
|
---|
1540 | 'cell' => :CELL,
|
---|
1541 | 'attr' => :ATTRIBUTE,
|
---|
1542 | 'var' => :VAR,
|
---|
1543 | 'call' => :CALL,
|
---|
1544 | 'entry' => :ENTRY,
|
---|
1545 | 'composite' => :COMPOSITE,
|
---|
1546 | 'require' => :REQUIRE,
|
---|
1547 | 'factory' => :FACTORY,
|
---|
1548 | 'FACTORY' => :CTFACTORY,
|
---|
1549 | 'typedef' => :TYPEDEF,
|
---|
1550 | 'struct' => :STRUCT,
|
---|
1551 | 'region' => :REGION,
|
---|
1552 | 'import' => :IMPORT,
|
---|
1553 | 'import_C' => :IMPORT_C,
|
---|
1554 | 'generate' => :GENERATE,
|
---|
1555 | '__tool_info__' => :TOOL_INFO,
|
---|
1556 |
|
---|
1557 | # types
|
---|
1558 | 'void' => :VOID,
|
---|
1559 |
|
---|
1560 | 'volatile'=> :VOLATILE,
|
---|
1561 | 'const' => :CONST,
|
---|
1562 |
|
---|
1563 | 'signed' => :SIGNED,
|
---|
1564 | 'unsigned'=> :UNSIGNED,
|
---|
1565 |
|
---|
1566 | 'int8_t' => :INT8_T,
|
---|
1567 | 'int16_t' => :INT16_T,
|
---|
1568 | 'int32_t' => :INT32_T,
|
---|
1569 | 'int64_t' => :INT64_T,
|
---|
1570 | 'int128_t' => :INT128_T,
|
---|
1571 | 'uint8_t' => :UINT8_T,
|
---|
1572 | 'uint16_t' => :UINT16_T,
|
---|
1573 | 'uint32_t' => :UINT32_T,
|
---|
1574 | 'uint64_t' => :UINT64_T,
|
---|
1575 | 'uint128_t' => :UINT128_T,
|
---|
1576 |
|
---|
1577 | 'float32_t' => :FLOAT32_T,
|
---|
1578 | 'double64_t' => :DOUBLE64_T,
|
---|
1579 | 'bool_t' => :BOOL_T,
|
---|
1580 | 'char_t' => :CHAR_T,
|
---|
1581 | 'schar_t' => :SCHAR_T,
|
---|
1582 | 'uchar_t' => :UCHAR_T,
|
---|
1583 |
|
---|
1584 | # unrecommened types
|
---|
1585 | 'int' => :INT,
|
---|
1586 | # 'intptr' => :INTPTR,
|
---|
1587 | 'short' => :SHORT,
|
---|
1588 | 'long' => :LONG,
|
---|
1589 |
|
---|
1590 | # obsolete types
|
---|
1591 | 'char' => :CHAR,
|
---|
1592 | # 'int8' => :INT8,
|
---|
1593 | # 'int16' => :INT16,
|
---|
1594 | # 'int32' => :INT32,
|
---|
1595 | # 'int64' => :INT64,
|
---|
1596 | # 'int128' => :INT128,
|
---|
1597 | # 'float' => :FLOAT,
|
---|
1598 | # 'double' => :DOUBLE,
|
---|
1599 | # 'bool' => :BOOL,
|
---|
1600 |
|
---|
1601 | 'enum' => :ENUM,
|
---|
1602 | 'enum8' => :ENUM8,
|
---|
1603 | 'enum16' => :ENUM16,
|
---|
1604 | 'enum32' => :ENUM32,
|
---|
1605 | 'enum64' => :ENUM64,
|
---|
1606 |
|
---|
1607 | 'true' => :TRUE,
|
---|
1608 | 'false' => :FALSE,
|
---|
1609 |
|
---|
1610 | 'C_EXP' => :C_EXP,
|
---|
1611 |
|
---|
1612 | 'Descriptor' => :DESCRIPTOR,
|
---|
1613 |
|
---|
1614 | # location information for TECSCDE
|
---|
1615 | '__location_information__' => :__LOCATION_INFORMATION__,
|
---|
1616 | '__cell__' => :__CELL__,
|
---|
1617 | '__join__' => :__JOIN__,
|
---|
1618 | }
|
---|
1619 |
|
---|
1620 | # 指定子 '[]' 内でのみ使用できるキーワード
|
---|
1621 | RESERVED2 = {
|
---|
1622 | # specifier
|
---|
1623 | 'id' => :ID,
|
---|
1624 |
|
---|
1625 | # signature
|
---|
1626 | 'callback' => :CALLBACK,
|
---|
1627 | 'context' => :CONTEXT,
|
---|
1628 | 'deviate' => :DEVIATE,
|
---|
1629 |
|
---|
1630 | # celltype
|
---|
1631 | 'singleton' => :SINGLETON,
|
---|
1632 | 'idx_is_id' => :IDX_IS_ID,
|
---|
1633 | 'active' => :ACTIVE,
|
---|
1634 |
|
---|
1635 | # port (entry)
|
---|
1636 | 'inline' => :INLINE,
|
---|
1637 | 'ref_desc' => :REF_DESC, # call も可
|
---|
1638 |
|
---|
1639 | # port (call)
|
---|
1640 | 'optional' => :OPTIONAL,
|
---|
1641 | 'dynamic' => :DYNAMIC,
|
---|
1642 |
|
---|
1643 | # port (call), attribute
|
---|
1644 | 'omit' => :OMIT,
|
---|
1645 |
|
---|
1646 | # attribute
|
---|
1647 | 'choice' => :CHOICE,
|
---|
1648 |
|
---|
1649 | # cell
|
---|
1650 | 'allocator' => :ALLOCATOR,
|
---|
1651 | 'prototype' => :PROTOTYPE,
|
---|
1652 | 'restrict' => :RESTRICT,
|
---|
1653 |
|
---|
1654 | # FuncType
|
---|
1655 | 'oneway' => :ONEWAY,
|
---|
1656 |
|
---|
1657 | # parameter (basic)
|
---|
1658 | 'in' => :IN,
|
---|
1659 | 'out' => :OUT,
|
---|
1660 | 'inout' => :INOUT,
|
---|
1661 | 'send' => :SEND,
|
---|
1662 | 'receive' => :RECEIVE,
|
---|
1663 |
|
---|
1664 | # parameter
|
---|
1665 | 'size_is' => :SIZE_IS,
|
---|
1666 | 'count_is' => :COUNT_IS,
|
---|
1667 | 'string' => :STRING,
|
---|
1668 | 'nullable' => :NULLABLE,
|
---|
1669 |
|
---|
1670 | 'through' => :THROUGH,
|
---|
1671 | 'in_through' => :IN_THROUGH,
|
---|
1672 | 'out_through' => :OUT_THROUGH,
|
---|
1673 | 'to_through' => :TO_THROUGH,
|
---|
1674 |
|
---|
1675 | 'node' => :NODE,
|
---|
1676 | 'linkunit' => :LINKUNIT ,
|
---|
1677 | 'domain' => :DOMAIN,
|
---|
1678 | 'class' => :CLASS,
|
---|
1679 | }
|
---|
1680 |
|
---|
1681 | # 再帰的なパーサのためのスタック
|
---|
1682 | @@generator_nest = -1
|
---|
1683 | @@generator_stack = []
|
---|
1684 | @@current_locale = []
|
---|
1685 |
|
---|
1686 | # import_C 中である
|
---|
1687 | @@import_C = false
|
---|
1688 |
|
---|
1689 | # すべての構文解析が完了した
|
---|
1690 | @@b_end_all_parse = false
|
---|
1691 |
|
---|
1692 | # tag なし struct
|
---|
1693 | @@no_struct_tag_num = 0
|
---|
1694 |
|
---|
1695 | def self.parse( file_name, plugin = nil, b_reuse = false )
|
---|
1696 | # パーサインスタンスを生成(別パーサで読み込む)
|
---|
1697 | parser = Generator.new
|
---|
1698 |
|
---|
1699 | # plugin から import されている場合の plugin 設定
|
---|
1700 | parser.set_plugin plugin
|
---|
1701 |
|
---|
1702 | # reuse フラグを設定
|
---|
1703 | parser.set_reuse b_reuse
|
---|
1704 |
|
---|
1705 | # cdl をパース
|
---|
1706 | parser.parse( [file_name] )
|
---|
1707 |
|
---|
1708 | # 終期化 パーサスタックを戻す
|
---|
1709 | parser.finalize
|
---|
1710 | end
|
---|
1711 |
|
---|
1712 | def finalize
|
---|
1713 |
|
---|
1714 | # mikan Namespace.pop
|
---|
1715 | Namespace.pop
|
---|
1716 | Signature.pop
|
---|
1717 | Celltype.pop
|
---|
1718 | Cell.pop
|
---|
1719 | CompositeCelltype.pop
|
---|
1720 | end
|
---|
1721 |
|
---|
1722 | def set_plugin( plugin )
|
---|
1723 | @plugin = plugin
|
---|
1724 | end
|
---|
1725 |
|
---|
1726 | def self.get_plugin
|
---|
1727 | if @@generator_stack[@@generator_nest] then
|
---|
1728 | # tecsgen 引数の cdl が import される場合は nil
|
---|
1729 | return @@generator_stack[@@generator_nest].get_plugin
|
---|
1730 | else
|
---|
1731 | return nil
|
---|
1732 | end
|
---|
1733 | end
|
---|
1734 |
|
---|
1735 | def get_plugin
|
---|
1736 | @plugin
|
---|
1737 | end
|
---|
1738 |
|
---|
1739 | def set_reuse( b_reuse )
|
---|
1740 | @b_reuse = b_reuse
|
---|
1741 | end
|
---|
1742 |
|
---|
1743 | def self.is_reuse?
|
---|
1744 | if @@generator_stack[@@generator_nest] then
|
---|
1745 | # tecsgen 引数の cdl が import される場合は nil
|
---|
1746 | return @@generator_stack[@@generator_nest].is_reuse?
|
---|
1747 | else
|
---|
1748 | return false
|
---|
1749 | end
|
---|
1750 | end
|
---|
1751 |
|
---|
1752 | def is_reuse?
|
---|
1753 | @b_reuse
|
---|
1754 | end
|
---|
1755 |
|
---|
1756 | def parse(files)
|
---|
1757 |
|
---|
1758 | # mikan Namespace.push
|
---|
1759 | Namespace.push
|
---|
1760 | Signature.push
|
---|
1761 | Celltype.push
|
---|
1762 | Cell.push
|
---|
1763 | CompositeCelltype.push
|
---|
1764 |
|
---|
1765 | @@generator_nest += 1
|
---|
1766 | @@generator_stack[@@generator_nest] = self
|
---|
1767 | @in_specifier = false
|
---|
1768 |
|
---|
1769 | begin
|
---|
1770 |
|
---|
1771 | @q = []
|
---|
1772 | b_in_comment = false
|
---|
1773 | b_in_string = false
|
---|
1774 |
|
---|
1775 | # euc のコメントを utf8 として扱うと、コメントの終わりを誤る問題の対策
|
---|
1776 | TECS_LANG::set_kcode_binary
|
---|
1777 |
|
---|
1778 | files.each {|file|
|
---|
1779 | lineno = 1
|
---|
1780 | begin
|
---|
1781 | string = ""
|
---|
1782 | #2.0 IO.foreach(file) {|line|
|
---|
1783 | TECSIO.foreach(file) {|line|
|
---|
1784 | col = 1
|
---|
1785 | # line.rstrip! 改行含む文字列を扱うようになったので、ここで空白を取り除けなくなった
|
---|
1786 |
|
---|
1787 | until line.empty?
|
---|
1788 |
|
---|
1789 | if b_in_comment
|
---|
1790 | case line
|
---|
1791 | # コメント終了
|
---|
1792 | when /\A\*\//
|
---|
1793 | b_in_comment = false
|
---|
1794 | when /\A./
|
---|
1795 | ;
|
---|
1796 | when /\s+/ # line.rstrip! を止めたため \n などの空白文字とまっちするルールが必要になった
|
---|
1797 | ;
|
---|
1798 | end
|
---|
1799 | elsif b_in_string
|
---|
1800 | if line =~ /\A(?:[^"\\]|\\.)*"/
|
---|
1801 | string = "#{string}#{$&}"
|
---|
1802 | @q << [:STRING_LITERAL, Token.new(string, file, lineno, col)]
|
---|
1803 | b_in_string = false
|
---|
1804 | elsif line =~ /\A.*\\\n/ # 改行 \n は '.' にマッチしない
|
---|
1805 | string += $&
|
---|
1806 | elsif line =~ /\A.*\n/ # 改行 \n は '.' にマッチしない
|
---|
1807 | string += line
|
---|
1808 | # この位置では error メソッドは使えない (token 読出し前)
|
---|
1809 | puts "#{file}:#{lineno}:#{col}: error: string literal has newline without escape"
|
---|
1810 | @@n_error += 1
|
---|
1811 | end
|
---|
1812 | else
|
---|
1813 | case line
|
---|
1814 | # 空白、プリプロセスディレクティブ
|
---|
1815 | when /\A\s+/
|
---|
1816 | ;
|
---|
1817 | # 識別子
|
---|
1818 | when /\A[a-zA-Z_]\w*/
|
---|
1819 | word = $&
|
---|
1820 | @q << [RESERVED[word] || :IDENTIFIER, Token.new(word.intern, file, lineno, col)]
|
---|
1821 | # 16 進数定数
|
---|
1822 | when /\A0x[0-9A-Fa-f]+/
|
---|
1823 | @q << [:HEX_CONSTANT, Token.new($&, file, lineno, col)]
|
---|
1824 | # 8 進数定数
|
---|
1825 | when /\A0[0-7]+/
|
---|
1826 | @q << [:OCTAL_CONSTANT, Token.new($&, file, lineno, col)]
|
---|
1827 | # 浮動小数定数
|
---|
1828 | when /\A[0-9]+\.([0-9]*)?([Ee][+-]?[0-9]+)?/
|
---|
1829 | @q << [:FLOATING_CONSTANT, Token.new($&, file, lineno, col)]
|
---|
1830 | # 整数定数
|
---|
1831 | when /\A\d+/
|
---|
1832 | @q << [:INTEGER_CONSTANT, Token.new($&.to_i, file, lineno, col)]
|
---|
1833 | # 文字定数
|
---|
1834 | when /\A'(?:[^'\\]|\\.)'/
|
---|
1835 | @q << [:CHARACTER_LITERAL, Token.new($&, file, lineno, col)]
|
---|
1836 | # 文字列
|
---|
1837 | # "#include #include #include \"../systask/logtask.cfg\" 最後の " 忘れ)で無限ループ
|
---|
1838 | # when /\A"(?:[^"\\]+|\\.)*"/
|
---|
1839 | when /\A"(?:[^"\\]|\\.)*"/ # これはうまく行くようだ
|
---|
1840 | @q << [:STRING_LITERAL, Token.new($&, file, lineno, col)]
|
---|
1841 | # 文字列 (改行あり)
|
---|
1842 | when /\A"(?:[^"\\]|\\.)*\\\n$/
|
---|
1843 | string = $&
|
---|
1844 | b_in_string = true
|
---|
1845 | # 文字列 (改行あり, escape なし)
|
---|
1846 | when /\A("(?:[^"\\]|\e\.)*)\n$/
|
---|
1847 | string = $1 + "\\\n"
|
---|
1848 | b_in_string = true
|
---|
1849 | # この位置では error メソッドは使えない (token 読出し前) # mikan cdl_error ではない
|
---|
1850 | puts "#{file}:#{lineno}:#{col}: error: string literal has newline without escape"
|
---|
1851 | @@n_error += 1
|
---|
1852 | # 山括弧で囲まれた文字列
|
---|
1853 | # when /\A<[0-9A-Za-z_\. \/]+>/ # AB: angle bracke
|
---|
1854 | when /\A<(?:[^>\\]|\\.)*>/ # これはうまく行くようだ
|
---|
1855 | @q << [:AB_STRING_LITERAL, Token.new($&, file, lineno, col)]
|
---|
1856 | # 行コメント
|
---|
1857 | when /\A\/\/.*$/
|
---|
1858 | # 読み飛ばすだけ
|
---|
1859 | # コメント開始
|
---|
1860 | when /\A\/\*/
|
---|
1861 | b_in_comment = true
|
---|
1862 | # '>>', '<<' など
|
---|
1863 | when /\A>>/, /\A<</, /\A==/, /\A!=/, /\A\&\&/, /\A\|\|/
|
---|
1864 | @q << [$&, Token.new($&, file, lineno, col)]
|
---|
1865 | when /\A::/, /\A=>/, /\A<=/, /\A>=/
|
---|
1866 | @q << [$&, Token.new($&, file, lineno, col)]
|
---|
1867 | # '(', ')' など一文字の記号、または未知の記号
|
---|
1868 | when /\A./
|
---|
1869 | @q << [$&, Token.new($&, file, lineno, col)]
|
---|
1870 | else
|
---|
1871 | raise
|
---|
1872 | end
|
---|
1873 | end
|
---|
1874 |
|
---|
1875 | line = $'
|
---|
1876 | col += $&.length
|
---|
1877 | end
|
---|
1878 |
|
---|
1879 | lineno += 1
|
---|
1880 | }
|
---|
1881 |
|
---|
1882 | rescue => evar
|
---|
1883 | Generator.error( "G1014 while open or reading \'$1\'" , file )
|
---|
1884 | if $debug then
|
---|
1885 | p puts( evar )
|
---|
1886 | pp $@
|
---|
1887 | end
|
---|
1888 | end
|
---|
1889 | }
|
---|
1890 |
|
---|
1891 | # 終了の印
|
---|
1892 | @q << nil
|
---|
1893 |
|
---|
1894 | @yydebug = true
|
---|
1895 | do_parse
|
---|
1896 |
|
---|
1897 | ensure
|
---|
1898 | @@generator_nest -= 1
|
---|
1899 | TECS_LANG::reset_kcode
|
---|
1900 | end
|
---|
1901 |
|
---|
1902 | end
|
---|
1903 |
|
---|
1904 | def next_token
|
---|
1905 | token = @q.shift
|
---|
1906 |
|
---|
1907 | if token then
|
---|
1908 | @@current_locale[@@generator_nest] = token[1].locale
|
---|
1909 |
|
---|
1910 | if token[0] == :IDENTIFIER then
|
---|
1911 | # TYPE_NAME トークンへ置換え
|
---|
1912 | if Namespace.is_typename?( token[1].val ) then
|
---|
1913 | token[0] = :TYPE_NAME
|
---|
1914 | elsif @in_specifier && RESERVED2[ token[1].val.to_s ] then
|
---|
1915 | # 指定子キーワード( '[', ']' 内でのみ有効)
|
---|
1916 | token[0] = RESERVED2[ token[1].val.to_s ]
|
---|
1917 | end
|
---|
1918 | end
|
---|
1919 |
|
---|
1920 | if $debug then # 070107 token 無効時ここを通さないようした (through 対応 -d の時に例外発生)
|
---|
1921 | locale = @@current_locale[@@generator_nest]
|
---|
1922 | if token then
|
---|
1923 | print( "#{locale[0]}: line #{locale[1]} : #{token[0]} '#{token[1].val}'\n" )
|
---|
1924 | else
|
---|
1925 | print( "#{locale[0]}: line #{locale[1]} : EOF\n" )
|
---|
1926 | end
|
---|
1927 | end
|
---|
1928 | else
|
---|
1929 | token = [ false, false ]
|
---|
1930 | end
|
---|
1931 |
|
---|
1932 | token
|
---|
1933 | end
|
---|
1934 |
|
---|
1935 | def on_error(t, v, vstack)
|
---|
1936 | # p t, token_to_str(t), vstack
|
---|
1937 | if token_to_str(t) == "$end" then
|
---|
1938 | Generator.error( "G1015 Unexpected EOF" )
|
---|
1939 | else
|
---|
1940 | Generator.error( "G1016 syntax error near \'$1\'" , v.val )
|
---|
1941 | end
|
---|
1942 | end
|
---|
1943 |
|
---|
1944 | def self.current_locale
|
---|
1945 | @@current_locale[ @@generator_nest ]
|
---|
1946 | end
|
---|
1947 |
|
---|
1948 | @@n_error = 0
|
---|
1949 | @@n_warning = 0
|
---|
1950 | @@n_info = 0
|
---|
1951 |
|
---|
1952 | # このメソッドは構文解析、意味解析からのみ呼出し可(コード生成でエラー発生は不適切)
|
---|
1953 | def self.error( msg, *arg )
|
---|
1954 | locale = nil
|
---|
1955 | self.error2( locale, msg, *arg )
|
---|
1956 | end
|
---|
1957 |
|
---|
1958 | def self.error2( locale, msg, *arg )
|
---|
1959 | @@n_error += 1
|
---|
1960 |
|
---|
1961 | msg = TECSMsg.get_error_message( msg )
|
---|
1962 | # $1, $2, ... を arg で置換
|
---|
1963 | count = 1
|
---|
1964 | arg.each{ |a|
|
---|
1965 | str = TECSIO.str_code_convert( msg, a.to_s )
|
---|
1966 | msg.sub!( /\$#{count}/, str )
|
---|
1967 | count += 1
|
---|
1968 | }
|
---|
1969 |
|
---|
1970 | # import_C の中でのエラー?
|
---|
1971 | if @@import_C then
|
---|
1972 | C_parser.error( msg )
|
---|
1973 | else
|
---|
1974 |
|
---|
1975 | # Node の記憶する 位置 (locale) を使用した場合、変更以前に比べ、
|
---|
1976 | # 問題発生箇所と異なる位置にエラーが出るため、構文解析中のエラー
|
---|
1977 | # は、解析中の位置を出力する.(new_XXX で owner が子要素のチェッ
|
---|
1978 | # クをすると owner の行番号が出てしまう点で、ずれが生じている)
|
---|
1979 |
|
---|
1980 | if @@b_end_all_parse == false || locale == nil then
|
---|
1981 | locale = @@current_locale[ @@generator_nest ]
|
---|
1982 | end
|
---|
1983 | if locale then
|
---|
1984 | Console.puts "#{locale[0]}:#{locale[1]}:#{locale[2]}: error: #{msg}"
|
---|
1985 | else
|
---|
1986 | Console.puts "error: #{msg}"
|
---|
1987 | end
|
---|
1988 | end
|
---|
1989 | end
|
---|
1990 |
|
---|
1991 | # このメソッドは構文解析、意味解析からのみ呼出し可(コード生成でウォーニング発生は不適切)
|
---|
1992 | def self.warning( msg, *arg )
|
---|
1993 | locale = nil
|
---|
1994 | self.warning2( locale, msg, *arg )
|
---|
1995 | end
|
---|
1996 |
|
---|
1997 | def self.warning2( locale, msg, *arg )
|
---|
1998 | @@n_warning += 1
|
---|
1999 |
|
---|
2000 | msg = TECSMsg.get_warning_message( msg )
|
---|
2001 | # $1, $2, ... を arg で置換
|
---|
2002 | count = 1
|
---|
2003 | arg.each{ |a|
|
---|
2004 | str = TECSIO.str_code_convert( msg, a.to_s )
|
---|
2005 | msg.sub!( /\$#{count}/, str )
|
---|
2006 | count += 1
|
---|
2007 | }
|
---|
2008 |
|
---|
2009 | # import_C の中でのウォーニング?
|
---|
2010 | if @@import_C then
|
---|
2011 | C_parser.warning( msg )
|
---|
2012 | else
|
---|
2013 | if @@b_end_all_parse == false || locale == nil then
|
---|
2014 | locale = @@current_locale[ @@generator_nest ]
|
---|
2015 | end
|
---|
2016 | if locale then
|
---|
2017 | Console.puts "#{locale[0]}:#{locale[1]}:#{locale[2]}: warning: #{msg}"
|
---|
2018 | else
|
---|
2019 | Console.puts "warning: #{msg}"
|
---|
2020 | end
|
---|
2021 | end
|
---|
2022 | end
|
---|
2023 |
|
---|
2024 | # このメソッドは構文解析、意味解析からのみ呼出し可
|
---|
2025 | def self.info( msg, *arg )
|
---|
2026 | locale = nil
|
---|
2027 | self.info2( locale, msg, *arg )
|
---|
2028 | end
|
---|
2029 |
|
---|
2030 | def self.info2( locale, msg, *arg )
|
---|
2031 | @@n_info += 1
|
---|
2032 |
|
---|
2033 | msg = TECSMsg.get_info_message( msg )
|
---|
2034 | # $1, $2, ... を arg で置換
|
---|
2035 | count = 1
|
---|
2036 | arg.each{ |a|
|
---|
2037 | str = TECSIO.str_code_convert( msg, a.to_s )
|
---|
2038 | msg.sub!( /\$#{count}/, str )
|
---|
2039 | count += 1
|
---|
2040 | }
|
---|
2041 |
|
---|
2042 | # import_C の中でのウォーニング?
|
---|
2043 | if @@import_C then
|
---|
2044 | C_parser.info( msg )
|
---|
2045 | else
|
---|
2046 | if @@b_end_all_parse == false || locale == nil then
|
---|
2047 | locale = @@current_locale[ @@generator_nest ]
|
---|
2048 | end
|
---|
2049 | if locale then
|
---|
2050 | Console.puts "#{locale[0]}:#{locale[1]}:#{locale[2]}: info: #{msg}"
|
---|
2051 | else
|
---|
2052 | Console.puts "info: #{msg}"
|
---|
2053 | end
|
---|
2054 | end
|
---|
2055 | end
|
---|
2056 |
|
---|
2057 | def self.get_n_error
|
---|
2058 | @@n_error
|
---|
2059 | end
|
---|
2060 |
|
---|
2061 | def self.get_n_warning
|
---|
2062 | @@n_warning
|
---|
2063 | end
|
---|
2064 |
|
---|
2065 | def self.get_n_info
|
---|
2066 | @@n_info
|
---|
2067 | end
|
---|
2068 |
|
---|
2069 | def self.get_nest
|
---|
2070 | @@generator_nest
|
---|
2071 | end
|
---|
2072 |
|
---|
2073 | def self.parsing_C?
|
---|
2074 | @@import_C
|
---|
2075 | end
|
---|
2076 |
|
---|
2077 | #=== '[' specifier 始め
|
---|
2078 | def set_in_specifier
|
---|
2079 | # p "set_in_specifier"
|
---|
2080 | @in_specifier = true
|
---|
2081 | end
|
---|
2082 |
|
---|
2083 | #=== ']' specifier 終わり
|
---|
2084 | def unset_in_specifier
|
---|
2085 | # p "unset_in_specifier"
|
---|
2086 | @in_specifier = false
|
---|
2087 | end
|
---|
2088 |
|
---|
2089 | # statement_specifier は構文解釈途中で参照したいため
|
---|
2090 | @@statement_specifier_stack = []
|
---|
2091 | def self.add_statement_specifier( ss )
|
---|
2092 | if( @@statement_specifier_stack[ @@generator_nest ] == nil )then
|
---|
2093 | @@statement_specifier_stack[ @@generator_nest ] = [ ss ]
|
---|
2094 | else
|
---|
2095 | @@statement_specifier_stack[ @@generator_nest ] << ss
|
---|
2096 | end
|
---|
2097 | end
|
---|
2098 |
|
---|
2099 |
|
---|
2100 | def self.get_statement_specifier
|
---|
2101 | spec_list = @@statement_specifier_stack[ @@generator_nest ]
|
---|
2102 | @@statement_specifier_stack[ @@generator_nest ] = nil
|
---|
2103 | return spec_list
|
---|
2104 | end
|
---|
2105 |
|
---|
2106 | #=== すべての構文解析が完了したことを報告
|
---|
2107 | def self.end_all_parse
|
---|
2108 | @@b_end_all_parse = true
|
---|
2109 | end
|
---|
2110 |
|
---|
2111 | ---- footer
|
---|
2112 |
|
---|
2113 |
|
---|
2114 | # ファイル => INCLUDE("header")の配列
|
---|
2115 | Include = Hash.new {|hash, key| hash[key] = []}
|
---|
2116 |
|
---|
2117 |
|
---|
2118 | class Token
|
---|
2119 |
|
---|
2120 | attr_accessor :val, :file, :lineno, :col
|
---|
2121 |
|
---|
2122 | def initialize(val, file, lineno, col)
|
---|
2123 | @val = val
|
---|
2124 | @file = file
|
---|
2125 | @lineno = lineno
|
---|
2126 | @col = col
|
---|
2127 |
|
---|
2128 | end
|
---|
2129 |
|
---|
2130 | def to_s
|
---|
2131 | @val.to_s
|
---|
2132 | end
|
---|
2133 |
|
---|
2134 | def to_sym
|
---|
2135 | @val.to_sym
|
---|
2136 | end
|
---|
2137 |
|
---|
2138 | def get_name
|
---|
2139 | @val
|
---|
2140 | end
|
---|
2141 |
|
---|
2142 | def locale
|
---|
2143 | [@file, @lineno, @col]
|
---|
2144 | end
|
---|
2145 |
|
---|
2146 | def eql?(other)
|
---|
2147 | if other.is_a? Symbol
|
---|
2148 | @val == other
|
---|
2149 | elsif other.is_a? Token
|
---|
2150 | @val == other.val
|
---|
2151 | elsif other.is_a? String
|
---|
2152 | @val.to_s == other
|
---|
2153 | else
|
---|
2154 | raise ArgumentError
|
---|
2155 | end
|
---|
2156 | end
|
---|
2157 |
|
---|
2158 | alias == eql?
|
---|
2159 |
|
---|
2160 | def show_tree( indent )
|
---|
2161 | indent.times { print " " }
|
---|
2162 | print "#{@val}\n"
|
---|
2163 | end
|
---|
2164 |
|
---|
2165 | end
|
---|
2166 |
|
---|
2167 | #= TECSIO
|
---|
2168 | # Ruby2.0(1.9) 対応に伴い導入したクラス
|
---|
2169 | # SJIS 以外では、ASCII-8BIT として入力する
|
---|
2170 | class TECSIO
|
---|
2171 | def self.foreach(file) # ブロック引数 { |line| }
|
---|
2172 | pr = Proc.new # このメソッドのブロック引数を pr に代入
|
---|
2173 | if $b_no_kcode then
|
---|
2174 | msg = "E".encode $Ruby19_File_Encode
|
---|
2175 | if( $Ruby19_File_Encode == "Shift_JIS" )
|
---|
2176 |
|
---|
2177 | # Shift JIS は、いったん Windows-31J として読み込ませ、Shift_JIS に変換させる.
|
---|
2178 | # コメント等に含まれる SJIS に不適切な文字コードは '?' または REPLACEMENT CHARACTER に変換される.
|
---|
2179 | # EUC や UTF-8 で記述された CDL が混在していても、Ruby 例外が発生することなく処理を進めることができる.
|
---|
2180 | # 文字コード指定が SJIS であって、文字列リテラルの中に、文字コードがSJIS 以外の非 ASCII が含まれている場合、
|
---|
2181 | # Ruby 1.8 の tecsgen では文字コード指定に影響なく処理されたものが、Ruby 1.9 以降では '?' に置き換わる可能性がある.
|
---|
2182 |
|
---|
2183 | mode = "r:Windows-31J"
|
---|
2184 | else
|
---|
2185 | mode = "r:#{$Ruby19_File_Encode}"
|
---|
2186 | end
|
---|
2187 | # mode = "r"
|
---|
2188 | else
|
---|
2189 | msg = "E"
|
---|
2190 | mode = "r"
|
---|
2191 | end
|
---|
2192 |
|
---|
2193 | f = File.open( file, mode )
|
---|
2194 | begin
|
---|
2195 | f.each{ |line|
|
---|
2196 | # dbgPrint line
|
---|
2197 | line = str_code_convert( msg, line )
|
---|
2198 | pr.call( line )
|
---|
2199 | }
|
---|
2200 | ensure
|
---|
2201 | f.close
|
---|
2202 | end
|
---|
2203 | end
|
---|
2204 |
|
---|
2205 | #=== 文字コードが相違する場合一致させる
|
---|
2206 | # msg と str の文字コードが相違する場合、str を msg の文字コードに変換する
|
---|
2207 | # 変換不可の文字コードは '?' (utf-8 の場合 U+FFFD (REPLACEMENT CHARACTER )) に変換
|
---|
2208 | #
|
---|
2209 | # このメソッドは、エラーメッセージ出力でも使用されていることに注意.
|
---|
2210 | #
|
---|
2211 | #msg_enc::Encode | String
|
---|
2212 | def self.str_code_convert( msg, str )
|
---|
2213 | if $b_no_kcode == false then
|
---|
2214 | return str # Ruby V1.8 まで
|
---|
2215 | end
|
---|
2216 | if msg.encoding != str.encoding then
|
---|
2217 | option = { :invalid => :replace, :undef => :replace } # 例外を発生させず、'?' に変換する(utf-8 は 0xfffd)
|
---|
2218 | # return str.encode( msg.encoding, option )
|
---|
2219 | str = str.encode( "utf-8", option )
|
---|
2220 | return str.encode( msg.encoding, option )
|
---|
2221 | else
|
---|
2222 | return str
|
---|
2223 | end
|
---|
2224 | end
|
---|
2225 | end
|
---|