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,1305 @@
|
|
1
|
+
/*******************************************************/
|
2
|
+
/* "C" Language Integrated Production System */
|
3
|
+
/* */
|
4
|
+
/* CLIPS Version 6.41 07/29/21 */
|
5
|
+
/* */
|
6
|
+
/* FACT RETE FUNCTION GENERATION MODULE */
|
7
|
+
/*******************************************************/
|
8
|
+
|
9
|
+
/*************************************************************/
|
10
|
+
/* Purpose: Creates expressions used by the fact pattern */
|
11
|
+
/* matcher and the join network. The expressions created */
|
12
|
+
/* are used to extract and compare values from facts as */
|
13
|
+
/* needed by the Rete pattern matching algorithm. These */
|
14
|
+
/* expressions are also used to extract values from facts */
|
15
|
+
/* needed by expressions on the RHS of a rule. */
|
16
|
+
/* */
|
17
|
+
/* Principal Programmer(s): */
|
18
|
+
/* Gary D. Riley */
|
19
|
+
/* */
|
20
|
+
/* Contributing Programmer(s): */
|
21
|
+
/* */
|
22
|
+
/* Revision History: */
|
23
|
+
/* */
|
24
|
+
/* 6.30: Support for performance optimizations. */
|
25
|
+
/* */
|
26
|
+
/* Increased maximum values for pattern/slot */
|
27
|
+
/* indices. */
|
28
|
+
/* */
|
29
|
+
/* 6.32: Join network fix for variable comparisons */
|
30
|
+
/* where both variables are from the right */
|
31
|
+
/* memory. */
|
32
|
+
/* */
|
33
|
+
/* 6.40: Pragma once and other inclusion changes. */
|
34
|
+
/* */
|
35
|
+
/* Added support for booleans with <stdbool.h>. */
|
36
|
+
/* */
|
37
|
+
/* Removed use of void pointers for specific */
|
38
|
+
/* data structures. */
|
39
|
+
/* */
|
40
|
+
/*************************************************************/
|
41
|
+
|
42
|
+
#include "setup.h"
|
43
|
+
|
44
|
+
#if DEFTEMPLATE_CONSTRUCT && DEFRULE_CONSTRUCT
|
45
|
+
|
46
|
+
#include <stdio.h>
|
47
|
+
|
48
|
+
#include "constant.h"
|
49
|
+
#include "constrct.h"
|
50
|
+
#include "envrnmnt.h"
|
51
|
+
#include "exprnpsr.h"
|
52
|
+
#include "factmch.h"
|
53
|
+
#include "factmngr.h"
|
54
|
+
#include "factprt.h"
|
55
|
+
#include "factrete.h"
|
56
|
+
#include "memalloc.h"
|
57
|
+
#include "network.h"
|
58
|
+
#include "pattern.h"
|
59
|
+
#include "prcdrpsr.h"
|
60
|
+
#include "reteutil.h"
|
61
|
+
#include "router.h"
|
62
|
+
#include "scanner.h"
|
63
|
+
#include "sysdep.h"
|
64
|
+
#include "tmpltdef.h"
|
65
|
+
#include "tmpltfun.h"
|
66
|
+
#include "tmpltlhs.h"
|
67
|
+
#include "tmpltutl.h"
|
68
|
+
|
69
|
+
#include "factgen.h"
|
70
|
+
|
71
|
+
#define FACTGEN_DATA 2
|
72
|
+
|
73
|
+
struct factgenData
|
74
|
+
{
|
75
|
+
struct entityRecord FactJNGV1Info;
|
76
|
+
struct entityRecord FactJNGV2Info;
|
77
|
+
struct entityRecord FactJNGV3Info;
|
78
|
+
struct entityRecord FactPNGV1Info;
|
79
|
+
struct entityRecord FactPNGV2Info;
|
80
|
+
struct entityRecord FactPNGV3Info;
|
81
|
+
struct entityRecord FactJNCV1Info;
|
82
|
+
struct entityRecord FactJNCV2Info;
|
83
|
+
struct entityRecord FactPNCV1Info;
|
84
|
+
struct entityRecord FactStoreMFInfo;
|
85
|
+
struct entityRecord FactSlotLengthInfo;
|
86
|
+
struct entityRecord FactPNConstant1Info;
|
87
|
+
struct entityRecord FactPNConstant2Info;
|
88
|
+
};
|
89
|
+
|
90
|
+
#define FactgenData(theEnv) ((struct factgenData *) GetEnvironmentData(theEnv,FACTGEN_DATA))
|
91
|
+
|
92
|
+
/***************************************/
|
93
|
+
/* LOCAL INTERNAL FUNCTION DEFINITIONS */
|
94
|
+
/***************************************/
|
95
|
+
|
96
|
+
#if (! RUN_TIME) && (! BLOAD_ONLY)
|
97
|
+
static void *FactGetVarJN1(Environment *,struct lhsParseNode *,int);
|
98
|
+
static void *FactGetVarJN2(Environment *,struct lhsParseNode *,int);
|
99
|
+
static void *FactGetVarJN3(Environment *,struct lhsParseNode *,int);
|
100
|
+
static void *FactGetVarPN1(Environment *,struct lhsParseNode *);
|
101
|
+
static void *FactGetVarPN2(Environment *,struct lhsParseNode *);
|
102
|
+
static void *FactGetVarPN3(Environment *,struct lhsParseNode *);
|
103
|
+
#endif
|
104
|
+
|
105
|
+
/*******************************************************************/
|
106
|
+
/* InitializeFactReteFunctions: Installs the fact pattern matching */
|
107
|
+
/* and value access routines as primitive operations. */
|
108
|
+
/*******************************************************************/
|
109
|
+
void InitializeFactReteFunctions(
|
110
|
+
Environment *theEnv)
|
111
|
+
{
|
112
|
+
#if DEFRULE_CONSTRUCT
|
113
|
+
struct entityRecord factJNGV1Info = { "FACT_JN_VAR1", FACT_JN_VAR1,0,1,0,
|
114
|
+
PrintFactJNGetVar1,
|
115
|
+
PrintFactJNGetVar1,NULL,
|
116
|
+
FactJNGetVar1,
|
117
|
+
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL };
|
118
|
+
|
119
|
+
struct entityRecord factJNGV2Info = { "FACT_JN_VAR2", FACT_JN_VAR2,0,1,0,
|
120
|
+
PrintFactJNGetVar2,
|
121
|
+
PrintFactJNGetVar2,NULL,
|
122
|
+
FactJNGetVar2,
|
123
|
+
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL };
|
124
|
+
|
125
|
+
struct entityRecord factJNGV3Info = { "FACT_JN_VAR3", FACT_JN_VAR3,0,1,0,
|
126
|
+
PrintFactJNGetVar3,
|
127
|
+
PrintFactJNGetVar3,NULL,
|
128
|
+
FactJNGetVar3,
|
129
|
+
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL };
|
130
|
+
|
131
|
+
struct entityRecord factPNGV1Info = { "FACT_PN_VAR1", FACT_PN_VAR1,0,1,0,
|
132
|
+
PrintFactPNGetVar1,
|
133
|
+
PrintFactPNGetVar1,NULL,
|
134
|
+
FactPNGetVar1,
|
135
|
+
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL };
|
136
|
+
|
137
|
+
struct entityRecord factPNGV2Info = { "FACT_PN_VAR2", FACT_PN_VAR2,0,1,0,
|
138
|
+
PrintFactPNGetVar2,
|
139
|
+
PrintFactPNGetVar2,NULL,
|
140
|
+
FactPNGetVar2,
|
141
|
+
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL };
|
142
|
+
|
143
|
+
struct entityRecord factPNGV3Info = { "FACT_PN_VAR3", FACT_PN_VAR3,0,1,0,
|
144
|
+
PrintFactPNGetVar3,
|
145
|
+
PrintFactPNGetVar3,NULL,
|
146
|
+
FactPNGetVar3,
|
147
|
+
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL };
|
148
|
+
|
149
|
+
struct entityRecord factJNCV1Info = { "FACT_JN_CMP1", FACT_JN_CMP1,0,1,1,
|
150
|
+
PrintFactJNCompVars1,
|
151
|
+
PrintFactJNCompVars1,NULL,
|
152
|
+
FactJNCompVars1,
|
153
|
+
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL };
|
154
|
+
|
155
|
+
struct entityRecord factJNCV2Info = { "FACT_JN_CMP2", FACT_JN_CMP2,0,1,1,
|
156
|
+
PrintFactJNCompVars2,
|
157
|
+
PrintFactJNCompVars2,NULL,
|
158
|
+
FactJNCompVars2,
|
159
|
+
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL };
|
160
|
+
|
161
|
+
struct entityRecord factPNCV1Info = { "FACT_PN_CMP1", FACT_PN_CMP1,0,1,1,
|
162
|
+
PrintFactPNCompVars1,
|
163
|
+
PrintFactPNCompVars1,NULL,
|
164
|
+
FactPNCompVars1,
|
165
|
+
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL };
|
166
|
+
|
167
|
+
struct entityRecord factStoreMFInfo = { "FACT_STORE_MULTIFIELD",
|
168
|
+
FACT_STORE_MULTIFIELD,0,1,0,
|
169
|
+
NULL,NULL,NULL,
|
170
|
+
FactStoreMultifield,
|
171
|
+
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL };
|
172
|
+
|
173
|
+
struct entityRecord factSlotLengthInfo = { "FACT_SLOT_LENGTH",
|
174
|
+
FACT_SLOT_LENGTH,0,1,0,
|
175
|
+
PrintFactSlotLength,
|
176
|
+
PrintFactSlotLength,NULL,
|
177
|
+
FactSlotLength,
|
178
|
+
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL };
|
179
|
+
|
180
|
+
struct entityRecord factPNConstant1Info = { "FACT_PN_CONSTANT1",
|
181
|
+
FACT_PN_CONSTANT1,0,1,1,
|
182
|
+
PrintFactPNConstant1,
|
183
|
+
PrintFactPNConstant1,NULL,
|
184
|
+
FactPNConstant1,
|
185
|
+
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL };
|
186
|
+
|
187
|
+
struct entityRecord factPNConstant2Info = { "FACT_PN_CONSTANT2",
|
188
|
+
FACT_PN_CONSTANT2,0,1,1,
|
189
|
+
PrintFactPNConstant2,
|
190
|
+
PrintFactPNConstant2,NULL,
|
191
|
+
FactPNConstant2,
|
192
|
+
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL };
|
193
|
+
|
194
|
+
AllocateEnvironmentData(theEnv,FACTGEN_DATA,sizeof(struct factgenData),NULL);
|
195
|
+
|
196
|
+
memcpy(&FactgenData(theEnv)->FactJNGV1Info,&factJNGV1Info,sizeof(struct entityRecord));
|
197
|
+
memcpy(&FactgenData(theEnv)->FactJNGV2Info,&factJNGV2Info,sizeof(struct entityRecord));
|
198
|
+
memcpy(&FactgenData(theEnv)->FactJNGV3Info,&factJNGV3Info,sizeof(struct entityRecord));
|
199
|
+
memcpy(&FactgenData(theEnv)->FactPNGV1Info,&factPNGV1Info,sizeof(struct entityRecord));
|
200
|
+
memcpy(&FactgenData(theEnv)->FactPNGV2Info,&factPNGV2Info,sizeof(struct entityRecord));
|
201
|
+
memcpy(&FactgenData(theEnv)->FactPNGV3Info,&factPNGV3Info,sizeof(struct entityRecord));
|
202
|
+
memcpy(&FactgenData(theEnv)->FactJNCV1Info,&factJNCV1Info,sizeof(struct entityRecord));
|
203
|
+
memcpy(&FactgenData(theEnv)->FactJNCV2Info,&factJNCV2Info,sizeof(struct entityRecord));
|
204
|
+
memcpy(&FactgenData(theEnv)->FactPNCV1Info,&factPNCV1Info,sizeof(struct entityRecord));
|
205
|
+
memcpy(&FactgenData(theEnv)->FactStoreMFInfo,&factStoreMFInfo,sizeof(struct entityRecord));
|
206
|
+
memcpy(&FactgenData(theEnv)->FactSlotLengthInfo,&factSlotLengthInfo,sizeof(struct entityRecord));
|
207
|
+
memcpy(&FactgenData(theEnv)->FactPNConstant1Info,&factPNConstant1Info,sizeof(struct entityRecord));
|
208
|
+
memcpy(&FactgenData(theEnv)->FactPNConstant2Info,&factPNConstant2Info,sizeof(struct entityRecord));
|
209
|
+
|
210
|
+
InstallPrimitive(theEnv,(EntityRecord *) &FactData(theEnv)->FactInfo,FACT_ADDRESS_TYPE);
|
211
|
+
InstallPrimitive(theEnv,&FactgenData(theEnv)->FactJNGV1Info,FACT_JN_VAR1);
|
212
|
+
InstallPrimitive(theEnv,&FactgenData(theEnv)->FactJNGV2Info,FACT_JN_VAR2);
|
213
|
+
InstallPrimitive(theEnv,&FactgenData(theEnv)->FactJNGV3Info,FACT_JN_VAR3);
|
214
|
+
InstallPrimitive(theEnv,&FactgenData(theEnv)->FactPNGV1Info,FACT_PN_VAR1);
|
215
|
+
InstallPrimitive(theEnv,&FactgenData(theEnv)->FactPNGV2Info,FACT_PN_VAR2);
|
216
|
+
InstallPrimitive(theEnv,&FactgenData(theEnv)->FactPNGV3Info,FACT_PN_VAR3);
|
217
|
+
InstallPrimitive(theEnv,&FactgenData(theEnv)->FactJNCV1Info,FACT_JN_CMP1);
|
218
|
+
InstallPrimitive(theEnv,&FactgenData(theEnv)->FactJNCV2Info,FACT_JN_CMP2);
|
219
|
+
InstallPrimitive(theEnv,&FactgenData(theEnv)->FactPNCV1Info,FACT_PN_CMP1);
|
220
|
+
InstallPrimitive(theEnv,&FactgenData(theEnv)->FactStoreMFInfo,FACT_STORE_MULTIFIELD);
|
221
|
+
InstallPrimitive(theEnv,&FactgenData(theEnv)->FactSlotLengthInfo,FACT_SLOT_LENGTH);
|
222
|
+
InstallPrimitive(theEnv,&FactgenData(theEnv)->FactPNConstant1Info,FACT_PN_CONSTANT1);
|
223
|
+
InstallPrimitive(theEnv,&FactgenData(theEnv)->FactPNConstant2Info,FACT_PN_CONSTANT2);
|
224
|
+
#endif
|
225
|
+
}
|
226
|
+
|
227
|
+
#if (! RUN_TIME) && (! BLOAD_ONLY)
|
228
|
+
|
229
|
+
/******************************************************************/
|
230
|
+
/* FactGenPNConstant: Generates an expression for use in the fact */
|
231
|
+
/* pattern network that compares a field from a single field or */
|
232
|
+
/* multifield slot against a constant. */
|
233
|
+
/******************************************************************/
|
234
|
+
struct expr *FactGenPNConstant(
|
235
|
+
Environment *theEnv,
|
236
|
+
struct lhsParseNode *theField)
|
237
|
+
{
|
238
|
+
struct expr *top;
|
239
|
+
ParseNodeType tempValue;
|
240
|
+
struct factConstantPN1Call hack1;
|
241
|
+
struct factConstantPN2Call hack2;
|
242
|
+
|
243
|
+
/*=================================================================*/
|
244
|
+
/* If the value of a single field slot (or relation name) is being */
|
245
|
+
/* compared against a constant, then use specialized routines for */
|
246
|
+
/* doing the comparison. */
|
247
|
+
/*=================================================================*/
|
248
|
+
|
249
|
+
if (theField->withinMultifieldSlot == false)
|
250
|
+
{
|
251
|
+
ClearBitString(&hack1,sizeof(struct factConstantPN1Call));
|
252
|
+
|
253
|
+
if (theField->negated) hack1.testForEquality = false;
|
254
|
+
else hack1.testForEquality = true;
|
255
|
+
|
256
|
+
hack1.whichSlot = (theField->slotNumber - 1);
|
257
|
+
|
258
|
+
top = GenConstant(theEnv,FACT_PN_CONSTANT1,AddBitMap(theEnv,&hack1,sizeof(struct factConstantPN1Call)));
|
259
|
+
|
260
|
+
top->argList = GenConstant(theEnv,NodeTypeToType(theField),theField->value);
|
261
|
+
|
262
|
+
return(top);
|
263
|
+
}
|
264
|
+
|
265
|
+
/*=================================================================*/
|
266
|
+
/* If a constant comparison is being done within a multifield slot */
|
267
|
+
/* and the constant's position has no multifields to the left, */
|
268
|
+
/* then use the same routine used for the single field slot case, */
|
269
|
+
/* but include the offset from the beginning of the slot. */
|
270
|
+
/*=================================================================*/
|
271
|
+
|
272
|
+
else if ((theField->multiFieldsBefore == 0) ||
|
273
|
+
((theField->multiFieldsBefore == 1) && (theField->multiFieldsAfter == 0)))
|
274
|
+
{
|
275
|
+
ClearBitString(&hack2,sizeof(struct factConstantPN2Call));
|
276
|
+
|
277
|
+
if (theField->negated) hack2.testForEquality = false;
|
278
|
+
else hack2.testForEquality = true;
|
279
|
+
|
280
|
+
hack2.whichSlot = (theField->slotNumber - 1);
|
281
|
+
|
282
|
+
if (theField->multiFieldsBefore == 0)
|
283
|
+
{
|
284
|
+
hack2.fromBeginning = true;
|
285
|
+
hack2.offset = theField->singleFieldsBefore;
|
286
|
+
}
|
287
|
+
else
|
288
|
+
{
|
289
|
+
hack2.fromBeginning = false;
|
290
|
+
hack2.offset = theField->singleFieldsAfter;
|
291
|
+
}
|
292
|
+
|
293
|
+
top = GenConstant(theEnv,FACT_PN_CONSTANT2,AddBitMap(theEnv,&hack2,sizeof(struct factConstantPN2Call)));
|
294
|
+
|
295
|
+
top->argList = GenConstant(theEnv,NodeTypeToType(theField),theField->value);
|
296
|
+
|
297
|
+
return(top);
|
298
|
+
}
|
299
|
+
|
300
|
+
/*===============================================================*/
|
301
|
+
/* Otherwise, use the equality or inequality function to compare */
|
302
|
+
/* the constant against the value returned by the appropriate */
|
303
|
+
/* pattern network variable retrieval function call. */
|
304
|
+
/*===============================================================*/
|
305
|
+
|
306
|
+
else
|
307
|
+
{
|
308
|
+
if (theField->negated)
|
309
|
+
{ top = GenConstant(theEnv,FCALL,ExpressionData(theEnv)->PTR_NEQ); }
|
310
|
+
else
|
311
|
+
{ top = GenConstant(theEnv,FCALL,ExpressionData(theEnv)->PTR_EQ); }
|
312
|
+
|
313
|
+
tempValue = theField->pnType;
|
314
|
+
theField->pnType = SF_VARIABLE_NODE;
|
315
|
+
top->argList = FactGenGetfield(theEnv,theField);
|
316
|
+
theField->pnType = tempValue;
|
317
|
+
|
318
|
+
top->argList->nextArg = GenConstant(theEnv,NodeTypeToType(theField),theField->value);
|
319
|
+
}
|
320
|
+
|
321
|
+
/*===============================================================*/
|
322
|
+
/* Return the expression for performing the constant comparison. */
|
323
|
+
/*===============================================================*/
|
324
|
+
|
325
|
+
return(top);
|
326
|
+
}
|
327
|
+
|
328
|
+
/*******************************************************/
|
329
|
+
/* FactGenGetfield: Generates an expression for use in */
|
330
|
+
/* the fact pattern network that retrieves a value */
|
331
|
+
/* from a single or multifield slot. */
|
332
|
+
/*******************************************************/
|
333
|
+
struct expr *FactGenGetfield(
|
334
|
+
Environment *theEnv,
|
335
|
+
struct lhsParseNode *theNode)
|
336
|
+
{
|
337
|
+
/*===================================================*/
|
338
|
+
/* Generate call to retrieve single field slot value */
|
339
|
+
/* or the fact relation name. */
|
340
|
+
/*===================================================*/
|
341
|
+
|
342
|
+
if ((theNode->slotNumber > 0) && (theNode->slotNumber != UNSPECIFIED_SLOT) && (theNode->withinMultifieldSlot == false))
|
343
|
+
{ return(GenConstant(theEnv,FACT_PN_VAR2,FactGetVarPN2(theEnv,theNode))); }
|
344
|
+
|
345
|
+
/*=====================================================*/
|
346
|
+
/* Generate call to retrieve a value from a multifield */
|
347
|
+
/* slot that contains at most one multifield variable */
|
348
|
+
/* or contains no multifield variables before the */
|
349
|
+
/* value to be retrieved. */
|
350
|
+
/*=====================================================*/
|
351
|
+
|
352
|
+
if (((theNode->pnType == SF_WILDCARD_NODE) || (theNode->pnType == SF_VARIABLE_NODE) || ConstantNode(theNode)) &&
|
353
|
+
((theNode->multiFieldsBefore == 0) ||
|
354
|
+
((theNode->multiFieldsBefore == 1) && (theNode->multiFieldsAfter == 0))))
|
355
|
+
{ return(GenConstant(theEnv,FACT_PN_VAR3,FactGetVarPN3(theEnv,theNode))); }
|
356
|
+
|
357
|
+
if (((theNode->pnType == MF_WILDCARD_NODE) || (theNode->pnType == MF_VARIABLE_NODE)) &&
|
358
|
+
(theNode->multiFieldsBefore == 0) && (theNode->multiFieldsAfter == 0))
|
359
|
+
{ return(GenConstant(theEnv,FACT_PN_VAR3,FactGetVarPN3(theEnv,theNode))); }
|
360
|
+
|
361
|
+
/*=========================================*/
|
362
|
+
/* Generate call to retrieve a value using */
|
363
|
+
/* the most general retrieval function. */
|
364
|
+
/*=========================================*/
|
365
|
+
|
366
|
+
return(GenConstant(theEnv,FACT_PN_VAR1,FactGetVarPN1(theEnv,theNode)));
|
367
|
+
}
|
368
|
+
|
369
|
+
/**************************************************/
|
370
|
+
/* FactGenGetvar: Generates an expression for use */
|
371
|
+
/* in the join network that retrieves a value */
|
372
|
+
/* from a single or multifield slot of a fact. */
|
373
|
+
/**************************************************/
|
374
|
+
struct expr *FactGenGetvar(
|
375
|
+
Environment *theEnv,
|
376
|
+
struct lhsParseNode *theNode,
|
377
|
+
int side)
|
378
|
+
{
|
379
|
+
/*====================================================*/
|
380
|
+
/* Generate call to retrieve single field slot value. */
|
381
|
+
/*====================================================*/
|
382
|
+
|
383
|
+
if ((theNode->slotNumber > 0) && (theNode->slotNumber != UNSPECIFIED_SLOT) && (theNode->withinMultifieldSlot == false))
|
384
|
+
{ return(GenConstant(theEnv,FACT_JN_VAR2,FactGetVarJN2(theEnv,theNode,side))); }
|
385
|
+
|
386
|
+
/*=====================================================*/
|
387
|
+
/* Generate call to retrieve a value from a multifield */
|
388
|
+
/* slot that contains at most one multifield variable */
|
389
|
+
/* or contains no multifield variables before the */
|
390
|
+
/* value to be retrieved. */
|
391
|
+
/*=====================================================*/
|
392
|
+
|
393
|
+
if (((theNode->pnType == SF_WILDCARD_NODE) || (theNode->pnType == SF_VARIABLE_NODE)) &&
|
394
|
+
((theNode->multiFieldsBefore == 0) ||
|
395
|
+
((theNode->multiFieldsBefore == 1) && (theNode->multiFieldsAfter == 0))))
|
396
|
+
{ return(GenConstant(theEnv,FACT_JN_VAR3,FactGetVarJN3(theEnv,theNode,side))); }
|
397
|
+
|
398
|
+
if (((theNode->pnType == MF_WILDCARD_NODE) || (theNode->pnType == MF_VARIABLE_NODE)) &&
|
399
|
+
(theNode->multiFieldsBefore == 0) &&
|
400
|
+
(theNode->multiFieldsAfter == 0))
|
401
|
+
{ return(GenConstant(theEnv,FACT_JN_VAR3,FactGetVarJN3(theEnv,theNode,side))); }
|
402
|
+
|
403
|
+
/*=========================================*/
|
404
|
+
/* Generate call to retrieve a value using */
|
405
|
+
/* the most general retrieval function. */
|
406
|
+
/*=========================================*/
|
407
|
+
|
408
|
+
return(GenConstant(theEnv,FACT_JN_VAR1,FactGetVarJN1(theEnv,theNode,side)));
|
409
|
+
}
|
410
|
+
|
411
|
+
/**************************************************************/
|
412
|
+
/* FactGenCheckLength: Generates an expression for use in the */
|
413
|
+
/* fact pattern network that determines if the value of a */
|
414
|
+
/* multifield slot contains enough fields to satisfy the */
|
415
|
+
/* number of pattern matching constaints. For example, the */
|
416
|
+
/* slot constraints (foo ?x a $? ?y) couldn't be matched */
|
417
|
+
/* unless the foo slot contained at least 3 fields. */
|
418
|
+
/**************************************************************/
|
419
|
+
struct expr *FactGenCheckLength(
|
420
|
+
Environment *theEnv,
|
421
|
+
struct lhsParseNode *theNode)
|
422
|
+
{
|
423
|
+
struct factCheckLengthPNCall hack;
|
424
|
+
|
425
|
+
/*===================================================*/
|
426
|
+
/* If the slot contains no single field constraints, */
|
427
|
+
/* then a length test is not necessary. */
|
428
|
+
/*===================================================*/
|
429
|
+
|
430
|
+
if ((theNode->singleFieldsAfter == 0) &&
|
431
|
+
(theNode->pnType != SF_VARIABLE_NODE) &&
|
432
|
+
(theNode->pnType != SF_WILDCARD_NODE))
|
433
|
+
{ return NULL; }
|
434
|
+
|
435
|
+
/*=======================================*/
|
436
|
+
/* Initialize the length test arguments. */
|
437
|
+
/*=======================================*/
|
438
|
+
|
439
|
+
ClearBitString(&hack,sizeof(struct factCheckLengthPNCall));
|
440
|
+
hack.whichSlot = (theNode->slotNumber - 1);
|
441
|
+
|
442
|
+
/*============================================*/
|
443
|
+
/* If the slot has no multifield constraints, */
|
444
|
+
/* then the length must match exactly. */
|
445
|
+
/*============================================*/
|
446
|
+
|
447
|
+
if ((theNode->pnType != MF_VARIABLE_NODE) &&
|
448
|
+
(theNode->pnType != MF_WILDCARD_NODE) &&
|
449
|
+
(theNode->multiFieldsAfter == 0))
|
450
|
+
{ hack.exactly = 1; }
|
451
|
+
else
|
452
|
+
{ hack.exactly = 0; }
|
453
|
+
|
454
|
+
/*============================================*/
|
455
|
+
/* The minimum length is the number of single */
|
456
|
+
/* field constraints contained in the slot. */
|
457
|
+
/*============================================*/
|
458
|
+
|
459
|
+
if ((theNode->pnType == SF_VARIABLE_NODE) || (theNode->pnType == SF_WILDCARD_NODE))
|
460
|
+
{ hack.minLength = 1 + theNode->singleFieldsAfter; }
|
461
|
+
else
|
462
|
+
{ hack.minLength = theNode->singleFieldsAfter; }
|
463
|
+
|
464
|
+
/*========================================================*/
|
465
|
+
/* Generate call to test the length of a multifield slot. */
|
466
|
+
/*========================================================*/
|
467
|
+
|
468
|
+
return(GenConstant(theEnv,FACT_SLOT_LENGTH,AddBitMap(theEnv,&hack,sizeof(struct factCheckLengthPNCall))));
|
469
|
+
}
|
470
|
+
|
471
|
+
/**************************************************************/
|
472
|
+
/* FactGenCheckZeroLength: Generates an expression for use in */
|
473
|
+
/* the fact pattern network that determines if the value of */
|
474
|
+
/* a multifield slot is a zero length multifield value. */
|
475
|
+
/**************************************************************/
|
476
|
+
struct expr *FactGenCheckZeroLength(
|
477
|
+
Environment *theEnv,
|
478
|
+
unsigned short theSlot)
|
479
|
+
{
|
480
|
+
struct factCheckLengthPNCall hack;
|
481
|
+
|
482
|
+
ClearBitString(&hack,sizeof(struct factCheckLengthPNCall));
|
483
|
+
|
484
|
+
hack.whichSlot = theSlot - 1;
|
485
|
+
hack.exactly = true;
|
486
|
+
hack.minLength = 0;
|
487
|
+
|
488
|
+
return(GenConstant(theEnv,FACT_SLOT_LENGTH,AddBitMap(theEnv,&hack,sizeof(struct factCheckLengthPNCall))));
|
489
|
+
}
|
490
|
+
|
491
|
+
/*********************************************************************/
|
492
|
+
/* FactReplaceGetvar: Replaces a variable reference in an expression */
|
493
|
+
/* with a function call to retrieve the variable using the join */
|
494
|
+
/* network variable access functions for facts. */
|
495
|
+
/*********************************************************************/
|
496
|
+
void FactReplaceGetvar(
|
497
|
+
Environment *theEnv,
|
498
|
+
struct expr *theItem,
|
499
|
+
struct lhsParseNode *theNode,
|
500
|
+
int side)
|
501
|
+
{
|
502
|
+
/*====================================================*/
|
503
|
+
/* Generate call to retrieve single field slot value. */
|
504
|
+
/*====================================================*/
|
505
|
+
|
506
|
+
if ((theNode->slotNumber > 0) &&
|
507
|
+
(theNode->slotNumber != UNSPECIFIED_SLOT) &&
|
508
|
+
(theNode->withinMultifieldSlot == false))
|
509
|
+
{
|
510
|
+
theItem->type = FACT_JN_VAR2;
|
511
|
+
theItem->value = FactGetVarJN2(theEnv,theNode,side);
|
512
|
+
return;
|
513
|
+
}
|
514
|
+
|
515
|
+
/*=====================================================*/
|
516
|
+
/* Generate call to retrieve a value from a multifield */
|
517
|
+
/* slot that contains at most one multifield variable */
|
518
|
+
/* or contains no multifield variables before the */
|
519
|
+
/* value to be retrieved. */
|
520
|
+
/*=====================================================*/
|
521
|
+
|
522
|
+
if (((theNode->pnType == SF_WILDCARD_NODE) || (theNode->pnType == SF_VARIABLE_NODE)) &&
|
523
|
+
((theNode->multiFieldsBefore == 0) ||
|
524
|
+
((theNode->multiFieldsBefore == 1) && (theNode->multiFieldsAfter == 0))))
|
525
|
+
{
|
526
|
+
theItem->type = FACT_JN_VAR3;
|
527
|
+
theItem->value = FactGetVarJN3(theEnv,theNode,side);
|
528
|
+
return;
|
529
|
+
}
|
530
|
+
|
531
|
+
if (((theNode->pnType == MF_WILDCARD_NODE) || (theNode->pnType == MF_VARIABLE_NODE)) &&
|
532
|
+
(theNode->multiFieldsBefore == 0) &&
|
533
|
+
(theNode->multiFieldsAfter == 0))
|
534
|
+
{
|
535
|
+
theItem->type = FACT_JN_VAR3;
|
536
|
+
theItem->value = FactGetVarJN3(theEnv,theNode,side);
|
537
|
+
return;
|
538
|
+
}
|
539
|
+
|
540
|
+
/*=========================================*/
|
541
|
+
/* Generate call to retrieve a value using */
|
542
|
+
/* the most general retrieval function. */
|
543
|
+
/*=========================================*/
|
544
|
+
|
545
|
+
theItem->type = FACT_JN_VAR1;
|
546
|
+
theItem->value = FactGetVarJN1(theEnv,theNode,side);
|
547
|
+
}
|
548
|
+
|
549
|
+
/***********************************************************************/
|
550
|
+
/* FactReplaceGetfield: Replaces a variable reference in an expression */
|
551
|
+
/* with a function call to retrieve the variable using the pattern */
|
552
|
+
/* network variable access functions for facts. */
|
553
|
+
/***********************************************************************/
|
554
|
+
void FactReplaceGetfield(
|
555
|
+
Environment *theEnv,
|
556
|
+
struct expr *theItem,
|
557
|
+
struct lhsParseNode *theNode)
|
558
|
+
{
|
559
|
+
/*====================================================*/
|
560
|
+
/* Generate call to retrieve single field slot value. */
|
561
|
+
/*====================================================*/
|
562
|
+
|
563
|
+
if (theNode->withinMultifieldSlot == false)
|
564
|
+
{
|
565
|
+
theItem->type = FACT_PN_VAR2;
|
566
|
+
theItem->value = FactGetVarPN2(theEnv,theNode);
|
567
|
+
return;
|
568
|
+
}
|
569
|
+
|
570
|
+
/*=====================================================*/
|
571
|
+
/* Generate call to retrieve a value from a multifield */
|
572
|
+
/* slot that contains at most one multifield variable */
|
573
|
+
/* or contains no multifield variables before the */
|
574
|
+
/* value to be retrieved. */
|
575
|
+
/*=====================================================*/
|
576
|
+
|
577
|
+
if (((theNode->pnType == SF_WILDCARD_NODE) || (theNode->pnType == SF_VARIABLE_NODE)) &&
|
578
|
+
((theNode->multiFieldsBefore == 0) ||
|
579
|
+
((theNode->multiFieldsBefore == 1) && (theNode->multiFieldsAfter == 0))))
|
580
|
+
{
|
581
|
+
theItem->type = FACT_PN_VAR3;
|
582
|
+
theItem->value = FactGetVarPN3(theEnv,theNode);
|
583
|
+
return;
|
584
|
+
}
|
585
|
+
|
586
|
+
if (((theNode->pnType == MF_WILDCARD_NODE) || (theNode->pnType == MF_VARIABLE_NODE)) &&
|
587
|
+
(theNode->multiFieldsBefore == 0) &&
|
588
|
+
(theNode->multiFieldsAfter == 0))
|
589
|
+
{
|
590
|
+
theItem->type = FACT_PN_VAR3;
|
591
|
+
theItem->value = FactGetVarPN3(theEnv,theNode);
|
592
|
+
return;
|
593
|
+
}
|
594
|
+
|
595
|
+
/*=========================================*/
|
596
|
+
/* Generate call to retrieve a value using */
|
597
|
+
/* the most general retrieval function. */
|
598
|
+
/*=========================================*/
|
599
|
+
|
600
|
+
theItem->type = FACT_PN_VAR1;
|
601
|
+
theItem->value = FactGetVarPN1(theEnv,theNode);
|
602
|
+
}
|
603
|
+
|
604
|
+
/*************************************************************/
|
605
|
+
/* FactGetVarJN1: Creates the arguments for the most general */
|
606
|
+
/* routine for retrieving a variable's value from the slot */
|
607
|
+
/* of a fact. The retrieval relies on information stored */
|
608
|
+
/* in a partial match, so this retrieval mechanism is used */
|
609
|
+
/* by expressions in the join network or from the RHS of a */
|
610
|
+
/* rule. */
|
611
|
+
/*************************************************************/
|
612
|
+
static void *FactGetVarJN1(
|
613
|
+
Environment *theEnv,
|
614
|
+
struct lhsParseNode *theNode,
|
615
|
+
int side)
|
616
|
+
{
|
617
|
+
struct factGetVarJN1Call hack;
|
618
|
+
|
619
|
+
/*===================================================*/
|
620
|
+
/* Clear the bitmap for storing the argument values. */
|
621
|
+
/*===================================================*/
|
622
|
+
|
623
|
+
ClearBitString(&hack,sizeof(struct factGetVarJN1Call));
|
624
|
+
|
625
|
+
/*=========================================*/
|
626
|
+
/* Store the position in the partial match */
|
627
|
+
/* from which the fact will be retrieved. */
|
628
|
+
/*=========================================*/
|
629
|
+
|
630
|
+
if (side == LHS)
|
631
|
+
{
|
632
|
+
hack.lhs = 1;
|
633
|
+
hack.whichPattern = theNode->joinDepth;
|
634
|
+
}
|
635
|
+
else if (side == RHS)
|
636
|
+
{
|
637
|
+
hack.rhs = 1;
|
638
|
+
hack.whichPattern = 0;
|
639
|
+
}
|
640
|
+
else if (side == NESTED_RHS)
|
641
|
+
{
|
642
|
+
hack.rhs = 1;
|
643
|
+
hack.whichPattern = theNode->joinDepth;
|
644
|
+
}
|
645
|
+
else
|
646
|
+
{ hack.whichPattern = theNode->joinDepth; }
|
647
|
+
|
648
|
+
/*========================================*/
|
649
|
+
/* A slot value of zero indicates that we */
|
650
|
+
/* want the pattern address returned. */
|
651
|
+
/*========================================*/
|
652
|
+
|
653
|
+
if ((theNode->slotNumber == 0) || (theNode->slotNumber == UNSPECIFIED_SLOT))
|
654
|
+
{
|
655
|
+
hack.factAddress = 1;
|
656
|
+
hack.allFields = 0;
|
657
|
+
hack.whichSlot = 0;
|
658
|
+
hack.whichField = 0;
|
659
|
+
}
|
660
|
+
|
661
|
+
/*=====================================================*/
|
662
|
+
/* A slot value greater than zero and a field value of */
|
663
|
+
/* zero indicate that we want the entire contents of */
|
664
|
+
/* the slot whether it is a single field or multifield */
|
665
|
+
/* slot. */
|
666
|
+
/*=====================================================*/
|
667
|
+
|
668
|
+
else if (theNode->index <= 0)
|
669
|
+
{
|
670
|
+
hack.factAddress = 0;
|
671
|
+
hack.allFields = 1;
|
672
|
+
hack.whichSlot = theNode->slotNumber - 1;
|
673
|
+
hack.whichField = 0;
|
674
|
+
}
|
675
|
+
|
676
|
+
/*=====================================================*/
|
677
|
+
/* A slot value, m, and a field value, n, both greater */
|
678
|
+
/* than zero indicate that we want the nth field of */
|
679
|
+
/* the mth slot. */
|
680
|
+
/*=====================================================*/
|
681
|
+
|
682
|
+
else
|
683
|
+
{
|
684
|
+
hack.factAddress = 0;
|
685
|
+
hack.allFields = 0;
|
686
|
+
hack.whichSlot = theNode->slotNumber - 1;
|
687
|
+
hack.whichField = theNode->index - 1;
|
688
|
+
}
|
689
|
+
|
690
|
+
/*=============================*/
|
691
|
+
/* Return the argument bitmap. */
|
692
|
+
/*=============================*/
|
693
|
+
|
694
|
+
return(AddBitMap(theEnv,&hack,sizeof(struct factGetVarJN1Call)));
|
695
|
+
}
|
696
|
+
|
697
|
+
/**************************************************************/
|
698
|
+
/* FactGetVarJN2: Creates the arguments for the routine which */
|
699
|
+
/* retrieves a variable's value from a single field slot of */
|
700
|
+
/* a fact. The retrieval relies on information stored in a */
|
701
|
+
/* partial match, so this retrieval mechanism is used by */
|
702
|
+
/* expressions in the join network or from the RHS of a */
|
703
|
+
/* rule. */
|
704
|
+
/**************************************************************/
|
705
|
+
static void *FactGetVarJN2(
|
706
|
+
Environment *theEnv,
|
707
|
+
struct lhsParseNode *theNode,
|
708
|
+
int side)
|
709
|
+
{
|
710
|
+
struct factGetVarJN2Call hack;
|
711
|
+
|
712
|
+
/*===================================================*/
|
713
|
+
/* Clear the bitmap for storing the argument values. */
|
714
|
+
/*===================================================*/
|
715
|
+
|
716
|
+
ClearBitString(&hack,sizeof(struct factGetVarJN2Call));
|
717
|
+
|
718
|
+
/*=====================================================*/
|
719
|
+
/* Store the position in the partial match from which */
|
720
|
+
/* the fact will be retrieved and the slot in the fact */
|
721
|
+
/* from which the value will be retrieved. */
|
722
|
+
/*=====================================================*/
|
723
|
+
|
724
|
+
hack.whichSlot = theNode->slotNumber - 1;
|
725
|
+
|
726
|
+
if (side == LHS)
|
727
|
+
{
|
728
|
+
hack.lhs = 1;
|
729
|
+
hack.whichPattern = theNode->joinDepth;
|
730
|
+
}
|
731
|
+
else if (side == RHS)
|
732
|
+
{
|
733
|
+
hack.rhs = 1;
|
734
|
+
hack.whichPattern = 0;
|
735
|
+
}
|
736
|
+
else if (side == NESTED_RHS)
|
737
|
+
{
|
738
|
+
hack.rhs = 1;
|
739
|
+
hack.whichPattern = theNode->joinDepth;
|
740
|
+
}
|
741
|
+
else
|
742
|
+
{ hack.whichPattern = theNode->joinDepth; }
|
743
|
+
|
744
|
+
/*=============================*/
|
745
|
+
/* Return the argument bitmap. */
|
746
|
+
/*=============================*/
|
747
|
+
|
748
|
+
return AddBitMap(theEnv,&hack,sizeof(struct factGetVarJN2Call));
|
749
|
+
}
|
750
|
+
|
751
|
+
/*************************************************************/
|
752
|
+
/* FactGetVarJN3: Creates the arguments for the routine for */
|
753
|
+
/* retrieving a variable's value from a multifield slot of */
|
754
|
+
/* a fact. For this routine, the variable's value must be */
|
755
|
+
/* from a multifield slot that contains at most one */
|
756
|
+
/* multifield variable or contains no multifield variables */
|
757
|
+
/* before the variable's value to be retrieved. The */
|
758
|
+
/* retrieval relies on information stored in a partial */
|
759
|
+
/* match, so this retrieval mechanism is used by */
|
760
|
+
/* expressions in the join network or from the RHS of a */
|
761
|
+
/* rule. */
|
762
|
+
/*************************************************************/
|
763
|
+
static void *FactGetVarJN3(
|
764
|
+
Environment *theEnv,
|
765
|
+
struct lhsParseNode *theNode,
|
766
|
+
int side)
|
767
|
+
{
|
768
|
+
struct factGetVarJN3Call hack;
|
769
|
+
|
770
|
+
/*===================================================*/
|
771
|
+
/* Clear the bitmap for storing the argument values. */
|
772
|
+
/*===================================================*/
|
773
|
+
|
774
|
+
ClearBitString(&hack,sizeof(struct factGetVarJN3Call));
|
775
|
+
|
776
|
+
/*=====================================================*/
|
777
|
+
/* Store the position in the partial match from which */
|
778
|
+
/* the fact will be retrieved and the slot in the fact */
|
779
|
+
/* from which the value will be retrieved. */
|
780
|
+
/*=====================================================*/
|
781
|
+
|
782
|
+
hack.whichSlot = theNode->slotNumber - 1;
|
783
|
+
|
784
|
+
if (side == LHS)
|
785
|
+
{
|
786
|
+
hack.lhs = 1;
|
787
|
+
hack.whichPattern = theNode->joinDepth;
|
788
|
+
}
|
789
|
+
else if (side == RHS)
|
790
|
+
{
|
791
|
+
hack.rhs = 1;
|
792
|
+
hack.whichPattern = 0;
|
793
|
+
}
|
794
|
+
else if (side == NESTED_RHS)
|
795
|
+
{
|
796
|
+
hack.rhs = 1;
|
797
|
+
hack.whichPattern = theNode->joinDepth;
|
798
|
+
}
|
799
|
+
else
|
800
|
+
{ hack.whichPattern = theNode->joinDepth; }
|
801
|
+
|
802
|
+
/*==============================================================*/
|
803
|
+
/* If a single field variable value is being retrieved, then... */
|
804
|
+
/*==============================================================*/
|
805
|
+
|
806
|
+
if ((theNode->pnType == SF_WILDCARD_NODE) || (theNode->pnType == SF_VARIABLE_NODE))
|
807
|
+
{
|
808
|
+
/*=========================================================*/
|
809
|
+
/* If no multifield values occur before the variable, then */
|
810
|
+
/* the variable's value can be retrieved based on its */
|
811
|
+
/* offset from the beginning of the slot's value */
|
812
|
+
/* regardless of the number of multifield variables or */
|
813
|
+
/* wildcards following the variable being retrieved. */
|
814
|
+
/*=========================================================*/
|
815
|
+
|
816
|
+
if (theNode->multiFieldsBefore == 0)
|
817
|
+
{
|
818
|
+
hack.fromBeginning = 1;
|
819
|
+
hack.fromEnd = 0;
|
820
|
+
hack.beginOffset = theNode->singleFieldsBefore;
|
821
|
+
hack.endOffset = 0;
|
822
|
+
}
|
823
|
+
|
824
|
+
/*===============================================*/
|
825
|
+
/* Otherwise the variable is retrieved based its */
|
826
|
+
/* position relative to the end of the slot. */
|
827
|
+
/*===============================================*/
|
828
|
+
|
829
|
+
else
|
830
|
+
{
|
831
|
+
hack.fromBeginning = 0;
|
832
|
+
hack.fromEnd = 1;
|
833
|
+
hack.beginOffset = 0;
|
834
|
+
hack.endOffset = theNode->singleFieldsAfter;
|
835
|
+
}
|
836
|
+
|
837
|
+
/*=============================*/
|
838
|
+
/* Return the argument bitmap. */
|
839
|
+
/*=============================*/
|
840
|
+
|
841
|
+
return(AddBitMap(theEnv,&hack,sizeof(struct factGetVarJN3Call)));
|
842
|
+
}
|
843
|
+
|
844
|
+
/*============================================================*/
|
845
|
+
/* A multifield variable value is being retrieved. This means */
|
846
|
+
/* that there are no other multifield variables or wildcards */
|
847
|
+
/* in the slot. The multifield value is retrieved by storing */
|
848
|
+
/* the number of single field values which come before and */
|
849
|
+
/* after the multifield value. The multifield value can then */
|
850
|
+
/* be retrieved based on the length of the value in the slot */
|
851
|
+
/* and the number of single field values which must occur */
|
852
|
+
/* before and after the multifield value. */
|
853
|
+
/*============================================================*/
|
854
|
+
|
855
|
+
hack.fromBeginning = 1;
|
856
|
+
hack.fromEnd = 1;
|
857
|
+
hack.beginOffset = theNode->singleFieldsBefore;
|
858
|
+
hack.endOffset = theNode->singleFieldsAfter;
|
859
|
+
|
860
|
+
/*=============================*/
|
861
|
+
/* Return the argument bitmap. */
|
862
|
+
/*=============================*/
|
863
|
+
|
864
|
+
return AddBitMap(theEnv,&hack,sizeof(struct factGetVarJN3Call));
|
865
|
+
}
|
866
|
+
|
867
|
+
/**************************************************************/
|
868
|
+
/* FactGetVarPN1: Creates the arguments for the most general */
|
869
|
+
/* routine for retrieving a variable's value from the slot */
|
870
|
+
/* of a fact. The retrieval relies on information stored */
|
871
|
+
/* during fact pattern matching, so this retrieval */
|
872
|
+
/* mechanism is only used by expressions in the pattern */
|
873
|
+
/* network. */
|
874
|
+
/**************************************************************/
|
875
|
+
static void *FactGetVarPN1(
|
876
|
+
Environment *theEnv,
|
877
|
+
struct lhsParseNode *theNode)
|
878
|
+
{
|
879
|
+
struct factGetVarPN1Call hack;
|
880
|
+
|
881
|
+
/*===================================================*/
|
882
|
+
/* Clear the bitmap for storing the argument values. */
|
883
|
+
/*===================================================*/
|
884
|
+
|
885
|
+
ClearBitString(&hack,sizeof(struct factGetVarPN1Call));
|
886
|
+
|
887
|
+
/*========================================*/
|
888
|
+
/* A slot value of zero indicates that we */
|
889
|
+
/* want the pattern address returned. */
|
890
|
+
/*========================================*/
|
891
|
+
|
892
|
+
if ((theNode->slotNumber == 0) ||
|
893
|
+
(theNode->slotNumber == UNSPECIFIED_SLOT))
|
894
|
+
{
|
895
|
+
hack.factAddress = 1;
|
896
|
+
hack.allFields = 0;
|
897
|
+
hack.whichSlot = 0;
|
898
|
+
hack.whichField = 0;
|
899
|
+
}
|
900
|
+
|
901
|
+
/*=====================================================*/
|
902
|
+
/* A slot value greater than zero and a field value of */
|
903
|
+
/* zero indicate that we want the entire contents of */
|
904
|
+
/* the slot whether it is a single field or multifield */
|
905
|
+
/* slot. */
|
906
|
+
/*=====================================================*/
|
907
|
+
|
908
|
+
else if (theNode->index <= 0)
|
909
|
+
{
|
910
|
+
hack.factAddress = 0;
|
911
|
+
hack.allFields = 1;
|
912
|
+
hack.whichSlot = theNode->slotNumber - 1;
|
913
|
+
hack.whichField = 0;
|
914
|
+
}
|
915
|
+
|
916
|
+
/*=============================================*/
|
917
|
+
/* A slot value, m, and a field value, n, both */
|
918
|
+
/* greater than zero indicate that we want the */
|
919
|
+
/* nth field of the mth slot. */
|
920
|
+
/*=============================================*/
|
921
|
+
|
922
|
+
else
|
923
|
+
{
|
924
|
+
hack.factAddress = 0;
|
925
|
+
hack.allFields = 0;
|
926
|
+
hack.whichSlot = theNode->slotNumber - 1;
|
927
|
+
hack.whichField = theNode->index - 1;
|
928
|
+
}
|
929
|
+
|
930
|
+
/*=============================*/
|
931
|
+
/* Return the argument bitmap. */
|
932
|
+
/*=============================*/
|
933
|
+
|
934
|
+
return AddBitMap(theEnv,&hack,sizeof(struct factGetVarPN1Call));
|
935
|
+
}
|
936
|
+
|
937
|
+
/***************************************************************/
|
938
|
+
/* FactGetVarPN2: Creates the arguments for the routine which */
|
939
|
+
/* retrieves a variable's value from a single field slot of */
|
940
|
+
/* a fact. The retrieval relies on information stored during */
|
941
|
+
/* fact pattern matching, so this retrieval mechanism is */
|
942
|
+
/* only used by expressions in the pattern network. */
|
943
|
+
/***************************************************************/
|
944
|
+
static void *FactGetVarPN2(
|
945
|
+
Environment *theEnv,
|
946
|
+
struct lhsParseNode *theNode)
|
947
|
+
{
|
948
|
+
struct factGetVarPN2Call hack;
|
949
|
+
|
950
|
+
/*===================================================*/
|
951
|
+
/* Clear the bitmap for storing the argument values. */
|
952
|
+
/*===================================================*/
|
953
|
+
|
954
|
+
ClearBitString(&hack,sizeof(struct factGetVarPN2Call));
|
955
|
+
|
956
|
+
/*=======================================*/
|
957
|
+
/* Store the slot in the fact from which */
|
958
|
+
/* the value will be retrieved. */
|
959
|
+
/*=======================================*/
|
960
|
+
|
961
|
+
hack.whichSlot = theNode->slotNumber - 1;
|
962
|
+
|
963
|
+
/*=============================*/
|
964
|
+
/* Return the argument bitmap. */
|
965
|
+
/*=============================*/
|
966
|
+
|
967
|
+
return AddBitMap(theEnv,&hack,sizeof(struct factGetVarPN2Call));
|
968
|
+
}
|
969
|
+
|
970
|
+
/*************************************************************/
|
971
|
+
/* FactGetVarPN3: Creates the arguments for the routine for */
|
972
|
+
/* retrieving a variable's value from a multifield slot of */
|
973
|
+
/* a fact. For this routine, the variable's value must be */
|
974
|
+
/* from a multifield slot that contains at most one */
|
975
|
+
/* multifield variable or contains no multifield variables */
|
976
|
+
/* before the variable's value to be retrieved. The */
|
977
|
+
/* retrieval relies on information stored during fact */
|
978
|
+
/* pattern matching, so this retrieval mechanism is only */
|
979
|
+
/* used by expressions in the pattern network. */
|
980
|
+
/*************************************************************/
|
981
|
+
static void *FactGetVarPN3(
|
982
|
+
Environment *theEnv,
|
983
|
+
struct lhsParseNode *theNode)
|
984
|
+
{
|
985
|
+
struct factGetVarPN3Call hack;
|
986
|
+
|
987
|
+
/*===================================================*/
|
988
|
+
/* Clear the bitmap for storing the argument values. */
|
989
|
+
/*===================================================*/
|
990
|
+
|
991
|
+
ClearBitString(&hack,sizeof(struct factGetVarPN3Call));
|
992
|
+
|
993
|
+
/*=======================================*/
|
994
|
+
/* Store the slot in the fact from which */
|
995
|
+
/* the value will be retrieved. */
|
996
|
+
/*=======================================*/
|
997
|
+
|
998
|
+
hack.whichSlot = theNode->slotNumber - 1;
|
999
|
+
|
1000
|
+
/*==============================================================*/
|
1001
|
+
/* If a single field variable value is being retrieved, then... */
|
1002
|
+
/*==============================================================*/
|
1003
|
+
|
1004
|
+
if ((theNode->pnType == SF_WILDCARD_NODE) || (theNode->pnType == SF_VARIABLE_NODE) || ConstantNode(theNode))
|
1005
|
+
{
|
1006
|
+
/*=========================================================*/
|
1007
|
+
/* If no multifield values occur before the variable, then */
|
1008
|
+
/* the variable's value can be retrieved based on its */
|
1009
|
+
/* offset from the beginning of the slot's value */
|
1010
|
+
/* regardless of the number of multifield variables or */
|
1011
|
+
/* wildcards following the variable being retrieved. */
|
1012
|
+
/*=========================================================*/
|
1013
|
+
|
1014
|
+
if (theNode->multiFieldsBefore == 0)
|
1015
|
+
{
|
1016
|
+
hack.fromBeginning = 1;
|
1017
|
+
hack.fromEnd = 0;
|
1018
|
+
hack.beginOffset = theNode->singleFieldsBefore;
|
1019
|
+
hack.endOffset = 0;
|
1020
|
+
}
|
1021
|
+
|
1022
|
+
/*===============================================*/
|
1023
|
+
/* Otherwise the variable is retrieved based its */
|
1024
|
+
/* position relative to the end of the slot. */
|
1025
|
+
/*===============================================*/
|
1026
|
+
|
1027
|
+
else
|
1028
|
+
{
|
1029
|
+
hack.fromBeginning = 0;
|
1030
|
+
hack.fromEnd = 1;
|
1031
|
+
hack.beginOffset = 0;
|
1032
|
+
hack.endOffset = theNode->singleFieldsAfter;
|
1033
|
+
}
|
1034
|
+
|
1035
|
+
return(AddBitMap(theEnv,&hack,sizeof(struct factGetVarPN3Call)));
|
1036
|
+
}
|
1037
|
+
|
1038
|
+
/*============================================================*/
|
1039
|
+
/* A multifield variable value is being retrieved. This means */
|
1040
|
+
/* that there are no other multifield variables or wildcards */
|
1041
|
+
/* in the slot. The multifield value is retrieved by storing */
|
1042
|
+
/* the number of single field values which come before and */
|
1043
|
+
/* after the multifield value. The multifield value can then */
|
1044
|
+
/* be retrieved based on the length of the value in the slot */
|
1045
|
+
/* and the number of single field values which must occur */
|
1046
|
+
/* before and after the multifield value. */
|
1047
|
+
/*============================================================*/
|
1048
|
+
|
1049
|
+
hack.fromBeginning = 1;
|
1050
|
+
hack.fromEnd = 1;
|
1051
|
+
hack.beginOffset = theNode->singleFieldsBefore;
|
1052
|
+
hack.endOffset = theNode->singleFieldsAfter;
|
1053
|
+
|
1054
|
+
/*=============================*/
|
1055
|
+
/* Return the argument bitmap. */
|
1056
|
+
/*=============================*/
|
1057
|
+
|
1058
|
+
return AddBitMap(theEnv,&hack,sizeof(struct factGetVarPN3Call));
|
1059
|
+
}
|
1060
|
+
|
1061
|
+
/*************************************************************/
|
1062
|
+
/* FactPNVariableComparison: Generates an expression for use */
|
1063
|
+
/* in the fact pattern network to compare two variables of */
|
1064
|
+
/* the same name found in the same pattern. */
|
1065
|
+
/*************************************************************/
|
1066
|
+
struct expr *FactPNVariableComparison(
|
1067
|
+
Environment *theEnv,
|
1068
|
+
struct lhsParseNode *selfNode,
|
1069
|
+
struct lhsParseNode *referringNode)
|
1070
|
+
{
|
1071
|
+
struct expr *top;
|
1072
|
+
struct factCompVarsPN1Call hack;
|
1073
|
+
|
1074
|
+
/*===================================================*/
|
1075
|
+
/* Clear the bitmap for storing the argument values. */
|
1076
|
+
/*===================================================*/
|
1077
|
+
|
1078
|
+
ClearBitString(&hack,sizeof(struct factCompVarsPN1Call));
|
1079
|
+
|
1080
|
+
/*================================================================*/
|
1081
|
+
/* If two single field slots of a deftemplate are being compared, */
|
1082
|
+
/* then use the following specified variable comparison routine. */
|
1083
|
+
/*================================================================*/
|
1084
|
+
|
1085
|
+
if ((selfNode->withinMultifieldSlot == false) &&
|
1086
|
+
(selfNode->slotNumber > 0) &&
|
1087
|
+
(selfNode->slotNumber != UNSPECIFIED_SLOT) &&
|
1088
|
+
(referringNode->withinMultifieldSlot == false) &&
|
1089
|
+
(referringNode->slotNumber > 0) &&
|
1090
|
+
(referringNode->slotNumber != UNSPECIFIED_SLOT))
|
1091
|
+
{
|
1092
|
+
hack.pass = 0;
|
1093
|
+
hack.fail = 0;
|
1094
|
+
hack.field1 = selfNode->slotNumber - 1;
|
1095
|
+
hack.field2 = referringNode->slotNumber - 1;
|
1096
|
+
|
1097
|
+
if (selfNode->negated) hack.fail = 1;
|
1098
|
+
else hack.pass = 1;
|
1099
|
+
|
1100
|
+
top = GenConstant(theEnv,FACT_PN_CMP1,AddBitMap(theEnv,&hack,sizeof(struct factCompVarsPN1Call)));
|
1101
|
+
}
|
1102
|
+
|
1103
|
+
/*================================================================*/
|
1104
|
+
/* Otherwise, use the eq function to compare the values retrieved */
|
1105
|
+
/* by the appropriate get variable value functions. */
|
1106
|
+
/*================================================================*/
|
1107
|
+
|
1108
|
+
else
|
1109
|
+
{
|
1110
|
+
if (selfNode->negated) top = GenConstant(theEnv,FCALL,ExpressionData(theEnv)->PTR_NEQ);
|
1111
|
+
else top = GenConstant(theEnv,FCALL,ExpressionData(theEnv)->PTR_EQ);
|
1112
|
+
|
1113
|
+
top->argList = FactGenGetfield(theEnv,selfNode);
|
1114
|
+
top->argList->nextArg = FactGenGetfield(theEnv,referringNode);
|
1115
|
+
}
|
1116
|
+
|
1117
|
+
/*======================================*/
|
1118
|
+
/* Return the expression for performing */
|
1119
|
+
/* the variable comparison. */
|
1120
|
+
/*======================================*/
|
1121
|
+
|
1122
|
+
return top;
|
1123
|
+
}
|
1124
|
+
|
1125
|
+
/*********************************************************/
|
1126
|
+
/* FactJNVariableComparison: Generates an expression for */
|
1127
|
+
/* use in the join network to compare two variables of */
|
1128
|
+
/* the same name found in different patterns. */
|
1129
|
+
/*********************************************************/
|
1130
|
+
struct expr *FactJNVariableComparison(
|
1131
|
+
Environment *theEnv,
|
1132
|
+
struct lhsParseNode *selfNode,
|
1133
|
+
struct lhsParseNode *referringNode,
|
1134
|
+
bool nandJoin)
|
1135
|
+
{
|
1136
|
+
struct expr *top;
|
1137
|
+
struct factCompVarsJN1Call hack1;
|
1138
|
+
struct factCompVarsJN2Call hack2;
|
1139
|
+
struct lhsParseNode *firstNode;
|
1140
|
+
|
1141
|
+
/*================================================================*/
|
1142
|
+
/* If two single field slots of a deftemplate are being compared, */
|
1143
|
+
/* then use the following specified variable comparison routine. */
|
1144
|
+
/*================================================================*/
|
1145
|
+
|
1146
|
+
if ((selfNode->withinMultifieldSlot == false) &&
|
1147
|
+
(selfNode->slotNumber > 0) &&
|
1148
|
+
(selfNode->slotNumber != UNSPECIFIED_SLOT) &&
|
1149
|
+
(referringNode->withinMultifieldSlot == false) &&
|
1150
|
+
(referringNode->slotNumber > 0) &&
|
1151
|
+
(referringNode->slotNumber != UNSPECIFIED_SLOT))
|
1152
|
+
{
|
1153
|
+
ClearBitString(&hack1,sizeof(struct factCompVarsJN1Call));
|
1154
|
+
hack1.pass = 0;
|
1155
|
+
hack1.fail = 0;
|
1156
|
+
|
1157
|
+
if (nandJoin)
|
1158
|
+
{ firstNode = referringNode; }
|
1159
|
+
else
|
1160
|
+
{ firstNode = selfNode; }
|
1161
|
+
|
1162
|
+
hack1.slot1 = firstNode->slotNumber - 1;
|
1163
|
+
|
1164
|
+
hack1.p1rhs = true;
|
1165
|
+
if (nandJoin)
|
1166
|
+
{ hack1.pattern1 = referringNode->joinDepth; }
|
1167
|
+
else
|
1168
|
+
{ hack1.pattern1 = 0; }
|
1169
|
+
|
1170
|
+
if ((! nandJoin) && (selfNode->joinDepth == referringNode->joinDepth))
|
1171
|
+
{
|
1172
|
+
hack1.p2rhs = true;
|
1173
|
+
hack1.pattern2 = 0;
|
1174
|
+
}
|
1175
|
+
else
|
1176
|
+
{
|
1177
|
+
hack1.p2lhs = true;
|
1178
|
+
hack1.pattern2 = referringNode->joinDepth;
|
1179
|
+
}
|
1180
|
+
|
1181
|
+
if (referringNode->index == NO_INDEX) hack1.slot2 = 0;
|
1182
|
+
else hack1.slot2 = referringNode->slotNumber - 1;
|
1183
|
+
|
1184
|
+
if (selfNode->negated) hack1.fail = 1;
|
1185
|
+
else hack1.pass = 1;
|
1186
|
+
|
1187
|
+
top = GenConstant(theEnv,FACT_JN_CMP1,AddBitMap(theEnv,&hack1,sizeof(struct factCompVarsJN1Call)));
|
1188
|
+
}
|
1189
|
+
|
1190
|
+
/*===============================================================*/
|
1191
|
+
/* If two single field values are compared and either or both of */
|
1192
|
+
/* them are contained in multifield slots (and the value can be */
|
1193
|
+
/* accessed relative to either the beginning or end of the slot */
|
1194
|
+
/* with no intervening multifield variables), then use the */
|
1195
|
+
/* following specified variable comparison routine. */
|
1196
|
+
/*===============================================================*/
|
1197
|
+
|
1198
|
+
else if ((selfNode->slotNumber > 0) &&
|
1199
|
+
(selfNode->slotNumber != UNSPECIFIED_SLOT) &&
|
1200
|
+
(selfNode->pnType == SF_VARIABLE_NODE) &&
|
1201
|
+
((selfNode->multiFieldsBefore == 0) ||
|
1202
|
+
((selfNode->multiFieldsBefore == 1) &&
|
1203
|
+
(selfNode->multiFieldsAfter == 0))) &&
|
1204
|
+
(referringNode->slotNumber > 0) &&
|
1205
|
+
(referringNode->slotNumber != UNSPECIFIED_SLOT) &&
|
1206
|
+
(referringNode->pnType == SF_VARIABLE_NODE) &&
|
1207
|
+
((referringNode->multiFieldsBefore == 0) ||
|
1208
|
+
(referringNode->multiFieldsAfter == 0)))
|
1209
|
+
{
|
1210
|
+
ClearBitString(&hack2,sizeof(struct factCompVarsJN2Call));
|
1211
|
+
hack2.pass = 0;
|
1212
|
+
hack2.fail = 0;
|
1213
|
+
|
1214
|
+
if (nandJoin)
|
1215
|
+
{ firstNode = referringNode; }
|
1216
|
+
else
|
1217
|
+
{ firstNode = selfNode; }
|
1218
|
+
|
1219
|
+
hack2.slot1 = firstNode->slotNumber - 1;
|
1220
|
+
|
1221
|
+
if (nandJoin)
|
1222
|
+
{ hack2.pattern1 = referringNode->joinDepth; }
|
1223
|
+
else
|
1224
|
+
{ hack2.pattern1 = 0; }
|
1225
|
+
|
1226
|
+
hack2.p1rhs = true;
|
1227
|
+
|
1228
|
+
if ((! nandJoin) && (selfNode->joinDepth == referringNode->joinDepth))
|
1229
|
+
{
|
1230
|
+
hack2.p2rhs = true;
|
1231
|
+
hack2.pattern2 = 0;
|
1232
|
+
}
|
1233
|
+
else
|
1234
|
+
{
|
1235
|
+
hack2.p2lhs = true;
|
1236
|
+
hack2.pattern2 = referringNode->joinDepth;
|
1237
|
+
}
|
1238
|
+
|
1239
|
+
hack2.slot2 = referringNode->slotNumber - 1;
|
1240
|
+
|
1241
|
+
if (firstNode->multiFieldsBefore == 0)
|
1242
|
+
{
|
1243
|
+
hack2.fromBeginning1 = 1;
|
1244
|
+
hack2.offset1 = firstNode->singleFieldsBefore;
|
1245
|
+
}
|
1246
|
+
else
|
1247
|
+
{
|
1248
|
+
hack2.fromBeginning1 = 0;
|
1249
|
+
hack2.offset1 = firstNode->singleFieldsAfter;
|
1250
|
+
}
|
1251
|
+
|
1252
|
+
if (referringNode->multiFieldsBefore == 0)
|
1253
|
+
{
|
1254
|
+
hack2.fromBeginning2 = 1;
|
1255
|
+
hack2.offset2 = referringNode->singleFieldsBefore;
|
1256
|
+
}
|
1257
|
+
else
|
1258
|
+
{
|
1259
|
+
hack2.fromBeginning2 = 0;
|
1260
|
+
hack2.offset2 = referringNode->singleFieldsAfter;
|
1261
|
+
}
|
1262
|
+
|
1263
|
+
if (selfNode->negated) hack2.fail = 1;
|
1264
|
+
else hack2.pass = 1;
|
1265
|
+
|
1266
|
+
top = GenConstant(theEnv,FACT_JN_CMP2,AddBitMap(theEnv,&hack2,sizeof(struct factCompVarsJN2Call)));
|
1267
|
+
}
|
1268
|
+
|
1269
|
+
/*===============================================================*/
|
1270
|
+
/* Otherwise, use the equality or inequality function to compare */
|
1271
|
+
/* the values returned by the appropriate join network variable */
|
1272
|
+
/* retrieval function call. */
|
1273
|
+
/*===============================================================*/
|
1274
|
+
|
1275
|
+
else
|
1276
|
+
{
|
1277
|
+
if (selfNode->negated)
|
1278
|
+
{ top = GenConstant(theEnv,FCALL,ExpressionData(theEnv)->PTR_NEQ); }
|
1279
|
+
else
|
1280
|
+
{ top = GenConstant(theEnv,FCALL,ExpressionData(theEnv)->PTR_EQ); }
|
1281
|
+
|
1282
|
+
if (nandJoin)
|
1283
|
+
{ top->argList = FactGenGetvar(theEnv,selfNode,NESTED_RHS); }
|
1284
|
+
else
|
1285
|
+
{ top->argList = FactGenGetvar(theEnv,selfNode,RHS); }
|
1286
|
+
|
1287
|
+
if ((! nandJoin) && (selfNode->joinDepth == referringNode->joinDepth))
|
1288
|
+
{ top->argList->nextArg = FactGenGetvar(theEnv,referringNode,RHS); }
|
1289
|
+
else
|
1290
|
+
{ top->argList->nextArg = FactGenGetvar(theEnv,referringNode,LHS); }
|
1291
|
+
}
|
1292
|
+
|
1293
|
+
/*======================================*/
|
1294
|
+
/* Return the expression for performing */
|
1295
|
+
/* the variable comparison. */
|
1296
|
+
/*======================================*/
|
1297
|
+
|
1298
|
+
return(top);
|
1299
|
+
}
|
1300
|
+
|
1301
|
+
#endif /* (! RUN_TIME) && (! BLOAD_ONLY) */
|
1302
|
+
|
1303
|
+
#endif /* DEFTEMPLATE_CONSTRUCT && DEFRULE_CONSTRUCT */
|
1304
|
+
|
1305
|
+
|