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
00029
00030
00031
00032
00033
00034
00035 #define _RULEBIN_SOURCE_
00036
00037 #include "setup.h"
00038
00039 #if DEFRULE_CONSTRUCT && (BLOAD || BLOAD_ONLY || BLOAD_AND_BSAVE) && (! RUN_TIME)
00040
00041 #include <stdio.h>
00042 #define _STDIO_INCLUDED_
00043 #include <string.h>
00044
00045 #include "memalloc.h"
00046 #include "bload.h"
00047 #include "bsave.h"
00048 #include "envrnmnt.h"
00049 #include "reteutil.h"
00050 #include "agenda.h"
00051 #include "engine.h"
00052 #include "retract.h"
00053 #include "rulebsc.h"
00054 #include "pattern.h"
00055 #include "moduldef.h"
00056
00057 #include "rulebin.h"
00058
00059
00060
00061
00062
00063 #if BLOAD_AND_BSAVE
00064 static void BsaveFind(void *);
00065 static void BsaveExpressions(void *,FILE *);
00066 static void BsaveStorage(void *,FILE *);
00067 static void BsaveBinaryItem(void *,FILE *);
00068 static void BsaveJoins(void *,FILE *);
00069 static void BsaveJoin(void *,FILE *,struct joinNode *);
00070 static void BsaveDisjuncts(void *,FILE *,struct defrule *);
00071 static void BsaveTraverseJoins(void *,FILE *,struct joinNode *);
00072 static void BsaveLinks(void *,FILE *);
00073 static void BsaveTraverseLinks(void *,FILE *,struct joinNode *);
00074 static void BsaveLink(FILE *,struct joinLink *);
00075 #endif
00076 static void BloadStorage(void *);
00077 static void BloadBinaryItem(void *);
00078 static void UpdateDefruleModule(void *,void *,long);
00079 static void UpdateDefrule(void *,void *,long);
00080 static void UpdateJoin(void *,void *,long);
00081 static void UpdateLink(void *,void *,long);
00082 static void ClearBload(void *);
00083 static void DeallocateDefruleBloadData(void *);
00084
00085
00086
00087
00088
00089 globle void DefruleBinarySetup(
00090 void *theEnv)
00091 {
00092 AllocateEnvironmentData(theEnv,RULEBIN_DATA,sizeof(struct defruleBinaryData),DeallocateDefruleBloadData);
00093
00094 #if BLOAD_AND_BSAVE
00095 AddBinaryItem(theEnv,"defrule",20,BsaveFind,BsaveExpressions,
00096 BsaveStorage,BsaveBinaryItem,
00097 BloadStorage,BloadBinaryItem,
00098 ClearBload);
00099 #endif
00100 #if BLOAD || BLOAD_ONLY
00101 AddBinaryItem(theEnv,"defrule",20,NULL,NULL,NULL,NULL,
00102 BloadStorage,BloadBinaryItem,
00103 ClearBload);
00104 #endif
00105 }
00106
00107
00108
00109
00110
00111 static void DeallocateDefruleBloadData(
00112 void *theEnv)
00113 {
00114 #if (BLOAD || BLOAD_ONLY || BLOAD_AND_BSAVE) && (! RUN_TIME)
00115 size_t space;
00116 long i;
00117 struct defruleModule *theModuleItem;
00118 struct activation *theActivation, *tmpActivation;
00119 struct salienceGroup *theGroup, *tmpGroup;
00120
00121 for (i = 0; i < DefruleBinaryData(theEnv)->NumberOfJoins; i++)
00122 {
00123 DestroyBetaMemory(theEnv,&DefruleBinaryData(theEnv)->JoinArray[i],LHS);
00124 DestroyBetaMemory(theEnv,&DefruleBinaryData(theEnv)->JoinArray[i],RHS);
00125 ReturnLeftMemory(theEnv,&DefruleBinaryData(theEnv)->JoinArray[i]);
00126 ReturnRightMemory(theEnv,&DefruleBinaryData(theEnv)->JoinArray[i]);
00127 }
00128
00129 for (i = 0; i < DefruleBinaryData(theEnv)->NumberOfDefruleModules; i++)
00130 {
00131 theModuleItem = &DefruleBinaryData(theEnv)->ModuleArray[i];
00132
00133 theActivation = theModuleItem->agenda;
00134 while (theActivation != NULL)
00135 {
00136 tmpActivation = theActivation->next;
00137
00138 rtn_struct(theEnv,activation,theActivation);
00139
00140 theActivation = tmpActivation;
00141 }
00142
00143 theGroup = theModuleItem->groupings;
00144 while (theGroup != NULL)
00145 {
00146 tmpGroup = theGroup->next;
00147
00148 rtn_struct(theEnv,salienceGroup,theGroup);
00149
00150 theGroup = tmpGroup;
00151 }
00152 }
00153
00154 space = DefruleBinaryData(theEnv)->NumberOfDefruleModules * sizeof(struct defruleModule);
00155 if (space != 0) genfree(theEnv,(void *) DefruleBinaryData(theEnv)->ModuleArray,space);
00156
00157 space = DefruleBinaryData(theEnv)->NumberOfDefrules * sizeof(struct defrule);
00158 if (space != 0) genfree(theEnv,(void *) DefruleBinaryData(theEnv)->DefruleArray,space);
00159
00160 space = DefruleBinaryData(theEnv)->NumberOfJoins * sizeof(struct joinNode);
00161 if (space != 0) genfree(theEnv,(void *) DefruleBinaryData(theEnv)->JoinArray,space);
00162
00163 space = DefruleBinaryData(theEnv)->NumberOfLinks * sizeof(struct joinLink);
00164 if (space != 0) genfree(theEnv,(void *) DefruleBinaryData(theEnv)->LinkArray,space);
00165
00166 if (Bloaded(theEnv))
00167 { rm3(theEnv,DefruleData(theEnv)->AlphaMemoryTable,sizeof(ALPHA_MEMORY_HASH *) * ALPHA_MEMORY_HASH_SIZE); }
00168 #endif
00169 }
00170
00171 #if BLOAD_AND_BSAVE
00172
00173
00174
00175
00176
00177
00178 static void BsaveFind(
00179 void *theEnv)
00180 {
00181 struct defrule *theDefrule, *theDisjunct;
00182 struct defmodule *theModule;
00183
00184
00185
00186
00187
00188
00189
00190 SaveBloadCount(theEnv,DefruleBinaryData(theEnv)->NumberOfDefruleModules);
00191 SaveBloadCount(theEnv,DefruleBinaryData(theEnv)->NumberOfDefrules);
00192 SaveBloadCount(theEnv,DefruleBinaryData(theEnv)->NumberOfJoins);
00193 SaveBloadCount(theEnv,DefruleBinaryData(theEnv)->NumberOfLinks);
00194
00195
00196
00197
00198
00199
00200 TagRuleNetwork(theEnv,&DefruleBinaryData(theEnv)->NumberOfDefruleModules,
00201 &DefruleBinaryData(theEnv)->NumberOfDefrules,
00202 &DefruleBinaryData(theEnv)->NumberOfJoins,
00203 &DefruleBinaryData(theEnv)->NumberOfLinks);
00204
00205
00206
00207
00208
00209 for (theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,NULL);
00210 theModule != NULL;
00211 theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,theModule))
00212 {
00213
00214
00215
00216
00217
00218 EnvSetCurrentModule(theEnv,(void *) theModule);
00219
00220
00221
00222
00223
00224 for (theDefrule = (struct defrule *) EnvGetNextDefrule(theEnv,NULL);
00225 theDefrule != NULL;
00226 theDefrule = (struct defrule *) EnvGetNextDefrule(theEnv,theDefrule))
00227 {
00228
00229
00230
00231
00232
00233 MarkConstructHeaderNeededItems(&theDefrule->header,theDefrule->header.bsaveID);
00234
00235
00236
00237
00238
00239
00240 ExpressionData(theEnv)->ExpressionCount += ExpressionSize(theDefrule->dynamicSalience);
00241 MarkNeededItems(theEnv,theDefrule->dynamicSalience);
00242
00243
00244
00245
00246
00247
00248
00249 for (theDisjunct = theDefrule;
00250 theDisjunct != NULL;
00251 theDisjunct = theDisjunct->disjunct)
00252 {
00253 ExpressionData(theEnv)->ExpressionCount += ExpressionSize(theDisjunct->actions);
00254 MarkNeededItems(theEnv,theDisjunct->actions);
00255 }
00256 }
00257 }
00258
00259
00260
00261
00262
00263
00264 MarkRuleNetwork(theEnv,1);
00265 }
00266
00267
00268
00269
00270
00271 static void BsaveExpressions(
00272 void *theEnv,
00273 FILE *fp)
00274 {
00275 struct defrule *theDefrule, *theDisjunct;
00276 struct defmodule *theModule;
00277
00278
00279
00280
00281
00282 for (theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,NULL);
00283 theModule != NULL;
00284 theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,theModule))
00285 {
00286
00287
00288
00289
00290 EnvSetCurrentModule(theEnv,(void *) theModule);
00291
00292
00293
00294
00295
00296 for (theDefrule = (struct defrule *) EnvGetNextDefrule(theEnv,NULL);
00297 theDefrule != NULL;
00298 theDefrule = (struct defrule *) EnvGetNextDefrule(theEnv,theDefrule))
00299 {
00300
00301
00302
00303
00304 BsaveExpression(theEnv,theDefrule->dynamicSalience,fp);
00305
00306
00307
00308
00309
00310
00311 for (theDisjunct = theDefrule;
00312 theDisjunct != NULL;
00313 theDisjunct = theDisjunct->disjunct)
00314 { BsaveExpression(theEnv,theDisjunct->actions,fp); }
00315 }
00316 }
00317
00318
00319
00320
00321
00322
00323 MarkRuleNetwork(theEnv,1);
00324 }
00325
00326
00327
00328
00329
00330 static void BsaveStorage(
00331 void *theEnv,
00332 FILE *fp)
00333 {
00334 size_t space;
00335 long int value;
00336
00337 space = sizeof(long) * 5;
00338 GenWrite(&space,sizeof(size_t),fp);
00339 GenWrite(&DefruleBinaryData(theEnv)->NumberOfDefruleModules,sizeof(long int),fp);
00340 GenWrite(&DefruleBinaryData(theEnv)->NumberOfDefrules,sizeof(long int),fp);
00341 GenWrite(&DefruleBinaryData(theEnv)->NumberOfJoins,sizeof(long int),fp);
00342 GenWrite(&DefruleBinaryData(theEnv)->NumberOfLinks,sizeof(long int),fp);
00343
00344 if (DefruleData(theEnv)->RightPrimeJoins == NULL)
00345 { value = -1; }
00346 else
00347 { value = DefruleData(theEnv)->RightPrimeJoins->bsaveID; }
00348
00349 GenWrite(&value,sizeof(long int),fp);
00350
00351 if (DefruleData(theEnv)->LeftPrimeJoins == NULL)
00352 { value = -1; }
00353 else
00354 { value = DefruleData(theEnv)->LeftPrimeJoins->bsaveID; }
00355
00356 GenWrite(&value,sizeof(long int),fp);
00357 }
00358
00359
00360
00361
00362
00363 static void BsaveBinaryItem(
00364 void *theEnv,
00365 FILE *fp)
00366 {
00367 size_t space;
00368 struct defrule *theDefrule;
00369 struct defmodule *theModule;
00370 struct defruleModule *theModuleItem;
00371 struct bsaveDefruleModule tempDefruleModule;
00372
00373
00374
00375
00376
00377 space = (DefruleBinaryData(theEnv)->NumberOfDefrules * sizeof(struct bsaveDefrule)) +
00378 (DefruleBinaryData(theEnv)->NumberOfJoins * sizeof(struct bsaveJoinNode)) +
00379 (DefruleBinaryData(theEnv)->NumberOfLinks * sizeof(struct bsaveJoinLink)) +
00380 (DefruleBinaryData(theEnv)->NumberOfDefruleModules * sizeof(struct bsaveDefruleModule));
00381 GenWrite(&space,sizeof(size_t),fp);
00382
00383
00384
00385
00386
00387 DefruleBinaryData(theEnv)->NumberOfDefrules = 0;
00388 for (theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,NULL);
00389 theModule != NULL;
00390 theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,theModule))
00391 {
00392 EnvSetCurrentModule(theEnv,(void *) theModule);
00393
00394 theModuleItem = (struct defruleModule *)
00395 GetModuleItem(theEnv,NULL,FindModuleItem(theEnv,"defrule")->moduleIndex);
00396 AssignBsaveDefmdlItemHdrVals(&tempDefruleModule.header,
00397 &theModuleItem->header);
00398 GenWrite(&tempDefruleModule,sizeof(struct bsaveDefruleModule),fp);
00399 }
00400
00401
00402
00403
00404
00405 for (theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,NULL);
00406 theModule != NULL;
00407 theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,theModule))
00408 {
00409 EnvSetCurrentModule(theEnv,(void *) theModule);
00410
00411 for (theDefrule = (struct defrule *) EnvGetNextDefrule(theEnv,NULL);
00412 theDefrule != NULL;
00413 theDefrule = (struct defrule *) EnvGetNextDefrule(theEnv,theDefrule))
00414 { BsaveDisjuncts(theEnv,fp,theDefrule); }
00415 }
00416
00417
00418
00419
00420
00421 MarkRuleNetwork(theEnv,1);
00422 BsaveJoins(theEnv,fp);
00423
00424
00425
00426
00427
00428 MarkRuleNetwork(theEnv,1);
00429 BsaveLinks(theEnv,fp);
00430
00431
00432
00433
00434
00435
00436
00437
00438 RestoreBloadCount(theEnv,&DefruleBinaryData(theEnv)->NumberOfDefruleModules);
00439 RestoreBloadCount(theEnv,&DefruleBinaryData(theEnv)->NumberOfDefrules);
00440 RestoreBloadCount(theEnv,&DefruleBinaryData(theEnv)->NumberOfJoins);
00441 RestoreBloadCount(theEnv,&DefruleBinaryData(theEnv)->NumberOfLinks);
00442 }
00443
00444
00445
00446
00447
00448 static void BsaveDisjuncts(
00449 void *theEnv,
00450 FILE *fp,
00451 struct defrule *theDefrule)
00452 {
00453 struct defrule *theDisjunct;
00454 struct bsaveDefrule tempDefrule;
00455 long int disjunctExpressionCount = 0L;
00456 int first;
00457
00458
00459
00460
00461
00462 for (theDisjunct = theDefrule, first = TRUE;
00463 theDisjunct != NULL;
00464 theDisjunct = theDisjunct->disjunct, first = FALSE)
00465 {
00466 DefruleBinaryData(theEnv)->NumberOfDefrules++;
00467
00468
00469
00470
00471
00472 AssignBsaveConstructHeaderVals(&tempDefrule.header,
00473 &theDisjunct->header);
00474 tempDefrule.salience = theDisjunct->salience;
00475 tempDefrule.localVarCnt = theDisjunct->localVarCnt;
00476 tempDefrule.complexity = theDisjunct->complexity;
00477 tempDefrule.autoFocus = theDisjunct->autoFocus;
00478
00479
00480
00481
00482
00483 if (theDisjunct->dynamicSalience != NULL)
00484 {
00485 if (first)
00486 {
00487 tempDefrule.dynamicSalience = ExpressionData(theEnv)->ExpressionCount;
00488 disjunctExpressionCount = ExpressionData(theEnv)->ExpressionCount;
00489 ExpressionData(theEnv)->ExpressionCount += ExpressionSize(theDisjunct->dynamicSalience);
00490 }
00491 else
00492 { tempDefrule.dynamicSalience = disjunctExpressionCount; }
00493 }
00494 else
00495 { tempDefrule.dynamicSalience = -1L; }
00496
00497
00498
00499
00500
00501 if (theDisjunct->actions != NULL)
00502 {
00503 tempDefrule.actions = ExpressionData(theEnv)->ExpressionCount;
00504 ExpressionData(theEnv)->ExpressionCount += ExpressionSize(theDisjunct->actions);
00505 }
00506 else
00507 { tempDefrule.actions = -1L; }
00508
00509
00510
00511
00512
00513
00514 tempDefrule.logicalJoin = BsaveJoinIndex(theDisjunct->logicalJoin);
00515 tempDefrule.lastJoin = BsaveJoinIndex(theDisjunct->lastJoin);
00516
00517
00518
00519
00520
00521 if (theDisjunct->disjunct != NULL)
00522 { tempDefrule.disjunct = DefruleBinaryData(theEnv)->NumberOfDefrules; }
00523 else
00524 { tempDefrule.disjunct = -1L; }
00525
00526
00527
00528
00529
00530 GenWrite(&tempDefrule,sizeof(struct bsaveDefrule),fp);
00531 }
00532 }
00533
00534
00535
00536
00537
00538 static void BsaveJoins(
00539 void *theEnv,
00540 FILE *fp)
00541 {
00542 struct defrule *rulePtr;
00543 struct defmodule *theModule;
00544
00545
00546
00547
00548
00549 for (theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,NULL);
00550 theModule != NULL;
00551 theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,theModule))
00552 {
00553 EnvSetCurrentModule(theEnv,(void *) theModule);
00554
00555
00556
00557
00558
00559 rulePtr = (struct defrule *) EnvGetNextDefrule(theEnv,NULL);
00560 while (rulePtr != NULL)
00561 {
00562
00563
00564
00565
00566 BsaveTraverseJoins(theEnv,fp,rulePtr->lastJoin);
00567
00568
00569
00570
00571
00572 if (rulePtr->disjunct != NULL) rulePtr = rulePtr->disjunct;
00573 else rulePtr = (struct defrule *) EnvGetNextDefrule(theEnv,rulePtr);
00574 }
00575 }
00576 }
00577
00578
00579
00580
00581 static void BsaveTraverseJoins(
00582 void *theEnv,
00583 FILE *fp,
00584 struct joinNode *joinPtr)
00585 {
00586 for (;
00587 joinPtr != NULL;
00588 joinPtr = joinPtr->lastLevel)
00589 {
00590 if (joinPtr->marked) BsaveJoin(theEnv,fp,joinPtr);
00591
00592 if (joinPtr->joinFromTheRight)
00593 { BsaveTraverseJoins(theEnv,fp,(struct joinNode *) joinPtr->rightSideEntryStructure); }
00594 }
00595 }
00596
00597
00598
00599
00600
00601 static void BsaveJoin(
00602 void *theEnv,
00603 FILE *fp,
00604 struct joinNode *joinPtr)
00605 {
00606 struct bsaveJoinNode tempJoin;
00607
00608 joinPtr->marked = 0;
00609 tempJoin.depth = joinPtr->depth;
00610 tempJoin.rhsType = joinPtr->rhsType;
00611 tempJoin.firstJoin = joinPtr->firstJoin;
00612 tempJoin.logicalJoin = joinPtr->logicalJoin;
00613 tempJoin.joinFromTheRight = joinPtr->joinFromTheRight;
00614 tempJoin.patternIsNegated = joinPtr->patternIsNegated;
00615 tempJoin.patternIsExists = joinPtr->patternIsExists;
00616
00617 if (joinPtr->joinFromTheRight)
00618 { tempJoin.rightSideEntryStructure = BsaveJoinIndex(joinPtr->rightSideEntryStructure); }
00619 else
00620 { tempJoin.rightSideEntryStructure = -1L; }
00621
00622 tempJoin.lastLevel = BsaveJoinIndex(joinPtr->lastLevel);
00623 tempJoin.nextLinks = BsaveJoinLinkIndex(joinPtr->nextLinks);
00624 tempJoin.rightMatchNode = BsaveJoinIndex(joinPtr->rightMatchNode);
00625 tempJoin.networkTest = HashedExpressionIndex(theEnv,joinPtr->networkTest);
00626 tempJoin.secondaryNetworkTest = HashedExpressionIndex(theEnv,joinPtr->secondaryNetworkTest);
00627 tempJoin.leftHash = HashedExpressionIndex(theEnv,joinPtr->leftHash);
00628 tempJoin.rightHash = HashedExpressionIndex(theEnv,joinPtr->rightHash);
00629
00630 if (joinPtr->ruleToActivate != NULL)
00631 {
00632 tempJoin.ruleToActivate =
00633 GetDisjunctIndex(joinPtr->ruleToActivate);
00634 }
00635 else
00636 { tempJoin.ruleToActivate = -1L; }
00637
00638 GenWrite(&tempJoin,(unsigned long) sizeof(struct bsaveJoinNode),fp);
00639 }
00640
00641
00642
00643
00644
00645 static void BsaveLinks(
00646 void *theEnv,
00647 FILE *fp)
00648 {
00649 struct defrule *rulePtr;
00650 struct defmodule *theModule;
00651 struct joinLink *theLink;
00652
00653 for (theLink = DefruleData(theEnv)->LeftPrimeJoins;
00654 theLink != NULL;
00655 theLink = theLink->next)
00656 { BsaveLink(fp,theLink); }
00657
00658 for (theLink = DefruleData(theEnv)->RightPrimeJoins;
00659 theLink != NULL;
00660 theLink = theLink->next)
00661 { BsaveLink(fp,theLink); }
00662
00663
00664
00665
00666
00667 for (theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,NULL);
00668 theModule != NULL;
00669 theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,theModule))
00670 {
00671 EnvSetCurrentModule(theEnv,(void *) theModule);
00672
00673
00674
00675
00676
00677 rulePtr = (struct defrule *) EnvGetNextDefrule(theEnv,NULL);
00678 while (rulePtr != NULL)
00679 {
00680
00681
00682
00683
00684 BsaveTraverseLinks(theEnv,fp,rulePtr->lastJoin);
00685
00686
00687
00688
00689
00690 if (rulePtr->disjunct != NULL) rulePtr = rulePtr->disjunct;
00691 else rulePtr = (struct defrule *) EnvGetNextDefrule(theEnv,rulePtr);
00692 }
00693 }
00694 }
00695
00696
00697
00698
00699
00700 static void BsaveTraverseLinks(
00701 void *theEnv,
00702 FILE *fp,
00703 struct joinNode *joinPtr)
00704 {
00705 struct joinLink *theLink;
00706
00707 for (;
00708 joinPtr != NULL;
00709 joinPtr = joinPtr->lastLevel)
00710 {
00711 if (joinPtr->marked)
00712 {
00713 for (theLink = joinPtr->nextLinks;
00714 theLink != NULL;
00715 theLink = theLink->next)
00716 { BsaveLink(fp,theLink); }
00717
00718 joinPtr->marked = 0;
00719 }
00720
00721 if (joinPtr->joinFromTheRight)
00722 { BsaveTraverseLinks(theEnv,fp,(struct joinNode *) joinPtr->rightSideEntryStructure); }
00723 }
00724 }
00725
00726
00727
00728
00729
00730 static void BsaveLink(
00731 FILE *fp,
00732 struct joinLink *linkPtr)
00733 {
00734 struct bsaveJoinLink tempLink;
00735
00736 tempLink.enterDirection = linkPtr->enterDirection;
00737 tempLink.join = BsaveJoinIndex(linkPtr->join);
00738 tempLink.next = BsaveJoinLinkIndex(linkPtr->next);
00739
00740 GenWrite(&tempLink,(unsigned long) sizeof(struct bsaveJoinLink),fp);
00741 }
00742
00743
00744
00745
00746
00747 globle void AssignBsavePatternHeaderValues(
00748 void *theEnv,
00749 struct bsavePatternNodeHeader *theBsaveHeader,
00750 struct patternNodeHeader *theHeader)
00751 {
00752 theBsaveHeader->multifieldNode = theHeader->multifieldNode;
00753 theBsaveHeader->entryJoin = BsaveJoinIndex(theHeader->entryJoin);
00754 theBsaveHeader->rightHash = HashedExpressionIndex(theEnv,theHeader->rightHash);
00755 theBsaveHeader->singlefieldNode = theHeader->singlefieldNode;
00756 theBsaveHeader->stopNode = theHeader->stopNode;
00757 theBsaveHeader->beginSlot = theHeader->beginSlot;
00758 theBsaveHeader->endSlot = theHeader->endSlot;
00759 theBsaveHeader->selector = theHeader->selector;
00760 }
00761
00762 #endif
00763
00764
00765
00766
00767
00768 static void BloadStorage(
00769 void *theEnv)
00770 {
00771 size_t space;
00772
00773
00774
00775
00776
00777
00778 GenReadBinary(theEnv,&space,sizeof(size_t));
00779 GenReadBinary(theEnv,&DefruleBinaryData(theEnv)->NumberOfDefruleModules,sizeof(long int));
00780 GenReadBinary(theEnv,&DefruleBinaryData(theEnv)->NumberOfDefrules,sizeof(long int));
00781 GenReadBinary(theEnv,&DefruleBinaryData(theEnv)->NumberOfJoins,sizeof(long int));
00782 GenReadBinary(theEnv,&DefruleBinaryData(theEnv)->NumberOfLinks,sizeof(long int));
00783 GenReadBinary(theEnv,&DefruleBinaryData(theEnv)->RightPrimeIndex,sizeof(long int));
00784 GenReadBinary(theEnv,&DefruleBinaryData(theEnv)->LeftPrimeIndex,sizeof(long int));
00785
00786
00787
00788
00789
00790
00791 if (DefruleBinaryData(theEnv)->NumberOfDefruleModules == 0)
00792 {
00793 DefruleBinaryData(theEnv)->ModuleArray = NULL;
00794 DefruleBinaryData(theEnv)->DefruleArray = NULL;
00795 DefruleBinaryData(theEnv)->JoinArray = NULL;
00796 }
00797
00798 space = DefruleBinaryData(theEnv)->NumberOfDefruleModules * sizeof(struct defruleModule);
00799 DefruleBinaryData(theEnv)->ModuleArray = (struct defruleModule *) genalloc(theEnv,space);
00800
00801
00802
00803
00804
00805
00806 if (DefruleBinaryData(theEnv)->NumberOfDefrules == 0)
00807 {
00808 DefruleBinaryData(theEnv)->DefruleArray = NULL;
00809 DefruleBinaryData(theEnv)->JoinArray = NULL;
00810 return;
00811 }
00812
00813 space = DefruleBinaryData(theEnv)->NumberOfDefrules * sizeof(struct defrule);
00814 DefruleBinaryData(theEnv)->DefruleArray = (struct defrule *) genalloc(theEnv,space);
00815
00816
00817
00818
00819
00820
00821 space = DefruleBinaryData(theEnv)->NumberOfJoins * sizeof(struct joinNode);
00822 DefruleBinaryData(theEnv)->JoinArray = (struct joinNode *) genalloc(theEnv,space);
00823
00824
00825
00826
00827
00828
00829 space = DefruleBinaryData(theEnv)->NumberOfLinks * sizeof(struct joinLink);
00830 DefruleBinaryData(theEnv)->LinkArray = (struct joinLink *) genalloc(theEnv,space);
00831 }
00832
00833
00834
00835
00836
00837 static void BloadBinaryItem(
00838 void *theEnv)
00839 {
00840 size_t space;
00841
00842
00843
00844
00845
00846
00847
00848 GenReadBinary(theEnv,&space,sizeof(size_t));
00849
00850
00851
00852
00853
00854
00855 BloadandRefresh(theEnv,DefruleBinaryData(theEnv)->NumberOfDefruleModules,
00856 sizeof(struct bsaveDefruleModule),UpdateDefruleModule);
00857
00858
00859
00860
00861
00862
00863 BloadandRefresh(theEnv,DefruleBinaryData(theEnv)->NumberOfDefrules,
00864 sizeof(struct bsaveDefrule),UpdateDefrule);
00865
00866
00867
00868
00869
00870
00871 BloadandRefresh(theEnv,DefruleBinaryData(theEnv)->NumberOfJoins,
00872 sizeof(struct bsaveJoinNode),UpdateJoin);
00873
00874
00875
00876
00877
00878
00879 BloadandRefresh(theEnv,DefruleBinaryData(theEnv)->NumberOfLinks,
00880 sizeof(struct bsaveJoinLink),UpdateLink);
00881
00882 DefruleData(theEnv)->RightPrimeJoins = BloadJoinLinkPointer(DefruleBinaryData(theEnv)->RightPrimeIndex);
00883 DefruleData(theEnv)->LeftPrimeJoins = BloadJoinLinkPointer(DefruleBinaryData(theEnv)->LeftPrimeIndex);
00884 }
00885
00886
00887
00888
00889
00890 static void UpdateDefruleModule(
00891 void *theEnv,
00892 void *buf,
00893 long obji)
00894 {
00895 struct bsaveDefruleModule *bdmPtr;
00896
00897 bdmPtr = (struct bsaveDefruleModule *) buf;
00898 UpdateDefmoduleItemHeader(theEnv,&bdmPtr->header,&DefruleBinaryData(theEnv)->ModuleArray[obji].header,
00899 (int) sizeof(struct defrule),
00900 (void *) DefruleBinaryData(theEnv)->DefruleArray);
00901 DefruleBinaryData(theEnv)->ModuleArray[obji].agenda = NULL;
00902 DefruleBinaryData(theEnv)->ModuleArray[obji].groupings = NULL;
00903
00904 }
00905
00906
00907
00908
00909
00910 static void UpdateDefrule(
00911 void *theEnv,
00912 void *buf,
00913 long obji)
00914 {
00915 struct bsaveDefrule *br;
00916
00917 br = (struct bsaveDefrule *) buf;
00918 UpdateConstructHeader(theEnv,&br->header,&DefruleBinaryData(theEnv)->DefruleArray[obji].header,
00919 (int) sizeof(struct defruleModule),(void *) DefruleBinaryData(theEnv)->ModuleArray,
00920 (int) sizeof(struct defrule),(void *) DefruleBinaryData(theEnv)->DefruleArray);
00921
00922 DefruleBinaryData(theEnv)->DefruleArray[obji].dynamicSalience = ExpressionPointer(br->dynamicSalience);
00923
00924 DefruleBinaryData(theEnv)->DefruleArray[obji].actions = ExpressionPointer(br->actions);
00925 DefruleBinaryData(theEnv)->DefruleArray[obji].logicalJoin = BloadJoinPointer(br->logicalJoin);
00926 DefruleBinaryData(theEnv)->DefruleArray[obji].lastJoin = BloadJoinPointer(br->lastJoin);
00927 DefruleBinaryData(theEnv)->DefruleArray[obji].disjunct = BloadDefrulePointer(DefruleBinaryData(theEnv)->DefruleArray,br->disjunct);
00928 DefruleBinaryData(theEnv)->DefruleArray[obji].salience = br->salience;
00929 DefruleBinaryData(theEnv)->DefruleArray[obji].localVarCnt = br->localVarCnt;
00930 DefruleBinaryData(theEnv)->DefruleArray[obji].complexity = br->complexity;
00931 DefruleBinaryData(theEnv)->DefruleArray[obji].autoFocus = br->autoFocus;
00932 DefruleBinaryData(theEnv)->DefruleArray[obji].executing = 0;
00933 DefruleBinaryData(theEnv)->DefruleArray[obji].afterBreakpoint = 0;
00934 #if DEBUGGING_FUNCTIONS
00935 DefruleBinaryData(theEnv)->DefruleArray[obji].watchActivation = AgendaData(theEnv)->WatchActivations;
00936 DefruleBinaryData(theEnv)->DefruleArray[obji].watchFiring = DefruleData(theEnv)->WatchRules;
00937 #endif
00938 }
00939
00940
00941
00942
00943
00944 static void UpdateJoin(
00945 void *theEnv,
00946 void *buf,
00947 long obji)
00948 {
00949 struct bsaveJoinNode *bj;
00950
00951 bj = (struct bsaveJoinNode *) buf;
00952 DefruleBinaryData(theEnv)->JoinArray[obji].firstJoin = bj->firstJoin;
00953 DefruleBinaryData(theEnv)->JoinArray[obji].logicalJoin = bj->logicalJoin;
00954 DefruleBinaryData(theEnv)->JoinArray[obji].joinFromTheRight = bj->joinFromTheRight;
00955 DefruleBinaryData(theEnv)->JoinArray[obji].patternIsNegated = bj->patternIsNegated;
00956 DefruleBinaryData(theEnv)->JoinArray[obji].patternIsExists = bj->patternIsExists;
00957 DefruleBinaryData(theEnv)->JoinArray[obji].depth = bj->depth;
00958 DefruleBinaryData(theEnv)->JoinArray[obji].rhsType = bj->rhsType;
00959 DefruleBinaryData(theEnv)->JoinArray[obji].networkTest = HashedExpressionPointer(bj->networkTest);
00960 DefruleBinaryData(theEnv)->JoinArray[obji].secondaryNetworkTest = HashedExpressionPointer(bj->secondaryNetworkTest);
00961 DefruleBinaryData(theEnv)->JoinArray[obji].leftHash = HashedExpressionPointer(bj->leftHash);
00962 DefruleBinaryData(theEnv)->JoinArray[obji].rightHash = HashedExpressionPointer(bj->rightHash);
00963 DefruleBinaryData(theEnv)->JoinArray[obji].nextLinks = BloadJoinLinkPointer(bj->nextLinks);
00964 DefruleBinaryData(theEnv)->JoinArray[obji].lastLevel = BloadJoinPointer(bj->lastLevel);
00965
00966 if (bj->joinFromTheRight == TRUE)
00967 { DefruleBinaryData(theEnv)->JoinArray[obji].rightSideEntryStructure = (void *) BloadJoinPointer(bj->rightSideEntryStructure); }
00968 else
00969 { DefruleBinaryData(theEnv)->JoinArray[obji].rightSideEntryStructure = NULL; }
00970
00971 DefruleBinaryData(theEnv)->JoinArray[obji].rightMatchNode = BloadJoinPointer(bj->rightMatchNode);
00972 DefruleBinaryData(theEnv)->JoinArray[obji].ruleToActivate = BloadDefrulePointer(DefruleBinaryData(theEnv)->DefruleArray,bj->ruleToActivate);
00973 DefruleBinaryData(theEnv)->JoinArray[obji].initialize = 0;
00974 DefruleBinaryData(theEnv)->JoinArray[obji].marked = 0;
00975 DefruleBinaryData(theEnv)->JoinArray[obji].bsaveID = 0L;
00976 DefruleBinaryData(theEnv)->JoinArray[obji].leftMemory = NULL;
00977 DefruleBinaryData(theEnv)->JoinArray[obji].rightMemory = NULL;
00978
00979 AddBetaMemoriesToJoin(theEnv,&DefruleBinaryData(theEnv)->JoinArray[obji]);
00980 }
00981
00982
00983
00984
00985
00986 static void UpdateLink(
00987 void *theEnv,
00988 void *buf,
00989 long obji)
00990 {
00991 struct bsaveJoinLink *bj;
00992
00993 bj = (struct bsaveJoinLink *) buf;
00994 DefruleBinaryData(theEnv)->LinkArray[obji].enterDirection = bj->enterDirection;
00995 DefruleBinaryData(theEnv)->LinkArray[obji].next = BloadJoinLinkPointer(bj->next);
00996 DefruleBinaryData(theEnv)->LinkArray[obji].join = BloadJoinPointer(bj->join);
00997 }
00998
00999
01000
01001
01002
01003 globle void UpdatePatternNodeHeader(
01004 void *theEnv,
01005 struct patternNodeHeader *theHeader,
01006 struct bsavePatternNodeHeader *theBsaveHeader)
01007 {
01008 struct joinNode *theJoin;
01009
01010 theHeader->singlefieldNode = theBsaveHeader->singlefieldNode;
01011 theHeader->multifieldNode = theBsaveHeader->multifieldNode;
01012 theHeader->stopNode = theBsaveHeader->stopNode;
01013 theHeader->beginSlot = theBsaveHeader->beginSlot;
01014 theHeader->endSlot = theBsaveHeader->endSlot;
01015 theHeader->selector = theBsaveHeader->selector;
01016 theHeader->initialize = 0;
01017 theHeader->marked = 0;
01018 theHeader->firstHash = NULL;
01019 theHeader->lastHash = NULL;
01020 theHeader->rightHash = HashedExpressionPointer(theBsaveHeader->rightHash);
01021
01022 theJoin = BloadJoinPointer(theBsaveHeader->entryJoin);
01023 theHeader->entryJoin = theJoin;
01024
01025 while (theJoin != NULL)
01026 {
01027 theJoin->rightSideEntryStructure = (void *) theHeader;
01028 theJoin = theJoin->rightMatchNode;
01029 }
01030 }
01031
01032
01033
01034
01035
01036 static void ClearBload(
01037 void *theEnv)
01038 {
01039 size_t space;
01040 long i;
01041 struct patternParser *theParser = NULL;
01042 struct patternEntity *theEntity = NULL;
01043 void *theModule;
01044
01045
01046
01047
01048
01049
01050 GetNextPatternEntity(theEnv,&theParser,&theEntity);
01051 while (theEntity != NULL)
01052 {
01053 (*theEntity->theInfo->base.deleteFunction)(theEnv,theEntity);
01054 theEntity = NULL;
01055 GetNextPatternEntity(theEnv,&theParser,&theEntity);
01056 }
01057
01058
01059
01060
01061
01062 SaveCurrentModule(theEnv);
01063 for (theModule = EnvGetNextDefmodule(theEnv,NULL);
01064 theModule != NULL;
01065 theModule = EnvGetNextDefmodule(theEnv,theModule))
01066 {
01067 EnvSetCurrentModule(theEnv,theModule);
01068 RemoveAllActivations(theEnv);
01069 }
01070 RestoreCurrentModule(theEnv);
01071 EnvClearFocusStack(theEnv);
01072
01073
01074
01075
01076
01077
01078
01079 for (i = 0; i < DefruleBinaryData(theEnv)->NumberOfJoins; i++)
01080 {
01081 FlushBetaMemory(theEnv,&DefruleBinaryData(theEnv)->JoinArray[i],LHS);
01082 ReturnLeftMemory(theEnv,&DefruleBinaryData(theEnv)->JoinArray[i]);
01083 FlushBetaMemory(theEnv,&DefruleBinaryData(theEnv)->JoinArray[i],RHS);
01084 ReturnRightMemory(theEnv,&DefruleBinaryData(theEnv)->JoinArray[i]);
01085 }
01086
01087
01088
01089
01090
01091 for (i = 0; i < DefruleBinaryData(theEnv)->NumberOfDefrules; i++)
01092 { UnmarkConstructHeader(theEnv,&DefruleBinaryData(theEnv)->DefruleArray[i].header); }
01093
01094
01095
01096
01097
01098 space = DefruleBinaryData(theEnv)->NumberOfDefruleModules * sizeof(struct defruleModule);
01099 if (space != 0) genfree(theEnv,(void *) DefruleBinaryData(theEnv)->ModuleArray,space);
01100 DefruleBinaryData(theEnv)->NumberOfDefruleModules = 0;
01101
01102 space = DefruleBinaryData(theEnv)->NumberOfDefrules * sizeof(struct defrule);
01103 if (space != 0) genfree(theEnv,(void *) DefruleBinaryData(theEnv)->DefruleArray,space);
01104 DefruleBinaryData(theEnv)->NumberOfDefrules = 0;
01105
01106 space = DefruleBinaryData(theEnv)->NumberOfJoins * sizeof(struct joinNode);
01107 if (space != 0) genfree(theEnv,(void *) DefruleBinaryData(theEnv)->JoinArray,space);
01108 DefruleBinaryData(theEnv)->NumberOfJoins = 0;
01109
01110 space = DefruleBinaryData(theEnv)->NumberOfLinks * sizeof(struct joinLink);
01111 if (space != 0) genfree(theEnv,(void *) DefruleBinaryData(theEnv)->LinkArray,space);
01112 DefruleBinaryData(theEnv)->NumberOfLinks = 0;
01113
01114 DefruleData(theEnv)->RightPrimeJoins = NULL;
01115 DefruleData(theEnv)->LeftPrimeJoins = NULL;
01116 }
01117
01118
01119
01120
01121
01122 globle void *BloadDefruleModuleReference(
01123 void *theEnv,
01124 int theIndex)
01125 {
01126 return ((void *) &DefruleBinaryData(theEnv)->ModuleArray[theIndex]);
01127 }
01128
01129 #endif
01130
01131