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
00027
00028 #define _FACTBLD_SOURCE_
00029
00030 #include "setup.h"
00031
00032 #if DEFTEMPLATE_CONSTRUCT && DEFRULE_CONSTRUCT
00033
00034 #include <stdio.h>
00035 #define _STDIO_INCLUDED_
00036
00037 #include "memalloc.h"
00038 #include "reteutil.h"
00039 #include "router.h"
00040 #include "reorder.h"
00041 #include "factcmp.h"
00042 #include "factmch.h"
00043 #include "factgen.h"
00044 #include "factmngr.h"
00045 #include "factlhs.h"
00046 #include "argacces.h"
00047 #include "modulutl.h"
00048 #include "tmpltdef.h"
00049 #include "envrnmnt.h"
00050
00051 #include "factbld.h"
00052
00053
00054
00055
00056
00057 #if (! RUN_TIME) && (! BLOAD_ONLY)
00058 static struct factPatternNode *FindPatternNode(struct factPatternNode *,struct lhsParseNode *,
00059 struct factPatternNode **,unsigned,unsigned);
00060 static struct factPatternNode *CreateNewPatternNode(void *,struct lhsParseNode *,struct factPatternNode *,
00061 struct factPatternNode *,unsigned,unsigned);
00062 static void ClearPatternMatches(void *,struct factPatternNode *);
00063 static void DetachFactPattern(void *,struct patternNodeHeader *);
00064 static struct patternNodeHeader *PlaceFactPattern(void *,struct lhsParseNode *);
00065 static struct lhsParseNode *RemoveUnneededSlots(void *,struct lhsParseNode *);
00066 static void FindAndSetDeftemplatePatternNetwork(void *,struct factPatternNode *,struct factPatternNode *);
00067 #endif
00068
00069
00070
00071
00072
00073
00074 globle void InitializeFactPatterns(
00075 void *theEnv)
00076 {
00077 #if DEFRULE_CONSTRUCT
00078 struct patternParser *newPtr;
00079
00080 InitializeFactReteFunctions(theEnv);
00081
00082 newPtr = get_struct(theEnv,patternParser);
00083
00084 newPtr->name = "facts";
00085 newPtr->priority = 0;
00086 newPtr->entityType = &FactData(theEnv)->FactInfo;
00087
00088 #if (! RUN_TIME) && (! BLOAD_ONLY)
00089 newPtr->recognizeFunction = FactPatternParserFind;
00090 newPtr->parseFunction = FactPatternParse;
00091 newPtr->postAnalysisFunction = NULL;
00092 newPtr->addPatternFunction = PlaceFactPattern;
00093 newPtr->removePatternFunction = DetachFactPattern;
00094 newPtr->genJNConstantFunction = NULL;
00095 newPtr->replaceGetJNValueFunction = FactReplaceGetvar;
00096 newPtr->genGetJNValueFunction = FactGenGetvar;
00097 newPtr->genCompareJNValuesFunction = FactJNVariableComparison;
00098 newPtr->genPNConstantFunction = FactGenPNConstant;
00099 newPtr->replaceGetPNValueFunction = FactReplaceGetfield;
00100 newPtr->genGetPNValueFunction = FactGenGetfield;
00101 newPtr->genComparePNValuesFunction = FactPNVariableComparison;
00102 newPtr->returnUserDataFunction = NULL;
00103 newPtr->copyUserDataFunction = NULL;
00104 #else
00105 newPtr->recognizeFunction = NULL;
00106 newPtr->parseFunction = NULL;
00107 newPtr->postAnalysisFunction = NULL;
00108 newPtr->addPatternFunction = NULL;
00109 newPtr->removePatternFunction = NULL;
00110 newPtr->genJNConstantFunction = NULL;
00111 newPtr->replaceGetJNValueFunction = NULL;
00112 newPtr->genGetJNValueFunction = NULL;
00113 newPtr->genCompareJNValuesFunction = NULL;
00114 newPtr->genPNConstantFunction = NULL;
00115 newPtr->replaceGetPNValueFunction = NULL;
00116 newPtr->genGetPNValueFunction = NULL;
00117 newPtr->genComparePNValuesFunction = NULL;
00118 newPtr->returnUserDataFunction = NULL;
00119 newPtr->copyUserDataFunction = NULL;
00120 #endif
00121
00122 newPtr->markIRPatternFunction = MarkFactPatternForIncrementalReset;
00123 newPtr->incrementalResetFunction = FactsIncrementalReset;
00124
00125 #if (! RUN_TIME) && (! BLOAD_ONLY)
00126 newPtr->initialPatternFunction = CreateInitialFactPattern;
00127 #if CONSTRUCT_COMPILER
00128 newPtr->codeReferenceFunction = FactPatternNodeReference;
00129 #else
00130 newPtr->codeReferenceFunction = NULL;
00131 #endif
00132 #else
00133 newPtr->initialPatternFunction = NULL;
00134 newPtr->codeReferenceFunction = NULL;
00135 #endif
00136
00137 AddPatternParser(theEnv,newPtr);
00138 #endif
00139 }
00140
00141 #if (! RUN_TIME) && (! BLOAD_ONLY)
00142
00143
00144
00145
00146 static struct patternNodeHeader *PlaceFactPattern(
00147 void *theEnv,
00148 struct lhsParseNode *thePattern)
00149 {
00150 struct lhsParseNode *tempPattern;
00151 struct factPatternNode *currentLevel, *lastLevel;
00152 struct factPatternNode *nodeBeforeMatch, *newNode = NULL;
00153 unsigned endSlot;
00154 int count;
00155 char *deftemplateName;
00156
00157
00158
00159
00160
00161
00162 deftemplateName = ValueToString(thePattern->right->bottom->value);
00163
00164
00165
00166
00167
00168 thePattern->right = RemoveUnneededSlots(theEnv,thePattern->right);
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181 if (thePattern->right->right == NULL)
00182 {
00183 ReturnExpression(theEnv,thePattern->right->networkTest);
00184 ReturnExpression(theEnv,thePattern->right->constantSelector);
00185 ReturnExpression(theEnv,thePattern->right->constantValue);
00186 thePattern->right->networkTest = NULL;
00187 thePattern->right->constantSelector = NULL;
00188 thePattern->right->constantValue = NULL;
00189 }
00190 else
00191 {
00192 tempPattern = thePattern->right;
00193 thePattern->right = thePattern->right->right;
00194 tempPattern->right = NULL;
00195 ReturnLHSParseNodes(theEnv,tempPattern);
00196 }
00197
00198
00199
00200
00201
00202
00203 tempPattern = thePattern->right;
00204 while (tempPattern->right != NULL)
00205 { tempPattern = tempPattern->right; }
00206
00207 if ((tempPattern->multifieldSlot) && (tempPattern->bottom != NULL))
00208 {
00209 tempPattern = tempPattern->bottom;
00210
00211 while (tempPattern->right != NULL)
00212 { tempPattern = tempPattern->right; }
00213 }
00214
00215 tempPattern->rightHash = thePattern->rightHash;
00216 thePattern->rightHash = NULL;
00217
00218 tempPattern = NULL;
00219
00220
00221
00222
00223
00224
00225
00226 FactData(theEnv)->CurrentDeftemplate = (struct deftemplate *)
00227 FindImportedConstruct(theEnv,"deftemplate",NULL,
00228 deftemplateName,&count,
00229 TRUE,NULL);
00230
00231
00232
00233
00234
00235
00236 currentLevel = FactData(theEnv)->CurrentDeftemplate->patternNetwork;
00237 lastLevel = NULL;
00238 thePattern = thePattern->right;
00239
00240
00241
00242
00243
00244
00245 while (thePattern != NULL)
00246 {
00247
00248
00249
00250
00251
00252 if (thePattern->multifieldSlot)
00253 {
00254 tempPattern = thePattern;
00255 thePattern = thePattern->bottom;
00256 }
00257
00258
00259
00260
00261
00262
00263 if ((thePattern->right == NULL) && (tempPattern != NULL))
00264 { endSlot = TRUE; }
00265 else
00266 { endSlot = FALSE; }
00267
00268
00269
00270
00271
00272
00273 newNode = FindPatternNode(currentLevel,thePattern,&nodeBeforeMatch,endSlot,FALSE);
00274
00275
00276
00277
00278
00279
00280 if (newNode == NULL)
00281 { newNode = CreateNewPatternNode(theEnv,thePattern,nodeBeforeMatch,lastLevel,endSlot,FALSE); }
00282
00283 if (thePattern->constantSelector != NULL)
00284 {
00285 currentLevel = newNode->nextLevel;
00286 lastLevel = newNode;
00287 newNode = FindPatternNode(currentLevel,thePattern,&nodeBeforeMatch,endSlot,TRUE);
00288
00289 if (newNode == NULL)
00290 { newNode = CreateNewPatternNode(theEnv,thePattern,nodeBeforeMatch,lastLevel,endSlot,TRUE); }
00291 }
00292
00293
00294
00295
00296
00297 if ((thePattern->right == NULL) && (tempPattern != NULL))
00298 {
00299 thePattern = tempPattern;
00300 tempPattern = NULL;
00301 }
00302
00303 thePattern = thePattern->right;
00304
00305
00306
00307
00308
00309
00310
00311
00312 if (thePattern == NULL) newNode->header.stopNode = TRUE;
00313
00314
00315
00316
00317
00318
00319
00320 lastLevel = newNode;
00321 currentLevel = newNode->nextLevel;
00322 }
00323
00324
00325
00326
00327
00328 return((struct patternNodeHeader *) newNode);
00329 }
00330
00331
00332
00333
00334
00335
00336 static struct factPatternNode *FindPatternNode(
00337 struct factPatternNode *listOfNodes,
00338 struct lhsParseNode *thePattern,
00339 struct factPatternNode **nodeBeforeMatch,
00340 unsigned endSlot,
00341 unsigned constantSelector)
00342 {
00343 struct expr *compareTest;
00344 *nodeBeforeMatch = NULL;
00345
00346 if (constantSelector)
00347 { compareTest = thePattern->constantValue; }
00348 else if (thePattern->constantSelector != NULL)
00349 { compareTest = thePattern->constantSelector; }
00350 else
00351 { compareTest = thePattern->networkTest; }
00352
00353
00354
00355
00356
00357
00358 while (listOfNodes != NULL)
00359 {
00360
00361
00362
00363
00364
00365
00366
00367
00368 if ((thePattern->type == SF_WILDCARD) || (thePattern->type == SF_VARIABLE))
00369 {
00370 if ((listOfNodes->header.singlefieldNode) &&
00371 (listOfNodes->header.endSlot == endSlot) &&
00372 (listOfNodes->whichField == thePattern->index) &&
00373 (listOfNodes->whichSlot == (thePattern->slotNumber - 1)) &&
00374 IdenticalExpression(listOfNodes->networkTest,compareTest) &&
00375 IdenticalExpression(listOfNodes->header.rightHash,thePattern->rightHash))
00376 { return(listOfNodes); }
00377 }
00378 else if ((thePattern->type == MF_WILDCARD) || (thePattern->type == MF_VARIABLE))
00379 {
00380 if ((listOfNodes->header.multifieldNode) &&
00381 (listOfNodes->header.endSlot == endSlot) &&
00382 (listOfNodes->leaveFields == thePattern->singleFieldsAfter) &&
00383 (listOfNodes->whichField == thePattern->index) &&
00384 (listOfNodes->whichSlot == (thePattern->slotNumber - 1)) &&
00385 IdenticalExpression(listOfNodes->networkTest,compareTest) &&
00386 IdenticalExpression(listOfNodes->header.rightHash,thePattern->rightHash))
00387 { return(listOfNodes); }
00388 }
00389
00390
00391
00392
00393
00394
00395 *nodeBeforeMatch = listOfNodes;
00396 listOfNodes = listOfNodes->rightNode;
00397 }
00398
00399
00400
00401
00402
00403 return(NULL);
00404 }
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419 static struct lhsParseNode *RemoveUnneededSlots(
00420 void *theEnv,
00421 struct lhsParseNode *thePattern)
00422 {
00423 struct lhsParseNode *tempPattern = thePattern;
00424 struct lhsParseNode *lastPattern = NULL, *head = thePattern;
00425 struct expr *theTest;
00426
00427 while (tempPattern != NULL)
00428 {
00429
00430
00431
00432
00433
00434
00435 if (((tempPattern->type == SF_WILDCARD) || (tempPattern->type == SF_VARIABLE)) &&
00436 (tempPattern->networkTest == NULL))
00437 {
00438 if (lastPattern != NULL) lastPattern->right = tempPattern->right;
00439 else head = tempPattern->right;
00440
00441 tempPattern->right = NULL;
00442 ReturnLHSParseNodes(theEnv,tempPattern);
00443
00444 if (lastPattern != NULL) tempPattern = lastPattern->right;
00445 else tempPattern = head;
00446 }
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456 else if (((tempPattern->type == MF_WILDCARD) || (tempPattern->type == MF_VARIABLE)) &&
00457 (tempPattern->multifieldSlot == FALSE) &&
00458 (tempPattern->networkTest == NULL) &&
00459 (tempPattern->multiFieldsBefore == 0) &&
00460 (tempPattern->multiFieldsAfter == 0))
00461 {
00462 if (lastPattern != NULL) lastPattern->right = tempPattern->right;
00463 else head = tempPattern->right;
00464
00465 tempPattern->right = NULL;
00466 ReturnLHSParseNodes(theEnv,tempPattern);
00467
00468 if (lastPattern != NULL) tempPattern = lastPattern->right;
00469 else tempPattern = head;
00470 }
00471
00472
00473
00474
00475
00476
00477
00478
00479 else if (((tempPattern->type == MF_WILDCARD) || (tempPattern->type == MF_VARIABLE)) &&
00480 (tempPattern->multifieldSlot == FALSE) &&
00481 (tempPattern->networkTest != NULL) &&
00482 (tempPattern->multiFieldsBefore == 0) &&
00483 (tempPattern->multiFieldsAfter == 0))
00484 {
00485 tempPattern->type = SF_WILDCARD;
00486 lastPattern = tempPattern;
00487 tempPattern = tempPattern->right;
00488 }
00489
00490
00491
00492
00493
00494
00495
00496
00497 else if ((tempPattern->type == MF_WILDCARD) &&
00498 (tempPattern->multifieldSlot == TRUE) &&
00499 (tempPattern->bottom == NULL))
00500 {
00501 tempPattern->type = SF_WILDCARD;
00502 tempPattern->networkTest = FactGenCheckZeroLength(theEnv,tempPattern->slotNumber);
00503 tempPattern->multifieldSlot = FALSE;
00504 lastPattern = tempPattern;
00505 tempPattern = tempPattern->right;
00506 }
00507
00508
00509
00510
00511
00512
00513 else if ((tempPattern->type == MF_WILDCARD) &&
00514 (tempPattern->multifieldSlot == TRUE))
00515 {
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527 theTest = FactGenCheckLength(theEnv,tempPattern->bottom);
00528 if (tempPattern->bottom->constantSelector != NULL)
00529 { tempPattern->bottom->constantSelector->nextArg = CopyExpression(theEnv,theTest); }
00530 theTest = CombineExpressions(theEnv,theTest,tempPattern->bottom->networkTest);
00531 tempPattern->bottom->networkTest = theTest;
00532
00533
00534
00535
00536
00537 tempPattern->bottom = RemoveUnneededSlots(theEnv,tempPattern->bottom);
00538
00539
00540
00541
00542
00543
00544
00545 if (tempPattern->bottom == NULL)
00546 {
00547 if (lastPattern != NULL) lastPattern->right = tempPattern->right;
00548 else head = tempPattern->right;
00549
00550 tempPattern->right = NULL;
00551 ReturnLHSParseNodes(theEnv,tempPattern);
00552
00553 if (lastPattern != NULL) tempPattern = lastPattern->right;
00554 else tempPattern = head;
00555 }
00556 else
00557 {
00558 lastPattern = tempPattern;
00559 tempPattern = tempPattern->right;
00560 }
00561 }
00562
00563
00564
00565
00566
00567
00568
00569 else
00570 {
00571 lastPattern = tempPattern;
00572 tempPattern = tempPattern->right;
00573 }
00574 }
00575
00576
00577
00578
00579
00580
00581 return(head);
00582 }
00583
00584
00585
00586
00587
00588 static struct factPatternNode *CreateNewPatternNode(
00589 void *theEnv,
00590 struct lhsParseNode *thePattern,
00591 struct factPatternNode *nodeBeforeMatch,
00592 struct factPatternNode *upperLevel,
00593 unsigned endSlot,
00594 unsigned constantSelector)
00595 {
00596 struct factPatternNode *newNode;
00597
00598
00599
00600
00601
00602
00603 newNode = get_struct(theEnv,factPatternNode);
00604 newNode->nextLevel = NULL;
00605 newNode->rightNode = NULL;
00606 newNode->leftNode = NULL;
00607 newNode->leaveFields = thePattern->singleFieldsAfter;
00608 InitializePatternHeader(theEnv,(struct patternNodeHeader *) &newNode->header);
00609
00610 if (thePattern->index > 0)
00611 { newNode->whichField = (unsigned short) thePattern->index; }
00612 else newNode->whichField = 0;
00613
00614 if (thePattern->slotNumber >= 0)
00615 { newNode->whichSlot = (unsigned short) (thePattern->slotNumber - 1); }
00616 else
00617 { newNode->whichSlot = newNode->whichField; }
00618
00619 if ((thePattern->constantSelector != NULL) && (! constantSelector))
00620 { newNode->header.selector = TRUE; }
00621
00622
00623
00624
00625
00626
00627 if ((thePattern->type == SF_WILDCARD) || (thePattern->type == SF_VARIABLE))
00628 { newNode->header.singlefieldNode = TRUE; }
00629 else if ((thePattern->type == MF_WILDCARD) || (thePattern->type == MF_VARIABLE))
00630 { newNode->header.multifieldNode = TRUE; }
00631 newNode->header.endSlot = endSlot;
00632
00633
00634
00635
00636
00637 if (constantSelector)
00638 { newNode->networkTest = AddHashedExpression(theEnv,thePattern->constantValue); }
00639 else if (thePattern->constantSelector != NULL)
00640 { newNode->networkTest = AddHashedExpression(theEnv,thePattern->constantSelector); }
00641 else
00642 { newNode->networkTest = AddHashedExpression(theEnv,thePattern->networkTest); }
00643
00644
00645
00646
00647
00648
00649 newNode->header.rightHash = AddHashedExpression(theEnv,thePattern->rightHash);
00650
00651
00652
00653
00654
00655 newNode->lastLevel = upperLevel;
00656
00657 if ((upperLevel != NULL) && (upperLevel->header.selector))
00658 { AddHashedPatternNode(theEnv,upperLevel,newNode,newNode->networkTest->type,newNode->networkTest->value); }
00659
00660
00661
00662
00663
00664
00665 if (nodeBeforeMatch == NULL)
00666 {
00667 if (upperLevel == NULL) FactData(theEnv)->CurrentDeftemplate->patternNetwork = newNode;
00668 else upperLevel->nextLevel = newNode;
00669 return(newNode);
00670 }
00671
00672
00673
00674
00675
00676
00677
00678 if (upperLevel != NULL)
00679 {
00680 newNode->rightNode = upperLevel->nextLevel;
00681 if (upperLevel->nextLevel != NULL)
00682 { upperLevel->nextLevel->leftNode = newNode; }
00683 upperLevel->nextLevel = newNode;
00684 return(newNode);
00685 }
00686
00687
00688
00689
00690
00691
00692
00693
00694 newNode->rightNode = FactData(theEnv)->CurrentDeftemplate->patternNetwork;
00695 if (FactData(theEnv)->CurrentDeftemplate->patternNetwork != NULL)
00696 { FactData(theEnv)->CurrentDeftemplate->patternNetwork->leftNode = newNode; }
00697
00698 FactData(theEnv)->CurrentDeftemplate->patternNetwork = newNode;
00699 return(newNode);
00700 }
00701
00702
00703
00704
00705
00706
00707
00708
00709
00710
00711
00712
00713
00714
00715
00716
00717
00718
00719
00720
00721
00722
00723
00724
00725
00726
00727 static void DetachFactPattern(
00728 void *theEnv,
00729 struct patternNodeHeader *thePattern)
00730 {
00731 struct factPatternNode *patternPtr;
00732 struct factPatternNode *upperLevel;
00733
00734
00735
00736
00737
00738 patternPtr = (struct factPatternNode *) thePattern;
00739 ClearPatternMatches(theEnv,patternPtr);
00740
00741
00742
00743
00744
00745
00746
00747
00748 if (patternPtr->header.entryJoin == NULL) patternPtr->header.stopNode = FALSE;
00749 if (patternPtr->nextLevel != NULL) return;
00750
00751
00752
00753
00754
00755 upperLevel = patternPtr;
00756 while (upperLevel != NULL)
00757 {
00758 if ((upperLevel->leftNode == NULL) &&
00759 (upperLevel->rightNode == NULL))
00760 {
00761
00762
00763
00764
00765
00766
00767
00768 patternPtr = upperLevel;
00769 upperLevel = patternPtr->lastLevel;
00770
00771 if (upperLevel == NULL)
00772 { FindAndSetDeftemplatePatternNetwork(theEnv,patternPtr,NULL); }
00773 else
00774 {
00775 if (upperLevel->header.selector)
00776 { RemoveHashedPatternNode(theEnv,upperLevel,patternPtr,patternPtr->networkTest->type,patternPtr->networkTest->value); }
00777
00778 upperLevel->nextLevel = NULL;
00779 if (upperLevel->header.stopNode) upperLevel = NULL;
00780 }
00781
00782 RemoveHashedExpression(theEnv,patternPtr->networkTest);
00783 RemoveHashedExpression(theEnv,patternPtr->header.rightHash);
00784 rtn_struct(theEnv,factPatternNode,patternPtr);
00785 }
00786 else if (upperLevel->leftNode != NULL)
00787 {
00788
00789
00790
00791
00792
00793
00794 patternPtr = upperLevel;
00795
00796 if ((patternPtr->lastLevel != NULL) &&
00797 (patternPtr->lastLevel->header.selector))
00798 { RemoveHashedPatternNode(theEnv,patternPtr->lastLevel,patternPtr,patternPtr->networkTest->type,patternPtr->networkTest->value); }
00799
00800 upperLevel->leftNode->rightNode = upperLevel->rightNode;
00801 if (upperLevel->rightNode != NULL)
00802 { upperLevel->rightNode->leftNode = upperLevel->leftNode; }
00803
00804 RemoveHashedExpression(theEnv,patternPtr->networkTest);
00805 RemoveHashedExpression(theEnv,patternPtr->header.rightHash);
00806 rtn_struct(theEnv,factPatternNode,patternPtr);
00807 upperLevel = NULL;
00808 }
00809 else
00810 {
00811
00812
00813
00814
00815
00816
00817 patternPtr = upperLevel;
00818 upperLevel = upperLevel->lastLevel;
00819 if (upperLevel == NULL)
00820 { FindAndSetDeftemplatePatternNetwork(theEnv,patternPtr,patternPtr->rightNode); }
00821 else
00822 {
00823 if (upperLevel->header.selector)
00824 { RemoveHashedPatternNode(theEnv,upperLevel,patternPtr,patternPtr->networkTest->type,patternPtr->networkTest->value); }
00825
00826 upperLevel->nextLevel = patternPtr->rightNode;
00827 }
00828 patternPtr->rightNode->leftNode = NULL;
00829
00830 RemoveHashedExpression(theEnv,patternPtr->networkTest);
00831 RemoveHashedExpression(theEnv,patternPtr->header.rightHash);
00832 rtn_struct(theEnv,factPatternNode,patternPtr);
00833 upperLevel = NULL;
00834 }
00835 }
00836 }
00837
00838 #endif
00839
00840
00841
00842
00843
00844 globle void DestroyFactPatternNetwork(
00845 void *theEnv,
00846 struct factPatternNode *thePattern)
00847 {
00848 struct factPatternNode *patternPtr;
00849
00850 if (thePattern == NULL) return;
00851
00852 while (thePattern != NULL)
00853 {
00854 patternPtr = thePattern->rightNode;
00855
00856 DestroyFactPatternNetwork(theEnv,thePattern->nextLevel);
00857
00858 DestroyAlphaMemory(theEnv,&thePattern->header,FALSE);
00859
00860 if ((thePattern->lastLevel != NULL) &&
00861 (thePattern->lastLevel->header.selector))
00862 { RemoveHashedPatternNode(theEnv,thePattern->lastLevel,thePattern,thePattern->networkTest->type,thePattern->networkTest->value); }
00863
00864 #if (! BLOAD_ONLY) && (! RUN_TIME)
00865 rtn_struct(theEnv,factPatternNode,thePattern);
00866 #endif
00867
00868 thePattern = patternPtr;
00869 }
00870 }
00871
00872 #if (! RUN_TIME) && (! BLOAD_ONLY)
00873
00874
00875
00876
00877
00878
00879
00880
00881
00882
00883
00884 static void FindAndSetDeftemplatePatternNetwork(
00885 void *theEnv,
00886 struct factPatternNode *rootNode,
00887 struct factPatternNode *newRootNode)
00888 {
00889 struct deftemplate *theDeftemplate;
00890 struct defmodule *theModule;
00891
00892
00893
00894
00895
00896 SaveCurrentModule(theEnv);
00897
00898
00899
00900
00901
00902
00903 for (theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,NULL);
00904 theModule != NULL;
00905 theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,theModule))
00906 {
00907
00908
00909
00910
00911 EnvSetCurrentModule(theEnv,(void *) theModule);
00912
00913
00914
00915
00916
00917
00918
00919 for (theDeftemplate = (struct deftemplate *) EnvGetNextDeftemplate(theEnv,NULL);
00920 theDeftemplate != NULL;
00921 theDeftemplate = (struct deftemplate *) EnvGetNextDeftemplate(theEnv,theDeftemplate))
00922 {
00923
00924
00925
00926
00927
00928
00929 if (theDeftemplate->patternNetwork == rootNode)
00930 {
00931 RestoreCurrentModule(theEnv);
00932 theDeftemplate->patternNetwork = newRootNode;
00933 return;
00934 }
00935 }
00936 }
00937
00938
00939
00940
00941
00942
00943
00944
00945 RestoreCurrentModule(theEnv);
00946 }
00947
00948
00949
00950
00951
00952
00953
00954
00955 static void ClearPatternMatches(
00956 void *theEnv,
00957 struct factPatternNode *patternPtr)
00958 {
00959 struct fact *theFact;
00960 struct patternMatch *lastMatch, *theMatch;
00961
00962
00963
00964
00965
00966 for (theFact = (struct fact *) EnvGetNextFact(theEnv,NULL);
00967 theFact != NULL;
00968 theFact = (struct fact *) EnvGetNextFact(theEnv,theFact))
00969 {
00970
00971
00972
00973
00974 lastMatch = NULL;
00975 theMatch = (struct patternMatch *) theFact->list;
00976
00977 while (theMatch != NULL)
00978 {
00979
00980
00981
00982
00983
00984 if (theMatch->matchingPattern == (struct patternNodeHeader *) patternPtr)
00985 {
00986 if (lastMatch == NULL)
00987 {
00988
00989
00990
00991
00992 theFact->list = (void *) theMatch->next;
00993 rtn_struct(theEnv,patternMatch,theMatch);
00994 theMatch = (struct patternMatch *) theFact->list;
00995 }
00996 else
00997 {
00998
00999
01000
01001
01002
01003 lastMatch->next = theMatch->next;
01004 rtn_struct(theEnv,patternMatch,theMatch);
01005 theMatch = lastMatch->next;
01006 }
01007 }
01008
01009
01010
01011
01012
01013
01014 else
01015 {
01016 lastMatch = theMatch;
01017 theMatch = theMatch->next;
01018 }
01019 }
01020 }
01021 }
01022
01023 #endif
01024
01025 #endif
01026
01027
01028