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,1150 @@
1
+ /*******************************************************/
2
+ /* "C" Language Integrated Production System */
3
+ /* */
4
+ /* CLIPS Version 6.40 10/01/16 */
5
+ /* */
6
+ /* DEFMODULE PARSER MODULE */
7
+ /*******************************************************/
8
+
9
+ /*************************************************************/
10
+ /* Purpose: Parses a defmodule construct. */
11
+ /* */
12
+ /* Principal Programmer(s): */
13
+ /* Gary D. Riley */
14
+ /* */
15
+ /* Contributing Programmer(s): */
16
+ /* Brian L. Dantes */
17
+ /* */
18
+ /* Revision History: */
19
+ /* */
20
+ /* 6.24: Renamed BOOLEAN macro type to intBool. */
21
+ /* */
22
+ /* 6.30: GetConstructNameAndComment API change. */
23
+ /* */
24
+ /* Added const qualifiers to remove C++ */
25
+ /* deprecation warnings. */
26
+ /* */
27
+ /* Fixed linkage issue when DEFMODULE_CONSTRUCT */
28
+ /* compiler flag is set to 0. */
29
+ /* */
30
+ /* 6.40: Pragma once and other inclusion changes. */
31
+ /* */
32
+ /* Added support for booleans with <stdbool.h>. */
33
+ /* */
34
+ /* Removed use of void pointers for specific */
35
+ /* data structures. */
36
+ /* */
37
+ /* Callbacks must be environment aware. */
38
+ /* */
39
+ /*************************************************************/
40
+
41
+ #include "setup.h"
42
+
43
+ #if DEFMODULE_CONSTRUCT && (! RUN_TIME) && (! BLOAD_ONLY)
44
+
45
+ #include <stdio.h>
46
+ #include <string.h>
47
+
48
+ #include "argacces.h"
49
+ #include "constant.h"
50
+ #include "constrct.h"
51
+ #include "cstrcpsr.h"
52
+ #include "envrnmnt.h"
53
+ #include "extnfunc.h"
54
+ #include "memalloc.h"
55
+ #include "modulutl.h"
56
+ #include "pprint.h"
57
+ #include "prntutil.h"
58
+ #include "router.h"
59
+ #include "utility.h"
60
+
61
+ #if BLOAD || BLOAD_AND_BSAVE
62
+ #include "bload.h"
63
+ #endif
64
+
65
+ #include "modulpsr.h"
66
+
67
+ /***************************************/
68
+ /* LOCAL INTERNAL FUNCTION DEFINITIONS */
69
+ /***************************************/
70
+
71
+ static bool ParsePortSpecifications(Environment *,
72
+ const char *,struct token *,
73
+ Defmodule *);
74
+ static bool ParseImportSpec(Environment *,const char *,struct token *,
75
+ Defmodule *);
76
+ static bool ParseExportSpec(Environment *,const char *,struct token *,
77
+ Defmodule *,
78
+ Defmodule *);
79
+ static bool DeleteDefmodule(Defmodule *,Environment *);
80
+ static bool FindMultiImportConflict(Environment *,Defmodule *);
81
+ static void NotExportedErrorMessage(Environment *,const char *,const char *,const char *);
82
+
83
+ /******************************************/
84
+ /* SetNumberOfDefmodules: Sets the number */
85
+ /* of defmodules currently defined. */
86
+ /******************************************/
87
+ void SetNumberOfDefmodules(
88
+ Environment *theEnv,
89
+ unsigned short value)
90
+ {
91
+ DefmoduleData(theEnv)->NumberOfDefmodules = value;
92
+ }
93
+
94
+ /****************************************************/
95
+ /* AddAfterModuleChangeFunction: Adds a function to */
96
+ /* the list of functions that are to be called */
97
+ /* after a module change occurs. */
98
+ /****************************************************/
99
+ void AddAfterModuleDefinedFunction(
100
+ Environment *theEnv,
101
+ const char *name,
102
+ VoidCallFunction *func,
103
+ int priority,
104
+ void *context)
105
+ {
106
+ DefmoduleData(theEnv)->AfterModuleDefinedFunctions =
107
+ AddVoidFunctionToCallList(theEnv,name,priority,func,DefmoduleData(theEnv)->AfterModuleDefinedFunctions,context);
108
+ }
109
+
110
+ /******************************************************/
111
+ /* AddPortConstructItem: Adds an item to the list of */
112
+ /* items that can be imported/exported by a module. */
113
+ /******************************************************/
114
+ void AddPortConstructItem(
115
+ Environment *theEnv,
116
+ const char *theName,
117
+ TokenType theType)
118
+ {
119
+ struct portConstructItem *newItem;
120
+
121
+ newItem = get_struct(theEnv,portConstructItem);
122
+ newItem->constructName = theName;
123
+ newItem->typeExpected = theType;
124
+ newItem->next = DefmoduleData(theEnv)->ListOfPortConstructItems;
125
+ DefmoduleData(theEnv)->ListOfPortConstructItems = newItem;
126
+ }
127
+
128
+ /******************************************************/
129
+ /* ParseDefmodule: Coordinates all actions necessary */
130
+ /* for the parsing and creation of a defmodule into */
131
+ /* the current environment. */
132
+ /******************************************************/
133
+ bool ParseDefmodule(
134
+ Environment *theEnv,
135
+ const char *readSource)
136
+ {
137
+ CLIPSLexeme *defmoduleName;
138
+ Defmodule *newDefmodule;
139
+ struct token inputToken;
140
+ unsigned int i;
141
+ struct moduleItem *theItem;
142
+ struct portItem *portSpecs, *nextSpec;
143
+ struct defmoduleItemHeader *theHeader;
144
+ struct voidCallFunctionItem *defineFunctions;
145
+ Defmodule *redefiningMainModule = NULL;
146
+ bool parseError;
147
+ struct portItem *oldImportList = NULL, *oldExportList = NULL;
148
+ bool overwrite = false;
149
+
150
+ /*================================================*/
151
+ /* Flush the buffer which stores the pretty print */
152
+ /* representation for a module. Add the already */
153
+ /* parsed keyword defmodule to this buffer. */
154
+ /*================================================*/
155
+
156
+ SetPPBufferStatus(theEnv,true);
157
+ FlushPPBuffer(theEnv);
158
+ SetIndentDepth(theEnv,3);
159
+ SavePPBuffer(theEnv,"(defmodule ");
160
+
161
+ /*===============================*/
162
+ /* Modules cannot be loaded when */
163
+ /* a binary load is in effect. */
164
+ /*===============================*/
165
+
166
+ #if BLOAD || BLOAD_ONLY || BLOAD_AND_BSAVE
167
+ if ((Bloaded(theEnv) == true) && (! ConstructData(theEnv)->CheckSyntaxMode))
168
+ {
169
+ CannotLoadWithBloadMessage(theEnv,"defmodule");
170
+ return true;
171
+ }
172
+ #endif
173
+
174
+ /*=====================================================*/
175
+ /* Parse the name and comment fields of the defmodule. */
176
+ /* Remove the defmodule if it already exists. */
177
+ /*=====================================================*/
178
+
179
+ defmoduleName = GetConstructNameAndComment(theEnv,readSource,&inputToken,"defmodule",
180
+ (FindConstructFunction *) FindDefmodule,
181
+ (DeleteConstructFunction *) DeleteDefmodule,"+",
182
+ true,true,false,false);
183
+ if (defmoduleName == NULL) { return true; }
184
+
185
+ if (strcmp(defmoduleName->contents,"MAIN") == 0)
186
+ { redefiningMainModule = FindDefmodule(theEnv,"MAIN"); }
187
+
188
+ /*==============================================*/
189
+ /* Create the defmodule structure if necessary. */
190
+ /*==============================================*/
191
+
192
+ if (redefiningMainModule == NULL)
193
+ {
194
+ newDefmodule = FindDefmodule(theEnv,defmoduleName->contents);
195
+ if (newDefmodule)
196
+ { overwrite = true; }
197
+ else
198
+ {
199
+ newDefmodule = get_struct(theEnv,defmodule);
200
+ newDefmodule->header.name = defmoduleName;
201
+ newDefmodule->header.whichModule = NULL;
202
+ newDefmodule->header.usrData = NULL;
203
+ newDefmodule->header.constructType = DEFMODULE;
204
+ newDefmodule->header.env = theEnv;
205
+ newDefmodule->header.next = NULL;
206
+ }
207
+ }
208
+ else
209
+ {
210
+ overwrite = true;
211
+ newDefmodule = redefiningMainModule;
212
+ }
213
+
214
+ if (overwrite)
215
+ {
216
+ oldImportList = newDefmodule->importList;
217
+ oldExportList = newDefmodule->exportList;
218
+ }
219
+
220
+ newDefmodule->importList = NULL;
221
+ newDefmodule->exportList = NULL;
222
+
223
+ /*===================================*/
224
+ /* Finish parsing the defmodule (its */
225
+ /* import/export specifications). */
226
+ /*===================================*/
227
+
228
+ parseError = ParsePortSpecifications(theEnv,readSource,&inputToken,newDefmodule);
229
+
230
+ /*====================================*/
231
+ /* Check for import/export conflicts. */
232
+ /*====================================*/
233
+
234
+ if (! parseError) parseError = FindMultiImportConflict(theEnv,newDefmodule);
235
+
236
+ /*======================================================*/
237
+ /* If an error occured in parsing or an import conflict */
238
+ /* was detected, abort the definition of the defmodule. */
239
+ /* If we're only checking syntax, then we want to exit */
240
+ /* at this point as well. */
241
+ /*======================================================*/
242
+
243
+ if (parseError || ConstructData(theEnv)->CheckSyntaxMode)
244
+ {
245
+ while (newDefmodule->importList != NULL)
246
+ {
247
+ nextSpec = newDefmodule->importList->next;
248
+ rtn_struct(theEnv,portItem,newDefmodule->importList);
249
+ newDefmodule->importList = nextSpec;
250
+ }
251
+
252
+ while (newDefmodule->exportList != NULL)
253
+ {
254
+ nextSpec = newDefmodule->exportList->next;
255
+ rtn_struct(theEnv,portItem,newDefmodule->exportList);
256
+ newDefmodule->exportList = nextSpec;
257
+ }
258
+
259
+ if ((redefiningMainModule == NULL) && (! overwrite))
260
+ { rtn_struct(theEnv,defmodule,newDefmodule); }
261
+
262
+ if (overwrite)
263
+ {
264
+ newDefmodule->importList = oldImportList;
265
+ newDefmodule->exportList = oldExportList;
266
+ }
267
+
268
+ if (parseError) return true;
269
+ return false;
270
+ }
271
+
272
+ /*===============================================*/
273
+ /* Increment the symbol table counts for symbols */
274
+ /* used in the defmodule data structures. */
275
+ /*===============================================*/
276
+
277
+ if (redefiningMainModule == NULL)
278
+ { IncrementLexemeCount(newDefmodule->header.name); }
279
+ else
280
+ {
281
+ if ((newDefmodule->importList != NULL) ||
282
+ (newDefmodule->exportList != NULL))
283
+ { DefmoduleData(theEnv)->MainModuleRedefinable = false; }
284
+ }
285
+
286
+ for (portSpecs = newDefmodule->importList; portSpecs != NULL; portSpecs = portSpecs->next)
287
+ {
288
+ if (portSpecs->moduleName != NULL) IncrementLexemeCount(portSpecs->moduleName);
289
+ if (portSpecs->constructType != NULL) IncrementLexemeCount(portSpecs->constructType);
290
+ if (portSpecs->constructName != NULL) IncrementLexemeCount(portSpecs->constructName);
291
+ }
292
+
293
+ for (portSpecs = newDefmodule->exportList; portSpecs != NULL; portSpecs = portSpecs->next)
294
+ {
295
+ if (portSpecs->moduleName != NULL) IncrementLexemeCount(portSpecs->moduleName);
296
+ if (portSpecs->constructType != NULL) IncrementLexemeCount(portSpecs->constructType);
297
+ if (portSpecs->constructName != NULL) IncrementLexemeCount(portSpecs->constructName);
298
+ }
299
+
300
+ /*====================================================*/
301
+ /* Allocate storage for the module's construct lists. */
302
+ /*====================================================*/
303
+
304
+ if (redefiningMainModule != NULL) { /* Do nothing */ }
305
+ else if (DefmoduleData(theEnv)->NumberOfModuleItems == 0) newDefmodule->itemsArray = NULL;
306
+ else
307
+ {
308
+ newDefmodule->itemsArray = (struct defmoduleItemHeader **) gm2(theEnv,sizeof(void *) * DefmoduleData(theEnv)->NumberOfModuleItems);
309
+ for (i = 0, theItem = DefmoduleData(theEnv)->ListOfModuleItems;
310
+ (i < DefmoduleData(theEnv)->NumberOfModuleItems) && (theItem != NULL);
311
+ i++, theItem = theItem->next)
312
+ {
313
+ if (theItem->allocateFunction == NULL)
314
+ { newDefmodule->itemsArray[i] = NULL; }
315
+ else
316
+ {
317
+ newDefmodule->itemsArray[i] = (struct defmoduleItemHeader *)
318
+ (*theItem->allocateFunction)(theEnv);
319
+ theHeader = (struct defmoduleItemHeader *) newDefmodule->itemsArray[i];
320
+ theHeader->theModule = newDefmodule;
321
+ theHeader->firstItem = NULL;
322
+ theHeader->lastItem = NULL;
323
+ }
324
+ }
325
+ }
326
+
327
+ /*=======================================*/
328
+ /* Save the pretty print representation. */
329
+ /*=======================================*/
330
+
331
+ SavePPBuffer(theEnv,"\n");
332
+
333
+ if (GetConserveMemory(theEnv) == true)
334
+ { newDefmodule->header.ppForm = NULL; }
335
+ else
336
+ { newDefmodule->header.ppForm = CopyPPBuffer(theEnv); }
337
+
338
+ /*==============================================*/
339
+ /* Add the defmodule to the list of defmodules. */
340
+ /*==============================================*/
341
+
342
+ if (redefiningMainModule == NULL)
343
+ {
344
+ if (DefmoduleData(theEnv)->LastDefmodule == NULL) DefmoduleData(theEnv)->ListOfDefmodules = newDefmodule;
345
+ else DefmoduleData(theEnv)->LastDefmodule->header.next = &newDefmodule->header;
346
+ DefmoduleData(theEnv)->LastDefmodule = newDefmodule;
347
+ newDefmodule->header.bsaveID = DefmoduleData(theEnv)->NumberOfDefmodules++;
348
+ }
349
+
350
+ SetCurrentModule(theEnv,newDefmodule);
351
+
352
+ /*=========================================*/
353
+ /* Call any functions required by other */
354
+ /* constructs when a new module is defined */
355
+ /*=========================================*/
356
+
357
+ for (defineFunctions = DefmoduleData(theEnv)->AfterModuleDefinedFunctions;
358
+ defineFunctions != NULL;
359
+ defineFunctions = defineFunctions->next)
360
+ { (* (void (*)(void *)) defineFunctions->func)(theEnv); }
361
+
362
+ /*===============================================*/
363
+ /* Defmodule successfully parsed with no errors. */
364
+ /*===============================================*/
365
+
366
+ return false;
367
+ }
368
+
369
+ /*************************************************************/
370
+ /* DeleteDefmodule: Used by the parsing routine to determine */
371
+ /* if a module can be redefined. Only the MAIN module can */
372
+ /* be redefined (and it can only be redefined once). */
373
+ /*************************************************************/
374
+ static bool DeleteDefmodule(
375
+ Defmodule *theDefmodule,
376
+ Environment *allEnv)
377
+ {
378
+ Environment *theEnv;
379
+
380
+ if (theDefmodule == NULL)
381
+ { theEnv = allEnv; }
382
+ else
383
+ { theEnv = theDefmodule->header.env; }
384
+
385
+ if (strcmp(DefmoduleName(theDefmodule),"MAIN") == 0)
386
+ { return(DefmoduleData(theEnv)->MainModuleRedefinable); }
387
+
388
+ return false;
389
+ }
390
+
391
+ /*********************************************************/
392
+ /* ParsePortSpecifications: Parses the import and export */
393
+ /* specifications found in a defmodule construct. */
394
+ /*********************************************************/
395
+ static bool ParsePortSpecifications(
396
+ Environment *theEnv,
397
+ const char *readSource,
398
+ struct token *theToken,
399
+ Defmodule *theDefmodule)
400
+ {
401
+ bool error;
402
+
403
+ /*=============================*/
404
+ /* The import and export lists */
405
+ /* are initially empty. */
406
+ /*=============================*/
407
+
408
+ theDefmodule->importList = NULL;
409
+ theDefmodule->exportList = NULL;
410
+
411
+ /*==========================================*/
412
+ /* Parse import/export specifications until */
413
+ /* a right parenthesis is encountered. */
414
+ /*==========================================*/
415
+
416
+ while (theToken->tknType != RIGHT_PARENTHESIS_TOKEN)
417
+ {
418
+ /*========================================*/
419
+ /* Look for the opening left parenthesis. */
420
+ /*========================================*/
421
+
422
+ if (theToken->tknType != LEFT_PARENTHESIS_TOKEN)
423
+ {
424
+ SyntaxErrorMessage(theEnv,"defmodule");
425
+ return true;
426
+ }
427
+
428
+ /*====================================*/
429
+ /* Look for the import/export keyword */
430
+ /* and call the appropriate functions */
431
+ /* for parsing the specification. */
432
+ /*====================================*/
433
+
434
+ GetToken(theEnv,readSource,theToken);
435
+
436
+ if (theToken->tknType != SYMBOL_TOKEN)
437
+ {
438
+ SyntaxErrorMessage(theEnv,"defmodule");
439
+ return true;
440
+ }
441
+
442
+ if (strcmp(theToken->lexemeValue->contents,"import") == 0)
443
+ {
444
+ error = ParseImportSpec(theEnv,readSource,theToken,theDefmodule);
445
+ }
446
+ else if (strcmp(theToken->lexemeValue->contents,"export") == 0)
447
+ {
448
+ error = ParseExportSpec(theEnv,readSource,theToken,theDefmodule,NULL);
449
+ }
450
+ else
451
+ {
452
+ SyntaxErrorMessage(theEnv,"defmodule");
453
+ return true;
454
+ }
455
+
456
+ if (error) return true;
457
+
458
+ /*============================================*/
459
+ /* Begin parsing the next port specification. */
460
+ /*============================================*/
461
+
462
+ PPCRAndIndent(theEnv);
463
+ GetToken(theEnv,readSource,theToken);
464
+
465
+ if (theToken->tknType == RIGHT_PARENTHESIS_TOKEN)
466
+ {
467
+ PPBackup(theEnv);
468
+ PPBackup(theEnv);
469
+ SavePPBuffer(theEnv,")");
470
+ }
471
+ }
472
+
473
+ /*===================================*/
474
+ /* Return false to indicate no error */
475
+ /* occurred while parsing the */
476
+ /* import/export specifications. */
477
+ /*===================================*/
478
+
479
+ return false;
480
+ }
481
+
482
+ /**********************************************************/
483
+ /* ParseImportSpec: Parses import specifications found in */
484
+ /* a defmodule construct. */
485
+ /* */
486
+ /* <import-spec> ::= (import <module-name> <port-item>) */
487
+ /* */
488
+ /* <port-item> ::= ?ALL | */
489
+ /* ?NONE | */
490
+ /* <construct-name> ?ALL | */
491
+ /* <construct-name> ?NONE | */
492
+ /* <construct-name> <names>* */
493
+ /**********************************************************/
494
+ static bool ParseImportSpec(
495
+ Environment *theEnv,
496
+ const char *readSource,
497
+ struct token *theToken,
498
+ Defmodule *newModule)
499
+ {
500
+ Defmodule *theModule;
501
+ struct portItem *thePort, *oldImportSpec;
502
+ bool found;
503
+ unsigned int count;
504
+
505
+ /*===========================*/
506
+ /* Look for the module name. */
507
+ /*===========================*/
508
+
509
+ SavePPBuffer(theEnv," ");
510
+
511
+ GetToken(theEnv,readSource,theToken);
512
+
513
+ if (theToken->tknType != SYMBOL_TOKEN)
514
+ {
515
+ SyntaxErrorMessage(theEnv,"defmodule import specification");
516
+ return true;
517
+ }
518
+
519
+ /*=====================================*/
520
+ /* Verify the existence of the module. */
521
+ /*=====================================*/
522
+
523
+ if ((theModule = FindDefmodule(theEnv,theToken->lexemeValue->contents)) == NULL)
524
+ {
525
+ CantFindItemErrorMessage(theEnv,"defmodule",theToken->lexemeValue->contents,true);
526
+ return true;
527
+ }
528
+
529
+ /*========================================*/
530
+ /* If the specified module doesn't export */
531
+ /* any constructs, then the import */
532
+ /* specification is meaningless. */
533
+ /*========================================*/
534
+
535
+ if (theModule->exportList == NULL)
536
+ {
537
+ NotExportedErrorMessage(theEnv,DefmoduleName(theModule),NULL,NULL);
538
+ return true;
539
+ }
540
+
541
+ /*==============================================*/
542
+ /* Parse the remaining portion of the import */
543
+ /* specification and return if an error occurs. */
544
+ /*==============================================*/
545
+
546
+ oldImportSpec = newModule->importList;
547
+ if (ParseExportSpec(theEnv,readSource,theToken,newModule,theModule)) return true;
548
+
549
+ /*========================================================*/
550
+ /* If the ?NONE keyword was used with the import spec, */
551
+ /* then no constructs were actually imported and the */
552
+ /* import spec does not need to be checked for conflicts. */
553
+ /*========================================================*/
554
+
555
+ if (newModule->importList == oldImportSpec) return false;
556
+
557
+ /*======================================================*/
558
+ /* Check to see if the construct being imported can be */
559
+ /* by the specified module. This check exported doesn't */
560
+ /* guarantee that a specific named construct actually */
561
+ /* exists. It just checks that it could be exported if */
562
+ /* it does exists. */
563
+ /*======================================================*/
564
+
565
+ if (newModule->importList->constructType != NULL)
566
+ {
567
+ /*=============================*/
568
+ /* Look for the construct in */
569
+ /* the module that exports it. */
570
+ /*=============================*/
571
+
572
+ found = false;
573
+ for (thePort = theModule->exportList;
574
+ (thePort != NULL) && (! found);
575
+ thePort = thePort->next)
576
+ {
577
+ if (thePort->constructType == NULL) found = true;
578
+ else if (thePort->constructType == newModule->importList->constructType)
579
+ {
580
+ if (newModule->importList->constructName == NULL) found = true;
581
+ else if (thePort->constructName == NULL) found = true;
582
+ else if (thePort->constructName == newModule->importList->constructName)
583
+ { found = true; }
584
+ }
585
+ }
586
+
587
+ /*=======================================*/
588
+ /* If it's not exported by the specified */
589
+ /* module, print an error message. */
590
+ /*=======================================*/
591
+
592
+ if (! found)
593
+ {
594
+ if (newModule->importList->constructName == NULL)
595
+ {
596
+ NotExportedErrorMessage(theEnv,DefmoduleName(theModule),
597
+ newModule->importList->constructType->contents,
598
+ NULL);
599
+ }
600
+ else
601
+ {
602
+ NotExportedErrorMessage(theEnv,DefmoduleName(theModule),
603
+ newModule->importList->constructType->contents,
604
+ newModule->importList->constructName->contents);
605
+ }
606
+ return true;
607
+ }
608
+ }
609
+
610
+ /*======================================================*/
611
+ /* Verify that specific named constructs actually exist */
612
+ /* and can be seen from the module importing them. */
613
+ /*======================================================*/
614
+
615
+ SaveCurrentModule(theEnv);
616
+ SetCurrentModule(theEnv,newModule);
617
+
618
+ for (thePort = newModule->importList;
619
+ thePort != NULL;
620
+ thePort = thePort->next)
621
+ {
622
+ if ((thePort->constructType == NULL) || (thePort->constructName == NULL))
623
+ { continue; }
624
+
625
+ theModule = FindDefmodule(theEnv,thePort->moduleName->contents);
626
+ SetCurrentModule(theEnv,theModule);
627
+ if (FindImportedConstruct(theEnv,thePort->constructType->contents,NULL,
628
+ thePort->constructName->contents,&count,
629
+ true,NULL) == NULL)
630
+ {
631
+ NotExportedErrorMessage(theEnv,DefmoduleName(theModule),
632
+ thePort->constructType->contents,
633
+ thePort->constructName->contents);
634
+ RestoreCurrentModule(theEnv);
635
+ return true;
636
+ }
637
+ }
638
+
639
+ RestoreCurrentModule(theEnv);
640
+
641
+ /*===============================================*/
642
+ /* The import list has been successfully parsed. */
643
+ /*===============================================*/
644
+
645
+ return false;
646
+ }
647
+
648
+ /**********************************************************/
649
+ /* ParseExportSpec: Parses export specifications found in */
650
+ /* a defmodule construct. This includes parsing the */
651
+ /* remaining specification found in an import */
652
+ /* specification after the module name. */
653
+ /**********************************************************/
654
+ static bool ParseExportSpec(
655
+ Environment *theEnv,
656
+ const char *readSource,
657
+ struct token *theToken,
658
+ Defmodule *newModule,
659
+ Defmodule *importModule)
660
+ {
661
+ struct portItem *newPort;
662
+ CLIPSLexeme *theConstruct, *moduleName;
663
+ struct portConstructItem *thePortConstruct;
664
+ const char *errorMessage;
665
+
666
+ /*===========================================*/
667
+ /* Set up some variables for error messages. */
668
+ /*===========================================*/
669
+
670
+ if (importModule != NULL)
671
+ {
672
+ errorMessage = "defmodule import specification";
673
+ moduleName = importModule->header.name;
674
+ }
675
+ else
676
+ {
677
+ errorMessage = "defmodule export specification";
678
+ moduleName = NULL;
679
+ }
680
+
681
+ /*=============================================*/
682
+ /* Handle the special variables ?ALL and ?NONE */
683
+ /* in the import/export specification. */
684
+ /*=============================================*/
685
+
686
+ SavePPBuffer(theEnv," ");
687
+ GetToken(theEnv,readSource,theToken);
688
+
689
+ if (theToken->tknType == SF_VARIABLE_TOKEN)
690
+ {
691
+ /*==============================*/
692
+ /* Check to see if the variable */
693
+ /* is either ?ALL or ?NONE. */
694
+ /*==============================*/
695
+
696
+ if (strcmp(theToken->lexemeValue->contents,"ALL") == 0)
697
+ {
698
+ newPort = (struct portItem *) get_struct(theEnv,portItem);
699
+ newPort->moduleName = moduleName;
700
+ newPort->constructType = NULL;
701
+ newPort->constructName = NULL;
702
+ newPort->next = NULL;
703
+ }
704
+ else if (strcmp(theToken->lexemeValue->contents,"NONE") == 0)
705
+ { newPort = NULL; }
706
+ else
707
+ {
708
+ SyntaxErrorMessage(theEnv,errorMessage);
709
+ return true;
710
+ }
711
+
712
+ /*=======================================================*/
713
+ /* The export/import specification must end with a right */
714
+ /* parenthesis after ?ALL or ?NONE at this point. */
715
+ /*=======================================================*/
716
+
717
+ GetToken(theEnv,readSource,theToken);
718
+
719
+ if (theToken->tknType != RIGHT_PARENTHESIS_TOKEN)
720
+ {
721
+ if (newPort != NULL) rtn_struct(theEnv,portItem,newPort);
722
+ PPBackup(theEnv);
723
+ SavePPBuffer(theEnv," ");
724
+ SavePPBuffer(theEnv,theToken->printForm);
725
+ SyntaxErrorMessage(theEnv,errorMessage);
726
+ return true;
727
+ }
728
+
729
+ /*=====================================*/
730
+ /* Add the new specification to either */
731
+ /* the import or export list. */
732
+ /*=====================================*/
733
+
734
+ if (newPort != NULL)
735
+ {
736
+ if (importModule != NULL)
737
+ {
738
+ newPort->next = newModule->importList;
739
+ newModule->importList = newPort;
740
+ }
741
+ else
742
+ {
743
+ newPort->next = newModule->exportList;
744
+ newModule->exportList = newPort;
745
+ }
746
+ }
747
+
748
+ /*============================================*/
749
+ /* Return false to indicate the import/export */
750
+ /* specification was successfully parsed. */
751
+ /*============================================*/
752
+
753
+ return false;
754
+ }
755
+
756
+ /*========================================================*/
757
+ /* If the ?ALL and ?NONE keywords were not used, then the */
758
+ /* token must be the name of an importable construct. */
759
+ /*========================================================*/
760
+
761
+ if (theToken->tknType != SYMBOL_TOKEN)
762
+ {
763
+ SyntaxErrorMessage(theEnv,errorMessage);
764
+ return true;
765
+ }
766
+
767
+ theConstruct = theToken->lexemeValue;
768
+
769
+ if ((thePortConstruct = ValidPortConstructItem(theEnv,theConstruct->contents)) == NULL)
770
+ {
771
+ SyntaxErrorMessage(theEnv,errorMessage);
772
+ return true;
773
+ }
774
+
775
+ /*=============================================================*/
776
+ /* If the next token is the special variable ?ALL, then all */
777
+ /* constructs of the specified type are imported/exported. If */
778
+ /* the next token is the special variable ?NONE, then no */
779
+ /* constructs of the specified type will be imported/exported. */
780
+ /*=============================================================*/
781
+
782
+ SavePPBuffer(theEnv," ");
783
+ GetToken(theEnv,readSource,theToken);
784
+
785
+ if (theToken->tknType == SF_VARIABLE_TOKEN)
786
+ {
787
+ /*==============================*/
788
+ /* Check to see if the variable */
789
+ /* is either ?ALL or ?NONE. */
790
+ /*==============================*/
791
+
792
+ if (strcmp(theToken->lexemeValue->contents,"ALL") == 0)
793
+ {
794
+ newPort = (struct portItem *) get_struct(theEnv,portItem);
795
+ newPort->moduleName = moduleName;
796
+ newPort->constructType = theConstruct;
797
+ newPort->constructName = NULL;
798
+ newPort->next = NULL;
799
+ }
800
+ else if (strcmp(theToken->lexemeValue->contents,"NONE") == 0)
801
+ { newPort = NULL; }
802
+ else
803
+ {
804
+ SyntaxErrorMessage(theEnv,errorMessage);
805
+ return true;
806
+ }
807
+
808
+ /*=======================================================*/
809
+ /* The export/import specification must end with a right */
810
+ /* parenthesis after ?ALL or ?NONE at this point. */
811
+ /*=======================================================*/
812
+
813
+ GetToken(theEnv,readSource,theToken);
814
+
815
+ if (theToken->tknType != RIGHT_PARENTHESIS_TOKEN)
816
+ {
817
+ if (newPort != NULL) rtn_struct(theEnv,portItem,newPort);
818
+ PPBackup(theEnv);
819
+ SavePPBuffer(theEnv," ");
820
+ SavePPBuffer(theEnv,theToken->printForm);
821
+ SyntaxErrorMessage(theEnv,errorMessage);
822
+ return true;
823
+ }
824
+
825
+ /*=====================================*/
826
+ /* Add the new specification to either */
827
+ /* the import or export list. */
828
+ /*=====================================*/
829
+
830
+ if (newPort != NULL)
831
+ {
832
+ if (importModule != NULL)
833
+ {
834
+ newPort->next = newModule->importList;
835
+ newModule->importList = newPort;
836
+ }
837
+ else
838
+ {
839
+ newPort->next = newModule->exportList;
840
+ newModule->exportList = newPort;
841
+ }
842
+ }
843
+
844
+ /*============================================*/
845
+ /* Return false to indicate the import/export */
846
+ /* specification was successfully parsed. */
847
+ /*============================================*/
848
+
849
+ return false;
850
+ }
851
+
852
+ /*============================================*/
853
+ /* There must be at least one named construct */
854
+ /* in the import/export list at this point. */
855
+ /*============================================*/
856
+
857
+ if (theToken->tknType == RIGHT_PARENTHESIS_TOKEN)
858
+ {
859
+ SyntaxErrorMessage(theEnv,errorMessage);
860
+ return true;
861
+ }
862
+
863
+ /*=====================================*/
864
+ /* Read in the list of imported items. */
865
+ /*=====================================*/
866
+
867
+ while (theToken->tknType != RIGHT_PARENTHESIS_TOKEN)
868
+ {
869
+ if (theToken->tknType != thePortConstruct->typeExpected)
870
+ {
871
+ SyntaxErrorMessage(theEnv,errorMessage);
872
+ return true;
873
+ }
874
+
875
+ /*========================================*/
876
+ /* Create the data structure to represent */
877
+ /* the import/export specification for */
878
+ /* the named construct. */
879
+ /*========================================*/
880
+
881
+ newPort = (struct portItem *) get_struct(theEnv,portItem);
882
+ newPort->moduleName = moduleName;
883
+ newPort->constructType = theConstruct;
884
+ newPort->constructName = theToken->lexemeValue;
885
+
886
+ /*=====================================*/
887
+ /* Add the new specification to either */
888
+ /* the import or export list. */
889
+ /*=====================================*/
890
+
891
+ if (importModule != NULL)
892
+ {
893
+ newPort->next = newModule->importList;
894
+ newModule->importList = newPort;
895
+ }
896
+ else
897
+ {
898
+ newPort->next = newModule->exportList;
899
+ newModule->exportList = newPort;
900
+ }
901
+
902
+ /*===================================*/
903
+ /* Move on to the next import/export */
904
+ /* specification. */
905
+ /*===================================*/
906
+
907
+ SavePPBuffer(theEnv," ");
908
+ GetToken(theEnv,readSource,theToken);
909
+ }
910
+
911
+ /*=============================*/
912
+ /* Fix up pretty print buffer. */
913
+ /*=============================*/
914
+
915
+ PPBackup(theEnv);
916
+ PPBackup(theEnv);
917
+ SavePPBuffer(theEnv,")");
918
+
919
+ /*============================================*/
920
+ /* Return false to indicate the import/export */
921
+ /* specification was successfully parsed. */
922
+ /*============================================*/
923
+
924
+ return false;
925
+ }
926
+
927
+ /*************************************************************/
928
+ /* ValidPortConstructItem: Returns true if a given construct */
929
+ /* name is in the list of constructs which can be exported */
930
+ /* and imported, otherwise false is returned. */
931
+ /*************************************************************/
932
+ struct portConstructItem *ValidPortConstructItem(
933
+ Environment *theEnv,
934
+ const char *theName)
935
+ {
936
+ struct portConstructItem *theItem;
937
+
938
+ for (theItem = DefmoduleData(theEnv)->ListOfPortConstructItems;
939
+ theItem != NULL;
940
+ theItem = theItem->next)
941
+ { if (strcmp(theName,theItem->constructName) == 0) return(theItem); }
942
+
943
+ return NULL;
944
+ }
945
+
946
+ /***********************************************************/
947
+ /* FindMultiImportConflict: Determines if a module imports */
948
+ /* the same named construct from more than one module */
949
+ /* (i.e. an ambiguous reference which is not allowed). */
950
+ /***********************************************************/
951
+ static bool FindMultiImportConflict(
952
+ Environment *theEnv,
953
+ Defmodule *theModule)
954
+ {
955
+ Defmodule *testModule;
956
+ unsigned int count;
957
+ struct portConstructItem *thePCItem;
958
+ Construct *theConstruct;
959
+ ConstructHeader *theCItem;
960
+
961
+ /*==========================*/
962
+ /* Save the current module. */
963
+ /*==========================*/
964
+
965
+ SaveCurrentModule(theEnv);
966
+
967
+ /*============================*/
968
+ /* Loop through every module. */
969
+ /*============================*/
970
+
971
+ for (testModule = GetNextDefmodule(theEnv,NULL);
972
+ testModule != NULL;
973
+ testModule = GetNextDefmodule(theEnv,testModule))
974
+ {
975
+ /*========================================*/
976
+ /* Loop through every construct type that */
977
+ /* can be imported/exported by a module. */
978
+ /*========================================*/
979
+
980
+ for (thePCItem = DefmoduleData(theEnv)->ListOfPortConstructItems;
981
+ thePCItem != NULL;
982
+ thePCItem = thePCItem->next)
983
+ {
984
+ SetCurrentModule(theEnv,testModule);
985
+
986
+ /*=====================================================*/
987
+ /* Loop through every construct of the specified type. */
988
+ /*=====================================================*/
989
+
990
+ theConstruct = FindConstruct(theEnv,thePCItem->constructName);
991
+
992
+ for (theCItem = (*theConstruct->getNextItemFunction)(theEnv,NULL);
993
+ theCItem != NULL;
994
+ theCItem = (*theConstruct->getNextItemFunction)(theEnv,theCItem))
995
+ {
996
+ /*===============================================*/
997
+ /* Check to see if the specific construct in the */
998
+ /* module can be imported with more than one */
999
+ /* reference into the module we're examining for */
1000
+ /* ambiguous import specifications. */
1001
+ /*===============================================*/
1002
+
1003
+ SetCurrentModule(theEnv,theModule);
1004
+ FindImportedConstruct(theEnv,thePCItem->constructName,NULL,
1005
+ (*theConstruct->getConstructNameFunction)(theCItem)->contents,
1006
+ &count,false,NULL);
1007
+ if (count > 1)
1008
+ {
1009
+ ImportExportConflictMessage(theEnv,"defmodule",DefmoduleName(theModule),
1010
+ thePCItem->constructName,
1011
+ (*theConstruct->getConstructNameFunction)(theCItem)->contents);
1012
+ RestoreCurrentModule(theEnv);
1013
+ return true;
1014
+ }
1015
+
1016
+ SetCurrentModule(theEnv,testModule);
1017
+ }
1018
+ }
1019
+ }
1020
+
1021
+ /*=============================*/
1022
+ /* Restore the current module. */
1023
+ /*=============================*/
1024
+
1025
+ RestoreCurrentModule(theEnv);
1026
+
1027
+ /*=======================================*/
1028
+ /* Return false to indicate no ambiguous */
1029
+ /* references were found. */
1030
+ /*=======================================*/
1031
+
1032
+ return false;
1033
+ }
1034
+
1035
+ /******************************************************/
1036
+ /* NotExportedErrorMessage: Generalized error message */
1037
+ /* for indicating that a construct type or specific */
1038
+ /* named construct is not exported. */
1039
+ /******************************************************/
1040
+ static void NotExportedErrorMessage(
1041
+ Environment *theEnv,
1042
+ const char *theModule,
1043
+ const char *theConstruct,
1044
+ const char *theName)
1045
+ {
1046
+ PrintErrorID(theEnv,"MODULPSR",1,true);
1047
+ WriteString(theEnv,STDERR,"Module '");
1048
+ WriteString(theEnv,STDERR,theModule);
1049
+ WriteString(theEnv,STDERR,"' does not export ");
1050
+
1051
+ if (theConstruct == NULL) WriteString(theEnv,STDERR,"any constructs");
1052
+ else if (theName == NULL)
1053
+ {
1054
+ WriteString(theEnv,STDERR,"any ");
1055
+ WriteString(theEnv,STDERR,theConstruct);
1056
+ WriteString(theEnv,STDERR," constructs");
1057
+ }
1058
+ else
1059
+ {
1060
+ WriteString(theEnv,STDERR,"the ");
1061
+ WriteString(theEnv,STDERR,theConstruct);
1062
+ WriteString(theEnv,STDERR," '");
1063
+ WriteString(theEnv,STDERR,theName);
1064
+ WriteString(theEnv,STDERR,"'");
1065
+ }
1066
+
1067
+ WriteString(theEnv,STDERR,".\n");
1068
+ }
1069
+
1070
+ /*************************************************************/
1071
+ /* FindImportExportConflict: Determines if the definition of */
1072
+ /* a construct would cause an import/export conflict. The */
1073
+ /* construct is not yet defined when this function is */
1074
+ /* called. True is returned if an import/export conflicts */
1075
+ /* is found, otherwise false is returned. */
1076
+ /*************************************************************/
1077
+ bool FindImportExportConflict(
1078
+ Environment *theEnv,
1079
+ const char *constructName,
1080
+ Defmodule *matchModule,
1081
+ const char *findName)
1082
+ {
1083
+ Defmodule *theModule;
1084
+ struct moduleItem *theModuleItem;
1085
+ unsigned int count;
1086
+
1087
+ /*===========================================================*/
1088
+ /* If the construct type can't be imported or exported, then */
1089
+ /* it's not possible to have an import/export conflict. */
1090
+ /*===========================================================*/
1091
+
1092
+ if (ValidPortConstructItem(theEnv,constructName) == NULL) return false;
1093
+
1094
+ /*============================================*/
1095
+ /* There module name should already have been */
1096
+ /* separated fromthe construct's name. */
1097
+ /*============================================*/
1098
+
1099
+ if (FindModuleSeparator(findName)) return false;
1100
+
1101
+ /*===============================================================*/
1102
+ /* The construct must be capable of being stored within a module */
1103
+ /* (this test should never fail). The construct must also have */
1104
+ /* a find function associated with it so we can actually look */
1105
+ /* for import/export conflicts. */
1106
+ /*===============================================================*/
1107
+
1108
+ if ((theModuleItem = FindModuleItem(theEnv,constructName)) == NULL) return false;
1109
+
1110
+ if (theModuleItem->findFunction == NULL) return false;
1111
+
1112
+ /*==========================*/
1113
+ /* Save the current module. */
1114
+ /*==========================*/
1115
+
1116
+ SaveCurrentModule(theEnv);
1117
+
1118
+ /*================================================================*/
1119
+ /* Look at each module and count each definition of the specified */
1120
+ /* construct which is visible to the module. If more than one */
1121
+ /* definition is visible, then an import/export conflict exists */
1122
+ /* and true is returned. */
1123
+ /*================================================================*/
1124
+
1125
+ for (theModule = GetNextDefmodule(theEnv,NULL);
1126
+ theModule != NULL;
1127
+ theModule = GetNextDefmodule(theEnv,theModule))
1128
+ {
1129
+ SetCurrentModule(theEnv,theModule);
1130
+
1131
+ FindImportedConstruct(theEnv,constructName,NULL,findName,&count,true,matchModule);
1132
+ if (count > 1)
1133
+ {
1134
+ RestoreCurrentModule(theEnv);
1135
+ return true;
1136
+ }
1137
+ }
1138
+
1139
+ /*==========================================*/
1140
+ /* Restore the current module. No conflicts */
1141
+ /* were detected so false is returned. */
1142
+ /*==========================================*/
1143
+
1144
+ RestoreCurrentModule(theEnv);
1145
+ return false;
1146
+ }
1147
+
1148
+ #endif /* DEFMODULE_CONSTRUCT && (! RUN_TIME) && (! BLOAD_ONLY) */
1149
+
1150
+