⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 objbin.c

📁 NASA 开发使用的一个专家系统
💻 C
📖 第 1 页 / 共 4 页
字号:
   /*******************************************************/   /*      "C" Language Integrated Production System      */   /*                                                     */   /*               CLIPS Version 6.05  04/09/97          */   /*                                                     */   /*                                                     */   /*******************************************************//*************************************************************//* Purpose: Binary Load/Save Functions for Classes and their *//*             message-handlers                              *//*                                                           *//* Principal Programmer(s):                                  *//*      Brian L. Donnell                                     *//*                                                           *//* Contributing Programmer(s):                               *//*                                                           *//* Revision History:                                         *//*                                                           *//*************************************************************/   /* =========================================   *****************************************               EXTERNAL DEFINITIONS   =========================================   ***************************************** */#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 "clipsmem.h"#include "cstrcbin.h"#include "cstrnbin.h"#include "insfun.h"#include "modulbin.h"#include "msgfun.h"#include "prntutil.h"#include "router.h"#define _OBJBIN_SOURCE_#include "objbin.h"/* =========================================   *****************************************                   CONSTANTS   =========================================   ***************************************** */   /* =========================================   *****************************************               MACROS AND TYPES   =========================================   ***************************************** */typedef unsigned long UNLN;#define SlotIndex(p)             (((p) != NULL) ? (p)->bsaveIndex : -1L)#define SlotNameIndex(p)         (p)->bsaveIndex                           #define LinkPointer(i)           (((i) == -1L) ? NULL : (DEFCLASS **) &linkArray[i])#define SlotPointer(i)           (((i) == -1L) ? NULL : (SLOT_DESC *) &slotArray[i])#define TemplateSlotPointer(i)   (((i) == -1L) ? NULL : (SLOT_DESC **) &tmpslotArray[i])#define OrderedSlotPointer(i)    (((i) == -1L) ? NULL : (unsigned *) &mapslotArray[i])#define SlotNamePointer(i)       ((SLOT_NAME *) &slotNameArray[i])#define HandlerPointer(i)        (((i) == -1L) ? NULL : (HANDLER *) &handlerArray[i])#define OrderedHandlerPointer(i) (((i) == -1L) ? NULL : (unsigned *) &maphandlerArray[i])typedef struct bsaveDefclassModule  {   struct bsaveDefmoduleItemHeader header;  } BSAVE_DEFCLASS_MODULE;typedef struct bsavePackedClassLinks  {   unsigned short 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 ANSI_COMPILER#if BLOAD_AND_BSAVEstatic VOID BsaveObjectsFind(void);static VOID MarkDefclassItems(struct constructHeader *,VOID *);static VOID BsaveObjectsExpressions(FILE *);static VOID BsaveDefaultSlotExpressions(struct constructHeader *,VOID *);static VOID BsaveHandlerActionExpressions(struct constructHeader *,VOID *);static VOID BsaveStorageObjects(FILE *);static VOID BsaveObjects(FILE *);static VOID BsaveDefclass(struct constructHeader *,VOID *);static VOID BsaveClassLinks(struct constructHeader *,VOID *);static VOID BsaveSlots(struct constructHeader *,VOID *);static VOID BsaveTemplateSlots(struct constructHeader *,VOID *);static VOID BsaveSlotMap(struct constructHeader *,VOID *);static VOID BsaveHandlers(struct constructHeader *,VOID *);static VOID BsaveHandlerMap(struct constructHeader *,VOID *);#endifstatic VOID BloadStorageObjects(void);static VOID BloadObjects(void);static VOID UpdatePrimitiveClassesMap(void);static VOID UpdateDefclassModule(VOID *,long);static VOID UpdateDefclass(VOID *,long);static VOID UpdateLink(VOID *,long);static VOID UpdateSlot(VOID *,long);static VOID UpdateSlotName(VOID *,long);static VOID UpdateTemplateSlot(VOID *,long);static VOID UpdateHandler(VOID *,long);static VOID ClearBloadObjects(void);#else#if BLOAD_AND_BSAVEstatic VOID BsaveObjectsFind();static VOID MarkDefclassItems();static VOID BsaveObjectsExpressions();static VOID BsaveDefaultSlotExpressions();static VOID BsaveHandlerActionExpressions();static VOID BsaveStorageObjects();static VOID BsaveObjects();static VOID BsaveDefclass();static VOID BsaveClassLinks();static VOID BsaveSlots();static VOID BsaveTemplateSlots();static VOID BsaveSlotMap();static VOID BsaveHandlers();static VOID BsaveHandlerMap();#endifstatic VOID BloadStorageObjects();static VOID BloadObjects();static VOID UpdatePrimitiveClassesMap();static VOID UpdateDefclassModule();static VOID UpdateDefclass();static VOID UpdateLink();static VOID UpdateSlot();static VOID UpdateSlotName();static VOID UpdateTemplateSlot();static VOID UpdateHandler();static VOID ClearBloadObjects();#endif      /* =========================================   *****************************************      EXTERNALLY VISIBLE GLOBAL VARIABLES   =========================================   ***************************************** */globle DEFCLASS HUGE_ADDR *defclassArray = NULL;/* =========================================   *****************************************      INTERNALLY VISIBLE GLOBAL VARIABLES   =========================================   ***************************************** */static long ModuleCount,            ClassCount,            LinkCount,            SlotCount,            SlotNameCount,            TemplateSlotCount,            SlotNameMapCount,            HandlerCount;            static DEFCLASS_MODULE HUGE_ADDR *ModuleArray;static DEFCLASS * HUGE_ADDR *linkArray = NULL;static SLOT_DESC HUGE_ADDR *slotArray = NULL;static SLOT_DESC * HUGE_ADDR *tmpslotArray = NULL;static SLOT_NAME HUGE_ADDR *slotNameArray = NULL;static unsigned HUGE_ADDR *mapslotArray = NULL;static HANDLER HUGE_ADDR *handlerArray = NULL;static unsigned HUGE_ADDR *maphandlerArray = NULL;/* =========================================   *****************************************          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()  {   AddAbortBloadFunction("defclass",CreateSystemClasses,0);   #if BLOAD_AND_BSAVE   AddBinaryItem("defclass",0,BsaveObjectsFind,BsaveObjectsExpressions,                             BsaveStorageObjects,BsaveObjects,                             BloadStorageObjects,BloadObjects,                             ClearBloadObjects);#endif#if BLOAD || BLOAD_ONLY   AddBinaryItem("defclass",0,NULL,NULL,NULL,NULL,                             BloadStorageObjects,BloadObjects,                             ClearBloadObjects);#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(index)  int index;  {   return ((VOID *) &ModuleArray[index]);  }/* =========================================   *****************************************          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()  {   register unsigned i;   SLOT_NAME *snp;      /* ========================================================      The counts need to be saved in case a bload is in effect      ======================================================== */   if (Bloaded())     {      SaveBloadCount(ModuleCount);      SaveBloadCount(ClassCount);      SaveBloadCount(LinkCount);      SaveBloadCount(SlotNameCount);      SaveBloadCount(SlotCount);      SaveBloadCount(TemplateSlotCount);      SaveBloadCount(SlotNameMapCount);      SaveBloadCount(HandlerCount);     }      ModuleCount= 0L;    ClassCount = 0L;   SlotCount = 0L;   SlotNameCount = 0L;   LinkCount = 0L;   TemplateSlotCount = 0L;   SlotNameMapCount = 0L;   HandlerCount = 0L;      /* ==============================================      Mark items needed by defclasses in all modules      ============================================== */   ModuleCount = DoForAllConstructs(MarkDefclassItems,DefclassModuleIndex,                                    CLIPS_FALSE,NULL);        /* =============================================      Mark items needed by canonicalized slot names      ============================================= */   for (i = 0 ; i < SLOT_NAME_TABLE_HASH_SIZE ; i++)     for (snp = SlotNameTable[i] ; snp != NULL ; snp = snp->nxt)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -