?? objbin.c
字號:
/*******************************************************/ /* "C" Language Integrated Production System */ /* */ /* CLIPS Version 6.24 05/17/06 */ /* */ /* */ /*******************************************************//*************************************************************//* Purpose: Binary Load/Save Functions for Classes and their *//* message-handlers *//* *//* Principal Programmer(s): *//* Brian L. Donnell *//* *//* Contributing Programmer(s): *//* *//* Revision History: *//* 6.24: Removed IMPERATIVE_MESSAGE_HANDLERS and *//* AUXILIARY_MESSAGE_HANDLERS compilation flags. *//* *//*************************************************************//* ========================================= ***************************************** EXTERNAL DEFINITIONS ========================================= ***************************************** */#include <stdlib.h>#include "setup.h"#if OBJECT_SYSTEM && (BLOAD || BLOAD_ONLY || BLOAD_AND_BSAVE)#include "bload.h"#include "bsave.h"#include "classcom.h"#include "classfun.h"#include "classini.h"#include "cstrcbin.h"#include "cstrnbin.h"#include "envrnmnt.h"#include "insfun.h"#include "memalloc.h"#include "modulbin.h"#include "msgcom.h"#include "msgfun.h"#include "prntutil.h"#include "router.h"#define _OBJBIN_SOURCE_#include "objbin.h"/* ========================================= ***************************************** MACROS AND TYPES ========================================= ***************************************** */#define SlotIndex(p) (((p) != NULL) ? (p)->bsaveIndex : -1L)#define SlotNameIndex(p) (p)->bsaveIndex#define LinkPointer(i) (((i) == -1L) ? NULL : (DEFCLASS **) &ObjectBinaryData(theEnv)->LinkArray[i])#define SlotPointer(i) (((i) == -1L) ? NULL : (SLOT_DESC *) &ObjectBinaryData(theEnv)->SlotArray[i])#define TemplateSlotPointer(i) (((i) == -1L) ? NULL : (SLOT_DESC **) &ObjectBinaryData(theEnv)->TmpslotArray[i])#define OrderedSlotPointer(i) (((i) == -1L) ? NULL : (unsigned *) &ObjectBinaryData(theEnv)->MapslotArray[i])#define SlotNamePointer(i) ((SLOT_NAME *) &ObjectBinaryData(theEnv)->SlotNameArray[i])#define HandlerPointer(i) (((i) == -1L) ? NULL : (HANDLER *) &ObjectBinaryData(theEnv)->HandlerArray[i])#define OrderedHandlerPointer(i) (((i) == -1L) ? NULL : (unsigned *) &ObjectBinaryData(theEnv)->MaphandlerArray[i])typedef struct bsaveDefclassModule { struct bsaveDefmoduleItemHeader header; } BSAVE_DEFCLASS_MODULE;typedef struct bsavePackedClassLinks { long classCount; long classArray; } BSAVE_PACKED_CLASS_LINKS;typedef struct bsaveDefclass { struct bsaveConstructHeader header; unsigned abstract : 1; unsigned reactive : 1; unsigned system : 1; unsigned short id; BSAVE_PACKED_CLASS_LINKS directSuperclasses, directSubclasses, allSuperclasses; unsigned slotCount,localInstanceSlotCount, instanceSlotCount,maxSlotNameID; unsigned handlerCount; long slots, instanceTemplate, slotNameMap, handlers, scopeMap; } BSAVE_DEFCLASS;typedef struct bsaveSlotName { unsigned id, hashTableIndex; long name, putHandlerName; } BSAVE_SLOT_NAME;typedef struct bsaveSlotDescriptor { unsigned shared : 1; unsigned multiple : 1; unsigned composite : 1; unsigned noInherit : 1; unsigned noWrite : 1; unsigned initializeOnly : 1; unsigned dynamicDefault : 1; unsigned noDefault : 1; unsigned reactive : 1; unsigned publicVisibility : 1; unsigned createReadAccessor : 1; unsigned createWriteAccessor : 1; long cls, slotName, defaultValue, constraint, overrideMessage; } BSAVE_SLOT_DESC;typedef struct bsaveMessageHandler { unsigned system : 1; unsigned type : 2; int minParams, maxParams, localVarCount; long name, cls, actions; } BSAVE_HANDLER;typedef struct handlerBsaveInfo { HANDLER *handlers; unsigned *handlerOrderMap; unsigned handlerCount; } HANDLER_BSAVE_INFO;/* ========================================= ***************************************** INTERNALLY VISIBLE FUNCTION HEADERS ========================================= ***************************************** */#if BLOAD_AND_BSAVEstatic void BsaveObjectsFind(void *);static void MarkDefclassItems(void *,struct constructHeader *,void *);static void BsaveObjectsExpressions(void *,FILE *);static void BsaveDefaultSlotExpressions(void *,struct constructHeader *,void *);static void BsaveHandlerActionExpressions(void *,struct constructHeader *,void *);static void BsaveStorageObjects(void *,FILE *);static void BsaveObjects(void *,FILE *);static void BsaveDefclass(void *,struct constructHeader *,void *);static void BsaveClassLinks(void *,struct constructHeader *,void *);static void BsaveSlots(void *,struct constructHeader *,void *);static void BsaveTemplateSlots(void *,struct constructHeader *,void *);static void BsaveSlotMap(void *,struct constructHeader *,void *);static void BsaveHandlers(void *,struct constructHeader *,void *);static void BsaveHandlerMap(void *,struct constructHeader *,void *);#endifstatic void BloadStorageObjects(void *);static void BloadObjects(void *);static void UpdatePrimitiveClassesMap(void *);static void UpdateDefclassModule(void *,void *,long);static void UpdateDefclass(void *,void *,long);static void UpdateLink(void *,void *,long);static void UpdateSlot(void *,void *,long);static void UpdateSlotName(void *,void *,long);static void UpdateTemplateSlot(void *,void *,long);static void UpdateHandler(void *,void *,long);static void ClearBloadObjects(void *);static void DeallocateObjectBinaryData(void *);/* ========================================= ***************************************** EXTERNALLY VISIBLE FUNCTIONS ========================================= ***************************************** *//*********************************************************** NAME : SetupObjectsBload DESCRIPTION : Initializes data structures and routines for binary loads of generic function constructs INPUTS : None RETURNS : Nothing useful SIDE EFFECTS : Routines defined and structures initialized NOTES : None ***********************************************************/globle void SetupObjectsBload( void *theEnv) { AllocateEnvironmentData(theEnv,OBJECTBIN_DATA,sizeof(struct objectBinaryData),DeallocateObjectBinaryData); AddAbortBloadFunction(theEnv,"defclass",CreateSystemClasses,0);#if BLOAD_AND_BSAVE AddBinaryItem(theEnv,"defclass",0,BsaveObjectsFind,BsaveObjectsExpressions, BsaveStorageObjects,BsaveObjects, BloadStorageObjects,BloadObjects, ClearBloadObjects);#endif#if BLOAD || BLOAD_ONLY AddBinaryItem(theEnv,"defclass",0,NULL,NULL,NULL,NULL, BloadStorageObjects,BloadObjects, ClearBloadObjects);#endif } /*******************************************************//* DeallocateObjectBinaryData: Deallocates environment *//* data for object binary functionality. *//*******************************************************/static void DeallocateObjectBinaryData( void *theEnv) { size_t space; long i;#if (BLOAD || BLOAD_ONLY || BLOAD_AND_BSAVE) && (! RUN_TIME) space = (sizeof(DEFCLASS_MODULE) * ObjectBinaryData(theEnv)->ModuleCount); if (space != 0) genfree(theEnv,(void *) ObjectBinaryData(theEnv)->ModuleArray,space); if (ObjectBinaryData(theEnv)->ClassCount != 0) { if (DefclassData(theEnv)->ClassIDMap != NULL) { rm(theEnv,(void *) DefclassData(theEnv)->ClassIDMap,(sizeof(DEFCLASS *) * DefclassData(theEnv)->AvailClassID)); } for (i = 0L ; i < ObjectBinaryData(theEnv)->SlotCount ; i++) { if ((ObjectBinaryData(theEnv)->SlotArray[i].defaultValue != NULL) && (ObjectBinaryData(theEnv)->SlotArray[i].dynamicDefault == 0)) { rtn_struct(theEnv,dataObject,ObjectBinaryData(theEnv)->SlotArray[i].defaultValue); } } space = (sizeof(DEFCLASS) * ObjectBinaryData(theEnv)->ClassCount); if (space != 0L) { genfree(theEnv,(void *) ObjectBinaryData(theEnv)->DefclassArray,space); } space = (sizeof(DEFCLASS *) * ObjectBinaryData(theEnv)->LinkCount); if (space != 0L) { genfree(theEnv,(void *) ObjectBinaryData(theEnv)->LinkArray,space); } space = (sizeof(SLOT_DESC) * ObjectBinaryData(theEnv)->SlotCount); if (space != 0L) { genfree(theEnv,(void *) ObjectBinaryData(theEnv)->SlotArray,space); } space = (sizeof(SLOT_NAME) * ObjectBinaryData(theEnv)->SlotNameCount); if (space != 0L) { genfree(theEnv,(void *) ObjectBinaryData(theEnv)->SlotNameArray,space); } space = (sizeof(SLOT_DESC *) * ObjectBinaryData(theEnv)->TemplateSlotCount); if (space != 0L) { genfree(theEnv,(void *) ObjectBinaryData(theEnv)->TmpslotArray,space); } space = (sizeof(unsigned) * ObjectBinaryData(theEnv)->SlotNameMapCount); if (space != 0L) { genfree(theEnv,(void *) ObjectBinaryData(theEnv)->MapslotArray,space); } } if (ObjectBinaryData(theEnv)->HandlerCount != 0L) { space = (sizeof(HANDLER) * ObjectBinaryData(theEnv)->HandlerCount); if (space != 0L) { genfree(theEnv,(void *) ObjectBinaryData(theEnv)->HandlerArray,space); space = (sizeof(unsigned) * ObjectBinaryData(theEnv)->HandlerCount); genfree(theEnv,(void *) ObjectBinaryData(theEnv)->MaphandlerArray,space); } }#endif }/*************************************************** NAME : BloadDefclassModuleReference DESCRIPTION : Returns a pointer to the appropriate defclass module INPUTS : The index of the module RETURNS : A pointer to the module SIDE EFFECTS : None NOTES : None ***************************************************/globle void *BloadDefclassModuleReference( void *theEnv, int theIndex) { return ((void *) &ObjectBinaryData(theEnv)->ModuleArray[theIndex]); }/* ========================================= ***************************************** INTERNALLY VISIBLE FUNCTIONS ========================================= ***************************************** */#if BLOAD_AND_BSAVE/*************************************************************************** NAME : BsaveObjectsFind DESCRIPTION : For all classes and their message-handlers, this routine marks all the needed symbols and system functions. Also, it also counts the number of expression structures needed. INPUTS : None RETURNS : Nothing useful SIDE EFFECTS : ExpressionCount (a global from BSAVE.C) is incremented for every expression needed Symbols are marked in their structures NOTES : Also sets bsaveIndex for each class (assumes classes will be bsaved in order of binary list) ***************************************************************************/static void BsaveObjectsFind( void *theEnv) { register unsigned i; SLOT_NAME *snp; /* ======================================================== The counts need to be saved in case a bload is in effect ======================================================== */ SaveBloadCount(theEnv,ObjectBinaryData(theEnv)->ModuleCount); SaveBloadCount(theEnv,ObjectBinaryData(theEnv)->ClassCount); SaveBloadCount(theEnv,ObjectBinaryData(theEnv)->LinkCount); SaveBloadCount(theEnv,ObjectBinaryData(theEnv)->SlotNameCount); SaveBloadCount(theEnv,ObjectBinaryData(theEnv)->SlotCount); SaveBloadCount(theEnv,ObjectBinaryData(theEnv)->TemplateSlotCount); SaveBloadCount(theEnv,ObjectBinaryData(theEnv)->SlotNameMapCount); SaveBloadCount(theEnv,ObjectBinaryData(theEnv)->HandlerCount); ObjectBinaryData(theEnv)->ModuleCount= 0L; ObjectBinaryData(theEnv)->ClassCount = 0L; ObjectBinaryData(theEnv)->SlotCount = 0L; ObjectBinaryData(theEnv)->SlotNameCount = 0L; ObjectBinaryData(theEnv)->LinkCount = 0L; ObjectBinaryData(theEnv)->TemplateSlotCount = 0L; ObjectBinaryData(theEnv)->SlotNameMapCount = 0L; ObjectBinaryData(theEnv)->HandlerCount = 0L; /* ============================================== Mark items needed by defclasses in all modules ============================================== */ ObjectBinaryData(theEnv)->ModuleCount = DoForAllConstructs(theEnv,MarkDefclassItems,DefclassData(theEnv)->DefclassModuleIndex, FALSE,NULL); /* ============================================= Mark items needed by canonicalized slot names ============================================= */ for (i = 0 ; i < SLOT_NAME_TABLE_HASH_SIZE ; i++) for (snp = DefclassData(theEnv)->SlotNameTable[i] ; snp != NULL ; snp = snp->nxt) { if ((snp->id != ISA_ID) && (snp->id != NAME_ID)) { snp->bsaveIndex = ObjectBinaryData(theEnv)->SlotNameCount++;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -