📄 rulebld.c
字号:
theLHS->negated,isExists,isLogical, networkTest,secondaryNetworkTest, leftHash,rightHash)) != NULL) ) {#if DEBUGGING_FUNCTIONS if ((EnvGetWatchItem(theEnv,"compilations") == TRUE) && GetPrintWhileLoading(theEnv)) { EnvPrintRouter(theEnv,WDIALOG,"=j"); }#endif lastJoin = oldJoin; } else { tryToReuse = FALSE; if (! joinFromTheRight) { lastJoin = CreateNewJoin(theEnv,networkTest,secondaryNetworkTest,lastJoin, lastPattern,FALSE,(int) theLHS->negated, isExists, leftHash,rightHash); lastJoin->rhsType = rhsType; } else { lastJoin = CreateNewJoin(theEnv,networkTest,secondaryNetworkTest,lastJoin, lastRightJoin,TRUE,(int) theLHS->negated, isExists, leftHash,rightHash); lastJoin->rhsType = rhsType; } } /*============================================*/ /* If we've reached the end of the subgroup, */ /* then return the last join of the subgroup. */ /*============================================*/ if (lastIteration) { break; } /*=======================================*/ /* Move on to the next join to be added. */ /*=======================================*/ theLHS = nextLHS; joinNumber++; firstJoin = FALSE; } /*=================================================*/ /* Add the final join which stores the activations */ /* of the rule. This join is never shared. */ /*=================================================*/ if (startDepth == 1) { lastJoin = CreateNewJoin(theEnv,NULL,NULL,lastJoin,NULL, FALSE,FALSE,FALSE,NULL,NULL); } /*===================================================*/ /* If compilations are being watched, put a carriage */ /* return after all of the =j's and +j's */ /*===================================================*/#if DEBUGGING_FUNCTIONS if ((startDepth == 1) && (EnvGetWatchItem(theEnv,"compilations") == TRUE) && GetPrintWhileLoading(theEnv)) { EnvPrintRouter(theEnv,WDIALOG,"\n"); }#endif /*=============================*/ /* Return the last join added. */ /*=============================*/ return(lastJoin); }/****************************************************************//* AttachTestCEsToPatternCEs: Attaches the expressions found in *//* test CEs to the closest preceeding pattern CE that is not *//* negated and is at the same not/and depth. *//****************************************************************/static void AttachTestCEsToPatternCEs( void *theEnv, struct lhsParseNode *theLHS) { struct lhsParseNode *lastNode = NULL, *tempNode, *orgNode; /* struct expr *tmpExpr; */ /* int depth = 1; */ if (theLHS == NULL) return; orgNode = theLHS; /*=============================================================*/ /* Attach test CEs that can be attached directly to a pattern. */ /*=============================================================*/ lastNode = theLHS; theLHS = lastNode->bottom; while (theLHS != NULL) { if ((theLHS->type != TEST_CE) || (lastNode->beginNandDepth != lastNode->endNandDepth) || (lastNode->beginNandDepth != theLHS->beginNandDepth)) { lastNode = theLHS; theLHS = theLHS->bottom; continue; } if (lastNode->negated) { lastNode->secondaryNetworkTest = CombineExpressions(theEnv,lastNode->secondaryNetworkTest,theLHS->networkTest); } else { lastNode->networkTest = CombineExpressions(theEnv,lastNode->networkTest,theLHS->networkTest); } theLHS->networkTest = NULL; tempNode = theLHS->bottom; theLHS->bottom = NULL; lastNode->bottom = tempNode; lastNode->endNandDepth = theLHS->endNandDepth; ReturnLHSParseNodes(theEnv,theLHS); theLHS = tempNode; } } /********************************************************************//* FindShareableJoin: Determines whether a join exists that can be *//* reused for the join currently being added to the join network. *//* Returns a pointer to the join to be shared if one if found, *//* otherwise returns a NULL pointer. *//********************************************************************/static struct joinNode *FindShareableJoin( struct joinLink *theLinks, struct joinNode *listOfJoins, intBool useLinks, void *rhsStruct, unsigned int firstJoin, unsigned int negatedRHS, unsigned int existsRHS, unsigned int isLogical, struct expr *joinTest, struct expr *secondaryJoinTest, struct expr *leftHash, struct expr *rightHash) { /*========================================*/ /* Loop through all of the joins in the */ /* list of potential candiates for reuse. */ /*========================================*/ if (useLinks) { if (theLinks != NULL) { listOfJoins = theLinks->join; } else { listOfJoins = NULL; } } while (listOfJoins != NULL) { /*=========================================================*/ /* If the join being tested for reuse is connected on the */ /* RHS to the end node of the pattern node associated with */ /* the join to be added, then determine if the join can */ /* be reused. If so, return the join. */ /*=========================================================*/ if (listOfJoins->rightSideEntryStructure == rhsStruct) { if (TestJoinForReuse(listOfJoins,firstJoin,negatedRHS,existsRHS, isLogical,joinTest,secondaryJoinTest, leftHash,rightHash)) { return(listOfJoins); } } /*====================================================*/ /* Move on to the next potential candidate. Note that */ /* the rightMatchNode link is used for traversing */ /* through the candidates for the first join of a */ /* rule and that rightDriveNode link is used for */ /* traversing through the candidates for subsequent */ /* joins of a rule. */ /*====================================================*/ if (useLinks) { theLinks = theLinks->next; if (theLinks != NULL) { listOfJoins = theLinks->join; } else { listOfJoins = NULL; } } else { listOfJoins = listOfJoins->rightMatchNode; } } /*================================*/ /* Return a NULL pointer, since a */ /* reusable join was not found. */ /*================================*/ return(NULL); }/**************************************************************//* TestJoinForReuse: Determines if the specified join can be *//* shared with a join being added for a rule being defined. *//* Returns TRUE if the join can be shared, otherwise FALSE. *//**************************************************************/static int TestJoinForReuse( struct joinNode *testJoin, unsigned firstJoin, unsigned negatedRHS, unsigned existsRHS, unsigned int isLogical, struct expr *joinTest, struct expr *secondaryJoinTest, struct expr *leftHash, struct expr *rightHash) { /*==================================================*/ /* The first join of a rule may only be shared with */ /* a join that has its firstJoin field set to TRUE. */ /*==================================================*/ if (testJoin->firstJoin != firstJoin) return(FALSE); /*========================================================*/ /* A join connected to a not CE may only be shared with a */ /* join that has its patternIsNegated field set to TRUE. */ /*========================================================*/ if ((testJoin->patternIsNegated != negatedRHS) && (! existsRHS)) return(FALSE); /*==========================================================*/ /* A join connected to an exists CE may only be shared with */ /* a join that has its patternIsExists field set to TRUE. */ /*==========================================================*/ if (testJoin->patternIsExists != existsRHS) return(FALSE); /*==========================================================*/ /* If the join added is associated with a logical CE, then */ /* either the join to be shared must be associated with a */ /* logical CE or the beta memory must be empty (since */ /* joins associate an extra field with each partial match). */ /*==========================================================*/ if ((isLogical == TRUE) && (testJoin->logicalJoin == FALSE) && BetaMemoryNotEmpty(testJoin)) { return(FALSE); } /*===============================================================*/ /* The expression associated with the join must be identical to */ /* the networkTest expression stored with the join to be shared. */ /*===============================================================*/ if (IdenticalExpression(testJoin->networkTest,joinTest) != TRUE) { return(FALSE); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -