📄 reteutil.c
字号:
struct partialMatch *thePartialMatch) { unsigned short i; for (i = 0 ; i < thePartialMatch->bcount; i++) { if (thePartialMatch->binds[i].gm.theMatch == NULL) continue; if (thePartialMatch->binds[i].gm.theMatch->matchingItem == theEntity) { return(TRUE); } } return(FALSE); } /***********************************************************************//* GetPatternNumberFromJoin: Given a pointer to a join associated with *//* a pattern CE, returns an integer representing the position of the *//* pattern CE in the rule (e.g. first, second, third). *//***********************************************************************/globle int GetPatternNumberFromJoin( struct joinNode *joinPtr) { int whichOne = 0; while (joinPtr != NULL) { if (joinPtr->joinFromTheRight) { joinPtr = (struct joinNode *) joinPtr->rightSideEntryStructure; } else { whichOne++; joinPtr = joinPtr->lastLevel; } } return(whichOne); }/************************************************************************//* TraceErrorToRule: Prints an error message when a error occurs as the *//* result of evaluating an expression in the pattern network. Used to *//* indicate which rule caused the problem. *//************************************************************************/globle void TraceErrorToRule( void *theEnv, struct joinNode *joinPtr, char *indentSpaces) { int patternCount; MarkRuleNetwork(theEnv,0); patternCount = CountPriorPatterns(joinPtr->lastLevel) + 1; TraceErrorToRuleDriver(theEnv,joinPtr,indentSpaces,patternCount,FALSE); MarkRuleNetwork(theEnv,0); }/**************************************************************//* TraceErrorToRuleDriver: Driver code for printing out which *//* rule caused a pattern or join network error. *//**************************************************************/static void TraceErrorToRuleDriver( void *theEnv, struct joinNode *joinPtr, char *indentSpaces, int priorRightJoinPatterns, int enteredJoinFromRight) { char *name; int priorPatternCount; struct joinLink *theLinks; if ((joinPtr->joinFromTheRight) && enteredJoinFromRight) { priorPatternCount = CountPriorPatterns(joinPtr->lastLevel); } else { priorPatternCount = 0; } if (joinPtr->marked) { /* Do Nothing */ } else if (joinPtr->ruleToActivate != NULL) { joinPtr->marked = 1; name = EnvGetDefruleName(theEnv,joinPtr->ruleToActivate); EnvPrintRouter(theEnv,WERROR,indentSpaces); EnvPrintRouter(theEnv,WERROR,"Of pattern #"); PrintLongInteger(theEnv,WERROR,priorRightJoinPatterns+priorPatternCount); EnvPrintRouter(theEnv,WERROR," in rule "); EnvPrintRouter(theEnv,WERROR,name); EnvPrintRouter(theEnv,WERROR,"\n"); } else { joinPtr->marked = 1; theLinks = joinPtr->nextLinks; while (theLinks != NULL) { TraceErrorToRuleDriver(theEnv,theLinks->join,indentSpaces, priorRightJoinPatterns+priorPatternCount, (theLinks->enterDirection == RHS)); theLinks = theLinks->next; } } }/**************************************************************//* CountPriorPatterns: *//**************************************************************/static int CountPriorPatterns( struct joinNode *joinPtr) { int count = 0; while (joinPtr != NULL) { if (joinPtr->joinFromTheRight) { count += CountPriorPatterns((struct joinNode *) joinPtr->rightSideEntryStructure); } else { count++; } joinPtr = joinPtr->lastLevel; } return(count); }/********************************************************//* MarkRuleNetwork: Sets the marked flag in each of the *//* joins in the join network to the specified value. *//********************************************************/globle void MarkRuleNetwork( void *theEnv, int value) { struct defrule *rulePtr; struct joinNode *joinPtr; struct defmodule *modulePtr; /*===========================*/ /* Loop through each module. */ /*===========================*/ SaveCurrentModule(theEnv); for (modulePtr = (struct defmodule *) EnvGetNextDefmodule(theEnv,NULL); modulePtr != NULL; modulePtr = (struct defmodule *) EnvGetNextDefmodule(theEnv,modulePtr)) { EnvSetCurrentModule(theEnv,(void *) modulePtr); /*=========================*/ /* Loop through each rule. */ /*=========================*/ rulePtr = (struct defrule *) EnvGetNextDefrule(theEnv,NULL); while (rulePtr != NULL) { /*=============================*/ /* Mark each join for the rule */ /* with the specified value. */ /*=============================*/ joinPtr = rulePtr->lastJoin; MarkRuleJoins(joinPtr,value); /*=================================*/ /* Move on to the next rule or the */ /* next disjunct for this rule. */ /*=================================*/ if (rulePtr->disjunct != NULL) rulePtr = rulePtr->disjunct; else rulePtr = (struct defrule *) EnvGetNextDefrule(theEnv,rulePtr); } } RestoreCurrentModule(theEnv); }/*****************************************//* MarkRuleJoins: *//*****************************************/ globle void MarkRuleJoins( struct joinNode *joinPtr, int value) { while (joinPtr != NULL) { if (joinPtr->joinFromTheRight) { MarkRuleJoins((struct joinNode *) joinPtr->rightSideEntryStructure,value); } joinPtr->marked = value; joinPtr = joinPtr->lastLevel; } }/*****************************************//* GetAlphaMemory: Retrieves the list of *//* matches from an alpha memory. *//*****************************************/ globle struct partialMatch *GetAlphaMemory( void *theEnv, struct patternNodeHeader *theHeader, unsigned long hashOffset) { struct alphaMemoryHash *theAlphaMemory; unsigned long hashValue; hashValue = AlphaMemoryHashValue(theHeader,hashOffset); theAlphaMemory = FindAlphaMemory(theEnv,theHeader,hashValue); if (theAlphaMemory == NULL) { return NULL; } return theAlphaMemory->alphaMemory; }/*****************************************//* GetLeftBetaMemory: Retrieves the list *//* of matches from a beta memory. *//*****************************************/ globle struct partialMatch *GetLeftBetaMemory( struct joinNode *theJoin, unsigned long hashValue) { unsigned long betaLocation; betaLocation = hashValue % theJoin->leftMemory->size; return theJoin->leftMemory->beta[betaLocation]; }/******************************************//* GetRightBetaMemory: Retrieves the list *//* of matches from a beta memory. *//******************************************/ globle struct partialMatch *GetRightBetaMemory( struct joinNode *theJoin, unsigned long hashValue) { unsigned long betaLocation; betaLocation = hashValue % theJoin->rightMemory->size; return theJoin->rightMemory->beta[betaLocation]; } /***************************************//* ReturnLeftMemory: Sets the contents *//* of a beta memory to NULL. *//***************************************/ globle void ReturnLeftMemory( void *theEnv, struct joinNode *theJoin) { if (theJoin->leftMemory == NULL) return; genfree(theEnv,theJoin->leftMemory->beta,sizeof(struct partialMatch *) * theJoin->leftMemory->size); rtn_struct(theEnv,betaMemory,theJoin->leftMemory); theJoin->leftMemory = NULL; }/***************************************//* ReturnRightMemory: Sets the contents *//* of a beta memory to NULL. *//***************************************/ globle void ReturnRightMemory( void *theEnv, struct joinNode *theJoin) { if (theJoin->rightMemory == NULL) return; genfree(theEnv,theJoin->rightMemory->beta,sizeof(struct partialMatch *) * theJoin->rightMemory->size); genfree(theEnv,theJoin->rightMemory->last,sizeof(struct partialMatch *) * theJoin->rightMemory->size); rtn_struct(theEnv,betaMemory,theJoin->rightMemory); theJoin->rightMemory = NULL; } /****************************************************************//* DestroyBetaMemory: Destroys the contents of a beta memory in *//* preperation for the deallocation of a join. Destroying is *//* performed when the environment is being deallocated and it *//* is not necessary to leave the environment in a consistent *//* state (as it would be if just a single rule were being *//* deleted). *//****************************************************************/globle void DestroyBetaMemory( void *theEnv, struct joinNode *theJoin, int side) { unsigned long i; if (side == LHS) { if (theJoin->leftMemory == NULL) return; for (i = 0; i < theJoin->leftMemory->size; i++) { DestroyAlphaBetaMemory(theEnv,theJoin->leftMemory->beta[i]); } } else { if (theJoin->rightMemory == NULL) return; for (i = 0; i < theJoin->rightMemory->size; i++) { DestroyAlphaBetaMemory(theEnv,theJoin->rightMemory->beta[i]); } } } /*************************************************************//* FlushBetaMemory: Flushes the contents of a beta memory in *//* preperation for the deallocation of a join. Flushing *//* is performed when the partial matches in the beta *//* memory may still be in use because the environment will *//* remain active. *//*************************************************************/globle void FlushBetaMemory( void *theEnv, struct joinNode *theJoin, int side) { unsigned long i; if (side == LHS) { if (theJoin->leftMemory == NULL) return; for (i = 0; i < theJoin->leftMemory->size; i++) { FlushAlphaBetaMemory(theEnv,theJoin->leftMemory->beta[i]); } } else { if (theJoin->rightMemory == NULL) return; for (i = 0; i < theJoin->rightMemory->size; i++) { FlushAlphaBetaMemory(theEnv,theJoin->rightMemory->beta[i]); } } } /*****************************************************************//* BetaMemoryNotEmpty: *//*****************************************************************/globle intBool BetaMemoryNotEmpty( struct joinNode *theJoin) { if (theJoin->leftMemory != NULL) { if (theJoin->leftMemory->count > 0) { return(TRUE); } } if (theJoin->rightMemory != NULL) { if (theJoin->rightMemory->count > 0) { return(TRUE); } } return(FALSE); } /*********************************************//* RemoveAlphaMemoryMatches: Removes matches *//* from an alpha memory. *//*********************************************/ globle void RemoveAlphaMemoryMatches( void *theEnv, struct patternNodeHeader *theHeader, struct partialMatch *theMatch, struct alphaMatch *theAlphaMatch) { struct alphaMemoryHash *theAlphaMemory = NULL; unsigned long hashValue; if ((theMatch->prevInMemory == NULL) || (theMatch->nextInMemory == NULL)) { hashValue = theAlphaMatch->bucket; theAlphaMemory = FindAlphaMemory(theEnv,theHeader,hashValue); } if (theMatch->prevInMemory != NULL) { theMatch->prevInMemory->nextInMemory = theMatch->nextInMemory; } else { theAlphaMemory->alphaMemory = theMatch->nextInMemory; } if (theMatch->nextInMemory != NULL) { theMatch->nextInMemory->prevInMemory = theMatch->prevInMemory; } else { theAlphaMemory->endOfQueue = theMatch->prevInMemory; } /*====================================*/ /* Add the match to the garbage list. */ /*====================================*/ theMatch->nextInMemory = EngineData(theEnv)->GarbagePartialMatches; EngineData(theEnv)->GarbagePartialMatches = theMatch; if ((theAlphaMemory != NULL) && (theAlphaMemory->alphaMemory == NULL)) { UnlinkAlphaMemory(theEnv,theHeader,theAlphaMemory); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -