00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #define _FACTGEN_SOURCE_
00027
00028 #include "setup.h"
00029
00030 #if DEFTEMPLATE_CONSTRUCT && DEFRULE_CONSTRUCT
00031
00032 #include <stdio.h>
00033 #define _STDIO_INCLUDED_
00034
00035 #include "constant.h"
00036 #include "memalloc.h"
00037 #include "router.h"
00038 #include "scanner.h"
00039 #include "exprnpsr.h"
00040 #include "constrct.h"
00041 #include "network.h"
00042 #include "reteutil.h"
00043 #include "factmch.h"
00044 #include "factrete.h"
00045 #include "factmngr.h"
00046 #include "pattern.h"
00047 #include "factprt.h"
00048 #include "envrnmnt.h"
00049
00050 #include "tmpltdef.h"
00051 #include "tmpltlhs.h"
00052
00053 #include "factgen.h"
00054
00055 #define FACTGEN_DATA 2
00056
00057 struct factgenData
00058 {
00059 globle struct entityRecord FactJNGV1Info;
00060 globle struct entityRecord FactJNGV2Info;
00061 globle struct entityRecord FactJNGV3Info;
00062 globle struct entityRecord FactPNGV1Info;
00063 globle struct entityRecord FactPNGV2Info;
00064 globle struct entityRecord FactPNGV3Info;
00065 globle struct entityRecord FactJNCV1Info;
00066 globle struct entityRecord FactJNCV2Info;
00067 globle struct entityRecord FactPNCV1Info;
00068 globle struct entityRecord FactStoreMFInfo;
00069 globle struct entityRecord FactSlotLengthInfo;
00070 globle struct entityRecord FactPNConstant1Info;
00071 globle struct entityRecord FactPNConstant2Info;
00072 };
00073
00074 #define FactgenData(theEnv) ((struct factgenData *) GetEnvironmentData(theEnv,FACTGEN_DATA))
00075
00076
00077
00078
00079
00080 #if (! RUN_TIME) && (! BLOAD_ONLY)
00081 static void *FactGetVarJN1(void *,struct lhsParseNode *,int);
00082 static void *FactGetVarJN2(void *,struct lhsParseNode *,int);
00083 static void *FactGetVarJN3(void *,struct lhsParseNode *,int);
00084 static void *FactGetVarPN1(void *,struct lhsParseNode *);
00085 static void *FactGetVarPN2(void *,struct lhsParseNode *);
00086 static void *FactGetVarPN3(void *,struct lhsParseNode *);
00087 #endif
00088
00089
00090
00091
00092
00093 globle void InitializeFactReteFunctions(
00094 void *theEnv)
00095 {
00096 #if DEFRULE_CONSTRUCT
00097 struct entityRecord factJNGV1Info = { "FACT_JN_VAR1", FACT_JN_VAR1,0,1,0,
00098 PrintFactJNGetVar1,
00099 PrintFactJNGetVar1,NULL,
00100 FactJNGetVar1,
00101 NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL };
00102
00103 struct entityRecord factJNGV2Info = { "FACT_JN_VAR2", FACT_JN_VAR2,0,1,0,
00104 PrintFactJNGetVar2,
00105 PrintFactJNGetVar2,NULL,
00106 FactJNGetVar2,
00107 NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL };
00108
00109 struct entityRecord factJNGV3Info = { "FACT_JN_VAR3", FACT_JN_VAR3,0,1,0,
00110 PrintFactJNGetVar3,
00111 PrintFactJNGetVar3,NULL,
00112 FactJNGetVar3,
00113 NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL };
00114
00115 struct entityRecord factPNGV1Info = { "FACT_PN_VAR1", FACT_PN_VAR1,0,1,0,
00116 PrintFactPNGetVar1,
00117 PrintFactPNGetVar1,NULL,
00118 FactPNGetVar1,
00119 NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL };
00120
00121 struct entityRecord factPNGV2Info = { "FACT_PN_VAR2", FACT_PN_VAR2,0,1,0,
00122 PrintFactPNGetVar2,
00123 PrintFactPNGetVar2,NULL,
00124 FactPNGetVar2,
00125 NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL };
00126
00127 struct entityRecord factPNGV3Info = { "FACT_PN_VAR3", FACT_PN_VAR3,0,1,0,
00128 PrintFactPNGetVar3,
00129 PrintFactPNGetVar3,NULL,
00130 FactPNGetVar3,
00131 NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL };
00132
00133 struct entityRecord factJNCV1Info = { "FACT_JN_CMP1", FACT_JN_CMP1,0,1,1,
00134 PrintFactJNCompVars1,
00135 PrintFactJNCompVars1,NULL,
00136 FactJNCompVars1,
00137 NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL };
00138
00139 struct entityRecord factJNCV2Info = { "FACT_JN_CMP2", FACT_JN_CMP2,0,1,1,
00140 PrintFactJNCompVars2,
00141 PrintFactJNCompVars2,NULL,
00142 FactJNCompVars2,
00143 NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL };
00144
00145 struct entityRecord factPNCV1Info = { "FACT_PN_CMP1", FACT_PN_CMP1,0,1,1,
00146 PrintFactPNCompVars1,
00147 PrintFactPNCompVars1,NULL,
00148 FactPNCompVars1,
00149 NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL };
00150
00151 struct entityRecord factStoreMFInfo = { "FACT_STORE_MULTIFIELD",
00152 FACT_STORE_MULTIFIELD,0,1,0,
00153 NULL,NULL,NULL,
00154 FactStoreMultifield,
00155 NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL };
00156
00157 struct entityRecord factSlotLengthInfo = { "FACT_SLOT_LENGTH",
00158 FACT_SLOT_LENGTH,0,1,0,
00159 PrintFactSlotLength,
00160 PrintFactSlotLength,NULL,
00161 FactSlotLength,
00162 NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL };
00163
00164 struct entityRecord factPNConstant1Info = { "FACT_PN_CONSTANT1",
00165 FACT_PN_CONSTANT1,0,1,1,
00166 PrintFactPNConstant1,
00167 PrintFactPNConstant1,NULL,
00168 FactPNConstant1,
00169 NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL };
00170
00171 struct entityRecord factPNConstant2Info = { "FACT_PN_CONSTANT2",
00172 FACT_PN_CONSTANT2,0,1,1,
00173 PrintFactPNConstant2,
00174 PrintFactPNConstant2,NULL,
00175 FactPNConstant2,
00176 NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL };
00177
00178 AllocateEnvironmentData(theEnv,FACTGEN_DATA,sizeof(struct factgenData),NULL);
00179
00180 memcpy(&FactgenData(theEnv)->FactJNGV1Info,&factJNGV1Info,sizeof(struct entityRecord));
00181 memcpy(&FactgenData(theEnv)->FactJNGV2Info,&factJNGV2Info,sizeof(struct entityRecord));
00182 memcpy(&FactgenData(theEnv)->FactJNGV3Info,&factJNGV3Info,sizeof(struct entityRecord));
00183 memcpy(&FactgenData(theEnv)->FactPNGV1Info,&factPNGV1Info,sizeof(struct entityRecord));
00184 memcpy(&FactgenData(theEnv)->FactPNGV2Info,&factPNGV2Info,sizeof(struct entityRecord));
00185 memcpy(&FactgenData(theEnv)->FactPNGV3Info,&factPNGV3Info,sizeof(struct entityRecord));
00186 memcpy(&FactgenData(theEnv)->FactJNCV1Info,&factJNCV1Info,sizeof(struct entityRecord));
00187 memcpy(&FactgenData(theEnv)->FactJNCV2Info,&factJNCV2Info,sizeof(struct entityRecord));
00188 memcpy(&FactgenData(theEnv)->FactPNCV1Info,&factPNCV1Info,sizeof(struct entityRecord));
00189 memcpy(&FactgenData(theEnv)->FactStoreMFInfo,&factStoreMFInfo,sizeof(struct entityRecord));
00190 memcpy(&FactgenData(theEnv)->FactSlotLengthInfo,&factSlotLengthInfo,sizeof(struct entityRecord));
00191 memcpy(&FactgenData(theEnv)->FactPNConstant1Info,&factPNConstant1Info,sizeof(struct entityRecord));
00192 memcpy(&FactgenData(theEnv)->FactPNConstant2Info,&factPNConstant2Info,sizeof(struct entityRecord));
00193
00194 InstallPrimitive(theEnv,(ENTITY_RECORD_PTR) &FactData(theEnv)->FactInfo,FACT_ADDRESS);
00195 InstallPrimitive(theEnv,&FactgenData(theEnv)->FactJNGV1Info,FACT_JN_VAR1);
00196 InstallPrimitive(theEnv,&FactgenData(theEnv)->FactJNGV2Info,FACT_JN_VAR2);
00197 InstallPrimitive(theEnv,&FactgenData(theEnv)->FactJNGV3Info,FACT_JN_VAR3);
00198 InstallPrimitive(theEnv,&FactgenData(theEnv)->FactPNGV1Info,FACT_PN_VAR1);
00199 InstallPrimitive(theEnv,&FactgenData(theEnv)->FactPNGV2Info,FACT_PN_VAR2);
00200 InstallPrimitive(theEnv,&FactgenData(theEnv)->FactPNGV3Info,FACT_PN_VAR3);
00201 InstallPrimitive(theEnv,&FactgenData(theEnv)->FactJNCV1Info,FACT_JN_CMP1);
00202 InstallPrimitive(theEnv,&FactgenData(theEnv)->FactJNCV2Info,FACT_JN_CMP2);
00203 InstallPrimitive(theEnv,&FactgenData(theEnv)->FactPNCV1Info,FACT_PN_CMP1);
00204 InstallPrimitive(theEnv,&FactgenData(theEnv)->FactStoreMFInfo,FACT_STORE_MULTIFIELD);
00205 InstallPrimitive(theEnv,&FactgenData(theEnv)->FactSlotLengthInfo,FACT_SLOT_LENGTH);
00206 InstallPrimitive(theEnv,&FactgenData(theEnv)->FactPNConstant1Info,FACT_PN_CONSTANT1);
00207 InstallPrimitive(theEnv,&FactgenData(theEnv)->FactPNConstant2Info,FACT_PN_CONSTANT2);
00208 #endif
00209 }
00210
00211 #if (! RUN_TIME) && (! BLOAD_ONLY)
00212
00213
00214
00215
00216
00217
00218 globle struct expr *FactGenPNConstant(
00219 void *theEnv,
00220 struct lhsParseNode *theField)
00221 {
00222 struct expr *top;
00223 unsigned short tempValue;
00224 struct factConstantPN1Call hack1;
00225 struct factConstantPN2Call hack2;
00226
00227
00228
00229
00230
00231
00232
00233 if (theField->withinMultifieldSlot == FALSE)
00234 {
00235 ClearBitString(&hack1,sizeof(struct factConstantPN1Call));
00236
00237 if (theField->negated) hack1.testForEquality = FALSE;
00238 else hack1.testForEquality = TRUE;
00239
00240 hack1.whichSlot = (unsigned short) (theField->slotNumber - 1);
00241
00242 top = GenConstant(theEnv,FACT_PN_CONSTANT1,EnvAddBitMap(theEnv,&hack1,sizeof(struct factConstantPN1Call)));
00243
00244 top->argList = GenConstant(theEnv,theField->type,theField->value);
00245
00246 return(top);
00247 }
00248
00249
00250
00251
00252
00253
00254
00255
00256 else if ((theField->multiFieldsBefore == 0) ||
00257 ((theField->multiFieldsBefore == 1) && (theField->multiFieldsAfter == 0)))
00258 {
00259 ClearBitString(&hack2,sizeof(struct factConstantPN2Call));
00260
00261 if (theField->negated) hack2.testForEquality = FALSE;
00262 else hack2.testForEquality = TRUE;
00263
00264 hack2.whichSlot = (unsigned short) (theField->slotNumber - 1);
00265
00266 if (theField->multiFieldsBefore == 0)
00267 {
00268 hack2.fromBeginning = TRUE;
00269 hack2.offset = theField->singleFieldsBefore;
00270 }
00271 else
00272 {
00273 hack2.fromBeginning = FALSE;
00274 hack2.offset = theField->singleFieldsAfter;
00275 }
00276
00277 top = GenConstant(theEnv,FACT_PN_CONSTANT2,EnvAddBitMap(theEnv,&hack2,sizeof(struct factConstantPN2Call)));
00278
00279 top->argList = GenConstant(theEnv,theField->type,theField->value);
00280
00281 return(top);
00282 }
00283
00284
00285
00286
00287
00288
00289
00290 else
00291 {
00292 if (theField->negated)
00293 { top = GenConstant(theEnv,FCALL,ExpressionData(theEnv)->PTR_NEQ); }
00294 else
00295 { top = GenConstant(theEnv,FCALL,ExpressionData(theEnv)->PTR_EQ); }
00296
00297 tempValue = theField->type;
00298 theField->type = SF_VARIABLE;
00299 top->argList = FactGenGetfield(theEnv,theField);
00300 theField->type = tempValue;
00301
00302 top->argList->nextArg = GenConstant(theEnv,theField->type,theField->value);
00303 }
00304
00305
00306
00307
00308
00309 return(top);
00310 }
00311
00312
00313
00314
00315
00316
00317 globle struct expr *FactGenGetfield(
00318 void *theEnv,
00319 struct lhsParseNode *theNode)
00320 {
00321
00322
00323
00324
00325
00326 if ((theNode->slotNumber > 0) && (theNode->withinMultifieldSlot == FALSE))
00327 { return(GenConstant(theEnv,FACT_PN_VAR2,FactGetVarPN2(theEnv,theNode))); }
00328
00329
00330
00331
00332
00333
00334
00335
00336 if (((theNode->type == SF_WILDCARD) || (theNode->type == SF_VARIABLE) || ConstantType(theNode->type)) &&
00337 ((theNode->multiFieldsBefore == 0) ||
00338 ((theNode->multiFieldsBefore == 1) && (theNode->multiFieldsAfter == 0))))
00339 { return(GenConstant(theEnv,FACT_PN_VAR3,FactGetVarPN3(theEnv,theNode))); }
00340
00341 if (((theNode->type == MF_WILDCARD) || (theNode->type == MF_VARIABLE)) &&
00342 (theNode->multiFieldsBefore == 0) && (theNode->multiFieldsAfter == 0))
00343 { return(GenConstant(theEnv,FACT_PN_VAR3,FactGetVarPN3(theEnv,theNode))); }
00344
00345
00346
00347
00348
00349
00350 return(GenConstant(theEnv,FACT_PN_VAR1,FactGetVarPN1(theEnv,theNode)));
00351 }
00352
00353
00354
00355
00356
00357
00358 globle struct expr *FactGenGetvar(
00359 void *theEnv,
00360 struct lhsParseNode *theNode,
00361 int side)
00362 {
00363
00364
00365
00366
00367 if ((theNode->slotNumber > 0) && (theNode->withinMultifieldSlot == FALSE))
00368 { return(GenConstant(theEnv,FACT_JN_VAR2,FactGetVarJN2(theEnv,theNode,side))); }
00369
00370
00371
00372
00373
00374
00375
00376
00377 if (((theNode->type == SF_WILDCARD) || (theNode->type == SF_VARIABLE)) &&
00378 ((theNode->multiFieldsBefore == 0) ||
00379 ((theNode->multiFieldsBefore == 1) && (theNode->multiFieldsAfter == 0))))
00380 { return(GenConstant(theEnv,FACT_JN_VAR3,FactGetVarJN3(theEnv,theNode,side))); }
00381
00382 if (((theNode->type == MF_WILDCARD) || (theNode->type == MF_VARIABLE)) &&
00383 (theNode->multiFieldsBefore == 0) &&
00384 (theNode->multiFieldsAfter == 0))
00385 { return(GenConstant(theEnv,FACT_JN_VAR3,FactGetVarJN3(theEnv,theNode,side))); }
00386
00387
00388
00389
00390
00391
00392 return(GenConstant(theEnv,FACT_JN_VAR1,FactGetVarJN1(theEnv,theNode,side)));
00393 }
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403 globle struct expr *FactGenCheckLength(
00404 void *theEnv,
00405 struct lhsParseNode *theNode)
00406 {
00407 struct factCheckLengthPNCall hack;
00408
00409
00410
00411
00412
00413
00414 if ((theNode->singleFieldsAfter == 0) &&
00415 (theNode->type != SF_VARIABLE) &&
00416 (theNode->type != SF_WILDCARD))
00417 { return(NULL); }
00418
00419
00420
00421
00422
00423 ClearBitString(&hack,sizeof(struct factCheckLengthPNCall));
00424 hack.whichSlot = (unsigned short) (theNode->slotNumber - 1);
00425
00426
00427
00428
00429
00430
00431 if ((theNode->type != MF_VARIABLE) &&
00432 (theNode->type != MF_WILDCARD) &&
00433 (theNode->multiFieldsAfter == 0))
00434 { hack.exactly = 1; }
00435 else
00436 { hack.exactly = 0; }
00437
00438
00439
00440
00441
00442
00443 if ((theNode->type == SF_VARIABLE) || (theNode->type == SF_WILDCARD))
00444 { hack.minLength = (unsigned short) (1 + theNode->singleFieldsAfter); }
00445 else
00446 { hack.minLength = theNode->singleFieldsAfter; }
00447
00448
00449
00450
00451
00452 return(GenConstant(theEnv,FACT_SLOT_LENGTH,EnvAddBitMap(theEnv,&hack,sizeof(struct factCheckLengthPNCall))));
00453 }
00454
00455
00456
00457
00458
00459
00460 globle struct expr *FactGenCheckZeroLength(
00461 void *theEnv,
00462 unsigned theSlot)
00463 {
00464 struct factCheckLengthPNCall hack;
00465
00466 ClearBitString(&hack,sizeof(struct factCheckLengthPNCall));
00467
00468 hack.whichSlot = (unsigned short) (theSlot - 1);
00469 hack.exactly = 1;
00470 hack.minLength = 0;
00471
00472 return(GenConstant(theEnv,FACT_SLOT_LENGTH,EnvAddBitMap(theEnv,&hack,sizeof(struct factCheckLengthPNCall))));
00473 }
00474
00475
00476
00477
00478
00479
00480 globle void FactReplaceGetvar(
00481 void *theEnv,
00482 struct expr *theItem,
00483 struct lhsParseNode *theNode,
00484 int side)
00485 {
00486
00487
00488
00489
00490 if ((theNode->slotNumber > 0) && (theNode->withinMultifieldSlot == FALSE))
00491 {
00492 theItem->type = FACT_JN_VAR2;
00493 theItem->value = FactGetVarJN2(theEnv,theNode,side);
00494 return;
00495 }
00496
00497
00498
00499
00500
00501
00502
00503
00504 if (((theNode->type == SF_WILDCARD) || (theNode->type == SF_VARIABLE)) &&
00505 ((theNode->multiFieldsBefore == 0) ||
00506 ((theNode->multiFieldsBefore == 1) && (theNode->multiFieldsAfter == 0))))
00507 {
00508 theItem->type = FACT_JN_VAR3;
00509 theItem->value = FactGetVarJN3(theEnv,theNode,side);
00510 return;
00511 }
00512
00513 if (((theNode->type == MF_WILDCARD) || (theNode->type == MF_VARIABLE)) &&
00514 (theNode->multiFieldsBefore == 0) &&
00515 (theNode->multiFieldsAfter == 0))
00516 {
00517 theItem->type = FACT_JN_VAR3;
00518 theItem->value = FactGetVarJN3(theEnv,theNode,side);
00519 return;
00520 }
00521
00522
00523
00524
00525
00526
00527 theItem->type = FACT_JN_VAR1;
00528 theItem->value = FactGetVarJN1(theEnv,theNode,side);
00529 }
00530
00531
00532
00533
00534
00535
00536 globle void FactReplaceGetfield(
00537 void *theEnv,
00538 struct expr *theItem,
00539 struct lhsParseNode *theNode)
00540 {
00541
00542
00543
00544
00545 if (theNode->withinMultifieldSlot == FALSE)
00546 {
00547 theItem->type = FACT_PN_VAR2;
00548 theItem->value = FactGetVarPN2(theEnv,theNode);
00549 return;
00550 }
00551
00552
00553
00554
00555
00556
00557
00558
00559 if (((theNode->type == SF_WILDCARD) || (theNode->type == SF_VARIABLE)) &&
00560 ((theNode->multiFieldsBefore == 0) ||
00561 ((theNode->multiFieldsBefore == 1) && (theNode->multiFieldsAfter == 0))))
00562 {
00563 theItem->type = FACT_PN_VAR3;
00564 theItem->value = FactGetVarPN3(theEnv,theNode);
00565 return;
00566 }
00567
00568 if (((theNode->type == MF_WILDCARD) || (theNode->type == MF_VARIABLE)) &&
00569 (theNode->multiFieldsBefore == 0) &&
00570 (theNode->multiFieldsAfter == 0))
00571 {
00572 theItem->type = FACT_PN_VAR3;
00573 theItem->value = FactGetVarPN3(theEnv,theNode);
00574 return;
00575 }
00576
00577
00578
00579
00580
00581
00582 theItem->type = FACT_PN_VAR1;
00583 theItem->value = FactGetVarPN1(theEnv,theNode);
00584 }
00585
00586
00587
00588
00589
00590
00591
00592
00593
00594 static void *FactGetVarJN1(
00595 void *theEnv,
00596 struct lhsParseNode *theNode,
00597 int side)
00598 {
00599 struct factGetVarJN1Call hack;
00600
00601
00602
00603
00604
00605 ClearBitString(&hack,sizeof(struct factGetVarJN1Call));
00606
00607
00608
00609
00610
00611
00612 if (side == LHS)
00613 {
00614 hack.lhs = 1;
00615 hack.whichPattern = (unsigned short) theNode->joinDepth;
00616 }
00617 else if (side == RHS)
00618 {
00619 hack.rhs = 1;
00620 hack.whichPattern = (unsigned short) 0;
00621 }
00622 else if (side == NESTED_RHS)
00623 {
00624 hack.rhs = 1;
00625 hack.whichPattern = (unsigned short) theNode->joinDepth;
00626 }
00627 else
00628 { hack.whichPattern = (unsigned short) theNode->joinDepth; }
00629
00630
00631
00632
00633
00634
00635 if (theNode->slotNumber <= 0)
00636 {
00637 hack.factAddress = 1;
00638 hack.allFields = 0;
00639 hack.whichSlot = 0;
00640 hack.whichField = 0;
00641 }
00642
00643
00644
00645
00646
00647
00648
00649
00650 else if (theNode->index <= 0)
00651 {
00652 hack.factAddress = 0;
00653 hack.allFields = 1;
00654 hack.whichSlot = (unsigned short) (theNode->slotNumber - 1);
00655 hack.whichField = 0;
00656 }
00657
00658
00659
00660
00661
00662
00663
00664 else
00665 {
00666 hack.factAddress = 0;
00667 hack.allFields = 0;
00668 hack.whichSlot = (unsigned short) (theNode->slotNumber - 1);
00669 hack.whichField = (unsigned short) (theNode->index - 1);
00670 }
00671
00672
00673
00674
00675
00676 return(EnvAddBitMap(theEnv,&hack,sizeof(struct factGetVarJN1Call)));
00677 }
00678
00679
00680
00681
00682
00683
00684
00685
00686
00687 static void *FactGetVarJN2(
00688 void *theEnv,
00689 struct lhsParseNode *theNode,
00690 int side)
00691 {
00692 struct factGetVarJN2Call hack;
00693
00694
00695
00696
00697
00698 ClearBitString(&hack,sizeof(struct factGetVarJN2Call));
00699
00700
00701
00702
00703
00704
00705
00706 hack.whichSlot = (unsigned short) (theNode->slotNumber - 1);
00707
00708 if (side == LHS)
00709 {
00710 hack.lhs = 1;
00711 hack.whichPattern = (unsigned short) theNode->joinDepth;
00712 }
00713 else if (side == RHS)
00714 {
00715 hack.rhs = 1;
00716 hack.whichPattern = (unsigned short) 0;
00717 }
00718 else if (side == NESTED_RHS)
00719 {
00720 hack.rhs = 1;
00721 hack.whichPattern = (unsigned short) theNode->joinDepth;
00722 }
00723 else
00724 { hack.whichPattern = (unsigned short) theNode->joinDepth; }
00725
00726
00727
00728
00729
00730 return(EnvAddBitMap(theEnv,&hack,sizeof(struct factGetVarJN2Call)));
00731 }
00732
00733
00734
00735
00736
00737
00738
00739
00740
00741
00742
00743
00744
00745 static void *FactGetVarJN3(
00746 void *theEnv,
00747 struct lhsParseNode *theNode,
00748 int side)
00749 {
00750 struct factGetVarJN3Call hack;
00751
00752
00753
00754
00755
00756 ClearBitString(&hack,sizeof(struct factGetVarJN3Call));
00757
00758
00759
00760
00761
00762
00763
00764 hack.whichSlot = (unsigned short) (theNode->slotNumber - 1);
00765
00766 if (side == LHS)
00767 {
00768 hack.lhs = 1;
00769 hack.whichPattern = (unsigned short) theNode->joinDepth;
00770 }
00771 else if (side == RHS)
00772 {
00773 hack.rhs = 1;
00774 hack.whichPattern = (unsigned short) 0;
00775 }
00776 else if (side == NESTED_RHS)
00777 {
00778 hack.rhs = 1;
00779 hack.whichPattern = (unsigned short) theNode->joinDepth;
00780 }
00781 else
00782 { hack.whichPattern = (unsigned short) theNode->joinDepth; }
00783
00784
00785
00786
00787
00788 if ((theNode->type == SF_WILDCARD) || (theNode->type == SF_VARIABLE))
00789 {
00790
00791
00792
00793
00794
00795
00796
00797
00798 if (theNode->multiFieldsBefore == 0)
00799 {
00800 hack.fromBeginning = 1;
00801 hack.fromEnd = 0;
00802 hack.beginOffset = theNode->singleFieldsBefore;
00803 hack.endOffset = 0;
00804 }
00805
00806
00807
00808
00809
00810
00811 else
00812 {
00813 hack.fromBeginning = 0;
00814 hack.fromEnd = 1;
00815 hack.beginOffset = 0;
00816 hack.endOffset = theNode->singleFieldsAfter;
00817 }
00818
00819
00820
00821
00822
00823 return(EnvAddBitMap(theEnv,&hack,sizeof(struct factGetVarJN3Call)));
00824 }
00825
00826
00827
00828
00829
00830
00831
00832
00833
00834
00835
00836
00837 hack.fromBeginning = 1;
00838 hack.fromEnd = 1;
00839 hack.beginOffset = theNode->singleFieldsBefore;
00840 hack.endOffset = theNode->singleFieldsAfter;
00841
00842
00843
00844
00845
00846 return(EnvAddBitMap(theEnv,&hack,sizeof(struct factGetVarJN3Call)));
00847 }
00848
00849
00850
00851
00852
00853
00854
00855
00856
00857 static void *FactGetVarPN1(
00858 void *theEnv,
00859 struct lhsParseNode *theNode)
00860 {
00861 struct factGetVarPN1Call hack;
00862
00863
00864
00865
00866
00867 ClearBitString(&hack,sizeof(struct factGetVarPN1Call));
00868
00869
00870
00871
00872
00873
00874 if (theNode->slotNumber <= 0)
00875 {
00876 hack.factAddress = 1;
00877 hack.allFields = 0;
00878 hack.whichSlot = 0;
00879 hack.whichField = 0;
00880 }
00881
00882
00883
00884
00885
00886
00887
00888
00889 else if (theNode->index <= 0)
00890 {
00891 hack.factAddress = 0;
00892 hack.allFields = 1;
00893 hack.whichSlot = (unsigned short) (theNode->slotNumber - 1);
00894 hack.whichField = 0;
00895 }
00896
00897
00898
00899
00900
00901
00902
00903 else
00904 {
00905 hack.factAddress = 0;
00906 hack.allFields = 0;
00907 hack.whichSlot = (unsigned short) (theNode->slotNumber - 1);
00908 hack.whichField = (unsigned short) (theNode->index - 1);
00909 }
00910
00911
00912
00913
00914
00915 return(EnvAddBitMap(theEnv,&hack,sizeof(struct factGetVarPN1Call)));
00916 }
00917
00918
00919
00920
00921
00922
00923
00924
00925 static void *FactGetVarPN2(
00926 void *theEnv,
00927 struct lhsParseNode *theNode)
00928 {
00929 struct factGetVarPN2Call hack;
00930
00931
00932
00933
00934
00935 ClearBitString(&hack,sizeof(struct factGetVarPN2Call));
00936
00937
00938
00939
00940
00941
00942 hack.whichSlot = (unsigned short) (theNode->slotNumber - 1);
00943
00944
00945
00946
00947
00948 return(EnvAddBitMap(theEnv,&hack,sizeof(struct factGetVarPN2Call)));
00949 }
00950
00951
00952
00953
00954
00955
00956
00957
00958
00959
00960
00961
00962 static void *FactGetVarPN3(
00963 void *theEnv,
00964 struct lhsParseNode *theNode)
00965 {
00966 struct factGetVarPN3Call hack;
00967
00968
00969
00970
00971
00972 ClearBitString(&hack,sizeof(struct factGetVarPN3Call));
00973
00974
00975
00976
00977
00978
00979 hack.whichSlot = (unsigned short) (theNode->slotNumber - 1);
00980
00981
00982
00983
00984
00985 if ((theNode->type == SF_WILDCARD) || (theNode->type == SF_VARIABLE) || ConstantType(theNode->type))
00986 {
00987
00988
00989
00990
00991
00992
00993
00994
00995 if (theNode->multiFieldsBefore == 0)
00996 {
00997 hack.fromBeginning = 1;
00998 hack.fromEnd = 0;
00999 hack.beginOffset = theNode->singleFieldsBefore;
01000 hack.endOffset = 0;
01001 }
01002
01003
01004
01005
01006
01007
01008 else
01009 {
01010 hack.fromBeginning = 0;
01011 hack.fromEnd = 1;
01012 hack.beginOffset = 0;
01013 hack.endOffset = theNode->singleFieldsAfter;
01014 }
01015
01016 return(EnvAddBitMap(theEnv,&hack,sizeof(struct factGetVarPN3Call)));
01017 }
01018
01019
01020
01021
01022
01023
01024
01025
01026
01027
01028
01029
01030 hack.fromBeginning = 1;
01031 hack.fromEnd = 1;
01032 hack.beginOffset = theNode->singleFieldsBefore;
01033 hack.endOffset = theNode->singleFieldsAfter;
01034
01035
01036
01037
01038
01039 return(EnvAddBitMap(theEnv,&hack,sizeof(struct factGetVarPN3Call)));
01040 }
01041
01042
01043
01044
01045
01046
01047 globle struct expr *FactPNVariableComparison(
01048 void *theEnv,
01049 struct lhsParseNode *selfNode,
01050 struct lhsParseNode *referringNode)
01051 {
01052 struct expr *top;
01053 struct factCompVarsPN1Call hack;
01054
01055
01056
01057
01058
01059 ClearBitString(&hack,sizeof(struct factCompVarsPN1Call));
01060
01061
01062
01063
01064
01065
01066 if ((selfNode->withinMultifieldSlot == FALSE) &&
01067 (selfNode->slotNumber > 0) &&
01068 (referringNode->withinMultifieldSlot == FALSE) &&
01069 (referringNode->slotNumber > 0))
01070 {
01071 hack.pass = 0;
01072 hack.fail = 0;
01073 hack.field1 = (unsigned short) (selfNode->slotNumber - 1);
01074 hack.field2 = (unsigned short) (referringNode->slotNumber - 1);
01075
01076 if (selfNode->negated) hack.fail = 1;
01077 else hack.pass = 1;
01078
01079 top = GenConstant(theEnv,FACT_PN_CMP1,EnvAddBitMap(theEnv,&hack,sizeof(struct factCompVarsPN1Call)));
01080 }
01081
01082
01083
01084
01085
01086
01087 else
01088 {
01089 if (selfNode->negated) top = GenConstant(theEnv,FCALL,ExpressionData(theEnv)->PTR_NEQ);
01090 else top = GenConstant(theEnv,FCALL,ExpressionData(theEnv)->PTR_EQ);
01091
01092 top->argList = FactGenGetfield(theEnv,selfNode);
01093 top->argList->nextArg = FactGenGetfield(theEnv,referringNode);
01094 }
01095
01096
01097
01098
01099
01100
01101 return(top);
01102 }
01103
01104
01105
01106
01107
01108
01109 globle struct expr *FactJNVariableComparison(
01110 void *theEnv,
01111 struct lhsParseNode *selfNode,
01112 struct lhsParseNode *referringNode,
01113 int nandJoin)
01114 {
01115 struct expr *top;
01116 struct factCompVarsJN1Call hack1;
01117 struct factCompVarsJN2Call hack2;
01118
01119
01120
01121
01122
01123
01124 if ((selfNode->withinMultifieldSlot == FALSE) &&
01125 (selfNode->slotNumber > 0) &&
01126 (referringNode->withinMultifieldSlot == FALSE) &&
01127 (referringNode->slotNumber > 0))
01128 {
01129 ClearBitString(&hack1,sizeof(struct factCompVarsJN1Call));
01130 hack1.pass = 0;
01131 hack1.fail = 0;
01132 hack1.slot1 = (unsigned short) (selfNode->slotNumber - 1);
01133
01134 if (nandJoin)
01135 { hack1.pattern1 = (unsigned short) selfNode->joinDepth; }
01136 else
01137 { hack1.pattern1 = 0; }
01138 hack1.p1rhs = TRUE;
01139
01140 if (nandJoin && (selfNode->beginNandDepth == referringNode->beginNandDepth))
01141 { hack1.p2rhs = TRUE; }
01142 else
01143 { hack1.p2lhs = TRUE; }
01144
01145 hack1.pattern2 = (unsigned short) referringNode->joinDepth;
01146
01147 if (referringNode->index < 0) hack1.slot2 = 0;
01148 else hack1.slot2 = (unsigned short) (referringNode->slotNumber - 1);
01149
01150 if (selfNode->negated) hack1.fail = 1;
01151 else hack1.pass = 1;
01152
01153 top = GenConstant(theEnv,FACT_JN_CMP1,EnvAddBitMap(theEnv,&hack1,sizeof(struct factCompVarsJN1Call)));
01154 }
01155
01156
01157
01158
01159
01160
01161
01162
01163
01164 else if ((selfNode->slotNumber > 0) &&
01165 (selfNode->type == SF_VARIABLE) &&
01166 ((selfNode->multiFieldsBefore == 0) ||
01167 ((selfNode->multiFieldsBefore == 1) &&
01168 (selfNode->multiFieldsAfter == 0))) &&
01169 (referringNode->slotNumber > 0) &&
01170 (referringNode->type == SF_VARIABLE) &&
01171 ((referringNode->multiFieldsBefore == 0) ||
01172 (referringNode->multiFieldsAfter == 0)))
01173 {
01174 ClearBitString(&hack2,sizeof(struct factCompVarsJN2Call));
01175 hack2.pass = 0;
01176 hack2.fail = 0;
01177 hack2.slot1 = (unsigned short) (selfNode->slotNumber - 1);
01178
01179 if (nandJoin)
01180 { hack2.pattern1 = (unsigned short) selfNode->joinDepth; }
01181 else
01182 { hack2.pattern1 = 0; }
01183 hack2.p1rhs = TRUE;
01184
01185 if (nandJoin && (selfNode->beginNandDepth == referringNode->beginNandDepth))
01186 { hack2.p2rhs = TRUE; }
01187 else
01188 { hack2.p2lhs = TRUE; }
01189
01190 hack2.pattern2 = (unsigned short) referringNode->joinDepth;
01191 hack2.slot2 = (unsigned short) (referringNode->slotNumber - 1);
01192
01193 if (selfNode->multiFieldsBefore == 0)
01194 {
01195 hack2.fromBeginning1 = 1;
01196 hack2.offset1 = selfNode->singleFieldsBefore;
01197 }
01198 else
01199 {
01200 hack2.fromBeginning1 = 0;
01201 hack2.offset1 = selfNode->singleFieldsAfter;
01202 }
01203
01204 if (referringNode->multiFieldsBefore == 0)
01205 {
01206 hack2.fromBeginning2 = 1;
01207 hack2.offset2 = referringNode->singleFieldsBefore;
01208 }
01209 else
01210 {
01211 hack2.fromBeginning2 = 0;
01212 hack2.offset2 = referringNode->singleFieldsAfter;
01213 }
01214
01215 if (selfNode->negated) hack2.fail = 1;
01216 else hack2.pass = 1;
01217
01218 top = GenConstant(theEnv,FACT_JN_CMP2,EnvAddBitMap(theEnv,&hack2,sizeof(struct factCompVarsJN2Call)));
01219 }
01220
01221
01222
01223
01224
01225
01226
01227 else
01228 {
01229 if (selfNode->negated)
01230 { top = GenConstant(theEnv,FCALL,ExpressionData(theEnv)->PTR_NEQ); }
01231 else
01232 { top = GenConstant(theEnv,FCALL,ExpressionData(theEnv)->PTR_EQ); }
01233
01234 if (nandJoin)
01235 { top->argList = FactGenGetvar(theEnv,selfNode,NESTED_RHS); }
01236 else
01237 { top->argList = FactGenGetvar(theEnv,selfNode,RHS); }
01238
01239 if (nandJoin && (selfNode->beginNandDepth == referringNode->beginNandDepth))
01240 { top->argList->nextArg = FactGenGetvar(theEnv,referringNode,NESTED_RHS); }
01241 else
01242 { top->argList->nextArg = FactGenGetvar(theEnv,referringNode,LHS); }
01243 }
01244
01245
01246
01247
01248
01249
01250 return(top);
01251 }
01252
01253 #endif
01254
01255 #endif
01256
01257