brinfo.c
来自「开放源码的编译器open watcom 1.6.0版的源代码」· C语言 代码 · 共 1,329 行 · 第 1/3 页
C
1,329 行
}
if( !in_template && sscope != NULL ) {
for( ;; ) {
if( scope->id == SCOPE_TEMPLATE_PARM ) {
in_template = TRUE;
break;
}
if( scope == sscope ) break;
scope = scope->enclosing;
}
}
if( !in_template ) {
adjustSrcFile( locn );
}
for( ; sscope != NULL; ) {
_dbgScope( sscope, "Br-inf-opn" );
ShcVerify( ! short_circuit
, "failed short-circuit assumption" );
brinfIcPtr( IC_BR_SCOPE_OPN, sscope );
recordBlkScopeIns( sscope );
PstkPush( &active_scopes, sscope );
sscope = PstkIterDnNext( &sym_iter );
}
for( ; ; ) {
SCOPE top = PstkPopElement( &sym_scopes );
if( NULL == top ) break;
}
}
retn = TRUE;
} else {
retn = FALSE;
}
return retn;
}
#undef ShcVerify
static boolean activeScopesAdjust // ADJUST ACTIVE SCOPES
( SYMBOL sym )
{
boolean retn; // - return: TRUE ==> scope for symbol
TOKEN_LOCN *locn;
if( NULL == sym->name ) {
retn = FALSE;
} else {
SCOPE scope = sym->name->containing;
if( NULL == scope ) {
retn = FALSE;
} else {
if( sym->locn != NULL ){
locn = &sym->locn->tl;
} else {
locn = NULL;
}
retn = activeScopesReset( scope, locn );
}
}
return retn;
}
static void destroyBrinfData // DESTROY ALL DATA
( void )
{
CarveDestroy( carve_scope_ins );
CarveDestroy( carve_blk_scope );
PstkClose( &active_scopes );
PstkClose( &sym_scopes );
}
static void activeScopesClose // CLOSE ACTIVE SCOPES
( void )
{
if( canWriteIc() ) {
for( ; ; ) {
SCOPE act = PstkPopElement( &active_scopes );
if( NULL == act ) break;
closeScopeIc( act );
}
}
if( BrinfActive() ) {
ACTBLK* act; // - active blk
RingIterBegSafe( ring_active_blks, act ) {
endBlkScope( act->scope );
} RingIterEndSafe( act );
destroyBrinfData();
}
}
void BrinfIcReference // WRITE OUT A REFERENCE
( CGINTEROP opcode // - opcode
, void const *ptr // - operand
, TOKEN_LOCN const* locn ) // - location
{
if( ref_file != locn->src_file ) {
ref_file = locn->src_file;
brinfIcPtr( IC_BR_REFTO_FILE, ref_file );
ref_line = 0;
ref_col = 0;
}
if( ref_line != locn->line ) {
ref_line = locn->line;
if( ref_line <= 0xFFFFFF
&& locn->column <= 0xFF ) {
ref_col = locn->column;
brinfIcBin( IC_BR_REFTO_LINECOL
, (ref_line << 8 ) + ref_col );
} else {
brinfIcBin( IC_BR_REFTO_LINE, ref_line );
}
}
if( ref_col != locn->column ) {
ref_col = locn->column;
brinfIcBin( IC_BR_REFTO_COL, ref_col );
}
brinfIcPtr( opcode, ptr );
}
static void brinfIcReference // WRITE OUT A REFERENCE, IF REQ'D
( CGINTEROP opcode // - opcode
, void const *ptr // - operand
, TOKEN_LOCN const* locn ) // - location
{
TOKEN_LOCN curr_locn;
locn = adjustLocn( locn, &curr_locn );
if( NULL == locn ) return;
if( canWriteIc()
&& activeScopesReset( GetCurrScope(), locn ) ) {
BrinfIcReference( opcode, ptr, locn );
}
}
void BrinfWriteSrcOpen // WRITE IC'S FOR SOURCE OPEN
( char const * fname // - file name (as entered)
, TOKEN_LOCN const* locn // - location
, SRCDEP const *dep ) // - dependency entry
{
brinfIcReference( IC_BR_INC_SRC, fname, locn );
brinfIcPtr( IC_BR_SRC_BEG, dep );
}
void BrinfWriteSrcClose // WRITE IC'S FOR SOURCE CLOSE
( void )
{
brinfIcPtr( IC_BR_SRC_END, NULL );
}
static void brinfIcDclSym // PUT OUT A SYMBOL DECLARATION
( CGINTEROP opcode // - opcode
, SYMBOL sym ) // - the symbol
{
//adjustSrcFile( &sym->locn->tl );
brinfIcPtr( opcode, sym );
}
static void typeUsage // TYPE USAGE
( TYPE type // - the type
, TOKEN_LOCN* locn ) // - reference location
{
if( CompFlags.optbr_t ) {
for( ; type != NULL; type = type->of ) {
switch( type->id ) {
case TYP_ENUM :
case TYP_CLASS :
brinfIcReference( IC_BR_REF_TYPE, type, locn );
break;
case TYP_MEMBER_POINTER :
brinfIcReference( IC_BR_REF_TYPE, type->u.mp.host, locn );
continue;
case TYP_FUNCTION :
{ arg_list* args = type->u.f.args;
int count = args->num_args;
for( ; count > 0; ) {
-- count;
typeUsage( args->type_list[count], locn );
}
}
// drops thru
default :
continue;
}
break;
}
}
}
static void refSymType // REFERENCE TYPES FOR A DECLARED SYMBOL
( SYMBOL sym ) // - the symbol
{
if( sym->flag2 & SF2_TOKEN_LOCN ) {
typeUsage( sym->sym_type, &sym->locn->tl );
}
}
static void fatalIoErr // SIGNAL FATAL I/O ERROR
( char const * msg // - message
, char const * file_name ) // - file name
{
puts( strerror( errno ) );
puts( file_name );
CFatal( (char*)msg );
}
static void usageIoErr // SIGNAL FATAL I/O ERROR: USAGE FILE
( char const * msg ) // - message
{
fatalIoErr( msg, usage_name );
}
static int brinfWrite // WRITE CALLBACK FUNCTION
( int cookie
, void const *buf // - write buffer
, unsigned len ) // - write length
{
FILE *fp = (FILE *) cookie;
int result;
result = fwrite(buf, 1, len, fp);
return result;
}
static long brinfLSeek // LSEEK CALLBACK FUNCTION
( int cookie
, long offset // - seek offset
, int whence ) // - seek direction, see b_write.h
{
FILE *fp = (FILE *) cookie;
fseek(fp, offset, whence);
return ftell(fp);
}
static BRI_Routines const rtns =// CALL-BACK FOR BROWSE WRITER
{ &brinfWrite
, &brinfLSeek
, &CMemAlloc
, &CMemFree
};
static int brinfWritePch // PCH WRITE CALLBACK FUNCTION
( int cookie
, void const *buf // - write buffer
, unsigned len ) // - write length
{
#ifndef NDEBUG
PCHVerifyFile( cookie );
#endif
PCHWriteUnaligned( buf, len );
return len;
}
static long brinfLSeekPch // PCH LSEEK CALLBACK FUNCTION
( int cookie
, long offset // - seek offset
, int whence ) // - seek direction, see b_write.h
{
#ifndef NDEBUG
PCHVerifyFile( cookie );
#endif
PCHFlushBuffer();
return PCHSeek( offset, whence );
}
static BRI_Routines const rtns_pch =// CALL-BACK FOR PCH WRITER
{ &brinfWritePch
, &brinfLSeekPch
, &CMemAlloc
, &CMemFree
};
static void brinfOpen // OPEN BROWSE-USE INFO, IF REQD
( void )
{
usage_name = strsave( IoSuppOutFileName( OFT_BRI ) );
usage_file = SrcFileFOpen( usage_name, SFO_WRITE_BINARY );
if( NULL == usage_file ) {
usageIoErr( "(-fbi) unable to open browse file for writing" );
}
IfDbgToggle( browse ) {
DbgStmt( printf( "Br-inf-use: open %s\n", usage_name ) );
}
}
static void brinfClose // CLOSE BROWSE-USE INFO, IF REQD
( void )
{
FILE *temp; // - file to be closed
temp = usage_file;
if( NULL != temp ) {
usage_file = NULL;
BrinfDepFini();
brinfo_state = BRS_INACTIVE;
if( 0 != SrcFileFClose( temp ) ) {
usageIoErr( "(-fbi) unable to close usage file" );
}
IfDbgToggle( browse ) {
DbgStmt( printf( "Br-inf-use: close %s\n", usage_name ) );
}
} else {
brinfo_state = BRS_INACTIVE;
}
}
void BrinfDeclClass // VALID CLASS HAS BEEN DECLARED
( TYPE cltype ) // - class type
{
TOKEN_LOCN* locn = LocnForClass( cltype ); // - location of the class
TOKEN_LOCN currLocn; // - parser's current location
if( locn == NULL ) {
SrcFileGetTokenLocn( &currLocn );
locn = &currLocn;
}
if( activeScopesReset( cltype->u.c.scope, locn ) ) {
ExtraRptIncrementCtr( ctr_class_decl );
if( BrinfActive() ) {
brinfIcPtr( IC_BR_DCL_CLASS, cltype );
}
}
}
void BrinfDeclNamespace // VALID NAMESPACE HAS BEEN DECLARED
( SYMBOL ns ) // - namespace defined
{
if( activeScopesAdjust( ns ) ) {
ExtraRptIncrementCtr( ctr_namespace_decl );
IfDbgToggle( browse ) {
DbgStmt( printf( "Br-inf-dcl: namespace is %s"
, ScopeNameSpaceName( ns->u.ns->scope )
)
);
DbgStmt( DbgDumpTokenLocn( &ns->locn->tl ) );
DbgStmt( printf( "\n" ) );
}
}
}
void BrinfDeclSymbol // VALID SYMBOL HAS BEEN DECLARED
( SYMBOL sym ) // - symbol defined
{
if( ! SymIsClassMember( sym )
&& SymIsBrowsable( sym )
&& activeScopesAdjust( sym ) ) {
ExtraRptIncrementCtr( ctr_symbol_decl );
IfDbgToggle( browse ) {
DbgStmt( printf( "Br-inf-dcl: symbol is %s"
, DbgSymNameFull( sym )
)
);
DbgStmt( DbgDumpTokenLocn( &sym->locn->tl ) );
DbgStmt( printf( "\n" ) );
}
if( SymIsFunction( sym ) ) {
if( CompFlags.optbr_f ) {
brinfIcDclSym( IC_BR_DCL_FUN, sym );
}
} else {
if( CompFlags.optbr_v
&& sym->locn != NULL
&& sym->locn->tl.src_file != NULL ) {
brinfIcDclSym( IC_BR_DCL_VAR, sym );
}
}
refSymType( sym );
}
}
void BrinfDeclTemplateClass // VALID CLASS TEMPLATE HAS BEEN DECLARED
( SYMBOL tc ) // - template defined
{
if( ! SymIsClassMember( tc )
&& activeScopesAdjust( tc ) ) {
ExtraRptIncrementCtr( ctr_template_class_decl );
IfDbgToggle( browse ) {
DbgStmt( printf( "Br-inf-def: template class is %s"
, DbgSymNameFull( tc )
)
);
DbgStmt( DbgDumpTokenLocn( &tc->locn->tl ) );
DbgStmt( printf( "\n" ) );
}
refSymType( tc );
}
}
void BrinfDeclTypedef // VALID TYPEDEF HAS BEEN DECLARED
( SYMBOL td ) // - namespace defined
{
if( ! SymIsClassMember( td )
&& activeScopesAdjust( td ) ) {
ExtraRptIncrementCtr( ctr_typedef );
IfDbgToggle( browse ) {
DbgStmt( printf( "Br-inf-def: typedef is %s"
, DbgSymNameFull( td )
)
);
DbgStmt( DbgDumpTokenLocn( &td->locn->tl ) );
DbgStmt( printf( "\n" ) );
}
if( CompFlags.optbr_t ) {
brinfIcDclSym( IC_BR_DCL_TDEF, td );
}
refSymType( td );
}
}
void BrinfReferenceSymbol // SYMBOL REFERENCE
( TOKEN_LOCN* locn // - location of access
, SYMBOL sym ) // - symbol accessed
{
if( BrinfActive()
&& SymIsBrowsable( sym ) ) {
IfDbgToggle( browse ) {
DbgStmt( printf( "Br-inf-ref: symbol is %s"
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?