zeroc-ice 3.6b1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (675) hide show
  1. checksums.yaml +7 -0
  2. data/ICE_LICENSE +54 -0
  3. data/LICENSE +339 -0
  4. data/bin/slice2rb +17 -0
  5. data/ext/Communicator.cpp +596 -0
  6. data/ext/Communicator.h +25 -0
  7. data/ext/Config.h +111 -0
  8. data/ext/Connection.cpp +381 -0
  9. data/ext/Connection.h +26 -0
  10. data/ext/Endpoint.cpp +311 -0
  11. data/ext/Endpoint.h +27 -0
  12. data/ext/ImplicitContext.cpp +152 -0
  13. data/ext/ImplicitContext.h +25 -0
  14. data/ext/Init.cpp +52 -0
  15. data/ext/Logger.cpp +151 -0
  16. data/ext/Logger.h +28 -0
  17. data/ext/ObjectFactory.cpp +140 -0
  18. data/ext/ObjectFactory.h +50 -0
  19. data/ext/Operation.cpp +676 -0
  20. data/ext/Operation.h +36 -0
  21. data/ext/Properties.cpp +369 -0
  22. data/ext/Properties.h +25 -0
  23. data/ext/Proxy.cpp +1354 -0
  24. data/ext/Proxy.h +27 -0
  25. data/ext/Slice.cpp +223 -0
  26. data/ext/Slice.h +22 -0
  27. data/ext/Types.cpp +3160 -0
  28. data/ext/Types.h +545 -0
  29. data/ext/Util.cpp +792 -0
  30. data/ext/Util.h +511 -0
  31. data/ext/extconf.rb +118 -0
  32. data/ext/ice/BZIP_LICENSE +42 -0
  33. data/ext/ice/MCPP_LICENSE +36 -0
  34. data/ext/ice/bzip2/blocksort.c +1094 -0
  35. data/ext/ice/bzip2/bzlib.c +1572 -0
  36. data/ext/ice/bzip2/bzlib.h +282 -0
  37. data/ext/ice/bzip2/bzlib_private.h +509 -0
  38. data/ext/ice/bzip2/compress.c +672 -0
  39. data/ext/ice/bzip2/crctable.c +104 -0
  40. data/ext/ice/bzip2/decompress.c +646 -0
  41. data/ext/ice/bzip2/huffman.c +205 -0
  42. data/ext/ice/bzip2/randtable.c +84 -0
  43. data/ext/ice/cpp/include/Ice/ACMF.h +30 -0
  44. data/ext/ice/cpp/include/Ice/Application.h +156 -0
  45. data/ext/ice/cpp/include/Ice/AsyncResult.h +363 -0
  46. data/ext/ice/cpp/include/Ice/AsyncResultF.h +26 -0
  47. data/ext/ice/cpp/include/Ice/BasicStream.h +1315 -0
  48. data/ext/ice/cpp/include/Ice/Buffer.h +159 -0
  49. data/ext/ice/cpp/include/Ice/BuiltinSequences.h +74 -0
  50. data/ext/ice/cpp/include/Ice/Communicator.h +194 -0
  51. data/ext/ice/cpp/include/Ice/CommunicatorAsync.h +115 -0
  52. data/ext/ice/cpp/include/Ice/CommunicatorF.h +60 -0
  53. data/ext/ice/cpp/include/Ice/Config.h +97 -0
  54. data/ext/ice/cpp/include/Ice/Connection.h +495 -0
  55. data/ext/ice/cpp/include/Ice/ConnectionAsync.h +115 -0
  56. data/ext/ice/cpp/include/Ice/ConnectionF.h +72 -0
  57. data/ext/ice/cpp/include/Ice/ConnectionFactoryF.h +30 -0
  58. data/ext/ice/cpp/include/Ice/ConnectionIF.h +37 -0
  59. data/ext/ice/cpp/include/Ice/Current.h +94 -0
  60. data/ext/ice/cpp/include/Ice/DefaultObjectFactory.h +48 -0
  61. data/ext/ice/cpp/include/Ice/DeprecatedStringConverter.h +62 -0
  62. data/ext/ice/cpp/include/Ice/DispatchInterceptor.h +33 -0
  63. data/ext/ice/cpp/include/Ice/Dispatcher.h +51 -0
  64. data/ext/ice/cpp/include/Ice/DynamicLibrary.h +105 -0
  65. data/ext/ice/cpp/include/Ice/DynamicLibraryF.h +29 -0
  66. data/ext/ice/cpp/include/Ice/Endpoint.h +350 -0
  67. data/ext/ice/cpp/include/Ice/EndpointF.h +97 -0
  68. data/ext/ice/cpp/include/Ice/EndpointTypes.h +74 -0
  69. data/ext/ice/cpp/include/Ice/Exception.h +114 -0
  70. data/ext/ice/cpp/include/Ice/FacetMap.h +56 -0
  71. data/ext/ice/cpp/include/Ice/FactoryTable.h +69 -0
  72. data/ext/ice/cpp/include/Ice/FactoryTableInit.h +87 -0
  73. data/ext/ice/cpp/include/Ice/Format.h +39 -0
  74. data/ext/ice/cpp/include/Ice/Functional.h +138 -0
  75. data/ext/ice/cpp/include/Ice/GCObject.h +73 -0
  76. data/ext/ice/cpp/include/Ice/Handle.h +192 -0
  77. data/ext/ice/cpp/include/Ice/Ice.h +54 -0
  78. data/ext/ice/cpp/include/Ice/Identity.h +160 -0
  79. data/ext/ice/cpp/include/Ice/ImplicitContext.h +96 -0
  80. data/ext/ice/cpp/include/Ice/ImplicitContextF.h +60 -0
  81. data/ext/ice/cpp/include/Ice/Incoming.h +131 -0
  82. data/ext/ice/cpp/include/Ice/IncomingAsync.h +108 -0
  83. data/ext/ice/cpp/include/Ice/IncomingAsyncF.h +35 -0
  84. data/ext/ice/cpp/include/Ice/Initialize.h +141 -0
  85. data/ext/ice/cpp/include/Ice/InstanceF.h +26 -0
  86. data/ext/ice/cpp/include/Ice/Instrumentation.h +377 -0
  87. data/ext/ice/cpp/include/Ice/InstrumentationF.h +71 -0
  88. data/ext/ice/cpp/include/Ice/LocalException.h +1022 -0
  89. data/ext/ice/cpp/include/Ice/LocalObject.h +36 -0
  90. data/ext/ice/cpp/include/Ice/LocalObjectF.h +26 -0
  91. data/ext/ice/cpp/include/Ice/Locator.h +2191 -0
  92. data/ext/ice/cpp/include/Ice/LocatorF.h +89 -0
  93. data/ext/ice/cpp/include/Ice/Logger.h +94 -0
  94. data/ext/ice/cpp/include/Ice/LoggerF.h +60 -0
  95. data/ext/ice/cpp/include/Ice/LoggerUtil.h +153 -0
  96. data/ext/ice/cpp/include/Ice/Makefile +26 -0
  97. data/ext/ice/cpp/include/Ice/Metrics.h +2989 -0
  98. data/ext/ice/cpp/include/Ice/MetricsAdminI.h +662 -0
  99. data/ext/ice/cpp/include/Ice/MetricsFunctional.h +144 -0
  100. data/ext/ice/cpp/include/Ice/MetricsObserverI.h +576 -0
  101. data/ext/ice/cpp/include/Ice/NativePropertiesAdmin.h +55 -0
  102. data/ext/ice/cpp/include/Ice/Object.h +165 -0
  103. data/ext/ice/cpp/include/Ice/ObjectAdapter.h +162 -0
  104. data/ext/ice/cpp/include/Ice/ObjectAdapterF.h +60 -0
  105. data/ext/ice/cpp/include/Ice/ObjectAdapterFactoryF.h +26 -0
  106. data/ext/ice/cpp/include/Ice/ObjectF.h +26 -0
  107. data/ext/ice/cpp/include/Ice/ObjectFactory.h +86 -0
  108. data/ext/ice/cpp/include/Ice/ObjectFactoryF.h +60 -0
  109. data/ext/ice/cpp/include/Ice/ObjectFactoryManagerF.h +26 -0
  110. data/ext/ice/cpp/include/Ice/ObserverHelper.h +177 -0
  111. data/ext/ice/cpp/include/Ice/Outgoing.h +197 -0
  112. data/ext/ice/cpp/include/Ice/OutgoingAsync.h +264 -0
  113. data/ext/ice/cpp/include/Ice/OutgoingAsyncF.h +38 -0
  114. data/ext/ice/cpp/include/Ice/Plugin.h +121 -0
  115. data/ext/ice/cpp/include/Ice/PluginF.h +66 -0
  116. data/ext/ice/cpp/include/Ice/Process.h +568 -0
  117. data/ext/ice/cpp/include/Ice/ProcessF.h +77 -0
  118. data/ext/ice/cpp/include/Ice/Properties.h +130 -0
  119. data/ext/ice/cpp/include/Ice/PropertiesAdmin.h +824 -0
  120. data/ext/ice/cpp/include/Ice/PropertiesF.h +83 -0
  121. data/ext/ice/cpp/include/Ice/Protocol.h +242 -0
  122. data/ext/ice/cpp/include/Ice/Proxy.h +2448 -0
  123. data/ext/ice/cpp/include/Ice/ProxyF.h +78 -0
  124. data/ext/ice/cpp/include/Ice/ProxyFactoryF.h +26 -0
  125. data/ext/ice/cpp/include/Ice/ProxyHandle.h +330 -0
  126. data/ext/ice/cpp/include/Ice/ReferenceF.h +34 -0
  127. data/ext/ice/cpp/include/Ice/RemoteLogger.h +1496 -0
  128. data/ext/ice/cpp/include/Ice/RequestHandlerF.h +29 -0
  129. data/ext/ice/cpp/include/Ice/ResponseHandlerF.h +25 -0
  130. data/ext/ice/cpp/include/Ice/Router.h +1155 -0
  131. data/ext/ice/cpp/include/Ice/RouterF.h +77 -0
  132. data/ext/ice/cpp/include/Ice/ServantLocator.h +90 -0
  133. data/ext/ice/cpp/include/Ice/ServantLocatorF.h +60 -0
  134. data/ext/ice/cpp/include/Ice/ServantManagerF.h +26 -0
  135. data/ext/ice/cpp/include/Ice/Service.h +260 -0
  136. data/ext/ice/cpp/include/Ice/SliceChecksumDict.h +56 -0
  137. data/ext/ice/cpp/include/Ice/SliceChecksums.h +34 -0
  138. data/ext/ice/cpp/include/Ice/SlicedData.h +103 -0
  139. data/ext/ice/cpp/include/Ice/SlicedDataF.h +34 -0
  140. data/ext/ice/cpp/include/Ice/Stream.h +449 -0
  141. data/ext/ice/cpp/include/Ice/StreamF.h +30 -0
  142. data/ext/ice/cpp/include/Ice/StreamHelpers.h +877 -0
  143. data/ext/ice/cpp/include/Ice/ThreadPoolF.h +28 -0
  144. data/ext/ice/cpp/include/Ice/UserExceptionFactory.h +56 -0
  145. data/ext/ice/cpp/include/Ice/Version.h +254 -0
  146. data/ext/ice/cpp/include/IceSSL/Config.h +23 -0
  147. data/ext/ice/cpp/include/IceSSL/ConnectionInfo.h +119 -0
  148. data/ext/ice/cpp/include/IceSSL/EndpointInfo.h +101 -0
  149. data/ext/ice/cpp/include/IceSSL/IceSSL.h +22 -0
  150. data/ext/ice/cpp/include/IceSSL/Makefile +26 -0
  151. data/ext/ice/cpp/include/IceSSL/Plugin.h +558 -0
  152. data/ext/ice/cpp/include/IceUtil/AbstractMutex.h +119 -0
  153. data/ext/ice/cpp/include/IceUtil/Cache.h +362 -0
  154. data/ext/ice/cpp/include/IceUtil/Cond.h +323 -0
  155. data/ext/ice/cpp/include/IceUtil/Config.h +234 -0
  156. data/ext/ice/cpp/include/IceUtil/CountDownLatch.h +50 -0
  157. data/ext/ice/cpp/include/IceUtil/CtrlCHandler.h +70 -0
  158. data/ext/ice/cpp/include/IceUtil/DisableWarnings.h +45 -0
  159. data/ext/ice/cpp/include/IceUtil/Exception.h +184 -0
  160. data/ext/ice/cpp/include/IceUtil/Functional.h +389 -0
  161. data/ext/ice/cpp/include/IceUtil/Handle.h +266 -0
  162. data/ext/ice/cpp/include/IceUtil/IceUtil.h +51 -0
  163. data/ext/ice/cpp/include/IceUtil/IconvStringConverter.h +302 -0
  164. data/ext/ice/cpp/include/IceUtil/InputUtil.h +47 -0
  165. data/ext/ice/cpp/include/IceUtil/Iterator.h +36 -0
  166. data/ext/ice/cpp/include/IceUtil/Lock.h +135 -0
  167. data/ext/ice/cpp/include/IceUtil/Makefile +26 -0
  168. data/ext/ice/cpp/include/IceUtil/Monitor.h +249 -0
  169. data/ext/ice/cpp/include/IceUtil/Mutex.h +357 -0
  170. data/ext/ice/cpp/include/IceUtil/MutexProtocol.h +28 -0
  171. data/ext/ice/cpp/include/IceUtil/MutexPtrLock.h +83 -0
  172. data/ext/ice/cpp/include/IceUtil/MutexPtrTryLock.h +82 -0
  173. data/ext/ice/cpp/include/IceUtil/Optional.h +322 -0
  174. data/ext/ice/cpp/include/IceUtil/Options.h +141 -0
  175. data/ext/ice/cpp/include/IceUtil/OutputUtil.h +362 -0
  176. data/ext/ice/cpp/include/IceUtil/PopDisableWarnings.h +19 -0
  177. data/ext/ice/cpp/include/IceUtil/PushDisableWarnings.h +26 -0
  178. data/ext/ice/cpp/include/IceUtil/Random.h +24 -0
  179. data/ext/ice/cpp/include/IceUtil/RecMutex.h +113 -0
  180. data/ext/ice/cpp/include/IceUtil/SHA1.h +65 -0
  181. data/ext/ice/cpp/include/IceUtil/ScannerConfig.h +44 -0
  182. data/ext/ice/cpp/include/IceUtil/ScopedArray.h +97 -0
  183. data/ext/ice/cpp/include/IceUtil/Shared.h +168 -0
  184. data/ext/ice/cpp/include/IceUtil/StringConverter.h +175 -0
  185. data/ext/ice/cpp/include/IceUtil/StringUtil.h +91 -0
  186. data/ext/ice/cpp/include/IceUtil/Thread.h +181 -0
  187. data/ext/ice/cpp/include/IceUtil/ThreadException.h +108 -0
  188. data/ext/ice/cpp/include/IceUtil/Time.h +209 -0
  189. data/ext/ice/cpp/include/IceUtil/Timer.h +143 -0
  190. data/ext/ice/cpp/include/IceUtil/UUID.h +22 -0
  191. data/ext/ice/cpp/include/IceUtil/UndefSysMacros.h +42 -0
  192. data/ext/ice/cpp/include/IceUtil/UniquePtr.h +101 -0
  193. data/ext/ice/cpp/include/Slice/CPlusPlusUtil.h +64 -0
  194. data/ext/ice/cpp/include/Slice/Checksum.h +26 -0
  195. data/ext/ice/cpp/include/Slice/CsUtil.h +92 -0
  196. data/ext/ice/cpp/include/Slice/DotNetNames.h +34 -0
  197. data/ext/ice/cpp/include/Slice/FileTracker.h +71 -0
  198. data/ext/ice/cpp/include/Slice/JavaUtil.h +277 -0
  199. data/ext/ice/cpp/include/Slice/Makefile +26 -0
  200. data/ext/ice/cpp/include/Slice/PHPUtil.h +50 -0
  201. data/ext/ice/cpp/include/Slice/Parser.h +1116 -0
  202. data/ext/ice/cpp/include/Slice/Preprocessor.h +68 -0
  203. data/ext/ice/cpp/include/Slice/PythonUtil.h +64 -0
  204. data/ext/ice/cpp/include/Slice/RubyUtil.h +54 -0
  205. data/ext/ice/cpp/include/Slice/Util.h +33 -0
  206. data/ext/ice/cpp/src/Ice/ACM.cpp +343 -0
  207. data/ext/ice/cpp/src/Ice/ACM.h +117 -0
  208. data/ext/ice/cpp/src/Ice/Acceptor.cpp +16 -0
  209. data/ext/ice/cpp/src/Ice/Acceptor.h +41 -0
  210. data/ext/ice/cpp/src/Ice/AcceptorF.h +30 -0
  211. data/ext/ice/cpp/src/Ice/Application.cpp +760 -0
  212. data/ext/ice/cpp/src/Ice/AsyncResult.cpp +599 -0
  213. data/ext/ice/cpp/src/Ice/Base64.cpp +269 -0
  214. data/ext/ice/cpp/src/Ice/Base64.h +36 -0
  215. data/ext/ice/cpp/src/Ice/BasicStream.cpp +3393 -0
  216. data/ext/ice/cpp/src/Ice/Buffer.cpp +98 -0
  217. data/ext/ice/cpp/src/Ice/BuiltinSequences.cpp +34 -0
  218. data/ext/ice/cpp/src/Ice/CollocatedRequestHandler.cpp +718 -0
  219. data/ext/ice/cpp/src/Ice/CollocatedRequestHandler.h +106 -0
  220. data/ext/ice/cpp/src/Ice/Communicator.cpp +45 -0
  221. data/ext/ice/cpp/src/Ice/CommunicatorF.cpp +38 -0
  222. data/ext/ice/cpp/src/Ice/CommunicatorI.cpp +386 -0
  223. data/ext/ice/cpp/src/Ice/CommunicatorI.h +112 -0
  224. data/ext/ice/cpp/src/Ice/ConnectRequestHandler.cpp +546 -0
  225. data/ext/ice/cpp/src/Ice/ConnectRequestHandler.h +97 -0
  226. data/ext/ice/cpp/src/Ice/Connection.cpp +58 -0
  227. data/ext/ice/cpp/src/Ice/ConnectionF.cpp +38 -0
  228. data/ext/ice/cpp/src/Ice/ConnectionFactory.cpp +1639 -0
  229. data/ext/ice/cpp/src/Ice/ConnectionFactory.h +236 -0
  230. data/ext/ice/cpp/src/Ice/ConnectionI.cpp +3876 -0
  231. data/ext/ice/cpp/src/Ice/ConnectionI.h +364 -0
  232. data/ext/ice/cpp/src/Ice/ConnectionRequestHandler.cpp +115 -0
  233. data/ext/ice/cpp/src/Ice/ConnectionRequestHandler.h +50 -0
  234. data/ext/ice/cpp/src/Ice/Connector.cpp +16 -0
  235. data/ext/ice/cpp/src/Ice/Connector.h +36 -0
  236. data/ext/ice/cpp/src/Ice/ConnectorF.h +26 -0
  237. data/ext/ice/cpp/src/Ice/Current.cpp +38 -0
  238. data/ext/ice/cpp/src/Ice/DefaultsAndOverrides.cpp +168 -0
  239. data/ext/ice/cpp/src/Ice/DefaultsAndOverrides.h +57 -0
  240. data/ext/ice/cpp/src/Ice/DefaultsAndOverridesF.h +26 -0
  241. data/ext/ice/cpp/src/Ice/DeprecatedStringConverter.cpp +60 -0
  242. data/ext/ice/cpp/src/Ice/DispatchInterceptor.cpp +49 -0
  243. data/ext/ice/cpp/src/Ice/DynamicLibrary.cpp +281 -0
  244. data/ext/ice/cpp/src/Ice/Endpoint.cpp +53 -0
  245. data/ext/ice/cpp/src/Ice/EndpointF.cpp +38 -0
  246. data/ext/ice/cpp/src/Ice/EndpointFactory.cpp +25 -0
  247. data/ext/ice/cpp/src/Ice/EndpointFactory.h +44 -0
  248. data/ext/ice/cpp/src/Ice/EndpointFactoryF.h +26 -0
  249. data/ext/ice/cpp/src/Ice/EndpointFactoryManager.cpp +208 -0
  250. data/ext/ice/cpp/src/Ice/EndpointFactoryManager.h +46 -0
  251. data/ext/ice/cpp/src/Ice/EndpointFactoryManagerF.h +26 -0
  252. data/ext/ice/cpp/src/Ice/EndpointI.cpp +87 -0
  253. data/ext/ice/cpp/src/Ice/EndpointI.h +165 -0
  254. data/ext/ice/cpp/src/Ice/EndpointIF.h +41 -0
  255. data/ext/ice/cpp/src/Ice/EndpointTypes.cpp +38 -0
  256. data/ext/ice/cpp/src/Ice/EventHandler.cpp +35 -0
  257. data/ext/ice/cpp/src/Ice/EventHandler.h +78 -0
  258. data/ext/ice/cpp/src/Ice/EventHandlerF.h +26 -0
  259. data/ext/ice/cpp/src/Ice/EventLoggerMsg.h +53 -0
  260. data/ext/ice/cpp/src/Ice/Exception.cpp +832 -0
  261. data/ext/ice/cpp/src/Ice/FacetMap.cpp +34 -0
  262. data/ext/ice/cpp/src/Ice/FactoryTable.cpp +158 -0
  263. data/ext/ice/cpp/src/Ice/FactoryTableInit.cpp +95 -0
  264. data/ext/ice/cpp/src/Ice/GCObject.cpp +444 -0
  265. data/ext/ice/cpp/src/Ice/HashUtil.h +59 -0
  266. data/ext/ice/cpp/src/Ice/HttpParser.cpp +680 -0
  267. data/ext/ice/cpp/src/Ice/HttpParser.h +124 -0
  268. data/ext/ice/cpp/src/Ice/IPEndpointI.cpp +733 -0
  269. data/ext/ice/cpp/src/Ice/IPEndpointI.h +157 -0
  270. data/ext/ice/cpp/src/Ice/IPEndpointIF.h +29 -0
  271. data/ext/ice/cpp/src/Ice/Identity.cpp +42 -0
  272. data/ext/ice/cpp/src/Ice/ImplicitContext.cpp +41 -0
  273. data/ext/ice/cpp/src/Ice/ImplicitContextF.cpp +38 -0
  274. data/ext/ice/cpp/src/Ice/ImplicitContextI.cpp +639 -0
  275. data/ext/ice/cpp/src/Ice/ImplicitContextI.h +51 -0
  276. data/ext/ice/cpp/src/Ice/Incoming.cpp +757 -0
  277. data/ext/ice/cpp/src/Ice/IncomingAsync.cpp +340 -0
  278. data/ext/ice/cpp/src/Ice/IncomingRequest.h +37 -0
  279. data/ext/ice/cpp/src/Ice/Initialize.cpp +401 -0
  280. data/ext/ice/cpp/src/Ice/Instance.cpp +1928 -0
  281. data/ext/ice/cpp/src/Ice/Instance.h +198 -0
  282. data/ext/ice/cpp/src/Ice/Instrumentation.cpp +68 -0
  283. data/ext/ice/cpp/src/Ice/InstrumentationF.cpp +43 -0
  284. data/ext/ice/cpp/src/Ice/InstrumentationI.cpp +1083 -0
  285. data/ext/ice/cpp/src/Ice/InstrumentationI.h +262 -0
  286. data/ext/ice/cpp/src/Ice/LocalException.cpp +2091 -0
  287. data/ext/ice/cpp/src/Ice/LocalObject.cpp +29 -0
  288. data/ext/ice/cpp/src/Ice/Locator.cpp +1946 -0
  289. data/ext/ice/cpp/src/Ice/LocatorF.cpp +39 -0
  290. data/ext/ice/cpp/src/Ice/LocatorInfo.cpp +917 -0
  291. data/ext/ice/cpp/src/Ice/LocatorInfo.h +193 -0
  292. data/ext/ice/cpp/src/Ice/LocatorInfoF.h +34 -0
  293. data/ext/ice/cpp/src/Ice/Logger.cpp +40 -0
  294. data/ext/ice/cpp/src/Ice/LoggerAdminI.cpp +862 -0
  295. data/ext/ice/cpp/src/Ice/LoggerAdminI.h +46 -0
  296. data/ext/ice/cpp/src/Ice/LoggerF.cpp +38 -0
  297. data/ext/ice/cpp/src/Ice/LoggerI.cpp +199 -0
  298. data/ext/ice/cpp/src/Ice/LoggerI.h +57 -0
  299. data/ext/ice/cpp/src/Ice/LoggerUtil.cpp +107 -0
  300. data/ext/ice/cpp/src/Ice/Makefile +190 -0
  301. data/ext/ice/cpp/src/Ice/Metrics.cpp +2159 -0
  302. data/ext/ice/cpp/src/Ice/MetricsAdminI.cpp +669 -0
  303. data/ext/ice/cpp/src/Ice/MetricsObserverI.cpp +14 -0
  304. data/ext/ice/cpp/src/Ice/Network.cpp +2694 -0
  305. data/ext/ice/cpp/src/Ice/Network.h +291 -0
  306. data/ext/ice/cpp/src/Ice/NetworkF.h +28 -0
  307. data/ext/ice/cpp/src/Ice/NetworkProxy.cpp +325 -0
  308. data/ext/ice/cpp/src/Ice/NetworkProxy.h +74 -0
  309. data/ext/ice/cpp/src/Ice/NetworkProxyF.h +26 -0
  310. data/ext/ice/cpp/src/Ice/Object.cpp +440 -0
  311. data/ext/ice/cpp/src/Ice/ObjectAdapter.cpp +41 -0
  312. data/ext/ice/cpp/src/Ice/ObjectAdapterF.cpp +38 -0
  313. data/ext/ice/cpp/src/Ice/ObjectAdapterFactory.cpp +241 -0
  314. data/ext/ice/cpp/src/Ice/ObjectAdapterFactory.h +52 -0
  315. data/ext/ice/cpp/src/Ice/ObjectAdapterI.cpp +1498 -0
  316. data/ext/ice/cpp/src/Ice/ObjectAdapterI.h +155 -0
  317. data/ext/ice/cpp/src/Ice/ObjectFactory.cpp +41 -0
  318. data/ext/ice/cpp/src/Ice/ObjectFactoryF.cpp +38 -0
  319. data/ext/ice/cpp/src/Ice/ObjectFactoryManager.cpp +140 -0
  320. data/ext/ice/cpp/src/Ice/ObjectFactoryManager.h +43 -0
  321. data/ext/ice/cpp/src/Ice/ObserverHelper.cpp +84 -0
  322. data/ext/ice/cpp/src/Ice/OpaqueEndpointI.cpp +407 -0
  323. data/ext/ice/cpp/src/Ice/OpaqueEndpointI.h +70 -0
  324. data/ext/ice/cpp/src/Ice/Outgoing.cpp +737 -0
  325. data/ext/ice/cpp/src/Ice/OutgoingAsync.cpp +874 -0
  326. data/ext/ice/cpp/src/Ice/Plugin.cpp +43 -0
  327. data/ext/ice/cpp/src/Ice/PluginF.cpp +38 -0
  328. data/ext/ice/cpp/src/Ice/PluginManagerI.cpp +503 -0
  329. data/ext/ice/cpp/src/Ice/PluginManagerI.h +67 -0
  330. data/ext/ice/cpp/src/Ice/Process.cpp +299 -0
  331. data/ext/ice/cpp/src/Ice/ProcessF.cpp +39 -0
  332. data/ext/ice/cpp/src/Ice/Properties.cpp +45 -0
  333. data/ext/ice/cpp/src/Ice/PropertiesAdmin.cpp +555 -0
  334. data/ext/ice/cpp/src/Ice/PropertiesAdminI.cpp +207 -0
  335. data/ext/ice/cpp/src/Ice/PropertiesAdminI.h +45 -0
  336. data/ext/ice/cpp/src/Ice/PropertiesF.cpp +39 -0
  337. data/ext/ice/cpp/src/Ice/PropertiesI.cpp +759 -0
  338. data/ext/ice/cpp/src/Ice/PropertiesI.h +78 -0
  339. data/ext/ice/cpp/src/Ice/PropertyNames.cpp +1293 -0
  340. data/ext/ice/cpp/src/Ice/PropertyNames.h +81 -0
  341. data/ext/ice/cpp/src/Ice/Protocol.cpp +137 -0
  342. data/ext/ice/cpp/src/Ice/ProtocolInstance.cpp +98 -0
  343. data/ext/ice/cpp/src/Ice/ProtocolInstance.h +91 -0
  344. data/ext/ice/cpp/src/Ice/ProtocolInstanceF.h +26 -0
  345. data/ext/ice/cpp/src/Ice/ProtocolPluginFacade.cpp +51 -0
  346. data/ext/ice/cpp/src/Ice/ProtocolPluginFacade.h +67 -0
  347. data/ext/ice/cpp/src/Ice/ProtocolPluginFacadeF.h +26 -0
  348. data/ext/ice/cpp/src/Ice/Proxy.cpp +1810 -0
  349. data/ext/ice/cpp/src/Ice/ProxyFactory.cpp +305 -0
  350. data/ext/ice/cpp/src/Ice/ProxyFactory.h +57 -0
  351. data/ext/ice/cpp/src/Ice/Reference.cpp +1947 -0
  352. data/ext/ice/cpp/src/Ice/Reference.h +305 -0
  353. data/ext/ice/cpp/src/Ice/ReferenceFactory.cpp +937 -0
  354. data/ext/ice/cpp/src/Ice/ReferenceFactory.h +81 -0
  355. data/ext/ice/cpp/src/Ice/ReferenceFactoryF.h +24 -0
  356. data/ext/ice/cpp/src/Ice/RemoteLogger.cpp +958 -0
  357. data/ext/ice/cpp/src/Ice/ReplyStatus.h +29 -0
  358. data/ext/ice/cpp/src/Ice/RequestHandler.cpp +40 -0
  359. data/ext/ice/cpp/src/Ice/RequestHandler.h +90 -0
  360. data/ext/ice/cpp/src/Ice/RequestHandlerFactory.cpp +70 -0
  361. data/ext/ice/cpp/src/Ice/RequestHandlerFactory.h +41 -0
  362. data/ext/ice/cpp/src/Ice/ResponseHandler.cpp +20 -0
  363. data/ext/ice/cpp/src/Ice/ResponseHandler.h +39 -0
  364. data/ext/ice/cpp/src/Ice/RetryQueue.cpp +154 -0
  365. data/ext/ice/cpp/src/Ice/RetryQueue.h +69 -0
  366. data/ext/ice/cpp/src/Ice/RetryQueueF.h +24 -0
  367. data/ext/ice/cpp/src/Ice/Router.cpp +849 -0
  368. data/ext/ice/cpp/src/Ice/RouterF.cpp +39 -0
  369. data/ext/ice/cpp/src/Ice/RouterInfo.cpp +381 -0
  370. data/ext/ice/cpp/src/Ice/RouterInfo.h +148 -0
  371. data/ext/ice/cpp/src/Ice/RouterInfoF.h +30 -0
  372. data/ext/ice/cpp/src/Ice/Selector.cpp +926 -0
  373. data/ext/ice/cpp/src/Ice/Selector.h +231 -0
  374. data/ext/ice/cpp/src/Ice/ServantLocator.cpp +41 -0
  375. data/ext/ice/cpp/src/Ice/ServantLocatorF.cpp +38 -0
  376. data/ext/ice/cpp/src/Ice/ServantManager.cpp +495 -0
  377. data/ext/ice/cpp/src/Ice/ServantManager.h +74 -0
  378. data/ext/ice/cpp/src/Ice/Service.cpp +1897 -0
  379. data/ext/ice/cpp/src/Ice/SharedContext.h +51 -0
  380. data/ext/ice/cpp/src/Ice/SliceChecksumDict.cpp +34 -0
  381. data/ext/ice/cpp/src/Ice/SliceChecksums.cpp +80 -0
  382. data/ext/ice/cpp/src/Ice/SlicedData.cpp +80 -0
  383. data/ext/ice/cpp/src/Ice/Stream.cpp +53 -0
  384. data/ext/ice/cpp/src/Ice/StreamI.cpp +832 -0
  385. data/ext/ice/cpp/src/Ice/StreamI.h +198 -0
  386. data/ext/ice/cpp/src/Ice/StreamSocket.cpp +521 -0
  387. data/ext/ice/cpp/src/Ice/StreamSocket.h +85 -0
  388. data/ext/ice/cpp/src/Ice/StringConverterPlugin.cpp +145 -0
  389. data/ext/ice/cpp/src/Ice/SysLoggerI.cpp +167 -0
  390. data/ext/ice/cpp/src/Ice/SysLoggerI.h +43 -0
  391. data/ext/ice/cpp/src/Ice/TcpAcceptor.cpp +235 -0
  392. data/ext/ice/cpp/src/Ice/TcpAcceptor.h +67 -0
  393. data/ext/ice/cpp/src/Ice/TcpConnector.cpp +133 -0
  394. data/ext/ice/cpp/src/Ice/TcpConnector.h +51 -0
  395. data/ext/ice/cpp/src/Ice/TcpEndpointI.cpp +397 -0
  396. data/ext/ice/cpp/src/Ice/TcpEndpointI.h +93 -0
  397. data/ext/ice/cpp/src/Ice/TcpTransceiver.cpp +127 -0
  398. data/ext/ice/cpp/src/Ice/TcpTransceiver.h +61 -0
  399. data/ext/ice/cpp/src/Ice/ThreadPool.cpp +1357 -0
  400. data/ext/ice/cpp/src/Ice/ThreadPool.h +399 -0
  401. data/ext/ice/cpp/src/Ice/TraceLevels.cpp +43 -0
  402. data/ext/ice/cpp/src/Ice/TraceLevels.h +50 -0
  403. data/ext/ice/cpp/src/Ice/TraceLevelsF.h +26 -0
  404. data/ext/ice/cpp/src/Ice/TraceUtil.cpp +452 -0
  405. data/ext/ice/cpp/src/Ice/TraceUtil.h +28 -0
  406. data/ext/ice/cpp/src/Ice/Transceiver.cpp +24 -0
  407. data/ext/ice/cpp/src/Ice/Transceiver.h +52 -0
  408. data/ext/ice/cpp/src/Ice/TransceiverF.h +38 -0
  409. data/ext/ice/cpp/src/Ice/UdpConnector.cpp +144 -0
  410. data/ext/ice/cpp/src/Ice/UdpConnector.h +51 -0
  411. data/ext/ice/cpp/src/Ice/UdpEndpointI.cpp +483 -0
  412. data/ext/ice/cpp/src/Ice/UdpEndpointI.h +95 -0
  413. data/ext/ice/cpp/src/Ice/UdpTransceiver.cpp +1156 -0
  414. data/ext/ice/cpp/src/Ice/UdpTransceiver.h +123 -0
  415. data/ext/ice/cpp/src/Ice/Version.cpp +46 -0
  416. data/ext/ice/cpp/src/Ice/WSAcceptor.cpp +103 -0
  417. data/ext/ice/cpp/src/Ice/WSAcceptor.h +61 -0
  418. data/ext/ice/cpp/src/Ice/WSConnector.cpp +113 -0
  419. data/ext/ice/cpp/src/Ice/WSConnector.h +51 -0
  420. data/ext/ice/cpp/src/Ice/WSEndpoint.cpp +441 -0
  421. data/ext/ice/cpp/src/Ice/WSEndpoint.h +97 -0
  422. data/ext/ice/cpp/src/Ice/WSTransceiver.cpp +1728 -0
  423. data/ext/ice/cpp/src/Ice/WSTransceiver.h +149 -0
  424. data/ext/ice/cpp/src/IceDiscovery/IceDiscovery.cpp +594 -0
  425. data/ext/ice/cpp/src/IceDiscovery/IceDiscovery.h +1035 -0
  426. data/ext/ice/cpp/src/IceDiscovery/LocatorI.cpp +208 -0
  427. data/ext/ice/cpp/src/IceDiscovery/LocatorI.h +78 -0
  428. data/ext/ice/cpp/src/IceDiscovery/LookupI.cpp +308 -0
  429. data/ext/ice/cpp/src/IceDiscovery/LookupI.h +183 -0
  430. data/ext/ice/cpp/src/IceDiscovery/Makefile +61 -0
  431. data/ext/ice/cpp/src/IceDiscovery/PluginI.cpp +148 -0
  432. data/ext/ice/cpp/src/IceDiscovery/PluginI.h +39 -0
  433. data/ext/ice/cpp/src/IceSSL/AcceptorI.cpp +258 -0
  434. data/ext/ice/cpp/src/IceSSL/AcceptorI.h +66 -0
  435. data/ext/ice/cpp/src/IceSSL/Certificate.cpp +1334 -0
  436. data/ext/ice/cpp/src/IceSSL/ConnectionInfo.cpp +42 -0
  437. data/ext/ice/cpp/src/IceSSL/ConnectorI.cpp +151 -0
  438. data/ext/ice/cpp/src/IceSSL/ConnectorI.h +56 -0
  439. data/ext/ice/cpp/src/IceSSL/EndpointI.cpp +397 -0
  440. data/ext/ice/cpp/src/IceSSL/EndpointI.h +96 -0
  441. data/ext/ice/cpp/src/IceSSL/EndpointInfo.cpp +41 -0
  442. data/ext/ice/cpp/src/IceSSL/Instance.cpp +38 -0
  443. data/ext/ice/cpp/src/IceSSL/Instance.h +42 -0
  444. data/ext/ice/cpp/src/IceSSL/InstanceF.h +34 -0
  445. data/ext/ice/cpp/src/IceSSL/Makefile +82 -0
  446. data/ext/ice/cpp/src/IceSSL/OpenSSLEngine.cpp +1001 -0
  447. data/ext/ice/cpp/src/IceSSL/OpenSSLTransceiverI.cpp +607 -0
  448. data/ext/ice/cpp/src/IceSSL/OpenSSLTransceiverI.h +75 -0
  449. data/ext/ice/cpp/src/IceSSL/PluginI.cpp +102 -0
  450. data/ext/ice/cpp/src/IceSSL/PluginI.h +56 -0
  451. data/ext/ice/cpp/src/IceSSL/RFC2253.cpp +541 -0
  452. data/ext/ice/cpp/src/IceSSL/RFC2253.h +67 -0
  453. data/ext/ice/cpp/src/IceSSL/SChannelEngine.cpp +729 -0
  454. data/ext/ice/cpp/src/IceSSL/SChannelTransceiverI.cpp +1062 -0
  455. data/ext/ice/cpp/src/IceSSL/SChannelTransceiverI.h +130 -0
  456. data/ext/ice/cpp/src/IceSSL/SSLEngine.cpp +291 -0
  457. data/ext/ice/cpp/src/IceSSL/SSLEngine.h +264 -0
  458. data/ext/ice/cpp/src/IceSSL/SSLEngineF.h +41 -0
  459. data/ext/ice/cpp/src/IceSSL/SecureTransportEngine.cpp +1514 -0
  460. data/ext/ice/cpp/src/IceSSL/SecureTransportTransceiverI.cpp +609 -0
  461. data/ext/ice/cpp/src/IceSSL/SecureTransportTransceiverI.h +91 -0
  462. data/ext/ice/cpp/src/IceSSL/TrustManager.cpp +246 -0
  463. data/ext/ice/cpp/src/IceSSL/TrustManager.h +51 -0
  464. data/ext/ice/cpp/src/IceSSL/TrustManagerF.h +26 -0
  465. data/ext/ice/cpp/src/IceSSL/Util.cpp +1423 -0
  466. data/ext/ice/cpp/src/IceSSL/Util.h +136 -0
  467. data/ext/ice/cpp/src/IceUtil/ArgVector.cpp +65 -0
  468. data/ext/ice/cpp/src/IceUtil/ArgVector.h +41 -0
  469. data/ext/ice/cpp/src/IceUtil/Cond.cpp +386 -0
  470. data/ext/ice/cpp/src/IceUtil/ConvertUTF.cpp +477 -0
  471. data/ext/ice/cpp/src/IceUtil/ConvertUTF.h +144 -0
  472. data/ext/ice/cpp/src/IceUtil/CountDownLatch.cpp +184 -0
  473. data/ext/ice/cpp/src/IceUtil/CtrlCHandler.cpp +273 -0
  474. data/ext/ice/cpp/src/IceUtil/Exception.cpp +782 -0
  475. data/ext/ice/cpp/src/IceUtil/FileUtil.cpp +532 -0
  476. data/ext/ice/cpp/src/IceUtil/FileUtil.h +159 -0
  477. data/ext/ice/cpp/src/IceUtil/InputUtil.cpp +41 -0
  478. data/ext/ice/cpp/src/IceUtil/Makefile +68 -0
  479. data/ext/ice/cpp/src/IceUtil/MutexProtocol.cpp +24 -0
  480. data/ext/ice/cpp/src/IceUtil/Options.cpp +1049 -0
  481. data/ext/ice/cpp/src/IceUtil/OutputUtil.cpp +591 -0
  482. data/ext/ice/cpp/src/IceUtil/Random.cpp +185 -0
  483. data/ext/ice/cpp/src/IceUtil/RecMutex.cpp +257 -0
  484. data/ext/ice/cpp/src/IceUtil/SHA1.cpp +126 -0
  485. data/ext/ice/cpp/src/IceUtil/Shared.cpp +200 -0
  486. data/ext/ice/cpp/src/IceUtil/StopWatch.h +54 -0
  487. data/ext/ice/cpp/src/IceUtil/StringConverter.cpp +450 -0
  488. data/ext/ice/cpp/src/IceUtil/StringUtil.cpp +842 -0
  489. data/ext/ice/cpp/src/IceUtil/Thread.cpp +809 -0
  490. data/ext/ice/cpp/src/IceUtil/ThreadException.cpp +172 -0
  491. data/ext/ice/cpp/src/IceUtil/Time.cpp +306 -0
  492. data/ext/ice/cpp/src/IceUtil/Timer.cpp +251 -0
  493. data/ext/ice/cpp/src/IceUtil/UUID.cpp +174 -0
  494. data/ext/ice/cpp/src/IceUtil/Unicode.cpp +131 -0
  495. data/ext/ice/cpp/src/IceUtil/Unicode.h +49 -0
  496. data/ext/ice/cpp/src/Slice/CPlusPlusUtil.cpp +1139 -0
  497. data/ext/ice/cpp/src/Slice/Checksum.cpp +452 -0
  498. data/ext/ice/cpp/src/Slice/CsUtil.cpp +2650 -0
  499. data/ext/ice/cpp/src/Slice/DotNetNames.cpp +146 -0
  500. data/ext/ice/cpp/src/Slice/FileTracker.cpp +203 -0
  501. data/ext/ice/cpp/src/Slice/Grammar.cpp +4755 -0
  502. data/ext/ice/cpp/src/Slice/Grammar.h +98 -0
  503. data/ext/ice/cpp/src/Slice/GrammarUtil.h +234 -0
  504. data/ext/ice/cpp/src/Slice/JavaUtil.cpp +4376 -0
  505. data/ext/ice/cpp/src/Slice/MD5.cpp +57 -0
  506. data/ext/ice/cpp/src/Slice/MD5.h +44 -0
  507. data/ext/ice/cpp/src/Slice/MD5I.cpp +385 -0
  508. data/ext/ice/cpp/src/Slice/MD5I.h +91 -0
  509. data/ext/ice/cpp/src/Slice/Makefile +65 -0
  510. data/ext/ice/cpp/src/Slice/PHPUtil.cpp +156 -0
  511. data/ext/ice/cpp/src/Slice/Parser.cpp +6386 -0
  512. data/ext/ice/cpp/src/Slice/Preprocessor.cpp +686 -0
  513. data/ext/ice/cpp/src/Slice/Python.cpp +675 -0
  514. data/ext/ice/cpp/src/Slice/PythonUtil.cpp +2614 -0
  515. data/ext/ice/cpp/src/Slice/Ruby.cpp +317 -0
  516. data/ext/ice/cpp/src/Slice/RubyUtil.cpp +1774 -0
  517. data/ext/ice/cpp/src/Slice/Scanner.cpp +2426 -0
  518. data/ext/ice/cpp/src/Slice/Util.cpp +325 -0
  519. data/ext/ice/mcpp/config.h.Darwin +227 -0
  520. data/ext/ice/mcpp/config.h.Linux +227 -0
  521. data/ext/ice/mcpp/config.h.MINGW +7 -0
  522. data/ext/ice/mcpp/configed.H +382 -0
  523. data/ext/ice/mcpp/directive.c +1699 -0
  524. data/ext/ice/mcpp/eval.c +1673 -0
  525. data/ext/ice/mcpp/expand.c +2980 -0
  526. data/ext/ice/mcpp/internal.H +564 -0
  527. data/ext/ice/mcpp/main.c +1131 -0
  528. data/ext/ice/mcpp/mbchar.c +869 -0
  529. data/ext/ice/mcpp/mcpp_lib.h +31 -0
  530. data/ext/ice/mcpp/mcpp_out.h +13 -0
  531. data/ext/ice/mcpp/support.c +2811 -0
  532. data/ext/ice/mcpp/system.H +396 -0
  533. data/ext/ice/mcpp/system.c +4940 -0
  534. data/ice.gemspec +41 -0
  535. data/lib/Glacier2.rb +12 -0
  536. data/lib/Glacier2/Metrics.rb +99 -0
  537. data/lib/Glacier2/PermissionsVerifier.rb +168 -0
  538. data/lib/Glacier2/PermissionsVerifierF.rb +34 -0
  539. data/lib/Glacier2/Router.rb +141 -0
  540. data/lib/Glacier2/RouterF.rb +29 -0
  541. data/lib/Glacier2/SSLInfo.rb +79 -0
  542. data/lib/Glacier2/Session.rb +470 -0
  543. data/lib/Ice.rb +659 -0
  544. data/lib/Ice/BuiltinSequences.rb +64 -0
  545. data/lib/Ice/Communicator.rb +93 -0
  546. data/lib/Ice/CommunicatorF.rb +28 -0
  547. data/lib/Ice/Connection.rb +414 -0
  548. data/lib/Ice/ConnectionF.rb +36 -0
  549. data/lib/Ice/Current.rb +152 -0
  550. data/lib/Ice/Endpoint.rb +265 -0
  551. data/lib/Ice/EndpointF.rb +52 -0
  552. data/lib/Ice/EndpointTypes.rb +77 -0
  553. data/lib/Ice/FacetMap.rb +28 -0
  554. data/lib/Ice/Identity.rb +70 -0
  555. data/lib/Ice/ImplicitContext.rb +59 -0
  556. data/lib/Ice/ImplicitContextF.rb +28 -0
  557. data/lib/Ice/Instrumentation.rb +425 -0
  558. data/lib/Ice/InstrumentationF.rb +35 -0
  559. data/lib/Ice/LocalException.rb +1081 -0
  560. data/lib/Ice/Locator.rb +314 -0
  561. data/lib/Ice/LocatorF.rb +34 -0
  562. data/lib/Ice/Logger.rb +57 -0
  563. data/lib/Ice/LoggerF.rb +28 -0
  564. data/lib/Ice/Metrics.rb +696 -0
  565. data/lib/Ice/ObjectAdapterF.rb +28 -0
  566. data/lib/Ice/ObjectFactory.rb +53 -0
  567. data/lib/Ice/ObjectFactoryF.rb +28 -0
  568. data/lib/Ice/Plugin.rb +87 -0
  569. data/lib/Ice/PluginF.rb +32 -0
  570. data/lib/Ice/Process.rb +93 -0
  571. data/lib/Ice/ProcessF.rb +29 -0
  572. data/lib/Ice/Properties.rb +65 -0
  573. data/lib/Ice/PropertiesAdmin.rb +104 -0
  574. data/lib/Ice/PropertiesF.rb +33 -0
  575. data/lib/Ice/Router.rb +163 -0
  576. data/lib/Ice/RouterF.rb +29 -0
  577. data/lib/Ice/SliceChecksumDict.rb +28 -0
  578. data/lib/Ice/Version.rb +100 -0
  579. data/lib/IceBox.rb +10 -0
  580. data/lib/IceBox/IceBox.rb +272 -0
  581. data/lib/IceGrid.rb +17 -0
  582. data/lib/IceGrid/Admin.rb +1076 -0
  583. data/lib/IceGrid/Descriptor.rb +1505 -0
  584. data/lib/IceGrid/Exception.rb +401 -0
  585. data/lib/IceGrid/FileParser.rb +105 -0
  586. data/lib/IceGrid/Locator.rb +105 -0
  587. data/lib/IceGrid/Observer.rb +571 -0
  588. data/lib/IceGrid/Query.rb +168 -0
  589. data/lib/IceGrid/Registry.rb +120 -0
  590. data/lib/IceGrid/Session.rb +114 -0
  591. data/lib/IceGrid/UserAccountMapper.rb +101 -0
  592. data/lib/IcePatch2.rb +10 -0
  593. data/lib/IcePatch2/FileInfo.rb +75 -0
  594. data/lib/IcePatch2/FileServer.rb +141 -0
  595. data/lib/IceStorm.rb +11 -0
  596. data/lib/IceStorm/IceStorm.rb +463 -0
  597. data/lib/IceStorm/Metrics.rb +155 -0
  598. data/slice/Freeze/BackgroundSaveEvictor.ice +111 -0
  599. data/slice/Freeze/CatalogData.ice +49 -0
  600. data/slice/Freeze/Connection.ice +111 -0
  601. data/slice/Freeze/ConnectionF.ice +20 -0
  602. data/slice/Freeze/DB.ice +37 -0
  603. data/slice/Freeze/Evictor.ice +339 -0
  604. data/slice/Freeze/EvictorF.ice +22 -0
  605. data/slice/Freeze/EvictorStorage.ice +72 -0
  606. data/slice/Freeze/Exception.ice +100 -0
  607. data/slice/Freeze/Transaction.ice +57 -0
  608. data/slice/Freeze/TransactionalEvictor.ice +50 -0
  609. data/slice/Glacier2/Metrics.ice +77 -0
  610. data/slice/Glacier2/PermissionsVerifier.ice +105 -0
  611. data/slice/Glacier2/PermissionsVerifierF.ice +21 -0
  612. data/slice/Glacier2/Router.ice +178 -0
  613. data/slice/Glacier2/RouterF.ice +20 -0
  614. data/slice/Glacier2/SSLInfo.ice +50 -0
  615. data/slice/Glacier2/Session.ice +273 -0
  616. data/slice/Ice/BuiltinSequences.ice +48 -0
  617. data/slice/Ice/Communicator.ice +567 -0
  618. data/slice/Ice/CommunicatorF.ice +20 -0
  619. data/slice/Ice/Connection.ice +323 -0
  620. data/slice/Ice/ConnectionF.ice +22 -0
  621. data/slice/Ice/Current.ice +160 -0
  622. data/slice/Ice/Endpoint.ice +227 -0
  623. data/slice/Ice/EndpointF.ice +32 -0
  624. data/slice/Ice/EndpointTypes.ice +38 -0
  625. data/slice/Ice/FacetMap.ice +25 -0
  626. data/slice/Ice/Identity.ice +59 -0
  627. data/slice/Ice/ImplicitContext.ice +109 -0
  628. data/slice/Ice/ImplicitContextF.ice +20 -0
  629. data/slice/Ice/Instrumentation.ice +499 -0
  630. data/slice/Ice/InstrumentationF.ice +26 -0
  631. data/slice/Ice/LocalException.ice +1015 -0
  632. data/slice/Ice/Locator.ice +227 -0
  633. data/slice/Ice/LocatorF.ice +21 -0
  634. data/slice/Ice/Logger.ice +86 -0
  635. data/slice/Ice/LoggerF.ice +20 -0
  636. data/slice/Ice/Metrics.ice +422 -0
  637. data/slice/Ice/ObjectAdapter.ice +673 -0
  638. data/slice/Ice/ObjectAdapterF.ice +20 -0
  639. data/slice/Ice/ObjectFactory.ice +60 -0
  640. data/slice/Ice/ObjectFactoryF.ice +20 -0
  641. data/slice/Ice/Plugin.ice +117 -0
  642. data/slice/Ice/PluginF.ice +21 -0
  643. data/slice/Ice/Process.ice +54 -0
  644. data/slice/Ice/ProcessF.ice +20 -0
  645. data/slice/Ice/Properties.ice +228 -0
  646. data/slice/Ice/PropertiesAdmin.ice +75 -0
  647. data/slice/Ice/PropertiesF.ice +21 -0
  648. data/slice/Ice/RemoteLogger.ice +232 -0
  649. data/slice/Ice/Router.ice +83 -0
  650. data/slice/Ice/RouterF.ice +20 -0
  651. data/slice/Ice/ServantLocator.ice +117 -0
  652. data/slice/Ice/ServantLocatorF.ice +20 -0
  653. data/slice/Ice/SliceChecksumDict.ice +25 -0
  654. data/slice/Ice/Version.ice +39 -0
  655. data/slice/IceBox/IceBox.ice +194 -0
  656. data/slice/IceDiscovery/IceDiscovery.ice +32 -0
  657. data/slice/IceGrid/Admin.ice +1578 -0
  658. data/slice/IceGrid/Descriptor.ice +1079 -0
  659. data/slice/IceGrid/Discovery.ice +73 -0
  660. data/slice/IceGrid/Exception.ice +383 -0
  661. data/slice/IceGrid/FileParser.ice +61 -0
  662. data/slice/IceGrid/Locator.ice +56 -0
  663. data/slice/IceGrid/Observer.ice +394 -0
  664. data/slice/IceGrid/PluginFacade.ice +316 -0
  665. data/slice/IceGrid/Query.ice +130 -0
  666. data/slice/IceGrid/Registry.ice +138 -0
  667. data/slice/IceGrid/Session.ice +124 -0
  668. data/slice/IceGrid/UserAccountMapper.ice +58 -0
  669. data/slice/IcePatch2/FileInfo.ice +49 -0
  670. data/slice/IcePatch2/FileServer.ice +129 -0
  671. data/slice/IceSSL/ConnectionInfo.ice +34 -0
  672. data/slice/IceSSL/EndpointInfo.ice +41 -0
  673. data/slice/IceStorm/IceStorm.ice +405 -0
  674. data/slice/IceStorm/Metrics.ice +71 -0
  675. metadata +737 -0
@@ -0,0 +1,98 @@
1
+
2
+ /* A Bison parser, made by GNU Bison 2.4.1. */
3
+
4
+ /* Skeleton interface for Bison's Yacc-like parsers in C
5
+
6
+ Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
7
+ Free Software Foundation, Inc.
8
+
9
+ This program is free software: you can redistribute it and/or modify
10
+ it under the terms of the GNU General Public License as published by
11
+ the Free Software Foundation, either version 3 of the License, or
12
+ (at your option) any later version.
13
+
14
+ This program is distributed in the hope that it will be useful,
15
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
+ GNU General Public License for more details.
18
+
19
+ You should have received a copy of the GNU General Public License
20
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
21
+
22
+ /* As a special exception, you may create a larger work that contains
23
+ part or all of the Bison parser skeleton and distribute that work
24
+ under terms of your choice, so long as that work isn't itself a
25
+ parser generator using the skeleton or a modified version thereof
26
+ as a parser skeleton. Alternatively, if you modify or redistribute
27
+ the parser skeleton itself, you may (at your option) remove this
28
+ special exception, which will cause the skeleton and the resulting
29
+ Bison output files to be licensed under the GNU General Public
30
+ License without this special exception.
31
+
32
+ This special exception was added by the Free Software Foundation in
33
+ version 2.2 of Bison. */
34
+
35
+
36
+ /* Tokens. */
37
+ #ifndef YYTOKENTYPE
38
+ # define YYTOKENTYPE
39
+ /* Put the tokens into the symbol table, so that GDB and other debuggers
40
+ know about them. */
41
+ enum yytokentype {
42
+ ICE_MODULE = 258,
43
+ ICE_CLASS = 259,
44
+ ICE_INTERFACE = 260,
45
+ ICE_EXCEPTION = 261,
46
+ ICE_STRUCT = 262,
47
+ ICE_SEQUENCE = 263,
48
+ ICE_DICTIONARY = 264,
49
+ ICE_ENUM = 265,
50
+ ICE_OUT = 266,
51
+ ICE_EXTENDS = 267,
52
+ ICE_IMPLEMENTS = 268,
53
+ ICE_THROWS = 269,
54
+ ICE_VOID = 270,
55
+ ICE_BYTE = 271,
56
+ ICE_BOOL = 272,
57
+ ICE_SHORT = 273,
58
+ ICE_INT = 274,
59
+ ICE_LONG = 275,
60
+ ICE_FLOAT = 276,
61
+ ICE_DOUBLE = 277,
62
+ ICE_STRING = 278,
63
+ ICE_OBJECT = 279,
64
+ ICE_LOCAL_OBJECT = 280,
65
+ ICE_LOCAL = 281,
66
+ ICE_CONST = 282,
67
+ ICE_FALSE = 283,
68
+ ICE_TRUE = 284,
69
+ ICE_IDEMPOTENT = 285,
70
+ ICE_OPTIONAL = 286,
71
+ ICE_SCOPE_DELIMITER = 287,
72
+ ICE_IDENTIFIER = 288,
73
+ ICE_STRING_LITERAL = 289,
74
+ ICE_INTEGER_LITERAL = 290,
75
+ ICE_FLOATING_POINT_LITERAL = 291,
76
+ ICE_IDENT_OP = 292,
77
+ ICE_KEYWORD_OP = 293,
78
+ ICE_OPTIONAL_OP = 294,
79
+ ICE_METADATA_OPEN = 295,
80
+ ICE_METADATA_CLOSE = 296,
81
+ ICE_GLOBAL_METADATA_OPEN = 297,
82
+ ICE_GLOBAL_METADATA_CLOSE = 298,
83
+ BAD_CHAR = 299
84
+ };
85
+ #endif
86
+
87
+
88
+
89
+ #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
90
+ typedef int YYSTYPE;
91
+ # define YYSTYPE_IS_TRIVIAL 1
92
+ # define yystype YYSTYPE /* obsolescent; will be withdrawn */
93
+ # define YYSTYPE_IS_DECLARED 1
94
+ #endif
95
+
96
+
97
+
98
+
@@ -0,0 +1,234 @@
1
+ // **********************************************************************
2
+ //
3
+ // Copyright (c) 2003-2014 ZeroC, Inc. All rights reserved.
4
+ //
5
+ // This copy of Ice is licensed to you under the terms described in the
6
+ // ICE_LICENSE file included in this distribution.
7
+ //
8
+ // **********************************************************************
9
+
10
+ #ifndef SLICE_GRAMMAR_UTIL_H
11
+ #define SLICE_GRAMMAR_UTIL_H
12
+
13
+ #include <Slice/Parser.h>
14
+
15
+ namespace Slice
16
+ {
17
+
18
+ class StringTok;
19
+ class StringListTok;
20
+ class TypeStringTok;
21
+ class TypeStringListTok;
22
+ class BoolTok;
23
+ class IntegerTok;
24
+ class FloatingTok;
25
+ class ExceptionListTok;
26
+ class ClassListTok;
27
+ class EnumeratorListTok;
28
+ class ConstDefTok;
29
+ class OptionalDefTok;
30
+ class OptionalTypeDefTok;
31
+ class ClassIdTok;
32
+
33
+ typedef ::IceUtil::Handle<StringTok> StringTokPtr;
34
+ typedef ::IceUtil::Handle<StringListTok> StringListTokPtr;
35
+ typedef ::IceUtil::Handle<TypeStringTok> TypeStringTokPtr;
36
+ typedef ::IceUtil::Handle<TypeStringListTok> TypeStringListTokPtr;
37
+ typedef ::IceUtil::Handle<BoolTok> BoolTokPtr;
38
+ typedef ::IceUtil::Handle<IntegerTok> IntegerTokPtr;
39
+ typedef ::IceUtil::Handle<FloatingTok> FloatingTokPtr;
40
+ typedef ::IceUtil::Handle<ExceptionListTok> ExceptionListTokPtr;
41
+ typedef ::IceUtil::Handle<ClassListTok> ClassListTokPtr;
42
+ typedef ::IceUtil::Handle<EnumeratorListTok> EnumeratorListTokPtr;
43
+ typedef ::IceUtil::Handle<ConstDefTok> ConstDefTokPtr;
44
+ typedef ::IceUtil::Handle<OptionalDefTok> OptionalDefTokPtr;
45
+ typedef ::IceUtil::Handle<ClassIdTok> ClassIdTokPtr;
46
+
47
+ // ----------------------------------------------------------------------
48
+ // StringTok
49
+ // ----------------------------------------------------------------------
50
+
51
+ class SLICE_API StringTok : public GrammarBase
52
+ {
53
+ public:
54
+
55
+ StringTok() { }
56
+ std::string v;
57
+ std::string literal;
58
+ };
59
+
60
+ // ----------------------------------------------------------------------
61
+ // StringListTok
62
+ // ----------------------------------------------------------------------
63
+
64
+ class SLICE_API StringListTok : public GrammarBase
65
+ {
66
+ public:
67
+
68
+ StringListTok() { }
69
+ StringList v;
70
+ };
71
+
72
+ // ----------------------------------------------------------------------
73
+ // TypeStringTok
74
+ // ----------------------------------------------------------------------
75
+
76
+ class SLICE_API TypeStringTok : public GrammarBase
77
+ {
78
+ public:
79
+
80
+ TypeStringTok() { }
81
+ TypeString v;
82
+ };
83
+
84
+ // ----------------------------------------------------------------------
85
+ // TypeStringListTok
86
+ // ----------------------------------------------------------------------
87
+
88
+ class SLICE_API TypeStringListTok : public GrammarBase
89
+ {
90
+ public:
91
+
92
+ TypeStringListTok() { }
93
+ TypeStringList v;
94
+ };
95
+
96
+ // ----------------------------------------------------------------------
97
+ // IntegerTok
98
+ // ----------------------------------------------------------------------
99
+
100
+ class SLICE_API IntegerTok : public GrammarBase
101
+ {
102
+ public:
103
+
104
+ IntegerTok() { }
105
+ IceUtil::Int64 v;
106
+ std::string literal;
107
+ };
108
+
109
+ // ----------------------------------------------------------------------
110
+ // FloatingTok
111
+ // ----------------------------------------------------------------------
112
+
113
+ class SLICE_API FloatingTok : public GrammarBase
114
+ {
115
+ public:
116
+
117
+ FloatingTok() { }
118
+ double v;
119
+ std::string literal;
120
+ };
121
+
122
+ // ----------------------------------------------------------------------
123
+ // BoolTok
124
+ // ----------------------------------------------------------------------
125
+
126
+ class SLICE_API BoolTok : public GrammarBase
127
+ {
128
+ public:
129
+
130
+ BoolTok() { }
131
+ bool v;
132
+ };
133
+
134
+ // ----------------------------------------------------------------------
135
+ // ExceptionListTok
136
+ // ----------------------------------------------------------------------
137
+
138
+ class SLICE_API ExceptionListTok : public GrammarBase
139
+ {
140
+ public:
141
+
142
+ ExceptionListTok() { }
143
+ ExceptionList v;
144
+ };
145
+
146
+ // ----------------------------------------------------------------------
147
+ // ClassListTok
148
+ // ----------------------------------------------------------------------
149
+
150
+ class SLICE_API ClassListTok : public GrammarBase
151
+ {
152
+ public:
153
+
154
+ ClassListTok() { }
155
+ ClassList v;
156
+ };
157
+
158
+ // ----------------------------------------------------------------------
159
+ // EnumeratorListTok
160
+ // ----------------------------------------------------------------------
161
+
162
+ class SLICE_API EnumeratorListTok : public GrammarBase
163
+ {
164
+ public:
165
+
166
+ EnumeratorListTok() { }
167
+ EnumeratorList v;
168
+ };
169
+
170
+ // ----------------------------------------------------------------------
171
+ // ConstDefTok
172
+ // ----------------------------------------------------------------------
173
+
174
+ class SLICE_API ConstDefTok : public GrammarBase
175
+ {
176
+ public:
177
+
178
+ ConstDefTok() { }
179
+ ConstDef v;
180
+ };
181
+
182
+ // ----------------------------------------------------------------------
183
+ // OptionalDefTok
184
+ // ----------------------------------------------------------------------
185
+
186
+ class SLICE_API OptionalDefTok : public GrammarBase
187
+ {
188
+ public:
189
+
190
+ OptionalDefTok() { }
191
+ OptionalDef v;
192
+ };
193
+
194
+ // ----------------------------------------------------------------------
195
+ // ClassIdTok
196
+ // ----------------------------------------------------------------------
197
+
198
+ class SLICE_API ClassIdTok : public GrammarBase
199
+ {
200
+ public:
201
+
202
+ ClassIdTok() { }
203
+ std::string v;
204
+ int t;
205
+ };
206
+
207
+ }
208
+
209
+ //
210
+ // Stuff for flex and bison
211
+ //
212
+
213
+ #define YYSTYPE Slice::GrammarBasePtr
214
+ #define YY_DECL int slice_lex(YYSTYPE* yylvalp)
215
+ YY_DECL;
216
+ int slice_parse();
217
+
218
+ //
219
+ // I must set the initial stack depth to the maximum stack depth to
220
+ // disable bison stack resizing. The bison stack resizing routines use
221
+ // simple malloc/alloc/memcpy calls, which do not work for the
222
+ // YYSTYPE, since YYSTYPE is a C++ type, with constructor, destructor,
223
+ // assignment operator, etc.
224
+ //
225
+ #define YYMAXDEPTH 10000
226
+ #define YYINITDEPTH YYMAXDEPTH // Initial depth is set to max depth, for the reasons described above.
227
+
228
+ //
229
+ // Newer bison versions allow to disable stack resizing by defining
230
+ // yyoverflow.
231
+ //
232
+ #define yyoverflow(a, b, c, d, e, f) yyerror(a)
233
+
234
+ #endif
@@ -0,0 +1,4376 @@
1
+ // **********************************************************************
2
+ //
3
+ // Copyright (c) 2003-2014 ZeroC, Inc. All rights reserved.
4
+ //
5
+ // This copy of Ice is licensed to you under the terms described in the
6
+ // ICE_LICENSE file included in this distribution.
7
+ //
8
+ // **********************************************************************
9
+
10
+ #include <IceUtil/DisableWarnings.h>
11
+ #include <Slice/JavaUtil.h>
12
+ #include <Slice/FileTracker.h>
13
+ #include <Slice/Util.h>
14
+ #include <Slice/MD5.h>
15
+ #include <IceUtil/Functional.h>
16
+ #include <IceUtil/DisableWarnings.h>
17
+
18
+ #include <sys/types.h>
19
+ #include <sys/stat.h>
20
+ #include <string.h>
21
+
22
+ #ifdef _WIN32
23
+ #include <direct.h>
24
+ #endif
25
+
26
+ #ifndef _WIN32
27
+ #include <unistd.h>
28
+ #endif
29
+
30
+ using namespace std;
31
+ using namespace Slice;
32
+ using namespace IceUtil;
33
+ using namespace IceUtilInternal;
34
+
35
+ namespace
36
+ {
37
+
38
+ void
39
+ hashAdd(long& hashCode, const std::string& value)
40
+ {
41
+ for(std::string::const_iterator p = value.begin(); p != value.end(); ++p)
42
+ {
43
+ hashCode = ((hashCode << 5) + hashCode) ^ *p;
44
+ }
45
+ }
46
+
47
+ string
48
+ typeToBufferString(const TypePtr& type)
49
+ {
50
+ static const char* builtinBufferTable[] =
51
+ {
52
+ "java.nio.ByteBuffer",
53
+ "???",
54
+ "java.nio.ShortBuffer",
55
+ "java.nio.IntBuffer",
56
+ "java.nio.LongBuffer",
57
+ "java.nio.FloatBuffer",
58
+ "java.nio.DoubleBuffer",
59
+ "???",
60
+ "???",
61
+ "???",
62
+ "???"
63
+ };
64
+
65
+ BuiltinPtr builtin = BuiltinPtr::dynamicCast(type);
66
+ if(!builtin)
67
+ {
68
+ return "???";
69
+ }
70
+ else
71
+ {
72
+ return builtinBufferTable[builtin->kind()];
73
+ }
74
+ }
75
+ }
76
+
77
+ long
78
+ Slice::computeSerialVersionUUID(const ClassDefPtr& p)
79
+ {
80
+ ostringstream os;
81
+
82
+ ClassList bases = p->bases();
83
+ os << "Name: " << p->scoped();
84
+
85
+ os << " Bases: [";
86
+ for(ClassList::const_iterator i = bases.begin(); i != bases.end();)
87
+ {
88
+ os << (*i)->scoped();
89
+ i++;
90
+ if(i != bases.end())
91
+ {
92
+ os << ", ";
93
+ }
94
+ }
95
+ os << "]";
96
+
97
+ os << " Members: [";
98
+ DataMemberList members = p->dataMembers();
99
+ for(DataMemberList::const_iterator i = members.begin(); i != members.end();)
100
+ {
101
+ os << (*i)->name() << ":" << (*i)->type();
102
+ i++;
103
+ if(i != members.end())
104
+ {
105
+ os << ", ";
106
+ }
107
+ }
108
+ os << "]";
109
+
110
+ const string data = os.str();
111
+ long hashCode = 5381;
112
+ hashAdd(hashCode, data);
113
+ return hashCode;
114
+ }
115
+
116
+ long
117
+ Slice::computeSerialVersionUUID(const StructPtr& p)
118
+ {
119
+ ostringstream os;
120
+
121
+ os << "Name: " << p->scoped();
122
+ os << " Members: [";
123
+ DataMemberList members = p->dataMembers();
124
+ for(DataMemberList::const_iterator i = members.begin(); i != members.end();)
125
+ {
126
+ os << (*i)->name() << ":" << (*i)->type();
127
+ i++;
128
+ if(i != members.end())
129
+ {
130
+ os << ", ";
131
+ }
132
+ }
133
+ os << "]";
134
+
135
+ const string data = os.str();
136
+ long hashCode = 5381;
137
+ hashAdd(hashCode, data);
138
+ return hashCode;
139
+ }
140
+
141
+ long
142
+ Slice::computeSerialVersionUUID(const ExceptionPtr& p)
143
+ {
144
+ ostringstream os;
145
+
146
+ os << "Name: " << p->scoped();
147
+ os << " Members: [";
148
+ DataMemberList members = p->dataMembers();
149
+ for(DataMemberList::const_iterator i = members.begin(); i != members.end();)
150
+ {
151
+ os << (*i)->name() << ":" << (*i)->type();
152
+ i++;
153
+ if(i != members.end())
154
+ {
155
+ os << ", ";
156
+ }
157
+ }
158
+ os << "]";
159
+
160
+ const string data = os.str();
161
+ long hashCode = 5381;
162
+ hashAdd(hashCode, data);
163
+ return hashCode;
164
+ }
165
+
166
+
167
+
168
+ Slice::JavaOutput::JavaOutput()
169
+ {
170
+ }
171
+
172
+ Slice::JavaOutput::JavaOutput(ostream& os) :
173
+ Output(os)
174
+ {
175
+ }
176
+
177
+ Slice::JavaOutput::JavaOutput(const char* s) :
178
+ Output(s)
179
+ {
180
+ }
181
+
182
+ void
183
+ Slice::JavaOutput::openClass(const string& cls, const string& prefix, const string& sliceFile)
184
+ {
185
+ string package;
186
+ string file;
187
+ string path = prefix;
188
+
189
+ string::size_type pos = cls.rfind('.');
190
+ if(pos != string::npos)
191
+ {
192
+ package = cls.substr(0, pos);
193
+ file = cls.substr(pos + 1);
194
+ string dir = package;
195
+
196
+ //
197
+ // Create package directories if necessary.
198
+ //
199
+ pos = 0;
200
+ string::size_type start = 0;
201
+ do
202
+ {
203
+ if(!path.empty())
204
+ {
205
+ path += "/";
206
+ }
207
+ pos = dir.find('.', start);
208
+ if(pos != string::npos)
209
+ {
210
+ path += dir.substr(start, pos - start);
211
+ start = pos + 1;
212
+ }
213
+ else
214
+ {
215
+ path += dir.substr(start);
216
+ }
217
+
218
+ struct stat st;
219
+ int result;
220
+ result = stat(path.c_str(), &st);
221
+ if(result == 0)
222
+ {
223
+ if(!(st.st_mode & S_IFDIR))
224
+ {
225
+ ostringstream os;
226
+ os << "failed to create package directory `" << path
227
+ << "': file already exists and is not a directory";
228
+ throw FileException(__FILE__, __LINE__, os.str());
229
+ }
230
+ continue;
231
+ }
232
+ #ifdef _WIN32
233
+ result = _mkdir(path.c_str());
234
+ #else
235
+ result = mkdir(path.c_str(), S_IRWXU | S_IRWXG | S_IRWXO);
236
+ #endif
237
+ if(result != 0)
238
+ {
239
+ ostringstream os;
240
+ os << "cannot create directory `" << path << "': " << strerror(errno);
241
+ throw FileException(__FILE__, __LINE__, os.str());
242
+ }
243
+ FileTracker::instance()->addDirectory(path);
244
+ }
245
+ while(pos != string::npos);
246
+ }
247
+ else
248
+ {
249
+ file = cls;
250
+ }
251
+ file += ".java";
252
+
253
+ //
254
+ // Open class file.
255
+ //
256
+ if(!path.empty())
257
+ {
258
+ path += "/";
259
+ }
260
+ path += file;
261
+
262
+ open(path.c_str());
263
+ if(isOpen())
264
+ {
265
+ FileTracker::instance()->addFile(path);
266
+ printHeader();
267
+ printGeneratedHeader(*this, sliceFile);
268
+ if(!package.empty())
269
+ {
270
+ separator();
271
+ print("package ");
272
+ print(package.c_str());
273
+ print(";");
274
+ }
275
+ }
276
+ else
277
+ {
278
+ ostringstream os;
279
+ os << "cannot open file `" << path << "': " << strerror(errno);
280
+ throw FileException(__FILE__, __LINE__, os.str());
281
+ }
282
+ }
283
+
284
+ void
285
+ Slice::JavaOutput::printHeader()
286
+ {
287
+ static const char* header =
288
+ "// **********************************************************************\n"
289
+ "//\n"
290
+ "// Copyright (c) 2003-2014 ZeroC, Inc. All rights reserved.\n"
291
+ "//\n"
292
+ "// This copy of Ice is licensed to you under the terms described in the\n"
293
+ "// ICE_LICENSE file included in this distribution.\n"
294
+ "//\n"
295
+ "// **********************************************************************\n"
296
+ ;
297
+
298
+ print(header);
299
+ print("//\n");
300
+ print("// Ice version ");
301
+ print(ICE_STRING_VERSION);
302
+ print("\n");
303
+ print("//\n");
304
+ }
305
+
306
+ const string Slice::JavaGenerator::_getSetMetaData = "java:getset";
307
+
308
+ Slice::JavaGenerator::JavaGenerator(const string& dir) :
309
+ _dir(dir),
310
+ _out(0)
311
+ {
312
+ }
313
+
314
+ Slice::JavaGenerator::~JavaGenerator()
315
+ {
316
+ // If open throws an exception other generators could be left open
317
+ // during the stack unwind.
318
+ if(_out != 0)
319
+ {
320
+ close();
321
+ }
322
+ assert(_out == 0);
323
+ }
324
+
325
+ void
326
+ Slice::JavaGenerator::open(const string& absolute, const string& file)
327
+ {
328
+ assert(_out == 0);
329
+
330
+ JavaOutput* out = createOutput();
331
+ try
332
+ {
333
+ out->openClass(absolute, _dir, file);
334
+ }
335
+ catch(const FileException&)
336
+ {
337
+ delete out;
338
+ throw;
339
+ }
340
+ _out = out;
341
+ }
342
+
343
+ void
344
+ Slice::JavaGenerator::close()
345
+ {
346
+ assert(_out != 0);
347
+ *_out << nl;
348
+ delete _out;
349
+ _out = 0;
350
+ }
351
+
352
+ Output&
353
+ Slice::JavaGenerator::output() const
354
+ {
355
+ assert(_out != 0);
356
+ return *_out;
357
+ }
358
+
359
+ static string
360
+ lookupKwd(const string& name)
361
+ {
362
+ //
363
+ // Keyword list. *Must* be kept in alphabetical order. Note that checkedCast and uncheckedCast
364
+ // are not Java keywords, but are in this list to prevent illegal code being generated if
365
+ // someone defines Slice operations with that name.
366
+ //
367
+ // NOTE: Any changes made to this list must also be made in BasicStream.java.
368
+ //
369
+ static const string keywordList[] =
370
+ {
371
+ "abstract", "assert", "boolean", "break", "byte", "case", "catch",
372
+ "char", "checkedCast", "class", "clone", "const", "continue", "default", "do",
373
+ "double", "else", "enum", "equals", "extends", "false", "final", "finalize",
374
+ "finally", "float", "for", "getClass", "goto", "hashCode", "if",
375
+ "implements", "import", "instanceof", "int", "interface", "long",
376
+ "native", "new", "notify", "notifyAll", "null", "package", "private",
377
+ "protected", "public", "return", "short", "static", "strictfp", "super", "switch",
378
+ "synchronized", "this", "throw", "throws", "toString", "transient",
379
+ "true", "try", "uncheckedCast", "void", "volatile", "wait", "while"
380
+ };
381
+ bool found = binary_search(&keywordList[0],
382
+ &keywordList[sizeof(keywordList) / sizeof(*keywordList)],
383
+ name);
384
+ return found ? "_" + name : name;
385
+ }
386
+
387
+ //
388
+ // Split a scoped name into its components and return the components as a list of (unscoped) identifiers.
389
+ //
390
+ static StringList
391
+ splitScopedName(const string& scoped)
392
+ {
393
+ assert(scoped[0] == ':');
394
+ StringList ids;
395
+ string::size_type next = 0;
396
+ string::size_type pos;
397
+ while((pos = scoped.find("::", next)) != string::npos)
398
+ {
399
+ pos += 2;
400
+ if(pos != scoped.size())
401
+ {
402
+ string::size_type endpos = scoped.find("::", pos);
403
+ if(endpos != string::npos)
404
+ {
405
+ ids.push_back(scoped.substr(pos, endpos - pos));
406
+ }
407
+ }
408
+ next = pos;
409
+ }
410
+ if(next != scoped.size())
411
+ {
412
+ ids.push_back(scoped.substr(next));
413
+ }
414
+ else
415
+ {
416
+ ids.push_back("");
417
+ }
418
+
419
+ return ids;
420
+ }
421
+
422
+ //
423
+ // If the passed name is a scoped name, return the identical scoped name,
424
+ // but with all components that are Java keywords replaced by
425
+ // their "_"-prefixed version; otherwise, if the passed name is
426
+ // not scoped, but a Java keyword, return the "_"-prefixed name;
427
+ // otherwise, return the name unchanged.
428
+ //
429
+ string
430
+ Slice::JavaGenerator::fixKwd(const string& name) const
431
+ {
432
+ if(name.empty())
433
+ {
434
+ return name;
435
+ }
436
+ if(name[0] != ':')
437
+ {
438
+ return lookupKwd(name);
439
+ }
440
+ StringList ids = splitScopedName(name);
441
+ transform(ids.begin(), ids.end(), ids.begin(), ptr_fun(lookupKwd));
442
+ stringstream result;
443
+ for(StringList::const_iterator i = ids.begin(); i != ids.end(); ++i)
444
+ {
445
+ result << "::" + *i;
446
+ }
447
+ return result.str();
448
+ }
449
+
450
+ string
451
+ Slice::JavaGenerator::convertScopedName(const string& scoped, const string& prefix, const string& suffix) const
452
+ {
453
+ string result;
454
+ string::size_type start = 0;
455
+ string fscoped = fixKwd(scoped);
456
+
457
+ //
458
+ // Skip leading "::"
459
+ //
460
+ if(fscoped[start] == ':')
461
+ {
462
+ assert(fscoped[start + 1] == ':');
463
+ start += 2;
464
+ }
465
+
466
+ //
467
+ // Convert all occurrences of "::" to "."
468
+ //
469
+ string::size_type pos;
470
+ do
471
+ {
472
+ pos = fscoped.find(':', start);
473
+ string fix;
474
+ if(pos == string::npos)
475
+ {
476
+ string s = fscoped.substr(start);
477
+ if(!s.empty())
478
+ {
479
+ fix = prefix + fixKwd(s) + suffix;
480
+ }
481
+ }
482
+ else
483
+ {
484
+ assert(fscoped[pos + 1] == ':');
485
+ fix = fixKwd(fscoped.substr(start, pos - start));
486
+ start = pos + 2;
487
+ }
488
+
489
+ if(!result.empty() && !fix.empty())
490
+ {
491
+ result += ".";
492
+ }
493
+ result += fix;
494
+ }
495
+ while(pos != string::npos);
496
+
497
+ return result;
498
+ }
499
+
500
+ string
501
+ Slice::JavaGenerator::getPackagePrefix(const ContainedPtr& cont) const
502
+ {
503
+ UnitPtr unit = cont->container()->unit();
504
+ string file = cont->file();
505
+ assert(!file.empty());
506
+
507
+ map<string, string>::const_iterator p = _filePackagePrefix.find(file);
508
+ if(p != _filePackagePrefix.end())
509
+ {
510
+ return p->second;
511
+ }
512
+
513
+ static const string prefix = "java:package:";
514
+ DefinitionContextPtr dc = unit->findDefinitionContext(file);
515
+ assert(dc);
516
+ string q = dc->findMetaData(prefix);
517
+ if(!q.empty())
518
+ {
519
+ q = q.substr(prefix.size());
520
+ }
521
+ _filePackagePrefix[file] = q;
522
+ return q;
523
+ }
524
+
525
+ string
526
+ Slice::JavaGenerator::getPackage(const ContainedPtr& cont) const
527
+ {
528
+ string scope = convertScopedName(cont->scope());
529
+ string prefix = getPackagePrefix(cont);
530
+ if(!prefix.empty())
531
+ {
532
+ if(!scope.empty())
533
+ {
534
+ return prefix + "." + scope;
535
+ }
536
+ else
537
+ {
538
+ return prefix;
539
+ }
540
+ }
541
+
542
+ return scope;
543
+ }
544
+
545
+ string
546
+ Slice::JavaGenerator::getAbsolute(const ContainedPtr& cont,
547
+ const string& package,
548
+ const string& prefix,
549
+ const string& suffix) const
550
+ {
551
+ string name = cont->name();
552
+ if(prefix == "" && suffix == "")
553
+ {
554
+ name = fixKwd(name);
555
+ }
556
+ string contPkg = getPackage(cont);
557
+ if(contPkg == package)
558
+ {
559
+ return prefix + name + suffix;
560
+ }
561
+ else if(!contPkg.empty())
562
+ {
563
+ return contPkg + "." + prefix + name + suffix;
564
+ }
565
+ else
566
+ {
567
+ return prefix + name + suffix;
568
+ }
569
+ }
570
+
571
+ string
572
+ Slice::JavaGenerator::getStaticId(const TypePtr& type, const string& package) const
573
+ {
574
+ BuiltinPtr b = BuiltinPtr::dynamicCast(type);
575
+ ClassDeclPtr cl = ClassDeclPtr::dynamicCast(type);
576
+
577
+ assert((b && b->kind() == Builtin::KindObject) || cl);
578
+
579
+ if(b)
580
+ {
581
+ return "Ice.ObjectImpl.ice_staticId()";
582
+ }
583
+ else if(cl->isInterface())
584
+ {
585
+ return getAbsolute(cl, package, "_", "Disp") + ".ice_staticId()";
586
+ }
587
+ else
588
+ {
589
+ return getAbsolute(cl, package) + ".ice_staticId()";
590
+ }
591
+ }
592
+
593
+ bool
594
+ Slice::JavaGenerator::useOptionalMapping(const OperationPtr& p)
595
+ {
596
+ //
597
+ // The "java:optional" metadata can be applied to an operation or its
598
+ // interface to force the mapping to use the Ice.Optional types.
599
+ //
600
+ // Without the tag, parameters use the normal (non-optional) mapping.
601
+ //
602
+ static const string tag = "java:optional";
603
+
604
+ ClassDefPtr cl = ClassDefPtr::dynamicCast(p->container());
605
+ assert(cl);
606
+
607
+ return p->hasMetaData(tag) || cl->hasMetaData(tag);
608
+ }
609
+
610
+ string
611
+ Slice::JavaGenerator::getOptionalFormat(const TypePtr& type)
612
+ {
613
+ BuiltinPtr bp = BuiltinPtr::dynamicCast(type);
614
+ if(bp)
615
+ {
616
+ switch(bp->kind())
617
+ {
618
+ case Builtin::KindByte:
619
+ case Builtin::KindBool:
620
+ {
621
+ return "Ice.OptionalFormat.F1";
622
+ }
623
+ case Builtin::KindShort:
624
+ {
625
+ return "Ice.OptionalFormat.F2";
626
+ }
627
+ case Builtin::KindInt:
628
+ case Builtin::KindFloat:
629
+ {
630
+ return "Ice.OptionalFormat.F4";
631
+ }
632
+ case Builtin::KindLong:
633
+ case Builtin::KindDouble:
634
+ {
635
+ return "Ice.OptionalFormat.F8";
636
+ }
637
+ case Builtin::KindString:
638
+ {
639
+ return "Ice.OptionalFormat.VSize";
640
+ }
641
+ case Builtin::KindObject:
642
+ {
643
+ return "Ice.OptionalFormat.Class";
644
+ }
645
+ case Builtin::KindObjectProxy:
646
+ {
647
+ return "Ice.OptionalFormat.FSize";
648
+ }
649
+ case Builtin::KindLocalObject:
650
+ {
651
+ assert(false);
652
+ break;
653
+ }
654
+ }
655
+ }
656
+
657
+ if(EnumPtr::dynamicCast(type))
658
+ {
659
+ return "Ice.OptionalFormat.Size";
660
+ }
661
+
662
+ SequencePtr seq = SequencePtr::dynamicCast(type);
663
+ if(seq)
664
+ {
665
+ return seq->type()->isVariableLength() ? "Ice.OptionalFormat.FSize" : "Ice.OptionalFormat.VSize";
666
+ }
667
+
668
+ DictionaryPtr d = DictionaryPtr::dynamicCast(type);
669
+ if(d)
670
+ {
671
+ return (d->keyType()->isVariableLength() || d->valueType()->isVariableLength()) ?
672
+ "Ice.OptionalFormat.FSize" : "Ice.OptionalFormat.VSize";
673
+ }
674
+
675
+ StructPtr st = StructPtr::dynamicCast(type);
676
+ if(st)
677
+ {
678
+ return st->isVariableLength() ? "Ice.OptionalFormat.FSize" : "Ice.OptionalFormat.VSize";
679
+ }
680
+
681
+ if(ProxyPtr::dynamicCast(type))
682
+ {
683
+ return "Ice.OptionalFormat.FSize";
684
+ }
685
+
686
+ ClassDeclPtr cl = ClassDeclPtr::dynamicCast(type);
687
+ assert(cl);
688
+ return "Ice.OptionalFormat.Class";
689
+ }
690
+
691
+ string
692
+ Slice::JavaGenerator::typeToString(const TypePtr& type,
693
+ TypeMode mode,
694
+ const string& package,
695
+ const StringList& metaData,
696
+ bool formal,
697
+ bool optional) const
698
+ {
699
+ static const char* builtinTable[] =
700
+ {
701
+ "byte",
702
+ "boolean",
703
+ "short",
704
+ "int",
705
+ "long",
706
+ "float",
707
+ "double",
708
+ "String",
709
+ "Ice.Object",
710
+ "Ice.ObjectPrx",
711
+ "java.lang.Object"
712
+ };
713
+ static const char* builtinHolderTable[] =
714
+ {
715
+ "Ice.ByteHolder",
716
+ "Ice.BooleanHolder",
717
+ "Ice.ShortHolder",
718
+ "Ice.IntHolder",
719
+ "Ice.LongHolder",
720
+ "Ice.FloatHolder",
721
+ "Ice.DoubleHolder",
722
+ "Ice.StringHolder",
723
+ "Ice.ObjectHolder",
724
+ "Ice.ObjectPrxHolder",
725
+ "Ice.LocalObjectHolder"
726
+ };
727
+ static const char* builtinOptionalTable[] =
728
+ {
729
+ "Ice.ByteOptional",
730
+ "Ice.BooleanOptional",
731
+ "Ice.ShortOptional",
732
+ "Ice.IntOptional",
733
+ "Ice.LongOptional",
734
+ "Ice.FloatOptional",
735
+ "Ice.DoubleOptional",
736
+ "???",
737
+ "???",
738
+ "???",
739
+ "???"
740
+ };
741
+
742
+ if(!type)
743
+ {
744
+ assert(mode == TypeModeReturn);
745
+ return "void";
746
+ }
747
+
748
+ BuiltinPtr builtin = BuiltinPtr::dynamicCast(type);
749
+ if(builtin)
750
+ {
751
+ if(optional)
752
+ {
753
+ switch(builtin->kind())
754
+ {
755
+ case Builtin::KindByte:
756
+ case Builtin::KindBool:
757
+ case Builtin::KindShort:
758
+ case Builtin::KindInt:
759
+ case Builtin::KindLong:
760
+ case Builtin::KindFloat:
761
+ case Builtin::KindDouble:
762
+ {
763
+ return builtinOptionalTable[builtin->kind()];
764
+ }
765
+ case Builtin::KindString:
766
+ case Builtin::KindObject:
767
+ case Builtin::KindObjectProxy:
768
+ case Builtin::KindLocalObject:
769
+ {
770
+ break;
771
+ }
772
+ }
773
+ }
774
+ else
775
+ {
776
+ if(mode == TypeModeOut)
777
+ {
778
+ return builtinHolderTable[builtin->kind()];
779
+ }
780
+ else
781
+ {
782
+ return builtinTable[builtin->kind()];
783
+ }
784
+ }
785
+ }
786
+
787
+ if(optional)
788
+ {
789
+ return "Ice.Optional<" + typeToString(type, TypeModeIn, package, metaData, formal) + ">";
790
+ }
791
+
792
+ ClassDeclPtr cl = ClassDeclPtr::dynamicCast(type);
793
+ if(cl)
794
+ {
795
+ return getAbsolute(cl, package, "", mode == TypeModeOut ? "Holder" : "");
796
+ }
797
+
798
+ ProxyPtr proxy = ProxyPtr::dynamicCast(type);
799
+ if(proxy)
800
+ {
801
+ return getAbsolute(proxy->_class(), package, "", mode == TypeModeOut ? "PrxHolder" : "Prx");
802
+ }
803
+
804
+ DictionaryPtr dict = DictionaryPtr::dynamicCast(type);
805
+ if(dict)
806
+ {
807
+ if(mode == TypeModeOut)
808
+ {
809
+ //
810
+ // Only use the type's generated holder if the instance and
811
+ // formal types match.
812
+ //
813
+ string instanceType, formalType;
814
+ getDictionaryTypes(dict, "", metaData, instanceType, formalType);
815
+ string origInstanceType, origFormalType;
816
+ getDictionaryTypes(dict, "", StringList(), origInstanceType, origFormalType);
817
+ if(formalType == origFormalType && instanceType == origInstanceType)
818
+ {
819
+ return getAbsolute(dict, package, "", "Holder");
820
+ }
821
+
822
+ //
823
+ // The custom type may or may not be compatible with the type used
824
+ // in the generated holder. We use a generic holder that holds a value of the
825
+ // formal custom type.
826
+ //
827
+ return string("Ice.Holder<") + formalType + " >";
828
+ }
829
+ else
830
+ {
831
+ string instanceType, formalType;
832
+ getDictionaryTypes(dict, package, metaData, instanceType, formalType);
833
+ return formal ? formalType : instanceType;
834
+ }
835
+ }
836
+
837
+ SequencePtr seq = SequencePtr::dynamicCast(type);
838
+ if(seq)
839
+ {
840
+ if(mode == TypeModeOut)
841
+ {
842
+ BuiltinPtr builtin = BuiltinPtr::dynamicCast(seq->type());
843
+ if(builtin && builtin->kind() == Builtin::KindByte)
844
+ {
845
+ string prefix = "java:serializable:";
846
+ string meta;
847
+ if(seq->findMetaData(prefix, meta))
848
+ {
849
+ return string("Ice.Holder<") + meta.substr(prefix.size()) + " >";
850
+ }
851
+ prefix = "java:protobuf:";
852
+ if(seq->findMetaData(prefix, meta))
853
+ {
854
+ return string("Ice.Holder<") + meta.substr(prefix.size()) + " >";
855
+ }
856
+ }
857
+
858
+ if(builtin &&
859
+ (builtin->kind() == Builtin::KindByte || builtin->kind() == Builtin::KindShort ||
860
+ builtin->kind() == Builtin::KindInt || builtin->kind() == Builtin::KindLong ||
861
+ builtin->kind() == Builtin::KindFloat || builtin->kind() == Builtin::KindDouble))
862
+ {
863
+ string prefix = "java:buffer";
864
+ string meta;
865
+ string ignore;
866
+ if(seq->findMetaData(prefix, meta) || findMetaData(prefix, metaData, ignore))
867
+ {
868
+ return string("Ice.Holder<") + typeToBufferString(seq->type()) + ">";
869
+ }
870
+ }
871
+
872
+ //
873
+ // Only use the type's generated holder if the instance and
874
+ // formal types match.
875
+ //
876
+ string instanceType, formalType;
877
+ getSequenceTypes(seq, "", metaData, instanceType, formalType);
878
+ string origInstanceType, origFormalType;
879
+ getSequenceTypes(seq, "", StringList(), origInstanceType, origFormalType);
880
+ if(formalType == origFormalType && instanceType == origInstanceType)
881
+ {
882
+ return getAbsolute(seq, package, "", "Holder");
883
+ }
884
+
885
+ //
886
+ // The custom type may or may not be compatible with the type used
887
+ // in the generated holder. We use a generic holder that holds a value of the
888
+ // formal custom type.
889
+ //
890
+ return string("Ice.Holder<") + formalType + " >";
891
+ }
892
+ else
893
+ {
894
+ BuiltinPtr builtin = BuiltinPtr::dynamicCast(seq->type());
895
+ if(builtin && builtin->kind() == Builtin::KindByte)
896
+ {
897
+ string prefix = "java:serializable:";
898
+ string meta;
899
+ if(seq->findMetaData(prefix, meta))
900
+ {
901
+ return meta.substr(prefix.size());
902
+ }
903
+
904
+ prefix = "java:protobuf:";
905
+ if(seq->findMetaData(prefix, meta))
906
+ {
907
+ return meta.substr(prefix.size());
908
+ }
909
+ }
910
+
911
+ if(builtin &&
912
+ (builtin->kind() == Builtin::KindByte || builtin->kind() == Builtin::KindShort ||
913
+ builtin->kind() == Builtin::KindInt || builtin->kind() == Builtin::KindLong ||
914
+ builtin->kind() == Builtin::KindFloat || builtin->kind() == Builtin::KindDouble))
915
+ {
916
+ string prefix = "java:buffer";
917
+ string meta;
918
+ string ignore;
919
+ if(seq->findMetaData(prefix, meta) || findMetaData(prefix, metaData, ignore))
920
+ {
921
+ return typeToBufferString(seq->type());
922
+ }
923
+ }
924
+
925
+ string instanceType, formalType;
926
+ getSequenceTypes(seq, package, metaData, instanceType, formalType);
927
+ return formal ? formalType : instanceType;
928
+ }
929
+ }
930
+
931
+ ContainedPtr contained = ContainedPtr::dynamicCast(type);
932
+ if(contained)
933
+ {
934
+ if(mode == TypeModeOut)
935
+ {
936
+ return getAbsolute(contained, package, "", "Holder");
937
+ }
938
+ else
939
+ {
940
+ return getAbsolute(contained, package);
941
+ }
942
+ }
943
+
944
+ return "???";
945
+ }
946
+
947
+ string
948
+ Slice::JavaGenerator::typeToObjectString(const TypePtr& type,
949
+ TypeMode mode,
950
+ const string& package,
951
+ const StringList& metaData,
952
+ bool formal) const
953
+ {
954
+ static const char* builtinTable[] =
955
+ {
956
+ "java.lang.Byte",
957
+ "java.lang.Boolean",
958
+ "java.lang.Short",
959
+ "java.lang.Integer",
960
+ "java.lang.Long",
961
+ "java.lang.Float",
962
+ "java.lang.Double",
963
+ "java.lang.String",
964
+ "Ice.Object",
965
+ "Ice.ObjectPrx",
966
+ "java.lang.Object"
967
+ };
968
+
969
+ BuiltinPtr builtin = BuiltinPtr::dynamicCast(type);
970
+ if(builtin && mode != TypeModeOut)
971
+ {
972
+ return builtinTable[builtin->kind()];
973
+ }
974
+
975
+ return typeToString(type, mode, package, metaData, formal);
976
+ }
977
+
978
+ void
979
+ Slice::JavaGenerator::writeMarshalUnmarshalCode(Output& out,
980
+ const string& package,
981
+ const TypePtr& type,
982
+ OptionalMode mode,
983
+ bool optionalMapping,
984
+ int tag,
985
+ const string& param,
986
+ bool marshal,
987
+ int& iter,
988
+ bool holder,
989
+ const StringList& metaData,
990
+ const string& patchParams)
991
+ {
992
+ string stream = marshal ? "__os" : "__is";
993
+ string v;
994
+ if(holder)
995
+ {
996
+ v = param + ".value";
997
+ }
998
+ else
999
+ {
1000
+ v = param;
1001
+ }
1002
+
1003
+ const bool optionalParam = mode == OptionalInParam || mode == OptionalOutParam || mode == OptionalReturnParam;
1004
+
1005
+ BuiltinPtr builtin = BuiltinPtr::dynamicCast(type);
1006
+ if(builtin)
1007
+ {
1008
+ switch(builtin->kind())
1009
+ {
1010
+ case Builtin::KindByte:
1011
+ {
1012
+ if(marshal)
1013
+ {
1014
+ if(optionalParam)
1015
+ {
1016
+ out << nl << stream << ".writeByte(" << tag << ", " << v << ");";
1017
+ }
1018
+ else
1019
+ {
1020
+ out << nl << stream << ".writeByte(" << v << ");";
1021
+ }
1022
+ }
1023
+ else
1024
+ {
1025
+ if(optionalParam)
1026
+ {
1027
+ out << nl << stream << ".readByte(" << tag << ", " << v << ");";
1028
+ }
1029
+ else
1030
+ {
1031
+ out << nl << v << " = " << stream << ".readByte();";
1032
+ }
1033
+ }
1034
+ break;
1035
+ }
1036
+ case Builtin::KindBool:
1037
+ {
1038
+ if(marshal)
1039
+ {
1040
+ if(optionalParam)
1041
+ {
1042
+ out << nl << stream << ".writeBool(" << tag << ", " << v << ");";
1043
+ }
1044
+ else
1045
+ {
1046
+ out << nl << stream << ".writeBool(" << v << ");";
1047
+ }
1048
+ }
1049
+ else
1050
+ {
1051
+ if(optionalParam)
1052
+ {
1053
+ out << nl << stream << ".readBool(" << tag << ", " << v << ");";
1054
+ }
1055
+ else
1056
+ {
1057
+ out << nl << v << " = " << stream << ".readBool();";
1058
+ }
1059
+ }
1060
+ break;
1061
+ }
1062
+ case Builtin::KindShort:
1063
+ {
1064
+ if(marshal)
1065
+ {
1066
+ if(optionalParam)
1067
+ {
1068
+ out << nl << stream << ".writeShort(" << tag << ", " << v << ");";
1069
+ }
1070
+ else
1071
+ {
1072
+ out << nl << stream << ".writeShort(" << v << ");";
1073
+ }
1074
+ }
1075
+ else
1076
+ {
1077
+ if(optionalParam)
1078
+ {
1079
+ out << nl << stream << ".readShort(" << tag << ", " << v << ");";
1080
+ }
1081
+ else
1082
+ {
1083
+ out << nl << v << " = " << stream << ".readShort();";
1084
+ }
1085
+ }
1086
+ break;
1087
+ }
1088
+ case Builtin::KindInt:
1089
+ {
1090
+ if(marshal)
1091
+ {
1092
+ if(optionalParam)
1093
+ {
1094
+ out << nl << stream << ".writeInt(" << tag << ", " << v << ");";
1095
+ }
1096
+ else
1097
+ {
1098
+ out << nl << stream << ".writeInt(" << v << ");";
1099
+ }
1100
+ }
1101
+ else
1102
+ {
1103
+ if(optionalParam)
1104
+ {
1105
+ out << nl << stream << ".readInt(" << tag << ", " << v << ");";
1106
+ }
1107
+ else
1108
+ {
1109
+ out << nl << v << " = " << stream << ".readInt();";
1110
+ }
1111
+ }
1112
+ break;
1113
+ }
1114
+ case Builtin::KindLong:
1115
+ {
1116
+ if(marshal)
1117
+ {
1118
+ if(optionalParam)
1119
+ {
1120
+ out << nl << stream << ".writeLong(" << tag << ", " << v << ");";
1121
+ }
1122
+ else
1123
+ {
1124
+ out << nl << stream << ".writeLong(" << v << ");";
1125
+ }
1126
+ }
1127
+ else
1128
+ {
1129
+ if(optionalParam)
1130
+ {
1131
+ out << nl << stream << ".readLong(" << tag << ", " << v << ");";
1132
+ }
1133
+ else
1134
+ {
1135
+ out << nl << v << " = " << stream << ".readLong();";
1136
+ }
1137
+ }
1138
+ break;
1139
+ }
1140
+ case Builtin::KindFloat:
1141
+ {
1142
+ if(marshal)
1143
+ {
1144
+ if(optionalParam)
1145
+ {
1146
+ out << nl << stream << ".writeFloat(" << tag << ", " << v << ");";
1147
+ }
1148
+ else
1149
+ {
1150
+ out << nl << stream << ".writeFloat(" << v << ");";
1151
+ }
1152
+ }
1153
+ else
1154
+ {
1155
+ if(optionalParam)
1156
+ {
1157
+ out << nl << stream << ".readFloat(" << tag << ", " << v << ");";
1158
+ }
1159
+ else
1160
+ {
1161
+ out << nl << v << " = " << stream << ".readFloat();";
1162
+ }
1163
+ }
1164
+ break;
1165
+ }
1166
+ case Builtin::KindDouble:
1167
+ {
1168
+ if(marshal)
1169
+ {
1170
+ if(optionalParam)
1171
+ {
1172
+ out << nl << stream << ".writeDouble(" << tag << ", " << v << ");";
1173
+ }
1174
+ else
1175
+ {
1176
+ out << nl << stream << ".writeDouble(" << v << ");";
1177
+ }
1178
+ }
1179
+ else
1180
+ {
1181
+ if(optionalParam)
1182
+ {
1183
+ out << nl << stream << ".readDouble(" << tag << ", " << v << ");";
1184
+ }
1185
+ else
1186
+ {
1187
+ out << nl << v << " = " << stream << ".readDouble();";
1188
+ }
1189
+ }
1190
+ break;
1191
+ }
1192
+ case Builtin::KindString:
1193
+ {
1194
+ if(marshal)
1195
+ {
1196
+ if(optionalParam)
1197
+ {
1198
+ out << nl << stream << ".writeString(" << tag << ", " << v << ");";
1199
+ }
1200
+ else
1201
+ {
1202
+ out << nl << stream << ".writeString(" << v << ");";
1203
+ }
1204
+ }
1205
+ else
1206
+ {
1207
+ if(optionalParam)
1208
+ {
1209
+ out << nl << stream << ".readString(" << tag << ", " << v << ");";
1210
+ }
1211
+ else
1212
+ {
1213
+ out << nl << v << " = " << stream << ".readString();";
1214
+ }
1215
+ }
1216
+ break;
1217
+ }
1218
+ case Builtin::KindObject:
1219
+ {
1220
+ if(marshal)
1221
+ {
1222
+ if(optionalParam)
1223
+ {
1224
+ out << nl << stream << ".writeObject(" << tag << ", " << v << ");";
1225
+ }
1226
+ else
1227
+ {
1228
+ out << nl << stream << ".writeObject(" << v << ");";
1229
+ }
1230
+ }
1231
+ else
1232
+ {
1233
+ if(optionalParam)
1234
+ {
1235
+ out << nl << stream << ".readObject(" << tag << ", " << param << ");";
1236
+ }
1237
+ else if(holder && mode == OptionalNone)
1238
+ {
1239
+ out << nl << stream << ".readObject(" << param << ");";
1240
+ }
1241
+ else
1242
+ {
1243
+ if(patchParams.empty())
1244
+ {
1245
+ out << nl << stream << ".readObject(new Patcher());";
1246
+ }
1247
+ else
1248
+ {
1249
+ out << nl << stream << ".readObject(" << patchParams << ");";
1250
+ }
1251
+ }
1252
+ }
1253
+ break;
1254
+ }
1255
+ case Builtin::KindObjectProxy:
1256
+ {
1257
+ if(marshal)
1258
+ {
1259
+ if(optionalParam)
1260
+ {
1261
+ out << nl << stream << ".writeProxy(" << tag << ", " << v << ");";
1262
+ }
1263
+ else if(mode == OptionalMember)
1264
+ {
1265
+ out << nl << "int __pos = " << stream << ".startSize();";
1266
+ out << nl << stream << ".writeProxy(" << v << ");";
1267
+ out << nl << stream << ".endSize(__pos);";
1268
+ }
1269
+ else
1270
+ {
1271
+ out << nl << stream << ".writeProxy(" << v << ");";
1272
+ }
1273
+ }
1274
+ else
1275
+ {
1276
+ if(optionalParam)
1277
+ {
1278
+ out << nl << stream << ".readProxy(" << tag << ", " << v << ");";
1279
+ }
1280
+ else if(mode == OptionalMember)
1281
+ {
1282
+ out << nl << stream << ".skip(4);";
1283
+ out << nl << v << " = " << stream << ".readProxy();";
1284
+ }
1285
+ else
1286
+ {
1287
+ out << nl << v << " = " << stream << ".readProxy();";
1288
+ }
1289
+ }
1290
+ break;
1291
+ }
1292
+ case Builtin::KindLocalObject:
1293
+ {
1294
+ assert(false);
1295
+ break;
1296
+ }
1297
+ }
1298
+ return;
1299
+ }
1300
+
1301
+ ProxyPtr prx = ProxyPtr::dynamicCast(type);
1302
+ if(prx)
1303
+ {
1304
+ string typeS = typeToString(type, TypeModeIn, package);
1305
+ if(marshal)
1306
+ {
1307
+ if(optionalParam)
1308
+ {
1309
+ if(optionalMapping)
1310
+ {
1311
+ out << nl << "if(" << v << " != null && " << v << ".isSet() && " << stream << ".writeOpt(" << tag
1312
+ << ", " << getOptionalFormat(type) << "))";
1313
+ out << sb;
1314
+ out << nl << "int __pos = " << stream << ".startSize();";
1315
+ out << nl << typeS << "Helper.__write(" << stream << ", " << v << ".get());";
1316
+ out << nl << stream << ".endSize(__pos);";
1317
+ out << eb;
1318
+ }
1319
+ else
1320
+ {
1321
+ out << nl << "if(" << stream << ".writeOpt(" << tag << ", " << getOptionalFormat(type) << "))";
1322
+ out << sb;
1323
+ out << nl << "int __pos = " << stream << ".startSize();";
1324
+ out << nl << typeS << "Helper.__write(" << stream << ", " << v << ");";
1325
+ out << nl << stream << ".endSize(__pos);";
1326
+ out << eb;
1327
+ }
1328
+ }
1329
+ else if(mode == OptionalMember)
1330
+ {
1331
+ out << nl << "int __pos = " << stream << ".startSize();";
1332
+ out << nl << typeS << "Helper.__write(" << stream << ", " << v << ");";
1333
+ out << nl << stream << ".endSize(__pos);";
1334
+ }
1335
+ else
1336
+ {
1337
+ out << nl << typeS << "Helper.__write(" << stream << ", " << v << ");";
1338
+ }
1339
+ }
1340
+ else
1341
+ {
1342
+ if(optionalParam)
1343
+ {
1344
+ out << nl << "if(" << stream << ".readOpt(" << tag << ", " << getOptionalFormat(type) << "))";
1345
+ out << sb;
1346
+ out << nl << stream << ".skip(4);";
1347
+ out << nl << v << ".set(" << typeS << "Helper.__read(" << stream << "));";
1348
+ out << eb;
1349
+ if(mode == OptionalOutParam)
1350
+ {
1351
+ out << nl << "else";
1352
+ out << sb;
1353
+ out << nl << v << ".clear();";
1354
+ out << eb;
1355
+ }
1356
+ }
1357
+ else if(mode == OptionalMember)
1358
+ {
1359
+ out << nl << stream << ".skip(4);";
1360
+ out << nl << v << " = " << typeS << "Helper.__read(" << stream << ");";
1361
+ }
1362
+ else
1363
+ {
1364
+ out << nl << v << " = " << typeS << "Helper.__read(" << stream << ");";
1365
+ }
1366
+ }
1367
+ return;
1368
+ }
1369
+
1370
+ ClassDeclPtr cl = ClassDeclPtr::dynamicCast(type);
1371
+ if(cl)
1372
+ {
1373
+ if(marshal)
1374
+ {
1375
+ if(optionalParam)
1376
+ {
1377
+ out << nl << stream << ".writeObject(" << tag << ", " << v << ");";
1378
+ }
1379
+ else
1380
+ {
1381
+ out << nl << stream << ".writeObject(" << v << ");";
1382
+ }
1383
+ }
1384
+ else
1385
+ {
1386
+ if(optionalParam)
1387
+ {
1388
+ string typeS = typeToString(type, TypeModeIn, package);
1389
+ out << nl << "if(" << stream << ".readOpt(" << tag << ", " << getOptionalFormat(type) << "))";
1390
+ out << sb;
1391
+ out << nl << stream << ".readObject(new Ice.OptionalObject(" << v << ", " << typeS << ".class, "
1392
+ << getStaticId(type, package) << "));";
1393
+ out << eb;
1394
+ if(mode == OptionalOutParam)
1395
+ {
1396
+ out << nl << "else";
1397
+ out << sb;
1398
+ out << nl << v << ".clear();";
1399
+ out << eb;
1400
+ }
1401
+ }
1402
+ else
1403
+ {
1404
+ if(holder && mode == OptionalNone)
1405
+ {
1406
+ out << nl << stream << ".readObject(" << param << ");";
1407
+ }
1408
+ else
1409
+ {
1410
+ if(patchParams.empty())
1411
+ {
1412
+ out << nl << stream << ".readObject(new Patcher());";
1413
+ }
1414
+ else
1415
+ {
1416
+ out << nl << stream << ".readObject(" << patchParams << ");";
1417
+ }
1418
+ }
1419
+ }
1420
+ }
1421
+ return;
1422
+ }
1423
+
1424
+ StructPtr st = StructPtr::dynamicCast(type);
1425
+ if(st)
1426
+ {
1427
+ if(marshal)
1428
+ {
1429
+ if(optionalParam || mode == OptionalMember)
1430
+ {
1431
+ string val;
1432
+
1433
+ if(optionalParam)
1434
+ {
1435
+ if(optionalMapping)
1436
+ {
1437
+ out << nl << "if(" << v << " != null && " << v << ".isSet() && " << stream << ".writeOpt("
1438
+ << tag << ", " << getOptionalFormat(type) << "))";
1439
+ val = v + ".get()";
1440
+ }
1441
+ else
1442
+ {
1443
+ out << nl << "if(" << stream << ".writeOpt(" << tag << ", " << getOptionalFormat(type) << "))";
1444
+ val = v;
1445
+ }
1446
+
1447
+ out << sb;
1448
+ }
1449
+ else
1450
+ {
1451
+ val = v;
1452
+ }
1453
+
1454
+ if(st->isVariableLength())
1455
+ {
1456
+ out << nl << "int __pos = " << stream << ".startSize();";
1457
+ out << nl << val << ".__write(" << stream << ");";
1458
+ out << nl << stream << ".endSize(__pos);";
1459
+ }
1460
+ else
1461
+ {
1462
+ out << nl << stream << ".writeSize(" << st->minWireSize() << ");";
1463
+ out << nl << val << ".__write(" << stream << ");";
1464
+ }
1465
+
1466
+ if(optionalParam)
1467
+ {
1468
+ out << eb;
1469
+ }
1470
+ }
1471
+ else
1472
+ {
1473
+ out << nl << v << ".__write(" << stream << ");";
1474
+ }
1475
+ }
1476
+ else
1477
+ {
1478
+ string typeS = typeToString(type, TypeModeIn, package, metaData);
1479
+
1480
+ if(optionalParam)
1481
+ {
1482
+ out << nl << "if(" << stream << ".readOpt(" << tag << ", " << getOptionalFormat(type) << "))";
1483
+ out << sb;
1484
+
1485
+ if(st->isVariableLength())
1486
+ {
1487
+ out << nl << stream << ".skip(4);";
1488
+ }
1489
+ else
1490
+ {
1491
+ out << nl << stream << ".skipSize();";
1492
+ }
1493
+
1494
+ out << nl << typeS << " __tmpOpt = new " << typeS << "();";
1495
+ out << nl << "__tmpOpt.__read(" << stream << ");";
1496
+ out << nl << v << ".set(__tmpOpt);";
1497
+
1498
+ out << eb;
1499
+
1500
+ if(mode == OptionalOutParam)
1501
+ {
1502
+ out << nl << "else";
1503
+ out << sb;
1504
+ out << nl << v << ".clear();";
1505
+ out << eb;
1506
+ }
1507
+ }
1508
+ else if(mode == OptionalMember)
1509
+ {
1510
+ if(st->isVariableLength())
1511
+ {
1512
+ out << nl << stream << ".skip(4);";
1513
+ }
1514
+ else
1515
+ {
1516
+ out << nl << stream << ".skipSize();";
1517
+ }
1518
+ out << nl << v << " = new " << typeS << "();";
1519
+ out << nl << v << ".__read(" << stream << ");";
1520
+ }
1521
+ else
1522
+ {
1523
+ out << nl << v << " = new " << typeS << "();";
1524
+ out << nl << v << ".__read(" << stream << ");";
1525
+ }
1526
+ }
1527
+ return;
1528
+ }
1529
+
1530
+ EnumPtr en = EnumPtr::dynamicCast(type);
1531
+ if(en)
1532
+ {
1533
+ if(marshal)
1534
+ {
1535
+ if(optionalParam)
1536
+ {
1537
+ if(optionalMapping)
1538
+ {
1539
+ out << nl << "if(" << v << " != null && " << v << ".isSet() && " << stream << ".writeOpt(" << tag
1540
+ << ", " << getOptionalFormat(type) << "))";
1541
+ out << sb;
1542
+ out << nl << v << ".get().__write(" << stream << ");";
1543
+ out << eb;
1544
+ }
1545
+ else
1546
+ {
1547
+ out << nl << "if(" << stream << ".writeOpt(" << tag << ", " << getOptionalFormat(type) << "))";
1548
+ out << sb;
1549
+ out << nl << v << ".__write(" << stream << ");";
1550
+ out << eb;
1551
+ }
1552
+ }
1553
+ else
1554
+ {
1555
+ out << nl << v << ".__write(" << stream << ");";
1556
+ }
1557
+ }
1558
+ else
1559
+ {
1560
+ string typeS = typeToString(type, TypeModeIn, package, metaData);
1561
+
1562
+ if(optionalParam)
1563
+ {
1564
+ out << nl << "if(" << stream << ".readOpt(" << tag << ", " << getOptionalFormat(type) << "))";
1565
+ out << sb;
1566
+ out << nl << v << ".set(" << typeS << ".__read(" << stream << "));";
1567
+ out << eb;
1568
+ if(mode == OptionalOutParam)
1569
+ {
1570
+ out << nl << "else";
1571
+ out << sb;
1572
+ out << nl << v << ".clear();";
1573
+ out << eb;
1574
+ }
1575
+ }
1576
+ else
1577
+ {
1578
+ out << nl << v << " = " << typeS << ".__read(" << stream << ");";
1579
+ }
1580
+ }
1581
+ return;
1582
+ }
1583
+
1584
+ DictionaryPtr dict = DictionaryPtr::dynamicCast(type);
1585
+ if(dict)
1586
+ {
1587
+ if(optionalParam || mode == OptionalMember)
1588
+ {
1589
+ string typeS = typeToString(type, TypeModeIn, package, metaData);
1590
+ TypePtr keyType = dict->keyType();
1591
+ TypePtr valueType = dict->valueType();
1592
+
1593
+ if(marshal)
1594
+ {
1595
+ if(optionalParam)
1596
+ {
1597
+ if(optionalMapping)
1598
+ {
1599
+ out << nl << "if(" << v << " != null && " << v << ".isSet() && " << stream << ".writeOpt("
1600
+ << tag << ", " << getOptionalFormat(type) << "))";
1601
+ out << sb;
1602
+ }
1603
+ else
1604
+ {
1605
+ out << nl << "if(" << stream << ".writeOpt(" << tag << ", " << getOptionalFormat(type) << "))";
1606
+ out << sb;
1607
+ }
1608
+ }
1609
+
1610
+ if(keyType->isVariableLength() || valueType->isVariableLength())
1611
+ {
1612
+ string d = optionalParam && optionalMapping ? v + ".get()" : v;
1613
+ out << nl << "int __pos = " << stream << ".startSize();";
1614
+ writeDictionaryMarshalUnmarshalCode(out, package, dict, d, marshal, iter, true, metaData);
1615
+ out << nl << stream << ".endSize(__pos);";
1616
+ }
1617
+ else
1618
+ {
1619
+ const size_t wireSize = keyType->minWireSize() + valueType->minWireSize();
1620
+ string tmpName;
1621
+ if(optionalParam && optionalMapping)
1622
+ {
1623
+ tmpName = "__optDict";
1624
+ out << nl << "final " << typeS << ' ' << tmpName << " = " << v << ".get();";
1625
+ }
1626
+ else
1627
+ {
1628
+ tmpName = v;
1629
+ }
1630
+ out << nl << "final int __optSize = " << tmpName << " == null ? 0 : " << tmpName << ".size();";
1631
+ out << nl << stream << ".writeSize(__optSize > 254 ? __optSize * " << wireSize
1632
+ << " + 5 : __optSize * " << wireSize << " + 1);";
1633
+ writeDictionaryMarshalUnmarshalCode(out, package, dict, tmpName, marshal, iter, true, metaData);
1634
+ }
1635
+
1636
+ if(optionalParam)
1637
+ {
1638
+ out << eb;
1639
+ }
1640
+ }
1641
+ else
1642
+ {
1643
+ string tmpName;
1644
+
1645
+ if(optionalParam)
1646
+ {
1647
+ tmpName = "__optDict";
1648
+ out << nl << "if(" << stream << ".readOpt(" << tag << ", " << getOptionalFormat(type) << "))";
1649
+ out << sb;
1650
+ out << nl << typeS << ' ' << tmpName << ';';
1651
+ }
1652
+ else
1653
+ {
1654
+ tmpName = v;
1655
+ }
1656
+
1657
+ if(keyType->isVariableLength() || valueType->isVariableLength())
1658
+ {
1659
+ out << nl << stream << ".skip(4);";
1660
+ }
1661
+ else
1662
+ {
1663
+ out << nl << stream << ".skipSize();";
1664
+ }
1665
+
1666
+ writeDictionaryMarshalUnmarshalCode(out, package, dict, tmpName, marshal, iter, true, metaData);
1667
+
1668
+ if(optionalParam)
1669
+ {
1670
+ out << nl << v << ".set(" << tmpName << ");";
1671
+ out << eb;
1672
+ if(mode == OptionalOutParam)
1673
+ {
1674
+ out << nl << "else";
1675
+ out << sb;
1676
+ out << nl << v << ".clear();";
1677
+ out << eb;
1678
+ }
1679
+ }
1680
+ }
1681
+ }
1682
+ else
1683
+ {
1684
+ writeDictionaryMarshalUnmarshalCode(out, package, dict, v, marshal, iter, true, metaData);
1685
+ }
1686
+ return;
1687
+ }
1688
+
1689
+ SequencePtr seq = SequencePtr::dynamicCast(type);
1690
+ if(seq)
1691
+ {
1692
+ if(optionalParam || mode == OptionalMember)
1693
+ {
1694
+ string typeS = typeToString(type, TypeModeIn, package, metaData);
1695
+ TypePtr elemType = seq->type();
1696
+ BuiltinPtr elemBuiltin = BuiltinPtr::dynamicCast(elemType);
1697
+
1698
+ if(optionalParam && elemBuiltin && elemBuiltin->kind() != Builtin::KindObject &&
1699
+ elemBuiltin->kind() != Builtin::KindObjectProxy && !hasTypeMetaData(seq, metaData))
1700
+ {
1701
+ static const char* builtinTable[] =
1702
+ {
1703
+ "Byte",
1704
+ "Bool",
1705
+ "Short",
1706
+ "Int",
1707
+ "Long",
1708
+ "Float",
1709
+ "Double",
1710
+ "String",
1711
+ "???",
1712
+ "???",
1713
+ "???"
1714
+ };
1715
+
1716
+ switch(elemBuiltin->kind())
1717
+ {
1718
+ case Builtin::KindByte:
1719
+ case Builtin::KindBool:
1720
+ case Builtin::KindShort:
1721
+ case Builtin::KindInt:
1722
+ case Builtin::KindLong:
1723
+ case Builtin::KindFloat:
1724
+ case Builtin::KindDouble:
1725
+ case Builtin::KindString:
1726
+ {
1727
+ string bs = builtinTable[elemBuiltin->kind()];
1728
+
1729
+ if(marshal)
1730
+ {
1731
+ out << nl << stream << ".write" << bs << "Seq(" << tag << ", " << v << ");";
1732
+ }
1733
+ else
1734
+ {
1735
+ out << nl << stream << ".read" << bs << "Seq(" << tag << ", " << v << ");";
1736
+ }
1737
+ return;
1738
+ }
1739
+ case Builtin::KindObject:
1740
+ case Builtin::KindObjectProxy:
1741
+ case Builtin::KindLocalObject:
1742
+ {
1743
+ assert(false);
1744
+ break;
1745
+ }
1746
+ }
1747
+ }
1748
+
1749
+ string ignore;
1750
+ const size_t wireSize = elemType->minWireSize();
1751
+
1752
+ if(marshal)
1753
+ {
1754
+ if(optionalParam)
1755
+ {
1756
+ if(optionalMapping)
1757
+ {
1758
+ out << nl << "if(" << v << " != null && " << v << ".isSet() && " << stream << ".writeOpt("
1759
+ << tag << ", " << getOptionalFormat(type) << "))";
1760
+ }
1761
+ else
1762
+ {
1763
+ out << nl << "if(" << stream << ".writeOpt(" << tag << ", " << getOptionalFormat(type) << "))";
1764
+ }
1765
+
1766
+ out << sb;
1767
+ }
1768
+
1769
+ if(elemType->isVariableLength())
1770
+ {
1771
+ string s = optionalParam && optionalMapping ? v + ".get()" : v;
1772
+ out << nl << "int __pos = " << stream << ".startSize();";
1773
+ writeSequenceMarshalUnmarshalCode(out, package, seq, s, marshal, iter, true, metaData);
1774
+ out << nl << stream << ".endSize(__pos);";
1775
+ }
1776
+ else if(findMetaData("java:type:", metaData, ignore) ||
1777
+ findMetaData("java:type:", seq->getMetaData(), ignore))
1778
+ {
1779
+ //
1780
+ // The sequence is an instance of java.util.List<E>, where E is a fixed-size type.
1781
+ // If the element type is bool or byte, we do NOT write an extra size.
1782
+ //
1783
+
1784
+ string tmpName;
1785
+ if(optionalParam && optionalMapping)
1786
+ {
1787
+ tmpName = "__optSeq";
1788
+ out << nl << "final " << typeS << ' ' << tmpName << " = " << v << ".get();";
1789
+ }
1790
+ else
1791
+ {
1792
+ tmpName = v;
1793
+ }
1794
+
1795
+ if(wireSize > 1)
1796
+ {
1797
+ out << nl << "final int __optSize = " << tmpName << " == null ? 0 : " << tmpName << ".size();";
1798
+ out << nl << stream << ".writeSize(__optSize > 254 ? __optSize * " << wireSize
1799
+ << " + 5 : __optSize * " << wireSize << " + 1);";
1800
+ }
1801
+ writeSequenceMarshalUnmarshalCode(out, package, seq, tmpName, marshal, iter, true, metaData);
1802
+ }
1803
+ else if(findMetaData("java:protobuf:", seq->getMetaData(), ignore) ||
1804
+ findMetaData("java:serializable:", seq->getMetaData(), ignore))
1805
+ {
1806
+ //
1807
+ // This just writes a byte sequence.
1808
+ //
1809
+ string s = optionalParam && optionalMapping ? v + ".get()" : v;
1810
+ writeSequenceMarshalUnmarshalCode(out, package, seq, s, marshal, iter, true, metaData);
1811
+ }
1812
+ else
1813
+ {
1814
+ //
1815
+ // At this point we have a regular Java array of a fixed-size type.
1816
+ //
1817
+
1818
+ string tmpName;
1819
+ if(optionalParam && optionalMapping)
1820
+ {
1821
+ tmpName = "__optSeq";
1822
+ out << nl << "final " << typeS << ' ' << tmpName << " = " << v << ".get();";
1823
+ }
1824
+ else
1825
+ {
1826
+ tmpName = v;
1827
+ }
1828
+
1829
+ if(wireSize > 1)
1830
+ {
1831
+ out << nl << "final int __optSize = " << tmpName << " == null ? 0 : " << tmpName << ".length;";
1832
+ out << nl << stream << ".writeSize(__optSize > 254 ? __optSize * " << wireSize
1833
+ << " + 5 : __optSize * " << wireSize << " + 1);";
1834
+ }
1835
+
1836
+ writeSequenceMarshalUnmarshalCode(out, package, seq, tmpName, marshal, iter, true, metaData);
1837
+ }
1838
+
1839
+ if(optionalParam)
1840
+ {
1841
+ out << eb;
1842
+ }
1843
+ }
1844
+ else
1845
+ {
1846
+ string tmpName;
1847
+ if(optionalParam)
1848
+ {
1849
+ tmpName = "__optSeq";
1850
+ out << nl << "if(" << stream << ".readOpt(" << tag << ", " << getOptionalFormat(type) << "))";
1851
+ out << sb;
1852
+ out << nl << typeS << ' ' << tmpName << ';';
1853
+ }
1854
+ else
1855
+ {
1856
+ tmpName = v;
1857
+ }
1858
+
1859
+ if(elemType->isVariableLength())
1860
+ {
1861
+ out << nl << stream << ".skip(4);";
1862
+ }
1863
+ else if(wireSize > 1)
1864
+ {
1865
+ if(findMetaData("java:type:", metaData, ignore) ||
1866
+ findMetaData("java:type:", seq->getMetaData(), ignore))
1867
+ {
1868
+ //
1869
+ // The sequence is an instance of java.util.List<E>, where E is a fixed-size type.
1870
+ //
1871
+
1872
+ out << nl << stream << ".skipSize();";
1873
+ }
1874
+ else if(!findMetaData("java:protobuf:", seq->getMetaData(), ignore) &&
1875
+ !findMetaData("java:serializable:", seq->getMetaData(), ignore))
1876
+ {
1877
+ out << nl << stream << ".skipSize();";
1878
+ }
1879
+ }
1880
+
1881
+ writeSequenceMarshalUnmarshalCode(out, package, seq, tmpName, marshal, iter, true, metaData);
1882
+
1883
+ if(optionalParam)
1884
+ {
1885
+ out << nl << v << ".set(" << tmpName << ");";
1886
+ out << eb;
1887
+ if(mode == OptionalOutParam)
1888
+ {
1889
+ out << nl << "else";
1890
+ out << sb;
1891
+ out << nl << v << ".clear();";
1892
+ out << eb;
1893
+ }
1894
+ }
1895
+ }
1896
+ }
1897
+ else
1898
+ {
1899
+ writeSequenceMarshalUnmarshalCode(out, package, seq, v, marshal, iter, true, metaData);
1900
+ }
1901
+ return;
1902
+ }
1903
+
1904
+ ConstructedPtr constructed = ConstructedPtr::dynamicCast(type);
1905
+ assert(constructed);
1906
+ string typeS = getAbsolute(constructed, package);
1907
+ if(marshal)
1908
+ {
1909
+ out << nl << typeS << "Helper.write(" << stream << ", " << v << ");";
1910
+ }
1911
+ else
1912
+ {
1913
+ out << nl << v << " = " << typeS << "Helper.read(" << stream << ");";
1914
+ }
1915
+ }
1916
+
1917
+ void
1918
+ Slice::JavaGenerator::writeDictionaryMarshalUnmarshalCode(Output& out,
1919
+ const string& package,
1920
+ const DictionaryPtr& dict,
1921
+ const string& param,
1922
+ bool marshal,
1923
+ int& iter,
1924
+ bool useHelper,
1925
+ const StringList& metaData)
1926
+ {
1927
+ string stream = marshal ? "__os" : "__is";
1928
+ string v = param;
1929
+
1930
+ string instanceType;
1931
+
1932
+ //
1933
+ // We have to determine whether it's possible to use the
1934
+ // type's generated helper class for this marshal/unmarshal
1935
+ // task. Since the user may have specified a custom type in
1936
+ // metadata, it's possible that the helper class is not
1937
+ // compatible and therefore we'll need to generate the code
1938
+ // in-line instead.
1939
+ //
1940
+ // Specifically, there may be "local" metadata (i.e., from
1941
+ // a data member or parameter definition) that overrides the
1942
+ // original type. We'll compare the mapped types with and
1943
+ // without local metadata to determine whether we can use
1944
+ // the helper.
1945
+ //
1946
+ string formalType;
1947
+ getDictionaryTypes(dict, "", metaData, instanceType, formalType);
1948
+ string origInstanceType, origFormalType;
1949
+ getDictionaryTypes(dict, "", StringList(), origInstanceType, origFormalType);
1950
+ if((formalType != origFormalType) || (!marshal && instanceType != origInstanceType))
1951
+ {
1952
+ useHelper = false;
1953
+ }
1954
+
1955
+ //
1956
+ // If we can use the helper, it's easy.
1957
+ //
1958
+ if(useHelper)
1959
+ {
1960
+ string typeS = getAbsolute(dict, package);
1961
+ if(marshal)
1962
+ {
1963
+ out << nl << typeS << "Helper.write(" << stream << ", " << v << ");";
1964
+ }
1965
+ else
1966
+ {
1967
+ out << nl << v << " = " << typeS << "Helper.read(" << stream << ");";
1968
+ }
1969
+ return;
1970
+ }
1971
+
1972
+ TypePtr key = dict->keyType();
1973
+ TypePtr value = dict->valueType();
1974
+
1975
+ string keyS = typeToString(key, TypeModeIn, package);
1976
+ string valueS = typeToString(value, TypeModeIn, package);
1977
+
1978
+ ostringstream o;
1979
+ o << iter;
1980
+ string iterS = o.str();
1981
+ iter++;
1982
+
1983
+ if(marshal)
1984
+ {
1985
+ out << nl << "if(" << v << " == null)";
1986
+ out << sb;
1987
+ out << nl << "__os.writeSize(0);";
1988
+ out << eb;
1989
+ out << nl << "else";
1990
+ out << sb;
1991
+ out << nl << "__os.writeSize(" << v << ".size());";
1992
+ string keyObjectS = typeToObjectString(key, TypeModeIn, package);
1993
+ string valueObjectS = typeToObjectString(value, TypeModeIn, package);
1994
+ out << nl << "for(java.util.Map.Entry<" << keyObjectS << ", " << valueObjectS << "> __e : " << v
1995
+ << ".entrySet())";
1996
+ out << sb;
1997
+ for(int i = 0; i < 2; i++)
1998
+ {
1999
+ string arg;
2000
+ TypePtr type;
2001
+ if(i == 0)
2002
+ {
2003
+ arg = "__e.getKey()";
2004
+ type = key;
2005
+ }
2006
+ else
2007
+ {
2008
+ arg = "__e.getValue()";
2009
+ type = value;
2010
+ }
2011
+ writeMarshalUnmarshalCode(out, package, type, OptionalNone, false, 0, arg, true, iter, false);
2012
+ }
2013
+ out << eb;
2014
+ out << eb;
2015
+ }
2016
+ else
2017
+ {
2018
+ out << nl << v << " = new " << instanceType << "();";
2019
+ out << nl << "int __sz" << iterS << " = __is.readSize();";
2020
+ out << nl << "for(int __i" << iterS << " = 0; __i" << iterS << " < __sz" << iterS << "; __i" << iterS << "++)";
2021
+ out << sb;
2022
+ for(int i = 0; i < 2; i++)
2023
+ {
2024
+ string arg;
2025
+ TypePtr type;
2026
+ string typeS;
2027
+ if(i == 0)
2028
+ {
2029
+ arg = "__key";
2030
+ type = key;
2031
+ typeS = keyS;
2032
+ }
2033
+ else
2034
+ {
2035
+ arg = "__value";
2036
+ type = value;
2037
+ typeS = valueS;
2038
+ }
2039
+
2040
+ BuiltinPtr b = BuiltinPtr::dynamicCast(type);
2041
+ if(ClassDeclPtr::dynamicCast(type) || (b && b->kind() == Builtin::KindObject))
2042
+ {
2043
+ string keyTypeStr = typeToObjectString(key, TypeModeIn, package);
2044
+ string valueTypeStr = typeToObjectString(value, TypeModeIn, package);
2045
+ writeMarshalUnmarshalCode(out, package, type, OptionalNone, false, 0, arg, false, iter, false,
2046
+ StringList(),
2047
+ "new IceInternal.DictionaryPatcher<" + keyTypeStr + ", " + valueTypeStr +
2048
+ ">(" + v + ", " + typeS + ".class, \"" + type->typeId() + "\", __key)");
2049
+ }
2050
+ else
2051
+ {
2052
+ out << nl << typeS << ' ' << arg << ';';
2053
+ writeMarshalUnmarshalCode(out, package, type, OptionalNone, false, 0, arg, false, iter, false);
2054
+ }
2055
+ }
2056
+ BuiltinPtr builtin = BuiltinPtr::dynamicCast(value);
2057
+ if(!(builtin && builtin->kind() == Builtin::KindObject) && !ClassDeclPtr::dynamicCast(value))
2058
+ {
2059
+ out << nl << "" << v << ".put(__key, __value);";
2060
+ }
2061
+ out << eb;
2062
+ }
2063
+ }
2064
+
2065
+ void
2066
+ Slice::JavaGenerator::writeSequenceMarshalUnmarshalCode(Output& out,
2067
+ const string& package,
2068
+ const SequencePtr& seq,
2069
+ const string& param,
2070
+ bool marshal,
2071
+ int& iter,
2072
+ bool useHelper,
2073
+ const StringList& metaData)
2074
+ {
2075
+ string stream = marshal ? "__os" : "__is";
2076
+ string v = param;
2077
+
2078
+ //
2079
+ // If the sequence is a byte sequence, check if there's the serializable or protobuf metadata to
2080
+ // get rid of these two easy cases first.
2081
+ //
2082
+ BuiltinPtr builtin = BuiltinPtr::dynamicCast(seq->type());
2083
+ if(builtin && builtin->kind() == Builtin::KindByte)
2084
+ {
2085
+ string meta;
2086
+ static const string protobuf = "java:protobuf:";
2087
+ static const string serializable = "java:serializable:";
2088
+ if(seq->findMetaData(serializable, meta))
2089
+ {
2090
+ if(marshal)
2091
+ {
2092
+ out << nl << stream << ".writeSerializable(" << v << ");";
2093
+ }
2094
+ else
2095
+ {
2096
+ string type = typeToString(seq, TypeModeIn, package);
2097
+ out << nl << v << " = (" << type << ")" << stream << ".readSerializable();";
2098
+ }
2099
+ return;
2100
+ }
2101
+ else if(seq->findMetaData(protobuf, meta))
2102
+ {
2103
+ if(marshal)
2104
+ {
2105
+ out << nl << "if(!" << v << ".isInitialized())";
2106
+ out << sb;
2107
+ out << nl << "throw new Ice.MarshalException(\"type not fully initialized\");";
2108
+ out << eb;
2109
+ out << nl << stream << ".writeByteSeq(" << v << ".toByteArray());";
2110
+ }
2111
+ else
2112
+ {
2113
+ string type = typeToString(seq, TypeModeIn, package);
2114
+ out << nl << "try";
2115
+ out << sb;
2116
+ out << nl << v << " = " << type << ".parseFrom(" << stream << ".readByteSeq());";
2117
+ out << eb;
2118
+ out << nl << "catch(com.google.protobuf.InvalidProtocolBufferException __ex)";
2119
+ out << sb;
2120
+ out << nl << "throw new Ice.MarshalException(__ex);";
2121
+ out << eb;
2122
+ }
2123
+ return;
2124
+ }
2125
+ }
2126
+
2127
+ if(builtin &&
2128
+ (builtin->kind() == Builtin::KindByte || builtin->kind() == Builtin::KindShort ||
2129
+ builtin->kind() == Builtin::KindInt || builtin->kind() == Builtin::KindLong ||
2130
+ builtin->kind() == Builtin::KindFloat || builtin->kind() == Builtin::KindDouble))
2131
+ {
2132
+ string meta;
2133
+ static const string bytebuffer = "java:buffer";
2134
+ if(seq->findMetaData(bytebuffer, meta) || findMetaData(bytebuffer, metaData, meta))
2135
+ {
2136
+ switch(builtin->kind())
2137
+ {
2138
+ case Builtin::KindByte:
2139
+ {
2140
+ if(marshal)
2141
+ {
2142
+ out << nl << stream << ".writeByteBuffer(" << v << ");";
2143
+ }
2144
+ else
2145
+ {
2146
+ out << nl << v << " = " << stream << ".readByteBuffer();";
2147
+ }
2148
+ break;
2149
+ }
2150
+ case Builtin::KindShort:
2151
+ {
2152
+ if(marshal)
2153
+ {
2154
+ out << nl << stream << ".writeShortBuffer(" << v << ");";
2155
+ }
2156
+ else
2157
+ {
2158
+ out << nl << v << " = " << stream << ".readShortBuffer();";
2159
+ }
2160
+ break;
2161
+ }
2162
+ case Builtin::KindInt:
2163
+ {
2164
+ if(marshal)
2165
+ {
2166
+ out << nl << stream << ".writeIntBuffer(" << v << ");";
2167
+ }
2168
+ else
2169
+ {
2170
+ out << nl << v << " = " << stream << ".readIntBuffer();";
2171
+ }
2172
+ break;
2173
+ }
2174
+ case Builtin::KindLong:
2175
+ {
2176
+ if(marshal)
2177
+ {
2178
+ out << nl << stream << ".writeLongBuffer(" << v << ");";
2179
+ }
2180
+ else
2181
+ {
2182
+ out << nl << v << " = " << stream << ".readLongBuffer();";
2183
+ }
2184
+ break;
2185
+ }
2186
+ case Builtin::KindFloat:
2187
+ {
2188
+ if(marshal)
2189
+ {
2190
+ out << nl << stream << ".writeFloatBuffer(" << v << ");";
2191
+ }
2192
+ else
2193
+ {
2194
+ out << nl << v << " = " << stream << ".readFloatBuffer();";
2195
+ }
2196
+ break;
2197
+ }
2198
+ case Builtin::KindDouble:
2199
+ {
2200
+ if(marshal)
2201
+ {
2202
+ out << nl << stream << ".writeDoubleBuffer(" << v << ");";
2203
+ }
2204
+ else
2205
+ {
2206
+ out << nl << v << " = " << stream << ".readDoubleBuffer();";
2207
+ }
2208
+ break;
2209
+ }
2210
+ case Builtin::KindBool:
2211
+ case Builtin::KindString:
2212
+ case Builtin::KindObject:
2213
+ case Builtin::KindObjectProxy:
2214
+ case Builtin::KindLocalObject:
2215
+ {
2216
+ assert(false);
2217
+ break;
2218
+ }
2219
+ }
2220
+ return;
2221
+ }
2222
+ }
2223
+
2224
+ bool customType = false;
2225
+ string instanceType;
2226
+
2227
+ //
2228
+ // We have to determine whether it's possible to use the
2229
+ // type's generated helper class for this marshal/unmarshal
2230
+ // task. Since the user may have specified a custom type in
2231
+ // metadata, it's possible that the helper class is not
2232
+ // compatible and therefore we'll need to generate the code
2233
+ // in-line instead.
2234
+ //
2235
+ // Specifically, there may be "local" metadata (i.e., from
2236
+ // a data member or parameter definition) that overrides the
2237
+ // original type. We'll compare the mapped types with and
2238
+ // without local metadata to determine whether we can use
2239
+ // the helper.
2240
+ //
2241
+ string formalType;
2242
+ customType = getSequenceTypes(seq, "", metaData, instanceType, formalType);
2243
+ string origInstanceType, origFormalType;
2244
+ getSequenceTypes(seq, "", StringList(), origInstanceType, origFormalType);
2245
+ if((formalType != origFormalType) || (!marshal && instanceType != origInstanceType))
2246
+ {
2247
+ useHelper = false;
2248
+ }
2249
+
2250
+ //
2251
+ // If we can use the helper, it's easy.
2252
+ //
2253
+ if(useHelper)
2254
+ {
2255
+ string typeS = getAbsolute(seq, package);
2256
+ if(marshal)
2257
+ {
2258
+ out << nl << typeS << "Helper.write(" << stream << ", " << v << ");";
2259
+ }
2260
+ else
2261
+ {
2262
+ out << nl << v << " = " << typeS << "Helper.read(" << stream << ");";
2263
+ }
2264
+ return;
2265
+ }
2266
+
2267
+ //
2268
+ // Determine sequence depth.
2269
+ //
2270
+ int depth = 0;
2271
+ TypePtr origContent = seq->type();
2272
+ SequencePtr s = SequencePtr::dynamicCast(origContent);
2273
+ while(s)
2274
+ {
2275
+ //
2276
+ // Stop if the inner sequence type has a custom, serializable or protobuf type.
2277
+ //
2278
+ if(hasTypeMetaData(s))
2279
+ {
2280
+ break;
2281
+ }
2282
+ depth++;
2283
+ origContent = s->type();
2284
+ s = SequencePtr::dynamicCast(origContent);
2285
+ }
2286
+ string origContentS = typeToString(origContent, TypeModeIn, package);
2287
+
2288
+ TypePtr type = seq->type();
2289
+
2290
+ if(customType)
2291
+ {
2292
+ //
2293
+ // Marshal/unmarshal a custom sequence type.
2294
+ //
2295
+ BuiltinPtr b = BuiltinPtr::dynamicCast(type);
2296
+ string typeS = getAbsolute(seq, package);
2297
+ ostringstream o;
2298
+ o << origContentS;
2299
+ int d = depth;
2300
+ while(d--)
2301
+ {
2302
+ o << "[]";
2303
+ }
2304
+ string cont = o.str();
2305
+ if(marshal)
2306
+ {
2307
+ out << nl << "if(" << v << " == null)";
2308
+ out << sb;
2309
+ out << nl << stream << ".writeSize(0);";
2310
+ out << eb;
2311
+ out << nl << "else";
2312
+ out << sb;
2313
+ out << nl << stream << ".writeSize(" << v << ".size());";
2314
+ string typeS = typeToString(type, TypeModeIn, package);
2315
+ out << nl << "for(" << typeS << " __elem : " << v << ')';
2316
+ out << sb;
2317
+ writeMarshalUnmarshalCode(out, package, type, OptionalNone, false, 0, "__elem", true, iter, false);
2318
+ out << eb;
2319
+ out << eb; // else
2320
+ }
2321
+ else
2322
+ {
2323
+ bool isObject = false;
2324
+ ClassDeclPtr cl = ClassDeclPtr::dynamicCast(type);
2325
+ if((b && b->kind() == Builtin::KindObject) || cl)
2326
+ {
2327
+ isObject = true;
2328
+ }
2329
+ out << nl << v << " = new " << instanceType << "();";
2330
+ out << nl << "final int __len" << iter << " = " << stream << ".readAndCheckSeqSize(" << type->minWireSize()
2331
+ << ");";
2332
+ if(isObject)
2333
+ {
2334
+ if(b)
2335
+ {
2336
+ out << nl << "final String __type" << iter << " = Ice.ObjectImpl.ice_staticId();";
2337
+ }
2338
+ else
2339
+ {
2340
+ assert(cl);
2341
+ if(cl->isInterface())
2342
+ {
2343
+ out << nl << "final String __type" << iter << " = "
2344
+ << getAbsolute(cl, package, "_", "Disp") << ".ice_staticId();";
2345
+ }
2346
+ else
2347
+ {
2348
+ out << nl << "final String __type" << iter << " = " << origContentS << ".ice_staticId();";
2349
+ }
2350
+ }
2351
+ }
2352
+ out << nl << "for(int __i" << iter << " = 0; __i" << iter << " < __len" << iter << "; __i" << iter
2353
+ << "++)";
2354
+ out << sb;
2355
+ if(isObject)
2356
+ {
2357
+ //
2358
+ // Add a null value to the list as a placeholder for the element.
2359
+ //
2360
+ out << nl << v << ".add(null);";
2361
+ ostringstream patchParams;
2362
+ patchParams << "new IceInternal.ListPatcher<" << origContentS << ">(" << v << ", " << origContentS
2363
+ << ".class, __type" << iter << ", __i" << iter << ')';
2364
+ writeMarshalUnmarshalCode(out, package, type, OptionalNone, false, 0, "__elem", false, iter,
2365
+ false, StringList(), patchParams.str());
2366
+ }
2367
+ else
2368
+ {
2369
+ out << nl << cont << " __elem;";
2370
+ writeMarshalUnmarshalCode(out, package, type, OptionalNone, false, 0, "__elem", false, iter, false);
2371
+ }
2372
+ if(!isObject)
2373
+ {
2374
+ out << nl << v << ".add(__elem);";
2375
+ }
2376
+ out << eb;
2377
+ iter++;
2378
+ }
2379
+ }
2380
+ else
2381
+ {
2382
+ BuiltinPtr b = BuiltinPtr::dynamicCast(type);
2383
+ if(b && b->kind() != Builtin::KindObject && b->kind() != Builtin::KindObjectProxy)
2384
+ {
2385
+ switch(b->kind())
2386
+ {
2387
+ case Builtin::KindByte:
2388
+ {
2389
+ if(marshal)
2390
+ {
2391
+ out << nl << stream << ".writeByteSeq(" << v << ");";
2392
+ }
2393
+ else
2394
+ {
2395
+ out << nl << v << " = " << stream << ".readByteSeq();";
2396
+ }
2397
+ break;
2398
+ }
2399
+ case Builtin::KindBool:
2400
+ {
2401
+ if(marshal)
2402
+ {
2403
+ out << nl << stream << ".writeBoolSeq(" << v << ");";
2404
+ }
2405
+ else
2406
+ {
2407
+ out << nl << v << " = " << stream << ".readBoolSeq();";
2408
+ }
2409
+ break;
2410
+ }
2411
+ case Builtin::KindShort:
2412
+ {
2413
+ if(marshal)
2414
+ {
2415
+ out << nl << stream << ".writeShortSeq(" << v << ");";
2416
+ }
2417
+ else
2418
+ {
2419
+ out << nl << v << " = " << stream << ".readShortSeq();";
2420
+ }
2421
+ break;
2422
+ }
2423
+ case Builtin::KindInt:
2424
+ {
2425
+ if(marshal)
2426
+ {
2427
+ out << nl << stream << ".writeIntSeq(" << v << ");";
2428
+ }
2429
+ else
2430
+ {
2431
+ out << nl << v << " = " << stream << ".readIntSeq();";
2432
+ }
2433
+ break;
2434
+ }
2435
+ case Builtin::KindLong:
2436
+ {
2437
+ if(marshal)
2438
+ {
2439
+ out << nl << stream << ".writeLongSeq(" << v << ");";
2440
+ }
2441
+ else
2442
+ {
2443
+ out << nl << v << " = " << stream << ".readLongSeq();";
2444
+ }
2445
+ break;
2446
+ }
2447
+ case Builtin::KindFloat:
2448
+ {
2449
+ if(marshal)
2450
+ {
2451
+ out << nl << stream << ".writeFloatSeq(" << v << ");";
2452
+ }
2453
+ else
2454
+ {
2455
+ out << nl << v << " = " << stream << ".readFloatSeq();";
2456
+ }
2457
+ break;
2458
+ }
2459
+ case Builtin::KindDouble:
2460
+ {
2461
+ if(marshal)
2462
+ {
2463
+ out << nl << stream << ".writeDoubleSeq(" << v << ");";
2464
+ }
2465
+ else
2466
+ {
2467
+ out << nl << v << " = " << stream << ".readDoubleSeq();";
2468
+ }
2469
+ break;
2470
+ }
2471
+ case Builtin::KindString:
2472
+ {
2473
+ if(marshal)
2474
+ {
2475
+ out << nl << stream << ".writeStringSeq(" << v << ");";
2476
+ }
2477
+ else
2478
+ {
2479
+ out << nl << v << " = " << stream << ".readStringSeq();";
2480
+ }
2481
+ break;
2482
+ }
2483
+ case Builtin::KindObject:
2484
+ case Builtin::KindObjectProxy:
2485
+ case Builtin::KindLocalObject:
2486
+ {
2487
+ assert(false);
2488
+ break;
2489
+ }
2490
+ }
2491
+ }
2492
+ else
2493
+ {
2494
+ if(marshal)
2495
+ {
2496
+ out << nl << "if(" << v << " == null)";
2497
+ out << sb;
2498
+ out << nl << stream << ".writeSize(0);";
2499
+ out << eb;
2500
+ out << nl << "else";
2501
+ out << sb;
2502
+ out << nl << stream << ".writeSize(" << v << ".length);";
2503
+ out << nl << "for(int __i" << iter << " = 0; __i" << iter << " < " << v << ".length; __i" << iter
2504
+ << "++)";
2505
+ out << sb;
2506
+ ostringstream o;
2507
+ o << v << "[__i" << iter << "]";
2508
+ iter++;
2509
+ writeMarshalUnmarshalCode(out, package, type, OptionalNone, false, 0, o.str(), true, iter, false);
2510
+ out << eb;
2511
+ out << eb;
2512
+ }
2513
+ else
2514
+ {
2515
+ bool isObject = false;
2516
+ ClassDeclPtr cl = ClassDeclPtr::dynamicCast(origContent);
2517
+ if((b && b->kind() == Builtin::KindObject) || cl)
2518
+ {
2519
+ isObject = true;
2520
+ }
2521
+ out << nl << "final int __len" << iter << " = " << stream << ".readAndCheckSeqSize("
2522
+ << type->minWireSize() << ");";
2523
+ if(isObject)
2524
+ {
2525
+ if(b)
2526
+ {
2527
+ out << nl << "final String __type" << iter << " = Ice.ObjectImpl.ice_staticId();";
2528
+ }
2529
+ else
2530
+ {
2531
+ assert(cl);
2532
+ if(cl->isInterface())
2533
+ {
2534
+ out << nl << "final String __type" << iter << " = "
2535
+ << getAbsolute(cl, package, "_", "Disp") << ".ice_staticId();";
2536
+ }
2537
+ else
2538
+ {
2539
+ out << nl << "final String __type" << iter << " = " << origContentS << ".ice_staticId();";
2540
+ }
2541
+ }
2542
+ }
2543
+ //
2544
+ // We cannot allocate an array of a generic type, such as
2545
+ //
2546
+ // arr = new Map<String, String>[sz];
2547
+ //
2548
+ // Attempting to compile this code results in a "generic array creation" error
2549
+ // message. This problem can occur when the sequence's element type is a
2550
+ // dictionary, or when the element type is a nested sequence that uses a custom
2551
+ // mapping.
2552
+ //
2553
+ // The solution is to rewrite the code as follows:
2554
+ //
2555
+ // arr = (Map<String, String>[])new Map[sz];
2556
+ //
2557
+ // Unfortunately, this produces an unchecked warning during compilation.
2558
+ //
2559
+ // A simple test is to look for a "<" character in the content type, which
2560
+ // indicates the use of a generic type.
2561
+ //
2562
+ string::size_type pos = origContentS.find('<');
2563
+ if(pos != string::npos)
2564
+ {
2565
+ string nonGenericType = origContentS.substr(0, pos);
2566
+ out << nl << v << " = (" << origContentS << "[]";
2567
+ int d = depth;
2568
+ while(d--)
2569
+ {
2570
+ out << "[]";
2571
+ }
2572
+ out << ")new " << nonGenericType << "[__len" << iter << "]";
2573
+ }
2574
+ else
2575
+ {
2576
+ out << nl << v << " = new " << origContentS << "[__len" << iter << "]";
2577
+ }
2578
+ int d = depth;
2579
+ while(d--)
2580
+ {
2581
+ out << "[]";
2582
+ }
2583
+ out << ';';
2584
+ out << nl << "for(int __i" << iter << " = 0; __i" << iter << " < __len" << iter << "; __i" << iter
2585
+ << "++)";
2586
+ out << sb;
2587
+ ostringstream o;
2588
+ o << v << "[__i" << iter << "]";
2589
+ ostringstream patchParams;
2590
+ if(isObject)
2591
+ {
2592
+ patchParams << "new IceInternal.SequencePatcher(" << v << ", " << origContentS
2593
+ << ".class, __type" << iter << ", __i" << iter << ')';
2594
+ writeMarshalUnmarshalCode(out, package, type, OptionalNone, false, 0, o.str(), false, iter,
2595
+ false, StringList(), patchParams.str());
2596
+ }
2597
+ else
2598
+ {
2599
+ writeMarshalUnmarshalCode(out, package, type, OptionalNone, false, 0, o.str(), false, iter, false);
2600
+ }
2601
+ out << eb;
2602
+ iter++;
2603
+ }
2604
+ }
2605
+ }
2606
+ }
2607
+
2608
+ void
2609
+ Slice::JavaGenerator::writeStreamMarshalUnmarshalCode(Output& out,
2610
+ const string& package,
2611
+ const TypePtr& type,
2612
+ bool optional,
2613
+ int /*tag*/,
2614
+ const string& param,
2615
+ bool marshal,
2616
+ int& iter,
2617
+ bool holder,
2618
+ const StringList& metaData,
2619
+ const string& patchParams)
2620
+ {
2621
+ string stream = marshal ? "__outS" : "__inS";
2622
+ string v;
2623
+ if(holder && !optional)
2624
+ {
2625
+ v = param + ".value";
2626
+ }
2627
+ else
2628
+ {
2629
+ v = param;
2630
+ }
2631
+
2632
+ BuiltinPtr builtin = BuiltinPtr::dynamicCast(type);
2633
+ if(builtin)
2634
+ {
2635
+ switch(builtin->kind())
2636
+ {
2637
+ case Builtin::KindByte:
2638
+ {
2639
+ if(marshal)
2640
+ {
2641
+ out << nl << stream << ".writeByte(" << v << ");";
2642
+ }
2643
+ else
2644
+ {
2645
+ out << nl << v << " = " << stream << ".readByte();";
2646
+ }
2647
+ break;
2648
+ }
2649
+ case Builtin::KindBool:
2650
+ {
2651
+ if(marshal)
2652
+ {
2653
+ out << nl << stream << ".writeBool(" << v << ");";
2654
+ }
2655
+ else
2656
+ {
2657
+ out << nl << v << " = " << stream << ".readBool();";
2658
+ }
2659
+ break;
2660
+ }
2661
+ case Builtin::KindShort:
2662
+ {
2663
+ if(marshal)
2664
+ {
2665
+ out << nl << stream << ".writeShort(" << v << ");";
2666
+ }
2667
+ else
2668
+ {
2669
+ out << nl << v << " = " << stream << ".readShort();";
2670
+ }
2671
+ break;
2672
+ }
2673
+ case Builtin::KindInt:
2674
+ {
2675
+ if(marshal)
2676
+ {
2677
+ out << nl << stream << ".writeInt(" << v << ");";
2678
+ }
2679
+ else
2680
+ {
2681
+ out << nl << v << " = " << stream << ".readInt();";
2682
+ }
2683
+ break;
2684
+ }
2685
+ case Builtin::KindLong:
2686
+ {
2687
+ if(marshal)
2688
+ {
2689
+ out << nl << stream << ".writeLong(" << v << ");";
2690
+ }
2691
+ else
2692
+ {
2693
+ out << nl << v << " = " << stream << ".readLong();";
2694
+ }
2695
+ break;
2696
+ }
2697
+ case Builtin::KindFloat:
2698
+ {
2699
+ if(marshal)
2700
+ {
2701
+ out << nl << stream << ".writeFloat(" << v << ");";
2702
+ }
2703
+ else
2704
+ {
2705
+ out << nl << v << " = " << stream << ".readFloat();";
2706
+ }
2707
+ break;
2708
+ }
2709
+ case Builtin::KindDouble:
2710
+ {
2711
+ if(marshal)
2712
+ {
2713
+ out << nl << stream << ".writeDouble(" << v << ");";
2714
+ }
2715
+ else
2716
+ {
2717
+ out << nl << v << " = " << stream << ".readDouble();";
2718
+ }
2719
+ break;
2720
+ }
2721
+ case Builtin::KindString:
2722
+ {
2723
+ if(marshal)
2724
+ {
2725
+ out << nl << stream << ".writeString(" << v << ");";
2726
+ }
2727
+ else
2728
+ {
2729
+ out << nl << v << " = " << stream << ".readString();";
2730
+ }
2731
+ break;
2732
+ }
2733
+ case Builtin::KindObject:
2734
+ {
2735
+ if(marshal)
2736
+ {
2737
+ out << nl << stream << ".writeObject(" << v << ");";
2738
+ }
2739
+ else
2740
+ {
2741
+ if(holder && !optional)
2742
+ {
2743
+ out << nl << stream << ".readObject(" << param << ");";
2744
+ }
2745
+ else
2746
+ {
2747
+ if(patchParams.empty())
2748
+ {
2749
+ out << nl << stream << ".readObject(new Patcher());";
2750
+ }
2751
+ else
2752
+ {
2753
+ out << nl << stream << ".readObject(" << patchParams << ");";
2754
+ }
2755
+ }
2756
+ }
2757
+ break;
2758
+ }
2759
+ case Builtin::KindObjectProxy:
2760
+ {
2761
+ if(marshal)
2762
+ {
2763
+ if(optional)
2764
+ {
2765
+ out << nl << "int __pos = " << stream << ".startSize();";
2766
+ out << nl << stream << ".writeProxy(" << v << ");";
2767
+ out << nl << stream << ".endSize(__pos);";
2768
+ }
2769
+ else
2770
+ {
2771
+ out << nl << stream << ".writeProxy(" << v << ");";
2772
+ }
2773
+ }
2774
+ else
2775
+ {
2776
+ if(optional)
2777
+ {
2778
+ out << nl << stream << ".skip(4);";
2779
+ }
2780
+ out << nl << v << " = " << stream << ".readProxy();";
2781
+ }
2782
+ break;
2783
+ }
2784
+ case Builtin::KindLocalObject:
2785
+ {
2786
+ assert(false);
2787
+ break;
2788
+ }
2789
+ }
2790
+ return;
2791
+ }
2792
+
2793
+ ProxyPtr prx = ProxyPtr::dynamicCast(type);
2794
+ if(prx)
2795
+ {
2796
+ string typeS = typeToString(type, TypeModeIn, package);
2797
+ if(marshal)
2798
+ {
2799
+ if(optional)
2800
+ {
2801
+ out << nl << "int __pos = " << stream << ".startSize();";
2802
+ out << nl << typeS << "Helper.write(" << stream << ", " << v << ");";
2803
+ out << nl << stream << ".endSize(__pos);";
2804
+ }
2805
+ else
2806
+ {
2807
+ out << nl << typeS << "Helper.write(" << stream << ", " << v << ");";
2808
+ }
2809
+ }
2810
+ else
2811
+ {
2812
+ if(optional)
2813
+ {
2814
+ out << nl << stream << ".skip(4);";
2815
+ }
2816
+ out << nl << v << " = " << typeS << "Helper.read(" << stream << ");";
2817
+ }
2818
+ return;
2819
+ }
2820
+
2821
+ ClassDeclPtr cl = ClassDeclPtr::dynamicCast(type);
2822
+ if(cl)
2823
+ {
2824
+ if(marshal)
2825
+ {
2826
+ out << nl << stream << ".writeObject(" << v << ");";
2827
+ }
2828
+ else
2829
+ {
2830
+ if(holder && !optional)
2831
+ {
2832
+ out << nl << stream << ".readObject(" << param << ");";
2833
+ }
2834
+ else
2835
+ {
2836
+ if(patchParams.empty())
2837
+ {
2838
+ out << nl << stream << ".readObject(new Patcher());";
2839
+ }
2840
+ else
2841
+ {
2842
+ out << nl << stream << ".readObject(" << patchParams << ");";
2843
+ }
2844
+ }
2845
+ }
2846
+ return;
2847
+ }
2848
+
2849
+ StructPtr st = StructPtr::dynamicCast(type);
2850
+ if(st)
2851
+ {
2852
+ if(marshal)
2853
+ {
2854
+ if(optional)
2855
+ {
2856
+ if(st->isVariableLength())
2857
+ {
2858
+ out << nl << "int __pos = " << stream << ".startSize();";
2859
+ out << nl << v << ".ice_write(" << stream << ");";
2860
+ out << nl << stream << ".endSize(__pos);";
2861
+ }
2862
+ else
2863
+ {
2864
+ out << nl << stream << ".writeSize(" << st->minWireSize() << ");";
2865
+ out << nl << v << ".ice_write(" << stream << ");";
2866
+ }
2867
+ }
2868
+ else
2869
+ {
2870
+ out << nl << v << ".ice_write(" << stream << ");";
2871
+ }
2872
+ }
2873
+ else
2874
+ {
2875
+ string typeS = typeToString(type, TypeModeIn, package);
2876
+ if(optional)
2877
+ {
2878
+ if(st->isVariableLength())
2879
+ {
2880
+ out << nl << stream << ".skip(4);";
2881
+ }
2882
+ else
2883
+ {
2884
+ out << nl << stream << ".skipSize();";
2885
+ }
2886
+ out << nl << v << " = new " << typeS << "();";
2887
+ out << nl << v << ".ice_read(" << stream << ");";
2888
+ }
2889
+ else
2890
+ {
2891
+ out << nl << v << " = new " << typeS << "();";
2892
+ out << nl << v << ".ice_read(" << stream << ");";
2893
+ }
2894
+ }
2895
+ return;
2896
+ }
2897
+
2898
+ EnumPtr en = EnumPtr::dynamicCast(type);
2899
+ if(en)
2900
+ {
2901
+ if(marshal)
2902
+ {
2903
+ out << nl << v << ".ice_write(" << stream << ");";
2904
+ }
2905
+ else
2906
+ {
2907
+ string typeS = typeToString(type, TypeModeIn, package);
2908
+ out << nl << v << " = " << typeS << ".ice_read(" << stream << ");";
2909
+ }
2910
+ return;
2911
+ }
2912
+
2913
+ DictionaryPtr dict = DictionaryPtr::dynamicCast(type);
2914
+ if(dict)
2915
+ {
2916
+ if(optional)
2917
+ {
2918
+ string typeS = typeToString(type, TypeModeIn, package, metaData);
2919
+ TypePtr keyType = dict->keyType();
2920
+ TypePtr valueType = dict->valueType();
2921
+
2922
+ if(marshal)
2923
+ {
2924
+ if(keyType->isVariableLength() || valueType->isVariableLength())
2925
+ {
2926
+ out << nl << "int __pos = " << stream << ".startSize();";
2927
+ writeStreamDictionaryMarshalUnmarshalCode(out, package, dict, v, marshal, iter, true, metaData);
2928
+ out << nl << stream << ".endSize(__pos);";
2929
+ }
2930
+ else
2931
+ {
2932
+ const size_t wireSize = keyType->minWireSize() + valueType->minWireSize();
2933
+ out << nl << "final int __optSize = " << v << " == null ? 0 : " << v << ".size();";
2934
+ out << nl << stream << ".writeSize(__optSize > 254 ? __optSize * " << wireSize
2935
+ << " + 5 : __optSize * " << wireSize << " + 1);";
2936
+ writeStreamDictionaryMarshalUnmarshalCode(out, package, dict, v, marshal, iter, true, metaData);
2937
+ }
2938
+ }
2939
+ else
2940
+ {
2941
+ if(keyType->isVariableLength() || valueType->isVariableLength())
2942
+ {
2943
+ out << nl << stream << ".skip(4);";
2944
+ }
2945
+ else
2946
+ {
2947
+ out << nl << stream << ".skipSize();";
2948
+ }
2949
+
2950
+ writeStreamDictionaryMarshalUnmarshalCode(out, package, dict, v, marshal, iter, true, metaData);
2951
+ }
2952
+ }
2953
+ else
2954
+ {
2955
+ writeStreamDictionaryMarshalUnmarshalCode(out, package, dict, v, marshal, iter, true, metaData);
2956
+ }
2957
+ return;
2958
+ }
2959
+
2960
+ SequencePtr seq = SequencePtr::dynamicCast(type);
2961
+ if(seq)
2962
+ {
2963
+ if(optional)
2964
+ {
2965
+ string typeS = typeToString(type, TypeModeIn, package, metaData);
2966
+ TypePtr elemType = seq->type();
2967
+ BuiltinPtr elemBuiltin = BuiltinPtr::dynamicCast(elemType);
2968
+
2969
+ string ignore;
2970
+
2971
+ if(marshal)
2972
+ {
2973
+ if(elemType->isVariableLength())
2974
+ {
2975
+ out << nl << "int __pos = " << stream << ".startSize();";
2976
+ writeStreamSequenceMarshalUnmarshalCode(out, package, seq, v, marshal, iter, true, metaData);
2977
+ out << nl << stream << ".endSize(__pos);";
2978
+ }
2979
+ else if(findMetaData("java:type:", metaData, ignore) ||
2980
+ findMetaData("java:type:", seq->getMetaData(), ignore))
2981
+ {
2982
+ //
2983
+ // The sequence is an instance of java.util.List<E>, where E is a fixed-size type.
2984
+ // If the element type is bool or byte, we do NOT write an extra size.
2985
+ //
2986
+
2987
+ if(!elemBuiltin ||
2988
+ (elemBuiltin->kind() != Builtin::KindByte && elemBuiltin->kind() != Builtin::KindBool))
2989
+ {
2990
+ out << nl << "final int __optSize = " << v << " == null ? 0 : " << v << ".size();";
2991
+ const size_t wireSize = elemType->minWireSize();
2992
+
2993
+ if(wireSize > 1)
2994
+ {
2995
+ out << nl << stream << ".writeSize(__optSize > 254 ? __optSize * " << wireSize
2996
+ << " + 5 : __optSize * " << wireSize << " + 1);";
2997
+ }
2998
+ else
2999
+ {
3000
+ //
3001
+ // The element type could be a struct with a wire size of 1.
3002
+ //
3003
+ out << nl << stream << ".writeSize(__optSize > 254 ? __optSize + 5 : __optSize + 1);";
3004
+ }
3005
+ }
3006
+ writeStreamSequenceMarshalUnmarshalCode(out, package, seq, v, marshal, iter, true, metaData);
3007
+ }
3008
+ else if(findMetaData("java:protobuf:", seq->getMetaData(), ignore) ||
3009
+ findMetaData("java:serializable:", seq->getMetaData(), ignore))
3010
+ {
3011
+ //
3012
+ // This just writes a byte sequence.
3013
+ //
3014
+ writeStreamSequenceMarshalUnmarshalCode(out, package, seq, v, marshal, iter, true, metaData);
3015
+ }
3016
+ else
3017
+ {
3018
+ //
3019
+ // At this point we have a regular Java array of a fixed-size type.
3020
+ //
3021
+
3022
+ if(!elemBuiltin || (elemBuiltin->kind() != Builtin::KindByte &&
3023
+ elemBuiltin->kind() != Builtin::KindBool))
3024
+ {
3025
+ out << nl << "final int __optSize = " << v << " == null ? 0 : " << v << ".length;";
3026
+ const size_t wireSize = elemType->minWireSize();
3027
+
3028
+ if(wireSize > 1)
3029
+ {
3030
+ out << nl << stream << ".writeSize(__optSize > 254 ? __optSize * " << wireSize
3031
+ << " + 5 : __optSize * " << wireSize << " + 1);";
3032
+ }
3033
+ else
3034
+ {
3035
+ //
3036
+ // The element type could be a struct with a wire size of 1.
3037
+ //
3038
+ out << nl << stream << ".writeSize(__optSize > 254 ? __optSize + 5 : __optSize + 1);";
3039
+ }
3040
+ }
3041
+
3042
+ writeStreamSequenceMarshalUnmarshalCode(out, package, seq, v, marshal, iter, true, metaData);
3043
+ }
3044
+ }
3045
+ else
3046
+ {
3047
+ if(elemType->isVariableLength())
3048
+ {
3049
+ out << nl << stream << ".skip(4);";
3050
+ }
3051
+ else if(findMetaData("java:type:", metaData, ignore) ||
3052
+ findMetaData("java:type:", seq->getMetaData(), ignore))
3053
+ {
3054
+ //
3055
+ // The sequence is an instance of java.util.List<E>, where E is a fixed-size type.
3056
+ // If the element type is bool or byte, we do NOT write an extra size.
3057
+ //
3058
+
3059
+ if(!elemBuiltin ||
3060
+ (elemBuiltin->kind() != Builtin::KindByte && elemBuiltin->kind() != Builtin::KindBool))
3061
+ {
3062
+ out << nl << stream << ".skipSize();";
3063
+ }
3064
+ }
3065
+ else if(!findMetaData("java:protobuf:", seq->getMetaData(), ignore) &&
3066
+ !findMetaData("java:serializable:", seq->getMetaData(), ignore))
3067
+ {
3068
+ if(!elemBuiltin ||
3069
+ (elemBuiltin->kind() != Builtin::KindByte && elemBuiltin->kind() != Builtin::KindBool))
3070
+ {
3071
+ out << nl << stream << ".skipSize();";
3072
+ }
3073
+ }
3074
+
3075
+ writeStreamSequenceMarshalUnmarshalCode(out, package, seq, v, marshal, iter, true, metaData);
3076
+ }
3077
+ }
3078
+ else
3079
+ {
3080
+ writeStreamSequenceMarshalUnmarshalCode(out, package, seq, v, marshal, iter, true, metaData);
3081
+ }
3082
+ return;
3083
+ }
3084
+
3085
+ ConstructedPtr constructed = ConstructedPtr::dynamicCast(type);
3086
+ assert(constructed);
3087
+ string typeS = getAbsolute(constructed, package);
3088
+ if(marshal)
3089
+ {
3090
+ out << nl << typeS << "Helper.write(" << stream << ", " << v << ");";
3091
+ }
3092
+ else
3093
+ {
3094
+ out << nl << v << " = " << typeS << "Helper.read(" << stream << ");";
3095
+ }
3096
+ }
3097
+
3098
+ void
3099
+ Slice::JavaGenerator::writeStreamDictionaryMarshalUnmarshalCode(Output& out,
3100
+ const string& package,
3101
+ const DictionaryPtr& dict,
3102
+ const string& param,
3103
+ bool marshal,
3104
+ int& iter,
3105
+ bool useHelper,
3106
+ const StringList& metaData)
3107
+ {
3108
+ string stream = marshal ? "__outS" : "__inS";
3109
+ string v = param;
3110
+
3111
+ //
3112
+ // We have to determine whether it's possible to use the
3113
+ // type's generated helper class for this marshal/unmarshal
3114
+ // task. Since the user may have specified a custom type in
3115
+ // metadata, it's possible that the helper class is not
3116
+ // compatible and therefore we'll need to generate the code
3117
+ // in-line instead.
3118
+ //
3119
+ // Specifically, there may be "local" metadata (i.e., from
3120
+ // a data member or parameter definition) that overrides the
3121
+ // original type. We'll compare the mapped types with and
3122
+ // without local metadata to determine whether we can use
3123
+ // the helper.
3124
+ //
3125
+ string instanceType, formalType;
3126
+ getDictionaryTypes(dict, "", metaData, instanceType, formalType);
3127
+ string origInstanceType, origFormalType;
3128
+ getDictionaryTypes(dict, "", StringList(), origInstanceType, origFormalType);
3129
+ if((formalType != origFormalType) || (!marshal && instanceType != origInstanceType))
3130
+ {
3131
+ useHelper = false;
3132
+ }
3133
+
3134
+ //
3135
+ // If we can use the helper, it's easy.
3136
+ //
3137
+ if(useHelper)
3138
+ {
3139
+ string typeS = getAbsolute(dict, package);
3140
+ if(marshal)
3141
+ {
3142
+ out << nl << typeS << "Helper.write(" << stream << ", " << v << ");";
3143
+ }
3144
+ else
3145
+ {
3146
+ out << nl << v << " = " << typeS << "Helper.read(" << stream << ");";
3147
+ }
3148
+ return;
3149
+ }
3150
+
3151
+ TypePtr key = dict->keyType();
3152
+ TypePtr value = dict->valueType();
3153
+
3154
+ string keyS = typeToString(key, TypeModeIn, package);
3155
+ string valueS = typeToString(value, TypeModeIn, package);
3156
+
3157
+ ostringstream o;
3158
+ o << iter;
3159
+ string iterS = o.str();
3160
+ iter++;
3161
+
3162
+ if(marshal)
3163
+ {
3164
+ out << nl << "if(" << v << " == null)";
3165
+ out << sb;
3166
+ out << nl << "__outS.writeSize(0);";
3167
+ out << eb;
3168
+ out << nl << "else";
3169
+ out << sb;
3170
+ out << nl << "__outS.writeSize(" << v << ".size());";
3171
+ string keyObjectS = typeToObjectString(key, TypeModeIn, package);
3172
+ string valueObjectS = typeToObjectString(value, TypeModeIn, package);
3173
+ out << nl << "for(java.util.Map.Entry<" << keyObjectS << ", " << valueObjectS << "> __e : " << v
3174
+ << ".entrySet())";
3175
+ out << sb;
3176
+ for(int i = 0; i < 2; i++)
3177
+ {
3178
+ string arg;
3179
+ TypePtr type;
3180
+ if(i == 0)
3181
+ {
3182
+ arg = "__e.getKey()";
3183
+ type = key;
3184
+ }
3185
+ else
3186
+ {
3187
+ arg = "__e.getValue()";
3188
+ type = value;
3189
+ }
3190
+ writeStreamMarshalUnmarshalCode(out, package, type, false, 0, arg, true, iter, false);
3191
+ }
3192
+ out << eb;
3193
+ out << eb;
3194
+ }
3195
+ else
3196
+ {
3197
+ out << nl << v << " = new " << instanceType << "();";
3198
+ out << nl << "int __sz" << iterS << " = __inS.readSize();";
3199
+ out << nl << "for(int __i" << iterS << " = 0; __i" << iterS << " < __sz" << iterS << "; __i" << iterS << "++)";
3200
+ out << sb;
3201
+ for(int i = 0; i < 2; i++)
3202
+ {
3203
+ string arg;
3204
+ TypePtr type;
3205
+ string typeS;
3206
+ if(i == 0)
3207
+ {
3208
+ arg = "__key";
3209
+ type = key;
3210
+ typeS = keyS;
3211
+ }
3212
+ else
3213
+ {
3214
+ arg = "__value";
3215
+ type = value;
3216
+ typeS = valueS;
3217
+ }
3218
+
3219
+ BuiltinPtr b = BuiltinPtr::dynamicCast(type);
3220
+ string s = typeToString(type, TypeModeIn, package);
3221
+ if(ClassDeclPtr::dynamicCast(type) || (b && b->kind() == Builtin::KindObject))
3222
+ {
3223
+ string keyTypeStr = typeToObjectString(key, TypeModeIn, package);
3224
+ string valueTypeStr = typeToObjectString(value, TypeModeIn, package);
3225
+ writeStreamMarshalUnmarshalCode(out, package, type, false, 0, arg, false, iter, false,
3226
+ StringList(), "new IceInternal.DictionaryPatcher<" + keyTypeStr +
3227
+ ", " + valueTypeStr + ">(" + v + ", " + s + ".class, \"" +
3228
+ type->typeId() + "\", __key)");
3229
+ }
3230
+ else
3231
+ {
3232
+ out << nl << s << ' ' << arg << ';';
3233
+ writeStreamMarshalUnmarshalCode(out, package, type, false, 0, arg, false, iter, false);
3234
+ }
3235
+ }
3236
+ BuiltinPtr builtin = BuiltinPtr::dynamicCast(value);
3237
+ if(!(builtin && builtin->kind() == Builtin::KindObject) && !ClassDeclPtr::dynamicCast(value))
3238
+ {
3239
+ out << nl << "" << v << ".put(__key, __value);";
3240
+ }
3241
+ out << eb;
3242
+ }
3243
+ }
3244
+
3245
+ void
3246
+ Slice::JavaGenerator::writeStreamSequenceMarshalUnmarshalCode(Output& out,
3247
+ const string& package,
3248
+ const SequencePtr& seq,
3249
+ const string& param,
3250
+ bool marshal,
3251
+ int& iter,
3252
+ bool useHelper,
3253
+ const StringList& metaData)
3254
+ {
3255
+ string stream = marshal ? "__outS" : "__inS";
3256
+ string v = param;
3257
+
3258
+ //
3259
+ // If the sequence is a byte sequence, check if there's the serializable or protobuf metadata to
3260
+ // get rid of these two easy cases first.
3261
+ //
3262
+ BuiltinPtr builtin = BuiltinPtr::dynamicCast(seq->type());
3263
+ if(builtin && builtin->kind() == Builtin::KindByte)
3264
+ {
3265
+ string meta;
3266
+ static const string protobuf = "java:protobuf:";
3267
+ static const string serializable = "java:serializable:";
3268
+ if(seq->findMetaData(serializable, meta))
3269
+ {
3270
+ if(marshal)
3271
+ {
3272
+ out << nl << stream << ".writeSerializable(" << v << ");";
3273
+ }
3274
+ else
3275
+ {
3276
+ string type = typeToString(seq, TypeModeIn, package);
3277
+ out << nl << v << " = (" << type << ")" << stream << ".readSerializable();";
3278
+ }
3279
+ return;
3280
+ }
3281
+ else if(seq->findMetaData(protobuf, meta))
3282
+ {
3283
+ if(marshal)
3284
+ {
3285
+ out << nl << "if(!" << v << ".isInitialized())";
3286
+ out << sb;
3287
+ out << nl << "throw new Ice.MarshalException(\"type not fully initialized\");";
3288
+ out << eb;
3289
+ out << nl << stream << ".writeByteSeq(" << v << ".toByteArray());";
3290
+ }
3291
+ else
3292
+ {
3293
+ string type = meta.substr(protobuf.size());
3294
+ out << nl << "try";
3295
+ out << sb;
3296
+ out << nl << v << " = " << type << ".parseFrom(" << stream << ".readByteSeq());";
3297
+ out << eb;
3298
+ out << nl << "catch(com.google.protobuf.InvalidProtocolBufferException __ex)";
3299
+ out << sb;
3300
+ out << nl << "Ice.MarshalException __mex = new Ice.MarshalException();";
3301
+ out << nl << "__mex.initCause(__ex);";
3302
+ out << nl << "throw __mex;";
3303
+ out << eb;
3304
+ }
3305
+ return;
3306
+ }
3307
+ }
3308
+
3309
+ if(builtin &&
3310
+ (builtin->kind() == Builtin::KindByte || builtin->kind() == Builtin::KindShort ||
3311
+ builtin->kind() == Builtin::KindInt || builtin->kind() == Builtin::KindLong ||
3312
+ builtin->kind() == Builtin::KindFloat || builtin->kind() == Builtin::KindDouble))
3313
+ {
3314
+ string meta;
3315
+ static const string bytebuffer = "java:buffer";
3316
+ if(seq->findMetaData(bytebuffer, meta) || findMetaData(bytebuffer, metaData, meta))
3317
+ {
3318
+ switch(builtin->kind())
3319
+ {
3320
+ case Builtin::KindByte:
3321
+ {
3322
+ if(marshal)
3323
+ {
3324
+ out << nl << stream << ".writeByteBuffer(" << v << ");";
3325
+ }
3326
+ else
3327
+ {
3328
+ out << nl << v << " = " << stream << ".readByteBuffer();";
3329
+ }
3330
+ break;
3331
+ }
3332
+ case Builtin::KindShort:
3333
+ {
3334
+ if(marshal)
3335
+ {
3336
+ out << nl << stream << ".writeShortBuffer(" << v << ");";
3337
+ }
3338
+ else
3339
+ {
3340
+ out << nl << v << " = " << stream << ".readShortBuffer();";
3341
+ }
3342
+ break;
3343
+ }
3344
+ case Builtin::KindInt:
3345
+ {
3346
+ if(marshal)
3347
+ {
3348
+ out << nl << stream << ".writeIntBuffer(" << v << ");";
3349
+ }
3350
+ else
3351
+ {
3352
+ out << nl << v << " = " << stream << ".readIntBuffer();";
3353
+ }
3354
+ break;
3355
+ }
3356
+ case Builtin::KindLong:
3357
+ {
3358
+ if(marshal)
3359
+ {
3360
+ out << nl << stream << ".writeLongBuffer(" << v << ");";
3361
+ }
3362
+ else
3363
+ {
3364
+ out << nl << v << " = " << stream << ".readLongBuffer();";
3365
+ }
3366
+ break;
3367
+ }
3368
+ case Builtin::KindFloat:
3369
+ {
3370
+ if(marshal)
3371
+ {
3372
+ out << nl << stream << ".writeFloatBuffer(" << v << ");";
3373
+ }
3374
+ else
3375
+ {
3376
+ out << nl << v << " = " << stream << ".readFloatBuffer();";
3377
+ }
3378
+ break;
3379
+ }
3380
+ case Builtin::KindDouble:
3381
+ {
3382
+ if(marshal)
3383
+ {
3384
+ out << nl << stream << ".writeDoubleBuffer(" << v << ");";
3385
+ }
3386
+ else
3387
+ {
3388
+ out << nl << v << " = " << stream << ".readDoubleBuffer();";
3389
+ }
3390
+ break;
3391
+ }
3392
+ case Builtin::KindBool:
3393
+ case Builtin::KindString:
3394
+ case Builtin::KindObject:
3395
+ case Builtin::KindObjectProxy:
3396
+ case Builtin::KindLocalObject:
3397
+ {
3398
+ assert(false);
3399
+ break;
3400
+ }
3401
+ }
3402
+ return;
3403
+ }
3404
+ }
3405
+
3406
+ //
3407
+ // We have to determine whether it's possible to use the
3408
+ // type's generated helper class for this marshal/unmarshal
3409
+ // task. Since the user may have specified a custom type in
3410
+ // metadata, it's possible that the helper class is not
3411
+ // compatible and therefore we'll need to generate the code
3412
+ // in-line instead.
3413
+ //
3414
+ // Specifically, there may be "local" metadata (i.e., from
3415
+ // a data member or parameter definition) that overrides the
3416
+ // original type. We'll compare the mapped types with and
3417
+ // without local metadata to determine whether we can use
3418
+ // the helper.
3419
+ //
3420
+ string instanceType, formalType;
3421
+ bool customType = getSequenceTypes(seq, "", metaData, instanceType, formalType);
3422
+ string origInstanceType, origFormalType;
3423
+ getSequenceTypes(seq, "", StringList(), origInstanceType, origFormalType);
3424
+ if((formalType != origFormalType) || (!marshal && instanceType != origInstanceType))
3425
+ {
3426
+ useHelper = false;
3427
+ }
3428
+
3429
+ //
3430
+ // If we can use the helper, it's easy.
3431
+ //
3432
+ if(useHelper)
3433
+ {
3434
+ string typeS = getAbsolute(seq, package);
3435
+ if(marshal)
3436
+ {
3437
+ out << nl << typeS << "Helper.write(" << stream << ", " << v << ");";
3438
+ }
3439
+ else
3440
+ {
3441
+ out << nl << v << " = " << typeS << "Helper.read(" << stream << ");";
3442
+ }
3443
+ return;
3444
+ }
3445
+
3446
+ //
3447
+ // Determine sequence depth
3448
+ //
3449
+ int depth = 0;
3450
+ TypePtr origContent = seq->type();
3451
+ SequencePtr s = SequencePtr::dynamicCast(origContent);
3452
+ while(s)
3453
+ {
3454
+ //
3455
+ // Stop if the inner sequence type has a custom, serializable or protobuf type.
3456
+ //
3457
+ if(hasTypeMetaData(s))
3458
+ {
3459
+ break;
3460
+ }
3461
+ depth++;
3462
+ origContent = s->type();
3463
+ s = SequencePtr::dynamicCast(origContent);
3464
+ }
3465
+ string origContentS = typeToString(origContent, TypeModeIn, package);
3466
+
3467
+ TypePtr type = seq->type();
3468
+
3469
+ if(customType)
3470
+ {
3471
+ //
3472
+ // Marshal/unmarshal a custom sequence type.
3473
+ //
3474
+ BuiltinPtr b = BuiltinPtr::dynamicCast(type);
3475
+ string typeS = getAbsolute(seq, package);
3476
+ ostringstream o;
3477
+ o << origContentS;
3478
+ int d = depth;
3479
+ while(d--)
3480
+ {
3481
+ o << "[]";
3482
+ }
3483
+ string cont = o.str();
3484
+ if(marshal)
3485
+ {
3486
+ out << nl << "if(" << v << " == null)";
3487
+ out << sb;
3488
+ out << nl << stream << ".writeSize(0);";
3489
+ out << eb;
3490
+ out << nl << "else";
3491
+ out << sb;
3492
+ out << nl << stream << ".writeSize(" << v << ".size());";
3493
+ string typeS = typeToString(type, TypeModeIn, package);
3494
+ out << nl << "for(" << typeS << " __elem : " << v << ')';
3495
+ out << sb;
3496
+ writeStreamMarshalUnmarshalCode(out, package, type, false, 0, "__elem", true, iter, false);
3497
+ out << eb;
3498
+ out << eb; // else
3499
+ }
3500
+ else
3501
+ {
3502
+ bool isObject = false;
3503
+ ClassDeclPtr cl = ClassDeclPtr::dynamicCast(type);
3504
+ if((b && b->kind() == Builtin::KindObject) || cl)
3505
+ {
3506
+ isObject = true;
3507
+ }
3508
+ out << nl << v << " = new " << instanceType << "();";
3509
+ out << nl << "final int __len" << iter << " = " << stream << ".readAndCheckSeqSize(" << type->minWireSize()
3510
+ << ");";
3511
+ if(isObject)
3512
+ {
3513
+ if(b)
3514
+ {
3515
+ out << nl << "final String __type" << iter << " = Ice.ObjectImpl.ice_staticId();";
3516
+ }
3517
+ else
3518
+ {
3519
+ assert(cl);
3520
+ if(cl->isInterface())
3521
+ {
3522
+ out << nl << "final String __type" << iter << " = "
3523
+ << getAbsolute(cl, package, "_", "Disp") << ".ice_staticId();";
3524
+ }
3525
+ else
3526
+ {
3527
+ out << nl << "final String __type" << iter << " = " << origContentS << ".ice_staticId();";
3528
+ }
3529
+ }
3530
+ }
3531
+ out << nl << "for(int __i" << iter << " = 0; __i" << iter << " < __len" << iter << "; __i" << iter
3532
+ << "++)";
3533
+ out << sb;
3534
+ if(isObject)
3535
+ {
3536
+ //
3537
+ // Add a null value to the list as a placeholder for the element.
3538
+ //
3539
+ out << nl << v << ".add(null);";
3540
+ ostringstream patchParams;
3541
+ patchParams << "new IceInternal.ListPatcher<" << origContentS << ">(" << v << ", " << origContentS
3542
+ << ".class, __type" << iter << ", __i" << iter << ')';
3543
+ writeStreamMarshalUnmarshalCode(out, package, type, false, 0, "__elem", false, iter, false,
3544
+ StringList(), patchParams.str());
3545
+ }
3546
+ else
3547
+ {
3548
+ out << nl << cont << " __elem;";
3549
+ writeStreamMarshalUnmarshalCode(out, package, type, false, 0, "__elem", false, iter, false);
3550
+ }
3551
+ if(!isObject)
3552
+ {
3553
+ out << nl << v << ".add(__elem);";
3554
+ }
3555
+ out << eb;
3556
+ iter++;
3557
+ }
3558
+ }
3559
+ else
3560
+ {
3561
+ BuiltinPtr b = BuiltinPtr::dynamicCast(type);
3562
+ if(b && b->kind() != Builtin::KindObject && b->kind() != Builtin::KindObjectProxy)
3563
+ {
3564
+ switch(b->kind())
3565
+ {
3566
+ case Builtin::KindByte:
3567
+ {
3568
+ if(marshal)
3569
+ {
3570
+ out << nl << stream << ".writeByteSeq(" << v << ");";
3571
+ }
3572
+ else
3573
+ {
3574
+ out << nl << v << " = " << stream << ".readByteSeq();";
3575
+ }
3576
+ break;
3577
+ }
3578
+ case Builtin::KindBool:
3579
+ {
3580
+ if(marshal)
3581
+ {
3582
+ out << nl << stream << ".writeBoolSeq(" << v << ");";
3583
+ }
3584
+ else
3585
+ {
3586
+ out << nl << v << " = " << stream << ".readBoolSeq();";
3587
+ }
3588
+ break;
3589
+ }
3590
+ case Builtin::KindShort:
3591
+ {
3592
+ if(marshal)
3593
+ {
3594
+ out << nl << stream << ".writeShortSeq(" << v << ");";
3595
+ }
3596
+ else
3597
+ {
3598
+ out << nl << v << " = " << stream << ".readShortSeq();";
3599
+ }
3600
+ break;
3601
+ }
3602
+ case Builtin::KindInt:
3603
+ {
3604
+ if(marshal)
3605
+ {
3606
+ out << nl << stream << ".writeIntSeq(" << v << ");";
3607
+ }
3608
+ else
3609
+ {
3610
+ out << nl << v << " = " << stream << ".readIntSeq();";
3611
+ }
3612
+ break;
3613
+ }
3614
+ case Builtin::KindLong:
3615
+ {
3616
+ if(marshal)
3617
+ {
3618
+ out << nl << stream << ".writeLongSeq(" << v << ");";
3619
+ }
3620
+ else
3621
+ {
3622
+ out << nl << v << " = " << stream << ".readLongSeq();";
3623
+ }
3624
+ break;
3625
+ }
3626
+ case Builtin::KindFloat:
3627
+ {
3628
+ if(marshal)
3629
+ {
3630
+ out << nl << stream << ".writeFloatSeq(" << v << ");";
3631
+ }
3632
+ else
3633
+ {
3634
+ out << nl << v << " = " << stream << ".readFloatSeq();";
3635
+ }
3636
+ break;
3637
+ }
3638
+ case Builtin::KindDouble:
3639
+ {
3640
+ if(marshal)
3641
+ {
3642
+ out << nl << stream << ".writeDoubleSeq(" << v << ");";
3643
+ }
3644
+ else
3645
+ {
3646
+ out << nl << v << " = " << stream << ".readDoubleSeq();";
3647
+ }
3648
+ break;
3649
+ }
3650
+ case Builtin::KindString:
3651
+ {
3652
+ if(marshal)
3653
+ {
3654
+ out << nl << stream << ".writeStringSeq(" << v << ");";
3655
+ }
3656
+ else
3657
+ {
3658
+ out << nl << v << " = " << stream << ".readStringSeq();";
3659
+ }
3660
+ break;
3661
+ }
3662
+ case Builtin::KindObject:
3663
+ case Builtin::KindObjectProxy:
3664
+ case Builtin::KindLocalObject:
3665
+ {
3666
+ assert(false);
3667
+ break;
3668
+ }
3669
+ }
3670
+ }
3671
+ else
3672
+ {
3673
+ if(marshal)
3674
+ {
3675
+ out << nl << "if(" << v << " == null)";
3676
+ out << sb;
3677
+ out << nl << stream << ".writeSize(0);";
3678
+ out << eb;
3679
+ out << nl << "else";
3680
+ out << sb;
3681
+ out << nl << stream << ".writeSize(" << v << ".length);";
3682
+ out << nl << "for(int __i" << iter << " = 0; __i" << iter << " < " << v << ".length; __i" << iter
3683
+ << "++)";
3684
+ out << sb;
3685
+ ostringstream o;
3686
+ o << v << "[__i" << iter << "]";
3687
+ iter++;
3688
+ writeStreamMarshalUnmarshalCode(out, package, type, false, 0, o.str(), true, iter, false);
3689
+ out << eb;
3690
+ out << eb;
3691
+ }
3692
+ else
3693
+ {
3694
+ bool isObject = false;
3695
+ ClassDeclPtr cl = ClassDeclPtr::dynamicCast(origContent);
3696
+ if((b && b->kind() == Builtin::KindObject) || cl)
3697
+ {
3698
+ isObject = true;
3699
+ }
3700
+ out << nl << "final int __len" << iter << " = " << stream << ".readAndCheckSeqSize("
3701
+ << type->minWireSize() << ");";
3702
+ if(isObject)
3703
+ {
3704
+ if(b)
3705
+ {
3706
+ out << nl << "final String __type" << iter << " = Ice.ObjectImpl.ice_staticId();";
3707
+ }
3708
+ else
3709
+ {
3710
+ assert(cl);
3711
+ if(cl->isInterface())
3712
+ {
3713
+ out << nl << "final String __type" << iter << " = "
3714
+ << getAbsolute(cl, package, "_", "Disp") << ".ice_staticId();";
3715
+ }
3716
+ else
3717
+ {
3718
+ out << nl << "final String __type" << iter << " = " << origContentS << ".ice_staticId();";
3719
+ }
3720
+ }
3721
+ }
3722
+ //
3723
+ // We cannot allocate an array of a generic type, such as
3724
+ //
3725
+ // arr = new Map<String, String>[sz];
3726
+ //
3727
+ // Attempting to compile this code results in a "generic array creation" error
3728
+ // message. This problem can occur when the sequence's element type is a
3729
+ // dictionary, or when the element type is a nested sequence that uses a custom
3730
+ // mapping.
3731
+ //
3732
+ // The solution is to rewrite the code as follows:
3733
+ //
3734
+ // arr = (Map<String, String>[])new Map[sz];
3735
+ //
3736
+ // Unfortunately, this produces an unchecked warning during compilation.
3737
+ //
3738
+ // A simple test is to look for a "<" character in the content type, which
3739
+ // indicates the use of a generic type.
3740
+ //
3741
+ string::size_type pos = origContentS.find('<');
3742
+ if(pos != string::npos)
3743
+ {
3744
+ string nonGenericType = origContentS.substr(0, pos);
3745
+ out << nl << v << " = (" << origContentS << "[]";
3746
+ int d = depth;
3747
+ while(d--)
3748
+ {
3749
+ out << "[]";
3750
+ }
3751
+ out << ")new " << nonGenericType << "[__len" << iter << "]";
3752
+ }
3753
+ else
3754
+ {
3755
+ out << nl << v << " = new " << origContentS << "[__len" << iter << "]";
3756
+ }
3757
+ int d = depth;
3758
+ while(d--)
3759
+ {
3760
+ out << "[]";
3761
+ }
3762
+ out << ';';
3763
+ out << nl << "for(int __i" << iter << " = 0; __i" << iter << " < __len" << iter << "; __i" << iter
3764
+ << "++)";
3765
+ out << sb;
3766
+ ostringstream o;
3767
+ o << v << "[__i" << iter << "]";
3768
+ ostringstream patchParams;
3769
+ if(isObject)
3770
+ {
3771
+ patchParams << "new IceInternal.SequencePatcher(" << v << ", " << origContentS
3772
+ << ".class, __type" << iter << ", __i" << iter << ')';
3773
+ writeStreamMarshalUnmarshalCode(out, package, type, false, 0, o.str(), false, iter, false,
3774
+ StringList(), patchParams.str());
3775
+ }
3776
+ else
3777
+ {
3778
+ writeStreamMarshalUnmarshalCode(out, package, type, false, 0, o.str(), false, iter, false);
3779
+ }
3780
+ out << eb;
3781
+ iter++;
3782
+ }
3783
+ }
3784
+ }
3785
+ }
3786
+
3787
+ bool
3788
+ Slice::JavaGenerator::findMetaData(const string& prefix, const StringList& metaData, string& value)
3789
+ {
3790
+ for(StringList::const_iterator q = metaData.begin(); q != metaData.end(); ++q)
3791
+ {
3792
+ if(q->find(prefix) == 0)
3793
+ {
3794
+ value = *q;
3795
+ return true;
3796
+ }
3797
+ }
3798
+
3799
+ return false;
3800
+ }
3801
+
3802
+ bool
3803
+ Slice::JavaGenerator::getTypeMetaData(const StringList& metaData, string& instanceType, string& formalType)
3804
+ {
3805
+ //
3806
+ // Extract the instance type and an optional formal type.
3807
+ // The correct syntax is "java:type:instance-type[:formal-type]".
3808
+ //
3809
+ static const string prefix = "java:type:";
3810
+ string directive;
3811
+ if(findMetaData(prefix, metaData, directive))
3812
+ {
3813
+ string::size_type pos = directive.find(':', prefix.size());
3814
+ if(pos != string::npos)
3815
+ {
3816
+ instanceType = directive.substr(prefix.size(), pos - prefix.size());
3817
+ formalType = directive.substr(pos + 1);
3818
+ }
3819
+ else
3820
+ {
3821
+ instanceType = directive.substr(prefix.size());
3822
+ formalType.clear();
3823
+ }
3824
+ return true;
3825
+ }
3826
+
3827
+ return false;
3828
+ }
3829
+
3830
+ bool
3831
+ Slice::JavaGenerator::hasTypeMetaData(const TypePtr& type, const StringList& localMetaData)
3832
+ {
3833
+ ContainedPtr cont = ContainedPtr::dynamicCast(type);
3834
+ if(cont)
3835
+ {
3836
+ static const string prefix = "java:type:";
3837
+ string directive;
3838
+
3839
+ if(findMetaData(prefix, localMetaData, directive))
3840
+ {
3841
+ return true;
3842
+ }
3843
+
3844
+ StringList metaData = cont->getMetaData();
3845
+
3846
+ if(findMetaData(prefix, metaData, directive))
3847
+ {
3848
+ return true;
3849
+ }
3850
+
3851
+ if(findMetaData("java:protobuf:", metaData, directive) ||
3852
+ findMetaData("java:serializable:", metaData, directive))
3853
+ {
3854
+ SequencePtr seq = SequencePtr::dynamicCast(cont);
3855
+ if(seq)
3856
+ {
3857
+ BuiltinPtr builtin = BuiltinPtr::dynamicCast(seq->type());
3858
+ if(builtin && builtin->kind() == Builtin::KindByte)
3859
+ {
3860
+ return true;
3861
+ }
3862
+ }
3863
+ }
3864
+
3865
+ if(findMetaData("java:buffer", localMetaData, directive))
3866
+ {
3867
+ SequencePtr seq = SequencePtr::dynamicCast(cont);
3868
+ if(seq)
3869
+ {
3870
+ BuiltinPtr builtin = BuiltinPtr::dynamicCast(seq->type());
3871
+ if(builtin &&
3872
+ (builtin->kind() == Builtin::KindByte || builtin->kind() == Builtin::KindShort ||
3873
+ builtin->kind() == Builtin::KindInt || builtin->kind() == Builtin::KindLong ||
3874
+ builtin->kind() == Builtin::KindFloat || builtin->kind() == Builtin::KindDouble))
3875
+ {
3876
+ return true;
3877
+ }
3878
+ }
3879
+ }
3880
+ }
3881
+
3882
+ return false;
3883
+ }
3884
+
3885
+ bool
3886
+ Slice::JavaGenerator::getDictionaryTypes(const DictionaryPtr& dict,
3887
+ const string& package,
3888
+ const StringList& metaData,
3889
+ string& instanceType,
3890
+ string& formalType) const
3891
+ {
3892
+ bool customType = false;
3893
+
3894
+ //
3895
+ // Collect metadata for a custom type.
3896
+ //
3897
+ string ct, at;
3898
+ customType = getTypeMetaData(metaData, ct, at);
3899
+ if(!customType)
3900
+ {
3901
+ customType = getTypeMetaData(dict->getMetaData(), ct, at);
3902
+ }
3903
+
3904
+ //
3905
+ // Get the types of the key and value.
3906
+ //
3907
+ string keyTypeStr = typeToObjectString(dict->keyType(), TypeModeIn, package);
3908
+ string valueTypeStr = typeToObjectString(dict->valueType(), TypeModeIn, package);
3909
+
3910
+ //
3911
+ // Handle a custom type.
3912
+ //
3913
+ if(customType)
3914
+ {
3915
+ assert(!ct.empty());
3916
+ instanceType = ct;
3917
+ formalType = at;
3918
+ }
3919
+
3920
+ //
3921
+ // Return a default type for the platform.
3922
+ //
3923
+ if(instanceType.empty())
3924
+ {
3925
+ instanceType = "java.util.HashMap<" + keyTypeStr + ", " + valueTypeStr + ">";
3926
+ }
3927
+
3928
+ //
3929
+ // If a formal type is not defined, we use the instance type as the default.
3930
+ // If instead we chose a default formal type, such as Map<K, V>, then we
3931
+ // might inadvertently generate uncompilable code. The Java5 compiler does not
3932
+ // allow polymorphic assignment between generic types if it can weaken the
3933
+ // compile-time type safety rules.
3934
+ //
3935
+ if(formalType.empty())
3936
+ {
3937
+ formalType = "java.util.Map<" + keyTypeStr + ", " + valueTypeStr + ">";
3938
+ }
3939
+
3940
+ return customType;
3941
+ }
3942
+
3943
+ bool
3944
+ Slice::JavaGenerator::getSequenceTypes(const SequencePtr& seq,
3945
+ const string& package,
3946
+ const StringList& metaData,
3947
+ string& instanceType,
3948
+ string& formalType) const
3949
+ {
3950
+ bool customType = false;
3951
+
3952
+ //
3953
+ // Collect metadata for a custom type.
3954
+ //
3955
+ string ct, at;
3956
+ customType = getTypeMetaData(metaData, ct, at);
3957
+ if(!customType)
3958
+ {
3959
+ customType = getTypeMetaData(seq->getMetaData(), ct, at);
3960
+ }
3961
+
3962
+ //
3963
+ // Get the inner type.
3964
+ //
3965
+ string typeStr = typeToObjectString(seq->type(), TypeModeIn, package);
3966
+
3967
+ //
3968
+ // Handle a custom type.
3969
+ //
3970
+ if(customType)
3971
+ {
3972
+ assert(!ct.empty());
3973
+ instanceType = ct;
3974
+
3975
+ if(!at.empty())
3976
+ {
3977
+ formalType = at;
3978
+ }
3979
+ else
3980
+ {
3981
+ //
3982
+ // If a formal type is not defined, we use the instance type as the default.
3983
+ // If instead we chose a default formal type, such as List<T>, then we
3984
+ // might inadvertently generate uncompilable code. The Java5 compiler does not
3985
+ // allow polymorphic assignment between generic types if it can weaken the
3986
+ // compile-time type safety rules.
3987
+ //
3988
+ formalType = "java.util.List<" + typeStr + ">";
3989
+ }
3990
+ }
3991
+
3992
+ //
3993
+ // The default mapping is a native array.
3994
+ //
3995
+ if(instanceType.empty())
3996
+ {
3997
+ instanceType = formalType = typeToString(seq->type(), TypeModeIn, package) + "[]";
3998
+ }
3999
+
4000
+ return customType;
4001
+ }
4002
+
4003
+ JavaOutput*
4004
+ Slice::JavaGenerator::createOutput()
4005
+ {
4006
+ return new JavaOutput;
4007
+ }
4008
+
4009
+ void
4010
+ Slice::JavaGenerator::validateMetaData(const UnitPtr& u)
4011
+ {
4012
+ MetaDataVisitor visitor;
4013
+ u->visit(&visitor, true);
4014
+ }
4015
+
4016
+ bool
4017
+ Slice::JavaGenerator::MetaDataVisitor::visitUnitStart(const UnitPtr& p)
4018
+ {
4019
+ static const string prefix = "java:";
4020
+
4021
+ //
4022
+ // Validate global metadata in the top-level file and all included files.
4023
+ //
4024
+ StringList files = p->allFiles();
4025
+
4026
+ for(StringList::iterator q = files.begin(); q != files.end(); ++q)
4027
+ {
4028
+ string file = *q;
4029
+ DefinitionContextPtr dc = p->findDefinitionContext(file);
4030
+ assert(dc);
4031
+ StringList globalMetaData = dc->getMetaData();
4032
+ for(StringList::const_iterator r = globalMetaData.begin(); r != globalMetaData.end(); ++r)
4033
+ {
4034
+ string s = *r;
4035
+ if(_history.count(s) == 0)
4036
+ {
4037
+ if(s.find(prefix) == 0)
4038
+ {
4039
+ bool ok = false;
4040
+
4041
+ static const string packagePrefix = "java:package:";
4042
+ if(s.find(packagePrefix) == 0 && s.size() > packagePrefix.size())
4043
+ {
4044
+ ok = true;
4045
+ }
4046
+
4047
+ if(!ok)
4048
+ {
4049
+ emitWarning(file, "", "ignoring invalid global metadata `" + s + "'");
4050
+ }
4051
+ }
4052
+ _history.insert(s);
4053
+ }
4054
+ }
4055
+ }
4056
+ return true;
4057
+ }
4058
+
4059
+ bool
4060
+ Slice::JavaGenerator::MetaDataVisitor::visitModuleStart(const ModulePtr& p)
4061
+ {
4062
+ StringList metaData = getMetaData(p);
4063
+ validateType(p, metaData, p->file(), p->line());
4064
+ validateGetSet(p, metaData, p->file(), p->line());
4065
+ return true;
4066
+ }
4067
+
4068
+ void
4069
+ Slice::JavaGenerator::MetaDataVisitor::visitClassDecl(const ClassDeclPtr& p)
4070
+ {
4071
+ StringList metaData = getMetaData(p);
4072
+ validateType(p, metaData, p->file(), p->line());
4073
+ validateGetSet(p, metaData, p->file(), p->line());
4074
+ }
4075
+
4076
+ bool
4077
+ Slice::JavaGenerator::MetaDataVisitor::visitClassDefStart(const ClassDefPtr& p)
4078
+ {
4079
+ StringList metaData = getMetaData(p);
4080
+ validateType(p, metaData, p->file(), p->line());
4081
+ validateGetSet(p, metaData, p->file(), p->line());
4082
+ return true;
4083
+ }
4084
+
4085
+ bool
4086
+ Slice::JavaGenerator::MetaDataVisitor::visitExceptionStart(const ExceptionPtr& p)
4087
+ {
4088
+ StringList metaData = getMetaData(p);
4089
+ validateType(p, metaData, p->file(), p->line());
4090
+ validateGetSet(p, metaData, p->file(), p->line());
4091
+ return true;
4092
+ }
4093
+
4094
+ bool
4095
+ Slice::JavaGenerator::MetaDataVisitor::visitStructStart(const StructPtr& p)
4096
+ {
4097
+ StringList metaData = getMetaData(p);
4098
+ validateType(p, metaData, p->file(), p->line());
4099
+ validateGetSet(p, metaData, p->file(), p->line());
4100
+ return true;
4101
+ }
4102
+
4103
+ void
4104
+ Slice::JavaGenerator::MetaDataVisitor::visitOperation(const OperationPtr& p)
4105
+ {
4106
+ if(p->hasMetaData("UserException"))
4107
+ {
4108
+ ClassDefPtr cl = ClassDefPtr::dynamicCast(p->container());
4109
+ if(!cl->isLocal())
4110
+ {
4111
+ ostringstream os;
4112
+ os << "ignoring invalid metadata `UserException': directive applies only to local operations "
4113
+ << "but enclosing " << (cl->isInterface() ? "interface" : "class") << " `" << cl->name()
4114
+ << "' is not local";
4115
+ emitWarning(p->file(), p->line(), os.str());
4116
+ }
4117
+ }
4118
+ StringList metaData = getMetaData(p);
4119
+ TypePtr returnType = p->returnType();
4120
+ if(!metaData.empty())
4121
+ {
4122
+ if(!returnType)
4123
+ {
4124
+ for(StringList::const_iterator q = metaData.begin(); q != metaData.end(); ++q)
4125
+ {
4126
+ if(q->find("java:type:", 0) == 0)
4127
+ {
4128
+ emitWarning(p->file(), p->line(), "ignoring invalid metadata `" + *q +
4129
+ "' for operation with void return type");
4130
+ break;
4131
+ }
4132
+ }
4133
+ }
4134
+ else
4135
+ {
4136
+ validateType(returnType, metaData, p->file(), p->line());
4137
+ }
4138
+ }
4139
+
4140
+ ParamDeclList params = p->parameters();
4141
+ for(ParamDeclList::iterator q = params.begin(); q != params.end(); ++q)
4142
+ {
4143
+ metaData = getMetaData(*q);
4144
+ validateType((*q)->type(), metaData, p->file(), (*q)->line());
4145
+ }
4146
+
4147
+ validateGetSet(p, metaData, p->file(), p->line());
4148
+ }
4149
+
4150
+ void
4151
+ Slice::JavaGenerator::MetaDataVisitor::visitDataMember(const DataMemberPtr& p)
4152
+ {
4153
+ StringList metaData = getMetaData(p);
4154
+ validateType(p->type(), metaData, p->file(), p->line());
4155
+ validateGetSet(p, metaData, p->file(), p->line());
4156
+ }
4157
+
4158
+ void
4159
+ Slice::JavaGenerator::MetaDataVisitor::visitSequence(const SequencePtr& p)
4160
+ {
4161
+ static const string protobuf = "java:protobuf:";
4162
+ static const string serializable = "java:serializable:";
4163
+ static const string bytebuffer = "java:buffer";
4164
+ StringList metaData = getMetaData(p);
4165
+ const string file = p->file();
4166
+ const string line = p->line();
4167
+ for(StringList::const_iterator q = metaData.begin(); q != metaData.end(); )
4168
+ {
4169
+ string s = *q++;
4170
+ if(_history.count(s) == 0) // Don't complain about the same metadata more than once.
4171
+ {
4172
+ if(s.find(protobuf) == 0 || s.find(serializable) == 0)
4173
+ {
4174
+ //
4175
+ // Remove from list so validateType does not try to handle as well.
4176
+ //
4177
+ metaData.remove(s);
4178
+
4179
+ BuiltinPtr builtin = BuiltinPtr::dynamicCast(p->type());
4180
+ if(!builtin || builtin->kind() != Builtin::KindByte)
4181
+ {
4182
+ _history.insert(s);
4183
+ emitWarning(file, line, "ignoring invalid metadata `" + s + "': " +
4184
+ "this metadata can only be used with a byte sequence");
4185
+ }
4186
+ }
4187
+ else if(s.find(bytebuffer) == 0)
4188
+ {
4189
+ metaData.remove(s);
4190
+
4191
+ BuiltinPtr builtin = BuiltinPtr::dynamicCast(p->type());
4192
+ if(!builtin ||
4193
+ (builtin->kind() != Builtin::KindByte && builtin->kind() != Builtin::KindShort &&
4194
+ builtin->kind() != Builtin::KindInt && builtin->kind() != Builtin::KindLong &&
4195
+ builtin->kind() != Builtin::KindFloat && builtin->kind() != Builtin::KindDouble))
4196
+ {
4197
+ _history.insert(s);
4198
+ emitWarning(file, line, "ignoring invalid metadata `" + s + "': " +
4199
+ "this metadata can not be used with this type");
4200
+ }
4201
+ }
4202
+ }
4203
+ }
4204
+
4205
+ validateType(p, metaData, file, line);
4206
+ validateGetSet(p, metaData, file, line);
4207
+ }
4208
+
4209
+ void
4210
+ Slice::JavaGenerator::MetaDataVisitor::visitDictionary(const DictionaryPtr& p)
4211
+ {
4212
+ StringList metaData = getMetaData(p);
4213
+ validateType(p, metaData, p->file(), p->line());
4214
+ validateGetSet(p, metaData, p->file(), p->line());
4215
+ }
4216
+
4217
+ void
4218
+ Slice::JavaGenerator::MetaDataVisitor::visitEnum(const EnumPtr& p)
4219
+ {
4220
+ StringList metaData = getMetaData(p);
4221
+ validateType(p, metaData, p->file(), p->line());
4222
+ validateGetSet(p, metaData, p->file(), p->line());
4223
+ }
4224
+
4225
+ void
4226
+ Slice::JavaGenerator::MetaDataVisitor::visitConst(const ConstPtr& p)
4227
+ {
4228
+ StringList metaData = getMetaData(p);
4229
+ validateType(p, metaData, p->file(), p->line());
4230
+ validateGetSet(p, metaData, p->file(), p->line());
4231
+ }
4232
+
4233
+ StringList
4234
+ Slice::JavaGenerator::MetaDataVisitor::getMetaData(const ContainedPtr& cont)
4235
+ {
4236
+ static const string prefix = "java:";
4237
+
4238
+ StringList metaData = cont->getMetaData();
4239
+ StringList result;
4240
+
4241
+ for(StringList::const_iterator p = metaData.begin(); p != metaData.end(); ++p)
4242
+ {
4243
+ string s = *p;
4244
+ if(_history.count(s) == 0) // Don't complain about the same metadata more than once.
4245
+ {
4246
+ if(s.find(prefix) == 0)
4247
+ {
4248
+ string::size_type pos = s.find(':', prefix.size());
4249
+ if(pos == string::npos)
4250
+ {
4251
+ if(s.size() > prefix.size())
4252
+ {
4253
+ string rest = s.substr(prefix.size());
4254
+ if(rest == "getset")
4255
+ {
4256
+ result.push_back(s);
4257
+ }
4258
+ else if(rest == "buffer")
4259
+ {
4260
+ result.push_back(s);
4261
+ }
4262
+ continue;
4263
+ }
4264
+ }
4265
+ else if(s.substr(prefix.size(), pos - prefix.size()) == "type")
4266
+ {
4267
+ result.push_back(s);
4268
+ continue;
4269
+ }
4270
+ else if(s.substr(prefix.size(), pos - prefix.size()) == "serializable")
4271
+ {
4272
+ result.push_back(s);
4273
+ continue;
4274
+ }
4275
+ else if(s.substr(prefix.size(), pos - prefix.size()) == "protobuf")
4276
+ {
4277
+ result.push_back(s);
4278
+ continue;
4279
+ }
4280
+ else if(s.substr(prefix.size(), pos - prefix.size()) == "serialVersionUID")
4281
+ {
4282
+ result.push_back(s);
4283
+ continue;
4284
+ }
4285
+
4286
+ emitWarning(cont->file(), cont->line(), "ignoring invalid metadata `" + s + "'");
4287
+ }
4288
+
4289
+ _history.insert(s);
4290
+ }
4291
+ }
4292
+
4293
+ return result;
4294
+ }
4295
+
4296
+ void
4297
+ Slice::JavaGenerator::MetaDataVisitor::validateType(const SyntaxTreeBasePtr& p, const StringList& metaData,
4298
+ const string& file, const string& line)
4299
+ {
4300
+ for(StringList::const_iterator i = metaData.begin(); i != metaData.end(); ++i)
4301
+ {
4302
+ //
4303
+ // Type metadata ("java:type:Foo") is only supported by sequences and dictionaries.
4304
+ //
4305
+ if(i->find("java:type:", 0) == 0 && (!SequencePtr::dynamicCast(p) && !DictionaryPtr::dynamicCast(p)))
4306
+ {
4307
+ string str;
4308
+ ContainedPtr cont = ContainedPtr::dynamicCast(p);
4309
+ if(cont)
4310
+ {
4311
+ str = cont->kindOf();
4312
+ }
4313
+ else
4314
+ {
4315
+ BuiltinPtr b = BuiltinPtr::dynamicCast(p);
4316
+ assert(b);
4317
+ str = b->typeId();
4318
+ }
4319
+ emitWarning(file, line, "invalid metadata for " + str);
4320
+ }
4321
+ else if(i->find("java:buffer") == 0)
4322
+ {
4323
+ SequencePtr seq = SequencePtr::dynamicCast(p);
4324
+ if(seq)
4325
+ {
4326
+ BuiltinPtr builtin = BuiltinPtr::dynamicCast(seq->type());
4327
+ if(builtin &&
4328
+ (builtin->kind() == Builtin::KindByte || builtin->kind() == Builtin::KindShort ||
4329
+ builtin->kind() == Builtin::KindInt || builtin->kind() == Builtin::KindLong ||
4330
+ builtin->kind() == Builtin::KindFloat || builtin->kind() == Builtin::KindDouble))
4331
+ {
4332
+ continue;
4333
+ }
4334
+
4335
+ }
4336
+ emitWarning(file, line, "ignoring invalid metadata `" + *i + "'");
4337
+ }
4338
+ else if(i->find("java:protobuf:") == 0 || i->find("java:serializable:") == 0)
4339
+ {
4340
+ //
4341
+ // Only valid in sequence defintion which is checked in visitSequence
4342
+ //
4343
+ emitWarning(file, line, "ignoring invalid metadata `" + *i + "'");
4344
+ }
4345
+ }
4346
+ }
4347
+
4348
+ void
4349
+ Slice::JavaGenerator::MetaDataVisitor::validateGetSet(const SyntaxTreeBasePtr& p, const StringList& metaData,
4350
+ const string& file, const string& line)
4351
+ {
4352
+ for(StringList::const_iterator i = metaData.begin(); i != metaData.end(); ++i)
4353
+ {
4354
+ //
4355
+ // The "getset" metadata can only be specified on a class, struct, exception or data member.
4356
+ //
4357
+ if((*i) == "java:getset" &&
4358
+ (!ClassDefPtr::dynamicCast(p) && !StructPtr::dynamicCast(p) && !ExceptionPtr::dynamicCast(p) &&
4359
+ !DataMemberPtr::dynamicCast(p)))
4360
+ {
4361
+ string str;
4362
+ ContainedPtr cont = ContainedPtr::dynamicCast(p);
4363
+ if(cont)
4364
+ {
4365
+ str = cont->kindOf();
4366
+ }
4367
+ else
4368
+ {
4369
+ BuiltinPtr b = BuiltinPtr::dynamicCast(p);
4370
+ assert(b);
4371
+ str = b->typeId();
4372
+ }
4373
+ emitWarning(file, line, "invalid metadata for " + str);
4374
+ }
4375
+ }
4376
+ }