zeroc-ice 3.6b1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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,2980 @@
1
+ /*-
2
+ * Copyright (c) 1998, 2002-2008 Kiyoshi Matsui <kmatsui@t3.rim.or.jp>
3
+ * All rights reserved.
4
+ *
5
+ * Some parts of this code are derived from the public domain software
6
+ * DECUS cpp (1984,1985) written by Martin Minow.
7
+ *
8
+ * Redistribution and use in source and binary forms, with or without
9
+ * modification, are permitted provided that the following conditions
10
+ * are met:
11
+ * 1. Redistributions of source code must retain the above copyright
12
+ * notice, this list of conditions and the following disclaimer.
13
+ * 2. Redistributions in binary form must reproduce the above copyright
14
+ * notice, this list of conditions and the following disclaimer in the
15
+ * documentation and/or other materials provided with the distribution.
16
+ *
17
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
18
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE
21
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27
+ * SUCH DAMAGE.
28
+ */
29
+
30
+ /*
31
+ * E X P A N D . C
32
+ * M a c r o E x p a n s i o n
33
+ *
34
+ * The macro expansion routines are placed here.
35
+ */
36
+
37
+ #if PREPROCESSED
38
+ #include "mcpp.H"
39
+ #else
40
+ #include "system.H"
41
+ #include "internal.H"
42
+ #endif
43
+
44
+ #define ARG_ERROR (-255)
45
+ #define CERROR 1
46
+ #define CWARN 2
47
+
48
+ typedef struct location { /* Where macro or arg locate */
49
+ long start_line; /* Beginning at 1 */
50
+ size_t start_col; /* Beginning at 0 */
51
+ long end_line;
52
+ size_t end_col;
53
+ } LOCATION;
54
+ typedef struct magic_seq { /* Data of a sequence inserted between tokens */
55
+ char * magic_start; /* First MAC_INF sequence */
56
+ char * magic_end; /* End of last MAC_INF seq */
57
+ int space; /* Space succeeds or not */
58
+ } MAGIC_SEQ;
59
+
60
+ static int compat_mode;
61
+ /* Expand recursive macro more than Standard (for compatibility with GNUC) */
62
+ #if COMPILER == GNUC
63
+ static int ansi; /* __STRICT_ANSI__ flag */
64
+ #endif
65
+
66
+ static char * expand_std( DEFBUF * defp, char * out, char * out_end
67
+ , LINE_COL line_col, int * pragma_op);
68
+ /* Expand a macro completely (for Standard modes) */
69
+ static char * expand_prestd( DEFBUF * defp, char * out, char * out_end
70
+ , LINE_COL line_col, int * pragma_op);
71
+ /* Expand a macro completely (for pre-Standard modes) */
72
+ static DEFBUF * is_macro_call( DEFBUF * defp, char ** cp, char ** endf
73
+ , MAGIC_SEQ * mgc_seq); /* Is this really a macro call ? */
74
+ static int collect_args( const DEFBUF * defp, char ** arglist, int m_num);
75
+ /* Collect arguments of a macro call*/
76
+ static int get_an_arg( int c, char ** argpp, char * arg_end
77
+ , char ** seqp, int var_arg, int nargs, LOCATION ** locp, int m_num
78
+ , MAGIC_SEQ * mgc_prefix); /* Get an argument */
79
+ static int squeeze_ws( char ** out, char ** endf, MAGIC_SEQ * mgc_seq);
80
+ /* Squeeze white spaces to a space */
81
+ static void skip_macro( void);
82
+ /* Skip the rest of macro call */
83
+ static void diag_macro( int severity, const char * format
84
+ , const char * arg1, long arg2, const char * arg3, const DEFBUF * defp1
85
+ , const DEFBUF * defp2) ;
86
+ /* Supplement diagnostic information*/
87
+ static void dump_args( const char * why, int nargs, const char ** arglist);
88
+ /* Dump arguments list */
89
+
90
+ static int rescan_level; /* Times of macro rescan */
91
+
92
+ static const char * const macbuf_overflow
93
+ = "Buffer overflow expanding macro \"%s\" at %.0ld\"%s\""; /* _E_ */
94
+ static const char * const empty_arg
95
+ = "Empty argument in macro call \"%s\""; /* _W2_ */
96
+ static const char * const unterm_macro
97
+ = "Unterminated macro call \"%s\""; /* _E_ */
98
+ static const char * const narg_error
99
+ = "%s than necessary %ld argument(s) in macro call \"%s\""; /* _E_ _W1_ */
100
+ static const char * const only_name
101
+ = "Macro \"%s\" needs arguments"; /* _W8_ */
102
+
103
+ void expand_init(
104
+ int compat, /* "Compatible" to GNUC expansion of recursive macro*/
105
+ int strict_ansi /* __STRICT_ANSI__ flag for GNUC */
106
+ )
107
+ /* Set expand_macro() function */
108
+ {
109
+ expand_macro = standard ? expand_std : expand_prestd;
110
+ compat_mode = compat;
111
+ #if COMPILER == GNUC
112
+ ansi = strict_ansi;
113
+ #endif
114
+ }
115
+
116
+ DEFBUF * is_macro(
117
+ char ** cp
118
+ )
119
+ /*
120
+ * The name is already in 'identifier', the next token is not yet read.
121
+ * Return the definition info if the name is a macro call, else return NULL.
122
+ */
123
+ {
124
+ DEFBUF * defp;
125
+
126
+ if ((defp = look_id( identifier)) != NULL) /* Is a macro name */
127
+ return is_macro_call( defp, cp, NULL, NULL);
128
+ else
129
+ return NULL;
130
+ }
131
+
132
+ static DEFBUF * is_macro_call(
133
+ DEFBUF * defp,
134
+ char ** cp, /* Pointer to output buffer */
135
+ char ** endf, /* Pointer to indicate end of infile buffer */
136
+ MAGIC_SEQ * mgc_seq /* Infs on MAC_INF sequences and space */
137
+ )
138
+ /*
139
+ * Return DEFBUF if the defp->name is a macro call, else return NULL.
140
+ */
141
+ {
142
+ int c;
143
+
144
+ if (defp->nargs >= 0 /* Function-like macro */
145
+ || defp->nargs == DEF_PRAGMA) { /* _Pragma() pseudo-macro */
146
+ c = squeeze_ws( cp, endf, mgc_seq); /* See the next char. */
147
+ if (c == CHAR_EOF) /* End of file */
148
+ unget_string( "\n", NULL); /* Restore skipped '\n' */
149
+ else if (! standard || c != RT_END)
150
+ /* Still in the file and rescan boundary ? */
151
+ unget_ch(); /* To see it again */
152
+ if (c != '(') { /* Only the name of function-like macro */
153
+ if (! standard && warn_level & 8)
154
+ cwarn( only_name, defp->name, 0L, NULL);
155
+ return NULL;
156
+ }
157
+ }
158
+ return defp; /* Really a macro call */
159
+ }
160
+
161
+ /*
162
+ * expand_macro() expands a macro call completely, and writes out the result
163
+ * to the specified output buffer and returns the advanced pointer.
164
+ */
165
+
166
+
167
+ /*
168
+ * T h e S T A N D A R D C o n f o r m i n g M o d e
169
+ * o f M a c r o E x p a n s i o n
170
+ *
171
+ * 1998/08 First released. kmatsui
172
+ */
173
+
174
+ /* For debug of -K option: should be turned off on release version. */
175
+ #define DEBUG_MACRO_ANN FALSE
176
+
177
+ /* Return value of is_able_repl() */
178
+ #define NO 0 /* "Blue-painted" */
179
+ #define YES 1 /* Not blue-painted */
180
+ #define READ_OVER 2
181
+ /* Still "blue-painted", yet has read over repl-list */
182
+
183
+ /*
184
+ * Macros related to macro notification mode.
185
+ * The macro notification routines are hacks on the normal processing
186
+ * routines, and very complicated and cumbersome. Be sure to keep symmetry
187
+ * of starting and closing magic sequences. Enable the routines enclosed
188
+ * by #if 0 - #endif for debugging.
189
+ * Any byte in the sequences beginning with MAC_INF can coincide with any
190
+ * other character. Hence, the data stream should be read from the top,
191
+ * not from the tail, in principle.
192
+ */
193
+ /* Length of sequence of MAC_INF, MAC_CALL_START, mac_num-1, mac_num-2 */
194
+ #define MAC_S_LEN 4
195
+ /* Length of sequence of MAC_INF, MAC_ARG_START, mac_num1, mac_num2, arg-num*/
196
+ #define ARG_S_LEN 5
197
+ #define MAC_E_LEN 2 /* Length of MAC_INF, MAC_CALL_END sequence */
198
+ #define ARG_E_LEN MAC_E_LEN /* Lenght of MAC_INF, MAC_ARG_END sequence */
199
+ #define MAC_E_LEN_V 4 /* Length of macro closing sequence in verbose mode */
200
+ /* MAC_INF, MAC_CALL_END, mac_num1, mac_num2 */
201
+ #define ARG_E_LEN_V 5 /* Length of argument closing sequence in verbose */
202
+ /* MAC_INF, MAC_ARG_END, mac_num1, mac_num2, arg_num */
203
+ #define IN_SRC_LEN 3 /* Length of sequence of IN_SRC, num-1, num-2 */
204
+ #define INIT_MAC_INF 0x100 /* Initial num of elements in mac_inf[] */
205
+ #define MAX_MAC_INF 0x1000 /* Maximum num of elements in mac_inf[] */
206
+ #define INIT_IN_SRC_NUM 0x100 /* Initial num of elements in in_src[] */
207
+ #define MAX_IN_SRC_NUM 0x1000 /* Maximum num of elements in in_src[] */
208
+
209
+ /* Variables for macro notification mode */
210
+ typedef struct macro_inf { /* Informations of a macro */
211
+ const DEFBUF * defp; /* Definition of the macro */
212
+ char * args; /* Arguments, if any */
213
+ int num_args; /* Number of real arguments */
214
+ int recur; /* Recurrence of this macro */
215
+ LOCATION locs; /* Location of macro call */
216
+ LOCATION * loc_args; /* Location of arguments */
217
+ } MACRO_INF;
218
+ static MACRO_INF * mac_inf;
219
+ static int max_mac_num; /* Current num of elements in mac_inf[] */
220
+ static int mac_num; /* Index into mac_inf[] */
221
+ static LOCATION * in_src; /* Location of identifiers in macro arguments */
222
+ static int max_in_src_num; /* Current num of elements in in_src[] */
223
+ static int in_src_num; /* Index into in_src[] */
224
+ static int trace_macro; /* Enable to trace macro infs */
225
+
226
+ static struct {
227
+ const DEFBUF * def; /* Macro definition */
228
+ int read_over; /* Has read over repl-list */
229
+ /* 'read_over' is never used in POST_STD mode and in compat_mode*/
230
+ } replacing[ RESCAN_LIMIT]; /* Macros currently replacing */
231
+ static int has_pragma = FALSE; /* Flag of _Pragma() operator */
232
+
233
+ static int print_macro_inf( int c, char ** cpp, char ** opp);
234
+ /* Embed macro infs into comments */
235
+ static char * print_macro_arg( char *out, MACRO_INF * m_inf, int argn
236
+ , int real_arg, int start);
237
+ /* Embed macro arg inf into comments*/
238
+ static char * chk_magic_balance( char * buf, char * buf_end, int move
239
+ , int diag); /* Check imbalance of magics */
240
+ static char * replace( DEFBUF * defp, char * out, char * out_end
241
+ , const DEFBUF * outer, FILEINFO * rt_file, LINE_COL line_col
242
+ , int in_src_n);
243
+ /* Replace a macro recursively */
244
+ static char * close_macro_inf( char * out_p, int m_num, int in_src_n);
245
+ /* Put closing mark for a macro call*/
246
+ static DEFBUF * def_special( DEFBUF * defp);
247
+ /* Re-define __LINE__, __FILE__ */
248
+ static int prescan( const DEFBUF * defp, const char ** arglist
249
+ , char * out, char * out_end);
250
+ /* Process #, ## operator */
251
+ static char * catenate( const DEFBUF * defp, const char ** arglist
252
+ , char * out, char * out_end, char ** token_p);
253
+ /* Catenate tokens */
254
+ static const char * remove_magics( const char * argp, int from_last);
255
+ /* Remove pair of magic characters */
256
+ #if DEBUG_MACRO_ANN
257
+ static void chk_symmetry( char * start_id, char * end_id, size_t len);
258
+ /* Check if a pair of magics are symmetrical */
259
+ #endif
260
+ static char * stringize( const DEFBUF * defp, const char * argp, char * out);
261
+ /* Stringize an argument */
262
+ static char * substitute( const DEFBUF * defp, const char ** arglist
263
+ , const char * in, char * out, char * out_end);
264
+ /* Substitute parms with arguments */
265
+ static char * rescan( const DEFBUF * outer, const char * in, char * out
266
+ , char * out_end);
267
+ /* Rescan once replaced sequences */
268
+ static int disable_repl( const DEFBUF * defp);
269
+ /* Disable the macro once replaced */
270
+ static void enable_repl( const DEFBUF * defp, int done);
271
+ /* Enable the macro for later use */
272
+ static int is_able_repl( const DEFBUF * defp);
273
+ /* Is the macro allowed to replace? */
274
+ static char * insert_to_bptr( char * ins, size_t len);
275
+ /* Insert a sequence into infile->bptr */
276
+
277
+ static char * expand_std(
278
+ DEFBUF * defp, /* Macro definition */
279
+ char * out, /* Output buffer */
280
+ char * out_end, /* End of output buffer */
281
+ LINE_COL line_col, /* Location of macro */
282
+ int * pragma_op /* _Pragma() is found ? */
283
+ )
284
+ /*
285
+ * Expand a macro call completely, write the results to the specified buffer
286
+ * and return the advanced output pointer.
287
+ */
288
+ {
289
+ char macrobuf[ NMACWORK + IDMAX]; /* Buffer for replace() */
290
+ char * out_p = out;
291
+ size_t len;
292
+ int c, c1;
293
+ char * cp;
294
+
295
+ has_pragma = FALSE; /* Have to re-initialize*/
296
+ macro_line = src_line; /* Line number for diag */
297
+ macro_name = defp->name;
298
+ rescan_level = 0;
299
+ trace_macro = (mcpp_mode == STD) && (mcpp_debug & MACRO_CALL)
300
+ && ! in_directive;
301
+ if (trace_macro) {
302
+ max_mac_num = INIT_MAC_INF;
303
+ mac_inf = (MACRO_INF *) xmalloc( sizeof (MACRO_INF) * max_mac_num);
304
+ memset( mac_inf, 0, sizeof (MACRO_INF) * max_mac_num);
305
+ max_in_src_num = INIT_IN_SRC_NUM;
306
+ in_src = (LOCATION *) xmalloc( sizeof (LOCATION) * max_in_src_num);
307
+ memset( in_src, 0, sizeof (LOCATION) * max_in_src_num);
308
+ mac_num = in_src_num = 0; /* Initialize */
309
+ }
310
+ if (replace( defp, macrobuf, macrobuf + NMACWORK, NULL, infile, line_col
311
+ , 0) == NULL) { /* Illegal macro call */
312
+ skip_macro();
313
+ macro_line = MACRO_ERROR;
314
+ goto exp_end;
315
+ }
316
+ len = (size_t) (out_end - out);
317
+ if (strlen( macrobuf) > len) {
318
+ cerror( macbuf_overflow, macro_name, 0, macrobuf);
319
+ memcpy( out, macrobuf, len);
320
+ out_p = out + len;
321
+ macro_line = MACRO_ERROR;
322
+ goto exp_end;
323
+ }
324
+
325
+ #if DEBUG_MACRO_ANN
326
+ chk_magic_balance( macrobuf, macrobuf + strlen( macrobuf), FALSE, TRUE);
327
+ #endif
328
+ cp = macrobuf;
329
+ c1 = '\0'; /* The char previous to 'c' */
330
+ while ((c = *cp++) != EOS) {
331
+ if (c == DEF_MAGIC)
332
+ continue; /* Skip DEF_MAGIC */
333
+ if (mcpp_mode == STD) {
334
+ if (c == IN_SRC) { /* Skip IN_SRC */
335
+ if (trace_macro)
336
+ cp += 2; /* Skip also the number (coded in 2 bytes) */
337
+ continue;
338
+ } else if (c == TOK_SEP) {
339
+ /* Remove redundant token separator */
340
+ if ((char_type[ c1 & UCHARMAX] & HSP)
341
+ || (char_type[ *cp & UCHARMAX] & HSP)
342
+ || in_include || option_flags.lang_asm
343
+ || (*cp == MAC_INF && *(cp + 1) == MAC_CALL_END)
344
+ || (!option_flags.v && c1 == MAC_CALL_END)
345
+ || (option_flags.v
346
+ && *(cp - MAC_E_LEN_V - 1) == MAC_INF
347
+ && *(cp - MAC_E_LEN_V) == MAC_CALL_END))
348
+ continue;
349
+ /* Skip separator just after ' ', '\t' */
350
+ /* and just after MAC_CALL_END. */
351
+ /* Also skip this in lang_asm mode, #include */
352
+ /* Skip just before another TOK_SEP, ' ', '\t' */
353
+ /* Skip just before MAC_INF,MAC_CALL_END seq too*/
354
+ else
355
+ c = ' '; /* Else convert to ' ' */
356
+ } else if (trace_macro && (c == MAC_INF)) {
357
+ /* Embed macro expansion informations into comments */
358
+ c = *cp++;
359
+ c1 = print_macro_inf( c, &cp, &out_p);
360
+ if (out_end <= out_p) {
361
+ cerror( macbuf_overflow, macro_name, 0, out);
362
+ macro_line = MACRO_ERROR;
363
+ goto exp_end;
364
+ }
365
+ continue;
366
+ }
367
+ }
368
+ *out_p++ = c1 = c;
369
+ }
370
+
371
+ macro_line = 0;
372
+ exp_end:
373
+ *out_p = EOS;
374
+ if (mcpp_debug & EXPAND)
375
+ dump_string( "expand_std exit", out);
376
+ macro_name = NULL;
377
+ clear_exp_mac(); /* Clear the information for diagnostic */
378
+ if (trace_macro) { /* Clear macro informations */
379
+ int num;
380
+ for (num = 1; num < mac_num; num++) { /* 'num' start at 1 */
381
+ if (mac_inf[ num].num_args >= 0) { /* Macro with args */
382
+ free( mac_inf[ num].args); /* Saved arguments */
383
+ free( mac_inf[ num].loc_args); /* Location of args */
384
+ }
385
+ }
386
+ free( mac_inf);
387
+ free( in_src);
388
+ }
389
+ *pragma_op = has_pragma;
390
+
391
+ return out_p;
392
+ }
393
+
394
+ static int print_macro_inf(
395
+ int c,
396
+ char ** cpp, /* Magic character sequence */
397
+ char ** opp /* Output for macro information */
398
+ )
399
+ /*
400
+ * Embed macro expansion information into comments.
401
+ * Enabled by '#pragma MCPP debug macro_call' or -K option in STD mode.
402
+ */
403
+ {
404
+ MACRO_INF * m_inf;
405
+ int num;
406
+ int num_args; /* Number of actual args (maybe less than expected) */
407
+ int i;
408
+
409
+ if (*((*opp) - 1) == '/' && *((*opp) - 2) != '*')
410
+ /* Immediately preceding token is '/' (not '*' and '/') */
411
+ *((*opp)++) = ' ';
412
+ /* Insert a space to separate with following '/' and '*' */
413
+ if (option_flags.v || c == MAC_CALL_START || c == MAC_ARG_START) {
414
+ num = ((*(*cpp)++ & UCHARMAX) - 1) * UCHARMAX;
415
+ num += (*(*cpp)++ & UCHARMAX) - 1;
416
+ m_inf = & mac_inf[ num]; /* Saved information */
417
+ }
418
+ switch (c) {
419
+ case MAC_CALL_START : /* Start of a macro expansion */
420
+ *opp += sprintf( *opp, "/*<%s", m_inf->defp->name); /* Macro name */
421
+ if (m_inf->locs.start_line) {
422
+ /* Location of the macro call in source file */
423
+ *opp += sprintf( *opp, " %ld:%d-%ld:%d"
424
+ , m_inf->locs.start_line, (int) m_inf->locs.start_col
425
+ , m_inf->locs.end_line, (int) m_inf->locs.end_col);
426
+ }
427
+ *opp = stpcpy( *opp, "*/");
428
+ if ((num_args = m_inf->num_args) >= 1) {
429
+ /* The macro has arguments. Show the locations. */
430
+ for (i = 0; i < num_args; i++) /* Arg num begins at 0 */
431
+ *opp = print_macro_arg( *opp, m_inf, i, TRUE, TRUE);
432
+ }
433
+ break;
434
+ case MAC_ARG_START : /* Start of an argument */
435
+ i = (*(*cpp)++ & UCHARMAX) - 1; /* Argument number */
436
+ *opp = print_macro_arg( *opp, m_inf, i, FALSE, TRUE);
437
+ break;
438
+ case MAC_CALL_END : /* End of a macro expansion */
439
+ if (option_flags.v) { /* Verbose mode */
440
+ *opp += sprintf( *opp, "/*%s>*/", m_inf->defp->name);
441
+ break;
442
+ }
443
+ /* Else fall through */
444
+ case MAC_ARG_END : /* End of an argument */
445
+ if (option_flags.v) {
446
+ i = (*(*cpp)++ & UCHARMAX) - 1;
447
+ /* Output verbose infs symmetrical to start of the arg infs */
448
+ *opp = print_macro_arg( *opp, m_inf, i, FALSE, FALSE);
449
+ } else {
450
+ *opp = stpcpy( *opp, "/*>*/");
451
+ }
452
+ break;
453
+ }
454
+
455
+ return **cpp & UCHARMAX;
456
+ }
457
+
458
+ static char * print_macro_arg(
459
+ char * out, /* Output buffer */
460
+ MACRO_INF * m_inf, /* &mac_inf[ m_num] */
461
+ int argn, /* Argument number */
462
+ int real_arg, /* Real argument or expanded argument ? */
463
+ int start /* Start of an argument or end ? */
464
+ )
465
+ /*
466
+ * Embed an argument information into a comment.
467
+ * This routine is only called from above print_macro_inf().
468
+ */
469
+ {
470
+ LOCATION * loc = m_inf->loc_args + argn;
471
+
472
+ out += sprintf( out, "/*%s%s:%d-%d", real_arg ? "!" : (start ? "<" : "")
473
+ , m_inf->defp->name, m_inf->recur, argn);
474
+
475
+ if (real_arg && m_inf->loc_args && loc->start_line) {
476
+ /* Location of the argument in source file */
477
+ out += sprintf( out, " %ld:%d-%ld:%d", loc->start_line
478
+ , (int) loc->start_col, loc->end_line, (int) loc->end_col);
479
+ }
480
+ if (! start) /* End of an argument in verbose mode */
481
+ out = stpcpy( out, ">");
482
+ out = stpcpy( out, "*/");
483
+
484
+ return out;
485
+ }
486
+
487
+ static char * chk_magic_balance(
488
+ char * buf, /* Sequence to check */
489
+ char * buf_end, /* End of the sequence */
490
+ int move, /* Move a straying magic ? */
491
+ int diag /* Output a diagnostic? */
492
+ )
493
+ /*
494
+ * Check imbalance of macro information magics and warn it.
495
+ * get_an_arg() calls this routine setting 'move' argument on, hence a stray
496
+ * magic is moved to an edge if found.
497
+ * This routine does not do token parsing. Yet it will do fine practically.
498
+ */
499
+ {
500
+ #define MAX_NEST_MAGICS 255
501
+ char mac_id[ MAX_NEST_MAGICS][ MAC_E_LEN_V - 2];
502
+ char arg_id[ MAX_NEST_MAGICS][ ARG_E_LEN_V - 2];
503
+ char * mac_loc[ MAX_NEST_MAGICS];
504
+ char * arg_loc[ MAX_NEST_MAGICS];
505
+ char * mesg = "%s %ld %s-closing-comment(s) in tracing macro";
506
+ int mac, arg;
507
+ int mac_s_n, mac_e_n, arg_s_n, arg_e_n;
508
+ char * buf_p = buf; /* Save 'buf' for debugging purpose */
509
+
510
+ mac = arg = 0;
511
+
512
+ while (buf_p < buf_end) {
513
+ if (*buf_p++ != MAC_INF)
514
+ continue;
515
+ switch (*buf_p++) {
516
+ case MAC_CALL_START :
517
+ if (option_flags.v) {
518
+ mac_loc[ mac] = buf_p - 2;
519
+ memcpy( mac_id[ mac], buf_p, MAC_S_LEN - 2);
520
+ }
521
+ mac++;
522
+ buf_p += MAC_S_LEN - 2;
523
+ break;
524
+ case MAC_ARG_START :
525
+ if (option_flags.v) {
526
+ arg_loc[ arg] = buf_p - 2;
527
+ memcpy( arg_id[ arg], buf_p, ARG_S_LEN - 2);
528
+ }
529
+ arg++;
530
+ buf_p += ARG_S_LEN - 2;
531
+ break;
532
+ case MAC_ARG_END :
533
+ arg--;
534
+ if (option_flags.v) {
535
+ if (arg < 0) { /* Perhaps moved magic */
536
+ if (diag)
537
+ cwarn( mesg, "Redundant", (long) -arg, "argument");
538
+ } else if (memcmp( arg_id[ arg], buf_p, ARG_E_LEN_V - 2) != 0)
539
+ {
540
+ char * to_be_edge = NULL;
541
+ char * cur_edge;
542
+
543
+ if (arg >= 1 && memcmp( arg_id[ 0], buf_p, ARG_E_LEN_V - 2)
544
+ == 0) {
545
+ to_be_edge = arg_loc[ arg];
546
+ /* To be moved to top */
547
+ cur_edge = arg_loc[ 0]; /* Current top */
548
+ } else if (arg == 0) {
549
+ char arg_end_magic[ 2] = { MAC_INF, MAC_ARG_END};
550
+ cur_edge = buf_end - ARG_E_LEN_V;
551
+ /* Search the last magic */
552
+ /* Sequence from get_an_arg() is always */
553
+ /* surrounded by starting of an arg magic */
554
+ /* and its corresponding closing magic. */
555
+ while (buf_p + (ARG_E_LEN_V - 2) <= cur_edge
556
+ && memcmp( cur_edge, arg_end_magic, 2) != 0)
557
+ cur_edge--;
558
+ if (buf_p + (ARG_E_LEN_V - 2) <= cur_edge
559
+ && memcmp( arg_id[ 0], cur_edge + 2
560
+ , ARG_E_LEN_V - 2) == 0) {
561
+ to_be_edge = buf_p - 2; /* To be moved to end */
562
+ }
563
+ }
564
+ if (to_be_edge) { /* Appropriate place found */
565
+ if (diag) {
566
+ mac_s_n = ((to_be_edge[ 2] & UCHARMAX) - 1)
567
+ * UCHARMAX;
568
+ mac_s_n += (to_be_edge[ 3] & UCHARMAX) - 1;
569
+ arg_s_n = (to_be_edge[ 4] & UCHARMAX) - 1;
570
+ mcpp_fprintf( ERR,
571
+ "Stray arg inf of macro: %d:%d at line:%d\n"
572
+ , mac_s_n, arg_s_n, src_line);
573
+ }
574
+ if (move) {
575
+ /* Move a stray magic to outside of sequences */
576
+ char magic[ ARG_E_LEN_V];
577
+ size_t len = ARG_E_LEN_V;
578
+ memcpy( magic, cur_edge, len);
579
+ /* Save current edge */
580
+ if (to_be_edge == arg_loc[ arg])
581
+ /* Shift followings to cur_edge */
582
+ memmove( cur_edge, cur_edge + len
583
+ , to_be_edge - cur_edge);
584
+ else /* Shift precedents to cur_edge */
585
+ memmove( to_be_edge + len, to_be_edge
586
+ , cur_edge - to_be_edge);
587
+ memcpy( to_be_edge, magic, len);
588
+ /* Restore old 'cur_edge' into old 'to_be_edge' */
589
+ }
590
+ } else { /* Serious imbalance, just warn */
591
+ char * arg_p = arg_id[ arg];
592
+ arg_s_n = ((arg_p[ 0] & UCHARMAX) - 1) * UCHARMAX;
593
+ arg_s_n += (arg_p[ 1] & UCHARMAX) - 1;
594
+ arg_e_n = ((buf_p[ 0] & UCHARMAX) - 1) * UCHARMAX;
595
+ arg_e_n += (buf_p[ 1] & UCHARMAX) - 1;
596
+ mcpp_fprintf( ERR,
597
+ "Asymmetry of arg inf found: start %d, end %d at line:%d\n"
598
+ , arg_s_n, arg_e_n, src_line);
599
+ }
600
+ }
601
+ buf_p += ARG_E_LEN_V - 2;
602
+ }
603
+ break;
604
+ case MAC_CALL_END :
605
+ mac--;
606
+ if (option_flags.v) {
607
+ if (mac < 0) {
608
+ if (diag)
609
+ cwarn( mesg, "Redundant", (long) -mac, "macro");
610
+ } else if (memcmp( mac_id[ mac], buf_p, MAC_E_LEN_V - 2) != 0)
611
+ {
612
+ char * mac_p = mac_id[ mac];
613
+ mac_s_n = ((mac_p[ 0] & UCHARMAX) - 1) * UCHARMAX;
614
+ mac_s_n += (mac_p[ 1] & UCHARMAX) - 1;
615
+ mac_e_n = ((buf_p[ 0] & UCHARMAX) - 1) * UCHARMAX;
616
+ mac_e_n += (buf_p[ 1] & UCHARMAX) - 1;
617
+ mcpp_fprintf( ERR,
618
+ "Asymmetry of macro inf found: start %d, end %d at line:%d\n"
619
+ , mac_s_n, mac_e_n, src_line);
620
+ }
621
+ buf_p += MAC_E_LEN_V - 2;
622
+ }
623
+ break;
624
+ default : /* Not a MAC_INF sequence */
625
+ break; /* Continue */
626
+ }
627
+ }
628
+
629
+ if (diag && (warn_level & 1)) {
630
+ if (mac > 0)
631
+ cwarn( mesg, "Lacking", (long) mac, "macro");
632
+ if (arg > 0)
633
+ cwarn( mesg, "Lacking", (long) arg, "argument");
634
+ if ((mac || arg) && (mcpp_debug & EXPAND))
635
+ mcpp_fputs(
636
+ "Imbalance of magics occurred (perhaps a moved magic), see <expand_std exit> and diagnostics.\n"
637
+ , DBG);
638
+ }
639
+
640
+ return buf;
641
+ }
642
+
643
+ static char * replace(
644
+ DEFBUF * defp, /* Macro to be replaced */
645
+ char * out, /* Output Buffer */
646
+ char * out_end, /* End of output buffer */
647
+ const DEFBUF * outer, /* Outer macro replacing*/
648
+ FILEINFO * rt_file, /* Repl-text "file" */
649
+ LINE_COL line_col, /* Location of macro */
650
+ int in_src_n /* Index into in_src[] */
651
+ )
652
+ /*
653
+ * Replace a possibly nested macro recursively.
654
+ * replace() and rescan() call each other recursively.
655
+ * Return the advanced output pointer or NULL on error.
656
+ */
657
+ {
658
+ char ** arglist = NULL; /* Pointers to arguments*/
659
+ int nargs; /* Number of arguments expected */
660
+ char * catbuf; /* Buffer for prescan() */
661
+ char * expbuf; /* Buffer for substitute() */
662
+ char * out_p; /* Output pointer */
663
+ char * cur_out = out; /* One more output pointer */
664
+ int num_args;
665
+ /* Number of actual arguments (maybe less than expected) */
666
+ int enable_trace_macro; /* To exclude _Pragma() pseudo macro */
667
+ int m_num = 0; /* 'mac_num' of current macro */
668
+ MACRO_INF * m_inf; /* Pointer into mac_inf[] */
669
+
670
+ if (mcpp_debug & EXPAND) {
671
+ dump_a_def( "replace entry", defp, FALSE, TRUE, fp_debug);
672
+ dump_unget( "replace entry");
673
+ }
674
+ if ((mcpp_debug & MACRO_CALL) && in_if)
675
+ mcpp_fprintf( OUT, "/*%s*/", defp->name);
676
+
677
+ enable_trace_macro = trace_macro && defp->nargs != DEF_PRAGMA;
678
+ if (enable_trace_macro) {
679
+ int num;
680
+ int recurs;
681
+
682
+ if (mac_num >= MAX_MAC_INF - 1) {
683
+ cerror( "Too many nested macros in tracing %s" /* _E_ */
684
+ , defp->name, 0L, NULL);
685
+ return NULL;
686
+ } else if (mac_num >= max_mac_num - 1) {
687
+ size_t len = sizeof (MACRO_INF) * max_mac_num;
688
+ /* Enlarge the array */
689
+ mac_inf = (MACRO_INF *) xrealloc( (char *) mac_inf, len * 2);
690
+ memset( mac_inf + max_mac_num, 0, len);
691
+ /* Clear the latter half */
692
+ max_mac_num *= 2;
693
+ }
694
+ m_num = ++mac_num; /* Remember this number */
695
+ /* Note 'mac_num' starts at 1 */
696
+ *cur_out++ = MAC_INF; /* Embed a magic char */
697
+ *cur_out++ = MAC_CALL_START; /* A macro call */
698
+ /* Its index number, can be greater than UCHARMAX */
699
+ /* We represent the number by 2 bytes where each byte is not '\0' */
700
+ *cur_out++ = (m_num / UCHARMAX) + 1;
701
+ *cur_out++ = (m_num % UCHARMAX) + 1;
702
+ *cur_out = EOS;
703
+ m_inf = & mac_inf[ m_num];
704
+ m_inf->defp = defp; /* The macro definition */
705
+ m_inf->num_args = 0; /* Default num of args */
706
+ if (line_col.line) {
707
+ get_src_location( & line_col);
708
+ m_inf->locs.start_line = line_col.line;
709
+ m_inf->locs.start_col = line_col.col;
710
+ } else {
711
+ m_inf->locs.start_col = m_inf->locs.start_line = 0L;
712
+ }
713
+ m_inf->args = m_inf->loc_args = NULL; /* Default args */
714
+ for (num = 1, recurs = 0; num < m_num; num++)
715
+ if (mac_inf[ num].defp == defp)
716
+ recurs++; /* Recursively nested macro */
717
+ m_inf->recur = recurs;
718
+ }
719
+
720
+ nargs = (defp->nargs == DEF_PRAGMA) ? 1 : (defp->nargs & ~AVA_ARGS);
721
+
722
+ if (nargs < DEF_NOARGS_DYNAMIC) { /* __FILE__, __LINE__ */
723
+ defp = def_special( defp); /* These are redefined dynamically */
724
+ if (mcpp_mode == STD) {
725
+ /* Wrap repl-text with token separators to prevent token merging */
726
+ *cur_out++ = TOK_SEP;
727
+ cur_out = stpcpy( cur_out, defp->repl);
728
+ *cur_out++ = TOK_SEP;
729
+ *cur_out = EOS;
730
+ } else {
731
+ cur_out = stpcpy( cur_out, defp->repl);
732
+ }
733
+ if (enable_trace_macro) {
734
+ m_inf->defp = defp; /* Redefined dynamically*/
735
+ cur_out = close_macro_inf( cur_out, m_num, in_src_n);
736
+ }
737
+ return cur_out;
738
+ } else if (nargs == DEF_NOARGS_PREDEF_OLD && standard
739
+ && (warn_level & 1)) { /* Some macros on GCC */
740
+ cwarn( "Old style predefined macro \"%s\" is used", /* _W2_ */
741
+ defp->name, 0L, NULL);
742
+ } else if (nargs >= 0) { /* Function-like macro */
743
+ squeeze_ws( NULL, NULL, NULL); /* Skip to '(' */
744
+ /* Magic sequences are already read over by is_macro_call() */
745
+ arglist = (char **) xmalloc( (nargs + 1) * sizeof (char *));
746
+ arglist[ 0] = xmalloc( (size_t) (NMACWORK + IDMAX * 2));
747
+ /* Note: arglist[ n] may be reallocated */
748
+ /* and re-written by collect_args() */
749
+ if ((num_args = collect_args( defp, arglist, m_num)) == ARG_ERROR) {
750
+ free( arglist[ 0]); /* Syntax error */
751
+ free( arglist);
752
+ return NULL;
753
+ }
754
+ if (enable_trace_macro) {
755
+ /* Save the arglist for later informations */
756
+ m_inf->args = arglist[ 0];
757
+ m_inf->num_args = num_args; /* Number of actual args*/
758
+ }
759
+ if (mcpp_mode == STD && outer && rt_file != infile) {
760
+ /* Has read over replacement-text */
761
+ if (compat_mode) {
762
+ enable_repl( outer, FALSE); /* Enable re-expansion */
763
+ if (mcpp_debug & EXPAND)
764
+ dump_string( "enabled re-expansion"
765
+ , outer ? outer->name : "<arg>");
766
+ } else {
767
+ replacing[ rescan_level-1].read_over = READ_OVER;
768
+ }
769
+ }
770
+ }
771
+
772
+ catbuf = xmalloc( (size_t) (NMACWORK + IDMAX));
773
+ if (mcpp_debug & EXPAND) {
774
+ mcpp_fprintf( DBG, "(%s)", defp->name);
775
+ dump_string( "prescan entry", defp->repl);
776
+ }
777
+ if (prescan( defp, (const char **) arglist, catbuf, catbuf + NMACWORK)
778
+ == FALSE) { /* Process #, ## operators */
779
+ diag_macro( CERROR, macbuf_overflow, defp->name, 0L, catbuf, defp
780
+ , NULL);
781
+ if (nargs >= 0) {
782
+ if (! enable_trace_macro)
783
+ /* arglist[0] is needed for macro infs */
784
+ free( arglist[ 0]);
785
+ free( arglist);
786
+ }
787
+ free( catbuf);
788
+ return NULL;
789
+ }
790
+ catbuf = xrealloc( catbuf, strlen( catbuf) + 1);
791
+ /* Use memory sparingly */
792
+ if (mcpp_debug & EXPAND) {
793
+ mcpp_fprintf( DBG, "(%s)", defp->name);
794
+ dump_string( "prescan exit", catbuf);
795
+ }
796
+
797
+ if (nargs > 0) { /* Function-like macro with any argument */
798
+ expbuf = xmalloc( (size_t) (NMACWORK + IDMAX));
799
+ if (mcpp_debug & EXPAND) {
800
+ mcpp_fprintf( DBG, "(%s)", defp->name);
801
+ dump_string( "substitute entry", catbuf);
802
+ }
803
+ out_p = substitute( defp, (const char **) arglist, catbuf, expbuf
804
+ , expbuf + NMACWORK); /* Expand each arguments */
805
+ if (! enable_trace_macro)
806
+ free( arglist[ 0]);
807
+ free( arglist);
808
+ free( catbuf);
809
+ expbuf = xrealloc( expbuf, strlen( expbuf) + 1);
810
+ /* Use memory sparingly */
811
+ if (mcpp_debug & EXPAND) {
812
+ mcpp_fprintf( DBG, "(%s)", defp->name);
813
+ dump_string( "substitute exit", expbuf);
814
+ }
815
+ } else { /* Object-like macro or */
816
+ if (nargs == 0 && ! enable_trace_macro)
817
+ /* Function-like macro with no argument */
818
+ free( arglist[ 0]);
819
+ free( arglist);
820
+ out_p = expbuf = catbuf;
821
+ }
822
+
823
+ if (out_p)
824
+ out_p = rescan( defp, expbuf, cur_out, out_end);
825
+ if (out_p && defp->nargs == DEF_PRAGMA)
826
+ has_pragma = TRUE;
827
+ /* Inform mcpp_main() that _Pragma() was found */
828
+ free( expbuf);
829
+ if (enable_trace_macro && out_p)
830
+ out_p = close_macro_inf( out_p, m_num, in_src_n);
831
+ if (mcpp_debug & EXPAND)
832
+ dump_string( "replace exit", out);
833
+
834
+ if (trace_macro && defp->nargs == DEF_PRAGMA) {
835
+ /* Remove intervening magics if the macro is _Pragma pseudo-macro */
836
+ /* These magics have been inserted by macros in _Pragma()'s args */
837
+ int c;
838
+ cur_out = out_p = out;
839
+ while ((c = *cur_out++) != EOS) {
840
+ if (c == MAC_INF) {
841
+ if (! option_flags.v) {
842
+ switch (*cur_out) {
843
+ case MAC_ARG_START :
844
+ cur_out++;
845
+ /* Fall through */
846
+ case MAC_CALL_START :
847
+ cur_out++;
848
+ cur_out++;
849
+ /* Fall through */
850
+ default:
851
+ cur_out++;
852
+ break;
853
+ }
854
+ } else {
855
+ switch (*cur_out) {
856
+ case MAC_ARG_START :
857
+ case MAC_ARG_END :
858
+ cur_out++;
859
+ /* Fall through */
860
+ default:
861
+ cur_out += 3;
862
+ break;
863
+ }
864
+ }
865
+ } else {
866
+ *out_p++ = c;
867
+ }
868
+ }
869
+ *out_p = EOS;
870
+ }
871
+
872
+ return out_p;
873
+ }
874
+
875
+ static char * close_macro_inf(
876
+ char * out_p, /* Current output pointer */
877
+ int m_num, /* 'mac_num' of this macro */
878
+ int in_src_n /* Location of macro in arg */
879
+ )
880
+ /*
881
+ * Mark up closing of a macro expansion.
882
+ * Note that 'm_num' argument is necessary rather than 'm_inf' from replace(),
883
+ * because mac_inf[] may have been reallocated while rescanning.
884
+ */
885
+ {
886
+ MACRO_INF * m_inf;
887
+ LINE_COL e_line_col;
888
+
889
+ m_inf = & mac_inf[ m_num];
890
+ *out_p++ = MAC_INF; /* Magic for end of macro expansion */
891
+ *out_p++ = MAC_CALL_END;
892
+ if (option_flags.v) {
893
+ *out_p++ = (m_num / UCHARMAX) + 1;
894
+ *out_p++ = (m_num % UCHARMAX) + 1;
895
+ }
896
+ *out_p = EOS;
897
+ get_ch(); /* Clear the garbage */
898
+ unget_ch();
899
+ if (infile->fp || in_src_n) {
900
+ if (infile->fp) { /* Macro call on source file */
901
+ e_line_col.line = src_line;
902
+ e_line_col.col = infile->bptr - infile->buffer;
903
+ } else { /* Macro in argument of parent macro and from source */
904
+ e_line_col.line = in_src[ in_src_n].end_line;
905
+ e_line_col.col = in_src[ in_src_n].end_col;
906
+ }
907
+ /* Get the location before line splicing by <backslash><newline> */
908
+ /* or by a line-crossing comment */
909
+ get_src_location( & e_line_col);
910
+ m_inf->locs.end_line = e_line_col.line;
911
+ m_inf->locs.end_col = e_line_col.col;
912
+ } else {
913
+ m_inf->locs.end_col = m_inf->locs.end_line = 0L;
914
+ }
915
+
916
+ return out_p;
917
+ }
918
+
919
+ static DEFBUF * def_special(
920
+ DEFBUF * defp /* Macro definition */
921
+ )
922
+ /*
923
+ * Re-define __LINE__, __FILE__.
924
+ * Return the new definition.
925
+ */
926
+ {
927
+ const FILEINFO * file;
928
+ DEFBUF ** prevp;
929
+ int cmp;
930
+
931
+ switch (defp->nargs) {
932
+ case DEF_NOARGS_DYNAMIC - 1: /* __LINE__ */
933
+ if ((src_line > std_limits.line_num || src_line <= 0)
934
+ && (warn_level & 1))
935
+ diag_macro( CWARN
936
+ , "Line number %.0s\"%ld\" is out of range" /* _W1_ */
937
+ , NULL, src_line, NULL, defp, NULL);
938
+ sprintf( defp->repl, "%ld", src_line); /* Re-define */
939
+ break;
940
+ case DEF_NOARGS_DYNAMIC - 2: /* __FILE__ */
941
+ for (file = infile; file != NULL; file = file->parent) {
942
+ if (file->fp != NULL) {
943
+ sprintf( work_buf, "\"%s\"", file->filename);
944
+ if (str_eq( work_buf, defp->repl))
945
+ break; /* No change */
946
+ defp->nargs = DEF_NOARGS; /* Enable to redefine */
947
+ prevp = look_prev( defp->name, &cmp);
948
+ defp = install_macro( "__FILE__", DEF_NOARGS_DYNAMIC - 2, ""
949
+ , work_buf, prevp, cmp, 0); /* Re-define */
950
+ break;
951
+ }
952
+ }
953
+ break;
954
+ }
955
+ return defp;
956
+ }
957
+
958
+ static int prescan(
959
+ const DEFBUF * defp, /* Definition of the macro */
960
+ const char ** arglist, /* Pointers to actual arguments */
961
+ char * out, /* Output buffer */
962
+ char * out_end /* End of output buffer */
963
+ )
964
+ /*
965
+ * Concatenate the tokens surounding ## by catenate(), and stringize the
966
+ * argument following # by stringize().
967
+ */
968
+ {
969
+ FILEINFO * file;
970
+ char * prev_token = NULL; /* Preceding token */
971
+ char * horiz_space = NULL; /* Horizontal white space */
972
+ int c; /* Value of a character */
973
+ /*
974
+ * The replacement lists are --
975
+ * stuff1<SEP>stuff2
976
+ * or stuff1<SEP>stuff2<SEP>stuff3...
977
+ * where <SEP> is CAT, maybe with preceding space and following space,
978
+ * stuff might be
979
+ * ordinary-token
980
+ * MAC_PARM<n>
981
+ * or <QUO>MAC_PARM<n>
982
+ * where <QUO> is ST_QUO, possibly with following space.
983
+ *
984
+ * DEF_MAGIC may has been inserted sometimes.
985
+ * In other than POST_STD modes, TOK_SEP and IN_SRC may have been
986
+ * inserted, and TOK_SEPs are inserted also in this routine.
987
+ * In trace_macro mode, many magic character sequences may have been
988
+ * inserted here and there.
989
+ */
990
+
991
+ if (mcpp_mode == POST_STD) {
992
+ file = unget_string( defp->repl, defp->name);
993
+ } else {
994
+ *out++ = TOK_SEP; /* Wrap replacement */
995
+ workp = work_buf; /* text with token */
996
+ workp = stpcpy( workp, defp->repl); /* separators to */
997
+ *workp++ = TOK_SEP; /* prevent unintended*/
998
+ *workp = EOS; /* token merging. */
999
+ file = unget_string( work_buf, defp->name);
1000
+ }
1001
+
1002
+ while (c = get_ch(), file == infile) { /* To the end of repl */
1003
+
1004
+ switch (c) {
1005
+ case ST_QUOTE:
1006
+ skip_ws(); /* Skip spaces and the returned MAC_PARM*/
1007
+ c = get_ch() - 1; /* Parameter number */
1008
+ prev_token = out; /* Remember the token */
1009
+ out = stringize( defp, arglist[ c], out);
1010
+ /* Stringize without expansion */
1011
+ horiz_space = NULL;
1012
+ break;
1013
+ case CAT:
1014
+ if (*prev_token == DEF_MAGIC || *prev_token == IN_SRC) {
1015
+ /* Rare case yet possible after catenate() */
1016
+ size_t len = 1;
1017
+ /* Remove trailing white space prior to removing DEF_MAGIC */
1018
+ if (horiz_space == out - 1) {
1019
+ *--out = EOS;
1020
+ horiz_space = NULL;
1021
+ }
1022
+ if (*prev_token == IN_SRC && trace_macro)
1023
+ len = IN_SRC_LEN;
1024
+ memmove( prev_token, prev_token + len
1025
+ , strlen( prev_token + len));
1026
+ out -= len;
1027
+ *out = EOS; /* Remove DEF_MAGIC, IN_SRC */
1028
+ }
1029
+ #if COMPILER == GNUC
1030
+ if (*prev_token == ',')
1031
+ break; /* ', ##' sequence (peculiar to GCC) */
1032
+ #endif
1033
+ if (horiz_space == out - 1) {
1034
+ *--out = EOS; /* Remove trailing white space */
1035
+ horiz_space = NULL;
1036
+ }
1037
+ out = catenate( defp, arglist, out, out_end, &prev_token);
1038
+ if (char_type[ *(out - 1) & UCHARMAX] & HSP)
1039
+ horiz_space = out - 1; /* TOK_SEP has been appended */
1040
+ break;
1041
+ case MAC_PARM:
1042
+ prev_token = out;
1043
+ *out++ = MAC_PARM;
1044
+ *out++ = get_ch(); /* Parameter number */
1045
+ break;
1046
+ case TOK_SEP:
1047
+ case ' ':
1048
+ case '\t' :
1049
+ if (out - 1 == horiz_space)
1050
+ continue; /* Squeeze white spaces */
1051
+ horiz_space = out;
1052
+ *out++ = c;
1053
+ break;
1054
+ default:
1055
+ prev_token = out;
1056
+ scan_token( c, &out, out_end); /* Ordinary token */
1057
+ break;
1058
+ }
1059
+
1060
+ *out = EOS; /* Ensure termination */
1061
+ if (out_end <= out) /* Buffer overflow */
1062
+ return FALSE;
1063
+ }
1064
+
1065
+ *out = EOS; /* Ensure terminatation in case of no token */
1066
+ unget_ch();
1067
+ return TRUE;
1068
+ }
1069
+
1070
+ static char * catenate(
1071
+ const DEFBUF * defp, /* The macro definition */
1072
+ const char ** arglist, /* Pointers to actual arguments */
1073
+ char * out, /* Output buffer */
1074
+ char * out_end, /* End of output buffer */
1075
+ char ** token_p /* Address of preceding token pointer */
1076
+ )
1077
+ /*
1078
+ * Concatenate the previous and the following tokens.
1079
+ * Note: The parameter codes may coincide with white spaces or any
1080
+ * other characters.
1081
+ */
1082
+ {
1083
+ FILEINFO * file;
1084
+ char * prev_prev_token = NULL;
1085
+ const char * invalid_token
1086
+ = "Not a valid preprocessing token \"%s\""; /* _E_ _W2_ */
1087
+ const char * argp; /* Pointer to an actual argument*/
1088
+ char * prev_token = *token_p; /* Preceding token */
1089
+ int in_arg = FALSE;
1090
+ int c; /* Value of a character */
1091
+
1092
+ /* Get the previous token */
1093
+ if (*prev_token == MAC_PARM) { /* Formal parameter */
1094
+ c = (*(prev_token + 1) & UCHARMAX) - 1; /* Parm number */
1095
+ argp = arglist[ c]; /* Actual argument */
1096
+ out = prev_token; /* To overwrite */
1097
+ if (trace_macro)
1098
+ argp = remove_magics( argp, TRUE); /* Remove pair of magics */
1099
+ if ((mcpp_mode == POST_STD && *argp == EOS)
1100
+ || (mcpp_mode == STD && *argp == RT_END)) {
1101
+ *out = EOS; /* An empty argument */
1102
+ } else {
1103
+ if (mcpp_mode == POST_STD) {
1104
+ file = unget_string( argp, NULL);
1105
+ while (c = get_ch(), file == infile) {
1106
+ prev_token = out; /* Remember the last token */
1107
+ scan_token( c, &out, out_end);
1108
+ } /* Copy actual argument without expansion */
1109
+ unget_ch();
1110
+ } else {
1111
+ unget_string( argp, NULL);
1112
+ if (trace_macro)
1113
+ free( (char *) argp);
1114
+ /* malloc()ed in remove_magics() */
1115
+ while ((c = get_ch()) != RT_END) {
1116
+ prev_prev_token = prev_token;
1117
+ prev_token = out; /* Remember the last token */
1118
+ scan_token( c, &out, out_end);
1119
+ } /* Copy actual argument without expansion */
1120
+ if (*prev_token == TOK_SEP) {
1121
+ out = prev_token;
1122
+ prev_token = prev_prev_token; /* Skip separator */
1123
+ }
1124
+ }
1125
+ if (*prev_token == DEF_MAGIC
1126
+ || (mcpp_mode == STD && *prev_token == IN_SRC)) {
1127
+ size_t len = 1;
1128
+ if (trace_macro && *prev_token == IN_SRC)
1129
+ len = IN_SRC_LEN;
1130
+ memmove( prev_token, prev_token + len
1131
+ , (size_t) ((out -= len) - prev_token));
1132
+ /* Remove DEF_MAGIC enabling the name to replace later */
1133
+ }
1134
+ }
1135
+ } /* Else the previous token is an ordinary token, not an argument */
1136
+
1137
+ c = skip_ws();
1138
+
1139
+ /* Catenate */
1140
+ switch (c) {
1141
+ case ST_QUOTE: /* First stringize and then catenate */
1142
+ skip_ws(); /* Skip MAC_PARM, ST_QUOTE */
1143
+ c = get_ch() - 1;
1144
+ out = stringize( defp, arglist[ c], out);
1145
+ break;
1146
+ case MAC_PARM:
1147
+ c = get_ch() - 1; /* Parameter number */
1148
+ argp = arglist[ c]; /* Actual argument */
1149
+ if (trace_macro)
1150
+ argp = remove_magics( argp, FALSE); /* Remove pair of magics */
1151
+ if ((mcpp_mode == POST_STD && *argp == EOS)
1152
+ || (mcpp_mode == STD && *argp == RT_END)) {
1153
+ *out = EOS; /* An empty argument */
1154
+ } else {
1155
+ unget_string( argp, NULL);
1156
+ if (trace_macro)
1157
+ free( (char *) argp);
1158
+ if ((c = get_ch()) == DEF_MAGIC) { /* Remove DEF_MAGIC */
1159
+ c = get_ch(); /* enabling to replace */
1160
+ } else if (c == IN_SRC) { /* Remove IN_SRC */
1161
+ if (trace_macro) {
1162
+ get_ch(); /* Also its number */
1163
+ get_ch();
1164
+ }
1165
+ c = get_ch();
1166
+ }
1167
+ scan_token( c, &out, out_end); /* The first token */
1168
+ if (*infile->bptr) /* There are more tokens*/
1169
+ in_arg = TRUE;
1170
+ }
1171
+ break;
1172
+ case IN_SRC:
1173
+ if (trace_macro) {
1174
+ get_ch();
1175
+ get_ch();
1176
+ }
1177
+ /* Fall through */
1178
+ case DEF_MAGIC:
1179
+ c = get_ch(); /* Skip DEF_MAGIC, IN_SRC */
1180
+ /* Fall through */
1181
+ default:
1182
+ scan_token( c, &out, out_end); /* Copy the token */
1183
+ break;
1184
+ }
1185
+
1186
+ /* The generated sequence is a valid preprocessing-token ? */
1187
+ if (*prev_token) { /* There is any token */
1188
+ unget_string( prev_token, NULL); /* Scan once more */
1189
+ c = get_ch(); /* This line should be before the next line. */
1190
+ infile->fp = (FILE *)-1; /* To check token length*/
1191
+ if (mcpp_debug & EXPAND)
1192
+ dump_string( "checking generated token", infile->buffer);
1193
+ scan_token( c, (workp = work_buf, &workp), work_end);
1194
+ infile->fp = NULL;
1195
+ if (*infile->bptr != EOS) { /* More than a token */
1196
+ if (option_flags.lang_asm) { /* Assembler source */
1197
+ if (warn_level & 2)
1198
+ diag_macro( CWARN, invalid_token, prev_token, 0L, NULL
1199
+ , defp, NULL);
1200
+ } else {
1201
+ diag_macro( CERROR, invalid_token, prev_token, 0L, NULL, defp
1202
+ , NULL);
1203
+ }
1204
+ infile->bptr += strlen( infile->bptr);
1205
+ }
1206
+ get_ch(); /* To the parent "file" */
1207
+ unget_ch();
1208
+ }
1209
+
1210
+ if (mcpp_mode == STD && ! option_flags.lang_asm) {
1211
+ *out++ = TOK_SEP; /* Prevent token merging*/
1212
+ *out = EOS;
1213
+ }
1214
+ if (in_arg) { /* There are more tokens after the generated one */
1215
+ if (mcpp_mode == POST_STD) {
1216
+ file = infile;
1217
+ while (c = get_ch(), file == infile) {
1218
+ prev_token = out; /* Remember the last token */
1219
+ scan_token( c, &out, out_end);
1220
+ } /* Copy rest of argument without expansion */
1221
+ unget_ch();
1222
+ } else {
1223
+ while ((c = get_ch()) != RT_END) {
1224
+ if (c == TOK_SEP)
1225
+ continue; /* Skip separator */
1226
+ prev_token = out; /* Remember the last token */
1227
+ scan_token( c, &out, out_end);
1228
+ } /* Copy rest of argument without expansion */
1229
+ }
1230
+ }
1231
+ *token_p = prev_token; /* Report back the last token */
1232
+
1233
+ return out;
1234
+ }
1235
+
1236
+ static const char * remove_magics(
1237
+ const char * argp, /* The argument list */
1238
+ int from_last /* token is the last or first? */
1239
+ )
1240
+ /*
1241
+ * Remove pair of magic character sequences in an argument in order to catenate
1242
+ * the last or first token to another.
1243
+ * Or remove pair of magic character sequences surrounding an argument in order
1244
+ * to keep symmetry of magics.
1245
+ */
1246
+ {
1247
+ #define INIT_MAGICS 128
1248
+
1249
+ char (* mac_id)[ MAC_S_LEN];
1250
+ char (* arg_id)[ ARG_S_LEN];
1251
+ char ** mac_loc;
1252
+ char ** arg_loc;
1253
+ char * mgc_index;
1254
+ size_t max_magics;
1255
+ int mac_n, arg_n, ind, n;
1256
+ char * first = NULL;
1257
+ char * last = NULL;
1258
+ char * token;
1259
+ char * arg_p;
1260
+ char * ap;
1261
+ char * ep;
1262
+ char * tp;
1263
+ char * space = NULL;
1264
+ int with_rtend;
1265
+ int c;
1266
+ FILEINFO * file;
1267
+
1268
+ mac_id = (char (*)[ MAC_S_LEN]) xmalloc( MAC_S_LEN * INIT_MAGICS);
1269
+ arg_id = (char (*)[ ARG_S_LEN]) xmalloc( ARG_S_LEN * INIT_MAGICS * 2);
1270
+ mac_loc = (char **) xmalloc( sizeof (char *) * INIT_MAGICS);
1271
+ arg_loc = (char **) xmalloc( sizeof (char *) * INIT_MAGICS * 2);
1272
+ mgc_index = xmalloc( INIT_MAGICS * 3);
1273
+ max_magics = INIT_MAGICS;
1274
+
1275
+ mac_n = arg_n = ind = 0;
1276
+ ap = arg_p = xmalloc( strlen( argp) + 1);
1277
+ strcpy( arg_p, argp);
1278
+ ep = arg_p + strlen( arg_p);
1279
+ if (*(ep - 1) == RT_END) {
1280
+ with_rtend = TRUE;
1281
+ ep--; /* Point to RT_END */
1282
+ } else {
1283
+ with_rtend = FALSE;
1284
+ }
1285
+ file = unget_string( arg_p, NULL); /* Stack to "file" for token parsing*/
1286
+
1287
+ /* Search all the magics in argument, as well as first and last token */
1288
+ /* Read stacked arg_p and write it to arg_p as a dummy buffer */
1289
+ while ((*ap++ = c = get_ch()) != RT_END && file == infile) {
1290
+ if (c == MAC_INF) {
1291
+ if (mac_n >= max_magics || arg_n >= max_magics * 2) {
1292
+ max_magics *= 2;
1293
+ mac_id = (char (*)[ MAC_S_LEN]) xrealloc( (void *) mac_id
1294
+ , MAC_S_LEN * max_magics);
1295
+ arg_id = (char (*)[ ARG_S_LEN]) xrealloc( (void *) arg_id
1296
+ , ARG_S_LEN * max_magics * 2);
1297
+ mac_loc = (char **) xrealloc( (void *) mac_loc
1298
+ , sizeof (char *) * max_magics);
1299
+ arg_loc = (char **) xrealloc( (void *) arg_loc
1300
+ , sizeof (char *) * max_magics * 2);
1301
+ mgc_index = xrealloc( mgc_index, max_magics * 3);
1302
+ }
1303
+ *ap++ = c = get_ch();
1304
+ switch (c) {
1305
+ case MAC_CALL_START :
1306
+ *ap++ = get_ch();
1307
+ *ap++ = get_ch();
1308
+ mac_loc[ mac_n] = ap - MAC_S_LEN; /* Location of the seq */
1309
+ memcpy( mac_id[ mac_n], ap - (MAC_S_LEN - 1), MAC_S_LEN - 1);
1310
+ /* Copy the sequence from its second byte */
1311
+ mac_id[ mac_n++][ MAC_S_LEN - 1] = FALSE;
1312
+ /* Mark of to-be-removed or not */
1313
+ break;
1314
+ case MAC_ARG_START :
1315
+ *ap++ = get_ch();
1316
+ *ap++ = get_ch();
1317
+ *ap++ = get_ch();
1318
+ arg_loc[ arg_n] = ap - ARG_S_LEN;
1319
+ memcpy( arg_id[ arg_n], ap - (ARG_S_LEN - 1), ARG_S_LEN - 1);
1320
+ arg_id[ arg_n++][ ARG_S_LEN - 1] = FALSE;
1321
+ break;
1322
+ case MAC_CALL_END :
1323
+ mac_loc[ mac_n] = ap - MAC_E_LEN;
1324
+ mac_id[ mac_n][ 0] = c;
1325
+ mac_id[ mac_n++][ MAC_E_LEN_V - 1] = FALSE;
1326
+ break;
1327
+ case MAC_ARG_END :
1328
+ arg_loc[ arg_n] = ap - ARG_E_LEN;
1329
+ arg_id[ arg_n][ 0] = c;
1330
+ arg_id[ arg_n++][ ARG_E_LEN_V - 1] = FALSE;
1331
+ break;
1332
+ }
1333
+ if (option_flags.v) {
1334
+ switch (c) {
1335
+ case MAC_CALL_END :
1336
+ mac_id[ mac_n - 1][ 1] = *ap++ = get_ch();
1337
+ mac_id[ mac_n - 1][ 2] = *ap++ = get_ch();
1338
+ break;
1339
+ case MAC_ARG_END :
1340
+ arg_id[ arg_n - 1][ 1] = *ap++ = get_ch();
1341
+ arg_id[ arg_n - 1][ 2] = *ap++ = get_ch();
1342
+ arg_id[ arg_n - 1][ 3] = *ap++ = get_ch();
1343
+ break;
1344
+ }
1345
+ }
1346
+ mgc_index[ ind++] = c; /* Index to mac_id[] and arg_id[] */
1347
+ continue;
1348
+ } else if (char_type[ c & UCHARMAX] & HSP) {
1349
+ if (! first) {
1350
+ ap--; /* Skip white space on top of the argument */
1351
+ ep--;
1352
+ }
1353
+ continue;
1354
+ }
1355
+ last = --ap;
1356
+ if (! first)
1357
+ first = ap;
1358
+ if (char_type[ c & UCHARMAX] & HSP)
1359
+ space = ap; /* Remember the last white space */
1360
+ scan_token( c, &ap, ep);
1361
+ }
1362
+ if (file == infile)
1363
+ get_ch(); /* Clear the "file" */
1364
+ unget_ch();
1365
+ if (space == ep - 1)
1366
+ ep--; /* Remove trailing white space */
1367
+ if (with_rtend)
1368
+ *ep++ = RT_END;
1369
+ *ep = EOS;
1370
+ if ((from_last && !last) || (!from_last && !first))
1371
+ return arg_p;
1372
+ if (mac_n == 0 && arg_n == 0) /* No magic sequence */
1373
+ return arg_p;
1374
+ token = from_last ? last : first;
1375
+
1376
+ /* Remove pair of magics surrounding the last (or first) token */
1377
+ if (mac_n) {
1378
+ /* Remove pair of macro magics surrounding the token */
1379
+ int magic, mac_s, mac_e;
1380
+ int nest_s, nest_e;
1381
+
1382
+ nest_s = 0;
1383
+ for (mac_s = 0; mac_loc[ mac_s] < token; mac_s++) {
1384
+ magic = mac_id[ mac_s][ 0];
1385
+ if (magic == MAC_CALL_START) { /* Starting magic */
1386
+ nest_e = ++nest_s;
1387
+ /* Search the corresponding closing magic */
1388
+ for (mac_e = mac_s + 1; mac_e < mac_n; mac_e++) {
1389
+ magic = mac_id[ mac_e][ 0];
1390
+ if (magic == MAC_CALL_START) {
1391
+ nest_e++;
1392
+ } else { /* MAC_CALL_END: Closing magic */
1393
+ nest_e--;
1394
+ /* Search after the token */
1395
+ if (token < mac_loc[ mac_e] && nest_e == nest_s - 1) {
1396
+ #if DEBUG_MACRO_ANN
1397
+ if (option_flags.v)
1398
+ chk_symmetry( mac_id[ mac_s], mac_id[ mac_e]
1399
+ , MAC_E_LEN - 2);
1400
+ #endif
1401
+ mac_id[ mac_e][ MAC_S_LEN - 1] = TRUE;
1402
+ /* To be removed */
1403
+ break; /* Done for this mac_s */
1404
+ }
1405
+ }
1406
+ }
1407
+ if (mac_e < mac_n) /* Found corresponding magic */
1408
+ mac_id[ mac_s][ MAC_S_LEN - 1] = TRUE; /* To be removed*/
1409
+ else /* Not found */
1410
+ break;
1411
+ } else {
1412
+ nest_s--; /* MAC_CALL_END: Closing magic */
1413
+ }
1414
+ }
1415
+ }
1416
+ if (arg_n) {
1417
+ /* Remove pair of arg magics surrounding the token */
1418
+ int magic, arg_s, arg_e;
1419
+ int nest_s, nest_e;
1420
+
1421
+ nest_s = 0;
1422
+ for (arg_s = 0; arg_loc[ arg_s] < token; arg_s++) {
1423
+ magic = arg_id[ arg_s][ 0];
1424
+ if (magic == MAC_ARG_START) {
1425
+ nest_e = ++nest_s;
1426
+ for (arg_e = arg_s + 1; arg_e < arg_n; arg_e++) {
1427
+ magic = arg_id[ arg_e][ 0];
1428
+ if (magic == MAC_ARG_START) {
1429
+ nest_e++;
1430
+ } else {
1431
+ nest_e--;
1432
+ if (token < arg_loc[ arg_e] && nest_e == nest_s - 1) {
1433
+ #if DEBUG_MACRO_ANN
1434
+ if (option_flags.v)
1435
+ chk_symmetry( arg_id[ arg_s], arg_id[ arg_e]
1436
+ , ARG_E_LEN_V - 2);
1437
+ #endif
1438
+ arg_id[ arg_e][ ARG_S_LEN - 1] = TRUE;
1439
+ break;
1440
+ }
1441
+ }
1442
+ }
1443
+ if (arg_e < arg_n)
1444
+ arg_id[ arg_s][ ARG_S_LEN - 1] = TRUE;
1445
+ else
1446
+ break;
1447
+ } else {
1448
+ nest_s--;
1449
+ }
1450
+ }
1451
+ }
1452
+
1453
+ /* Copy the sequences skipping the to-be-removed magic seqs */
1454
+ file = unget_string( arg_p, NULL); /* Stack to "file" for token parsing*/
1455
+ tp = arg_p;
1456
+ ep = arg_p + strlen( arg_p);
1457
+ mac_n = arg_n = n = 0;
1458
+
1459
+ while ((*tp++ = c = get_ch()) != RT_END && file == infile) {
1460
+ char ** loc_tab;
1461
+ int num, mark, rm, magic;
1462
+ size_t len;
1463
+
1464
+ if (c != MAC_INF) {
1465
+ scan_token( c, (--tp, &tp), ep);
1466
+ continue;
1467
+ }
1468
+ unget_ch(); /* Pushback MAC_INF */
1469
+ tp--;
1470
+
1471
+ switch (magic = mgc_index[ n++]) {
1472
+ case MAC_CALL_START :
1473
+ len = MAC_S_LEN;
1474
+ mark = MAC_S_LEN - 1;
1475
+ break;
1476
+ case MAC_CALL_END :
1477
+ len = option_flags.v ? MAC_E_LEN_V : MAC_E_LEN;
1478
+ mark = MAC_E_LEN_V - 1;
1479
+ break;
1480
+ case MAC_ARG_START :
1481
+ len = ARG_S_LEN;
1482
+ mark = ARG_S_LEN - 1;
1483
+ break;
1484
+ case MAC_ARG_END :
1485
+ len = option_flags.v ? ARG_E_LEN_V : ARG_E_LEN;
1486
+ mark = ARG_E_LEN_V - 1;
1487
+ break;
1488
+ }
1489
+ switch (magic) {
1490
+ case MAC_CALL_START :
1491
+ case MAC_CALL_END :
1492
+ loc_tab = mac_loc;
1493
+ num = mac_n;
1494
+ rm = mac_id[ mac_n++][ mark];
1495
+ break;
1496
+ case MAC_ARG_START :
1497
+ case MAC_ARG_END :
1498
+ loc_tab = arg_loc;
1499
+ num = arg_n;
1500
+ rm = arg_id[ arg_n++][ mark];
1501
+ break;
1502
+ }
1503
+ if (rm == FALSE) { /* Not to be removed */
1504
+ memmove( tp, loc_tab[ num], len);
1505
+ /* Copy it (from arg_p buffer for convenience) */
1506
+ tp += len;
1507
+ }
1508
+ infile->bptr += len;
1509
+ }
1510
+ if (! with_rtend)
1511
+ tp--;
1512
+ *tp = EOS;
1513
+ if (file == infile)
1514
+ get_ch(); /* Clear the "file" */
1515
+ unget_ch();
1516
+
1517
+ return arg_p;
1518
+ }
1519
+
1520
+ #if DEBUG_MACRO_ANN
1521
+ static void chk_symmetry(
1522
+ char * start_id, /* Sequence of macro (or arg) starting inf */
1523
+ char * end_id, /* Sequence of macro (or arg) closing inf */
1524
+ size_t len /* Length of the sequence */
1525
+ )
1526
+ /*
1527
+ * Check whether starting sequence and corresponding closing sequence is the
1528
+ * same.
1529
+ */
1530
+ {
1531
+ int s_id, e_id, arg_s_n, arg_e_n;
1532
+
1533
+ if (memcmp( start_id + 1, end_id + 1, len) == 0)
1534
+ return; /* The sequences are the same */
1535
+ s_id = ((start_id[ 1] & UCHARMAX) - 1) * UCHARMAX;
1536
+ s_id += (start_id[ 2] & UCHARMAX) - 1;
1537
+ e_id = ((end_id[ 1] & UCHARMAX) - 1) * UCHARMAX;
1538
+ e_id += (end_id[ 2] & UCHARMAX) - 1;
1539
+ if (len >= 3) {
1540
+ arg_s_n = (start_id[ 3] & UCHARMAX) - 1;
1541
+ arg_e_n = (end_id[ 3] & UCHARMAX) - 1;
1542
+ mcpp_fprintf( ERR,
1543
+ "Asymmetry of arg inf found removing magics: start %d:%d, end: %d:%d at line:%d\n"
1544
+ , s_id, arg_s_n, e_id, arg_e_n, src_line);
1545
+ } else {
1546
+ mcpp_fprintf( ERR,
1547
+ "Asymmetry of macro inf found removing magics: start %d, end: %d at line:%d\n"
1548
+ , s_id, e_id, src_line);
1549
+ }
1550
+ }
1551
+ #endif
1552
+
1553
+ static char * stringize(
1554
+ const DEFBUF * defp, /* The macro definition */
1555
+ const char * argp, /* Pointer to argument */
1556
+ char * out /* Output buffer */
1557
+ )
1558
+ /*
1559
+ * Make a string literal from an argument.
1560
+ */
1561
+ {
1562
+ char arg_end_inf[ 8][ ARG_E_LEN_V - 1];
1563
+ /* Verbose information of macro arguments */
1564
+ FILEINFO * file;
1565
+ int stray_bsl = FALSE; /* '\\' not in literal */
1566
+ char * out_p = out;
1567
+ int token_type;
1568
+ int num_arg_magic = 0;
1569
+ size_t len;
1570
+ size_t arg_e_len = option_flags.v ? ARG_E_LEN_V : ARG_E_LEN;
1571
+ int c;
1572
+
1573
+ if (trace_macro) {
1574
+ while ((*argp == MAC_INF && *(argp + 1) == MAC_ARG_START)
1575
+ /* Argument is prefixed with macro tracing magics */
1576
+ || (char_type[ *argp & UCHARMAX] & HSP)) {
1577
+ if (*argp == MAC_INF) { /* Move magics to outside of string */
1578
+ memcpy( out_p, argp, ARG_S_LEN);
1579
+ out_p += ARG_S_LEN;
1580
+ argp += ARG_S_LEN;
1581
+ num_arg_magic++;
1582
+ } else { /* Skip white spaces */
1583
+ argp++;
1584
+ }
1585
+ }
1586
+ }
1587
+
1588
+ file = unget_string( argp, NULL);
1589
+ len = strlen( infile->buffer); /* Sequence ends with RT_END */
1590
+ if (trace_macro) { /* Remove suffixed argument closing magics */
1591
+ /* There are 0 or more argument closing magic sequences and */
1592
+ /* 0 or more TOK_SEPs and no space at the end of argp. */
1593
+ /* This is assured by get_an_arg(). */
1594
+ int nmagic = 0;
1595
+ while (len > arg_e_len
1596
+ && (((*(infile->buffer + len - arg_e_len - 1) == MAC_INF
1597
+ && *(infile->buffer + len - arg_e_len) == MAC_ARG_END)
1598
+ || *(infile->buffer + len - 2) == TOK_SEP))) {
1599
+ if (*(infile->buffer + len - arg_e_len - 1) == MAC_INF
1600
+ && *(infile->buffer + len - arg_e_len) == MAC_ARG_END) {
1601
+ if (option_flags.v) {
1602
+ memcpy( arg_end_inf[ nmagic]
1603
+ , infile->buffer + len - arg_e_len + 1
1604
+ , arg_e_len - 2);
1605
+ arg_end_inf[ nmagic][ arg_e_len - 2] = EOS;
1606
+ }
1607
+ nmagic++;
1608
+ len -= arg_e_len;
1609
+ *(infile->buffer + len - 1) = RT_END;
1610
+ *(infile->buffer + len) = EOS;
1611
+ } else if (*(infile->buffer + len - 2) == TOK_SEP) {
1612
+ len--;
1613
+ *(infile->buffer + len - 1) = RT_END;
1614
+ *(infile->buffer + len) = EOS;
1615
+ }
1616
+ }
1617
+ if (nmagic != num_arg_magic) { /* There are some imbalances */
1618
+ /* Some surrounding magics correspond to intervening ones. */
1619
+ /* So, unmatched surrounding magics should be removed. */
1620
+ if (num_arg_magic > nmagic) {
1621
+ num_arg_magic = nmagic; /* Ignore the surplus */
1622
+ out_p = out + ARG_S_LEN * num_arg_magic;
1623
+ } /* Else simply ignore the surplus nmagic */
1624
+ }
1625
+ }
1626
+ *out_p++ = '"'; /* Starting quote */
1627
+
1628
+ while ((c = get_ch()), ((mcpp_mode == POST_STD && file == infile)
1629
+ || (mcpp_mode == STD && c != RT_END))) {
1630
+ if (c == ' ' || c == '\t') {
1631
+ *out_p++ = c;
1632
+ continue;
1633
+ } else if (c == TOK_SEP) {
1634
+ continue; /* Skip inserted separator */
1635
+ } else if (c == IN_SRC) { /* Skip magics */
1636
+ if (trace_macro) {
1637
+ get_ch();
1638
+ get_ch();
1639
+ }
1640
+ continue;
1641
+ } else if (c == '\\') {
1642
+ stray_bsl = TRUE; /* May cause a trouble */
1643
+ } else if (c == MAC_INF) { /* Remove intervening magics */
1644
+ switch (c = get_ch()) {
1645
+ case MAC_ARG_START :
1646
+ get_ch();
1647
+ /* Fall through */
1648
+ case MAC_CALL_START :
1649
+ get_ch();
1650
+ get_ch();
1651
+ break;
1652
+ }
1653
+ if (option_flags.v) {
1654
+ switch (c) {
1655
+ case MAC_ARG_END :
1656
+ get_ch();
1657
+ /* Fall through */
1658
+ case MAC_CALL_END :
1659
+ get_ch();
1660
+ get_ch();
1661
+ break;
1662
+ }
1663
+ }
1664
+ continue;
1665
+ }
1666
+ token_type = scan_token( c, (workp = work_buf, &workp), work_end);
1667
+
1668
+ switch (token_type) {
1669
+ case WSTR:
1670
+ case WCHR:
1671
+ case STR:
1672
+ case CHR:
1673
+ workp = work_buf;
1674
+ while ((c = *workp++ & UCHARMAX) != EOS) {
1675
+ if (char_type[ c] & mbchk) { /* Multi-byte character */
1676
+ mb_read( c, &workp, (*out_p++ = c, &out_p));
1677
+ /* Copy as it is */
1678
+ continue;
1679
+ } else if (c == '"') {
1680
+ *out_p++ = '\\'; /* Insert '\\' */
1681
+ } else if (c == '\\') {
1682
+ #if OK_UCN
1683
+ if (mcpp_mode == POST_STD || ! stdc3
1684
+ || (*workp != 'u' && *workp != 'U'))
1685
+ /* Not UCN */
1686
+ #endif
1687
+ *out_p++ = '\\';
1688
+ }
1689
+ *out_p++ = c;
1690
+ }
1691
+ *out_p = EOS;
1692
+ break;
1693
+ default:
1694
+ out_p = stpcpy( out_p, work_buf);
1695
+ break;
1696
+ }
1697
+ }
1698
+
1699
+ if (mcpp_mode == POST_STD)
1700
+ unget_ch();
1701
+ *out_p++ = '"'; /* Closing quote */
1702
+ if (trace_macro) {
1703
+ while (num_arg_magic--) {
1704
+ *out_p++ = MAC_INF; /* Restore removed magic*/
1705
+ *out_p++ = MAC_ARG_END;
1706
+ if (option_flags.v)
1707
+ out_p = stpcpy( out_p, arg_end_inf[ num_arg_magic]);
1708
+ }
1709
+ }
1710
+ *out_p = EOS;
1711
+
1712
+ if (stray_bsl) { /* '\\' outside of quotation has been found */
1713
+ int invalid = FALSE;
1714
+ unget_string( out, defp->name);
1715
+ if (mcpp_debug & EXPAND)
1716
+ dump_string( "checking generated token", infile->buffer);
1717
+ scan_quote( get_ch(), work_buf, work_end, TRUE);
1718
+ /* Unterminated or too long string will be diagnosed */
1719
+ if (*infile->bptr != EOS) /* More than a token */
1720
+ invalid = TRUE; /* Diagnose after clearing the "file" */
1721
+ infile->bptr += strlen( infile->bptr);
1722
+ get_ch(); /* Clear the "file" */
1723
+ unget_ch();
1724
+ if (invalid)
1725
+ diag_macro( CERROR
1726
+ , "Not a valid string literal %s" /* _E_ */
1727
+ , out, 0L, NULL, defp, NULL);
1728
+ }
1729
+ #if NWORK-2 > SLEN90MIN
1730
+ else if ((warn_level & 4) && out_p - out > std_limits.str_len)
1731
+ diag_macro( CWARN
1732
+ , "String literal longer than %.0s%ld bytes %s" /* _W4_ */
1733
+ , NULL , (long) std_limits.str_len, out, defp, NULL);
1734
+ #endif
1735
+ return out_p;
1736
+ }
1737
+
1738
+ static char * substitute(
1739
+ const DEFBUF * defp, /* The macro getting arguments */
1740
+ const char ** arglist, /* Pointers to actual arguments */
1741
+ const char * in, /* Replacement text */
1742
+ char * out, /* Output buffer */
1743
+ char * out_end /* End of output buffer */
1744
+ )
1745
+ /*
1746
+ * Replace completely each actual arguments of the macro, and substitute for
1747
+ * the formal parameters in the replacement list.
1748
+ */
1749
+ {
1750
+ char * out_start = out;
1751
+ const char * arg;
1752
+ int c;
1753
+ int gvar_arg; /* gvar_arg'th argument is GCC variable argument */
1754
+
1755
+ gvar_arg = (defp->nargs & GVA_ARGS) ? (defp->nargs & ~AVA_ARGS) : 0;
1756
+ *out = EOS; /* Ensure to termanate */
1757
+
1758
+ while ((c = *in++) != EOS) {
1759
+ if (c == MAC_PARM) { /* Formal parameter */
1760
+ c = *in++ & UCHARMAX; /* Parameter number */
1761
+ if (mcpp_debug & EXPAND) {
1762
+ mcpp_fprintf( DBG, " (expanding arg[%d])", c);
1763
+ dump_string( NULL, arglist[ c - 1]);
1764
+ }
1765
+ #if COMPILER == GNUC || COMPILER == MSC
1766
+ arg = arglist[ c - 1];
1767
+ if (trace_macro) {
1768
+ if (*arg == MAC_INF) {
1769
+ if (*++arg == MAC_ARG_START)
1770
+ arg += ARG_S_LEN - 1; /* Next to magic chars */
1771
+ }
1772
+ }
1773
+ #if COMPILER == GNUC
1774
+ if (c == gvar_arg && *arg == RT_END && ! ansi) {
1775
+ /*
1776
+ * GCC variadic macro and its variable argument is absent.
1777
+ * Note that in its "strict-ansi" mode GCC does not remove
1778
+ * ',', nevertheless it ignores '##' (inconsistent
1779
+ * behavior). Though GCC2 changes behavior depending the
1780
+ * ',' is preceded by space or not, we only count on the
1781
+ * "strict-ansi" flag.
1782
+ */
1783
+ #else
1784
+ if ((defp->nargs & VA_ARGS) && c == (defp->nargs & ~VA_ARGS)
1785
+ && *arg == RT_END && mcpp_mode == STD) {
1786
+ /* Visual C 2005 also removes ',' immediately preceding */
1787
+ /* absent variable arguments. It does not use '##' though. */
1788
+ #endif
1789
+ char * tmp;
1790
+ tmp = out - 1;
1791
+ while (char_type[ *tmp & UCHARMAX] & HSP)
1792
+ tmp--;
1793
+ if (*tmp == ',') {
1794
+ out = tmp; /* Remove the immediately preceding ',' */
1795
+ if (warn_level & 1) {
1796
+ *out = EOS;
1797
+ diag_macro( CWARN,
1798
+ "Removed ',' preceding the absent variable argument: %s" /* _W1_ */
1799
+ , out_start, 0L, NULL, defp, NULL);
1800
+ }
1801
+ }
1802
+ } else
1803
+ #endif
1804
+ if ((out = rescan( NULL, arglist[ c - 1], out, out_end))
1805
+ == NULL) { /* Replace completely */
1806
+ return NULL; /* Error */
1807
+ }
1808
+ } else {
1809
+ *out++ = c; /* Copy the character */
1810
+ }
1811
+ }
1812
+ *out = EOS;
1813
+ return out;
1814
+ }
1815
+
1816
+ static char * rescan(
1817
+ const DEFBUF * outer, /* Outer macro just replacing */
1818
+ const char * in, /* Sequences to be rescanned */
1819
+ char * out, /* Output buffer */
1820
+ char * out_end /* End of output buffer */
1821
+ )
1822
+ /*
1823
+ * Re-scan the once replaced sequences to replace the remaining macros
1824
+ * completely.
1825
+ * rescan() and replace() call each other recursively.
1826
+ *
1827
+ * Note: POST_STD mode does not use IN_SRC nor TOK_SEP and seldom uses RT_END.
1828
+ * Checking of those are unnecessary overhead for POST_STD mode. To integrate
1829
+ * the code for POST_STD with STD mode, however, we use these checkings
1830
+ * commonly.
1831
+ * Also compat_mode does not use IN_SRC unless in trace_macro mode.
1832
+ * STD mode has macro notification mode (trace_macro mode), too. Its routines
1833
+ * are complicated and not easy to understand.
1834
+ */
1835
+ {
1836
+ char * cur_cp = NULL;
1837
+ char * tp = NULL; /* Temporary pointer into buffer*/
1838
+ char * out_p = out; /* Current output pointer */
1839
+ FILEINFO * file; /* Input sequences stacked on a "file" */
1840
+ DEFBUF * inner; /* Inner macro to replace */
1841
+ int c; /* First character of token */
1842
+ int token_type;
1843
+ char * mac_arg_start = NULL;
1844
+ #if COMPILER == GNUC
1845
+ int within_defined = FALSE;
1846
+ int within_defined_arg_depth = 0;
1847
+ #endif
1848
+
1849
+ if (mcpp_debug & EXPAND) {
1850
+ mcpp_fprintf( DBG, "rescan_level--%d (%s) "
1851
+ , rescan_level + 1, outer ? outer->name : "<arg>");
1852
+ dump_string( "rescan entry", in);
1853
+ }
1854
+ if (! disable_repl( outer)) /* Don't re-replace replacing macro */
1855
+ return NULL; /* Too deeply nested macro call */
1856
+ if (mcpp_mode == STD) {
1857
+ get_ch(); /* Clear empty "file"s */
1858
+ unget_ch(); /* for diagnostic */
1859
+ cur_cp = infile->bptr; /* Remember current location */
1860
+ }
1861
+ file = unget_string( in, outer ? outer->name : NULL);
1862
+ /* Stack input on a "file" */
1863
+
1864
+ while ((c = get_ch()), file == infile
1865
+ /* Rescanning is limited to the "file" */
1866
+ && c != RT_END) {
1867
+ /*
1868
+ * This is the trick of STD mode. collect_args() via replace()
1869
+ * may read over to file->parent (provided the "file" is macro)
1870
+ * unless stopped by RT_END.
1871
+ */
1872
+ size_t len = 0;
1873
+
1874
+ if (char_type[ c] & HSP) {
1875
+ *out_p++ = c;
1876
+ continue;
1877
+ } else if (c == MAC_INF) { /* Only in STD mode */
1878
+ *out_p++ = c;
1879
+ *out_p++ = c = get_ch();
1880
+ switch (c) {
1881
+ case MAC_ARG_START :
1882
+ mac_arg_start = out_p - 2; /* Remember the position */
1883
+ *out_p++ = get_ch();
1884
+ /* Fall through */
1885
+ case MAC_CALL_START :
1886
+ *out_p++ = get_ch();
1887
+ *out_p++ = get_ch();
1888
+ break;
1889
+ case MAC_ARG_END :
1890
+ if (! option_flags.v)
1891
+ break;
1892
+ else
1893
+ *out_p++ = get_ch();
1894
+ /* Fall through */
1895
+ case MAC_CALL_END :
1896
+ if (option_flags.v) {
1897
+ *out_p++ = get_ch();
1898
+ *out_p++ = get_ch();
1899
+ }
1900
+ break;
1901
+ } /* Pass these characters as they are */
1902
+ continue;
1903
+ }
1904
+ token_type = scan_token( c, (tp = out_p, &out_p), out_end);
1905
+ #if COMPILER == GNUC
1906
+ if (mcpp_mode == STD) {
1907
+ /* Pass stuff within defined() as they are, if in_directive */
1908
+ if ((within_defined || within_defined_arg_depth)) {
1909
+ if (c == '(') {
1910
+ within_defined_arg_depth++;
1911
+ within_defined = FALSE;
1912
+ } else if (within_defined_arg_depth && c == ')') {
1913
+ within_defined_arg_depth--;
1914
+ } /* Else should be a name (possibly macro) */
1915
+ continue;
1916
+ } else if (token_type == NAM && in_directive
1917
+ && str_eq(identifier, "defined")) {
1918
+ within_defined = TRUE;
1919
+ /* 'defined' token in directive line */
1920
+ continue;
1921
+ }
1922
+ }
1923
+ #endif
1924
+ if (mcpp_mode == STD && c == IN_SRC)
1925
+ len = trace_macro ? IN_SRC_LEN : 1;
1926
+ if (token_type == NAM && c != DEF_MAGIC
1927
+ && (inner = look_id( tp + len)) != NULL) { /* A macro name */
1928
+ int is_able; /* Macro is not "blue-painted" */
1929
+ char * endf = NULL; /* Output stream at end of infile */
1930
+ MAGIC_SEQ mgc_seq; /* Magics between macro name and '(' */
1931
+
1932
+ if (trace_macro)
1933
+ memset( &mgc_seq, 0, sizeof (MAGIC_SEQ));
1934
+ if (is_macro_call( inner, &out_p, &endf
1935
+ , trace_macro ? &mgc_seq : NULL)
1936
+ && ((mcpp_mode == POST_STD && is_able_repl( inner))
1937
+ || (mcpp_mode == STD
1938
+ && (((is_able = is_able_repl( inner)) == YES)
1939
+ || (is_able == READ_OVER
1940
+ && (c == IN_SRC || compat_mode)))))) {
1941
+ /* Really a macro call */
1942
+ LINE_COL in_src_line_col = { 0L, 0};
1943
+ int in_src_n = 0;
1944
+
1945
+ if (trace_macro) {
1946
+ if (c == IN_SRC) { /* Macro in argument from source */
1947
+ /* Get the location in source */
1948
+ in_src_n = ((*(tp + 1) & UCHARMAX) - 1) * UCHARMAX;
1949
+ in_src_n += (*(tp + 2) & UCHARMAX) - 1;
1950
+ in_src_line_col.line = in_src[ in_src_n].start_line;
1951
+ in_src_line_col.col = in_src[ in_src_n].start_col;
1952
+ }
1953
+ if (inner->nargs >= 0 && mgc_seq.magic_start) {
1954
+ /* Magic sequence is found between macro */
1955
+ /* name and '('. This is a nuisance. */
1956
+ char * mgc_cleared;
1957
+ size_t seq_len;
1958
+ size_t arg_elen = option_flags.v ? ARG_E_LEN_V
1959
+ : ARG_E_LEN;
1960
+ if ((tp - ARG_S_LEN) == mac_arg_start
1961
+ && *mgc_seq.magic_start == MAC_INF
1962
+ && *(mgc_seq.magic_start + 1) == MAC_ARG_END) {
1963
+ /* Name of function-like macro is surrounded by */
1964
+ /* magics, which were inserted by outer macro. */
1965
+ /* Remove the starting magic. (The closing magic*/
1966
+ /* has already been removed by is_macro_call(). */
1967
+ tp -= ARG_S_LEN;
1968
+ mgc_seq.magic_start += arg_elen; /* Next seq */
1969
+ }
1970
+ /* Restore once skipped magic sequences, */
1971
+ /* then remove "pair"s of sequences. */
1972
+ seq_len = mgc_seq.magic_end - mgc_seq.magic_start;
1973
+ if (seq_len) {
1974
+ insert_to_bptr( mgc_seq.magic_start, seq_len);
1975
+ mgc_cleared = remove_magics(
1976
+ (const char *) infile->bptr, FALSE);
1977
+ /* Remove pair of magics */
1978
+ strcpy( infile->bptr, mgc_cleared);
1979
+ free( mgc_cleared);
1980
+ }
1981
+ }
1982
+ }
1983
+ if ((out_p = replace( inner, tp, out_end, outer, file
1984
+ , in_src_line_col, in_src_n)) == NULL)
1985
+ break; /* Error of macro call */
1986
+ } else {
1987
+ if (endf && strlen( endf)) {
1988
+ /* Has read over to parent file: another nuisance. */
1989
+ /* Restore the read-over sequence into current buffer. */
1990
+ /* Don't use unget_string() here. */
1991
+ insert_to_bptr( endf, out_p - endf);
1992
+ out_p = endf;
1993
+ *out_p = EOS;
1994
+ }
1995
+ if ((is_able = is_able_repl( inner)) == NO
1996
+ || (mcpp_mode == STD && is_able == READ_OVER
1997
+ && c != IN_SRC && ! compat_mode)) {
1998
+ if (mcpp_mode == POST_STD || c != IN_SRC)
1999
+ memmove( tp + 1, tp, (size_t) (out_p++ - tp));
2000
+ *tp = DEF_MAGIC; /* Mark not to replace */
2001
+ } /* Else not a macro call*/
2002
+ }
2003
+ }
2004
+ if (out_end <= out_p) {
2005
+ *out_p = EOS;
2006
+ diag_macro( CERROR, macbuf_overflow, outer ? outer->name : in, 0L
2007
+ , out, outer, inner);
2008
+ out_p = NULL;
2009
+ break;
2010
+ }
2011
+ }
2012
+
2013
+ if (out_p) {
2014
+ *out_p = EOS;
2015
+ if (mcpp_mode == STD) {
2016
+ if (c != RT_END) {
2017
+ unget_ch();
2018
+ if (outer != NULL) { /* outer isn't a macro in argument */
2019
+ if (infile && infile->bptr != cur_cp
2020
+ /* Have overrun replacement list*/
2021
+ && !(tp && *tp == DEF_MAGIC)
2022
+ /* Macro is enabled */
2023
+ && ((!compat_mode && (warn_level & 1))
2024
+ || (compat_mode && (warn_level & 8)))) {
2025
+ diag_macro( CWARN,
2026
+ "Replacement text \"%s\" of macro %.0ld\"%s\" involved subsequent text" /* _W1_ */
2027
+ , in, 0L, outer->name, outer, inner);
2028
+ }
2029
+ }
2030
+ } /* Else remove RT_END */
2031
+ } else {
2032
+ unget_ch();
2033
+ }
2034
+ }
2035
+ enable_repl( outer, TRUE); /* Enable macro for later text */
2036
+ if (mcpp_debug & EXPAND) {
2037
+ mcpp_fprintf( DBG, "rescan_level--%d (%s) "
2038
+ , rescan_level + 1, outer ? outer->name : "<arg>");
2039
+ dump_string( "rescan exit", out);
2040
+ }
2041
+ return out_p;
2042
+ }
2043
+
2044
+ static int disable_repl(
2045
+ const DEFBUF * defp
2046
+ )
2047
+ /*
2048
+ * Register the macro name currently replacing.
2049
+ */
2050
+ {
2051
+ if (defp == NULL)
2052
+ return TRUE;
2053
+ if (rescan_level >= RESCAN_LIMIT) {
2054
+ diag_macro( CERROR,
2055
+ "Rescanning macro \"%s\" more than %ld times at \"%s\"" /* _E_ */
2056
+ , macro_name, (long) RESCAN_LIMIT, defp->name, defp, NULL);
2057
+ return FALSE;
2058
+ }
2059
+ replacing[ rescan_level].def = defp;
2060
+ replacing[ rescan_level++].read_over = NO;
2061
+ return TRUE;
2062
+ }
2063
+
2064
+ static void enable_repl(
2065
+ const DEFBUF * defp,
2066
+ int done
2067
+ )
2068
+ /*
2069
+ * Un-register the macro name just replaced for later text.
2070
+ */
2071
+ {
2072
+ if (defp == NULL)
2073
+ return;
2074
+ replacing[ rescan_level - 1].def = NULL;
2075
+ if (done && rescan_level)
2076
+ rescan_level--;
2077
+ }
2078
+
2079
+ static int is_able_repl(
2080
+ const DEFBUF * defp
2081
+ )
2082
+ /*
2083
+ * The macro is permitted to replace ?
2084
+ */
2085
+ {
2086
+ int i;
2087
+
2088
+ if (defp == NULL)
2089
+ return YES;
2090
+ for (i = rescan_level-1; i >= 0; i--) {
2091
+ if (defp == replacing[ i].def)
2092
+ return replacing[ i].read_over;
2093
+ }
2094
+ return YES;
2095
+ }
2096
+
2097
+ static char * insert_to_bptr(
2098
+ char * ins, /* Sequence to be inserted */
2099
+ size_t len /* Byte to be inserted */
2100
+ )
2101
+ /*
2102
+ * Insert a sequence into infile->bptr.
2103
+ * infile->buffer is reallocated to ensure buffer size.
2104
+ * This routine changes absolute address of infile->bptr, hence rescan() emits
2105
+ * a "Replacement text ... involved subsequent text" warning. Anyway,
2106
+ * a macro which needs this routine deserves that warning.
2107
+ */
2108
+ {
2109
+ size_t bptr_offset = infile->bptr - infile->buffer;
2110
+
2111
+ if (infile->fp == NULL) { /* Not source file */
2112
+ infile->buffer = xrealloc( infile->buffer
2113
+ , strlen( infile->buffer) + len + 1);
2114
+ infile->bptr = infile->buffer + bptr_offset;
2115
+ }
2116
+ memmove( infile->bptr + len, infile->bptr, strlen( infile->bptr) + 1);
2117
+ memcpy( infile->bptr, ins, len);
2118
+
2119
+ return infile->buffer;
2120
+ }
2121
+
2122
+ /*
2123
+ * M a c r o E x p a n s i o n i n P R E - S T A N D A R D M o d e
2124
+ */
2125
+
2126
+ #include "setjmp.h"
2127
+
2128
+ static jmp_buf jump;
2129
+
2130
+ static char * arglist_pre[ NMACPARS]; /* Pointers to args */
2131
+
2132
+ static int rescan_pre( int c, char * mp, char * mac_end);
2133
+ /* Replace a macro repeatedly */
2134
+ static int replace_pre( DEFBUF * defp);
2135
+ /* Replace a macro once */
2136
+ static void substitute_pre( DEFBUF * defp);
2137
+ /* Substitute parms with args */
2138
+
2139
+ static char * expand_prestd(
2140
+ DEFBUF * defp, /* Macro definition */
2141
+ char * out, /* Output buffer */
2142
+ char * out_end, /* End of output buffer */
2143
+ LINE_COL line_col, /* Location of macro (not used in prestd) */
2144
+ int * pragma_op /* Flag of _Pragma (not used in prestd) */
2145
+ )
2146
+ /*
2147
+ * Expand a macro call completely, write the results to the specified buffer
2148
+ * and return the advanced pointer.
2149
+ */
2150
+ {
2151
+ char macrobuf[ NMACWORK + IDMAX]; /* Buffer for rescan_pre() */
2152
+ char * mac_end = &macrobuf[ NMACWORK]; /* End of macrobuf[] */
2153
+ char * out_p; /* Pointer into out[] */
2154
+ char * mp = macrobuf; /* Pointer into macrobuf*/
2155
+ int len; /* Length of a token */
2156
+ int token_type; /* Type of token */
2157
+ int c;
2158
+
2159
+ macro_line = src_line; /* Line number for diag.*/
2160
+ unget_string( identifier, identifier); /* To re-read */
2161
+ macro_name = defp->name;
2162
+ rescan_level = 0;
2163
+ if (setjmp( jump) == 1) {
2164
+ skip_macro();
2165
+ mp = macrobuf;
2166
+ *mp = EOS;
2167
+ macro_line = MACRO_ERROR;
2168
+ goto err_end;
2169
+ }
2170
+
2171
+ while ((c = get_ch()) != CHAR_EOF && infile->fp == NULL) {
2172
+ /* While the input stream is a macro */
2173
+ while (c == ' ' || c == '\t') { /* Output the spaces */
2174
+ *mp++ = c;
2175
+ c = get_ch();
2176
+ if (infile == NULL || infile->fp != NULL)
2177
+ goto exp_end;
2178
+ }
2179
+ token_type = rescan_pre( c, mp, mac_end); /* Scan token */
2180
+ /* and expand. Result of expansion is written at mp. */
2181
+
2182
+ switch (token_type) {
2183
+ case STR: /* String literal */
2184
+ case CHR: /* Character constant */
2185
+ case NUM: /* Number token */
2186
+ case OPE: /* Operator or punct. */
2187
+ case NAM: /* Identifier */
2188
+ len = strlen( mp);
2189
+ mp += len;
2190
+ break;
2191
+ case SEP: /* Special character */
2192
+ switch( *mp) {
2193
+ case COM_SEP:
2194
+ if (mcpp_mode == OLD_PREP)
2195
+ break; /* Zero-length comment is removed now */
2196
+ /* Else fall through */
2197
+ default: /* Who knows ? */
2198
+ mp++; /* Copy the character */
2199
+ break;
2200
+ }
2201
+ break;
2202
+ case NO_TOKEN: break; /* End of file */
2203
+ default: /* Unkown token char. */
2204
+ mp++; /* Copy the character */
2205
+ break;
2206
+ }
2207
+
2208
+ if (mac_end <= mp) {
2209
+ *mp = EOS;
2210
+ cerror( macbuf_overflow, macro_name, 0L, macrobuf);
2211
+ longjmp( jump, 1);
2212
+ }
2213
+ if (mcpp_debug & GETC) {
2214
+ *mp = EOS;
2215
+ dump_string( "macrobuf", macrobuf);
2216
+ }
2217
+ }
2218
+
2219
+ exp_end:
2220
+ unget_ch();
2221
+ while (macrobuf < mp && (*(mp - 1) == ' ' || *(mp - 1) == '\t'))
2222
+ mp--; /* Remove trailing blank */
2223
+ macro_line = 0;
2224
+ *mp = EOS;
2225
+ if (mp - macrobuf > out_end - out) {
2226
+ cerror( macbuf_overflow, macro_name, 0L, macrobuf);
2227
+ macro_line = MACRO_ERROR;
2228
+ }
2229
+ err_end:
2230
+ out_p = stpcpy( out, macrobuf);
2231
+ if (mcpp_debug & EXPAND) {
2232
+ dump_string( "expand_prestd exit", out);
2233
+ }
2234
+ macro_name = NULL;
2235
+ clear_exp_mac();
2236
+ *pragma_op = FALSE;
2237
+ return out_p;
2238
+ }
2239
+
2240
+ static int rescan_pre(
2241
+ int c, /* First character of token */
2242
+ char * mp, /* Output buffer */
2243
+ char * mac_end /* End of output buffer */
2244
+ )
2245
+ /*
2246
+ * If the token is a macro name, replace the macro repeatedly until the first
2247
+ * token becomes a non-macro and return the type of token after expansion.
2248
+ */
2249
+ {
2250
+ int token_type; /* Type of token */
2251
+ char * cp = mp; /* Value of mp should not be changed */
2252
+ DEFBUF * defp;
2253
+ FILEINFO * file;
2254
+
2255
+ while ((token_type = scan_token( c, &cp, mac_end)) == NAM
2256
+ && (defp = look_id( identifier)) != NULL) { /* Macro */
2257
+ if (replace_pre( defp) == FALSE)
2258
+ break; /* Macro name with no argument */
2259
+ file = infile;
2260
+ c = get_ch();
2261
+ if (file != infile) { /* Replaced to 0 token */
2262
+ unget_ch();
2263
+ token_type = NO_TOKEN;
2264
+ break;
2265
+ }
2266
+ cp = mp; /* Overwrite on the macro call */
2267
+ } /* The macro call is replaced */
2268
+ return token_type;
2269
+ }
2270
+
2271
+ static int replace_pre(
2272
+ DEFBUF * defp /* Definition of the macro */
2273
+ )
2274
+ /*
2275
+ * Replace a macro one level. Called from expand_prestd() (via rescan_pre())
2276
+ * when an identifier is found in the macro table. It calls collect_args()
2277
+ * to parse actual arguments, checking for the correct number. It then
2278
+ * creates a "file" containing single line containing the replacement text
2279
+ * with the actual arguments inserted appropriately. This is "pushed back"
2280
+ * onto the input stream. (When get_ch() routine runs off the end of the macro
2281
+ * line, it will dismiss the macro itself.)
2282
+ */
2283
+ {
2284
+ int arg_len;
2285
+ int c;
2286
+
2287
+ if (mcpp_debug & EXPAND) {
2288
+ dump_a_def( "replace_pre entry", defp, FALSE, TRUE, fp_debug);
2289
+ dump_unget( "replace_pre entry");
2290
+ }
2291
+ if (++rescan_level >= PRESTD_RESCAN_LIMIT) {
2292
+ diag_macro( CERROR
2293
+ , "Recursive macro definition of \"%s\"" /* _E_ */
2294
+ , defp->name, 0L, NULL, defp, NULL);
2295
+ longjmp( jump, 1);
2296
+ }
2297
+
2298
+ /*
2299
+ * Here's a macro to replace.
2300
+ */
2301
+ switch (defp->nargs) {
2302
+ case DEF_NOARGS: /* No argument just stuffs */
2303
+ case DEF_NOARGS_PREDEF_OLD: /* Compiler-specific predef without '_' */
2304
+ case DEF_NOARGS_PREDEF: /* Compiler-specific predef */
2305
+ break;
2306
+ default: /* defp->nargs >= 0 */
2307
+ c = squeeze_ws( NULL, NULL, NULL); /* Look for and skip '('*/
2308
+ if (c != '(') { /* Macro name without following '(' */
2309
+ unget_ch();
2310
+ if (warn_level & 8)
2311
+ diag_macro( CWARN, only_name, defp->name, 0L, NULL, defp, NULL);
2312
+ return FALSE;
2313
+ } else {
2314
+ arglist_pre[ 0] = xmalloc( (size_t) (NMACWORK + IDMAX * 2));
2315
+ arg_len = collect_args( defp, arglist_pre, 0);
2316
+ /* Collect arguments */
2317
+ if (arg_len == ARG_ERROR) { /* End of input */
2318
+ free( arglist_pre[ 0]);
2319
+ longjmp( jump, 1);
2320
+ }
2321
+ }
2322
+ break;
2323
+ }
2324
+
2325
+ if (defp->nargs > 0)
2326
+ substitute_pre( defp); /* Do actual arguments */
2327
+ else
2328
+ unget_string( defp->repl, defp->name);
2329
+
2330
+ if (mcpp_debug & EXPAND)
2331
+ dump_unget( "replace_pre exit");
2332
+ if (defp->nargs >= 0)
2333
+ free( arglist_pre[ 0]);
2334
+ return TRUE;
2335
+ }
2336
+
2337
+ static void substitute_pre(
2338
+ DEFBUF * defp /* Current macro being replaced */
2339
+ )
2340
+ /*
2341
+ * Stuff the macro body, substituting formal parameters with actual arguments.
2342
+ */
2343
+ {
2344
+ int c; /* Current character */
2345
+ FILEINFO * file; /* Funny #include */
2346
+ char * out_end; /* -> output buffer end */
2347
+ char * in_p; /* -> replacement text */
2348
+ char * out_p; /* -> macro output buff */
2349
+
2350
+ file = get_file( defp->name, NULL, NULL, (size_t) (NMACWORK + 1), FALSE);
2351
+ /* file == infile */
2352
+ in_p = defp->repl; /* -> macro replacement */
2353
+ out_p = file->buffer; /* -> output buffer */
2354
+ out_end = file->buffer + NMACWORK; /* -> buffer end */
2355
+
2356
+ while ((c = *in_p++) != EOS) {
2357
+ if (c == MAC_PARM) {
2358
+ c = (*in_p++ & UCHARMAX) - 1; /* Parm number */
2359
+ /*
2360
+ * Substitute formal parameter with actual argument.
2361
+ */
2362
+ if (out_end <= (out_p + strlen( arglist_pre[ c])))
2363
+ goto nospace;
2364
+ out_p = stpcpy( out_p, arglist_pre[ c]);
2365
+ } else {
2366
+ *out_p++ = c;
2367
+ }
2368
+ if (out_end <= out_p)
2369
+ goto nospace;
2370
+ }
2371
+
2372
+ *out_p = EOS;
2373
+ file->buffer = xrealloc( file->buffer, strlen( file->buffer) + 1);
2374
+ file->bptr = file->buffer; /* Truncate buffer */
2375
+ if (mcpp_debug & EXPAND)
2376
+ dump_string( "substitute_pre macroline", file->buffer);
2377
+ return;
2378
+
2379
+ nospace:
2380
+ *out_p = EOS;
2381
+ diag_macro( CERROR, macbuf_overflow, defp->name, 0L, file->buffer, defp
2382
+ , NULL);
2383
+ longjmp( jump, 1);
2384
+ }
2385
+
2386
+
2387
+ /*
2388
+ * C O M M O N R O U T I N E S
2389
+ * f o r S T A N D A R D a n d p r e - S T A N D A R D M o d e s
2390
+ */
2391
+
2392
+ static int collect_args(
2393
+ const DEFBUF * defp, /* Definition of the macro */
2394
+ char ** arglist, /* Pointers to actual arguments */
2395
+ int m_num /* Index into mac_inf[] */
2396
+ )
2397
+ /*
2398
+ * Collect the actual arguments for the macro, checking for correct number
2399
+ * of arguments.
2400
+ * Variable arguments (on Standard modes) are read as a merged argument.
2401
+ * Return number of real arguments, or ARG_ERROR on error of unterminated
2402
+ * macro.
2403
+ * collect_args() may read over to the next line unless 'in_directive' is
2404
+ * set to TRUE.
2405
+ * collect_args() may read over into file->parent to complete a macro call
2406
+ * unless stopped by RT_END (provided the "file" is macro). This is a key
2407
+ * trick of STD mode macro expansion. Meanwhile, POST_STD mode limits the
2408
+ * arguments in the "file" (macro or not).
2409
+ * Note: arglist[ n] may be reallocated by collect_args().
2410
+ */
2411
+ {
2412
+ const char * name = defp->name;
2413
+ char * argp = arglist[ 0]; /* Pointer to an argument */
2414
+ char * arg_end; /* End of arguments buffer */
2415
+ char * valid_argp = NULL; /* End of valid arguments */
2416
+ char * sequence; /* Token sequence for diagnostics */
2417
+ char * seq; /* Current pointer into 'sequence' */
2418
+ char * seq_end; /* Limit of buffer */
2419
+ int args; /* Number of arguments expected */
2420
+ int nargs = 0; /* Number of collected args */
2421
+ int var_arg = defp->nargs & VA_ARGS; /* Variable args */
2422
+ int more_to_come = FALSE; /* Next argument is expected*/
2423
+ LOCATION * locs; /* Location of args in source file */
2424
+ LOCATION * loc; /* Current locs */
2425
+ MAGIC_SEQ mgc_prefix; /* MAC_INF seqs and spaces preceding an arg */
2426
+ int c;
2427
+
2428
+ if (mcpp_debug & EXPAND)
2429
+ dump_unget( "collect_args entry");
2430
+ args = (defp->nargs == DEF_PRAGMA) ? 1 : (defp->nargs & ~AVA_ARGS);
2431
+ if (args == 0) /* Need no argument */
2432
+ valid_argp = argp;
2433
+ *argp = EOS; /* Make sure termination */
2434
+ arg_end = argp + NMACWORK/2;
2435
+ seq = sequence = arg_end + IDMAX; /* Use latter half of argp */
2436
+ seq_end = seq + NMACWORK/2;
2437
+ seq = stpcpy( seq, name);
2438
+ *seq++ = '(';
2439
+ if (mcpp_mode == STD) {
2440
+ /*
2441
+ * in_getarg is set TRUE while getting macro arguments, for the sake
2442
+ * of diagnostic's convenience. in_getarg is used only in STD mode.
2443
+ */
2444
+ in_getarg = TRUE;
2445
+ if (trace_macro && m_num) {
2446
+ /* #pragma MCPP debug macro_call, and the macro is on source */
2447
+ mac_inf[ m_num].loc_args = loc = locs
2448
+ = (LOCATION *) xmalloc( (sizeof (LOCATION)) * UCHARMAX);
2449
+ memset( loc, 0, (sizeof (LOCATION)) * UCHARMAX);
2450
+ /* 0-clear for default values, including empty argument */
2451
+ }
2452
+ }
2453
+
2454
+ while (1) {
2455
+ memset( &mgc_prefix, 0, sizeof (MAGIC_SEQ));
2456
+ c = squeeze_ws( &seq, NULL
2457
+ , (trace_macro && m_num) ? &mgc_prefix : NULL);
2458
+ /* Skip MAC_INF seqs and white spaces, still remember */
2459
+ /* the sequence in buffer, if necessary. */
2460
+ if (c == ')' || c == ',')
2461
+ scan_token( c, &seq, seq_end); /* Ensure token parsing */
2462
+ else
2463
+ *seq = EOS;
2464
+
2465
+ switch (c) { /* First character of token */
2466
+ case ')':
2467
+ if (! more_to_come) { /* Zero argument */
2468
+ if (trace_macro && m_num)
2469
+ loc++;
2470
+ break;
2471
+ } /* Else fall through */
2472
+ case ',': /* Empty argument */
2473
+ if (trace_macro && m_num)
2474
+ loc++; /* Advance pointer to infs */
2475
+ if (warn_level & 2)
2476
+ diag_macro( CWARN, empty_arg, sequence, 0L, NULL, defp, NULL);
2477
+ if (standard && var_arg && nargs == args - 1) {
2478
+ /* Variable arguments begin with an empty argument */
2479
+ c = get_an_arg( c, &argp, arg_end, &seq, 1, nargs, &loc
2480
+ , m_num, (trace_macro && m_num) ? &mgc_prefix : NULL);
2481
+ } else {
2482
+ if (mcpp_mode == STD)
2483
+ *argp++ = RT_END;
2484
+ *argp++ = EOS;
2485
+ }
2486
+ if (++nargs == args)
2487
+ valid_argp = argp;
2488
+ if (c == ',') {
2489
+ more_to_come = TRUE;
2490
+ continue;
2491
+ } else { /* ')' */
2492
+ break;
2493
+ }
2494
+ case '\n': /* Unterminated macro call in directive line*/
2495
+ unget_ch(); /* Fall through */
2496
+ case RT_END: /* Error of missing ')' */
2497
+ diag_macro( CERROR, unterm_macro, sequence, 0L, NULL, defp, NULL);
2498
+ /* Fall through */
2499
+ case CHAR_EOF: /* End of file in macro call*/
2500
+ nargs = ARG_ERROR;
2501
+ goto arg_ret; /* Diagnosed by at_eof() */
2502
+ default: /* Nomal argument */
2503
+ break;
2504
+ }
2505
+
2506
+ if (c == ')') /* At end of all args */
2507
+ break;
2508
+
2509
+ c = get_an_arg( c, &argp, arg_end, &seq
2510
+ , (var_arg && nargs == args - 1) ? 1 : 0, nargs, &loc
2511
+ , m_num, (trace_macro && m_num) ? &mgc_prefix : NULL);
2512
+
2513
+ if (++nargs == args)
2514
+ valid_argp = argp; /* End of valid arguments */
2515
+ if (c == ')')
2516
+ break;
2517
+ if (c == 0) { /* End of file */
2518
+ nargs = ARG_ERROR;
2519
+ goto arg_ret; /* Diagnosed by at_eof() */
2520
+ }
2521
+ if (c == -1) { /* Untermanated macro call */
2522
+ diag_macro( CERROR, unterm_macro, sequence, 0L, NULL, defp, NULL);
2523
+ nargs = ARG_ERROR;
2524
+ goto arg_ret;
2525
+ }
2526
+ more_to_come = (c == ',');
2527
+ } /* Collected all arguments */
2528
+
2529
+ if (nargs == 0 && args == 1) { /* Only and empty argument */
2530
+ if (warn_level & 2)
2531
+ diag_macro( CWARN, empty_arg, sequence, 0L, NULL, defp, NULL);
2532
+ } else if (nargs != args) { /* Wrong number of arguments*/
2533
+ if (mcpp_mode != OLD_PREP || (warn_level & 1)) {
2534
+ if ((standard && var_arg && (nargs == args - 1))
2535
+ /* Absence of variable arguments */
2536
+ || (mcpp_mode == OLD_PREP)) {
2537
+ if (warn_level & 1)
2538
+ diag_macro( CWARN, narg_error, nargs < args ? "Less"
2539
+ : "More", (long) args, sequence, defp, NULL);
2540
+ } else {
2541
+ diag_macro( CERROR, narg_error, nargs < args ? "Less" : "More"
2542
+ , (long) args, sequence, defp, NULL);
2543
+ }
2544
+ }
2545
+ }
2546
+ if (args < nargs) {
2547
+ argp = valid_argp; /* Truncate excess arguments*/
2548
+ } else {
2549
+ for (c = nargs; c < args; c++) {
2550
+ if (mcpp_mode == STD)
2551
+ *argp++ = RT_END; /* For rescan() */
2552
+ *argp++ = EOS; /* Missing arguments */
2553
+ }
2554
+ if (c == 0)
2555
+ argp++; /* Ensure positive length */
2556
+ }
2557
+ arglist[ 0] = argp
2558
+ = xrealloc( arglist[ 0], (size_t) (argp - arglist[ 0]));
2559
+ /* Use memory sparingly */
2560
+ for (c = 1; c < args; c++)
2561
+ arglist[ c] = argp += strlen( argp) + 1;
2562
+ if (trace_macro && m_num)
2563
+ mac_inf[ m_num].loc_args /* Truncate excess memory */
2564
+ = (LOCATION *) xrealloc( (char *) locs
2565
+ , (loc - locs) * sizeof (LOCATION));
2566
+
2567
+ if (mcpp_debug & EXPAND) {
2568
+ if (nargs > 0) {
2569
+ if (nargs > args)
2570
+ nargs = args;
2571
+ dump_args( "collect_args exit", nargs, (const char **) arglist);
2572
+ }
2573
+ dump_unget( "collect_args exit");
2574
+ }
2575
+ arg_ret:
2576
+ if (mcpp_mode == STD)
2577
+ in_getarg = FALSE;
2578
+ /* Return number of found arguments for function-like macro at most */
2579
+ /* defp->nargs, or return defp->nargs for object-like macro. */
2580
+ return defp->nargs <= DEF_NOARGS ? defp->nargs : nargs;
2581
+ }
2582
+
2583
+ static int get_an_arg(
2584
+ int c,
2585
+ char ** argpp, /* Address of pointer into argument list */
2586
+ char * arg_end, /* End of argument list buffer */
2587
+ char ** seqp, /* Buffer for diagnostics */
2588
+ int var_arg, /* 1 on __VA_ARGS__, 0 on others*/
2589
+ int nargs, /* Argument number */
2590
+ LOCATION ** locp, /* Where to save location infs */
2591
+ int m_num, /* Macro number to trace */
2592
+ MAGIC_SEQ * mgc_prefix /* White space and magics leading to argument */
2593
+ )
2594
+ /*
2595
+ * Get an argument of macro into '*argpp', return the next punctuator.
2596
+ * Variable arguments are read as a merged argument.
2597
+ * Note: nargs, locp and m_num are used only in macro trace mode of
2598
+ * '#pragma MCPP debug macro_call' or -K option.
2599
+ */
2600
+ {
2601
+ struct {
2602
+ int n_par;
2603
+ int n_in_src;
2604
+ } n_paren[ 16];
2605
+ int num_paren = 0;
2606
+ int end_an_arg = FALSE; /* End-of-an-arg flag */
2607
+ int paren = var_arg; /* For embedded ()'s */
2608
+ int token_type;
2609
+ char * prevp;
2610
+ char * argp = *argpp;
2611
+ int trace_arg = 0; /* Enable tracing arg */
2612
+ LINE_COL s_line_col, e_line_col; /* Location of macro in an argument */
2613
+ MAGIC_SEQ mgc_seq; /* Magic seqs and spaces succeeding an arg */
2614
+ size_t len;
2615
+
2616
+ if (trace_macro) {
2617
+ trace_arg = m_num && infile->fp;
2618
+ if (m_num) {
2619
+ if (trace_arg) { /* The macro call is in source */
2620
+ s_line_col.line = src_line;
2621
+ s_line_col.col = infile->bptr - infile->buffer - 1;
2622
+ /* '-1': bptr is one byte passed beginning of the token */
2623
+ get_src_location( & s_line_col);
2624
+ (*locp)->start_line = s_line_col.line;
2625
+ (*locp)->start_col = s_line_col.col;
2626
+ e_line_col = s_line_col;
2627
+ /* Save the location, */
2628
+ /* also for end of arg in case of empty arg*/
2629
+ memset( n_paren, 0, sizeof (n_paren));
2630
+ }
2631
+ *argp++ = MAC_INF;
2632
+ *argp++ = MAC_ARG_START;
2633
+ *argp++ = (m_num / UCHARMAX) + 1;
2634
+ *argp++ = (m_num % UCHARMAX) + 1;
2635
+ *argp++ = nargs + 1;
2636
+ /* Argument number internally starts at 1 */
2637
+ if (mgc_prefix->magic_start) {
2638
+ /* Copy the preceding magics, if any */
2639
+ len = mgc_prefix->magic_end - mgc_prefix->magic_start;
2640
+ memcpy( argp, mgc_prefix->magic_start, len);
2641
+ argp += len;
2642
+ }
2643
+ }
2644
+ memset( &mgc_seq, 0, sizeof (MAGIC_SEQ));
2645
+ }
2646
+
2647
+ while (1) {
2648
+ if (c == '\n' /* In control line */
2649
+ || c == RT_END) { /* Boundary of rescan (in STD mode) */
2650
+ if (c == '\n')
2651
+ unget_ch();
2652
+ break;
2653
+ }
2654
+ if (trace_arg) { /* Save the location */
2655
+ s_line_col.line = src_line; /* of the token */
2656
+ s_line_col.col = infile->bptr - infile->buffer - 1;
2657
+ }
2658
+ token_type = scan_token( c, (prevp = argp, &argp), arg_end);
2659
+ /* Scan the next token */
2660
+ switch (c) {
2661
+ case '(': /* Worry about balance */
2662
+ paren++; /* To know about commas */
2663
+ break;
2664
+ case ')': /* Other side too */
2665
+ if (paren-- == var_arg) /* At the end? */
2666
+ end_an_arg = TRUE; /* Else more to come */
2667
+ if (trace_arg) {
2668
+ if (num_paren && paren == n_paren[ num_paren].n_par) {
2669
+ /* Maybe corresponding parentheses for the macro in arg */
2670
+ int src_n;
2671
+ src_n = n_paren[ num_paren].n_in_src;
2672
+ in_src[ src_n].end_line = s_line_col.line;
2673
+ in_src[ src_n].end_col = s_line_col.col + 1;
2674
+ num_paren--;
2675
+ }
2676
+ }
2677
+ break;
2678
+ case ',':
2679
+ if (paren == 0) /* Comma delimits arg */
2680
+ end_an_arg = TRUE;
2681
+ break;
2682
+ case MAC_INF : /* Copy magics as they are */
2683
+ switch (*argp++ = get_ch()) {
2684
+ case MAC_ARG_START :
2685
+ *argp++ = get_ch();
2686
+ /* Fall through */
2687
+ case MAC_CALL_START :
2688
+ *argp++ = get_ch();
2689
+ *argp++ = get_ch();
2690
+ break;
2691
+ case MAC_ARG_END :
2692
+ if (! option_flags.v)
2693
+ break;
2694
+ else
2695
+ *argp++ = get_ch();
2696
+ /* Fall through */
2697
+ case MAC_CALL_END :
2698
+ if (option_flags.v) {
2699
+ *argp++ = get_ch();
2700
+ *argp++ = get_ch();
2701
+ }
2702
+ break;
2703
+ }
2704
+ break;
2705
+ case CHAR_EOF : /* Unexpected EOF */
2706
+ return 0;
2707
+ default : /* Any token */
2708
+ if (mcpp_mode == STD && token_type == NAM
2709
+ && c != IN_SRC && c != DEF_MAGIC && infile->fp) {
2710
+ len = trace_arg ? IN_SRC_LEN : 1;
2711
+ memmove( prevp + len, prevp, (size_t) (argp - prevp));
2712
+ argp += len;
2713
+ *prevp = IN_SRC;
2714
+ /* Mark that the name is read from source file */
2715
+ if (trace_arg) {
2716
+ DEFBUF * defp;
2717
+
2718
+ defp = look_id( prevp + IN_SRC_LEN);
2719
+ if (in_src_num >= MAX_IN_SRC_NUM - 1) {
2720
+ cerror(
2721
+ "Too many names in arguments tracing %s" /* _E_ */
2722
+ , defp ? defp->name : null, 0L, NULL);
2723
+ return 0;
2724
+ } else if (++in_src_num > max_in_src_num) {
2725
+ size_t old_len;
2726
+ old_len = sizeof (LOCATION) * max_in_src_num;
2727
+ /* Enlarge the array */
2728
+ in_src = (LOCATION *) xrealloc( (char *) in_src
2729
+ , old_len * 2);
2730
+ /* Have to initialize the enlarged area */
2731
+ memset( in_src + max_in_src_num, 0, old_len);
2732
+ max_in_src_num *= 2;
2733
+ }
2734
+ /* Insert the identifier number in 2-bytes-encoding */
2735
+ *(prevp + 1) = (in_src_num / UCHARMAX) + 1;
2736
+ *(prevp + 2) = (in_src_num % UCHARMAX) + 1;
2737
+ if (defp) { /* Macro name in arg */
2738
+ in_src[ in_src_num].start_line = s_line_col.line;
2739
+ in_src[ in_src_num].start_col = s_line_col.col;
2740
+ /* For object-like macro, also for function-like */
2741
+ /* macro in case of parens are not found. */
2742
+ in_src[ in_src_num].end_line = s_line_col.line;
2743
+ in_src[ in_src_num].end_col
2744
+ = infile->bptr - infile->buffer;
2745
+ if (defp->nargs >= 0) {
2746
+ /* Function-like macro: search parentheses */
2747
+ n_paren[ ++num_paren].n_par = paren;
2748
+ n_paren[ num_paren].n_in_src = in_src_num;
2749
+ }
2750
+ } /* Else in_src[ in_src_num].* are 0L */
2751
+ }
2752
+ }
2753
+ break;
2754
+ } /* End of switch */
2755
+
2756
+ if (end_an_arg) /* End of an argument */
2757
+ break;
2758
+ if (trace_arg) { /* Save the location */
2759
+ e_line_col.line = src_line; /* before spaces */
2760
+ e_line_col.col = infile->bptr - infile->buffer;
2761
+ }
2762
+ memset( &mgc_seq, 0, sizeof (MAGIC_SEQ));
2763
+ c = squeeze_ws( &argp, NULL, &mgc_seq);
2764
+ /* To the next token */
2765
+ } /* Collected an argument*/
2766
+
2767
+ *argp = EOS;
2768
+ *seqp = stpcpy( *seqp, *argpp); /* Save the sequence */
2769
+ if (c == '\n' || c == RT_END)
2770
+ return -1; /* Unterminated macro */
2771
+ argp--; /* Remove the punctuator*/
2772
+ if (mgc_seq.space)
2773
+ --argp; /* Remove trailing space */
2774
+ if (mcpp_mode == STD) {
2775
+ if (trace_macro && m_num) {
2776
+ if (trace_arg) { /* Location of end of an arg */
2777
+ get_src_location( & e_line_col);
2778
+ (*locp)->end_line = e_line_col.line;
2779
+ (*locp)->end_col = e_line_col.col;
2780
+ }
2781
+ (*locp)++; /* Advance pointer even if !trace_arg */
2782
+ *argp++ = MAC_INF;
2783
+ *argp++ = MAC_ARG_END;
2784
+ if (option_flags.v) {
2785
+ *argp++ = (m_num / UCHARMAX) + 1;
2786
+ *argp++ = (m_num % UCHARMAX) + 1;
2787
+ *argp++ = nargs + 1;
2788
+ *argp = EOS;
2789
+ *argpp = chk_magic_balance( *argpp, argp, TRUE, FALSE);
2790
+ /* Check a stray magic caused by abnormal macro */
2791
+ /* and move it to an edge if found. */
2792
+ }
2793
+ }
2794
+ *argp++ = RT_END; /* For rescan() */
2795
+ }
2796
+ *argp++ = EOS; /* Terminate an argument*/
2797
+ *argpp = argp;
2798
+ return c;
2799
+ }
2800
+
2801
+ static int squeeze_ws(
2802
+ char ** out, /* Pointer to output pointer */
2803
+ char ** endf, /* Pointer to end of infile data*/
2804
+ MAGIC_SEQ * mgc_seq /* Sequence of MAC_INFs and space */
2805
+ /* mgc_seq should be initialized in the calling routine */
2806
+ )
2807
+ /*
2808
+ * Squeeze white spaces to one space.
2809
+ * White spaces are ' ' (and possibly '\t', when keep_spaces == TRUE. Note
2810
+ * that '\r', '\v', '\f' have been already converted to ' ' by get_ch()),
2811
+ * and '\n' unless in_directive is set.
2812
+ * COM_SEP is skipped. TOK_SEPs are squeezed to one TOK_SEP.
2813
+ * Copy MAC_INF and its sequences as they are.
2814
+ * If white spaces are found and 'out' is not NULL, write a space to *out and
2815
+ * increment *out.
2816
+ * Record start and end of MAC_INF sequences and whether space is found or
2817
+ * not for a convenience of get_an_arg().
2818
+ * Return the next character.
2819
+ */
2820
+ {
2821
+ int c;
2822
+ int space = 0;
2823
+ int tsep = 0;
2824
+ FILEINFO * file = infile;
2825
+ FILE * fp = infile->fp;
2826
+ int end_of_file = (out && endf) ? FALSE : TRUE;
2827
+
2828
+ while (((char_type[ c = get_ch()] & SPA) && (! standard
2829
+ || (mcpp_mode == POST_STD && file == infile)
2830
+ || (mcpp_mode == STD
2831
+ && ((macro_line != 0 && macro_line != MACRO_ERROR)
2832
+ || file == infile))))
2833
+ || c == MAC_INF) {
2834
+ if (! end_of_file && file != infile) { /* Infile has been read over*/
2835
+ *endf = *out; /* Remember the location */
2836
+ end_of_file = TRUE;
2837
+ }
2838
+ if (c == '\n' && in_directive) /* If scanning control line */
2839
+ break; /* do not skip newline. */
2840
+ switch (c) {
2841
+ case '\n':
2842
+ space++;
2843
+ wrong_line = TRUE;
2844
+ break;
2845
+ case TOK_SEP:
2846
+ if (mcpp_mode == STD)
2847
+ tsep++;
2848
+ continue; /* Skip COM_SEP in OLD_PREP mode */
2849
+ case MAC_INF : /* Copy magics as they are, or skip */
2850
+ if (mgc_seq && ! mgc_seq->magic_start)
2851
+ mgc_seq->magic_start = *out;
2852
+ /* First occurence of magic seq */
2853
+ if (out)
2854
+ *(*out)++ = c;
2855
+ c = get_ch();
2856
+ if (out)
2857
+ *(*out)++ = c;
2858
+ switch (c) {
2859
+ case MAC_ARG_START :
2860
+ c = get_ch();
2861
+ if (out)
2862
+ *(*out)++ = c;
2863
+ /* Fall through */
2864
+ case MAC_CALL_START :
2865
+ c = get_ch();
2866
+ if (out)
2867
+ *(*out)++ = c;
2868
+ c = get_ch();
2869
+ if (out)
2870
+ *(*out)++ = c;
2871
+ break;
2872
+ case MAC_ARG_END :
2873
+ if (! option_flags.v) {
2874
+ break;
2875
+ } else {
2876
+ c = get_ch();
2877
+ if (out)
2878
+ *(*out)++ = c;
2879
+ /* Fall through */
2880
+ }
2881
+ case MAC_CALL_END :
2882
+ if (option_flags.v) {
2883
+ c = get_ch();
2884
+ if (out)
2885
+ *(*out)++ = c;
2886
+ c = get_ch();
2887
+ if (out)
2888
+ *(*out)++ = c;
2889
+ }
2890
+ break;
2891
+ }
2892
+ if (mgc_seq) /* Remember end of last magic seq */
2893
+ mgc_seq->magic_end = *out;
2894
+ break;
2895
+ default:
2896
+ space++;
2897
+ break;
2898
+ }
2899
+ }
2900
+
2901
+ if (out) {
2902
+ if (space) { /* Write a space to output pointer */
2903
+ *(*out)++ = ' '; /* and increment the pointer. */
2904
+ if (mgc_seq)
2905
+ mgc_seq->space = TRUE;
2906
+ }
2907
+ if (tsep && !space) /* Needs to preserve token separator*/
2908
+ *(*out)++ = TOK_SEP;
2909
+ **out = EOS;
2910
+ }
2911
+ if (mcpp_mode == POST_STD && file != infile) {
2912
+ unget_ch(); /* Arguments cannot cross "file"s */
2913
+ c = fp ? CHAR_EOF : RT_END; /* EOF is diagnosed by at_eof() */
2914
+ } else if (mcpp_mode == STD && macro_line == MACRO_ERROR
2915
+ && file != infile) { /* EOF */
2916
+ unget_ch(); /* diagnosed by at_eof() or only */
2917
+ c = CHAR_EOF; /* name of a function-like macro. */
2918
+ } /* at_eof() resets macro_line on error */
2919
+ return c; /* Return the next character */
2920
+ }
2921
+
2922
+ static void skip_macro( void)
2923
+ /*
2924
+ * Clear the stacked (i.e. half-expanded) macro, called on macro error.
2925
+ */
2926
+ {
2927
+ if (infile == NULL) /* End of input */
2928
+ return;
2929
+ if (infile->fp) /* Source file */
2930
+ return;
2931
+ while (infile->fp == NULL) { /* Stacked stuff */
2932
+ infile->bptr += strlen( infile->bptr);
2933
+ get_ch(); /* To the parent "file" */
2934
+ }
2935
+ unget_ch();
2936
+ }
2937
+
2938
+ static void diag_macro(
2939
+ int severity, /* Error or warning */
2940
+ const char * format,
2941
+ const char * arg1,
2942
+ long arg2,
2943
+ const char * arg3,
2944
+ const DEFBUF * defp1, /* Macro causing the problem 1 */
2945
+ const DEFBUF * defp2 /* 2 */
2946
+ )
2947
+ /*
2948
+ * Supplement macro information for diagnostic.
2949
+ */
2950
+ {
2951
+
2952
+ if (defp1 && defp1->name != macro_name)
2953
+ expanding( defp1->name, FALSE);
2954
+ /* Inform of the problematic macro call */
2955
+ if (defp2 && defp2->name != macro_name)
2956
+ expanding( defp2->name, FALSE);
2957
+ if (severity == CERROR)
2958
+ cerror( format, arg1, arg2, arg3);
2959
+ else
2960
+ cwarn( format, arg1, arg2, arg3);
2961
+ }
2962
+
2963
+ static void dump_args(
2964
+ const char * why,
2965
+ int nargs,
2966
+ const char ** arglist
2967
+ )
2968
+ /*
2969
+ * Dump arguments list.
2970
+ */
2971
+ {
2972
+ int i;
2973
+
2974
+ mcpp_fprintf( DBG, "dump of %d actual arguments %s\n", nargs, why);
2975
+ for (i = 0; i < nargs; i++) {
2976
+ mcpp_fprintf( DBG, "arg[%d]", i + 1);
2977
+ dump_string( NULL, arglist[ i]);
2978
+ }
2979
+ }
2980
+