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.
Files changed (237) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +12 -0
  3. data/.rubocop.yml +125 -0
  4. data/.rubocop_todo.yml +188 -0
  5. data/CHANGELOG.md +3 -0
  6. data/Gemfile +6 -0
  7. data/LICENSE +46 -0
  8. data/LICENSE.ja +32 -0
  9. data/README.ja.md +200 -0
  10. data/README.md +35 -0
  11. data/Rakefile +27 -0
  12. data/bin/tecscde +64 -0
  13. data/glade/tecscde-cell-property.glade +205 -0
  14. data/glade/tecscde-celltype-property.glade +172 -0
  15. data/glade/tecscde-celltype.glade +414 -0
  16. data/glade/tecscde-export.glade +161 -0
  17. data/glade/test-cell-plugin.rb +51 -0
  18. data/glade/test-cell-property.rb +35 -0
  19. data/glade/test-export.rb +35 -0
  20. data/glade/test-palette.rb +26 -0
  21. data/lib/tcflow.rb +148 -0
  22. data/lib/tecscde.rb +65 -0
  23. data/lib/tecscde/NewCell.png +0 -0
  24. data/lib/tecscde/SelectArrow.png +0 -0
  25. data/lib/tecscde/attr_tree_view.rb +253 -0
  26. data/lib/tecscde/cell_plugin_dialog.glade +294 -0
  27. data/lib/tecscde/cell_plugin_dialog.rb +89 -0
  28. data/lib/tecscde/celltype_tree_view.rb +105 -0
  29. data/lib/tecscde/change_set_control.rb +35 -0
  30. data/lib/tecscde/change_set_control/change_set.rb +32 -0
  31. data/lib/tecscde/change_set_control/change_set_manager.rb +62 -0
  32. data/lib/tecscde/command.rb +35 -0
  33. data/lib/tecscde/control.rb +491 -0
  34. data/lib/tecscde/highlighted_objects.rb +180 -0
  35. data/lib/tecscde/logger.rb +74 -0
  36. data/lib/tecscde/main_view_and_model.rb +80 -0
  37. data/lib/tecscde/palette.glade +553 -0
  38. data/lib/tecscde/palette.rb +174 -0
  39. data/lib/tecscde/preferences.glade +117 -0
  40. data/lib/tecscde/preferences.rb +44 -0
  41. data/lib/tecscde/tecs_model.rb +1137 -0
  42. data/lib/tecscde/tecs_model/hbar.rb +68 -0
  43. data/lib/tecscde/tecs_model/tm_c_port.rb +122 -0
  44. data/lib/tecscde/tecs_model/tm_c_port_array.rb +98 -0
  45. data/lib/tecscde/tecs_model/tm_cell.rb +496 -0
  46. data/lib/tecscde/tecs_model/tm_e_port.rb +126 -0
  47. data/lib/tecscde/tecs_model/tm_e_port_array.rb +78 -0
  48. data/lib/tecscde/tecs_model/tm_join.rb +293 -0
  49. data/lib/tecscde/tecs_model/tm_join_bar.rb +146 -0
  50. data/lib/tecscde/tecs_model/tm_port.rb +238 -0
  51. data/lib/tecscde/tecs_model/tm_port_array.rb +246 -0
  52. data/lib/tecscde/tecs_model/tm_region.rb +107 -0
  53. data/lib/tecscde/tecs_model/tm_uneditable.rb +68 -0
  54. data/lib/tecscde/tecs_model/vbar.rb +68 -0
  55. data/lib/tecscde/templates/_cell_info.cde.erb +15 -0
  56. data/lib/tecscde/templates/_join_info.cde.erb +28 -0
  57. data/lib/tecscde/templates/main.cde.erb +49 -0
  58. data/lib/tecscde/tm_object.rb +91 -0
  59. data/lib/tecscde/version.rb +4 -0
  60. data/lib/tecscde/view.rb +58 -0
  61. data/lib/tecscde/view/cairo_matrix.rb +90 -0
  62. data/lib/tecscde/view/canvas.rb +59 -0
  63. data/lib/tecscde/view/constants.rb +114 -0
  64. data/lib/tecscde/view/main_view.rb +1245 -0
  65. data/lib/tecsflow.rb +475 -0
  66. data/lib/tecsflow/C_parser.tab.rb +2471 -0
  67. data/lib/tecsflow/C_parser.y.rb +1087 -0
  68. data/lib/tecsflow/classes.rb +421 -0
  69. data/lib/tecsgen.rb +581 -0
  70. data/lib/tecsgen/core/C_parser.tab.rb +2477 -0
  71. data/lib/tecsgen/core/C_parser.y +1032 -0
  72. data/lib/tecsgen/core/bnf-deb.tab.rb +5193 -0
  73. data/lib/tecsgen/core/bnf.tab.rb +5193 -0
  74. data/lib/tecsgen/core/bnf.y +2211 -0
  75. data/lib/tecsgen/core/componentobj.rb +7901 -0
  76. data/lib/tecsgen/core/ctypes.rb +226 -0
  77. data/lib/tecsgen/core/expression.rb +1031 -0
  78. data/lib/tecsgen/core/gen_xml.rb +374 -0
  79. data/lib/tecsgen/core/generate.rb +5206 -0
  80. data/lib/tecsgen/core/location.rb +116 -0
  81. data/lib/tecsgen/core/messages.rb +101 -0
  82. data/lib/tecsgen/core/optimize.rb +456 -0
  83. data/lib/tecsgen/core/plugin.rb +332 -0
  84. data/lib/tecsgen/core/pluginModule.rb +165 -0
  85. data/lib/tecsgen/core/syntaxobj.rb +1234 -0
  86. data/lib/tecsgen/core/tecs_lang.rb +306 -0
  87. data/lib/tecsgen/core/tecsgen.rb +453 -0
  88. data/lib/tecsgen/core/tecsinfo.rb +860 -0
  89. data/lib/tecsgen/core/tool_info.rb +258 -0
  90. data/lib/tecsgen/core/types.rb +1632 -0
  91. data/lib/tecsgen/core/unjoin_plugin.rb +218 -0
  92. data/lib/tecsgen/core/value.rb +650 -0
  93. data/lib/tecsgen/messages/messages_console_en_US.rb +1171 -0
  94. data/lib/tecsgen/messages/messages_console_ja_JP.rb +1171 -0
  95. data/lib/tecsgen/messages/messages_file_en_US.rb +334 -0
  96. data/lib/tecsgen/messages/messages_file_ja_JP.rb +163 -0
  97. data/lib/tecsgen/plugin/ATK1AlarmPlugin.rb +196 -0
  98. data/lib/tecsgen/plugin/ATK1DelayTaskPlugin.rb +106 -0
  99. data/lib/tecsgen/plugin/ATK1EventPlugin.rb +147 -0
  100. data/lib/tecsgen/plugin/ATK1ISRPlugin.rb +174 -0
  101. data/lib/tecsgen/plugin/ATK1KernelPlugin.rb +287 -0
  102. data/lib/tecsgen/plugin/ATK1ResourcePlugin.rb +124 -0
  103. data/lib/tecsgen/plugin/ATK1TaskPlugin.rb +220 -0
  104. data/lib/tecsgen/plugin/C2TECSBridgePlugin.rb +210 -0
  105. data/lib/tecsgen/plugin/CellPlugin.rb +61 -0
  106. data/lib/tecsgen/plugin/CelltypePlugin.rb +72 -0
  107. data/lib/tecsgen/plugin/CompositePlugin.rb +66 -0
  108. data/lib/tecsgen/plugin/DomainPlugin.rb +89 -0
  109. data/lib/tecsgen/plugin/HRP2AlarmHandlerPlugin.rb +76 -0
  110. data/lib/tecsgen/plugin/HRP2Cache.rb +1 -0
  111. data/lib/tecsgen/plugin/HRP2CyclicHandlerPlugin.rb +75 -0
  112. data/lib/tecsgen/plugin/HRP2DataqueuePlugin.rb +68 -0
  113. data/lib/tecsgen/plugin/HRP2EventflagPlugin.rb +68 -0
  114. data/lib/tecsgen/plugin/HRP2FixedSizeMemoryPoolPlugin.rb +68 -0
  115. data/lib/tecsgen/plugin/HRP2HandlerPlugin.rb +117 -0
  116. data/lib/tecsgen/plugin/HRP2KernelObjectPlugin.rb +372 -0
  117. data/lib/tecsgen/plugin/HRP2ObjectPlugin.rb +94 -0
  118. data/lib/tecsgen/plugin/HRP2Plugin.rb +140 -0
  119. data/lib/tecsgen/plugin/HRP2PostHook.rb +111 -0
  120. data/lib/tecsgen/plugin/HRP2PriorityDataqueuePlugin.rb +66 -0
  121. data/lib/tecsgen/plugin/HRP2RPCPlugin.rb +319 -0
  122. data/lib/tecsgen/plugin/HRP2SVCPlugin.rb +473 -0
  123. data/lib/tecsgen/plugin/HRP2SemaphorePlugin.rb +67 -0
  124. data/lib/tecsgen/plugin/HRP2TaskPlugin.rb +200 -0
  125. data/lib/tecsgen/plugin/HRPHandlerPlugin.rb +125 -0
  126. data/lib/tecsgen/plugin/HRPKernelObjectManager.rb +72 -0
  127. data/lib/tecsgen/plugin/HRPKernelObjectPlugin.rb +333 -0
  128. data/lib/tecsgen/plugin/HRPObjectPlugin.rb +93 -0
  129. data/lib/tecsgen/plugin/HRPPlugin.rb +356 -0
  130. data/lib/tecsgen/plugin/HRPRPCPlugin.rb +407 -0
  131. data/lib/tecsgen/plugin/HRPSVCPlugin.rb +859 -0
  132. data/lib/tecsgen/plugin/HRPTaskPlugin.rb +107 -0
  133. data/lib/tecsgen/plugin/Mruby2CBridgePlugin.rb +86 -0
  134. data/lib/tecsgen/plugin/MrubyBridgeCellPlugin.rb +264 -0
  135. data/lib/tecsgen/plugin/MrubyBridgeCelltypePlugin.rb +293 -0
  136. data/lib/tecsgen/plugin/MrubyBridgeCompositePlugin.rb +49 -0
  137. data/lib/tecsgen/plugin/MrubyBridgePlugin.rb +67 -0
  138. data/lib/tecsgen/plugin/MrubyBridgeSignaturePlugin.rb +1307 -0
  139. data/lib/tecsgen/plugin/MrubyInfoBridgePlugin.rb +14 -0
  140. data/lib/tecsgen/plugin/MrubyInfoBridgeSignaturePlugin.rb +994 -0
  141. data/lib/tecsgen/plugin/MultiPlugin.rb +57 -0
  142. data/lib/tecsgen/plugin/NotifierPlugin.rb +1217 -0
  143. data/lib/tecsgen/plugin/OpaqueMarshalerPlugin.rb +81 -0
  144. data/lib/tecsgen/plugin/OpaqueRPCPlugin.rb +323 -0
  145. data/lib/tecsgen/plugin/RPCPlugin.rb +266 -0
  146. data/lib/tecsgen/plugin/RepeatCellPlugin.rb +166 -0
  147. data/lib/tecsgen/plugin/RepeatJoinPlugin.rb +130 -0
  148. data/lib/tecsgen/plugin/SharedOpaqueRPCPlugin.rb +357 -0
  149. data/lib/tecsgen/plugin/SharedRPCPlugin.rb +329 -0
  150. data/lib/tecsgen/plugin/SignaturePlugin.rb +77 -0
  151. data/lib/tecsgen/plugin/TECS2CBridgePlugin.rb +178 -0
  152. data/lib/tecsgen/plugin/TECSInfoPlugin.rb +280 -0
  153. data/lib/tecsgen/plugin/ThroughPlugin.rb +333 -0
  154. data/lib/tecsgen/plugin/TracePlugin.rb +484 -0
  155. data/lib/tecsgen/plugin/lib/GenHRP2Marshaler.rb +761 -0
  156. data/lib/tecsgen/plugin/lib/GenOpaqueMarshaler.rb +1107 -0
  157. data/lib/tecsgen/plugin/lib/GenParamCopy.rb +365 -0
  158. data/lib/tecsgen/plugin/lib/GenTransparentMarshaler.rb +683 -0
  159. data/lib/tecsgen/plugin/lib/MrubyBridgeCelltypePluginModule.rb +283 -0
  160. data/lib/tecsgen/plugin/lib/MrubyBridgeSignaturePluginModule.rb +277 -0
  161. data/lib/tecsgen/version.rb +6 -0
  162. data/samples/FigureSamples/active/active.cde +104 -0
  163. data/samples/FigureSamples/active/active.cdl +20 -0
  164. data/samples/FigureSamples/active/active.pdf +0 -0
  165. data/samples/FigureSamples/active/active.png +0 -0
  166. data/samples/FigureSamples/active/gen/tmp_C_src.c +36 -0
  167. data/samples/FigureSamples/active/gen/tmp_cygwin_tecs.h +1908 -0
  168. data/samples/FigureSamples/active/gen/tmp_plugin_post_code.cdl +0 -0
  169. data/samples/FigureSamples/allocator/allocator-internal.png +0 -0
  170. data/samples/FigureSamples/allocator/allocator.cde +171 -0
  171. data/samples/FigureSamples/allocator/allocator.cdl +58 -0
  172. data/samples/FigureSamples/allocator/allocator.png +0 -0
  173. data/samples/FigureSamples/basic/Makefile +87 -0
  174. data/samples/FigureSamples/basic/SimpleSample-trace.cdl +50 -0
  175. data/samples/FigureSamples/basic/SimpleSample.cde +91 -0
  176. data/samples/FigureSamples/basic/SimpleSample.cdl +47 -0
  177. data/samples/FigureSamples/basic/basic.cde +93 -0
  178. data/samples/FigureSamples/basic/basic.cdl +46 -0
  179. data/samples/FigureSamples/basic/basic.png +0 -0
  180. data/samples/FigureSamples/callback/callback.cde +130 -0
  181. data/samples/FigureSamples/callback/callback.cdl +29 -0
  182. data/samples/FigureSamples/callback/callback.png +0 -0
  183. data/samples/FigureSamples/carray/carray.cde +144 -0
  184. data/samples/FigureSamples/carray/carray.cdl +38 -0
  185. data/samples/FigureSamples/carray/carray.png +0 -0
  186. data/samples/FigureSamples/cearray/cearray.cde +314 -0
  187. data/samples/FigureSamples/cearray/cearray.cdl +60 -0
  188. data/samples/FigureSamples/cearray/cearray.png +0 -0
  189. data/samples/FigureSamples/composite/composite-internal.png +0 -0
  190. data/samples/FigureSamples/composite/composite.cde +216 -0
  191. data/samples/FigureSamples/composite/composite.cdl +95 -0
  192. data/samples/FigureSamples/composite/composite.png +0 -0
  193. data/samples/FigureSamples/earray/earray.cde +142 -0
  194. data/samples/FigureSamples/earray/earray.cdl +38 -0
  195. data/samples/FigureSamples/earray/earray.png +0 -0
  196. data/samples/FigureSamples/join/Makefile +87 -0
  197. data/samples/FigureSamples/join/join.cde +132 -0
  198. data/samples/FigureSamples/join/join.cdl +40 -0
  199. data/samples/FigureSamples/join/join.png +0 -0
  200. data/samples/FigureSamples/relay/Makefile +99 -0
  201. data/samples/FigureSamples/relay/relay-internal.png +0 -0
  202. data/samples/FigureSamples/relay/relay.cde +284 -0
  203. data/samples/FigureSamples/relay/relay.cdl +52 -0
  204. data/samples/FigureSamples/relay/relay.png +0 -0
  205. data/samples/FigureSamples/rpc/Makefile +123 -0
  206. data/samples/FigureSamples/rpc/rpc-expand.png +0 -0
  207. data/samples/FigureSamples/rpc/rpc.cde +245 -0
  208. data/samples/FigureSamples/rpc/rpc.png +0 -0
  209. data/samples/FigureSamples/rpc/rpc_sample.cdl +53 -0
  210. data/samples/SimpleSample/Makefile +25 -0
  211. data/samples/SimpleSample/SimpleSample/Makefile +86 -0
  212. data/samples/SimpleSample/SimpleSample/Makefile-trace +91 -0
  213. data/samples/SimpleSample/SimpleSample/README.txt +106 -0
  214. data/samples/SimpleSample/SimpleSample/SimpleSample-trace.cdl +50 -0
  215. data/samples/SimpleSample/SimpleSample/SimpleSample.cdl +45 -0
  216. data/samples/SimpleSample/SimpleSample/src/tSample.c +77 -0
  217. data/samples/SimpleSample/SimpleSample/src/tSimple.c +48 -0
  218. data/samples/SimpleSample/SimpleSample/src/tecs-types.h +27 -0
  219. data/samples/SimpleSample/SimpleSampleOpaqueRPC/Makefile +51 -0
  220. data/samples/SimpleSample/SimpleSampleOpaqueRPC/Makefile-trace +91 -0
  221. data/samples/SimpleSample/SimpleSampleOpaqueRPC/README.txt +106 -0
  222. data/samples/SimpleSample/SimpleSampleOpaqueRPC/SimpleSample-trace.cdl +80 -0
  223. data/samples/SimpleSample/SimpleSampleOpaqueRPC/SimpleSample.cdl +77 -0
  224. data/samples/SimpleSample/SimpleSampleOpaqueRPC/rSample/Makefile +112 -0
  225. data/samples/SimpleSample/SimpleSampleOpaqueRPC/rSimple/Makefile +109 -0
  226. data/samples/SimpleSample/SimpleSampleOpaqueRPC/src/tSample.c +80 -0
  227. data/samples/SimpleSample/SimpleSampleOpaqueRPC/src/tSimple.c +47 -0
  228. data/samples/SimpleSample/SimpleSampleOpaqueRPC/src/tTaskMain.c +66 -0
  229. data/samples/SimpleSample/SimpleSampleOpaqueRPC/src/tecs-types.h +27 -0
  230. data/samples/SimpleSample/SimpleSampleTransparentRPC/Makefile +125 -0
  231. data/samples/SimpleSample/SimpleSampleTransparentRPC/Makefile-trace +130 -0
  232. data/samples/SimpleSample/SimpleSampleTransparentRPC/SimpleSample-trace.cdl +54 -0
  233. data/samples/SimpleSample/SimpleSampleTransparentRPC/SimpleSample.cdl +53 -0
  234. data/samples/SimpleSample/SimpleSampleTransparentRPC/src/tSample.c +80 -0
  235. data/samples/SimpleSample/SimpleSampleTransparentRPC/src/tSimple.c +54 -0
  236. data/tecscde.gemspec +41 -0
  237. metadata +353 -0
@@ -0,0 +1,1234 @@
1
+ #
2
+ # TECS Generator
3
+ # Generator for TOPPERS Embedded Component System
4
+ #
5
+ # Copyright (C) 2008-2017 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: syntaxobj.rb 2633 2017-04-02 06:02:05Z okuma-top $
37
+ #++
38
+
39
+ # mikan ruby の symbol と文字列の使い分けがどうしてもうまくいかないことが時々あるので name.to_sym を入れることにした
40
+
41
+ #== Node
42
+ #
43
+ # Node の直接の子クラス: C_EXP, Type, BaseVal, BDNode(ほとんどのものは BDNode の子クラス)
44
+ # Node に (BDNodeにも) 入らないもの: Token, Import, Import_C, Generate
45
+ #
46
+ # owner を持たないものが Node となる
47
+ # エラーは、cdl_error を通じて報告する (意味解析が構文解析後に行われる場合には、行番号が正しく出力できる
48
+ #
49
+
50
+ class Node
51
+ # @locale:: [@file, @lineno, @col]
52
+
53
+ def initialize
54
+ @locale = Generator.current_locale
55
+ end
56
+
57
+ #=== エラーを出力する
58
+ def cdl_error(message, *arg)
59
+ Generator.error2(@locale, message, *arg)
60
+ end
61
+
62
+ #=== エラーを出力する
63
+ # locale:: Array(locale info) : 構文解析中は無視される
64
+ def cdl_error2(locale, message, *arg)
65
+ Generator.error2(locale, message, *arg)
66
+ end
67
+
68
+ #=== エラーを出力する
69
+ # locale:: Array(locale info)
70
+ # 構文解析中 cdl_error2 では locale が無視されるため、別に locale を出力する
71
+ def cdl_error3(locale, message, *arg)
72
+ Generator.error(message, *arg)
73
+ Console.puts "check: #{locale[0]}: line #{locale[1]} for above error"
74
+ end
75
+
76
+ #=== ウォーニング出力する
77
+ def cdl_warning(message, *arg)
78
+ Generator.warning2(@locale, message, *arg)
79
+ end
80
+
81
+ #=== ウォーニング出力する
82
+ def cdl_warning2(locale, message, *arg)
83
+ Generator.warning2(locale, message, *arg)
84
+ end
85
+
86
+ #=== 情報を表示する
87
+ def cdl_info(message, *arg)
88
+ Generator.info2(@locale, message, *arg)
89
+ end
90
+
91
+ #=== 情報を表示する
92
+ def cdl_info2(locale, message, *arg)
93
+ Generator.info2(locale, message, *arg)
94
+ end
95
+
96
+ def get_locale
97
+ @locale
98
+ end
99
+
100
+ def set_locale(locale)
101
+ @locale = locale
102
+ end
103
+
104
+ def locale_str
105
+ "locale=( #{@locale[0]}, #{@locale[1]} )"
106
+ end
107
+ end
108
+
109
+ #== 双方向 Node (Bi Direction Node)
110
+ #
111
+ # Node の子クラス
112
+ # owner Node から参照されているもの (owner へのリンクも取り出せる)
113
+ #
114
+ # get_owner で得られるもの
115
+ # FuncHead => Signature
116
+ # Decl => Namespace(const), Typedef(typedef),
117
+ # Celltype, CompositeCelltype(attr,var)
118
+ # Struct(member), ParamDecl(parameter), FuncHead(funchead)
119
+ # Signature, Celltype, CompositeCelltype, Typedef => Namespace
120
+ # , Namespace => Namespace, Generator.class (root Namespace の場合)
121
+ # Cell => Region, CompositeCelltype(in_composite)
122
+ # Port => Celltype, Composite
123
+ # Factory => Celltype
124
+ # Join => Cell
125
+ # CompositeCelltypeJoin => CompositeCelltype
126
+ # Region => Region,
127
+ # ParamDecl => ParamList
128
+ # ParamList => FuncHead
129
+ # Expression => Namespace
130
+ # 大半のものは new_* メソッドで owner Node に伝達される
131
+ # そのメソッドが呼び出されたときに owner Node が記録される
132
+ # new_* がないもの:
133
+ # Decl(parameter), ParamDecl, ParamList, FuncHead, Expression
134
+ #
135
+ # Expression は、owner Node となるものが多くあるが、改造が困難であるため
136
+ # Expression が定義されたときの Namespace を owner Node とする
137
+ # StructType は Type の一種なので owner を持たない
138
+ #
139
+ class BDNode < Node
140
+ # @owner::Node
141
+ # @NamespacePath:: NamespacePath
142
+ # @Generator::
143
+ # @import::Import :
144
+
145
+ def initialize
146
+ super
147
+ @owner = nil
148
+ @NamespacePath = nil
149
+ @import = Import.get_current
150
+ end
151
+
152
+ #=== owner を設定する
153
+ def set_owner(owner)
154
+ dbgPrint "set_owner: #{owner.class.name}\n"
155
+ @owner = owner
156
+ end
157
+
158
+ #=== owner を得る
159
+ # class の説明を参照
160
+ def get_owner
161
+ if @owner.nil?
162
+ raise "Node have no owner #{self.class.name} #{get_name}"
163
+ end
164
+ @owner
165
+ end
166
+ end
167
+
168
+ #== Namespace 名を持つ BDNode
169
+ # Namespace(Region), Signature, Celltype, CompositeCelltype, Cell
170
+ class NSBDNode < BDNode
171
+ def initialize
172
+ super
173
+ end
174
+
175
+ #=== 属する namespace を得る
176
+ # owner を namespace にたどり着くまで上にたどる
177
+ def get_namespace
178
+ if @owner.is_a? Namespace
179
+ return @owner
180
+ elsif !@owner.nil?
181
+ return @owner.get_namespace
182
+ else
183
+ # @owner == nil なら "::"
184
+ if @name != "::"
185
+ raise "non-root namespace has no owner #{self.class.name}##{@name} #{self}"
186
+ end
187
+ return nil
188
+ end
189
+ end
190
+
191
+ def set_namespace_path
192
+ ns = get_namespace
193
+ if ns
194
+ @NamespacePath = ns.get_namespace_path.append(get_name)
195
+ else
196
+ raise "get_namespace_path: no namespace found"
197
+ end
198
+ end
199
+
200
+ #=== NamespacePath を得る
201
+ def get_namespace_path
202
+ return @NamespacePath
203
+ end
204
+
205
+ def is_imported?
206
+ if @import
207
+ return @import.is_imported?
208
+ else
209
+ return false # mikan: 仮 @import が nil になるケースが追求できていない
210
+ end
211
+ end
212
+ end
213
+
214
+ class NamedList
215
+ # @names:: {} of items
216
+ # @items:: [] of items : item の CLASS は get_name メソッドを持つこと get_name の戻り値は Symbol でなくてはならない
217
+ # NamedList を clone_for_composite する場合は、item にもメソッドが必要
218
+ # @type:: string エラーメッセージ
219
+
220
+ def initialize(item, type)
221
+ @names = {}
222
+ @items = []
223
+ @type = type
224
+ add_item(item)
225
+ end
226
+
227
+ #=== 要素を加える
228
+ # parse した時点で加えること(場所を記憶する)
229
+ def add_item(item)
230
+ if item
231
+ assert_name item
232
+ name = item.get_name
233
+ prev = @names[name]
234
+ if prev
235
+ Generator.error("S2001 \'$1\' duplicate $2", name, @type)
236
+ prev_locale = prev.get_locale
237
+ puts "previous: #{prev_locale[0]}: line #{prev_locale[1]} \'#{name}\' defined here"
238
+ return self
239
+ end
240
+
241
+ @names[name] = item
242
+ @items << item
243
+ end
244
+
245
+ return self
246
+ end
247
+
248
+ def change_item(item)
249
+ assert_name item
250
+ name = item.get_name
251
+
252
+ prev_one = @names[name]
253
+ @names[name] = item
254
+
255
+ @items = @items - [prev_one]
256
+ @items << item
257
+ end
258
+
259
+ def del_item(item)
260
+ assert_name item
261
+ name = item.get_name
262
+ @names.delete name
263
+
264
+ @items = @items - [item]
265
+ end
266
+
267
+ def get_item(name)
268
+ if !name.is_a? Symbol
269
+ print "get_item: '#{name}', items are below\n"
270
+ @names.each{|nm, item|
271
+ p nm
272
+ }
273
+ raise "get_item: #{name}: not Symbol"
274
+ end
275
+ if name
276
+ return @names[name.to_sym]
277
+ else
278
+ return nil
279
+ end
280
+ end
281
+
282
+ def get_items
283
+ return @items
284
+ end
285
+
286
+ #=== composite cell を clone した時に要素(JOIN) の clone する
287
+ #
288
+ # mikan このメソッドは Join に特化されているので NamedList から分離すべき
289
+ def clone_for_composite(ct_name, cell_name, locale)
290
+ cl = self.clone
291
+ cl.set_cloned(ct_name, cell_name, locale)
292
+ return cl
293
+ end
294
+
295
+ #=== clone された NamedList インスタンスの参照するもの(item)を clone
296
+ #
297
+ # mikan このメソッドは Join に特化されているので NamedList から分離すべき
298
+ def set_cloned(ct_name, cell_name, locale)
299
+ items = []
300
+ names = {}
301
+ @items.each {|i|
302
+ dbgPrint "NamedList clone #{ct_name}, #{cell_name}, #{i.get_name}\n"
303
+
304
+ cl = i.clone_for_composite(ct_name, cell_name, locale)
305
+ names[cl.get_name] = cl
306
+ items << cl
307
+ }
308
+ @items = items
309
+ @names = names
310
+ end
311
+
312
+ def assert_name(item)
313
+ if !item.get_name.is_a? Symbol
314
+ raise "Not symbol for NamedList item"
315
+ end
316
+ end
317
+
318
+ def show_tree(indent)
319
+ @items.each {|i|
320
+ i.show_tree(indent)
321
+ }
322
+ end
323
+ end
324
+
325
+ class Typedef < BDNode
326
+ # @declarator:: Decl
327
+
328
+ def self.new_decl_list(type_spec_qual_list, decl_list)
329
+ decl_list.each {|decl|
330
+ Typedef.new(type_spec_qual_list, decl)
331
+ }
332
+ end
333
+
334
+ def initialize(type_spec_qual_list, decl)
335
+ super()
336
+ decl.set_type(type_spec_qual_list)
337
+ @declarator = decl
338
+ decl.set_owner self # Decl(Typedef)
339
+
340
+ Namespace.new_typedef(self)
341
+ end
342
+
343
+ def get_name
344
+ @declarator.get_name
345
+ end
346
+
347
+ def get_declarator
348
+ @declarator
349
+ end
350
+
351
+ def show_tree(indent)
352
+ indent.times { print " " }
353
+ puts "Typedef: #{locale_str}"
354
+ @declarator.show_tree(indent + 1)
355
+ end
356
+ end
357
+
358
+ #== 関数頭部
359
+ # signature に登録される関数
360
+ class FuncHead < BDNode
361
+ # @declarator:: Decl
362
+
363
+ def initialize(declarator, type, b_oneway)
364
+ super()
365
+ declarator.set_type(type)
366
+ @declarator = declarator
367
+ @declarator.set_owner self # Decl (FuncHead)
368
+
369
+ if @declarator.get_type.is_a?(FuncType)
370
+ if b_oneway
371
+ @declarator.get_type.set_oneway(b_oneway)
372
+ end
373
+ end
374
+ @declarator.get_type.check_struct_tag :FUNCHEAD
375
+
376
+ # check if return type is pointer
377
+ if declarator.get_type.is_a? FuncType
378
+ if declarator.get_type.get_type.get_original_type.is_a?(PtrType) &&
379
+ Signature.get_current.is_deviate? == false
380
+ cdl_warning("W3004 $1 pointer type has returned. specify deviate or stop return pointer", @declarator.get_identifier)
381
+ end
382
+ end
383
+ end
384
+
385
+ def get_name
386
+ @declarator.get_name
387
+ end
388
+
389
+ def get_declarator
390
+ @declarator
391
+ end
392
+
393
+ def is_oneway?
394
+ if @declarator.is_function?
395
+ return @declarator.get_type.is_oneway?
396
+ end
397
+ return false
398
+ end
399
+
400
+ def is_function?
401
+ @declarator.is_function?
402
+ end
403
+
404
+ #=== FuncHead# 関数の名前を返す
405
+ def get_name
406
+ return @declarator.get_name
407
+ end
408
+
409
+ #=== FuncHead# 関数の戻り値の型を返す
410
+ # types.rb に定義されている型
411
+ # 関数ヘッダの定義として不完全な場合 nil を返す
412
+ def get_return_type
413
+ if is_function?
414
+ return @declarator.get_type.get_type
415
+ end
416
+ end
417
+
418
+ #=== FuncHead# 関数の引数のリストを返す
419
+ # ParamList を返す
420
+ # 関数ヘッダの定義として不完全な場合 nil を返す
421
+ def get_paramlist
422
+ if is_function?
423
+ return @declarator.get_type.get_paramlist
424
+ end
425
+ end
426
+
427
+ def show_tree(indent)
428
+ indent.times { print " " }
429
+ puts "FuncHead: #{locale_str}"
430
+ @declarator.show_tree(indent + 1)
431
+ end
432
+ end
433
+
434
+ #=== 宣言
435
+ # @kind で示される各種の宣言
436
+ class Decl < BDNode
437
+ # @identifer:: String
438
+ # @global_name:: String | nil : String(@kind=TYPEDEF||:CONSTANT), nil(@kind=その他)
439
+ # set_kind にて設定される
440
+ # @type:: ArrayType, FuncType, PtrType, IntType, StructType
441
+ # VoidType, FloatType, DefinedType, BoolType
442
+ # @initializer:: constant_expression, mikan { initlist }
443
+ # @kind:: :VAR, :ATTRIBUTE, :PARAMETER, :TYPEDEF, :CONSTANT, :MEMBER, :FUNCHEAD(signatureの関数定義)
444
+ # @b_referenced:: bool
445
+ #
446
+ # 以下は、@kind が :VAR, :ATTRIBUTE のときに有効
447
+ # @rw:: bool # 古い文法では attr に指定可能だった(消すには generate の修正も必要)
448
+ # @omit:: bool
449
+ # @choice_list:: [String] attr 初期値の選択肢
450
+ # 以下は、@kind が :VAR, :ATTRIBUTE, :MEMBER のときに有効
451
+ # @size_is:: Expression or nil unless specified
452
+ # 以下は、@kind が :MEMBER のときに有効
453
+ # @count_is:: Expression or nil unless specified
454
+ # attr, var の場合、count_is は指定できない
455
+ # @string:: Expression, -1 (length not specified) or nil (not specified)
456
+ #
457
+ # mikan ParamDecl だけ別に設けたが、MemberDecl, AttrDecl なども分けるべきか(?)
458
+
459
+ def initialize(identifier)
460
+ super()
461
+ @identifier = identifier
462
+ @rw = false
463
+ @omit = false
464
+ @size_is = nil
465
+ @count_is = nil
466
+ @string = nil
467
+ @choice_list = nil
468
+ @b_referenced = false
469
+ end
470
+
471
+ def set_initializer(initializer)
472
+ @initializer = initializer
473
+ end
474
+
475
+ def get_initializer
476
+ @initializer
477
+ end
478
+
479
+ def is_function?
480
+ if @type.class == FuncType
481
+ return true
482
+ else
483
+ return false
484
+ end
485
+ end
486
+
487
+ #== Decl の意味的誤りをチェックする
488
+ def check
489
+ # return nil if @type == nil
490
+
491
+ # 構造体タグチェック(ポインタ型から構造体が参照されている場合は、タグの存在をチェックしない)
492
+ @type.check_struct_tag @kind
493
+
494
+ # 型のチェックを行う
495
+ res = @type.check
496
+ if res
497
+ cdl_error("S2002 $1: $2", @identifier, res)
498
+ end
499
+
500
+ # 不要の初期化子をチェックする
501
+ if @initializer
502
+ case @kind
503
+ when :PARAMETER, :TYPEDEF, :MEMBER, :FUNCHEAD
504
+ cdl_error("S2003 $1: $2 cannot have initializer", @identifier, @kind.to_s.downcase)
505
+ when :VAR, :ATTRIBUTE, :CONSTANT
506
+ # p @initializer ここでは代入可能かどうか、チェックしない
507
+ # :VAR, :ATTRIBUTE, :CONSTANT はそれぞれでチェックする
508
+ # return @type.check_init( @identifier, @initializer, @kind )
509
+ else
510
+ raise "unknown kind in Delc::check"
511
+ end
512
+ end
513
+
514
+ if (@type.is_a? ArrayType) && @type.get_subscript.nil? && (@omit == false)
515
+ if @kind == :ATTRIBUTE
516
+ cdl_error("S2004 $1: array subscript must be specified or omit", @identifier)
517
+ elsif @kind == :VAR || @kind == :MEMBER
518
+ cdl_error("S2005 $1: array subscript must be specified", @identifier)
519
+ end
520
+ end
521
+
522
+ return nil
523
+ end
524
+
525
+ #== ポインタレベルを得る
526
+ # 戻り値:
527
+ # 非ポインタ変数 = 0
528
+ # ポインタ変数 = 1
529
+ # 二重ポインタ変数 = 2
530
+ def get_ptr_level
531
+ level = 0
532
+ type = @type
533
+ while 1
534
+ if type.is_a?(PtrType)
535
+ level += 1
536
+ type = type.get_referto
537
+ # elsif type.kind_of?( ArrayType ) then # 添数なし配列はポインタとみなす
538
+ # if type.get_subscript == nil then
539
+ # level += 1
540
+ # type = type.get_type
541
+ # else
542
+ # break
543
+ # end
544
+ # mikan ポインタの添数あり配列のポインタレベルは0でよい?
545
+ elsif type.is_a?(DefinedType)
546
+ type = type.get_type
547
+ # p "DefinedType: #{type} #{type.class}"
548
+ else
549
+ break
550
+ end
551
+ end
552
+ return level
553
+ end
554
+
555
+ def get_name
556
+ @identifier
557
+ end
558
+
559
+ def get_global_name
560
+ @global_name
561
+ end
562
+
563
+ def set_type(type)
564
+ unless @type
565
+ @type = type
566
+ else
567
+ @type.set_type(type) # 葉に設定
568
+ end
569
+ end
570
+
571
+ def get_type
572
+ @type
573
+ end
574
+
575
+ def get_identifier
576
+ @identifier
577
+ end
578
+
579
+ # STAGE: B
580
+ def set_kind(kind)
581
+ @kind = kind
582
+ case kind
583
+ when :TYPEDEF, :CONSTANT
584
+ if Namespace.get_global_name.to_s == ""
585
+ @global_name = @identifier
586
+ else
587
+ @global_name = :"#{Namespace.get_global_name}_#{@identifier}"
588
+ end
589
+ else
590
+ @global_name = nil
591
+ end
592
+ end
593
+
594
+ def get_kind
595
+ @kind
596
+ end
597
+
598
+ def set_specifier_list(spec_list)
599
+ spec_list.each{|spec|
600
+ case spec[0]
601
+ when :RW
602
+ @rw = true
603
+ when :OMIT
604
+ @omit = true
605
+ when :SIZE_IS
606
+ @size_is = spec[1]
607
+ when :COUNT_IS
608
+ @count_is = spec[1]
609
+ when :STRING
610
+ @string = spec[1]
611
+ when :CHOICE
612
+ @choice_list = spec[1]
613
+ else
614
+ raise "Unknown specifier #{spec[0]}"
615
+ end
616
+ }
617
+
618
+ if @size_is || @count_is || @string
619
+ @type.set_scs(@size_is, @count_is, @string, nil, false)
620
+ end
621
+ end
622
+
623
+ def is_rw?
624
+ @rw
625
+ end
626
+
627
+ def is_omit?
628
+ @omit
629
+ end
630
+
631
+ def get_size_is
632
+ @size_is
633
+ end
634
+
635
+ def get_count_is
636
+ @count_is
637
+ end
638
+
639
+ def get_string
640
+ @string
641
+ end
642
+
643
+ def get_choice_list
644
+ @choice_list
645
+ end
646
+
647
+ def referenced
648
+ @b_referenced = true
649
+ end
650
+
651
+ def is_referenced?
652
+ @b_referenced
653
+ end
654
+
655
+ def is_type?(type)
656
+ t = @type
657
+ while 1
658
+ if t.is_a?(type)
659
+ return true
660
+ elsif t.is_a?(DefinedType)
661
+ t = t.get_type
662
+ else
663
+ return false
664
+ end
665
+ end
666
+ end
667
+
668
+ def is_const?
669
+ type = @type
670
+ while 1
671
+ if type.is_const?
672
+ return true
673
+ elsif type.is_a?(DefinedType)
674
+ type = type.get_type
675
+ else
676
+ return false
677
+ end
678
+ end
679
+ end
680
+
681
+ def show_tree(indent)
682
+ indent.times { print " " }
683
+ puts "Declarator: name: #{@identifier} kind: #{@kind} global_name: #{@global_name} #{locale_str}"
684
+ (indent + 1).times { print " " }
685
+ puts "type:"
686
+ @type.show_tree(indent + 2)
687
+ if @initializer
688
+ (indent + 1).times { print " " }
689
+ puts "initializer:"
690
+ @initializer.show_tree(indent + 2)
691
+ else
692
+ (indent + 1).times { print " " }
693
+ puts "initializer: no"
694
+ end
695
+ (indent + 1).times { print " " }
696
+ puts "size_is: #{@size_is}, count_is: #{@count_is}, string: #{@string} referenced: #{@b_referenced} "
697
+ end
698
+ end
699
+
700
+ # 関数パラメータの宣言
701
+ class ParamDecl < BDNode
702
+ # @declarator:: Decl: Token, ArrayType, FuncType, PtrType
703
+ # @direction:: :IN, :OUT, :INOUT, :SEND, :RECEIVE
704
+ # @size:: Expr (size_is 引数)
705
+ # @count:: Expr (count_is 引数)
706
+ # @max:: Expr (size_is の第二引数)
707
+ # @b_nullable:: Bool : nullable
708
+ # @string:: Expr or -1(if size not specified) (string 引数)
709
+ # @allocator:: Signature of allocator
710
+ # @b_ref:: bool : size_is, count_is, string_is 引数として参照されている
711
+ #
712
+ # 1. 関数型でないこと
713
+ # 2. 2次元以上の配列であって最も内側以外の添数があること
714
+ # 3. in, out, ..., size_is, count_is, ... の重複指定がないこと
715
+ # 4. ポインタレベルが適切なこと
716
+
717
+ def initialize(declarator, specifier, param_specifier)
718
+ super()
719
+ @declarator = declarator
720
+ @declarator.set_owner self # Decl (ParamDecl)
721
+ @declarator.set_type(specifier)
722
+ @param_specifier = param_specifier
723
+ @b_ref = false
724
+ @b_nullable = false
725
+
726
+ if @declarator.is_function? # (1)
727
+ cdl_error("S2006 \'$1\' function", get_name)
728
+ return
729
+ end
730
+
731
+ res = @declarator.check
732
+ if res # (2)
733
+ cdl_error("S2007 \'$1\' $2", get_name, res)
734
+ return
735
+ end
736
+
737
+ @param_specifier.each {|i|
738
+ case i[0] # (3)
739
+ when :IN, :OUT, :INOUT, :SEND, :RECEIVE
740
+ if @direction.nil?
741
+ @direction = i[0]
742
+ elsif i[0] == @direction
743
+ cdl_warning("W3001 $1: duplicate", i[0])
744
+ next
745
+ else
746
+ cdl_error("S2008 $1: inconsitent with previous one", i[0])
747
+ next
748
+ end
749
+
750
+ case i[0]
751
+ when :SEND, :RECEIVE
752
+ @allocator = Namespace.find(i[1]) # 1
753
+ if !@allocator.instance_of?(Signature)
754
+ cdl_error("S2009 $1: not found or not signature", i[1])
755
+ next
756
+ elsif !@allocator.is_allocator?
757
+ # cdl_error( "S2010 $1: not allocator signature" , i[1] )
758
+ end
759
+ end
760
+
761
+ when :SIZE_IS
762
+ if @size
763
+ cdl_error("S2011 size_is duplicate")
764
+ else
765
+ @size = i[1]
766
+ end
767
+ when :COUNT_IS
768
+ if @count
769
+ cdl_error("S2012 count_is duplicate")
770
+ else
771
+ @count = i[1]
772
+ end
773
+ when :STRING
774
+ if @string
775
+ cdl_error("S2013 string duplicate")
776
+ elsif i[1]
777
+ @string = i[1]
778
+ else
779
+ @string = -1
780
+ end
781
+ when :MAX_IS
782
+ # max_is は、内部的なもの bnf.y.rb 参照
783
+ # size_is で重複チェックされる
784
+ @max = i[1]
785
+ when :NULLABLE
786
+ # if ! @declarator.get_type.kind_of?( PtrType ) then
787
+ # cdl_error( "S2026 '$1' nullable specified for non-pointer type", @declarator.get_name )
788
+ # else
789
+ @b_nullable = true
790
+ # end
791
+ end
792
+
793
+ }
794
+
795
+ if @direction.nil?
796
+ cdl_error("S2014 No direction specified. [in/out/inout/send/receive]")
797
+ end
798
+
799
+ if (@direction == :OUT || @direction == :INOUT) && @string == -1
800
+ cdl_warning("W3002 $1: this string might cause buffer over run", get_name)
801
+ end
802
+
803
+ # mikan ポインタの配列(添数有)のレベルが0
804
+ ptr_level = @declarator.get_ptr_level
805
+
806
+ # p "ptr_level: #{@declarator.get_identifier} #{ptr_level}"
807
+ # p @declarator
808
+
809
+ #---- set req_level, min_level & max_level ----#
810
+ if !(@size || @count || @string) # (4)
811
+ req_level = 1
812
+ elsif (@size || @count) && @string
813
+ req_level = 2
814
+ else
815
+ req_level = 1
816
+ end
817
+
818
+ if @direction == :RECEIVE
819
+ req_level += 1
820
+ end
821
+ min_level = req_level
822
+ max_level = req_level
823
+
824
+ # IN without pointer specifier can be non-pointer type
825
+ if @direction == :IN && !(@size || @count || @string)
826
+ min_level = 0
827
+ end
828
+
829
+ # if size_is specified and pointer refer to struct, max_level increase
830
+ if @size
831
+ type = @declarator.get_type.get_original_type
832
+ while type.is_a? PtrType
833
+ type = type.get_referto.get_original_type
834
+ end
835
+ if type.is_a? StructType
836
+ max_level += 1
837
+ end
838
+ end
839
+ #---- end req_level & max_level ----#
840
+
841
+ # p "req_level: #{req_level} ptr_level: #{ptr_level}"
842
+ # if ptr_level < req_level && ! ( @direction == :IN && req_level == 1 && ptr_level == 0) then
843
+ if ptr_level < min_level
844
+ cdl_error("S2014 $1 need pointer or more pointer", @declarator.get_identifier)
845
+ elsif ptr_level > max_level
846
+ # note: 構文解析段階で実行のため get_current 可
847
+ if Signature.get_current.nil? || Signature.get_current.is_deviate? == false
848
+ cdl_warning("W3003 $1 pointer level mismatch", @declarator.get_identifier)
849
+ end
850
+ end
851
+
852
+ type = @declarator.get_type
853
+ while type.is_a?(DefinedType)
854
+ type = type.get_original_type
855
+ end
856
+
857
+ if ptr_level > 0
858
+ # size_is, count_is, string をセット
859
+ if @direction == :RECEIVE && ptr_level > 1
860
+ type.get_type.set_scs(@size, @count, @string, @max, @b_nullable)
861
+ else
862
+ type.set_scs(@size, @count, @string, @max, @b_nullable)
863
+ end
864
+
865
+ # p ptr_level
866
+ # type.show_tree 1
867
+
868
+ # ポインタが指している先のデータ型を得る
869
+ i = 0
870
+ t2 = type
871
+ while i < ptr_level
872
+ t2 = t2.get_referto
873
+ while t2.is_a?(DefinedType)
874
+ t2 = t2.get_original_type
875
+ end
876
+ i += 1
877
+ end
878
+
879
+ # p @declarator.get_name
880
+ # t2.show_tree 1
881
+ # p t2.is_const?
882
+
883
+ # const 修飾が適切かチェック
884
+ if @direction == :IN
885
+ if !t2.is_const?
886
+ cdl_error("S2015 '$1' must be const for \'in\' parameter $2", get_name, type.class)
887
+ end
888
+ else
889
+ if t2.is_const?
890
+ cdl_error("S2016 '$1' can not be const for $2 parameter", get_name, @direction)
891
+ end
892
+ end
893
+ else
894
+ # 非ポインタタイプ
895
+ if !@size.nil? || !@count.nil? || !@string.nil? || !@max.nil? || @b_nullable
896
+ type.set_scs(@size, @count, @string, @max, @b_nullable)
897
+ end
898
+ end
899
+
900
+ # if ptr_level > 0 && @direction == :IN then
901
+ # if type.is_const != :CONST
902
+ # end
903
+
904
+ # p self
905
+ end
906
+
907
+ def check_struct_tag(kind)
908
+ @declarator.get_type.check_struct_tag :PARAMETER
909
+ end
910
+
911
+ def get_name
912
+ @declarator.get_name
913
+ end
914
+
915
+ def get_size
916
+ @size
917
+ end
918
+
919
+ def get_count
920
+ @count
921
+ end
922
+
923
+ def get_string
924
+ @string
925
+ end
926
+
927
+ def get_max
928
+ @max
929
+ end
930
+
931
+ def clear_max
932
+ # p "clear_max: #{@declarator.get_name} #{@max.to_s}"
933
+ @max = nil
934
+ @declarator.get_type.clear_max
935
+ end
936
+
937
+ def is_nullable?
938
+ @b_nullable
939
+ end
940
+
941
+ def get_type
942
+ @declarator.get_type
943
+ end
944
+
945
+ def get_direction
946
+ @direction
947
+ end
948
+
949
+ def get_declarator
950
+ @declarator
951
+ end
952
+
953
+ def get_allocator
954
+ @allocator
955
+ end
956
+
957
+ def referenced
958
+ @b_ref = true
959
+ end
960
+
961
+ def is_referenced?
962
+ @b_ref
963
+ end
964
+
965
+ #=== PPAllocator が必要か
966
+ # Transparent RPC の場合 in で size_is, count_is, string のいずれかが指定されている場合 oneway では PPAllocator が必要
967
+ # Transparent PC で oneway かどうかは、ここでは判断しないので別途判断が必要
968
+ # Opaque RPC の場合 size_is, count_is, string のいずれかが指定されている場合、PPAllocator が必要
969
+ def need_PPAllocator?(b_opaque = false)
970
+ if !b_opaque
971
+ # if @direction == :IN && ( @size || @count || @string ) then
972
+ if @direction == :IN && @declarator.get_type.get_original_type.is_a?(PtrType)
973
+ return true
974
+ end
975
+ else
976
+ if (@direction == :IN || @direction == :OUT || @direction == :INOUT) &&
977
+ @declarator.get_type.get_original_type.is_a?(PtrType)
978
+ return true
979
+ end
980
+ end
981
+ return false
982
+ end
983
+
984
+ def show_tree(indent)
985
+ indent.times { print " " }
986
+ puts "ParamDecl: direction: #{@direction} #{locale_str}"
987
+ @declarator.show_tree(indent + 1)
988
+ if @size
989
+ (indent + 1).times { print " " }
990
+ puts "size:"
991
+ @size.show_tree(indent + 2)
992
+ end
993
+ if @count
994
+ (indent + 1).times { print " " }
995
+ puts "count:"
996
+ @count.show_tree(indent + 2)
997
+ end
998
+ if @string
999
+ (indent + 1).times { print " " }
1000
+ puts "string:"
1001
+ if @string == -1
1002
+ (indent + 2).times { print " " }
1003
+ puts "size is not specified"
1004
+ else
1005
+ @string.show_tree(indent + 2)
1006
+ end
1007
+ end
1008
+ if @allocator
1009
+ (indent + 1).times { print " " }
1010
+ puts "allocator: signature: #{@allocator.get_name}"
1011
+ end
1012
+ end
1013
+ end
1014
+
1015
+ # 関数パラメータリスト
1016
+ class ParamList < BDNode
1017
+ # @param_list:: NamedList : item: ParamDecl
1018
+
1019
+ def initialize(paramdecl)
1020
+ super()
1021
+ @param_list = NamedList.new(paramdecl, "parameter")
1022
+ @param_list.get_items.each {|paramdecl|
1023
+ paramdecl.set_owner self # ParamDecl
1024
+ }
1025
+ end
1026
+
1027
+ def add_param(paramdecl)
1028
+ return if paramdecl.nil? # 既にエラー
1029
+
1030
+ @param_list.add_item(paramdecl)
1031
+ paramdecl.set_owner self # ParamDecl
1032
+ end
1033
+
1034
+ def get_items
1035
+ @param_list.get_items
1036
+ end
1037
+
1038
+ #=== size_is, count_is, string の引数の式をチェック
1039
+ # 変数は前方参照可能なため、関数頭部の構文解釈が終わった後にチェックする
1040
+ def check_param
1041
+ @param_list.get_items.each {|i|
1042
+ next if i.nil? # i == nil : エラー時
1043
+
1044
+ if i.get_type.class == VoidType
1045
+ # 単一の void 型はここにはこない
1046
+ cdl_error("S2027 '$1' parameter cannot be void type", i.get_name)
1047
+ end
1048
+
1049
+ size = i.get_size # Expression
1050
+ if size
1051
+ val = size.eval_const(@param_list)
1052
+ if val.nil? # 定数式でないか?
1053
+ # mikan 変数を含む式:単一の変数のみ OK
1054
+ type = size.get_type(@param_list)
1055
+ unless type.is_a?(IntType)
1056
+ cdl_error("S2017 size_is argument is not integer type")
1057
+ else
1058
+ size.check_dir_for_param(@param_list, i.get_direction, "size_is")
1059
+ end
1060
+ else
1061
+ if val != Integer(val)
1062
+ cdl_error("S2018 \'$1\' size_is parameter not integer", i.get_declarator.get_identifier)
1063
+ elsif val <= 0
1064
+ cdl_error("S2019 \'$1\' size_is parameter negative or zero", i.get_declarator.get_identifier)
1065
+ end
1066
+ end
1067
+ end
1068
+
1069
+ max = i.get_max
1070
+ if max
1071
+ val2 = max.eval_const(@param_list)
1072
+ if val2.nil?
1073
+ cdl_error("S2028 '$1' max (size_is 2nd parameter) not constant", i.get_name)
1074
+ elsif val2 != Integer(val2) || val2 <= 0
1075
+ cdl_error("S2029 '$1' max (size_is 2nd parameter) negative or zero, or not integer", i.get_name)
1076
+ end
1077
+ end
1078
+
1079
+ if !val.nil? && !val2.nil?
1080
+ if val < val2
1081
+ cdl_warning("W3005 '$1' size_is always lower than max. max is ignored", i.get_name)
1082
+ i.clear_max
1083
+ else
1084
+ cdl_error("S2030 '$1' both size_is and max are const. size_is larger than max", i.get_name)
1085
+ end
1086
+ end
1087
+
1088
+ count = i.get_count # Expression
1089
+ if count
1090
+ val = count.eval_const(@param_list)
1091
+ if val.nil? # 定数式でないか?
1092
+ # mikan 変数を含む式:単一の変数のみ OK
1093
+ type = count.get_type(@param_list)
1094
+ unless type.is_a?(IntType)
1095
+ cdl_error("S2020 count_is argument is not integer type")
1096
+ else
1097
+ count.check_dir_for_param(@param_list, i.get_direction, "count_is")
1098
+ end
1099
+ else
1100
+ if val != Integer(val)
1101
+ cdl_error("S2021 \'$1\' count_is parameter not integer", i.get_declarator.get_identifier)
1102
+ elsif val <= 0
1103
+ cdl_error("S2022 \'$1\' count_is parameter negative or zero", i.get_declarator.get_identifier)
1104
+ end
1105
+ end
1106
+ end
1107
+
1108
+ string = i.get_string # Expression
1109
+ if string != -1 && string
1110
+ val = string.eval_const(@param_list)
1111
+ if val.nil? # 定数式でないか?
1112
+ # mikan 変数を含む式:単一の変数のみ OK
1113
+ type = string.get_type(@param_list)
1114
+ unless type.is_a?(IntType)
1115
+ cdl_error("S2023 string argument is not integer type")
1116
+ else
1117
+ string.check_dir_for_param(@param_list, i.get_direction, "string")
1118
+ end
1119
+ else
1120
+ if val != Integer(val)
1121
+ cdl_error("S2024 \'$1\' string parameter not integer", i.get_declarator.get_identifier)
1122
+ elsif val <= 0
1123
+ cdl_error("S2025 \'$1\' string parameter negative or zero", i.get_declarator.get_identifier)
1124
+ end
1125
+ end
1126
+ end
1127
+ }
1128
+ end
1129
+
1130
+ def check_struct_tag(kind)
1131
+ @param_list.get_items.each{|p|
1132
+ p.check_struct_tag kind
1133
+ }
1134
+ end
1135
+
1136
+ #=== Push Pop Allocator が必要か?
1137
+ # Transparent RPC の場合 (oneway かつ) in の配列(size_is, count_is, string のいずれかで修飾)がある
1138
+ def need_PPAllocator?(b_opaque = false)
1139
+ @param_list.get_items.each {|i|
1140
+ if i.need_PPAllocator?(b_opaque)
1141
+ return true
1142
+ end
1143
+ }
1144
+ false
1145
+ end
1146
+
1147
+ def find(name)
1148
+ @param_list.get_item(name)
1149
+ end
1150
+
1151
+ #== ParamList# 文字列化
1152
+ # b_name:: Bool: パラメータ名を含める
1153
+ def to_str(b_name)
1154
+ str = "("
1155
+ delim = ""
1156
+ @param_list.get_items.each{|paramdecl|
1157
+ decl = paramdecl.get_declarator
1158
+ str += delim + decl.get_type
1159
+ if b_name
1160
+ str += " " + decl.get_name
1161
+ end
1162
+ str += decl.get_type_post
1163
+ delim = ", "
1164
+ }
1165
+ str += ")"
1166
+ end
1167
+
1168
+ def show_tree(indent)
1169
+ indent.times { print " " }
1170
+ puts "ParamList: #{locale_str}"
1171
+ @param_list.show_tree(indent + 1)
1172
+ end
1173
+ end
1174
+
1175
+ #== CDL の文字列リテラルを扱うためのクラス
1176
+ # CDL の文字列リテラルそのものではない
1177
+ class CDLString
1178
+ # エスケープ文字を変換
1179
+ def self.escape(str)
1180
+ str = str.dup
1181
+ str.gsub!(/\\a/, "\x07")
1182
+ str.gsub!(/\\b/, "\x08")
1183
+ str.gsub!(/\\f/, "\x0c")
1184
+ str.gsub!(/\\n/, "\x0a")
1185
+ str.gsub!(/\\r/, "\x0d")
1186
+ str.gsub!(/\\t/, "\x08")
1187
+ str.gsub!(/\\v/, "\x0b")
1188
+ str.gsub!(/(\\[Xx][0-9A-Fa-f]{1,2})/, '{printf \"\\1\"}')
1189
+ str.gsub!(/(\\[0-7]{1,3})/, '{printf \"\\1\"}')
1190
+ str.gsub!(/\\(.)/, "\\1") # mikan 未定義のエスケープシーケンスを変換してしまう (gcc V3.4.4 では警告が出される)
1191
+ return str
1192
+ end
1193
+
1194
+ #=== CDLString#前後の " を取り除く
1195
+ def self.remove_dquote(str)
1196
+ s = str.sub(/\A"/, "")
1197
+ s.sub!(/"\z/, "")
1198
+ return s
1199
+ end
1200
+ end
1201
+
1202
+ #== CDL の初期化子を扱うためのクラス
1203
+ # CDL の初期化子そのものではない
1204
+ class CDLInitializer
1205
+ #=== 初期化子のクローン
1206
+ # 初期化子は Expression, C_EXP, Array のいずれか
1207
+ def self.clone_for_composite(rhs, ct_name, cell_name, locale)
1208
+ if rhs.instance_of? C_EXP
1209
+ # C_EXP の clone を作るとともに置換
1210
+ rhs = rhs.clone_for_composite(ct_name, cell_name, locale)
1211
+ elsif rhs.instance_of? Expression
1212
+ rhs = rhs.clone_for_composite
1213
+ elsif rhs.instance_of? Array
1214
+ rhs = clone_for_compoiste_array(rhs, ct_name, cell_name, locale)
1215
+ else
1216
+ raise "unknown rhs for join"
1217
+ end
1218
+ return rhs
1219
+ end
1220
+
1221
+ #=== 初期化子(配列)のクローン
1222
+ # 要素は clone_for_composite を持つものだけ
1223
+ def self.clone_for_compoiste_array(array, ct_name, cell_name, locale)
1224
+ # "compoiste.identifier" の場合 (CDL としては誤り)
1225
+ if array[0] == :COMPOSITE
1226
+ return array.clone
1227
+ end
1228
+
1229
+ new_array = array.map{|m|
1230
+ clone_for_composite(m, ct_name, cell_name, locale)
1231
+ }
1232
+ return new_array
1233
+ end
1234
+ end