globle void PatternNodeHeaderToCode( void *theEnv, FILE *fp, struct patternNodeHeader *theHeader, int imageID, int maxIndices) { fprintf(fp,"{NULL,NULL,"); if (theHeader->entryJoin == NULL) { fprintf(fp,"NULL,"); } else { fprintf(fp,"&%s%d_%d[%d],", JoinPrefix(),imageID, (((int) theHeader->entryJoin->bsaveID) / maxIndices) + 1, ((int) theHeader->entryJoin->bsaveID) % maxIndices); } PrintHashedExpressionReference(theEnv,fp,theHeader->rightHash,imageID,maxIndices); fprintf(fp,",%d,%d,%d,0,0,%d,%d,%d}",theHeader->singlefieldNode, theHeader->multifieldNode, theHeader->stopNode, theHeader->beginSlot, theHeader->endSlot, theHeader->selector); }
void PatternNodeHeaderToCode( Environment *theEnv, FILE *fp, struct patternNodeHeader *theHeader, unsigned int imageID, unsigned int maxIndices) { fprintf(fp,"{NULL,NULL,"); if (theHeader->entryJoin == NULL) { fprintf(fp,"NULL,"); } else { fprintf(fp,"&%s%u_%lu[%lu],", JoinPrefix(),imageID, (theHeader->entryJoin->bsaveID / maxIndices) + 1, theHeader->entryJoin->bsaveID % maxIndices); } PrintHashedExpressionReference(theEnv,fp,theHeader->rightHash,imageID,maxIndices); fprintf(fp,",%d,%d,%d,0,0,%d,%d,%d}",theHeader->singlefieldNode, theHeader->multifieldNode, theHeader->stopNode, theHeader->beginSlot, theHeader->endSlot, theHeader->selector); }
static int RuleCompilerTraverseJoins( void *theEnv, EXEC_STATUS, struct joinNode *joinPtr, char *fileName, char *pathName, char *fileNameBuffer, int fileID, FILE *headerFP, int imageID, int maxIndices, FILE **joinFile, FILE **linkFile, int *fileCount, int *joinArrayVersion, int *joinArrayCount, int *linkArrayVersion, int *linkArrayCount) { for (; joinPtr != NULL; joinPtr = joinPtr->lastLevel) { if (joinPtr->marked) { *joinFile = OpenFileIfNeeded(theEnv,execStatus,*joinFile,fileName,pathName,fileNameBuffer,fileID,imageID,fileCount, *joinArrayVersion,headerFP, "struct joinNode",JoinPrefix(),FALSE,NULL); if (*joinFile == NULL) { return(FALSE); } JoinToCode(theEnv,execStatus,*joinFile,joinPtr,imageID,maxIndices); (*joinArrayCount)++; *joinFile = CloseFileIfNeeded(theEnv,execStatus,*joinFile,joinArrayCount,joinArrayVersion, maxIndices,NULL,NULL); if (! TraverseJoinLinks(theEnv,execStatus,joinPtr->nextLinks,fileName,pathName,fileNameBuffer,fileID,headerFP,imageID, maxIndices,linkFile,fileCount,linkArrayVersion,linkArrayCount)) { return(FALSE); } } if (joinPtr->joinFromTheRight) { if (RuleCompilerTraverseJoins(theEnv,execStatus,(struct joinNode *) joinPtr->rightSideEntryStructure,fileName,pathName, fileNameBuffer,fileID,headerFP,imageID,maxIndices,joinFile,linkFile,fileCount, joinArrayVersion,joinArrayCount, linkArrayVersion,linkArrayCount) == FALSE) { return(FALSE); } } } return(TRUE); }
static void LinkToCode( void *theEnv, EXEC_STATUS, FILE *theFile, struct joinLink *theLink, int imageID, int maxIndices) { /*==================*/ /* Enter Direction. */ /*==================*/ fprintf(theFile,"{%d,",theLink->enterDirection); /*======*/ /* Join */ /*======*/ if (theLink->join == NULL) { fprintf(theFile,"NULL,"); } else { fprintf(theFile,"&%s%d_%ld[%ld],",JoinPrefix(), imageID,(theLink->join->bsaveID / maxIndices) + 1, theLink->join->bsaveID % maxIndices); } /*======*/ /* Next */ /*======*/ if (theLink->next == NULL) { fprintf(theFile,"NULL,"); } else { fprintf(theFile,"&%s%d_%ld[%ld],",LinkPrefix(), imageID,(theLink->next->bsaveID / maxIndices) + 1, theLink->next->bsaveID % maxIndices); } /*===========*/ /* Bsave ID. */ /*===========*/ fprintf(theFile,"0}"); }
globle void PatternNodeHeaderToCode( FILE *fp, struct patternNodeHeader *theHeader, int imageID, int maxIndices) { fprintf(fp,"{NULL,NULL,"); if (theHeader->entryJoin == NULL) { fprintf(fp,"NULL,"); } else { fprintf(fp,"&%s%d_%d[%d],", JoinPrefix(),imageID, (((int) theHeader->entryJoin->bsaveID) / maxIndices) + 1, ((int) theHeader->entryJoin->bsaveID) % maxIndices); } fprintf(fp,"%d,%d,%d,0,0,%d,%d}",theHeader->singlefieldNode, theHeader->multifieldNode, theHeader->stopNode, theHeader->beginSlot, theHeader->endSlot); }
static void JoinToCode( void *theEnv, FILE *joinFile, struct joinNode *theJoin, int imageID, int maxIndices) { struct patternParser *theParser; /*===========================*/ /* Mark the join as visited. */ /*===========================*/ theJoin->marked = 0; /*===========================*/ /* Flags and Integer Values. */ /*===========================*/ fprintf(joinFile,"{%d,%d,%d,%d,%d,0,0,%d,%d,0,0,0,0,", theJoin->firstJoin,theJoin->logicalJoin, theJoin->joinFromTheRight,theJoin->patternIsNegated, theJoin->patternIsExists, theJoin->rhsType,theJoin->depth); /*==========================*/ /* Left and right Memories. */ /*==========================*/ fprintf(joinFile,"NULL,NULL,"); /*====================*/ /* Network Expression */ /*====================*/ PrintHashedExpressionReference(theEnv,joinFile,theJoin->networkTest,imageID,maxIndices); fprintf(joinFile,","); PrintHashedExpressionReference(theEnv,joinFile,theJoin->secondaryNetworkTest,imageID,maxIndices); fprintf(joinFile,","); PrintHashedExpressionReference(theEnv,joinFile,theJoin->leftHash,imageID,maxIndices); fprintf(joinFile,","); PrintHashedExpressionReference(theEnv,joinFile,theJoin->rightHash,imageID,maxIndices); fprintf(joinFile,","); /*============================*/ /* Right Side Entry Structure */ /*============================*/ if (theJoin->rightSideEntryStructure == NULL) { fprintf(joinFile,"NULL,"); } else if (theJoin->joinFromTheRight == FALSE) { theParser = GetPatternParser(theEnv,(int) theJoin->rhsType); if (theParser->codeReferenceFunction == NULL) fprintf(joinFile,"NULL,"); else { fprintf(joinFile,"VS "); (*theParser->codeReferenceFunction)(theEnv,theJoin->rightSideEntryStructure, joinFile,imageID,maxIndices); fprintf(joinFile,","); } } else { fprintf(joinFile,"&%s%d_%ld[%ld],",JoinPrefix(), imageID,(((struct joinNode *) theJoin->rightSideEntryStructure)->bsaveID / maxIndices) + 1, ((struct joinNode *) theJoin->rightSideEntryStructure)->bsaveID % maxIndices); } /*=================*/ /* Next Join Level */ /*=================*/ if (theJoin->nextLinks == NULL) { fprintf(joinFile,"NULL,"); } else { fprintf(joinFile,"&%s%d_%ld[%ld],",LinkPrefix(), imageID,(theJoin->nextLinks->bsaveID / maxIndices) + 1, theJoin->nextLinks->bsaveID % maxIndices); } /*=================*/ /* Last Join Level */ /*=================*/ if (theJoin->lastLevel == NULL) { fprintf(joinFile,"NULL,"); } else { fprintf(joinFile,"&%s%d_%ld[%ld],",JoinPrefix(), imageID,(theJoin->lastLevel->bsaveID / maxIndices) + 1, theJoin->lastLevel->bsaveID % maxIndices); } /*==================*/ /* Right Match Node */ /*==================*/ if (theJoin->rightMatchNode == NULL) { fprintf(joinFile,"NULL,"); } else { fprintf(joinFile,"&%s%d_%ld[%ld],",JoinPrefix(), imageID,(theJoin->rightMatchNode->bsaveID / maxIndices) + 1, theJoin->rightMatchNode->bsaveID % maxIndices); } /*==================*/ /* Rule to Activate */ /*==================*/ if (theJoin->ruleToActivate == NULL) { fprintf(joinFile,"NULL}"); } else { fprintf(joinFile,"&%s%d_%ld[%ld]}",ConstructPrefix(DefruleData(theEnv)->DefruleCodeItem),imageID, (theJoin->ruleToActivate->header.bsaveID / maxIndices) + 1, theJoin->ruleToActivate->header.bsaveID % maxIndices); } }
static void DefruleToCode( void *theEnv, FILE *theFile, struct defrule *theDefrule, int imageID, int maxIndices, int moduleCount) { /*==================*/ /* Construct Header */ /*==================*/ fprintf(theFile,"{"); ConstructHeaderToCode(theEnv,theFile,&theDefrule->header,imageID,maxIndices, moduleCount,ModulePrefix(DefruleData(theEnv)->DefruleCodeItem), ConstructPrefix(DefruleData(theEnv)->DefruleCodeItem)); /*==========================*/ /* Flags and Integer Values */ /*==========================*/ fprintf(theFile,",%d,%d,%d,%d,%d,%d,%d,%d,", theDefrule->salience,theDefrule->localVarCnt, theDefrule->complexity,theDefrule->afterBreakpoint, theDefrule->watchActivation,theDefrule->watchFiring, theDefrule->autoFocus,theDefrule->executing); /*==================*/ /* Dynamic Salience */ /*==================*/ ExpressionToCode(theEnv,theFile,theDefrule->dynamicSalience); fprintf(theFile,","); /*=============*/ /* RHS Actions */ /*=============*/ ExpressionToCode(theEnv,theFile,theDefrule->actions); fprintf(theFile,","); /*=========================*/ /* Logical Dependency Join */ /*=========================*/ if (theDefrule->logicalJoin != NULL) { fprintf(theFile,"&%s%d_%ld[%ld],",JoinPrefix(), imageID,(theDefrule->logicalJoin->bsaveID / maxIndices) + 1, theDefrule->logicalJoin->bsaveID % maxIndices); } else { fprintf(theFile,"NULL,"); } /*===========*/ /* Last Join */ /*===========*/ if (theDefrule->lastJoin != NULL) { fprintf(theFile,"&%s%d_%ld[%ld],",JoinPrefix(), imageID,(theDefrule->lastJoin->bsaveID / maxIndices) + 1, theDefrule->lastJoin->bsaveID % maxIndices); } else { fprintf(theFile,"NULL,"); } /*===============*/ /* Next Disjunct */ /*===============*/ if (theDefrule->disjunct != NULL) { fprintf(theFile,"&%s%d_%ld[%ld]}",ConstructPrefix(DefruleData(theEnv)->DefruleCodeItem), imageID,(theDefrule->disjunct->header.bsaveID / maxIndices) + 1, theDefrule->disjunct->header.bsaveID % maxIndices); } else { fprintf(theFile,"NULL}"); } }
static int ConstructToCode( char *fileName, int fileID, FILE *headerFP, int imageID, int maxIndices) { int fileCount = 1; struct defmodule *theModule; struct defrule *theDefrule; struct joinNode *theJoin; int joinArrayCount = 0, joinArrayVersion = 1; int moduleCount = 0, moduleArrayCount = 0, moduleArrayVersion = 1; int defruleArrayCount = 0, defruleArrayVersion = 1; FILE *joinFile = NULL, *moduleFile = NULL, *defruleFile = NULL; #if FUZZY_DEFTEMPLATES struct fzSlotLocator *thePatternFv; int patternFvArrayCount = 0, patternFvArrayVersion = 1; FILE *patternFvFile = NULL; #endif /*==============================================*/ /* Include the appropriate defrule header file. */ /*==============================================*/ fprintf(headerFP,"#include \"ruledef.h\"\n"); /*=========================================================*/ /* Loop through all the modules, all the defrules, and all */ /* the join nodes writing their C code representation to */ /* the file as they are traversed. */ /*=========================================================*/ #if FUZZY_DEFTEMPLATES /*=========================================================*/ /* ALSO write the patternFv arrays as required if Fuzzy */ /*=========================================================*/ #endif for (theModule = (struct defmodule *) GetNextDefmodule(NULL); theModule != NULL; theModule = (struct defmodule *) GetNextDefmodule(theModule)) { /*=========================*/ /* Set the current module. */ /*=========================*/ SetCurrentModule((void *) theModule); /*==========================*/ /* Save the defrule module. */ /*==========================*/ moduleFile = OpenFileIfNeeded(moduleFile,fileName,fileID,imageID,&fileCount, moduleArrayVersion,headerFP, "struct defruleModule",ModulePrefix(DefruleCodeItem), FALSE,NULL); if (moduleFile == NULL) { #if FUZZY_DEFTEMPLATES CloseDefruleFiles(moduleFile,defruleFile,joinFile,patternFvFile,maxIndices); #else CloseDefruleFiles(moduleFile,defruleFile,joinFile,maxIndices); #endif return(0); } DefruleModuleToCode(moduleFile,theModule,imageID,maxIndices,moduleCount); moduleFile = CloseFileIfNeeded(moduleFile,&moduleArrayCount,&moduleArrayVersion, maxIndices,NULL,NULL); /*=========================================*/ /* Loop through all of the defrules (and */ /* their disjuncts) in the current module. */ /*=========================================*/ theDefrule = (struct defrule *) GetNextDefrule(NULL); while (theDefrule != NULL) { /*===================================*/ /* Save the defrule data structures. */ /*===================================*/ defruleFile = OpenFileIfNeeded(defruleFile,fileName,fileID,imageID,&fileCount, defruleArrayVersion,headerFP, "struct defrule",ConstructPrefix(DefruleCodeItem), FALSE,NULL); if (defruleFile == NULL) { #if FUZZY_DEFTEMPLATES CloseDefruleFiles(moduleFile,defruleFile,joinFile,patternFvFile,maxIndices); #else CloseDefruleFiles(moduleFile,defruleFile,joinFile,maxIndices); #endif return(0); } #if FUZZY_DEFTEMPLATES DefruleToCode(defruleFile,theDefrule,imageID,maxIndices, moduleCount, patternFvArrayCount, patternFvArrayVersion); #else DefruleToCode(defruleFile,theDefrule,imageID,maxIndices, moduleCount); #endif defruleArrayCount++; defruleFile = CloseFileIfNeeded(defruleFile,&defruleArrayCount,&defruleArrayVersion, maxIndices,NULL,NULL); #if FUZZY_DEFTEMPLATES /* write out the patternFv array of fzSlotLocator structs */ thePatternFv = theDefrule->pattern_fv_arrayPtr; if (thePatternFv != NULL) { int i; int numFzSlots = theDefrule->numberOfFuzzySlots; patternFvFile = OpenFileIfNeeded(patternFvFile,fileName,fileID,imageID,&fileCount, patternFvArrayVersion,headerFP, "struct fzSlotLocator",PatternFvPrefix(),FALSE,NULL); if (patternFvFile == NULL) { CloseDefruleFiles(moduleFile,defruleFile,joinFile,patternFvFile,maxIndices); return(0); } for (i=0; i< numFzSlots; i++) { fprintf(patternFvFile, "{%d, %d, ", thePatternFv[i].patternNum, thePatternFv[i].slotNum); PrintFuzzyValueReference(patternFvFile,thePatternFv[i].fvhnPtr); fprintf(patternFvFile, "}"); if (i != numFzSlots-1) fprintf(patternFvFile, ","); } patternFvArrayCount += numFzSlots; patternFvFile = CloseFileIfNeeded(patternFvFile,&patternFvArrayCount,&patternFvArrayVersion, maxIndices,NULL,NULL); } #endif /*================================*/ /* Save the join data structures. */ /*================================*/ for (theJoin = theDefrule->lastJoin; theJoin != NULL; theJoin = GetPreviousJoin(theJoin)) { if (theJoin->marked) { joinFile = OpenFileIfNeeded(joinFile,fileName,fileID,imageID,&fileCount, joinArrayVersion,headerFP, "struct joinNode",JoinPrefix(),FALSE,NULL); if (joinFile == NULL) { #if FUZZY_DEFTEMPLATES CloseDefruleFiles(moduleFile,defruleFile,joinFile,patternFvFile,maxIndices); #else CloseDefruleFiles(moduleFile,defruleFile,joinFile,maxIndices); #endif return(0); } JoinToCode(joinFile,theJoin,imageID,maxIndices); joinArrayCount++; joinFile = CloseFileIfNeeded(joinFile,&joinArrayCount,&joinArrayVersion, maxIndices,NULL,NULL); } } /*==========================================*/ /* Move on to the next disjunct or defrule. */ /*==========================================*/ if (theDefrule->disjunct != NULL) theDefrule = theDefrule->disjunct; else theDefrule = (struct defrule *) GetNextDefrule(theDefrule); } moduleCount++; moduleArrayCount++; } #if FUZZY_DEFTEMPLATES CloseDefruleFiles(moduleFile,defruleFile,joinFile,patternFvFile,maxIndices); #else CloseDefruleFiles(moduleFile,defruleFile,joinFile,maxIndices); #endif return(1); }