static void BsaveFind() { struct defglobal *defglobalPtr; struct defmodule *theModule; /*=======================================================*/ /* If a binary image is already loaded, then temporarily */ /* save the count values since these will be overwritten */ /* in the process of saving the binary image. */ /*=======================================================*/ if (Bloaded()) { SaveBloadCount(NumberOfDefglobalModules); SaveBloadCount(NumberOfDefglobals); } /*============================================*/ /* Set the count of defglobals and defglobals */ /* module data structures to zero. */ /*============================================*/ NumberOfDefglobals = 0; NumberOfDefglobalModules = 0; for (theModule = (struct defmodule *) GetNextDefmodule(NULL); theModule != NULL; theModule = (struct defmodule *) GetNextDefmodule(theModule)) { /*================================================*/ /* Set the current module to the module being */ /* examined and increment the number of defglobal */ /* modules encountered. */ /*================================================*/ SetCurrentModule((void *) theModule); NumberOfDefglobalModules++; /*====================================================*/ /* Loop through each defglobal in the current module. */ /*====================================================*/ for (defglobalPtr = (struct defglobal *) GetNextDefglobal(NULL); defglobalPtr != NULL; defglobalPtr = (struct defglobal *) GetNextDefglobal(defglobalPtr)) { /*======================================================*/ /* Initialize the construct header for the binary save. */ /*======================================================*/ MarkConstructHeaderNeededItems(&defglobalPtr->header,NumberOfDefglobals++); } } }
Defglobal *QFindDefglobal( Environment *theEnv, CLIPSLexeme *defglobalName) { Defglobal *theDefglobal; for (theDefglobal = GetNextDefglobal(theEnv,NULL); theDefglobal != NULL; theDefglobal = GetNextDefglobal(theEnv,theDefglobal)) { if (defglobalName == theDefglobal->header.name) return theDefglobal; } return NULL; }
void UpdateDefglobalScope( Environment *theEnv) { Defglobal *theDefglobal; unsigned int moduleCount; Defmodule *theModule; struct defmoduleItemHeader *theItem; /*============================*/ /* Loop through every module. */ /*============================*/ for (theModule = GetNextDefmodule(theEnv,NULL); theModule != NULL; theModule = GetNextDefmodule(theEnv,theModule)) { /*============================================================*/ /* Loop through every defglobal in the module being examined. */ /*============================================================*/ theItem = (struct defmoduleItemHeader *) GetModuleItem(theEnv,theModule,DefglobalData(theEnv)->DefglobalModuleIndex); for (theDefglobal = (Defglobal *) theItem->firstItem; theDefglobal != NULL ; theDefglobal = GetNextDefglobal(theEnv,theDefglobal)) { /*====================================================*/ /* If the defglobal is visible to the current module, */ /* then mark it as being in scope, otherwise mark it */ /* as being out of scope. */ /*====================================================*/ if (FindImportedConstruct(theEnv,"defglobal",theModule, theDefglobal->header.name->contents, &moduleCount,true,NULL) != NULL) { theDefglobal->inScope = true; } else { theDefglobal->inScope = false; } } } }
static bool ConstructToCode( Environment *theEnv, const char *fileName, const char *pathName, char *fileNameBuffer, unsigned int fileID, FILE *headerFP, unsigned int imageID, unsigned int maxIndices) { unsigned int fileCount = 1; Defmodule *theModule; Defglobal *theDefglobal; unsigned int moduleCount = 0, moduleArrayCount = 0, moduleArrayVersion = 1; unsigned int defglobalArrayCount = 0, defglobalArrayVersion = 1; FILE *moduleFile = NULL, *defglobalFile = NULL; /*================================================*/ /* Include the appropriate defglobal header file. */ /*================================================*/ fprintf(headerFP,"#include \"globldef.h\"\n"); /*===================================================================*/ /* Loop through all the modules and all the defglobals writing their */ /* C code representation to the file as they are traversed. */ /*===================================================================*/ for (theModule = GetNextDefmodule(theEnv,NULL); theModule != NULL; theModule = GetNextDefmodule(theEnv,theModule)) { SetCurrentModule(theEnv,theModule); moduleFile = OpenFileIfNeeded(theEnv,moduleFile,fileName,pathName,fileNameBuffer,fileID,imageID,&fileCount, moduleArrayVersion,headerFP, "struct defglobalModule",ModulePrefix(DefglobalData(theEnv)->DefglobalCodeItem), false,NULL); if (moduleFile == NULL) { CloseDefglobalFiles(theEnv,moduleFile,defglobalFile,maxIndices); return false; } DefglobalModuleToCode(theEnv,moduleFile,theModule,imageID,maxIndices,moduleCount); moduleFile = CloseFileIfNeeded(theEnv,moduleFile,&moduleArrayCount,&moduleArrayVersion, maxIndices,NULL,NULL); for (theDefglobal = GetNextDefglobal(theEnv,NULL); theDefglobal != NULL; theDefglobal = GetNextDefglobal(theEnv,theDefglobal)) { defglobalFile = OpenFileIfNeeded(theEnv,defglobalFile,fileName,pathName,fileNameBuffer,fileID,imageID,&fileCount, defglobalArrayVersion,headerFP, "Defglobal",ConstructPrefix(DefglobalData(theEnv)->DefglobalCodeItem), false,NULL); if (defglobalFile == NULL) { CloseDefglobalFiles(theEnv,moduleFile,defglobalFile,maxIndices); return false; } DefglobalToCode(theEnv,defglobalFile,theDefglobal,imageID,maxIndices,moduleCount); defglobalArrayCount++; defglobalFile = CloseFileIfNeeded(theEnv,defglobalFile,&defglobalArrayCount, &defglobalArrayVersion,maxIndices,NULL,NULL); } moduleCount++; moduleArrayCount++; } CloseDefglobalFiles(theEnv,moduleFile,defglobalFile,maxIndices); return true; }
Defglobal *GetNextDefglobalInScope( Environment *theEnv, Defglobal *theGlobal) { struct defmoduleItemHeader *theItem; /*=======================================*/ /* If we're beginning the search for the */ /* first defglobal in scope, then ... */ /*=======================================*/ if (theGlobal == NULL) { /*==============================================*/ /* If the current module has been changed since */ /* the last time the scopes were computed, then */ /* recompute the scopes. */ /*==============================================*/ if (DefglobalData(theEnv)->LastModuleIndex != DefmoduleData(theEnv)->ModuleChangeIndex) { UpdateDefglobalScope(theEnv); DefglobalData(theEnv)->LastModuleIndex = DefmoduleData(theEnv)->ModuleChangeIndex; } /*==========================================*/ /* Get the first module and first defglobal */ /* to start the search with. */ /*==========================================*/ DefglobalData(theEnv)->TheDefmodule = GetNextDefmodule(theEnv,NULL); theItem = (struct defmoduleItemHeader *) GetModuleItem(theEnv,DefglobalData(theEnv)->TheDefmodule,DefglobalData(theEnv)->DefglobalModuleIndex); theGlobal = (Defglobal *) theItem->firstItem; } /*==================================================*/ /* Otherwise, see if the last defglobal returned by */ /* this function has a defglobal following it. */ /*==================================================*/ else { theGlobal = GetNextDefglobal(theEnv,theGlobal); } /*======================================*/ /* Continue looping through the modules */ /* until a defglobal in scope is found. */ /*======================================*/ while (DefglobalData(theEnv)->TheDefmodule != NULL) { /*=====================================================*/ /* Loop through the defglobals in the module currently */ /* being examined to see if one is in scope. */ /*=====================================================*/ for (; theGlobal != NULL; theGlobal = GetNextDefglobal(theEnv,theGlobal)) { if (theGlobal->inScope) return theGlobal; } /*================================================*/ /* If a global in scope couldn't be found in this */ /* module, then move on to the next module. */ /*================================================*/ DefglobalData(theEnv)->TheDefmodule = GetNextDefmodule(theEnv,DefglobalData(theEnv)->TheDefmodule); theItem = (struct defmoduleItemHeader *) GetModuleItem(theEnv,DefglobalData(theEnv)->TheDefmodule,DefglobalData(theEnv)->DefglobalModuleIndex); theGlobal = (Defglobal *) theItem->firstItem; } /*====================================*/ /* All the globals in scope have been */ /* traversed and there are none left. */ /*====================================*/ return NULL; }
static void BsaveBinaryItem( FILE *fp) { unsigned long int space; struct defglobal *theDefglobal; struct bsaveDefglobal newDefglobal; struct defmodule *theModule; struct bsaveDefglobalModule tempDefglobalModule; struct defglobalModule *theModuleItem; /*==========================================================*/ /* Write out the amount of space taken up by the defglobal */ /* and defglobalModule data structures in the binary image. */ /*==========================================================*/ space = NumberOfDefglobals * sizeof(struct bsaveDefglobal) + (NumberOfDefglobalModules * sizeof(struct bsaveDefglobalModule)); GenWrite(&space,(unsigned long) sizeof(unsigned long int),fp); /*=================================================*/ /* Write out each defglobal module data structure. */ /*=================================================*/ NumberOfDefglobals = 0; for (theModule = (struct defmodule *) GetNextDefmodule(NULL); theModule != NULL; theModule = (struct defmodule *) GetNextDefmodule(theModule)) { SetCurrentModule((void *) theModule); theModuleItem = (struct defglobalModule *) GetModuleItem(NULL,FindModuleItem("defglobal")->moduleIndex); AssignBsaveDefmdlItemHdrVals(&tempDefglobalModule.header, &theModuleItem->header); GenWrite(&tempDefglobalModule,(unsigned long) sizeof(struct bsaveDefglobalModule),fp); } /*===========================*/ /* Write out each defglobal. */ /*===========================*/ NumberOfDefglobals = 0; for (theModule = (struct defmodule *) GetNextDefmodule(NULL); theModule != NULL; theModule = (struct defmodule *) GetNextDefmodule(theModule)) { SetCurrentModule((void *) theModule); for (theDefglobal = (struct defglobal *) GetNextDefglobal(NULL); theDefglobal != NULL; theDefglobal = (struct defglobal *) GetNextDefglobal(theDefglobal)) { AssignBsaveConstructHeaderVals(&newDefglobal.header, &theDefglobal->header); newDefglobal.initial = HashedExpressionIndex(theDefglobal->initial); GenWrite(&newDefglobal,(unsigned long) sizeof(struct bsaveDefglobal),fp); } } /*=============================================================*/ /* If a binary image was already loaded when the bsave command */ /* was issued, then restore the counts indicating the number */ /* of defglobals and defglobal modules in the binary image */ /* (these were overwritten by the binary save). */ /*=============================================================*/ if (Bloaded()) { RestoreBloadCount(&NumberOfDefglobalModules); RestoreBloadCount(&NumberOfDefglobals); } }