📄 objbin.c
字号:
snp->name->neededSymbol = TRUE;
snp->putHandlerName->neededSymbol = TRUE;
}
}
}
/***************************************************
NAME : MarkDefclassItems
DESCRIPTION : Marks needed items for a defclass
INPUTS : 1) The defclass
2) User buffer (ignored)
RETURNS : Nothing useful
SIDE EFFECTS : Bsave indices set and needed
ephemerals marked
NOTES : None
***************************************************/
#if IBM_TBC
#pragma argsused
#endif
static void MarkDefclassItems(
void *theEnv,
struct constructHeader *theDefclass,
void *buf)
{
#if MAC_MCW || IBM_MCW || MAC_XCD
#pragma unused(buf)
#endif
DEFCLASS *cls = (DEFCLASS *) theDefclass;
register unsigned i;
EXPRESSION *tmpexp;
MarkConstructHeaderNeededItems(&cls->header,ObjectBinaryData(theEnv)->ClassCount++);
ObjectBinaryData(theEnv)->LinkCount += cls->directSuperclasses.classCount +
cls->directSubclasses.classCount +
cls->allSuperclasses.classCount;
#if DEFMODULE_CONSTRUCT
cls->scopeMap->neededBitMap = TRUE;
#endif
/* ===================================================
Mark items needed by slot default value expressions
=================================================== */
for (i = 0 ; i < cls->slotCount ; i++)
{
cls->slots[i].bsaveIndex = ObjectBinaryData(theEnv)->SlotCount++;
cls->slots[i].overrideMessage->neededSymbol = TRUE;
if (cls->slots[i].defaultValue != NULL)
{
if (cls->slots[i].dynamicDefault)
{
ExpressionData(theEnv)->ExpressionCount +=
ExpressionSize((EXPRESSION *) cls->slots[i].defaultValue);
MarkNeededItems(theEnv,(EXPRESSION *) cls->slots[i].defaultValue);
}
else
{
/* =================================================
Static default values are stotred as data objects
and must be converted into expressions
================================================= */
tmpexp =
ConvertValueToExpression(theEnv,(DATA_OBJECT *) cls->slots[i].defaultValue);
ExpressionData(theEnv)->ExpressionCount += ExpressionSize(tmpexp);
MarkNeededItems(theEnv,tmpexp);
ReturnExpression(theEnv,tmpexp);
}
}
}
/* ========================================
Count canonical slots needed by defclass
======================================== */
ObjectBinaryData(theEnv)->TemplateSlotCount += (long) cls->instanceSlotCount;
if (cls->instanceSlotCount != 0)
ObjectBinaryData(theEnv)->SlotNameMapCount += (long) cls->maxSlotNameID + 1;
/* ===============================================
Mark items needed by defmessage-handler actions
=============================================== */
for (i = 0 ; i < cls->handlerCount ; i++)
{
cls->handlers[i].name->neededSymbol = TRUE;
ExpressionData(theEnv)->ExpressionCount += ExpressionSize(cls->handlers[i].actions);
MarkNeededItems(theEnv,cls->handlers[i].actions);
}
ObjectBinaryData(theEnv)->HandlerCount += (long) cls->handlerCount;
}
/***************************************************
NAME : BsaveObjectsExpressions
DESCRIPTION : Writes out all expressions needed
by classes and handlers
INPUTS : The file pointer of the binary file
RETURNS : Nothing useful
SIDE EFFECTS : File updated
NOTES : None
***************************************************/
static void BsaveObjectsExpressions(
void *theEnv,
FILE *fp)
{
if ((ObjectBinaryData(theEnv)->ClassCount == 0L) && (ObjectBinaryData(theEnv)->HandlerCount == 0L))
return;
/* ================================================
Save the defclass slot default value expressions
================================================ */
DoForAllConstructs(theEnv,BsaveDefaultSlotExpressions,DefclassData(theEnv)->DefclassModuleIndex,
FALSE,(void *) fp);
/* ==============================================
Save the defmessage-handler action expressions
============================================== */
DoForAllConstructs(theEnv,BsaveHandlerActionExpressions,DefclassData(theEnv)->DefclassModuleIndex,
FALSE,(void *) fp);
}
/***************************************************
NAME : BsaveDefaultSlotExpressions
DESCRIPTION : Writes expressions for default
slot values to binary file
INPUTS : 1) The defclass
2) The binary file pointer
RETURNS : Nothing useful
SIDE EFFECTS : Slot value expressions written
NOTES : None
***************************************************/
static void BsaveDefaultSlotExpressions(
void *theEnv,
struct constructHeader *theDefclass,
void *buf)
{
DEFCLASS *cls = (DEFCLASS *) theDefclass;
register unsigned i;
EXPRESSION *tmpexp;
for (i = 0 ; i < cls->slotCount ; i++)
{
if (cls->slots[i].defaultValue != NULL)
{
if (cls->slots[i].dynamicDefault)
BsaveExpression(theEnv,(EXPRESSION *) cls->slots[i].defaultValue,(FILE *) buf);
else
{
/* =================================================
Static default values are stotred as data objects
and must be converted into expressions
================================================= */
tmpexp =
ConvertValueToExpression(theEnv,(DATA_OBJECT *) cls->slots[i].defaultValue);
BsaveExpression(theEnv,tmpexp,(FILE *) buf);
ReturnExpression(theEnv,tmpexp);
}
}
}
}
/***************************************************
NAME : BsaveHandlerActionExpressions
DESCRIPTION : Writes expressions for handler
actions to binary file
INPUTS : 1) The defclass
2) The binary file pointer
RETURNS : Nothing useful
SIDE EFFECTS : Handler actions expressions written
NOTES : None
***************************************************/
static void BsaveHandlerActionExpressions(
void *theEnv,
struct constructHeader *theDefclass,
void *buf)
{
DEFCLASS *cls = (DEFCLASS *) theDefclass;
register unsigned i;
for (i = 0 ; i < cls->handlerCount ; i++)
BsaveExpression(theEnv,cls->handlers[i].actions,(FILE *) buf);
}
/*************************************************************************************
NAME : BsaveStorageObjects
DESCRIPTION : Writes out number of each type of structure required for COOL
Space required for counts (unsigned long)
Number of class modules (long)
Number of classes (long)
Number of links to classes (long)
Number of slots (long)
Number of instance template slots (long)
Number of handlers (long)
Number of definstances (long)
INPUTS : File pointer of binary file
RETURNS : Nothing useful
SIDE EFFECTS : Binary file adjusted
NOTES : None
*************************************************************************************/
static void BsaveStorageObjects(
void *theEnv,
FILE *fp)
{
UNLN space;
if ((ObjectBinaryData(theEnv)->ClassCount == 0L) && (ObjectBinaryData(theEnv)->HandlerCount == 0L))
{
space = 0L;
GenWrite((void *) &space,(UNLN) sizeof(long),fp);
return;
}
space = sizeof(long) * 9;
GenWrite((void *) &space,(UNLN) sizeof(long),fp);
GenWrite((void *) &ObjectBinaryData(theEnv)->ModuleCount,(UNLN) sizeof(long),fp);
GenWrite((void *) &ObjectBinaryData(theEnv)->ClassCount,(UNLN) sizeof(long),fp);
GenWrite((void *) &ObjectBinaryData(theEnv)->LinkCount,(UNLN) sizeof(long),fp);
GenWrite((void *) &ObjectBinaryData(theEnv)->SlotNameCount,(UNLN) sizeof(long),fp);
GenWrite((void *) &ObjectBinaryData(theEnv)->SlotCount,(UNLN) sizeof(long),fp);
GenWrite((void *) &ObjectBinaryData(theEnv)->TemplateSlotCount,(UNLN) sizeof(long),fp);
GenWrite((void *) &ObjectBinaryData(theEnv)->SlotNameMapCount,(UNLN) sizeof(long),fp);
GenWrite((void *) &ObjectBinaryData(theEnv)->HandlerCount,(UNLN) sizeof(long),fp);
space = (UNLN) DefclassData(theEnv)->MaxClassID;
GenWrite((void *) &space,(UNLN) sizeof(long),fp);
}
/*************************************************************************************
NAME : BsaveObjects
DESCRIPTION : Writes out classes and message-handlers in binary format
Space required (unsigned long)
Followed by the data structures in order
INPUTS : File pointer of binary file
RETURNS : Nothing useful
SIDE EFFECTS : Binary file adjusted
NOTES : None
*************************************************************************************/
static void BsaveObjects(
void *theEnv,
FILE *fp)
{
UNLN space;
struct defmodule *theModule;
DEFCLASS_MODULE *theModuleItem;
BSAVE_DEFCLASS_MODULE dummy_mitem;
BSAVE_SLOT_NAME dummy_slot_name;
SLOT_NAME *snp;
register unsigned i;
if ((ObjectBinaryData(theEnv)->ClassCount == 0L) && (ObjectBinaryData(theEnv)->HandlerCount == 0L))
{
space = 0L;
GenWrite((void *) &space,(UNLN) sizeof(UNLN),fp);
return;
}
space = (ObjectBinaryData(theEnv)->ModuleCount * (UNLN) sizeof(BSAVE_DEFCLASS_MODULE)) +
(ObjectBinaryData(theEnv)->ClassCount * (UNLN) sizeof(BSAVE_DEFCLASS)) +
(ObjectBinaryData(theEnv)->LinkCount * (UNLN) sizeof(long)) +
(ObjectBinaryData(theEnv)->SlotCount * (UNLN) sizeof(BSAVE_SLOT_DESC)) +
(ObjectBinaryData(theEnv)->SlotNameCount * (UNLN) sizeof(BSAVE_SLOT_NAME)) +
(ObjectBinaryData(theEnv)->TemplateSlotCount * (UNLN) sizeof(long)) +
(ObjectBinaryData(theEnv)->SlotNameMapCount * (UNLN) sizeof(unsigned)) +
(ObjectBinaryData(theEnv)->HandlerCount * (UNLN) sizeof(BSAVE_HANDLER)) +
(ObjectBinaryData(theEnv)->HandlerCount * (UNLN) sizeof(unsigned));
GenWrite((void *) &space,(UNLN) sizeof(UNLN),fp);
ObjectBinaryData(theEnv)->ClassCount = 0L;
ObjectBinaryData(theEnv)->LinkCount = 0L;
ObjectBinaryData(theEnv)->SlotCount = 0L;
ObjectBinaryData(theEnv)->SlotNameCount = 0L;
ObjectBinaryData(theEnv)->TemplateSlotCount = 0L;
ObjectBinaryData(theEnv)->SlotNameMapCount = 0L;
ObjectBinaryData(theEnv)->HandlerCount = 0L;
/* =================================
Write out each defclass module
================================= */
theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,NULL);
while (theModule != NULL)
{
theModuleItem = (DEFCLASS_MODULE *)
GetModuleItem(theEnv,theModule,FindModuleItem(theEnv,"defclass")->moduleIndex);
AssignBsaveDefmdlItemHdrVals(&dummy_mitem.header,&theModuleItem->header);
GenWrite((void *) &dummy_mitem,(unsigned long) sizeof(BSAVE_DEFCLASS_MODULE),fp);
theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,(void *) theModule);
}
/* =====================
Write out the classes
===================== */
DoForAllConstructs(theEnv,BsaveDefclass,DefclassData(theEnv)->DefclassModuleIndex,FALSE,(void *) fp);
/* =========================
Write out the class links
========================= */
ObjectBinaryData(theEnv)->LinkCount = 0L;
DoForAllConstructs(theEnv,BsaveClassLinks,DefclassData(theEnv)->DefclassModuleIndex,FALSE,(void *) fp);
/* ===============================
Write out the slot name entries
=============================== */
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))
{
dummy_slot_name.id = snp->id;
dummy_slot_name.hashTableIndex = snp->hashTableIndex;
dummy_slot_name.name = (long) snp->name->bucket;
dummy_slot_name.putHandlerName = (long) snp->putHandlerName->bucket;
GenWrite((void *) &dummy_slot_name,(UNLN) sizeof(BSAVE_SLOT_NAME),fp);
}
}
/* ===================
Write out the slots
=================== */
DoForAllConstructs(theEnv,BsaveSlots,DefclassData(theEnv)->DefclassModuleIndex,FALSE,(void *) fp);
/* =====================================
Write out the template instance slots
===================================== */
DoForAllConstructs(theEnv,BsaveTemplateSlots,DefclassData(theEnv)->DefclassModuleIndex,FALSE,(void *) fp);
/* =============================================
Write out the ordered instance slot name maps
============================================= */
DoForAllConstructs(theEnv,BsaveSlotMap,DefclassData(theEnv)->DefclassModuleIndex,FALSE,(void *) fp);
/* ==============================
Write out the message-handlers
============================== */
DoForAllConstructs(theEnv,BsaveHandlers,DefclassData(theEnv)->DefclassModuleIndex,FALSE,(void *) fp);
/* ==========================================
Write out the ordered message-handler maps
========================================== */
DoForAllConstructs(theEnv,BsaveHandlerMap,DefclassData(theEnv)->DefclassModuleIndex,FALSE,(void *) fp);
RestoreBloadCount(theEnv,&ObjectBinaryData(theEnv)->ModuleCount);
RestoreBloadCount(theEnv,&ObjectBinaryData(theEnv)->ClassCount);
RestoreBloadCount(theEnv,&ObjectBinaryData(theEnv)->LinkCount);
RestoreBloadCount(theEnv,&ObjectBinaryData(theEnv)->SlotCount);
RestoreBloadCount(theEnv,&ObjectBinaryData(theEnv)->SlotNameCount);
RestoreBloadCount(theEnv,&ObjectBinaryData(theEnv)->TemplateSlotCount);
RestoreBloadCount(theEnv,&ObjectBinaryData(theEnv)->SlotNameMapCount);
RestoreBloadCount(theEnv,&ObjectBinaryData(theEnv)->HandlerCount);
}
/***************************************************
NAME : BsaveDefclass
DESCRIPTION : Writes defclass binary data
INPUTS : 1) The defclass
2) The binary file pointer
RETURNS : Nothing useful
SIDE EFFECTS : Defclass binary data written
NOTES : None
***************************************************/
static void BsaveDefclass(
void *theEnv,
struct constructHeader *theDefclass,
void *buf)
{
DEFCLASS *cls = (DEFCLASS *) theDefclass;
BSAVE_DEFCLASS dummy_class;
AssignBsaveConstructHeaderVals(&dummy_class.header,&cls->header);
dummy_class.abstract = cls->abstract;
dummy_class.reactive = cls->reactive;
dummy_class.system = cls->system;
dummy_class.id = cls->id;
dummy_class.slotCount = cls->slotCount;
dummy_class.instanceSlotCount = cls->instanceSlotCount;
dummy_class.localInstanceSlotCount = cls->localInstanceSlotCount;
dummy_class.maxSlotNameID = cls->maxSlotNameID;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -