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