?? genrcbin.c
字號:
/*******************************************************/ /* "C" Language Integrated Production System */ /* */ /* CLIPS Version 6.22 06/15/04 */ /* */ /* */ /*******************************************************//*************************************************************//* 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 "envrnmnt.h"#include "memalloc.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"/* ========================================= ***************************************** MACROS AND TYPES ========================================= ***************************************** */#define MethodPointer(i) (((i) == -1L) ? NULL : (DEFMETHOD *) &DefgenericBinaryData(theEnv)->MethodArray[i])#define RestrictionPointer(i) (((i) == -1L) ? NULL : (RESTRICTION *) &DefgenericBinaryData(theEnv)->RestrictionArray[i])#define TypePointer(i) (((i) == -1L) ? NULL : (void **) &DefgenericBinaryData(theEnv)->TypeArray[i])typedef struct bsaveRestriction { long types,query; short 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 BLOAD_AND_BSAVEstatic void BsaveGenericsFind(void *);static void MarkDefgenericItems(void *,struct constructHeader *,void *);static void BsaveGenericsExpressions(void *,FILE *);static void BsaveMethodExpressions(void *,struct constructHeader *,void *);static void BsaveRestrictionExpressions(void *,struct constructHeader *,void *);static void BsaveGenerics(void *,FILE *);static void BsaveDefgenericHeader(void *,struct constructHeader *,void *);static void BsaveMethods(void *,struct constructHeader *,void *);static void BsaveMethodRestrictions(void *,struct constructHeader *,void *);static void BsaveRestrictionTypes(void *,struct constructHeader *,void *);static void BsaveStorageGenerics(void *,FILE *);#endifstatic void BloadStorageGenerics(void *);static void BloadGenerics(void *);static void UpdateGenericModule(void *,void *,long);static void UpdateGeneric(void *,void *,long);static void UpdateMethod(void *,void *,long);static void UpdateRestriction(void *,void *,long);static void UpdateType(void *,void *,long);static void ClearBloadGenerics(void *);static void DeallocateDefgenericBinaryData(void *);/* ========================================= ***************************************** 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( void *theEnv) { AllocateEnvironmentData(theEnv,GENRCBIN_DATA,sizeof(struct defgenericBinaryData),DeallocateDefgenericBinaryData);#if BLOAD_AND_BSAVE AddBinaryItem(theEnv,"generic functions",0,BsaveGenericsFind,BsaveGenericsExpressions, BsaveStorageGenerics,BsaveGenerics, BloadStorageGenerics,BloadGenerics, ClearBloadGenerics);#endif#if BLOAD || BLOAD_ONLY AddBinaryItem(theEnv,"generic functions",0,NULL,NULL,NULL,NULL, BloadStorageGenerics,BloadGenerics, ClearBloadGenerics);#endif } /***********************************************************//* DeallocateDefgenericBinaryData: Deallocates environment *//* data for the defgeneric binary functionality. *//***********************************************************/static void DeallocateDefgenericBinaryData( void *theEnv) {#if (BLOAD || BLOAD_ONLY || BLOAD_AND_BSAVE) && (! RUN_TIME) size_t space; space = DefgenericBinaryData(theEnv)->GenericCount * sizeof(struct defgeneric); if (space != 0) genfree(theEnv,(void *) DefgenericBinaryData(theEnv)->DefgenericArray,space); space = DefgenericBinaryData(theEnv)->MethodCount * sizeof(struct method); if (space != 0) genfree(theEnv,(void *) DefgenericBinaryData(theEnv)->MethodArray,space); space = DefgenericBinaryData(theEnv)->RestrictionCount * sizeof(struct restriction); if (space != 0) genfree(theEnv,(void *) DefgenericBinaryData(theEnv)->RestrictionArray,space); space = DefgenericBinaryData(theEnv)->TypeCount * sizeof(void *); if (space != 0) genfree(theEnv,(void *) DefgenericBinaryData(theEnv)->TypeArray,space); space = DefgenericBinaryData(theEnv)->ModuleCount * sizeof(struct defgenericModule); if (space != 0) genfree(theEnv,(void *) DefgenericBinaryData(theEnv)->ModuleArray,space);#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( void *theEnv, int theIndex) { return ((void *) &DefgenericBinaryData(theEnv)->ModuleArray[theIndex]); }/* ========================================= ***************************************** 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( void *theEnv) { SaveBloadCount(theEnv,DefgenericBinaryData(theEnv)->ModuleCount); SaveBloadCount(theEnv,DefgenericBinaryData(theEnv)->GenericCount); SaveBloadCount(theEnv,DefgenericBinaryData(theEnv)->MethodCount); SaveBloadCount(theEnv,DefgenericBinaryData(theEnv)->RestrictionCount); SaveBloadCount(theEnv,DefgenericBinaryData(theEnv)->TypeCount); DefgenericBinaryData(theEnv)->GenericCount = 0L; DefgenericBinaryData(theEnv)->MethodCount = 0L; DefgenericBinaryData(theEnv)->RestrictionCount = 0L; DefgenericBinaryData(theEnv)->TypeCount = 0L; DefgenericBinaryData(theEnv)->ModuleCount = DoForAllConstructs(theEnv,MarkDefgenericItems,DefgenericData(theEnv)->DefgenericModuleIndex, 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( void *theEnv, struct constructHeader *theDefgeneric, void *userBuffer) {#if MAC_MCW || IBM_MCW || MAC_XCD#pragma unused(userBuffer)#endif DEFGENERIC *gfunc = (DEFGENERIC *) theDefgeneric; long i,j; DEFMETHOD *meth; RESTRICTION *rptr; MarkConstructHeaderNeededItems(&gfunc->header,DefgenericBinaryData(theEnv)->GenericCount++); DefgenericBinaryData(theEnv)->MethodCount += (long) gfunc->mcnt; for (i = 0 ; i < gfunc->mcnt ; i++) { meth = &gfunc->methods[i]; ExpressionData(theEnv)->ExpressionCount += ExpressionSize(meth->actions); MarkNeededItems(theEnv,meth->actions); DefgenericBinaryData(theEnv)->RestrictionCount += meth->restrictionCount; for (j = 0 ; j < meth->restrictionCount ; j++) { rptr = &meth->restrictions[j]; ExpressionData(theEnv)->ExpressionCount += ExpressionSize(rptr->query); MarkNeededItems(theEnv,rptr->query); DefgenericBinaryData(theEnv)->TypeCount += rptr->tcnt; } } }/*************************************************** NAME : BsaveGenericsExpressions DESCRIPTION : Writes out all expressions needed by generic functions INPUTS : The file pointer of the binary file RETURNS : Nothing useful SIDE EFFECTS : File updated NOTES : None ***************************************************/static void BsaveGenericsExpressions( void *theEnv, FILE *fp) {
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -