📄 genrcbin.c
字号:
/*******************************************************/ /* "C" Language Integrated Production System */ /* */ /* CLIPS Version 6.05 04/09/97 */ /* */ /* */ /*******************************************************//*************************************************************//* Purpose: Binary Load/Save Functions for Generic Functions *//* *//* Principal Programmer(s): *//* Brian L. Donnell *//* *//* Contributing Programmer(s): *//* *//* Revision History: *//* *//*************************************************************/ /* ========================================= ***************************************** EXTERNAL DEFINITIONS ========================================= ***************************************** */#include "setup.h"#if DEFGENERIC_CONSTRUCT && (BLOAD || BLOAD_ONLY || BLOAD_AND_BSAVE)#include "constant.h"#include "clipsmem.h"#include "bload.h"#include "bsave.h"#include "cstrcbin.h"#if OBJECT_SYSTEM#include "objbin.h"#endif#include "genrccom.h"#include "modulbin.h"#define _GENRCBIN_SOURCE_#include "genrcbin.h"#include "router.h"/* ========================================= ***************************************** CONSTANTS ========================================= ***************************************** */ /* ========================================= ***************************************** MACROS AND TYPES ========================================= ***************************************** */ #define MethodPointer(i) (((i) == -1L) ? NULL : (DEFMETHOD *) &methodArray[i])#define RestrictionPointer(i) (((i) == -1L) ? NULL : (RESTRICTION *) &restrictionArray[i])#define TypePointer(i) (((i) == -1L) ? NULL : (VOID **) &typeArray[i])typedef struct bsaveRestriction { long types,query; unsigned tcnt; } BSAVE_RESTRICTION;typedef struct bsaveMethod { unsigned index; int restrictionCount, minRestrictions,maxRestrictions, localVarCount; int system; long restrictions,actions; } BSAVE_METHOD;typedef struct bsaveGenericFunc { struct bsaveConstructHeader header; long methods; unsigned mcnt; } BSAVE_GENERIC;typedef struct bsaveGenericModule { struct bsaveDefmoduleItemHeader header; } BSAVE_DEFGENERIC_MODULE;/* ========================================= ***************************************** INTERNALLY VISIBLE FUNCTION HEADERS ========================================= ***************************************** */#if ANSI_COMPILER#if BLOAD_AND_BSAVEstatic VOID BsaveGenericsFind(void);static VOID MarkDefgenericItems(struct constructHeader *,VOID *);static VOID BsaveGenericsExpressions(FILE *);static VOID BsaveMethodExpressions(struct constructHeader *,VOID *);static VOID BsaveRestrictionExpressions(struct constructHeader *,VOID *);static VOID BsaveGenerics(FILE *);static VOID BsaveDefgenericHeader(struct constructHeader *,VOID *);static VOID BsaveMethods(struct constructHeader *,VOID *);static VOID BsaveMethodRestrictions(struct constructHeader *,VOID *);static VOID BsaveRestrictionTypes(struct constructHeader *,VOID *);static VOID BsaveStorageGenerics(FILE *);#endifstatic VOID BloadStorageGenerics(void);static VOID BloadGenerics(void);static VOID UpdateGenericModule(VOID *,long);static VOID UpdateGeneric(VOID *,long);static VOID UpdateMethod(VOID *,long);static VOID UpdateRestriction(VOID *,long);static VOID UpdateType(VOID *,long);static VOID ClearBloadGenerics(void);#else#if BLOAD_AND_BSAVEstatic VOID BsaveGenericsFind();static VOID MarkDefgenericItems();static VOID BsaveGenericsExpressions();static VOID BsaveMethodExpressions();static VOID BsaveRestrictionExpressions();static VOID BsaveGenerics();static VOID BsaveDefgenericHeader();static VOID BsaveMethods();static VOID BsaveMethodRestrictions();static VOID BsaveRestrictionTypes();static VOID BsaveStorageGenerics();#endifstatic VOID BloadStorageGenerics();static VOID BloadGenerics();static VOID UpdateGenericModule();static VOID UpdateGeneric();static VOID UpdateMethod();static VOID UpdateRestriction();static VOID UpdateType();static VOID ClearBloadGenerics();#endif /* ========================================= ***************************************** EXTERNALLY VISIBLE GLOBAL VARIABLES ========================================= ***************************************** */globle DEFGENERIC HUGE_ADDR *defgenericArray = NULL;/* ========================================= ***************************************** INTERNALLY VISIBLE GLOBAL VARIABLES ========================================= ***************************************** */static long ModuleCount = 0L, GenericCount = 0L, MethodCount = 0L, RestrictionCount = 0L, TypeCount = 0L; static DEFGENERIC_MODULE HUGE_ADDR *ModuleArray = NULL;static DEFMETHOD HUGE_ADDR *methodArray = NULL;static RESTRICTION HUGE_ADDR *restrictionArray = NULL;static VOID * HUGE_ADDR *typeArray = NULL;/* ========================================= ***************************************** EXTERNALLY VISIBLE FUNCTIONS ========================================= ***************************************** */ /*********************************************************** NAME : SetupGenericsBload 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 SetupGenericsBload() {#if BLOAD_AND_BSAVE AddBinaryItem("generic functions",0,BsaveGenericsFind,BsaveGenericsExpressions, BsaveStorageGenerics,BsaveGenerics, BloadStorageGenerics,BloadGenerics, ClearBloadGenerics);#endif#if BLOAD || BLOAD_ONLY AddBinaryItem("generic functions",0,NULL,NULL,NULL,NULL, BloadStorageGenerics,BloadGenerics, ClearBloadGenerics);#endif } /*************************************************** NAME : BloadDefgenericModuleReference DESCRIPTION : Returns a pointer to the appropriate defgeneric module INPUTS : The index of the module RETURNS : A pointer to the module SIDE EFFECTS : None NOTES : None ***************************************************/globle VOID *BloadDefgenericModuleReference(index) int index; { return ((VOID *) &ModuleArray[index]); }/* ========================================= ***************************************** INTERNALLY VISIBLE FUNCTIONS ========================================= ***************************************** */#if BLOAD_AND_BSAVE/*************************************************************************** NAME : BsaveGenericsFind DESCRIPTION : For all generic functions and their methods, this routine marks all the needed symbols and system functions. Also, it also counts the number of expression structures needed. Also, counts total number of generics, methods, restrictions and types. INPUTS : None RETURNS : Nothing useful SIDE EFFECTS : ExpressionCount (a global from BSAVE.C) is incremented for every expression needed Symbols and system function are marked in their structures NOTES : Also sets bsaveIndex for each generic function (assumes generic functions will be bsaved in order of binary list) ***************************************************************************/static VOID BsaveGenericsFind() { if (Bloaded()) { SaveBloadCount(ModuleCount); SaveBloadCount(GenericCount); SaveBloadCount(MethodCount); SaveBloadCount(RestrictionCount); SaveBloadCount(TypeCount); } GenericCount = 0L; MethodCount = 0L; RestrictionCount = 0L; TypeCount = 0L; ModuleCount = DoForAllConstructs(MarkDefgenericItems,DefgenericModuleIndex, CLIPS_FALSE,NULL); } /*************************************************** NAME : MarkDefgenericItems DESCRIPTION : Marks the needed items for a defgeneric (and methods) bsave INPUTS : 1) The defgeneric 2) User data buffer (ignored) RETURNS : Nothing useful SIDE EFFECTS : Needed items marked NOTES : None ***************************************************/#if IBM_TBC#pragma argsused#endifstatic VOID MarkDefgenericItems(theDefgeneric,userBuffer) struct constructHeader *theDefgeneric; VOID *userBuffer; {#if MAC_MPW || MAC_MCW#pragma unused(userBuffer)#endif DEFGENERIC *gfunc = (DEFGENERIC *) theDefgeneric; register unsigned i,j; DEFMETHOD *meth; RESTRICTION *rptr; MarkConstructHeaderNeededItems(&gfunc->header,GenericCount++); MethodCount += gfunc->mcnt; for (i = 0 ; i < gfunc->mcnt ; i++) { meth = &gfunc->methods[i]; ExpressionCount += ExpressionSize(meth->actions); MarkNeededItems(meth->actions); RestrictionCount += meth->restrictionCount;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -