📄 objcmp.c
字号:
{
#if MAC_MCW || IBM_MCW || MAC_XCD
#pragma unused(maxIndices)
#endif
fprintf(initFP," ObjectsRunTimeInitialize(theEnv,%s%d_1,%s%d_1,%s%d_1,%s%d);\n",
ClassHashPrefix(),imageID,SlotNameHashPrefix(),imageID,
ClassIDPrefix(),imageID,MaxClassIDPrefix(),imageID);
}
/*************************************************************
NAME : ObjectsToCode
DESCRIPTION : Writes out static array code for
classes, message-handlers, and associated
structures
INPUTS : 1) The base name of the construct set
2) The base id for this construct
3) The file pointer for the header file
4) The base id for the construct set
5) The max number of indices allowed
in an array
RETURNS : -1 if no classes, 0 on errors,
1 if object system structures written
SIDE EFFECTS : Code written to files
NOTES : None
*************************************************************/
static int ObjectsToCode(
void *theEnv,
char *fileName,
int fileID,
FILE *headerFP,
int imageID,
int maxIndices)
{
int fileCount = 1;
struct defmodule *theModule;
DEFCLASS *theDefclass;
register int i;
int moduleCount = 0;
int itemArrayCounts[SAVE_ITEMS];
int itemArrayVersions[SAVE_ITEMS];
FILE *itemFiles[SAVE_ITEMS];
int itemReopenFlags[SAVE_ITEMS];
struct CodeGeneratorFile itemCodeFiles[SAVE_ITEMS];
for (i = 0 ; i < SAVE_ITEMS ; i++)
{
itemArrayCounts[i] = 0;
itemArrayVersions[i] = 1;
itemFiles[i] = NULL;
itemReopenFlags[i] = FALSE;
itemCodeFiles[i].filePrefix = NULL;
}
fprintf(headerFP,"#include \"classcom.h\"\n");
fprintf(headerFP,"#include \"classini.h\"\n");
if (ClassIDMapToCode(theEnv,fileName,fileID,headerFP,imageID,maxIndices,&fileCount)
== FALSE)
return(0);
if (ClassHashTableToCode(theEnv,fileName,fileID,headerFP,imageID,maxIndices,&fileCount)
== FALSE)
return(0);
if (SlotNameHashTableToCode(theEnv,fileName,fileID,headerFP,imageID,maxIndices,&fileCount)
== FALSE)
return(0);
if (SlotNameEntriesToCode(theEnv,fileName,fileID,headerFP,imageID,maxIndices,&fileCount)
== FALSE)
return(0);
/* =============================================================
Loop through all the modules and all the defclasses writing
their C code representation to the file as they are traversed
============================================================= */
theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,NULL);
while (theModule != NULL)
{
EnvSetCurrentModule(theEnv,(void *) theModule);
itemFiles[MODULEI] =
OpenFileIfNeeded(theEnv,itemFiles[MODULEI],fileName,fileID,imageID,&fileCount,
itemArrayVersions[MODULEI],headerFP,
"DEFCLASS_MODULE",ModulePrefix(ObjectCompilerData(theEnv)->ObjectCodeItem),
itemReopenFlags[MODULEI],&itemCodeFiles[MODULEI]);
if (itemFiles[MODULEI] == NULL)
goto ObjectCodeError;
DefclassModuleToCode(theEnv,itemFiles[MODULEI],theModule,imageID,maxIndices);
itemFiles[MODULEI] =
CloseFileIfNeeded(theEnv,itemFiles[MODULEI],&itemArrayCounts[MODULEI],
&itemArrayVersions[MODULEI],maxIndices,
&itemReopenFlags[MODULEI],&itemCodeFiles[MODULEI]);
for (theDefclass = (DEFCLASS *) EnvGetNextDefclass(theEnv,NULL) ;
theDefclass != NULL ;
theDefclass = (DEFCLASS *) EnvGetNextDefclass(theEnv,(void *) theDefclass))
{
itemFiles[CLASSI] =
OpenFileIfNeeded(theEnv,itemFiles[CLASSI],fileName,fileID,imageID,&fileCount,
itemArrayVersions[CLASSI],headerFP,
"DEFCLASS",ClassPrefix(),
itemReopenFlags[CLASSI],&itemCodeFiles[CLASSI]);
if (itemFiles[CLASSI] == NULL)
goto ObjectCodeError;
SingleDefclassToCode(theEnv,itemFiles[CLASSI],imageID,maxIndices,
theDefclass,moduleCount,
itemArrayVersions[LINKI],itemArrayCounts[LINKI],
itemArrayVersions[SLOTI],itemArrayCounts[SLOTI],
itemArrayVersions[TSLOTI],itemArrayCounts[TSLOTI],
itemArrayVersions[OSLOTI],itemArrayCounts[OSLOTI],
itemArrayVersions[HANDLERI],itemArrayCounts[HANDLERI],
itemArrayVersions[OHANDLERI],itemArrayCounts[OHANDLERI]);
itemArrayCounts[CLASSI]++;
itemFiles[CLASSI] =
CloseFileIfNeeded(theEnv,itemFiles[CLASSI],&itemArrayCounts[CLASSI],
&itemArrayVersions[CLASSI],maxIndices,
&itemReopenFlags[CLASSI],&itemCodeFiles[CLASSI]);
if (InheritanceLinksToCode(theEnv,&itemFiles[LINKI],fileName,fileID,imageID,
headerFP,&fileCount,maxIndices,theDefclass,
&itemArrayVersions[LINKI],&itemArrayCounts[LINKI],
&itemReopenFlags[LINKI],&itemCodeFiles[LINKI])
== FALSE)
goto ObjectCodeError;
if (SlotsToCode(theEnv,&itemFiles[SLOTI],fileName,fileID,imageID,
headerFP,&fileCount,maxIndices,theDefclass,
&itemArrayVersions[SLOTI],&itemArrayCounts[SLOTI],
&itemReopenFlags[SLOTI],&itemCodeFiles[SLOTI])
== FALSE)
goto ObjectCodeError;
if (TemplateSlotsToCode(theEnv,&itemFiles[TSLOTI],fileName,fileID,imageID,
headerFP,&fileCount,maxIndices,theDefclass,
&itemArrayVersions[TSLOTI],&itemArrayCounts[TSLOTI],
&itemReopenFlags[TSLOTI],&itemCodeFiles[TSLOTI])
== FALSE)
goto ObjectCodeError;
if (OrderedSlotsToCode(theEnv,&itemFiles[OSLOTI],fileName,fileID,imageID,
headerFP,&fileCount,maxIndices,theDefclass,
&itemArrayVersions[OSLOTI],&itemArrayCounts[OSLOTI],
&itemReopenFlags[OSLOTI],&itemCodeFiles[OSLOTI])
== FALSE)
goto ObjectCodeError;
if (HandlersToCode(theEnv,&itemFiles[HANDLERI],fileName,fileID,imageID,
headerFP,&fileCount,maxIndices,theDefclass,
&itemArrayVersions[HANDLERI],&itemArrayCounts[HANDLERI],
&itemReopenFlags[HANDLERI],&itemCodeFiles[HANDLERI])
== FALSE)
goto ObjectCodeError;
if (OrderedHandlersToCode(theEnv,&itemFiles[OHANDLERI],fileName,fileID,imageID,
headerFP,&fileCount,maxIndices,theDefclass,
&itemArrayVersions[OHANDLERI],&itemArrayCounts[OHANDLERI],
&itemReopenFlags[OHANDLERI],&itemCodeFiles[OHANDLERI])
== FALSE)
goto ObjectCodeError;
}
theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,theModule);
moduleCount++;
itemArrayCounts[MODULEI]++;
}
CloseObjectFiles(theEnv,itemFiles,itemReopenFlags,itemCodeFiles,maxIndices);
return(1);
ObjectCodeError:
CloseObjectFiles(theEnv,itemFiles,itemReopenFlags,itemCodeFiles,maxIndices);
return(0);
}
/************************************************************
NAME : ClassIDMapToCode
DESCRIPTION : Writes out class id map
INPUTS : 1) Header file pointer
2) Output file pointer
3) The construct set image id
4) The max # of allowed indices
5) Caller's file count buffer
RETURNS : TRUE if all OK, FALSE otherwise
SIDE EFFECTS : Class ID Map and Max Indices Written
NOTES : None
***********************************************************/
static int ClassIDMapToCode(
void *theEnv,
char *fileName,
int fileID,
FILE *headerFP,
int imageID,
int maxIndices,
int *fileCount)
{
FILE *classIDMapFile = NULL;
int classIDMapArrayCount,
classIDMapArrayVersion = 1;
classIDMapFile = OpenFileIfNeeded(theEnv,classIDMapFile,fileName,fileID,imageID,fileCount,
classIDMapArrayVersion,headerFP,
"DEFCLASS *",ClassIDPrefix(),FALSE,NULL);
if (classIDMapFile == NULL)
return(FALSE);
for (classIDMapArrayCount = 0 ;
classIDMapArrayCount < DefclassData(theEnv)->MaxClassID ;
classIDMapArrayCount++)
{
if (classIDMapArrayCount > 0)
fprintf(classIDMapFile,",\n");
PrintClassReference(theEnv,classIDMapFile,DefclassData(theEnv)->ClassIDMap[classIDMapArrayCount],
imageID,maxIndices);
}
fprintf(classIDMapFile,"};\n\n");
fprintf(classIDMapFile,"unsigned %s%d = %u;\n",
MaxClassIDPrefix(),imageID,(unsigned) DefclassData(theEnv)->MaxClassID);
fprintf(headerFP,"extern unsigned %s%d;\n",MaxClassIDPrefix(),imageID);
GenClose(theEnv,classIDMapFile);
return(TRUE);
}
/************************************************************
NAME : ClassHashTableToCode
DESCRIPTION : Writes out class hash table
INPUTS : 1) Header file pointer
2) Output file pointer
3) The construct set image id
4) The max # of allowed indices
5) Caller's file count buffer
RETURNS : TRUE if all OK, FALSE otherwise
SIDE EFFECTS : Class Hash Table Written
NOTES : None
***********************************************************/
static int ClassHashTableToCode(
void *theEnv,
char *fileName,
int fileID,
FILE *headerFP,
int imageID,
int maxIndices,
int *fileCount)
{
FILE *classHashFile = NULL;
int classHashArrayCount,
classHashArrayVersion = 1;
classHashFile = OpenFileIfNeeded(theEnv,classHashFile,fileName,fileID,imageID,fileCount,
classHashArrayVersion,headerFP,
"DEFCLASS *",ClassHashPrefix(),FALSE,NULL);
if (classHashFile == NULL)
return(FALSE);
for (classHashArrayCount = 0 ;
classHashArrayCount < CLASS_TABLE_HASH_SIZE ;
classHashArrayCount++)
{
if (classHashArrayCount > 0)
fprintf(classHashFile,",\n");
PrintClassReference(theEnv,classHashFile,DefclassData(theEnv)->ClassTable[classHashArrayCount],
imageID,maxIndices);
}
CloseFileIfNeeded(theEnv,classHashFile,&classHashArrayCount,
&classHashArrayVersion,classHashArrayCount,NULL,NULL);
return(TRUE);
}
/************************************************************
NAME : SlotNameHashTableToCode
DESCRIPTION : Writes out slot name entry hash table
INPUTS : 1) Header file pointer
2) Output file pointer
3) The construct set image id
4) The max # of allowed indices
5) Caller's version number buffer
RETURNS : TRUE if all OK, FALSE otherwise
SIDE EFFECTS : Slot Name Hash Table Written
NOTES : None
***********************************************************/
static int SlotNameHashTableToCode(
void *theEnv,
char *fileName,
int fileID,
FILE *headerFP,
int imageID,
int maxIndices,
int *fileCount)
{
FILE *slotNameHashFile = NULL;
int slotNameHashArrayCount,
slotNameHashArrayVersion = 1;
slotNameHashFile = OpenFileIfNeeded(theEnv,slotNameHashFile,fileName,fileID,
imageID,fileCount,
slotNameHashArrayVersion,headerFP,
"SLOT_NAME *",SlotNameHashPrefix(),FALSE,NULL);
if (slotNameHashFile == NULL)
return(FALSE);
for (slotNameHashArrayCount = 0 ;
slotNameHashArrayCount < SLOT_NAME_TABLE_HASH_SIZE ;
slotNameHashArrayCount++)
{
if (slotNameHashArrayCount > 0)
fprintf(slotNameHashFile,",\n");
PrintSlotNameReference(theEnv,slotNameHashFile,DefclassData(theEnv)->SlotNameTable[slotNameHashArrayCount],
imageID,maxIndices);
}
CloseFileIfNeeded(theEnv,slotNameHashFile,&slotNameHashArrayCount,
&slotNameHashArrayVersion,slotNameHashArrayCount,
NULL,NULL);
return(TRUE);
}
/************************************************************
NAME : SlotNameEntriesToCode
DESCRIPTION : Writes out slot name entries
INPUTS : 1) Header file pointer
2) Output file pointer
3) The construct set image id
4) The max # of allowed indices
5) Caller's version number buffer
RETURNS : TRUE if all OK, FALSE otherwise
SIDE EFFECTS : Slot name entries Written
NOTES : None
***********************************************************/
static int SlotNameEntriesToCode(
void *theEnv,
char *fileName,
int fileID,
FILE *headerFP,
int imageID,
int maxIndices,
int *fileCount)
{
FILE *slotNameFile = NULL;
int slotNameArrayCount = 0,
slotNameArrayVersion = 1;
SLOT_NAME *snp;
register unsigned i;
for (i = 0 ; i < SLOT_NAME_TABLE_HASH_SIZE ; i++)
{
for (snp = DefclassData(theEnv)->SlotNameTable[i] ; snp != NULL ; snp = snp->nxt)
{
slotNameFile = OpenFileIfNeeded(theEnv,slotNameFile,fileName,fileID,
imageID,fileCount,
slotNameArrayVersion,headerFP,
"SLOT_NAME",SlotNamePrefix(),FALSE,NULL);
if (slotNameFile == NULL)
return(FALSE);
fprintf(slotNameFile,"{ %u,1,%u,",snp->hashTableIndex,snp->id);
PrintSymbolReference(theEnv,slotNameFile,snp->name);
fprintf(slotNameFile,",");
PrintSymbolReference(theEnv,slotNameFile,snp->putHandlerName);
fprintf(slotNameFile,",");
PrintSlotNameReference(theEnv,slotNameFile,snp->nxt,imageID,maxIndices);
fprintf(slotNameFile,",0L }");
slotNameArrayCount++;
slotNameFile = CloseFileIfNeeded(theEnv,slotNameFile,&slotNameArrayCount,
&slotNameArrayVersion,maxIndices,NULL,NULL);
}
}
if (slotNameFile != NULL)
CloseFileIfNeeded(theEnv,slotNameFile,&slotNameArrayCount,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -