📄 genrcbin.c
字号:
/*************************************************************
NAME : BsaveRestrictionTypes
DESCRIPTION : Bsaves defgeneric methods' retrictions' types
INPUTS : 1) The defgeneric
2) Output data file pointer
RETURNS : Nothing useful
SIDE EFFECTS : Defgeneric methods' restrictions' types saved
NOTES : None
*************************************************************/
#if IBM_TBC
#pragma argsused
#endif
static void BsaveRestrictionTypes(
void *theEnv,
struct constructHeader *theDefgeneric,
void *userBuffer)
{
DEFGENERIC *gfunc = (DEFGENERIC *) theDefgeneric;
long dummy_type;
RESTRICTION *rptr;
register unsigned i,j,k;
#if MAC_MCW || IBM_MCW || MAC_XCD
#pragma unused(theEnv)
#endif
for (i = 0 ; i < gfunc->mcnt ; i++)
{
for (j = 0 ; j < (unsigned) gfunc->methods[i].restrictionCount ; j++)
{
rptr = &gfunc->methods[i].restrictions[j];
for (k = 0 ; k < rptr->tcnt ; k++)
{
#if OBJECT_SYSTEM
dummy_type = DefclassIndex(rptr->types[k]);
#else
dummy_type = (long) ((INTEGER_HN *) rptr->types[k])->contents;
#endif
GenWrite(&dummy_type,(unsigned long) sizeof(long),(FILE *) userBuffer);
}
}
}
}
#endif
/***********************************************************************
NAME : BloadStorageGenerics
DESCRIPTION : This routine space required for generic function
structures and allocates space for them
INPUTS : Nothing
RETURNS : Nothing useful
SIDE EFFECTS : Arrays allocated and set
NOTES : This routine makes no attempt to reset any pointers
within the structures
***********************************************************************/
static void BloadStorageGenerics(
void *theEnv)
{
unsigned long space;
long counts[5];
GenReadBinary(theEnv,(void *) &space,(unsigned long) sizeof(unsigned long));
if (space == 0L)
return;
GenReadBinary(theEnv,(void *) counts,space);
DefgenericBinaryData(theEnv)->ModuleCount = counts[0];
DefgenericBinaryData(theEnv)->GenericCount = counts[1];
DefgenericBinaryData(theEnv)->MethodCount = counts[2];
DefgenericBinaryData(theEnv)->RestrictionCount = counts[3];
DefgenericBinaryData(theEnv)->TypeCount = counts[4];
if (DefgenericBinaryData(theEnv)->ModuleCount != 0L)
{
space = (unsigned long) (sizeof(DEFGENERIC_MODULE) * DefgenericBinaryData(theEnv)->ModuleCount);
DefgenericBinaryData(theEnv)->ModuleArray = (DEFGENERIC_MODULE *) genlongalloc(theEnv,space);
}
else
return;
if (DefgenericBinaryData(theEnv)->GenericCount != 0L)
{
space = (unsigned long) (sizeof(DEFGENERIC) * DefgenericBinaryData(theEnv)->GenericCount);
DefgenericBinaryData(theEnv)->DefgenericArray = (DEFGENERIC *) genlongalloc(theEnv,space);
}
else
return;
if (DefgenericBinaryData(theEnv)->MethodCount != 0L)
{
space = (unsigned long) (sizeof(DEFMETHOD) * DefgenericBinaryData(theEnv)->MethodCount);
DefgenericBinaryData(theEnv)->MethodArray = (DEFMETHOD *) genlongalloc(theEnv,space);
}
else
return;
if (DefgenericBinaryData(theEnv)->RestrictionCount != 0L)
{
space = (unsigned long) (sizeof(RESTRICTION) * DefgenericBinaryData(theEnv)->RestrictionCount);
DefgenericBinaryData(theEnv)->RestrictionArray = (RESTRICTION *) genlongalloc(theEnv,space);
}
else
return;
if (DefgenericBinaryData(theEnv)->TypeCount != 0L)
{
space = (unsigned long) (sizeof(void *) * DefgenericBinaryData(theEnv)->TypeCount);
DefgenericBinaryData(theEnv)->TypeArray = (void * *) genlongalloc(theEnv,space);
}
}
/*********************************************************************
NAME : BloadGenerics
DESCRIPTION : This routine reads generic function information from
a binary file in four chunks:
Generic-header array
Method array
Method restrictions array
Restriction types array
This routine moves through the generic function
binary arrays updating pointers
INPUTS : None
RETURNS : Nothing useful
SIDE EFFECTS : Pointers reset from array indices
NOTES : Assumes all loading is finished
********************************************************************/
static void BloadGenerics(
void *theEnv)
{
unsigned long space;
GenReadBinary(theEnv,(void *) &space,(unsigned long) sizeof(unsigned long));
if (DefgenericBinaryData(theEnv)->ModuleCount == 0L)
return;
BloadandRefresh(theEnv,DefgenericBinaryData(theEnv)->ModuleCount,(unsigned) sizeof(BSAVE_DEFGENERIC_MODULE),UpdateGenericModule);
if (DefgenericBinaryData(theEnv)->GenericCount == 0L)
return;
BloadandRefresh(theEnv,DefgenericBinaryData(theEnv)->GenericCount,(unsigned) sizeof(BSAVE_GENERIC),UpdateGeneric);
BloadandRefresh(theEnv,DefgenericBinaryData(theEnv)->MethodCount,(unsigned) sizeof(BSAVE_METHOD),UpdateMethod);
BloadandRefresh(theEnv,DefgenericBinaryData(theEnv)->RestrictionCount,(unsigned) sizeof(BSAVE_RESTRICTION),UpdateRestriction);
BloadandRefresh(theEnv,DefgenericBinaryData(theEnv)->TypeCount,(unsigned) sizeof(long),UpdateType);
}
/*********************************************
Bload update routines for generic structures
*********************************************/
static void UpdateGenericModule(
void *theEnv,
void *buf,
long obji)
{
BSAVE_DEFGENERIC_MODULE *bdptr;
bdptr = (BSAVE_DEFGENERIC_MODULE *) buf;
UpdateDefmoduleItemHeader(theEnv,&bdptr->header,&DefgenericBinaryData(theEnv)->ModuleArray[obji].header,
(int) sizeof(DEFGENERIC),(void *) DefgenericBinaryData(theEnv)->DefgenericArray);
}
static void UpdateGeneric(
void *theEnv,
void *buf,
long obji)
{
BSAVE_GENERIC *bgp;
DEFGENERIC *gp;
bgp = (BSAVE_GENERIC *) buf;
gp = (DEFGENERIC *) &DefgenericBinaryData(theEnv)->DefgenericArray[obji];
UpdateConstructHeader(theEnv,&bgp->header,&gp->header,
(int) sizeof(DEFGENERIC_MODULE),(void *) DefgenericBinaryData(theEnv)->ModuleArray,
(int) sizeof(DEFGENERIC),(void *) DefgenericBinaryData(theEnv)->DefgenericArray);
DefgenericBinaryData(theEnv)->DefgenericArray[obji].busy = 0;
#if DEBUGGING_FUNCTIONS
DefgenericBinaryData(theEnv)->DefgenericArray[obji].trace = DefgenericData(theEnv)->WatchGenerics;
#endif
DefgenericBinaryData(theEnv)->DefgenericArray[obji].methods = MethodPointer(bgp->methods);
DefgenericBinaryData(theEnv)->DefgenericArray[obji].mcnt = bgp->mcnt;
DefgenericBinaryData(theEnv)->DefgenericArray[obji].new_index = 0;
}
static void UpdateMethod(
void *theEnv,
void *buf,
long obji)
{
BSAVE_METHOD *bmth;
bmth = (BSAVE_METHOD *) buf;
DefgenericBinaryData(theEnv)->MethodArray[obji].index = bmth->index;
DefgenericBinaryData(theEnv)->MethodArray[obji].busy = 0;
#if DEBUGGING_FUNCTIONS
DefgenericBinaryData(theEnv)->MethodArray[obji].trace = DefgenericData(theEnv)->WatchMethods;
#endif
DefgenericBinaryData(theEnv)->MethodArray[obji].restrictionCount = bmth->restrictionCount;
DefgenericBinaryData(theEnv)->MethodArray[obji].minRestrictions = bmth->minRestrictions;
DefgenericBinaryData(theEnv)->MethodArray[obji].maxRestrictions = bmth->maxRestrictions;
DefgenericBinaryData(theEnv)->MethodArray[obji].localVarCount = bmth->localVarCount;
DefgenericBinaryData(theEnv)->MethodArray[obji].system = bmth->system;
DefgenericBinaryData(theEnv)->MethodArray[obji].restrictions = RestrictionPointer(bmth->restrictions);
DefgenericBinaryData(theEnv)->MethodArray[obji].actions = ExpressionPointer(bmth->actions);
DefgenericBinaryData(theEnv)->MethodArray[obji].ppForm = NULL;
DefgenericBinaryData(theEnv)->MethodArray[obji].usrData = NULL;
}
static void UpdateRestriction(
void *theEnv,
void *buf,
long obji)
{
BSAVE_RESTRICTION *brp;
brp = (BSAVE_RESTRICTION *) buf;
DefgenericBinaryData(theEnv)->RestrictionArray[obji].tcnt = brp->tcnt;
DefgenericBinaryData(theEnv)->RestrictionArray[obji].types = TypePointer(brp->types);
DefgenericBinaryData(theEnv)->RestrictionArray[obji].query = ExpressionPointer(brp->query);
}
static void UpdateType(
void *theEnv,
void *buf,
long obji)
{
#if OBJECT_SYSTEM
DefgenericBinaryData(theEnv)->TypeArray[obji] = (void *) DefclassPointer(* (long *) buf);
#else
if ((* (long *) buf) > (long) INSTANCE_TYPE_CODE)
{
PrintWarningID(theEnv,"GENRCBIN",1,FALSE);
EnvPrintRouter(theEnv,WWARNING,"COOL not installed! User-defined class\n");
EnvPrintRouter(theEnv,WWARNING," in method restriction substituted with OBJECT.\n");
DefgenericBinaryData(theEnv)->TypeArray[obji] = (void *) EnvAddLong(theEnv,(long) OBJECT_TYPE_CODE);
}
else
DefgenericBinaryData(theEnv)->TypeArray[obji] = (void *) EnvAddLong(theEnv,* (long *) buf);
IncrementIntegerCount((INTEGER_HN *) DefgenericBinaryData(theEnv)->TypeArray[obji]);
#endif
}
/***************************************************************
NAME : ClearBloadGenerics
DESCRIPTION : Release all binary-loaded generic function
structure arrays
Resets generic function list to NULL
INPUTS : None
RETURNS : Nothing useful
SIDE EFFECTS : Memory cleared
NOTES : Generic function name symbol counts decremented
***************************************************************/
static void ClearBloadGenerics(
void *theEnv)
{
register long i;
unsigned long space;
space = (unsigned long) (sizeof(DEFGENERIC_MODULE) * DefgenericBinaryData(theEnv)->ModuleCount);
if (space == 0L)
return;
genlongfree(theEnv,(void *) DefgenericBinaryData(theEnv)->ModuleArray,space);
DefgenericBinaryData(theEnv)->ModuleArray = NULL;
DefgenericBinaryData(theEnv)->ModuleCount = 0L;
for (i = 0 ; i < DefgenericBinaryData(theEnv)->GenericCount ; i++)
UnmarkConstructHeader(theEnv,&DefgenericBinaryData(theEnv)->DefgenericArray[i].header);
space = (unsigned long) (sizeof(DEFGENERIC) * DefgenericBinaryData(theEnv)->GenericCount);
if (space == 0L)
return;
genlongfree(theEnv,(void *) DefgenericBinaryData(theEnv)->DefgenericArray,space);
DefgenericBinaryData(theEnv)->DefgenericArray = NULL;
DefgenericBinaryData(theEnv)->GenericCount = 0L;
space = (unsigned long) (sizeof(DEFMETHOD) * DefgenericBinaryData(theEnv)->MethodCount);
if (space == 0L)
return;
genlongfree(theEnv,(void *) DefgenericBinaryData(theEnv)->MethodArray,space);
DefgenericBinaryData(theEnv)->MethodArray = NULL;
DefgenericBinaryData(theEnv)->MethodCount = 0L;
space = (unsigned long) (sizeof(RESTRICTION) * DefgenericBinaryData(theEnv)->RestrictionCount);
if (space == 0L)
return;
genlongfree(theEnv,(void *) DefgenericBinaryData(theEnv)->RestrictionArray,space);
DefgenericBinaryData(theEnv)->RestrictionArray = NULL;
DefgenericBinaryData(theEnv)->RestrictionCount = 0L;
#if ! OBJECT_SYSTEM
for (i = 0 ; i < DefgenericBinaryData(theEnv)->TypeCount ; i++)
DecrementIntegerCount(theEnv,(INTEGER_HN *) DefgenericBinaryData(theEnv)->TypeArray[i]);
#endif
space = (unsigned long) (sizeof(void *) * DefgenericBinaryData(theEnv)->TypeCount);
if (space == 0L)
return;
genlongfree(theEnv,(void *) DefgenericBinaryData(theEnv)->TypeArray,space);
DefgenericBinaryData(theEnv)->TypeArray = NULL;
DefgenericBinaryData(theEnv)->TypeCount = 0L;
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -