label.c
来自「开放源码的编译器open watcom 1.6.0版的源代码」· C语言 代码 · 共 1,084 行 · 第 1/3 页
C
1,084 行
}
if( blk_end ) {
CgFrontCodePtr( IC_BLOCK_END, GetCurrScope() );
}
} else {
if( enclosing != NULL ) {
RingPrune( &enclosing->contains, blk );
CarveFree( carveBLK_INIT, blk );
}
CgFrontCode( IC_BLOCK_DONE );
}
}
void LabelDefFree( // FREE A LABEL DEFN
LAB_DEF *def ) // - the definition
{
LAB_REF *ref;
if( def == NULL ) {
return;
}
RingIterBegSafe( def->forward, ref ) {
LabelRefFree( ref );
} RingIterEndSafe( ref )
CarveFree( carveLAB_DEF, def );
}
void LabelRefFree( // FREE A LABEL REFERENCE
LAB_REF *ref ) // - the reference
{
CarveFree( carveLAB_REF, ref );
}
void LabelBlkTry( // INDICATE TRY BLOCK
TOKEN_LOCN* posn, // - position of "{"
SYMBOL try_var ) // - try variable
{
BLK_INIT *blk; // - BLK_INIT for scope
blk = labelFindBlk( GetCurrScope() );
blk->try_blk = TRUE;
GetCurrScope()->try_catch = TRUE;
blk->locn = *posn;
ScopeKeep( GetCurrScope() );
CgFrontCodePtr( IC_SET_TRY_STATE, try_var );
}
void LabelTryComplete( // TRY HAS BEEN COMPLETED
SYMBOL try_var ) // - try variable
{
CgFrontCodePtr( IC_TRY_DONE, try_var );
}
void LabelBlkCatch( // INDICATE CATCH BLOCK
TOKEN_LOCN* posn, // - position of "{"
void* try_id ) // - id of try block
{
BLK_INIT *blk; // - BLK_INIT for scope
blk = labelFindBlk( GetCurrScope() );
blk->catch_blk = TRUE;
blk->try_id = try_id;
GetCurrScope()->try_catch = TRUE;
blk->locn = *posn;
ScopeKeep( GetCurrScope() );
CgFrontCode( IC_SET_CATCH_STATE );
}
void LabelExprBegin( // START OF REGION FOR TEMPORARIES
void )
{
expr_dtor_bound = currDcledSymbol();
expr_dtor_depth = 0;
labelFlags.has_setjmp = FALSE;
labelFlags.has_newctor = FALSE;
CgFrontCode( IC_NO_OP ); // zapped to IC_EXPR_TEMP, when dtorable temps
ins_temp = CgFrontLastIns();
}
void LabelExprEnd( // END OF REGION FOR TEMPORARIES (AFTER CGDONE)
void )
{
BLK_INIT* blk; // - current BLK_INIT
SCOPE scope; // - current scope
blk = labelFindBlk( GetCurrScope() );
if( expr_dtor_bound != blkDtorSymbol( blk )
|| labelFlags.has_newctor
|| labelFlags.has_setjmp ) {
scope = dtorScope( blk );
CgFrontZapUint( ins_temp, IC_EXPR_TEMP, 0 );
if( labelFlags.has_setjmp ) {
CgFrontCode( IC_SETJMP_DTOR );
}
CgFrontCode( IC_STMT_SCOPE_END );
}
blk->sym_dtored = blk->dcled_dtored;
}
void LabelExprSetjmp( // MARK SETJMP REFERENCE
void )
{
labelFlags.has_setjmp = TRUE;
ScopeMarkVisibleAutosInMem();
}
void LabelExprNewCtor( // MARK NEW-CTOR REFERENCE
void )
{
labelFlags.has_newctor = TRUE;
FunctionRegistrationFlag();
}
void LabelTempDtored( // ENSURE DTOR OF TEMP IS OK
PTREE expr, // - expression for errors
SYMBOL temp ) // - a temporary symbol
{
BLK_INIT *blk; // - current initialization block
expr = expr; // ***** later, use for a better message *****
ClassAccessDtor( temp->sym_type );
blk = labelFindBlk( SymScope( temp ) );
labelMarkDtorSym( blk, temp );
}
void LabelCondTrue( // START TRUE PART OF CONDITIONAL BLOCK
void )
{
COND_BLK* cb; // - conditional block
cb = VstkPush( &stack_cond );
CgFrontCodeUint( IC_COND_TRUE, 0 );
cb->ins_true = CgFrontLastIns();
cb->sym_dtored = currDtorSymbol();
cb->has_false = FALSE;
}
void LabelCondFalse( // START FALSE PART OF CONDITIONAL BLOCK
void )
{
COND_BLK* cb; // - conditional block
cb = VstkTop( &stack_cond );
CgFrontCodeUint( IC_COND_FALSE, 0 );
cb->ins_false = CgFrontLastIns();
cb->has_false = TRUE;
}
void LabelCondEnd( // END OF CONDITIONAL BLOCK
void )
{
COND_BLK* cb; // - conditional block
cb = VstkPop( &stack_cond );
if( cb->sym_dtored != currDtorSymbol() ) {
FunctionRegistrationFlag();
if( cb->has_false ) {
CgFrontZapUint( cb->ins_true, IC_COND_TRUE, 1 );
CgFrontZapUint( cb->ins_false, IC_COND_FALSE, 1 );
CgFrontCodeUint( IC_COND_END, 0 );
} else {
CgFrontZapUint( cb->ins_true, IC_COND_TRUE, 2 );
CgFrontCodeUint( IC_COND_END, 1 );
}
}
}
static void labelInit( // INITIALIZE LABELS (PGM)
INITFINI* defn ) // - definition
{
defn = defn;
carveLAB_DEF = CarveCreate( sizeof( LAB_DEF ), BLOCK_LAB_DEF );
carveLAB_REF = CarveCreate( sizeof( LAB_REF ), BLOCK_LAB_REF );
VstkOpen( &stack_cond, sizeof( COND_BLK ), 16 );
}
static void labelFini( // COMPLETION OF LABLES (PGM)
INITFINI* defn ) // - definition
{
defn = defn;
CarveDestroy( carveLAB_DEF );
CarveDestroy( carveLAB_REF );
VstkClose( &stack_cond );
}
INITDEFN( labels, labelInit, labelFini );
void *LabelBlockOpenFindZap( LAB_MEM *lm, CGFILE_INS *p )
{
BLK_INIT *h;
BLK_INIT *b;
RingIterBeg( lm->blk_hdr, h ) {
if( h->open_zap || h->dead_zap ) {
if( p->block != h->open_ins.block ) continue;
if( p->offset != h->open_ins.offset ) continue;
return( CarveGetIndex( lm->carve, h ) );
}
RingIterBeg( h->contains, b ) {
if( b->open_zap || b->dead_zap ) {
if( p->block != b->open_ins.block ) continue;
if( p->offset != b->open_ins.offset ) continue;
return( CarveGetIndex( lm->carve, b ) );
}
} RingIterEnd( b );
} RingIterEnd( h )
return( (void *) CARVE_NULL_INDEX );
}
CGFILE_INS *LabelBlockOpenAdjustZap( LAB_MEM *lm, void *h )
{
BLK_INIT *b;
b = CarveMapIndex( lm->carve, h );
if( b == NULL ) {
return( NULL );
}
return( &(b->open_ins) );
}
static void markFreeBLK_INIT( void *p )
{
BLK_INIT *b = p;
b->free = TRUE;
}
static void saveBLK_INIT( void *e, carve_walk_base *d )
{
BLK_INIT *b = e;
BLK_INIT *save_next;
BLK_INIT *save_containing;
BLK_INIT *save_contains;
SCOPE save_scope;
SYMBOL save_first_init;
SYMBOL save_sym;
SYMBOL save_sym_containing;
SYMBOL save_sym_dtored;
SYMBOL save_sym_dtored_containing;
SYMBOL save_dcled_dtored;
SRCFILE save_locn_src_file;
SCOPE save_sw_scope;
SYMBOL save_sw_sym;
if( b->free ) {
return;
}
DbgVerify( b->try_id == NULL, "invalid label detected during PCH write" );
save_next = b->next;
b->next = CarveGetIndex( d->extra, save_next );
save_containing = b->containing;
b->containing = CarveGetIndex( d->extra, save_containing );
save_contains = b->contains;
b->contains = CarveGetIndex( d->extra, save_contains );
save_scope = b->scope;
b->scope = ScopeGetIndex( save_scope );
save_first_init = b->first_init;
b->first_init = SymbolGetIndex( save_first_init );
save_sym = b->sym;
b->sym = SymbolGetIndex( save_sym );
save_sym_containing = b->sym_containing;
b->sym_containing = SymbolGetIndex( save_sym_containing );
save_sym_dtored = b->sym_dtored;
b->sym_dtored = SymbolGetIndex( save_sym_dtored );
save_sym_dtored_containing = b->sym_dtored_containing;
b->sym_dtored_containing = SymbolGetIndex( save_sym_dtored_containing );
save_dcled_dtored = b->dcled_dtored;
b->dcled_dtored = SymbolGetIndex( save_dcled_dtored );
save_locn_src_file = b->locn.src_file;
b->locn.src_file = SrcFileGetIndex( save_locn_src_file );
save_sw_scope = b->switch_posn.scope;
b->switch_posn.scope = ScopeGetIndex( save_sw_scope );
save_sw_sym = b->switch_posn.sym;
b->switch_posn.sym = SymbolGetIndex( save_sw_sym );
PCHWriteCVIndex( d->index );
PCHWrite( b, sizeof( *b ) );
b->next = save_next;
b->containing = save_containing;
b->contains = save_contains;
b->scope = save_scope;
b->first_init = save_first_init;
b->sym = save_sym;
b->sym_containing = save_sym_containing;
b->sym_dtored = save_sym_dtored;
b->sym_dtored_containing = save_sym_dtored_containing;
b->dcled_dtored = save_dcled_dtored;
b->locn.src_file = save_locn_src_file;
b->switch_posn.scope = save_sw_scope;
b->switch_posn.sym = save_sw_sym;
}
void LabelPCHWrite( LAB_MEM *p )
{
BLK_INIT *header;
cv_index terminator = CARVE_NULL_INDEX;
cv_index n;
auto carve_walk_base data;
n = CarveLastValidIndex( p->carve );
PCHWriteCVIndex( n );
header = CarveGetIndex( p->carve, p->blk_hdr );
PCHWrite( &header, sizeof( header ) );
data.extra = p->carve;
CarveWalkAllFree( p->carve, markFreeBLK_INIT );
CarveWalkAll( p->carve, saveBLK_INIT, &data );
PCHWrite( &terminator, sizeof( terminator ) );
}
void LabelPCHRead( LAB_MEM *p )
{
BLK_INIT *header;
BLK_INIT *b;
cv_index i;
cv_index n;
auto cvinit_t data;
p->carve = CarveRestart( p->carve );
n = PCHReadCVIndex();
CarveMapOptimize( p->carve, n );
PCHRead( &header, sizeof( header ) );
p->blk_hdr = CarveMapIndex( p->carve, header );
CarveInitStart( p->carve, &data );
for(;;) {
i = PCHReadCVIndex();
if( i == CARVE_NULL_INDEX ) break;
b = CarveInitElement( &data, i );
PCHRead( b, sizeof( *b ) );
b->next = CarveMapIndex( p->carve, b->next );
b->containing = CarveMapIndex( p->carve, b->containing );
b->contains = CarveMapIndex( p->carve, b->contains );
b->scope = ScopeMapIndex( b->scope );
b->first_init = SymbolMapIndex( b->first_init );
b->sym = SymbolMapIndex( b->sym );
b->sym_containing = SymbolMapIndex( b->sym_containing );
b->sym_dtored = SymbolMapIndex( b->sym_dtored );
b->sym_dtored_containing = SymbolMapIndex( b->sym_dtored_containing );
b->dcled_dtored = SymbolMapIndex( b->dcled_dtored );
b->locn.src_file = SrcFileMapIndex( b->locn.src_file );
b->switch_posn.scope = ScopeMapIndex( b->switch_posn.scope );
b->switch_posn.sym = SymbolMapIndex( b->switch_posn.sym );
}
CarveMapUnoptimize( p->carve );
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?