clipsruby 0.0.2

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 (346) hide show
  1. checksums.yaml +7 -0
  2. data/ext/clipsruby/agenda.c +1373 -0
  3. data/ext/clipsruby/agenda.h +169 -0
  4. data/ext/clipsruby/analysis.c +1142 -0
  5. data/ext/clipsruby/analysis.h +61 -0
  6. data/ext/clipsruby/argacces.c +526 -0
  7. data/ext/clipsruby/argacces.h +77 -0
  8. data/ext/clipsruby/bload.c +884 -0
  9. data/ext/clipsruby/bload.h +94 -0
  10. data/ext/clipsruby/bmathfun.c +557 -0
  11. data/ext/clipsruby/bmathfun.h +66 -0
  12. data/ext/clipsruby/bsave.c +634 -0
  13. data/ext/clipsruby/bsave.h +130 -0
  14. data/ext/clipsruby/classcom.c +976 -0
  15. data/ext/clipsruby/classcom.h +115 -0
  16. data/ext/clipsruby/classexm.c +1376 -0
  17. data/ext/clipsruby/classexm.h +97 -0
  18. data/ext/clipsruby/classfun.c +1392 -0
  19. data/ext/clipsruby/classfun.h +164 -0
  20. data/ext/clipsruby/classinf.c +1245 -0
  21. data/ext/clipsruby/classinf.h +94 -0
  22. data/ext/clipsruby/classini.c +843 -0
  23. data/ext/clipsruby/classini.h +75 -0
  24. data/ext/clipsruby/classpsr.c +957 -0
  25. data/ext/clipsruby/classpsr.h +73 -0
  26. data/ext/clipsruby/clips.h +133 -0
  27. data/ext/clipsruby/clipsruby.c +619 -0
  28. data/ext/clipsruby/clsltpsr.c +931 -0
  29. data/ext/clipsruby/clsltpsr.h +72 -0
  30. data/ext/clipsruby/commline.c +1217 -0
  31. data/ext/clipsruby/commline.h +131 -0
  32. data/ext/clipsruby/conscomp.c +1593 -0
  33. data/ext/clipsruby/conscomp.h +150 -0
  34. data/ext/clipsruby/constant.h +264 -0
  35. data/ext/clipsruby/constrct.c +1090 -0
  36. data/ext/clipsruby/constrct.h +216 -0
  37. data/ext/clipsruby/constrnt.c +554 -0
  38. data/ext/clipsruby/constrnt.h +132 -0
  39. data/ext/clipsruby/crstrtgy.c +1088 -0
  40. data/ext/clipsruby/crstrtgy.h +85 -0
  41. data/ext/clipsruby/cstrcbin.c +185 -0
  42. data/ext/clipsruby/cstrcbin.h +61 -0
  43. data/ext/clipsruby/cstrccmp.h +43 -0
  44. data/ext/clipsruby/cstrccom.c +1791 -0
  45. data/ext/clipsruby/cstrccom.h +115 -0
  46. data/ext/clipsruby/cstrcpsr.c +835 -0
  47. data/ext/clipsruby/cstrcpsr.h +97 -0
  48. data/ext/clipsruby/cstrnbin.c +282 -0
  49. data/ext/clipsruby/cstrnbin.h +55 -0
  50. data/ext/clipsruby/cstrnchk.c +826 -0
  51. data/ext/clipsruby/cstrnchk.h +91 -0
  52. data/ext/clipsruby/cstrncmp.c +238 -0
  53. data/ext/clipsruby/cstrncmp.h +57 -0
  54. data/ext/clipsruby/cstrnops.c +1176 -0
  55. data/ext/clipsruby/cstrnops.h +47 -0
  56. data/ext/clipsruby/cstrnpsr.c +1394 -0
  57. data/ext/clipsruby/cstrnpsr.h +88 -0
  58. data/ext/clipsruby/cstrnutl.c +564 -0
  59. data/ext/clipsruby/cstrnutl.h +54 -0
  60. data/ext/clipsruby/default.c +454 -0
  61. data/ext/clipsruby/default.h +57 -0
  62. data/ext/clipsruby/defins.c +971 -0
  63. data/ext/clipsruby/defins.h +127 -0
  64. data/ext/clipsruby/developr.c +677 -0
  65. data/ext/clipsruby/developr.h +69 -0
  66. data/ext/clipsruby/dffctbin.c +477 -0
  67. data/ext/clipsruby/dffctbin.h +76 -0
  68. data/ext/clipsruby/dffctbsc.c +308 -0
  69. data/ext/clipsruby/dffctbsc.h +72 -0
  70. data/ext/clipsruby/dffctcmp.c +297 -0
  71. data/ext/clipsruby/dffctcmp.h +44 -0
  72. data/ext/clipsruby/dffctdef.c +364 -0
  73. data/ext/clipsruby/dffctdef.h +104 -0
  74. data/ext/clipsruby/dffctpsr.c +179 -0
  75. data/ext/clipsruby/dffctpsr.h +49 -0
  76. data/ext/clipsruby/dffnxbin.c +520 -0
  77. data/ext/clipsruby/dffnxbin.h +67 -0
  78. data/ext/clipsruby/dffnxcmp.c +378 -0
  79. data/ext/clipsruby/dffnxcmp.h +54 -0
  80. data/ext/clipsruby/dffnxexe.c +241 -0
  81. data/ext/clipsruby/dffnxexe.h +58 -0
  82. data/ext/clipsruby/dffnxfun.c +1192 -0
  83. data/ext/clipsruby/dffnxfun.h +155 -0
  84. data/ext/clipsruby/dffnxpsr.c +514 -0
  85. data/ext/clipsruby/dffnxpsr.h +57 -0
  86. data/ext/clipsruby/dfinsbin.c +509 -0
  87. data/ext/clipsruby/dfinsbin.h +66 -0
  88. data/ext/clipsruby/dfinscmp.c +345 -0
  89. data/ext/clipsruby/dfinscmp.h +48 -0
  90. data/ext/clipsruby/drive.c +1191 -0
  91. data/ext/clipsruby/drive.h +65 -0
  92. data/ext/clipsruby/emathfun.c +1213 -0
  93. data/ext/clipsruby/emathfun.h +99 -0
  94. data/ext/clipsruby/engine.c +1568 -0
  95. data/ext/clipsruby/engine.h +203 -0
  96. data/ext/clipsruby/entities.h +276 -0
  97. data/ext/clipsruby/envrnbld.c +514 -0
  98. data/ext/clipsruby/envrnbld.h +40 -0
  99. data/ext/clipsruby/envrnmnt.c +257 -0
  100. data/ext/clipsruby/envrnmnt.h +112 -0
  101. data/ext/clipsruby/evaluatn.c +1736 -0
  102. data/ext/clipsruby/evaluatn.h +211 -0
  103. data/ext/clipsruby/expressn.c +494 -0
  104. data/ext/clipsruby/expressn.h +154 -0
  105. data/ext/clipsruby/exprnbin.c +538 -0
  106. data/ext/clipsruby/exprnbin.h +60 -0
  107. data/ext/clipsruby/exprnops.c +564 -0
  108. data/ext/clipsruby/exprnops.h +67 -0
  109. data/ext/clipsruby/exprnpsr.c +1112 -0
  110. data/ext/clipsruby/exprnpsr.h +98 -0
  111. data/ext/clipsruby/extconf.rb +2 -0
  112. data/ext/clipsruby/extnfunc.c +1015 -0
  113. data/ext/clipsruby/extnfunc.h +157 -0
  114. data/ext/clipsruby/factbin.c +447 -0
  115. data/ext/clipsruby/factbin.h +56 -0
  116. data/ext/clipsruby/factbld.c +1035 -0
  117. data/ext/clipsruby/factbld.h +63 -0
  118. data/ext/clipsruby/factcmp.c +386 -0
  119. data/ext/clipsruby/factcmp.h +46 -0
  120. data/ext/clipsruby/factcom.c +759 -0
  121. data/ext/clipsruby/factcom.h +80 -0
  122. data/ext/clipsruby/factfile.c +1761 -0
  123. data/ext/clipsruby/factfile.h +54 -0
  124. data/ext/clipsruby/factfun.c +682 -0
  125. data/ext/clipsruby/factfun.h +77 -0
  126. data/ext/clipsruby/factgen.c +1305 -0
  127. data/ext/clipsruby/factgen.h +229 -0
  128. data/ext/clipsruby/facthsh.c +438 -0
  129. data/ext/clipsruby/facthsh.h +81 -0
  130. data/ext/clipsruby/factlhs.c +250 -0
  131. data/ext/clipsruby/factlhs.h +54 -0
  132. data/ext/clipsruby/factmch.c +905 -0
  133. data/ext/clipsruby/factmch.h +68 -0
  134. data/ext/clipsruby/factmngr.c +3373 -0
  135. data/ext/clipsruby/factmngr.h +325 -0
  136. data/ext/clipsruby/factprt.c +498 -0
  137. data/ext/clipsruby/factprt.h +60 -0
  138. data/ext/clipsruby/factqpsr.c +796 -0
  139. data/ext/clipsruby/factqpsr.h +61 -0
  140. data/ext/clipsruby/factqury.c +1267 -0
  141. data/ext/clipsruby/factqury.h +112 -0
  142. data/ext/clipsruby/factrete.c +978 -0
  143. data/ext/clipsruby/factrete.h +70 -0
  144. data/ext/clipsruby/factrhs.c +667 -0
  145. data/ext/clipsruby/factrhs.h +55 -0
  146. data/ext/clipsruby/filecom.c +353 -0
  147. data/ext/clipsruby/filecom.h +137 -0
  148. data/ext/clipsruby/filertr.c +481 -0
  149. data/ext/clipsruby/filertr.h +94 -0
  150. data/ext/clipsruby/fileutil.c +1020 -0
  151. data/ext/clipsruby/fileutil.h +50 -0
  152. data/ext/clipsruby/generate.c +1079 -0
  153. data/ext/clipsruby/generate.h +57 -0
  154. data/ext/clipsruby/genrcbin.c +902 -0
  155. data/ext/clipsruby/genrcbin.h +69 -0
  156. data/ext/clipsruby/genrccmp.c +640 -0
  157. data/ext/clipsruby/genrccmp.h +59 -0
  158. data/ext/clipsruby/genrccom.c +2017 -0
  159. data/ext/clipsruby/genrccom.h +119 -0
  160. data/ext/clipsruby/genrcexe.c +737 -0
  161. data/ext/clipsruby/genrcexe.h +73 -0
  162. data/ext/clipsruby/genrcfun.c +890 -0
  163. data/ext/clipsruby/genrcfun.h +185 -0
  164. data/ext/clipsruby/genrcpsr.c +1618 -0
  165. data/ext/clipsruby/genrcpsr.h +80 -0
  166. data/ext/clipsruby/globlbin.c +458 -0
  167. data/ext/clipsruby/globlbin.h +71 -0
  168. data/ext/clipsruby/globlbsc.c +361 -0
  169. data/ext/clipsruby/globlbsc.h +83 -0
  170. data/ext/clipsruby/globlcmp.c +330 -0
  171. data/ext/clipsruby/globlcmp.h +52 -0
  172. data/ext/clipsruby/globlcom.c +289 -0
  173. data/ext/clipsruby/globlcom.h +63 -0
  174. data/ext/clipsruby/globldef.c +1087 -0
  175. data/ext/clipsruby/globldef.h +151 -0
  176. data/ext/clipsruby/globlpsr.c +530 -0
  177. data/ext/clipsruby/globlpsr.h +59 -0
  178. data/ext/clipsruby/immthpsr.c +431 -0
  179. data/ext/clipsruby/immthpsr.h +55 -0
  180. data/ext/clipsruby/incrrset.c +530 -0
  181. data/ext/clipsruby/incrrset.h +73 -0
  182. data/ext/clipsruby/inherpsr.c +850 -0
  183. data/ext/clipsruby/inherpsr.h +52 -0
  184. data/ext/clipsruby/inscom.c +2076 -0
  185. data/ext/clipsruby/inscom.h +182 -0
  186. data/ext/clipsruby/insfile.c +1764 -0
  187. data/ext/clipsruby/insfile.h +96 -0
  188. data/ext/clipsruby/insfun.c +1451 -0
  189. data/ext/clipsruby/insfun.h +134 -0
  190. data/ext/clipsruby/insmngr.c +2550 -0
  191. data/ext/clipsruby/insmngr.h +125 -0
  192. data/ext/clipsruby/insmoddp.c +1041 -0
  193. data/ext/clipsruby/insmoddp.h +91 -0
  194. data/ext/clipsruby/insmult.c +804 -0
  195. data/ext/clipsruby/insmult.h +62 -0
  196. data/ext/clipsruby/inspsr.c +602 -0
  197. data/ext/clipsruby/inspsr.h +60 -0
  198. data/ext/clipsruby/insquery.c +1278 -0
  199. data/ext/clipsruby/insquery.h +115 -0
  200. data/ext/clipsruby/insqypsr.c +729 -0
  201. data/ext/clipsruby/insqypsr.h +63 -0
  202. data/ext/clipsruby/iofun.c +2045 -0
  203. data/ext/clipsruby/iofun.h +116 -0
  204. data/ext/clipsruby/lgcldpnd.c +644 -0
  205. data/ext/clipsruby/lgcldpnd.h +75 -0
  206. data/ext/clipsruby/main.c +112 -0
  207. data/ext/clipsruby/match.h +142 -0
  208. data/ext/clipsruby/memalloc.c +481 -0
  209. data/ext/clipsruby/memalloc.h +197 -0
  210. data/ext/clipsruby/miscfun.c +1801 -0
  211. data/ext/clipsruby/miscfun.h +132 -0
  212. data/ext/clipsruby/modulbin.c +607 -0
  213. data/ext/clipsruby/modulbin.h +84 -0
  214. data/ext/clipsruby/modulbsc.c +347 -0
  215. data/ext/clipsruby/modulbsc.h +67 -0
  216. data/ext/clipsruby/modulcmp.c +499 -0
  217. data/ext/clipsruby/modulcmp.h +54 -0
  218. data/ext/clipsruby/moduldef.c +817 -0
  219. data/ext/clipsruby/moduldef.h +271 -0
  220. data/ext/clipsruby/modulpsr.c +1150 -0
  221. data/ext/clipsruby/modulpsr.h +69 -0
  222. data/ext/clipsruby/modulutl.c +1036 -0
  223. data/ext/clipsruby/modulutl.h +84 -0
  224. data/ext/clipsruby/msgcom.c +1221 -0
  225. data/ext/clipsruby/msgcom.h +125 -0
  226. data/ext/clipsruby/msgfun.c +1076 -0
  227. data/ext/clipsruby/msgfun.h +118 -0
  228. data/ext/clipsruby/msgpass.c +1441 -0
  229. data/ext/clipsruby/msgpass.h +103 -0
  230. data/ext/clipsruby/msgpsr.c +698 -0
  231. data/ext/clipsruby/msgpsr.h +73 -0
  232. data/ext/clipsruby/multifld.c +1404 -0
  233. data/ext/clipsruby/multifld.h +130 -0
  234. data/ext/clipsruby/multifun.c +2182 -0
  235. data/ext/clipsruby/multifun.h +102 -0
  236. data/ext/clipsruby/network.h +142 -0
  237. data/ext/clipsruby/objbin.c +1522 -0
  238. data/ext/clipsruby/objbin.h +79 -0
  239. data/ext/clipsruby/objcmp.c +1507 -0
  240. data/ext/clipsruby/objcmp.h +71 -0
  241. data/ext/clipsruby/object.h +260 -0
  242. data/ext/clipsruby/objrtbin.c +701 -0
  243. data/ext/clipsruby/objrtbin.h +79 -0
  244. data/ext/clipsruby/objrtbld.c +2393 -0
  245. data/ext/clipsruby/objrtbld.h +66 -0
  246. data/ext/clipsruby/objrtcmp.c +734 -0
  247. data/ext/clipsruby/objrtcmp.h +66 -0
  248. data/ext/clipsruby/objrtfnx.c +1330 -0
  249. data/ext/clipsruby/objrtfnx.h +222 -0
  250. data/ext/clipsruby/objrtgen.c +736 -0
  251. data/ext/clipsruby/objrtgen.h +63 -0
  252. data/ext/clipsruby/objrtmch.c +1524 -0
  253. data/ext/clipsruby/objrtmch.h +160 -0
  254. data/ext/clipsruby/parsefun.c +415 -0
  255. data/ext/clipsruby/parsefun.h +67 -0
  256. data/ext/clipsruby/pattern.c +1265 -0
  257. data/ext/clipsruby/pattern.h +163 -0
  258. data/ext/clipsruby/pprint.c +328 -0
  259. data/ext/clipsruby/pprint.h +79 -0
  260. data/ext/clipsruby/prccode.c +1478 -0
  261. data/ext/clipsruby/prccode.h +145 -0
  262. data/ext/clipsruby/prcdrfun.c +640 -0
  263. data/ext/clipsruby/prcdrfun.h +95 -0
  264. data/ext/clipsruby/prcdrpsr.c +1068 -0
  265. data/ext/clipsruby/prcdrpsr.h +79 -0
  266. data/ext/clipsruby/prdctfun.c +869 -0
  267. data/ext/clipsruby/prdctfun.h +77 -0
  268. data/ext/clipsruby/prntutil.c +878 -0
  269. data/ext/clipsruby/prntutil.h +125 -0
  270. data/ext/clipsruby/proflfun.c +827 -0
  271. data/ext/clipsruby/proflfun.h +118 -0
  272. data/ext/clipsruby/reorder.c +2082 -0
  273. data/ext/clipsruby/reorder.h +172 -0
  274. data/ext/clipsruby/reteutil.c +1732 -0
  275. data/ext/clipsruby/reteutil.h +111 -0
  276. data/ext/clipsruby/retract.c +710 -0
  277. data/ext/clipsruby/retract.h +74 -0
  278. data/ext/clipsruby/router.c +737 -0
  279. data/ext/clipsruby/router.h +147 -0
  280. data/ext/clipsruby/rulebin.c +1136 -0
  281. data/ext/clipsruby/rulebin.h +153 -0
  282. data/ext/clipsruby/rulebld.c +1328 -0
  283. data/ext/clipsruby/rulebld.h +62 -0
  284. data/ext/clipsruby/rulebsc.c +517 -0
  285. data/ext/clipsruby/rulebsc.h +91 -0
  286. data/ext/clipsruby/rulecmp.c +733 -0
  287. data/ext/clipsruby/rulecmp.h +63 -0
  288. data/ext/clipsruby/rulecom.c +1583 -0
  289. data/ext/clipsruby/rulecom.h +116 -0
  290. data/ext/clipsruby/rulecstr.c +892 -0
  291. data/ext/clipsruby/rulecstr.h +53 -0
  292. data/ext/clipsruby/ruledef.c +559 -0
  293. data/ext/clipsruby/ruledef.h +179 -0
  294. data/ext/clipsruby/ruledlt.c +599 -0
  295. data/ext/clipsruby/ruledlt.h +58 -0
  296. data/ext/clipsruby/rulelhs.c +1216 -0
  297. data/ext/clipsruby/rulelhs.h +52 -0
  298. data/ext/clipsruby/rulepsr.c +1073 -0
  299. data/ext/clipsruby/rulepsr.h +61 -0
  300. data/ext/clipsruby/scanner.c +856 -0
  301. data/ext/clipsruby/scanner.h +112 -0
  302. data/ext/clipsruby/setup.h +488 -0
  303. data/ext/clipsruby/sortfun.c +433 -0
  304. data/ext/clipsruby/sortfun.h +55 -0
  305. data/ext/clipsruby/strngfun.c +1173 -0
  306. data/ext/clipsruby/strngfun.h +96 -0
  307. data/ext/clipsruby/strngrtr.c +523 -0
  308. data/ext/clipsruby/strngrtr.h +97 -0
  309. data/ext/clipsruby/symblbin.c +648 -0
  310. data/ext/clipsruby/symblbin.h +64 -0
  311. data/ext/clipsruby/symblcmp.c +893 -0
  312. data/ext/clipsruby/symblcmp.h +61 -0
  313. data/ext/clipsruby/symbol.c +1961 -0
  314. data/ext/clipsruby/symbol.h +243 -0
  315. data/ext/clipsruby/sysdep.c +894 -0
  316. data/ext/clipsruby/sysdep.h +164 -0
  317. data/ext/clipsruby/textpro.c +1388 -0
  318. data/ext/clipsruby/textpro.h +77 -0
  319. data/ext/clipsruby/tmpltbin.c +609 -0
  320. data/ext/clipsruby/tmpltbin.h +108 -0
  321. data/ext/clipsruby/tmpltbsc.c +327 -0
  322. data/ext/clipsruby/tmpltbsc.h +87 -0
  323. data/ext/clipsruby/tmpltcmp.c +450 -0
  324. data/ext/clipsruby/tmpltcmp.h +57 -0
  325. data/ext/clipsruby/tmpltdef.c +584 -0
  326. data/ext/clipsruby/tmpltdef.h +155 -0
  327. data/ext/clipsruby/tmpltfun.c +2477 -0
  328. data/ext/clipsruby/tmpltfun.h +122 -0
  329. data/ext/clipsruby/tmpltlhs.c +379 -0
  330. data/ext/clipsruby/tmpltlhs.h +50 -0
  331. data/ext/clipsruby/tmpltpsr.c +819 -0
  332. data/ext/clipsruby/tmpltpsr.h +59 -0
  333. data/ext/clipsruby/tmpltrhs.c +595 -0
  334. data/ext/clipsruby/tmpltrhs.h +55 -0
  335. data/ext/clipsruby/tmpltutl.c +637 -0
  336. data/ext/clipsruby/tmpltutl.h +82 -0
  337. data/ext/clipsruby/userdata.c +156 -0
  338. data/ext/clipsruby/userdata.h +72 -0
  339. data/ext/clipsruby/userfunctions.c +70 -0
  340. data/ext/clipsruby/usrsetup.h +7 -0
  341. data/ext/clipsruby/utility.c +1594 -0
  342. data/ext/clipsruby/utility.h +250 -0
  343. data/ext/clipsruby/watch.c +865 -0
  344. data/ext/clipsruby/watch.h +124 -0
  345. data/lib/clipsruby.rb +1 -0
  346. metadata +388 -0
@@ -0,0 +1,1507 @@
1
+ /*******************************************************/
2
+ /* "C" Language Integrated Production System */
3
+ /* */
4
+ /* CLIPS Version 6.40 02/03/18 */
5
+ /* */
6
+ /* */
7
+ /*******************************************************/
8
+
9
+ /*************************************************************/
10
+ /* Purpose: Object System Construct Compiler Code */
11
+ /* */
12
+ /* Principal Programmer(s): */
13
+ /* Brian L. Dantes */
14
+ /* */
15
+ /* Contributing Programmer(s): */
16
+ /* */
17
+ /* Revision History: */
18
+ /* */
19
+ /* 6.24: Renamed BOOLEAN macro type to intBool. */
20
+ /* */
21
+ /* Added environment parameter to GenClose. */
22
+ /* */
23
+ /* 6.30: Changed integer type/precision. */
24
+ /* */
25
+ /* Removed conditional code for unsupported */
26
+ /* compilers/operating systems (IBM_MCW, */
27
+ /* MAC_MCW, and IBM_TBC). */
28
+ /* */
29
+ /* Added support for path name argument to */
30
+ /* constructs-to-c. */
31
+ /* */
32
+ /* Added const qualifiers to remove C++ */
33
+ /* deprecation warnings. */
34
+ /* */
35
+ /* 6.31: Optimization for marking relevant alpha nodes */
36
+ /* in the object pattern network. */
37
+ /* */
38
+ /* 6.40: Pragma once and other inclusion changes. */
39
+ /* */
40
+ /* Added support for booleans with <stdbool.h>. */
41
+ /* */
42
+ /* Removed use of void pointers for specific */
43
+ /* data structures. */
44
+ /* */
45
+ /* UDF redesign. */
46
+ /* */
47
+ /*************************************************************/
48
+
49
+ /* =========================================
50
+ *****************************************
51
+ EXTERNAL DEFINITIONS
52
+ =========================================
53
+ ***************************************** */
54
+ #include "setup.h"
55
+
56
+ #if OBJECT_SYSTEM && CONSTRUCT_COMPILER && (! RUN_TIME)
57
+
58
+ #include "conscomp.h"
59
+ #include "classcom.h"
60
+ #include "classfun.h"
61
+ #include "classini.h"
62
+ #include "cstrncmp.h"
63
+ #include "envrnmnt.h"
64
+ #include "objrtfnx.h"
65
+ #include "sysdep.h"
66
+
67
+ #if DEFRULE_CONSTRUCT
68
+ #include "objrtcmp.h"
69
+ #endif
70
+
71
+ #include "objcmp.h"
72
+
73
+ /* =========================================
74
+ *****************************************
75
+ CONSTANTS
76
+ =========================================
77
+ ***************************************** */
78
+ #define MODULEI 0
79
+ #define CLASSI 1
80
+ #define LINKI 2
81
+ #define SLOTI 3
82
+ #define TSLOTI 4
83
+ #define OSLOTI 5
84
+ #define HANDLERI 6
85
+ #define OHANDLERI 7
86
+
87
+ #define SAVE_ITEMS 8
88
+
89
+ /* =========================================
90
+ *****************************************
91
+ MACROS AND TYPES
92
+ =========================================
93
+ ***************************************** */
94
+ #define ClassPrefix() ConstructPrefix(ObjectCompilerData(theEnv)->ObjectCodeItem)
95
+ #define ClassLinkPrefix() ArbitraryPrefix(ObjectCompilerData(theEnv)->ObjectCodeItem,2)
96
+ #define SlotPrefix() ArbitraryPrefix(ObjectCompilerData(theEnv)->ObjectCodeItem,3)
97
+ #define TemplateSlotPrefix() ArbitraryPrefix(ObjectCompilerData(theEnv)->ObjectCodeItem,4)
98
+ #define OrderedSlotPrefix() ArbitraryPrefix(ObjectCompilerData(theEnv)->ObjectCodeItem,5)
99
+ #define HandlerPrefix() ArbitraryPrefix(ObjectCompilerData(theEnv)->ObjectCodeItem,6)
100
+ #define OrderedHandlerPrefix() ArbitraryPrefix(ObjectCompilerData(theEnv)->ObjectCodeItem,7)
101
+ #define SlotNamePrefix() ArbitraryPrefix(ObjectCompilerData(theEnv)->ObjectCodeItem,8)
102
+ #define SlotNameHashPrefix() ArbitraryPrefix(ObjectCompilerData(theEnv)->ObjectCodeItem,9)
103
+ #define ClassHashPrefix() ArbitraryPrefix(ObjectCompilerData(theEnv)->ObjectCodeItem,10)
104
+ #define ClassIDPrefix() ArbitraryPrefix(ObjectCompilerData(theEnv)->ObjectCodeItem,11)
105
+ #define MaxClassIDPrefix() ArbitraryPrefix(ObjectCompilerData(theEnv)->ObjectCodeItem,12)
106
+
107
+ typedef struct
108
+ {
109
+ unsigned long classCount;
110
+ unsigned short currentPartition;
111
+ unsigned short slotCount;
112
+ unsigned int maxIndices;
113
+ } MARK_INFO;
114
+
115
+ typedef union
116
+ {
117
+ struct
118
+ {
119
+ unsigned thePartition : 16;
120
+ unsigned theOffset : 16;
121
+ } theLocation;
122
+ unsigned long theLong;
123
+ } PACKED_LOCATION_INFO;
124
+
125
+ /***************************************/
126
+ /* LOCAL INTERNAL FUNCTION DEFINITIONS */
127
+ /***************************************/
128
+
129
+ static void ReadyObjectsForCode(Environment *);
130
+ static void MarkDefclassAndSlots(Environment *,ConstructHeader *,void *);
131
+ static void PrintSlotNameReference(Environment *,FILE *,SLOT_NAME *,unsigned int,unsigned int);
132
+ static void InitObjectsCode(Environment *,FILE *,unsigned int,unsigned int);
133
+ static bool ObjectsToCode(Environment *,const char *,const char *,char *,unsigned int,
134
+ FILE *,unsigned int,unsigned int);
135
+ static bool ClassIDMapToCode(Environment *,const char *,const char *,char *,unsigned int,
136
+ FILE *,unsigned int,unsigned int,unsigned int *);
137
+ static bool ClassHashTableToCode(Environment *,const char *,const char *,char *,unsigned int,
138
+ FILE *,unsigned int,unsigned int,unsigned int *);
139
+ static bool SlotNameHashTableToCode(Environment *,const char *,const char *,char *,unsigned int,
140
+ FILE *,unsigned int,unsigned int,unsigned int *);
141
+ static bool SlotNameEntriesToCode(Environment *,const char *,const char *,char *,unsigned int,
142
+ FILE *,unsigned int,unsigned int,unsigned int *);
143
+ static void CloseObjectFiles(Environment *,FILE *[SAVE_ITEMS],bool [SAVE_ITEMS],
144
+ struct CodeGeneratorFile [SAVE_ITEMS],unsigned int);
145
+ static void DefclassModuleToCode(Environment *,FILE *,Defmodule *,unsigned int,unsigned int);
146
+ static void SingleDefclassToCode(Environment *,FILE *,unsigned int,unsigned int,Defclass *,unsigned int,
147
+ unsigned int,unsigned int,unsigned int,unsigned int,unsigned int,unsigned int,
148
+ unsigned int,unsigned int,unsigned int,unsigned int,unsigned int,unsigned int);
149
+ static bool InheritanceLinksToCode(Environment *,FILE **,const char *,const char *,char *,
150
+ unsigned int,unsigned int,FILE *,
151
+ unsigned int *,unsigned int,Defclass *,unsigned int *,
152
+ unsigned int *,bool *,struct CodeGeneratorFile *);
153
+ static bool SlotsToCode(Environment *,FILE **,const char *,const char *,char *,unsigned int,unsigned int,FILE *,
154
+ unsigned int *,unsigned int,Defclass *,unsigned int *,
155
+ unsigned int *,bool *,struct CodeGeneratorFile *);
156
+ static bool TemplateSlotsToCode(Environment *,FILE **,const char *,const char *,char *,
157
+ unsigned int,unsigned int,FILE *,
158
+ unsigned int *,unsigned int,Defclass *,unsigned int *,
159
+ unsigned int *,bool *,struct CodeGeneratorFile *);
160
+ static bool OrderedSlotsToCode(Environment *,FILE **,const char *,const char *,char *,
161
+ unsigned int,unsigned int,FILE *,
162
+ unsigned int *,unsigned int,Defclass *,unsigned int *,
163
+ unsigned int *,bool *,struct CodeGeneratorFile *);
164
+ static bool HandlersToCode(Environment *,FILE **,const char *,const char *,char *,
165
+ unsigned int,unsigned int,FILE *,
166
+ unsigned int *,unsigned int,Defclass *,unsigned int,unsigned int *,
167
+ unsigned int *,bool *,struct CodeGeneratorFile *);
168
+ static bool OrderedHandlersToCode(Environment *,FILE **,const char *,const char *,char *,
169
+ unsigned int,unsigned int,FILE *,
170
+ unsigned int *,unsigned int,Defclass *,unsigned int *,
171
+ unsigned int *,bool *,struct CodeGeneratorFile *);
172
+
173
+ /* =========================================
174
+ *****************************************
175
+ EXTERNALLY VISIBLE FUNCTIONS
176
+ =========================================
177
+ ***************************************** */
178
+
179
+ /***************************************************
180
+ NAME : SetupObjectsCompiler
181
+ DESCRIPTION : Initializes the construct compiler
182
+ item for defclasses & handlers
183
+ INPUTS : None
184
+ RETURNS : Nothing useful
185
+ SIDE EFFECTS : Code generator item initialized
186
+ NOTES : None
187
+ ***************************************************/
188
+ void SetupObjectsCompiler(
189
+ Environment *theEnv)
190
+ {
191
+ AllocateEnvironmentData(theEnv,OBJECT_COMPILER_DATA,sizeof(struct objectCompilerData),NULL);
192
+
193
+ ObjectCompilerData(theEnv)->ObjectCodeItem = AddCodeGeneratorItem(theEnv,"objects",0,ReadyObjectsForCode,
194
+ InitObjectsCode,ObjectsToCode,13);
195
+ }
196
+
197
+
198
+ /*********************************************************
199
+ NAME : PrintClassReference
200
+ DESCRIPTION : Writes out a reference to the class array
201
+ INPUTS : 1) Output file pointer
202
+ 2) Class address
203
+ 3) Construct set image id
204
+ 4) The maximum number of indices allowed
205
+ in an array
206
+ RETURNS : Nothing useful
207
+ SIDE EFFECTS : Writes out class array reference to file
208
+ NOTES : None
209
+ *********************************************************/
210
+ void PrintClassReference(
211
+ Environment *theEnv,
212
+ FILE *fp,
213
+ Defclass *cls,
214
+ unsigned int imageID,
215
+ unsigned int maxIndices)
216
+ {
217
+ if (cls == NULL)
218
+ fprintf(fp,"NULL");
219
+ else
220
+ fprintf(fp,"&%s%u_%lu[%lu]",
221
+ ClassPrefix(),
222
+ imageID,
223
+ ((cls->header.bsaveID / maxIndices) + 1),
224
+ (cls->header.bsaveID % maxIndices));
225
+ }
226
+
227
+ /****************************************************
228
+ NAME : DefclassCModuleReference
229
+ DESCRIPTION : Prints out a reference to a
230
+ defclass module
231
+ INPUTS : 1) The output file
232
+ 2) The id of the module item
233
+ 3) The id of the image
234
+ 4) The maximum number of elements
235
+ allowed in an array
236
+ RETURNS : Nothing useful
237
+ SIDE EFFECTS : Defclass module reference printed
238
+ NOTES : None
239
+ ****************************************************/
240
+ void DefclassCModuleReference(
241
+ Environment *theEnv,
242
+ FILE *theFile,
243
+ unsigned long count,
244
+ unsigned int imageID,
245
+ unsigned int maxIndices)
246
+ {
247
+ fprintf(theFile,"MIHS &%s%u_%lu[%lu]",
248
+ ModulePrefix(ObjectCompilerData(theEnv)->ObjectCodeItem),
249
+ imageID,
250
+ (count / maxIndices) + 1,
251
+ (count % maxIndices));
252
+ }
253
+
254
+ /* =========================================
255
+ *****************************************
256
+ INTERNALLY VISIBLE FUNCTIONS
257
+ =========================================
258
+ ***************************************** */
259
+
260
+ /*******************************************************
261
+ NAME : ReadyObjectsForCode
262
+ DESCRIPTION : Sets index of classes and slot name
263
+ entries for use in compiled
264
+ expressions
265
+ INPUTS : None
266
+ RETURNS : Nothing useful
267
+ SIDE EFFECTS : BsaveIndices set
268
+ NOTES : None
269
+ *******************************************************/
270
+ static void ReadyObjectsForCode(
271
+ Environment *theEnv)
272
+ {
273
+ MARK_INFO markInfo;
274
+ unsigned long i;
275
+ int j;
276
+ SLOT_NAME *snp;
277
+
278
+ markInfo.classCount = 0L;
279
+ markInfo.currentPartition = 1;
280
+ markInfo.slotCount = 0;
281
+
282
+ /* =====================================
283
+ Gets the value of MaxIndices directly
284
+ from the global in CONSCOMP.C
285
+ ===================================== */
286
+ markInfo.maxIndices = ConstructCompilerData(theEnv)->MaxIndices;
287
+ DoForAllConstructs(theEnv,MarkDefclassAndSlots,DefclassData(theEnv)->DefclassModuleIndex,
288
+ false,&markInfo);
289
+ i = 0L;
290
+ for (j = 0 ; j < SLOT_NAME_TABLE_HASH_SIZE ; j++)
291
+ for (snp = DefclassData(theEnv)->SlotNameTable[j] ; snp != NULL ; snp = snp->nxt)
292
+ snp->bsaveIndex = i++;
293
+ }
294
+
295
+ /************************************************************
296
+ NAME : MarkDefclassAndSlots
297
+ DESCRIPTION : Sets the bsave indices of the classes
298
+ for use in printing references to
299
+ them later.
300
+
301
+ Also, the partitions and offsets are
302
+ predetermined for every slot and
303
+ packed into a single long (the slot
304
+ bsave index) for use in printing
305
+ references to them later
306
+ INPUTS : 1) The defclass
307
+ 2) A buffer containing the info:
308
+ a) Total number of classes counted so far
309
+ b) The current partition # for slots
310
+ c) The current offset in that partition
311
+ d) The max # of elements in any array
312
+ RETURNS : Nothing useful
313
+ SIDE EFFECTS : Bsave indices of classes and slots set
314
+ NOTES : The template slots are written at the
315
+ same time as the real slots - thus the
316
+ references must be predetermined
317
+ ************************************************************/
318
+ static void MarkDefclassAndSlots(
319
+ Environment *theEnv,
320
+ ConstructHeader *vTheDefclass,
321
+ void *vTheBuffer)
322
+ {
323
+ Defclass *theDefclass = (Defclass *) vTheDefclass;
324
+ MARK_INFO *markInfo = (MARK_INFO *) vTheBuffer;
325
+ long i;
326
+ PACKED_LOCATION_INFO theLocationInfo;
327
+ #if MAC_XCD
328
+ #pragma unused(theEnv)
329
+ #endif
330
+
331
+ theDefclass->header.bsaveID = markInfo->classCount++;
332
+ for (i = 0 ; i < theDefclass->slotCount ; i++)
333
+ {
334
+ theLocationInfo.theLocation.thePartition = markInfo->currentPartition;
335
+ theLocationInfo.theLocation.theOffset = markInfo->slotCount;
336
+ theDefclass->slots[i].bsaveIndex = theLocationInfo.theLong;
337
+ markInfo->slotCount++;
338
+ if (markInfo->slotCount >= markInfo->maxIndices)
339
+ {
340
+ markInfo->currentPartition++;
341
+ markInfo->slotCount = 0;
342
+ }
343
+ }
344
+ }
345
+
346
+ /*************************************************************
347
+ NAME : PrintSlotNameReference
348
+ DESCRIPTION : Writes out a reference to the slot name array
349
+ INPUTS : 1) Output file pointer
350
+ 2) Slot name address
351
+ 3) Construct set image id
352
+ 4) The maximum number of indices allowed
353
+ in an array
354
+ RETURNS : Nothing useful
355
+ SIDE EFFECTS : Writes out slot name array reference to file
356
+ NOTES : None
357
+ *************************************************************/
358
+ static void PrintSlotNameReference(
359
+ Environment *theEnv,
360
+ FILE *fp,
361
+ SLOT_NAME *snp,
362
+ unsigned int imageID,
363
+ unsigned int maxIndices)
364
+ {
365
+ if (snp == NULL)
366
+ fprintf(fp,"NULL");
367
+ else
368
+ fprintf(fp,"&%s%u_%lu[%lu]",
369
+ SlotNamePrefix(),
370
+ imageID,
371
+ ((snp->bsaveIndex / maxIndices) + 1),
372
+ (snp->bsaveIndex % maxIndices));
373
+ }
374
+
375
+ /*******************************************************
376
+ NAME : InitObjectsCode
377
+ DESCRIPTION : Writes out initialization code for
378
+ generic functions
379
+ INPUTS : 1) The initialization code file pointer
380
+ 2) The construct set image id
381
+ 3) The max number of indices allowed in
382
+ an array for this construct set
383
+ RETURNS : Nothing useful
384
+ SIDE EFFECTS : Writes out initialization code
385
+ NOTES : None
386
+ *******************************************************/
387
+ static void InitObjectsCode(
388
+ Environment *theEnv,
389
+ FILE *initFP,
390
+ unsigned int imageID,
391
+ unsigned int maxIndices)
392
+ {
393
+ #if MAC_XCD
394
+ #pragma unused(maxIndices)
395
+ #endif
396
+
397
+ fprintf(initFP," ObjectsRunTimeInitialize(theEnv,%s%u_1,%s%u_1,%s%u_1,%s%u);\n",
398
+ ClassHashPrefix(),imageID,SlotNameHashPrefix(),imageID,
399
+ ClassIDPrefix(),imageID,MaxClassIDPrefix(),imageID);
400
+ }
401
+
402
+ /*************************************************************
403
+ NAME : ObjectsToCode
404
+ DESCRIPTION : Writes out static array code for
405
+ classes, message-handlers, and associated
406
+ structures
407
+ INPUTS : 1) The base name of the construct set
408
+ 2) The base id for this construct
409
+ 3) The file pointer for the header file
410
+ 4) The base id for the construct set
411
+ 5) The max number of indices allowed
412
+ in an array
413
+ RETURNS : False on errors,
414
+ True if object system structures written
415
+ SIDE EFFECTS : Code written to files
416
+ NOTES : None
417
+ *************************************************************/
418
+ static bool ObjectsToCode(
419
+ Environment *theEnv,
420
+ const char *fileName,
421
+ const char *pathName,
422
+ char *fileNameBuffer,
423
+ unsigned int fileID,
424
+ FILE *headerFP,
425
+ unsigned int imageID,
426
+ unsigned int maxIndices)
427
+ {
428
+ unsigned int fileCount = 1;
429
+ Defmodule *theModule;
430
+ Defclass *theDefclass;
431
+ int i;
432
+ unsigned int moduleCount = 0;
433
+ unsigned int itemArrayCounts[SAVE_ITEMS];
434
+ unsigned int itemArrayVersions[SAVE_ITEMS];
435
+ FILE *itemFiles[SAVE_ITEMS];
436
+ bool itemReopenFlags[SAVE_ITEMS];
437
+ struct CodeGeneratorFile itemCodeFiles[SAVE_ITEMS];
438
+
439
+ for (i = 0 ; i < SAVE_ITEMS ; i++)
440
+ {
441
+ itemArrayCounts[i] = 0;
442
+ itemArrayVersions[i] = 1;
443
+ itemFiles[i] = NULL;
444
+ itemReopenFlags[i] = false;
445
+ itemCodeFiles[i].filePrefix = NULL;
446
+ itemCodeFiles[i].pathName = pathName;
447
+ itemCodeFiles[i].fileNameBuffer = fileNameBuffer;
448
+ }
449
+ fprintf(headerFP,"#include \"classcom.h\"\n");
450
+ fprintf(headerFP,"#include \"classini.h\"\n");
451
+ if (ClassIDMapToCode(theEnv,fileName,pathName,fileNameBuffer,fileID,headerFP,imageID,maxIndices,&fileCount)
452
+ == false)
453
+ return false;
454
+ if (ClassHashTableToCode(theEnv,fileName,pathName,fileNameBuffer,fileID,headerFP,imageID,maxIndices,&fileCount)
455
+ == false)
456
+ return false;
457
+ if (SlotNameHashTableToCode(theEnv,fileName,pathName,fileNameBuffer,fileID,headerFP,imageID,maxIndices,&fileCount)
458
+ == false)
459
+ return false;
460
+ if (SlotNameEntriesToCode(theEnv,fileName,pathName,fileNameBuffer,fileID,headerFP,imageID,maxIndices,&fileCount)
461
+ == false)
462
+ return false;
463
+
464
+ /* =============================================================
465
+ Loop through all the modules and all the defclasses writing
466
+ their C code representation to the file as they are traversed
467
+ ============================================================= */
468
+ theModule = GetNextDefmodule(theEnv,NULL);
469
+
470
+ while (theModule != NULL)
471
+ {
472
+ SetCurrentModule(theEnv,theModule);
473
+
474
+ itemFiles[MODULEI] =
475
+ OpenFileIfNeeded(theEnv,itemFiles[MODULEI],fileName,pathName,fileNameBuffer,fileID,imageID,&fileCount,
476
+ itemArrayVersions[MODULEI],headerFP,
477
+ "DEFCLASS_MODULE",ModulePrefix(ObjectCompilerData(theEnv)->ObjectCodeItem),
478
+ itemReopenFlags[MODULEI],&itemCodeFiles[MODULEI]);
479
+ if (itemFiles[MODULEI] == NULL)
480
+ goto ObjectCodeError;
481
+
482
+ DefclassModuleToCode(theEnv,itemFiles[MODULEI],theModule,imageID,maxIndices);
483
+ itemFiles[MODULEI] =
484
+ CloseFileIfNeeded(theEnv,itemFiles[MODULEI],&itemArrayCounts[MODULEI],
485
+ &itemArrayVersions[MODULEI],maxIndices,
486
+ &itemReopenFlags[MODULEI],&itemCodeFiles[MODULEI]);
487
+
488
+ for (theDefclass = GetNextDefclass(theEnv,NULL) ;
489
+ theDefclass != NULL ;
490
+ theDefclass = GetNextDefclass(theEnv,theDefclass))
491
+ {
492
+ itemFiles[CLASSI] =
493
+ OpenFileIfNeeded(theEnv,itemFiles[CLASSI],fileName,pathName,fileNameBuffer,fileID,imageID,&fileCount,
494
+ itemArrayVersions[CLASSI],headerFP,
495
+ "Defclass",ClassPrefix(),
496
+ itemReopenFlags[CLASSI],&itemCodeFiles[CLASSI]);
497
+ if (itemFiles[CLASSI] == NULL)
498
+ goto ObjectCodeError;
499
+ SingleDefclassToCode(theEnv,itemFiles[CLASSI],imageID,maxIndices,
500
+ theDefclass,moduleCount,
501
+ itemArrayVersions[LINKI],itemArrayCounts[LINKI],
502
+ itemArrayVersions[SLOTI],itemArrayCounts[SLOTI],
503
+ itemArrayVersions[TSLOTI],itemArrayCounts[TSLOTI],
504
+ itemArrayVersions[OSLOTI],itemArrayCounts[OSLOTI],
505
+ itemArrayVersions[HANDLERI],itemArrayCounts[HANDLERI],
506
+ itemArrayVersions[OHANDLERI],itemArrayCounts[OHANDLERI]);
507
+ itemArrayCounts[CLASSI]++;
508
+ itemFiles[CLASSI] =
509
+ CloseFileIfNeeded(theEnv,itemFiles[CLASSI],&itemArrayCounts[CLASSI],
510
+ &itemArrayVersions[CLASSI],maxIndices,
511
+ &itemReopenFlags[CLASSI],&itemCodeFiles[CLASSI]);
512
+
513
+ if (InheritanceLinksToCode(theEnv,&itemFiles[LINKI],fileName,pathName,fileNameBuffer,fileID,imageID,
514
+ headerFP,&fileCount,maxIndices,theDefclass,
515
+ &itemArrayVersions[LINKI],&itemArrayCounts[LINKI],
516
+ &itemReopenFlags[LINKI],&itemCodeFiles[LINKI])
517
+ == false)
518
+ goto ObjectCodeError;
519
+
520
+ if (SlotsToCode(theEnv,&itemFiles[SLOTI],fileName,pathName,fileNameBuffer,fileID,imageID,
521
+ headerFP,&fileCount,maxIndices,theDefclass,
522
+ &itemArrayVersions[SLOTI],&itemArrayCounts[SLOTI],
523
+ &itemReopenFlags[SLOTI],&itemCodeFiles[SLOTI])
524
+ == false)
525
+ goto ObjectCodeError;
526
+
527
+ if (TemplateSlotsToCode(theEnv,&itemFiles[TSLOTI],fileName,pathName,fileNameBuffer,fileID,imageID,
528
+ headerFP,&fileCount,maxIndices,theDefclass,
529
+ &itemArrayVersions[TSLOTI],&itemArrayCounts[TSLOTI],
530
+ &itemReopenFlags[TSLOTI],&itemCodeFiles[TSLOTI])
531
+ == false)
532
+ goto ObjectCodeError;
533
+
534
+ if (OrderedSlotsToCode(theEnv,&itemFiles[OSLOTI],fileName,pathName,fileNameBuffer,fileID,imageID,
535
+ headerFP,&fileCount,maxIndices,theDefclass,
536
+ &itemArrayVersions[OSLOTI],&itemArrayCounts[OSLOTI],
537
+ &itemReopenFlags[OSLOTI],&itemCodeFiles[OSLOTI])
538
+ == false)
539
+ goto ObjectCodeError;
540
+
541
+ if (HandlersToCode(theEnv,&itemFiles[HANDLERI],fileName,pathName,fileNameBuffer,fileID,imageID,
542
+ headerFP,&fileCount,maxIndices,theDefclass,moduleCount,
543
+ &itemArrayVersions[HANDLERI],&itemArrayCounts[HANDLERI],
544
+ &itemReopenFlags[HANDLERI],&itemCodeFiles[HANDLERI])
545
+ == false)
546
+ goto ObjectCodeError;
547
+
548
+ if (OrderedHandlersToCode(theEnv,&itemFiles[OHANDLERI],fileName,pathName,fileNameBuffer,fileID,imageID,
549
+ headerFP,&fileCount,maxIndices,theDefclass,
550
+ &itemArrayVersions[OHANDLERI],&itemArrayCounts[OHANDLERI],
551
+ &itemReopenFlags[OHANDLERI],&itemCodeFiles[OHANDLERI])
552
+ == false)
553
+ goto ObjectCodeError;
554
+ }
555
+
556
+ theModule = GetNextDefmodule(theEnv,theModule);
557
+ moduleCount++;
558
+ itemArrayCounts[MODULEI]++;
559
+ }
560
+
561
+ CloseObjectFiles(theEnv,itemFiles,itemReopenFlags,itemCodeFiles,maxIndices);
562
+ return true;
563
+
564
+ ObjectCodeError:
565
+ CloseObjectFiles(theEnv,itemFiles,itemReopenFlags,itemCodeFiles,maxIndices);
566
+ return false;
567
+ }
568
+
569
+ /************************************************************
570
+ NAME : ClassIDMapToCode
571
+ DESCRIPTION : Writes out class id map
572
+ INPUTS : 1) Header file pointer
573
+ 2) Output file pointer
574
+ 3) The construct set image id
575
+ 4) The max # of allowed indices
576
+ 5) Caller's file count buffer
577
+ RETURNS : True if all OK, false otherwise
578
+ SIDE EFFECTS : Class ID Map and Max Indices Written
579
+ NOTES : None
580
+ ***********************************************************/
581
+ static bool ClassIDMapToCode(
582
+ Environment *theEnv,
583
+ const char *fileName,
584
+ const char *pathName,
585
+ char *fileNameBuffer,
586
+ unsigned int fileID,
587
+ FILE *headerFP,
588
+ unsigned int imageID,
589
+ unsigned int maxIndices,
590
+ unsigned int *fileCount)
591
+ {
592
+ FILE *classIDMapFile = NULL;
593
+ unsigned int classIDMapArrayCount;
594
+ unsigned int classIDMapArrayVersion = 1;
595
+
596
+ classIDMapFile = OpenFileIfNeeded(theEnv,classIDMapFile,fileName,pathName,fileNameBuffer,fileID,imageID,fileCount,
597
+ classIDMapArrayVersion,headerFP,
598
+ "Defclass *",ClassIDPrefix(),false,NULL);
599
+ if (classIDMapFile == NULL)
600
+ return false;
601
+ for (classIDMapArrayCount = 0 ;
602
+ classIDMapArrayCount < DefclassData(theEnv)->MaxClassID ;
603
+ classIDMapArrayCount++)
604
+ {
605
+ if (classIDMapArrayCount > 0)
606
+ fprintf(classIDMapFile,",\n");
607
+ PrintClassReference(theEnv,classIDMapFile,DefclassData(theEnv)->ClassIDMap[classIDMapArrayCount],
608
+ imageID,maxIndices);
609
+ }
610
+ fprintf(classIDMapFile,"};\n\n");
611
+ fprintf(classIDMapFile,"unsigned %s%d = %u;\n",
612
+ MaxClassIDPrefix(),imageID,(unsigned) DefclassData(theEnv)->MaxClassID);
613
+ fprintf(headerFP,"extern unsigned %s%d;\n",MaxClassIDPrefix(),imageID);
614
+ GenClose(theEnv,classIDMapFile);
615
+ return true;
616
+ }
617
+
618
+ /************************************************************
619
+ NAME : ClassHashTableToCode
620
+ DESCRIPTION : Writes out class hash table
621
+ INPUTS : 1) Header file pointer
622
+ 2) Output file pointer
623
+ 3) The construct set image id
624
+ 4) The max # of allowed indices
625
+ 5) Caller's file count buffer
626
+ RETURNS : True if all OK, false otherwise
627
+ SIDE EFFECTS : Class Hash Table Written
628
+ NOTES : None
629
+ ***********************************************************/
630
+ static bool ClassHashTableToCode(
631
+ Environment *theEnv,
632
+ const char *fileName,
633
+ const char *pathName,
634
+ char *fileNameBuffer,
635
+ unsigned int fileID,
636
+ FILE *headerFP,
637
+ unsigned int imageID,
638
+ unsigned int maxIndices,
639
+ unsigned int *fileCount)
640
+ {
641
+ FILE *classHashFile = NULL;
642
+ unsigned int classHashArrayCount,
643
+ classHashArrayVersion = 1;
644
+
645
+ classHashFile = OpenFileIfNeeded(theEnv,classHashFile,fileName,pathName,fileNameBuffer,fileID,imageID,fileCount,
646
+ classHashArrayVersion,headerFP,
647
+ "Defclass *",ClassHashPrefix(),false,NULL);
648
+ if (classHashFile == NULL)
649
+ return false;
650
+ for (classHashArrayCount = 0 ;
651
+ classHashArrayCount < CLASS_TABLE_HASH_SIZE ;
652
+ classHashArrayCount++)
653
+ {
654
+ if (classHashArrayCount > 0)
655
+ fprintf(classHashFile,",\n");
656
+ PrintClassReference(theEnv,classHashFile,DefclassData(theEnv)->ClassTable[classHashArrayCount],
657
+ imageID,maxIndices);
658
+ }
659
+
660
+ CloseFileIfNeeded(theEnv,classHashFile,&classHashArrayCount,
661
+ &classHashArrayVersion,classHashArrayCount,NULL,NULL);
662
+ return true;
663
+ }
664
+
665
+ /************************************************************
666
+ NAME : SlotNameHashTableToCode
667
+ DESCRIPTION : Writes out slot name entry hash table
668
+ INPUTS : 1) Header file pointer
669
+ 2) Output file pointer
670
+ 3) The construct set image id
671
+ 4) The max # of allowed indices
672
+ 5) Caller's version number buffer
673
+ RETURNS : True if all OK, false otherwise
674
+ SIDE EFFECTS : Slot Name Hash Table Written
675
+ NOTES : None
676
+ ***********************************************************/
677
+ static bool SlotNameHashTableToCode(
678
+ Environment *theEnv,
679
+ const char *fileName,
680
+ const char *pathName,
681
+ char *fileNameBuffer,
682
+ unsigned int fileID,
683
+ FILE *headerFP,
684
+ unsigned int imageID,
685
+ unsigned int maxIndices,
686
+ unsigned int *fileCount)
687
+ {
688
+ FILE *slotNameHashFile = NULL;
689
+ unsigned int slotNameHashArrayCount,
690
+ slotNameHashArrayVersion = 1;
691
+
692
+ slotNameHashFile = OpenFileIfNeeded(theEnv,slotNameHashFile,fileName,pathName,fileNameBuffer,fileID,
693
+ imageID,fileCount,
694
+ slotNameHashArrayVersion,headerFP,
695
+ "SLOT_NAME *",SlotNameHashPrefix(),false,NULL);
696
+ if (slotNameHashFile == NULL)
697
+ return false;
698
+ for (slotNameHashArrayCount = 0 ;
699
+ slotNameHashArrayCount < SLOT_NAME_TABLE_HASH_SIZE ;
700
+ slotNameHashArrayCount++)
701
+ {
702
+ if (slotNameHashArrayCount > 0)
703
+ fprintf(slotNameHashFile,",\n");
704
+ PrintSlotNameReference(theEnv,slotNameHashFile,DefclassData(theEnv)->SlotNameTable[slotNameHashArrayCount],
705
+ imageID,maxIndices);
706
+ }
707
+ CloseFileIfNeeded(theEnv,slotNameHashFile,&slotNameHashArrayCount,
708
+ &slotNameHashArrayVersion,slotNameHashArrayCount,
709
+ NULL,NULL);
710
+ return true;
711
+ }
712
+
713
+ /************************************************************
714
+ NAME : SlotNameEntriesToCode
715
+ DESCRIPTION : Writes out slot name entries
716
+ INPUTS : 1) Header file pointer
717
+ 2) Output file pointer
718
+ 3) The construct set image id
719
+ 4) The max # of allowed indices
720
+ 5) Caller's version number buffer
721
+ RETURNS : True if all OK, false otherwise
722
+ SIDE EFFECTS : Slot name entries Written
723
+ NOTES : None
724
+ ***********************************************************/
725
+ static bool SlotNameEntriesToCode(
726
+ Environment *theEnv,
727
+ const char *fileName,
728
+ const char *pathName,
729
+ char *fileNameBuffer,
730
+ unsigned int fileID,
731
+ FILE *headerFP,
732
+ unsigned int imageID,
733
+ unsigned int maxIndices,
734
+ unsigned int *fileCount)
735
+ {
736
+ FILE *slotNameFile = NULL;
737
+ unsigned int slotNameArrayCount = 0,
738
+ slotNameArrayVersion = 1;
739
+ SLOT_NAME *snp;
740
+ unsigned i;
741
+
742
+ for (i = 0 ; i < SLOT_NAME_TABLE_HASH_SIZE ; i++)
743
+ {
744
+ for (snp = DefclassData(theEnv)->SlotNameTable[i] ; snp != NULL ; snp = snp->nxt)
745
+ {
746
+ slotNameFile = OpenFileIfNeeded(theEnv,slotNameFile,fileName,pathName,fileNameBuffer,fileID,
747
+ imageID,fileCount,
748
+ slotNameArrayVersion,headerFP,
749
+ "SLOT_NAME",SlotNamePrefix(),false,NULL);
750
+ if (slotNameFile == NULL)
751
+ return false;
752
+ fprintf(slotNameFile,"{ %u,1,%d,",snp->hashTableIndex,snp->id);
753
+ PrintSymbolReference(theEnv,slotNameFile,snp->name);
754
+ fprintf(slotNameFile,",");
755
+ PrintSymbolReference(theEnv,slotNameFile,snp->putHandlerName);
756
+ fprintf(slotNameFile,",");
757
+ PrintSlotNameReference(theEnv,slotNameFile,snp->nxt,imageID,maxIndices);
758
+ fprintf(slotNameFile,",0L }");
759
+ slotNameArrayCount++;
760
+ slotNameFile = CloseFileIfNeeded(theEnv,slotNameFile,&slotNameArrayCount,
761
+ &slotNameArrayVersion,maxIndices,NULL,NULL);
762
+ }
763
+ }
764
+ if (slotNameFile != NULL)
765
+ CloseFileIfNeeded(theEnv,slotNameFile,&slotNameArrayCount,
766
+ &slotNameArrayVersion,slotNameArrayCount,NULL,NULL);
767
+ return true;
768
+ }
769
+
770
+ /******************************************************
771
+ NAME : CloseObjectFiles
772
+ DESCRIPTION : Closes construct compiler files
773
+ for defclass structures
774
+ INPUTS : 1) An array containing all the
775
+ pertinent file pointers
776
+ 2) An array containing all the
777
+ pertinent file reopen flags
778
+ 3) An array containing all the
779
+ pertinent file name/id/version info
780
+ 4) The maximum number of indices
781
+ allowed in an array
782
+ RETURNS : Nothing useful
783
+ SIDE EFFECTS : Files closed
784
+ NOTES : None
785
+ *****************************************************/
786
+ static void CloseObjectFiles(
787
+ Environment *theEnv,
788
+ FILE *itemFiles[SAVE_ITEMS],
789
+ bool itemReopenFlags[SAVE_ITEMS],
790
+ struct CodeGeneratorFile itemCodeFiles[SAVE_ITEMS],
791
+ unsigned int maxIndices)
792
+ {
793
+ unsigned int count = maxIndices;
794
+ unsigned int arrayVersion = 0;
795
+ int i;
796
+
797
+ for (i = 0 ; i < SAVE_ITEMS ; i++)
798
+ {
799
+ count = maxIndices;
800
+ itemFiles[i] = CloseFileIfNeeded(theEnv,itemFiles[i],&count,&arrayVersion,
801
+ maxIndices,&itemReopenFlags[i],
802
+ &itemCodeFiles[i]);
803
+ }
804
+ }
805
+
806
+ /***************************************************
807
+ NAME : DefclassModuleToCode
808
+ DESCRIPTION : Writes out the C values for a
809
+ defclass module item
810
+ INPUTS : 1) The output file
811
+ 2) The module for the defclasses
812
+ 3) The compile image id
813
+ 4) The maximum number of elements
814
+ in an array
815
+ RETURNS : Nothing useful
816
+ SIDE EFFECTS : Defclass module item written
817
+ NOTES : None
818
+ ***************************************************/
819
+ static void DefclassModuleToCode(
820
+ Environment *theEnv,
821
+ FILE *theFile,
822
+ Defmodule *theModule,
823
+ unsigned int imageID,
824
+ unsigned int maxIndices)
825
+ {
826
+ fprintf(theFile,"{");
827
+ ConstructModuleToCode(theEnv,theFile,theModule,imageID,maxIndices,
828
+ DefclassData(theEnv)->DefclassModuleIndex,ClassPrefix());
829
+ fprintf(theFile,"}");
830
+ }
831
+
832
+ /****************************************************************
833
+ NAME : SingleDefclassToCode
834
+ DESCRIPTION : Writes out a single defclass's
835
+ data to the file
836
+ INPUTS : 1) The output file
837
+ 2) The compile image id
838
+ 3) The maximum number of
839
+ elements in an array
840
+ 4) The defclass
841
+ 5) The module index
842
+ 6) The partition holding the
843
+ defclass inheritance links
844
+ 7) The relative index of the
845
+ inheritance links in the partition
846
+ 8) The partition holding the
847
+ defclass slots
848
+ 9) The relative index of the
849
+ slots in the partition
850
+ 10) The partition holding the
851
+ defclass template slots
852
+ 11) The relative index of the
853
+ template slots in the partition
854
+ 12) The partition holding the
855
+ defclass ordered slot map
856
+ 13) The relative index of the
857
+ ordered slot map in the partition
858
+ 14) The partition holding the
859
+ defclass message-handlers
860
+ 15) The relative index of the
861
+ message-handlers in the partition
862
+ 16) The partition holding the
863
+ defclass ordered handler map
864
+ 17) The relative index of the
865
+ ordered handler map in the partition
866
+ RETURNS : Nothing useful
867
+ SIDE EFFECTS : Defclass data written
868
+ NOTES : None
869
+ ***************************************************************/
870
+ static void SingleDefclassToCode(
871
+ Environment *theEnv,
872
+ FILE *theFile,
873
+ unsigned int imageID,
874
+ unsigned int maxIndices,
875
+ Defclass *theDefclass,
876
+ unsigned int moduleCount,
877
+ unsigned int classLinkArrayVersion,
878
+ unsigned int classLinkArrayCount,
879
+ unsigned int slotArrayVersion,
880
+ unsigned int slotArrayCount,
881
+ unsigned int templateSlotArrayVersion,
882
+ unsigned int templateSlotArrayCount,
883
+ unsigned int orderedSlotArrayVersion,
884
+ unsigned int orderedSlotArrayCount,
885
+ unsigned int handlerArrayVersion,
886
+ unsigned int handlerArrayCount,
887
+ unsigned int orderedHandlerArrayVersion,
888
+ unsigned int orderedHandlerArrayCount)
889
+ {
890
+ /* ==================
891
+ Defclass Header
892
+ ================== */
893
+ fprintf(theFile,"{");
894
+ ConstructHeaderToCode(theEnv,theFile,&theDefclass->header,imageID,maxIndices,moduleCount,
895
+ ModulePrefix(ObjectCompilerData(theEnv)->ObjectCodeItem),ClassPrefix());
896
+
897
+ /* =========================
898
+ Defclass specific data
899
+ ========================= */
900
+ fprintf(theFile,",1,%u,%u,%u,0,0,%u,0,%u,\n ",
901
+ theDefclass->system,theDefclass->abstract,
902
+ theDefclass->reactive,(unsigned) theDefclass->id,
903
+ theDefclass->hashTableIndex);
904
+
905
+ if (theDefclass->directSuperclasses.classCount > 0)
906
+ fprintf(theFile,"{ %lu,&%s%d_%d[%d] },",
907
+ theDefclass->directSuperclasses.classCount,
908
+ ClassLinkPrefix(),
909
+ imageID,classLinkArrayVersion,classLinkArrayCount);
910
+ else
911
+ fprintf(theFile,"{ 0,NULL },");
912
+ classLinkArrayCount += theDefclass->directSuperclasses.classCount;
913
+
914
+ if (theDefclass->directSubclasses.classCount > 0)
915
+ fprintf(theFile,"{ %lu,&%s%d_%d[%d] },",
916
+ theDefclass->directSubclasses.classCount,
917
+ ClassLinkPrefix(),
918
+ imageID,classLinkArrayVersion,classLinkArrayCount);
919
+ else
920
+ fprintf(theFile,"{ 0,NULL },");
921
+ classLinkArrayCount += theDefclass->directSubclasses.classCount;
922
+
923
+ if (theDefclass->allSuperclasses.classCount > 0)
924
+ fprintf(theFile,"{ %lu,&%s%d_%d[%d] },",
925
+ theDefclass->allSuperclasses.classCount,
926
+ ClassLinkPrefix(),
927
+ imageID,classLinkArrayVersion,classLinkArrayCount);
928
+ else
929
+ fprintf(theFile,"{ 0,NULL },\n ");
930
+
931
+ if (theDefclass->slots != NULL)
932
+ fprintf(theFile,"&%s%d_%d[%d],",
933
+ SlotPrefix(),imageID,
934
+ slotArrayVersion,slotArrayCount);
935
+ else
936
+ fprintf(theFile,"NULL,");
937
+
938
+ if (theDefclass->instanceTemplate != NULL)
939
+ fprintf(theFile,"&%s%d_%d[%d],",
940
+ TemplateSlotPrefix(),imageID,
941
+ templateSlotArrayVersion,templateSlotArrayCount);
942
+ else
943
+ fprintf(theFile,"NULL,");
944
+
945
+ if (theDefclass->slotNameMap != NULL)
946
+ fprintf(theFile,"&%s%d_%d[%d],",
947
+ OrderedSlotPrefix(),imageID,
948
+ orderedSlotArrayVersion,orderedSlotArrayCount);
949
+ else
950
+ fprintf(theFile,"NULL,");
951
+
952
+ fprintf(theFile,"%u,%u,%u,%u,NULL,NULL,\n ",
953
+ theDefclass->slotCount,theDefclass->localInstanceSlotCount,
954
+ theDefclass->instanceSlotCount,theDefclass->maxSlotNameID);
955
+
956
+ if (theDefclass->handlers != NULL)
957
+ fprintf(theFile,"&%s%d_%d[%d],",
958
+ HandlerPrefix(),imageID,
959
+ handlerArrayVersion,handlerArrayCount);
960
+ else
961
+ fprintf(theFile,"NULL,");
962
+
963
+ if (theDefclass->handlerOrderMap != NULL)
964
+ fprintf(theFile,"&%s%d_%d[%d],",
965
+ OrderedHandlerPrefix(),imageID,
966
+ orderedHandlerArrayVersion,orderedHandlerArrayCount);
967
+ else
968
+ fprintf(theFile,"NULL,");
969
+
970
+ fprintf(theFile,"%u,",theDefclass->handlerCount);
971
+ PrintClassReference(theEnv,theFile,theDefclass->nxtHash,imageID,maxIndices);
972
+ fprintf(theFile,",");
973
+ PrintBitMapReference(theEnv,theFile,theDefclass->scopeMap);
974
+
975
+ #if DEFRULE_CONSTRUCT
976
+ fprintf(theFile,",");
977
+ ClassAlphaLinkReference(theEnv,theDefclass->relevant_terminal_alpha_nodes,theFile,imageID,maxIndices);
978
+ #endif
979
+
980
+ fprintf(theFile,",\"\"");
981
+
982
+ fprintf(theFile,"}");
983
+ }
984
+
985
+ /***********************************************************
986
+ NAME : InheritanceLinksToCode
987
+ DESCRIPTION : Prints out superclass/subclass
988
+ inheritance links - all links
989
+ for a particular class are
990
+ guaranteed to be in the same
991
+ array partition
992
+ INPUTS : 1) A buffer for the inheritance links file
993
+ 2) The base image name
994
+ 3) The id for this type of data
995
+ 4) The base image id
996
+ 5) The general header file
997
+ 6) A buffer for the version number of
998
+ the file for this type of data
999
+ 7) The maximum # of elements in any array
1000
+ 8) A pointer to the class
1001
+ 9) A buffer holding the links partition #
1002
+ 10) A buffer holding the links relative
1003
+ index in the partition
1004
+ 11) A buffer for a flag indicating if the
1005
+ buffer file can be reopened later
1006
+ 12) A pointer to the file info for
1007
+ this data if the last file needs
1008
+ to be reopened for termination
1009
+ RETURNS : True if all OK, false otherwise
1010
+ SIDE EFFECTS : Inheritance links written
1011
+ NOTES : None
1012
+ ***********************************************************/
1013
+ static bool InheritanceLinksToCode(
1014
+ Environment *theEnv,
1015
+ FILE **classLinkFile,
1016
+ const char *fileName,
1017
+ const char *pathName,
1018
+ char *fileNameBuffer,
1019
+ unsigned int fileID,
1020
+ unsigned int imageID,
1021
+ FILE *headerFP,
1022
+ unsigned int *fileCount,
1023
+ unsigned int maxIndices,
1024
+ Defclass *theDefclass,
1025
+ unsigned int *classLinkArrayVersion,
1026
+ unsigned int *classLinkArrayCount,
1027
+ bool *reopenClassLinkFile,
1028
+ struct CodeGeneratorFile *classLinkCodeFile)
1029
+ {
1030
+ unsigned long i;
1031
+ unsigned long inheritanceLinkCount;
1032
+ bool linkPrinted = false;
1033
+
1034
+ inheritanceLinkCount = theDefclass->directSuperclasses.classCount +
1035
+ theDefclass->directSubclasses.classCount +
1036
+ theDefclass->allSuperclasses.classCount;
1037
+
1038
+ if (inheritanceLinkCount == 0)
1039
+ return true;
1040
+
1041
+ *classLinkFile = OpenFileIfNeeded(theEnv,*classLinkFile,fileName,pathName,fileNameBuffer,fileID,
1042
+ imageID,fileCount,
1043
+ *classLinkArrayVersion,headerFP,
1044
+ "Defclass *",ClassLinkPrefix(),
1045
+ *reopenClassLinkFile,classLinkCodeFile);
1046
+ if (*classLinkFile == NULL)
1047
+ return false;
1048
+
1049
+ for (i = 0 ; i < theDefclass->directSuperclasses.classCount ; i++)
1050
+ {
1051
+ if (linkPrinted)
1052
+ fprintf(*classLinkFile,",");
1053
+ PrintClassReference(theEnv,*classLinkFile,
1054
+ theDefclass->directSuperclasses.classArray[i],
1055
+ imageID,maxIndices);
1056
+ linkPrinted = true;
1057
+ }
1058
+ for (i = 0 ; i < theDefclass->directSubclasses.classCount ; i++)
1059
+ {
1060
+ if (linkPrinted)
1061
+ fprintf(*classLinkFile,",");
1062
+ PrintClassReference(theEnv,*classLinkFile,
1063
+ theDefclass->directSubclasses.classArray[i],
1064
+ imageID,maxIndices);
1065
+ linkPrinted = true;
1066
+ }
1067
+ for (i = 0 ; i < theDefclass->allSuperclasses.classCount ; i++)
1068
+ {
1069
+ if (linkPrinted)
1070
+ fprintf(*classLinkFile,",");
1071
+ PrintClassReference(theEnv,*classLinkFile,
1072
+ theDefclass->allSuperclasses.classArray[i],
1073
+ imageID,maxIndices);
1074
+ linkPrinted = true;
1075
+ }
1076
+ *classLinkArrayCount += inheritanceLinkCount;
1077
+ *classLinkFile = CloseFileIfNeeded(theEnv,*classLinkFile,classLinkArrayCount,
1078
+ classLinkArrayVersion,maxIndices,
1079
+ reopenClassLinkFile,classLinkCodeFile);
1080
+ return true;
1081
+ }
1082
+
1083
+ /***********************************************************
1084
+ NAME : SlotsToCode
1085
+ DESCRIPTION : Prints out slots - all slots
1086
+ for a particular class are
1087
+ guaranteed to be in the same
1088
+ array partition
1089
+ INPUTS : 1) A buffer for the slots file
1090
+ 2) The base image name
1091
+ 3) The id for this type of data
1092
+ 4) The base image id
1093
+ 5) The general header file
1094
+ 6) A buffer for the version number of
1095
+ the file for this type of data
1096
+ 7) The maximum # of elements in any array
1097
+ 8) A pointer to the class
1098
+ 9) A buffer holding the slots partition #
1099
+ 10) A buffer holding the slots relative
1100
+ index in the partition
1101
+ 11) A buffer for a flag indicating if the
1102
+ buffer file can be reopened later
1103
+ 12) A pointer to the file info for
1104
+ this data if the last file needs
1105
+ to be reopened for termination
1106
+ RETURNS : True if all OK, FALSE
1107
+ otherwise
1108
+ SIDE EFFECTS : Slots written
1109
+ NOTES : None
1110
+ ***********************************************************/
1111
+ static bool SlotsToCode(
1112
+ Environment *theEnv,
1113
+ FILE **slotFile,
1114
+ const char *fileName,
1115
+ const char *pathName,
1116
+ char *fileNameBuffer,
1117
+ unsigned int fileID,
1118
+ unsigned int imageID,
1119
+ FILE *headerFP,
1120
+ unsigned int *fileCount,
1121
+ unsigned int maxIndices,
1122
+ Defclass *theDefclass,
1123
+ unsigned int *slotArrayVersion,
1124
+ unsigned int *slotArrayCount,
1125
+ bool *reopenSlotFile,
1126
+ struct CodeGeneratorFile *slotCodeFile)
1127
+ {
1128
+ long i;
1129
+ SlotDescriptor *sd;
1130
+ Expression *tmpexp;
1131
+ PACKED_LOCATION_INFO theLocationInfo;
1132
+
1133
+ if (theDefclass->slotCount == 0)
1134
+ return true;
1135
+
1136
+ *slotFile = OpenFileIfNeeded(theEnv,*slotFile,fileName,pathName,fileNameBuffer,fileID,
1137
+ imageID,fileCount,
1138
+ *slotArrayVersion,headerFP,
1139
+ "SlotDescriptor",SlotPrefix(),
1140
+ *reopenSlotFile,slotCodeFile);
1141
+ if (*slotFile == NULL)
1142
+ return false;
1143
+
1144
+ for (i = 0 ; i < theDefclass->slotCount ; i++)
1145
+ {
1146
+ sd = &theDefclass->slots[i];
1147
+ if (i > 0)
1148
+ fprintf(*slotFile,",\n");
1149
+ fprintf(*slotFile,"{ %u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,",
1150
+ sd->shared,sd->multiple,
1151
+ sd->composite,sd->noInherit,
1152
+ sd->noWrite,sd->initializeOnly,
1153
+ sd->dynamicDefault,sd->defaultSpecified,
1154
+ sd->noDefault,sd->reactive,
1155
+ sd->publicVisibility,sd->createReadAccessor,
1156
+ sd->createWriteAccessor,sd->overrideMessageSpecified);
1157
+ PrintClassReference(theEnv,*slotFile,sd->cls,imageID,maxIndices);
1158
+ fprintf(*slotFile,",");
1159
+ PrintSlotNameReference(theEnv,*slotFile,sd->slotName,imageID,maxIndices);
1160
+ fprintf(*slotFile,",\n ");
1161
+ PrintSymbolReference(theEnv,*slotFile,sd->overrideMessage);
1162
+ if (sd->defaultValue != NULL)
1163
+ {
1164
+ fprintf(*slotFile,",(void *) ");
1165
+ if (sd->dynamicDefault)
1166
+ ExpressionToCode(theEnv,*slotFile,(Expression *) sd->defaultValue);
1167
+ else
1168
+ {
1169
+ tmpexp = ConvertValueToExpression(theEnv,(UDFValue *) sd->defaultValue);
1170
+ ExpressionToCode(theEnv,*slotFile,tmpexp);
1171
+ ReturnExpression(theEnv,tmpexp);
1172
+ }
1173
+ }
1174
+ else
1175
+ fprintf(*slotFile,",NULL");
1176
+ fprintf(*slotFile,",");
1177
+ PrintConstraintReference(theEnv,*slotFile,sd->constraint,imageID,maxIndices);
1178
+ fprintf(*slotFile,",0,0L,");
1179
+ if (sd->shared)
1180
+ {
1181
+ theLocationInfo.theLong = sd->sharedValue.desc->bsaveIndex;
1182
+ fprintf(*slotFile,"{ &%s%d_%u[%u],0,0,0,{ NULL } } }",
1183
+ SlotPrefix(),imageID,
1184
+ theLocationInfo.theLocation.thePartition,
1185
+ theLocationInfo.theLocation.theOffset);
1186
+ }
1187
+ else
1188
+ fprintf(*slotFile,"{ NULL,0,0,0, { NULL } } }");
1189
+ }
1190
+ *slotArrayCount += theDefclass->slotCount;
1191
+ *slotFile = CloseFileIfNeeded(theEnv,*slotFile,slotArrayCount,
1192
+ slotArrayVersion,maxIndices,
1193
+ reopenSlotFile,slotCodeFile);
1194
+ return true;
1195
+ }
1196
+
1197
+ /*************************************************************
1198
+ NAME : TemplateSlotsToCode
1199
+ DESCRIPTION : Prints out instance template -
1200
+ the entire instance slot template
1201
+ for a particular class is
1202
+ guaranteed to be in the same
1203
+ array partition
1204
+ INPUTS : 1) A buffer for the template file
1205
+ 2) The base image name
1206
+ 3) The id for this type of data
1207
+ 4) The base image id
1208
+ 5) The general header file
1209
+ 6) A buffer for the version number of
1210
+ the file for this type of data
1211
+ 7) The maximum # of elements in any array
1212
+ 8) A pointer to the class
1213
+ 9) A buffer holding the template partition #
1214
+ 10) A buffer holding the template relative
1215
+ index in the partition
1216
+ 11) A buffer for a flag indicating if the
1217
+ buffer file can be reopened later
1218
+ 12) A pointer to the file info for
1219
+ this data if the last file needs
1220
+ to be reopened for termination
1221
+ RETURNS : True if all OK, false
1222
+ otherwise
1223
+ SIDE EFFECTS : Templates written
1224
+ NOTES : None
1225
+ *************************************************************/
1226
+ static bool TemplateSlotsToCode(
1227
+ Environment *theEnv,
1228
+ FILE **templateSlotFile,
1229
+ const char *fileName,
1230
+ const char *pathName,
1231
+ char *fileNameBuffer,
1232
+ unsigned int fileID,
1233
+ unsigned int imageID,
1234
+ FILE *headerFP,
1235
+ unsigned int *fileCount,
1236
+ unsigned int maxIndices,
1237
+ Defclass *theDefclass,
1238
+ unsigned int *templateSlotArrayVersion,
1239
+ unsigned int *templateSlotArrayCount,
1240
+ bool *reopenTemplateSlotFile,
1241
+ struct CodeGeneratorFile *templateSlotCodeFile)
1242
+ {
1243
+ unsigned long i;
1244
+ SlotDescriptor *sd;
1245
+ PACKED_LOCATION_INFO theLocationInfo;
1246
+
1247
+ if (theDefclass->instanceSlotCount == 0)
1248
+ return true;
1249
+
1250
+ *templateSlotFile = OpenFileIfNeeded(theEnv,*templateSlotFile,fileName,pathName,fileNameBuffer,fileID,
1251
+ imageID,fileCount,
1252
+ *templateSlotArrayVersion,headerFP,
1253
+ "SlotDescriptor *",TemplateSlotPrefix(),
1254
+ *reopenTemplateSlotFile,templateSlotCodeFile);
1255
+ if (*templateSlotFile == NULL)
1256
+ return false;
1257
+
1258
+ for (i = 0 ; i < theDefclass->instanceSlotCount ; i++)
1259
+ {
1260
+ sd = theDefclass->instanceTemplate[i];
1261
+ if (i > 0)
1262
+ fprintf(*templateSlotFile,",");
1263
+ theLocationInfo.theLong = sd->bsaveIndex;
1264
+ fprintf(*templateSlotFile,"&%s%d_%u[%u]",
1265
+ SlotPrefix(),imageID,
1266
+ theLocationInfo.theLocation.thePartition,
1267
+ theLocationInfo.theLocation.theOffset);
1268
+ }
1269
+ *templateSlotArrayCount += theDefclass->instanceSlotCount;
1270
+ *templateSlotFile = CloseFileIfNeeded(theEnv,*templateSlotFile,templateSlotArrayCount,
1271
+ templateSlotArrayVersion,maxIndices,
1272
+ reopenTemplateSlotFile,templateSlotCodeFile);
1273
+ return true;
1274
+ }
1275
+
1276
+ /*************************************************************
1277
+ NAME : OrderedSlotsToCode
1278
+ DESCRIPTION : Prints out slot name map -
1279
+ the entire slot name map
1280
+ for a particular class is
1281
+ guaranteed to be in the same
1282
+ array partition
1283
+ INPUTS : 1) A buffer for the slot map file
1284
+ 2) The base image name
1285
+ 3) The id for this type of data
1286
+ 4) The base image id
1287
+ 5) The general header file
1288
+ 6) A buffer for the version number of
1289
+ the file for this type of data
1290
+ 7) The maximum # of elements in any array
1291
+ 8) A pointer to the class
1292
+ 9) A buffer holding the slot map partition #
1293
+ 10) A buffer holding the slot map relative
1294
+ index in the partition
1295
+ 11) A buffer for a flag indicating if the
1296
+ buffer file can be reopened later
1297
+ 12) A pointer to the file info for
1298
+ this data if the last file needs
1299
+ to be reopened for termination
1300
+ RETURNS : True if all OK, false
1301
+ otherwise
1302
+ SIDE EFFECTS : Slot maps written
1303
+ NOTES : None
1304
+ *************************************************************/
1305
+ static bool OrderedSlotsToCode(
1306
+ Environment *theEnv,
1307
+ FILE **orderedSlotFile,
1308
+ const char *fileName,
1309
+ const char *pathName,
1310
+ char *fileNameBuffer,
1311
+ unsigned int fileID,
1312
+ unsigned int imageID,
1313
+ FILE *headerFP,
1314
+ unsigned int *fileCount,
1315
+ unsigned int maxIndices,
1316
+ Defclass *theDefclass,
1317
+ unsigned int *orderedSlotArrayVersion,
1318
+ unsigned int *orderedSlotArrayCount,
1319
+ bool *reopenOrderedSlotFile,
1320
+ struct CodeGeneratorFile *orderedSlotCodeFile)
1321
+ {
1322
+ long i;
1323
+
1324
+ if (theDefclass->instanceSlotCount == 0)
1325
+ return true;
1326
+
1327
+ *orderedSlotFile = OpenFileIfNeeded(theEnv,*orderedSlotFile,fileName,pathName,fileNameBuffer,fileID,
1328
+ imageID,fileCount,
1329
+ *orderedSlotArrayVersion,headerFP,
1330
+ "unsigned",OrderedSlotPrefix(),
1331
+ *reopenOrderedSlotFile,orderedSlotCodeFile);
1332
+ if (*orderedSlotFile == NULL)
1333
+ return false;
1334
+
1335
+ for (i = 0 ; i <= theDefclass->maxSlotNameID ; i++)
1336
+ {
1337
+ if (i > 0)
1338
+ fprintf(*orderedSlotFile,",");
1339
+ fprintf(*orderedSlotFile,"%u",theDefclass->slotNameMap[i]);
1340
+ }
1341
+ *orderedSlotArrayCount += theDefclass->maxSlotNameID + 1;
1342
+ *orderedSlotFile = CloseFileIfNeeded(theEnv,*orderedSlotFile,orderedSlotArrayCount,
1343
+ orderedSlotArrayVersion,maxIndices,
1344
+ reopenOrderedSlotFile,orderedSlotCodeFile);
1345
+ return true;
1346
+ }
1347
+
1348
+ /*************************************************************
1349
+ NAME : HandlersToCode
1350
+ DESCRIPTION : Prints out message-handlers -
1351
+ all message-handlers for a particular class
1352
+ are guaranteed to be in the same array
1353
+ partition
1354
+ INPUTS : 1) A buffer for the handler file
1355
+ 2) The base image name
1356
+ 3) The id for this type of data
1357
+ 4) The base image id
1358
+ 5) The general header file
1359
+ 6) A buffer for the version number of
1360
+ the file for this type of data
1361
+ 7) The maximum # of elements in any array
1362
+ 8) A pointer to the class
1363
+ 9) A buffer holding the handler partition #
1364
+ 10) A buffer holding the handler relative
1365
+ index in the partition
1366
+ 11) A buffer for a flag indicating if the
1367
+ buffer file can be reopened later
1368
+ 12) A pointer to the file info for
1369
+ this data if the last file needs
1370
+ to be reopened for termination
1371
+ RETURNS : True if all OK, false
1372
+ otherwise
1373
+ SIDE EFFECTS : Handlers written
1374
+ NOTES : None
1375
+ *************************************************************/
1376
+ static bool HandlersToCode(
1377
+ Environment *theEnv,
1378
+ FILE **handlerFile,
1379
+ const char *fileName,
1380
+ const char *pathName,
1381
+ char *fileNameBuffer,
1382
+ unsigned int fileID,
1383
+ unsigned int imageID,
1384
+ FILE *headerFP,
1385
+ unsigned int *fileCount,
1386
+ unsigned int maxIndices,
1387
+ Defclass *theDefclass,
1388
+ unsigned int moduleCount,
1389
+ unsigned int *handlerArrayVersion,
1390
+ unsigned int *handlerArrayCount,
1391
+ bool *reopenHandlerFile,
1392
+ struct CodeGeneratorFile *handlerCodeFile)
1393
+ {
1394
+ unsigned int i;
1395
+ DefmessageHandler *hnd;
1396
+
1397
+ if (theDefclass->handlerCount == 0)
1398
+ return true;
1399
+
1400
+ *handlerFile = OpenFileIfNeeded(theEnv,*handlerFile,fileName,pathName,fileNameBuffer,fileID,
1401
+ imageID,fileCount,
1402
+ *handlerArrayVersion,headerFP,
1403
+ "DefmessageHandler",HandlerPrefix(),*reopenHandlerFile,
1404
+ handlerCodeFile);
1405
+ if (*handlerFile == NULL)
1406
+ return false;
1407
+
1408
+ for (i = 0 ; i < theDefclass->handlerCount ; i++)
1409
+ {
1410
+ if (i > 0)
1411
+ fprintf(*handlerFile,",\n");
1412
+ hnd = &theDefclass->handlers[i];
1413
+
1414
+ fprintf(*handlerFile,"{");
1415
+ ConstructHeaderToCode(theEnv,*handlerFile,&hnd->header,imageID,maxIndices,moduleCount,
1416
+ ModulePrefix(ObjectCompilerData(theEnv)->ObjectCodeItem),HandlerPrefix());
1417
+
1418
+ fprintf(*handlerFile,",%u,%u,0,0,0,",hnd->system,hnd->type);
1419
+ PrintClassReference(theEnv,*handlerFile,hnd->cls,imageID,maxIndices);
1420
+ fprintf(*handlerFile,",%hu,%hu,%hu,",hnd->minParams,hnd->maxParams,hnd->localVarCount);
1421
+ ExpressionToCode(theEnv,*handlerFile,hnd->actions);
1422
+ fprintf(*handlerFile,"}");
1423
+ }
1424
+ *handlerArrayCount += theDefclass->handlerCount;
1425
+ *handlerFile = CloseFileIfNeeded(theEnv,*handlerFile,handlerArrayCount,
1426
+ handlerArrayVersion,maxIndices,
1427
+ reopenHandlerFile,handlerCodeFile);
1428
+ return true;
1429
+ }
1430
+
1431
+ /****************************************************************
1432
+ NAME : OrderedHandlersToCode
1433
+ DESCRIPTION : Prints out handler map -
1434
+ the entire handler map
1435
+ for a particular class is
1436
+ guaranteed to be in the same
1437
+ array partition
1438
+ INPUTS : 1) A buffer for the handler map file
1439
+ 2) The base image name
1440
+ 3) The id for this type of data
1441
+ 4) The base image id
1442
+ 5) The general header file
1443
+ 6) A buffer for the version number of
1444
+ the file for this type of data
1445
+ 7) The maximum # of elements in any array
1446
+ 8) A pointer to the class
1447
+ 9) A buffer holding the handler map partition #
1448
+ 10) A buffer holding the handler map relative
1449
+ index in the partition
1450
+ 11) A buffer for a flag indicating if the
1451
+ buffer file can be reopened later
1452
+ 12) A pointer to the file info for
1453
+ this data if the last file needs
1454
+ to be reopened for termination
1455
+ RETURNS : True if all OK, false
1456
+ otherwise
1457
+ SIDE EFFECTS : Handler maps written
1458
+ NOTES : None
1459
+ ****************************************************************/
1460
+ static bool OrderedHandlersToCode(
1461
+ Environment *theEnv,
1462
+ FILE **orderedHandlerFile,
1463
+ const char *fileName,
1464
+ const char *pathName,
1465
+ char *fileNameBuffer,
1466
+ unsigned int fileID,
1467
+ unsigned int imageID,
1468
+ FILE *headerFP,
1469
+ unsigned int *fileCount,
1470
+ unsigned int maxIndices,
1471
+ Defclass *theDefclass,
1472
+ unsigned int *orderedHandlerArrayVersion,
1473
+ unsigned int *orderedHandlerArrayCount,
1474
+ bool *reopenOrderedHandlerFile,
1475
+ struct CodeGeneratorFile *orderedHandlerCodeFile)
1476
+ {
1477
+ long i;
1478
+
1479
+ if (theDefclass->handlerCount == 0)
1480
+ return true;
1481
+
1482
+ *orderedHandlerFile = OpenFileIfNeeded(theEnv,*orderedHandlerFile,fileName,pathName,fileNameBuffer,fileID,
1483
+ imageID,fileCount,
1484
+ *orderedHandlerArrayVersion,headerFP,
1485
+ "unsigned",OrderedHandlerPrefix(),
1486
+ *reopenOrderedHandlerFile,
1487
+ orderedHandlerCodeFile);
1488
+ if (*orderedHandlerFile == NULL)
1489
+ return false;
1490
+
1491
+ for (i = 0 ; i < theDefclass->handlerCount ; i++)
1492
+ {
1493
+ if (i > 0)
1494
+ fprintf(*orderedHandlerFile,",");
1495
+ fprintf(*orderedHandlerFile,"%u",theDefclass->handlerOrderMap[i]);
1496
+ }
1497
+ *orderedHandlerArrayCount += theDefclass->handlerCount;
1498
+ *orderedHandlerFile = CloseFileIfNeeded(theEnv,*orderedHandlerFile,orderedHandlerArrayCount,
1499
+ orderedHandlerArrayVersion,maxIndices,
1500
+ reopenOrderedHandlerFile,
1501
+ orderedHandlerCodeFile);
1502
+ return true;
1503
+ }
1504
+
1505
+ #endif
1506
+
1507
+