📄 objcmp.c
字号:
3) The max number of indices allowed in an array for this construct set RETURNS : Nothing useful SIDE EFFECTS : Writes out initialization code NOTES : None *******************************************************/#if IBM_TBC#pragma argsused#endifstatic VOID InitObjectsCode(initFP,imageID,maxIndices) FILE *initFP; int imageID; int maxIndices; {#if MAC_MPW || MAC_MCW#pragma unused(maxIndices)#endif fprintf(initFP," ObjectsRunTimeInitialize(%s%d_1,%s%d_1,%s%d_1,%s%d);\n", ClassHashPrefix(),imageID,SlotNameHashPrefix(),imageID, ClassIDPrefix(),imageID,MaxClassIDPrefix(),imageID); }/************************************************************* NAME : ObjectsToCode DESCRIPTION : Writes out static array code for classes, message-handlers, and associated structures INPUTS : 1) The base name of the construct set 2) The base id for this construct 3) The file pointer for the header file 4) The base id for the construct set 5) The max number of indices allowed in an array RETURNS : -1 if no classes, 0 on errors, 1 if object system structures written SIDE EFFECTS : Code written to files NOTES : None *************************************************************/static int ObjectsToCode(fileName,fileID,headerFP,imageID,maxIndices) char *fileName; int fileID; FILE *headerFP; int imageID; int maxIndices; { int fileCount = 1; struct defmodule *theModule; DEFCLASS *theDefclass; register int i; int moduleCount = 0; int itemArrayCounts[SAVE_ITEMS]; int itemArrayVersions[SAVE_ITEMS]; FILE *itemFiles[SAVE_ITEMS]; int itemReopenFlags[SAVE_ITEMS]; struct CodeGeneratorFile itemCodeFiles[SAVE_ITEMS]; for (i = 0 ; i < SAVE_ITEMS ; i++) { itemArrayCounts[i] = 0; itemArrayVersions[i] = 1; itemFiles[i] = NULL; itemReopenFlags[i] = CLIPS_FALSE; itemCodeFiles[i].filePrefix = NULL; } fprintf(headerFP,"#include \"classcom.h\"\n"); fprintf(headerFP,"#include \"classini.h\"\n"); if (ClassIDMapToCode(fileName,fileID,headerFP,imageID,maxIndices,&fileCount) == CLIPS_FALSE) return(0); if (ClassHashTableToCode(fileName,fileID,headerFP,imageID,maxIndices,&fileCount) == CLIPS_FALSE) return(0); if (SlotNameHashTableToCode(fileName,fileID,headerFP,imageID,maxIndices,&fileCount) == CLIPS_FALSE) return(0); if (SlotNameEntriesToCode(fileName,fileID,headerFP,imageID,maxIndices,&fileCount) == CLIPS_FALSE) return(0); /* ============================================================= Loop through all the modules and all the defclasses writing their C code representation to the file as they are traversed ============================================================= */ theModule = (struct defmodule *) GetNextDefmodule(NULL); while (theModule != NULL) { SetCurrentModule((VOID *) theModule); itemFiles[MODULEI] = OpenFileIfNeeded(itemFiles[MODULEI],fileName,fileID,imageID,&fileCount, itemArrayVersions[MODULEI],headerFP, "DEFCLASS_MODULE",ModulePrefix(ObjectCodeItem), itemReopenFlags[MODULEI],&itemCodeFiles[MODULEI]); if (itemFiles[MODULEI] == NULL) goto ObjectCodeError; DefclassModuleToCode(itemFiles[MODULEI],theModule,imageID,maxIndices); itemFiles[MODULEI] = CloseFileIfNeeded(itemFiles[MODULEI],&itemArrayCounts[MODULEI], &itemArrayVersions[MODULEI],maxIndices, &itemReopenFlags[MODULEI],&itemCodeFiles[MODULEI]); for (theDefclass = (DEFCLASS *) GetNextDefclass(NULL) ; theDefclass != NULL ; theDefclass = (DEFCLASS *) GetNextDefclass((VOID *) theDefclass)) { itemFiles[CLASSI] = OpenFileIfNeeded(itemFiles[CLASSI],fileName,fileID,imageID,&fileCount, itemArrayVersions[CLASSI],headerFP, "DEFCLASS",ClassPrefix(), itemReopenFlags[CLASSI],&itemCodeFiles[CLASSI]); if (itemFiles[CLASSI] == NULL) goto ObjectCodeError; SingleDefclassToCode(itemFiles[CLASSI],imageID,maxIndices, theDefclass,moduleCount, itemArrayVersions[LINKI],itemArrayCounts[LINKI], itemArrayVersions[SLOTI],itemArrayCounts[SLOTI], itemArrayVersions[TSLOTI],itemArrayCounts[TSLOTI], itemArrayVersions[OSLOTI],itemArrayCounts[OSLOTI], itemArrayVersions[HANDLERI],itemArrayCounts[HANDLERI], itemArrayVersions[OHANDLERI],itemArrayCounts[OHANDLERI]); itemArrayCounts[CLASSI]++; itemFiles[CLASSI] = CloseFileIfNeeded(itemFiles[CLASSI],&itemArrayCounts[CLASSI], &itemArrayVersions[CLASSI],maxIndices, &itemReopenFlags[CLASSI],&itemCodeFiles[CLASSI]); if (InheritanceLinksToCode(&itemFiles[LINKI],fileName,fileID,imageID, headerFP,&fileCount,maxIndices,theDefclass, &itemArrayVersions[LINKI],&itemArrayCounts[LINKI], &itemReopenFlags[LINKI],&itemCodeFiles[LINKI]) == CLIPS_FALSE) goto ObjectCodeError; if (SlotsToCode(&itemFiles[SLOTI],fileName,fileID,imageID, headerFP,&fileCount,maxIndices,theDefclass, &itemArrayVersions[SLOTI],&itemArrayCounts[SLOTI], &itemReopenFlags[SLOTI],&itemCodeFiles[SLOTI]) == CLIPS_FALSE) goto ObjectCodeError; if (TemplateSlotsToCode(&itemFiles[TSLOTI],fileName,fileID,imageID, headerFP,&fileCount,maxIndices,theDefclass, &itemArrayVersions[TSLOTI],&itemArrayCounts[TSLOTI], &itemReopenFlags[TSLOTI],&itemCodeFiles[TSLOTI]) == CLIPS_FALSE) goto ObjectCodeError; if (OrderedSlotsToCode(&itemFiles[OSLOTI],fileName,fileID,imageID, headerFP,&fileCount,maxIndices,theDefclass, &itemArrayVersions[OSLOTI],&itemArrayCounts[OSLOTI], &itemReopenFlags[OSLOTI],&itemCodeFiles[OSLOTI]) == CLIPS_FALSE) goto ObjectCodeError; if (HandlersToCode(&itemFiles[HANDLERI],fileName,fileID,imageID, headerFP,&fileCount,maxIndices,theDefclass, &itemArrayVersions[HANDLERI],&itemArrayCounts[HANDLERI], &itemReopenFlags[HANDLERI],&itemCodeFiles[HANDLERI]) == CLIPS_FALSE) goto ObjectCodeError; if (OrderedHandlersToCode(&itemFiles[OHANDLERI],fileName,fileID,imageID, headerFP,&fileCount,maxIndices,theDefclass, &itemArrayVersions[OHANDLERI],&itemArrayCounts[OHANDLERI], &itemReopenFlags[OHANDLERI],&itemCodeFiles[OHANDLERI]) == CLIPS_FALSE) goto ObjectCodeError; } theModule = (struct defmodule *) GetNextDefmodule(theModule); moduleCount++; itemArrayCounts[MODULEI]++; } CloseObjectFiles(itemFiles,itemReopenFlags,itemCodeFiles,maxIndices); return(1);ObjectCodeError: CloseObjectFiles(itemFiles,itemReopenFlags,itemCodeFiles,maxIndices); return(0); } /************************************************************ NAME : ClassIDMapToCode DESCRIPTION : Writes out class id map INPUTS : 1) Header file pointer 2) Output file pointer 3) The construct set image id 4) The max # of allowed indices 5) Caller's file count buffer RETURNS : CLIPS_TRUE if all OK, CLIPS_FALSE otherwise SIDE EFFECTS : Class ID Map and Max Indices Written NOTES : None ***********************************************************/static int ClassIDMapToCode(fileName,fileID,headerFP,imageID,maxIndices,fileCount) char *fileName; FILE *headerFP; int fileID,imageID,maxIndices,*fileCount; { FILE *classIDMapFile = NULL; int classIDMapArrayCount, classIDMapArrayVersion = 1; classIDMapFile = OpenFileIfNeeded(classIDMapFile,fileName,fileID,imageID,fileCount, classIDMapArrayVersion,headerFP, "DEFCLASS *",ClassIDPrefix(),CLIPS_FALSE,NULL); if (classIDMapFile == NULL) return(CLIPS_FALSE); for (classIDMapArrayCount = 0 ; classIDMapArrayCount < MaxClassID ; classIDMapArrayCount++) { if (classIDMapArrayCount > 0) fprintf(classIDMapFile,",\n"); PrintClassReference(classIDMapFile,ClassIDMap[classIDMapArrayCount], imageID,maxIndices); } fprintf(classIDMapFile,"};\n\n"); fprintf(classIDMapFile,"unsigned %s%d = %u;\n", MaxClassIDPrefix(),imageID,(unsigned) MaxClassID); fprintf(headerFP,"extern unsigned %s%d;\n",MaxClassIDPrefix(),imageID); fclose(classIDMapFile); return(CLIPS_TRUE); } /************************************************************ NAME : ClassHashTableToCode DESCRIPTION : Writes out class hash table INPUTS : 1) Header file pointer 2) Output file pointer 3) The construct set image id 4) The max # of allowed indices 5) Caller's file count buffer RETURNS : CLIPS_TRUE if all OK, CLIPS_FALSE otherwise SIDE EFFECTS : Class Hash Table Written NOTES : None ***********************************************************/static int ClassHashTableToCode(fileName,fileID,headerFP,imageID,maxIndices,fileCount) char *fileName; FILE *headerFP; int fileID,imageID,maxIndices,*fileCount; { FILE *classHashFile = NULL; int classHashArrayCount, classHashArrayVersion = 1; classHashFile = OpenFileIfNeeded(classHashFile,fileName,fileID,imageID,fileCount, classHashArrayVersion,headerFP, "DEFCLASS *",ClassHashPrefix(),CLIPS_FALSE,NULL); if (classHashFile == NULL) return(CLIPS_FALSE); for (classHashArrayCount = 0 ; classHashArrayCount < CLASS_TABLE_HASH_SIZE ; classHashArrayCount++) { if (classHashArrayCount > 0) fprintf(classHashFile,",\n"); PrintClassReference(classHashFile,ClassTable[classHashArrayCount], imageID,maxIndices); } CloseFileIfNeeded(classHashFile,&classHashArrayCount, &classHashArrayVersion,classHashArrayCount,NULL,NULL); return(CLIPS_TRUE); } /************************************************************ NAME : SlotNameHashTableToCode DESCRIPTION : Writes out slot name entry hash table INPUTS : 1) Header file pointer 2) Output file pointer 3) The construct set image id 4) The max # of allowed indices 5) Caller's version number buffer RETURNS : CLIPS_TRUE if all OK, CLIPS_FALSE otherwise SIDE EFFECTS : Slot Name Hash Table Written NOTES : None ***********************************************************/static int SlotNameHashTableToCode(fileName,fileID,headerFP,imageID,maxIndices,fileCount) char *fileName; FILE *headerFP; int fileID,imageID,maxIndices,*fileCount; { FILE *slotNameHashFile = NULL; int slotNameHashArrayCount, slotNameHashArrayVersion = 1; slotNameHashFile = OpenFileIfNeeded(slotNameHashFile,fileName,fileID, imageID,fileCount, slotNameHashArrayVersion,headerFP, "SLOT_NAME *",SlotNameHashPrefix(),CLIPS_FALSE,NULL); if (slotNameHashFile == NULL) return(CLIPS_FALSE); for (slotNameHashArrayCount = 0 ; slotNameHashArrayCount < SLOT_NAME_TABLE_HASH_SIZE ; slotNameHashArrayCount++) { if (slotNameHashArrayCount > 0) fprintf(slotNameHashFile,",\n"); PrintSlotNameReference(slotNameHashFile,SlotNameTable[slotNameHashArrayCount], imageID,maxIndices); } CloseFileIfNeeded(slotNameHashFile,&slotNameHashArrayCount, &slotNameHashArrayVersion,slotNameHashArrayCount, NULL,NULL); return(CLIPS_TRUE); } /************************************************************ NAME : SlotNameEntriesToCode DESCRIPTION : Writes out slot name entries INPUTS : 1) Header file pointer 2) Output file pointer 3) The construct set image id 4) The max # of allowed indices 5) Caller's version number buffer RETURNS : CLIPS_TRUE if all OK, CLIPS_FALSE otherwise SIDE EFFECTS : Slot name entries Written NOTES : None ***********************************************************/static int SlotNameEntriesToCode(fileName,fileID,headerFP,imageID,maxIndices,fileCount) char *fileName; FILE *headerFP; int fileID,imageID,maxIndices,*fileCount; { FILE *slotNameFile = NULL; int slotNameArrayCount = 0, slotNameArrayVersion = 1; SLOT_NAME *snp; register unsigned i; for (i = 0 ; i < SLOT_NAME_TABLE_HASH_SIZE ; i++) { for (snp = SlotNameTable[i] ; snp != NULL ; snp = snp->nxt) { slotNameFile = OpenFileIfNeeded(slotNameFile,fileName,fileID, imageID,fileCount, slotNameArrayVersion,headerFP, "SLOT_NAME",SlotNamePrefix(),CLIPS_FALSE,NULL); if (slotNameFile == NULL) return(CLIPS_FALSE); fprintf(slotNameFile,"{ %u,1,%u,",snp->hashTableIndex,snp->id); PrintSymbolReference(slotNameFile,snp->name); fprintf(slotNameFile,","); PrintSymbolReference(slotNameFile,snp->putHandlerName); fprintf(slotNameFile,","); PrintSlotNameReference(slotNameFile,snp->nxt,imageID,maxIndices); fprintf(slotNameFile,",0L }"); slotNameArrayCount++; slotNameFile = CloseFileIfNeeded(slotNameFile,&slotNameArrayCount, &slotNameArrayVersion,maxIndices,NULL,NULL);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -