r2corba 1.6.1-x64-mingw-ucrt

Sign up to get free protection for your applications and to get access to all the features.
Files changed (237) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGES +173 -0
  3. data/LICENSE +59 -0
  4. data/README.rdoc +62 -0
  5. data/THANKS +54 -0
  6. data/bin/r2corba +8 -0
  7. data/bin/r2corba.bat +20 -0
  8. data/bin/ridlc +11 -0
  9. data/bin/ridlc.bat +23 -0
  10. data/bin/rins +7 -0
  11. data/bin/rins.bat +19 -0
  12. data/ext/.keep +0 -0
  13. data/lib/corba/cbase/IORMap.rb +32 -0
  14. data/lib/corba/cbase/ORB.rb +239 -0
  15. data/lib/corba/cbase/Request.rb +133 -0
  16. data/lib/corba/cbase/Streams.rb +128 -0
  17. data/lib/corba/cbase/Stub.rb +18 -0
  18. data/lib/corba/cbase/Typecode.rb +440 -0
  19. data/lib/corba/cbase/Values.rb +130 -0
  20. data/lib/corba/cbase/exception.rb +67 -0
  21. data/lib/corba/cbase/poa.rb +22 -0
  22. data/lib/corba/cbase/policies.rb +77 -0
  23. data/lib/corba/cbase/post_require.rb +13 -0
  24. data/lib/corba/cbase/require.rb +36 -0
  25. data/lib/corba/cmds/base.rb +84 -0
  26. data/lib/corba/cmds/test.rb +29 -0
  27. data/lib/corba/common/Any.rb +91 -0
  28. data/lib/corba/common/IDL.rb +100 -0
  29. data/lib/corba/common/ORB.rb +367 -0
  30. data/lib/corba/common/Object.rb +211 -0
  31. data/lib/corba/common/Request.rb +19 -0
  32. data/lib/corba/common/Servant.rb +107 -0
  33. data/lib/corba/common/Struct.rb +21 -0
  34. data/lib/corba/common/Stub.rb +78 -0
  35. data/lib/corba/common/Typecode.rb +1147 -0
  36. data/lib/corba/common/Union.rb +60 -0
  37. data/lib/corba/common/Values.rb +92 -0
  38. data/lib/corba/common/const.rb +21 -0
  39. data/lib/corba/common/exception.rb +68 -0
  40. data/lib/corba/common/require.rb +34 -0
  41. data/lib/corba/common/version.rb +21 -0
  42. data/lib/corba/idl/BiDirPolicyC.rb +62 -0
  43. data/lib/corba/idl/CosNamingC.rb +460 -0
  44. data/lib/corba/idl/CosNamingS.rb +308 -0
  45. data/lib/corba/idl/IDL.rb +20 -0
  46. data/lib/corba/idl/IORTable.pidl +61 -0
  47. data/lib/corba/idl/IORTableC.rb +116 -0
  48. data/lib/corba/idl/MessagingC.rb +903 -0
  49. data/lib/corba/idl/POAC.rb +929 -0
  50. data/lib/corba/idl/TAO_Ext.pidl +45 -0
  51. data/lib/corba/idl/TAO_ExtC.rb +178 -0
  52. data/lib/corba/idl/r2c_orb.rb +571 -0
  53. data/lib/corba/idl/require.rb +19 -0
  54. data/lib/corba/jbase/Any.rb +274 -0
  55. data/lib/corba/jbase/IORMap.rb +35 -0
  56. data/lib/corba/jbase/ORB.rb +111 -0
  57. data/lib/corba/jbase/Object.rb +98 -0
  58. data/lib/corba/jbase/Request.rb +225 -0
  59. data/lib/corba/jbase/Servant.rb +247 -0
  60. data/lib/corba/jbase/ServerRequest.rb +127 -0
  61. data/lib/corba/jbase/Streams.rb +734 -0
  62. data/lib/corba/jbase/Stub.rb +37 -0
  63. data/lib/corba/jbase/Typecode.rb +520 -0
  64. data/lib/corba/jbase/Values.rb +174 -0
  65. data/lib/corba/jbase/exception.rb +106 -0
  66. data/lib/corba/jbase/poa.rb +228 -0
  67. data/lib/corba/jbase/policies.rb +299 -0
  68. data/lib/corba/jbase/post_require.rb +13 -0
  69. data/lib/corba/jbase/require.rb +92 -0
  70. data/lib/corba/naming.rb +13 -0
  71. data/lib/corba/naming_service.rb +14 -0
  72. data/lib/corba/poa.rb +14 -0
  73. data/lib/corba/policies.rb +17 -0
  74. data/lib/corba/require.rb +16 -0
  75. data/lib/corba/svcs/ins/cos_naming.rb +432 -0
  76. data/lib/corba/svcs/ins/ins.rb +525 -0
  77. data/lib/corba/svcs/ins/naming_service.rb +118 -0
  78. data/lib/corba.rb +15 -0
  79. data/lib/ridlbe/ruby/config.rb +340 -0
  80. data/lib/ridlbe/ruby/orb.pidlc +0 -0
  81. data/lib/ridlbe/ruby/require.rb +15 -0
  82. data/lib/ridlbe/ruby/walker.rb +1605 -0
  83. data/mkrf_conf_bingem.rb +149 -0
  84. data/rakelib/bin.rake +79 -0
  85. data/rakelib/bin.rb +145 -0
  86. data/rakelib/build.rake +87 -0
  87. data/rakelib/config.rake +51 -0
  88. data/rakelib/config.rb +542 -0
  89. data/rakelib/ext.rake +183 -0
  90. data/rakelib/ext.rb +277 -0
  91. data/rakelib/ext_r2tao.rb +208 -0
  92. data/rakelib/gem.rake +251 -0
  93. data/rakelib/gem.rb +145 -0
  94. data/rakelib/package.rake +25 -0
  95. data/rakelib/test.rake +22 -0
  96. data/test/BiDirectional/Test.idl +33 -0
  97. data/test/BiDirectional/client.rb +131 -0
  98. data/test/BiDirectional/run_test.rb +67 -0
  99. data/test/BiDirectional/server.rb +167 -0
  100. data/test/CORBA_Services/Naming/BindingIterator/Test.idl +26 -0
  101. data/test/CORBA_Services/Naming/BindingIterator/client.rb +120 -0
  102. data/test/CORBA_Services/Naming/BindingIterator/run_test.rb +81 -0
  103. data/test/CORBA_Services/Naming/BindingIterator/server.rb +108 -0
  104. data/test/CORBA_Services/Naming/Corbaname/Test.idl +26 -0
  105. data/test/CORBA_Services/Naming/Corbaname/client.rb +84 -0
  106. data/test/CORBA_Services/Naming/Corbaname/run_test.rb +87 -0
  107. data/test/CORBA_Services/Naming/Corbaname/server.rb +134 -0
  108. data/test/CORBA_Services/Naming/Simple/Test.idl +26 -0
  109. data/test/CORBA_Services/Naming/Simple/client.rb +83 -0
  110. data/test/CORBA_Services/Naming/Simple/run_test.rb +81 -0
  111. data/test/CORBA_Services/Naming/Simple/server.rb +108 -0
  112. data/test/Collocation/Diamond.idl +38 -0
  113. data/test/Collocation/run_test.rb +51 -0
  114. data/test/Collocation/test.rb +201 -0
  115. data/test/Connect_Timeout/Test.idl +26 -0
  116. data/test/Connect_Timeout/client.rb +109 -0
  117. data/test/Connect_Timeout/run_test.rb +51 -0
  118. data/test/DII/Test.idl +26 -0
  119. data/test/DII/client.rb +114 -0
  120. data/test/DII/run_test.rb +68 -0
  121. data/test/DII/server.rb +94 -0
  122. data/test/DSI/Test.idl +26 -0
  123. data/test/DSI/client.rb +65 -0
  124. data/test/DSI/run_test.rb +68 -0
  125. data/test/DSI/server.rb +105 -0
  126. data/test/Exceptions/Test.idl +47 -0
  127. data/test/Exceptions/client.rb +117 -0
  128. data/test/Exceptions/run_test.rb +68 -0
  129. data/test/Exceptions/server.rb +130 -0
  130. data/test/Hello/Test.idl +26 -0
  131. data/test/Hello/client.rb +77 -0
  132. data/test/Hello/run_test.rb +70 -0
  133. data/test/Hello/server.rb +94 -0
  134. data/test/IDL_Test/Test.idl +116 -0
  135. data/test/IDL_Test/Test_inc.idl +17 -0
  136. data/test/IDL_Test/client.rb +103 -0
  137. data/test/IDL_Test/run_test.rb +68 -0
  138. data/test/IDL_Test/server.rb +103 -0
  139. data/test/IORMap/Test.idl +26 -0
  140. data/test/IORMap/client.rb +72 -0
  141. data/test/IORMap/run_test.rb +68 -0
  142. data/test/IORMap/server.rb +113 -0
  143. data/test/IORTable/Test.idl +26 -0
  144. data/test/IORTable/client.rb +74 -0
  145. data/test/IORTable/run_test.rb +68 -0
  146. data/test/IORTable/server.rb +129 -0
  147. data/test/Implicit_Conversion/Test.idl +30 -0
  148. data/test/Implicit_Conversion/client.rb +112 -0
  149. data/test/Implicit_Conversion/run_test.rb +68 -0
  150. data/test/Implicit_Conversion/server.rb +98 -0
  151. data/test/Multi_Threading/Multiple_ORB/Test.idl +26 -0
  152. data/test/Multi_Threading/Multiple_ORB/client.rb +81 -0
  153. data/test/Multi_Threading/Multiple_ORB/run_test.rb +70 -0
  154. data/test/Multi_Threading/Multiple_ORB/server.rb +107 -0
  155. data/test/Multi_Threading/Simple/Test.idl +26 -0
  156. data/test/Multi_Threading/Simple/client.rb +92 -0
  157. data/test/Multi_Threading/Simple/run_test.rb +68 -0
  158. data/test/Multi_Threading/Simple/server.rb +117 -0
  159. data/test/Multi_Threading/Threads/Test.idl +27 -0
  160. data/test/Multi_Threading/Threads/client.rb +77 -0
  161. data/test/Multi_Threading/Threads/run_test.rb +75 -0
  162. data/test/Multi_Threading/Threads/server.rb +116 -0
  163. data/test/Multi_Threading/Threads/watchdog.rb +87 -0
  164. data/test/Multiple_Servant_Interfaces/Test.idl +33 -0
  165. data/test/Multiple_Servant_Interfaces/client.rb +69 -0
  166. data/test/Multiple_Servant_Interfaces/run_test.rb +68 -0
  167. data/test/Multiple_Servant_Interfaces/server.rb +101 -0
  168. data/test/Nil/Test.idl +26 -0
  169. data/test/Nil/run_test.rb +51 -0
  170. data/test/Nil/test.rb +80 -0
  171. data/test/OBV/AbstractInterface/client.rb +178 -0
  172. data/test/OBV/AbstractInterface/run_test.rb +68 -0
  173. data/test/OBV/AbstractInterface/server.rb +149 -0
  174. data/test/OBV/AbstractInterface/test.idl +52 -0
  175. data/test/OBV/Custom/OBV.idl +18 -0
  176. data/test/OBV/Custom/OBV_impl.rb +41 -0
  177. data/test/OBV/Custom/client.rb +85 -0
  178. data/test/OBV/Custom/run_test.rb +68 -0
  179. data/test/OBV/Custom/server.rb +99 -0
  180. data/test/OBV/Simple/OBV.idl +15 -0
  181. data/test/OBV/Simple/OBV_impl.rb +26 -0
  182. data/test/OBV/Simple/client.rb +85 -0
  183. data/test/OBV/Simple/run_test.rb +68 -0
  184. data/test/OBV/Simple/server.rb +99 -0
  185. data/test/OBV/Simple_Event/Event.idl +15 -0
  186. data/test/OBV/Simple_Event/Event_impl.rb +26 -0
  187. data/test/OBV/Simple_Event/client.rb +85 -0
  188. data/test/OBV/Simple_Event/run_test.rb +68 -0
  189. data/test/OBV/Simple_Event/server.rb +99 -0
  190. data/test/OBV/Supports/client.rb +115 -0
  191. data/test/OBV/Supports/run_test.rb +68 -0
  192. data/test/OBV/Supports/server.rb +102 -0
  193. data/test/OBV/Supports/supports.idl +32 -0
  194. data/test/OBV/Supports/supports_impl.rb +59 -0
  195. data/test/OBV/Tree/client.rb +115 -0
  196. data/test/OBV/Tree/run_test.rb +68 -0
  197. data/test/OBV/Tree/server.rb +116 -0
  198. data/test/OBV/Tree/test.idl +31 -0
  199. data/test/OBV/Truncatable/Extra.idl +26 -0
  200. data/test/OBV/Truncatable/Truncatable.idl +105 -0
  201. data/test/OBV/Truncatable/Truncatable_impl.rb +85 -0
  202. data/test/OBV/Truncatable/client.rb +278 -0
  203. data/test/OBV/Truncatable/run_test.rb +68 -0
  204. data/test/OBV/Truncatable/server.rb +88 -0
  205. data/test/OBV/ValueBox/client.rb +497 -0
  206. data/test/OBV/ValueBox/run_test.rb +68 -0
  207. data/test/OBV/ValueBox/server.rb +271 -0
  208. data/test/OBV/ValueBox/valuebox.idl +101 -0
  209. data/test/OBV/ValueBox/vb_basic.idl +75 -0
  210. data/test/OBV/ValueBox/vb_struct.idl +68 -0
  211. data/test/OBV/ValueBox/vb_union.idl +21 -0
  212. data/test/Object/Test.idl +26 -0
  213. data/test/Object/client.rb +111 -0
  214. data/test/Object/run_test.rb +68 -0
  215. data/test/Object/server.rb +125 -0
  216. data/test/POA/Test.idl +27 -0
  217. data/test/POA/run_test.rb +51 -0
  218. data/test/POA/test.rb +111 -0
  219. data/test/Param_Test/Test.idl +182 -0
  220. data/test/Param_Test/client.rb +276 -0
  221. data/test/Param_Test/run_test.rb +68 -0
  222. data/test/Param_Test/server.rb +295 -0
  223. data/test/Performance/Simple/Test.idl +26 -0
  224. data/test/Performance/Simple/client.rb +89 -0
  225. data/test/Performance/Simple/run_test.rb +68 -0
  226. data/test/Performance/Simple/server.rb +94 -0
  227. data/test/Policies/Test.idl +26 -0
  228. data/test/Policies/run_test.rb +51 -0
  229. data/test/Policies/test.rb +142 -0
  230. data/test/Timeout/client.rb +206 -0
  231. data/test/Timeout/run_test.rb +68 -0
  232. data/test/Timeout/server.rb +108 -0
  233. data/test/Timeout/test.idl +18 -0
  234. data/test/lib/assert.rb +41 -0
  235. data/test/lib/test.rb +546 -0
  236. data/test/test_runner.rb +191 -0
  237. metadata +318 -0
@@ -0,0 +1,1605 @@
1
+ #--------------------------------------------------------------------
2
+ # walker.rb - IDL typecode and client stubs backend walker
3
+ #
4
+ # Author: Martin Corino
5
+ #
6
+ # This program is free software; you can redistribute it and/or
7
+ # modify it under the terms of the R2CORBA LICENSE which is
8
+ # included with this program.
9
+ #
10
+ # Copyright (c) Remedy IT Expertise BV
11
+ #--------------------------------------------------------------------
12
+ module IDL
13
+ class RubyWriterBase
14
+ def initialize(output = STDOUT, params = {}, indent = ' ')
15
+ @output = output
16
+ @params = params
17
+ @indent = indent
18
+ @nest = 0
19
+ end
20
+
21
+ def print(str); @output << str; end
22
+
23
+ def println(str = ''); @output << str << "\n"; end
24
+
25
+ def printi(str = ''); @output << indent() << str; end
26
+
27
+ def printiln(str = ''); @output << indent() << str << "\n"; end
28
+
29
+ def indent()
30
+ @indent * @nest
31
+ end
32
+
33
+ def nest(in_ = 1)
34
+ @nest += in_
35
+ begin
36
+ yield
37
+ ensure
38
+ @nest -= in_
39
+ end
40
+ end
41
+
42
+ def visit_nodes(parser)
43
+ pre_visit(parser)
44
+
45
+ parser.walk_nodes(self)
46
+
47
+ post_visit(parser)
48
+ end
49
+ end
50
+
51
+ class RubyStubWriter < RubyWriterBase
52
+ def initialize(output = STDOUT, params = {}, indent = ' ')
53
+ super
54
+ end
55
+
56
+ def pre_visit(parser)
57
+ print(
58
+ %Q{# -*- Ruby -*-
59
+ #
60
+ # **** Code generated by the R2CORBA IDL Compiler ****
61
+ # R2CORBA has been developed by:
62
+ # Remedy IT Expertise BV
63
+ # The Netherlands
64
+ # https://www.remedy.nl
65
+ #
66
+ })
67
+ println("require 'corba'") if @params[:libinit]
68
+ println()
69
+ enter_module(parser.root_namespace) unless parser.root_namespace.nil?
70
+ idleval = @params[:idl_eval] || false
71
+ if !idleval
72
+ printiln("CORBA.implement('#{@params[:idlfile]}', {}, CORBA::IDL::CLIENT_STUB) {")
73
+ println()
74
+ end
75
+ end
76
+
77
+ def post_visit(parser)
78
+ idleval = @params[:idl_eval] || false
79
+ if !idleval
80
+ printiln("} ## end of '#{@params[:idlfile]}'")
81
+ end
82
+ leave_module(parser.root_namespace) unless parser.root_namespace.nil?
83
+ println('# -*- END -*-')
84
+ end
85
+
86
+ def visit_include(node)
87
+ printiln(format("require '%s'", node.filename.sub(/\.[^\.]*$/, @params[:stub_pfx])))
88
+ println()
89
+ end
90
+
91
+ def enter_include(node)
92
+ printiln('## include')
93
+ printiln("CORBA.implement('#{node.filename}', {}, CORBA::IDL::CLIENT_STUB) {")
94
+ println()
95
+ end
96
+
97
+ def leave_include(node)
98
+ println()
99
+ printiln("} ## end of include '#{node.filename}'")
100
+ println()
101
+ end
102
+
103
+ def enter_module(node)
104
+ printiln('module ' + node.rubyname)
105
+ println()
106
+ @nest += 1
107
+ end
108
+
109
+ def leave_module(node)
110
+ @nest -= 1
111
+ printiln("end #of module #{node.rubyname}")
112
+ println()
113
+ end
114
+
115
+ def declare_interface(node)
116
+ name = node.rubyname
117
+ if not @params[:class_interfaces].nil? and @params[:class_interfaces].include?(name)
118
+ printiln("class #{name}; end ## interface forward")
119
+ else
120
+ printiln("module #{name}; end ## interface forward")
121
+ end
122
+ end
123
+
124
+ def enter_interface(node)
125
+ println
126
+ name = node.rubyname
127
+ if node.is_pseudo?
128
+ if not @params[:class_interfaces].nil? and @params[:class_interfaces].include?(name)
129
+ printiln("class #{name} ## pseudo object interface")
130
+ else
131
+ printiln("module #{name} ## pseudo object interface")
132
+ end
133
+ @nest += 1
134
+ else
135
+ if not @params[:class_interfaces].nil? and @params[:class_interfaces].include?(name)
136
+ printiln("class #{node.rubyname} ## interface")
137
+ else
138
+ printiln("module #{node.rubyname} ## interface")
139
+ end
140
+ println()
141
+ @nest += 1
142
+
143
+ if node.bases.size > 0
144
+ node.bases.each do |n|
145
+ printiln("include #{n.scoped_rubyname}")
146
+ end
147
+ println()
148
+ end
149
+
150
+ printiln(format("Id = '%s'.freeze", node.repository_id))
151
+ printi('Ids = [ Id')
152
+ if node.is_abstract?
153
+ println(',')
154
+ printi(" 'IDL:omg.org/CORBA/AbstractBase:1.0'")
155
+ end
156
+ if node.bases.size > 0
157
+ node.bases.each do |n|
158
+ println(',')
159
+ printi(" #{n.scoped_rubyname}::Id")
160
+ end
161
+ end
162
+ println(' ].freeze')
163
+
164
+ println
165
+ unless node.is_abstract?
166
+ printiln(format("def %s._tc; @@tc_%s ||= CORBA::TypeCode::ObjectRef.new(Id, '%s', self); end",
167
+ node.rubyname, node.rubyname, node.rubyname))
168
+ else
169
+ printiln(format("def %s._tc; @@tc_%s ||= CORBA::TypeCode::AbstractInterface.new(Id, '%s', self); end",
170
+ node.rubyname, node.rubyname, node.rubyname))
171
+ end
172
+ printiln('self._tc # register typecode');
173
+
174
+ println
175
+ printiln("def #{name}._narrow(obj)")
176
+ nest {
177
+ printiln('return nil if CORBA.is_nil(obj)')
178
+ if node.is_local?
179
+ printiln('return CORBA::Stub.create_stub(obj)._unchecked_narrow!(self)')
180
+ else
181
+ printiln('return CORBA::Stub.create_stub(obj)._narrow!(self)')
182
+ end
183
+ }
184
+ printiln('end')
185
+ println
186
+ printiln("def #{name}._duplicate(obj)")
187
+ nest {
188
+ if node.is_local?
189
+ printiln('obj');
190
+ else
191
+ printiln('return nil if CORBA.is_nil(obj)')
192
+ printiln('return CORBA::Stub.create_stub(super(obj))._narrow!(self)')
193
+ end
194
+ }
195
+ printiln('end')
196
+ println
197
+ printiln('def _interface_repository_id')
198
+ nest {
199
+ printiln("#{node.scoped_rubyname}::Id")
200
+ }
201
+ printiln('end')
202
+ end
203
+ println
204
+ end
205
+
206
+ def leave_interface(node)
207
+ name = node.rubyname
208
+ @nest -= 1
209
+ printiln("end #of interface #{name}")
210
+ println
211
+ end
212
+
213
+ private
214
+ def print_valuetype_typecode(node)
215
+ if node.is_a?(IDL::AST::Eventtype)
216
+ println("CORBA::TypeCode::Eventtype.new('#{node.repository_id}'.freeze, '#{node.rubyname}',")
217
+ else
218
+ println("CORBA::TypeCode::Valuetype.new('#{node.repository_id}'.freeze, '#{node.rubyname}',")
219
+ end
220
+ nest(3) {
221
+ printi(":#{node.modifier}, ")
222
+ if node.has_concrete_base?
223
+ print("#{node.bases.first.rubyname}._tc")
224
+ else
225
+ print('nil')
226
+ end
227
+ state_members_ = node.state_members
228
+ unless state_members_.empty?
229
+ pfx = '['
230
+ state_members_.each do |m|
231
+ println(',')
232
+ printi(pfx)
233
+ pfx = ''
234
+ if m.has_incomplete_type?
235
+ print("['#{m.rubyname}', ")
236
+ print_valuetype_typecode(m.idltype.resolved_type.node)
237
+ print(", :#{m.visibility}]")
238
+ elsif m.is_recursive?
239
+ print("['#{m.rubyname}', ")
240
+ print("CORBA::TypeCode::Recursive.new('#{m.idltype.resolved_type.node.repository_id}')")
241
+ print(", :#{m.visibility}]")
242
+ else
243
+ print(format("['%s', %s, :%s]", m.rubyname, get_typecode(m.idltype), m.visibility))
244
+ end
245
+ end
246
+ print('], self)')
247
+ else
248
+ print(', self)')
249
+ end
250
+ }
251
+ end
252
+
253
+ public
254
+
255
+ def declare_valuetype(node)
256
+ end
257
+
258
+ def enter_valuetype(node)
259
+ println()
260
+ name = node.rubyname
261
+ unless node.is_abstract?
262
+ printiln("class #{name}")
263
+ else
264
+ printiln("module #{name}")
265
+ end
266
+ @nest += 1
267
+
268
+ unless node.is_abstract?
269
+ if node.is_custom?
270
+ printiln('include CORBA::Portable::CustomValueBase')
271
+ else
272
+ printiln('include CORBA::ValueBase')
273
+ end
274
+ else
275
+ printiln('include CORBA::AbstractValueBase')
276
+ end
277
+
278
+ unless node.is_abstract?
279
+ trunc_ids = node.truncatable_ids
280
+ println()
281
+ printi('TRUNCATABLE_IDS = [')
282
+ print("'#{trunc_ids.shift}'")
283
+ unless trunc_ids.empty?
284
+ nest {
285
+ trunc_ids.each do |trunc_id|
286
+ println(',')
287
+ printi("'#{trunc_id}'")
288
+ end
289
+ }
290
+ end
291
+ println(' ].freeze')
292
+ end
293
+
294
+ println()
295
+ printiln(format('def %s._tc', node.rubyname))
296
+ nest {
297
+ printi("@@tc_#{node.rubyname} ||= ")
298
+ print_valuetype_typecode(node)
299
+ println()
300
+ }
301
+ printiln('end')
302
+ printiln('self._tc # register typecode')
303
+ end
304
+
305
+ def leave_valuetype(node)
306
+ println()
307
+ printiln('module Intf')
308
+ nest {
309
+ intfs_ = node.interfaces
310
+ unless intfs_.empty?
311
+ printiln('## supported interfaces')
312
+ intfs_.each do |intf|
313
+ printiln("include #{intf.scoped_rubyname}")
314
+ end
315
+ printiln('undef :_interface_repository_id')
316
+ end
317
+
318
+ bases_ = Array.new(node.bases)
319
+ if node.has_concrete_base?
320
+ printiln('## concrete base type')
321
+ printiln("include #{bases_.shift.scoped_rubyname}::Intf")
322
+ end
323
+ unless bases_.empty?
324
+ printiln('## abstract base types')
325
+ bases_.each do |base|
326
+ printiln("include #{base.scoped_rubyname}::Intf")
327
+ end
328
+ end
329
+
330
+ if node.has_concrete_base?() || !bases_.empty?() || !intfs_.empty?()
331
+ println
332
+ end
333
+
334
+ intf_members_ = node.interface_members
335
+ [IDL::AST::Operation, IDL::AST::Attribute].each do |m_type|
336
+ has_type = false
337
+ intf_members_.each do |m|
338
+ if m.is_a?(m_type)
339
+ if m.is_a?(IDL::AST::Operation)
340
+ printi('## operations') unless has_type
341
+ visit_operation(m)
342
+ has_type = true
343
+ else
344
+ printi('## attributes') unless has_type
345
+ visit_attribute(m)
346
+ has_type = true
347
+ end
348
+ end
349
+ end
350
+ println() if has_type
351
+ end
352
+
353
+ unless node.is_abstract?
354
+ state_members_ = node.state_members
355
+ has_type = false
356
+ state_members_.each do |m|
357
+ if m.visibility == :public
358
+ printiln('## public value state') unless has_type
359
+ printiln(format('attr_accessor :%s', m.rubyname))
360
+ has_type = true
361
+ end
362
+ end
363
+ println() if has_type
364
+ has_type = false
365
+ state_members_.each do |m|
366
+ unless m.visibility == :public
367
+ unless has_type
368
+ printiln('## private value state')
369
+ printiln('protected')
370
+ end
371
+ printiln(format('attr_accessor :%s', m.rubyname))
372
+ has_type = true
373
+ end
374
+ end
375
+ println() if has_type
376
+
377
+ printiln('public')
378
+ println()
379
+
380
+ unless node.is_custom?
381
+ printiln('def self.marshal(vt, __os__)')
382
+ nest {
383
+ printiln("#{node.bases.first.scoped_rubyname}::Intf.marshal(vt, __os__)") if node.has_concrete_base?
384
+ unless state_members_.empty?
385
+ printiln('vt._marshal_with(__os__) do')
386
+ nest {
387
+ state_members_.each_with_index do |m, i|
388
+ printiln("__os__.write_member(#{node.scoped_rubyname}._tc.member_type(#{i}),")
389
+ printiln(" self.#{m.rubyname})")
390
+ end
391
+ }
392
+ printiln('end')
393
+ end
394
+ }
395
+ printiln('end')
396
+ println()
397
+
398
+ printiln('def self.unmarshal(vt, __is__)')
399
+ nest {
400
+ printiln("#{node.bases.first.scoped_rubyname}::Intf.unmarshal(vt, __is__)") if node.has_concrete_base?
401
+ unless state_members_.empty?
402
+ printiln('vt._unmarshal_with(__is__) do')
403
+ nest {
404
+ state_members_.each_with_index do |m, i|
405
+ printi("self.#{m.rubyname} = ")
406
+ println("__is__.read_member(#{node.scoped_rubyname}._tc.member_type(#{i}))")
407
+ end
408
+ }
409
+ printiln('end')
410
+ end
411
+ }
412
+ printiln('end')
413
+ println()
414
+
415
+ printiln('def marshal(os)')
416
+ nest {
417
+ printiln("#{node.scoped_rubyname}::Intf.marshal(self, os)")
418
+ }
419
+ printiln('end')
420
+ println()
421
+
422
+ printiln('def unmarshal(is)')
423
+ nest {
424
+ printiln("#{node.scoped_rubyname}::Intf.unmarshal(self, is)")
425
+ }
426
+ printiln('end')
427
+ println()
428
+ end
429
+ end
430
+ }
431
+ printiln('end # of Intf')
432
+ println
433
+ printiln('include Intf')
434
+ println
435
+
436
+ @nest -= 1
437
+ if node.is_a?(IDL::AST::Eventtype)
438
+ printiln("end #of eventtype #{node.rubyname}")
439
+ else
440
+ printiln("end #of valuetype #{node.rubyname}")
441
+ end
442
+
443
+ unless node.is_abstract?
444
+ println
445
+ initializers = node.initializers
446
+ printiln("class #{node.rubyname}Factory < CORBA::Portable::ValueFactoryBase")
447
+ nest {
448
+ printiln("VALUE_ID = '#{node.repository_id}'.freeze")
449
+ if initializers.empty?
450
+ unless node.has_operations_or_attributes?(false)
451
+ # valuetype has only state, create the default factory
452
+ printiln('def _create_default')
453
+ nest {
454
+ printiln("#{node.scoped_rubyname}.new")
455
+ }
456
+ printiln('end')
457
+ end
458
+ else
459
+ println()
460
+ initializers.each do |init|
461
+ printiln("def #{init.rubyname}(#{init.params().collect {|p| p.rubyname}.join(',')})")
462
+ nest {
463
+ printiln("raise RuntimeError, 'unimplemented local operation called'")
464
+ }
465
+ printiln('end')
466
+ end
467
+ end
468
+ }
469
+ printiln("end # of #{node.rubyname}Factory")
470
+ end
471
+ end
472
+
473
+ def visit_valuebox(node)
474
+ println
475
+ name = node.rubyname
476
+ printiln("class #{name}")
477
+ nest {
478
+ printiln('include CORBA::Portable::BoxedValueBase')
479
+ println()
480
+ printiln("TRUNCATABLE_IDS = [ '#{node.repository_id}' ].freeze")
481
+ println()
482
+ printiln(format('def %s._tc', node.rubyname))
483
+ nest {
484
+ printiln(format("@@tc_%s ||= CORBA::TypeCode::Valuebox.new('%s'.freeze, '%s',",
485
+ node.rubyname, node.repository_id, node.rubyname))
486
+ printiln(" #{get_typecode(node.boxed_type)}, self)")
487
+ }
488
+ printiln('end')
489
+ printiln('self._tc # register typecode');
490
+ printiln('attr_accessor :value')
491
+ printiln('def initialize(val = nil); @value = val; end')
492
+ }
493
+ printiln("end #of valuebox #{name}")
494
+ println
495
+ end
496
+
497
+ def visit_const(node)
498
+ # v = Expression::Value.new(node.idltype, node.value)
499
+ s = node.rubyname + ' = ' + expression_to_s(node.expression)
500
+ printiln(s)
501
+ end
502
+
503
+ def visit_operation(node, from_valuetype = false)
504
+ _parm = node.params
505
+ _in = node.in_params
506
+ _out = node.out_params
507
+ _intf = node.enclosure
508
+
509
+ println()
510
+ printi("def #{node.rubyname}(")
511
+ print(_in.collect{ |p| p.rubyname }.join(', '))
512
+ if node.oneway
513
+ println(') # oneway')
514
+ else
515
+ println(')')
516
+ end
517
+
518
+ nest do
519
+ if _intf.is_a?(IDL::AST::Valuetype) or from_valuetype
520
+ printiln("raise RuntimeError, 'unimplemented local operation called'")
521
+ elsif _intf.is_local?
522
+ printiln('raise ::CORBA::NO_IMPLEMENT.new(')
523
+ printiln(" 'unimplemented operation on local interface',")
524
+ printiln(' 1, ::CORBA::COMPLETED_NO)')
525
+ else
526
+ ## check if this is a proper object reference
527
+ printiln('raise ::CORBA::NO_IMPLEMENT unless self.respond_to?(:_invoke, true)')
528
+
529
+ ## validate data for IN/INOUT args
530
+ ##
531
+ if _parm.size > 0
532
+ _parm.each do |p|
533
+ if p.attribute != IDL::AST::Parameter::OUT
534
+ printiln("#{p.rubyname} = #{get_typecode(p.idltype)}.validate(#{p.rubyname})")
535
+ end
536
+ end
537
+ end
538
+
539
+ ## invoke operation
540
+ ##
541
+ if not node.oneway
542
+ printi("_ret = self._invoke('#{node.name}', {")
543
+ else
544
+ printi("self._invoke('#{node.name}', {")
545
+ end
546
+
547
+ newln = ''
548
+ if _parm.size > 0
549
+ println(newln)
550
+ nest do
551
+ printi(':arg_list => [')
552
+ nest {
553
+ pfx = ''
554
+ _parm.each do |p|
555
+ println(pfx)
556
+ printi("['#{p.rubyname}', #{get_arg_type(p.attribute)}, ");
557
+ print(get_typecode(p.idltype))
558
+ if p.attribute != IDL::AST::Parameter::OUT
559
+ print(", #{p.rubyname}]")
560
+ else
561
+ print(']')
562
+ end
563
+ pfx = ','
564
+ end
565
+ print(']')
566
+ }
567
+ end
568
+ newln = ','
569
+ end
570
+
571
+ if not node.oneway
572
+ println(newln)
573
+ nest { printi(":result_type => #{get_typecode(node.idltype)}") }
574
+ newln = ','
575
+ end
576
+
577
+ if node.raises.size > 0
578
+ println(newln)
579
+ nest {
580
+ printi(':exc_list => [')
581
+ pfx = ''
582
+ nest {
583
+ node.raises.each { |ex|
584
+ println(pfx)
585
+ pfx = ','
586
+ printi(get_typecode(ex))
587
+ }
588
+ print(']')
589
+ }
590
+ }
591
+ end
592
+
593
+ println('})')
594
+
595
+ if not node.oneway
596
+ returns_void = (node.idltype.is_a? Type::Void)
597
+ size = _out.size
598
+ size += 1 unless returns_void
599
+ printiln('_ret')
600
+ end
601
+ end
602
+ end
603
+
604
+ printiln("end #of operation #{node.rubyname}")
605
+ end
606
+
607
+ def visit_attribute(node, from_valuetype = false)
608
+ _intf = node.enclosure
609
+ println()
610
+ printiln("def #{node.rubyname}()")
611
+ nest do
612
+ if _intf.is_a?(IDL::AST::Valuetype) or from_valuetype
613
+ printiln("@#{node.name}")
614
+ elsif _intf.is_local?
615
+ printiln('raise ::CORBA::NO_IMPLEMENT.new(')
616
+ printiln(" 'unimplemented attribute on local interface',")
617
+ printiln(' 1, ::CORBA::COMPLETED_NO)')
618
+ else
619
+ ## check if this is a proper object reference
620
+ printiln('raise ::CORBA::NO_IMPLEMENT unless self.respond_to?(:_invoke, true)')
621
+
622
+ printiln("_ret = self._invoke('_get_#{node.name}', {")
623
+ nest { printi(":result_type => #{get_typecode(node.idltype)}") }
624
+ if node.get_raises.size > 0
625
+ println(',')
626
+ nest {
627
+ printi(':exc_list => [')
628
+ pfx = ''
629
+ nest {
630
+ node.get_raises.each { |ex|
631
+ println(pfx)
632
+ pfx = ','
633
+ printi(get_typecode(ex))
634
+ }
635
+ print(']')
636
+ }
637
+ }
638
+ end
639
+ println('})')
640
+
641
+ printiln('_ret')
642
+ end
643
+ end
644
+ printiln("end #of attribute #{node.name} getter")
645
+ if not node.readonly
646
+ printiln("def #{node.rubyname}=(val)")
647
+ nest do
648
+ if _intf.is_a?(IDL::AST::Valuetype) or from_valuetype
649
+ printiln("@#{node.name} = val")
650
+ elsif _intf.is_local?
651
+ printiln('raise ::CORBA::NO_IMPLEMENT.new(')
652
+ printiln(" 'unimplemented attribute on local interface',")
653
+ printiln(' 1, ::CORBA::COMPLETED_NO)')
654
+ else
655
+ ## check if this is a proper object reference
656
+ printiln('raise ::CORBA::NO_IMPLEMENT unless self.respond_to?(:_invoke, true)')
657
+
658
+ ## validate IN arg
659
+ printiln("val = #{get_typecode(node.idltype)}.validate(val)")
660
+ ## invoke operation
661
+ printiln("self._invoke('_set_#{node.name}', {")
662
+ nest {
663
+ printiln(':arg_list => [')
664
+ nest {
665
+ printiln("['val', CORBA::ARG_IN, #{get_typecode(node.idltype)}, val]],");
666
+ }
667
+ printi(':result_type => CORBA._tc_void')
668
+ if node.set_raises.size > 0
669
+ println(',')
670
+ printi(':exc_list => [')
671
+ pfx = ''
672
+ nest {
673
+ node.set_raises.each { |ex|
674
+ println(pfx)
675
+ pfx = ','
676
+ printi(get_typecode(ex))
677
+ }
678
+ print(']')
679
+ }
680
+ end
681
+ println('})')
682
+ }
683
+ end
684
+ end
685
+ printiln("end #of attribute #{node.name} setter")
686
+ end
687
+ end
688
+
689
+ def get_typecode(_type)
690
+ case _type
691
+ when Type::Octet,
692
+ Type::UShort, Type::Short,
693
+ Type::ULong, Type::Long,
694
+ Type::ULongLong, Type::LongLong,
695
+ Type::Boolean, Type::Char, Type::WChar,
696
+ Type::Float, Type::Double, Type::LongDouble,
697
+ Type::Void, Type::Any
698
+ s = _type.class.name.split('::') # IDL::Type::Octet -> [IDL, Type, Octet]
699
+ s = s[s.length - 1]
700
+ s.downcase!
701
+ format('CORBA._tc_%s', s)
702
+
703
+ when Type::Object
704
+ 'CORBA._tc_Object'
705
+
706
+ when Type::String
707
+ if not _type.length.nil?
708
+ format('CORBA::TypeCode::String.new(%d)', _type.length)
709
+ else
710
+ 'CORBA._tc_string'
711
+ end
712
+
713
+ when Type::WString
714
+ if not _type.length.nil?
715
+ format('CORBA::TypeCode::WString.new(%d)', _type.length)
716
+ else
717
+ 'CORBA._tc_wstring'
718
+ end
719
+
720
+ when Type::ScopedName
721
+ scoped_type = _type.node.idltype
722
+ if scoped_type.is_a?(IDL::Type::Interface) && scoped_type.node.is_forward?()
723
+ node = scoped_type.node
724
+ "(CORBA::TypeCode.typecode_for_id('#{node.repository_id}') || " +
725
+ "CORBA::TypeCode::ObjectRef.new('#{node.repository_id}', '#{node.rubyname}', #{node.scoped_rubyname}))"
726
+ else
727
+ _type.node.scoped_rubyname + '._tc'
728
+ end
729
+
730
+ when Type::Array
731
+ sep = ''
732
+ tc = 'CORBA::TypeCode::Array.new(' +
733
+ get_typecode(_type.basetype) + ', '
734
+ _type.sizes.each do |sz|
735
+ tc += "#{sep}#{sz.to_s}"
736
+ sep = ', '
737
+ end
738
+ tc + ')'
739
+
740
+ when Type::Sequence
741
+ if _type.is_recursive?
742
+ "CORBA::TypeCode::Sequence.new(CORBA::TypeCode::Recursive.new('#{_type.basetype.resolved_type.node.repository_id}'))"
743
+ else
744
+ 'CORBA::TypeCode::Sequence.new(' +
745
+ get_typecode(_type.basetype) +
746
+ if not _type.length.nil? then format(', %d)', _type.length) else ')' end
747
+ end
748
+
749
+ else
750
+ raise "invalid type for (un)marshalling: #{_type.typename}"
751
+ end
752
+ end
753
+
754
+ def get_arg_type(_idl_argtype)
755
+ case _idl_argtype
756
+ when IDL::AST::Parameter::IN
757
+ 'CORBA::ARG_IN'
758
+ when IDL::AST::Parameter::OUT
759
+ 'CORBA::ARG_OUT'
760
+ else
761
+ 'CORBA::ARG_INOUT'
762
+ end
763
+ end
764
+
765
+ def expression_to_s(exp)
766
+ case exp
767
+ when Expression::Value
768
+ value_to_s(exp)
769
+ when Expression::Operation
770
+ operation_to_s(exp)
771
+ when Expression::ScopedName, Expression::Enumerator
772
+ exp.node.scoped_rubyname
773
+ else
774
+ raise "unknown expression type: #{exp.class.name}"
775
+ end
776
+ end
777
+
778
+ def value_to_s(exp)
779
+ s = nil
780
+ v = exp.value
781
+ case exp.idltype
782
+ when Type::Void
783
+ s = 'nil'
784
+ when Type::Char
785
+ s = "'#{v.chr}'"
786
+ when Type::Integer,
787
+ Type::Boolean,
788
+ Type::Octet,
789
+ Type::Float
790
+ s = v.to_s
791
+ when Type::WChar
792
+ s = (case v.first
793
+ when :char, :esc_ch
794
+ v.last.unpack('c')
795
+ when :esc
796
+ IDL::Scanner::ESCTBL[v.last]
797
+ when :oct
798
+ v.last.oct
799
+ when :hex2, :hex4
800
+ v.last.hex
801
+ else
802
+ 0
803
+ end).to_s
804
+ when Type::Enum
805
+ v = exp.idltype.narrow(v)
806
+ s = exp.idltype.node.enumerators[v].scoped_rubyname
807
+ when Type::String
808
+ s = "'#{v.to_s}'"
809
+ when Type::WString
810
+ v = (v.collect do |(elt, elv)|
811
+ case elt
812
+ when :char, :esc_ch
813
+ elv.unpack('c')
814
+ when :esc
815
+ IDL::Scanner::ESCTBL[elv]
816
+ when :oct
817
+ elv.oct
818
+ when :hex2, :hex4
819
+ elv.hex
820
+ else
821
+ nil
822
+ end
823
+ end).compact
824
+ s = "[#{v.join(',')}]"
825
+ # when Type::Fixed
826
+ # when Type::Any
827
+ # when Type::Object
828
+ when Type::ScopedName
829
+ s = value_to_s(Expression::Value.new(exp.idltype.node.idltype, v))
830
+ else
831
+ raise "#{exp.typename}'s not been supported yet."
832
+ end
833
+ s
834
+ end
835
+
836
+ def operation_to_s(exp)
837
+ s = nil
838
+ op = exp.operands
839
+ case exp
840
+ when Expression::Operation::UnaryPlus
841
+ s = expression_to_s(op[0])
842
+ when Expression::Operation::UnaryMinus
843
+ s = '-' + expression_to_s(op[0])
844
+ when Expression::Operation::UnaryNot
845
+ s = '~' + expression_to_s(op[0])
846
+ when Expression::Operation::Or
847
+ s = expression_to_s(op[0]) + ' | ' + expression_to_s(op[1])
848
+ when Expression::Operation::And
849
+ s = expression_to_s(op[0]) + ' & ' + expression_to_s(op[1])
850
+ when Expression::Operation::LShift
851
+ s = expression_to_s(op[0]) + ' << ' + expression_to_s(op[1])
852
+ when Expression::Operation::RShift
853
+ s = expression_to_s(op[0]) + ' >> ' + expression_to_s(op[1])
854
+ when Expression::Operation::Add
855
+ s = expression_to_s(op[0]) + ' + ' + expression_to_s(op[1])
856
+ when Expression::Operation::Minus
857
+ s = expression_to_s(op[0]) + ' - ' + expression_to_s(op[1])
858
+ when Expression::Operation::Mult
859
+ s = expression_to_s(op[0]) + ' * ' + expression_to_s(op[1])
860
+ when Expression::Operation::Div
861
+ s = expression_to_s(op[0]) + ' / ' + expression_to_s(op[1])
862
+ when Expression::Operation::Mod
863
+ s = expression_to_s(op[0]) + ' % ' + expression_to_s(op[1])
864
+ else
865
+ raise "unknown operation: #{exp.type.name}"
866
+ end
867
+ '(' + s + ')'
868
+ end
869
+
870
+ def declare_struct(node)
871
+ end
872
+
873
+ def enter_struct(node)
874
+ println()
875
+ name = node.rubyname
876
+ printiln("class #{name} < CORBA::Portable::Struct")
877
+ @nest += 1
878
+ end
879
+
880
+ def leave_struct(node)
881
+ tc_ = if node.is_a? IDL::AST::Exception then 'Except' else 'Struct' end
882
+ println()
883
+ printiln(format('def %s._tc', node.rubyname))
884
+ struct_members_ = node.members
885
+ nest {
886
+ printi(format("@@tc_%s ||= CORBA::TypeCode::%s.new('%s'.freeze, '%s'",
887
+ node.rubyname, tc_, node.repository_id, node.rubyname))
888
+ unless struct_members_.empty?
889
+ pfx = ' ['
890
+ struct_members_.each do |m|
891
+ println(',')
892
+ printi(pfx)
893
+ pfx = ' '
894
+ print(format("['%s', %s]", m.rubyname, get_typecode(m.idltype)))
895
+ end
896
+ println('], self)')
897
+ else
898
+ println(', self)')
899
+ end
900
+ }
901
+ printiln('end')
902
+ printiln('self._tc # register typecode');
903
+ struct_members_.each do |m|
904
+ printiln(format('attr_accessor :%s', m.rubyname))
905
+ end
906
+
907
+ if struct_members_.size > 0
908
+ printiln('def initialize(*param_)')
909
+ nest {
910
+ struct_members_.each do |m|
911
+ printiln("@#{m.rubyname} = param_.shift")
912
+ end
913
+ }
914
+ printiln('end')
915
+ println()
916
+ end
917
+
918
+ name = node.rubyname
919
+ @nest -= 1
920
+ printiln("end #of #{if node.is_a? IDL::AST::Exception then "exception" else "struct" end} #{name}")
921
+ end
922
+
923
+ def enter_exception(node)
924
+ println()
925
+ name = node.rubyname
926
+ printiln("class #{name} < CORBA::UserException")
927
+ @nest += 1
928
+ end
929
+
930
+ def leave_exception(node)
931
+ leave_struct(node)
932
+ end
933
+
934
+ def declare_union(node)
935
+ end
936
+
937
+ def enter_union(node)
938
+ println()
939
+ name = node.rubyname
940
+ printiln("class #{name} < CORBA::Portable::Union")
941
+ @nest += 1
942
+ end
943
+
944
+ def leave_union(node)
945
+ println()
946
+ printiln(format('def %s._tc', node.rubyname))
947
+ nest {
948
+ printiln(format("@@tc_%s ||= CORBA::TypeCode::Union.new('%s'.freeze, '%s',",
949
+ node.rubyname, node.repository_id, node.rubyname))
950
+ printi(" #{get_typecode(node.switchtype)}")
951
+ if node.members.size > 0
952
+ pfx = ' ['
953
+ node.members.each do |m|
954
+ m.labels.each do |lbl|
955
+ println(',')
956
+ printi(pfx)
957
+ pfx = ' '
958
+ labeltxt = if lbl == :default then ':default'; else expression_to_s(lbl); end
959
+ print(format("[%s, '%s', %s]", labeltxt, m.rubyname, get_typecode(m.idltype)))
960
+ end
961
+ end
962
+ print('], self')
963
+ else
964
+ print(', self')
965
+ end
966
+ if (!node.has_default?) && node.default_label # has implicit default?
967
+ println(", #{expression_to_s(node.default_label)})")
968
+ else
969
+ println(')')
970
+ end
971
+ }
972
+ printiln('end')
973
+ printiln('self._tc # register typecode');
974
+ ix = 0
975
+ if node.members.size > 0
976
+ node.members.each do |m|
977
+ printiln(format('def %s; @value; end', m.rubyname))
978
+ printiln(format('def %s=(val); _set_value(%d, val); end', m.rubyname, ix))
979
+ ix += m.labels.size
980
+ end
981
+ end
982
+
983
+ if (!node.has_default?) && node.default_label # has implicit default?
984
+ def_label = expression_to_s(node.default_label)
985
+ printiln("def _default; @discriminator = #{def_label}; @value = nil; end")
986
+ end
987
+
988
+ name = node.rubyname
989
+ @nest -= 1
990
+ printiln("end #of union #{name}")
991
+ end
992
+
993
+ def visit_enum(node)
994
+ printiln(format('class %s < ::R2CORBA::FIXNUM_KLASS', node.rubyname))
995
+ nest {
996
+ printiln(format('def %s._tc', node.rubyname))
997
+ nest {
998
+ printi(format("@@tc_%s ||= CORBA::TypeCode::Enum.new('%s'.freeze, '%s', [",
999
+ node.rubyname, node.repository_id, node.rubyname))
1000
+ pfx = ''
1001
+ node.enumerators.each { |e|
1002
+ println(pfx)
1003
+ pfx = ','
1004
+ printi(" '#{e.rubyname}'")
1005
+ }
1006
+ println('])')
1007
+ }
1008
+ printiln('end')
1009
+ printiln('self._tc # register typecode');
1010
+ }
1011
+ printiln(format('end # enum %s', node.rubyname))
1012
+ end
1013
+
1014
+ def visit_enumerator(node)
1015
+ v = Expression::Value.new(node.idltype, node.value)
1016
+ s = node.rubyname + ' = ' + expression_to_s(v)
1017
+ printiln(s)
1018
+ end
1019
+
1020
+ def visit_typedef(node)
1021
+ # tc_ = node.enclosure.rubyname + '._tc_' + node.rubyname
1022
+ # typ_ = node.enclosure.rubyname + '.' + node.rubyname
1023
+ case t = node.idltype
1024
+ when Type::ScopedName
1025
+ if Type::Interface === t.resolved_type
1026
+ printiln(format('%s = %s # typedef %s', node.rubyname, t.node.scoped_rubyname, node.rubyname))
1027
+ else
1028
+ printiln(format('class %s < %s', node.rubyname, t.node.scoped_rubyname))
1029
+ nest {
1030
+ printi(format('def %s._tc; ', node.rubyname))
1031
+ print(format("@@tc_%s ||= CORBA::TypeCode::Alias.new('%s', '%s',", node.rubyname, node.repository_id, node.rubyname))
1032
+ println(format('%s, self); end', get_typecode(t)))
1033
+ }
1034
+ printiln(format('end # typedef %s', node.rubyname))
1035
+ end
1036
+
1037
+ when IDL::Type::Native
1038
+ printiln("class #{node.rubyname}; end ## 'native' type");
1039
+
1040
+ when Type::Any, Type::Octet,
1041
+ Type::UShort, Type::Short,
1042
+ Type::ULong, Type::Long,
1043
+ Type::ULongLong, Type::LongLong,
1044
+ Type::Boolean, Type::Char, Type::WChar,
1045
+ Type::Float, Type::Double, Type::LongDouble
1046
+ s = t.class.name.split('::') # IDL::Type::Octet -> [IDL, Type, Octet]
1047
+ s = s[s.length - 1]
1048
+ s.downcase!
1049
+ printiln(format('class %s < CORBA::_tc_%s.get_type', node.rubyname, s))
1050
+ nest {
1051
+ printiln(format("def %s._tc; @@tc_%s ||= CORBA::TypeCode::Alias.new('%s', '%s', CORBA::_tc_%s, self); end",
1052
+ node.rubyname, node.rubyname, node.repository_id, node.rubyname, s))
1053
+ }
1054
+ printiln(format('end # typedef %s', node.rubyname))
1055
+
1056
+ when Type::String
1057
+ printiln(format('class %s < String', node.rubyname))
1058
+ nest {
1059
+ if not t.length.nil?
1060
+ printiln(format("def %s._tc; @@tc_%s ||= CORBA::TypeCode::Alias.new('%s', '%s', CORBA::TypeCode::String.new(%d), self); end",
1061
+ node.rubyname, node.rubyname, node.repository_id, node.rubyname, t.length))
1062
+ else
1063
+ printiln(format("def %s._tc; @@tc_%s ||= CORBA::TypeCode::Alias.new('%s', '%s', CORBA::_tc_string, self); end",
1064
+ node.rubyname, node.rubyname, node.repository_id, node.rubyname))
1065
+ end
1066
+ }
1067
+ printiln(format('end # typedef %s', node.rubyname))
1068
+
1069
+ when Type::WString
1070
+ printiln(format('class %s < Array', node.rubyname))
1071
+ nest {
1072
+ if not t.length.nil?
1073
+ printiln(format("def %s._tc; @@tc_%s ||= CORBA::TypeCode::Alias.new('%s', '%s', CORBA::TypeCode::WString.new(%d), self); end",
1074
+ node.rubyname, node.rubyname, node.repository_id, node.rubyname, t.length))
1075
+ else
1076
+ printiln(format("def %s._tc; @@tc_%s ||= CORBA::TypeCode::Alias.new('%s', '%s', CORBA::_tc_wstring, self); end",
1077
+ node.rubyname, node.rubyname, node.repository_id, node.rubyname))
1078
+ end
1079
+ }
1080
+ printiln(format('end # typedef %s', node.rubyname))
1081
+
1082
+ when IDL::Type::Array
1083
+ printiln(format('class %s < Array', node.rubyname))
1084
+ nest {
1085
+ printiln(format('def %s._tc', node.rubyname))
1086
+ nest {
1087
+ printiln(format("@@tc_%s ||= CORBA::TypeCode::Alias.new('%s', '%s',", node.rubyname, node.repository_id, node.rubyname))
1088
+ nest { printiln(format('%s, self)', get_typecode(t))) }
1089
+ }
1090
+ printiln('end')
1091
+ }
1092
+ printiln(format('end # typedef %s', node.rubyname))
1093
+
1094
+ when IDL::Type::Sequence
1095
+ case t.basetype.resolved_type
1096
+ when IDL::Type::Char, IDL::Type::Octet
1097
+ printiln(format('class %s < String', node.rubyname))
1098
+ else
1099
+ printiln(format('class %s < Array', node.rubyname))
1100
+ end
1101
+ nest {
1102
+ printiln(format('def %s._tc', node.rubyname))
1103
+ nest {
1104
+ printiln(format("@@tc_%s ||= CORBA::TypeCode::Alias.new('%s', '%s',", node.rubyname, node.repository_id, node.rubyname))
1105
+ nest { printiln(format('%s, self)', get_typecode(t))) }
1106
+ }
1107
+ printiln('end')
1108
+ }
1109
+ printiln(format('end # typedef %s', node.rubyname))
1110
+
1111
+ when IDL::Type::Object
1112
+ printiln(format("%s = CORBA::Object # typedef %s\n", node.rubyname, node.rubyname))
1113
+
1114
+ else
1115
+ raise "unsupported typedef for #{t.class.name}."
1116
+ end
1117
+ end
1118
+ end ## RubyStubWriter
1119
+
1120
+ class RubyServantWriter < RubyWriterBase
1121
+ def initialize(output = STDOUT, params = {}, indent = ' ')
1122
+ super
1123
+ @stub_root = '::'
1124
+ end
1125
+
1126
+ def pre_visit(parser)
1127
+ print(
1128
+ %Q{# -*- Ruby -*-
1129
+ #
1130
+ # **** Code generated by the R2CORBA IDL Compiler ****
1131
+ # R2CORBA has been developed by:
1132
+ # Remedy IT Expertise BV
1133
+ # The Netherlands
1134
+ # https://www.remedy.nl
1135
+ #
1136
+ })
1137
+ idleval = @params[:idl_eval] || false
1138
+ println("require 'corba/poa.rb'") if @params[:libinit]
1139
+ if !@params[:expand_includes]
1140
+ println("require '" + @params[:idlfile].sub(/\.[^\.]*$/, @params[:stub_pfx]) + "'")
1141
+ end
1142
+ println()
1143
+ printiln('module POA')
1144
+ @nest += 1
1145
+ if !idleval
1146
+ printiln("CORBA.implement('#{@params[:idlfile]}', {}, CORBA::IDL::SERVANT_INTF) {")
1147
+ println()
1148
+ end
1149
+ ## register explicit (*not* IDL derived) rootnamespace used for client stubs
1150
+ @stub_root = "#{parser.root_namespace.rubyname}::" unless parser.root_namespace.nil?
1151
+ end
1152
+
1153
+ def post_visit(parser)
1154
+ idleval = @params[:idl_eval] || false
1155
+ if !idleval
1156
+ printiln("} ## end of '#{@params[:idlfile]}'")
1157
+ end
1158
+ @nest -= 1
1159
+ printiln('end #of module POA')
1160
+ println('# -*- END -*-')
1161
+ end
1162
+
1163
+ def visit_include(node)
1164
+ printiln(format("require '%s'", node.filename.sub(/\.[^\.]*$/, @params[:srv_pfx])))
1165
+ println()
1166
+ end
1167
+
1168
+ def enter_include(node)
1169
+ printiln('## include')
1170
+ printiln("CORBA.implement('#{node.filename}', {}, CORBA::IDL::SERVANT_INTF) {")
1171
+ println()
1172
+ end
1173
+
1174
+ def leave_include(node)
1175
+ println()
1176
+ printiln("} ## end of include '#{node.filename}'")
1177
+ println()
1178
+ end
1179
+
1180
+ def enter_module(node)
1181
+ printiln('module ' + node.rubyname)
1182
+ println()
1183
+ @nest += 1
1184
+ end
1185
+
1186
+ def leave_module(node)
1187
+ @nest -= 1
1188
+ printiln("end #of module #{node.rubyname}")
1189
+ println()
1190
+ end
1191
+
1192
+ def declare_interface(node)
1193
+ printiln("class #{node.rubyname} < PortableServer::Servant; end ## servant forward")
1194
+ end
1195
+
1196
+ def enter_interface(node)
1197
+ if !node.is_local?
1198
+ println
1199
+ printiln("class #{node.rubyname} < PortableServer::Servant ## servant")
1200
+ println()
1201
+ @nest += 1
1202
+
1203
+ printiln('module Intf')
1204
+ @nest += 1
1205
+ printiln(format("Id = '%s'.freeze", node.repository_id))
1206
+ printi('Ids = [ Id')
1207
+ if node.is_abstract?
1208
+ print(", 'IDL:omg.org/CORBA/AbstractBase:1.0'")
1209
+ end
1210
+ println(' ]')
1211
+ printiln('Operations = {}')
1212
+ println()
1213
+ end
1214
+ end
1215
+
1216
+ def leave_interface(node)
1217
+ if !node.is_local?
1218
+ name = node.rubyname
1219
+
1220
+ @nest -= 1
1221
+ printiln('end #of Intf')
1222
+
1223
+ println()
1224
+ printiln('Id = Intf::Id')
1225
+ println()
1226
+
1227
+ if node.bases.size > 0
1228
+ node.bases.each do |n|
1229
+ printiln("include_interface(#{n.scoped_rubyname}::Intf)")
1230
+ end
1231
+ else
1232
+ printiln('include_interface(PortableServer::Servant::Intf)')
1233
+ end
1234
+ println()
1235
+
1236
+ printiln('include Intf')
1237
+ println()
1238
+
1239
+ printiln("def _this; #{@stub_root}#{node.scoped_rubyname}._narrow(super); end")
1240
+
1241
+ @nest -= 1
1242
+ printiln("end #of servant #{name}")
1243
+ end
1244
+ end
1245
+
1246
+ def declare_valuetype(node)
1247
+ end
1248
+
1249
+ def enter_valuetype(node)
1250
+ println
1251
+ printiln("class #{node.rubyname} < PortableServer::Servant ## servant")
1252
+ @nest += 1
1253
+ printiln('## valuetype interface')
1254
+ printiln("include #{@stub_root}#{node.scoped_rubyname}")
1255
+ println
1256
+ printiln('## object interfaces')
1257
+ node.interfaces.each do |intf|
1258
+ # printiln("include #{@stub_root}#{intf.scoped_rubyname}")
1259
+ printiln("include #{intf.scoped_rubyname}")
1260
+ end
1261
+ end
1262
+
1263
+ def leave_valuetype(node)
1264
+ @nest -= 1
1265
+ printiln("end #of servant #{node.rubyname}")
1266
+ end
1267
+
1268
+ def visit_valuebox(node)
1269
+ end
1270
+
1271
+ def visit_const(node)
1272
+ end
1273
+
1274
+ def visit_operation(node)
1275
+ _parm = node.params
1276
+ _in = node.in_params
1277
+ _out = node.out_params
1278
+ _intf = node.enclosure
1279
+
1280
+ ## do nothing for valuetypes or local interfaces
1281
+ return nil if _intf.is_a?(IDL::AST::Valuetype) || _intf.is_local?
1282
+
1283
+ printi("Operations.store(:#{node.name}, {")
1284
+ newln = ''
1285
+ if _parm.size > 0
1286
+ println(newln)
1287
+ nest do
1288
+ printi(':arg_list => [')
1289
+ nest {
1290
+ pfx = ''
1291
+ _parm.each do |p|
1292
+ println(pfx)
1293
+ printi("['#{p.rubyname}', #{get_arg_type(p.attribute)}, ");
1294
+ print(get_typecode(p.idltype))
1295
+ print(']')
1296
+ pfx = ','
1297
+ end
1298
+ print(']')
1299
+ }
1300
+ end
1301
+ newln = ','
1302
+ end
1303
+
1304
+ if not node.oneway
1305
+ println(newln)
1306
+ nest { printi(":result_type => #{get_typecode(node.idltype)}") }
1307
+ newln = ','
1308
+ end
1309
+
1310
+ if node.raises.size > 0
1311
+ println(newln)
1312
+ nest {
1313
+ printi(':exc_list => [')
1314
+ pfx = ''
1315
+ nest {
1316
+ node.raises.each { |ex|
1317
+ println(pfx)
1318
+ pfx = ','
1319
+ printi(get_typecode(ex))
1320
+ }
1321
+ print(']')
1322
+ }
1323
+ }
1324
+ newln = ','
1325
+ end
1326
+
1327
+ if node.rubyname != node.name
1328
+ println(newln)
1329
+ nest { printi(":op_sym => :#{node.rubyname}") }
1330
+ end
1331
+ println('})')
1332
+ println()
1333
+
1334
+ printi("def #{node.rubyname}(")
1335
+ print(_in.collect{ |p| p.rubyname }.join(', '))
1336
+ if node.oneway
1337
+ println(') # oneway')
1338
+ else
1339
+ println(')')
1340
+ end
1341
+ nest {
1342
+ printiln('raise ::CORBA::NO_IMPLEMENT.new(')
1343
+ printiln(" 'unimplemented servant operation',")
1344
+ printiln(' 1, ::CORBA::COMPLETED_NO)')
1345
+ }
1346
+ printiln('end')
1347
+ println()
1348
+ end
1349
+
1350
+ def visit_attribute(node)
1351
+ _intf = node.enclosure
1352
+
1353
+ ## do nothing for valuetypes or local interfaces
1354
+ return nil if _intf.is_a?(IDL::AST::Valuetype) || _intf.is_local?
1355
+
1356
+ printiln("Operations.store(:_get_#{node.name}, {")
1357
+ nest {
1358
+ nest {
1359
+ printiln(":result_type => #{get_typecode(node.idltype)},")
1360
+ if node.get_raises.size > 0
1361
+ printi(':exc_list => [')
1362
+ pfx = ''
1363
+ nest {
1364
+ node.get_raises.each { |ex|
1365
+ println(pfx)
1366
+ pfx = ','
1367
+ printi(get_typecode(ex))
1368
+ }
1369
+ println('],')
1370
+ }
1371
+ end
1372
+ printiln(":op_sym => :#{node.rubyname} })")
1373
+ }
1374
+ }
1375
+ println()
1376
+
1377
+ printiln("def #{node.rubyname}()")
1378
+ nest {
1379
+ printiln('raise ::CORBA::NO_IMPLEMENT.new(')
1380
+ printiln(" 'unimplemented servant attribute get',")
1381
+ printiln(' 1, ::CORBA::COMPLETED_NO)')
1382
+ }
1383
+ printiln("end #of attribute get_#{node.name}")
1384
+ println()
1385
+
1386
+ if not node.readonly
1387
+ printiln("Operations.store(:_set_#{node.name}, {")
1388
+ nest {
1389
+ nest {
1390
+ printiln(':arg_list => [')
1391
+ nest {
1392
+ printiln("['val', CORBA::ARG_IN, #{get_typecode(node.idltype)}]],");
1393
+ }
1394
+ printiln(':result_type => CORBA._tc_void,')
1395
+ if node.set_raises.size > 0
1396
+ printi(':exc_list => [')
1397
+ pfx = ''
1398
+ nest {
1399
+ node.set_raises.each { |ex|
1400
+ println(pfx)
1401
+ pfx = ','
1402
+ printi(get_typecode(ex))
1403
+ }
1404
+ println('],')
1405
+ }
1406
+ end
1407
+ printiln(":op_sym => :#{node.rubyname}= })")
1408
+ }
1409
+ }
1410
+ println()
1411
+
1412
+ printiln("def #{node.rubyname}=(val)")
1413
+ nest {
1414
+ printiln('raise ::CORBA::NO_IMPLEMENT.new(')
1415
+ printiln(" 'unimplemented servant attribute set',")
1416
+ printiln(' 1, ::CORBA::COMPLETED_NO)')
1417
+ }
1418
+ printiln("end #of attribute set_#{node.name}")
1419
+ println()
1420
+ end
1421
+ end
1422
+
1423
+ def get_typecode(_type)
1424
+ case _type
1425
+ when Type::Octet,
1426
+ Type::UShort, Type::Short,
1427
+ Type::ULong, Type::Long,
1428
+ Type::ULongLong, Type::LongLong,
1429
+ Type::Boolean, Type::Char, Type::WChar,
1430
+ Type::Float, Type::Double, Type::LongDouble,
1431
+ Type::Void, Type::Any
1432
+ s = _type.class.name.split('::') # IDL::Type::Octet -> [IDL, Type, Octet]
1433
+ s = s[s.length - 1]
1434
+ s.downcase!
1435
+ format('CORBA._tc_%s', s)
1436
+
1437
+ when Type::Object
1438
+ 'CORBA._tc_Object'
1439
+
1440
+ when Type::String
1441
+ if not _type.length.nil?
1442
+ format('CORBA::TypeCode::String.new(%d)', _type.length)
1443
+ else
1444
+ 'CORBA._tc_string'
1445
+ end
1446
+
1447
+ when Type::WString
1448
+ if not _type.length.nil?
1449
+ format('CORBA::TypeCode::WString.new(%d)', _type.length)
1450
+ else
1451
+ 'CORBA._tc_wstring'
1452
+ end
1453
+
1454
+ when Type::ScopedName
1455
+ @stub_root + _type.node.scoped_rubyname + '._tc'
1456
+
1457
+ when Type::Array
1458
+ sep = ''
1459
+ tc = 'CORBA::TypeCode::Array.new(' +
1460
+ get_typecode(_type.basetype) + ', '
1461
+ _type.sizes.each do |sz|
1462
+ tc += "#{sep}#{sz.to_s}"
1463
+ sep = ', '
1464
+ end
1465
+ tc + ')'
1466
+
1467
+ when Type::Sequence
1468
+ if _type.is_recursive?
1469
+ "CORBA::TypeCode::Sequence.new(CORBA::TypeCode::Recursive.new('#{_type.basetype.resolved_type.node.repository_id}'))"
1470
+ else
1471
+ 'CORBA::TypeCode::Sequence.new(' +
1472
+ get_typecode(_type.basetype) +
1473
+ if not _type.length.nil? then format(', %d)', _type.length) else ')' end +
1474
+ '.freeze'
1475
+ end
1476
+
1477
+ else
1478
+ raise "invalid type for (un)marshalling: #{_type.typename}"
1479
+ end
1480
+ end
1481
+
1482
+ def get_arg_type(_idl_argtype)
1483
+ case _idl_argtype
1484
+ when IDL::AST::Parameter::IN
1485
+ 'CORBA::ARG_IN'
1486
+ when IDL::AST::Parameter::OUT
1487
+ 'CORBA::ARG_OUT'
1488
+ else
1489
+ 'CORBA::ARG_INOUT'
1490
+ end
1491
+ end
1492
+
1493
+ def expression_to_s(exp)
1494
+ case exp
1495
+ when Expression::Value
1496
+ value_to_s(exp)
1497
+ when Expression::Operation
1498
+ operation_to_s(exp)
1499
+ when Expression::ScopedName
1500
+ @stub_root + exp.node.scoped_rubyname
1501
+ else
1502
+ raise "unknown expression type: #{exp.class.name}"
1503
+ end
1504
+ end
1505
+
1506
+ def value_to_s(exp)
1507
+ s = nil
1508
+ v = exp.value
1509
+ case exp.idltype
1510
+ when Type::Void
1511
+ s = 'nil'
1512
+ when Type::Char
1513
+ s = "'#{v.chr}'"
1514
+ when Type::Integer,
1515
+ Type::Boolean,
1516
+ Type::Octet,
1517
+ Type::Float,
1518
+ Type::WChar
1519
+ s = v.to_s
1520
+ when Type::Enum
1521
+ s = v.to_s
1522
+ when Type::String
1523
+ s = "'#{v.to_s}'"
1524
+ when Type::WString
1525
+ s = "[#{v.join(',')}]"
1526
+ # when Type::Fixed
1527
+ # when Type::Any
1528
+ # when Type::Object
1529
+ when Type::ScopedName
1530
+ s = value_to_s(Expression::Value.new(exp.idltype.node.idltype, v))
1531
+ else
1532
+ raise "#{exp.typename}'s not been supported yet."
1533
+ end
1534
+ s
1535
+ end
1536
+
1537
+ def operation_to_s(exp)
1538
+ s = nil
1539
+ op = exp.operands
1540
+ case exp
1541
+ when Expression::UnaryPlus
1542
+ s = expression_to_s(op[0])
1543
+ when Expression::UnaryMinus
1544
+ s = '-' + expression_to_s(op[0])
1545
+ when Expression::UnaryNot
1546
+ s = '~' + expression_to_s(op[0])
1547
+ when Expression::Or
1548
+ s = expression_to_s(op[0]) + ' | ' + expression_to_s(op[1])
1549
+ when Expression::And
1550
+ s = expression_to_s(op[0]) + ' & ' + expression_to_s(op[1])
1551
+ when Expression::LShift
1552
+ s = expression_to_s(op[0]) + ' << ' + expression_to_s(op[1])
1553
+ when Expression::RShift
1554
+ s = expression_to_s(op[0]) + ' >> ' + expression_to_s(op[1])
1555
+ when Expression::Add
1556
+ s = expression_to_s(op[0]) + ' + ' + expression_to_s(op[1])
1557
+ when Expression::Minus
1558
+ s = expression_to_s(op[0]) + ' - ' + expression_to_s(op[1])
1559
+ when Expression::Mult
1560
+ s = expression_to_s(op[0]) + ' * ' + expression_to_s(op[1])
1561
+ when Expression::Div
1562
+ s = expression_to_s(op[0]) + ' / ' + expression_to_s(op[1])
1563
+ when Expression::Mod
1564
+ s = expression_to_s(op[0]) + ' % ' + expression_to_s(op[1])
1565
+ else
1566
+ raise "unknown operation: #{exp.type.name}"
1567
+ end
1568
+ '(' + s + ')'
1569
+ end
1570
+
1571
+ def declare_struct(node)
1572
+ end
1573
+
1574
+ def enter_struct(node)
1575
+ end
1576
+
1577
+ def leave_struct(node)
1578
+ end
1579
+
1580
+ def enter_exception(node)
1581
+ end
1582
+
1583
+ def leave_exception(node)
1584
+ end
1585
+
1586
+ def declare_union(node)
1587
+ end
1588
+
1589
+ def enter_union(node)
1590
+ end
1591
+
1592
+ def leave_union(node)
1593
+ end
1594
+
1595
+ def visit_enum(node)
1596
+ end
1597
+
1598
+ def visit_enumerator(node)
1599
+ end
1600
+
1601
+ def visit_typedef(node)
1602
+ end
1603
+ end ## RubyServantWriter
1604
+
1605
+ end ## module IDL