static void SlotToCode( void *theEnv, FILE *theFile, struct templateSlot *theSlot, int imageID, int maxIndices, int slotCount) { /*===========*/ /* Slot Name */ /*===========*/ fprintf(theFile,"{"); PrintSymbolReference(theEnv,theFile,theSlot->slotName); /*=============================*/ /* Multislot and Default Flags */ /*=============================*/ fprintf(theFile,",%d,%d,%d,%d,",theSlot->multislot,theSlot->noDefault, theSlot->defaultPresent,theSlot->defaultDynamic); /*=============*/ /* Constraints */ /*=============*/ PrintConstraintReference(theEnv,theFile,theSlot->constraints,imageID,maxIndices); /*===============*/ /* Default Value */ /*===============*/ fprintf(theFile,","); PrintHashedExpressionReference(theEnv,theFile,theSlot->defaultList,imageID,maxIndices); /*============*/ /* Facet List */ /*============*/ fprintf(theFile,","); PrintHashedExpressionReference(theEnv,theFile,theSlot->facetList,imageID,maxIndices); fprintf(theFile,","); /*===========*/ /* Next Slot */ /*===========*/ if (theSlot->next == NULL) { fprintf(theFile,"NULL}"); } else { fprintf(theFile,"&%s%d_%d[%d]}",SlotPrefix(),imageID, ((slotCount+1) / maxIndices) + 1, (slotCount+1) % maxIndices); } }
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 void DefglobalToCode( void *theEnv, EXEC_STATUS, FILE *theFile, struct defglobal *theDefglobal, int imageID, int maxIndices, int moduleCount) { /*==================*/ /* Defglobal Header */ /*==================*/ fprintf(theFile,"{"); ConstructHeaderToCode(theEnv,execStatus,theFile,&theDefglobal->header,imageID,maxIndices, moduleCount,ModulePrefix(DefglobalData(theEnv,execStatus)->DefglobalCodeItem), ConstructPrefix(DefglobalData(theEnv,execStatus)->DefglobalCodeItem)); fprintf(theFile,","); /*============================================*/ /* Watch Flag, In Scope Flag, and Busy Count. */ /*============================================*/ fprintf(theFile,"0,0,%ld,",theDefglobal->busyCount); /*================*/ /* Current Value. */ /*================*/ fprintf(theFile,"{NULL,RVOID}"); /*=====================*/ /* Initial Expression. */ /*=====================*/ fprintf(theFile,","); PrintHashedExpressionReference(theEnv,execStatus,theFile,theDefglobal->initial,imageID,maxIndices); fprintf(theFile,"}"); }
static void DefglobalToCode( Environment *theEnv, FILE *theFile, Defglobal *theDefglobal, unsigned int imageID, unsigned int maxIndices, unsigned int moduleCount) { /*==================*/ /* Defglobal Header */ /*==================*/ fprintf(theFile,"{"); ConstructHeaderToCode(theEnv,theFile,&theDefglobal->header,imageID,maxIndices, moduleCount,ModulePrefix(DefglobalData(theEnv)->DefglobalCodeItem), ConstructPrefix(DefglobalData(theEnv)->DefglobalCodeItem)); fprintf(theFile,","); /*============================================*/ /* Watch Flag, In Scope Flag, and Busy Count. */ /*============================================*/ fprintf(theFile,"0,0,%ld,",theDefglobal->busyCount); /*================*/ /* Current Value. */ /*================*/ fprintf(theFile,"{ { NULL } }"); /*=====================*/ /* Initial Expression. */ /*=====================*/ fprintf(theFile,","); PrintHashedExpressionReference(theEnv,theFile,theDefglobal->initial,imageID,maxIndices); fprintf(theFile,"}"); }
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); } }
globle int ConstraintsToCode( void *theEnv, char *fileName, int fileID, FILE *headerFP, int imageID, int maxIndices) { int i, j, count; int newHeader = TRUE; FILE *fp; int version = 1; int arrayVersion = 1; unsigned short numberOfConstraints = 0; CONSTRAINT_RECORD *tmpPtr; /*===============================================*/ /* Count the total number of constraint records. */ /*===============================================*/ for (i = 0 ; i < SIZE_CONSTRAINT_HASH; i++) { for (tmpPtr = ConstraintData(theEnv)->ConstraintHashtable[i]; tmpPtr != NULL; tmpPtr = tmpPtr->next) { tmpPtr->bsaveIndex = numberOfConstraints++; } } /*=====================================================*/ /* If dynamic constraint checking is disabled, then */ /* contraints won't be saved. If there are constraints */ /* which could be saved, then issue a warning message. */ /*=====================================================*/ if ((! EnvGetDynamicConstraintChecking(theEnv)) && (numberOfConstraints != 0)) { numberOfConstraints = 0; PrintWarningID(theEnv,"CSTRNCMP",1,FALSE); EnvPrintRouter(theEnv,WWARNING,"Constraints are not saved with a constructs-to-c image\n"); EnvPrintRouter(theEnv,WWARNING," when dynamic constraint checking is disabled.\n"); } if (numberOfConstraints == 0) return(-1); /*=================================================*/ /* Print the extern definition in the header file. */ /*=================================================*/ for (i = 1; i <= (numberOfConstraints / maxIndices) + 1 ; i++) { fprintf(headerFP,"extern CONSTRAINT_RECORD C%d_%d[];\n",imageID,i); } /*==================*/ /* Create the file. */ /*==================*/ if ((fp = NewCFile(theEnv,fileName,fileID,version,FALSE)) == NULL) return(-1); /*===================*/ /* List the entries. */ /*===================*/ j = 0; count = 0; for (i = 0; i < SIZE_CONSTRAINT_HASH; i++) { for (tmpPtr = ConstraintData(theEnv)->ConstraintHashtable[i]; tmpPtr != NULL; tmpPtr = tmpPtr->next) { if (newHeader) { fprintf(fp,"CONSTRAINT_RECORD C%d_%d[] = {\n",imageID,arrayVersion); newHeader = FALSE; } fprintf(fp,"{%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", tmpPtr->anyAllowed, tmpPtr->symbolsAllowed, tmpPtr->stringsAllowed, tmpPtr->floatsAllowed, tmpPtr->integersAllowed, tmpPtr->instanceNamesAllowed, tmpPtr->instanceAddressesAllowed, tmpPtr->externalAddressesAllowed, tmpPtr->factAddressesAllowed, 0, /* void allowed */ tmpPtr->anyRestriction, tmpPtr->symbolRestriction, tmpPtr->stringRestriction, tmpPtr->floatRestriction, tmpPtr->integerRestriction, tmpPtr->instanceNameRestriction, tmpPtr->multifieldsAllowed, tmpPtr->singlefieldsAllowed); fprintf(fp,",0,"); /* bsaveIndex */ PrintHashedExpressionReference(theEnv,fp,tmpPtr->restrictionList,imageID,maxIndices); fprintf(fp,","); PrintHashedExpressionReference(theEnv,fp,tmpPtr->minValue,imageID,maxIndices); fprintf(fp,","); PrintHashedExpressionReference(theEnv,fp,tmpPtr->maxValue,imageID,maxIndices); fprintf(fp,","); PrintHashedExpressionReference(theEnv,fp,tmpPtr->minFields,imageID,maxIndices); fprintf(fp,","); PrintHashedExpressionReference(theEnv,fp,tmpPtr->maxFields,imageID,maxIndices); /* multifield slot */ fprintf(fp,",NULL"); /* next slot */ if (tmpPtr->next == NULL) { fprintf(fp,",NULL,"); } else { if ((j + 1) >= maxIndices) { fprintf(fp,",&C%d_%d[%d],",imageID,arrayVersion + 1,0); } else { fprintf(fp,",&C%d_%d[%d],",imageID,arrayVersion,j + 1); } } fprintf(fp,"%d,%d",tmpPtr->bucket,tmpPtr->count + 1); count++; j++; if ((count == numberOfConstraints) || (j >= maxIndices)) { fprintf(fp,"}};\n"); GenClose(fp); j = 0; version++; arrayVersion++; if (count < numberOfConstraints) { if ((fp = NewCFile(theEnv,fileName,1,version,FALSE)) == NULL) return(0); newHeader = TRUE; } } else { fprintf(fp,"},\n"); } } } return(version); }
static void PatternNodeToCode( FILE *theFile, struct factPatternNode *thePatternNode, int imageID, int maxIndices) { fprintf(theFile,"{"); /*=====================*/ /* Pattern Node Header */ /*=====================*/ PatternNodeHeaderToCode(theFile,&thePatternNode->header,imageID,maxIndices); /*========================*/ /* Field and Slot Indices */ /*========================*/ fprintf(theFile,",0,%d,%d,%d,",thePatternNode->whichField, thePatternNode->whichSlot, thePatternNode->leaveFields); /*===============*/ /* Network Tests */ /*===============*/ PrintHashedExpressionReference(theFile,thePatternNode->networkTest,imageID,maxIndices); /*============*/ /* Next Level */ /*============*/ if (thePatternNode->nextLevel == NULL) { fprintf(theFile,",NULL,"); } else { fprintf(theFile,",&%s%d_%ld[%ld],",FactPrefix(), imageID,(thePatternNode->nextLevel->bsaveID / maxIndices) + 1, thePatternNode->nextLevel->bsaveID % maxIndices); } /*============*/ /* Last Level */ /*============*/ if (thePatternNode->lastLevel == NULL) { fprintf(theFile,"NULL,"); } else { fprintf(theFile,"&%s%d_%ld[%ld],",FactPrefix(), imageID,(thePatternNode->lastLevel->bsaveID / maxIndices) + 1, thePatternNode->lastLevel->bsaveID % maxIndices); } /*===========*/ /* Left Node */ /*===========*/ if (thePatternNode->leftNode == NULL) { fprintf(theFile,"NULL,"); } else { fprintf(theFile,"&%s%d_%ld[%ld],",FactPrefix(), imageID,(thePatternNode->leftNode->bsaveID / maxIndices) + 1, thePatternNode->leftNode->bsaveID % maxIndices); } /*============*/ /* Right Node */ /*============*/ if (thePatternNode->rightNode == NULL) { fprintf(theFile,"NULL}"); } else { fprintf(theFile,"&%s%d_%ld[%ld]}",FactPrefix(), imageID,(thePatternNode->rightNode->bsaveID / maxIndices) + 1, thePatternNode->rightNode->bsaveID % maxIndices); } }
/************************************************************* NAME : IntermediatePatternNodesToCode DESCRIPTION : Writes out data structures for run-time creation of object pattern intermediate nodes INPUTS : 1) The base image output file name 2) The base image file id 3) A pointer to the header output file 4) The id of constructs-to-c image 5) The maximum number of indices allowed in any single array in the image RETURNS : Next version file to open, 0 if error SIDE EFFECTS : Object patterns code written to files NOTES : None *************************************************************/ static int IntermediatePatternNodesToCode( void *theEnv, char *fileName, int fileID, FILE *headerFP, int imageID, int maxIndices, int version) { FILE *fp; int arrayVersion; int newHeader; int i; OBJECT_PATTERN_NODE *thePattern; /* ================ Create the file. ================ */ if (ObjectNetworkPointer(theEnv) == NULL) return(1); fprintf(headerFP,"#include \"objrtmch.h\"\n"); /* ================================= Dump the pattern node structures. ================================= */ if ((fp = NewCFile(theEnv,fileName,fileID,version,FALSE)) == NULL) return(0); newHeader = TRUE; arrayVersion = 1; i = 1; thePattern = ObjectNetworkPointer(theEnv); while (thePattern != NULL) { if (newHeader) { fprintf(fp,"OBJECT_PATTERN_NODE %s%d_%d[] = {\n", ObjectPNPrefix(),imageID,arrayVersion); fprintf(headerFP,"extern OBJECT_PATTERN_NODE %s%d_%d[];\n", ObjectPNPrefix(),imageID,arrayVersion); newHeader = FALSE; } fprintf(fp,"{0,%u,%u,%u,%u,0L,%u,",thePattern->multifieldNode, thePattern->endSlot, thePattern->whichField, thePattern->leaveFields, thePattern->slotNameID); PrintHashedExpressionReference(theEnv,fp,thePattern->networkTest,imageID,maxIndices); fprintf(fp,","); IntermediatePatternNodeReference(theEnv,thePattern->nextLevel,fp,imageID,maxIndices); fprintf(fp,","); IntermediatePatternNodeReference(theEnv,thePattern->lastLevel,fp,imageID,maxIndices); fprintf(fp,","); IntermediatePatternNodeReference(theEnv,thePattern->leftNode,fp,imageID,maxIndices); fprintf(fp,","); IntermediatePatternNodeReference(theEnv,thePattern->rightNode,fp,imageID,maxIndices); fprintf(fp,","); ObjectPatternNodeReference(theEnv,(void *) thePattern->alphaNode,fp,imageID,maxIndices); fprintf(fp,",0L}"); i++; thePattern = GetNextObjectPatternNode(thePattern); if ((i > maxIndices) || (thePattern == NULL)) { fprintf(fp,"};\n"); GenClose(fp); i = 1; version++; arrayVersion++; if (thePattern != NULL) { if ((fp = NewCFile(theEnv,fileName,fileID,version,FALSE)) == NULL) return(0); newHeader = TRUE; } } else if (thePattern != NULL) { fprintf(fp,",\n"); } } return(version); }