r2corba 1.4.1

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