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.
- checksums.yaml +7 -0
- data/ext/clipsruby/agenda.c +1373 -0
- data/ext/clipsruby/agenda.h +169 -0
- data/ext/clipsruby/analysis.c +1142 -0
- data/ext/clipsruby/analysis.h +61 -0
- data/ext/clipsruby/argacces.c +526 -0
- data/ext/clipsruby/argacces.h +77 -0
- data/ext/clipsruby/bload.c +884 -0
- data/ext/clipsruby/bload.h +94 -0
- data/ext/clipsruby/bmathfun.c +557 -0
- data/ext/clipsruby/bmathfun.h +66 -0
- data/ext/clipsruby/bsave.c +634 -0
- data/ext/clipsruby/bsave.h +130 -0
- data/ext/clipsruby/classcom.c +976 -0
- data/ext/clipsruby/classcom.h +115 -0
- data/ext/clipsruby/classexm.c +1376 -0
- data/ext/clipsruby/classexm.h +97 -0
- data/ext/clipsruby/classfun.c +1392 -0
- data/ext/clipsruby/classfun.h +164 -0
- data/ext/clipsruby/classinf.c +1245 -0
- data/ext/clipsruby/classinf.h +94 -0
- data/ext/clipsruby/classini.c +843 -0
- data/ext/clipsruby/classini.h +75 -0
- data/ext/clipsruby/classpsr.c +957 -0
- data/ext/clipsruby/classpsr.h +73 -0
- data/ext/clipsruby/clips.h +133 -0
- data/ext/clipsruby/clipsruby.c +619 -0
- data/ext/clipsruby/clsltpsr.c +931 -0
- data/ext/clipsruby/clsltpsr.h +72 -0
- data/ext/clipsruby/commline.c +1217 -0
- data/ext/clipsruby/commline.h +131 -0
- data/ext/clipsruby/conscomp.c +1593 -0
- data/ext/clipsruby/conscomp.h +150 -0
- data/ext/clipsruby/constant.h +264 -0
- data/ext/clipsruby/constrct.c +1090 -0
- data/ext/clipsruby/constrct.h +216 -0
- data/ext/clipsruby/constrnt.c +554 -0
- data/ext/clipsruby/constrnt.h +132 -0
- data/ext/clipsruby/crstrtgy.c +1088 -0
- data/ext/clipsruby/crstrtgy.h +85 -0
- data/ext/clipsruby/cstrcbin.c +185 -0
- data/ext/clipsruby/cstrcbin.h +61 -0
- data/ext/clipsruby/cstrccmp.h +43 -0
- data/ext/clipsruby/cstrccom.c +1791 -0
- data/ext/clipsruby/cstrccom.h +115 -0
- data/ext/clipsruby/cstrcpsr.c +835 -0
- data/ext/clipsruby/cstrcpsr.h +97 -0
- data/ext/clipsruby/cstrnbin.c +282 -0
- data/ext/clipsruby/cstrnbin.h +55 -0
- data/ext/clipsruby/cstrnchk.c +826 -0
- data/ext/clipsruby/cstrnchk.h +91 -0
- data/ext/clipsruby/cstrncmp.c +238 -0
- data/ext/clipsruby/cstrncmp.h +57 -0
- data/ext/clipsruby/cstrnops.c +1176 -0
- data/ext/clipsruby/cstrnops.h +47 -0
- data/ext/clipsruby/cstrnpsr.c +1394 -0
- data/ext/clipsruby/cstrnpsr.h +88 -0
- data/ext/clipsruby/cstrnutl.c +564 -0
- data/ext/clipsruby/cstrnutl.h +54 -0
- data/ext/clipsruby/default.c +454 -0
- data/ext/clipsruby/default.h +57 -0
- data/ext/clipsruby/defins.c +971 -0
- data/ext/clipsruby/defins.h +127 -0
- data/ext/clipsruby/developr.c +677 -0
- data/ext/clipsruby/developr.h +69 -0
- data/ext/clipsruby/dffctbin.c +477 -0
- data/ext/clipsruby/dffctbin.h +76 -0
- data/ext/clipsruby/dffctbsc.c +308 -0
- data/ext/clipsruby/dffctbsc.h +72 -0
- data/ext/clipsruby/dffctcmp.c +297 -0
- data/ext/clipsruby/dffctcmp.h +44 -0
- data/ext/clipsruby/dffctdef.c +364 -0
- data/ext/clipsruby/dffctdef.h +104 -0
- data/ext/clipsruby/dffctpsr.c +179 -0
- data/ext/clipsruby/dffctpsr.h +49 -0
- data/ext/clipsruby/dffnxbin.c +520 -0
- data/ext/clipsruby/dffnxbin.h +67 -0
- data/ext/clipsruby/dffnxcmp.c +378 -0
- data/ext/clipsruby/dffnxcmp.h +54 -0
- data/ext/clipsruby/dffnxexe.c +241 -0
- data/ext/clipsruby/dffnxexe.h +58 -0
- data/ext/clipsruby/dffnxfun.c +1192 -0
- data/ext/clipsruby/dffnxfun.h +155 -0
- data/ext/clipsruby/dffnxpsr.c +514 -0
- data/ext/clipsruby/dffnxpsr.h +57 -0
- data/ext/clipsruby/dfinsbin.c +509 -0
- data/ext/clipsruby/dfinsbin.h +66 -0
- data/ext/clipsruby/dfinscmp.c +345 -0
- data/ext/clipsruby/dfinscmp.h +48 -0
- data/ext/clipsruby/drive.c +1191 -0
- data/ext/clipsruby/drive.h +65 -0
- data/ext/clipsruby/emathfun.c +1213 -0
- data/ext/clipsruby/emathfun.h +99 -0
- data/ext/clipsruby/engine.c +1568 -0
- data/ext/clipsruby/engine.h +203 -0
- data/ext/clipsruby/entities.h +276 -0
- data/ext/clipsruby/envrnbld.c +514 -0
- data/ext/clipsruby/envrnbld.h +40 -0
- data/ext/clipsruby/envrnmnt.c +257 -0
- data/ext/clipsruby/envrnmnt.h +112 -0
- data/ext/clipsruby/evaluatn.c +1736 -0
- data/ext/clipsruby/evaluatn.h +211 -0
- data/ext/clipsruby/expressn.c +494 -0
- data/ext/clipsruby/expressn.h +154 -0
- data/ext/clipsruby/exprnbin.c +538 -0
- data/ext/clipsruby/exprnbin.h +60 -0
- data/ext/clipsruby/exprnops.c +564 -0
- data/ext/clipsruby/exprnops.h +67 -0
- data/ext/clipsruby/exprnpsr.c +1112 -0
- data/ext/clipsruby/exprnpsr.h +98 -0
- data/ext/clipsruby/extconf.rb +2 -0
- data/ext/clipsruby/extnfunc.c +1015 -0
- data/ext/clipsruby/extnfunc.h +157 -0
- data/ext/clipsruby/factbin.c +447 -0
- data/ext/clipsruby/factbin.h +56 -0
- data/ext/clipsruby/factbld.c +1035 -0
- data/ext/clipsruby/factbld.h +63 -0
- data/ext/clipsruby/factcmp.c +386 -0
- data/ext/clipsruby/factcmp.h +46 -0
- data/ext/clipsruby/factcom.c +759 -0
- data/ext/clipsruby/factcom.h +80 -0
- data/ext/clipsruby/factfile.c +1761 -0
- data/ext/clipsruby/factfile.h +54 -0
- data/ext/clipsruby/factfun.c +682 -0
- data/ext/clipsruby/factfun.h +77 -0
- data/ext/clipsruby/factgen.c +1305 -0
- data/ext/clipsruby/factgen.h +229 -0
- data/ext/clipsruby/facthsh.c +438 -0
- data/ext/clipsruby/facthsh.h +81 -0
- data/ext/clipsruby/factlhs.c +250 -0
- data/ext/clipsruby/factlhs.h +54 -0
- data/ext/clipsruby/factmch.c +905 -0
- data/ext/clipsruby/factmch.h +68 -0
- data/ext/clipsruby/factmngr.c +3373 -0
- data/ext/clipsruby/factmngr.h +325 -0
- data/ext/clipsruby/factprt.c +498 -0
- data/ext/clipsruby/factprt.h +60 -0
- data/ext/clipsruby/factqpsr.c +796 -0
- data/ext/clipsruby/factqpsr.h +61 -0
- data/ext/clipsruby/factqury.c +1267 -0
- data/ext/clipsruby/factqury.h +112 -0
- data/ext/clipsruby/factrete.c +978 -0
- data/ext/clipsruby/factrete.h +70 -0
- data/ext/clipsruby/factrhs.c +667 -0
- data/ext/clipsruby/factrhs.h +55 -0
- data/ext/clipsruby/filecom.c +353 -0
- data/ext/clipsruby/filecom.h +137 -0
- data/ext/clipsruby/filertr.c +481 -0
- data/ext/clipsruby/filertr.h +94 -0
- data/ext/clipsruby/fileutil.c +1020 -0
- data/ext/clipsruby/fileutil.h +50 -0
- data/ext/clipsruby/generate.c +1079 -0
- data/ext/clipsruby/generate.h +57 -0
- data/ext/clipsruby/genrcbin.c +902 -0
- data/ext/clipsruby/genrcbin.h +69 -0
- data/ext/clipsruby/genrccmp.c +640 -0
- data/ext/clipsruby/genrccmp.h +59 -0
- data/ext/clipsruby/genrccom.c +2017 -0
- data/ext/clipsruby/genrccom.h +119 -0
- data/ext/clipsruby/genrcexe.c +737 -0
- data/ext/clipsruby/genrcexe.h +73 -0
- data/ext/clipsruby/genrcfun.c +890 -0
- data/ext/clipsruby/genrcfun.h +185 -0
- data/ext/clipsruby/genrcpsr.c +1618 -0
- data/ext/clipsruby/genrcpsr.h +80 -0
- data/ext/clipsruby/globlbin.c +458 -0
- data/ext/clipsruby/globlbin.h +71 -0
- data/ext/clipsruby/globlbsc.c +361 -0
- data/ext/clipsruby/globlbsc.h +83 -0
- data/ext/clipsruby/globlcmp.c +330 -0
- data/ext/clipsruby/globlcmp.h +52 -0
- data/ext/clipsruby/globlcom.c +289 -0
- data/ext/clipsruby/globlcom.h +63 -0
- data/ext/clipsruby/globldef.c +1087 -0
- data/ext/clipsruby/globldef.h +151 -0
- data/ext/clipsruby/globlpsr.c +530 -0
- data/ext/clipsruby/globlpsr.h +59 -0
- data/ext/clipsruby/immthpsr.c +431 -0
- data/ext/clipsruby/immthpsr.h +55 -0
- data/ext/clipsruby/incrrset.c +530 -0
- data/ext/clipsruby/incrrset.h +73 -0
- data/ext/clipsruby/inherpsr.c +850 -0
- data/ext/clipsruby/inherpsr.h +52 -0
- data/ext/clipsruby/inscom.c +2076 -0
- data/ext/clipsruby/inscom.h +182 -0
- data/ext/clipsruby/insfile.c +1764 -0
- data/ext/clipsruby/insfile.h +96 -0
- data/ext/clipsruby/insfun.c +1451 -0
- data/ext/clipsruby/insfun.h +134 -0
- data/ext/clipsruby/insmngr.c +2550 -0
- data/ext/clipsruby/insmngr.h +125 -0
- data/ext/clipsruby/insmoddp.c +1041 -0
- data/ext/clipsruby/insmoddp.h +91 -0
- data/ext/clipsruby/insmult.c +804 -0
- data/ext/clipsruby/insmult.h +62 -0
- data/ext/clipsruby/inspsr.c +602 -0
- data/ext/clipsruby/inspsr.h +60 -0
- data/ext/clipsruby/insquery.c +1278 -0
- data/ext/clipsruby/insquery.h +115 -0
- data/ext/clipsruby/insqypsr.c +729 -0
- data/ext/clipsruby/insqypsr.h +63 -0
- data/ext/clipsruby/iofun.c +2045 -0
- data/ext/clipsruby/iofun.h +116 -0
- data/ext/clipsruby/lgcldpnd.c +644 -0
- data/ext/clipsruby/lgcldpnd.h +75 -0
- data/ext/clipsruby/main.c +112 -0
- data/ext/clipsruby/match.h +142 -0
- data/ext/clipsruby/memalloc.c +481 -0
- data/ext/clipsruby/memalloc.h +197 -0
- data/ext/clipsruby/miscfun.c +1801 -0
- data/ext/clipsruby/miscfun.h +132 -0
- data/ext/clipsruby/modulbin.c +607 -0
- data/ext/clipsruby/modulbin.h +84 -0
- data/ext/clipsruby/modulbsc.c +347 -0
- data/ext/clipsruby/modulbsc.h +67 -0
- data/ext/clipsruby/modulcmp.c +499 -0
- data/ext/clipsruby/modulcmp.h +54 -0
- data/ext/clipsruby/moduldef.c +817 -0
- data/ext/clipsruby/moduldef.h +271 -0
- data/ext/clipsruby/modulpsr.c +1150 -0
- data/ext/clipsruby/modulpsr.h +69 -0
- data/ext/clipsruby/modulutl.c +1036 -0
- data/ext/clipsruby/modulutl.h +84 -0
- data/ext/clipsruby/msgcom.c +1221 -0
- data/ext/clipsruby/msgcom.h +125 -0
- data/ext/clipsruby/msgfun.c +1076 -0
- data/ext/clipsruby/msgfun.h +118 -0
- data/ext/clipsruby/msgpass.c +1441 -0
- data/ext/clipsruby/msgpass.h +103 -0
- data/ext/clipsruby/msgpsr.c +698 -0
- data/ext/clipsruby/msgpsr.h +73 -0
- data/ext/clipsruby/multifld.c +1404 -0
- data/ext/clipsruby/multifld.h +130 -0
- data/ext/clipsruby/multifun.c +2182 -0
- data/ext/clipsruby/multifun.h +102 -0
- data/ext/clipsruby/network.h +142 -0
- data/ext/clipsruby/objbin.c +1522 -0
- data/ext/clipsruby/objbin.h +79 -0
- data/ext/clipsruby/objcmp.c +1507 -0
- data/ext/clipsruby/objcmp.h +71 -0
- data/ext/clipsruby/object.h +260 -0
- data/ext/clipsruby/objrtbin.c +701 -0
- data/ext/clipsruby/objrtbin.h +79 -0
- data/ext/clipsruby/objrtbld.c +2393 -0
- data/ext/clipsruby/objrtbld.h +66 -0
- data/ext/clipsruby/objrtcmp.c +734 -0
- data/ext/clipsruby/objrtcmp.h +66 -0
- data/ext/clipsruby/objrtfnx.c +1330 -0
- data/ext/clipsruby/objrtfnx.h +222 -0
- data/ext/clipsruby/objrtgen.c +736 -0
- data/ext/clipsruby/objrtgen.h +63 -0
- data/ext/clipsruby/objrtmch.c +1524 -0
- data/ext/clipsruby/objrtmch.h +160 -0
- data/ext/clipsruby/parsefun.c +415 -0
- data/ext/clipsruby/parsefun.h +67 -0
- data/ext/clipsruby/pattern.c +1265 -0
- data/ext/clipsruby/pattern.h +163 -0
- data/ext/clipsruby/pprint.c +328 -0
- data/ext/clipsruby/pprint.h +79 -0
- data/ext/clipsruby/prccode.c +1478 -0
- data/ext/clipsruby/prccode.h +145 -0
- data/ext/clipsruby/prcdrfun.c +640 -0
- data/ext/clipsruby/prcdrfun.h +95 -0
- data/ext/clipsruby/prcdrpsr.c +1068 -0
- data/ext/clipsruby/prcdrpsr.h +79 -0
- data/ext/clipsruby/prdctfun.c +869 -0
- data/ext/clipsruby/prdctfun.h +77 -0
- data/ext/clipsruby/prntutil.c +878 -0
- data/ext/clipsruby/prntutil.h +125 -0
- data/ext/clipsruby/proflfun.c +827 -0
- data/ext/clipsruby/proflfun.h +118 -0
- data/ext/clipsruby/reorder.c +2082 -0
- data/ext/clipsruby/reorder.h +172 -0
- data/ext/clipsruby/reteutil.c +1732 -0
- data/ext/clipsruby/reteutil.h +111 -0
- data/ext/clipsruby/retract.c +710 -0
- data/ext/clipsruby/retract.h +74 -0
- data/ext/clipsruby/router.c +737 -0
- data/ext/clipsruby/router.h +147 -0
- data/ext/clipsruby/rulebin.c +1136 -0
- data/ext/clipsruby/rulebin.h +153 -0
- data/ext/clipsruby/rulebld.c +1328 -0
- data/ext/clipsruby/rulebld.h +62 -0
- data/ext/clipsruby/rulebsc.c +517 -0
- data/ext/clipsruby/rulebsc.h +91 -0
- data/ext/clipsruby/rulecmp.c +733 -0
- data/ext/clipsruby/rulecmp.h +63 -0
- data/ext/clipsruby/rulecom.c +1583 -0
- data/ext/clipsruby/rulecom.h +116 -0
- data/ext/clipsruby/rulecstr.c +892 -0
- data/ext/clipsruby/rulecstr.h +53 -0
- data/ext/clipsruby/ruledef.c +559 -0
- data/ext/clipsruby/ruledef.h +179 -0
- data/ext/clipsruby/ruledlt.c +599 -0
- data/ext/clipsruby/ruledlt.h +58 -0
- data/ext/clipsruby/rulelhs.c +1216 -0
- data/ext/clipsruby/rulelhs.h +52 -0
- data/ext/clipsruby/rulepsr.c +1073 -0
- data/ext/clipsruby/rulepsr.h +61 -0
- data/ext/clipsruby/scanner.c +856 -0
- data/ext/clipsruby/scanner.h +112 -0
- data/ext/clipsruby/setup.h +488 -0
- data/ext/clipsruby/sortfun.c +433 -0
- data/ext/clipsruby/sortfun.h +55 -0
- data/ext/clipsruby/strngfun.c +1173 -0
- data/ext/clipsruby/strngfun.h +96 -0
- data/ext/clipsruby/strngrtr.c +523 -0
- data/ext/clipsruby/strngrtr.h +97 -0
- data/ext/clipsruby/symblbin.c +648 -0
- data/ext/clipsruby/symblbin.h +64 -0
- data/ext/clipsruby/symblcmp.c +893 -0
- data/ext/clipsruby/symblcmp.h +61 -0
- data/ext/clipsruby/symbol.c +1961 -0
- data/ext/clipsruby/symbol.h +243 -0
- data/ext/clipsruby/sysdep.c +894 -0
- data/ext/clipsruby/sysdep.h +164 -0
- data/ext/clipsruby/textpro.c +1388 -0
- data/ext/clipsruby/textpro.h +77 -0
- data/ext/clipsruby/tmpltbin.c +609 -0
- data/ext/clipsruby/tmpltbin.h +108 -0
- data/ext/clipsruby/tmpltbsc.c +327 -0
- data/ext/clipsruby/tmpltbsc.h +87 -0
- data/ext/clipsruby/tmpltcmp.c +450 -0
- data/ext/clipsruby/tmpltcmp.h +57 -0
- data/ext/clipsruby/tmpltdef.c +584 -0
- data/ext/clipsruby/tmpltdef.h +155 -0
- data/ext/clipsruby/tmpltfun.c +2477 -0
- data/ext/clipsruby/tmpltfun.h +122 -0
- data/ext/clipsruby/tmpltlhs.c +379 -0
- data/ext/clipsruby/tmpltlhs.h +50 -0
- data/ext/clipsruby/tmpltpsr.c +819 -0
- data/ext/clipsruby/tmpltpsr.h +59 -0
- data/ext/clipsruby/tmpltrhs.c +595 -0
- data/ext/clipsruby/tmpltrhs.h +55 -0
- data/ext/clipsruby/tmpltutl.c +637 -0
- data/ext/clipsruby/tmpltutl.h +82 -0
- data/ext/clipsruby/userdata.c +156 -0
- data/ext/clipsruby/userdata.h +72 -0
- data/ext/clipsruby/userfunctions.c +70 -0
- data/ext/clipsruby/usrsetup.h +7 -0
- data/ext/clipsruby/utility.c +1594 -0
- data/ext/clipsruby/utility.h +250 -0
- data/ext/clipsruby/watch.c +865 -0
- data/ext/clipsruby/watch.h +124 -0
- data/lib/clipsruby.rb +1 -0
- metadata +388 -0
@@ -0,0 +1,1593 @@
|
|
1
|
+
/*******************************************************/
|
2
|
+
/* "C" Language Integrated Production System */
|
3
|
+
/* */
|
4
|
+
/* CLIPS Version 6.41 12/04/22 */
|
5
|
+
/* */
|
6
|
+
/* CONSTRUCT COMPILER MODULE */
|
7
|
+
/*******************************************************/
|
8
|
+
|
9
|
+
/*************************************************************/
|
10
|
+
/* Purpose: Provides core routines for the constructs-to-c */
|
11
|
+
/* command. */
|
12
|
+
/* */
|
13
|
+
/* Principal Programmer(s): */
|
14
|
+
/* Gary D. Riley */
|
15
|
+
/* Brian L. Dantes */
|
16
|
+
/* Barry Cameron */
|
17
|
+
/* */
|
18
|
+
/* Contributing Programmer(s): */
|
19
|
+
/* */
|
20
|
+
/* Revision History: */
|
21
|
+
/* */
|
22
|
+
/* 6.23: Modifications to use the system constant */
|
23
|
+
/* FILENAME_MAX to check file name lengths. */
|
24
|
+
/* DR0856 */
|
25
|
+
/* */
|
26
|
+
/* Corrected compilation errors for files */
|
27
|
+
/* generated by constructs-to-c. DR0861 */
|
28
|
+
/* */
|
29
|
+
/* 6.24: Used EnvClear rather than Clear in */
|
30
|
+
/* InitCImage initialization code. */
|
31
|
+
/* */
|
32
|
+
/* Added environment parameter to GenClose. */
|
33
|
+
/* Added environment parameter to GenOpen. */
|
34
|
+
/* */
|
35
|
+
/* Removed SHORT_LINK_NAMES code as this option */
|
36
|
+
/* is no longer supported. */
|
37
|
+
/* */
|
38
|
+
/* Support for run-time programs directly passing */
|
39
|
+
/* the hash tables for initialization. */
|
40
|
+
/* */
|
41
|
+
/* 6.30: Added path name argument to constructs-to-c. */
|
42
|
+
/* */
|
43
|
+
/* Changed integer type/precision. */
|
44
|
+
/* */
|
45
|
+
/* Support for long long integers. */
|
46
|
+
/* */
|
47
|
+
/* Removed conditional code for unsupported */
|
48
|
+
/* compilers/operating systems (IBM_MCW, MAC_MCW, */
|
49
|
+
/* IBM_TBC, IBM_MSC, IBM_ICB, IBM_ZTC, and */
|
50
|
+
/* IBM_SC). */
|
51
|
+
/* */
|
52
|
+
/* Use genstrcpy instead of strcpy. */
|
53
|
+
/* */
|
54
|
+
/* Added const qualifiers to remove C++ */
|
55
|
+
/* deprecation warnings. */
|
56
|
+
/* */
|
57
|
+
/* 6.40: Changed restrictions from char * to */
|
58
|
+
/* CLIPSLexeme * to support strings */
|
59
|
+
/* originating from sources that are not */
|
60
|
+
/* statically allocated. */
|
61
|
+
/* */
|
62
|
+
/* Pragma once and other inclusion changes. */
|
63
|
+
/* */
|
64
|
+
/* Added support for booleans with <stdbool.h>. */
|
65
|
+
/* */
|
66
|
+
/* Removed use of void pointers for specific */
|
67
|
+
/* data structures. */
|
68
|
+
/* */
|
69
|
+
/* Removed VAX_VMS support. */
|
70
|
+
/* */
|
71
|
+
/* Callbacks must be environment aware. */
|
72
|
+
/* */
|
73
|
+
/* UDF redesign. */
|
74
|
+
/* */
|
75
|
+
/* Eval support for run time and bload only. */
|
76
|
+
/* */
|
77
|
+
/* 6.41: Used gensnprintf in place of gensprintf and. */
|
78
|
+
/* sprintf. */
|
79
|
+
/* */
|
80
|
+
/*************************************************************/
|
81
|
+
|
82
|
+
#include "setup.h"
|
83
|
+
|
84
|
+
#if CONSTRUCT_COMPILER && (! RUN_TIME)
|
85
|
+
|
86
|
+
#include <stdio.h>
|
87
|
+
#include <stdlib.h>
|
88
|
+
#include <string.h>
|
89
|
+
|
90
|
+
#include "argacces.h"
|
91
|
+
#include "constant.h"
|
92
|
+
#include "constrct.h"
|
93
|
+
#include "cstrccom.h"
|
94
|
+
#include "cstrncmp.h"
|
95
|
+
#include "exprnpsr.h"
|
96
|
+
#include "envrnmnt.h"
|
97
|
+
#include "memalloc.h"
|
98
|
+
#include "modulcmp.h"
|
99
|
+
#include "prntutil.h"
|
100
|
+
#include "router.h"
|
101
|
+
#include "symbol.h"
|
102
|
+
#include "sysdep.h"
|
103
|
+
#include "utility.h"
|
104
|
+
|
105
|
+
#if DEFRULE_CONSTRUCT
|
106
|
+
#include "network.h"
|
107
|
+
#endif
|
108
|
+
|
109
|
+
#if DEFFUNCTION_CONSTRUCT
|
110
|
+
#include "dffnxcmp.h"
|
111
|
+
#endif
|
112
|
+
|
113
|
+
#if DEFTEMPLATE_CONSTRUCT
|
114
|
+
#include "tmpltcmp.h"
|
115
|
+
#endif
|
116
|
+
|
117
|
+
#if DEFGLOBAL_CONSTRUCT
|
118
|
+
#include "globlcmp.h"
|
119
|
+
#endif
|
120
|
+
|
121
|
+
#if DEFGENERIC_CONSTRUCT
|
122
|
+
#include "genrccmp.h"
|
123
|
+
#endif
|
124
|
+
|
125
|
+
#if OBJECT_SYSTEM
|
126
|
+
#include "objcmp.h"
|
127
|
+
#endif
|
128
|
+
|
129
|
+
#include "conscomp.h"
|
130
|
+
|
131
|
+
/***************/
|
132
|
+
/* DEFINITIONS */
|
133
|
+
/***************/
|
134
|
+
|
135
|
+
#define EXTRA_FILE_NAME 20
|
136
|
+
|
137
|
+
/**********************************************/
|
138
|
+
/* CONSTRUCT CODES DEFINITIONS: The codes F, */
|
139
|
+
/* I, B, S, E, P, L, and C are not included */
|
140
|
+
/* because those are already taken. */
|
141
|
+
/* */
|
142
|
+
/* B: BitMap hash nodes */
|
143
|
+
/* C: Constraint hash nodes */
|
144
|
+
/* E: Expression hash nodes */
|
145
|
+
/* F: Float hash nodes */
|
146
|
+
/* I: Integer hash nodes */
|
147
|
+
/* L: Bitmaps */
|
148
|
+
/* P: Functions */
|
149
|
+
/* S: Symbol hash nodes */
|
150
|
+
/**********************************************/
|
151
|
+
|
152
|
+
#define PRIMARY_CODES "ADGHJKMNOQRTUVWXYZ"
|
153
|
+
#define PRIMARY_LEN 18
|
154
|
+
|
155
|
+
const char *SecondaryCodes[] = { "A" , "B", "C", "D", "E" , "F" , "G" , "H", "I", "J" , "K",
|
156
|
+
"L" , "M", "N", "O", "P" , "Q" , "R" , "S", "T", "U" , "V",
|
157
|
+
"W" , "X", "Y", "Z", "AA", "BB", "CC", "DD", "EE" , "FF" };
|
158
|
+
|
159
|
+
#define SECONDARY_LEN 32
|
160
|
+
|
161
|
+
/***************************************/
|
162
|
+
/* LOCAL INTERNAL FUNCTION DEFINITIONS */
|
163
|
+
/***************************************/
|
164
|
+
|
165
|
+
void ConstructsToCCommand(Environment *,UDFContext *,UDFValue *);
|
166
|
+
static bool ConstructsToC(Environment *,const char *,const char *,char *,long long,long long);
|
167
|
+
static void WriteFunctionExternDeclarations(Environment *,FILE *);
|
168
|
+
static bool FunctionsToCode(Environment *theEnv,const char *,const char *,char *);
|
169
|
+
static bool WriteInitializationFunction(Environment *,const char *,const char *,char *);
|
170
|
+
static void DumpExpression(Environment *,struct expr *);
|
171
|
+
static void MarkConstruct(Environment *,ConstructHeader *,void *);
|
172
|
+
static void HashedExpressionsToCode(Environment *);
|
173
|
+
static void DeallocateConstructCompilerData(Environment *);
|
174
|
+
|
175
|
+
/**********************************************************/
|
176
|
+
/* InitializeConstructCompilerData: Allocates environment */
|
177
|
+
/* data for the constructs-to-c command. */
|
178
|
+
/**********************************************************/
|
179
|
+
void InitializeConstructCompilerData(
|
180
|
+
Environment *theEnv)
|
181
|
+
{
|
182
|
+
AllocateEnvironmentData(theEnv,CONSTRUCT_COMPILER_DATA,sizeof(struct constructCompilerData),DeallocateConstructCompilerData);
|
183
|
+
|
184
|
+
ConstructCompilerData(theEnv)->MaxIndices = 2000;
|
185
|
+
ConstructCompilerData(theEnv)->CodeGeneratorCount = 0;
|
186
|
+
}
|
187
|
+
|
188
|
+
/************************************************************/
|
189
|
+
/* DeallocateConstructCompilerData: Deallocates environment */
|
190
|
+
/* data for the constructs-to-c command. */
|
191
|
+
/************************************************************/
|
192
|
+
static void DeallocateConstructCompilerData(
|
193
|
+
Environment *theEnv)
|
194
|
+
{
|
195
|
+
struct CodeGeneratorItem *tmpPtr, *nextPtr;
|
196
|
+
unsigned int i;
|
197
|
+
|
198
|
+
tmpPtr = ConstructCompilerData(theEnv)->ListOfCodeGeneratorItems;
|
199
|
+
while (tmpPtr != NULL)
|
200
|
+
{
|
201
|
+
nextPtr = tmpPtr->next;
|
202
|
+
|
203
|
+
for (i = 0; i < tmpPtr->arrayCount ; i++)
|
204
|
+
{ rm(theEnv,tmpPtr->arrayNames[i],strlen(tmpPtr->arrayNames[i]) + 1); }
|
205
|
+
|
206
|
+
if (tmpPtr->arrayCount != 0)
|
207
|
+
{ rm(theEnv,tmpPtr->arrayNames,sizeof(char *) * tmpPtr->arrayCount); }
|
208
|
+
|
209
|
+
rtn_struct(theEnv,CodeGeneratorItem,tmpPtr);
|
210
|
+
tmpPtr = nextPtr;
|
211
|
+
}
|
212
|
+
}
|
213
|
+
|
214
|
+
/**********************************************/
|
215
|
+
/* ConstructsToCCommand: H/L access routine */
|
216
|
+
/* for the constructs-to-c command. */
|
217
|
+
/**********************************************/
|
218
|
+
void ConstructsToCCommand(
|
219
|
+
Environment *theEnv,
|
220
|
+
UDFContext *context,
|
221
|
+
UDFValue *returnValue)
|
222
|
+
{
|
223
|
+
const char *fileName;
|
224
|
+
char *fileNameBuffer;
|
225
|
+
const char *pathName;
|
226
|
+
UDFValue theArg;
|
227
|
+
long long id, max;
|
228
|
+
size_t nameLength, pathLength;
|
229
|
+
#if WIN_MVC
|
230
|
+
int i;
|
231
|
+
#endif
|
232
|
+
|
233
|
+
/*====================================================*/
|
234
|
+
/* Get the name of the file in which to place C code. */
|
235
|
+
/*====================================================*/
|
236
|
+
|
237
|
+
if (! UDFFirstArgument(context,LEXEME_BITS,&theArg))
|
238
|
+
{ return; }
|
239
|
+
|
240
|
+
fileName = theArg.lexemeValue->contents;
|
241
|
+
nameLength = strlen(fileName);
|
242
|
+
|
243
|
+
/*================================*/
|
244
|
+
/* File names for the VAX and IBM */
|
245
|
+
/* PCs can't contain a period. */
|
246
|
+
/*================================*/
|
247
|
+
|
248
|
+
#if WIN_MVC
|
249
|
+
for (i = 0 ; *(fileName+i) ; i++)
|
250
|
+
{
|
251
|
+
if (*(fileName+i) == '.')
|
252
|
+
{
|
253
|
+
PrintErrorID(theEnv,"CONSCOMP",1,false);
|
254
|
+
WriteString(theEnv,STDERR,"Invalid file name ");
|
255
|
+
WriteString(theEnv,STDERR,fileName);
|
256
|
+
WriteString(theEnv,STDERR," contains \'.\'\n");
|
257
|
+
return;
|
258
|
+
}
|
259
|
+
}
|
260
|
+
#endif
|
261
|
+
|
262
|
+
/*==========================================================*/
|
263
|
+
/* The maximum file name size that can be passed into fopen */
|
264
|
+
/* is specified by FILENAME_MAX. Assume that the most */
|
265
|
+
/* characters that will be appended to the file prefix will */
|
266
|
+
/* be 20 and check that the prefix plus the additional */
|
267
|
+
/* characters is less than the supported maximum. */
|
268
|
+
/*==========================================================*/
|
269
|
+
|
270
|
+
if ((nameLength + EXTRA_FILE_NAME) > FILENAME_MAX)
|
271
|
+
{
|
272
|
+
PrintErrorID(theEnv,"CONSCOMP",2,false);
|
273
|
+
WriteString(theEnv,STDERR,"Aborting because the base file name may cause the fopen maximum of ");
|
274
|
+
WriteInteger(theEnv,STDERR,FILENAME_MAX);
|
275
|
+
WriteString(theEnv,STDERR," to be violated when file names are generated.\n");
|
276
|
+
return;
|
277
|
+
}
|
278
|
+
|
279
|
+
/*====================================*/
|
280
|
+
/* Get the runtime image ID argument. */
|
281
|
+
/*====================================*/
|
282
|
+
|
283
|
+
if (! UDFNextArgument(context,INTEGER_BIT,&theArg))
|
284
|
+
{ return; }
|
285
|
+
|
286
|
+
id = theArg.integerValue->contents;
|
287
|
+
if (id < 0)
|
288
|
+
{
|
289
|
+
ExpectedTypeError1(theEnv,"constructs-to-c",2,"'positive integer'");
|
290
|
+
return;
|
291
|
+
}
|
292
|
+
|
293
|
+
/*==================================================*/
|
294
|
+
/* Get the path name argument if one was specified. */
|
295
|
+
/*==================================================*/
|
296
|
+
|
297
|
+
if (UDFHasNextArgument(context))
|
298
|
+
{
|
299
|
+
if (! UDFNextArgument(context,LEXEME_BITS,&theArg))
|
300
|
+
{ return; }
|
301
|
+
|
302
|
+
pathName = theArg.lexemeValue->contents;
|
303
|
+
pathLength = strlen(pathName);
|
304
|
+
}
|
305
|
+
else
|
306
|
+
{
|
307
|
+
pathName = "";
|
308
|
+
pathLength = 0;
|
309
|
+
}
|
310
|
+
|
311
|
+
/*===========================================*/
|
312
|
+
/* Get the maximum number of data structures */
|
313
|
+
/* to store per file argument (if supplied). */
|
314
|
+
/*===========================================*/
|
315
|
+
|
316
|
+
if (UDFHasNextArgument(context))
|
317
|
+
{
|
318
|
+
if (! UDFNextArgument(context,INTEGER_BIT,&theArg))
|
319
|
+
{ return; }
|
320
|
+
|
321
|
+
max = theArg.integerValue->contents;
|
322
|
+
|
323
|
+
if (max < 0)
|
324
|
+
{
|
325
|
+
ExpectedTypeError1(theEnv,"constructs-to-c",4,"'positive integer'");
|
326
|
+
return;
|
327
|
+
}
|
328
|
+
}
|
329
|
+
else
|
330
|
+
{ max = 10000; }
|
331
|
+
|
332
|
+
/*============================*/
|
333
|
+
/* Call the driver routine to */
|
334
|
+
/* generate the C code. */
|
335
|
+
/*============================*/
|
336
|
+
|
337
|
+
fileNameBuffer = (char *) genalloc(theEnv,nameLength + pathLength + EXTRA_FILE_NAME);
|
338
|
+
|
339
|
+
ConstructsToC(theEnv,fileName,pathName,fileNameBuffer,id,max);
|
340
|
+
|
341
|
+
genfree(theEnv,fileNameBuffer,nameLength + pathLength + EXTRA_FILE_NAME);
|
342
|
+
}
|
343
|
+
|
344
|
+
/***************************************/
|
345
|
+
/* ConstructsToC: C access routine for */
|
346
|
+
/* the constructs-to-c command. */
|
347
|
+
/***************************************/
|
348
|
+
static bool ConstructsToC(
|
349
|
+
Environment *theEnv,
|
350
|
+
const char *fileName,
|
351
|
+
const char *pathName,
|
352
|
+
char *fileNameBuffer,
|
353
|
+
long long theImageID,
|
354
|
+
long long max)
|
355
|
+
{
|
356
|
+
unsigned fileVersion;
|
357
|
+
struct CodeGeneratorItem *cgPtr;
|
358
|
+
|
359
|
+
/*===============================================*/
|
360
|
+
/* Set the global MaxIndices variable indicating */
|
361
|
+
/* the maximum number of data structures to save */
|
362
|
+
/* in each file. */
|
363
|
+
/*===============================================*/
|
364
|
+
|
365
|
+
ConstructCompilerData(theEnv)->MaxIndices = (unsigned) max; /* TBD */
|
366
|
+
|
367
|
+
/*=====================================================*/
|
368
|
+
/* Open a header file for dumping general information. */
|
369
|
+
/*=====================================================*/
|
370
|
+
|
371
|
+
gensprintf(fileNameBuffer,"%s%s.h",pathName,fileName);
|
372
|
+
if ((ConstructCompilerData(theEnv)->HeaderFP = GenOpen(theEnv,fileNameBuffer,"w")) == NULL)
|
373
|
+
{
|
374
|
+
OpenErrorMessage(theEnv,"constructs-to-c",fileNameBuffer);
|
375
|
+
return false;
|
376
|
+
}
|
377
|
+
|
378
|
+
/*============================================*/
|
379
|
+
/* Open a file for dumping fixup information. */
|
380
|
+
/*============================================*/
|
381
|
+
|
382
|
+
gensprintf(fileNameBuffer,"%s%s_init.c",pathName,fileName);
|
383
|
+
if ((ConstructCompilerData(theEnv)->FixupFP = GenOpen(theEnv,fileNameBuffer,"w")) == NULL)
|
384
|
+
{
|
385
|
+
OpenErrorMessage(theEnv,"constructs-to-c",fileNameBuffer);
|
386
|
+
return false;
|
387
|
+
}
|
388
|
+
|
389
|
+
/*==================================*/
|
390
|
+
/* Call the list of functions to be */
|
391
|
+
/* executed before generating code. */
|
392
|
+
/*==================================*/
|
393
|
+
|
394
|
+
for (cgPtr = ConstructCompilerData(theEnv)->ListOfCodeGeneratorItems;
|
395
|
+
cgPtr != NULL;
|
396
|
+
cgPtr = cgPtr->next)
|
397
|
+
{ if (cgPtr->beforeFunction != NULL) (*cgPtr->beforeFunction)(theEnv); }
|
398
|
+
|
399
|
+
/*=====================================*/
|
400
|
+
/* Initialize some global information. */
|
401
|
+
/*=====================================*/
|
402
|
+
|
403
|
+
ConstructCompilerData(theEnv)->FilePrefix = fileName;
|
404
|
+
ConstructCompilerData(theEnv)->PathName = pathName;
|
405
|
+
ConstructCompilerData(theEnv)->FileNameBuffer = fileNameBuffer;
|
406
|
+
ConstructCompilerData(theEnv)->ImageID = (unsigned) theImageID; /* TBD */
|
407
|
+
ConstructCompilerData(theEnv)->ExpressionFP = NULL;
|
408
|
+
ConstructCompilerData(theEnv)->ExpressionVersion = 1;
|
409
|
+
ConstructCompilerData(theEnv)->ExpressionHeader = true;
|
410
|
+
ConstructCompilerData(theEnv)->ExpressionCount = 0;
|
411
|
+
|
412
|
+
fprintf(ConstructCompilerData(theEnv)->HeaderFP,"#ifndef _CONSTRUCT_COMPILER_HEADER_\n");
|
413
|
+
fprintf(ConstructCompilerData(theEnv)->HeaderFP,"#define _CONSTRUCT_COMPILER_HEADER_\n\n");
|
414
|
+
|
415
|
+
fprintf(ConstructCompilerData(theEnv)->HeaderFP,"#include <stdio.h>\n");
|
416
|
+
fprintf(ConstructCompilerData(theEnv)->HeaderFP,"#include \"setup.h\"\n");
|
417
|
+
fprintf(ConstructCompilerData(theEnv)->HeaderFP,"#include \"expressn.h\"\n");
|
418
|
+
fprintf(ConstructCompilerData(theEnv)->HeaderFP,"#include \"extnfunc.h\"\n");
|
419
|
+
fprintf(ConstructCompilerData(theEnv)->HeaderFP,"#include \"%s\"\n",API_HEADER);
|
420
|
+
fprintf(ConstructCompilerData(theEnv)->HeaderFP,"\n#define VS (void *)\n");
|
421
|
+
fprintf(ConstructCompilerData(theEnv)->HeaderFP,"\n");
|
422
|
+
|
423
|
+
/*=========================================================*/
|
424
|
+
/* Give extern declarations for user and system functions. */
|
425
|
+
/*=========================================================*/
|
426
|
+
|
427
|
+
WriteFunctionExternDeclarations(theEnv,ConstructCompilerData(theEnv)->HeaderFP);
|
428
|
+
|
429
|
+
fprintf(ConstructCompilerData(theEnv)->HeaderFP,"\n#endif\n\n");
|
430
|
+
fprintf(ConstructCompilerData(theEnv)->HeaderFP,"/****************************/\n");
|
431
|
+
fprintf(ConstructCompilerData(theEnv)->HeaderFP,"/* EXTERN ARRAY DEFINITIONS */\n");
|
432
|
+
fprintf(ConstructCompilerData(theEnv)->HeaderFP,"/****************************/\n\n");
|
433
|
+
|
434
|
+
/*================================================*/
|
435
|
+
/* Write out the first portion of the fixup file. */
|
436
|
+
/*================================================*/
|
437
|
+
|
438
|
+
fprintf(ConstructCompilerData(theEnv)->FixupFP,"#include \"%s.h\"\n",fileName);
|
439
|
+
fprintf(ConstructCompilerData(theEnv)->FixupFP,"\n");
|
440
|
+
|
441
|
+
fprintf(ConstructCompilerData(theEnv)->FixupFP,"\n");
|
442
|
+
fprintf(ConstructCompilerData(theEnv)->FixupFP,"/**********************************/\n");
|
443
|
+
fprintf(ConstructCompilerData(theEnv)->FixupFP,"/* CONSTRUCT IMAGE FIXUP FUNCTION */\n");
|
444
|
+
fprintf(ConstructCompilerData(theEnv)->FixupFP,"/**********************************/\n");
|
445
|
+
|
446
|
+
fprintf(ConstructCompilerData(theEnv)->FixupFP,"\nvoid FixupCImage_%d(\n",ConstructCompilerData(theEnv)->ImageID);
|
447
|
+
fprintf(ConstructCompilerData(theEnv)->FixupFP," Environment *theEnv)\n");
|
448
|
+
fprintf(ConstructCompilerData(theEnv)->FixupFP," {\n");
|
449
|
+
|
450
|
+
/*==================================*/
|
451
|
+
/* Generate code for atomic values, */
|
452
|
+
/* function definitions, hashed */
|
453
|
+
/* expressions, and constructs. */
|
454
|
+
/*==================================*/
|
455
|
+
|
456
|
+
AtomicValuesToCode(theEnv,fileName,pathName,fileNameBuffer);
|
457
|
+
|
458
|
+
FunctionsToCode(theEnv,fileName,pathName,fileNameBuffer);
|
459
|
+
|
460
|
+
HashedExpressionsToCode(theEnv);
|
461
|
+
|
462
|
+
ConstraintsToCode(theEnv,fileName,pathName,fileNameBuffer,4,
|
463
|
+
ConstructCompilerData(theEnv)->HeaderFP,
|
464
|
+
ConstructCompilerData(theEnv)->ImageID,
|
465
|
+
ConstructCompilerData(theEnv)->MaxIndices);
|
466
|
+
|
467
|
+
/*===============================*/
|
468
|
+
/* Call each code generator item */
|
469
|
+
/* for the various constructs. */
|
470
|
+
/*===============================*/
|
471
|
+
|
472
|
+
fileVersion = 5;
|
473
|
+
for (cgPtr = ConstructCompilerData(theEnv)->ListOfCodeGeneratorItems;
|
474
|
+
cgPtr != NULL;
|
475
|
+
cgPtr = cgPtr->next)
|
476
|
+
{
|
477
|
+
if (cgPtr->generateFunction != NULL)
|
478
|
+
{
|
479
|
+
(*cgPtr->generateFunction)(theEnv,fileName,pathName,fileNameBuffer,fileVersion,ConstructCompilerData(theEnv)->HeaderFP,ConstructCompilerData(theEnv)->ImageID,ConstructCompilerData(theEnv)->MaxIndices);
|
480
|
+
fileVersion++;
|
481
|
+
}
|
482
|
+
}
|
483
|
+
|
484
|
+
/*=========================================*/
|
485
|
+
/* Restore the atomic data bucket values */
|
486
|
+
/* (which were set to an index reference). */
|
487
|
+
/*=========================================*/
|
488
|
+
|
489
|
+
RestoreAtomicValueBuckets(theEnv);
|
490
|
+
|
491
|
+
/*============================*/
|
492
|
+
/* Close the expression file. */
|
493
|
+
/*============================*/
|
494
|
+
|
495
|
+
if (ConstructCompilerData(theEnv)->ExpressionFP != NULL)
|
496
|
+
{
|
497
|
+
fprintf(ConstructCompilerData(theEnv)->ExpressionFP,"};\n");
|
498
|
+
GenClose(theEnv,ConstructCompilerData(theEnv)->ExpressionFP);
|
499
|
+
}
|
500
|
+
|
501
|
+
/*=======================*/
|
502
|
+
/* Close the fixup file. */
|
503
|
+
/*=======================*/
|
504
|
+
|
505
|
+
if (ConstructCompilerData(theEnv)->FixupFP != NULL)
|
506
|
+
{
|
507
|
+
fprintf(ConstructCompilerData(theEnv)->FixupFP," }\n");
|
508
|
+
GenClose(theEnv,ConstructCompilerData(theEnv)->FixupFP);
|
509
|
+
}
|
510
|
+
|
511
|
+
/*====================================*/
|
512
|
+
/* Write the initialization function. */
|
513
|
+
/*====================================*/
|
514
|
+
|
515
|
+
WriteInitializationFunction(theEnv,fileName,pathName,fileNameBuffer);
|
516
|
+
|
517
|
+
/*========================*/
|
518
|
+
/* Close the header file. */
|
519
|
+
/*========================*/
|
520
|
+
|
521
|
+
GenClose(theEnv,ConstructCompilerData(theEnv)->HeaderFP);
|
522
|
+
|
523
|
+
/*==================================================*/
|
524
|
+
/* Return true to indicate that the constructs-to-c */
|
525
|
+
/* command was successfully executed. */
|
526
|
+
/*==================================================*/
|
527
|
+
|
528
|
+
return true;
|
529
|
+
}
|
530
|
+
|
531
|
+
/*******************************************************/
|
532
|
+
/* WriteFunctionExternDeclarations: Loop through the */
|
533
|
+
/* list of function definitions and generates extern */
|
534
|
+
/* declarations for them in the specified file. */
|
535
|
+
/*******************************************************/
|
536
|
+
static void WriteFunctionExternDeclarations(
|
537
|
+
Environment *theEnv,
|
538
|
+
FILE *fp)
|
539
|
+
{
|
540
|
+
struct functionDefinition *theFunction;
|
541
|
+
|
542
|
+
fprintf(fp,"\n");
|
543
|
+
fprintf(fp,"/************************************/\n");
|
544
|
+
fprintf(fp,"/* EXTERNAL FUNCTION DEFINITIONS */\n");
|
545
|
+
fprintf(fp,"/************************************/\n\n");
|
546
|
+
|
547
|
+
for (theFunction = GetFunctionList(theEnv);
|
548
|
+
theFunction != NULL;
|
549
|
+
theFunction = theFunction->next)
|
550
|
+
{
|
551
|
+
fprintf(fp,"extern ");
|
552
|
+
fprintf(fp,"void ");
|
553
|
+
|
554
|
+
fprintf(fp,"%s(",theFunction->actualFunctionName);
|
555
|
+
|
556
|
+
fprintf(fp,"Environment *,UDFContext *,UDFValue *");
|
557
|
+
|
558
|
+
fprintf(fp,");\n");
|
559
|
+
}
|
560
|
+
}
|
561
|
+
|
562
|
+
/****************************************************/
|
563
|
+
/* FunctionsToCode: Generates C code to represent */
|
564
|
+
/* the function declaration data structures (used */
|
565
|
+
/* to declare system and user defined functions). */
|
566
|
+
/****************************************************/
|
567
|
+
static bool FunctionsToCode(
|
568
|
+
Environment *theEnv,
|
569
|
+
const char *fileName,
|
570
|
+
const char *pathName,
|
571
|
+
char *fileNameBuffer)
|
572
|
+
{
|
573
|
+
unsigned short i = 0;
|
574
|
+
FILE *fp;
|
575
|
+
unsigned version = 1;
|
576
|
+
bool newHeader = true;
|
577
|
+
struct functionDefinition *fctnPtr;
|
578
|
+
|
579
|
+
/*=============================*/
|
580
|
+
/* Assign a reference index to */
|
581
|
+
/* each of the functions. */
|
582
|
+
/*=============================*/
|
583
|
+
|
584
|
+
for (fctnPtr = GetFunctionList(theEnv);
|
585
|
+
fctnPtr != NULL;
|
586
|
+
fctnPtr = fctnPtr->next)
|
587
|
+
{ fctnPtr->bsaveIndex = i++; }
|
588
|
+
|
589
|
+
/*=======================================*/
|
590
|
+
/* Create the file in which to store the */
|
591
|
+
/* function definition data structures. */
|
592
|
+
/*=======================================*/
|
593
|
+
|
594
|
+
if ((fp = NewCFile(theEnv,fileName,pathName,fileNameBuffer,2,version,false)) == NULL)
|
595
|
+
{ return false; }
|
596
|
+
|
597
|
+
/*===============================================*/
|
598
|
+
/* Construct the definition of the function list */
|
599
|
+
/* from the definitions of the functions. */
|
600
|
+
/*===============================================*/
|
601
|
+
|
602
|
+
fprintf(fp,"\n\n");
|
603
|
+
fprintf(fp,"/************************************/\n");
|
604
|
+
fprintf(fp,"/* FUNCTION LIST DEFINITION */\n");
|
605
|
+
fprintf(fp,"/************************************/\n\n");
|
606
|
+
|
607
|
+
i = 1;
|
608
|
+
fctnPtr = GetFunctionList(theEnv);
|
609
|
+
while (fctnPtr != NULL)
|
610
|
+
{
|
611
|
+
if (newHeader)
|
612
|
+
{
|
613
|
+
fprintf(fp,"struct functionDefinition P%d_%d[] = {\n",ConstructCompilerData(theEnv)->ImageID,version);
|
614
|
+
fprintf(ConstructCompilerData(theEnv)->HeaderFP,"extern struct functionDefinition P%d_%d[];\n",ConstructCompilerData(theEnv)->ImageID,version);
|
615
|
+
newHeader = false;
|
616
|
+
}
|
617
|
+
|
618
|
+
fprintf(fp,"{");
|
619
|
+
PrintSymbolReference(theEnv,fp,fctnPtr->callFunctionName);
|
620
|
+
fprintf(fp,",\"%s\",",fctnPtr->actualFunctionName);
|
621
|
+
fprintf(fp,"%u,",fctnPtr->unknownReturnValueType);
|
622
|
+
fprintf(fp,"%s,",fctnPtr->actualFunctionName);
|
623
|
+
fprintf(fp,"NULL,");
|
624
|
+
|
625
|
+
PrintSymbolReference(theEnv,fp,fctnPtr->restrictions);
|
626
|
+
|
627
|
+
fprintf(fp,",%d,%d,0,0,0,0,",fctnPtr->minArgs,fctnPtr->maxArgs);
|
628
|
+
|
629
|
+
PrintFunctionReference(theEnv,fp,fctnPtr->next);
|
630
|
+
|
631
|
+
i++;
|
632
|
+
fctnPtr = fctnPtr->next;
|
633
|
+
if ((i > ConstructCompilerData(theEnv)->MaxIndices) || (fctnPtr == NULL))
|
634
|
+
{
|
635
|
+
fprintf(fp,"}};\n");
|
636
|
+
GenClose(theEnv,fp);
|
637
|
+
i = 1;
|
638
|
+
version++;
|
639
|
+
if (fctnPtr != NULL)
|
640
|
+
{
|
641
|
+
if ((fp = NewCFile(theEnv,fileName,pathName,fileNameBuffer,2,version,false)) == NULL) return false;
|
642
|
+
newHeader = true;
|
643
|
+
}
|
644
|
+
}
|
645
|
+
else
|
646
|
+
{ fprintf(fp,"},\n"); }
|
647
|
+
}
|
648
|
+
|
649
|
+
return true;
|
650
|
+
}
|
651
|
+
|
652
|
+
/************************************************************/
|
653
|
+
/* PrintFunctionReference: Writes the C code representation */
|
654
|
+
/* of a pointer to a function definition data structure. */
|
655
|
+
/************************************************************/
|
656
|
+
void PrintFunctionReference(
|
657
|
+
Environment *theEnv,
|
658
|
+
FILE *fp,
|
659
|
+
struct functionDefinition *funcPtr)
|
660
|
+
{
|
661
|
+
if (funcPtr == NULL) fprintf(fp,"NULL");
|
662
|
+
else
|
663
|
+
fprintf(fp,"&P%d_%lu[%lu]",ConstructCompilerData(theEnv)->ImageID,
|
664
|
+
(funcPtr->bsaveIndex / ConstructCompilerData(theEnv)->MaxIndices) + 1,
|
665
|
+
funcPtr->bsaveIndex % ConstructCompilerData(theEnv)->MaxIndices);
|
666
|
+
}
|
667
|
+
|
668
|
+
/******************************************/
|
669
|
+
/* WriteInitializationFunction: Generates */
|
670
|
+
/* the C initialization function for */
|
671
|
+
/* this constructs-to-c module. */
|
672
|
+
/******************************************/
|
673
|
+
static bool WriteInitializationFunction(
|
674
|
+
Environment *theEnv,
|
675
|
+
const char *fileName,
|
676
|
+
const char *pathName,
|
677
|
+
char *fileNameBuffer)
|
678
|
+
{
|
679
|
+
FILE *fp;
|
680
|
+
struct CodeGeneratorItem *cgPtr;
|
681
|
+
|
682
|
+
/*===============================*/
|
683
|
+
/* Open the initialization file. */
|
684
|
+
/*===============================*/
|
685
|
+
|
686
|
+
gensprintf(fileNameBuffer,"%s%s.c",pathName,fileName);
|
687
|
+
if ((fp = GenOpen(theEnv,fileNameBuffer,"w")) == NULL)
|
688
|
+
{
|
689
|
+
OpenErrorMessage(theEnv,"constructs-to-c",fileNameBuffer);
|
690
|
+
return false;
|
691
|
+
}
|
692
|
+
|
693
|
+
/*=====================================*/
|
694
|
+
/* Write out #includes and prototypes. */
|
695
|
+
/*=====================================*/
|
696
|
+
|
697
|
+
fprintf(fp,"#include \"%s.h\"\n",fileName);
|
698
|
+
fprintf(fp,"\n");
|
699
|
+
fprintf(fp,"#include \"utility.h\"\n");
|
700
|
+
fprintf(fp,"#include \"generate.h\"\n");
|
701
|
+
fprintf(fp,"#include \"envrnmnt.h\"\n");
|
702
|
+
fprintf(fp,"#include \"expressn.h\"\n");
|
703
|
+
fprintf(fp,"#include \"extnfunc.h\"\n");
|
704
|
+
fprintf(fp,"#include \"objrtmch.h\"\n");
|
705
|
+
fprintf(fp,"#include \"rulebld.h\"\n\n");
|
706
|
+
|
707
|
+
fprintf(ConstructCompilerData(theEnv)->HeaderFP," Environment *InitCImage_%d(void);\n",ConstructCompilerData(theEnv)->ImageID);
|
708
|
+
fprintf(ConstructCompilerData(theEnv)->HeaderFP," void FixupCImage_%d(Environment *);\n",ConstructCompilerData(theEnv)->ImageID);
|
709
|
+
|
710
|
+
/*============================================*/
|
711
|
+
/* Begin writing the initialization function. */
|
712
|
+
/*============================================*/
|
713
|
+
|
714
|
+
fprintf(fp,"\n");
|
715
|
+
fprintf(fp,"/*******************************************/\n");
|
716
|
+
fprintf(fp,"/* CONSTRUCT IMAGE INITIALIZATION FUNCTION */\n");
|
717
|
+
fprintf(fp,"/*******************************************/\n");
|
718
|
+
|
719
|
+
fprintf(fp,"\nEnvironment *InitCImage_%d()\n",ConstructCompilerData(theEnv)->ImageID);
|
720
|
+
fprintf(fp," {\n");
|
721
|
+
fprintf(fp," static Environment *theEnv = NULL;\n\n");
|
722
|
+
fprintf(fp," if (theEnv != NULL) return NULL;\n\n");
|
723
|
+
fprintf(fp," theEnv = CreateRuntimeEnvironment(sht%d,fht%d,iht%d,bmht%d,P%d_1);\n\n",
|
724
|
+
ConstructCompilerData(theEnv)->ImageID,ConstructCompilerData(theEnv)->ImageID,
|
725
|
+
ConstructCompilerData(theEnv)->ImageID,ConstructCompilerData(theEnv)->ImageID,
|
726
|
+
ConstructCompilerData(theEnv)->ImageID);
|
727
|
+
|
728
|
+
fprintf(fp," Clear(theEnv);\n");
|
729
|
+
|
730
|
+
fprintf(fp," RefreshSpecialSymbols(theEnv);\n");
|
731
|
+
fprintf(fp," InitExpressionPointers(theEnv);\n");
|
732
|
+
fprintf(fp," FixupCImage_%d(theEnv);\n\n",ConstructCompilerData(theEnv)->ImageID);
|
733
|
+
|
734
|
+
/*==========================================*/
|
735
|
+
/* Write construct specific initialization. */
|
736
|
+
/*==========================================*/
|
737
|
+
|
738
|
+
cgPtr = ConstructCompilerData(theEnv)->ListOfCodeGeneratorItems;
|
739
|
+
while (cgPtr != NULL)
|
740
|
+
{
|
741
|
+
if (cgPtr->initFunction != NULL)
|
742
|
+
{
|
743
|
+
(*cgPtr->initFunction)(theEnv,fp,ConstructCompilerData(theEnv)->ImageID,ConstructCompilerData(theEnv)->MaxIndices);
|
744
|
+
fprintf(fp,"\n");
|
745
|
+
}
|
746
|
+
cgPtr = cgPtr->next;
|
747
|
+
}
|
748
|
+
|
749
|
+
/*================================*/
|
750
|
+
/* Close the initialization file. */
|
751
|
+
/*================================*/
|
752
|
+
|
753
|
+
fprintf(fp," return(theEnv);\n");
|
754
|
+
fprintf(fp," }\n");
|
755
|
+
|
756
|
+
GenClose(theEnv,fp);
|
757
|
+
|
758
|
+
/*========================================*/
|
759
|
+
/* Return true to indicate initialization */
|
760
|
+
/* file was successfully written. */
|
761
|
+
/*========================================*/
|
762
|
+
|
763
|
+
return true;
|
764
|
+
}
|
765
|
+
|
766
|
+
/**************************************************/
|
767
|
+
/* NewCFile: Opens a new file for writing C code. */
|
768
|
+
/**************************************************/
|
769
|
+
FILE *NewCFile(
|
770
|
+
Environment *theEnv,
|
771
|
+
const char *fileName,
|
772
|
+
const char *pathName,
|
773
|
+
char *fileNameBuffer,
|
774
|
+
unsigned id,
|
775
|
+
unsigned version,
|
776
|
+
bool reopenOldFile)
|
777
|
+
{
|
778
|
+
FILE *newFP;
|
779
|
+
|
780
|
+
gensprintf(fileNameBuffer,"%s%s%d_%d.c",pathName,fileName,id,version);
|
781
|
+
|
782
|
+
if (reopenOldFile)
|
783
|
+
{ newFP = GenOpen(theEnv,fileNameBuffer,"a"); }
|
784
|
+
else
|
785
|
+
{ newFP = GenOpen(theEnv,fileNameBuffer,"w"); }
|
786
|
+
|
787
|
+
if (newFP == NULL)
|
788
|
+
{
|
789
|
+
OpenErrorMessage(theEnv,"constructs-to-c",fileNameBuffer);
|
790
|
+
return NULL;
|
791
|
+
}
|
792
|
+
|
793
|
+
if (reopenOldFile == false)
|
794
|
+
{
|
795
|
+
fprintf(newFP,"#include \"%s.h\"\n",fileName);
|
796
|
+
fprintf(newFP,"\n");
|
797
|
+
}
|
798
|
+
|
799
|
+
return(newFP);
|
800
|
+
}
|
801
|
+
|
802
|
+
/**********************************************************/
|
803
|
+
/* HashedExpressionsToCode: Traverses the expression hash */
|
804
|
+
/* table and calls ExpressionToCode to write the C */
|
805
|
+
/* code representation to a file of every expression in */
|
806
|
+
/* the table. */
|
807
|
+
/**********************************************************/
|
808
|
+
static void HashedExpressionsToCode(
|
809
|
+
Environment *theEnv)
|
810
|
+
{
|
811
|
+
unsigned i;
|
812
|
+
EXPRESSION_HN *exphash;
|
813
|
+
|
814
|
+
for (i = 0; i < EXPRESSION_HASH_SIZE; i++)
|
815
|
+
{
|
816
|
+
for (exphash = ExpressionData(theEnv)->ExpressionHashTable[i];
|
817
|
+
exphash != NULL;
|
818
|
+
exphash = exphash->next)
|
819
|
+
{
|
820
|
+
exphash->bsaveID = ConstructCompilerData(theEnv)->ExpressionCount + (ConstructCompilerData(theEnv)->MaxIndices * ConstructCompilerData(theEnv)->ExpressionVersion);
|
821
|
+
ExpressionToCode(theEnv,NULL,exphash->exp);
|
822
|
+
}
|
823
|
+
}
|
824
|
+
}
|
825
|
+
|
826
|
+
/*****************************************************/
|
827
|
+
/* PrintHashedExpressionReference: Writes the C code */
|
828
|
+
/* representation of a pointer to an expression */
|
829
|
+
/* stored in the expression hash table. */
|
830
|
+
/*****************************************************/
|
831
|
+
void PrintHashedExpressionReference(
|
832
|
+
Environment *theEnv,
|
833
|
+
FILE *theFile,
|
834
|
+
struct expr *theExpression,
|
835
|
+
unsigned imageID,
|
836
|
+
unsigned maxIndices)
|
837
|
+
{
|
838
|
+
unsigned long theIDValue;
|
839
|
+
|
840
|
+
if (theExpression == NULL)
|
841
|
+
{ fprintf(theFile,"NULL"); }
|
842
|
+
else
|
843
|
+
{
|
844
|
+
theIDValue = HashedExpressionIndex(theEnv,theExpression);
|
845
|
+
|
846
|
+
fprintf(theFile,"&E%d_%ld[%ld]",
|
847
|
+
imageID,
|
848
|
+
theIDValue / maxIndices,
|
849
|
+
theIDValue % maxIndices);
|
850
|
+
}
|
851
|
+
}
|
852
|
+
|
853
|
+
/**************************************************************/
|
854
|
+
/* ExpressionToCode: Writes the C code reference of a pointer */
|
855
|
+
/* to an expression and then calls DumpExpression to write */
|
856
|
+
/* the C code for the expression to the expression file. */
|
857
|
+
/**************************************************************/
|
858
|
+
int ExpressionToCode(
|
859
|
+
Environment *theEnv,
|
860
|
+
FILE *fp,
|
861
|
+
struct expr *exprPtr)
|
862
|
+
{
|
863
|
+
/*========================================*/
|
864
|
+
/* Print the reference to the expression. */
|
865
|
+
/*========================================*/
|
866
|
+
|
867
|
+
if (exprPtr == NULL)
|
868
|
+
{
|
869
|
+
if (fp != NULL) fprintf(fp,"NULL");
|
870
|
+
return 0;
|
871
|
+
}
|
872
|
+
else if (fp != NULL)
|
873
|
+
{ fprintf(fp,"&E%d_%d[%ld]",ConstructCompilerData(theEnv)->ImageID,ConstructCompilerData(theEnv)->ExpressionVersion,ConstructCompilerData(theEnv)->ExpressionCount); }
|
874
|
+
|
875
|
+
/*==================================================*/
|
876
|
+
/* Create a new expression code file, if necessary. */
|
877
|
+
/*==================================================*/
|
878
|
+
|
879
|
+
if (ConstructCompilerData(theEnv)->ExpressionHeader == true)
|
880
|
+
{
|
881
|
+
if ((ConstructCompilerData(theEnv)->ExpressionFP = NewCFile(theEnv,ConstructCompilerData(theEnv)->FilePrefix,
|
882
|
+
ConstructCompilerData(theEnv)->PathName,
|
883
|
+
ConstructCompilerData(theEnv)->FileNameBuffer,
|
884
|
+
3,ConstructCompilerData(theEnv)->ExpressionVersion,false)) == NULL)
|
885
|
+
{ return(-1); }
|
886
|
+
|
887
|
+
fprintf(ConstructCompilerData(theEnv)->ExpressionFP,"struct expr E%d_%d[] = {\n",ConstructCompilerData(theEnv)->ImageID,ConstructCompilerData(theEnv)->ExpressionVersion);
|
888
|
+
fprintf(ConstructCompilerData(theEnv)->HeaderFP,"extern struct expr E%d_%d[];\n",ConstructCompilerData(theEnv)->ImageID,ConstructCompilerData(theEnv)->ExpressionVersion);
|
889
|
+
ConstructCompilerData(theEnv)->ExpressionHeader = false;
|
890
|
+
}
|
891
|
+
else
|
892
|
+
{ fprintf(ConstructCompilerData(theEnv)->ExpressionFP,",\n"); }
|
893
|
+
|
894
|
+
/*===========================*/
|
895
|
+
/* Dump the expression code. */
|
896
|
+
/*===========================*/
|
897
|
+
|
898
|
+
DumpExpression(theEnv,exprPtr);
|
899
|
+
|
900
|
+
/*=========================================*/
|
901
|
+
/* Close the expression file if necessary. */
|
902
|
+
/*=========================================*/
|
903
|
+
|
904
|
+
if (ConstructCompilerData(theEnv)->ExpressionCount >= ConstructCompilerData(theEnv)->MaxIndices)
|
905
|
+
{
|
906
|
+
ConstructCompilerData(theEnv)->ExpressionCount = 0;
|
907
|
+
ConstructCompilerData(theEnv)->ExpressionVersion++;
|
908
|
+
fprintf(ConstructCompilerData(theEnv)->ExpressionFP,"};\n");
|
909
|
+
GenClose(theEnv,ConstructCompilerData(theEnv)->ExpressionFP);
|
910
|
+
ConstructCompilerData(theEnv)->ExpressionFP = NULL;
|
911
|
+
ConstructCompilerData(theEnv)->ExpressionHeader = true;
|
912
|
+
}
|
913
|
+
|
914
|
+
/*==========================================*/
|
915
|
+
/* Return 1 to indicate the expression */
|
916
|
+
/* reference and expression data structures */
|
917
|
+
/* were succcessfully written to the file. */
|
918
|
+
/*==========================================*/
|
919
|
+
|
920
|
+
return 1;
|
921
|
+
}
|
922
|
+
|
923
|
+
/**********************************************************/
|
924
|
+
/* DumpExpression: Writes the C code representation of an */
|
925
|
+
/* expression data structure to the expression file. */
|
926
|
+
/**********************************************************/
|
927
|
+
static void DumpExpression(
|
928
|
+
Environment *theEnv,
|
929
|
+
struct expr *exprPtr)
|
930
|
+
{
|
931
|
+
while (exprPtr != NULL)
|
932
|
+
{
|
933
|
+
fprintf(ConstructCompilerData(theEnv)->ExpressionFP,"{");
|
934
|
+
fprintf(ConstructCompilerData(theEnv)->ExpressionFP,"%d,",exprPtr->type);
|
935
|
+
fprintf(ConstructCompilerData(theEnv)->ExpressionFP,"{ ");
|
936
|
+
switch (exprPtr->type)
|
937
|
+
{
|
938
|
+
case FCALL:
|
939
|
+
PrintFunctionReference(theEnv,ConstructCompilerData(theEnv)->ExpressionFP,exprPtr->functionValue);
|
940
|
+
break;
|
941
|
+
|
942
|
+
case INTEGER_TYPE:
|
943
|
+
PrintIntegerReference(theEnv,ConstructCompilerData(theEnv)->ExpressionFP,exprPtr->integerValue);
|
944
|
+
break;
|
945
|
+
|
946
|
+
case FLOAT_TYPE:
|
947
|
+
PrintFloatReference(theEnv,ConstructCompilerData(theEnv)->ExpressionFP,exprPtr->floatValue);
|
948
|
+
break;
|
949
|
+
|
950
|
+
case PCALL:
|
951
|
+
#if DEFFUNCTION_CONSTRUCT
|
952
|
+
PrintDeffunctionReference(theEnv,ConstructCompilerData(theEnv)->ExpressionFP,(Deffunction *) exprPtr->value,
|
953
|
+
ConstructCompilerData(theEnv)->ImageID,ConstructCompilerData(theEnv)->MaxIndices);
|
954
|
+
#else
|
955
|
+
fprintf(ConstructCompilerData(theEnv)->ExpressionFP,"NULL");
|
956
|
+
#endif
|
957
|
+
break;
|
958
|
+
|
959
|
+
case GCALL:
|
960
|
+
#if DEFGENERIC_CONSTRUCT
|
961
|
+
PrintGenericFunctionReference(theEnv,ConstructCompilerData(theEnv)->ExpressionFP,(Defgeneric *) exprPtr->value,
|
962
|
+
ConstructCompilerData(theEnv)->ImageID,ConstructCompilerData(theEnv)->MaxIndices);
|
963
|
+
#else
|
964
|
+
fprintf(ConstructCompilerData(theEnv)->ExpressionFP,"NULL");
|
965
|
+
#endif
|
966
|
+
break;
|
967
|
+
|
968
|
+
case DEFTEMPLATE_PTR:
|
969
|
+
#if DEFTEMPLATE_CONSTRUCT
|
970
|
+
DeftemplateCConstructReference(theEnv,ConstructCompilerData(theEnv)->ExpressionFP,
|
971
|
+
(Deftemplate *) exprPtr->value,ConstructCompilerData(theEnv)->ImageID,ConstructCompilerData(theEnv)->MaxIndices);
|
972
|
+
#else
|
973
|
+
fprintf(ConstructCompilerData(theEnv)->ExpressionFP,"NULL");
|
974
|
+
#endif
|
975
|
+
break;
|
976
|
+
|
977
|
+
case DEFGLOBAL_PTR:
|
978
|
+
#if DEFGLOBAL_CONSTRUCT
|
979
|
+
DefglobalCConstructReference(theEnv,ConstructCompilerData(theEnv)->ExpressionFP,
|
980
|
+
(Defglobal *) exprPtr->value,ConstructCompilerData(theEnv)->ImageID,ConstructCompilerData(theEnv)->MaxIndices);
|
981
|
+
#else
|
982
|
+
fprintf(ConstructCompilerData(theEnv)->ExpressionFP,"NULL");
|
983
|
+
#endif
|
984
|
+
break;
|
985
|
+
|
986
|
+
case DEFCLASS_PTR:
|
987
|
+
#if OBJECT_SYSTEM
|
988
|
+
PrintClassReference(theEnv,ConstructCompilerData(theEnv)->ExpressionFP,
|
989
|
+
(Defclass *) exprPtr->value,ConstructCompilerData(theEnv)->ImageID,
|
990
|
+
ConstructCompilerData(theEnv)->MaxIndices);
|
991
|
+
#else
|
992
|
+
fprintf(ConstructCompilerData(theEnv)->ExpressionFP,"NULL");
|
993
|
+
#endif
|
994
|
+
break;
|
995
|
+
|
996
|
+
case FACT_ADDRESS_TYPE:
|
997
|
+
#if DEFTEMPLATE_CONSTRUCT
|
998
|
+
fprintf(ConstructCompilerData(theEnv)->ExpressionFP,"NULL");
|
999
|
+
fprintf(ConstructCompilerData(theEnv)->FixupFP,
|
1000
|
+
" E%d_%d[%ld].value = &FactData(theEnv)->DummyFact;\n",
|
1001
|
+
ConstructCompilerData(theEnv)->ImageID,
|
1002
|
+
ConstructCompilerData(theEnv)->ExpressionVersion,
|
1003
|
+
ConstructCompilerData(theEnv)->ExpressionCount);
|
1004
|
+
#else
|
1005
|
+
fprintf(ConstructCompilerData(theEnv)->ExpressionFP,"NULL");
|
1006
|
+
#endif
|
1007
|
+
break;
|
1008
|
+
|
1009
|
+
case INSTANCE_ADDRESS_TYPE:
|
1010
|
+
#if OBJECT_SYSTEM
|
1011
|
+
fprintf(ConstructCompilerData(theEnv)->ExpressionFP,"NULL");
|
1012
|
+
fprintf(ConstructCompilerData(theEnv)->FixupFP,
|
1013
|
+
" E%d_%d[%ld].value = &InstanceData(theEnv)->DummyInstance;\n",
|
1014
|
+
ConstructCompilerData(theEnv)->ImageID,
|
1015
|
+
ConstructCompilerData(theEnv)->ExpressionVersion,
|
1016
|
+
ConstructCompilerData(theEnv)->ExpressionCount);
|
1017
|
+
#else
|
1018
|
+
fprintf(ConstructCompilerData(theEnv)->ExpressionFP,"NULL");
|
1019
|
+
#endif
|
1020
|
+
break;
|
1021
|
+
|
1022
|
+
case STRING_TYPE:
|
1023
|
+
case SYMBOL_TYPE:
|
1024
|
+
case INSTANCE_NAME_TYPE:
|
1025
|
+
case GBL_VARIABLE:
|
1026
|
+
PrintSymbolReference(theEnv,ConstructCompilerData(theEnv)->ExpressionFP,exprPtr->lexemeValue);
|
1027
|
+
break;
|
1028
|
+
|
1029
|
+
case VOID_TYPE:
|
1030
|
+
fprintf(ConstructCompilerData(theEnv)->ExpressionFP,"NULL");
|
1031
|
+
break;
|
1032
|
+
|
1033
|
+
default:
|
1034
|
+
if (EvaluationData(theEnv)->PrimitivesArray[exprPtr->type] == NULL)
|
1035
|
+
{ fprintf(ConstructCompilerData(theEnv)->ExpressionFP,"NULL"); }
|
1036
|
+
else if (EvaluationData(theEnv)->PrimitivesArray[exprPtr->type]->bitMap)
|
1037
|
+
{ PrintBitMapReference(theEnv,ConstructCompilerData(theEnv)->ExpressionFP,(CLIPSBitMap *) exprPtr->value); }
|
1038
|
+
else
|
1039
|
+
{ fprintf(ConstructCompilerData(theEnv)->ExpressionFP,"NULL"); }
|
1040
|
+
break;
|
1041
|
+
}
|
1042
|
+
|
1043
|
+
fprintf(ConstructCompilerData(theEnv)->ExpressionFP,"},");
|
1044
|
+
|
1045
|
+
ConstructCompilerData(theEnv)->ExpressionCount++;
|
1046
|
+
if (exprPtr->argList == NULL)
|
1047
|
+
{ fprintf(ConstructCompilerData(theEnv)->ExpressionFP,"NULL,"); }
|
1048
|
+
else
|
1049
|
+
{
|
1050
|
+
fprintf(ConstructCompilerData(theEnv)->ExpressionFP,"&E%d_%d[%ld],",ConstructCompilerData(theEnv)->ImageID,ConstructCompilerData(theEnv)->ExpressionVersion,
|
1051
|
+
ConstructCompilerData(theEnv)->ExpressionCount);
|
1052
|
+
}
|
1053
|
+
|
1054
|
+
if (exprPtr->nextArg == NULL)
|
1055
|
+
{ fprintf(ConstructCompilerData(theEnv)->ExpressionFP,"NULL}"); }
|
1056
|
+
else
|
1057
|
+
{
|
1058
|
+
fprintf(ConstructCompilerData(theEnv)->ExpressionFP,"&E%d_%d[%ld]}",ConstructCompilerData(theEnv)->ImageID,ConstructCompilerData(theEnv)->ExpressionVersion,
|
1059
|
+
ConstructCompilerData(theEnv)->ExpressionCount + ExpressionSize(exprPtr->argList));
|
1060
|
+
}
|
1061
|
+
|
1062
|
+
if (exprPtr->argList != NULL)
|
1063
|
+
{
|
1064
|
+
fprintf(ConstructCompilerData(theEnv)->ExpressionFP,",\n");
|
1065
|
+
DumpExpression(theEnv,exprPtr->argList);
|
1066
|
+
}
|
1067
|
+
|
1068
|
+
exprPtr = exprPtr->nextArg;
|
1069
|
+
if (exprPtr != NULL) fprintf(ConstructCompilerData(theEnv)->ExpressionFP,",\n");
|
1070
|
+
}
|
1071
|
+
}
|
1072
|
+
|
1073
|
+
/***********************************************/
|
1074
|
+
/* ConstructsToCCommandDefinition: Initializes */
|
1075
|
+
/* the constructs-to-c command. */
|
1076
|
+
/***********************************************/
|
1077
|
+
void ConstructsToCCommandDefinition(
|
1078
|
+
Environment *theEnv)
|
1079
|
+
{
|
1080
|
+
AddUDF(theEnv,"constructs-to-c","v",2,4,"*;sy;l;sy;l",ConstructsToCCommand,"ConstructsToCCommand",NULL);
|
1081
|
+
}
|
1082
|
+
|
1083
|
+
/*********************************************************/
|
1084
|
+
/* AddCodeGeneratorItem: Adds another code generator */
|
1085
|
+
/* item to the list of items for which code is */
|
1086
|
+
/* generated bythe constructs-to-c function. Typically */
|
1087
|
+
/* each construct has its own code generator item. */
|
1088
|
+
/*********************************************************/
|
1089
|
+
struct CodeGeneratorItem *AddCodeGeneratorItem(
|
1090
|
+
Environment *theEnv,
|
1091
|
+
const char *name,
|
1092
|
+
int priority,
|
1093
|
+
void (*beforeFunction)(Environment *),
|
1094
|
+
void (*initFunction)(Environment *,FILE *,unsigned,unsigned),
|
1095
|
+
bool (*generateFunction)(Environment *,const char *,const char *,char *,
|
1096
|
+
unsigned int,FILE *,unsigned int,unsigned int),
|
1097
|
+
unsigned arrayCount)
|
1098
|
+
{
|
1099
|
+
struct CodeGeneratorItem *newPtr, *currentPtr, *lastPtr = NULL;
|
1100
|
+
unsigned int i;
|
1101
|
+
char theBuffer[4];
|
1102
|
+
|
1103
|
+
/*======================================*/
|
1104
|
+
/* Create the code generator item data */
|
1105
|
+
/* structure and initialize its values. */
|
1106
|
+
/*======================================*/
|
1107
|
+
|
1108
|
+
newPtr = get_struct(theEnv,CodeGeneratorItem);
|
1109
|
+
|
1110
|
+
newPtr->name = name;
|
1111
|
+
newPtr->beforeFunction = beforeFunction;
|
1112
|
+
newPtr->initFunction = initFunction;
|
1113
|
+
newPtr->generateFunction = generateFunction;
|
1114
|
+
newPtr->priority = priority;
|
1115
|
+
newPtr->arrayCount = arrayCount;
|
1116
|
+
|
1117
|
+
/*================================================*/
|
1118
|
+
/* Create the primary and secondary codes used to */
|
1119
|
+
/* provide names for the C data structure arrays. */
|
1120
|
+
/* (The maximum number of arrays is currently */
|
1121
|
+
/* limited to 47. */
|
1122
|
+
/*================================================*/
|
1123
|
+
|
1124
|
+
if (arrayCount != 0)
|
1125
|
+
{
|
1126
|
+
if ((arrayCount + ConstructCompilerData(theEnv)->CodeGeneratorCount) > (PRIMARY_LEN + SECONDARY_LEN))
|
1127
|
+
{
|
1128
|
+
SystemError(theEnv,"CONSCOMP",3);
|
1129
|
+
ExitRouter(theEnv,EXIT_FAILURE);
|
1130
|
+
}
|
1131
|
+
|
1132
|
+
newPtr->arrayNames = (char **) gm2(theEnv,(sizeof(char *) * arrayCount));
|
1133
|
+
|
1134
|
+
for (i = 0 ; i < arrayCount ; i++)
|
1135
|
+
{
|
1136
|
+
if (ConstructCompilerData(theEnv)->CodeGeneratorCount < PRIMARY_LEN)
|
1137
|
+
{ gensnprintf(theBuffer,sizeof(theBuffer),"%c",PRIMARY_CODES[ConstructCompilerData(theEnv)->CodeGeneratorCount]); }
|
1138
|
+
else
|
1139
|
+
{ gensnprintf(theBuffer,sizeof(theBuffer),"%s_",SecondaryCodes[ConstructCompilerData(theEnv)->CodeGeneratorCount - PRIMARY_LEN]); }
|
1140
|
+
ConstructCompilerData(theEnv)->CodeGeneratorCount++;
|
1141
|
+
newPtr->arrayNames[i] = (char *) gm2(theEnv,(strlen(theBuffer) + 1));
|
1142
|
+
genstrcpy(newPtr->arrayNames[i],theBuffer);
|
1143
|
+
}
|
1144
|
+
}
|
1145
|
+
else
|
1146
|
+
{ newPtr->arrayNames = NULL; }
|
1147
|
+
|
1148
|
+
/*===========================================*/
|
1149
|
+
/* Add the new item in the appropriate place */
|
1150
|
+
/* in the code generator item list. */
|
1151
|
+
/*===========================================*/
|
1152
|
+
|
1153
|
+
if (ConstructCompilerData(theEnv)->ListOfCodeGeneratorItems == NULL)
|
1154
|
+
{
|
1155
|
+
newPtr->next = NULL;
|
1156
|
+
ConstructCompilerData(theEnv)->ListOfCodeGeneratorItems = newPtr;
|
1157
|
+
return(newPtr);
|
1158
|
+
}
|
1159
|
+
|
1160
|
+
currentPtr = ConstructCompilerData(theEnv)->ListOfCodeGeneratorItems;
|
1161
|
+
while ((currentPtr != NULL) ? (priority < currentPtr->priority) : false)
|
1162
|
+
{
|
1163
|
+
lastPtr = currentPtr;
|
1164
|
+
currentPtr = currentPtr->next;
|
1165
|
+
}
|
1166
|
+
|
1167
|
+
if (lastPtr == NULL)
|
1168
|
+
{
|
1169
|
+
newPtr->next = ConstructCompilerData(theEnv)->ListOfCodeGeneratorItems;
|
1170
|
+
ConstructCompilerData(theEnv)->ListOfCodeGeneratorItems = newPtr;
|
1171
|
+
}
|
1172
|
+
else
|
1173
|
+
{
|
1174
|
+
newPtr->next = currentPtr;
|
1175
|
+
lastPtr->next = newPtr;
|
1176
|
+
}
|
1177
|
+
|
1178
|
+
/*=========================*/
|
1179
|
+
/* Return a pointer to the */
|
1180
|
+
/* code generator item. */
|
1181
|
+
/*=========================*/
|
1182
|
+
|
1183
|
+
return(newPtr);
|
1184
|
+
}
|
1185
|
+
|
1186
|
+
/************************************************************/
|
1187
|
+
/* CloseFileIfNeeded: Determines if a C file to which data */
|
1188
|
+
/* structures have been written should be closed. The */
|
1189
|
+
/* file is closed either when all data structures of */
|
1190
|
+
/* that specific type are written to files or the maximum */
|
1191
|
+
/* number of array entries for a single file has been */
|
1192
|
+
/* exceeded. */
|
1193
|
+
/************************************************************/
|
1194
|
+
FILE *CloseFileIfNeeded(
|
1195
|
+
Environment *theEnv,
|
1196
|
+
FILE *theFile,
|
1197
|
+
unsigned int *theCount,
|
1198
|
+
unsigned int *arrayVersion,
|
1199
|
+
unsigned int maxIndices,
|
1200
|
+
bool *canBeReopened,
|
1201
|
+
struct CodeGeneratorFile *codeFile)
|
1202
|
+
{
|
1203
|
+
/*==========================================*/
|
1204
|
+
/* If the maximum number of entries for the */
|
1205
|
+
/* file hasn't been exceeded, then... */
|
1206
|
+
/*==========================================*/
|
1207
|
+
|
1208
|
+
if (*theCount < maxIndices)
|
1209
|
+
{
|
1210
|
+
/*====================================*/
|
1211
|
+
/* If the file can be reopened later, */
|
1212
|
+
/* close it. Otherwise, keep it open. */
|
1213
|
+
/*====================================*/
|
1214
|
+
|
1215
|
+
if (canBeReopened != NULL)
|
1216
|
+
{
|
1217
|
+
*canBeReopened = true;
|
1218
|
+
GenClose(theEnv,theFile);
|
1219
|
+
return NULL;
|
1220
|
+
}
|
1221
|
+
|
1222
|
+
return theFile;
|
1223
|
+
}
|
1224
|
+
|
1225
|
+
/*===========================================*/
|
1226
|
+
/* Otherwise, the number of entries allowed */
|
1227
|
+
/* in a file has been reached. Indicate that */
|
1228
|
+
/* the file can't be reopened. */
|
1229
|
+
/*===========================================*/
|
1230
|
+
|
1231
|
+
if (canBeReopened != NULL)
|
1232
|
+
{ *canBeReopened = false; }
|
1233
|
+
|
1234
|
+
/*===============================================*/
|
1235
|
+
/* If the file is closed, then we need to reopen */
|
1236
|
+
/* it to print the final closing right brace. */
|
1237
|
+
/*===============================================*/
|
1238
|
+
|
1239
|
+
if (theFile == NULL)
|
1240
|
+
{
|
1241
|
+
if ((canBeReopened == NULL) || (codeFile == NULL))
|
1242
|
+
{
|
1243
|
+
SystemError(theEnv,"CONSCOMP",4);
|
1244
|
+
ExitRouter(theEnv,EXIT_FAILURE);
|
1245
|
+
}
|
1246
|
+
|
1247
|
+
if (codeFile->filePrefix == NULL)
|
1248
|
+
{ return NULL; }
|
1249
|
+
|
1250
|
+
theFile = NewCFile(theEnv,codeFile->filePrefix,codeFile->pathName,
|
1251
|
+
codeFile->fileNameBuffer,
|
1252
|
+
codeFile->id,codeFile->version,true);
|
1253
|
+
if (theFile == NULL)
|
1254
|
+
{
|
1255
|
+
SystemError(theEnv,"CONSCOMP",5);
|
1256
|
+
ExitRouter(theEnv,EXIT_FAILURE);
|
1257
|
+
}
|
1258
|
+
}
|
1259
|
+
|
1260
|
+
/*================================*/
|
1261
|
+
/* Print the final closing brace. */
|
1262
|
+
/*================================*/
|
1263
|
+
|
1264
|
+
fprintf(theFile,"};\n");
|
1265
|
+
GenClose(theEnv,theFile);
|
1266
|
+
|
1267
|
+
/*============================================*/
|
1268
|
+
/* Update index values for subsequent writing */
|
1269
|
+
/* of data structures to files. */
|
1270
|
+
/*============================================*/
|
1271
|
+
|
1272
|
+
*theCount = 0;
|
1273
|
+
(*arrayVersion)++;
|
1274
|
+
|
1275
|
+
/*=========================*/
|
1276
|
+
/* Return NULL to indicate */
|
1277
|
+
/* the file is closed. */
|
1278
|
+
/*=========================*/
|
1279
|
+
|
1280
|
+
return NULL;
|
1281
|
+
}
|
1282
|
+
|
1283
|
+
/**************************************************************/
|
1284
|
+
/* OpenFileIfNeeded: Determines if a C file to which data */
|
1285
|
+
/* structures have been written should be closed. The */
|
1286
|
+
/* file is closed either when all data structures of */
|
1287
|
+
/* that specific type are written to files or the maximum */
|
1288
|
+
/* number of array entries for a single file has been */
|
1289
|
+
/* exceeded. */
|
1290
|
+
/******************************************************************/
|
1291
|
+
FILE *OpenFileIfNeeded(
|
1292
|
+
Environment *theEnv,
|
1293
|
+
FILE *theFile,
|
1294
|
+
const char *fileName,
|
1295
|
+
const char *pathName,
|
1296
|
+
char *fileNameBuffer,
|
1297
|
+
unsigned fileID,
|
1298
|
+
unsigned int imageID,
|
1299
|
+
unsigned *fileCount,
|
1300
|
+
unsigned int arrayVersion,
|
1301
|
+
FILE *headerFP,
|
1302
|
+
const char *structureName,
|
1303
|
+
char *structPrefix,
|
1304
|
+
bool reopenOldFile,
|
1305
|
+
struct CodeGeneratorFile *codeFile)
|
1306
|
+
{
|
1307
|
+
char arrayName[80];
|
1308
|
+
const char *newName;
|
1309
|
+
unsigned int newID, newVersion;
|
1310
|
+
|
1311
|
+
/*===========================================*/
|
1312
|
+
/* If a file is being reopened, use the same */
|
1313
|
+
/* version number, name, and ID as before. */
|
1314
|
+
/*===========================================*/
|
1315
|
+
|
1316
|
+
if (reopenOldFile)
|
1317
|
+
{
|
1318
|
+
if (codeFile == NULL)
|
1319
|
+
{
|
1320
|
+
SystemError(theEnv,"CONSCOMP",6);
|
1321
|
+
ExitRouter(theEnv,EXIT_FAILURE);
|
1322
|
+
}
|
1323
|
+
|
1324
|
+
newName = codeFile->filePrefix;
|
1325
|
+
newID = codeFile->id;
|
1326
|
+
newVersion = codeFile->version;
|
1327
|
+
}
|
1328
|
+
|
1329
|
+
/*=====================================================*/
|
1330
|
+
/* Otherwise, use the specified version number, name, */
|
1331
|
+
/* and ID. If the appropriate argument is supplied, */
|
1332
|
+
/* remember these values for later reopening the file. */
|
1333
|
+
/*=====================================================*/
|
1334
|
+
|
1335
|
+
else
|
1336
|
+
{
|
1337
|
+
newName = fileName;
|
1338
|
+
newVersion = *fileCount;
|
1339
|
+
newID = fileID;
|
1340
|
+
|
1341
|
+
if (codeFile != NULL)
|
1342
|
+
{
|
1343
|
+
codeFile->version = newVersion;
|
1344
|
+
codeFile->filePrefix = newName;
|
1345
|
+
codeFile->id = newID;
|
1346
|
+
}
|
1347
|
+
}
|
1348
|
+
|
1349
|
+
/*=========================================*/
|
1350
|
+
/* If the file is already open, return it. */
|
1351
|
+
/*=========================================*/
|
1352
|
+
|
1353
|
+
if (theFile != NULL)
|
1354
|
+
{
|
1355
|
+
fprintf(theFile,",\n");
|
1356
|
+
return(theFile);
|
1357
|
+
}
|
1358
|
+
|
1359
|
+
/*================*/
|
1360
|
+
/* Open the file. */
|
1361
|
+
/*================*/
|
1362
|
+
|
1363
|
+
if ((theFile = NewCFile(theEnv,newName,pathName,fileNameBuffer,newID,newVersion,reopenOldFile)) == NULL)
|
1364
|
+
{ return NULL; }
|
1365
|
+
|
1366
|
+
/*=========================================*/
|
1367
|
+
/* If this is the first time the file has */
|
1368
|
+
/* been opened, write out the beginning of */
|
1369
|
+
/* the array variable definition. */
|
1370
|
+
/*=========================================*/
|
1371
|
+
|
1372
|
+
if (reopenOldFile == false)
|
1373
|
+
{
|
1374
|
+
(*fileCount)++;
|
1375
|
+
gensnprintf(arrayName,sizeof(arrayName),"%s%d_%d",structPrefix,imageID,arrayVersion);
|
1376
|
+
fprintf(theFile,"%s %s[] = {\n",structureName,arrayName);
|
1377
|
+
fprintf(headerFP,"extern %s %s[];\n",structureName,arrayName);
|
1378
|
+
}
|
1379
|
+
else
|
1380
|
+
{ fprintf(theFile,",\n"); }
|
1381
|
+
|
1382
|
+
/*==================*/
|
1383
|
+
/* Return the file. */
|
1384
|
+
/*==================*/
|
1385
|
+
|
1386
|
+
return(theFile);
|
1387
|
+
}
|
1388
|
+
|
1389
|
+
/*************************************************/
|
1390
|
+
/* MarkConstructBsaveIDs: Mark all occurences of */
|
1391
|
+
/* a specific construct with a unique ID. */
|
1392
|
+
/*************************************************/
|
1393
|
+
void MarkConstructBsaveIDs(
|
1394
|
+
Environment *theEnv,
|
1395
|
+
unsigned int constructModuleIndex)
|
1396
|
+
{
|
1397
|
+
long theCount = 0;
|
1398
|
+
|
1399
|
+
DoForAllConstructs(theEnv,MarkConstruct,constructModuleIndex,false,&theCount);
|
1400
|
+
}
|
1401
|
+
|
1402
|
+
/*************************************************************/
|
1403
|
+
/* MarkConstruct: Sets the bsaveID for a specific construct. */
|
1404
|
+
/* Used with the MarkConstructBsaveIDs function to mark all */
|
1405
|
+
/* occurences of a specific construct with a unique ID. */
|
1406
|
+
/*************************************************************/
|
1407
|
+
static void MarkConstruct(
|
1408
|
+
Environment *theEnv,
|
1409
|
+
ConstructHeader *theConstruct,
|
1410
|
+
void *vTheBuffer)
|
1411
|
+
{
|
1412
|
+
unsigned long *count = (unsigned long *) vTheBuffer;
|
1413
|
+
#if MAC_XCD
|
1414
|
+
#pragma unused(theEnv)
|
1415
|
+
#endif
|
1416
|
+
|
1417
|
+
theConstruct->bsaveID = (*count)++;
|
1418
|
+
}
|
1419
|
+
|
1420
|
+
/***********************************************************/
|
1421
|
+
/* ConstructHeaderToCode: Writes the C code representation */
|
1422
|
+
/* of a single construct header to the specified file. */
|
1423
|
+
/***********************************************************/
|
1424
|
+
void ConstructHeaderToCode(
|
1425
|
+
Environment *theEnv,
|
1426
|
+
FILE *theFile,
|
1427
|
+
ConstructHeader *theConstruct,
|
1428
|
+
unsigned int imageID,
|
1429
|
+
unsigned int maxIndices,
|
1430
|
+
unsigned int moduleCount,
|
1431
|
+
const char *constructModulePrefix,
|
1432
|
+
const char *constructPrefix)
|
1433
|
+
{
|
1434
|
+
/*================*/
|
1435
|
+
/* Construct Name */
|
1436
|
+
/*================*/
|
1437
|
+
|
1438
|
+
fprintf(theFile,"{");
|
1439
|
+
|
1440
|
+
switch (theConstruct->constructType)
|
1441
|
+
{
|
1442
|
+
case DEFMODULE:
|
1443
|
+
fprintf(theFile,"DEFMODULE,");
|
1444
|
+
break;
|
1445
|
+
case DEFRULE:
|
1446
|
+
fprintf(theFile,"DEFRULE,");
|
1447
|
+
break;
|
1448
|
+
case DEFTEMPLATE:
|
1449
|
+
fprintf(theFile,"DEFTEMPLATE,");
|
1450
|
+
break;
|
1451
|
+
case DEFFACTS:
|
1452
|
+
fprintf(theFile,"DEFFACTS,");
|
1453
|
+
break;
|
1454
|
+
case DEFGLOBAL:
|
1455
|
+
fprintf(theFile,"DEFGLOBAL,");
|
1456
|
+
break;
|
1457
|
+
case DEFFUNCTION:
|
1458
|
+
fprintf(theFile,"DEFFUNCTION,");
|
1459
|
+
break;
|
1460
|
+
case DEFGENERIC:
|
1461
|
+
fprintf(theFile,"DEFGENERIC,");
|
1462
|
+
break;
|
1463
|
+
case DEFMETHOD:
|
1464
|
+
fprintf(theFile,"DEFMETHOD,");
|
1465
|
+
break;
|
1466
|
+
case DEFCLASS:
|
1467
|
+
fprintf(theFile,"DEFCLASS,");
|
1468
|
+
break;
|
1469
|
+
case DEFMESSAGE_HANDLER:
|
1470
|
+
fprintf(theFile,"DEFMESSAGE_HANDLER,");
|
1471
|
+
break;
|
1472
|
+
case DEFINSTANCES:
|
1473
|
+
fprintf(theFile,"DEFINSTANCES,");
|
1474
|
+
break;
|
1475
|
+
}
|
1476
|
+
|
1477
|
+
PrintSymbolReference(theEnv,theFile,theConstruct->name);
|
1478
|
+
|
1479
|
+
/*===================*/
|
1480
|
+
/* Pretty Print Form */
|
1481
|
+
/*===================*/
|
1482
|
+
|
1483
|
+
fprintf(theFile,",NULL,");
|
1484
|
+
|
1485
|
+
/*==================*/
|
1486
|
+
/* Construct Module */
|
1487
|
+
/*==================*/
|
1488
|
+
|
1489
|
+
if (theConstruct->whichModule != NULL)
|
1490
|
+
{
|
1491
|
+
fprintf(theFile,"MIHS &%s%d_%d[%d],",
|
1492
|
+
constructModulePrefix,
|
1493
|
+
imageID,
|
1494
|
+
(moduleCount / maxIndices) + 1,
|
1495
|
+
moduleCount % maxIndices);
|
1496
|
+
}
|
1497
|
+
else
|
1498
|
+
{ fprintf(theFile,"NULL,"); }
|
1499
|
+
|
1500
|
+
/*==========*/
|
1501
|
+
/* Bsave ID */
|
1502
|
+
/*==========*/
|
1503
|
+
|
1504
|
+
fprintf(theFile,"0,");
|
1505
|
+
|
1506
|
+
/*================*/
|
1507
|
+
/* Next Construct */
|
1508
|
+
/*================*/
|
1509
|
+
|
1510
|
+
if (theConstruct->next == NULL)
|
1511
|
+
{ fprintf(theFile,"NULL}"); }
|
1512
|
+
else
|
1513
|
+
{
|
1514
|
+
fprintf(theFile,"CHS &%s%d_%ld[%ld]}",
|
1515
|
+
constructPrefix,
|
1516
|
+
imageID,
|
1517
|
+
(theConstruct->next->bsaveID / maxIndices) + 1,
|
1518
|
+
theConstruct->next->bsaveID % maxIndices);
|
1519
|
+
}
|
1520
|
+
}
|
1521
|
+
|
1522
|
+
/***********************************************************/
|
1523
|
+
/* ConstructModuleToCode: Writes the C code representation */
|
1524
|
+
/* of a single construct module to the specified file. */
|
1525
|
+
/***********************************************************/
|
1526
|
+
void ConstructModuleToCode(
|
1527
|
+
Environment *theEnv,
|
1528
|
+
FILE *theFile,
|
1529
|
+
Defmodule *theModule,
|
1530
|
+
unsigned int imageID,
|
1531
|
+
unsigned int maxIndices,
|
1532
|
+
unsigned int constructIndex,
|
1533
|
+
const char *constructPrefix)
|
1534
|
+
{
|
1535
|
+
struct defmoduleItemHeader *theModuleItem;
|
1536
|
+
|
1537
|
+
/*======================*/
|
1538
|
+
/* Associated Defmodule */
|
1539
|
+
/*======================*/
|
1540
|
+
|
1541
|
+
fprintf(theFile,"{");
|
1542
|
+
|
1543
|
+
theModuleItem = (struct defmoduleItemHeader *)
|
1544
|
+
GetModuleItem(theEnv,theModule,constructIndex);
|
1545
|
+
|
1546
|
+
PrintDefmoduleReference(theEnv,theFile,theModule);
|
1547
|
+
|
1548
|
+
fprintf(theFile,",");
|
1549
|
+
|
1550
|
+
/*=============================*/
|
1551
|
+
/* First Construct Module Item */
|
1552
|
+
/*=============================*/
|
1553
|
+
|
1554
|
+
if (theModuleItem->firstItem == NULL) fprintf(theFile,"NULL,");
|
1555
|
+
else fprintf(theFile,"CHS &%s%d_%ld[%ld],",
|
1556
|
+
constructPrefix,
|
1557
|
+
imageID,
|
1558
|
+
(theModuleItem->firstItem->bsaveID / maxIndices) + 1,
|
1559
|
+
theModuleItem->firstItem->bsaveID % maxIndices);
|
1560
|
+
|
1561
|
+
/*============================*/
|
1562
|
+
/* Last Construct Module Item */
|
1563
|
+
/*============================*/
|
1564
|
+
|
1565
|
+
if (theModuleItem->lastItem == NULL) fprintf(theFile,"NULL");
|
1566
|
+
else fprintf(theFile,"CHS &%s%d_%ld[%ld]",
|
1567
|
+
constructPrefix,
|
1568
|
+
imageID,
|
1569
|
+
(theModuleItem->lastItem->bsaveID / maxIndices) + 1,
|
1570
|
+
theModuleItem->lastItem->bsaveID % maxIndices);
|
1571
|
+
|
1572
|
+
fprintf(theFile,"}");
|
1573
|
+
}
|
1574
|
+
|
1575
|
+
#else /* CONSTRUCT_COMPILER && (! RUN_TIME) */
|
1576
|
+
|
1577
|
+
void ConstructsToCCommand(Environment *,UDFContext *,UDFValue *);
|
1578
|
+
|
1579
|
+
/************************************/
|
1580
|
+
/* ConstructsToCCommand: Definition */
|
1581
|
+
/* for rule compiler stub. */
|
1582
|
+
/************************************/
|
1583
|
+
void ConstructsToCCommand(
|
1584
|
+
Environment *theEnv,
|
1585
|
+
UDFContext *context,
|
1586
|
+
UDFValue *returnValue)
|
1587
|
+
{
|
1588
|
+
#if MAC_XCD
|
1589
|
+
#pragma unused(theEnv)
|
1590
|
+
#endif
|
1591
|
+
}
|
1592
|
+
|
1593
|
+
#endif /* CONSTRUCT_COMPILER && (! RUN_TIME) */
|