📄 csym.c
字号:
hsym->next_sym = sym_list;
sym_list = hsym;
}
HashTab[i] = hsym;
}
// if SymLevel == 0 then should sort the sym_list so that we don't do
// a lot of page thrashing.
if( SymLevel == 0 ) {
for( i = 0; i < MAX_SYM_SEGS; i++ ) {
sym_seglist[i] = NULL;
}
for( hsym = sym_list; hsym; hsym = next_hsymptr ) {
next_hsymptr = hsym->next_sym;
i = hsym->handle / (SYMS_PER_BUF * SYMBUFS_PER_SEG);
hsym->next_sym = sym_seglist[i];
sym_seglist[i] = hsym;
}
sym_list = NULL;
sym_tail = NULL;
for( i = 0; i < MAX_SYM_SEGS; i++ ) {
for( j = 0; j < SYMBUFS_PER_SEG; j++ ) {
sym_buflist[j] = NULL;
sym_buftail[j] = NULL;
}
for( hsym = sym_seglist[i]; hsym; hsym = next_hsymptr ) {
next_hsymptr = hsym->next_sym;
j = (hsym->handle / SYMS_PER_BUF) % SYMBUFS_PER_SEG;
hsym->next_sym = sym_buflist[j];
sym_buflist[j] = hsym;
if( sym_buftail[j] == NULL ) sym_buftail[j] = hsym;
}
for( j = 0; j < SYMBUFS_PER_SEG; j++ ) {
hsym = sym_buflist[j];
if( hsym != NULL ) {
if( sym_list == NULL ) sym_list = hsym;
if( sym_tail != NULL ) sym_tail->next_sym = hsym;
sym_tail = sym_buftail[j];
}
}
}
}
return( sym_list );
}
local SYM_HASHPTR FreeSym()
{
SYM_HASHPTR hsym;
SYM_HASHPTR next_hsymptr;
SYM_HASHPTR sym_list;
int sym_len;
int bucket;
SYM_HANDLE prev_tail;
auto SYM_ENTRY sym;
auto SYM_HANDLE head[BUCKETS];
auto SYM_HANDLE tail[BUCKETS];
#if _CPU == 370 /* MJC */
void *xlist;
InitExtName( &xlist );
#endif
for( bucket = 0; bucket < BUCKETS; ++bucket ) {
head[ bucket ] = 0;
tail[ bucket ] = 0;
}
sym_list = GetSymList();
for( hsym = sym_list; hsym; hsym = next_hsymptr ) {
SymGet( &sym, hsym->handle );
next_hsymptr = hsym->next_sym;
if(( sym.stg_class == SC_TYPEDEF || /* 10-nov-87 FWC */
( SymLevel != 0 ) ||
( sym.flags & (SYM_REFERENCED|SYM_DEFINED) ) ) ||
( sym.stg_class == SC_NULL ) ) {
if( SymLevel == 0 ) {
bucket = SymBucket( &sym );
sym.handle = head[ bucket ];
if( ( sym.flags & SYM_FUNCTION ) == 0 ) { /* if var */
if( sym.stg_class == SC_NULL ) { /* 28-nov-90 */
if( sym.sym_type->decl_type == TYPE_ARRAY ) {
if( sym.sym_type->u.array->dimension == 0 ){
sym.sym_type->u.array->dimension = 1;
}
}
}
AssignSeg( &sym );
} else { /* FUNCTION */ /* 28-oct-91 */
#ifndef WCPP
ChkFunction( &sym, hsym->name );/* 05-nov-91 */
#endif
}
if( tail[ bucket ] == 0 ) {
tail[ bucket ] = hsym->handle;
}
head[ bucket ] = hsym->handle;
}
/* keep static names so that we can output static pubdefs and get nicer
-d1 debugging */
sym_len = far_strlen_plus1( hsym->name );
sym.name = CPermAlloc( sym_len );
far_memcpy( sym.name, hsym->name, sym_len );
sym.info.backinfo = NULL;
SymReplace( &sym, hsym->handle );
}
ChkIncomplete( &sym, hsym->name );
if( SymLevel == 0 ) {
ChkDefined( &sym, hsym->name );
} else {
ChkReference( &sym, hsym->name );
if( sym.stg_class == SC_STATIC && /* 27-nov-91 */
! (sym.flags & SYM_FUNCTION) ) {
CurFuncNode->op.func.flags &= ~FUNC_OK_TO_INLINE;
SymReplace( CurFunc, CurFuncHandle );
}
}
}
if( SymLevel == 0 ) {
GlobalSym = 0;
prev_tail = 0;
for( bucket = BUCKETS - 1; bucket >= 0; --bucket ) {
if( head[ bucket ] != 0 ) {
if( GlobalSym == 0 ) GlobalSym = head[ bucket ];
if( prev_tail != 0 ) {
SymGet( &sym, prev_tail );
sym.handle = head[ bucket ];
SymReplace( &sym, prev_tail );
}
prev_tail = tail[ bucket ];
}
}
}
return( sym_list );
}
void AsgnSegs( SYM_HANDLE sym_handle )
{
auto SYM_ENTRY sym;
for( ; sym_handle; ) {
SymGet( &sym, sym_handle );
if( ( sym.flags & SYM_FUNCTION ) == 0 ) { /* if variable */
AssignSeg( &sym );
SymReplace( &sym, sym_handle );
}
sym_handle = sym.handle;
}
}
void EndBlock()
{
SYM_HASHPTR sym_list;
FreeEnums();
FreeTags();
sym_list = FreeSym();
if( SymLevel != 0 ) {
/* CurFunc->u.func.locals = FreeVars( sym_list ); */
if( SymLevel == 1 ) {
AsgnSegs( CurFunc->u.func.locals );
/* DumpWeights( CurFunc->u.func.locals ); */
} else {
AsgnSegs( GetBlockSymList() );
}
}
--SymLevel;
}
#if 0
local void DumpWeights( SYMPTR sym )
{
if( DebugFlag > 0 ) {
for( ; sym; sym = sym->thread ) {
printf( "%4x: %s\n", sym->u.var.offset, sym->name );
}
}
}
#endif
LABELPTR LkLabel( char *name )
{
LABELPTR label;
label = LabelHead;
while( label != NULL ) {
if( strcmp( name, label->name ) == 0 ) return( label );
label = label->next_label;
}
label = (LABELPTR) CMemAlloc( sizeof( LABELDEFN ) + strlen( name ) );
if( label != NULL ) {
label->next_label = LabelHead;
LabelHead = label;
strcpy( label->name, name );
label->defined = 0;
label->referenced = 0;
label->ref_list = NextLabel();
}
return( label );
}
void FreeLabels()
{
LABELPTR label;
for( ; (label = LabelHead); ) {
LabelHead = label->next_label;
if( label->defined == 0 ) {
CErr2p( ERR_UNDEFINED_LABEL, label->name );
} else if( label->referenced == 0 ) { /* 05-apr-91 */
CWarn( WARN_UNREFERENCED_LABEL, ERR_UNREFERENCED_LABEL,
label->name );
}
CMemFree( label );
}
}
#if 0
static void DoSymPurge( SYMPTR sym )
{
SYMPTR curr;
SYMPTR temp;
if(( sym->flags & SYM_FUNCTION )&&( sym != CurFunc )) {
curr = sym->u.func.parms;
while( curr != NULL ) {
temp = curr->thread;
CMemFree( curr );
curr = temp;
}
curr = sym->u.func.locals;
while( curr != NULL ) {
temp = curr->thread;
CMemFree( curr );
curr = temp;
}
}
CMemFree( sym );
}
#endif
void SymsPurge()
{
LABELPTR label;
label = LabelHead;
while( label != NULL ) {
LabelHead = label->next_label;
CMemFree( label );
label = LabelHead;
}
// EnumInit();
// PurgeTags( TagHead );
TagHead = NULL;
// PurgeTags( DeadTags );
DeadTags = NULL;
#if 0
{
register int i;
register SYMPTR tmp_sym, sym;
for( i = 0; i < SYM_HASH_SIZE; i++ ) {
sym = HashTab[i];
HashTab[i] = NULL;
while( sym != NULL ) {
tmp_sym = sym->next_sym;
DoSymPurge( sym );
sym = tmp_sym;
}
}
sym = GlobalSym;
while( sym != NULL ) {
GlobalSym = sym->thread;
DoSymPurge( sym );
sym = GlobalSym;
}
sym = SpecialSyms;
while( sym != NULL ) {
SpecialSyms = sym->thread;
DoSymPurge( sym );
sym = SpecialSyms;
}
}
#endif
TypesPurge();
}
#if 0 /* can't free these because they are in CPermArea */
local void PurgeTags( TAGPTR tag_head )
{
TAGPTR tag;
FIELDPTR field;
int tag_type;
for( ; tag = tag_head; ) {
tag_type = tag->sym_type->decl_type;
if( tag_type == TYPE_STRUCT || tag_type == TYPE_UNION ) {
for( ; field = tag->u.field_list; ) {
tag->u.field_list = field->next_field;
CMemFree( field );
}
} else { /* tag_type == TYPE_ENUM */
PurgeEnums( tag->u.enum_list );
}
tag_head = tag->next_tag;
CMemFree( tag );
}
}
local void PurgeEnums( ENUM_HANDLE list_head )
{
ENUMPTR ep;
for( ; ep = list_head; ) {
list_head = ep->thread;
CMemFree( ep );
}
}
#endif
XREFPTR NewXref( XREFPTR next_xref )
{
XREFPTR xref;
xref = (XREFPTR) CMemAlloc( sizeof(XREF_ENTRY) );
xref->next_xref = next_xref;
xref->linenum = TokenLine;
xref->filenum = SrcFno;
return( xref );
}
void FreeXrefs( XREFPTR xref )
{
XREFPTR next;
while( xref != NULL ) {
next = xref->next_xref;
CMemFree( xref );
xref = next;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -